/* ================================================================
   Mangos — sistema visual
   Tinta petróleo sobre papel frío. Dualidad de monedas:
   celeste = ARS · verde dólar = USD. Cifras en mono (Spline Sans Mono),
   voz de la interfaz en Archivo (Omnibus-Type, Buenos Aires).
   ================================================================ */

:root {
  color-scheme: light dark;

  --ink: #1c2b3a;
  --ink-soft: #45566a;
  --ink-faint: #7d8b9c;
  --paper: #eef1f0;
  --surface: #ffffff;
  --line: #d9dfe3;
  --line-soft: #e8ecee;
  --hover: #f7f9f8;
  --pizarra: #1c2b3a;       /* el ticker/hinge son oscuros en ambos temas */

  --ars: #2f6fa7;
  --ars-bg: #e3eef7;
  --usd: #2e7d5b;
  --usd-bg: #e2f0e9;

  --accent: #2854d6;        /* el "blue" */
  --accent-soft: rgba(40, 84, 214, .12);
  --danger: #b4443c;
  --danger-bg: #f7e7e5;
  --warn: #a8721f;
  --warn-bg: #f8efdd;
  --ok: #2e7d5b;
  --ok-bg: #e2f0e9;

  --radius: 10px;
  --radius-lg: 16px;
  --shadow: 0 1px 2px rgba(28, 43, 58, .06), 0 4px 16px rgba(28, 43, 58, .05);
  --font: "Archivo", system-ui, sans-serif;
  --mono: "Spline Sans Mono", ui-monospace, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --ink: #e6ecf2;
    --ink-soft: #a9b6c4;
    --ink-faint: #76848f;
    --paper: #10161d;
    --surface: #1a222c;
    --line: #2b3644;
    --line-soft: #232d39;
    --hover: #1f2934;

    --ars: #7db3e0;
    --ars-bg: #1d3a52;
    --usd: #6cc59c;
    --usd-bg: #17362a;

    --accent: #7c9aff;
    --accent-soft: rgba(124, 154, 255, .14);
    --danger: #e0837b;
    --danger-bg: #3a2321;
    --warn: #d9a856;
    --warn-bg: #382e1b;
    --ok: #6cc59c;
    --ok-bg: #17362a;

    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------- Shell: sidebar + contenido ---------- */
.shell { display: grid; grid-template-columns: 224px minmax(0, 1fr); min-height: 100vh; }

.sidebar {
  border-right: 1px solid var(--line);
  background: var(--surface);
  padding: 22px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.wordmark {
  font-weight: 900;
  font-size: 26px;
  letter-spacing: -0.03em;
  color: var(--ink);
  padding: 0 10px 18px;
}
.wordmark em { font-style: normal; color: var(--accent); }
.wordmark:hover { text-decoration: none; }

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: var(--radius);
  color: var(--ink-soft);
  font-weight: 500;
}
.nav-link svg { width: 18px; height: 18px; flex: none; }
.nav-link:hover { background: var(--paper); text-decoration: none; color: var(--ink); }
.nav-link.active { background: var(--ink); color: var(--paper); }

.sidebar .spacer { flex: 1; }

.sidebar-user {
  border-top: 1px solid var(--line-soft);
  padding: 12px 10px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  color: var(--ink-soft);
  font-weight: 600;
}

/* ---------- Contenido ---------- */
/* min-width:0 — como item de grid, las tablas internas no deben inflar su
   ancho mínimo; scrollean dentro de .table-wrap */
.main { padding: 22px 30px 60px; max-width: 1060px; width: 100%; margin: 0 auto; min-width: 0; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}
.topbar h1 {
  margin: 0;
  font-size: 24px;
  font-weight: 800;
  letter-spacing: -0.02em;
}
.topbar-side { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

/* Ticker del blue: pizarra de cueva */
.ticker {
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
  background: var(--pizarra);
  color: #cfe3f5;
  border-radius: 999px;
  padding: 6px 14px;
  font-family: var(--mono);
  font-size: 13px;
  white-space: nowrap;
}
.ticker .label { font-family: var(--font); font-weight: 800; font-size: 11px; letter-spacing: .14em; color: #8fb8dd; }
.ticker .value { font-weight: 600; font-size: 15px; color: #fff; }
.ticker .sub { color: #8fa4b8; font-size: 11px; }

/* ---------- Componentes base ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 20px;
}
.card + .card, .stack > * + * { margin-top: 16px; }

.card-title {
  margin: 0 0 14px;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

/* minmax(0,1fr): las tablas internas no deben forzar el ancho de la columna */
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.grid-2 > *, .grid-3 > *, .stat-cards > * { min-width: 0; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 10px 18px;
  font: 600 14px var(--font);
  cursor: pointer;
  background: var(--ink);
  color: var(--paper);
  text-decoration: none;
  transition: filter .12s ease;
}
.btn:hover { filter: brightness(1.15); text-decoration: none; }
.btn:active { transform: scale(.97); }
.btn-ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.btn-ghost:hover { background: var(--surface); filter: none; }
.btn-danger { background: transparent; color: var(--danger); border-color: transparent; }
.btn-danger:hover { background: var(--danger-bg); filter: none; }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn svg { width: 16px; height: 16px; }
.btn:disabled { opacity: .5; cursor: default; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 12px;
  font-weight: 700;
}
.chip-ars { background: var(--ars-bg); color: var(--ars); }
.chip-usd { background: var(--usd-bg); color: var(--usd); }
.chip-cat { background: var(--paper); color: var(--ink-soft); }
.chip-cat .dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.chip-warn { background: var(--warn-bg); color: var(--warn); }

.amount { font-family: var(--mono); font-variant-numeric: tabular-nums; font-weight: 600; }
.money-ars { color: var(--ink); }
.money-usd { color: var(--usd); }
.muted { color: var(--ink-faint); }
.small { font-size: 13px; }
.show-mobile { display: none; }

/* ---------- Hero del dashboard: el "hinge" ARS ↔ blue ↔ USD ---------- */
.hero {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 20px;
  padding: 28px 32px;
}
.hero .side { min-width: 0; }
.hero .side.right { text-align: right; }
.hero .kicker {
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin-bottom: 6px;
}
.hero .big {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  font-size: clamp(26px, 4vw, 40px);
  letter-spacing: -0.02em;
  line-height: 1.1;
  word-break: break-word;
}
.hero .side.right .big { color: var(--usd); }
.hinge {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 10px 16px;
  border-radius: 999px;
  background: var(--pizarra);
  color: #fff;
  font-family: var(--mono);
  font-size: 13px;
  text-align: center;
}
.hinge .tag { font-family: var(--font); font-size: 10px; font-weight: 800; letter-spacing: .16em; color: #8fb8dd; }

/* ---------- Pager de mes ---------- */
.month-pager { display: inline-flex; align-items: center; gap: 4px; }
.month-pager .label {
  min-width: 140px;
  text-align: center;
  font-weight: 700;
}
.month-pager a {
  display: inline-flex;
  width: 32px; height: 32px;
  align-items: center; justify-content: center;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink-soft);
  font-weight: 700;
}
.month-pager a:hover { text-decoration: none; color: var(--ink); }

/* ---------- Tablas ---------- */
.table-wrap { overflow-x: auto; }
table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
table.data th {
  text-align: left;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--ink-faint);
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
table.data td {
  padding: 10px;
  border-bottom: 1px solid var(--line-soft);
  vertical-align: middle;
}
table.data tr:hover td { background: var(--hover); }
table.data td.num, table.data th.num { text-align: right; }
table.data tfoot td { font-weight: 700; border-bottom: none; border-top: 2px solid var(--ink); }
.row-actions { display: flex; gap: 2px; justify-content: flex-end; }
.totals-bar {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  padding: 14px 10px 2px;
  border-top: 2px solid var(--ink);
  margin-top: -1px;
  font-weight: 700;
}

/* ---------- Formularios ---------- */
form.stacked label, .field label {
  display: block;
  font-size: 13px;
  font-weight: 700;
  margin-bottom: 6px;
  color: var(--ink-soft);
}
input[type="text"], input[type="password"], input[type="number"],
input[type="date"], input[type="month"], input[type="file"], select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font: 400 15px var(--font);
  color: var(--ink);
  background: var(--surface);
  min-height: 44px;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: var(--accent); }
.field { margin-bottom: 16px; }
.field-row { display: flex; gap: 12px; }
.field-row .field { flex: 1; }
.hint { font-size: 12px; color: var(--ink-faint); margin-top: 4px; }

/* Selector de moneda como segmented control */
.segmented { display: flex; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented label {
  flex: 1;
  margin: 0;
  text-align: center;
  padding: 10px 0;
  font-weight: 700;
  color: var(--ink-faint);
  cursor: pointer;
  background: var(--surface);
}
/* texto = surface: contrasta en claro (blanco sobre color) y en oscuro
   (fondo oscuro sobre el color aclarado del tema dark) */
.segmented input:checked + label.seg-ars { background: var(--ars); color: var(--surface); }
.segmented input:checked + label.seg-usd { background: var(--usd); color: var(--surface); }
.segmented input:focus-visible + label { outline: 2px solid var(--accent); outline-offset: -2px; }

/* Conversión en vivo */
.conversion {
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  background: var(--paper);
  padding: 12px 14px;
  font-family: var(--mono);
  font-size: 14px;
}
.conversion .equals { font-size: 18px; font-weight: 600; }

/* ---------- Barras de presupuesto ---------- */
.budget-row { margin-bottom: 14px; }
.budget-row .top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 4px; }
.budget-row .name { font-weight: 600; display: inline-flex; align-items: center; gap: 8px; }
.budget-row .name .dot { width: 10px; height: 10px; border-radius: 50%; }
.progress { height: 8px; border-radius: 999px; background: var(--line-soft); overflow: hidden; }
.progress > span { display: block; height: 100%; border-radius: 999px; transition: width .4s ease; }
.progress.over > span { background: var(--danger) !important; }

/* ---------- Flash / toasts ---------- */
.flash {
  display: flex;
  align-items: center;
  gap: 10px;
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 18px;
  font-weight: 600;
  border: 1px solid transparent;
}
.flash-ok { background: var(--ok-bg); color: var(--ok); }
.flash-warn { background: var(--warn-bg); color: var(--warn); }
.flash-error { background: var(--danger-bg); color: var(--danger); }

/* ---------- Estados vacíos ---------- */
.empty {
  text-align: center;
  padding: 44px 20px;
  color: var(--ink-faint);
}
.empty .big-icon { font-size: 34px; margin-bottom: 8px; }
.empty p { margin: 0 0 16px; }

/* ---------- Login ---------- */
.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
  background:
    radial-gradient(circle at 15% 20%, rgba(47, 111, 167, .10), transparent 40%),
    radial-gradient(circle at 85% 80%, rgba(46, 125, 91, .10), transparent 40%),
    var(--paper);
}
.login-card { width: 100%; max-width: 380px; padding: 34px; }
.login-card .wordmark { font-size: 34px; text-align: center; display: block; padding: 0 0 4px; }
.login-card .tagline { text-align: center; color: var(--ink-faint); margin: 0 0 26px; }

/* ---------- Filtros ---------- */
/* En mobile se colapsan tras un toggle; en desktop siempre abiertos (JS). */
details.filters summary {
  cursor: pointer;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 10px;
  list-style: none;
  -webkit-user-select: none;
  user-select: none;
}
details.filters summary::-webkit-details-marker { display: none; }
details.filters summary::after {
  content: '▾';
  color: var(--ink-faint);
  margin-left: auto;
  transition: transform .15s ease;
}
details.filters[open] summary::after { transform: rotate(180deg); }
details.filters[open] summary { margin-bottom: 14px; }
@media (min-width: 861px) {
  details.filters summary { display: none; }
}

.filterbar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: end;
}
.filterbar .field { margin: 0; min-width: 130px; flex: 1; }
.filterbar .field.grow { min-width: 180px; flex: 2; }

/* ---------- Import preview ---------- */
tr.excluded td { opacity: .45; }
tr.dup td { background: var(--warn-bg); }
.preview-input { min-height: 36px; padding: 6px 8px; font-size: 13px; }
td .preview-input.amt { text-align: right; font-family: var(--mono); max-width: 110px; }

.dropzone {
  border: 2px dashed var(--line);
  border-radius: var(--radius-lg);
  padding: 36px 20px;
  text-align: center;
  color: var(--ink-faint);
  background: var(--surface);
  transition: border-color .15s ease, background .15s ease;
}
.dropzone.drag { border-color: var(--accent); background: var(--accent-soft); }
.dropzone input[type="file"] { display: none; }

/* ---------- Reportes ---------- */
.stat-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; }
.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 16px 18px;
}
.stat .label { font-size: 11px; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; color: var(--ink-faint); }
.stat .value { font-family: var(--mono); font-size: 22px; font-weight: 600; margin-top: 4px; font-variant-numeric: tabular-nums; }
.stat .delta { font-size: 12px; margin-top: 2px; font-weight: 600; }
.delta.up { color: var(--danger); }
.delta.down { color: var(--ok); }
.chart-box { position: relative; width: 100%; max-height: 320px; }

