:root {
  --bg: #F2F2F7;
  --card: #FFFFFF;
  --text: #1D1D1F;
  --muted: #8A8A8E;
  --muted2: #6E6E73;
  --hairline: rgba(60, 60, 67, 0.12);
  --blue: #007AFF;
  --green: #34C759;
  --red: #FF3B30;
  --orange: #FF9500;
  --purple: #AF52DE;
  --radius: 14px;
  --radius-sm: 10px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --tabbar-h: 52px;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, system-ui, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
/* El atributo hidden DEBE ganar a cualquier display de clase (.login usa
   display:flex y, a igual especificidad, anulaba [hidden]→display:none del
   navegador: la pantalla de login no se ocultaba nunca y tapaba el dashboard). */
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.4;
  overscroll-behavior-y: none;
  -webkit-font-smoothing: antialiased;
}
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: 16px; }

/* ── Login ─────────────────────────────────────────── */
.login {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg);
  padding: 24px;
  z-index: 50;
}
.login-box { width: 100%; max-width: 340px; text-align: center; }
.login-logo {
  width: 72px; height: 72px; margin: 0 auto 18px;
  border-radius: 18px;
  background: linear-gradient(160deg, #0A84FF, #0060DF);
  color: #fff; font-weight: 700; font-size: 30px; letter-spacing: -1px;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 8px 24px rgba(0, 122, 255, 0.3);
}
.login h1 { font-size: 24px; font-weight: 700; letter-spacing: -0.5px; margin: 0 0 4px; }
.login-sub { color: var(--muted2); font-size: 14px; margin: 0 0 28px; }
.login-box input {
  width: 100%; padding: 15px 16px; margin-bottom: 12px;
  border: 1px solid var(--hairline); border-radius: var(--radius-sm);
  background: var(--card); color: var(--text);
  outline: none; transition: border-color .15s;
}
.login-box input:focus { border-color: var(--blue); }
.login-box button {
  width: 100%; padding: 15px; border: none; border-radius: var(--radius-sm);
  background: var(--blue); color: #fff; font-size: 17px; font-weight: 600;
  transition: opacity .15s;
}
.login-box button:active { opacity: .7; }
.login-box button:disabled { opacity: .5; }
.login-err { color: var(--red); font-size: 14px; margin-top: 14px; }

/* ── Topbar ────────────────────────────────────────── */
.topbar {
  position: sticky; top: 0; z-index: 20;
  padding: calc(var(--safe-top) + 8px) 16px 8px;
  background: rgba(255,255,255,0.82);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 0.5px solid var(--hairline);
  display: flex; align-items: center; justify-content: space-between;
  min-height: 44px;
}
.topbar h2 { font-size: 22px; font-weight: 700; letter-spacing: -0.5px; margin: 0; }
.topbar-actions { display: flex; gap: 4px; }
.icon-btn {
  border: none; background: transparent; color: var(--blue);
  width: 38px; height: 38px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
}
.icon-btn:active { background: rgba(0,0,0,0.05); }
.icon-btn.spin svg { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── View / scroll area ────────────────────────────── */
.view {
  padding: 12px 16px calc(var(--tabbar-h) + var(--safe-bottom) + 24px);
  -webkit-overflow-scrolling: touch;
  min-height: 60vh;
}

/* ── Tabbar ────────────────────────────────────────── */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  height: calc(var(--tabbar-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  display: flex;
  background: rgba(255,255,255,0.9);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-top: 0.5px solid var(--hairline);
}
.tab {
  flex: 1; border: none; background: transparent;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; color: var(--muted); font-size: 10px; font-weight: 500;
  padding-top: 6px;
}
.tab svg { width: 25px; height: 25px; }
.tab.active { color: var(--blue); }

/* ── Cards / lists ─────────────────────────────────── */
.group-title {
  font-size: 13px; font-weight: 600; color: var(--muted2);
  text-transform: uppercase; letter-spacing: 0.4px;
  margin: 22px 4px 8px;
}
.group-title:first-child { margin-top: 6px; }
.card {
  background: var(--card); border-radius: var(--radius);
  padding: 14px 16px; margin-bottom: 10px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.04);
}
.list { background: var(--card); border-radius: var(--radius); overflow: hidden; }
.list-row {
  padding: 13px 16px; border-bottom: 0.5px solid var(--hairline);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.list-row:last-child { border-bottom: none; }
.list-row:active { background: rgba(0,0,0,0.03); }
.row-main { min-width: 0; flex: 1; }
.row-title { font-size: 16px; font-weight: 600; letter-spacing: -0.2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-sub { font-size: 13px; color: var(--muted2); margin-top: 2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-right { text-align: right; flex-shrink: 0; }
.row-amount { font-size: 16px; font-weight: 600; font-variant-numeric: tabular-nums; }
.chevron { color: var(--muted); flex-shrink: 0; }

/* KPI grid */
.kpi-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.kpi {
  background: var(--card); border-radius: var(--radius); padding: 14px 16px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.04);
}
.kpi-label { font-size: 12px; color: var(--muted2); font-weight: 500; margin-bottom: 6px;
  text-transform: uppercase; letter-spacing: 0.3px; }
.kpi-value { font-size: 22px; font-weight: 700; letter-spacing: -0.6px; font-variant-numeric: tabular-nums; }
.kpi-value.pos { color: var(--green); }
.kpi-value.neg { color: var(--red); }
.kpi.wide { grid-column: 1 / -1; }

/* Badges */
.badge {
  display: inline-block; font-size: 12px; font-weight: 600;
  padding: 3px 9px; border-radius: 100px; white-space: nowrap;
}
.badge.green  { background: rgba(52,199,89,0.15);  color: #1F8A3B; }
.badge.orange { background: rgba(255,149,0,0.16);  color: #C26A00; }
.badge.red    { background: rgba(255,59,48,0.14);  color: #C7261D; }
.badge.blue   { background: rgba(0,122,255,0.13);  color: #0062CC; }
.badge.gray   { background: rgba(120,120,128,0.14);color: #5A5A60; }
.badge.purple { background: rgba(175,82,222,0.14); color: #8731B5; }

/* Progress bar */
.progress { height: 6px; border-radius: 100px; background: rgba(120,120,128,0.16); overflow: hidden; margin-top: 8px; }
.progress > div { height: 100%; background: var(--blue); border-radius: 100px; }

/* FAB */
.fab {
  position: fixed; right: 18px;
  bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 16px);
  width: 56px; height: 56px; border-radius: 50%;
  background: var(--blue); color: #fff; border: none; z-index: 25;
  box-shadow: 0 6px 18px rgba(0,122,255,0.4);
  display: flex; align-items: center; justify-content: center;
}
.fab:active { opacity: .85; }
.fab svg { width: 28px; height: 28px; }

/* Segmented control */
.segmented {
  display: flex; background: rgba(120,120,128,0.12); border-radius: 9px;
  padding: 2px; margin-bottom: 14px;
}
.segmented button {
  flex: 1; border: none; background: transparent; padding: 7px;
  font-size: 14px; font-weight: 600; color: var(--text); border-radius: 7px;
}
.segmented button.active { background: var(--card); box-shadow: 0 1px 3px rgba(0,0,0,0.12); }

/* Empty / loading */
.empty { text-align: center; color: var(--muted2); padding: 48px 24px; font-size: 15px; }
.skeleton { background: linear-gradient(90deg,#ececec 25%,#f5f5f5 50%,#ececec 75%);
  background-size: 200% 100%; animation: sk 1.2s infinite; border-radius: var(--radius); }
@keyframes sk { to { background-position: -200% 0; } }
.sk-card { height: 64px; margin-bottom: 10px; }

/* ── Modal (integrado, no nativo) ──────────────────── */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(0,0,0,0.4);
  display: flex; align-items: flex-end; justify-content: center;
  opacity: 0; transition: opacity .2s; padding: 0;
}
.modal-backdrop.show { opacity: 1; }
.modal {
  background: var(--card); width: 100%; max-width: 520px;
  border-radius: 20px 20px 0 0;
  padding: 8px 20px calc(20px + var(--safe-bottom));
  transform: translateY(100%); transition: transform .26s cubic-bezier(.2,.8,.2,1);
  max-height: 92vh; overflow-y: auto;
}
.modal-backdrop.show .modal { transform: translateY(0); }
.modal-grabber { width: 38px; height: 5px; border-radius: 3px; background: var(--hairline);
  margin: 6px auto 14px; }
.modal h3 { font-size: 20px; font-weight: 700; letter-spacing: -0.4px; margin: 0 0 16px; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; font-weight: 600; color: var(--muted2); margin-bottom: 6px; }
.field input, .field select, .field textarea {
  width: 100%; padding: 13px 14px; border: 1px solid var(--hairline);
  border-radius: var(--radius-sm); background: var(--card); color: var(--text); outline: none;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--blue); }
.field-row { display: flex; gap: 10px; }
.field-row .field { flex: 1; }
.field .hint { font-size: 12px; color: var(--muted); margin-top: 5px; }
.toggle-row { display: flex; align-items: center; justify-content: space-between; padding: 4px 0 14px; }
.toggle-row label { font-size: 15px; font-weight: 500; color: var(--text); }
.modal-actions { display: flex; gap: 10px; margin-top: 8px; }
.btn {
  flex: 1; padding: 14px; border: none; border-radius: var(--radius-sm);
  font-size: 17px; font-weight: 600; transition: opacity .15s;
}
.btn:active { opacity: .7; }
.btn-primary { background: var(--blue); color: #fff; }
.btn-secondary { background: rgba(120,120,128,0.14); color: var(--text); }
.btn-danger { background: var(--red); color: #fff; }
.btn:disabled { opacity: .5; }
.modal p.modal-body { font-size: 15px; color: var(--muted2); margin: -6px 0 18px; line-height: 1.45; }

/* Detail rows inside modal */
.detail-row { display: flex; justify-content: space-between; gap: 12px;
  padding: 11px 0; border-bottom: 0.5px solid var(--hairline); font-size: 15px; }
.detail-row:last-of-type { border-bottom: none; }
.detail-row .k { color: var(--muted2); }
.detail-row .v { font-weight: 600; text-align: right; }
.link-pdf { color: var(--blue); text-decoration: none; font-weight: 600; }

/* Toast */
#toast-root { position: fixed; left: 0; right: 0; bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 20px);
  z-index: 80; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; }
.toast {
  background: rgba(40,40,42,0.96); color: #fff; padding: 12px 18px; border-radius: 100px;
  font-size: 14px; font-weight: 500; max-width: 90%;
  box-shadow: 0 6px 20px rgba(0,0,0,0.25);
  opacity: 0; transform: translateY(10px); transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.ok { background: rgba(34,140,60,0.97); }
.toast.err { background: rgba(199,38,29,0.97); }

/* Más menu */
.mas-item svg { width: 24px; height: 24px; color: var(--blue); flex-shrink: 0; }
.mas-row { display: flex; align-items: center; gap: 14px; }
.logout-btn { width: 100%; margin-top: 24px; padding: 15px; border: none; border-radius: var(--radius);
  background: var(--card); color: var(--red); font-size: 16px; font-weight: 600;
  box-shadow: 0 1px 2px rgba(0,0,0,0.04); }
