:root {
    color-scheme: light;
    --pos-chart-bar: #111111;
}

@media screen {
    .theme-toggle {
        display: inline-flex; align-items: center; justify-content: center; gap: 8px;
        min-height: 38px; padding: 8px 11px; flex-shrink: 0;
        border: 1px solid #d8deef; border-radius: 10px; background: #f4f7fc; color: #111111;
        font: inherit; font-size: 12px; font-weight: 600; cursor: pointer;
    }
    .theme-toggle:hover { border-color: #a1a1aa; }
    .theme-toggle:focus-visible { outline: 2px solid #d4a900; outline-offset: 3px; }
    .login-theme-switch { position: fixed; top: 18px; right: 18px; z-index: 1100; }

    html[data-theme="dark"] {
        color-scheme: dark;
        --pos-bg: #0f0f0f;
        --pos-surface: #191919;
        --pos-raised: #242424;
        --pos-border: #343434;
        --pos-text: #f4f4f5;
        --pos-muted: #a1a1aa;
        --pos-accent: #ffd700;
        --pos-chart-bar: #85858f;
        --pos-progress-track: #333333;
        background: var(--pos-bg);
    }
    html[data-theme="dark"] body,
    html[data-theme="dark"] .dashboard-container,
    html[data-theme="dark"] .main-content,
    html[data-theme="dark"] .top-header,
    html[data-theme="dark"] .sidebar {
        background: var(--pos-bg) !important; color: var(--pos-text) !important;
    }
    html[data-theme="dark"] .top-header { border-bottom: 1px solid var(--pos-border); }
    html[data-theme="dark"] :is(.metric-card, .stat-card, .chart-card, .summary-card, .toolbar,
        .recent-orders, .form-card, .settings-card, .shop-card, .purchase-product-card,
        .user-profile, .search-box, .search-dialog, .app-dialog, .modal-content,
        .notif-dropdown, .global-search-suggestions, .autocomplete-dropdown,
        .purchase-suggestions, .login-card, .logo-container, .card-body, .offline-container) {
        background: var(--pos-surface) !important; border-color: var(--pos-border) !important;
        box-shadow: 0 8px 24px rgba(0, 0, 0, .18);
    }
    html[data-theme="dark"] :is(.page-title, .menu-toggle, .user-info h4, .chart-header h3,
        .section-header h3, .app-dialog-header h3, .app-dialog-section-title,
        .global-search-title, .notif-header h5, .notif-body p) { color: var(--pos-text) !important; }
    html[data-theme="dark"] :is(.user-info p, .search-hint, .form-hint, .metric-sub,
        .autocomplete-meta, .global-search-meta, .notif-time, .purchase-color-hint,
        .purchase-suggestions-empty, .hint-text, .descriptor) { color: var(--pos-muted) !important; }
    html[data-theme="dark"] :is(.search-overlay, .app-dialog-overlay) { background: rgba(0, 0, 0, .72) !important; }
    html[data-theme="dark"] :is(.app-dialog-header, .app-dialog-section, .notif-header,
        .notif-footer, .global-search-item, .autocomplete-item) { border-color: var(--pos-border) !important; }
    html[data-theme="dark"] :is(input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]), select, textarea) {
        background-color: var(--pos-raised) !important; color: var(--pos-text) !important;
        border-color: var(--pos-border) !important; caret-color: var(--pos-accent);
    }
    html[data-theme="dark"] :is(input, textarea)::placeholder { color: #92929d !important; opacity: 1; }
    html[data-theme="dark"] :is(input, select, textarea):focus {
        border-color: var(--pos-accent) !important; outline-color: var(--pos-accent) !important;
    }
    html[data-theme="dark"] :is(input[type="checkbox"], input[type="radio"]) { accent-color: var(--pos-accent); }
    html[data-theme="dark"] :is(.button-secondary, .pill, .search-close, .app-dialog-close,
        .purchase-suggestion-option, .theme-toggle) {
        background: var(--pos-raised) !important; color: var(--pos-text) !important; border-color: var(--pos-border) !important;
    }
    html[data-theme="dark"] :is(.button-secondary, .pill, .purchase-suggestion-option):hover,
    html[data-theme="dark"] .purchase-suggestion-option[aria-selected="true"] { background: #333333 !important; }
    html[data-theme="dark"] :is(.button-primary, .login-btn) { background: #f4f4f5 !important; color: #0f0f0f !important; }
    html[data-theme="dark"] :is(.button-primary, .login-btn):hover { background: #d4d4d8 !important; }
    html[data-theme="dark"] .login-btn i { color: #0f0f0f !important; }
    html[data-theme="dark"] .pill.active { color: var(--pos-accent) !important; border-color: var(--pos-accent) !important; }
    html[data-theme="dark"] .sidebar .nav-item.active,
    html[data-theme="dark"] .theme-toggle[aria-pressed="true"] { background: var(--pos-accent) !important; color: #0f0f0f !important; }
    html[data-theme="dark"] .sidebar .nav-item.active i { color: #0f0f0f !important; }
    html[data-theme="dark"] .sidebar { scrollbar-color: #454545 var(--pos-bg) !important; }
    html[data-theme="dark"] .sidebar::-webkit-scrollbar-track { background: var(--pos-bg) !important; }
    html[data-theme="dark"] .sidebar::-webkit-scrollbar-thumb { background: #454545 !important; }
    html[data-theme="dark"] :is(.logo-symbol, .shop-logo img) { background: #fff; border-radius: 8px; padding: 5px; }
    html[data-theme="dark"] table { color: var(--pos-text); }
    html[data-theme="dark"] thead { background: var(--pos-raised) !important; }
    html[data-theme="dark"] th { color: #c4c4cc !important; background: var(--pos-raised) !important; }
    html[data-theme="dark"] :is(td, th) { border-color: var(--pos-border) !important; }
    html[data-theme="dark"] tbody tr:hover { background: var(--pos-raised) !important; }
    html[data-theme="dark"] :is(.notif-item.unread, .notif-item:hover, .global-search-item:hover,
        .global-search-item.active, .autocomplete-item:hover) { background: var(--pos-raised) !important; }
    html[data-theme="dark"] .notif-item.unread { border-left-color: var(--pos-accent); }
    html[data-theme="dark"] .global-search-highlight { background: #5c4800; color: #fff3a3; }
    html[data-theme="dark"] .swal2-popup { background: var(--pos-surface) !important; color: var(--pos-text) !important; }
    html[data-theme="dark"] :is(.swal2-title, .swal2-html-container, .swal2-label) { color: var(--pos-text) !important; }
    html[data-theme="dark"] .swal2-footer { border-color: var(--pos-border) !important; }
    html[data-theme="dark"] [data-dark-background] { background-color: var(--pos-auto-bg) !important; background-image: none !important; }
    html[data-theme="dark"] [data-dark-color] { color: var(--pos-auto-fg) !important; }
    html[data-theme="dark"] [data-dark-border] { border-color: var(--pos-auto-border) !important; }
    html[data-theme="dark"] * { scrollbar-color: #454545 var(--pos-bg); }
    @media (max-width: 1024px) {
        .top-header .theme-toggle [data-theme-toggle-label] { display: none; }
        .top-header .theme-toggle { width: 38px; padding: 8px; }
        .top-header .header-right { gap: 12px; }
    }
    @media (max-width: 600px) {
        .top-header { padding: 12px 16px; column-gap: 12px; }
        .top-header .header-left { gap: 12px; min-width: 0; }
        .top-header .page-title { font-size: 20px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
        .top-header .user-info { display: none; }
        .top-header .user-profile { padding: 6px; }
    }
}

@media print {
    html { color-scheme: light !important; }
    .theme-toggle, .login-theme-switch { display: none !important; }
}
