/* ---------- tokens ---------- */
:root {
  color-scheme: light;
  --surface-0:  #f4f3f0;
  --surface-1:  #fcfcfb;
  --surface-2:  #eceae5;
  --border:     #e0ded7;
  --border-strong: #cbc8c0;
  --text-primary:   #0b0b0b;
  --text-secondary: #52514e;
  --text-muted:     #8a8a85;
  --series-1:  #2a78d6;
  --series-1-soft: #cde2fb;
  --accent:    #2a78d6;
  --accent-ink: #ffffff;
  --danger:    #c93b3a;
  --good:      #008300;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.05);
  --radius: 14px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --surface-0:  #101010;
    --surface-1:  #1a1a19;
    --surface-2:  #262624;
    --border:     #2e2e2b;
    --border-strong: #454541;
    --text-primary:   #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted:     #8f8e86;
    --series-1:  #3987e5;
    --series-1-soft: #184f95;
    --accent:    #3987e5;
    --danger:    #e66767;
    --good:      #22a922;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.3);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-0:#101010; --surface-1:#1a1a19; --surface-2:#262624;
  --border:#2e2e2b; --border-strong:#454541;
  --text-primary:#ffffff; --text-secondary:#c3c2b7; --text-muted:#8f8e86;
  --series-1:#3987e5; --series-1-soft:#184f95; --accent:#3987e5;
  --danger:#e66767; --good:#22a922;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.3);
}

/* ---------- base ---------- */
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; font-family: var(--font); font-size: 15px; line-height: 1.45;
  background: var(--surface-0); color: var(--text-primary);
  -webkit-text-size-adjust: 100%; overscroll-behavior-y: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }
.hide { display: none !important; }
.num { font-variant-numeric: tabular-nums; }

/* ---------- estructura ---------- */
#app { min-height: 100%; display: flex; flex-direction: column; }
header.top {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px; padding-top: calc(10px + env(safe-area-inset-top));
  background: var(--surface-1); border-bottom: 1px solid var(--border);
}
header.top h1 { font-size: 16px; margin: 0; font-weight: 650; letter-spacing: -.01em; }
header.top .spacer { flex: 1; }
.whoami { font-size: 13px; color: var(--text-secondary); }

main { flex: 1; padding: 16px; padding-bottom: 96px; max-width: 900px; width: 100%; margin: 0 auto; }

nav.tabs {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--surface-1); border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
nav.tabs button {
  background: none; border: 0; padding: 10px 4px 12px;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  font-size: 11px; color: var(--text-muted); font-weight: 500;
}
nav.tabs button svg { width: 22px; height: 22px; stroke-width: 1.7; }
nav.tabs button[aria-current="page"] { color: var(--accent); }

/* ---------- tarjetas y formularios ---------- */
.card {
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px; margin-bottom: 14px; box-shadow: var(--shadow);
}
.card > h2 { margin: 0 0 12px; font-size: 13px; font-weight: 650; letter-spacing: .04em;
             text-transform: uppercase; color: var(--text-secondary); }
.row { display: flex; gap: 10px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
label.field { display: block; margin-bottom: 14px; }
label.field > span { display: block; font-size: 12px; font-weight: 600; color: var(--text-secondary);
                     margin-bottom: 5px; letter-spacing: .01em; }
input[type=text], input[type=password], input[type=number], input[type=search],
input[type=date], input[type=datetime-local], select, textarea {
  width: 100%; padding: 11px 12px; border: 1px solid var(--border-strong);
  border-radius: 10px; background: var(--surface-1); outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent); }
textarea { resize: vertical; min-height: 58px; }

.btn {
  padding: 11px 16px; border-radius: 10px; border: 1px solid var(--border-strong);
  background: var(--surface-1); font-weight: 560;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, var(--border)); }
.btn.block { width: 100%; }
.btn.sm { padding: 6px 10px; font-size: 13px; border-radius: 8px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.chips { display: flex; gap: 7px; flex-wrap: wrap; }
.chip {
  padding: 7px 13px; border-radius: 999px; border: 1px solid var(--border-strong);
  background: var(--surface-1); font-size: 14px; white-space: nowrap;
}
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 560; }

/* ---------- importe ---------- */
.amount-wrap { display: flex; align-items: baseline; gap: 8px;
  border: 1px solid var(--border-strong); border-radius: 12px; padding: 10px 14px; background: var(--surface-1); }
.amount-wrap:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent); }
.amount-wrap .cur { font-size: 22px; color: var(--text-muted); }
#amount {
  border: 0; padding: 0; background: none; font-size: 34px; font-weight: 620;
  letter-spacing: -.02em; font-variant-numeric: tabular-nums; width: 100%;
}
#amount:focus { box-shadow: none; }

