:root {
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: #e6e5df;
  --in: #2a78d6;
  --out: #eb6834;
  --good: #006300;
  --bad: #b42323;
  --accent: #2a78d6;
  --chip: #eef3fb;
  --warn-bg: #fff6e0;
  --warn-ink: #6b4a00;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --page: #0d0d0d; --surface: #1a1a19; --ink: #f0efec; --ink-2: #c3c2b7; --muted: #898781;
    --grid: #2c2c2a; --axis: #383835; --border: #2c2c2a; --in: #3987e5; --out: #d95926;
    --good: #0ca30c; --bad: #e66767; --accent: #3987e5; --chip: #1f2a3a; --warn-bg: #2e2510; --warn-ink: #f2cf7a;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --page: #0d0d0d; --surface: #1a1a19; --ink: #f0efec; --ink-2: #c3c2b7; --muted: #898781;
  --grid: #2c2c2a; --axis: #383835; --border: #2c2c2a; --in: #3987e5; --out: #d95926;
  --good: #0ca30c; --bad: #e66767; --accent: #3987e5; --chip: #1f2a3a; --warn-bg: #2e2510; --warn-ink: #f2cf7a;
  color-scheme: dark;
}

* { box-sizing: border-box; }
body {
  margin: 0; background: var(--page); color: var(--ink);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); }
h1 { font-size: 18px; margin: 0; }
h2 { font-size: 15px; margin: 0 0 12px; }
h3 { margin: 0 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.pos { color: var(--good); }
.neg { color: var(--bad); }

.topbar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between; gap: 8px;
  /* En la PWA instalada el contenido llega bajo la barra de estado / notch */
  padding: env(safe-area-inset-top) calc(8px + env(safe-area-inset-right)) 0 calc(16px + env(safe-area-inset-left)); border-bottom: 1px solid var(--border); background: var(--surface); }
.topbar .actions { display: flex; gap: 2px; flex-shrink: 0; }
.icon-btn { border: 0; background: none; color: var(--ink-2); width: 40px; height: 40px; padding: 0; justify-content: center; border-radius: 8px; }
.icon-btn:hover { background: color-mix(in srgb, var(--ink) 7%, transparent); color: var(--ink); }
.icon-btn.active { color: var(--accent); }
.icon-btn.spinning svg { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

label { display: inline-flex; flex-direction: column; gap: 2px; font-size: 12px; color: var(--ink-2); }
label.check { flex-direction: row; align-items: center; gap: 6px; }
label.grow, .grow { flex: 1 1 180px; }
input, select, button, .button {
  font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--axis);
  border-radius: 6px; padding: 6px 10px; min-height: 32px;
}
input[type="checkbox"] { min-height: 0; }
/* Flecha propia: mismo margen a la derecha (10px) que el texto a la izquierda */
select {
  appearance: none; -webkit-appearance: none; padding-right: 30px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23898781' stroke-width='2.5' 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 10px center; background-size: 12px;
}
.moves-summary { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 28px; padding-bottom: 14px; margin-bottom: 14px; border-bottom: 1px solid var(--grid); }
.moves-summary span { color: var(--ink-2); font-size: 12.5px; margin-right: 8px; }
.moves-summary strong { font-size: 18px; font-variant-numeric: tabular-nums; }
.moves-summary .muted { margin-left: auto; }
button, .button { cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button:disabled { opacity: .6; cursor: progress; }
button.link { border: 0; background: none; padding: 0 4px; min-height: 0; color: var(--accent); }

.tabs { display: flex; gap: 2px; overflow-x: auto; min-width: 0; }
.tabs button { border: 0; border-bottom: 2px solid transparent; border-radius: 0; background: none; padding: 14px 12px 12px; min-height: 52px; color: var(--ink-2); white-space: nowrap; }
.tabs button svg { display: block; }
.tabs button.active { border-bottom-color: var(--accent); color: var(--ink); font-weight: 600; }

main { padding: 16px; max-width: 1200px; margin: 0 auto; display: grid; gap: 16px; }
section { display: grid; gap: 16px; }
section[hidden] { display: none; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 16px; min-width: 0; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; flex-wrap: wrap; gap: 8px; }
.hero { text-align: center; padding: 28px 16px; }
.hero-label { color: var(--ink-2); font-size: 15px; }
.hero-value { font-size: clamp(40px, 9vw, 64px); font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.1; margin: 6px 0 8px; }
.hero-value.pos { color: var(--good); }
.hero-value.neg { color: var(--bad); }
.hero-sub { color: var(--ink-2); font-size: 13.5px; }
.hero-loans { margin-top: 10px; color: var(--ink-2); }
.hero-loans .link { font-size: 13px; color: var(--ink-2); text-decoration: underline dotted; }
.loan-chip { display: inline-block; background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent); border-radius: 4px; padding: 1px 6px; font-size: 11.5px; font-weight: 600; margin-left: 6px; white-space: nowrap; }
.loan-head { text-align: center; }
.loan-head #loan-back { display: block; margin-bottom: 8px; text-align: left; }
.loan-head h2 { margin: 0; font-size: 18px; }
.loan-head .inline-form { justify-content: center; margin-top: 16px; }
.loan-moves tr.is-hidden td { opacity: 1; }
.settled { color: var(--muted); font-size: 12.5px; }
.hero-value.settled-big { color: var(--muted); }
.loan-form { display: flex; flex-wrap: wrap; align-items: end; gap: 8px; padding: 12px 0; margin-bottom: 12px; border-top: 1px solid var(--grid); border-bottom: 1px solid var(--grid); }
.loan-form label { flex: 1 1 180px; }
.banner { background: var(--warn-bg); color: var(--warn-ink); border-radius: 8px; padding: 10px 14px; }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px; }
.tile .label { color: var(--ink-2); font-size: 12.5px; }
.tile .value { font-size: 24px; font-weight: 600; font-variant-numeric: tabular-nums; margin-top: 2px; }
.tile .sub { color: var(--muted); font-size: 12px; }




