/* ============================================================================
   Astrotek UI v1.4.0 — subconjunto compatible con Bootstrap para SimplePOS.
   GENERADO por tools/ui/generar_astrotek_subset.py: no editar a mano.
   Incluye tokens y componentes sin colisión con Bootstrap 5.3. Los botones,
   cards, modales, formularios, alertas y dropdowns se tematizan en
   static/css/simplepos-ui.css con los mismos tokens.
   ============================================================================ */

/* ---- Sección 1 ---- */
:root {
  /* ---- Marca ---- */
  --primary:          #2563EB;
  --primary-strong:   #1D4ED8;   /* hover / active */
  --primary-soft:     #EFF4FF;   /* fondos seleccionados, hover de outline */
  --primary-ring:     rgba(37, 99, 235, .18);  /* anillo de foco (se deriva solo de --primary, ver abajo) */
  --on-primary:       #FFFFFF;
  --grad-from:        #1E6FF0;   /* degradado KPI destacado */
  --grad-to:          #0B57D0;

  /* ---- Superficies ---- */
  --bg:               #F4F6FA;   /* fondo de aplicación */
  --surface:          #FFFFFF;   /* cards, modales, inputs */
  --surface-alt:      #F8FAFC;   /* cabeceras de tabla, zonas secundarias */
  --border:           #E6E8EC;   /* separadores y bordes de cards */
  --border-strong:    #D3D8E0;   /* bordes de controles (inputs, selects) */
  --row-hover:        #F1F5F9;
  --overlay:          rgba(15, 23, 42, .45);   /* fondo de modales y drawer */
  --skeleton-hi:      #EDF1F6;

  /* ---- Texto (v1.2: oscurecidos para cumplir AA sobre todas las superficies) ---- */
  --text:             #0F172A;
  --text-muted:       #4F5D73;   /* descripciones, labels de campo */
  --text-label:       #5F6E86;   /* etiquetas uppercase, placeholders */

  /* ---- Semánticos ---- */
  --success: #16A34A;  --success-soft: #DCFCE7;  --success-text: #15803D;  --success-border: #BBF7D0;  --success-strong: #166534;
  --danger:  #DC2626;  --danger-soft:  #FEE2E2;  --danger-text:  #B91C1C;  --danger-border:  #FECACA;
  --warning: #D97706;  --warning-soft: #FEF3C7;  --warning-text: #92400E;  --warning-border: #FDE68A;
  --info:    #0284C7;  --info-soft:    #E0F2FE;  --info-text:    #075985;  --info-border:    #BAE6FD;
  --neutral-soft:     #EFF1F5;   --neutral-text: #475569;
  --danger-ring:      rgba(220, 38, 38, .15);

  /* ---- Sidebar ---- */
  --sidebar-bg:       #16233E;
  --sidebar-text:     #C7D2E0;
  --sidebar-label:    #4F9CFF;
  --sidebar-active:   #1E3357;
  --sidebar-width:    230px;

  /* ---- Selector de color (v1.4) ----
     --color-picker-bg: fondo de cada muestra; conviene que sea el fondo donde la app muestra el color.
     --color-picker-rainbow: ícono de «Personalizado» sin color elegido; la app puede redefinirlo con su paleta. */
  --color-picker-bg:      var(--sidebar-bg);
  --color-picker-rainbow: conic-gradient(#F87171, #FBBF24, #34D399, #4F9CFF, #C4B5FD, #F87171);

  /* ---- Tipografía ---- */
  --font-sans: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, 'Cascadia Code', Consolas, monospace;
  --fs-xs:    11px;     /* etiquetas uppercase, badges */
  --fs-sm:    12.5px;   /* metadatos, cabeceras de tabla, pills, ayudas */
  --fs-md:    13px;     /* texto secundario denso, labels de campo */
  --fs-base:  14px;     /* cuerpo por defecto */
  --fs-title: 15px;     /* título de card */
  --fs-lg:    16px;     /* subtítulos */
  --fs-xl:    18px;     /* títulos de modal / sección */
  --fs-2xl:   20px;     /* título de página */
  --fs-3xl:   26px;     /* valor de KPI */

  /* ---- Espaciado (escala de 4px) ---- */
  --sp-1: 4px;  --sp-2: 8px;  --sp-3: 12px;  --sp-4: 16px;
  --sp-5: 20px; --sp-6: 24px; --sp-7: 28px;  --sp-8: 32px;

  /* ---- Altura de controles (botones e inputs comparten altura) ---- */
  --control-h:    38px;
  --control-h-sm: 32px;
  --control-h-lg: 44px;
  /* v1.3: en pantallas táctiles los tres suben a 44 / 40 / 48px (ver sección 17) */

  /* ---- Radios ---- */
  --radius-sm:   6px;      /* pills pequeños internos, chips */
  --radius-btn:  8px;      /* botones, inputs */
  --radius-card: 12px;     /* cards */
  --radius-lg:   14px;     /* modales */
  --radius-pill: 9999px;

  /* ---- Sombras ---- */
  --shadow-sm: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.10);
  --shadow-md: 0 4px 12px rgba(16,24,40,.10);
  --shadow-lg: 0 20px 60px rgba(16,24,40,.25);

  /* ---- Movimiento ---- */
  --t-fast: .12s ease;
  --t-base: .2s ease;

  /* ---- Capas (de abajo hacia arriba) ---- */
  --z-topbar: 20;
  --z-sidebar: 30;
  --z-dropdown: 40;
  --z-drawer: 45;
  --z-modal: 50;
  --z-toast: 60;

  /* ---- Zonas seguras (v1.3): notch, isla dinámica, barra de gestos ----
     Valen 0 salvo que la app use <meta name="viewport" content="…, viewport-fit=cover">.
     Usarlas en cualquier elemento propio pegado a un borde de la pantalla. */
  --safe-top:    env(safe-area-inset-top, 0px);
  --safe-right:  env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left:   env(safe-area-inset-left, 0px);

  /* ---- Navegación inferior (v1.3) ----
     --bottom-offset: cuánto ocupa el borde inferior (zona segura + .bottom-nav si hay).
     Todo lo fijo abajo (toasts, .fab, .sticky-actions, elementos propios) se apoya en él. */
  --bottom-nav-h:  60px;
  --bottom-offset: var(--safe-bottom);
}
@supports (color: color-mix(in srgb, red 50%, blue)) {
  :root {
    --primary-ring: color-mix(in srgb, var(--primary) 18%, transparent);
    --danger-ring:  color-mix(in srgb, var(--danger) 15%, transparent);
  }
}

