/* =====================================================================
   Panel del hogar — estilos
   Móvil primero. Tokens en :root, tema oscuro por prefers-color-scheme
   y por data-theme en <html>. Sin dependencias.
   body[data-module="inicio|super|familia|artec"] decide qué barra lateral/inferior se ve.
   ===================================================================== */

/* ---------- Tokens ---------- */
:root {
  --bg: #f3f5f3;
  --surface: #ffffff;
  --surface-2: #eaeeea;
  --surface-3: #dfe5df;
  --border: #dbe1db;
  --text: #17201a;
  --text-muted: #5f6b64;
  --text-faint: #93a097;

  --accent: #15803d;
  --accent-strong: #166534;
  --accent-soft: #dcfce7;
  --on-accent: #ffffff;

  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --warning: #d97706;
  --warning-soft: #fef3c7;

  /* Acento del módulo Artec (azul acero, sutil: solo icono del módulo y marca) */
  --artec: #2f5f8a;
  --artec-soft: #dde9f3;

  --chart-1: #15803d;
  --chart-2: #0e7490;
  --chart-3: #b45309;
  --chart-4: #6d28d9;
  --chart-5: #be185d;
  --chart-6: #4d7c0f;
  --chart-7: #1d4ed8;
  --chart-8: #78716c;

  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .05), 0 4px 16px rgba(0, 0, 0, .05);
  --shadow-lg: 0 12px 40px rgba(0, 0, 0, .18);
  --focus: 0 0 0 3px color-mix(in srgb, var(--accent) 35%, transparent);

  --tabbar-h: 62px;
  --topbar-h: 56px;
  --sidebar-w: 236px;
  --gutter: 16px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1411;
    --surface: #161d19;
    --surface-2: #1d2621;
    --surface-3: #263129;
    --border: #2b3730;
    --text: #e7ede8;
    --text-muted: #9daba2;
    --text-faint: #66746b;
    --accent: #4ade80;
    --accent-strong: #86efac;
    --accent-soft: #14361f;
    --on-accent: #052e16;
    --danger: #f87171;
    --danger-soft: #3b1212;
    --warning: #fbbf24;
    --warning-soft: #3a2506;
    --artec: #7fb0dc;
    --artec-soft: #15293b;
    --chart-1: #4ade80;
    --chart-2: #22d3ee;
    --chart-3: #fbbf24;
    --chart-4: #a78bfa;
    --chart-5: #f472b6;
    --chart-6: #a3e635;
    --chart-7: #60a5fa;
    --chart-8: #a8a29e;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
    --shadow-lg: 0 12px 40px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0e1411;
  --surface: #161d19;
  --surface-2: #1d2621;
  --surface-3: #263129;
  --border: #2b3730;
  --text: #e7ede8;
  --text-muted: #9daba2;
  --text-faint: #66746b;
  --accent: #4ade80;
  --accent-strong: #86efac;
  --accent-soft: #14361f;
  --on-accent: #052e16;
  --danger: #f87171;
  --danger-soft: #3b1212;
  --warning: #fbbf24;
  --warning-soft: #3a2506;
  --artec: #7fb0dc;
  --artec-soft: #15293b;
  --chart-1: #4ade80;
  --chart-2: #22d3ee;
  --chart-3: #fbbf24;
  --chart-4: #a78bfa;
  --chart-5: #f472b6;
  --chart-6: #a3e635;
  --chart-7: #60a5fa;
  --chart-8: #a8a29e;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
  --shadow-lg: 0 12px 40px rgba(0, 0, 0, .5);
  color-scheme: dark;
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  min-height: 100vh;
  overflow-x: hidden;
}
h1, h2, h3, h4 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 1.45rem; }
h2 { font-size: 1.05rem; }
h3 { font-size: .95rem; }
p { margin: 0 0 .75rem; }
a { color: var(--accent-strong); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font: inherit; color: inherit; }
img { max-width: 100%; display: block; }
canvas { max-width: 100%; }
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.sr-only { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.muted { color: var(--text-muted); font-weight: 400; }
.small { font-size: .85rem; }
.mono { font-family: var(--mono); }
.inline { display: inline; }
.text-danger { color: var(--danger); }
.text-success { color: var(--accent-strong); }
.item-icon.success { background: var(--accent-soft); color: var(--accent-strong); }
.alert-mark.down { color: var(--accent-strong); background: var(--accent-soft); }
.text-ok { color: var(--accent); }
.text-warning { color: var(--warning); }
.nowrap { white-space: nowrap; }
.right { text-align: right; }

/* Iconos: siempre monocromos, un solo color (currentColor) */
.icon {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: none;
  vertical-align: middle;
}
.icon-sm { width: 16px; height: 16px; }
.icon-lg { width: 36px; height: 36px; }
.icon-spin { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

:focus-visible { outline: none; box-shadow: var(--focus); }

/* ---------- Layout ---------- */
.app { min-height: 100vh; }
.main {
  padding: var(--gutter);
  padding-top: calc(var(--topbar-h) + var(--gutter));
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px) + 24px);
  max-width: 1180px;
  margin: 0 auto;
}
.tab > * + * { margin-top: 16px; }
[data-overview] > * + *, [data-budget-kpis] > * + * { margin-top: 16px; }
.tab[hidden] { display: none; }
[hidden] { display: none !important; }

.brand { display: flex; align-items: center; gap: 10px; color: var(--text); font-weight: 650; }
.brand:hover { text-decoration: none; }
.brand-logo {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: 10px;
  background: var(--accent); color: var(--on-accent);
}
.brand-name { font-size: 1rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Cabecera móvil */
.topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 30;
  height: var(--topbar-h);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 var(--gutter);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.topbar-actions { display: flex; align-items: center; gap: 4px; }

/* Barra inferior móvil (una por módulo; la portada no tiene) */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: none; justify-content: space-around;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px));
  padding: 0 4px env(safe-area-inset-bottom, 0px);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
}
body[data-module="super"] .tabbar[data-tabbar="super"],
body[data-module="familia"] .tabbar[data-tabbar="familia"],
body[data-module="artec"] .tabbar[data-tabbar="artec"] { display: flex; }
.tabbar a, .tabbar button {
  position: relative;
  flex: 1 1 0; min-width: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  padding: 6px 2px; margin: 0;
  background: none; border: 0; cursor: pointer;
  color: var(--text-muted); font-size: .66rem; font-weight: 500;
  border-radius: var(--radius-sm);
}
.tabbar a span:not(.badge), .tabbar button span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.tabbar a:hover { text-decoration: none; }
.tabbar a.active { color: var(--accent-strong); }
.tabbar a .icon, .tabbar button .icon { width: 22px; height: 22px; }
.tabbar .tab-primary .icon {
  width: 40px; height: 40px; padding: 9px; margin-top: -18px;
  background: var(--accent); color: var(--on-accent); border-radius: 50%;
  box-shadow: var(--shadow);
}
.tabbar a .badge { position: absolute; top: 4px; left: calc(50% + 4px); }