/* ---------- avatar de comercio ---------- */
.ava {
  width: 34px; height: 34px; border-radius: 9px; flex: none;
  display: grid; place-items: center; overflow: hidden;
  background: var(--surface-2); border: 1px solid var(--border);
  font-size: 13px; font-weight: 680; color: #fff; text-transform: uppercase;
}
.ava img { width: 100%; height: 100%; object-fit: contain; background: #fff; }
.ava.lg { width: 44px; height: 44px; border-radius: 11px; font-size: 16px; }

/* ---------- autocompletado ---------- */
.typeahead { position: relative; }
.suggest {
  position: absolute; z-index: 40; left: 0; right: 0; top: calc(100% + 5px);
  background: var(--surface-1); border: 1px solid var(--border-strong);
  border-radius: 12px; box-shadow: var(--shadow); max-height: 310px; overflow-y: auto; padding: 5px;
}
.suggest button {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left;
  padding: 8px 9px; border: 0; border-radius: 9px; background: none;
}
.suggest button:hover, .suggest button.active { background: var(--surface-2); }
.suggest .nm { font-weight: 560; }
.suggest .meta { font-size: 12px; color: var(--text-muted); }
.suggest .new { color: var(--accent); font-weight: 560; }

.filters { display: grid; grid-template-columns: 1fr; gap: 8px; }
@media (min-width: 560px) { .filters { grid-template-columns: repeat(3, 1fr); } }

/* ---------- listas ---------- */
.daygroup { margin-bottom: 18px; }
.daygroup > .dayhead {
  display: flex; justify-content: space-between; align-items: baseline;
  padding: 0 4px 6px; font-size: 12px; font-weight: 650; color: var(--text-secondary);
  text-transform: none;
}
.list { background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.item { display: flex; align-items: center; gap: 11px; padding: 11px 13px; width: 100%;
        border: 0; border-top: 1px solid var(--border); background: none; text-align: left; }
.item:first-child { border-top: 0; }
.item:hover { background: var(--surface-2); }
.item .nm { font-weight: 560; }
.item .meta { font-size: 12px; color: var(--text-muted); display: flex; gap: 6px; flex-wrap: wrap; }
.item .amt { margin-left: auto; font-weight: 650; font-variant-numeric: tabular-nums; white-space: nowrap; }
.dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; flex: none; }
.empty { text-align: center; color: var(--text-muted); padding: 34px 16px; font-size: 14px; }

/* ---------- informes ---------- */
.hero { text-align: center; padding: 6px 0 4px; }
.hero .figure { font-size: 40px; font-weight: 680; letter-spacing: -.03em; font-variant-numeric: tabular-nums; }
.hero .sub { color: var(--text-secondary); font-size: 13px; margin-top: 2px; }
.periodbar { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.periodbar .label { flex: 1; text-align: center; font-weight: 600; font-size: 14px; }
.periodbar button { width: 38px; height: 38px; border-radius: 10px; border: 1px solid var(--border-strong);
                    background: var(--surface-1); display: grid; place-items: center; }

.bars { display: flex; flex-direction: column; gap: 9px; }
.barrow { display: grid; grid-template-columns: 34px 1fr auto; align-items: center; gap: 10px; }
.barrow.nologo { grid-template-columns: 1fr auto; }
.barrow .track { position: relative; height: 26px; display: flex; align-items: center; }
.barrow .fill { height: 10px; border-radius: 0 4px 4px 0; background: var(--series-1); min-width: 2px; }
.barrow .lab { position: absolute; left: 0; top: -2px; font-size: 13px; }
.barrow .val { font-variant-numeric: tabular-nums; font-size: 13px; font-weight: 600; white-space: nowrap; }
.barrow .cnt { color: var(--text-muted); font-weight: 400; font-size: 12px; }

svg.chart { width: 100%; display: block; overflow: visible; }
svg.chart .grid { stroke: var(--border); stroke-width: 1; }
svg.chart .axis { fill: var(--text-muted); font-size: 10px; }
svg.chart .bar { fill: var(--series-1); }
svg.chart .bar.dim { fill: var(--series-1-soft); }
svg.chart .hit { fill: transparent; cursor: pointer; }
svg.chart .hit:hover + .bar, svg.chart .bar.on { fill: var(--accent); }

.tip {
  position: fixed; z-index: 60; pointer-events: none; background: var(--surface-1);
  border: 1px solid var(--border-strong); border-radius: 9px; padding: 7px 10px;
  font-size: 12px; box-shadow: var(--shadow); white-space: nowrap;
}
.tip b { font-variant-numeric: tabular-nums; }

/* ---------- ajustes ---------- */
.settingrow { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-top: 1px solid var(--border); }
.settingrow:first-of-type { border-top: 0; }
.settingrow .grow { min-width: 0; }
.settingrow .nm { font-weight: 560; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.settingrow .meta { font-size: 12px; color: var(--text-muted); }
.swatch { width: 18px; height: 18px; border-radius: 5px; border: 1px solid var(--border-strong); flex: none; }
.subnav { display: flex; gap: 6px; margin-bottom: 14px; overflow-x: auto; padding-bottom: 2px; }
.subnav button { padding: 7px 13px; border-radius: 999px; border: 1px solid var(--border-strong);
                 background: var(--surface-1); font-size: 14px; white-space: nowrap; }
.subnav button[aria-current="true"] { background: var(--surface-2); border-color: var(--border-strong); font-weight: 600; }

/* ---------- modal ---------- */
.modal-bg { position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.45);
            display: flex; align-items: flex-end; justify-content: center; padding: 0; }
@media (min-width: 640px) { .modal-bg { align-items: center; padding: 20px; } }
.modal {
  background: var(--surface-1); width: 100%; max-width: 520px; max-height: 90vh; overflow-y: auto;
  border-radius: 18px 18px 0 0; padding: 18px; padding-bottom: calc(18px + env(safe-area-inset-bottom));
}
@media (min-width: 640px) { .modal { border-radius: 16px; } }
.modal h2 { margin: 0 0 14px; font-size: 17px; }

/* ---------- login ---------- */
.login-wrap { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.login-card { width: 100%; max-width: 360px; }
.login-card .brand { text-align: center; margin-bottom: 22px; }
.login-card .brand .mark { font-size: 40px; }
.login-card .brand h1 { margin: 6px 0 2px; font-size: 21px; letter-spacing: -.02em; }
.login-card .brand p { margin: 0; color: var(--text-muted); font-size: 13px; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: 84px; z-index: 70;
  background: var(--text-primary); color: var(--surface-1); padding: 10px 16px;
  border-radius: 999px; font-size: 14px; box-shadow: var(--shadow); max-width: 92vw;
}
.toast.err { background: var(--danger); color: #fff; }
