:root {
  --bg: #070b16;
  --bg-2: #0b1222;
  --card: #0f182d;
  --card-2: #142039;
  --line: rgba(148, 178, 255, 0.10);
  --line-2: rgba(148, 178, 255, 0.18);
  --text: #e7eeff;
  --muted: #8796b8;
  --dim: #5a6886;
  --blue: #3b82f6;
  --blue-2: #60a5fa;
  --cyan: #38bdf8;
  --green: #34d399;
  --amber: #fbbf24;
  --red: #f87171;
  --radius: 20px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.4;
  min-height: 100vh;
  min-height: 100dvh;
  overscroll-behavior-y: none;
  touch-action: manipulation;
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.bg-glow {
  position: fixed; inset: 0; pointer-events: none; z-index: 0;
  background:
    radial-gradient(600px 380px at 85% -10%, rgba(59,130,246,.22), transparent 70%),
    radial-gradient(500px 340px at -10% 30%, rgba(56,189,248,.10), transparent 70%);
}

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(var(--safe-top) + 14px) 18px 12px;
  background: linear-gradient(var(--bg) 60%, rgba(7,11,22,0));
}
.topbar h1 { margin: 0; font-size: 28px; font-weight: 750; letter-spacing: -0.02em; }
#topActions { display: flex; gap: 8px; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center;
  background: var(--card); border: 1px solid var(--line); color: var(--blue-2);
}
.icon-btn svg { width: 20px; height: 20px; }

main {
  position: relative; z-index: 1;
  padding: 4px 16px calc(var(--safe-bottom) + 110px);
  max-width: 560px; margin: 0 auto;
  animation: fade .25s ease;
}
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- Cards ---------- */
.card {
  background: linear-gradient(180deg, var(--card-2), var(--card));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
}
.section-title {
  display: flex; align-items: center; justify-content: space-between;
  margin: 22px 4px 10px; font-size: 13px; font-weight: 650; color: var(--muted);
  text-transform: uppercase; letter-spacing: .06em;
}
.section-title button { color: var(--blue-2); text-transform: none; letter-spacing: 0; font-size: 14px; font-weight: 600; }

/* Period switcher */
.period {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 6px;
  margin-bottom: 14px;
}
.period button.arrow { width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center; color: var(--blue-2); }
.period button.arrow:active { background: var(--card-2); }
.period .label { text-align: center; flex: 1; }
.period .label b { display: block; font-size: 15px; font-weight: 650; }
.period .label small { color: var(--muted); font-size: 12px; }

