/* Shared appearance controls; the existing palette remains the light theme. */
:root {
    --theme-bg: #eef3f8;
    --theme-panel: #ffffff;
    --theme-soft: #f3f7fa;
    --theme-ink: #152033;
    --theme-muted: #64748b;
    --theme-line: #ccd9e2;
    --theme-accent: #17654d;
}
button.parms-theme-toggle {
    display: inline-grid; place-items: center; flex: 0 0 44px;
    width: 44px; min-width: 44px; height: 44px; min-height: 44px;
    padding: 10px; margin: 0; border: 1px solid var(--theme-line); border-radius: 12px;
    background: var(--theme-panel); color: var(--theme-accent); cursor: pointer;
}
.parms-theme-toggle svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.parms-theme-toggle:hover { background: var(--theme-soft); }
.parms-theme-toggle:focus-visible, [data-theme-select]:focus-visible { outline: 3px solid #549dde; outline-offset: 3px; }
.parms-theme-toggle .theme-sun { display: none; }
[data-theme="dark"] .parms-theme-toggle .theme-sun { display: block; }
[data-theme="dark"] .parms-theme-toggle .theme-moon { display: none; }
.login-theme-control { display: flex; justify-content: flex-end; margin-bottom: 12px; }
.mobile-login-theme { display: flex; justify-content: flex-end; }
.parms-theme-setting { padding: 14px; margin-bottom: 18px; border: 1px solid var(--theme-line); border-radius: 12px; background: var(--theme-soft); }
.parms-theme-setting label { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; margin: 0 0 6px; color: var(--theme-ink); }
.parms-theme-setting select { width: auto; min-width: 150px; min-height: 44px; }
.parms-theme-setting small { display: block; color: var(--theme-muted); font-size: .78rem; }

/* Screen-only overrides keep printed reports in their original light palette. */
@media screen {
    html[data-theme="dark"] {
        --theme-bg: #101a25; --theme-panel: #192735; --theme-soft: #213343;
        --theme-ink: #e5edf4; --theme-muted: #acbdca; --theme-line: #405565; --theme-accent: #82dcbc;
        --bg: var(--theme-bg); --bg-soft: var(--theme-soft); --panel: var(--theme-panel); --panel-soft: var(--theme-soft);
        --ink: var(--theme-ink); --muted: var(--theme-muted); --line: var(--theme-line); --line-strong: #577183;
        --primary: #8dbaff; --primary-dark: #b7d3ff; --green: #82dcbc; --green-dark: #afead4;
        --teal: #76d8d2; --blue: #93c6ff; --amber: #f3c777; --red: #ffacaa;
        --field-ink: #e5edf4; --field-focus: #8dbaff;
        --cream: #152330; --cream-soft: #101a25; --white: #192735;
        --shadow-sm: 0 8px 24px #0003; --shadow-md: 0 18px 46px #0005;
    }
    html[data-theme="dark"] body { background: var(--theme-bg); color: var(--theme-ink); }
    html[data-theme="dark"] body.smartparms-app {
        --smart-green: #82dcbc; --smart-green-dark: #afead4; --smart-mint: #213d37;
        --smart-navy: #e5edf4; --smart-text: #e5edf4; --smart-muted: #acbdca;
        --smart-line: #405565; --smart-surface: #192735;
    }
    html[data-theme="dark"] :is(
        .topbar, .section-menu, .panel, .card, .summary-card, .modal-content, .modal-footer,
        .global-search-hero, .global-search-form, .global-result-group, .global-quick-link,
        .cultivation-step, .cultivation-summary-item, .cultivation-plr-stats label, .profile-grid div,
        .subscription-admin-card, .subscription-process-form, .duty-card,
        .login-shell, .login-form-panel, .login-card, .login-brand-panel, .offline-login, .offline-card,
        .offline-top, .sync-strip, .offline-tabs, .smart-global-header, .app-bottom-nav,
        .tool-menu > button, .tool-menu > a, .offline-record-row, .duty-card,
        .duty-detail-sheet, .duty-plan-sheet, .sheet-heading, .farmer-profile-grid div,
        .farmer-profile-note, .farmer-profile-card details, .smart-home-list, .smart-stat-card,
        .mobile-record-card, .smart-ai-card, .smart-ai-results, .smart-ai-result, .smart-ai-result-card,
        .smart-ai-form, .smart-ai-guide, .smart-search-detail-grid > div, .plrc-card,
        .public-header, .public-nav, .value-grid article, .module-grid article,
        .subscribe-steps article, .subscribe-request-card form, .mini-grid > div,
        .message-card, .sitemap-grid > div, .smart-benefit-grid article, .smart-mobile-card,
        .smart-phone-screen, .smart-app-grid > div, .smart-app-nav
    ) { background: var(--theme-panel); color: var(--theme-ink); border-color: var(--theme-line); }
    html[data-theme="dark"] :is(
        .table thead th, .table tfoot th, .global-result-group .panel-header, .topbar-help kbd,
        .linked-box, .cultivation-page-head, .cultivation-step-head, .cultivation-empty-line,
        .cultivation-modal .modal-footer, .cultivation-plr-modal .modal-body, .cultivation-modal-note,
        .service-address-box, .subscription-admin-head, .subscription-approval-help,
        .subscription-invitation-bar, .workflow-guidance, .workflow-action-box,
        .page-help-summary, .shortcut-grid > span, .page-help-scope, .setup-username, .password-rules,
        .duty-detail-grid div, .duty-detail-block, .register-history-toggle,
        .cultivation-live-bar, .plr-application-detail, .farmer-search-box, .farmer-profile-card summary,
        .mobile-form-intro, .smart-ai-answer, .smart-ai-guide section, .smart-ai-user-turn p,
        .smart-ai-breakdown, .smart-ai-breakdown-head, .app-icon-button,
        .smart-ai-prompts button, .smart-ai-followups button, .smart-ai-result-actions button,
        .soft-section, .intro-section, .workflow-section, .founder-section, .manual-section, .contact-section,
        .audience-section, .audience-list > div,
        .pricing-section, .subscribe-request-section, .manual-note, .smart-benefits-section, .smart-mobile-section,
        .smart-mini-visual, .smart-tool-list article, .smart-public-cta
    ) { background: var(--theme-soft); color: var(--theme-ink); border-color: var(--theme-line); }
    html[data-theme="dark"] .cultivation-invoice-line { background: var(--theme-panel) !important; border-color: var(--theme-line) !important; }
    html[data-theme="dark"] :is(.table-empty-state, .empty-state-inline) { background: var(--theme-panel) !important; }
    html[data-theme="dark"] :is(.summary-icon, .tool-icon, .smart-stat-icon, .workflow-step-marker, .live-check, .smart-ai-mark, .smart-icon) {
        background: var(--theme-soft); color: var(--theme-accent); border-color: var(--theme-line);
    }
    html[data-theme="dark"] .summary-card .summary-icon { background: var(--theme-soft); }
    html[data-theme="dark"] :is(
        .page-title, .page-kicker, .topbar-help, .panel-title, .panel-header h2, .summary-card strong,
        .summary-value, .empty-state-content strong,
        .public-site h2, .public-site h3, .smart-app-top strong, .manual-nav strong, .accordion summary,
        .login-brand-copy h2, .login-credit strong, .cultivation-line-id, .cultivation-total-card small,
        .global-search-hero h2, .global-result-item, .cultivation-step-title, .cultivation-summary-item strong,
        .page-help-body h6, .workflow-step-title, .form-section-heading, .app-section-heading h2,
        .smart-home-row, .smart-stat-card strong, .smart-ai-heading, .smart-ai-heading h2,
        .public-brand strong, .public-nav > a:not(.staff-login), .section-heading h2,
        .intro-copy h2, .value-grid h3, .module-grid h3, .manual-copy h2, .contact-section h2,
        .price-comparison h2, .price-comparison > div strong, .comparison-kicker,
        .smart-benefit-grid h3, .smart-tool-list h3, .smart-mobile-copy h2, .smart-public-cta h2
    ) { color: var(--theme-ink); }
    html[data-theme="dark"] :is(label, .form-label, .plr-checklist, .duty-detail-grid strong, .duty-detail-block p) { color: var(--theme-ink); }
    html[data-theme="dark"] :is(
        .text-muted, .text-secondary, .hint, .section-eyebrow, .login-credit, .record-main small,
        .record-side small, .smart-ai-note, .smart-ai-keyboard-hint, .smart-ai-heading > div > span,
        .smart-home-row small, .smart-home-empty, .smart-ai-card > p, .smart-ai-guide section span, .plrc-prefix, .plrc-heading p,
        .smart-app-top small, .smart-screen-heading small, .smart-sync-card small, .manual-note p,
        .plrc-note, .plrc-footnote, .plrc-metrics span, .plrc-breakdown, .plrc-add-hint,
        .plrc-application-row small, .plrc-application-list > p
    ) { color: var(--theme-muted) !important; }
    html[data-theme="dark"] :is(input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]):not([type="submit"]):not([type="button"]), select, textarea) {
        background-color: #13212d; color: var(--theme-ink); -webkit-text-fill-color: var(--theme-ink);
        border-color: #577183; caret-color: #8dbaff;
    }
    html[data-theme="dark"] :is(input, textarea)::placeholder { color: #a3b5c4; -webkit-text-fill-color: #a3b5c4; opacity: 1; }
    html[data-theme="dark"] :is(input, select, textarea):focus {
        background-color: #192c3b; border-color: #8dbaff; outline-color: #8dbaff;
    }
    html[data-theme="dark"] :is(input, select, textarea):disabled { color: var(--theme-muted); -webkit-text-fill-color: var(--theme-muted); opacity: .7; }
    html[data-theme="dark"] :is(input, select, textarea)[readonly] { background-color: var(--theme-soft); }
    html[data-theme="dark"] input:-webkit-autofill {
        -webkit-box-shadow: 0 0 0 1000px #13212d inset; -webkit-text-fill-color: var(--theme-ink);
    }
    html[data-theme="dark"] .btn-primary {
        --bs-btn-bg: #275daf; --bs-btn-border-color: #5286cb; --bs-btn-hover-bg: #316bc5;
        --bs-btn-hover-border-color: #8dbaff; --bs-btn-active-bg: #275daf; --bs-btn-color: #fff;
    }
    html[data-theme="dark"] .btn-light { --bs-btn-bg: #213343; --bs-btn-border-color: #405565; --bs-btn-color: #e5edf4; --bs-btn-hover-bg: #304859; --bs-btn-hover-color: #fff; }
    html[data-theme="dark"] :is(.btn-outline-success, .btn-outline-danger, .btn-outline-secondary) { --bs-btn-color: var(--theme-ink); }
    html[data-theme="dark"] :is(button.primary, .app-primary-action, .smart-ai-submit, .plrc-save-row button) {
        background: #22664f; color: #fff; border-color: #60ae92;
    }
    html[data-theme="dark"] .smartparms-app .smart-ai-submit { background: #22664f; color: #fff; }
    html[data-theme="dark"] .smartparms-app .smart-ai-form .smart-ai-clear { color: var(--theme-muted); }
    html[data-theme="dark"] .table-hover > tbody > tr:hover > * { --bs-table-bg-state: #304859; }
    html[data-theme="dark"] .plr-checklist button:not([type="submit"]) { background: var(--theme-soft); color: var(--theme-accent); border-color: var(--theme-line); }
    html[data-theme="dark"] .table {
        --bs-table-color: #e5edf4; --bs-table-bg: #192735; --bs-table-border-color: #405565;
        --bs-table-striped-bg: #213343; --bs-table-striped-color: #e5edf4;
        --bs-table-hover-bg: #304859; --bs-table-hover-color: #fff;
    }
    html[data-theme="dark"] :is(.table-responsive, .plrc-application-list, .plrc-application-row, .smart-home-row, .smart-ai-result) { border-color: var(--theme-line); }
    html[data-theme="dark"] :is(.filter-state-bar, .cultivation-saved-line, .offline-item-action button, .status-pill, .offline-badge, .plrc-badge.none, .plrc-badge.partial) { background: #243e55; color: #b9d8ff; border-color: #52718b; }
    html[data-theme="dark"] :is(.live-check.ok, .cultivation-total-card, .workflow-guidance-success, .global-search-scope, .offline-badge.done, .plrc-badge.full) { background: #203f35; color: #a6e5c9; border-color: #497b68; }
    html[data-theme="dark"] :is(.live-check.bad, .form-validation-summary, .workflow-guidance-danger, .plrc-badge.over) { background: #472d35; color: #ffbcbc; border-color: #955564; }
    html[data-theme="dark"] :is(.workflow-guidance-warning, .plrc-pending, .planning-window) { background: #423821; color: #f3d393; border-color: #8b7749; }
    html[data-theme="dark"] :is(.plrc-comparison.mismatch, .plrc-card-message, .plrc-feedback[data-error="true"]) { color: #ffca89; }
    html[data-theme="dark"] :is(.text-success, .plrc-balance, .login-app-name, .smart-ai-guide summary) { color: #82dcbc !important; }
    html[data-theme="dark"] :is(.text-danger, .message.error) { color: #ffacaa !important; }
    html[data-theme="dark"] :is(.skip-link, .filter-clear-button, .password-toggle, .nav-toggle, .smart-ai-clear) { background: var(--theme-soft); color: var(--theme-ink); }
    html[data-theme="dark"] :is(.offline-tabs button, .app-bottom-nav button) { color: var(--theme-muted); }
    html[data-theme="dark"] :is(.offline-tabs button.active, .app-bottom-nav button.active, .sync-strip button) { background: #213d37; color: #a6e5c9; }
    html[data-theme="dark"] :is(.global-result-item, .global-quick-link, .offline-record-row, .smart-ai-result, .tool-menu > button):hover { background: #2b4253; color: var(--theme-ink); }
    html[data-theme="dark"] :is(.cultivation-step-title i, .smart-home-row > span:last-child, .workflow-step.current .workflow-step-marker) { background: #243e55; color: #b9d8ff; }
    html[data-theme="dark"] :is(.bg-white, .bg-light) { background-color: var(--theme-panel) !important; color: var(--theme-ink); }
    html[data-theme="dark"] .text-dark { color: var(--theme-ink) !important; }
    /* Public pages retain the photographic hero and existing green brand sections. */
    html[data-theme="dark"] .public-brand strong,
    html[data-theme="dark"] .public-site :is(.eyebrow:not(.light), .founder-qualification, .manual-kicker, .text-link, .smart-label, .contact-person > span) { color: #a6e5c9; }
    html[data-theme="dark"] :is(.price-comparison > div.highlight, .public-btn.gold, .smart-primary-btn.light) { color: #14291f; }
    html[data-theme="dark"] :is(.mission-card.gold h2, .price-comparison > div.highlight strong, .public-site .smart-primary-btn) { color: #14291f; }
    html[data-theme="dark"] .public-btn.white { background: var(--theme-soft); color: var(--theme-ink); }
    html[data-theme="dark"] .public-nav .staff-login { background: #22664f; color: #fff; }
}
@media print {
    .parms-theme-toggle, .parms-theme-setting { display: none !important; }
    html { color-scheme: light !important; }
    html[data-theme="dark"] :is(body, .panel, .card, .table, .table th, .table td, .modal-content, .form-control, .form-select) {
        background-color: #fff !important; color: #152033 !important; -webkit-text-fill-color: #152033 !important;
        --bs-table-bg: #fff; --bs-table-color: #152033; --bs-table-striped-bg: #f3f5f7; --bs-table-striped-color: #152033;
        --bs-body-color: #152033; --bs-body-bg: #fff; --bs-secondary-color: #536475;
    }
}
