/* ============================================================================
   Presupuesto — estilos
   Modo claro/oscuro/sistema, 5 temas, 3 tamaños de letra, iconos SVG.
   ============================================================================ */

:root{
  --bg:#f4f7f9;
  --surface:#ffffff;
  --surface-2:#e9eef2;
  --text:#18222c;
  --text-muted:#5e6b78;
  --border:#d9e1e7;
  --shadow:0 8px 24px rgba(20,35,50,.07);
  --danger:#b4483c;
  --warning:#a86a12;
  --warning-soft:rgba(168,106,18,.12);
  --success:#2e7d5d;
  --radius:16px;
  --accent:#2b5f8a;
  --accent-2:#2e7d5d;
  --accent-soft:rgba(43,95,138,.12);
  --font-scale:1;
}

/* Temas (color de acento) */
html[data-theme="ocean"]{ --accent-base:#2b5f8a; --accent-2-base:#2e7d5d; }
html[data-theme="forest"]{ --accent-base:#2f6b4f; --accent-2-base:#a86a12; }
html[data-theme="graphite"]{ --accent-base:#41576b; --accent-2-base:#6b8fb5; }
html[data-theme="sand"]{ --accent-base:#8a5a2b; --accent-2-base:#b07a3a; }
html[data-theme="violet"]{ --accent-base:#6b4a8a; --accent-2-base:#a06fb0; }

:root{ --accent:var(--accent-base); --accent-2:var(--accent-2-base); }
html[data-mode="dark"]{
  --accent:color-mix(in srgb, var(--accent-base) 74%, white);
  --accent-2:color-mix(in srgb, var(--accent-2-base) 74%, white);
  --accent-soft:color-mix(in srgb, var(--accent) 18%, transparent);
}
@media (prefers-color-scheme: dark){
  html[data-mode="system"]{
    --accent:color-mix(in srgb, var(--accent-base) 74%, white);
    --accent-2:color-mix(in srgb, var(--accent-2-base) 74%, white);
    --accent-soft:color-mix(in srgb, var(--accent) 18%, transparent);
  }
}

/* Modo claro */
html[data-mode="light"]{
  --bg:#f4f7f9; --surface:#ffffff; --surface-2:#e9eef2;
  --text:#18222c; --text-muted:#5e6b78; --border:#d9e1e7;
  --shadow:0 8px 24px rgba(20,35,50,.07);
  color-scheme:light;
}

/* Modo oscuro */
html[data-mode="dark"]{
  --bg:#0e151c; --surface:#16202a; --surface-2:#1f2b37;
  --text:#e9eff4; --text-muted:#9aa8b4; --border:#2a3742;
  --shadow:0 10px 28px rgba(0,0,0,.32);
  color-scheme:dark;
}
@media (prefers-color-scheme: dark){
  html[data-mode="system"]{
    --bg:#0e151c; --surface:#16202a; --surface-2:#1f2b37;
    --text:#e9eff4; --text-muted:#9aa8b4; --border:#2a3742;
    --shadow:0 10px 28px rgba(0,0,0,.32);
    color-scheme:dark;
  }
}

/* Tamaño de letra */
html{font-size:16px}
html[data-fontsize="small"]{font-size:14px}
html[data-fontsize="normal"]{font-size:16px}
html[data-fontsize="large"]{font-size:18px}

*{box-sizing:border-box}
[hidden]{display:none!important}
html,body{margin:0;padding:0}
body{
  background:var(--bg);
  color:var(--text);
  font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Inter,Helvetica,Arial,"Noto Sans","Noto Sans CJK SC","Noto Sans Cyrillic",sans-serif;
  line-height:1.45;
  -webkit-font-smoothing:antialiased;
  -webkit-tap-highlight-color:transparent;
  overflow-x:hidden;
}
a{color:inherit;text-decoration:none}
button{font:inherit;color:inherit;background:none;border:0;cursor:pointer}
input,select,textarea{font:inherit;color:var(--text)}
h1,h2,h3,h4,p{margin:0}
ul,ol{margin:0;padding-left:1.1rem}
.muted{color:var(--text-muted)}
.small{font-size:.82rem}
.empty{text-align:center;color:var(--text-muted);padding:24px 8px;font-size:.9rem}
.form-error{color:var(--danger);font-size:.85rem;text-align:center}
.legal-note{font-size:.72rem;color:var(--text-muted);line-height:1.5;text-align:center}
.legal-note a{color:var(--accent);text-decoration:underline;text-underline-offset:2px}

/* Iconos */
.icon-sprite{display:none}
.icon{
  width:1.25em;height:1.25em;flex:0 0 auto;
  fill:none;stroke:currentColor;stroke-width:1.8;
  stroke-linecap:round;stroke-linejoin:round;
  vertical-align:-.18em;
}

/* Shell */
.app-shell{min-height:100vh;display:flex;flex-direction:column}
.app-main{width:100%;max-width:1100px;margin:0 auto;padding:16px 14px 96px;flex:1}

/* Header */
.app-header{
  position:sticky;top:0;z-index:25;
  display:flex;align-items:center;gap:10px;
  padding:calc(10px + env(safe-area-inset-top)) calc(14px + env(safe-area-inset-right)) 10px calc(14px + env(safe-area-inset-left));
  background:color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter:blur(14px);
  border-bottom:1px solid var(--border);
}
.header-title{flex:1;min-width:0;text-align:center}
.header-title h1{font-size:1.05rem;font-weight:700;letter-spacing:-.01em;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.header-sub{display:block;font-size:.7rem;color:var(--text-muted);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.header-actions{display:flex;gap:4px}
.icon-btn{
  display:inline-flex;align-items:center;justify-content:center;
  width:44px;height:44px;border-radius:12px;color:var(--text);
  transition:background .15s ease;
}
.icon-btn:hover{background:var(--surface-2)}
.icon-btn .icon{width:1.3em;height:1.3em}

/* Pantallas */
.pantalla{display:none}
.pantalla.activa{display:block}

/* Login */
.login-card{
  max-width:360px;margin:8vh auto 0;
  display:flex;flex-direction:column;align-items:center;gap:14px;text-align:center;
}
.brand-mark{
  width:72px;height:72px;border-radius:22px;
  display:grid;place-items:center;
  background:linear-gradient(145deg,var(--accent),var(--accent-2));
  color:#fff;font-size:2rem;font-weight:800;letter-spacing:-.04em;
  box-shadow:var(--shadow);
}
.login-card h2{font-size:1.5rem;font-weight:750}
.gsi-button{min-height:44px;display:flex;justify-content:center;width:100%}
.gsi-button > div{width:100%!important}

/* Tarjetas */
.card{
  background:var(--surface);
  border:1px solid var(--border);
  border-radius:var(--radius);
  box-shadow:var(--shadow);
  padding:14px;
}

/* KPIs */
.kpi-grid{display:grid;grid-template-columns:repeat(2,1fr);gap:10px}
.kpi{display:flex;flex-direction:column;gap:6px;min-width:0}
.kpi-label{font-size:.72rem;text-transform:uppercase;letter-spacing:.07em;color:var(--text-muted);font-weight:600}
.kpi-value{font-size:1.35rem;font-weight:750;letter-spacing:-.02em;font-variant-numeric:tabular-nums;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
@media(min-width:760px){.kpi-grid{grid-template-columns:repeat(4,1fr)}}

/* Toolbar y campos */
.toolbar{display:flex;flex-wrap:wrap;gap:10px;margin:12px 0}
.field{display:flex;flex-direction:column;gap:6px;font-size:.78rem;color:var(--text-muted);min-width:0}
.field.compact{flex:1 1 140px}
.field.grow{flex:2 1 200px}
.field input,.field select{
  width:100%;padding:10px 12px;border-radius:10px;
  border:1px solid var(--border);background:var(--surface);
  color:var(--text);outline:none;font-size:.92rem;
}
.field input:focus,.field select:focus{border-color:var(--accent);box-shadow:0 0 0 3px var(--accent-soft)}
.field small{font-size:.72rem;color:var(--text-muted);line-height:1.35}
.two-cols{display:grid;grid-template-columns:1fr 1fr;gap:10px}

/* Botones */
.btn{
  display:inline-flex;align-items:center;justify-content:center;gap:8px;
  padding:10px 14px;min-height:44px;border-radius:12px;font-weight:650;font-size:.9rem;
  border:1px solid transparent;transition:transform .1s ease,background .15s ease,opacity .15s ease;
}
.btn:active{transform:translateY(1px)}
.btn:disabled{opacity:.45;cursor:not-allowed}
.btn-primary{background:var(--accent);color:#fff}
.btn-ghost{background:transparent;border-color:var(--border);color:var(--text)}
.btn-ghost:hover{background:var(--surface-2)}
.btn-danger{background:var(--danger);color:#fff}
.btn-block{width:100%}
.btn-sm{padding:8px 12px;font-size:.82rem;border-radius:10px}

/* Chips */
.chip-row{display:flex;flex-wrap:wrap;gap:8px;overflow:visible;padding:2px 0 6px}
.chip{
  display:inline-flex;align-items:center;gap:7px;white-space:nowrap;
  padding:9px 13px;min-height:44px;border-radius:999px;border:1px solid var(--border);
  background:var(--surface);color:var(--text-muted);font-size:.85rem;font-weight:600;
}
.chip.active{background:var(--accent);border-color:var(--accent);color:#fff}
.chip .icon{width:1.05em;height:1.05em}

/* Gráficos */
.charts-grid{display:grid;grid-template-columns:1fr;gap:12px;margin:12px 0}
@media(min-width:820px){.charts-grid{grid-template-columns:1.25fr 1fr}}
.chart-card h3{font-size:.92rem;font-weight:700;margin-bottom:12px}
.bars{display:flex;flex-direction:column;gap:12px}
.bar-row{display:grid;grid-template-columns:1fr auto;gap:5px 10px;align-items:end}
.bar-label{font-size:.8rem;font-weight:600;color:var(--text);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.bar-value{font-size:.8rem;font-weight:700;color:var(--text-muted);font-variant-numeric:tabular-nums;white-space:nowrap}
.bar-track{grid-column:1 / -1;height:9px;border-radius:999px;background:var(--surface-2);overflow:hidden}
.bar-fill{height:100%;border-radius:999px;background:linear-gradient(90deg,var(--accent),var(--accent-2));transition:width .35s ease}
.chart-empty{font-size:.85rem;color:var(--text-muted);padding:18px 0;text-align:center}
.donut-wrap{display:flex;align-items:center;gap:18px;flex-wrap:wrap;justify-content:center}
.donut{width:132px;height:132px;flex:0 0 auto}
.donut-center{font-variant-numeric:tabular-nums}
.donut-legend{display:flex;flex-direction:column;gap:8px;font-size:.82rem;min-width:130px}
.legend-item{display:flex;align-items:center;gap:8px}
.legend-dot{width:10px;height:10px;border-radius:50%;flex:0 0 auto}
.legend-value{margin-left:auto;font-weight:700;font-variant-numeric:tabular-nums}

/* Accesos rápidos */
.quick-grid{display:grid;grid-template-columns:1fr 1fr;gap:10px;margin-top:12px}
.quick{display:flex;flex-direction:column;gap:4px;transition:border-color .15s ease}
.quick:hover{border-color:var(--accent)}
.quick .icon{color:var(--accent);width:1.45em;height:1.45em;margin-bottom:2px}
.quick span{font-size:.78rem;color:var(--text-muted)}
.quick strong{font-size:1.05rem;font-variant-numeric:tabular-nums}

/* Cargar */
.upload-card{border-style:dashed;display:flex;flex-direction:column;align-items:center;gap:10px;text-align:center;margin-top:10px}
.upload-title{font-weight:700}
.preview-wrap{display:flex;flex-direction:column;align-items:center;gap:10px}
.preview-wrap img{max-width:230px;max-height:230px;border-radius:12px;border:1px solid var(--border);object-fit:cover}
.row-actions{display:flex;gap:8px;flex-wrap:wrap;justify-content:flex-end}
.row-actions.mt{margin-top:12px}
.status{display:flex;align-items:center;gap:10px;color:var(--text-muted);font-size:.85rem;margin:10px 0}
.spinner{width:18px;height:18px;border-radius:50%;border:2px solid var(--border);border-top-color:var(--accent);animation:spin .8s linear infinite}
@keyframes spin{to{transform:rotate(360deg)}}

/* Confirmar */
.confirm-grid{display:grid;grid-template-columns:1fr;gap:12px;margin:12px 0}
@media(min-width:720px){.confirm-grid{grid-template-columns:220px 1fr}}
.confirm-photo{display:flex;flex-direction:column;align-items:center;gap:8px}
.confirm-photo img{max-width:100%;max-height:230px;border-radius:12px;border:1px solid var(--border);object-fit:cover}
.confirm-fields{display:flex;flex-direction:column;gap:8px}
.confirm-field{display:flex;flex-direction:column;gap:3px;padding:9px 11px;border:1px solid var(--border);border-radius:10px;background:var(--surface)}
.confirm-field label{font-size:.72rem;color:var(--text-muted);text-transform:uppercase;letter-spacing:.05em}
.confirm-field input,.confirm-field select{border:0;padding:0;background:transparent;font-weight:650;font-size:.92rem;outline:none;width:100%;color:var(--text)}
.confirm-field.dudoso{border-color:var(--danger)}
.warn{display:flex;align-items:flex-start;gap:8px;padding:10px 12px;border-radius:12px;background:var(--warning-soft);color:var(--warning);font-size:.82rem;margin:10px 0}
.warn .icon{margin-top:1px}

/* Listados */
.section-head{display:flex;align-items:center;justify-content:space-between;gap:10px;margin-bottom:10px}
.section-head h2,.section-head h3{font-size:1.05rem;font-weight:750}
.list{display:flex;flex-direction:column;gap:8px}
.list-item{
  display:flex;align-items:center;justify-content:space-between;gap:12px;
  padding:12px;border:1px solid var(--border);border-radius:12px;
  background:var(--surface);cursor:pointer;transition:border-color .15s ease;
}
.list-item:hover{border-color:var(--accent)}
.list-item .info{min-width:0;display:flex;flex-direction:column;gap:2px}
.list-item .title{font-weight:650;font-size:.9rem;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.list-item .sub{font-size:.76rem;color:var(--text-muted);margin-top:0}
.list-item .amount{font-weight:750;font-variant-numeric:tabular-nums;white-space:nowrap;font-size:.9rem}
.list-item .amount.gasto{color:var(--danger)}

/* Segmentado */
.segmented{display:inline-flex;gap:3px;padding:3px;border-radius:12px;background:var(--surface-2);flex-wrap:wrap;margin-bottom:12px}
.seg{display:inline-flex;align-items:center;gap:6px;padding:8px 12px;min-height:44px;border-radius:9px;font-size:.83rem;color:var(--text-muted);font-weight:600}
.seg.active{background:var(--surface);color:var(--text);box-shadow:0 1px 3px rgba(0,0,0,.12)}
.seg .icon{width:1.05em;height:1.05em}

/* Ajustes */
.settings-block{margin-bottom:12px;display:flex;flex-direction:column;gap:8px}
.settings-block h3{display:flex;align-items:center;gap:8px;font-size:.95rem;font-weight:750}
.settings-block h3 .icon{color:var(--accent);width:1.15em;height:1.15em}
.settings-block .segmented{margin-bottom:2px}
.theme-grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(92px,1fr));gap:8px}
.theme-card{
  display:flex;flex-direction:column;gap:6px;padding:9px;border:1px solid var(--border);
  border-radius:12px;background:var(--surface);text-align:left;font-size:.78rem;font-weight:600;
}
.theme-card.active{border-color:var(--accent);box-shadow:0 0 0 2px var(--accent-soft)}
.theme-dots{display:flex;gap:4px}
.theme-dot{width:17px;height:17px;border-radius:50%;border:1px solid rgba(0,0,0,.08)}

/* Modales */
dialog.modal{border:0;padding:0;background:transparent;max-width:560px;width:calc(100% - 24px);margin:auto}
dialog.modal::backdrop{background:rgba(8,14,20,.58);backdrop-filter:blur(3px)}
.modal-card{background:var(--surface);border:1px solid var(--border);border-radius:18px;padding:16px;max-height:82vh;overflow:auto;box-shadow:var(--shadow)}
.modal-card .section-head{margin-bottom:8px}
.detalle-fila{display:flex;justify-content:space-between;gap:12px;padding:7px 0;border-bottom:1px solid var(--border);font-size:.84rem}
.detalle-fila:last-child{border-bottom:0}
.detalle-fila span:first-child{color:var(--text-muted)}
.detalle-fila span:last-child{font-weight:600;text-align:right;word-break:break-word}

/* Toast */
.toast{
  position:fixed;left:50%;bottom:calc(86px + env(safe-area-inset-bottom));
  transform:translateX(-50%) translateY(8px);
  background:var(--text);color:var(--bg);
  padding:10px 15px;border-radius:11px;font-size:.84rem;font-weight:600;
  opacity:0;pointer-events:none;transition:opacity .2s ease,transform .2s ease;z-index:70;
  max-width:min(92vw,420px);text-align:center;
}
.toast.show{opacity:1;transform:translateX(-50%)}

/* Navegación inferior */
.bottom-nav{
  position:fixed;left:0;right:0;bottom:0;z-index:30;
  display:flex;justify-content:space-around;
  background:var(--surface);border-top:1px solid var(--border);
  padding:6px 4px calc(6px + env(safe-area-inset-bottom));
}
/* En Netlify la etiqueta "Powered by Netlify" ocupa la esquina inferior derecha.
   Reservamos una franja para que no tape los textos del menú. */
html.host-netlify .bottom-nav{padding-bottom:calc(46px + env(safe-area-inset-bottom))}
html.host-netlify .app-main{padding-bottom:150px}
.nav-item{
  display:flex;flex-direction:column;align-items:center;gap:3px;
  padding:4px 8px;border-radius:10px;font-size:.68rem;font-weight:600;color:var(--text-muted);
  min-width:56px;min-height:48px;
}
.nav-item .icon{width:1.45em;height:1.45em}
.nav-item.active{color:var(--accent)}

/* Responsive */
@media(max-width:520px){
  .header-sub{display:none}
  .kpi-value{font-size:1.2rem}
  .two-cols{grid-template-columns:1fr}
}
@media(min-width:760px){
  .app-main{padding:20px 22px 100px}
  .kpi-grid{gap:12px}
}

/* Accesibilidad */
:focus-visible{outline:2px solid var(--accent);outline-offset:2px}
@media(prefers-reduced-motion:reduce){
  *{animation-duration:.001ms!important;transition-duration:.001ms!important}
}
