/*
 * Altayseer light / dark theme layer.
 * Loaded after app.css or admin.css so it can safely override both without
 * replacing the existing project styles.
 */

html {
    color-scheme: light;
}

html[data-theme="dark"] {
    color-scheme: dark;
}

/* Shared toggle */
.theme-toggle {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-width: 42px;
    height: 42px;
    padding: 0 12px;
    border: 1px solid rgba(9, 45, 86, .18);
    border-radius: 999px;
    background: rgba(255, 255, 255, .9);
    color: #092d56;
    box-shadow: 0 8px 22px rgba(9, 45, 86, .08);
    cursor: pointer;
    font: inherit;
    font-weight: 800;
    line-height: 1;
    transition: background-color .2s ease, color .2s ease, border-color .2s ease, transform .2s ease, box-shadow .2s ease;
}

.theme-toggle:hover {
    transform: translateY(-1px);
    border-color: rgba(213, 164, 58, .7);
    box-shadow: 0 10px 26px rgba(9, 45, 86, .13);
}

.theme-toggle:focus-visible {
    outline: 3px solid rgba(213, 164, 58, .38);
    outline-offset: 3px;
}

.theme-toggle-icon {
    display: inline-grid;
    place-items: center;
    width: 20px;
    height: 20px;
    font-size: 1.15rem;
    line-height: 1;
    transition: opacity .18s ease, transform .25s ease;
}

.theme-icon-sun {
    position: absolute;
    opacity: 0;
    transform: rotate(-35deg) scale(.65);
}

.theme-icon-moon {
    opacity: 1;
    transform: rotate(0) scale(1);
}

html[data-theme="dark"] .theme-icon-sun {
    position: static;
    opacity: 1;
    transform: rotate(0) scale(1);
}

html[data-theme="dark"] .theme-icon-moon {
    position: absolute;
    opacity: 0;
    transform: rotate(35deg) scale(.65);
}

.public-theme-toggle .theme-toggle-label {
    display: none;
}

html[data-theme="dark"] .theme-toggle {
    background: rgba(15, 45, 70, .92);
    color: #f8d77e;
    border-color: rgba(225, 238, 248, .18);
    box-shadow: 0 10px 28px rgba(0, 0, 0, .22);
}

/* Reduce transition discomfort while keeping the theme change polished. */
.public-site,
.public-site .navbar,
.public-site .service-card,
.public-site .news-card,
.public-site .two-cards article,
.public-site .contact-aside,
.public-site .searchbar,
.admin-page,
.admin-page .admin-top,
.admin-page .panel,
.admin-page .stat-grid article,
.admin-page input,
.admin-page textarea,
.admin-page select,
.admin-page .login-card {
    transition: background-color .2s ease, color .2s ease, border-color .2s ease, box-shadow .2s ease;
}

/* ================================================================
   Public website — dark theme
   ================================================================ */

html[data-theme="dark"] .public-site {
    --theme-bg: #071725;
    --theme-surface: #0c263d;
    --theme-surface-2: #102f4a;
    --theme-soft: #0a2034;
    --theme-text: #edf4fa;
    --theme-muted: #aebfcd;
    --theme-border: #29475f;
    --theme-heading: #f5f9fc;
    --theme-link: #8fc9ff;
    background: var(--theme-bg);
    color: var(--theme-text);
}

html[data-theme="dark"] .public-site .navbar {
    background: rgba(7, 23, 37, .94);
    border-bottom-color: rgba(218, 232, 243, .13);
    box-shadow: 0 10px 35px rgba(0, 0, 0, .18);
}