/* ---- Sección 2 ---- */
.mono { font-family: var(--font-mono); font-size: .92em; }
.tabular { font-variant-numeric: tabular-nums; }
.money { font-variant-numeric: tabular-nums; white-space: nowrap; }
.money.pos, .pos { color: var(--success-text); }
.money.neg, .neg { color: var(--danger-text); }

/* ---- Sección 5 ---- */
.kpi { padding: 18px 20px; border-radius: var(--radius-card); min-width: 0; }
.kpi .label { font-size: var(--fs-md); opacity: .9; }
.kpi .value { font-size: var(--fs-3xl); font-weight: 700; margin-top: 6px;
  font-variant-numeric: tabular-nums; line-height: 1.2; }
.kpi .sub { font-size: var(--fs-sm); opacity: .85; margin-top: 4px; }
.kpi-primary {
  background: linear-gradient(135deg, var(--grad-from), var(--grad-to));
  color: #fff; box-shadow: var(--shadow-sm);
}
.kpi-white {
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-sm);
}
.kpi-white .label { color: var(--text-muted); opacity: 1; }
.kpi-white .sub { opacity: 1; }
.delta { font-size: var(--fs-sm); font-weight: 600; }
.delta.up { color: var(--success-text); }
.delta.down { color: var(--danger-text); }
.kpi-primary .delta.up, .kpi-primary .delta.down { color: #fff; }
.kv { display: flex; justify-content: space-between; gap: var(--sp-3); padding: 9px 0; }
.kv + .kv { border-top: 1px solid var(--border); }
.kv .k { color: var(--text-muted); }
.kv .v { font-weight: 600; font-variant-numeric: tabular-nums; text-align: right; }
.kv.total .k, .kv.total .v { color: var(--text); font-weight: 700; font-size: var(--fs-lg); }
.avatar {
  width: 32px; height: 32px; border-radius: 50%; flex-shrink: 0;
  display: inline-grid; place-items: center;
  background: var(--primary-soft); color: var(--primary-strong);
  font-size: var(--fs-sm); font-weight: 700; letter-spacing: .3px;
}

/* ---- Sección 6 ---- */
.pill {
  display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px;
  border-radius: var(--radius-pill); font-size: var(--fs-sm); font-weight: 700;
  letter-spacing: .2px; white-space: nowrap;
}
.pill-success { background: var(--success-soft); color: var(--success-text); }
.pill-danger { background: var(--danger-soft);  color: var(--danger-text); }
.pill-warning { background: var(--warning-soft); color: var(--warning-text); }
.pill-info { background: var(--info-soft);    color: var(--info-text); }
.pill-neutral { background: var(--neutral-soft); color: var(--neutral-text); }
.pill-primary { background: var(--primary-soft); color: var(--primary-strong); }
.pill-anulado { background: var(--row-hover); color: var(--text-muted); text-decoration: line-through; }
.pill-ingreso { background: var(--success-soft); color: var(--success-text); }
.pill-egreso { background: var(--danger-soft);  color: var(--danger-text); }
.status { display: inline-flex; align-items: center; gap: 6px; font-size: var(--fs-md); font-weight: 600; white-space: nowrap; }
.status::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--text-label); flex-shrink: 0; }
.status-success::before { background: var(--success); }
.status-danger::before { background: var(--danger); }
.status-warning::before { background: var(--warning); }
.status-info::before { background: var(--info); }
.chip {
  display: inline-flex; align-items: center; gap: 4px; padding: 3px 5px 3px 10px;
  background: var(--primary-soft); color: var(--primary-strong);
  border-radius: var(--radius-pill); font-size: var(--fs-sm); font-weight: 600;
}
.chip .x {
  cursor: pointer; border: 0; background: none; color: inherit;
  width: 20px; height: 20px; display: inline-grid; place-items: center; padding: 0;
  font-size: var(--fs-xs); line-height: 1; border-radius: 50%;
}
.chip .x:hover { background: var(--primary-ring); }