/* Portada: sin barra inferior */
body[data-module="inicio"] .main { padding-bottom: 32px; }
body[data-module="inicio"] .toasts { bottom: 16px; }

/* Barra lateral escritorio */
.sidebar { display: none; }
.sidebar .nav { display: none; }
body[data-module="super"] .nav[data-module-nav="super"],
body[data-module="familia"] .nav[data-module-nav="familia"],
body[data-module="artec"] .nav[data-module-nav="artec"] { display: flex; }
/* Artec: la marca del módulo lleva su acento azul acero (el resto de la interfaz no cambia) */
body[data-module="artec"] .brand-logo { background: var(--artec); color: #fff; }
.sidebar-back {
  display: inline-flex; align-items: center; gap: 6px; align-self: flex-start;
  padding: 4px 8px; border-radius: var(--radius-sm);
  color: var(--text-muted); font-size: .85rem; font-weight: 550;
}
.sidebar-back:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.sidebar-back .icon { width: 16px; height: 16px; }

@media (min-width: 900px) {
  .topbar { display: none; }
  .tabbar { display: none !important; }
  .sidebar {
    position: fixed; top: 0; bottom: 0; left: 0; z-index: 30;
    width: var(--sidebar-w);
    display: flex; flex-direction: column; gap: 16px;
    padding: 16px 14px 20px;
    background: var(--surface);
    border-right: 1px solid var(--border);
  }
  .sidebar .brand { padding: 0 8px; }
  .sidebar-brand { margin-top: -6px; }
  .nav { flex-direction: column; gap: 2px; flex: 1; }
  .nav a {
    position: relative;
    display: flex; align-items: center; gap: 12px;
    padding: 10px 12px; border-radius: var(--radius-sm);
    color: var(--text-muted); font-weight: 500;
  }
  .nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
  .nav a.active { background: var(--accent-soft); color: var(--accent-strong); }
  .nav a .badge { margin-left: auto; }
  .sidebar-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 0 4px; }
  .main {
    margin-left: var(--sidebar-w);
    padding: 28px 32px 48px;
    max-width: calc(var(--sidebar-w) + 1180px);
  }
  /* Portada en escritorio: sin barra lateral, con cabecera */
  body[data-module="inicio"] .sidebar { display: none; }
  body[data-module="inicio"] .topbar { display: flex; }
  body[data-module="inicio"] .main { margin-left: 0; max-width: 1180px; padding: calc(var(--topbar-h) + 28px) 32px 48px; }
}

