/*
 * Kitab Ghar dark theme
 * Warm Library Charcoal: comfortable charcoal surfaces with sage and amber accents.
 * Screen-only by design so reports and labels retain their existing print output.
 */
@media screen {
    html[data-theme="dark"] {
        color-scheme: dark;
        --canvas: #262925;
        --surface: #30342F;
        --surface-soft: #2B2F2C;
        --surface-raised: #373C38;
        --forest: #73A889;
        --forest-dark: #9AC9AE;
        --amber: #C59A62;
        --sage: #405A4C;
        --charcoal: #EEF0EC;
        --muted: #B5BDB7;
        --line: #4B524D;
        --danger: #E1847C;
        --warning: #DFB16F;
        --success: #88C5A0;
        --focus-ring: #9AC9AE;
        --border: #4B524D;
        --ink-muted: #B5BDB7;
        --shadow: 0 10px 30px rgba(10, 13, 11, .22);
        --shadow-soft: 0 3px 14px rgba(10, 13, 11, .18);
    }

    html[data-theme="dark"] body {
        background: var(--canvas);
        color: var(--charcoal);
    }

    html[data-theme="dark"] ::selection {
        background: #537963;
        color: #FFFFFF;
    }

    html[data-theme="dark"] a {
        color: #9AC9AE;
    }

    html[data-theme="dark"] .muted,
    html[data-theme="dark"] small {
        color: var(--muted);
    }

    html[data-theme="dark"] .eyebrow {
        color: #A7D2B9;
    }

    html[data-theme="dark"] input,
    html[data-theme="dark"] select,
    html[data-theme="dark"] textarea {
        border-color: #59615B;
        background: #353A36;
        color: var(--charcoal);
    }

    html[data-theme="dark"] input::placeholder,
    html[data-theme="dark"] textarea::placeholder {
        color: #929B95;
        opacity: 1;
    }

    html[data-theme="dark"] input:focus,
    html[data-theme="dark"] select:focus,
    html[data-theme="dark"] textarea:focus {
        border-color: #83B89A;
        outline-color: rgba(131, 184, 154, .38);
    }

    html[data-theme="dark"] input:disabled,
    html[data-theme="dark"] select:disabled,
    html[data-theme="dark"] textarea:disabled,
    html[data-theme="dark"] input[readonly],
    html[data-theme="dark"] textarea[readonly] {
        background: #2B2F2C !important;
        color: #A7AFA9 !important;
    }

    html[data-theme="dark"] label {
        color: #D7DCD8;
    }

    html[data-theme="dark"] .sidebar {
        background: #20231F;
        color: #F5F5F0;
        border-right: 1px solid #3D433F;
    }

    html[data-theme="dark"] .app-brand,
    html[data-theme="dark"] .nav-link,
    html[data-theme="dark"] .account-links a {
        color: #E8ECE8;
    }

    html[data-theme="dark"] .app-brand small,
    html[data-theme="dark"] .nav-label,
    html[data-theme="dark"] .user-summary small {
        color: #AEBBB3;
    }

    html[data-theme="dark"] .nav-link:hover {
        background: rgba(131, 184, 154, .11);
    }

    html[data-theme="dark"] .nav-link.active {
        background: rgba(131, 184, 154, .17);
        color: #FFFFFF;
        box-shadow: none;
    }

    html[data-theme="dark"] .nav-link.active .nav-icon {
        color: #DDB27A;
    }

    html[data-theme="dark"] .sidebar-foot {
        border-top-color: #3D433F;
    }

    html[data-theme="dark"] .avatar {
        color: #201810;
    }

    html[data-theme="dark"] .theme-toggle {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 12px;
        width: 100%;
        min-height: 44px;
        margin: 0 0 14px;
        padding: 8px 2px;
        border: 0;
        border-bottom: 1px solid #3D433F;
        background: transparent;
        color: #E8ECE8;
        cursor: pointer;
        text-align: left;
    }

    html[data-theme="dark"] .theme-toggle:hover .theme-toggle-copy strong,
    html[data-theme="dark"] .theme-toggle:focus-visible .theme-toggle-copy strong {
        color: #FFFFFF;
    }

    .theme-toggle {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 12px;
        width: 100%;
        min-height: 44px;
        margin: 0 0 14px;
        padding: 8px 2px;
        border: 0;
        border-bottom: 1px solid rgba(255, 255, 255, .12);
        background: transparent;
        color: #FFFFFF;
        cursor: pointer;
        text-align: left;
    }

    .theme-toggle-copy {
        display: flex;
        align-items: center;
        gap: 9px;
        min-width: 0;
    }

    .theme-toggle-icon {
        width: 18px;
        height: 18px;
        flex: 0 0 auto;
    }

    .theme-toggle-copy strong,
    .theme-toggle-copy small {
        display: block;
        line-height: 1.2;
    }

    .theme-toggle-copy strong {
        font-size: .78rem;
    }

    .theme-toggle-copy small {
        margin-top: 2px;
        color: #BDD0C7;
        font-size: .66rem;
    }

    .theme-switch {
        position: relative;
        width: 38px;
        height: 22px;
        flex: 0 0 auto;
        border: 1px solid rgba(255, 255, 255, .24);
        border-radius: 999px;
        background: rgba(255, 255, 255, .15);
        transition: background-color .15s ease, border-color .15s ease;
    }

    .theme-switch::after {
        content: "";
        position: absolute;
        top: 3px;
        left: 3px;
        width: 14px;
        height: 14px;
        border-radius: 50%;
        background: #FFFFFF;
        box-shadow: 0 1px 4px rgba(0, 0, 0, .28);
        transition: transform .15s ease;
    }

    .theme-toggle[aria-pressed="true"] .theme-switch {
        border-color: #83B89A;
        background: #5F9276;
    }

    .theme-toggle[aria-pressed="true"] .theme-switch::after {
        transform: translateX(16px);
    }

    html[data-theme="dark"] .topbar {
        background: rgba(38, 41, 37, .94);
        border-bottom-color: var(--line);
    }

    html[data-theme="dark"] .branch-context select {
        border-color: #59615B;
        background: #353A36;
    }

    html[data-theme="dark"] .panel,
    html[data-theme="dark"] .stat-card,
    html[data-theme="dark"] .catalog-card,
    html[data-theme="dark"] .confirm-dialog,
    html[data-theme="dark"] .session-dialog {
        border-color: var(--line);
        background: var(--surface);
        color: var(--charcoal);
    }

    html[data-theme="dark"] .confirm-dialog::backdrop,
    html[data-theme="dark"] .session-dialog::backdrop,
    html[data-theme="dark"] .nav-backdrop {
        background: rgba(10, 13, 11, .7);
    }

    html[data-theme="dark"] .action-card,
    html[data-theme="dark"] .button-quiet {
        color: var(--charcoal);
    }

    html[data-theme="dark"] .action-card:hover,
    html[data-theme="dark"] .button-quiet:hover {
        border-color: #668573;
        background: #373D38;
    }

    html[data-theme="dark"] .button {
        border-color: #83B89A;
        background: #83B89A;
        color: #17231C;
    }

    html[data-theme="dark"] .button:hover {
        border-color: #9AC9AE;
        background: #9AC9AE;
        color: #111A15;
    }

    html[data-theme="dark"] .button-secondary {
        border-color: #668573;
        background: #343936;
        color: #B7DFC7;
    }

    html[data-theme="dark"] .button-secondary:hover {
        background: #3B423D;
    }

    html[data-theme="dark"] .button-danger {
        border-color: #B85E57;
        background: #B85E57;
        color: #FFFFFF;
    }

    html[data-theme="dark"] .button-warning {
        border-color: #B98749;
        background: #B98749;
        color: #1C1710;
    }

    html[data-theme="dark"] th,
    html[data-theme="dark"] td {
        border-bottom-color: #474D49;
    }

    html[data-theme="dark"] th {
        color: #B8C0BA;
    }

    html[data-theme="dark"] tbody tr:hover,
    html[data-theme="dark"] .page-shell .table-wrap .responsive-table tbody tr:hover {
        background: #373C38;
    }

    html[data-theme="dark"] .page-shell .table-wrap .responsive-table thead th {
        border-bottom-color: #59605B;
        background: #2B2F2C;
        color: #C1C8C3;
    }

    html[data-theme="dark"] .workspace-tabs,
    html[data-theme="dark"] .borrower-type-tabs,
    html[data-theme="dark"] .catalog-scope-switch,
    html[data-theme="dark"] .catalog-manage-tabs,
    html[data-theme="dark"] .catalog-editor-steps,
    html[data-theme="dark"] .history-status-tabs,
    html[data-theme="dark"] .labels-status-tabs,
    html[data-theme="dark"] .report-tabs,
    html[data-theme="dark"] .stocktake-filter-tabs,
    html[data-theme="dark"] .taxonomy-tabs,
    html[data-theme="dark"] .circulation-mode-switch {
        border-color: var(--line);
        background: #292D2A;
    }

    html[data-theme="dark"] :is(.workspace-tabs,.borrower-type-tabs,.catalog-scope-switch,.catalog-manage-tabs,.catalog-editor-steps,.history-status-tabs,.labels-status-tabs,.report-tabs,.stocktake-filter-tabs,.taxonomy-tabs,.circulation-mode-switch) a,
    html[data-theme="dark"] .circulation-mode {
        color: #BCC4BE;
    }

    html[data-theme="dark"] :is(.workspace-tabs,.borrower-type-tabs,.catalog-scope-switch,.catalog-manage-tabs,.catalog-editor-steps,.history-status-tabs,.labels-status-tabs,.report-tabs,.stocktake-filter-tabs,.taxonomy-tabs,.circulation-mode-switch) a:hover,
    html[data-theme="dark"] .circulation-mode:hover {
        background: #373C38;
    }

    html[data-theme="dark"] :is(.workspace-tabs,.borrower-type-tabs,.catalog-scope-switch,.catalog-manage-tabs,.catalog-editor-steps,.history-status-tabs,.labels-status-tabs,.report-tabs,.stocktake-filter-tabs,.taxonomy-tabs,.circulation-mode-switch) a.active,
    html[data-theme="dark"] .catalog-editor-steps a.is-current,
    html[data-theme="dark"] .circulation-mode.active {
        border-color: #5A655E;
        background: #3A403C;
        color: #F4F5F1;
    }

    html[data-theme="dark"] .status,
    html[data-theme="dark"] .tag,
    html[data-theme="dark"] .status-success,
    html[data-theme="dark"] .status.status-normal {
        border-color: #547261;
        background: #30443A;
        color: #A9D8BA;
    }

    html[data-theme="dark"] .status-danger,
    html[data-theme="dark"] .borrower-overdue-pill,
    html[data-theme="dark"] .catalog-archive-pill {
        border-color: #724943;
        background: #49322F;
        color: #F0AAA2;
    }

    html[data-theme="dark"] .status-warning {
        border-color: #6D5937;
        background: #443927;
        color: #EBC487;
    }

    html[data-theme="dark"] .status-info {
        border-color: #496776;
        background: #2E3E46;
        color: #A9D1E4;
    }

    html[data-theme="dark"] .status-muted,
    html[data-theme="dark"] .borrower-kind {
        border-color: #555C57;
        background: #393E3A;
        color: #C0C6C1;
    }

    html[data-theme="dark"] .alert-success {
        border-color: #557B66;
        background: #2E4438;
        color: #B7DEC5;
    }

    html[data-theme="dark"] .alert-error {
        border-color: #85534D;
        background: #4A312F;
        color: #F1B0A9;
    }

    html[data-theme="dark"] .alert-info {
        border-color: #4E6B62;
        background: #2D4039;
        color: #B9D7CA;
    }

    html[data-theme="dark"] .alert-warning {
        border-color: #7C663F;
        background: #463B29;
        color: #ECC98F;
    }

    html[data-theme="dark"] .auth-page {
        background: var(--canvas);
    }

    html[data-theme="dark"] .auth-identity {
        background: #293A32;
    }

    html[data-theme="dark"] .auth-brand {
        color: var(--charcoal);
    }

    html[data-theme="dark"] .school-logo {
        background: #F7F4EE;
    }

    html[data-theme="dark"] .book-cover,
    html[data-theme="dark"] .catalog-identity img {
        background: #3A403C;
    }

    html[data-theme="dark"] .inline-editor,
    html[data-theme="dark"] .policy-card,
    html[data-theme="dark"] .confirm-bar,
    html[data-theme="dark"] .optional-fields,
    html[data-theme="dark"] .detail-list > div,
    html[data-theme="dark"] .label-format-note,
    html[data-theme="dark"] .print-setup,
    html[data-theme="dark"] .catalog-identity,
    html[data-theme="dark"] .scanner-panel.is-disabled {
        border-color: var(--line);
        background: #2B2F2C;
    }

    html[data-theme="dark"] .taxonomy-scope {
        border-color: var(--line) !important;
        background: var(--surface) !important;
        color: var(--charcoal);
    }

    html[data-theme="dark"] .stat-grid.metrics-strip,
    html[data-theme="dark"] .metrics-strip .stat-card,
    html[data-theme="dark"] .circulation-step-card.is-compact-complete {
        border-color: var(--line);
        background: var(--surface) !important;
        color: var(--charcoal);
    }

    html[data-theme="dark"] .metrics-strip .stat-card[href]:hover,
    html[data-theme="dark"] .borrower-circulation-stat:hover,
    html[data-theme="dark"] .history-context-card > a:hover,
    html[data-theme="dark"] .admin-local-nav a:hover,
    html[data-theme="dark"] .quick-filters a:hover,
    html[data-theme="dark"] .stocktake-sound:hover,
    html[data-theme="dark"] .taxonomy-item:hover,
    html[data-theme="dark"] .notice-borrower-row:hover {
        background: #373C38 !important;
    }

    html[data-theme="dark"] .borrower-summary,
    html[data-theme="dark"] .circulation-borrower-card,
    html[data-theme="dark"] .taxonomy-inline-editor,
    html[data-theme="dark"] .catalog-local-isbn-card,
    html[data-theme="dark"] .history-context-card,
    html[data-theme="dark"] .catalog-record-scope-note,
    html[data-theme="dark"] .dashboard-actions .action-card.primary-work {
        border-color: #506258;
        background: #303B35;
        color: var(--charcoal);
    }

    html[data-theme="dark"] .borrower-info-grid,
    html[data-theme="dark"] .borrower-circulation-grid,
    html[data-theme="dark"] .directory-health-grid,
    html[data-theme="dark"] .manual-sync-options .check-row,
    html[data-theme="dark"] .connection-settings,
    html[data-theme="dark"] .import-summary,
    html[data-theme="dark"] .report-summary-item,
    html[data-theme="dark"] .stocktake-review-summary,
    html[data-theme="dark"] .label-preview,
    html[data-theme="dark"] .label-selection-bar,
    html[data-theme="dark"] .labels-sheet-details > summary,
    html[data-theme="dark"] .labels-sheet-popover,
    html[data-theme="dark"] .history-filter-drawer > summary,
    html[data-theme="dark"] .stocktake-more > summary,
    html[data-theme="dark"] .stocktake-more-panel,
    html[data-theme="dark"] .taxonomy-more > summary,
    html[data-theme="dark"] .taxonomy-menu,
    html[data-theme="dark"] .report-period-presets a,
    html[data-theme="dark"] .report-custom-dates > summary,
    html[data-theme="dark"] .report-custom-dates form,
    html[data-theme="dark"] .report-columns-menu,
    html[data-theme="dark"] .report-summary-strip,
    html[data-theme="dark"] .report-overview-metric,
    html[data-theme="dark"] .stocktake-summary-tabs a,
    html[data-theme="dark"] .stocktake-finalize-card .check-row,
    html[data-theme="dark"] .labels-selection-tools .button,
    html[data-theme="dark"] .circulation-sound-toggle,
    html[data-theme="dark"] .catalog-copy-summary,
    html[data-theme="dark"] .catalog-more-menu {
        border-color: var(--line);
        background: var(--surface);
        color: var(--charcoal);
    }

    html[data-theme="dark"] .quick-filters a.active,
    html[data-theme="dark"] .catalog-local-isbn-status,
    html[data-theme="dark"] .stocktake-scan-state,
    html[data-theme="dark"] .stocktake-start-steps b,
    html[data-theme="dark"] .stocktake-start-note > span:first-child,
    html[data-theme="dark"] .stocktake-review-button > span,
    html[data-theme="dark"] .stocktake-summary-tabs a strong,
    html[data-theme="dark"] .borrower-no-loans > span {
        background: #344A3E;
        color: #B2DCC2;
    }

    html[data-theme="dark"] .catalog-local-isbn-card.is-existing,
    html[data-theme="dark"] .catalog-local-isbn-card.is-shared {
        border-color: #526C5D;
        background: #303D36;
    }

    html[data-theme="dark"] .catalog-optional-marker,
    html[data-theme="dark"] #catalog-step-copies .catalog-copy-note,
    html[data-theme="dark"] .catalog-copy-summary-line span,
    html[data-theme="dark"] .labels-call-number,
    html[data-theme="dark"] .circulation-empty-icon,
    html[data-theme="dark"] .class-group-row td,
    html[data-theme="dark"] .taxonomy-page-arrow {
        border-color: #505852;
        background: #393E3A;
        color: #C2C8C3;
    }

    html[data-theme="dark"] .catalog-copy-summary-line .is-exception,
    html[data-theme="dark"] .stocktake-summary-tabs a.is-attention strong,
    html[data-theme="dark"] .stocktake-filter-tabs a.has-attention b {
        background: #503633;
        color: #F0AAA2;
    }

    html[data-theme="dark"] .labels-search-polished > .labels-select-page-toolbar {
        border-color: #59615B !important;
        background: var(--surface) !important;
        color: var(--charcoal);
    }

    html[data-theme="dark"] .labels-search-polished > .labels-select-page-toolbar:hover {
        border-color: #65766C !important;
        background: #373C38 !important;
    }

    html[data-theme="dark"] .labels-search-form .advanced-filters > summary {
        border-color: #59615B;
        background: var(--surface);
        color: var(--charcoal);
    }

    html[data-theme="dark"] .borrower-search-panel,
    html[data-theme="dark"] .catalog-manage-isbn,
    html[data-theme="dark"] .catalog-optional-block,
    html[data-theme="dark"] .catalog-heading-field,
    html[data-theme="dark"] .catalog-heading-empty,
    html[data-theme="dark"] .catalog-manage-add-copies,
    html[data-theme="dark"] .catalog-isbn-workbench,
    html[data-theme="dark"] .catalog-metadata-review,
    html[data-theme="dark"] .catalog-cover-thumb,
    html[data-theme="dark"] .catalog-local-copy-summary li,
    html[data-theme="dark"] .catalog-local-library-chip,
    html[data-theme="dark"] .catalog-search-panel,
    html[data-theme="dark"] .catalog-filter-state span,
    html[data-theme="dark"] .borrower-filter-state span,
    html[data-theme="dark"] .history-filter-grid,
    html[data-theme="dark"] .history-active-filters,
    html[data-theme="dark"] .history-filter-chip,
    html[data-theme="dark"] .labels-search-form .advanced-filters .filters,
    html[data-theme="dark"] .labels-search-polished > .labels-inline-filters,
    html[data-theme="dark"] .notice-filter-row,
    html[data-theme="dark"] .notice-selection-actions,
    html[data-theme="dark"] .report-result-head,
    html[data-theme="dark"] .stocktake-start-steps li,
    html[data-theme="dark"] .stocktake-start-form,
    html[data-theme="dark"] .stocktake-finalize,
    html[data-theme="dark"] .stocktake-finalize-card,
    html[data-theme="dark"] .taxonomy-filter-form,
    html[data-theme="dark"] .taxonomy-filter-state span,
    html[data-theme="dark"] .taxonomy-list-columns,
    html[data-theme="dark"] .taxonomy-merge-panel,
    html[data-theme="dark"] .client-empty-state,
    html[data-theme="dark"] .heading-options,
    html[data-theme="dark"] .circulation-step-card.is-locked,
    html[data-theme="dark"] .circulation-locked-message,
    html[data-theme="dark"] .circulation-confirm-dock,
    html[data-theme="dark"] .profile-verification,
    html[data-theme="dark"] .profile-account-note {
        border-color: var(--line) !important;
        background: #2B2F2C !important;
        color: var(--charcoal);
    }

    html[data-theme="dark"] .catalog-heading-create {
        border-color: #5C655F !important;
        background: #2B2F2C !important;
    }

    html[data-theme="dark"] .catalog-heading-create p {
        color: #B8C0BA !important;
    }

    html[data-theme="dark"] .heading-selected,
    html[data-theme="dark"] .batch-action-bar,
    html[data-theme="dark"] .sticky-form-actions,
    html[data-theme="dark"] .sticky-action-bar,
    html[data-theme="dark"] .catalog-editor-savebar,
    html[data-theme="dark"] .catalog-manage-savebar,
    html[data-theme="dark"] .labels-print-tray {
        border-color: #56605A;
        background: rgba(48, 52, 47, .97);
        color: var(--charcoal);
        box-shadow: 0 -8px 24px rgba(10, 13, 11, .18);
    }

    html[data-theme="dark"] .catalog-required-marker,
    html[data-theme="dark"] .catalog-step-index,
    html[data-theme="dark"] .catalog-manage-tabs a span,
    html[data-theme="dark"] .labels-status-count,
    html[data-theme="dark"] .taxonomy-tab-count,
    html[data-theme="dark"] .history-filter-count,
    html[data-theme="dark"] .history-status-tabs a span,
    html[data-theme="dark"] .stocktake-filter-tabs b,
    html[data-theme="dark"] .report-rank,
    html[data-theme="dark"] .circulation-mode-icon,
    html[data-theme="dark"] .circulation-step-number,
    html[data-theme="dark"] .circulation-step-state,
    html[data-theme="dark"] .circulation-queue-count,
    html[data-theme="dark"] .empty-workspace-inline .empty-symbol,
    html[data-theme="dark"] .compact-empty .empty-icon,
    html[data-theme="dark"] .borrower-detail-avatar,
    html[data-theme="dark"] .profile-avatar,
    html[data-theme="dark"] .profile-role {
        border-color: #526059;
        background: #39433D;
        color: #B8D9C5;
    }

    html[data-theme="dark"] .catalog-required-marker,
    html[data-theme="dark"] .catalog-edit-manager .catalog-required-marker {
        color: #F0AAA2 !important;
    }

    html[data-theme="dark"] .catalog-manage-savebar > span {
        color: #E8C185 !important;
    }

    html[data-theme="dark"] [data-lookup-status].is-success,
    html[data-theme="dark"] .catalog-editor-savebar > span.is-complete,
    html[data-theme="dark"] .catalog-metadata-kicker,
    html[data-theme="dark"] .catalog-local-isbn-kicker {
        color: #A9D8BA !important;
    }

    html[data-theme="dark"] .catalog-local-isbn-card.is-archived .catalog-local-isbn-kicker,
    html[data-theme="dark"] .catalog-availability.has-none strong,
    html[data-theme="dark"] .dashboard-balanced .dashboard-kpi-card.is-warning > strong,
    html[data-theme="dark"] .conflict-reason strong {
        color: #E7BE80 !important;
    }

    html[data-theme="dark"] .catalog-local-isbn-card .catalog-local-inline-error,
    html[data-theme="dark"] .catalog-record-options p,
    html[data-theme="dark"] .circulation-remove-button,
    html[data-theme="dark"] .circulation-clear-button {
        color: #ECA69F;
    }

    html[data-theme="dark"] .circulation-remove-button:hover,
    html[data-theme="dark"] .circulation-clear-button:hover {
        background: #49322F;
    }

    html[data-theme="dark"] .directory-sync-note {
        border-color: #557262;
        background: #30443A;
        color: #B7DEC5;
    }

    html[data-theme="dark"] .catalog-heading-chip,
    html[data-theme="dark"] .heading-chip,
    html[data-theme="dark"] .catalog-local-suggestion-chip,
    html[data-theme="dark"] .taxonomy-linked a,
    html[data-theme="dark"] .taxonomy-linked span {
        border-color: #526D5E;
        background: #31443A;
        color: #B5DCC4;
    }

    html[data-theme="dark"] .catalog-shared-confirm,
    html[data-theme="dark"] .catalog-record-scope-note.is-warning,
    html[data-theme="dark"] .catalog-local-isbn-card.is-archived,
    html[data-theme="dark"] .catalog-local-suggestion-chip.is-missing,
    html[data-theme="dark"] .circulation-inline-warning,
    html[data-theme="dark"] .scanner-local-status.is-warning,
    html[data-theme="dark"] .directory-conflict-panel {
        border-color: #735E3A;
        background: #433927;
        color: #E8C185;
    }

    html[data-theme="dark"] .borrower-table tbody tr.borrower-has-overdue,
    html[data-theme="dark"] .borrower-current-loans-table tbody tr.is-overdue,
    html[data-theme="dark"] .catalog-record-options > div,
    html[data-theme="dark"] .dashboard-kpi-card.is-alert,
    html[data-theme="dark"] .history-status-tabs a.active.has-exception,
    html[data-theme="dark"] .audit-table .audit-critical,
    html[data-theme="dark"] .import-stat.is-exception,
    html[data-theme="dark"] .report-summary-item.is-exception,
    html[data-theme="dark"] .stocktake-review-summary .review-summary-main.has-exceptions,
    html[data-theme="dark"] .report-summary-card.is-exception,
    html[data-theme="dark"] .report-overview-metric.is-exception,
    html[data-theme="dark"] .stocktake-summary-tabs a.is-attention,
    html[data-theme="dark"] .stocktake-filter-tabs a.active.has-attention,
    html[data-theme="dark"] .is-invalid,
    html[data-theme="dark"] .scanner-local-status.is-error {
        border-color: #774A45 !important;
        background: #49322F !important;
        color: #EFB0A9;
    }

    html[data-theme="dark"] .borrower-current-loans-table tbody tr.is-due-today {
        background: #403A2B;
    }

    html[data-theme="dark"] .dashboard-balanced .dashboard-kpi-card,
    html[data-theme="dark"] .dashboard-kpi-grid,
    html[data-theme="dark"] .dashboard-kpi-card,
    html[data-theme="dark"] .dashboard-actions .action-card.secondary-work,
    html[data-theme="dark"] .stocktake-progress > .stat-card {
        border-color: var(--line) !important;
        background: var(--surface) !important;
        color: var(--charcoal);
    }

    html[data-theme="dark"] .dashboard-balanced .dashboard-kpi-card:hover,
    html[data-theme="dark"] .dashboard-kpi-card:hover {
        border-color: #65766C !important;
        background: #393F3B !important;
    }

    html[data-theme="dark"] .dashboard-balanced .dashboard-kpi-card.is-alert,
    html[data-theme="dark"] .dashboard-kpi-card.is-alert {
        border-color: #674844 !important;
        background: #3B302E !important;
    }

    html[data-theme="dark"] .dashboard-kpi-label,
    html[data-theme="dark"] .dashboard-balanced .dashboard-kpi-label,
    html[data-theme="dark"] .dashboard-balanced .dashboard-intro time,
    html[data-theme="dark"] .dashboard-kpi-arrow {
        color: #B5BDB7;
    }

    html[data-theme="dark"] .dashboard-balanced .dashboard-kpi-icon {
        background: #35463D;
    }

    html[data-theme="dark"] .dashboard-balanced .dashboard-kpi-card.is-warning .dashboard-kpi-icon {
        background: #493D2B;
        color: #E4BA78;
    }

    html[data-theme="dark"] .dashboard-balanced .dashboard-kpi-card.is-alert .dashboard-kpi-icon,
    html[data-theme="dark"] .dashboard-balanced .dashboard-kpi-card.is-muted-alert .dashboard-kpi-icon {
        background: #493430;
    }

    html[data-theme="dark"] .catalog-editor-grid label,
    html[data-theme="dark"] .catalog-metadata-review-copy strong,
    html[data-theme="dark"] .catalog-local-isbn-title,
    html[data-theme="dark"] .catalog-local-copy-summary strong,
    html[data-theme="dark"] .catalog-local-classification h4,
    html[data-theme="dark"] .borrower-metrics strong,
    html[data-theme="dark"] .circulation-summary strong {
        color: var(--charcoal);
    }

    html[data-theme="dark"] .catalog-source-label,
    html[data-theme="dark"] .catalog-isbn-guidance,
    html[data-theme="dark"] [data-lookup-status],
    html[data-theme="dark"] .catalog-metadata-review-copy > span:not(.catalog-metadata-kicker),
    html[data-theme="dark"] .catalog-heading-selected-head,
    html[data-theme="dark"] .catalog-copy-summary-line,
    html[data-theme="dark"] .catalog-local-isbn-author,
    html[data-theme="dark"] .catalog-local-detail-grid small,
    html[data-theme="dark"] .catalog-local-isbn-note,
    html[data-theme="dark"] .catalog-local-classification > p,
    html[data-theme="dark"] .catalog-local-suggestion-label,
    html[data-theme="dark"] .borrower-search-row label,
    html[data-theme="dark"] .borrower-filter-grid label,
    html[data-theme="dark"] .catalog-search-row label,
    html[data-theme="dark"] .catalog-filter-bar label,
    html[data-theme="dark"] .report-custom-dates label,
    html[data-theme="dark"] .notice-filter-row label,
    html[data-theme="dark"] .taxonomy-filter-search,
    html[data-theme="dark"] .taxonomy-refine-row label,
    html[data-theme="dark"] .profile-security-rules li {
        color: #B8C0BA !important;
    }

    html[data-theme="dark"] .catalog-local-detail-grid span,
    html[data-theme="dark"] .heading-options .check-label,
    html[data-theme="dark"] .report-columns-menu label {
        color: #D9DEDA;
    }

    html[data-theme="dark"] .history-filter-drawer[open] > summary,
    html[data-theme="dark"] .labels-sheet-details[open] > summary,
    html[data-theme="dark"] .labels-search-form .advanced-filters[open] > summary,
    html[data-theme="dark"] .stocktake-more[open] > summary,
    html[data-theme="dark"] .taxonomy-more[open] > summary,
    html[data-theme="dark"] .report-custom-dates[open] > summary,
    html[data-theme="dark"] .catalog-heading-chip:hover,
    html[data-theme="dark"] .heading-options .check-label:hover,
    html[data-theme="dark"] .labels-selection-tools .button:hover,
    html[data-theme="dark"] .stocktake-summary-tabs a:hover,
    html[data-theme="dark"] .taxonomy-menu a:hover,
    html[data-theme="dark"] .taxonomy-menu button:hover,
    html[data-theme="dark"] .taxonomy-page-arrow:hover,
    html[data-theme="dark"] a.taxonomy-page-number:hover {
        border-color: #61756A !important;
        background: #38423C !important;
    }

    html[data-theme="dark"] .heading-options .check-label:has(input:checked),
    html[data-theme="dark"] .report-period-presets a.active,
    html[data-theme="dark"] .taxonomy-alphabet a.is-current,
    html[data-theme="dark"] .circulation-step-card.is-complete,
    html[data-theme="dark"] .circulation-confirm-dock.is-ready,
    html[data-theme="dark"] .scan-feedback-success,
    html[data-theme="dark"] .scanner-local-status.is-success {
        border-color: #5A806A !important;
        background: #30463A !important;
        color: #B3DEC2;
    }

    html[data-theme="dark"] .labels-table tbody tr.is-selected {
        background: #314039;
    }

    html[data-theme="dark"] .taxonomy-item.is-archived,
    html[data-theme="dark"] .circulation-step-card.is-locked {
        background: #2A2D2B !important;
    }

    html[data-theme="dark"] .history-timeline::before,
    html[data-theme="dark"] .stocktake-progress-track {
        background: #4B524D;
    }

    html[data-theme="dark"] .history-event::before {
        border-color: #40574B;
    }

    html[data-theme="dark"] .toast {
        border-color: #587967;
        background: #334239;
        color: #DCE9E1;
        box-shadow: 0 12px 34px rgba(8, 11, 9, .3);
    }

    html[data-theme="dark"] .page-progress {
        background: rgba(131, 184, 154, .18);
    }

    html[data-theme="dark"] .skip-link,
    html[data-theme="dark"] .mobile-menu {
        border-color: #668573;
        background: #343936;
        color: #D6EADC;
    }

    html[data-theme="dark"] .danger-disclosure > summary,
    html[data-theme="dark"] .danger-disclosure form {
        border-color: #744B46;
        background: #3D302E;
    }

    html[data-theme="dark"] .dataTables_wrapper,
    html[data-theme="dark"] .dt-container,
    html[data-theme="dark"] .dt-container .dt-info,
    html[data-theme="dark"] .dt-container .dt-length,
    html[data-theme="dark"] .dt-container .dt-search {
        color: var(--muted);
    }

    html[data-theme="dark"] .dt-container .dt-paging .dt-paging-button {
        border-color: transparent !important;
        color: #C8CEC9 !important;
    }

    html[data-theme="dark"] .dt-container .dt-paging .dt-paging-button:hover,
    html[data-theme="dark"] .dt-container .dt-paging .dt-paging-button.current {
        border-color: #5C6C63 !important;
        background: #3A403C !important;
        color: #FFFFFF !important;
    }

    html[data-theme="dark"] ::-webkit-calendar-picker-indicator {
        filter: invert(.82);
    }

    html[data-theme="dark"] * {
        scrollbar-color: #59625C #2A2D2B;
    }

    html[data-theme="dark"] .auth-brand-row .theme-toggle {
        width: 126px;
        margin: 0;
        padding: 7px 0;
        border-bottom-color: var(--line);
        color: var(--charcoal);
    }

    html[data-theme="dark"] .borrower-type-tabs a > span {
        background: #39433D;
        color: #B8D9C5;
    }


    /* Contrast fixes for operational controls and count badges. */
    html[data-theme="dark"] .loan-status-tabs {
        border-color: #59615B;
        background: #2B2F2C;
    }

    html[data-theme="dark"] .loan-status-tabs a {
        color: #D2D8D3;
    }

    html[data-theme="dark"] .loan-status-tabs a:hover {
        background: #373C38;
        color: #F2F4F1;
    }

    html[data-theme="dark"] .loan-status-tabs a.active {
        border-color: #68746D;
        background: #414843;
        color: #FFFFFF;
    }

    html[data-theme="dark"] .loan-status-count,
    html[data-theme="dark"] .history-status-tabs a span,
    html[data-theme="dark"] .labels-status-count,
    html[data-theme="dark"] .taxonomy-tab-count,
    html[data-theme="dark"] .find-type-tabs span,
    html[data-theme="dark"] .loans-filter-count,
    html[data-theme="dark"] .history-filter-count {
        background: #3A463F !important;
        color: #D3E7DB !important;
    }

    html[data-theme="dark"] .loan-status-tabs a.has-overdue .loan-status-count,
    html[data-theme="dark"] .history-status-tabs a.has-exception span {
        background: #563A36 !important;
        color: #F3B7AF !important;
    }

    html[data-theme="dark"] .loan-due-status {
        background: #35423A;
        color: #D9E9DF;
    }

    html[data-theme="dark"] .loan-due-status small {
        color: #B8C9BE;
    }

    html[data-theme="dark"] .loan-due-status.is-today {
        background: #4B402C;
        color: #F2D49A;
    }

    html[data-theme="dark"] .loan-due-status.is-today small {
        color: #DFC58F;
    }

    html[data-theme="dark"] .loan-due-status.is-overdue {
        background: #4C3431;
        color: #F2B0A8;
    }

    html[data-theme="dark"] .loan-due-status.is-overdue small {
        color: #E6A39B;
    }

    html[data-theme="dark"] .loans-filter-panel,
    html[data-theme="dark"] .history-filter-grid {
        border-color: var(--line);
        background: #2B2F2C;
    }

    html[data-theme="dark"] .loans-filter-form select,
    html[data-theme="dark"] .history-filter-grid input {
        background: #353A36;
        color: var(--charcoal);
    }

    html[data-theme="dark"] .loan-filter-chip,
    html[data-theme="dark"] .history-filter-chip {
        border-color: #56655C;
        background: #334139;
        color: #C9E0D2;
    }

    html[data-theme="dark"] .borrower-scope-note {
        border-color: #52635A;
        background: #2F3C35;
        color: #D3DDD7;
    }

    html[data-theme="dark"] .borrower-scope-note span:first-child {
        background: #405247;
        color: #CDE3D5;
    }

    html[data-theme="dark"] .taxonomy-tabs {
        background: transparent;
    }

    html[data-theme="dark"] .taxonomy-tabs a {
        border-color: var(--line);
        background: var(--surface);
        color: #C6CEC8;
    }

    html[data-theme="dark"] .taxonomy-tabs a.active {
        border-color: #64806F;
        background: #35453C;
        color: #E9F1EC;
    }

    html[data-theme="dark"] .taxonomy-tabs a.active strong,
    html[data-theme="dark"] .taxonomy-tabs a.active small {
        color: inherit;
    }

    html[data-theme="dark"] .find-scope label {
        border-color: var(--line);
        background: #30342F;
        color: #D7DCD8;
    }

    html[data-theme="dark"] .find-scope label:has(input:checked) {
        border-color: #64806F;
        background: #35453C;
        color: #E9F1EC;
    }

    html[data-theme="dark"] .catalog-detail-jump a.active,
    html[data-theme="dark"] .catalog-detail-jump a[aria-selected="true"] {
        border-color: #64806F;
        background: #35453C;
        color: #E9F1EC;
    }

    @media (prefers-reduced-motion: reduce) {
        .theme-switch,
        .theme-switch::after {
            transition: none;
        }
    }
}
