:root {
    color-scheme: light;
    --theme-page: #f4f6f8;
    --theme-surface: #ffffff;
    --theme-surface-muted: #f7fafc;
    --theme-surface-raised: #ffffff;
    --theme-text: #172033;
    --theme-text-strong: #10233f;
    --theme-text-muted: #627d98;
    --theme-border: #d9e2ec;
    --theme-border-strong: #bcccdc;
    --theme-hover: #eff6ff;
    --theme-input: #ffffff;
    --theme-shadow: rgba(16, 35, 63, .12);
    --card-motion-border: #93bde2;
    --card-motion-shadow: 0 16px 36px rgba(16, 35, 63, .13), 0 0 0 1px rgba(37, 99, 235, .08);
    --quick-bar-bg: #f7fbff;
    --quick-bar-border: #d5e3ef;
    --quick-label: #42617d;
    --quick-input-bg: #ffffff;
    --quick-input-border: #b9cee0;
    --quick-input-text: #102d4b;
    --quick-output: #668099;
    --quick-button-bg: #ffffff;
    --quick-button-border: #c7d8e7;
    --quick-button-text: #375774;
}

:root[data-theme="dark"] {
    color-scheme: dark;
    --theme-page: #08111f;
    --theme-surface: #111c2d;
    --theme-surface-muted: #0d1828;
    --theme-surface-raised: #162338;
    --theme-text: #dbe7f3;
    --theme-text-strong: #f1f6fb;
    --theme-text-muted: #9db0c4;
    --theme-border: #2b3b50;
    --theme-border-strong: #3b516a;
    --theme-hover: #172a43;
    --theme-input: #0c1727;
    --theme-shadow: rgba(0, 0, 0, .32);
    --card-motion-border: #466784;
    --card-motion-shadow: 0 18px 42px rgba(0, 0, 0, .38), 0 0 0 1px rgba(56, 189, 248, .13);
    --quick-bar-bg: #0d1929;
    --quick-bar-border: #2b4058;
    --quick-label: #a8bdd0;
    --quick-input-bg: #101d2f;
    --quick-input-border: #3b526b;
    --quick-input-text: #e5eef7;
    --quick-output: #91a7bb;
    --quick-button-bg: #16263a;
    --quick-button-border: #385069;
    --quick-button-text: #b8cadb;
}

/* Appearance controls */
.theme-picker {
    position: relative;
}

/* One restrained control group instead of four competing pills. */
.topbar-control-cluster {
    display: inline-flex;
    align-items: center;
    gap: 0;
    padding: 3px;
    border: 1px solid var(--theme-border);
    border-radius: 999px;
    background: color-mix(in srgb, var(--theme-surface-raised) 92%, transparent);
    box-shadow: 0 4px 14px var(--theme-shadow);
}

.topbar-control-cluster > :not(:first-child) {
    border-left: 1px solid var(--theme-border);
}

.topbar-control-cluster :is(.notification-trigger, .theme-toggle, .density-toggle, .topbar-user-toggle) {
    border: 0;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
}

.topbar-control-cluster .notification-trigger {
    width: 32px;
    height: 30px;
}

.topbar-control-cluster :is(.theme-toggle, .density-toggle) {
    min-height: 30px;
    padding: 5px 10px;
}

.topbar-control-cluster .topbar-user-toggle {
    width: auto;
    min-height: 30px;
    padding: 2px 4px 2px 8px;
}

.topbar-control-cluster .topbar-user-summary { display: none; }
.topbar-control-cluster .avatar { width: 26px; height: 26px; }

.topbar-control-cluster :is(.notification-trigger, .theme-toggle, .density-toggle, .topbar-user-toggle):hover,
.topbar-control-cluster .topbar-user-menu[open] .topbar-user-toggle,
.topbar-control-cluster .notification-center[open] .notification-trigger {
    background: var(--theme-hover);
    box-shadow: none;
}

.theme-toggle,
.login-theme-switch {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    border: 1px solid var(--theme-border);
    background: var(--theme-surface-muted);
    color: var(--theme-text-muted);
    cursor: pointer;
    transition: border-color .15s ease, background-color .15s ease, color .15s ease;
}

.theme-toggle {
    padding: 6px 9px;
    border-radius: 999px;
    font-size: .62rem;
}

.theme-toggle strong,
.login-theme-switch strong {
    color: var(--theme-text-strong);
    line-height: 1;
}

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

.theme-toggle:hover,
.login-theme-switch:hover {
    border-color: #38bdf8;
    background: var(--theme-hover);
}

.theme-icon {
    display: grid;
    place-items: center;
    width: 15px;
    height: 15px;
    border-radius: 999px;
    background: #dff4ff;
    color: #075985;
    font-size: .72rem;
}

:root[data-theme="dark"] .theme-icon {
    background: #24334b;
    color: #fde68a;
}

.theme-chevron {
    color: var(--theme-text-muted);
    font-size: .85rem;
    line-height: 1;
}

.theme-menu {
    position: absolute;
    z-index: 70;
    top: calc(100% + 7px);
    right: 0;
    display: grid;
    width: 240px;
    padding: 5px;
    border: 1px solid var(--theme-border);
    border-radius: 10px;
    background: var(--theme-surface-raised);
    box-shadow: 0 12px 30px var(--theme-shadow);
}

.theme-menu[hidden] { display: none; }

.theme-menu button {
    display: grid;
    grid-template-columns: 21px 1fr;
    align-items: center;
    gap: 1px 7px;
    padding: 8px 9px;
    border: 0;
    border-radius: 7px;
    background: transparent;
    color: var(--theme-text);
    text-align: left;
    cursor: pointer;
}

.theme-menu button > span {
    grid-row: 1 / span 2;
    color: var(--theme-text-muted);
    font-size: 1rem;
}

