/* =========================================================================
   Helados Iberia — interfaz móvil
   Diseño "mobile first": todo se piensa para 360–430 px y se amplía en
   tablet/escritorio (barra lateral en vez de barra inferior).
   ========================================================================= */

:root {
  color-scheme: light;
  --brand: #1b6fcc;
  --brand-strong: #145aa9;
  --brand-soft: #e7f0fb;
  --sun: #f6c41a;

  --bg: #f3f5f8;
  --surface: #ffffff;
  --surface-2: #f7f8fa;
  --surface-3: #eef1f5;
  --border: rgba(15, 23, 42, .09);
  --border-strong: rgba(15, 23, 42, .16);

  --ink: #0f172a;
  --ink-2: #475467;
  --muted: #8a94a6;

  --good: #0ca30c;
  --good-ink: #006300;
  --bad: #d03b3b;
  --bad-ink: #b42323;
  --warn: #fab219;
  --warn-ink: #8a5a00;

  /* Gráficos: paleta de referencia validada (skill dataviz), modo claro */
  --chart-surface: #ffffff;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --axis-ink: #898781;

  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .05), 0 4px 16px rgba(15, 23, 42, .05);
  --shadow-lg: 0 10px 40px rgba(15, 23, 42, .18);

  --header-h: 56px;
  --nav-h: 64px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);

  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --brand: #4c96ec;
    --brand-strong: #7ab2f2;
    --brand-soft: #172a42;
    --bg: #0d0f12;
    --surface: #17191d;
    --surface-2: #1d2025;
    --surface-3: #252930;
    --border: rgba(255, 255, 255, .08);
    --border-strong: rgba(255, 255, 255, .16);
    --ink: #f2f4f7;
    --ink-2: #c3c7cf;
    --muted: #8b93a1;
    --good-ink: #3fcf3f;
    --bad-ink: #ff7b7b;
    --warn-ink: #fab219;
    --chart-surface: #17191d;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --grid: #2c2c2a;
    --axis: #383835;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow-lg: 0 10px 40px rgba(0, 0, 0, .6);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --brand: #4c96ec;
  --brand-strong: #7ab2f2;
  --brand-soft: #172a42;
  --bg: #0d0f12;
  --surface: #17191d;
  --surface-2: #1d2025;
  --surface-3: #252930;
  --border: rgba(255, 255, 255, .08);
  --border-strong: rgba(255, 255, 255, .16);
  --ink: #f2f4f7;
  --ink-2: #c3c7cf;
  --muted: #8b93a1;
  --good-ink: #3fcf3f;
  --bad-ink: #ff7b7b;
  --warn-ink: #fab219;
  --chart-surface: #17191d;
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --grid: #2c2c2a;
  --axis: #383835;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow-lg: 0 10px 40px rgba(0, 0, 0, .6);
}

/* ------------------------------------------------------------------ Base */

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: contain;
}