/* ---------- Componentes ---------- */
.page-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
}
.page-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
@media (max-width: 899px) { .hide-mobile { display: none !important; } }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.card + .card { margin-top: 16px; }
.card-title { margin-bottom: 12px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.card-head .card-title { margin-bottom: 0; }
.sub-title { color: var(--text-muted); font-weight: 600; margin-bottom: 8px; font-size: .85rem; text-transform: uppercase; letter-spacing: .04em; }

.grid { display: grid; gap: 16px; }
.grid-2, .grid-3 { grid-template-columns: 1fr; }
.grid-kpi { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.grid-kpi-3 > :nth-child(3) { grid-column: 1 / -1; }
@media (min-width: 720px) {
  .grid-2, .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-kpi { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .grid-kpi-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .grid-kpi-3 > :nth-child(3) { grid-column: auto; }
}
@media (min-width: 1100px) {
  .grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

/* KPI */
.kpi { padding: 14px; }
.kpi-label { display: flex; align-items: center; gap: 6px; color: var(--text-muted); font-size: .78rem; font-weight: 500; }
.kpi-value { font-size: 1.35rem; font-weight: 700; margin-top: 4px; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.kpi-sub { color: var(--text-muted); font-size: .78rem; margin-top: 2px; }
.kpi-delta { display: inline-flex; align-items: center; gap: 4px; }
.kpi-delta.up { color: var(--danger); }
.kpi-delta.down { color: var(--accent); }
.kpi-delta.flat { color: var(--text-muted); }
/* Variantes semánticas (presupuesto familiar: subir ingresos es bueno, subir gastos es malo) */
.kpi-delta.pos { color: var(--accent); }
.kpi-delta.neg { color: var(--danger); }
.kpi-sub .kpi-delta { font-weight: 600; }
.kpi-sub .kpi-delta .icon { width: 13px; height: 13px; }
.kpi-sub .pill { vertical-align: middle; margin-right: 4px; }
@media (min-width: 720px) { .kpi-value { font-size: 1.55rem; } }

/* Botones */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 9px 14px; min-height: 40px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text);
  font-weight: 550; cursor: pointer; text-decoration: none;
  transition: background .15s, border-color .15s, transform .05s;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn-primary:hover { background: var(--accent-strong); border-color: var(--accent-strong); }
.btn-secondary { background: var(--accent-soft); border-color: transparent; color: var(--accent-strong); }
.btn-secondary:hover { background: color-mix(in srgb, var(--accent-soft) 80%, var(--accent)); }
.btn-danger { background: var(--danger-soft); border-color: transparent; color: var(--danger); }
.btn-danger:hover { background: color-mix(in srgb, var(--danger-soft) 80%, var(--danger)); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-icon { padding: 8px; width: 40px; min-width: 40px; }
.btn-sm { padding: 5px 10px; min-height: 32px; font-size: .85rem; }
.btn-sm.btn-icon { width: 32px; min-width: 32px; padding: 5px; }
.btn-block { width: 100%; }
.btn .icon { width: 18px; height: 18px; }

.icon-sun, .icon-moon { display: none; }
html:not([data-theme="dark"]) .icon-moon { display: block; }
html[data-theme="dark"] .icon-sun { display: block; }
@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]):not([data-theme="dark"]) .icon-moon { display: none; }
  html:not([data-theme="light"]):not([data-theme="dark"]) .icon-sun { display: block; }
}

/* Formularios */
.input {
  width: 100%;
  padding: 9px 12px; min-height: 40px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text);
  font: inherit;
}
.input::placeholder { color: var(--text-faint); }
.input:focus { border-color: var(--accent); outline: none; box-shadow: var(--focus); }
.input.is-invalid { border-color: var(--danger); }
select.input { appearance: none; -webkit-appearance: none; padding-right: 30px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23888' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 8px center; background-size: 16px; }
textarea.input { min-height: 72px; resize: vertical; }
.input-month { width: auto; min-width: 150px; }
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field-label { font-size: .82rem; font-weight: 600; color: var(--text-muted); }
.field-help { font-size: .78rem; color: var(--text-faint); }
.form-grid { display: grid; grid-template-columns: 1fr; gap: 14px; margin-bottom: 14px; }
@media (min-width: 720px) { .form-grid { grid-template-columns: 1fr 1fr; } }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
.form-error { display: flex; align-items: center; gap: 8px; color: var(--danger); background: var(--danger-soft); padding: 10px 12px; border-radius: var(--radius-sm); font-size: .9rem; }
.check { display: flex; align-items: flex-start; gap: 10px; cursor: pointer; }
.check input { width: 18px; height: 18px; margin-top: 2px; accent-color: var(--accent); }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.toolbar-group { display: flex; gap: 6px; align-items: center; flex: 1; }
.toolbar-group select { flex: 1; min-width: 140px; }
.search { position: relative; display: flex; align-items: center; flex: 1 1 100%; }
.search .icon { position: absolute; left: 12px; color: var(--text-faint); pointer-events: none; }
.search .input { padding-left: 40px; }
@media (min-width: 720px) {
  .search { flex: 1 1 320px; }
  .toolbar-group { flex: 0 0 auto; }
}

/* Selector de mes */
.month-picker { display: inline-flex; align-items: center; gap: 2px; }

/* Control segmentado (filtros, tipo de movimiento) */
.segmented { display: inline-flex; gap: 2px; padding: 3px; border-radius: var(--radius-sm); background: var(--surface-2); max-width: 100%; }
.segmented button {
  flex: 1 1 auto; min-height: 32px; padding: 5px 12px;
  border: 0; border-radius: 6px; background: transparent; color: var(--text-muted);
  font-weight: 550; font-size: .85rem; cursor: pointer; white-space: nowrap;
  transition: background .15s, color .15s;
}
.segmented button:hover { color: var(--text); }
.segmented button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.segmented-block { display: flex; width: 100%; }
.segmented-block button { min-height: 38px; }

/* Badge */
.badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 999px;
  background: var(--danger); color: #fff;
  font-size: .68rem; font-weight: 700; line-height: 1;
}
.badge[hidden] { display: none; }
.pill {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; border-radius: 999px;
  font-size: .75rem; font-weight: 600;
  background: var(--surface-2); color: var(--text-muted);
}
.pill-danger { background: var(--danger-soft); color: var(--danger); }
.pill-ok { background: var(--accent-soft); color: var(--accent-strong); }
.pill-warning { background: var(--warning-soft); color: var(--warning); }
.pill .icon { width: 13px; height: 13px; }

/* Barra de progreso (presupuesto) */
.progress { height: 10px; border-radius: 999px; background: var(--surface-3); overflow: hidden; }
.progress > span { display: block; height: 100%; border-radius: inherit; background: var(--accent); transition: width .4s ease; }
.progress.warning > span { background: var(--warning); }
.progress.over > span { background: var(--danger); }
.budget-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-bottom: 8px; flex-wrap: wrap; }
.budget-meta { display: flex; justify-content: space-between; gap: 12px; font-size: .82rem; color: var(--text-muted); margin-top: 6px; flex-wrap: wrap; }