.theme-menu button strong { color: var(--theme-text-strong); font-size: .76rem; }
.theme-menu button small { color: var(--theme-text-muted); font-size: .67rem; }
.theme-menu button:hover,
.theme-menu button.active { background: var(--theme-hover); }
.theme-menu button.active > span { color: #38bdf8; }

.login-theme-switch {
    position: fixed;
    z-index: 20;
    top: 22px;
    right: 24px;
    min-height: 36px;
    padding: 8px 12px;
    border-color: rgba(125, 211, 252, .3);
    border-radius: 999px;
    background: rgba(5, 18, 29, .78);
    color: #a9c1d2;
    box-shadow: 0 8px 24px rgba(0, 0, 0, .18);
    backdrop-filter: blur(14px);
}

.login-theme-switch strong { color: #edf8ff; font-size: .72rem; }
.login-theme-switch > span { color: #fde68a; font-size: .95rem; }

/* Light login */
:root[data-theme="light"] body {
    background: #eaf1f7;
}

:root[data-theme="light"] .login-shell {
    background:
        radial-gradient(circle at 18% 8%, rgba(14, 165, 233, .13), transparent 34%),
        radial-gradient(circle at 88% 88%, rgba(37, 99, 235, .12), transparent 38%),
        linear-gradient(145deg, #edf5fb 0%, #f8fbfd 52%, #e5eef6 100%);
}

:root[data-theme="light"] .login-grid {
    opacity: .22;
    background-image:
        linear-gradient(rgba(14, 116, 144, .13) 1px, transparent 1px),
        linear-gradient(90deg, rgba(14, 116, 144, .13) 1px, transparent 1px);
}

:root[data-theme="light"] .login-experience {
    border-color: rgba(30, 108, 154, .18) !important;
    background: rgba(255, 255, 255, .92) !important;
    box-shadow: 0 30px 90px rgba(43, 70, 94, .2), 0 0 0 1px rgba(255, 255, 255, .8) inset !important;
}

:root[data-theme="light"] .login-layout-content .login-card {
    background: rgba(255, 255, 255, .94) !important;
}

:root[data-theme="light"] .login-card .login-heading h1 { color: #10233f; }
:root[data-theme="light"] .login-card .login-heading p { color: #627d98; }
:root[data-theme="light"] .login-eyebrow { color: #087ea4; }
:root[data-theme="light"] .login-card .login-form label { color: #344d68; }

:root[data-theme="light"] .login-card .login-field input {
    border-color: #c6d6e6;
    background: #f8fbfd;
    color: #102a43;
    box-shadow: 0 1px 2px rgba(16, 35, 63, .04);
}

:root[data-theme="light"] .login-card .login-field input::placeholder { color: #829ab1; }
:root[data-theme="light"] .login-card .login-field input:hover { border-color: #7ebbd2; background: #ffffff; }
:root[data-theme="light"] .login-card .login-field input:focus { border-color: #0891b2; background: #ffffff; box-shadow: 0 0 0 3px rgba(8, 145, 178, .12); }
:root[data-theme="light"] .login-field svg { stroke: #607d96; }
:root[data-theme="light"] .login-footer { border-top-color: #e1e9f0; color: #71869c; }
:root[data-theme="light"] .login-secondary-link { color: #1f6c98 !important; }

:root[data-theme="light"] .login-theme-switch {
    border-color: rgba(37, 99, 235, .2);
    background: rgba(255, 255, 255, .82);
    color: #60758c;
    box-shadow: 0 8px 24px rgba(43, 70, 94, .12);
}

:root[data-theme="light"] .login-theme-switch strong { color: #173454; }
:root[data-theme="light"] .login-theme-switch > span { color: #d97706; }

/* The light theme intentionally keeps a navy navigation rail for orientation. */
:root[data-theme="light"] .app-sidebar {
    border-right: 1px solid rgba(125, 211, 252, .12);
    background: #133150;
    box-shadow: 10px 0 28px rgba(16, 35, 63, .08);
}

:root[data-theme="light"] .app-sidebar .main-nav a:hover,
:root[data-theme="light"] .app-sidebar .main-nav a.active {
    background: #2b5374;
}

/* Dark application shell */
:root[data-theme="dark"] body {
    background: #08111f;
}

:root[data-theme="dark"] .app-shell {
    background: var(--theme-page);
    color: var(--theme-text);
}

:root[data-theme="dark"] .topbar {
    border-bottom-color: var(--theme-border);
    background: #0d1828;
}

:root[data-theme="dark"] .topbar h1,
:root[data-theme="dark"] .topbar-user-toggle strong,
:root[data-theme="dark"] .topbar-user-company strong,
:root[data-theme="dark"] .topbar-user-meta strong {
    color: var(--theme-text-strong);
}

:root[data-theme="dark"] .topbar .eyebrow,
:root[data-theme="dark"] .topbar-user-toggle small,
:root[data-theme="dark"] .topbar-user-company small,
:root[data-theme="dark"] .topbar-user-meta small {
    color: var(--theme-text-muted);
}

:root[data-theme="dark"] :is(.topbar-user-toggle, .topbar-user-panel, .density-toggle, .density-menu, .logout-button) {
    border-color: var(--theme-border);
    background: var(--theme-surface-raised);
    color: var(--theme-text);
}

:root[data-theme="dark"] .topbar-control-cluster {
    border-color: #2b3d55;
    background: rgba(17, 29, 47, .88);
}

:root[data-theme="dark"] .topbar-control-cluster > :not(:first-child) { border-left-color: #2b3d55; }

:root[data-theme="dark"] :is(.notification-panel, .topbar-user-panel) {
    border-color: var(--theme-border);
    background: var(--theme-surface-raised);
    color: var(--theme-text);
    box-shadow: 0 18px 45px rgba(0, 0, 0, .38);
}

:root[data-theme="dark"] .notification-panel > header,
:root[data-theme="dark"] .notification-panel > footer {
    border-color: var(--theme-border);
    background: var(--theme-surface-muted);
    color: var(--theme-text-muted);
}

:root[data-theme="dark"] .notification-panel > header strong,
:root[data-theme="dark"] .notification-item strong,
:root[data-theme="dark"] .notification-empty strong { color: var(--theme-text-strong); }
:root[data-theme="dark"] .notification-panel :is(header span, header small, .notification-item small, .notification-empty small) { color: var(--theme-text-muted); }
:root[data-theme="dark"] .notification-item { border-color: var(--theme-border); color: var(--theme-text); }
:root[data-theme="dark"] .notification-item:hover { background: var(--theme-hover); }
:root[data-theme="dark"] .notification-item-actions :is(a, button) {
    border-color: var(--theme-border-strong);
    background: var(--theme-surface-muted);
    color: #7fc8ff;
}
:root[data-theme="dark"] .notification-item-actions :is(a, button):hover {
    border-color: #4a86bd;
    background: var(--theme-hover);
    color: #b7e3ff;
}
:root[data-theme="dark"] .notification-count { border-color: var(--theme-surface-raised); }

:root[data-theme="dark"] .density-toggle strong,
:root[data-theme="dark"] .density-menu button,
:root[data-theme="dark"] .density-menu button strong {
    color: var(--theme-text-strong);
}

:root[data-theme="dark"] .density-menu button small,
:root[data-theme="dark"] .density-chevron { color: var(--theme-text-muted); }
:root[data-theme="dark"] .density-menu button:hover,
:root[data-theme="dark"] .density-menu button.active { background: var(--theme-hover); }

:root[data-theme="dark"] .topbar-company-logo {
    border-color: transparent;
    background: transparent;
}

:root[data-theme="dark"] .page-content {
    color: var(--theme-text);
}

:root[data-theme="dark"] .page-content :is(h1, h2, h3, h4),
:root[data-theme="dark"] :is(.page-heading h1, .page-heading h2, .section-title h2, .section-heading h2, .section-heading h3, .card-header h3) {
    color: var(--theme-text-strong);
}

:root[data-theme="dark"] :is(.page-heading p:not(.eyebrow), .section-title p, .section-heading p, .card-header p, .result-count, .field label, .check-field, .cash-modal-copy) {
    color: var(--theme-text-muted);
}

:root[data-theme="dark"] .page-content :is(input:not([type="checkbox"]):not([type="radio"]), select, textarea),
:root[data-theme="dark"] :is(.modal-card, .help-modal, .catalog-modal, .client-editor, .cash-modal) :is(input:not([type="checkbox"]):not([type="radio"]), select, textarea) {
    border-color: var(--theme-border-strong);
    background: var(--theme-input);
    color: var(--theme-text);
}

:root[data-theme="dark"] .page-content :is(input, textarea)::placeholder { color: #71869c; }
:root[data-theme="dark"] .page-content option { background: var(--theme-input); color: var(--theme-text); }

:root[data-theme="dark"] :is(
    .filter-card,
    .table-card,
    .dashboard-card,
    .metric-card,
    .history-summary-card,
    .inventory-kpi,
    .financial-card,
    .sales-chart-panel,
    .sales-intelligence,
    .route-message,
    .budget-vehicle-panel,
    .budget-lines,
    .budget-total,
    .purchase-card,
    .purchase-history,
    .agenda-editor,
    .agenda-list,
    .agenda-month,
    .agenda-week,
    .company-config-card,
    .config-section-card,
    .config-savebar,
    .role-card,
    .role-editor-card,
    .permission-editor,
    .product-history-card,
    .inventory-view-card,
    .detail-card,
    .client-history-card,
    .client-history-modal,
    .history-detail-modal,
    .modal-card,
    .help-modal,
    .catalog-modal,
    .client-editor,
    .cash-modal,
    .delete-confirm-modal,
    .finance-confirm-modal,
    .invoice-result-modal,
    .quick-sale-modal,
    .sii-certification-card,
    .sii-stage-editor,
    .sii-prevalidation-panel,
    .sii-inbox-panel,
    .sii-evidence-library,
    .supervision-toolbar,
    .diagnostic-section,
    .diagnostic-modal,
    .print-agent-modal
) {
    border-color: var(--theme-border);
    background: var(--theme-surface);
    color: var(--theme-text);
    box-shadow: 0 5px 18px var(--theme-shadow);
}

:root[data-theme="dark"] :is(.metric-card, .history-summary-card).summary-total {
    background: linear-gradient(135deg, var(--theme-surface), #292315);
}

:root[data-theme="dark"] :is(.table-toolbar, .section-title, .card-header, .modal-header, .catalog-modal-header, .cash-modal-header) {
    border-color: var(--theme-border);
    color: var(--theme-text-strong);
}

:root[data-theme="dark"] .data-table th {
    border-color: var(--theme-border);
    background: var(--theme-surface-muted);
    color: #a9bdd0;
}

:root[data-theme="dark"] .data-table td {
    border-color: var(--theme-border);
    color: var(--theme-text);
}

:root[data-theme="dark"] .data-table tr:hover td { background: var(--theme-hover); }
:root[data-theme="dark"] .data-table td small { color: var(--theme-text-muted); }
:root[data-theme="dark"] .data-table .price { color: var(--theme-text-strong); }

:root[data-theme="dark"] :is(.table-paginator, .table-toolbar, .cash-close-summary, .budget-total, .pos-summary, .client-history-summary) {
    border-color: var(--theme-border);
    background: var(--theme-surface-muted);
    color: var(--theme-text-muted);
}

:root[data-theme="dark"] :is(.table-paginator button, .table-paginator select, .row-button, .icon-button, .modal-close, .modal-close-button) {
    border-color: var(--theme-border-strong);
    background: var(--theme-surface-raised);
    color: #7dd3fc;
}

:root[data-theme="dark"] :is(
    .metric-card span,
    .metric-card small,
    .history-summary-card span,
    .history-summary-card small,
    .dashboard-card p,
    .product-meta,
    .field-hint,
    .form-field-feedback,
    .muted
) { color: var(--theme-text-muted); }

:root[data-theme="dark"] :is(
    .metric-card strong,
    .history-summary-card strong,
    .dashboard-card h3,
    .budget-total strong,
    .cash-close-summary strong,
    .sales-chart-heading strong,
    .active-company-chip
) { color: var(--theme-text-strong); }

:root[data-theme="dark"] .status-row {
    border-bottom-color: var(--theme-border);
    color: var(--theme-text);
}

:root[data-theme="dark"] .status-row b { color: var(--theme-text-strong); }
:root[data-theme="dark"] .flow-line { color: var(--theme-text); }
:root[data-theme="dark"] .flow-line i { background: #3b516a; }
:root[data-theme="dark"] .flow-line a { color: #d8b4fe; }
:root[data-theme="dark"] .card-header a { color: #60a5fa; }

:root[data-theme="dark"] .finance-tabs {
    border-color: var(--theme-border);
    background: var(--theme-surface-muted);
    box-shadow: 0 5px 18px var(--theme-shadow);
}

:root[data-theme="dark"] .finance-tabs button {
    background: transparent;
    color: var(--theme-text-muted);
}

:root[data-theme="dark"] .finance-tabs button:hover {
    background: var(--theme-hover);
    color: var(--theme-text);
}

:root[data-theme="dark"] .finance-tabs button.active {
    background: #173454;
    color: #bfdbfe;
    box-shadow: inset 0 0 0 1px #315475, 0 3px 10px var(--theme-shadow);
}

:root[data-theme="dark"] :is(.agenda-day, .agenda-month-day, .board-column, .board-card, .sale-card, .sale-line, .checkout-list-row, .product-result, .customer-row, .payment-row, .client-contact-row, .client-data-row) {
    border-color: var(--theme-border);
    background: var(--theme-surface-muted);
    color: var(--theme-text);
}

:root[data-theme="dark"] :is(.agenda-day:hover, .agenda-month-day:hover, .board-card:hover, .product-result:hover, .customer-row:hover) {
    background: var(--theme-hover);
}

:root[data-theme="dark"] .agenda-day strong,
:root[data-theme="dark"] .agenda-month-day span,
:root[data-theme="dark"] .agenda-event strong {
    color: var(--theme-text-strong);
}

:root[data-theme="dark"] .agenda-day.today {
    border-color: #3b82f6;
    background: #162943;
}

:root[data-theme="dark"] .agenda-event {
    border-bottom-color: var(--theme-border);
    color: var(--theme-text);
}

:root[data-theme="dark"] .agenda-event-service { background: #111f33; }
:root[data-theme="dark"] .agenda-event-reminder { background: #2a2416; }
:root[data-theme="dark"] .agenda-event small,
:root[data-theme="dark"] .agenda-legend { color: var(--theme-text-muted); }
:root[data-theme="dark"] .agenda-actions select {
    border-color: var(--theme-border-strong);
    background: var(--theme-input);
    color: var(--theme-text);
}

:root[data-theme="dark"] .agenda-client-field > label,
:root[data-theme="dark"] .agenda-client-hint { color: var(--theme-text-muted); }
:root[data-theme="dark"] .agenda-client-status { color: #86efac; }
:root[data-theme="dark"] .agenda-client-search {
    border-color: var(--theme-border);
    background: var(--theme-surface-muted);
}

:root[data-theme="dark"] .agenda-client-results button {
    border-color: var(--theme-border);
    background: var(--theme-surface-raised);
    color: var(--theme-text);
}

:root[data-theme="dark"] .agenda-client-results button:hover {
    border-color: #4f78a1;
    background: var(--theme-hover);
}

:root[data-theme="dark"] .agenda-client-results button small,
:root[data-theme="dark"] .agenda-client-results > span { color: var(--theme-text-muted); }

:root[data-theme="dark"] :is(.config-tabs, .agenda-tabs, .history-tabs, .mail-config-tabs, .sii-module-tabs) {
    border-color: var(--theme-border);
    background: var(--theme-surface-muted);
}

:root[data-theme="dark"] :is(.config-tab, .agenda-view-button, .diagnostic-tab, .emit-tab) {
    border-color: transparent;
    background: transparent;
    color: var(--theme-text-muted);
}

:root[data-theme="dark"] :is(.config-tab.active, .agenda-view-button.active, .diagnostic-tab.active, .emit-tab.active) {
    border-color: var(--theme-border);
    background: var(--theme-surface-raised);
    color: #7dd3fc;
}

:root[data-theme="dark"] :is(.notice, .payment-waiting, .sii-exchange-panel, .sii-format-box, .help-modal-note) {
    border-color: #31577c;
    background: #102844;
    color: #bfdbfe;
}

/* Configuracion de empresa: Empresa, Cajas/POS, SII y Correo. */
:root[data-theme="dark"] .company-config-card .budget-form {
    border-color: var(--theme-border);
    background: linear-gradient(135deg, var(--theme-surface-muted), var(--theme-surface));
}

:root[data-theme="dark"] :is(
    .company-config-card .section-title h2,
    .config-section-card h2,
    .config-section-card h3,
    .config-savebar strong,
    .pos-summary b,
    .pos-machine-chip b,
    .pos-grid-row strong,
    .sale-checkout-current strong,
    .uploaded-file-chip strong,
    .imap-mailbox-main strong,
    .imap-editor h3
) { color: var(--theme-text-strong); }

:root[data-theme="dark"] :is(
    .company-config-card .section-title p,
    .company-config-card .budget-form label,
    .company-logo-label,
    .company-logo-actions,
    .company-logo-actions small,
    .config-section-card p:not(.eyebrow),
    .config-section-card .config-status,
    .config-section-card .config-field-help,
    .config-pos-form label,
    .config-upload-grid label,
    .checkout-editor-grid > label,
    .checkout-editor-grid legend,
    .checkout-editor-grid fieldset label,
    .checkout-switches label,
    .checkout-list-row,
    .checkout-list-row small,
    .pos-machines-list,
    .pos-machine-chip small,
    .pos-summary,
    .pos-grid-header,
    .pos-grid-row,
    .pos-empty-state,
    .sale-checkout-current,
    .uploaded-file-chip small,
    .imap-mailbox-main span,
    .imap-mailbox-main small
) { color: var(--theme-text-muted); }

:root[data-theme="dark"] .company-logo-control {
    border-color: var(--theme-border-strong);
    background: var(--theme-surface-muted);
}

:root[data-theme="dark"] :is(.company-logo-preview, .company-logo-placeholder) {
    border-color: var(--theme-border);
    background: var(--theme-input);
}

:root[data-theme="dark"] :is(
    .config-checklist .config-status,
    .config-inline-options,
    .pos-machine-chip,
    .pos-summary,
    .pos-machines-grid,
    .pos-empty-state,
    .checkout-editor-grid fieldset,
    .checkout-switches,
    .checkout-list,
    .checkout-list-row,
    .sale-checkout-current,
    .uploaded-file-chip,
    .imap-mailbox-row,
    .imap-editor,
    .imap-empty
) {
    border-color: var(--theme-border);
    background: var(--theme-surface-muted);
}

:root[data-theme="dark"] :is(.config-pos-form, .config-upload-grid, .checkout-editor-grid) input::file-selector-button,
:root[data-theme="dark"] .company-logo-actions input::file-selector-button {
    margin-right: .65rem;
    padding: .38rem .62rem;
    border: 1px solid var(--theme-border-strong);
    border-radius: 6px;
    background: var(--theme-surface-raised);
    color: var(--theme-text);
    cursor: pointer;
}

:root[data-theme="dark"] .config-inline-options { color: var(--theme-text); }

:root[data-theme="dark"] .config-example {
    border-left-color: #f59e0b;
    background: #302713;
    color: #fde68a;
}

:root[data-theme="dark"] .pos-grid-header {
    background: var(--theme-surface-raised);
}

:root[data-theme="dark"] :is(.pos-grid-row, .checkout-list-row) {
    border-top-color: var(--theme-border);
}

:root[data-theme="dark"] .pos-enabled { color: #86efac; }
:root[data-theme="dark"] .pos-disabled { color: #fda4af; }

:root[data-theme="dark"] .field-help-button {
    border-color: var(--theme-border-strong);
    background: var(--theme-surface-raised);
    color: #7dd3fc;
}

:root[data-theme="dark"] .field-help-button:hover { background: var(--theme-hover); }

:root[data-theme="dark"] .uploaded-file-chip {
    box-shadow: 0 4px 12px var(--theme-shadow);
}

:root[data-theme="dark"] .file-icon {
    background: #173454;
    color: #93c5fd;
}

:root[data-theme="dark"] .certificate-chip .file-icon {
    background: #302044;
    color: #d8b4fe;
}

:root[data-theme="dark"] .certification-set-chip .file-icon {
    background: #173d2e;
    color: #86efac;
}

:root[data-theme="dark"] .file-remove {
    border: 1px solid #63343b;
    background: #3a1c24;
    color: #fca5a5;
}

:root[data-theme="dark"] .imap-mailbox-row { border-left-color: #4ade80; }
:root[data-theme="dark"] .imap-mailbox-row.disabled { border-left-color: #64748b; }
:root[data-theme="dark"] .imap-mailbox-state { background: #173d2e; color: #86efac; }
:root[data-theme="dark"] .imap-mailbox-row.disabled .imap-mailbox-state { background: #243244; color: #b8cadb; }

/* El inventario CAF es compartido, pero debe heredar el tema de la pagina. */
:root[data-theme="dark"] .caf-monitor {
    border-color: var(--theme-border);
    background: var(--theme-surface);
    color: var(--theme-text);
    box-shadow: 0 5px 18px var(--theme-shadow);
}

:root[data-theme="dark"] .caf-monitor-header h2,
:root[data-theme="dark"] .caf-card h3,
:root[data-theme="dark"] .caf-card dd,
:root[data-theme="dark"] .caf-steps-title strong { color: var(--theme-text-strong); }

:root[data-theme="dark"] :is(
    .caf-monitor-header p,
    .caf-card-title,
    .caf-available small,
    .caf-card dt,
    .caf-loading
) { color: var(--theme-text-muted); }

:root[data-theme="dark"] .caf-refresh {
    border-color: var(--theme-border-strong);
    background: var(--theme-surface-raised);
    color: #93c5fd;
}

:root[data-theme="dark"] .caf-refresh:hover { background: var(--theme-hover); }

:root[data-theme="dark"] .caf-environment-strip.test {
    border-color: #684a89;
    background: #241c33;
    color: #d8b4fe;
}

:root[data-theme="dark"] .caf-environment-strip.test > b { background: #392650; }

:root[data-theme="dark"] .caf-environment-strip.production {
    border-color: #347454;
    background: #13271f;
    color: #86efac;
}

:root[data-theme="dark"] .caf-environment-strip.production > b { background: #173d2e; }

:root[data-theme="dark"] .caf-alert.normal {
    border-color: #4ade80;
    background: #13271f;
    color: #86efac;
}

:root[data-theme="dark"] .caf-alert.warning {
    border-color: #f59e0b;
    background: #302713;
    color: #fde68a;
}

:root[data-theme="dark"] .caf-alert.critical {
    border-color: #ef4444;
    background: #2b171d;
    color: #fca5a5;
}

:root[data-theme="dark"] .caf-card {
    border-color: var(--theme-border);
    background: var(--theme-surface-muted);
    box-shadow: 0 5px 16px var(--theme-shadow);
}

:root[data-theme="dark"] .caf-card-title em.test { background: #392650; color: #d8b4fe; }
:root[data-theme="dark"] .caf-card-title em.production { background: #173d2e; color: #86efac; }
:root[data-theme="dark"] .caf-card.normal .caf-available { background: #173d2e; color: #86efac; }
:root[data-theme="dark"] .caf-card.warning .caf-available { background: #302713; color: #fde68a; }
:root[data-theme="dark"] .caf-card.critical .caf-available { background: #3a1c24; color: #fca5a5; }

:root[data-theme="dark"] .caf-card dl {
    border-color: var(--theme-border);
    background: var(--theme-surface);
}

:root[data-theme="dark"] .caf-card dl div { border-top-color: var(--theme-border); }

:root[data-theme="dark"] .caf-steps {
    border-color: var(--theme-border);
    background: var(--theme-surface-muted);
    color: var(--theme-text);
}

:root[data-theme="dark"] .caf-steps-title button { color: var(--theme-text-muted); }

:root[data-theme="dark"] :is(.notice-success, .form-field-valid, .sii-production-approved, .sii-approval-confirm) {
    border-color: #266047;
    background: #102b23 !important;
    color: #86efac;
}

:root[data-theme="dark"] :is(.notice-error, .error-banner, .form-field-invalid, .sii-help-warning) {
    border-color: #6f3540;
    background: #321820 !important;
    color: #fda4af;
}

:root[data-theme="dark"] :is(.import-warning, .manual-payment-warning, .sii-print-panel) {
    border-color: #745b27;
    background: #302713;
    color: #fde68a;
}

:root[data-theme="dark"] :is(.modal-backdrop, .catalog-modal-backdrop, .client-history-backdrop, .cash-modal-backdrop, .finance-confirm-backdrop, .inventory-detail-backdrop, .print-agent-modal-backdrop) {
    background: rgba(1, 6, 13, .78);
}

:root[data-theme="dark"] :is(.sii-stage, .sii-readiness-grid > div, .sii-exchange-files article, .sii-file-map > div, .sii-validation-checks article, .sii-history-item, .sii-pdf-item, .sii-evidence-column) {
    border-color: var(--theme-border);
    background: var(--theme-surface-muted);
    color: var(--theme-text);
}

:root[data-theme="dark"] :is(.sii-stage strong, .sii-readiness-grid strong, .sii-file-map strong, .sii-validation-checks strong, .sii-evidence-column-title) {
    color: var(--theme-text-strong);
}

:root[data-theme="dark"] :is(.sii-stage small, .sii-readiness-grid span, .sii-file-map small, .sii-validation-checks small, .sii-history-item small, .sii-pdf-item small) {
    color: var(--theme-text-muted);
}

:root[data-theme="dark"] .sii-readiness-card {
    border-color: #6f3540;
    background: linear-gradient(135deg, var(--theme-surface), #2d171d);
}

:root[data-theme="dark"] .sii-readiness-card.verde {
    border-color: #266047;
    background: linear-gradient(135deg, var(--theme-surface), #102b23);
}

:root[data-theme="dark"] .sii-readiness-card.amarillo {
    border-color: #745b27;
    background: linear-gradient(135deg, var(--theme-surface), #302713);
}

/* Sales workspace: complete dark surfaces instead of mixed light fragments. */
:root[data-theme="dark"] .cash-banner {
    border-color: var(--theme-border);
    background: var(--theme-surface);
    color: var(--theme-text);
    box-shadow: 0 5px 18px var(--theme-shadow);
}

:root[data-theme="dark"] .cash-banner strong { color: var(--theme-text-strong); }
:root[data-theme="dark"] .cash-banner small { color: var(--theme-text-muted); }
:root[data-theme="dark"] .cash-banner .badge.warning { background: #302713; color: #fde68a; }

:root[data-theme="dark"] :is(.product-picker, .sale-card) {
    border-color: var(--theme-border);
    background: var(--theme-surface);
}

:root[data-theme="dark"] :is(.product-picker, .sale-card) .section-title,
:root[data-theme="dark"] .scan-row {
    border-color: var(--theme-border);
}

:root[data-theme="dark"] .sale-card .sale-header {
    background: linear-gradient(180deg, var(--theme-surface), var(--theme-surface-muted));
}

:root[data-theme="dark"] .sale-tools { border-color: var(--theme-border); }
:root[data-theme="dark"] .sale-options-toggle { border-color: var(--theme-border-strong); background: var(--theme-surface-raised); color: var(--theme-text); }
:root[data-theme="dark"] .sale-options-toggle:hover { background: var(--theme-hover); }
:root[data-theme="dark"] .sale-options-toggle.open { border-color: #a86c12; background: #38290f; color: #f8cf72; }
:root[data-theme="dark"] .sale-options-toggle.open:hover { background: #463312; }

:root[data-theme="dark"] .scan-button {
    border-color: #31577c;
    background: #102844;
    color: #7dd3fc;
}

:root[data-theme="dark"] .product-result {
    border-bottom-color: var(--theme-border);
    background: var(--theme-surface);
    color: var(--theme-text);
}

:root[data-theme="dark"] .product-result:hover { background: var(--theme-hover); }
:root[data-theme="dark"] .product-result strong,
:root[data-theme="dark"] .product-meta b { color: var(--theme-text-strong); }
:root[data-theme="dark"] .product-result small,
:root[data-theme="dark"] .product-meta small { color: #93a9bf; }

:root[data-theme="dark"] .product-result.out-of-stock {
    border-color: #6f3540;
    background: #2b171d;
}

:root[data-theme="dark"] .sale-tool-group {
    border-color: var(--theme-border);
    background: var(--theme-surface-raised);
}

:root[data-theme="dark"] .sale-tools .sale-option-label { color: var(--theme-text); }
:root[data-theme="dark"] .sale-quick-group { background: transparent; }
:root[data-theme="dark"] .sale-tools .discount-input { border-color: var(--theme-border); }
:root[data-theme="dark"] .sale-tools .discount-input span { color: var(--theme-text-muted); }
:root[data-theme="dark"] .sale-tools .sale-option-label input[type="text"] { border-color: var(--theme-border-strong); background: var(--theme-surface); color: var(--theme-text-strong); }
:root[data-theme="dark"] .sale-header .icon-button { background: #173454; color: #7dd3fc; }
:root[data-theme="dark"] .sale-lines { background: var(--theme-surface); }
:root[data-theme="dark"] .sale-line { border-color: var(--theme-border); color: var(--theme-text); }
:root[data-theme="dark"] .sale-line small { color: var(--theme-text-muted); }
:root[data-theme="dark"] .quantity button { border-color: var(--theme-border-strong); background: var(--theme-surface-raised); color: var(--theme-text); }
:root[data-theme="dark"] .sale-empty-state { color: var(--theme-text-muted); }

:root[data-theme="dark"] .sale-summary {
    border-color: var(--theme-border);
    background: var(--theme-surface-muted);
    color: var(--theme-text);
}

:root[data-theme="dark"] .summary-row { color: var(--theme-text-muted); }
:root[data-theme="dark"] .summary-row strong { color: var(--theme-text-strong); }
:root[data-theme="dark"] .summary-row.final { border-color: var(--theme-border-strong); color: var(--theme-text-strong); }
:root[data-theme="dark"] .summary-row.warning { color: #fde68a; }

:root[data-theme="dark"] :is(.customer-row, .document-row, .payment-row) { color: var(--theme-text); }
:root[data-theme="dark"] .customer-row > .check-field {
    border-color: var(--theme-border-strong);
    background: var(--theme-surface-raised);
    color: var(--theme-text);
}

:root[data-theme="dark"] :is(.customer-row input, .customer-row select, .document-row select, .payment-row select) {
    border-color: var(--theme-border-strong);
    background: var(--theme-input);
    color: var(--theme-text);
}

:root[data-theme="dark"] .document-hint { background: #302713; color: #fde68a; }
:root[data-theme="dark"] .quick-sale-form,
:root[data-theme="dark"] .quick-sale-line,
:root[data-theme="dark"] .quick-sale-modal .empty-state {
    border-color: var(--theme-border);
    background: var(--theme-surface-muted);
    color: var(--theme-text);
}

/* Inventory metrics need explicit contrast because their light-theme selectors are more specific. */
:root[data-theme="dark"] .inventory-kpi span,
:root[data-theme="dark"] .inventory-view-card span {
    color: #a9bdd0;
}

:root[data-theme="dark"] .inventory-kpi small,
:root[data-theme="dark"] .inventory-view-card small {
    color: #91a7bb;
}

:root[data-theme="dark"] .inventory-kpi strong {
    color: #f5f9ff;
    text-shadow: 0 1px 10px rgba(125, 211, 252, .08);
}

:root[data-theme="dark"] .inventory-view-card strong {
    color: #eaf2ff;
}

:root[data-theme="dark"] .inventory-view-card:hover,
:root[data-theme="dark"] .inventory-view-card.active {
    border-color: #3b82f6;
    background: #152942;
    box-shadow: inset 0 0 0 1px rgba(96, 165, 250, .18), 0 5px 16px rgba(0, 0, 0, .18);
}

:root[data-theme="dark"] .inventory-view-card.active strong { color: #7dd3fc; }
:root[data-theme="dark"] .inventory-table td:nth-child(3) { color: #93c5fd; }

/* Users and permissions */
:root[data-theme="dark"] .users-page .card {
    border-color: var(--theme-border);
    background: var(--theme-surface);
    color: var(--theme-text);
    box-shadow: 0 5px 18px var(--theme-shadow);
}

:root[data-theme="dark"] .users-page .section-heading {
    border-color: var(--theme-border);
    background: var(--theme-surface);
}

:root[data-theme="dark"] .users-page :is(.section-heading h2, .user-license-card h2) { color: var(--theme-text-strong); }
:root[data-theme="dark"] .users-page :is(.section-heading p, .user-license-card p) { color: var(--theme-text-muted); }

:root[data-theme="dark"] .user-license-metrics span {
    border: 1px solid var(--theme-border);
    background: var(--theme-surface-muted);
}

:root[data-theme="dark"] .user-license-metrics small { color: var(--theme-text-muted); }
:root[data-theme="dark"] .user-license-metrics strong { color: var(--theme-text-strong); }
:root[data-theme="dark"] .user-extra-control label { color: var(--theme-text-muted); }
:root[data-theme="dark"] .user-limit-note { background: #321820; color: #fda4af; }

:root[data-theme="dark"] .stack-form label { color: #a9bdd0; }
:root[data-theme="dark"] .stack-form :is(input, select) {
    border-color: var(--theme-border-strong);
    background: var(--theme-input);
    color: var(--theme-text);
}

:root[data-theme="dark"] .stack-form :is(input, select):focus {
    border-color: #60a5fa;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, .18);
}

:root[data-theme="dark"] .compact-table table { background: var(--theme-surface); }
:root[data-theme="dark"] .compact-table th {
    border-color: var(--theme-border);
    background: var(--theme-surface-muted);
    color: #a9bdd0;
}

:root[data-theme="dark"] .compact-table td {
    border-color: var(--theme-border);
    background: var(--theme-surface);
    color: var(--theme-text);
}

:root[data-theme="dark"] .compact-table td strong { color: var(--theme-text-strong); }
:root[data-theme="dark"] .compact-table td small,
:root[data-theme="dark"] .muted-text { color: var(--theme-text-muted); }
:root[data-theme="dark"] .active-session-device { color: #86efac; }

:root[data-theme="dark"] .user-status-filter .row-button.active {
    border-color: #3b82f6;
    background: #173454;
    color: #7dd3fc;
    box-shadow: inset 0 0 0 1px rgba(96, 165, 250, .16);
}

:root[data-theme="dark"] .role-card {
    border-color: var(--theme-border);
    background: var(--theme-surface-muted);
}

:root[data-theme="dark"] .role-card-heading strong,
:root[data-theme="dark"] .permission-group-title { color: var(--theme-text-strong); }
:root[data-theme="dark"] .role-card-heading span,
:root[data-theme="dark"] .role-card > p { color: var(--theme-text-muted); }
:root[data-theme="dark"] .permission-off { background: #1c2a3d; color: #91a7bb; }
:root[data-theme="dark"] .permission-on { background: #123126; color: #86efac; }

:root[data-theme="dark"] .permission-editor .check-field {
    border-color: var(--theme-border);
    background: var(--theme-surface-muted);
    color: var(--theme-text);
}

:root[data-theme="dark"] .permission-editor small { color: var(--theme-text-muted); }

/* Supervision: estado de continuidad y respaldos. */
:root[data-theme="dark"] .backup-readiness {
    border-color: var(--theme-border);
    background: var(--theme-surface);
    color: var(--theme-text);
    box-shadow: 0 12px 28px var(--theme-shadow);
}

:root[data-theme="dark"] .backup-readiness-copy h3 { color: var(--theme-text-strong); }
:root[data-theme="dark"] .backup-readiness-copy p,
:root[data-theme="dark"] .backup-readiness-copy small { color: var(--theme-text-muted); }

:root[data-theme="dark"] .backup-readiness-meta span {
    border-color: var(--theme-border);
    background: var(--theme-surface-raised);
    color: var(--theme-text);
}

:root[data-theme="dark"] .backup-critical {
    border-color: #713640;
    background: linear-gradient(120deg, #2b171d, var(--theme-surface));
}

:root[data-theme="dark"] .backup-critical .backup-readiness-mark {
    background: #3a1c24;
    color: #fca5a5;
}

:root[data-theme="dark"] .backup-warning {
    border-color: #745b27;
    background: linear-gradient(120deg, #2a2416, var(--theme-surface));
}

:root[data-theme="dark"] .backup-warning .backup-readiness-mark {
    background: #3a2d13;
    color: #fde68a;
}

:root[data-theme="dark"] .backup-healthy {
    border-color: #28513f;
    background: linear-gradient(120deg, #13271f, var(--theme-surface));
}

:root[data-theme="dark"] .backup-healthy .backup-readiness-mark {
    background: #173d2e;
    color: #86efac;
}

:root[data-theme="dark"] .supervision-table .selected-row,
:root[data-theme="dark"] .supervision-table .selected-row td {
    border-color: #315475;
    background: #162943;
    color: var(--theme-text);
}

:root[data-theme="dark"] .supervision-table .selected-row td:first-child {
    box-shadow: inset 4px 0 0 #3b82f6;
}

:root[data-theme="dark"] .supervision-table .selected-row strong { color: var(--theme-text-strong); }
:root[data-theme="dark"] .supervision-table .selected-row td small { color: #9db7d0; }

/* Shared SII progress bar. */
:root[data-theme="dark"] .sii-setup-steps {
    border-color: var(--theme-border);
    background: var(--theme-surface-muted);
    box-shadow: 0 8px 22px var(--theme-shadow);
}

:root[data-theme="dark"] .sii-setup-step {
    color: #9ec5ef;
}

:root[data-theme="dark"] .sii-setup-step:hover {
    background: var(--theme-hover);
}

:root[data-theme="dark"] .sii-setup-step > span {
    border: 1px solid #35597d;
    background: #173454;
    color: #93c5fd;
}

:root[data-theme="dark"] .sii-setup-step strong { color: var(--theme-text-strong); }
:root[data-theme="dark"] .sii-setup-step small { color: var(--theme-text-muted); }

:root[data-theme="dark"] .sii-setup-step.current {
    border-color: #3b82f6;
    background: #162943;
    box-shadow: inset 0 0 0 1px rgba(96, 165, 250, .12), 0 4px 14px var(--theme-shadow);
}

:root[data-theme="dark"] .sii-setup-step.current > span {
    border-color: #60a5fa;
    background: #2563b8;
    color: #fff;
}

:root[data-theme="dark"] .step-environment.test { background: #3a2d13; color: #fde68a; }
:root[data-theme="dark"] .step-environment.production { background: #3a1c24; color: #fca5a5; }

/* Habilitacion tributaria: preserve status meaning without leaving light panels. */
:root[data-theme="dark"] .tax-overview {
    border-color: var(--theme-border);
    background: linear-gradient(120deg, #111c2d, #161d29);
    box-shadow: 0 8px 22px var(--theme-shadow);
}

:root[data-theme="dark"] .tax-overview-heading h1,
:root[data-theme="dark"] .tax-company-inline strong,
:root[data-theme="dark"] .tax-environment-tabs strong,
:root[data-theme="dark"] .tax-panel h2,
:root[data-theme="dark"] .environment-closures-heading h2,
:root[data-theme="dark"] .environment-context-note strong,
:root[data-theme="dark"] .environment-closure h3,
:root[data-theme="dark"] .tax-save-bar strong {
    color: var(--theme-text-strong);
}

:root[data-theme="dark"] :is(
    .tax-overview-heading p:not(.eyebrow),
    .tax-company-inline small,
    .tax-summary-card small,
    .tax-environment-tabs small,
    .tax-panel header p,
    .environment-closures-heading p,
    .environment-context-note p,
    .environment-closure header p,
    .environment-check p,
    .tax-save-bar span
) {
    color: var(--theme-text-muted);
}

:root[data-theme="dark"] .tax-overview-context {
    border-color: var(--theme-border);
}

:root[data-theme="dark"] .tax-superadmin-badge {
    border: 1px solid #36506d;
    background: #162943;
    color: #dbeafe;
}

:root[data-theme="dark"] .tax-setup-links > span,
:root[data-theme="dark"] :is(.tax-scope-legend, .tax-mode-legend) > small {
    color: #91a9c0;
}

:root[data-theme="dark"] .tax-setup-links a,
:root[data-theme="dark"] .tax-link.secondary {
    border-color: var(--theme-border-strong);
    background: var(--theme-surface-raised);
    color: #93c5fd;
}

:root[data-theme="dark"] .tax-setup-links a:hover,
:root[data-theme="dark"] .tax-link.secondary:hover {
    border-color: #4f78a1;
    background: var(--theme-hover);
}

:root[data-theme="dark"] .tax-overview-loading {
    background: rgba(13, 24, 40, .84);
    color: var(--theme-text-muted);
}

:root[data-theme="dark"] .tax-summary-card {
    border-color: #63343b;
    border-left-color: #f87171;
    background: #2b171d;
}

:root[data-theme="dark"] .tax-summary-card.ready {
    border-color: #28513f;
    border-left-color: #4ade80;
    background: #13271f;
}

:root[data-theme="dark"] .tax-summary-card span { color: #aec0d2; }
:root[data-theme="dark"] .tax-summary-card strong { color: #fca5a5; }
:root[data-theme="dark"] .tax-summary-card.ready strong { color: #86efac; }

:root[data-theme="dark"] .tax-notice {
    border-color: #315475;
    background: #10243a;
    color: #bfdbfe;
}

:root[data-theme="dark"] .tax-environment-tabs {
    border-color: var(--theme-border);
    background: var(--theme-surface-muted);
}

:root[data-theme="dark"] .tax-environment-tabs button {
    color: var(--theme-text-muted);
}

:root[data-theme="dark"] .tax-environment-tabs button:hover {
    background: var(--theme-hover);
}

:root[data-theme="dark"] .tax-environment-tabs button.active {
    border-color: #456581;
    background: var(--theme-surface-raised);
    box-shadow: 0 4px 14px var(--theme-shadow);
}

:root[data-theme="dark"] .tax-environment-tabs button.test.active {
    border-color: #76569a;
    background: #241c33;
}

:root[data-theme="dark"] .tax-environment-tabs button.production.active {
    border-color: #87682e;
    background: #2a2416;
}

:root[data-theme="dark"] .tax-environment-tabs span { color: #91a9c0; }
:root[data-theme="dark"] .tax-environment-tabs button.test span { color: #d8b4fe; }
:root[data-theme="dark"] .tax-environment-tabs button.production span { color: #fcd34d; }

:root[data-theme="dark"] .tax-scope.certification { background: #302044; color: #d8b4fe; }
:root[data-theme="dark"] .tax-scope.production { background: #352a14; color: #fde68a; }
:root[data-theme="dark"] .tax-scope.transversal { background: #173454; color: #93c5fd; }
:root[data-theme="dark"] .tax-check-mode.automatic { border-color: #3a526b; background: #16263a; color: #b8cadb; }
:root[data-theme="dark"] .tax-check-mode.manual { border-color: #765a26; background: #302713; color: #fde68a; }

:root[data-theme="dark"] .tax-panel {
    border-color: var(--theme-border);
    background: var(--theme-surface);
    box-shadow: 0 8px 22px var(--theme-shadow);
}

:root[data-theme="dark"] .tax-panel > header,
:root[data-theme="dark"] .boleta-panel > header,
:root[data-theme="dark"] .shared-panel > header {
    border-color: var(--theme-border);
    background: linear-gradient(120deg, var(--theme-surface-raised), var(--theme-surface));
}

:root[data-theme="dark"] .tax-panel-kicker { color: #60a5fa; }
:root[data-theme="dark"] .tax-state { background: #3a1c24; color: #fca5a5; }
:root[data-theme="dark"] .tax-state.ready { background: #123126; color: #86efac; }

:root[data-theme="dark"] .tax-check {
    border-color: var(--theme-border);
    background: var(--theme-surface-muted);
}

:root[data-theme="dark"] .tax-check.pending {
    border-color: #63343b;
    background: #2b171d;
    box-shadow: inset 3px 0 0 #ef4444;
}

:root[data-theme="dark"] .tax-check.complete {
    border-color: #28513f;
    background: #13271f;
}

:root[data-theme="dark"] .tax-check strong { color: var(--theme-text-strong); }
:root[data-theme="dark"] .tax-check.pending strong { color: #fecaca; }
:root[data-theme="dark"] .tax-check p { color: var(--theme-text-muted); }
:root[data-theme="dark"] .tax-check small { color: #d2b77f; }
:root[data-theme="dark"] .tax-check.pending small { color: #fca5a5; }
:root[data-theme="dark"] .tax-check.complete small { color: #86b99a; }
:root[data-theme="dark"] .tax-check-mark { background: #3a1c24; color: #fca5a5; }
:root[data-theme="dark"] .tax-check.complete .tax-check-mark { background: #173d2e; color: #86efac; }

:root[data-theme="dark"] .environment-closures {
    border-color: var(--theme-border);
    background: var(--theme-surface-muted);
}

:root[data-theme="dark"] .environment-context-note {
    border-color: var(--theme-border);
    background: var(--theme-surface);
}

:root[data-theme="dark"] .environment-closure {
    border-color: #684a89;
    background: var(--theme-surface);
}

:root[data-theme="dark"] .environment-closure.production { border-color: #87682e; }
:root[data-theme="dark"] .environment-closure.pending,
:root[data-theme="dark"] .environment-closure.production.pending { border-color: #9f3a45; }
:root[data-theme="dark"] .environment-closure.ready { border-color: #347454; }

:root[data-theme="dark"] .environment-closure > header { background: #241c33; }
:root[data-theme="dark"] .environment-closure.production > header { background: #2a2416; }
:root[data-theme="dark"] .environment-closure.pending > header,
:root[data-theme="dark"] .environment-closure.production.pending > header { background: #2b171d; }
:root[data-theme="dark"] .environment-closure.ready > header { background: #13271f; }

:root[data-theme="dark"] .environment-closure header span { color: #d8b4fe; }
:root[data-theme="dark"] .environment-closure.production header span { color: #fde68a; }
:root[data-theme="dark"] .environment-closure.pending header span,
:root[data-theme="dark"] .environment-closure.production.pending header span { color: #fca5a5; }
:root[data-theme="dark"] .environment-closure header b { background: #392650; color: #e9d5ff; }
:root[data-theme="dark"] .environment-closure.production header b { background: #413116; color: #fde68a; }
:root[data-theme="dark"] .environment-closure.pending header b,
:root[data-theme="dark"] .environment-closure.production.pending header b { background: #3a1c24; color: #fca5a5; }
:root[data-theme="dark"] .environment-closure.ready header b { background: #173d2e; color: #86efac; }

:root[data-theme="dark"] .environment-check {
    border-color: #4b3b61;
    background: #1d1829;
}

:root[data-theme="dark"] .production .environment-check {
    border-color: #574721;
    background: #211e15;
}

:root[data-theme="dark"] .environment-check.pending,
:root[data-theme="dark"] .production .environment-check.pending {
    border-color: #63343b;
    background: #2b171d;
    box-shadow: inset 3px 0 0 #ef4444;
}

:root[data-theme="dark"] .environment-check.complete {
    border-color: #28513f;
    background: #13271f;
}

:root[data-theme="dark"] .environment-check strong { color: var(--theme-text-strong); }
:root[data-theme="dark"] .environment-check.pending strong { color: #fecaca; }
:root[data-theme="dark"] .environment-check-mark { background: #3a1c24; color: #fca5a5; }
:root[data-theme="dark"] .environment-check.complete .environment-check-mark { background: #173d2e; color: #86efac; }
:root[data-theme="dark"] .environment-scope { background: #173454; color: #bfdbfe; }
:root[data-theme="dark"] .environment-scope.certificación { background: #302044; color: #d8b4fe; }
:root[data-theme="dark"] .environment-scope.producción { background: #352a14; color: #fde68a; }
:root[data-theme="dark"] .production-approval-actions label { color: var(--theme-text); }
:root[data-theme="dark"] .environment-approved { color: #86efac; }

:root[data-theme="dark"] .tax-save-bar {
    border-color: var(--theme-border-strong);
    background: rgba(17, 28, 45, .96);
    box-shadow: 0 12px 30px var(--theme-shadow);
}

:root[data-theme="dark"] .tax-save-bar .success { color: #86efac; }
:root[data-theme="dark"] .tax-save-bar .error { color: #fca5a5; }

:root[data-theme="dark"] #blazor-error-ui {
    color-scheme: dark;
    border-top: 1px solid #745b27;
    background: #302713;
    color: #fde68a;
}

/* Respuesta visible y uniforme para todos los controles que actúan como botón. */
:where(
    button,
    input[type="button"],
    input[type="submit"],
    input[type="reset"],
    a.button,
    a.primary-action,
    a.confirm-button,
    a.row-button,
    label.row-button,
    [role="button"]
):not(:disabled):not([aria-disabled="true"]) {
    position: relative;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition:
        translate .14s ease,
        scale .14s ease,
        filter .16s ease,
        border-color .16s ease,
        box-shadow .16s ease;
}

:where(
    button,
    a.button,
    a.primary-action,
    a.confirm-button,
    a.row-button,
    label.row-button,
    [role="button"]
):not(:disabled):not([aria-disabled="true"])::after {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: inherit;
    background: currentColor;
    opacity: 0;
    pointer-events: none;
    transition: opacity .15s ease;
}

@media (hover: hover) and (pointer: fine) {
    :root[data-theme="light"] :where(
        button,
        input[type="button"],
        input[type="submit"],
        input[type="reset"],
        a.button,
        a.primary-action,
        a.confirm-button,
        a.row-button,
        label.row-button,
        [role="button"]
    ):not(:disabled):not([aria-disabled="true"]):hover {
        translate: 0 -1px;
        filter: brightness(.94) saturate(1.12);
    }

    :root[data-theme="dark"] :where(
        button,
        input[type="button"],
        input[type="submit"],
        input[type="reset"],
        a.button,
        a.primary-action,
        a.confirm-button,
        a.row-button,
        label.row-button,
        [role="button"]
    ):not(:disabled):not([aria-disabled="true"]):hover {
        translate: 0 -1px;
        filter: brightness(1.14) saturate(1.12);
    }

    :where(
        button,
        a.button,
        a.primary-action,
        a.confirm-button,
        a.row-button,
        label.row-button,
        [role="button"]
    ):not(:disabled):not([aria-disabled="true"]):hover::after {
        opacity: .065;
    }
}

:where(
    button,
    input[type="button"],
    input[type="submit"],
    input[type="reset"],
    a.button,
    a.primary-action,
    a.confirm-button,
    a.row-button,
    label.row-button,
    [role="button"]
):not(:disabled):not([aria-disabled="true"]):active {
    translate: 0 1px;
    scale: .965;
    filter: brightness(.84) saturate(1.08);
    box-shadow: inset 0 2px 5px rgba(3, 17, 34, .3);
}

:where(
    button,
    a.button,
    a.primary-action,
    a.confirm-button,
    a.row-button,
    label.row-button,
    [role="button"]
):not(:disabled):not([aria-disabled="true"]):active::after {
    opacity: .15;
}

:where(
    button,
    input[type="button"],
    input[type="submit"],
    input[type="reset"],
    a.button,
    a.primary-action,
    a.confirm-button,
    a.row-button,
    label.row-button,
    [role="button"]
):focus-visible {
    outline: 3px solid color-mix(in srgb, #2f6fed 62%, #fff);
    outline-offset: 2px;
}

.ui-button-pressed:not(:disabled):not([aria-disabled="true"]) {
    animation: aiventas-button-confirm .24s cubic-bezier(.22, 1, .36, 1);
}

.ui-button-pressed:not(:disabled):not([aria-disabled="true"])::after {
    animation: aiventas-button-flash .24s ease-out;
}

@keyframes aiventas-button-confirm {
    0% { scale: 1; }
    38% { scale: .955; filter: brightness(.82) saturate(1.12); }
    100% { scale: 1; }
}

@keyframes aiventas-button-flash {
    0% { opacity: .17; }
    100% { opacity: 0; }
}

/* Movimiento compartido para las superficies principales del producto. */
.page-content :where(
    .metric-card,
    .dashboard-card,
    .table-card,
    .filter-card,
    .history-summary-card,
    .inventory-kpi,
    .financial-card,
    .sales-chart-panel,
    .sales-intelligence,
    .route-message,
    .budget-vehicle-panel,
    .budget-lines,
    .budget-total,
    .budget-board,
    .purchase-card,
    .purchase-history,
    .agenda-editor,
    .agenda-list,
    .agenda-month,
    .agenda-week,
    .company-config-card,
    .config-section-card,
    .role-card,
    .role-editor-card,
    .permission-editor,
    .product-history-card,
    .inventory-view-card,
    .detail-card,
    .client-history-card,
    .sii-certification-card,
    .sii-stage-editor,
    .sii-prevalidation-panel,
    .sii-inbox-panel,
    .sii-evidence-library,
    .supervision-toolbar,
    .diagnostic-section,
    .caf-monitor,
    .tax-overview,
    .tax-panel,
    .environment-closures,
    .board-card,
    .sale-card
).ui-motion-card {
    transform-origin: 50% 60%;
    transition:
        transform .28s cubic-bezier(.22, 1, .36, 1),
        border-color .24s ease,
        box-shadow .28s ease,
        filter .24s ease;
}

:root.ui-motion-ready .page-content .ui-motion-card:not(.ui-motion-visible) {
    opacity: 0;
    transform: translateY(10px) scale(.992);
}

.page-content .ui-motion-card.ui-motion-visible {
    animation: aiventas-card-reveal .52s cubic-bezier(.22, 1, .36, 1) var(--card-enter-delay, 0ms) backwards;
}

@media (hover: hover) and (pointer: fine) {
    .page-content .ui-motion-card:hover {
        z-index: 1;
        transform: translateY(-3px);
        border-color: var(--card-motion-border);
        box-shadow: var(--card-motion-shadow);
        filter: saturate(1.025);
    }

    .page-content .ui-motion-card:hover :is(.metric-icon, .history-summary-icon, .file-icon) {
        transform: translateY(-2px) scale(1.055);
    }
}

@keyframes aiventas-card-reveal {
    from {
        opacity: 0;
        transform: translateY(10px) scale(.992);
        filter: blur(2px);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
        filter: blur(0);
    }
}

@media (max-width: 720px) {
    .login-theme-switch { top: 10px; right: 12px; }
    .theme-menu { right: -52px; }
    .topbar-control-cluster :is(.theme-toggle strong, .density-toggle strong, .theme-chevron, .density-chevron) { display: none; }
    .topbar-control-cluster :is(.theme-toggle, .density-toggle) { padding-inline: 8px; }
}

@media (prefers-reduced-motion: reduce) {
    :where(
        button,
        input[type="button"],
        input[type="submit"],
        input[type="reset"],
        a.button,
        a.primary-action,
        a.confirm-button,
        a.row-button,
        label.row-button,
        [role="button"]
    ) {
        transition: filter .12s ease, border-color .12s ease, box-shadow .12s ease;
    }

    :where(
        button,
        input[type="button"],
        input[type="submit"],
        input[type="reset"],
        a.button,
        a.primary-action,
        a.confirm-button,
        a.row-button,
        label.row-button,
        [role="button"]
    ):not(:disabled):not([aria-disabled="true"]):is(:hover, :active) {
        translate: none;
        scale: 1;
    }

    .ui-button-pressed:not(:disabled):not([aria-disabled="true"]),
    .ui-button-pressed:not(:disabled):not([aria-disabled="true"])::after {
        animation: none;
    }

    :root.ui-motion-ready .page-content .ui-motion-card,
    .page-content .ui-motion-card.ui-motion-visible {
        opacity: 1;
        transform: none;
        animation: none;
        transition: border-color .15s ease, background-color .15s ease;
        filter: none;
    }
}