h1, h2, h3, h4 { margin: 0; line-height: 1.2; font-weight: 650; }
h1 { font-size: 1.35rem; }
h2 { font-size: 1.05rem; }
h3 { font-size: .95rem; }
p { margin: 0; }
a { color: var(--brand); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
img { max-width: 100%; display: block; }

.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.ink-2 { color: var(--ink-2); }
.small { font-size: .82rem; }
.tiny { font-size: .74rem; }
.strong { font-weight: 650; }
.right { text-align: right; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.good { color: var(--good-ink); }
.bad { color: var(--bad-ink); }
.warn { color: var(--warn-ink); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.stack { display: flex; flex-direction: column; gap: 12px; }
.stack-lg { display: flex; flex-direction: column; gap: 18px; }
.row { display: flex; align-items: center; gap: 10px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1 1 auto; min-width: 0; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }

/* ------------------------------------------------------------------ Estructura */

.app { min-height: 100dvh; }

.topbar {
  position: sticky; top: 0; z-index: 30;
  height: calc(var(--header-h) + var(--safe-top));
  padding: var(--safe-top) 12px 0 16px;
  display: flex; align-items: center; gap: 10px;
  background: var(--brand);
  color: #fff;
}
.topbar .titulo { flex: 1 1 auto; min-width: 0; }
.topbar .titulo strong { display: block; font-size: 1.02rem; font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .titulo span { display: block; font-size: .74rem; opacity: .85; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .icon-btn { color: #fff; }
.topbar .icon-btn:hover { background: rgba(255, 255, 255, .14); }
.topbar .marca { width: 34px; height: 34px; border-radius: 10px; background: #fff; display: grid; place-items: center; flex: none; overflow: hidden; }
.topbar .marca img { width: 30px; }

.avatar {
  width: 34px; height: 34px; border-radius: 50%;
  display: grid; place-items: center;
  background: rgba(255, 255, 255, .2); color: #fff;
  font-size: .8rem; font-weight: 700; letter-spacing: .02em;
  border: 0; cursor: pointer;
}

.contenido {
  padding: 16px 16px calc(var(--nav-h) + var(--safe-bottom) + 24px);
  max-width: 1180px;
  margin: 0 auto;
}

/* Barra inferior (móvil) */
.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  height: calc(var(--nav-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--surface);
  border-top: 1px solid var(--border);
}
.bottom-nav a, .bottom-nav button {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--muted); font-size: .7rem; font-weight: 600;
  background: none; border: 0; cursor: pointer; position: relative;
}
.bottom-nav svg { width: 24px; height: 24px; }
.bottom-nav .active { color: var(--brand); }
.bottom-nav .active::before {
  content: ""; position: absolute; top: 0; left: 30%; right: 30%; height: 3px;
  border-radius: 0 0 3px 3px; background: var(--brand);
}

/* Barra lateral (escritorio) */
.side-nav { display: none; }

@media (min-width: 960px) {
  .app { display: grid; grid-template-columns: 248px 1fr; grid-template-rows: auto 1fr; }
  .topbar { grid-column: 1 / -1; }
  .bottom-nav { display: none; }
  .side-nav {
    display: flex; flex-direction: column; gap: 2px;
    position: sticky; top: var(--header-h); height: calc(100dvh - var(--header-h));
    padding: 16px 12px; overflow-y: auto;
    background: var(--surface); border-right: 1px solid var(--border);
  }
  .side-nav a {
    display: flex; align-items: center; gap: 12px;
    padding: 10px 12px; border-radius: 10px;
    color: var(--ink-2); font-weight: 550;
  }
  .side-nav a:hover { background: var(--surface-2); }
  .side-nav a.active { background: var(--brand-soft); color: var(--brand); }
  .side-nav svg { width: 20px; height: 20px; flex: none; }
  .side-nav .seccion { margin: 14px 12px 6px; font-size: .72rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
  .contenido { padding: 24px 28px 40px; width: 100%; }
}

/* Encabezado de página */
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.page-head h1 { font-size: 1.3rem; }
.page-head .sub { color: var(--muted); font-size: .84rem; margin-top: 2px; }
.volver { display: inline-flex; align-items: center; gap: 4px; color: var(--ink-2); font-size: .86rem; font-weight: 550; margin-bottom: 8px; }
.volver svg { width: 18px; height: 18px; }

/* ------------------------------------------------------------------ Tarjetas */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  min-width: 0;
}
.card-flat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.card-head h2 { font-size: .98rem; }
.card-head .muted { font-size: .78rem; }

.hero { padding: 18px 16px 16px; }
.hero .etiqueta { font-size: .82rem; color: var(--ink-2); font-weight: 550; }
.hero .valor { font-size: 2.35rem; font-weight: 700; letter-spacing: -.02em; line-height: 1.1; margin: 4px 0 6px; }
.hero .detalle { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; font-size: .84rem; color: var(--ink-2); }

.stat { padding: 12px 14px; }
.stat .etiqueta { font-size: .76rem; color: var(--ink-2); font-weight: 550; }
.stat .valor { font-size: 1.22rem; font-weight: 680; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat .nota { font-size: .74rem; color: var(--muted); margin-top: 2px; }

.delta { display: inline-flex; align-items: center; gap: 3px; font-weight: 650; font-size: .82rem; }
.delta svg { width: 14px; height: 14px; }
.delta.sube { color: var(--good-ink); }
.delta.baja { color: var(--bad-ink); }
.delta.igual { color: var(--muted); }

/* ------------------------------------------------------------------ Controles */

.chips {
  display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none;
  margin: 0 -16px 14px; padding: 2px 16px;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; height: 34px; padding: 0 14px;
  border-radius: 999px; border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--ink-2);
  font-size: .84rem; font-weight: 600; cursor: pointer; white-space: nowrap;
  display: inline-flex; align-items: center; gap: 6px;
}
.chip.on { background: var(--ink); border-color: var(--ink); color: var(--surface); }
.chip svg { width: 16px; height: 16px; }
@media (min-width: 960px) { .chips { margin: 0 0 16px; padding: 2px 0; flex-wrap: wrap; } }

.segmented { display: inline-flex; padding: 3px; gap: 2px; background: var(--surface-3); border-radius: 11px; }
.segmented button {
  border: 0; background: transparent; padding: 6px 12px; border-radius: 8px;
  font-size: .82rem; font-weight: 600; color: var(--ink-2); cursor: pointer;
}
.segmented button.on { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.08); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 44px; padding: 0 18px; border-radius: 12px;
  border: 1px solid transparent; cursor: pointer;
  font-weight: 650; font-size: .92rem; white-space: nowrap;
  background: var(--surface-3); color: var(--ink);
  transition: filter .15s, background .15s;
}
.btn:hover { filter: brightness(.97); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn svg { width: 18px; height: 18px; }
.btn.primary { background: var(--brand); color: #fff; }
.btn.danger { background: var(--bad); color: #fff; }
.btn.ghost { background: transparent; border-color: var(--border-strong); }
.btn.sm { height: 34px; padding: 0 12px; font-size: .82rem; border-radius: 10px; }
.btn.block { width: 100%; }

.icon-btn {
  width: 40px; height: 40px; border-radius: 12px; border: 0; background: transparent;
  display: inline-grid; place-items: center; cursor: pointer; color: var(--ink-2); flex: none;
}
.icon-btn:hover { background: var(--surface-3); }
.icon-btn svg { width: 22px; height: 22px; }

.fab {
  position: fixed; right: 16px; z-index: 25;
  bottom: calc(var(--nav-h) + var(--safe-bottom) + 16px);
  height: 52px; padding: 0 20px 0 16px; border-radius: 16px; border: 0;
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--brand); color: #fff; font-weight: 700; font-size: .92rem;
  box-shadow: 0 6px 20px rgba(27, 111, 204, .35); cursor: pointer;
}
.fab svg { width: 22px; height: 22px; }
@media (min-width: 960px) { .fab { bottom: 28px; right: 28px; } }

.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > span, .field > label { font-size: .8rem; font-weight: 600; color: var(--ink-2); }
.input, .field input, .field select, .field textarea {
  width: 100%; min-height: 46px; padding: 10px 12px;
  border-radius: 12px; border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--ink);
  font-size: 16px; /* evita el zoom automático en iOS */
  outline: none;
}
.field textarea { min-height: 84px; resize: vertical; }
.input:focus, .field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--brand); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 22%, transparent);
}
.field .ayuda { font-size: .76rem; color: var(--muted); }
.field .error { font-size: .78rem; color: var(--bad-ink); font-weight: 600; }
.input-monto { font-size: 1.4rem !important; font-weight: 700; font-variant-numeric: tabular-nums; }

.buscador { position: relative; }
.buscador svg { position: absolute; left: 12px; top: 50%; width: 20px; height: 20px; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.buscador input { padding-left: 40px; }

.check { display: inline-flex; align-items: center; gap: 8px; font-size: .9rem; cursor: pointer; }
.check input { width: 20px; height: 20px; accent-color: var(--brand); }

/* ------------------------------------------------------------------ Listas */

.lista { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.lista > .item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px; min-height: 60px;
  border-bottom: 1px solid var(--border);
  color: inherit; background: none; width: 100%; text-align: left;
  border-left: 0; border-right: 0; border-top: 0;
}
.lista > .item:last-child { border-bottom: 0; }
a.item, button.item { cursor: pointer; }
a.item:hover, button.item:hover { background: var(--surface-2); }
.item .principal { flex: 1 1 auto; min-width: 0; }
.item .principal strong { display: block; font-weight: 600; font-size: .93rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .principal span { display: block; font-size: .78rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .monto { text-align: right; flex: none; font-variant-numeric: tabular-nums; }
.item .monto strong { display: block; font-weight: 650; }
.item .monto span { display: block; font-size: .74rem; color: var(--muted); }
.item .chev { color: var(--muted); width: 18px; height: 18px; flex: none; }
.item.tachado .principal strong, .item.tachado .monto strong { text-decoration: line-through; color: var(--muted); }

.lista-grupo { font-size: .74rem; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); padding: 14px 4px 6px; }

.ico-circ {
  width: 38px; height: 38px; border-radius: 12px; flex: none;
  display: grid; place-items: center; background: var(--surface-3); color: var(--ink-2);
}
.ico-circ svg { width: 20px; height: 20px; }
.ico-circ.ing { background: color-mix(in srgb, var(--good) 14%, transparent); color: var(--good-ink); }
.ico-circ.egr { background: color-mix(in srgb, var(--bad) 13%, transparent); color: var(--bad-ink); }
.ico-circ.neutro { background: var(--brand-soft); color: var(--brand); }

.badge {
  display: inline-flex; align-items: center; gap: 4px;
  height: 22px; padding: 0 8px; border-radius: 999px;
  font-size: .7rem; font-weight: 700; letter-spacing: .02em;
  background: var(--surface-3); color: var(--ink-2); white-space: nowrap;
}
.badge.good { background: color-mix(in srgb, var(--good) 14%, transparent); color: var(--good-ink); }
.badge.bad { background: color-mix(in srgb, var(--bad) 14%, transparent); color: var(--bad-ink); }
.badge.warn { background: color-mix(in srgb, var(--warn) 22%, transparent); color: var(--warn-ink); }
.badge.brand { background: var(--brand-soft); color: var(--brand); }
.badge svg { width: 12px; height: 12px; }

.kv { display: grid; grid-template-columns: 1fr auto; gap: 8px 0; font-size: .9rem; }
.kv dt { color: var(--ink-2); }
.kv dd { margin: 0; padding-left: 16px; text-align: right; font-variant-numeric: tabular-nums; font-weight: 550; }
.kv .total { font-weight: 700; color: var(--ink); padding-top: 8px; border-top: 1px solid var(--border); }
.kv .sep { grid-column: 1 / -1; height: 1px; background: var(--border); margin: 2px 0; }

/* Tabla (escritorio y reportes) */
.tabla-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
table.tabla { width: 100%; border-collapse: collapse; font-size: .86rem; }
.tabla th, .tabla td { padding: 10px 12px; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; }
.tabla th { font-size: .74rem; font-weight: 700; color: var(--ink-2); background: var(--surface-2); position: sticky; top: 0; cursor: pointer; user-select: none; }
.tabla td.num, .tabla th.num { text-align: right; font-variant-numeric: tabular-nums; }
.tabla tr:last-child td { border-bottom: 0; }
.tabla tfoot td { font-weight: 700; background: var(--surface-2); border-top: 1px solid var(--border-strong); }

/* ------------------------------------------------------------------ Estados */

.vacio { text-align: center; padding: 40px 20px; color: var(--muted); }
.vacio svg { width: 44px; height: 44px; margin: 0 auto 10px; opacity: .55; }
.vacio strong { display: block; color: var(--ink-2); margin-bottom: 4px; }

.cargando { display: grid; place-items: center; padding: 48px 0; }
.spinner {
  width: 30px; height: 30px; border-radius: 50%;
  border: 3px solid var(--surface-3); border-top-color: var(--brand);
  animation: gira .8s linear infinite;
}
.spinner.sm { width: 18px; height: 18px; border-width: 2px; }
@keyframes gira { to { transform: rotate(360deg); } }

.recargando { opacity: .55; transition: opacity .2s; pointer-events: none; }

.skeleton { background: linear-gradient(90deg, var(--surface-3), var(--surface-2), var(--surface-3)); background-size: 200% 100%; animation: brillo 1.2s infinite; border-radius: 8px; }
@keyframes brillo { to { background-position: -200% 0; } }

.alerta {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 12px 14px; border-radius: 12px; font-size: .86rem;
  background: var(--brand-soft); color: var(--ink);
}
.alerta svg { width: 20px; height: 20px; flex: none; margin-top: 1px; color: var(--brand); }
.alerta.bad { background: color-mix(in srgb, var(--bad) 12%, transparent); }
.alerta.bad svg { color: var(--bad-ink); }
.alerta.warn { background: color-mix(in srgb, var(--warn) 18%, transparent); }
.alerta.warn svg { color: var(--warn-ink); }

/* ------------------------------------------------------------------ Hoja inferior (modal) */

.hoja-fondo {
  position: fixed; inset: 0; z-index: 50; background: rgba(15, 23, 42, .45);
  display: flex; align-items: flex-end; justify-content: center;
  animation: aparece .18s ease-out;
}
.hoja {
  width: 100%; max-width: 560px; max-height: 92dvh; overflow-y: auto;
  background: var(--surface); border-radius: 20px 20px 0 0;
  padding: 8px 18px calc(18px + var(--safe-bottom));
  box-shadow: var(--shadow-lg);
  animation: sube .22s cubic-bezier(.2, .8, .2, 1);
}
.hoja .agarre { width: 40px; height: 4px; border-radius: 2px; background: var(--border-strong); margin: 4px auto 12px; }
.hoja .hoja-titulo { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; }
.hoja .hoja-titulo h2 { font-size: 1.1rem; }
.hoja .acciones { display: flex; gap: 10px; margin-top: 18px; }
.hoja .acciones .btn { flex: 1; }
@media (min-width: 640px) {
  .hoja-fondo { align-items: center; }
  .hoja { border-radius: 20px; padding-bottom: 18px; }
}
@keyframes aparece { from { opacity: 0; } }
@keyframes sube { from { transform: translateY(40px); opacity: .6; } }

.toast-zona {
  position: fixed; left: 16px; right: 16px; z-index: 60;
  bottom: calc(var(--nav-h) + var(--safe-bottom) + 16px);
  display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none;
}
.toast {
  max-width: 480px; width: 100%;
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px; border-radius: 12px;
  background: var(--ink); color: var(--surface);
  font-size: .88rem; font-weight: 550; box-shadow: var(--shadow-lg);
  animation: sube .2s ease-out; pointer-events: auto;
}
.toast svg { width: 20px; height: 20px; flex: none; }
.toast.ok svg { color: #4ade80; }
.toast.error { background: var(--bad); color: #fff; }

/* ------------------------------------------------------------------ Gráficos */

.grafico { position: relative; }
.grafico svg { display: block; width: 100%; height: auto; overflow: visible; }
.grafico .barra { fill: var(--series-1); transition: opacity .12s; }
.grafico .barra.dim { opacity: .35; }
.grafico .barra.actual { fill: var(--series-1); }
.grafico .grid { stroke: var(--grid); stroke-width: 1; shape-rendering: crispEdges; }
.grafico .base { stroke: var(--axis); stroke-width: 1; shape-rendering: crispEdges; }
.grafico .eje { fill: var(--axis-ink); font-size: 10.5px; font-family: var(--font); font-variant-numeric: tabular-nums; }
.grafico .hit { fill: transparent; cursor: pointer; }
.grafico .tip {
  position: absolute; top: 0; transform: translateX(-50%);
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: 10px;
  box-shadow: var(--shadow-lg); padding: 8px 10px; pointer-events: none;
  font-size: .8rem; white-space: nowrap; z-index: 2;
}
.grafico .tip strong { display: block; font-size: .95rem; }
.grafico .tip span { color: var(--ink-2); }

.barras-h { display: flex; flex-direction: column; gap: 12px; }
.barras-h .fila { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 12px; align-items: baseline; }
.barras-h .fila .nombre { font-size: .86rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.barras-h .fila .valor { font-size: .86rem; font-weight: 650; font-variant-numeric: tabular-nums; text-align: right; }
.barras-h .fila .valor small { font-weight: 500; color: var(--muted); margin-left: 6px; }
.barras-h .pista { grid-column: 1 / -1; height: 8px; border-radius: 4px; background: var(--surface-3); overflow: hidden; }
.barras-h .relleno { height: 100%; border-radius: 0 4px 4px 0; background: var(--series-1); }

.apilada { display: flex; height: 12px; border-radius: 6px; overflow: hidden; gap: 2px; background: var(--chart-surface); }
.apilada > div { height: 100%; }
.apilada > div:last-child { border-radius: 0 4px 4px 0; }
.leyenda { display: flex; flex-direction: column; gap: 8px; margin-top: 14px; }
.leyenda .li { display: flex; align-items: center; gap: 10px; font-size: .86rem; }
.leyenda .sw { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.leyenda .li .grow { color: var(--ink-2); }
.leyenda .li .v { font-weight: 650; font-variant-numeric: tabular-nums; }
.leyenda .li .p { width: 44px; text-align: right; color: var(--muted); font-size: .78rem; font-variant-numeric: tabular-nums; }
.s1 { background: var(--series-1); }
.s2 { background: var(--series-2); }
.s3 { background: var(--series-3); }
.s4 { background: var(--muted); }

/* Calendario */
.calendario { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; }
.calendario .dow { text-align: center; font-size: .7rem; font-weight: 700; color: var(--muted); padding: 4px 0; }
.calendario .dia {
  min-height: 58px; padding: 6px 4px; border-radius: 10px;
  background: var(--surface); border: 1px solid var(--border);
  display: flex; flex-direction: column; align-items: center; justify-content: space-between; gap: 2px;
}
.calendario .dia .n { font-size: .78rem; font-weight: 650; color: var(--ink-2); }
.calendario .dia .t { font-size: .68rem; font-weight: 650; font-variant-numeric: tabular-nums; color: var(--ink); }
.calendario .dia.hoy { border-color: var(--brand); box-shadow: inset 0 0 0 1px var(--brand); }
.calendario .dia.vacio-dia { background: transparent; border: 0; }
.calendario .dia.con-valor { background: var(--brand-soft); }

/* Login */
.login {
  min-height: 100dvh; display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 24px 18px calc(24px + var(--safe-bottom));
  background: radial-gradient(1200px 600px at 50% -10%, #d9e9fb 0%, var(--bg) 60%);
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) .login { background: radial-gradient(1200px 600px at 50% -10%, #14263d 0%, var(--bg) 60%); }
}
.login .panel { width: 100%; max-width: 400px; }
.login .logo { width: 220px; margin: 0 auto 22px; border-radius: 14px; }
.login .card { padding: 22px 18px; }
.login h1 { font-size: 1.2rem; margin-bottom: 4px; }
.login .pie { text-align: center; font-size: .76rem; color: var(--muted); margin-top: 18px; }

/* Pantalla de carga mientras se conecta el circuito */
.splash { position: fixed; inset: 0; display: grid; place-items: center; background: var(--bg); z-index: 5; }
.splash .spinner { width: 36px; height: 36px; }
body:has(.app) .splash { display: none; }

/* Reconexión (Blazor) */
#components-reconnect-modal { display: none; }
#components-reconnect-modal.components-reconnect-show,
#components-reconnect-modal.components-reconnect-failed,
#components-reconnect-modal.components-reconnect-rejected,
#components-reconnect-modal.components-reconnect-retrying {
  display: flex; position: fixed; inset: 0; z-index: 100;
  align-items: flex-end; justify-content: center; padding: 16px;
  background: rgba(15, 23, 42, .35);
}
#components-reconnect-modal .caja {
  width: 100%; max-width: 420px; background: var(--surface); color: var(--ink);
  border-radius: 16px; padding: 16px; box-shadow: var(--shadow-lg);
  display: flex; align-items: center; gap: 12px; margin-bottom: calc(var(--safe-bottom) + 8px);
}
#components-reconnect-modal .msg-fallo { display: none; }
#components-reconnect-modal.components-reconnect-failed .msg-conectando,
#components-reconnect-modal.components-reconnect-rejected .msg-conectando { display: none; }
#components-reconnect-modal.components-reconnect-failed .msg-fallo,
#components-reconnect-modal.components-reconnect-rejected .msg-fallo { display: flex; }

#blazor-error-ui {
  display: none; position: fixed; left: 16px; right: 16px; z-index: 90;
  bottom: calc(var(--nav-h) + var(--safe-bottom) + 12px);
  background: var(--bad); color: #fff; padding: 12px 16px; border-radius: 12px; box-shadow: var(--shadow-lg);
}
#blazor-error-ui a { color: #fff; font-weight: 700; margin-left: 8px; text-decoration: underline; }
#blazor-error-ui .dismiss { float: right; cursor: pointer; }

/* Impresión de reportes */
@media print {
  .topbar, .bottom-nav, .side-nav, .fab, .chips, .no-print, .toast-zona { display: none !important; }
  body { background: #fff; }
  .app { display: block; }
  .contenido { padding: 0; max-width: none; }
  .card, .lista, .tabla-wrap { box-shadow: none; break-inside: avoid; }
}

/* Columnas (GraficoColumnas.razor) */
.col-chart { position: relative; user-select: none; }
.cc-body { display: grid; grid-template-columns: 46px minmax(0, 1fr); height: var(--alto); }
.cc-y { position: relative; }
.cc-y span {
  position: absolute; right: 8px; transform: translateY(50%);
  font-size: 10.5px; line-height: 1; color: var(--axis-ink); font-variant-numeric: tabular-nums; white-space: nowrap;
}
.cc-plot { position: relative; }
.cc-grid { position: absolute; left: 0; right: 0; height: 1px; background: var(--grid); }
.cc-grid.base { background: var(--axis); }
.cc-cols { position: absolute; inset: 0; display: flex; align-items: flex-end; gap: 2px; }
.cc-col {
  flex: 1 1 0; min-width: 0; height: 100%; padding: 0; border: 0; background: none; cursor: pointer;
  display: flex; align-items: flex-end; justify-content: center;
}
.cc-bar {
  display: block; width: min(24px, 76%); min-width: 2px;
  background: var(--series-1); border-radius: 4px 4px 0 0; transition: opacity .12s;
}
.cc-bar.dim { opacity: .35; }
.cc-x { position: relative; height: 22px; margin-left: 46px; }
.cc-x span {
  position: absolute; top: 6px; transform: translateX(-50%);
  font-size: 10.5px; color: var(--axis-ink); white-space: nowrap; font-variant-numeric: tabular-nums;
}
.col-chart .tip {
  position: absolute; top: -6px; transform: translate(-50%, -100%);
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: 10px;
  box-shadow: var(--shadow-lg); padding: 7px 10px; pointer-events: none;
  font-size: .78rem; white-space: nowrap; z-index: 3;
}
.col-chart .tip strong { display: block; font-size: .95rem; }
.col-chart .tip span { color: var(--ink-2); }
.cc-vacio { display: grid; place-items: center; color: var(--muted); font-size: .86rem; background: var(--surface-2); border-radius: 12px; }

.ico-inline { width: 16px; height: 16px; flex: none; }

/* Dashboard */
.dash { display: flex; flex-direction: column; gap: 12px; }
.dash-2col { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; }
@media (min-width: 900px) { .dash-2col { grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; } }
a.card { color: inherit; display: block; }
a.card:hover { border-color: var(--border-strong); }
.lista-plana { border: 0; border-radius: 0; margin: 0 -16px -16px; border-top: 1px solid var(--border); }
.girando { animation: gira .9s linear infinite; }

/* Ventas */
.resumen-ventas { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 4px; padding: 14px 16px; }
.resumen-ventas .total { font-size: 1.45rem; font-weight: 700; letter-spacing: -.01em; }
.venta-total { font-size: 2rem; font-weight: 700; letter-spacing: -.02em; }
.item-producto { align-items: flex-start; }
.item-producto .principal span.pack { white-space: normal; }
.detalle-venta { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; }
@media (min-width: 900px) { .detalle-venta { grid-template-columns: minmax(0, 5fr) minmax(0, 6fr); align-items: start; } }

/* Reporte */
.link-btn { background: none; border: 0; padding: 0; color: var(--brand); font-weight: 600; font-size: .86rem; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; align-self: flex-start; }
@media (max-width: 520px) {
  .reporte-config { grid-template-columns: minmax(0, 1fr); }
  .reporte-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .reporte-kpis > :first-child { grid-column: 1 / -1; }
}
.segmented button:disabled { opacity: .45; cursor: not-allowed; }

/* Caja */
.caja-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; }
@media (min-width: 900px) { .caja-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; } }
details.conteo { margin-top: 12px; border-top: 1px solid var(--border); padding-top: 10px; }
details.conteo summary { cursor: pointer; font-weight: 600; font-size: .86rem; color: var(--brand); }
.item .monto .good, .kv .good, .kv .total.good { color: var(--good-ink); }
.item .monto .bad, .kv .bad, .kv .total.bad { color: var(--bad-ink); }
.item .monto .warn { color: var(--warn-ink); }

/* Caja General */
.saldos { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.saldos .principal-saldo { grid-column: 1 / -1; }
@media (min-width: 900px) { .saldos { grid-template-columns: 2fr 1fr 1fr 1fr; } .saldos .principal-saldo { grid-column: auto; } }
.accesos { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
@media (min-width: 700px) { .accesos { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.acceso { display: flex; flex-direction: column; gap: 10px; padding: 14px; color: inherit; }
.acceso .ico-circ { width: 40px; height: 40px; }
.acceso strong { font-size: .92rem; }
.acceso span.small { color: var(--muted); }
.acciones-rapidas { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.acciones-rapidas .btn { flex-direction: column; height: auto; padding: 12px 6px; gap: 6px; font-size: .8rem; }
.item .principal .uso { display: block; height: 6px; border-radius: 3px; background: var(--surface-3); overflow: hidden; margin-top: 6px; max-width: 220px; }
.item .principal .uso > span { display: block; height: 100%; background: var(--series-1); border-radius: 0 3px 3px 0; }
.mov-saldo { font-size: .74rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.fila-retiro .principal strong::after { content: " · retiro"; color: var(--warn-ink); font-weight: 600; font-size: .78rem; }
.totales-tres { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.totales-tres .stat .valor { font-size: 1.02rem; }
.mes-nav { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.mes-nav h2 { font-size: 1.05rem; }

/* Totales de tres columnas: en celular pasan a filas para que los montos no se corten */
@media (max-width: 560px) {
  .totales-tres {
    grid-template-columns: minmax(0, 1fr); gap: 0;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
    overflow: hidden;
  }
  .totales-tres > .card {
    display: flex; align-items: baseline; justify-content: space-between; gap: 12px;
    border: 0; border-bottom: 1px solid var(--border); border-radius: 0; box-shadow: none; padding: 10px 14px;
  }
  .totales-tres > .card:last-child { border-bottom: 0; }
  .totales-tres .stat .valor { margin-top: 0; font-size: 1rem; }
}
/* Espacio para que el botón flotante no tape el último elemento */
main.contenido:has(.fab) { padding-bottom: calc(var(--nav-h) + var(--safe-bottom) + 96px); }
@media (min-width: 960px) { main.contenido:has(.fab) { padding-bottom: 110px; } }

/* Almacén */
.prod-thumb { width: 44px; height: 44px; flex: none; border-radius: 10px; object-fit: contain; background: #fff; border: 1px solid var(--border); }
.prod-foto { display: block; max-width: 100%; max-height: 200px; margin: 0 auto 6px; object-fit: contain; border-radius: 12px; background: #fff; }
.ficha-producto { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; }
@media (min-width: 900px) { .ficha-producto { grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; } }
