/* =========================================================
   Hogar Finanzas · sistema visual propio
   Mobile first · light/dark · sombras mínimas · mucho aire
   ========================================================= */
:root{
  --accent:#0E9F6E; --accent-soft:#E6F6EF; --accent-ink:#07724F;
  --income:#0E9F6E; --expense:#E5484D; --transfer:#3B82F6;
  --warning:#F59E0B; --danger:#E5484D; --info:#3B82F6; --success:#0E9F6E;

  --bg:#F4F6F8; --surface:#FFFFFF; --surface-2:#F8FAFB; --surface-3:#EEF1F5;
  --ink:#0B1220; --ink-2:#3C4757; --muted:#6B7A8D; --line:#E6EAF0;
  --shadow:0 1px 2px rgba(11,18,32,.05), 0 8px 24px -16px rgba(11,18,32,.18);
  --shadow-lg:0 2px 6px rgba(11,18,32,.06), 0 24px 48px -24px rgba(11,18,32,.3);

  --r-sm:12px; --r:16px; --r-lg:22px; --r-xl:28px; --r-full:999px;
  --sp:16px;
  --nav-h:68px;
  --font:-apple-system,BlinkMacSystemFont,"Inter","Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif;
  --ease:cubic-bezier(.22,.61,.36,1);
  color-scheme:light;
}
html[data-theme="dark"], html[data-theme="system"]{color-scheme:light dark}
@media (prefers-color-scheme:dark){
  html[data-theme="system"]{
    --bg:#080D16; --surface:#111A28; --surface-2:#16202F; --surface-3:#1D2939;
    --ink:#E9EEF6; --ink-2:#BCC7D6; --muted:#8391A5; --line:#222E40;
    --accent-soft:#0E2A22;
    --shadow:0 1px 2px rgba(0,0,0,.4); --shadow-lg:0 24px 48px -24px rgba(0,0,0,.8);
  }
}
html[data-theme="dark"]{
  --bg:#080D16; --surface:#111A28; --surface-2:#16202F; --surface-3:#1D2939;
  --ink:#E9EEF6; --ink-2:#BCC7D6; --muted:#8391A5; --line:#222E40;
  --accent-soft:#0E2A22;
  --shadow:0 1px 2px rgba(0,0,0,.4); --shadow-lg:0 24px 48px -24px rgba(0,0,0,.8);
}