/* Listas con barra (top tiendas/categorías) */
.ranked { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.ranked li { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; font-size: .9rem; }
.ranked .ranked-bar { grid-column: 1 / -1; height: 5px; background: var(--surface-3); border-radius: 999px; overflow: hidden; }
.ranked .ranked-bar > span { display: block; height: 100%; background: var(--accent); border-radius: inherit; }
.ranked .ranked-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ranked .ranked-value { font-variant-numeric: tabular-nums; font-weight: 600; }
.ranked .ranked-sub { color: var(--text-muted); font-size: .78rem; }
.ranked .ranked-name { display: flex; align-items: center; gap: 7px; }
.ranked .ranked-name a { display: inline-flex; align-items: center; gap: 3px; color: var(--accent-strong); font-weight: 600; }
.ranked .ranked-name a .icon { width: 14px; height: 14px; }
.ranked .ranked-bar > span.c2 { background: var(--chart-2); }
.ranked .ranked-bar > span.c3 { background: var(--chart-3); }
.ranked li.clickable { cursor: pointer; border-radius: var(--radius-sm); margin: 0 -6px; padding: 4px 6px; transition: background .15s; }
.ranked li.clickable:hover, .ranked li.clickable:focus-visible { background: var(--surface-2); }

/* Gráficos */
.chart-wrap { position: relative; width: 100%; height: 220px; }
.chart-tall { height: 260px; }
.chart-donut { height: 220px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 10px; font-size: .8rem; }
.legend-item { display: inline-flex; align-items: center; gap: 6px; color: var(--text-muted); }
.legend-dot { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.legend-item b { color: var(--text); font-variant-numeric: tabular-nums; }

/* Tablas */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th, .table td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table th { font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); font-weight: 600; background: var(--surface-2); white-space: nowrap; }
.table tbody tr:last-child td { border-bottom: 0; }
.table td.num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table tr.clickable { cursor: pointer; }
.table tr.clickable:hover, .table tr.clickable:focus-visible { background: var(--surface-2); }
.table .cell-main { font-weight: 600; }
.table .cell-sub { color: var(--text-muted); font-size: .8rem; }

/* Tabla → tarjetas en móvil */
@media (max-width: 719px) {
  .table-cards { border: 0; background: transparent; overflow: visible; }
  .table-cards .table, .table-cards tbody, .table-cards tr, .table-cards td { display: block; width: 100%; }
  .table-cards thead { display: none; }
  .table-cards tr {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    margin-bottom: 10px; padding: 6px 12px; box-shadow: var(--shadow);
  }
  .table-cards td { border: 0; padding: 5px 0; display: flex; justify-content: space-between; gap: 12px; text-align: right; }
  .table-cards td.num { text-align: right; }
  .table-cards td::before { content: attr(data-label); color: var(--text-muted); font-size: .75rem; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; flex: none; text-align: left; }
  .table-cards td.cell-title { flex-direction: column; align-items: flex-start; text-align: left; padding-bottom: 8px; border-bottom: 1px solid var(--border); margin-bottom: 4px; }
  .table-cards td.cell-title::before { display: none; }
}

/* Lista de compras (tarjetas) */
.list { display: flex; flex-direction: column; gap: 10px; }
.item-card {
  display: grid; grid-template-columns: auto 1fr auto; gap: 12px; align-items: center;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px 14px; box-shadow: var(--shadow); cursor: pointer; text-align: left; width: 100%;
  transition: background .15s;
}
.item-card:hover, .item-card:focus-visible { background: var(--surface-2); }
.item-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px; border-radius: 10px;
  background: var(--surface-2); color: var(--accent-strong);
}
.item-icon.danger { background: var(--danger-soft); color: var(--danger); }
.item-icon.muted { color: var(--text-muted); }
.item-body { min-width: 0; }
.item-title { display: block; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-title .icon { width: 14px; height: 14px; color: var(--text-faint); margin-left: 4px; }
.item-sub { color: var(--text-muted); font-size: .8rem; display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.item-sub .icon { width: 13px; height: 13px; }
.item-sub + .item-sub { margin-top: 3px; }
.item-right { text-align: right; }
.item-right.stack { display: flex; flex-direction: column; align-items: flex-end; gap: 1px; }
.item-amount { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.item-card.unseen { border-left: 3px solid var(--danger); }
.item-amount.income { color: var(--accent); }
.item-card.current { border-color: var(--accent); }
.item-amount.sm { font-size: .92rem; }

/* Contexto de alerta (misma tienda / otra tienda) */
.alert-ctx .pill { flex: none; }

/* Chips (totales por categoría, listas de solo lectura) */
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chips:empty { display: none; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 10px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text-muted);
  font: inherit; font-size: .8rem; font-weight: 550; cursor: pointer; white-space: nowrap;
  transition: background .15s, color .15s;
}
.chip b { color: var(--text); font-variant-numeric: tabular-nums; }
.chip:hover { background: var(--surface-2); }
.chip.active { background: var(--accent-soft); border-color: transparent; color: var(--accent-strong); }
.chip.active b { color: inherit; }
.chip .icon { width: 13px; height: 13px; }

/* Importe con selector de moneda (modal de movimiento) */
.amount-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: stretch; }
.amount-row .segmented { padding: 3px; }
.amount-row .segmented button { min-height: 32px; padding: 5px 10px; }
.rate-row { display: flex; align-items: center; gap: 8px; }
.rate-prefix { color: var(--text-muted); font-weight: 600; white-space: nowrap; font-size: .9rem; }
.rate-row .input { max-width: 160px; }
.tx-thumb { display: flex; align-items: center; gap: 12px; }
.tx-thumb .small { color: var(--text-muted); }

/* Lista clave-valor (resumen familiar) */
.kv-list { display: flex; flex-direction: column; gap: 6px; }
.kv { display: flex; justify-content: space-between; align-items: center; gap: 12px; font-size: .92rem; }
.kv > span { display: inline-flex; align-items: center; gap: 6px; color: var(--text-muted); }
.kv > span .icon { width: 15px; height: 15px; }
.kv b { font-variant-numeric: tabular-nums; white-space: nowrap; }
.kv-total { border-top: 1px solid var(--border); padding-top: 8px; margin-top: 2px; font-size: 1rem; }
.kv-total b { font-size: 1.1rem; }

/* Ayuda colapsable */
.help-card { padding: 0; }
.help-card summary {
  display: flex; align-items: center; gap: 10px; padding: 14px 16px;
  cursor: pointer; font-weight: 650; list-style: none; border-radius: var(--radius);
}
.help-card summary::-webkit-details-marker { display: none; }
.help-card summary .icon:first-child { color: var(--accent-strong); }
.help-card summary span { flex: 1; }
.help-card .help-chevron { color: var(--text-faint); transition: transform .2s; }
.help-card[open] .help-chevron { transform: rotate(180deg); }
.help-card[open] summary { border-bottom: 1px solid var(--border); }
.help-card > :not(summary) { margin-left: 16px; margin-right: 16px; }
.help-card > ul { margin-top: 14px; }
.help-card > p:last-child { padding-bottom: 14px; }
.help-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.help-list li { display: grid; grid-template-columns: auto 1fr; gap: 12px; align-items: center; font-size: .9rem; color: var(--text-muted); }
.help-list li .item-icon { width: 36px; height: 36px; }
code { font-family: var(--mono); font-size: .85em; color: var(--text); background: var(--surface-2); padding: 2px 6px; border-radius: 6px; white-space: nowrap; }

/* Detalle de compra */
.detail-head { display: grid; grid-template-columns: 1fr auto; gap: 12px; align-items: start; margin-bottom: 12px; }
.detail-meta { display: flex; flex-wrap: wrap; gap: 6px 14px; color: var(--text-muted); font-size: .85rem; }
.detail-meta span { display: inline-flex; align-items: center; gap: 5px; }
.detail-meta .icon { width: 14px; height: 14px; }
.detail-total { font-size: 1.4rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.thumb { width: 72px; height: 72px; object-fit: cover; border-radius: var(--radius-sm); border: 1px solid var(--border); cursor: zoom-in; }
.thumb-btn { padding: 0; border: 0; background: none; cursor: zoom-in; }
.alert-mark { display: inline-flex; align-items: center; gap: 4px; color: var(--danger); font-size: .75rem; font-weight: 600; }
.alert-mark .icon { width: 13px; height: 13px; }
.lightbox { display: flex; align-items: center; justify-content: center; }
.lightbox img { max-height: 80vh; max-width: 100%; border-radius: var(--radius-sm); object-fit: contain; }

/* Estados */
.empty {
  text-align: center; padding: 36px 16px; color: var(--text-muted);
  background: var(--surface); border: 1px dashed var(--border); border-radius: var(--radius);
}
.empty .icon { width: 36px; height: 36px; margin: 0 auto 10px; color: var(--text-faint); }
.empty p { max-width: 380px; margin: 0 auto 12px; }
.skeleton { display: flex; flex-direction: column; gap: 10px; }
.skeleton > span {
  display: block; height: 16px; border-radius: 6px;
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-3) 50%, var(--surface-2) 75%);
  background-size: 200% 100%; animation: shimmer 1.2s infinite;
}
.skeleton > span.tall { height: 120px; }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
.loading-row { display: flex; align-items: center; gap: 10px; color: var(--text-muted); padding: 12px 0; }