.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-weight: 500; color: var(--ink-2); font-size: 12.5px; border-bottom: 1px solid var(--axis); padding: 6px 8px; white-space: nowrap; }
td { border-bottom: 1px solid var(--grid); padding: 7px 8px; vertical-align: middle; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: color-mix(in srgb, var(--accent) 6%, transparent); }
tr.is-hidden td { opacity: .55; }

.dir { font-size: 12px; font-weight: 600; white-space: nowrap; }
.dir.in { color: var(--in); }
.dir.out { color: var(--out); }
.addr { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; }
.addr-full { display: block; word-break: break-all; margin-bottom: 10px; font-size: 12px; }
.tag { display: inline-block; background: var(--chip); color: var(--ink); border-radius: 999px; padding: 1px 8px; font-size: 12px; font-weight: 500; margin-right: 6px; }
.flag { display: inline-block; background: var(--warn-bg); color: var(--warn-ink); border-radius: 4px; padding: 1px 6px; font-size: 11.5px; margin: 1px 4px 1px 0; white-space: nowrap; }
.salary { display: inline-block; background: color-mix(in srgb, var(--good) 16%, transparent); color: var(--good); border-radius: 4px; padding: 1px 6px; font-size: 11.5px; font-weight: 600; }
.chev { color: var(--muted); text-align: right; width: 1%; font-size: 18px; line-height: 1; }
#tx-dialog { width: min(520px, calc(100vw - 24px)); padding: 20px; }
.tx-head { display: flex; align-items: center; gap: 8px; }
.tx-head .close { margin-left: auto; width: 32px; height: 32px; min-height: 0; font-size: 15px; }
.tx-amount { font-size: 32px; font-weight: 700; font-variant-numeric: tabular-nums; margin: 4px 0 12px; }
.tx-amount span { font-size: 15px; color: var(--ink-2); font-weight: 500; }
.tx-amount.in { color: var(--in); }
.tx-dl { display: grid; grid-template-columns: max-content 1fr; gap: 10px 14px; margin: 0 0 16px; }
.tx-dl dt { color: var(--ink-2); font-size: 12.5px; padding-top: 2px; }
.tx-dl dd { margin: 0; min-width: 0; }
.addr-wrap { word-break: break-all; font-size: 12px; }
.row.tight { margin-top: 6px; gap: 6px; }
.row.tight .button, .row.tight button { min-height: 28px; padding: 3px 10px; font-size: 12.5px; }
.cp { display: inline-flex; align-items: center; flex-wrap: wrap; gap: 2px; }

.filters { display: flex; flex-wrap: wrap; gap: 10px 12px; align-items: end; margin-bottom: 12px; }
.list { list-style: none; padding: 0; margin: 0 0 12px; display: grid; gap: 6px; }
.list li { display: flex; justify-content: space-between; align-items: center; gap: 8px; border: 1px solid var(--grid); border-radius: 8px; padding: 6px 10px; }
.list li > div { min-width: 0; overflow-wrap: anywhere; }
.inline-form { display: flex; flex-wrap: wrap; gap: 8px; align-items: end; }
.inline-form > input { flex: 1 1 160px; }
.stack-form { display: grid; gap: 8px; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: end; }
.row.end { justify-content: flex-end; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); gap: 16px; }

dialog { border: 1px solid var(--border); border-radius: 12px; background: var(--surface); color: var(--ink); width: min(440px, calc(100vw - 32px)); }
dialog form { display: grid; gap: 10px; }
dialog::backdrop { background: rgb(0 0 0 / .35); }

[hidden] { display: none !important; }

main { padding-bottom: calc(16px + env(safe-area-inset-bottom)); }
.logout-row { display: flex; justify-content: flex-end; }
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(340px, 100%); display: grid; gap: 12px; text-align: center; padding: 28px 24px; }
.login-card img { margin: 0 auto; border-radius: 14px; }
.login-card h1 { margin: 0 0 4px; }
.login-card label { text-align: left; }
.login-card button { justify-content: center; min-height: 40px; }
.login-error { color: var(--bad); margin: 0; font-size: 13px; }