*,*::before,*::after{box-sizing:border-box}
[hidden]{display:none !important}
html,body{height:100%}
body{
  margin:0; background:var(--bg); color:var(--ink);
  font-family:var(--font); font-size:15px; line-height:1.45;
  -webkit-font-smoothing:antialiased; text-rendering:optimizeLegibility;
  overscroll-behavior-y:none;
}
button,input,select,textarea{font:inherit;color:inherit}
button{cursor:pointer;border:0;background:none}
a{color:var(--accent);text-decoration:none}
h1,h2,h3,h4{margin:0;font-weight:650;letter-spacing:-.015em}
h1{font-size:26px} h2{font-size:19px} h3{font-size:16px}
p{margin:0}
ul{margin:0;padding:0;list-style:none}
.num{font-variant-numeric:tabular-nums;font-feature-settings:"tnum"}
:focus-visible{outline:2px solid var(--accent);outline-offset:2px;border-radius:8px}
::selection{background:var(--accent);color:#fff}
@media (prefers-reduced-motion:reduce){*{animation-duration:.01ms !important;transition-duration:.01ms !important}}

/* ---------- arranque ---------- */
.boot{min-height:100dvh;display:grid;place-content:center;gap:22px;justify-items:center;color:var(--accent)}
.boot__bar{width:120px;height:3px;border-radius:3px;background:var(--surface-3);overflow:hidden}
.boot__bar span{display:block;height:100%;width:40%;background:var(--accent);border-radius:3px;animation:slide 1.1s var(--ease) infinite}
@keyframes slide{0%{transform:translateX(-110%)}100%{transform:translateX(320%)}}

/* ---------- estructura ---------- */
.app-shell{min-height:100dvh;display:flex;flex-direction:column}
.topbar{
  position:sticky;top:0;z-index:30;display:flex;align-items:center;gap:10px;
  padding:calc(env(safe-area-inset-top) + 10px) var(--sp) 10px;
  background:color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter:saturate(180%) blur(14px); -webkit-backdrop-filter:saturate(180%) blur(14px);
  border-bottom:1px solid transparent; transition:border-color .2s
}
.topbar--scrolled{border-bottom-color:var(--line)}
.topbar__title{flex:1;min-width:0}
.topbar__title b{display:block;font-size:16px;font-weight:650;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.topbar__title small{display:block;color:var(--muted);font-size:12.5px}
.main{flex:1;padding:4px var(--sp) calc(var(--nav-h) + 34px + env(safe-area-inset-bottom));max-width:720px;width:100%;margin:0 auto}
@media(min-width:760px){
  .topbar{padding-left:max(var(--sp),calc((100vw - 720px)/2));padding-right:max(var(--sp),calc((100vw - 720px)/2))}
  .bottom-nav{left:50%;transform:translateX(-50%);width:min(560px,calc(100% - 32px));bottom:18px;border-radius:22px;border:1px solid var(--line);box-shadow:var(--shadow-lg);height:var(--nav-h)}
  .toasts{bottom:calc(var(--nav-h) + 34px)}
  .update-bar{left:50%;transform:translateX(-50%);width:min(520px,calc(100% - 32px));bottom:calc(var(--nav-h) + 34px)}
}
.view{animation:fade .22s var(--ease)}
@keyframes fade{from{opacity:0;transform:translateY(6px)}to{opacity:1;transform:none}}
.stack{display:flex;flex-direction:column;gap:14px}
.row{display:flex;align-items:center;gap:10px}
.row--between{justify-content:space-between}
.grid-2{display:grid;grid-template-columns:1fr 1fr;gap:12px}
.grid-auto{display:grid;grid-template-columns:repeat(auto-fill,minmax(150px,1fr));gap:12px}
.section-title{display:flex;align-items:center;justify-content:space-between;margin:18px 2px 2px}
.section-title h2{font-size:17px}
.section-title a,.section-title button{color:var(--accent);font-size:13.5px;font-weight:600}
.muted{color:var(--muted)}
.small{font-size:13px}
.center{text-align:center}

/* ---------- tarjetas ---------- */
.card{background:var(--surface);border-radius:var(--r-lg);padding:18px;box-shadow:var(--shadow)}
.card--flat{box-shadow:none;border:1px solid var(--line)}
.card--tap{transition:transform .15s var(--ease)}
.card--tap:active{transform:scale(.985)}
.card__head{display:flex;align-items:center;justify-content:space-between;gap:10px;margin-bottom:12px}

/* héroe del balance */
.hero{
  position:relative;overflow:hidden;color:#fff;border-radius:var(--r-xl);padding:22px;
  background:linear-gradient(145deg,#0E9F6E 0%,#0B8B61 45%,#0A6E52 100%);
  box-shadow:0 20px 40px -24px rgba(14,159,110,.85)
}
.hero::after{content:"";position:absolute;inset:auto -60px -90px auto;width:220px;height:220px;border-radius:50%;background:rgba(255,255,255,.09)}
.hero::before{content:"";position:absolute;top:-70px;right:30px;width:150px;height:150px;border-radius:50%;background:rgba(255,255,255,.07)}
.hero__label{font-size:12.5px;opacity:.82;letter-spacing:.02em;text-transform:uppercase}
.hero__value{font-size:34px;font-weight:700;letter-spacing:-.03em;margin:4px 0 14px}
.hero__grid{position:relative;display:grid;grid-template-columns:1fr 1fr;gap:12px}
.hero__item{background:rgba(255,255,255,.14);border-radius:var(--r);padding:10px 12px}
.hero__item small{display:block;font-size:11.5px;opacity:.85}
.hero__item b{font-size:16.5px;font-weight:650}

/* KPI */
.kpi{background:var(--surface);border-radius:var(--r-lg);padding:14px 15px;box-shadow:var(--shadow)}
.kpi small{display:block;color:var(--muted);font-size:12.5px;margin-bottom:3px}
.kpi b{font-size:19px;font-weight:680;letter-spacing:-.02em}
.kpi .delta{font-size:12px;font-weight:600;margin-left:6px}
.delta--up{color:var(--expense)} .delta--down{color:var(--income)}

/* ---------- listas ---------- */
.list{background:var(--surface);border-radius:var(--r-lg);box-shadow:var(--shadow);overflow:hidden}
.item{display:flex;align-items:center;gap:12px;padding:13px 15px;width:100%;text-align:left;border-bottom:1px solid var(--line);background:none}
.item:last-child{border-bottom:0}
.item:active{background:var(--surface-2)}
.item__body{flex:1;min-width:0}
.item__title{display:block;font-weight:600;font-size:14.5px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.item__sub{display:block;color:var(--muted);font-size:12.5px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.item__amount{display:block}
.item__amount{font-weight:680;font-size:15px;white-space:nowrap}
.amount--income{color:var(--income)} .amount--expense{color:var(--ink)} .amount--transfer{color:var(--transfer)}
.day-head{display:flex;justify-content:space-between;padding:16px 4px 6px;color:var(--muted);font-size:12.5px;font-weight:600;text-transform:capitalize}

.scope-picker{display:flex;flex-direction:column;gap:10px}
.scope-picker .seg{width:100%}
.scope-picker .seg button{padding:11px 10px}
.scope-picker__hint{font-size:12.5px;color:var(--muted);line-height:1.4}

.tag-scope{display:inline-flex;align-items:center;gap:3px;margin-right:6px;padding:1px 7px;border-radius:var(--r-full);
  background:var(--surface-3);color:var(--ink-2);font-size:10.5px;font-weight:650;vertical-align:1px}
.tag-scope svg{width:11px;height:11px}

.avatar{width:34px;height:34px;border-radius:var(--r-full);display:grid;place-items:center;color:#fff;font-weight:650;font-size:13px;flex:none}
.avatar--sm{width:24px;height:24px;font-size:11px}
.bubble{width:40px;height:40px;border-radius:14px;display:grid;place-items:center;flex:none;background:var(--surface-3)}
.bubble svg{width:20px;height:20px}

/* ---------- barras de progreso ---------- */
.bar{height:8px;border-radius:var(--r-full);background:var(--surface-3);overflow:hidden}
.bar>span{display:block;height:100%;border-radius:var(--r-full);background:var(--accent);transition:width .5s var(--ease)}
.bar--normal>span{background:var(--accent)}
.bar--warning>span{background:var(--warning)}
.bar--critical>span{background:#F97316}
.bar--exceeded>span{background:var(--danger)}
.bar__mark{position:relative}
.bar__mark::after{content:"";position:absolute;top:-3px;width:2px;height:14px;border-radius:2px;background:var(--ink);opacity:.35;left:var(--at,50%)}

/* ---------- chips / pills / badges ---------- */
.chips{display:flex;gap:8px;overflow-x:auto;padding:2px 0 4px;scrollbar-width:none;-ms-overflow-style:none}
.chips::-webkit-scrollbar{display:none}
.chip{flex:none;padding:8px 14px;border-radius:var(--r-full);background:var(--surface);border:1px solid var(--line);font-size:13.5px;font-weight:600;color:var(--ink-2);white-space:nowrap;transition:.15s var(--ease)}
.chip[aria-pressed="true"],.chip.is-active{background:var(--ink);color:var(--bg);border-color:var(--ink)}
.badge{display:inline-flex;align-items:center;gap:5px;padding:3px 9px;border-radius:var(--r-full);font-size:11.5px;font-weight:650;background:var(--surface-3);color:var(--ink-2)}
.badge--accent{background:var(--accent-soft);color:var(--accent-ink)}
.badge--warning{background:#FEF3C7;color:#92400E}
.badge--danger{background:#FEE2E2;color:#991B1B}
.badge--info{background:#DBEAFE;color:#1E40AF}
html[data-theme="dark"] .badge--warning{background:#3A2A08;color:#FCD34D}
html[data-theme="dark"] .badge--danger{background:#3B1416;color:#FCA5A5}
html[data-theme="dark"] .badge--info{background:#132347;color:#93C5FD}

/* ---------- insights ---------- */
.insight{display:flex;gap:11px;padding:13px 14px;border-radius:var(--r);background:var(--surface);box-shadow:var(--shadow);align-items:flex-start}
.insight__dot{width:8px;height:8px;border-radius:50%;margin-top:6px;flex:none;background:var(--info)}
.insight--warning .insight__dot{background:var(--warning)}
.insight--danger .insight__dot{background:var(--danger)}
.insight--success .insight__dot{background:var(--success)}
.insight p{font-size:13.5px;line-height:1.45;color:var(--ink-2)}
.insights-scroll{display:grid;grid-auto-flow:column;grid-auto-columns:minmax(250px,84%);gap:10px;overflow-x:auto;scroll-snap-type:x mandatory;padding-bottom:4px;scrollbar-width:none}
.insights-scroll::-webkit-scrollbar{display:none}
.insights-scroll>*{scroll-snap-align:start}
@media(min-width:640px){.insights-scroll{grid-auto-flow:row;grid-auto-columns:auto;overflow:visible}}

/* ---------- formularios ---------- */
.field{display:block;margin-bottom:14px}
.field>span{display:block;font-size:12.5px;font-weight:600;color:var(--muted);margin-bottom:6px}
.input,.select,.textarea{
  width:100%;padding:13px 14px;border-radius:var(--r);border:1px solid var(--line);
  background:var(--surface-2);color:var(--ink);transition:border-color .15s,background .15s;font-size:15px
}
.input:focus,.select:focus,.textarea:focus{outline:none;border-color:var(--accent);background:var(--surface)}
.textarea{min-height:84px;resize:vertical}
.select{appearance:none;background-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%236B7A8D' stroke-width='2.2' stroke-linecap='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");background-repeat:no-repeat;background-position:right 12px center;background-size:18px;padding-right:38px}
.field--error .input,.field--error .select{border-color:var(--danger)}
.field__error{display:block;color:var(--danger);font-size:12px;margin-top:5px}
.hint{font-size:12.5px;color:var(--muted);margin-top:6px}
.switch{display:flex;align-items:center;justify-content:space-between;gap:12px;padding:12px 0}
.switch input{appearance:none;width:46px;height:28px;border-radius:var(--r-full);background:var(--surface-3);position:relative;transition:.2s var(--ease);flex:none}
.switch input::after{content:"";position:absolute;top:3px;left:3px;width:22px;height:22px;border-radius:50%;background:#fff;box-shadow:0 1px 3px rgba(0,0,0,.25);transition:.2s var(--ease)}
.switch input:checked{background:var(--accent)}
.switch input:checked::after{transform:translateX(18px)}

.btn{display:inline-flex;align-items:center;justify-content:center;gap:8px;padding:13px 20px;border-radius:var(--r);font-weight:650;font-size:15px;background:var(--surface-3);color:var(--ink);transition:transform .12s var(--ease),opacity .15s}
.btn:active{transform:scale(.97)}
.btn[disabled]{opacity:.55;pointer-events:none}
.btn--primary{background:var(--accent);color:#fff;box-shadow:0 10px 20px -12px rgba(14,159,110,.9)}
.btn--danger{background:transparent;color:var(--danger);border:1px solid var(--danger)}
.btn--ghost{background:transparent;color:var(--ink-2);border:1px solid var(--line)}
.btn--block{width:100%}
.btn--sm{padding:9px 14px;font-size:13.5px;border-radius:12px}
.icon-btn{width:38px;height:38px;border-radius:var(--r-full);display:grid;place-items:center;background:var(--surface);box-shadow:var(--shadow);color:var(--ink-2);flex:none}
.icon-btn:active{transform:scale(.94)}
.icon-btn svg{width:19px;height:19px}
.icon-btn__dot{position:absolute;top:6px;right:6px;width:8px;height:8px;border-radius:50%;background:var(--danger);border:2px solid var(--bg)}

/* teclado de importe */
.amount-input{display:flex;align-items:center;justify-content:center;gap:8px;padding:14px 0 6px}
.amount-input span{font-size:20px;color:var(--muted);font-weight:600}
.amount-input input{
  border:0;background:none;font-size:42px;font-weight:700;letter-spacing:-.03em;text-align:left;
  flex:0 1 auto;width:auto;max-width:calc(100% - 60px);min-width:0;padding:0;color:var(--ink);
  font-variant-numeric:tabular-nums
}
.amount-input input:focus{outline:none}
.seg{display:grid;grid-auto-flow:column;background:var(--surface-3);border-radius:var(--r-full);padding:4px;gap:2px}
.seg button{padding:9px 10px;border-radius:var(--r-full);font-size:13.5px;font-weight:650;color:var(--muted);transition:.16s var(--ease)}
.seg button[aria-pressed="true"]{background:var(--surface);color:var(--ink);box-shadow:var(--shadow)}

/* ---------- navegación inferior ---------- */
.bottom-nav{
  position:fixed;left:0;right:0;bottom:0;z-index:40;display:grid;grid-template-columns:repeat(5,1fr);
  align-items:center;height:calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom:env(safe-area-inset-bottom);
  background:color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter:saturate(180%) blur(18px);-webkit-backdrop-filter:saturate(180%) blur(18px);
  border-top:1px solid var(--line)
}
.bottom-nav a{display:grid;justify-items:center;gap:3px;color:var(--muted);font-size:10.5px;font-weight:600;padding:8px 0}
.bottom-nav a svg{width:22px;height:22px}
.bottom-nav a.is-active{color:var(--accent)}
.fab{
  justify-self:center;width:54px;height:54px;border-radius:20px;background:var(--accent);color:#fff;
  display:grid;place-items:center;box-shadow:0 14px 26px -12px rgba(14,159,110,.95);margin-top:-18px;
  transition:transform .16s var(--ease)
}
.fab:active{transform:scale(.92) rotate(90deg)}
.fab svg{width:26px;height:26px}

/* ---------- hoja modal ---------- */
.sheet-backdrop{position:fixed;inset:0;z-index:60;background:rgba(6,11,20,.45);backdrop-filter:blur(2px);animation:fadeIn .18s var(--ease)}
@keyframes fadeIn{from{opacity:0}to{opacity:1}}
.sheet{
  position:fixed;left:0;right:0;bottom:0;z-index:61;background:var(--surface);
  border-radius:var(--r-xl) var(--r-xl) 0 0;box-shadow:var(--shadow-lg);
  max-height:92dvh;display:flex;flex-direction:column;animation:up .26s var(--ease);
  padding-bottom:env(safe-area-inset-bottom)
}
@keyframes up{from{transform:translateY(100%)}to{transform:none}}
@media(min-width:680px){
  .sheet{left:50%;right:auto;bottom:auto;top:50%;transform:translate(-50%,-50%);width:520px;border-radius:var(--r-xl);animation:pop .22s var(--ease)}
  @keyframes pop{from{opacity:0;transform:translate(-50%,-46%) scale(.97)}to{opacity:1;transform:translate(-50%,-50%) scale(1)}}
}
.sheet__grab{width:40px;height:4px;border-radius:4px;background:var(--surface-3);margin:10px auto 2px}
.sheet__head{display:flex;align-items:center;justify-content:space-between;padding:8px 18px 4px}
.sheet__body{padding:10px 18px 20px;overflow-y:auto;-webkit-overflow-scrolling:touch}
.sheet__foot{padding:12px 18px calc(16px + env(safe-area-inset-bottom));border-top:1px solid var(--line);display:flex;gap:10px}
.sheet__foot .btn{flex:1}

/* ---------- avisos ---------- */
.toasts{position:fixed;left:0;right:0;bottom:calc(var(--nav-h) + 14px + env(safe-area-inset-bottom));z-index:80;display:grid;justify-items:center;gap:8px;padding:0 16px;pointer-events:none}
.toast{
  background:var(--ink);color:var(--bg);padding:12px 16px;border-radius:14px;font-size:13.5px;font-weight:600;
  box-shadow:var(--shadow-lg);max-width:420px;animation:up .2s var(--ease);display:flex;gap:9px;align-items:center
}
.toast--error{background:var(--danger);color:#fff}
.toast--success{background:var(--accent);color:#fff}

/* ---------- skeleton y vacíos ---------- */
.sk{background:linear-gradient(90deg,var(--surface-3) 25%,var(--surface-2) 37%,var(--surface-3) 63%);background-size:400% 100%;animation:shimmer 1.4s linear infinite;border-radius:10px}
@keyframes shimmer{0%{background-position:100% 0}100%{background-position:0 0}}
.sk--hero{height:170px;border-radius:var(--r-xl)}
.sk--row{height:62px;border-radius:var(--r)}
.sk--kpi{height:74px;border-radius:var(--r-lg)}
.empty{display:grid;justify-items:center;gap:10px;text-align:center;padding:34px 22px;color:var(--muted)}
.empty svg{width:56px;height:56px;color:var(--surface-3)}
.empty h3{color:var(--ink);font-size:16px}
.empty p{font-size:13.5px;max-width:280px}

/* ---------- gráficos ---------- */
.chart-wrap{position:relative;height:210px}
.legend{display:flex;flex-wrap:wrap;gap:10px 16px;margin-top:12px}
.legend li{display:flex;align-items:center;gap:7px;font-size:12.5px;color:var(--ink-2)}
.legend i{width:9px;height:9px;border-radius:3px;flex:none}
.mini-bars{display:flex;align-items:flex-end;gap:7px;height:96px}
.mini-bars div{flex:1;display:flex;flex-direction:column;justify-content:flex-end;gap:3px;height:100%}
.mini-bars span{display:block;border-radius:5px 5px 0 0;min-height:3px}
.mini-bars small{font-size:10px;color:var(--muted);text-align:center}

/* ---------- auth ---------- */
.auth{min-height:100dvh;display:grid;place-items:center;padding:24px 20px calc(24px + env(safe-area-inset-bottom));background:var(--bg)}
.auth__card{width:100%;max-width:400px}
.auth__brand{display:grid;justify-items:center;gap:10px;margin-bottom:26px;color:var(--accent)}
.auth__brand b{color:var(--ink);font-size:21px;letter-spacing:-.02em}
.auth__brand small{color:var(--muted);font-size:13.5px;font-weight:500}
.auth__switch{margin-top:18px;text-align:center;font-size:13.5px;color:var(--muted)}

/* tabla compacta */
.table{width:100%;border-collapse:collapse;font-size:13.5px}
.table th{text-align:left;color:var(--muted);font-weight:600;font-size:12px;padding:8px 6px;border-bottom:1px solid var(--line)}
.table td{padding:10px 6px;border-bottom:1px solid var(--line)}
.table tr:last-child td{border-bottom:0}
.table td.r,.table th.r{text-align:right;white-space:nowrap}
.table td:first-child{white-space:nowrap;max-width:180px;overflow:hidden;text-overflow:ellipsis}
.scroll-x{overflow-x:auto;-webkit-overflow-scrolling:touch}

.update-bar{position:fixed;left:16px;right:16px;bottom:calc(var(--nav-h) + 16px + env(safe-area-inset-bottom));z-index:70;background:var(--ink);color:var(--bg);padding:12px 14px;border-radius:16px;display:flex;align-items:center;gap:12px;box-shadow:var(--shadow-lg);font-size:13.5px}
.update-bar button{margin-left:auto;background:var(--accent);color:#fff;padding:8px 14px;border-radius:10px;font-weight:650;font-size:13px}
.offline-flag{background:var(--warning);color:#3b2500;text-align:center;font-size:12.5px;font-weight:650;padding:6px}
