/* SafeTech Admin R8 — auditoría visual integral */
:root{color-scheme:light;--surface:#fff;--surface-2:#f8fafc;--surface-3:#eef2f7;--input:#fff;--text-strong:#172033}
html[data-theme="dark"]{
 color-scheme:dark;
 --ink:#f8fafc;--muted:#aebdd0;--line:#2a3c57;--paper:#111c2f;--bg:#09111f;
 --surface:#111c2f;--surface-2:#17243a;--surface-3:#20304a;--input:#0c1627;--text-strong:#f8fafc;
 --shadow:0 18px 48px rgba(0,0,0,.34);--red:#ef2b2b;--red-dark:#b91c1c;--blue:#60a5fa;--success:#34d399;--warning:#fbbf24;
 --r8-info-bg:#102a45;--r8-info-text:#bfdbfe;--r8-info-border:#28598a;
 --r8-warn-bg:#39290f;--r8-warn-text:#fde68a;--r8-warn-border:#7c5c20;
 --r8-success-bg:#0b3028;--r8-success-text:#6ee7b7;--r8-success-border:#176b58;
 --r8-danger-bg:#3a171d;--r8-danger-text:#fecdd3;--r8-danger-border:#7f2a3c;
}
html[data-theme="dark"] body{background:var(--bg)!important;color:var(--ink)!important}
html[data-theme="dark"] body:before{background-image:linear-gradient(rgba(148,163,184,.035) 1px,transparent 1px),linear-gradient(90deg,rgba(148,163,184,.035) 1px,transparent 1px)!important}

/* Selector visible */
.theme-toggle{display:inline-flex;align-items:center;justify-content:center;gap:7px;min-width:94px;height:39px;padding:4px 9px;border:1px solid var(--line);border-radius:999px;background:var(--surface-2);color:var(--ink);cursor:pointer;box-shadow:0 5px 16px rgba(0,0,0,.12);transition:.2s}
.theme-toggle:hover{transform:translateY(-1px);border-color:#ef4444}.theme-toggle:focus-visible{outline:3px solid rgba(248,113,113,.3);outline-offset:2px}
.theme-toggle__track{position:relative;flex:0 0 34px;width:34px;height:18px;border-radius:999px;background:#cbd5e1;transition:.2s}.theme-toggle__thumb{position:absolute;left:2px;top:2px;width:14px;height:14px;border-radius:50%;background:#fff;box-shadow:0 2px 5px rgba(0,0,0,.28);transition:.2s}.theme-toggle__icon{font-size:.76rem}.theme-toggle__label{min-width:38px;font-size:.68rem;font-weight:850;text-align:left}
html[data-theme="dark"] .theme-toggle__track{background:#9f2020}html[data-theme="dark"] .theme-toggle__thumb{transform:translateX(16px)}

/* Estructura principal */
html[data-theme="dark"] .loading-screen{background:var(--bg)!important;color:var(--ink)!important}
html[data-theme="dark"] .topbar{background:rgba(9,17,31,.91)!important;border-color:var(--line)!important;backdrop-filter:blur(16px)}
html[data-theme="dark"] .sidebar{background:#0d182a!important;border-color:var(--line)!important;box-shadow:18px 0 42px rgba(0,0,0,.18)!important}
html[data-theme="dark"] :is(.sidebar-brand,.sidebar-footer){border-color:var(--line)!important}
html[data-theme="dark"] .sidebar-brand img{width:168px!important;max-width:100%!important}
html[data-theme="dark"] .app-content{background:radial-gradient(circle at 88% 0%,rgba(37,99,235,.06),transparent 28%),var(--bg)!important}

/* Superficies principales y secundarias */
html[data-theme="dark"] :is(
.auth-card,.panel,.stat-card,.stock-card,.managed-card,.coupon-item,.integration-card,.mini-form,
.finance-kpi-card,.finance-more-metrics,.finance-advanced-step,.account-card,.decision-card,
.inventory-batch-row,.help-details,.confirm-dialog form,.fixed-cost-payment-dialog form,
.manual-sale-edit-dialog form,.managed-complete-dialog form,.owner-guidance-card,.sales-tax-item
){background:var(--surface)!important;border-color:var(--line)!important;color:var(--ink)!important;box-shadow:var(--shadow)!important}
html[data-theme="dark"] :is(
.quick-action,.beginner-steps>div,.simple-explainer-grid p,.fixed-cost-row,.product-cost-row,.stock-row,
.compact-row,.health-row,.audit-row,.managed-meta,.glossary-grid p,.tax-profile-row,.mini-stats span,
.finance-action-grid button,.finance-attention,.finance-mini-metric,.finance-roadmap-grid>div,
.finance-plain-guide>div,.finance-guide-strip>div,.finance-exception-note,.planning-snapshot,
.sii-check-row,.integration-card dl>div,.inventory-product-summary article,.manual-sale-calculation,
.manual-sale-calculation span,.inventory-calculation,.inventory-calculation span,.manual-sale-edit-document-grid,
.form-grid .check-row,.form-stack .check-row,.check-row,.inline-note,.warning-check,.paid-renewal-note
){background:var(--surface-2)!important;border-color:var(--line)!important;color:var(--ink)!important}
html[data-theme="dark"] :is(.quick-action,.stock-row,.compact-row,.health-row,.audit-row,.managed-card,.coupon-item,.finance-action-grid button):hover{background:var(--surface-3)!important;border-color:#4b668a!important}
html[data-theme="dark"] :is(.beginner-panel,.simple-explainer,.flow-auto-panel){background:linear-gradient(135deg,#111c2f,#17243a)!important;border-color:#3b5272!important}

/* Navegación */
html[data-theme="dark"] :is(.nav-item,.nav-subitem,.sidebar-footer a,.logout-button){color:#b8c7d9!important}
html[data-theme="dark"] .nav-item span{background:#20304a!important;color:#d4dfec!important}
html[data-theme="dark"] .nav-item:hover,html[data-theme="dark"] .nav-subitem:hover{background:#17243a!important;color:#fff!important}
html[data-theme="dark"] .nav-item.is-active,html[data-theme="dark"] .nav-subitem.is-active{background:rgba(239,68,68,.17)!important;color:#fca5a5!important}
html[data-theme="dark"] .app-version{background:#17243a!important;color:#dbe5f1!important;border:1px solid #2f4562!important}

/* Tipografía */
html[data-theme="dark"] :is(h1,h2,h3,h4,h5,strong,b,.table-primary,.panel-head h3,.managed-card h4,.category-bar b,.beginner-steps b,.glossary-grid b,.manual-sale-calculation strong,.inventory-calculation strong,.inventory-product-summary strong){color:#f8fafc!important}
html[data-theme="dark"] :is(.section-intro p,.panel p,.stat-card small,.stock-card p,.quick-action span,.compact-row small,.stock-row small,.managed-card p,.field-help,.updated-label,.inline-note,.switch-label small,.coupon-item p,.health-row small,.audit-row time,.audit-row p,.confirm-dialog p,.chart-legend,.fixed-cost-row small,.product-cost-row small,.managed-meta,.category-bar>div,.beginner-steps span,.simple-explainer-grid p,.glossary-grid p,.sales-tax-head small,.tax-source,.sales-tax-item p,.tax-profile-row small,.account-card small,.account-card span,.mini-stats small,.finance-action-grid small,.finance-attention small,.finance-kpi-card small,.finance-mini-metric span,.finance-roadmap-grid small,.finance-plain-guide small,.finance-guide-strip span,.finance-exception-note p,.finance-form-step legend small,.finance-advanced-step>summary small,.finance-period-picker label>small,.finance-period-picker em,.finance-period-picker>p,.decision-card small,.decision-card span,.locked-tax-row>small,.owner-guidance-card span,.owner-guidance-card p,.integration-card p,.integration-card dt,.manual-sale-calculation small,.inventory-calculation small,.form-divider span,.inventory-product-summary small,.inventory-product-summary span,.inventory-batch-row small){color:var(--muted)!important}
html[data-theme="dark"] :is(label,.form-stack label,.form-grid label,.filter-row label){color:#c8d4e2!important}
html[data-theme="dark"] .eyebrow,html[data-theme="dark"] .topbar-kicker{color:#f87171!important}

/* Formularios */
html[data-theme="dark"] :is(input,select,textarea,.period-picker input,.managed-actions select,.sales-tax-controls select,.report-actions input){background:var(--input)!important;color:#f8fafc!important;border-color:#3b5272!important}
html[data-theme="dark"] :is(input,select,textarea)::placeholder{color:#8293aa!important}
html[data-theme="dark"] :is(input,select,textarea):focus{border-color:#f87171!important;box-shadow:0 0 0 3px rgba(248,113,113,.22)!important}
html[data-theme="dark"] :is(.btn-soft,.icon-button,.menu-button,.user-chip,.mini-button,.order-status-actions button){background:#17243a!important;color:#e8eef7!important;border-color:#3b5272!important}
html[data-theme="dark"] :is(.btn-soft,.icon-button,.mini-button,.order-status-actions button):hover{background:#20304a!important;border-color:#ef4444!important;color:#fff!important}
html[data-theme="dark"] .user-chip{color:#dbe5f1!important}
html[data-theme="dark"] .switch{background:#334863!important;border-color:#4a6385!important}
html[data-theme="dark"] .switch:after{background:#fff!important}

/* Tablas y listados densos */
html[data-theme="dark"] :is(table,.data-table){background:var(--surface)!important;color:var(--ink)!important}
html[data-theme="dark"] th{background:#17243a!important;color:#dbe5f1!important;border-color:var(--line)!important}
html[data-theme="dark"] td{color:#c5d1df!important;border-color:var(--line)!important}
html[data-theme="dark"] tbody tr:hover td{background:#1b2a42!important}
html[data-theme="dark"] .table-primary{color:#fff!important}
html[data-theme="dark"] #autodesk-history-card .autodesk-history-table tr{background:var(--surface-2)!important;border-color:var(--line)!important}

/* Badges */
html[data-theme="dark"] :is(.status-badge,.large-badge,.meta-pill,.priority-badge,.source-tag,.friendly-badge){background:#20304a!important;color:#dbe5f1!important;border-color:#405776!important}
html[data-theme="dark"] :is(.status-badge.is-ok,.friendly-badge,.stock-number:not(.is-low),.owner-guidance-card.is-ready){background:var(--r8-success-bg)!important;color:var(--r8-success-text)!important;border-color:var(--r8-success-border)!important}
html[data-theme="dark"] :is(.status-badge.is-warning,.stock-number.is-low,.friendly-badge.is-warning,.account-card.is-different,.recurring-reminder-row,.fixed-cost-row.is-overdue){background:var(--r8-warn-bg)!important;color:var(--r8-warn-text)!important;border-color:var(--r8-warn-border)!important}
html[data-theme="dark"] :is(.managed-card.is-overdue,.manual-reset-preview,.manual-reset-panel){background:var(--r8-danger-bg)!important;color:var(--r8-danger-text)!important;border-color:var(--r8-danger-border)!important}

/* Cajas informativas semánticas */
html[data-theme="dark"] :is(.info-banner,.legal-boundary-panel,.web-sales-summary-note,.fixed-cost-scope-note,.payment-effect-note,.fixed-cost-paid-toggle,.manual-sale-edit-scope){background:var(--r8-info-bg)!important;color:var(--r8-info-text)!important;border-color:var(--r8-info-border)!important}
html[data-theme="dark"] :is(.info-banner.warning,.warning,.finance-attention.warning,.decision-explanation>div,.recurring-reminder-row){background:var(--r8-warn-bg)!important;color:var(--r8-warn-text)!important;border-color:var(--r8-warn-border)!important}
html[data-theme="dark"] :is(.success,.fixed-cost-paid-fields,.manual-reset-preserved,.owner-guidance-card.is-ready){background:var(--r8-success-bg)!important;color:var(--r8-success-text)!important;border-color:var(--r8-success-border)!important}
html[data-theme="dark"] :is(.info-banner,.warning,.success,.finance-attention,.payment-effect-note,.fixed-cost-scope-note,.manual-sale-edit-scope) :is(strong,b,p,small,span){color:inherit!important}

/* Cálculos y resúmenes que antes quedaban blancos */
html[data-theme="dark"] :is(.manual-sale-calculation span,.inventory-calculation span,.mini-stats span){background:#1b2a42!important;border-color:#304761!important}
html[data-theme="dark"] .manual-sale-calculation .is-total{background:#3a171d!important;border-color:#7f2a3c!important}
html[data-theme="dark"] .form-divider{background:#251a25!important;border-color:#ef4444!important}
html[data-theme="dark"] .balance-check{background:#20304a!important;color:#f8fafc!important}
html[data-theme="dark"] .finance-action-grid button>span,html[data-theme="dark"] .finance-roadmap-grid span,html[data-theme="dark"] .finance-plain-guide span{background:#2a2030!important;color:#f87171!important}
html[data-theme="dark"] .fixed-cost-payment-dialog .dialog-actions,html[data-theme="dark"] .manual-sale-edit-dialog .dialog-actions{background:var(--surface)!important}
html[data-theme="dark"] code{background:#20304a!important;color:#fca5a5!important}

@media(max-width:760px){.theme-toggle{min-width:54px;width:54px;padding-inline:7px}.theme-toggle__label,.theme-toggle__icon{display:none}.topbar-actions{gap:7px}.sidebar-brand img{width:145px!important}}
@media(prefers-reduced-motion:reduce){*,*:before,*:after{transition:none!important}}

/* R8: contraste AA fino en acciones y detalles */
html[data-theme="dark"] .btn-primary{background:#d62020!important;color:#fff!important;border-color:#ef4444!important}
html[data-theme="dark"] .btn-primary:hover{background:#b91c1c!important}
html[data-theme="dark"] .inventory-allocation-details summary{color:#cbd7e4!important;background:#17243a!important;border-color:#3b5272!important}

/* R9 — corrección integral del Centro de Dinero y selector persistente */
html[data-theme="dark"] :is(
  .finance-hero,.finance-workspace,.finance-form-step,.finance-advanced-step,
  .finance-plain-guide,.planning-snapshot>article,.report-decision-panel,
  .flow-settlement-card,.mp-settlement-card,.tax-review-item,
  .web-sales-summary-grid>article,.finance-primary-task
){
  background:var(--surface)!important;
  border-color:var(--line)!important;
  color:var(--ink)!important;
  box-shadow:var(--shadow)!important;
}
html[data-theme="dark"] .finance-hero{
  background:
    radial-gradient(circle at 8% 12%,rgba(239,43,43,.12),transparent 34%),
    linear-gradient(135deg,#111c2f,#17243a)!important;
  border-color:#3b5272!important;
}
html[data-theme="dark"] :is(.finance-hero h3,.finance-hero-copy h3,.finance-workspace-heading h3){color:#f8fafc!important}
html[data-theme="dark"] :is(.finance-hero p,.finance-hero-copy p,.planning-snapshot p,.tax-review-main p,.tax-review-main small){color:var(--muted)!important}
html[data-theme="dark"] :is(
  .flow-settlement-money span,.mp-settlement-values>span,.mp-settlement-values>div,
  .web-sales-summary-grid>article,.planning-snapshot>article,
  .sii-check-row,.tax-review-item,.finance-form-step,.finance-advanced-step
){background:#17243a!important;border-color:#304761!important}
html[data-theme="dark"] :is(.flow-settlement-money span,.mp-settlement-values>span,.mp-settlement-values>div) :is(small,span){color:#aebdd0!important}
html[data-theme="dark"] :is(.flow-settlement-money span,.mp-settlement-values>span,.mp-settlement-values>div) b{color:#f8fafc!important}
html[data-theme="dark"] :is(.flow-settlement-card,.mp-settlement-card){background:#111c2f!important;border-color:#304761!important}
html[data-theme="dark"] :is(.flow-settlement-card details,.flow-confirmed,.finance-more-metrics,.help-details){border-color:#304761!important;color:#d7e2ee!important}
html[data-theme="dark"] :is(.flow-settlement-card summary,.flow-confirmed summary,.finance-more-metrics>summary,.help-details>summary){color:#dbe5f1!important}
html[data-theme="dark"] .flow-order-list div{border-color:#304761!important}
html[data-theme="dark"] .flow-order-list span{color:#aebdd0!important}
html[data-theme="dark"] :is(.flow-settlement-document,.mp-settlement-document){background:#20304a!important;color:#dbe5f1!important;border-color:#405776!important}

html[data-theme="dark"] :is(.finance-form-step legend,.finance-advanced-step>summary){color:#f8fafc!important}
html[data-theme="dark"] .finance-form-step legend{background:#17243a!important;border-radius:12px;padding:3px 8px!important}
html[data-theme="dark"] :is(.finance-form-step legend b,.finance-advanced-step>summary b){color:#f8fafc!important}
html[data-theme="dark"] :is(.finance-form-step legend small,.finance-advanced-step>summary small){color:#aebdd0!important}
html[data-theme="dark"] :is(.finance-guided-form,.compact-guided-form,.wide-form){color:#f8fafc!important}
html[data-theme="dark"] :is(.finance-form-step,.finance-advanced-step) :is(label,.field-help){color:#c8d4e2!important}
html[data-theme="dark"] .finance-submit-bar{background:#20304a!important;border:1px solid #405776!important;color:#f8fafc!important}
html[data-theme="dark"] .finance-submit-bar span{color:#c6d2df!important}

html[data-theme="dark"] .decision-explanation>div{background:var(--r8-warn-bg)!important;border-color:var(--r8-warn-border)!important;color:var(--r8-warn-text)!important}
html[data-theme="dark"] .decision-explanation>div :is(strong,span,p,small){color:inherit!important}
html[data-theme="dark"] .legal-boundary-panel{background:var(--r8-info-bg)!important;border-color:var(--r8-info-border)!important;color:var(--r8-info-text)!important}
html[data-theme="dark"] .vat-policy-panel{background:var(--r8-success-bg)!important;border-color:var(--r8-success-border)!important;color:var(--r8-success-text)!important}
html[data-theme="dark"] :is(.legal-boundary-panel,.vat-policy-panel) :is(h3,strong,p,span,small){color:inherit!important}
html[data-theme="dark"] .planning-snapshot>article{background:linear-gradient(135deg,#111c2f,#17243a)!important}
html[data-theme="dark"] .sii-check-row>div:last-child{color:#c5d1df!important}
html[data-theme="dark"] .tax-review-item.is-automatic{background:#14263d!important}
html[data-theme="dark"] .tax-review-actions strong{color:#f8fafc!important}
html[data-theme="dark"] .web-sales-summary-grid>article :is(small,span){color:#aebdd0!important}
html[data-theme="dark"] .web-sales-summary-grid>article strong{color:#f8fafc!important}
html[data-theme="dark"] .web-sales-tax-status{color:#6ee7b7!important}

/* El selector queda siempre visible y no compite con el correo. */
.topbar-actions .theme-toggle{flex:0 0 auto}
html[data-theme="light"] .theme-toggle{background:#fff;color:#172033;border-color:#d4d9e2}
html[data-theme="light"] .theme-toggle__track{background:#cbd5e1}
html[data-theme="light"] .theme-toggle__thumb{transform:translateX(0)}
html[data-theme="dark"] .theme-toggle{background:#17243a!important;color:#f8fafc!important;border-color:#405776!important}
@media(max-width:900px){.topbar-actions .theme-toggle{min-width:54px;width:54px;padding-inline:7px}.topbar-actions .theme-toggle__label,.topbar-actions .theme-toggle__icon{display:none}}
@media(max-width:560px){.topbar-actions .user-chip{max-width:42px;padding-inline:11px}.topbar-actions .user-chip span:last-child{display:none}}