html[data-theme="dark"] .public-site .brand b,
html[data-theme="dark"] .public-site .nav-toggle,
html[data-theme="dark"] .public-site .section-head h2,
html[data-theme="dark"] .public-site .split h2,
html[data-theme="dark"] .public-site .two-cards h2,
html[data-theme="dark"] .public-site .service-card h2,
html[data-theme="dark"] .public-site .service-card h3,
html[data-theme="dark"] .public-site .news-body h2,
html[data-theme="dark"] .public-site .news-body h3,
html[data-theme="dark"] .public-site .branch h3,
html[data-theme="dark"] .public-site .contact-grid h2,
html[data-theme="dark"] .public-site .error-page h1 {
    color: var(--theme-heading);
}

html[data-theme="dark"] .public-site .brand small,
html[data-theme="dark"] .public-site .service-card p,
html[data-theme="dark"] .public-site .news-body p,
html[data-theme="dark"] .public-site .split p,
html[data-theme="dark"] .public-site .branch p,
html[data-theme="dark"] .public-site .prose,
html[data-theme="dark"] .public-site .footer p {
    color: var(--theme-muted);
}

html[data-theme="dark"] .public-site .nav-links {
    color: #d5e2ec;
}

html[data-theme="dark"] .public-site .nav-links a:hover,
html[data-theme="dark"] .public-site .section-head > a,
html[data-theme="dark"] .public-site .service-card a,
html[data-theme="dark"] .public-site .news-card a {
    color: var(--theme-link);
}

html[data-theme="dark"] .public-site .nav-links .dashboard-link {
    color: #f0ca70;
    border-color: rgba(240, 202, 112, .42);
    background: rgba(213, 164, 58, .08);
}

html[data-theme="dark"] .public-site .nav-links .language {
    background: #d5a43a;
    color: #13263a;
}

html[data-theme="dark"] .public-site .section,
html[data-theme="dark"] .public-site .article-body,
html[data-theme="dark"] .public-site .error-page {
    background-color: var(--theme-bg);
}

html[data-theme="dark"] .public-site .section.soft,
html[data-theme="dark"] .public-site .soft,
html[data-theme="dark"] .public-site .split-section {
    background: var(--theme-soft);
}

html[data-theme="dark"] .public-site .service-card,
html[data-theme="dark"] .public-site .news-card,
html[data-theme="dark"] .public-site .two-cards article,
html[data-theme="dark"] .public-site .searchbar,
html[data-theme="dark"] .public-site .contact-aside,
html[data-theme="dark"] .public-site .empty-state {
    background: var(--theme-surface);
    border-color: var(--theme-border);
    color: var(--theme-text);
}

html[data-theme="dark"] .public-site .service-card:hover,
html[data-theme="dark"] .public-site .news-card:hover {
    border-color: rgba(213, 164, 58, .56);
    box-shadow: 0 22px 55px rgba(0, 0, 0, .28);
}

html[data-theme="dark"] .public-site .news-image {
    background: #102f4a;
}

html[data-theme="dark"] .public-site .check-list li::before {
    background: rgba(34, 197, 94, .16);
    color: #70e69a;
}

html[data-theme="dark"] .public-site .contact-form input,
html[data-theme="dark"] .public-site .contact-form textarea,
html[data-theme="dark"] .public-site .contact-form select,
html[data-theme="dark"] .public-site .searchbar input {
    background: var(--theme-surface-2);
    border-color: var(--theme-border);
    color: var(--theme-text);
}

html[data-theme="dark"] .public-site input::placeholder,
html[data-theme="dark"] .public-site textarea::placeholder {
    color: #8ea4b6;
}

html[data-theme="dark"] .public-site .searchbar button,
html[data-theme="dark"] .public-site .btn-navy {
    background: #174f7d;
    color: #fff;
}

html[data-theme="dark"] .public-site .branch,
html[data-theme="dark"] .public-site .legacy-gallery {
    border-color: var(--theme-border);
}