/* ---------- Tab bar mobile ---------- */
.tabbar { display: none; }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  /* Safe areas: Dynamic Island arriba (modo app), curvas a los costados
     en apaisado, home indicator abajo. env() = 0 donde no aplica. */
  .main {
    padding: 16px max(16px, env(safe-area-inset-right)) calc(96px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  }

  .mobile-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 14px;
    padding-top: env(safe-area-inset-top);
  }
  .mobile-top .wordmark { font-size: 22px; padding: 0; }

  /* Safari iOS hace zoom al enfocar inputs con fuente < 16px */
  input[type="text"], input[type="password"], input[type="number"],
  input[type="date"], input[type="month"], select, .preview-input {
    font-size: 16px;
  }

  /* Targets táctiles cómodos */
  .btn { min-height: 44px; }
  .btn-sm { min-height: 40px; }
  .month-pager a { width: 40px; height: 40px; }

  .tabbar {
    display: flex;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    background: color-mix(in srgb, var(--surface) 88%, transparent);
    -webkit-backdrop-filter: blur(14px);
    backdrop-filter: blur(14px);
    border-top: 1px solid var(--line);
    padding: 6px max(8px, env(safe-area-inset-right)) calc(6px + env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
    z-index: 50;
  }
  .tabbar a:active { transform: scale(.94); transition: transform .1s ease; }
  .tabbar a {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 6px 0;
    font-size: 10px;
    font-weight: 700;
    color: var(--ink-faint);
    border-radius: var(--radius);
  }
  .tabbar a svg { width: 22px; height: 22px; }
  .tabbar a.active { color: var(--ink); }
  .tabbar a:hover { text-decoration: none; }
  .tabbar a.tab-new .plus {
    color: #fff;
    display: grid;
    place-items: center;
    width: 44px; height: 44px;
    margin-top: -22px;
    border-radius: 50%;
    background: var(--accent);
    box-shadow: 0 4px 12px rgba(40, 84, 214, .4);
  }
  .tabbar a.tab-new .plus svg { width: 22px; height: 22px; }

  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .show-mobile { display: block; }
  .hero { grid-template-columns: 1fr; text-align: center; padding: 22px; }
  .hero .side.right { text-align: center; }
  .hinge { flex-direction: row; gap: 8px; }
  .field-row { flex-direction: column; gap: 0; }
  .topbar h1 { font-size: 20px; }
  .hide-mobile { display: none !important; }
}

@media (min-width: 861px) {
  .mobile-top { display: none; }
}

@media print {
  .sidebar, .tabbar, .topbar-side, .filterbar, .btn, .row-actions { display: none !important; }
  .shell { grid-template-columns: 1fr; }
  body { background: #fff; }
  .card { box-shadow: none; }
}