/* ---- Sección 7 ---- */
.table-wrap { overflow-x: auto; position: relative; }
table.data { width: 100%; border-collapse: collapse; font-size: var(--fs-base); }
table.data thead th {
  background: var(--surface-alt); color: var(--neutral-text);
  text-align: left; font-weight: 600; font-size: var(--fs-sm);
  text-transform: uppercase; letter-spacing: .3px;
  padding: 11px 14px; border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
table.data tbody td { padding: 12px 14px; border-bottom: 1px solid var(--border); }
table.data tbody tr:hover { background: var(--row-hover); }
table.data tbody tr:last-child td { border-bottom: 0; }
table.data tbody tr.selected { background: var(--primary-soft); }
table.data tbody tr.clickable { cursor: pointer; }
table.data thead th.num, .num { text-align: right; }
table.data .col-check { width: 40px; padding-right: 0; }
table.data tfoot td {
  padding: 12px 14px; background: var(--surface-alt); font-weight: 700;
  border-top: 1px solid var(--border-strong);
}
.th-sort {
  display: inline-flex; align-items: center; gap: 6px; background: none; border: 0; padding: 0;
  font: inherit; color: inherit; text-transform: inherit; letter-spacing: inherit; cursor: pointer;
}
.th-sort::after {
  content: ""; border-left: 4px solid transparent; border-right: 4px solid transparent;
  border-top: 5px solid currentColor; opacity: .35;
}
.th-sort:hover, th[aria-sort="ascending"] .th-sort, th[aria-sort="descending"] .th-sort { color: var(--text); }
th[aria-sort="ascending"] .th-sort::after { border-top: 0; border-bottom: 5px solid currentColor; opacity: 1; }
th[aria-sort="descending"] .th-sort::after { opacity: 1; }
.table-wrap.sticky-head { overflow-y: auto; }
.table-wrap.sticky-head thead th { position: sticky; top: 0; z-index: 1; }
td.actions { text-align: right; white-space: nowrap; }
table.data.compact thead th { padding: 8px 12px; }
table.data.compact tbody td, table.data.compact tfoot td { padding: 8px 12px; font-size: var(--fs-md); }
.bulk-bar {
  display: flex; align-items: center; flex-wrap: wrap; gap: var(--sp-3);
  padding: 8px 20px; background: var(--primary-soft); color: var(--primary-strong);
  border-bottom: 1px solid var(--border); font-size: var(--fs-md); font-weight: 600;
}
.bulk-bar .bulk-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-left: auto; }
@media (max-width: 620px) {
  table.data.stack-mobile, table.data.stack-mobile tbody, table.data.stack-mobile tfoot, table.data.stack-mobile tr, table.data.stack-mobile td { display: block; }
  table.data.stack-mobile thead {
    position: absolute; width: 1px; height: 1px; overflow: hidden;
    clip: rect(0,0,0,0); white-space: nowrap;
  }
  table.data.stack-mobile tbody tr {
    position: relative; display: flex; flex-direction: column; gap: 2px;
    padding: 12px 16px; border-bottom: 1px solid var(--border);
  }
  table.data.stack-mobile tbody tr:last-child { border-bottom: 0; }
  table.data.stack-mobile tbody td {
    display: flex; flex-wrap: wrap; align-items: baseline; justify-content: flex-end;
    gap: 2px 6px; padding: 2px 0; border: 0; text-align: right; min-width: 0;
  }
  table.data.stack-mobile tbody td::before {
    content: attr(data-label); margin-right: auto; padding-right: var(--sp-3);
    text-align: left; color: var(--text-muted); font-size: var(--fs-md); font-weight: 500;
  }
  table.data.stack-mobile td:empty { display: none; }
  table.data.stack-mobile tbody td[colspan] { display: block; text-align: center; }
  table.data.stack-mobile tbody td.cell-main {
    order: -1; display: block; text-align: left; padding-bottom: 4px;
    font-size: var(--fs-lg); font-weight: 600;
  }
  table.data.stack-mobile tbody tr:has(td.col-check) td.cell-main { padding-right: 40px; }
  table.data.stack-mobile tbody td.col-check {
    position: absolute; top: 12px; right: 16px; width: auto; padding: 0;
  }
  table.data.stack-mobile tbody td.actions { order: 99; padding-top: 6px; }
  table.data.stack-mobile tbody td.cell-main::before, table.data.stack-mobile tbody td.col-check::before, table.data.stack-mobile tbody td.actions::before, table.data.stack-mobile tbody td[colspan]::before { content: none; }
  table.data.stack-mobile tfoot tr {
    display: flex; flex-wrap: wrap; justify-content: space-between; gap: 4px 12px;
    padding: 12px 16px; background: var(--surface-alt); border-top: 1px solid var(--border-strong);
  }
  table.data.stack-mobile tfoot td { padding: 0; border: 0; background: none; }
  table.data.stack-mobile.compact tbody tr { padding: 8px 14px; }
}