/* Aviso */
.notice {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: var(--radius-sm);
  background: var(--surface-2); color: var(--text-muted); font-size: .88rem;
}
.notice .icon { color: var(--accent-strong); }
.notice-warning { background: var(--warning-soft); color: var(--text); }
.notice-warning .icon { color: var(--warning); }
.notice-danger { background: var(--danger-soft); color: var(--text); }
.notice-danger .icon { color: var(--danger); }
.notice-edit { background: var(--accent-soft); color: var(--accent-strong); font-weight: 600; }
.notice-edit .btn { margin-left: auto; }
.notice ul { margin: 0; padding-left: 18px; }

/* Paginación */
.pager { display: flex; align-items: center; justify-content: center; gap: 8px; margin-top: 12px; color: var(--text-muted); font-size: .85rem; }
.pager:empty { display: none; }

/* Toasts */
.toasts {
  position: fixed; z-index: 100;
  left: var(--gutter); right: var(--gutter);
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px) + 12px);
  display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none;
}
.toast {
  display: flex; align-items: center; gap: 10px;
  max-width: 420px; width: 100%;
  padding: 11px 14px; border-radius: var(--radius-sm);
  background: var(--text); color: var(--bg);
  box-shadow: var(--shadow-lg); font-size: .9rem;
  animation: toast-in .2s ease-out; pointer-events: auto;
}
.toast .icon { color: var(--accent); }
.toast-error .icon { color: var(--danger); }
.toast-warning .icon { color: var(--warning); }
.toast.out { opacity: 0; transform: translateY(6px); transition: .25s; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }
@media (min-width: 900px) {
  .toasts { left: auto; right: 24px; bottom: 24px; align-items: flex-end; }
}