/* Hero balance */
.hero {
  position: relative; overflow: hidden;
  background: linear-gradient(135deg, #1d4ed8 0%, #1e3a8a 55%, #0f1d45 100%);
  border: 1px solid rgba(96,165,250,.35);
  box-shadow: 0 18px 40px -18px rgba(37,99,235,.65);
}
.hero::after {
  content: ""; position: absolute; right: -60px; top: -60px; width: 200px; height: 200px; border-radius: 50%;
  background: radial-gradient(circle, rgba(56,189,248,.35), transparent 70%);
}
.hero .k { color: rgba(219,234,254,.8); font-size: 13px; font-weight: 600; }
.hero .big { font-size: 36px; font-weight: 780; letter-spacing: -0.03em; margin: 2px 0 14px; font-variant-numeric: tabular-nums; }
.hero .row { display: flex; gap: 10px; position: relative; z-index: 1; }
.hero .pill {
  flex: 1; background: rgba(7,11,22,.28); border: 1px solid rgba(147,197,253,.18);
  border-radius: 14px; padding: 10px 12px;
}
.hero .pill small { display: flex; align-items: center; gap: 6px; color: rgba(219,234,254,.75); font-size: 12px; }
.hero .pill b { display: block; font-size: 17px; font-variant-numeric: tabular-nums; margin-top: 2px; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }

/* Budget bars */
.budget { padding: 14px 16px; }
.budget + .budget { margin-top: -4px; }
.budget-head { display: flex; align-items: center; gap: 12px; }
.cat-ico {
  width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; font-size: 20px; flex: none;
}
.budget-head .name { flex: 1; min-width: 0; }
.budget-head .name b { display: block; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.budget-head .name small { color: var(--muted); font-size: 12.5px; font-variant-numeric: tabular-nums; }
.budget-head .pct { font-weight: 700; font-variant-numeric: tabular-nums; font-size: 15px; }
.bar { height: 10px; background: rgba(148,178,255,.08); border-radius: 99px; margin-top: 12px; overflow: hidden; position: relative; }
.bar > i {
  display: block; height: 100%; border-radius: 99px; width: 0;
  transition: width .7s cubic-bezier(.2,.8,.2,1);
}
.bar.ok > i { background: linear-gradient(90deg, #2563eb, #38bdf8); box-shadow: 0 0 12px rgba(56,189,248,.45); }
.bar.warn > i { background: linear-gradient(90deg, #f59e0b, #fbbf24); box-shadow: 0 0 12px rgba(251,191,36,.4); }
.bar.over > i { background: linear-gradient(90deg, #ef4444, #f87171); box-shadow: 0 0 12px rgba(248,113,113,.5); }
.budget-foot { display: flex; justify-content: space-between; margin-top: 8px; font-size: 12.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.budget-foot .over { color: var(--red); font-weight: 650; }
.budget-foot .warn { color: var(--amber); font-weight: 600; }
.pct.ok { color: var(--cyan); } .pct.warn { color: var(--amber); } .pct.over { color: var(--red); }

/* Movements list */
.list { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.day { padding: 14px 4px 8px; font-size: 13px; color: var(--muted); font-weight: 600; display: flex; justify-content: space-between; }
.item { display: flex; align-items: center; gap: 12px; padding: 12px 14px; width: 100%; text-align: left; }
.item + .item { border-top: 1px solid var(--line); }
.item:active { background: var(--card-2); }
.item .meta { flex: 1; min-width: 0; }
.item .meta b { display: block; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .meta small { display: block; color: var(--muted); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.amt { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.amt.in { color: var(--green); }
.amt.out { color: var(--text); }

.empty { text-align: center; color: var(--muted); padding: 28px 16px; }
.empty .em { font-size: 36px; margin-bottom: 6px; }
.empty button { margin-top: 12px; }

/* Segmented + chips */
.seg { display: flex; background: var(--bg-2); border: 1px solid var(--line); border-radius: 14px; padding: 4px; gap: 4px; }
.seg button { flex: 1; padding: 9px 8px; border-radius: 10px; color: var(--muted); font-weight: 600; font-size: 14px; }
.seg button.on { background: var(--card-2); color: var(--text); box-shadow: inset 0 0 0 1px var(--line-2); }
.seg.type button.on[data-v="gasto"] { background: rgba(248,113,113,.14); color: #fecaca; box-shadow: inset 0 0 0 1px rgba(248,113,113,.35); }
.seg.type button.on[data-v="ingreso"] { background: rgba(52,211,153,.14); color: #a7f3d0; box-shadow: inset 0 0 0 1px rgba(52,211,153,.35); }

.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 4px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; padding: 8px 13px; border-radius: 99px; background: var(--card); border: 1px solid var(--line);
  color: var(--muted); font-size: 13.5px; font-weight: 600; white-space: nowrap;
}
.chip.on { background: rgba(59,130,246,.18); border-color: rgba(96,165,250,.5); color: #dbeafe; }

.filters { display: grid; gap: 10px; margin-bottom: 6px; }
.totals { display: flex; gap: 10px; margin: 12px 0 4px; }
.totals div { flex: 1; background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px; }
.totals small { color: var(--muted); font-size: 12px; display: block; }
.totals b { font-variant-numeric: tabular-nums; font-size: 15px; }

/* Buttons */
.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%;
  padding: 14px 16px; border-radius: 14px; font-weight: 650; font-size: 16px;
  background: linear-gradient(180deg, #3b82f6, #2563eb); color: white;
  box-shadow: 0 10px 24px -12px rgba(37,99,235,.9);
}
.btn:active { transform: scale(.985); }
.btn.ghost { background: var(--card); color: var(--blue-2); border: 1px solid var(--line-2); box-shadow: none; }
.btn.danger { background: rgba(248,113,113,.12); color: var(--red); border: 1px solid rgba(248,113,113,.3); box-shadow: none; }
.btn.small { width: auto; padding: 10px 16px; font-size: 14px; display: inline-flex; }
.btn svg { width: 19px; height: 19px; }

/* Settings rows */
.row-set { display: flex; align-items: center; gap: 12px; padding: 14px; width: 100%; text-align: left; }
.row-set + .row-set { border-top: 1px solid var(--line); }
.row-set .ico { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; background: rgba(59,130,246,.14); color: var(--blue-2); flex: none; }
.row-set .ico svg { width: 19px; height: 19px; }
.row-set .meta { flex: 1; min-width: 0; }
.row-set .meta small { display: block; color: var(--muted); font-size: 12.5px; }
.row-set.danger .ico { background: rgba(248,113,113,.12); color: var(--red); }
.row-set.danger .meta b { color: var(--red); }
.chev { color: var(--dim); }
.note { color: var(--muted); font-size: 13px; padding: 4px 6px 0; }
.note b { color: var(--text); }

/* ---------- Tab bar ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-template-columns: 1fr 1fr 76px 1fr 1fr; align-items: end;
  padding: 8px 8px calc(var(--safe-bottom) + 8px);
  background: rgba(9,14,28,.82);
  backdrop-filter: blur(18px) saturate(1.4); -webkit-backdrop-filter: blur(18px) saturate(1.4);
  border-top: 1px solid var(--line);
}
.tab { display: flex; flex-direction: column; align-items: center; gap: 3px; color: var(--dim); font-size: 10.5px; font-weight: 600; padding: 4px 0; }
.tab.active { color: var(--blue-2); }
.fab {
  justify-self: center; width: 58px; height: 58px; border-radius: 20px; margin-top: -26px;
  display: grid; place-items: center; color: white;
  background: linear-gradient(145deg, #38bdf8, #2563eb);
  box-shadow: 0 12px 28px -8px rgba(37,99,235,.9), inset 0 1px 0 rgba(255,255,255,.3);
}
.fab svg { width: 28px; height: 28px; stroke-width: 2.5; }
.fab:active { transform: scale(.94); }

/* ---------- Bottom sheet ---------- */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 40; background: rgba(2,5,12,.6);
  opacity: 0; pointer-events: none; transition: opacity .25s;
}
.sheet-backdrop.open { opacity: 1; pointer-events: auto; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
  max-width: 560px; margin: 0 auto; max-height: 92dvh; overflow-y: auto;
  background: var(--bg-2); border: 1px solid var(--line-2); border-bottom: 0;
  border-radius: 26px 26px 0 0;
  padding: 10px 18px calc(var(--safe-bottom) + 18px);
  transform: translateY(105%); transition: transform .32s cubic-bezier(.2,.9,.25,1);
  box-shadow: 0 -20px 50px rgba(0,0,0,.5);
}
.sheet.open { transform: none; }
.grab { width: 40px; height: 5px; border-radius: 99px; background: var(--line-2); margin: 0 auto 12px; }
.sheet h2 { margin: 0 0 14px; font-size: 20px; display: flex; justify-content: space-between; align-items: center; }
.sheet h2 button { color: var(--muted); font-size: 15px; font-weight: 500; }

.field { margin-bottom: 14px; }
.field > label { display: block; font-size: 13px; color: var(--muted); font-weight: 600; margin: 0 0 6px 4px; }
.input {
  width: 100%; background: var(--card); border: 1px solid var(--line-2); border-radius: 14px;
  padding: 13px 14px; font-size: 16px; outline: none; -webkit-appearance: none; appearance: none;
}
.input:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(59,130,246,.2); }
input[type="date"].input, input[type="month"].input { min-height: 50px; }
.amount-wrap { display: flex; align-items: center; justify-content: center; gap: 4px; padding: 6px 0 12px; }
.amount-wrap span { font-size: 34px; color: var(--muted); font-weight: 600; }
.amount-input {
  background: none; border: 0; outline: none; font-size: 44px; font-weight: 780; letter-spacing: -0.03em;
  width: 100%; max-width: 280px; text-align: center; font-variant-numeric: tabular-nums;
}
.amount-input::placeholder { color: var(--dim); }

.cat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.cat-opt {
  display: flex; flex-direction: column; align-items: center; gap: 5px; padding: 10px 4px;
  border-radius: 14px; background: var(--card); border: 1px solid var(--line); font-size: 11.5px; font-weight: 600; color: var(--muted);
  min-width: 0;
}
.cat-opt span:last-child { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cat-opt .e { font-size: 22px; }
.cat-opt.on { border-color: var(--blue); background: rgba(59,130,246,.14); color: var(--text); }

.emoji-grid { display: grid; grid-template-columns: repeat(8, 1fr); gap: 6px; }
.emoji-grid button { aspect-ratio: 1; border-radius: 10px; font-size: 20px; background: var(--card); border: 1px solid var(--line); }
.emoji-grid button.on { border-color: var(--blue); background: rgba(59,130,246,.18); }
.color-grid { display: flex; flex-wrap: wrap; gap: 10px; }
.color-grid button { width: 34px; height: 34px; border-radius: 50%; border: 3px solid transparent; }
.color-grid button.on { border-color: white; }
.actions { display: grid; gap: 10px; margin-top: 18px; }
.pay-row { display: flex; gap: 10px; }
.pay-row .input { text-align: center; }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--safe-bottom) + 96px); z-index: 60;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: #1e293b; border: 1px solid var(--line-2); color: var(--text);
  padding: 11px 18px; border-radius: 14px; font-weight: 600; font-size: 14px; white-space: nowrap;
  transition: all .25s; box-shadow: 0 10px 30px rgba(0,0,0,.4);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Íconos de categoría ---------- */
.cat-ico svg { width: 20px; height: 20px; }
.cat-opt .e { display: grid; place-items: center; height: 24px; }
.cat-opt .e svg { width: 22px; height: 22px; }
.emoji-grid button { display: grid; place-items: center; color: var(--muted); }
.emoji-grid button svg { width: 20px; height: 20px; }
.emoji-grid button.on { color: var(--blue-2); }
.empty .em { display: grid; place-items: center; color: var(--blue-2); }
.empty .em svg { width: 36px; height: 36px; stroke-width: 1.6; }
