/* ===========================================================================
   LootHound — hoja de estilos única.
   Tokens en :root, tema claro y oscuro automáticos.
   =========================================================================== */

/* Oscuro por defecto, a propósito: la app se usa de noche y mirar una
   pantalla blanca cansa. El claro sólo aparece si se pide explícitamente,
   así que no depende de cómo esté configurado el sistema operativo. */
:root {
  --bg: #0e1015;
  --surface: #171a21;
  --surface-2: #1e222b;
  --text: #e8eaef;
  --muted: #9aa3b2;
  --line: #2a2f3a;
  --accent: #9b7dff;
  --accent-soft: #241d3d;
  --in: #34d399;
  --out: #f87171;
  --warn: #fbbf24;
  --warn-soft: #2b2415;
  --info-soft: #16202e;
  --ok-soft: #13251c;
  --danger: #f87171;
  --radius: 12px;
  --shadow: 0 1px 2px rgb(0 0 0 / 40%), 0 4px 14px rgb(0 0 0 / 30%);
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

:root[data-theme="light"] {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --text: #16181d;
  --muted: #5f6774;
  --line: #dfe3e9;
  --accent: #6d4aff;
  --accent-soft: #efeaff;
  --in: #17915c;
  --out: #d0342c;
  --warn: #b7791f;
  --warn-soft: #fdf5e3;
  --info-soft: #eaf2fd;
  --ok-soft: #e8f6ee;
  --danger: #c0271f;
  --shadow: 0 1px 2px rgb(16 18 24 / 6%), 0 4px 14px rgb(16 18 24 / 5%);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0 0 .5rem; line-height: 1.25; }
h1 { font-size: 1.6rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 .75rem; }
code { font-family: var(--mono); font-size: .9em; }

.muted { color: var(--muted); }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.empty { padding: 1.5rem 0; text-align: center; }
.is-bad { color: var(--out); }
.is-good { color: var(--in); }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

/* ------------------------------------------------------------------ layout */
.topbar {
  display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
  padding: .75rem 1.25rem;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.brand { font-weight: 700; letter-spacing: -.01em; display: flex; align-items: center; gap: .45rem; }
.brand__mark { font-size: 1.2rem; }
.topbar__right { margin-left: auto; display: flex; align-items: center; gap: .75rem; }
.topbar__email { font-size: .85rem; max-width: 22ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.nav { display: flex; gap: .25rem; flex-wrap: wrap; }
.nav__item {
  display: flex; align-items: center; gap: .4rem;
  padding: .45rem .8rem; border: 0; border-radius: 999px;
  background: transparent; color: var(--muted);
  font: inherit; font-size: .9rem; cursor: pointer;
}
.nav__item:hover { background: var(--surface-2); color: var(--text); }
.nav__item.is-active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav__icon { font-size: .95rem; }

.main { max-width: 1180px; margin: 0 auto; padding: 1.25rem; }
/* `minmax(0, 1fr)` y `min-width: 0` son OBLIGATORIOS: sin ellos, el contenido más
   ancho (una tabla con `nowrap`) estira la columna entera de la cuadrícula y toda
   la página se desliza de lado en el celular, en vez de que sólo scrollee la
   tabla dentro de su caja. */
.view { display: grid; gap: 1.25rem; grid-template-columns: minmax(0, 1fr); }
.view > *, .grid > * { min-width: 0; }
.grid { display: grid; gap: 1.25rem; }
.grid--2 { grid-template-columns: repeat(auto-fit, minmax(min(330px, 100%), 1fr)); }

/* ------------------------------------------------------------------- cards */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.1rem;
  box-shadow: var(--shadow);
}
.card__head { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; margin-bottom: .75rem; flex-wrap: wrap; }
.card__actions { display: flex; align-items: center; gap: .6rem; }
.modal p { white-space: pre-line; }
.card--error { border-color: var(--out); }
.card--warn { border-color: var(--warn); background: var(--warn-soft); }
.reviewlist { list-style: none; margin: .5rem 0 0; padding: 0; display: grid; gap: .75rem; }
.reviewlist__item { display: flex; flex-wrap: wrap; gap: .5rem 1rem; align-items: center; justify-content: space-between; padding-top: .75rem; border-top: 1px solid var(--border, rgba(127,127,127,.25)); }
.reviewlist__main { min-width: 0; flex: 1 1 260px; overflow-wrap: anywhere; }
.reviewlist__actions { display: flex; flex-wrap: wrap; gap: .5rem; }

/* ------------------------------------------------------------------- login */
.auth-wrap { min-height: 100dvh; display: grid; place-items: center; padding: 1.25rem; }
.auth { width: min(420px, 100%); display: grid; gap: .85rem; }
.auth label { display: grid; gap: .3rem; font-size: .875rem; color: var(--muted); }
.auth__links { display: flex; justify-content: space-between; gap: .5rem; flex-wrap: wrap; }
.linkish {
  border: 0; background: none; color: var(--accent);
  font: inherit; font-size: .85rem; cursor: pointer; padding: 0; text-align: left;
}
.linkish:hover { text-decoration: underline; }
.linkish--quiet { color: var(--muted); font-size: .78rem; }
.note { font-size: .8rem; color: var(--muted); margin: 0; }
.note--inline { padding: .5rem .75rem; background: var(--surface-2); border-radius: 8px; }

/* ---------------------------------------------------------------- controles */
input, select, textarea, button { font: inherit; color: inherit; }
input, select, textarea {
  padding: .5rem .6rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  min-width: 0;
}
input:focus-visible, select:focus-visible, button:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}

.btn {
  padding: .5rem .95rem; border-radius: 8px; border: 1px solid transparent;
  cursor: pointer; font-weight: 600; font-size: .9rem;
  display: inline-flex; align-items: center; gap: .4rem;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn--primary { background: var(--accent); color: #fff; }
.btn--primary:hover:not(:disabled) { filter: brightness(1.08); }
.btn--ghost { background: transparent; border-color: var(--line); color: var(--text); }
.btn--ghost:hover:not(:disabled) { background: var(--surface-2); }
.btn--danger { background: var(--danger); color: #fff; }
.btn--sm { padding: .3rem .6rem; font-size: .8rem; }
.btn.is-busy { opacity: .6; pointer-events: none; }

.iconbtn {
  border: 0; background: transparent; color: var(--muted);
  cursor: pointer; padding: .25rem .45rem; border-radius: 6px; line-height: 1;
}
.iconbtn:hover { background: var(--surface-2); color: var(--out); }

.select-inline {
  padding: .25rem .4rem; font-size: .82rem; border-radius: 6px;
  background: var(--surface-2); border-width: 1px; max-width: 160px;
}

/* --------------------------------------------------------------- estadística */
.monthbar { display: flex; align-items: center; justify-content: center; gap: 1rem; }
.monthbar__label { margin: 0; text-transform: capitalize; min-width: 12ch; text-align: center; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: .85rem; }
.stat {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: .9rem 1rem;
  display: grid; gap: .15rem; box-shadow: var(--shadow);
}
.stat__label { font-size: .78rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.stat__value { font-size: 1.4rem; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.stat--in .stat__value { color: var(--in); }
.stat--out .stat__value { color: var(--out); }
.stat__delta { font-size: .78rem; color: var(--muted); }

/* ------------------------------------------------------------------ gráficas */
.donut-wrap { display: flex; gap: 1.25rem; align-items: center; flex-wrap: wrap; }
.donut { width: 200px; height: 200px; flex: 0 0 auto; }
.donut__arc { transition: opacity .15s; }
.donut__arc:hover { opacity: .75; }
.donut__value { font-size: 17px; font-weight: 700; fill: var(--text); }
.donut__label { font-size: 11px; fill: var(--muted); }

.legend { list-style: none; margin: 0; padding: 0; flex: 1 1 200px; display: grid; gap: .3rem; }
.legend__item {
  display: grid; grid-template-columns: 10px 1fr auto auto; gap: .5rem;
  align-items: center; font-size: .85rem; padding: .2rem .3rem; border-radius: 6px; cursor: pointer;
}
.legend__item:hover { background: var(--surface-2); }
.legend__dot { width: 10px; height: 10px; border-radius: 3px; }
.legend__name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.legend__pct { color: var(--muted); font-variant-numeric: tabular-nums; }
.legend__amount { font-variant-numeric: tabular-nums; }

.bars { display: flex; gap: .5rem; align-items: flex-end; justify-content: space-around; }
.bars__col { display: grid; gap: .35rem; justify-items: center; flex: 1; }
.bars__pair { display: flex; gap: 3px; align-items: flex-end; }
.bars__bar { width: 14px; border-radius: 3px 3px 0 0; min-height: 2px; }
.bars__bar--in { background: var(--in); }
.bars__bar--out { background: var(--out); }
.bars__label { font-size: .72rem; color: var(--muted); }
.bars__key { display: flex; gap: 1rem; justify-content: center; margin-top: .6rem; font-size: .8rem; color: var(--muted); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: .3rem; }
.dot--in { background: var(--in); }
.dot--out { background: var(--out); }

.rank { list-style: none; margin: 0; padding: 0; display: grid; gap: .45rem; }
.rank__row { display: grid; grid-template-columns: minmax(80px, 1fr) 2fr auto; gap: .6rem; align-items: center; font-size: .85rem; }
.rank__name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank__track { background: var(--surface-2); border-radius: 999px; height: 8px; overflow: hidden; }
.rank__fill { display: block; height: 100%; border-radius: 999px; }
.rank__value { font-variant-numeric: tabular-nums; }

/* -------------------------------------------------------------------- tablas */
.table-wrap { overflow-x: auto; }
.table-wrap--tall { max-height: 60vh; overflow-y: auto; }
.table { width: 100%; border-collapse: collapse; font-size: .875rem; }
.table th {
  text-align: left; font-size: .74rem; text-transform: uppercase; letter-spacing: .05em;
  color: var(--muted); font-weight: 600; padding: .5rem .5rem; border-bottom: 1px solid var(--line);
  position: sticky; top: 0; background: var(--surface);
}
.table td { padding: .45rem .5rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tbody tr:hover { background: var(--surface-2); }
.table--mini { font-size: .8rem; margin-top: .5rem; }
.table--mini th, .table--mini td { padding: .25rem .4rem; }

.txrow__date { white-space: nowrap; color: var(--muted); font-size: .82rem; }
.txrow__desc { display: inline-block; max-width: 34ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: bottom; }
.txrow__fx { color: var(--muted); font-size: .74rem; }
.txrow__note { display: block; color: var(--muted); font-size: .76rem; }
.amount { white-space: nowrap; font-weight: 600; }
.amount--expense { color: var(--out); }
.amount--income { color: var(--in); }
.amount--transfer { color: var(--muted); font-weight: 500; }

tr.is-dup { opacity: .5; }
tr.is-similar { background: var(--warn-soft); }
tr.is-optional { background: var(--info-soft); }
tr.is-off { opacity: .5; }

/* ------------------------------------------------------------------ etiquetas */
.tag {
  display: inline-block; margin-left: .35rem; padding: .05rem .35rem;
  border-radius: 4px; font-size: .68rem; font-weight: 600; text-transform: uppercase;
  letter-spacing: .03em; background: var(--surface-2); color: var(--muted);
}
.tag--pdf { background: var(--accent-soft); color: var(--accent); }
.tag--rule { background: var(--surface-2); }
.tag--dup { background: var(--surface-2); }
.tag--similar { background: var(--warn-soft); color: var(--warn); }
.tag--optional { background: var(--info-soft); color: var(--accent); }
.tag--transfer { background: var(--surface-2); color: var(--muted); text-transform: none; }

.cashcard__row {
  display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
  padding: .5rem 0;
}
.cashcard__row > div { display: grid; gap: .1rem; }
.cashcard__row strong { font-size: 1.15rem; font-variant-numeric: tabular-nums; }
.cashcard__op { font-size: 1.2rem; color: var(--muted); }

/* -------------------------------------------------------------- presupuesto */
.insights { list-style: none; margin: 0; padding: 0; display: grid; gap: .6rem; }
.insight {
  display: grid; gap: .15rem; padding: .6rem .8rem;
  border-radius: 8px; border-left: 3px solid var(--line); background: var(--surface-2);
  font-size: .88rem;
}
.insight--good { border-left-color: var(--in); }
.insight--bad { border-left-color: var(--out); }
.insight--warn { border-left-color: var(--warn); }
.insight--info { border-left-color: var(--accent); }
.insight span { font-size: .82rem; }

.input-tope {
  width: 96px; text-align: right; padding: .25rem .4rem;
  font-size: .85rem; font-variant-numeric: tabular-nums;
}
tr.is-over td { background: color-mix(in srgb, var(--out) 8%, transparent); }
.table .rank__track { min-width: 90px; display: block; }

/* ------------------------------------------------------------ editar movimiento */
.modal--wide { max-width: min(640px, calc(100vw - 2rem)); width: 100%; }
.editform { display: grid; gap: .85rem; }
.editform__grid { display: grid; gap: .7rem; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }
.editform__field { display: grid; gap: .25rem; font-size: .8rem; color: var(--muted); }
.editform__field[hidden] { display: none; }
.editform__field:has(textarea), .editform__field:has([name="description"]) { grid-column: 1 / -1; }
.editform textarea { resize: vertical; font: inherit; }
.field-error { color: var(--out); font-size: .76rem; }
.txrow__actions { white-space: nowrap; text-align: right; }
.editform__field--wide { grid-column: 1 / -1; }

/* --------------------------------------------------------------- inversiones */
.invtable td, .invtable th { white-space: nowrap; }
.invtable tfoot td { font-weight: 700; border-top: 2px solid var(--line); border-bottom: 0; }
.invtable__date { display: block; font-size: .7rem; color: var(--muted); font-weight: 400; }
.invtable__date.is-stale { color: var(--warn); }
.valgrid { display: grid; gap: .6rem; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); margin: .6rem 0 .85rem; }
.chip--btn { cursor: pointer; background: transparent; color: inherit; }
.chip--btn:hover { border-color: var(--accent); color: var(--accent); }
.card--full { grid-column: 1 / -1; }
.linechart { width: 100%; height: auto; max-height: 300px; }
.linechart text { font-size: 11px; }
.help { margin-top: .75rem; }
.help summary { cursor: pointer; color: var(--accent); font-size: .85rem; }
.iconbtn--edit:hover { color: var(--accent); }

.chips { display: flex; flex-wrap: wrap; gap: .4rem; margin-bottom: .85rem; }
.chip {
  display: inline-flex; align-items: center; gap: .35rem;
  padding: .2rem .55rem; border: 1px solid var(--line);
  border-radius: 999px; font-size: .82rem;
}
.chip__dot { width: 8px; height: 8px; border-radius: 50%; }

/* -------------------------------------------------------------------- formas */
.formrow { display: flex; gap: .6rem; flex-wrap: wrap; align-items: end; }
.formrow label { display: grid; gap: .25rem; font-size: .8rem; color: var(--muted); flex: 1 1 150px; }
.formrow--tight { align-items: center; }

.filters { display: flex; gap: .5rem; flex-wrap: wrap; margin-bottom: .85rem; }
.filters input, .filters select { flex: 1 1 140px; font-size: .85rem; }

.quickadd__row { display: flex; gap: .6rem; flex-wrap: wrap; align-items: end; }
.quickadd__row label { display: grid; gap: .25rem; font-size: .78rem; color: var(--muted); flex: 1 1 120px; }
.quickadd__amount { flex: 0 0 130px; }
.quickadd__amount input { font-size: 1.15rem; font-weight: 600; }
.quickadd__note { flex: 2 1 200px; }

.accounts { list-style: none; margin: 0 0 .85rem; padding: 0; display: grid; gap: .4rem; font-size: .9rem; }

/* -------------------------------------------------------------------- import */
.dropzone {
  display: grid; place-items: center; gap: .35rem;
  padding: 2.2rem 1rem; margin: .5rem 0;
  border: 2px dashed var(--line); border-radius: var(--radius);
  background: var(--surface-2); cursor: pointer; text-align: center;
  transition: border-color .15s, background .15s;
}
.dropzone:hover, .dropzone.is-over { border-color: var(--accent); background: var(--accent-soft); }
.dropzone__icon { font-size: 2rem; }
.dropzone__badge { font-size: .78rem; color: var(--muted); margin-top: .3rem; }

.help { margin-top: .75rem; font-size: .85rem; }
.help summary { cursor: pointer; color: var(--accent); }
.help ul { margin: .5rem 0; }

.callout { padding: .7rem .85rem; border-radius: 8px; margin: .75rem 0; font-size: .87rem; }
.callout p:last-child { margin-bottom: 0; }
.callout ul { margin: .35rem 0 0; padding-left: 1.1rem; }
.callout--ok { background: var(--ok-soft); }
.callout--warn { background: var(--warn-soft); }
.callout--info { background: var(--info-soft); }

.preview__bar {
  display: flex; align-items: center; gap: .85rem; flex-wrap: wrap;
  padding: .6rem 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line);
  font-size: .85rem; margin: .75rem 0;
}
.preview__totals { margin-left: auto; color: var(--muted); }
.preview__actions { display: flex; gap: .6rem; justify-content: flex-end; margin-top: 1rem; }

/* -------------------------------------------------------------------- avisos */
.toasts {
  position: fixed; bottom: 1rem; right: 1rem; z-index: 100;
  display: grid; gap: .5rem; max-width: min(400px, calc(100vw - 2rem));
}
.toast {
  padding: .65rem .9rem; border-radius: 8px; font-size: .87rem;
  background: var(--surface); border: 1px solid var(--line);
  box-shadow: var(--shadow); animation: toast-in .2s ease-out;
}
.toast--ok { border-left: 3px solid var(--in); }
.toast--error { border-left: 3px solid var(--out); }
.toast--out { opacity: 0; transition: opacity .25s; }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } }

.modal {
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface); color: var(--text);
  padding: 1.25rem; max-width: min(440px, calc(100vw - 2rem)); box-shadow: var(--shadow);
}
.modal::backdrop { background: rgb(0 0 0 / 45%); }
.modal__actions { display: flex; gap: .6rem; justify-content: flex-end; margin-top: 1rem; }

/* --------------------------------------------------------------------- móvil */
@media (max-width: 720px) {
  .topbar { padding: .6rem .85rem; }
  .topbar__email { display: none; }
  .nav { order: 3; width: 100%; overflow-x: auto; }
  .nav__item { white-space: nowrap; }
  .main { padding: .85rem; }
  .stat__value { font-size: 1.2rem; }
  .txrow__desc { max-width: 20ch; }
  .donut-wrap { justify-content: center; }
}

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