/* ---- Sección 9 ---- */
.filters { margin-bottom: var(--sp-4); }
.filters .filters-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 20px 0;
}
.filters-grid {
  display: grid; gap: 12px 16px; padding: 14px 20px;
  grid-template-columns: repeat(4, 1fr);
}
.filters-grid label.field { margin-bottom: 0; min-width: 0; }
.filters-foot {
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: var(--sp-3);
  padding: 0 20px 14px;
}
.filters-count { font-size: var(--fs-md); color: var(--text-muted); }
.filters-chips { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.filters.is-collapsed .filters-grid, .filters.is-collapsed .filters-foot { display: none; }
.filters.is-collapsed .filters-head { padding-bottom: 14px; }
@media (max-width: 980px) {
  .filters-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 620px) {
  .filters-grid { grid-template-columns: 1fr; }
}
.filters [data-filters-sheet-open], .filters .filters-head [data-filters-sheet-close] { display: none; }
@media (max-width: 620px) {
  .filters.sheet-mobile [data-filters-toggle] { display: none; }
  .filters.sheet-mobile [data-filters-sheet-open] { display: inline-flex; }
  .filters.sheet-mobile:not(.is-sheet-open) .filters-grid, .filters.sheet-mobile:not(.is-sheet-open) .filters-foot > :not(.filters-chips) { display: none; }
  .filters.sheet-mobile:not(.is-sheet-open) .filters-foot:not(:has(.chip)) { display: none; }
  .filters.sheet-mobile:not(.is-sheet-open) .filters-head { padding-bottom: 14px; }
  .filters.sheet-mobile:not(.is-sheet-open) .filters-foot { padding-top: 0; }
  .filters.sheet-mobile.is-sheet-open {
    position: fixed; left: 0; right: 0; bottom: 0; margin: 0; z-index: var(--z-modal);
    max-height: calc(100vh - 16px - var(--safe-top));
    max-height: calc(100dvh - 16px - var(--safe-top));
    overflow-y: auto; overscroll-behavior: contain;
    border: 0; border-radius: var(--radius-lg) var(--radius-lg) 0 0; box-shadow: var(--shadow-lg);
    padding-left: var(--safe-left); padding-right: var(--safe-right);
    animation: sheetIn .22s ease;
  }
  .filters.sheet-mobile.is-sheet-open .filters-grid { display: grid; }
  .filters.sheet-mobile.is-sheet-open .filters-foot { display: flex; }
  .filters.sheet-mobile.is-sheet-open [data-filters-sheet-open] { display: none; }
  .filters.sheet-mobile.is-sheet-open .filters-head [data-filters-sheet-close] { display: inline-grid; }
  .filters.sheet-mobile.is-sheet-open .filters-head {
    position: sticky; top: 0; z-index: 1; background: var(--surface);
    padding-bottom: 14px; border-bottom: 1px solid var(--border);
  }
  .filters.sheet-mobile.is-sheet-open .filters-foot {
    position: sticky; bottom: 0; background: var(--surface);
    padding-top: 14px; padding-bottom: calc(14px + var(--safe-bottom));
    border-top: 1px solid var(--border);
  }
}

/* ---- Sección 14 ---- */
.empty { text-align: center; color: var(--text-muted); padding: 48px 16px; }
.empty .title { font-weight: 600; color: var(--text); margin-bottom: 4px; }
.empty .hint { font-size: var(--fs-md); margin-bottom: 14px; }
.skeleton {
  background: linear-gradient(90deg, var(--surface-alt) 25%, var(--skeleton-hi) 50%, var(--surface-alt) 75%);
  background-size: 200% 100%; animation: shimmer 1.3s infinite;
  border-radius: var(--radius-sm); min-height: 14px;
}
@keyframes shimmer { to { background-position: -200% 0; } }
.spinner {
  width: 22px; height: 22px; border-radius: 50%; flex-shrink: 0;
  border: 3px solid var(--border); border-top-color: var(--primary);
  animation: spin .7s linear infinite;
}

/* ---- Sección 16 ---- */
.muted { color: var(--text-muted); }
.label-up {
  font-size: var(--fs-xs); font-weight: 700; letter-spacing: .5px;
  text-transform: uppercase; color: var(--text-label);
}
.stack { display: flex; flex-direction: column; gap: var(--sp-4); }
.grow { flex: 1; min-width: 0; }
.nowrap { white-space: nowrap; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}
@media (max-width: 620px) {
  .hide-mobile { display: none !important; }
}

/* ---- Sección 17 ---- */
@media (pointer: coarse) {
  :root {
    --control-h:    44px;
    --control-h-sm: 40px;
    --control-h-lg: 48px;
  }
  .chip .x { width: 32px; height: 32px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important; animation-iteration-count: 1 !important;
    transition-duration: .01ms !important; scroll-behavior: auto !important;
  }
  .skeleton { animation: none; background: var(--skeleton-hi); }
  .spinner {
    animation-duration: 1.6s !important; animation-iteration-count: infinite !important;
  }
}
