.theme-toggle.button { min-width: 36px; min-height: 36px; padding: 5px; flex-shrink: 0; }
.theme-toggle .theme-sun, [data-theme="dark"] .theme-toggle .theme-moon { display: none; }
[data-theme="dark"] .theme-toggle .theme-sun { display: inline-grid; }
.theme-document-controls { display: flex; justify-content: flex-end; margin-bottom: 8px; }
.theme-toggle-auth { position: fixed; z-index: 5; top: 14px; right: 14px; }

.topbar-right { gap: clamp(6px, 1.1vw, 14px); }
.topbar-right > :is(.notification, .theme-toggle.button) {
    position: relative;
    display: grid;
    place-items: center;
    flex: 0 0 36px;
    width: 36px;
    height: 36px;
    min-height: 36px;
    padding: 0;
    border: 1px solid var(--line);
    border-radius: 9px;
    background: #fff;
    color: #54635b;
}
.topbar-right > :is(.notification, .theme-toggle.button):hover { background: #edf6f0; }
.topbar-right > :is(.notification, .theme-toggle.button) > .icon { width: 16px; height: 16px; font-size: 15px; }
.notification .notification-dot { width: 7px; height: 7px; top: 7px; right: 7px; border: 1px solid #fff; }

@media screen {
    :root[data-theme="dark"] {
        color-scheme: dark;
        --bg: #111815;
        --ink: #e6eee9;
        --muted: #a4b5aa;
        --line: #35443a;
        --green: #4bd497;
        --dark-green: #137247;
        --theme-surface: #1b2620;
        --theme-raised: #233229;
        --theme-accent: #83e3b2;
    }

    [data-theme="dark"] :is(body, .auth-body, .harvest-auth, .app-shell) {
        background: var(--bg);
        color: var(--ink);
    }

    [data-theme="dark"] :is(.sidebar, .topbar, .panel, .workspace-dialog, .harvest-card, .harvest-form-side, .password-card, .settings-mini-sidebar, .overview-search-results, .bill-to-suggestions, .project-client-suggestions, .envato-item-card) {
        background: var(--theme-surface);
        color: var(--ink);
        border-color: var(--line);
        box-shadow: none;
    }

    [data-theme="dark"] :is(.search-box, .button:not(.primary, .logout-button, .client-danger-solid), .dialog-heading > button, .tracker-sheet thead th, .tracker-sheet .tracker-letters td, .dashboard-calendar-grid th, .dashboard-calendar-grid .calendar-outside, .earnings-month-grid > div, .overview-rank, .key) {
        background: var(--theme-raised);
        border-color: var(--line);
        color: var(--ink);
    }

    [data-theme="dark"] :is(input:not([type="checkbox"], [type="radio"]), select, textarea) {
        background-color: var(--bg);
        border-color: var(--line);
        color: var(--ink);
    }

    [data-theme="dark"] .search-box :is(input, select) { background-color: transparent; }
    [data-theme="dark"] .search-box option { background: var(--theme-surface); }

    [data-theme="dark"] :is(.sidebar-note, .overview-welcome, .overview-actions a, .register-callout, .client-balance-preview, .mail-setup-note, .growth-card, .invoice-form-note) {
        background: var(--theme-raised);
        border-color: var(--line);
        color: var(--ink);
    }

    [data-theme="dark"] :is(.brand, .page-heading h1, .project-workspace .page-heading h1, .clients-workspace .page-heading h1, .harvest-form h1, .harvest-wordmark, .harvest-form label, .password-card h1, .panel-heading h2, .panel h3, .dialog-heading h2, .account, .nav-link, .table-wrap th, .table-wrap td, .tracker-sheet th, .tracker-sheet td) {
        color: var(--ink);
    }

    [data-theme="dark"] :is(.muted, .eyebrow, .page-heading p, .account small, .nav-caption, .tracker-sheet small, .earnings-card small, .earnings-month-grid span, .harvest-subtitle, .harvest-access, .harvest-form-side label small, footer) {
        color: var(--muted);
    }

    [data-theme="dark"] :is(.text-link, .text-button, .strong-link, .green-text, .tracker-balance, .earnings-year-total, .search-box > button, .harvest-form a:not(.harvest-wordmark), .back-login) {
        color: var(--theme-accent);
    }

    [data-theme="dark"] :is(.nav-link.active, .nav-link:hover, .button:not(.primary, .logout-button, .client-danger-solid):hover, .overview-search-results a:hover, .overview-person:hover, .calendar-date-button:hover) {
        background: #2c4235;
        color: var(--ink);
    }

    [data-theme="dark"] :is(.tracker-sheet tbody tr:nth-child(even), .tracker-sheet tbody tr:hover, .table-wrap thead, .table-wrap th) {
        background: var(--theme-raised);
    }

    [data-theme="dark"] :is(.tracker-sheet th, .tracker-sheet td, .dashboard-calendar-grid th, .dashboard-calendar-grid td, .calendar-day-section, .client-directory-row, .overview-person, .form-actions, .table-wrap th, .table-wrap td, .topbar-divider) {
        border-color: var(--line);
    }

    [data-theme="dark"] #logout-form .nav-link { background: #a52d35; color: #fff; }
    [data-theme="dark"] #logout-form .nav-link:hover { background: #87232a; }

    [data-theme="dark"] .alert.success { background: #193c2b; border-color: #34684e; color: #b3efcc; }
    [data-theme="dark"] .alert.error { background: #422829; border-color: #754547; color: #ffd1d1; }
    [data-theme="dark"] .button.client-danger { color: #ffb5b5; }
    [data-theme="dark"] .workspace-dialog::backdrop { background: #080f0bd1; }

    [data-theme="dark"] :is(.stat-card, .donut > div, .invoice-create-dialog .form-actions, .client-pay-dialog, .invoice-row-popup iframe) {
        background: var(--theme-surface);
        border-color: var(--line);
        color: var(--ink);
    }

    [data-theme="dark"] :is(.stat-bottom > span, .status-ring:not(.paid), .overview-progress, .bill-to-editor, .invoice-project-picker, .invoice-project-option, .invoice-project-thumb, .invoice-project-option-check, .invoice-selected-project, .invoice-scope-editor, .invoice-payment-plan, .payment-dialog-balance, .bill-to-dropdown-toggle, .sharing-amount, .sharing-file-preview, .sharing-link-input) {
        background: var(--theme-raised);
        border-color: var(--line);
        color: var(--ink);
    }

    [data-theme="dark"] :is(.tabs a.selected, .bill-to-suggestion:hover, .bill-to-suggestion[aria-selected="true"], .invoice-project-option:hover, .invoice-project-option[aria-pressed="true"], .invoice-row-actions .invoice-copy-link) {
        background: #2b4738;
        border-color: #426451;
        color: var(--theme-accent);
    }

    [data-theme="dark"] :is(.stat-top, .stat-value small, .overview-meta, .chart-legend, .chart-caption, .chart-caption span, .due-detail small, .recent-item small, .donut small, .growth-card p, .overview-welcome p, .overview-open > span, .overview-actions small, .attention-copy small, .overview-person small, .overview-person > span:last-child, .overview-search-results small, .overview-search-results p, .tracker-sheet .tracker-empty, .section-heading p, .invoice-currency-note, .invoice-scope-editor p, .invoice-payment-plan p, .bill-to-suggestion small, .invoice-project-empty, .payment-entry small, .client-feedback-dialog p, .sharing-project, .sharing-label, .sharing-amount > span, .sharing-amount > small, .sharing-totals dt, .sharing-file-preview small, .sharing-option > p, .sharing-expiry) {
        color: var(--muted);
    }

    [data-theme="dark"] :is(.overview-actions strong, .attention-copy strong, .overview-person strong, .overview-search-results strong, .invoice-editor h2, .invoice-project-picker > label, .bill-to-suggestion strong, .invoice-project-option strong, .client-feedback-dialog h2, .client-pay-dialog .dialog-heading h2, .sharing-amount > strong, .sharing-file-preview strong, .sharing-email-recipient strong, .sharing-totals dd) {
        color: var(--ink);
    }

    [data-theme="dark"] :is(.overview-open > strong, .bill-to-suggestion-stage, .payment-entry strong, .payment-dialog-balance strong, .payment-shortcuts button) {
        color: var(--theme-accent);
    }

    [data-theme="dark"] :is(.empty-icon, .client-confirm-icon, .sharing-document-icon, .sharing-method-icon) {
        background: #2b4738;
        color: var(--theme-accent);
    }

    [data-theme="dark"] .donut { background: conic-gradient(var(--green) calc(var(--progress) * 1%), var(--line) 0); }
    [data-theme="dark"] .chart svg line { stroke: var(--line); }
    [data-theme="dark"] .chart svg text { fill: var(--muted); }
    [data-theme="dark"] .chart svg circle { stroke: var(--theme-surface); }
    [data-theme="dark"] .tracker-sheet .tracker-balance { color: var(--theme-accent); }
    [data-theme="dark"] .invoice-editor :is(.totals > div, .totals > label) { color: var(--muted); }
    [data-theme="dark"] .invoice-editor .totals strong { color: var(--ink); }
    [data-theme="dark"] .invoice-editor .grand-total strong { color: var(--theme-accent) !important; }
    [data-theme="dark"] .invoice-selected-project input { background: transparent; }

    [data-theme="dark"] :is(.tracker-status, .pill.sent, .dashboard-calendar .delivery) {
        background: #253b51;
        color: #b6d9ff;
    }

    [data-theme="dark"] :is(.tracker-status.ongoing, .pill.partial, .dashboard-calendar .support, .sharing-notice) {
        background: #453820;
        color: #f6d590;
    }

    [data-theme="dark"] :is(.tracker-status.completed, .pill.paid, .dashboard-calendar .payment, .client-payment-success) {
        background: #224432;
        color: #a7ebc5;
    }

    [data-theme="dark"] .pill.draft { background: #3c3050; color: #e3cbff; }
    [data-theme="dark"] .pill.overdue { background: #492b30; color: #ffc3c6; }
    [data-theme="dark"] :is(.pill.void, .pill.unpaid) { background: #34413a; color: #d3e0d7; }
    [data-theme="dark"] .dashboard-calendar .calendar-dot { background: currentColor; }

    [data-theme="dark"] .topbar-right > :is(.notification, .theme-toggle.button) {
        background: var(--theme-raised);
        color: var(--ink);
    }

    [data-theme="dark"] .topbar-right > :is(.notification, .theme-toggle.button):hover { background: #2c4235; }
    [data-theme="dark"] .notification-dot { border-color: var(--theme-raised); }
    [data-theme="dark"] :is(input, textarea)::placeholder { color: var(--muted); opacity: 1; }
    [data-theme="dark"] :is(a, button, input, select, textarea):focus-visible { outline: 2px solid var(--theme-accent); outline-offset: 2px; }

    [data-theme="dark"] :is(.settings-section-links a, .integration-status, .connection-result, .envato-items-status, .envato-item-mark, .envato-item-card > a.text-link span, .client-form-section-title > span, .harvest-footer > span) {
        background: var(--theme-raised);
        border-color: var(--line);
        color: var(--muted);
    }

    [data-theme="dark"] :is(.settings-mini-sidebar a, .settings-section-links a, .envato-item-card > a.text-link) {
        color: var(--theme-accent);
        border-color: var(--line);
    }

    [data-theme="dark"] :is(.settings-mini-sidebar a:hover, .settings-mini-sidebar a.active, .settings-section-links a:hover, .envato-item-card > a.text-link:hover, .overview-person:target, .client-directory-row:target) {
        background: #2c4235;
        color: var(--ink);
    }

    [data-theme="dark"] :is(.client-directory-info strong, .client-contact-list dd, .clients-directory .empty-state h3, .clients-workspace .client-form-section-title, .envato-item-card h3) {
        color: var(--ink);
    }

    [data-theme="dark"] :is(.client-directory-info small, .client-contact-list dt, .clients-directory .empty-state p, .envato-item-card p, .report-stats span, .aging-grid span, .harvest-footer, .harvest-wordmark > span:last-child, .sharing-kicker, .sharing-file-currency, .sharing-email-recipient > span) {
        color: var(--muted);
    }

    [data-theme="dark"] :is(.client-contact-list > div, .clients-workspace .form-actions, .clients-workspace .client-form-section-title, .envato-item-card > a.text-link, .envato-item-image) {
        border-color: var(--line);
    }

    [data-theme="dark"] .app-shell table:not(.invoice-paper table, .quote-document table) th {
        background: var(--theme-raised);
        border-color: var(--line);
        color: var(--ink);
    }

    [data-theme="dark"] :is(.envato-item-image, .invoice-project-thumb img, .invoice-project-option-check) {
        background-color: var(--theme-raised);
        border-color: var(--line);
    }

    [data-theme="dark"] .connection-ok { background: #224432; border-color: #34684e; color: #a7ebc5; }
    [data-theme="dark"] .connection-failed { background: #492b30; border-color: #754547; color: #ffc3c6; }

    [data-theme="dark"] .clients-workspace :is(.register-callout, .client-contact-list > div, .client-invoice-history, .client-invoice-row, .client-directory-row) {
        border-color: var(--line);
    }

    [data-theme="dark"] .clients-workspace .register-callout,
    [data-theme="dark"] .clients-workspace :is(.clients-directory .panel-heading .muted, .client-inline-actions button, .clients-directory .client-avatar) {
        background: var(--theme-raised);
        border-color: var(--line);
        color: var(--ink);
    }

    [data-theme="dark"] .clients-workspace :is(.clients-directory .panel-heading h2, .client-invoice-history h3, .client-profile-heading strong, .workspace-dialog label) {
        color: var(--ink);
    }

    [data-theme="dark"] .clients-workspace :is(.page-heading .eyebrow, .page-heading p, .register-callout > span, .client-invoice-row small) {
        color: var(--muted);
    }

    [data-theme="dark"] .clients-workspace :is(.register-callout strong, .register-callout .button, .client-invoice-row strong, .clients-directory .panel-heading h2 .icon) {
        color: var(--theme-accent);
    }

    [data-theme="dark"] .clients-workspace :is(.client-inline-actions button:hover, .client-invoice-row:hover) {
        background: #2c4235;
        border-color: #426451;
    }

    [data-theme="dark"] .clients-workspace .client-inline-actions .client-delete-action {
        background: #492b30;
        border-color: #754547;
        color: #ffc3c6;
    }

    [data-theme="dark"] .clients-workspace .client-inline-actions .client-delete-action:hover {
        background: #60383d;
    }

    [data-theme="dark"] .clients-workspace :is(.workspace-dialog, .client-project-form) :is(input, select, textarea) {
        background: var(--bg);
        border-color: var(--line);
        color: var(--ink);
    }

    [data-theme="dark"] .clients-workspace :is(.workspace-dialog, .client-project-form) :is(input, select, textarea):focus {
        background: var(--bg);
        border-color: var(--theme-accent);
    }

    [data-theme="dark"] .dashboard-page :is(.stat-card, .earnings-card, .dashboard-grid > .panel, .overview-feature-grid > .panel, .calendar-day-dialog) {
        background: var(--theme-surface);
        border-color: var(--line);
        color: var(--ink);
    }

    [data-theme="dark"] .dashboard-page :is(.overview-welcome, .growth-card, .overview-actions > .panel) {
        background: var(--theme-raised);
        border-color: var(--line);
        color: var(--ink);
    }

    [data-theme="dark"] .dashboard-page :is(.stat-card:hover, .overview-actions > .panel:hover, .due-item:hover, .recent-item:hover, .overview-person:hover) {
        background: #2c4235;
        border-color: #426451;
    }

    [data-theme="dark"] .dashboard-page :is(.attention-item, .overview-person, .recent-item, .due-item, .chart-caption, .dashboard-calendar-grid th, .dashboard-calendar-grid td, .calendar-day-section) {
        border-color: var(--line);
    }

    [data-theme="dark"] .dashboard-page :is(.stat-top, .tabs, .chart-legend, .chart-caption, .chart-caption span, .donut-legend, .empty-state p, .growth-card .eyebrow) {
        color: var(--muted);
    }

    [data-theme="dark"] .dashboard-page :is(.panel-heading h2 .icon, .growth-card .rocket.icon) {
        color: var(--theme-accent);
    }

    [data-theme="dark"] .dashboard-page :is(.icon-disc.green, .avatar, .status-ring.paid) {
        background: #224432;
        color: #a7ebc5;
    }

    [data-theme="dark"] .dashboard-page .icon-disc.blue { background: #253b51; color: #b6d9ff; }
    [data-theme="dark"] .dashboard-page .icon-disc.purple { background: #3c3050; color: #e3cbff; }
    [data-theme="dark"] .dashboard-page .icon-disc.orange { background: #453820; color: #f6d590; }
    [data-theme="dark"] .dashboard-page .green-text { color: #a7ebc5; }
    [data-theme="dark"] .dashboard-page .blue-text { color: #b6d9ff; }
    [data-theme="dark"] .dashboard-page .purple-text { color: #e3cbff; }
    [data-theme="dark"] .dashboard-page .orange-text { color: #f6d590; }

    [data-theme="dark"] .dashboard-page .tabs a:not(.selected):hover { color: var(--ink); }
    [data-theme="dark"] .dashboard-page .growth-card::after { background: #335646; }
    [data-theme="dark"] .dashboard-page .dashboard-calendar-grid .calendar-today { box-shadow: inset 0 0 0 2px var(--theme-accent); }
    [data-theme="dark"] .dashboard-page .calendar-today time { color: var(--theme-accent); }

    [data-theme="dark"] :is(.invoice-paper, .quote-document, .receipt-paper) {
        color-scheme: light;
        --ink: #19232e;
        --muted: #64748b;
        --line: #edf0f2;
        --dark-green: #007d49;
        --theme-accent: #007d49;
        background: #fff;
        border-color: var(--line);
        color: var(--ink);
    }

    [data-theme="dark"] .invoice-paper .button:not(.primary) {
        background: #fff;
        border-color: #dbe4ed;
        color: #22344b;
    }
}

@media screen {
    [data-theme="dark"] .topbar-right .button.topbar-logout { background: #a52d35; border-color: #be4a52; color: #fff; }
    [data-theme="dark"] .topbar-right .button.topbar-logout:hover { background: #87232a; color: #fff; }
    [data-theme="dark"] .sidebar-bottom { background: var(--theme-surface); }
}