/* Modal */
.modal-root:empty { display: none; }
.modal {
  position: fixed; inset: 0; z-index: 80;
  display: flex; align-items: flex-end; justify-content: center;
  background: rgba(0, 0, 0, .5);
  -webkit-backdrop-filter: blur(2px); backdrop-filter: blur(2px);
  animation: fade-in .15s ease-out;
}
.modal-box {
  background: var(--surface); color: var(--text);
  width: 100%; max-height: 92vh;
  border-radius: var(--radius) var(--radius) 0 0;
  box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column;
  animation: slide-up .2s ease-out;
}
.modal-head { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.modal-head h2 { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.modal-body { padding: 16px; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.modal-body > * + * { margin-top: 14px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--border); flex-wrap: wrap; }
.modal-foot .spacer { flex: 1; }
@keyframes fade-in { from { opacity: 0; } }
@keyframes slide-up { from { transform: translateY(24px); } }
@media (min-width: 720px) {
  .modal { align-items: center; padding: 24px; }
  .modal-box { max-width: 560px; border-radius: var(--radius); max-height: 88vh; }
  .modal-box.wide { max-width: 880px; }
}
body.modal-open { overflow: hidden; }

/* Ficha de producto */
.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.stat { background: var(--surface-2); border-radius: var(--radius-sm); padding: 8px 10px; }
.stat-label { font-size: .72rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; }
.stat-value { font-weight: 700; font-variant-numeric: tabular-nums; }
.merge-results { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.merge-results button { text-align: left; justify-content: flex-start; width: 100%; }
.section-title { display: flex; align-items: center; gap: 8px; font-weight: 650; font-size: .95rem; padding-top: 6px; border-top: 1px solid var(--border); }

/* Subir factura */
.dropzone {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  padding: 36px 16px; text-align: center; cursor: pointer;
  border: 2px dashed var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text); transition: border-color .15s, background .15s;
}
.dropzone .icon-lg { color: var(--accent); margin-bottom: 6px; }
.dropzone:hover, .dropzone.drag { border-color: var(--accent); background: var(--accent-soft); }
.upload-actions { display: flex; justify-content: center; margin-top: 10px; }
.upload-preview { display: grid; grid-template-columns: 96px 1fr; gap: 14px; align-items: center; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; }
.upload-preview img { width: 96px; height: 96px; object-fit: cover; border-radius: var(--radius-sm); border: 1px solid var(--border); cursor: zoom-in; }
.upload-status { display: flex; align-items: center; gap: 10px; color: var(--text-muted); }
.upload-status.error { color: var(--danger); }

/* Borrador (formulario de compra) */
.draft-lines { display: flex; flex-direction: column; gap: 10px; }
.line-head { display: none; }
.line {
  display: grid; gap: 8px;
  grid-template-columns: 1fr 1fr;
  background: var(--surface-2); border-radius: var(--radius-sm); padding: 10px;
}
.line .field { gap: 3px; }
.line .field-label { font-size: .72rem; }
.line .f-name { grid-column: 1 / -1; }
.line .f-total .input { background: transparent; border-style: dashed; font-weight: 600; }
.line .f-remove { grid-column: 1 / -1; display: flex; justify-content: flex-end; }
.line .input { min-height: 36px; padding: 6px 10px; font-size: .9rem; }
@media (min-width: 900px) {
  .line-head, .line {
    display: grid; align-items: end;
    grid-template-columns: minmax(160px, 2.2fr) minmax(90px, 1fr) minmax(70px, .8fr) minmax(120px, 1.2fr) 70px 100px 110px 36px;
    gap: 6px;
  }
  .line-head { padding: 0 10px; font-size: .72rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; }
  .line { padding: 6px 10px; background: transparent; border-bottom: 1px solid var(--border); border-radius: 0; }
  .line .field-label { display: none; }
  .line .f-name, .line .f-remove { grid-column: auto; }
  .draft-lines { gap: 0; }
}
.draft-sum { display: flex; flex-wrap: wrap; gap: 6px 18px; align-items: center; font-size: .9rem; margin-top: 12px; padding: 10px 12px; border-radius: var(--radius-sm); background: var(--surface-2); }
.draft-sum b { font-variant-numeric: tabular-nums; }
.draft-sum.mismatch { background: var(--warning-soft); }
.draft-sum .btn { margin-left: auto; }
.result-alerts { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.result-alerts li { display: flex; justify-content: space-between; gap: 10px; padding: 8px 10px; border-radius: var(--radius-sm); background: var(--danger-soft); font-size: .88rem; }

/* Comparar meses */
.compare-form { display: grid; grid-template-columns: 1fr auto 1fr; gap: 8px; align-items: end; margin-bottom: 14px; }
.compare-form .btn { grid-column: 1 / -1; }
.compare-vs { display: flex; align-items: center; justify-content: center; color: var(--text-faint); padding-bottom: 10px; }
@media (min-width: 720px) {
  .compare-form { grid-template-columns: 1fr auto 1fr auto; }
  .compare-form .btn { grid-column: auto; }
}
.compare-summary { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-bottom: 14px; }
.diff-pos { color: var(--danger); }
.diff-neg { color: var(--accent); }
.diff-zero { color: var(--text-muted); }

/* Usuarios */
.user-row { display: grid; grid-template-columns: auto 1fr; gap: 10px 12px; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--border); }
.user-row:last-child { border-bottom: 0; }
.user-row .user-actions { grid-column: 1 / -1; display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.user-row .input { max-width: 240px; }
.user-row.inactive .item-title { color: var(--text-muted); text-decoration: line-through; }
@media (min-width: 720px) {
  .user-row { grid-template-columns: auto 1fr auto; }
  .user-row .user-actions { grid-column: auto; }
}

/* ---------- Portada ---------- */
/* Tres accesos: apilados en móvil, 2+1 en tablet (la tercera ocupa la fila entera), tres columnas en escritorio */
.home { display: grid; gap: 16px; }
@media (min-width: 720px) {
  .home { grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: stretch; }
  .home > .card:nth-child(3) { grid-column: 1 / -1; }
}
@media (min-width: 1100px) {
  .home { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .home > .card:nth-child(3) { grid-column: auto; }
}
/* Las tarjetas nacen a la misma altura y miden lo mismo (anula el margen genérico entre tarjetas). */
.home > .card { margin-top: 0; }
.home-icon.artec { background: var(--artec-soft); color: var(--artec); }

/* Estado de resultados (portada y Resumen de Artec): cuatro cifras en fila, 2×2 en móvil */
.statement-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.statement-head .card-title { display: flex; align-items: center; gap: 8px; }
.statement-head .card-title .icon { color: var(--artec); }
.statement-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
@media (min-width: 720px) { .statement-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.statement-cell {
  display: flex; flex-direction: column; gap: 2px; min-width: 0;
  padding: 10px 12px; border-radius: var(--radius-sm); background: var(--surface-2);
}
.statement-label { display: flex; align-items: center; gap: 5px; color: var(--text-muted); font-size: .74rem; font-weight: 600; }
.statement-label .icon { width: 14px; height: 14px; }
.statement-value { font-size: 1.1rem; font-weight: 700; letter-spacing: -.01em; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.statement-note { color: var(--text-muted); font-size: .74rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.statement-cell.result.pos { background: var(--accent-soft); }
.statement-cell.result.pos .statement-value, .statement-cell.result.pos .statement-label { color: var(--accent-strong); }
.statement-cell.result.neg { background: var(--danger-soft); }
.statement-cell.result.neg .statement-value, .statement-cell.result.neg .statement-label { color: var(--danger); }
.statement-formula { margin: 10px 0 0; color: var(--text-faint); font-size: .76rem; }
@media (min-width: 720px) { .statement-value { font-size: 1.3rem; } }

/* Canal de un ingreso (pill en filas y mini-listas) */
.pill-channel { background: var(--artec-soft); color: var(--artec); }
.mini-sub .pill { vertical-align: middle; padding: 0 6px; font-size: .68rem; }
.home-card { position: relative; padding: 0; overflow: hidden; transition: border-color .15s, box-shadow .15s; display: flex; flex-direction: column; }
.home-card .home-summary { flex: 1; }
.home-head { align-items: flex-start; }
.home-family { text-transform: uppercase; letter-spacing: .12em; font-size: .78rem; font-weight: 650; color: var(--accent-strong); margin-top: 4px; }
.home-card:hover { border-color: var(--accent); box-shadow: var(--shadow-lg); }
.home-card-link {
  display: grid; grid-template-columns: auto 1fr auto; gap: 14px; align-items: center;
  padding: 18px 16px; color: var(--text);
}
.home-card-link:hover { text-decoration: none; }
/* Toda la tarjeta es pulsable: el enlace se extiende con un pseudoelemento */
.home-card-link::after { content: ''; position: absolute; inset: 0; }
.home-card-link:focus-visible { box-shadow: none; }
.home-card:has(.home-card-link:focus-visible) { box-shadow: var(--focus); }
.home-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 54px; height: 54px; border-radius: 14px;
  background: var(--accent-soft); color: var(--accent-strong);
}
.home-icon .icon { width: 28px; height: 28px; }
.home-card-text { min-width: 0; }
.home-card-title { display: block; font-size: 1.15rem; font-weight: 650; letter-spacing: -.01em; }
.home-card-desc { display: block; color: var(--text-muted); font-size: .88rem; margin-top: 2px; }
.home-card-arrow { color: var(--text-faint); }
/* Acceso destacado al chat (portada, bajo el estado de resultados) */
.home-chat {
  display: grid; grid-template-columns: auto 1fr auto; gap: 14px; align-items: center;
  padding: 14px 16px; color: var(--text);
  border-color: color-mix(in srgb, var(--accent) 40%, var(--border));
  background: linear-gradient(135deg, color-mix(in srgb, var(--accent-soft) 55%, var(--surface)), var(--surface));
  transition: border-color .15s, box-shadow .15s;
}
.home-chat:hover { text-decoration: none; border-color: var(--accent); box-shadow: var(--shadow-lg); }
.home-chat .home-icon { background: var(--accent); color: var(--on-accent); }
.home-chat-text { min-width: 0; }
.home-chat-title { display: block; font-size: 1.05rem; font-weight: 650; letter-spacing: -.01em; }
.home-chat-desc { display: block; color: var(--text-muted); font-size: .85rem; margin-top: 2px; }
.home-summary { border-top: 1px solid var(--border); padding: 14px 16px 16px; }
.home-summary > * + * { margin-top: 12px; }
.home-summary-head {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  color: var(--text-muted); font-size: .75rem; font-weight: 600; text-transform: uppercase; letter-spacing: .04em;
}
.home-summary .kv-list { gap: 5px; }
.home-summary .kv { font-size: .9rem; }
.home-summary .progress { height: 8px; }
.home-summary .budget-meta { margin-top: 4px; font-size: .78rem; }
.home-sub-title { color: var(--text-muted); font-size: .78rem; font-weight: 600; margin: 12px 0 6px; }
.mini-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.mini-list li { display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center; font-size: .9rem; }
.mini-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 30px; height: 30px; border-radius: 8px;
  background: var(--surface-2); color: var(--text-muted);
}
.mini-icon .icon { width: 16px; height: 16px; }
.mini-icon.income { color: var(--accent-strong); }
.mini-body { min-width: 0; }
.mini-title { display: block; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mini-sub { display: block; color: var(--text-muted); font-size: .78rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mini-amount { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.mini-amount.income { color: var(--accent); }
.mini-amount .small { display: block; font-weight: 500; color: var(--text-muted); }
.home-empty { display: flex; align-items: center; gap: 8px; margin: 0; color: var(--text-muted); font-size: .88rem; }
.home-empty .icon { color: var(--text-faint); }

/* ---------- Login ---------- */
.login-body { display: flex; flex-direction: column; min-height: 100vh; background: var(--bg); }
.login { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: var(--gutter); }
.login-card {
  width: 100%; max-width: 380px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 18px;
  box-shadow: var(--shadow); padding: 28px 24px;
}
.login-brand { text-align: center; margin-bottom: 22px; }
.login-logo {
  display: inline-flex; align-items: center; justify-content: center;
  width: 56px; height: 56px; border-radius: 16px; margin-bottom: 12px;
  background: var(--accent); color: var(--on-accent);
}
.login-logo .icon { width: 28px; height: 28px; }
.login-brand h1 { font-size: 1.3rem; }
.login-sub { color: var(--text-muted); margin: 4px 0 0; font-size: .9rem; }
.login-form { display: flex; flex-direction: column; gap: 14px; }
.input-code { text-align: center; font-size: 1.6rem; letter-spacing: .4em; font-family: var(--mono); padding: 12px; }
.login-foot { color: var(--text-faint); font-size: .8rem; margin-top: 18px; text-align: center; }

/* Reducir movimiento */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* Franja de resumen en Compras */
.compras-summary { margin-bottom: 14px; }
.compras-summary-row { display: grid; grid-template-columns: 1fr 1.2fr; gap: 16px; align-items: center; }
.compras-kpi { display: flex; flex-direction: column; }
.compras-budget { display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.compras-budget .progress { width: 100%; }
.compras-budget .budget-meta { width: 100%; }
@media (max-width: 720px) {
  .compras-summary-row { grid-template-columns: 1fr; gap: 12px; }
}

/* ---------- Cuentas de banco (portada) ---------- */
/* Lista de cuentas + grupo "Prestado a terceros"; totales debajo en móvil y a la derecha en escritorio */
.accounts .card-title { display: flex; align-items: center; gap: 8px; margin-bottom: 0; }
.accounts .card-title .icon { color: var(--artec); }
.accounts-body { display: grid; gap: 14px; }
.acct-list { display: flex; flex-direction: column; min-width: 0; }
.acct-row {
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 12px; align-items: center;
  width: 100%; padding: 10px 6px; margin: 0;
  border: 0; border-bottom: 1px solid var(--border); border-radius: var(--radius-sm);
  background: none; color: inherit; font: inherit; text-align: left; cursor: pointer;
  transition: background .15s;
}
.acct-list > .acct-row:last-child { border-bottom: 0; }
.acct-row:hover, .acct-row:focus-visible { background: var(--surface-2); }
.acct-row .mini-icon.loan { color: var(--warning); background: var(--warning-soft); }
.acct-balance { display: flex; flex-direction: column; align-items: flex-end; gap: 1px; text-align: right; white-space: nowrap; }
.acct-balance b { font-size: 1.05rem; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.acct-balance .small { color: var(--text-muted); font-variant-numeric: tabular-nums; }
.acct-group {
  display: flex; align-items: center; gap: 6px;
  color: var(--text-muted); font-size: .75rem; font-weight: 600; text-transform: uppercase; letter-spacing: .04em;
  padding: 12px 6px 4px;
}
.acct-totals { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.acct-total { display: flex; flex-direction: column; gap: 2px; min-width: 0; padding: 10px 12px; border-radius: var(--radius-sm); background: var(--surface-2); }
.acct-total.main { background: var(--accent-soft); }
.acct-total.main .acct-total-label, .acct-total.main .acct-total-value { color: var(--accent-strong); }
.acct-total-label { display: flex; align-items: center; gap: 5px; color: var(--text-muted); font-size: .74rem; font-weight: 600; }
.acct-total-label .icon { width: 14px; height: 14px; }
.acct-total-value { font-size: 1.1rem; font-weight: 700; letter-spacing: -.01em; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.acct-total-note { color: var(--text-muted); font-size: .74rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.acct-rate { grid-column: 1 / -1; display: flex; align-items: center; gap: 5px; flex-wrap: wrap; color: var(--text-faint); font-size: .76rem; }
@media (min-width: 720px) {
  .accounts-body { grid-template-columns: minmax(0, 1fr) 280px; align-items: start; }
  .acct-totals { grid-template-columns: 1fr; }
  .acct-total-value { font-size: 1.3rem; }
}

/* ---------- MDI (Artec): reparto de referencia por porcentajes ---------- */
.page-title-sub { display: block; color: var(--text-muted); font-size: .9rem; font-weight: 500; letter-spacing: 0; }
@media (min-width: 720px) { .page-title-sub { display: inline; margin-left: 2px; } }
.mdi-base-grid { display: grid; gap: 14px; }
@media (min-width: 720px) { .mdi-base-grid { grid-template-columns: 1fr 1fr; align-items: start; } }
.mdi-amount-row { display: flex; align-items: center; gap: 8px; }
.mdi-amount-row .input { flex: 1; min-width: 0; }
.mdi-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.mdi-row { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 5px 10px; align-items: center; }
.mdi-row .legend-dot { width: 12px; height: 12px; }
.mdi-name { display: flex; flex-direction: column; min-width: 0; }
.mdi-name-line { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.mdi-name-line b { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mdi-hint { color: var(--text-muted); font-size: .78rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mdi-pct { flex: none; font-size: .78rem; font-weight: 600; color: var(--text-muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.mdi-amount { font-size: 1.05rem; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; text-align: right; }
.mdi-bar { grid-column: 2 / -1; height: 6px; background: var(--surface-3); border-radius: 999px; overflow: hidden; }
.mdi-bar > span { display: block; height: 100%; border-radius: inherit; background: var(--accent); transition: width .4s ease; }
.mdi-adjust { padding: 14px 0 16px; }
.mdi-adj { display: grid; grid-template-columns: minmax(0, 1fr) 118px; gap: 10px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--border); cursor: text; }
.mdi-adj:last-of-type { border-bottom: 0; }
.mdi-adj-name { display: flex; flex-direction: column; min-width: 0; }
.mdi-adj-name b { font-weight: 600; }
.mdi-adj-name small { color: var(--text-muted); }
.mdi-adj-input { display: flex; align-items: center; gap: 6px; }
.mdi-adj-input .input { text-align: right; min-height: 36px; padding: 6px 10px; }
.mdi-adj-input span { color: var(--text-muted); font-weight: 600; }
.mdi-sum { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-weight: 650; margin-top: 12px; font-variant-numeric: tabular-nums; }
.mdi-sum.ok { color: var(--accent-strong); }
.mdi-sum.err { color: var(--danger); }
.mdi-sum .icon { width: 16px; height: 16px; }

/* Portada: la tarjeta de cuentas va debajo de los tres accesos */
#tab-inicio .accounts { margin-top: 16px; }

/* Personas: alta con código */
.user-add { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border); }
.user-add-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 6px; }
.user-add-row .input { flex: 1 1 160px; }
.input-code { max-width: 150px; font-variant-numeric: tabular-nums; }

/* ---------- Login: colores del logo (morado de fondo, verde de acción) ---------- */
.login-body { --brand-purple: #5432ee; --brand-green: #32f595; background: var(--brand-purple) !important; color-scheme: light; }
.login-body .login { background: radial-gradient(120% 80% at 50% 0%, rgba(255,255,255,.10) 0%, rgba(255,255,255,0) 60%); }
.login-body .login-card { background: #ffffff; color: #1b1b2a; border: 0; box-shadow: 0 24px 60px rgba(20, 10, 90, .35); }
.login-logo-img { display: block; width: 104px; height: 104px; margin: -4px auto 10px; border-radius: 26px; box-shadow: 0 10px 24px rgba(84,50,238,.35); }
.login-body .login-brand h1 { color: var(--brand-purple); font-size: 1.45rem; letter-spacing: -.01em; }
.login-body .login-sub { color: #5b5b74; }
.login-body .field-label { color: #3a3a52; }
.login-body .input { background: #f6f5ff; border-color: #dcd8fb; color: #1b1b2a; }
.login-body .input:focus { border-color: var(--brand-purple); box-shadow: 0 0 0 3px rgba(84,50,238,.18); }
.login-body .field-help { color: #7a7a90; }
.login-body .btn-primary { background: var(--brand-green); border-color: var(--brand-green); color: #0b2a1a; font-weight: 700; }
.login-body .btn-primary:hover { background: #2fd97f; border-color: #2fd97f; }
.login-body .form-error { color: #b4232c; background: #fde8ea; }
.login-body .login-foot { color: rgba(255,255,255,.75); }
@media (max-width: 480px) {
  .login-body .login-card { border-radius: 22px; }
  .login-logo-img { width: 92px; height: 92px; border-radius: 22px; }
}

/* Botón "+" global en la cabecera */
.quick-add { gap: 6px; padding-inline: 12px; }
@media (max-width: 720px) { .quick-add span { display: none; } .quick-add { padding-inline: 10px; } }
.quick-add-grid { display: grid; gap: 10px; }
@media (min-width: 560px) { .quick-add-grid { grid-template-columns: 1fr 1fr; } }
.quick-add-opt { display: flex; align-items: center; gap: 12px; text-align: left; padding: 14px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-2); color: var(--text); cursor: pointer; transition: border-color .15s, background .15s; }
.quick-add-opt:hover { border-color: var(--accent); background: var(--surface); }
.quick-add-icon { display: inline-flex; align-items: center; justify-content: center; width: 44px; height: 44px; border-radius: 12px; background: var(--accent-soft); color: var(--accent-strong); flex: 0 0 auto; }
.quick-add-icon .icon { width: 22px; height: 22px; }
.quick-add-icon--artec { background: var(--artec-soft, var(--accent-soft)); color: var(--artec, var(--accent-strong)); }
.quick-add-icon--income { background: var(--accent-soft); color: var(--accent-strong); }
.quick-add-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.quick-add-text small { color: var(--text-muted); font-size: .8rem; }
