/* Apariencia EMNA: control pequeño y paleta oscura. El modo claro conserva el diseño. */
@media screen {
  html[data-theme="light"] { color-scheme: light; }
  .theme-switch[role="group"] {
    display: inline-flex; align-items: center; flex: 0 0 auto; gap: 2px;
    padding: 3px; border: 1px solid #e0e6ef; border-radius: 999px;
    background: #f5f7fb; text-align: center; vertical-align: middle;
  }
  .theme-choice {
    display: grid; place-items: center; width: 30px; height: 30px; padding: 0;
    border: 0; border-radius: 50%; background: transparent; color: #6b7b94;
    box-shadow: none; cursor: pointer; transition: background-color 140ms ease, color 140ms ease;
  }
  .theme-choice svg { width: 15px; height: 15px; pointer-events: none; }
  .theme-choice:hover { color: #233d69; background: #e8edf6; }
  .theme-choice[aria-pressed="true"] { color: #304d8b; background: #fff; box-shadow: 0 1px 4px #20334b12; }
  .theme-choice:focus-visible { outline: 3px solid #3d5bb3; outline-offset: 2px; }
  :is(.login-page, .error-page) > .theme-switch { position: fixed; top: 20px; right: 22px; z-index: 70; }

  html[data-theme="dark"] {
    color-scheme: dark;
    --bg: #0e1624; --ink: #e5edf8; --muted: #a5b4cc; --line: #2c3a50;
    --white: #172233; --emna-heading: #edf3fc; --brand-ink: #e5edf8;
    --brand-blue: #8eafff; --brand-blue-dark: #b2c8ff; --blue: #8eafff;
    --brand-green-dark: #b4d795; --brand-wash: #1b2c43;
    --retail-black: #e5edf8; --retail-soft: #1b283b; --retail-line: #2c3a50;
    --emna-surface-shadow: 0 4px 20px #00000014;
  }
  html[data-theme="dark"] body { color: var(--ink); background: var(--bg); }
  html[data-theme="dark"] :is(.panel, .stats article, .topbar, .panel-head, .form-panel, .search, .report-filter, .login-card, .error-card) {
    color: var(--ink); background: #172233; border-color: var(--line); box-shadow: var(--emna-surface-shadow);
  }
  html[data-theme="dark"] :is(h1, h2, h3, .page-title h1, .dashboard-stats strong, .receipt-meta strong, .quick-links strong, .error-brand) { color: #edf3fc; }
  html[data-theme="dark"] :is(.eyebrow, .welcome-card .eyebrow) { color: #b9d899; }
  html[data-theme="dark"] :is(.page-title small, .panel-head small, .dashboard-stats span, .dashboard-stats small, .quick-links small, .form-section p, .panel-intro p, .receipt-footer, .receipt-meta span, .checkout-note, .login-help, .error-card > p:not(.error-code)) { color: var(--muted); }
  html[data-theme="dark"] .sidebar { background: linear-gradient(170deg, #182a46, #101d32); box-shadow: 4px 0 24px #00000018; }
  html[data-theme="dark"] .topbar-context strong { color: #edf3fc; }
  html[data-theme="dark"] .topbar-context small { color: #b0bed2; }
  html[data-theme="dark"] .welcome-card { border-color: #364e70; background: radial-gradient(ellipse at 95% 0, #2e4669, transparent 65%), #1b2c46; }
  html[data-theme="dark"] .welcome-card h1 { color: #fff; }
  html[data-theme="dark"] .welcome-card p:last-child { color: #d1def0; }
  html[data-theme="dark"] .quick-links > a { border-bottom-color: var(--line); }
  html[data-theme="dark"] .quick-links > a:hover { background: #1f2e44; }
  html[data-theme="dark"] .quick-links > a > span { color: #a8c0ff; background: #243653; border-color: #344d72; }
  html[data-theme="dark"] :is(.stat-icon.blue, .stat-icon.violet) { color: #adc5ff; background: #243653; border-color: #3b5276; }
  html[data-theme="dark"] .stat-icon.green { color: #c1e3a8; background: #24382d; border-color: #3c5945; }
  html[data-theme="dark"] .stat-icon.amber { color: #edcf87; background: #3b321f; border-color: #625131; }

  /* Botones: conservar la semántica de acción, peligro y deshabilitado. */
  html[data-theme="dark"] :is(.btn, .primary, .secondary, .danger-button, .camera-button, .link-button, .search button, .quote-status button, .quantity button, .receive-row button, .table-pagination button) {
    --button-bg: #1d2c42; --button-fg: #dfebfc; --button-border: #405370;
    --button-hover-bg: #293c58; --button-hover-border: #627b9c; --button-shadow: 0 2px 6px #00000012;
  }
  html[data-theme="dark"] :is(.btn.btn-primary, .primary:not(.btn-secondary):not(.btn-scan)) {
    --button-bg: #4766bd; --button-fg: #fff; --button-border: #5c7cd0; --button-hover-bg: #5574ce; --button-hover-border: #7d9bea;
  }
  html[data-theme="dark"] :is(.btn.btn-danger, .danger-button) {
    --button-bg: #a63849; --button-fg: #fff; --button-border: #c65669; --button-hover-bg: #b84558; --button-hover-border: #e17b8b;
  }
  html[data-theme="dark"] :is(.btn.btn-danger.link-button, .quantity .remove-item, .receive-row button) {
    --button-bg: #3a2532; --button-fg: #f5bfca; --button-border: #684151; --button-hover-bg: #503040; --button-hover-border: #a56c80;
  }
  html[data-theme="dark"] :is(.btn.btn-scan, .camera-button) {
    --button-bg: #253655; --button-fg: #c2d3ff; --button-border: #415d8d; --button-hover-bg: #30466b; --button-hover-border: #728fbb;
  }
  html[data-theme="dark"] .btn.btn-success { --button-bg: #213a2b; --button-fg: #c0e3a8; --button-border: #476344; --button-hover-bg: #2c4c38; }
  html[data-theme="dark"] :is(.btn, .primary, .secondary, .danger-button, .camera-button, .link-button, .search button, .quote-status button, .quantity button, .receive-row button, .table-pagination button):not(.product-card):not(.category-tab):not(.sort-column):disabled {
    color: #a0afc3; background: #202b3b; border-color: #364359; box-shadow: none;
  }
  html[data-theme="dark"] form[aria-busy="true"] [data-original-label]:disabled { color: #fff; background: #4766bd; border-color: #5c7cd0; }
  html[data-theme="dark"] :is(.btn, .theme-choice, input, select, textarea):focus-visible { outline-color: #a5beff; }

  /* Campos nativos y superficies interiores. */
  html[data-theme="dark"] :is(.record-form, .sale-fields, .login-card) label { color: #cfdbed; }
  html[data-theme="dark"] :is(input, select, textarea):not(:where([type="checkbox"], [type="radio"], [type="hidden"], [type="file"])) {
    background: #101c2e; color: #e4edfa; border-color: #40516c; box-shadow: none;
  }
  html[data-theme="dark"] :is(.record-form, .sale-fields, .report-filter, .search, .login-card) :is(input, select, textarea):not(:where([type="checkbox"], [type="radio"], [type="hidden"], [type="file"])) {
    background: #101c2e; color: #e4edfa; border-color: #40516c; box-shadow: none;
  }
  html[data-theme="dark"] :is(.record-form, .sale-fields, .report-filter, .search, .login-card) :is(input, select, textarea):focus { border-color: #9bb8fa; background: #17253b; box-shadow: 0 0 0 3px #8eafff20; }
  html[data-theme="dark"] input::placeholder, html[data-theme="dark"] textarea::placeholder { color: #9bacc4; }
  html[data-theme="dark"] select option { color: #e4edfa; background: #172233; }
  html[data-theme="dark"] :is(.record-form small, .sale-fields small, .barcode-field-help, .table-note, .checkout-note) { color: var(--muted); }
  html[data-theme="dark"] .record-form .field-error { color: #ffb9c5; }
  html[data-theme="dark"] :is(.form-actions, .record-form > .form-section, .sale-fields, .totals, .cart-row) { border-color: var(--line); }
  html[data-theme="dark"] :is(.product-form-intro, .unit-guide span, .conversion-summary, .void-confirm dl div, .payment-amount) { background: #1e3049; color: #ccdbf5; border-color: #39506e; }
  html[data-theme="dark"] .product-form-intro strong { color: #e2edfc; }
  html[data-theme="dark"] .presentation-card { border-color: #34435b; }
  html[data-theme="dark"] .presentation-card:hover { background: #203049; }
  html[data-theme="dark"] .presentation-factor { color: #c9dbfa; background: #223650; border-color: #405978; }
  html[data-theme="dark"] .base-presentation .presentation-factor { color: #c4e6ae; background: #233c2d; border-color: #42613d; }
  html[data-theme="dark"] .presentation-factor strong { color: inherit; }
  html[data-theme="dark"] .presentation-example { color: #cfdfd6; background: #213a30; border-color: #426453; }
  html[data-theme="dark"] .presentation-example strong { color: #c4e6ae; }
  html[data-theme="dark"] .presentation-example span { color: #cfdfd6; }
  html[data-theme="dark"] .settings-links a:hover { background: #1f3047; border-color: #547096; }
  html[data-theme="dark"] .settings-links strong { color: #adc7ff; }

  /* Tablas, estados y avisos legibles. */
  html[data-theme="dark"] table { color: #d4dfef; background: #172233; }
  html[data-theme="dark"] th { color: #b5c6df; background: #1d2b40; border-color: #34435b; }
  html[data-theme="dark"] td { color: #d4dfef; border-color: #2b3a50; }
  html[data-theme="dark"] td strong { color: #e4edfa; }
  html[data-theme="dark"] td small { color: var(--muted); }
  html[data-theme="dark"] tbody tr:hover { background: #203049; }
  html[data-theme="dark"] .table-pagination { color: var(--muted); background: #141f30; border-color: #2c3a50; }
  html[data-theme="dark"] :is(.badge.success-badge, .stock-chip, .cash-pill.open, .pos-session-pill) { color: #c4e6ae; background: #233c2d; border-color: #42613d; }
  html[data-theme="dark"] :is(.badge.warning, .stock-chip.low-stock) { color: #f0d393; background: #3b301c; border-color: #6d562f; }
  html[data-theme="dark"] :is(.badge.danger-badge, .quote-vencida) { color: #fac0c8; background: #3e2430; border-color: #6b3c4d; }
  html[data-theme="dark"] :is(.badge.neutral-badge, .quote-convertida, .catalog-count) { color: #c5d6ff; background: #253754; border-color: #405a83; }
  html[data-theme="dark"] .content a:not(:where(.btn, .button, .primary, .secondary, .product-card)) { color: #adc7ff; }
  html[data-theme="dark"] :is(.movement.positive, .positive) { color: #bbdda5; }
  html[data-theme="dark"] :is(.movement.negative, .negative) { color: #ffbdc6; }
  html[data-theme="dark"] .empty { color: #a8b8ce; }
  html[data-theme="dark"] .message { background: #233651; color: #d0dfff; border-color: #47618c; }
  html[data-theme="dark"] .message.success { background: #233c2d; color: #d1ecc2; border-color: #45653f; }
  html[data-theme="dark"] .message.warning { background: #3b301c; color: #f4dda8; border-color: #6d562f; }
  html[data-theme="dark"] :is(.message.error, .error, .void-banner, .danger-zone) { color: #f9c4cc; background: #34232d; border-color: #704252; }
  html[data-theme="dark"] .danger-zone :is(h2, strong) { color: #ffd1d8; }

  /* Catálogo, cobro y documentos: sin paneles blancos aislados. */
  html[data-theme="dark"] :is(.product-card, .pos-product-card, .product-visual, .pos-toolbar, .category-tabs) { color: #e1ebfa; background: #19283e; border-color: #344761; }
  html[data-theme="dark"] .product-card:hover { background: #21344f; border-color: #7c99c4; }
  html[data-theme="dark"] :is(.product-visual > span, .product-symbol) { color: #bdd2ff; background: #283d5d; box-shadow: none; }
  html[data-theme="dark"] :is(.product-card > strong, .pos-product-card > strong, .catalog-heading h2, .cart-heading h2) { color: #e8f1ff; }
  html[data-theme="dark"] :is(.product-card small, .product-card span:not([class]), .product-category, .product-meta) { color: #aebed6; }
  html[data-theme="dark"] .pos-product-card .product-footer b { color: #b4ccff; }
  html[data-theme="dark"] .pos-product-card .product-footer .add-product { color: #c4e6ae; background: #233c2d; border-color: #42613d; }
  html[data-theme="dark"] :is(.catalog-heading, .cart-heading, .pos-toolbar .pos-search, .barcode-zone:not(.pos-toolbar)) { background: #172233; border-color: #344761; }
  html[data-theme="dark"] .pos-toolbar .pos-search input { color: #e4edfa; background: transparent; border: 0; box-shadow: none; }
  html[data-theme="dark"] .category-tab { color: #b5c5de; background: transparent; }
  html[data-theme="dark"] .category-tab.active { color: #e6eeff; background: #304a70; }
  html[data-theme="dark"] :is(.pos-totals > div > span, .report-list span, .report-filter label) { color: #b9c8de; }
  html[data-theme="dark"] #cart-count { color: #d0dfff; background: #2b4262; }
  html[data-theme="dark"] .pos-totals .grand-total > span { color: #fff; }
  html[data-theme="dark"] .pos-totals .grand-total { color: #fff; background: #2b456d; }
  html[data-theme="dark"] .pos-totals .grand-total strong { color: #fff; }
  html[data-theme="dark"] .invoice-status { color: #dce8fb; background: #20324c; border-color: #3d5274; }
  html[data-theme="dark"] .invoice-status span { color: #b9c9e1; }
  html[data-theme="dark"] .receipt-totals .grand-total { border-color: #476080; }
  html[data-theme="dark"] :is(.barcode-dialog, .scanner-dialog, .scan-feedback) { color: #dbe7fa; background: #1c2e47; border-color: #466187; }

  html[data-theme="dark"] .login-shell { background: #0e1624; }
  html[data-theme="dark"] .login-card > p:not(.eyebrow) { color: #b4c4db; }
  html[data-theme="dark"] .login-card .input-wrap svg { color: #afc1dd; }
  html[data-theme="dark"] .login-mobile-brand { color: #e5edf8; }
  html[data-theme="dark"] .error-code { color: #a8bee4; }
  html[data-theme="dark"] .theme-switch { background: #152135; border-color: #34455f; }
  html[data-theme="dark"] .theme-choice { color: #93a6c4; }
  html[data-theme="dark"] .theme-choice:hover { color: #e0ebff; background: #253853; }
  html[data-theme="dark"] .theme-choice[aria-pressed="true"] { color: #e1eaff; background: #30466a; box-shadow: none; }

  @media (max-width: 650px) {
    .theme-choice { width: 34px; height: 34px; }
    .topbar { gap: 10px; }
    .topbar-context { max-width: calc(100vw - 175px); }
    :is(.login-page, .error-page) > .theme-switch { top: 14px; right: 14px; }
    .login-page .login-shell { padding-top: 44px; }
  }
  @media (prefers-reduced-motion: reduce) { .theme-choice { transition: none; } }
}
@media print {
  .theme-switch { display: none !important; }
  html { color-scheme: light; }
}
