/* Apunta — estilo sobrio: una sola superficie, líneas de 1 px, radio de 6 px y un único acento azul.
   Sin gradientes, sin sombras grandes. */

:root {
  --bg: #ffffff;
  --text: #1f2328;
  --muted: #656d76;
  --line: #d8dee4;
  --hover: #f6f8fa;
  --accent: #2563eb;
  --accent-ink: #ffffff;
  --accent-wash: #eef3fe;
  --danger: #cf222e;
  --track: #eaeef2;
  --radius: 6px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1117;
    --text: #e6edf3;
    --muted: #8b949e;
    --line: #30363d;
    --hover: #161b22;
    --accent: #4c8dff;
    --accent-ink: #0d1117;
    --accent-wash: #11213f;
    --danger: #ff7b72;
    --track: #21262d;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans", Helvetica, Arial, sans-serif;
}

h1, h2, h3, p { margin: 0; }
h1 { font-size: 20px; font-weight: 600; }
h2 { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin-bottom: 12px; }
h3 { font-size: 14px; font-weight: 600; margin-bottom: 4px; }

.muted { color: var(--muted); }
.spacer { flex: 1; }
[hidden] { display: none !important; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ------------------------------------------------------------------ controles */

.btn {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 5px 12px;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.btn:hover:not(:disabled) { background: var(--hover); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.primary:hover:not(:disabled) { background: var(--accent); filter: brightness(.92); }
.btn.block { width: 100%; padding: 8px 12px; }

.icon-btn {
  font: inherit; font-size: 18px; line-height: 1;
  width: 28px; height: 28px;
  color: var(--text); background: transparent;
  border: 1px solid transparent; border-radius: var(--radius);
  cursor: pointer;
}
.icon-btn:hover:not(:disabled) { background: var(--hover); border-color: var(--line); }
.icon-btn:disabled { opacity: .35; cursor: default; }

.link {
  font: inherit; color: var(--accent);
  background: none; border: 0; padding: 0; cursor: pointer;
}
.link:hover { text-decoration: underline; }
.link.danger { color: var(--danger); }

input, select {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 6px 10px;
  min-width: 0;
  width: 100%;
}
input:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
input:disabled { color: var(--muted); }
input[type=checkbox] { width: auto; margin-top: 3px; accent-color: var(--accent); }

.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field-label { font-weight: 600; font-size: 12px; }
.field-hint { color: var(--muted); font-size: 12px; }
.form-error { color: var(--danger); font-size: 13px; }

/* ------------------------------------------------------------------ estructura */

.topbar { border-bottom: 1px solid var(--line); }
.topbar-inner {
  max-width: 960px; margin: 0 auto;
  padding: 10px 16px; padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right));
  display: flex; align-items: center; gap: 8px;
}
.brand { font-weight: 700; font-size: 16px; letter-spacing: -.01em; }
.brand-lg { font-size: 22px; text-align: center; margin-bottom: 16px; }
.user { color: var(--muted); margin-right: 4px; }

.container {
  max-width: 960px; margin: 0 auto;
  padding-block: 20px 48px; padding-inline: max(16px, env(safe-area-inset-left)) max(16px, env(safe-area-inset-right));
}

.panel { border: 1px solid var(--line); border-radius: var(--radius); }
.panel > section { padding: 20px; }
.panel > section + section { border-top: 1px solid var(--line); }
.panel.loading { opacity: .55; transition: opacity .15s; }
.form-panel { padding: 16px; margin-bottom: 12px; }

/* ------------------------------------------------------------------ barra de periodo */

.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-bottom: 12px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.seg-btn {
  font: inherit; color: var(--muted); background: var(--bg);
  border: 0; padding: 5px 12px; cursor: pointer;
}
.seg-btn + .seg-btn { border-left: 1px solid var(--line); }
.seg-btn:hover { background: var(--hover); }
.seg-btn.on { background: var(--accent-wash); color: var(--accent); font-weight: 600; }
.nav { display: flex; align-items: center; gap: 4px; }
.nav-label { min-width: 150px; text-align: center; font-weight: 600; }
.range { display: flex; align-items: center; gap: 8px; }
.range input { width: auto; }

/* ------------------------------------------------------------------ cifra principal */

.hero-label { color: var(--muted); font-size: 13px; }
.hero-value { font-size: 48px; line-height: 1.15; font-weight: 600; letter-spacing: -.02em; }

/* ------------------------------------------------------------------ gráficos */

.charts { display: grid; grid-template-columns: 1.6fr 1fr; gap: 32px; }
.charts.single { grid-template-columns: 1fr; }
.charts > * { min-width: 0; }

.chart { --plot-h: 160px; }
.chart-body { position: relative; height: var(--plot-h); padding-left: 40px; }
.grid { position: absolute; top: 0; bottom: 0; left: 40px; right: 0; display: flex; flex-direction: column; justify-content: space-between; pointer-events: none; }
.grid-line { position: relative; height: 0; border-top: 1px solid var(--line); }
.grid-line span { position: absolute; left: -40px; top: -9px; width: 34px; text-align: right; font-size: 11px; color: var(--muted); }
.bars { position: relative; height: 100%; display: grid; grid-template-columns: repeat(var(--n, 1), minmax(0, 1fr)); gap: 2px; }
.bar-slot { min-width: 0; display: flex; align-items: flex-end; justify-content: center; border-radius: var(--radius); }
.bar-slot:not(.empty):hover, .bar-slot:focus-visible { background: var(--accent-wash); }
.bar { width: min(100%, 24px); background: var(--accent); border-radius: 4px 4px 0 0; }
.chart-x { display: flex; margin-top: 6px; }
.chart-x-gutter { width: 40px; flex: none; }
.axis-x { flex: 1; min-width: 0; display: grid; grid-template-columns: repeat(var(--n, 1), minmax(0, 1fr)); gap: 2px; }
.axis-x span { min-width: 0; text-align: center; font-size: 11px; color: var(--muted); white-space: nowrap; overflow: visible; }

.data-table { margin-top: 12px; color: var(--muted); font-size: 12px; }
.data-table summary { cursor: pointer; }
.data-table table { width: 100%; margin-top: 8px; border-collapse: collapse; color: var(--text); }
.data-table th, .data-table td { text-align: left; padding: 4px 0; border-bottom: 1px solid var(--line); font-weight: 400; }
.data-table th { color: var(--muted); }
.num { text-align: right !important; font-variant-numeric: tabular-nums; }

.cat-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.cat-row {
  display: grid; grid-template-columns: minmax(70px, 1fr) minmax(40px, 1.2fr) 118px; align-items: center; gap: 10px;
  padding: 4px 6px; margin-inline: -6px; border-radius: var(--radius);
}
.cat-row:hover, .cat-row:focus-visible { background: var(--hover); }
.cat-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cat-track { height: 8px; background: var(--track); border-radius: 4px; overflow: hidden; }
.cat-fill { display: block; height: 100%; background: var(--accent); border-radius: 4px; }
.cat-value { font-variant-numeric: tabular-nums; text-align: right; }
.cat-pct { color: var(--muted); font-size: 12px; }

.tip {
  position: absolute; z-index: 20; pointer-events: none;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 6px 10px; font-size: 12px; white-space: nowrap;
}
.tip-value { font-weight: 600; font-size: 14px; font-variant-numeric: tabular-nums; }
.tip-label { color: var(--muted); }

/* ------------------------------------------------------------------ lista de gastos */

.rows { list-style: none; margin: 0; padding: 0; }
.row {
  display: grid; grid-template-columns: 72px minmax(0, 1fr) minmax(0, 140px) 104px auto; align-items: center; gap: 12px;
  padding: 8px 6px; margin-inline: -6px; border-bottom: 1px solid var(--line); border-radius: 0;
}
.row:last-child { border-bottom: 0; }
.row:hover, .row:focus-within { background: var(--hover); }
.row-date { color: var(--muted); }
.row-concept { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-cat { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-amount { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.row-actions { display: flex; gap: 12px; opacity: 0; }
.row:hover .row-actions, .row:focus-within .row-actions { opacity: 1; }
@media (hover: none) { .row-actions { opacity: 1; } }
.more { margin-top: 12px; text-align: center; }

.empty { padding: 40px 20px; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 8px; }

/* ------------------------------------------------------------------ formularios y diálogos */

.form-row { display: grid; grid-template-columns: 2fr 1fr 1fr 1fr; gap: 12px; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }
.form-actions + .form-error, .form-row + .form-error { margin-top: 8px; }

.dialog {
  color: var(--text); background: var(--bg);
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px; width: min(560px, calc(100vw - 32px)); max-height: calc(100vh - 32px);
}
.dialog.wide { width: min(640px, calc(100vw - 32px)); }
.dialog::backdrop { background: rgba(0, 0, 0, .45); }
.dialog h2 { text-transform: none; letter-spacing: 0; font-size: 16px; color: var(--text); margin-bottom: 12px; }
.dialog .form-row { grid-template-columns: 1fr 1fr; }
.dialog .form-row .field:first-child { grid-column: 1 / -1; }
.dialog-head { display: flex; align-items: center; justify-content: space-between; }
.dialog-head h2 { margin-bottom: 0; }

.settings-section { padding: 16px 0; border-top: 1px solid var(--line); display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.settings-section:first-of-type { margin-top: 12px; }

.cat-admin { list-style: none; margin: 0; padding: 0; width: 100%; display: flex; flex-direction: column; gap: 12px; }
.cat-admin-row.archived { opacity: .6; }
.cat-admin-head { display: flex; align-items: center; gap: 12px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; align-items: center; }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 0 4px 0 8px; border: 1px solid var(--line); border-radius: var(--radius); color: var(--muted); font-size: 12px; }
.chip button { font: inherit; border: 0; background: none; color: var(--muted); cursor: pointer; padding: 0 4px; }
.chip button:hover { color: var(--danger); }
.alias-form input { width: 110px; padding: 1px 8px; font-size: 12px; }
.inline-form { display: flex; gap: 8px; width: 100%; }

.legal { white-space: pre-wrap; max-height: 45vh; overflow: auto; border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; font-size: 13px; margin: 8px 0 12px; }
.consent.agree { align-items: center; }
.btn.danger { color: var(--danger); border-color: var(--danger); }
.btn.danger:hover:not(:disabled) { background: var(--hover); }
.form-actions-left { display: flex; gap: 8px; flex-wrap: wrap; }
.delete-confirm { width: 100%; display: flex; flex-direction: column; gap: 8px; }

.consents { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.consent { display: flex; gap: 10px; cursor: pointer; }
.consent > span { display: flex; flex-direction: column; }

.toast {
  position: fixed; left: 50%; bottom: max(16px, env(safe-area-inset-bottom)); transform: translateX(-50%);
  z-index: 30; display: flex; align-items: center; gap: 16px;
  background: var(--text); color: var(--bg);
  border-radius: var(--radius); padding: 8px 14px; max-width: calc(100vw - 32px);
}
.toast-action { font: inherit; font-weight: 600; color: var(--bg); background: none; border: 0; text-decoration: underline; cursor: pointer; padding: 0; }

/* ------------------------------------------------------------------ acceso */

.auth { max-width: 380px; margin: 0 auto; padding: 56px 16px; }
.auth-card { border: 1px solid var(--line); border-radius: var(--radius); padding: 24px; display: flex; flex-direction: column; gap: 12px; }
.auth-form { display: flex; flex-direction: column; gap: 12px; margin-top: 4px; }
.auth-links { display: flex; flex-wrap: wrap; gap: 4px 16px; justify-content: space-between; margin-top: 4px; font-size: 13px; }

/* ------------------------------------------------------------------ pantallas angostas */

@media (max-width: 720px) {
  .charts { grid-template-columns: 1fr; gap: 24px; }
  .form-row { grid-template-columns: 1fr 1fr; }
  .form-row .field:first-child { grid-column: 1 / -1; }
  .row { grid-template-columns: 56px minmax(0, 1fr) 96px; row-gap: 0; }
  .row-cat { grid-column: 2 / 3; grid-row: 2; font-size: 12px; }
  .row-actions { grid-column: 3; grid-row: 2; justify-content: flex-end; opacity: 1; }
  .hero-value { font-size: 40px; }
  .nav-label { min-width: 120px; }
  .user { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .panel.loading { transition: none; }
}