html[data-theme="dark"] .public-site .article-header {
    background: linear-gradient(135deg, #04111e, #0a3154);
}

html[data-theme="dark"] .public-site .article-primary-image {
    background: var(--theme-surface);
}

html[data-theme="dark"] .public-site .article-rich-content,
html[data-theme="dark"] .public-site .article-rich-content p,
html[data-theme="dark"] .public-site .article-rich-content li {
    color: #dce8f1 !important;
}

html[data-theme="dark"] .public-site .article-rich-content h2,
html[data-theme="dark"] .public-site .article-rich-content h3,
html[data-theme="dark"] .public-site .article-rich-content strong {
    color: #f5f9fc !important;
}

html[data-theme="dark"] .public-site .article-rich-content a {
    color: #83c7ff !important;
}

html[data-theme="dark"] .public-site .article-rich-content blockquote {
    background: var(--theme-surface);
    color: #d8e5ef;
}

html[data-theme="dark"] .public-site .article-rich-content .article-inline-image img,
html[data-theme="dark"] .public-site .article-gallery-item {
    background: #0e2b44;
    box-shadow: 0 18px 45px rgba(0, 0, 0, .3);
}

html[data-theme="dark"] .public-site .footer {
    background: #030e19;
}

html[data-theme="dark"] .public-site .footer-bottom {
    border-top-color: rgba(255, 255, 255, .12);
}

html[data-theme="dark"] .public-site .alert.success {
    background: rgba(34, 197, 94, .14);
    color: #8ce7aa;
}

html[data-theme="dark"] .public-site .alert.error {
    background: rgba(239, 68, 68, .14);
    color: #ffb4b4;
}

@media (max-width: 900px) {
    html[data-theme="dark"] .public-site .nav-links {
        background: #0c263d;
        border: 1px solid #29475f;
        box-shadow: 0 22px 55px rgba(0, 0, 0, .34);
    }

    .public-theme-toggle {
        justify-content: flex-start;
        width: 100%;
    }

    .public-theme-toggle .theme-toggle-label {
        display: inline;
    }
}

/* ================================================================
   Admin dashboard and login — dark theme
   ================================================================ */

.admin-top-meta {
    display: flex;
    align-items: center;
    gap: 14px;
}

.admin-user-summary {
    display: flex;
    flex-direction: column;
}

.admin-theme-toggle .theme-toggle-label,
.login-theme-toggle .theme-toggle-label {
    display: inline;
}

.login-theme-toggle {
    position: fixed;
    top: 20px;
    inset-inline-end: 20px;
    z-index: 30;
}

html[data-theme="dark"] .admin-page {
    --admin-bg-dark: #061522;
    --admin-surface-dark: #0b2438;
    --admin-surface-2-dark: #102d45;
    --admin-text-dark: #e9f1f7;
    --admin-muted-dark: #a9bbc9;
    --admin-line-dark: #29465d;
    background: var(--admin-bg-dark);
    color: var(--admin-text-dark);
}

html[data-theme="dark"] .admin-page .admin-top {
    background: #0a2033;
    border-bottom-color: var(--admin-line-dark);
}

html[data-theme="dark"] .admin-page .admin-top small,
html[data-theme="dark"] .admin-page .page-title p,
html[data-theme="dark"] .admin-page .stat-grid span,
html[data-theme="dark"] .admin-page .panel td small,
html[data-theme="dark"] .admin-page .activity span,
html[data-theme="dark"] .admin-page .setting-row small,
html[data-theme="dark"] .admin-page .appearance-section-head p,
html[data-theme="dark"] .admin-page .media-setting-title p,
html[data-theme="dark"] .admin-page .media-recommendation,
html[data-theme="dark"] .admin-page .alt-settings > p,
html[data-theme="dark"] .admin-page .appearance-save-bar > div,
html[data-theme="dark"] .admin-page .login-card > p {
    color: var(--admin-muted-dark);
}

html[data-theme="dark"] .admin-page .page-title h1,
html[data-theme="dark"] .admin-page .panel h2,
html[data-theme="dark"] .admin-page .stat-grid b,
html[data-theme="dark"] .admin-page .media-panel h3,
html[data-theme="dark"] .admin-page .media-setting-title h3,
html[data-theme="dark"] .admin-page .alt-settings > h3,
html[data-theme="dark"] .admin-page .appearance-save-bar b,
html[data-theme="dark"] .admin-page .login-card h1 {
    color: #f6d477;
}

html[data-theme="dark"] .admin-page .panel,
html[data-theme="dark"] .admin-page .stat-grid article,
html[data-theme="dark"] .admin-page .primary-image-box,
html[data-theme="dark"] .admin-page .gallery-upload-box,
html[data-theme="dark"] .admin-page .admin-gallery-item,
html[data-theme="dark"] .admin-page .media-setting-card,
html[data-theme="dark"] .admin-page .appearance-save-bar,
html[data-theme="dark"] .admin-page .login-card {
    background: var(--admin-surface-dark);
    border-color: var(--admin-line-dark);
    color: var(--admin-text-dark);
}

html[data-theme="dark"] .admin-page .panel th,
html[data-theme="dark"] .admin-page .message-body,
html[data-theme="dark"] .admin-page .unread,
html[data-theme="dark"] .admin-page .rich-editor-toolbar,
html[data-theme="dark"] .admin-page .media-preview,
html[data-theme="dark"] .admin-page .media-preview:not(.dark) {
    background: var(--admin-surface-2-dark);
    color: var(--admin-text-dark);
}

html[data-theme="dark"] .admin-page .panel th,
html[data-theme="dark"] .admin-page .panel td,
html[data-theme="dark"] .admin-page .activity > div,
html[data-theme="dark"] .admin-page .settings-panel .setting-row,
html[data-theme="dark"] .admin-page .alt-setting-row,
html[data-theme="dark"] .admin-page .alt-settings,
html[data-theme="dark"] .admin-page .appearance-save-bar {
    border-color: var(--admin-line-dark);
}

html[data-theme="dark"] .admin-page input,
html[data-theme="dark"] .admin-page textarea,
html[data-theme="dark"] .admin-page select,
html[data-theme="dark"] .admin-page .editor-form input,
html[data-theme="dark"] .admin-page .editor-form textarea,
html[data-theme="dark"] .admin-page .editor-form select,
html[data-theme="dark"] .admin-page .narrow-form input,
html[data-theme="dark"] .admin-page .narrow-form textarea,
html[data-theme="dark"] .admin-page .settings-panel textarea,
html[data-theme="dark"] .admin-page .media-upload-label input,
html[data-theme="dark"] .admin-page .alt-setting-row input {
    background: #102d45;
    border-color: var(--admin-line-dark);
    color: var(--admin-text-dark);
}

html[data-theme="dark"] .admin-page input::placeholder,
html[data-theme="dark"] .admin-page textarea::placeholder {
    color: #8ba1b2;
}

html[data-theme="dark"] .admin-page .filter button,
html[data-theme="dark"] .admin-page .button,
html[data-theme="dark"] .admin-page .primary {
    background: #bf8d24;
    color: #0a1c2b;
}

html[data-theme="dark"] .admin-page .secondary-button {
    background: #102d45;
    color: #dce8f2;
    border-color: var(--admin-line-dark);
}

html[data-theme="dark"] .admin-page .actions a,
html[data-theme="dark"] .admin-page .login-card > a {
    color: #8dccff;
}

html[data-theme="dark"] .admin-page .rich-editor {
    background: #0e2940;
    border-color: var(--admin-line-dark);
}

html[data-theme="dark"] .admin-page .rich-editor-toolbar button {
    background: #173a55;
    color: #eaf2f8;
    border-color: #3c5a70;
}

html[data-theme="dark"] .admin-page .rich-editor-toolbar button:hover {
    background: #214861;
    border-color: #6f8ba0;
}

html[data-theme="dark"] .admin-page .rich-editor-toolbar .insert-image-button {
    background: #bf8d24;
    border-color: #bf8d24;
    color: #081623;
}

html[data-theme="dark"] .admin-page .rich-editor-surface {
    background: #0e2940;
    color: #e5eef5;
}

html[data-theme="dark"] .admin-page .rich-editor-surface h2,
html[data-theme="dark"] .admin-page .rich-editor-surface h3 {
    color: #f4d277;
}

html[data-theme="dark"] .admin-page .rich-editor-surface blockquote {
    background: #14344d;
    color: #d7e3ec;
}

html[data-theme="dark"] .admin-page .rich-editor-surface .article-inline-image {
    background: #102d45;
    border-color: #557187;
}

html[data-theme="dark"] .admin-page .rich-editor-surface .article-inline-image img {
    background: #071725;
}

html[data-theme="dark"] .admin-page .media-status.default,
html[data-theme="dark"] .admin-page .badge.muted {
    background: #1b3a52;
    color: #c1d0dc;
}

html[data-theme="dark"] .admin-page .media-status.custom,
html[data-theme="dark"] .admin-page .badge.ok,
html[data-theme="dark"] .admin-page .flash.success {
    background: rgba(34, 197, 94, .14);
    color: #8ce7aa;
}

html[data-theme="dark"] .admin-page .flash.error {
    background: rgba(239, 68, 68, .14);
    color: #ffb4b4;
}

html[data-theme="dark"] .admin-page.login-page {
    background: linear-gradient(135deg, #020a11, #092945);
}

html[data-theme="dark"] .admin-page .login-card {
    box-shadow: 0 30px 90px rgba(0, 0, 0, .45);
}

/* Flatpickr dark support */
html[data-theme="dark"] .flatpickr-calendar,
html[data-theme="dark"] .flatpickr-months,
html[data-theme="dark"] .flatpickr-month,
html[data-theme="dark"] .flatpickr-weekdays,
html[data-theme="dark"] span.flatpickr-weekday,
html[data-theme="dark"] .flatpickr-time,
html[data-theme="dark"] .flatpickr-time input,
html[data-theme="dark"] .flatpickr-time .flatpickr-am-pm {
    background: #0b2438;
    color: #e9f1f7;
    border-color: #29465d;
}

html[data-theme="dark"] .flatpickr-day {
    color: #dce7ef;
}

html[data-theme="dark"] .flatpickr-day:hover,
html[data-theme="dark"] .flatpickr-day:focus {
    background: #173a55;
    border-color: #173a55;
}

html[data-theme="dark"] .flatpickr-day.selected,
html[data-theme="dark"] .flatpickr-day.startRange,
html[data-theme="dark"] .flatpickr-day.endRange {
    background: #bf8d24;
    border-color: #bf8d24;
    color: #081623;
}

html[data-theme="dark"] .flatpickr-day.prevMonthDay,
html[data-theme="dark"] .flatpickr-day.nextMonthDay {
    color: #6e8495;
}

@media (max-width: 760px) {
    .admin-top-meta {
        gap: 9px;
    }

    .admin-theme-toggle {
        min-width: 42px;
        padding: 0 10px;
    }

    .admin-theme-toggle .theme-toggle-label {
        display: none;
    }

    .admin-user-summary small {
        max-width: 145px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
}

@media (prefers-reduced-motion: reduce) {
    .theme-toggle,
    .theme-toggle-icon,
    .public-site,
    .public-site *,
    .admin-page,
    .admin-page * {
        transition: none !important;
        scroll-behavior: auto !important;
    }
}

/* Preserve horizontal admin header layout despite the legacy .admin-top div rule. */
.admin-page .admin-top-meta {
    flex-direction: row !important;
}

/* If no dedicated light-on-dark logo exists, make the main logo readable. */
html[data-theme="dark"] img[data-theme-logo][data-dark-fallback="true"] {
    filter: brightness(0) invert(1);
}

html[data-theme="light"] img[data-theme-logo] {
    filter: none;
}
