/* ============================================
   FLUJO — Safari iOS compatible
   Tested: iOS 13+ / Chrome / Firefox
   ============================================ */

/* DARK default on :root — Safari reads this before JS runs */
:root {
  --bg:     #0a0a0a;
  --bg1:    #111111;
  --bg2:    #1a1a1a;
  --bg3:    #242424;
  --brd:    rgba(255,255,255,0.09);
  --brd2:   rgba(255,255,255,0.15);
  --txt:    #f0f0f0;
  --txt2:   #888888;
  --txt3:   #444444;
  --acc:    #a3e635;
  --grn:    #4ade80;
  --red:    #f87171;
  --org:    #fb923c;
  --blu:    #60a5fa;
  --pur:    #c084fc;
}
/* Light override */
[data-theme="light"] {
  --bg:     #f4f4f4;
  --bg1:    #ffffff;
  --bg2:    #f9f9f9;
  --bg3:    #ebebeb;
  --brd:    rgba(0,0,0,0.09);
  --brd2:   rgba(0,0,0,0.15);
  --txt:    #111111;
  --txt2:   #666666;
  --txt3:   #aaaaaa;
  --acc:    #65a30d;
  --grn:    #16a34a;
  --red:    #dc2626;
  --org:    #ea580c;
  --blu:    #2563eb;
  --pur:    #9333ea;
}

/* ── RESET ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html {
  font-size: 15px;
  -webkit-text-size-adjust: 100%;
  -ms-text-size-adjust: 100%;
}
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--txt);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
}
a { text-decoration: none; color: inherit; }
button, input, select, textarea {
  font-family: inherit;
  color: inherit;
  /* Safari iOS: kill native styling */
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  border-radius: 0;
}
svg { display: block; fill: currentColor; }

/* ── SPLASH ── */
.splash {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  z-index: 999;
  background: var(--bg);
  display: -webkit-flex;
  display: flex;
  -webkit-align-items: center;
  align-items: center;
  -webkit-justify-content: center;
  justify-content: center;
  overflow: hidden;
}
.splash-glow {
  position: absolute;
  border-radius: 50%;
  filter: blur(80px);
  pointer-events: none;
}
.g1 { width: 400px; height: 400px; background: rgba(163,230,53,0.12); top: -150px; left: -150px; }
.g2 { width: 350px; height: 350px; background: rgba(251,146,60,0.1); bottom: -100px; right: -80px; }
.splash-inner {
  position: relative;
  z-index: 1;
  text-align: center;
  padding: 2rem 1.5rem;
  max-width: 340px;
  width: 100%;
}
.splash-brand {
  display: -webkit-inline-flex;
  display: inline-flex;
  -webkit-align-items: center;
  align-items: center;
  gap: 8px;
  margin-bottom: 2rem;
  background: var(--bg2);
  border: 1px solid var(--brd2);
  padding: 8px 14px;
  border-radius: 100px;
}
.s-logo {
  width: 26px; height: 26px;
  background: var(--acc);
  border-radius: 8px;
  display: -webkit-flex; display: flex;
  -webkit-align-items: center; align-items: center;
  -webkit-justify-content: center; justify-content: center;
  color: #000;
  flex-shrink: 0;
}
.splash-brand span { font-size: 0.95rem; font-weight: 800; letter-spacing: -0.5px; }
.splash-title {
  font-size: 2.8rem;
  font-weight: 900;
  letter-spacing: -2px;
  line-height: 1.05;
  margin-bottom: 0.75rem;
}
.splash-accent { color: var(--acc); }
.splash-desc { font-size: 0.82rem; color: var(--txt2); margin-bottom: 2rem; }
.splash-btn {
  display: -webkit-inline-flex;
  display: inline-flex;
  -webkit-align-items: center;
  align-items: center;
  gap: 8px;
  background: var(--acc);
  color: #000;
  border: none;
  border-radius: 100px;
  padding: 0.75rem 1.75rem;
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
}
.splash-btn svg { width: 16px; height: 16px; fill: none; stroke: #000; stroke-width: 2.5; stroke-linecap: round; }

/* ── APP ── */
.app {
  display: -webkit-flex;
  display: flex;
  min-height: 100vh;
}

/* ── SIDEBAR (desktop) ── */
.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--bg1);
  border-right: 1px solid var(--brd);
  display: -webkit-flex;
  display: flex;
  -webkit-flex-direction: column;
  flex-direction: column;
  position: -webkit-sticky;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.sb-brand {
  display: -webkit-flex; display: flex;
  -webkit-align-items: center; align-items: center;
  gap: 8px;
  padding: 1.25rem 1rem 0.75rem;
}
.sb-logo {
  width: 28px; height: 28px;
  background: var(--acc);
  border-radius: 8px;
  display: -webkit-flex; display: flex;
  -webkit-align-items: center; align-items: center;
  -webkit-justify-content: center; justify-content: center;
  color: #000; flex-shrink: 0;
}
.sb-name { font-size: 1.05rem; font-weight: 900; letter-spacing: -0.5px; }
.sb-mes-wrap { padding: 0.25rem 1rem 0.5rem; }
.sb-mes-label { font-size: 0.65rem; color: var(--txt3); text-transform: uppercase; letter-spacing: 1px; display: block; margin-bottom: 4px; }
.mes-sel {
  width: 100%;
  background: var(--bg3);
  border: 1px solid var(--brd);
  border-radius: 8px;
  color: var(--txt);
  padding: 0.45rem 1.8rem 0.45rem 0.75rem;
  font-size: 0.82rem; font-weight: 600;
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%23888'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
}
.sb-nav { padding: 0.25rem 0.75rem; -webkit-flex: 1; flex: 1; }
.sb-link {
  display: -webkit-flex; display: flex;
  -webkit-align-items: center; align-items: center;
  gap: 9px;
  padding: 0.55rem 0.75rem;
  border-radius: 10px;
  color: var(--txt2);
  font-size: 0.84rem; font-weight: 500;
  margin-bottom: 2px;
}
.sb-link svg { width: 16px; height: 16px; flex-shrink: 0; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.sb-link:hover { background: var(--bg3); color: var(--txt); }
.sb-link.active { background: var(--bg3); color: var(--acc); font-weight: 600; }
.sb-link.active svg { stroke: var(--acc); }
.sb-footer {
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--brd);
  margin-top: auto;
  display: -webkit-flex; display: flex;
  -webkit-flex-direction: column; flex-direction: column;
  gap: 0.75rem;
}
.theme-btn {
  background: var(--bg3);
  border: 1px solid var(--brd);
  border-radius: 8px;
  padding: 0.4rem 0.6rem;
  display: -webkit-flex; display: flex;
  -webkit-align-items: center; align-items: center;
  gap: 6px;
  font-size: 0.75rem; font-weight: 600;
  color: var(--txt2);
  cursor: pointer;
  width: -webkit-fit-content; width: fit-content;
}
.theme-btn svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
[data-theme="dark"]  .icon-moon { display: none; }
[data-theme="light"] .icon-sun  { display: none; }
.sb-user { display: -webkit-flex; display: flex; -webkit-align-items: center; align-items: center; gap: 8px; }
.sb-avatar {
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--acc); color: #000;
  font-size: 0.8rem; font-weight: 800;
  display: -webkit-flex; display: flex;
  -webkit-align-items: center; align-items: center;
  -webkit-justify-content: center; justify-content: center;
  flex-shrink: 0;
}
.sb-uname { font-size: 0.8rem; font-weight: 600; display: block; }
.sb-urole { font-size: 0.68rem; color: var(--txt3); display: block; }

/* ── TOPBAR (mobile) ── */
.topbar {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 200;
  background: var(--bg1);
  border-bottom: 1px solid var(--brd);
  -webkit-align-items: flex-end; align-items: flex-end;
  padding: 0 0.75rem 10px;
  gap: 0.5rem;
  /* Height = base + notch. Three lines for max Safari compat */
  height: 54px;
  height: calc(54px + constant(safe-area-inset-top));
  height: calc(54px + env(safe-area-inset-top));
  padding-top: constant(safe-area-inset-top);
  padding-top: env(safe-area-inset-top);
}
.ham-btn {
  background: none; border: none;
  width: 36px; height: 36px;
  display: -webkit-flex; display: flex;
  -webkit-flex-direction: column; flex-direction: column;
  -webkit-align-items: center; align-items: center;
  -webkit-justify-content: center; justify-content: center;
  gap: 5px; flex-shrink: 0; cursor: pointer;
}
.ham-btn span { display: block; width: 18px; height: 2px; background: var(--txt2); border-radius: 2px; }
.tb-center { -webkit-flex: 1; flex: 1; font-size: 0.88rem; font-weight: 700; text-align: center; }
.tb-right { display: -webkit-flex; display: flex; -webkit-align-items: center; align-items: center; gap: 6px; }
.mes-mob-sel {
  background: var(--bg3);
  border: 1px solid var(--brd);
  border-radius: 8px;
  color: var(--txt);
  padding: 0.35rem 0.5rem;
  font-size: 0.72rem; font-weight: 600;
  cursor: pointer;
  max-width: 82px;
}
.theme-btn-sm {
  background: none;
  border: 1px solid var(--brd);
  border-radius: 8px;
  padding: 0.35rem 0.45rem;
  display: -webkit-flex; display: flex;
  -webkit-align-items: center; align-items: center;
  cursor: pointer; color: var(--txt2); flex-shrink: 0;
}
.theme-btn-sm svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }

/* Backdrop */
.sb-backdrop {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.6);
  z-index: 249;
}
.sb-backdrop.show { display: block; }

/* ── MAIN ── */
.main { -webkit-flex: 1; flex: 1; min-width: 0; padding: 1.75rem 2rem; }

/* ── PAGES ── */
.page { display: none; }
.page.active { display: block; }

/* ── PAGE HEADER ── */
.page-head {
  display: -webkit-flex; display: flex;
  -webkit-align-items: flex-start; align-items: flex-start;
  -webkit-justify-content: space-between; justify-content: space-between;
  gap: 1rem; margin-bottom: 1.25rem; flex-wrap: wrap;
}
.ph-title { font-size: 1.65rem; font-weight: 900; letter-spacing: -1.5px; line-height: 1; }
.ph-sub { font-size: 0.78rem; color: var(--txt2); margin-top: 3px; }

/* ── DASHBOARD ── */
.dash-layout { display: -webkit-flex; display: flex; -webkit-flex-direction: column; flex-direction: column; gap: 1rem; }
.hero-card {
  background: var(--bg2);
  border: 1px solid var(--brd);
  border-radius: 16px;
  padding: 1.25rem 1.35rem;
}
.hero-top {
  display: -webkit-flex; display: flex;
  -webkit-align-items: center; align-items: center;
  -webkit-justify-content: space-between; justify-content: space-between;
  gap: 1rem; margin-bottom: 0.75rem;
}
.hero-greeting { font-size: 0.72rem; color: var(--txt2); margin-bottom: 4px; font-weight: 500; }
.hero-label { font-size: 0.68rem; text-transform: uppercase; letter-spacing: 1px; color: var(--txt3); margin-bottom: 3px; }
.hero-amount { font-size: 2.6rem; font-weight: 900; letter-spacing: -2px; line-height: 1; color: var(--acc); }
.hero-chips { display: -webkit-flex; display: flex; -webkit-align-items: center; align-items: center; gap: 0.6rem; flex-wrap: wrap; }
.hero-badge { font-size: 0.72rem; font-weight: 700; padding: 3px 10px; border-radius: 100px; border: 1px solid; }
.b-green { background: rgba(74,222,128,0.12); color: var(--grn); border-color: rgba(74,222,128,0.25); }
.b-yellow { background: rgba(234,179,8,0.12); color: #eab308; border-color: rgba(234,179,8,0.25); }
.b-red { background: rgba(248,113,113,0.12); color: var(--red); border-color: rgba(248,113,113,0.25); }
.hero-mes { font-size: 0.72rem; color: var(--txt3); }
.hero-ring-wrap { flex-shrink: 0; }
.ring { width: 90px; height: 90px; }
.ring-bg { stroke: var(--bg3); }
.ring-prog { stroke: var(--acc); stroke-linecap: round; -webkit-transition: stroke-dashoffset 0.7s; transition: stroke-dashoffset 0.7s; }
.ring-num { font-size: 14px; font-weight: 800; fill: var(--txt); font-family: 'Inter', sans-serif; }
.ring-sub { font-size: 7px; fill: var(--txt3); font-family: 'Inter', sans-serif; }

/* KPI */
.kpi-grid { display: -webkit-flex; display: flex; flex-wrap: wrap; gap: 0.6rem; }
.kpi {
  background: var(--bg2); border: 1px solid var(--brd);
  border-radius: 12px; padding: 0.85rem 1rem;
  -webkit-flex: 1; flex: 1; min-width: calc(50% - 0.3rem);
}
.kpi-top {
  display: -webkit-flex; display: flex;
  -webkit-align-items: center; align-items: center;
  -webkit-justify-content: space-between; justify-content: space-between;
  margin-bottom: 5px;
}
.kpi-lbl { font-size: 0.65rem; color: var(--txt2); text-transform: uppercase; letter-spacing: 0.5px; font-weight: 600; }
.kpi-dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }
.c-green { background: var(--grn); }
.c-red   { background: var(--red); }
.c-purple{ background: var(--pur); }
.c-blue  { background: var(--blu); }
.kpi-val { font-size: 1.05rem; font-weight: 800; letter-spacing: -0.5px; display: block; }

/* ANA QUICK */
.ana-quick {
  display: -webkit-flex; display: flex;
  -webkit-align-items: center; align-items: center;
  gap: 0.5rem; margin-bottom: 0.5rem;
}
.ana-q-card {
  -webkit-flex: 1; flex: 1;
  border-radius: 12px; padding: 0.85rem 1rem; border: 1px solid;
}
.ana-q-card.blue  { background: rgba(96,165,250,0.08); border-color: rgba(96,165,250,0.2); }
.ana-q-card.orange{ background: rgba(251,146,60,0.08); border-color: rgba(251,146,60,0.2); }
.ana-q-label { font-size: 0.65rem; color: var(--txt2); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 3px; font-weight: 600; }
.ana-q-val { font-size: 1.1rem; font-weight: 800; letter-spacing: -0.5px; }
.ana-q-card.blue   .ana-q-val { color: var(--blu); }
.ana-q-card.orange .ana-q-val { color: var(--org); }
.ana-q-sep { font-size: 1.2rem; color: var(--txt3); flex-shrink: 0; }

/* SECTION HEAD */
.section-head {
  display: -webkit-flex; display: flex;
  -webkit-align-items: center; align-items: center;
  -webkit-justify-content: space-between; justify-content: space-between;
  font-size: 0.68rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: 1px; color: var(--txt2);
  padding: 0.25rem 0;
}
.link-more { background: none; border: none; color: var(--acc); font-size: 0.72rem; font-weight: 600; cursor: pointer; letter-spacing: 0; text-transform: none; }

/* CAT LIST */
.cat-list { display: -webkit-flex; display: flex; -webkit-flex-direction: column; flex-direction: column; gap: 6px; }
.cat-row {
  display: -webkit-flex; display: flex;
  -webkit-align-items: center; align-items: center;
  gap: 10px;
  background: var(--bg2); border: 1px solid var(--brd);
  border-radius: 10px; padding: 0.7rem 0.9rem;
}
.cat-emoji { width: 30px; height: 30px; border-radius: 8px; display: -webkit-flex; display: flex; -webkit-align-items: center; align-items: center; -webkit-justify-content: center; justify-content: center; font-size: 1.05rem; flex-shrink: 0; }
.cat-meta { -webkit-flex: 1; flex: 1; min-width: 0; }
.cat-name { font-size: 0.8rem; font-weight: 600; margin-bottom: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cat-track { height: 4px; background: var(--bg3); border-radius: 10px; overflow: hidden; }
.cat-fill { height: 100%; border-radius: 10px; }
.cat-amt { font-size: 0.82rem; font-weight: 800; white-space: nowrap; }

/* TX LIST */
.tx-list { display: -webkit-flex; display: flex; -webkit-flex-direction: column; flex-direction: column; gap: 5px; }
.tx-item {
  display: -webkit-flex; display: flex;
  -webkit-align-items: center; align-items: center;
  gap: 10px;
  background: var(--bg2); border: 1px solid var(--brd);
  border-radius: 10px; padding: 0.7rem 0.9rem;
}
.tx-ic {
  width: 34px; height: 34px; border-radius: 9px;
  background: var(--bg3);
  display: -webkit-flex; display: flex;
  -webkit-align-items: center; align-items: center;
  -webkit-justify-content: center; justify-content: center;
  font-size: 1rem; flex-shrink: 0; overflow: hidden;
}
.tx-ic img { width: 22px; height: 22px; object-fit: contain; border-radius: 4px; }
.tx-body { -webkit-flex: 1; flex: 1; min-width: 0; }
.tx-name { font-size: 0.82rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx-meta { font-size: 0.68rem; color: var(--txt2); margin-top: 1px; }
.tx-amt { font-size: 0.88rem; font-weight: 800; white-space: nowrap; color: var(--red); flex-shrink: 0; }
.tx-amt.pos { color: var(--grn); }
.tx-actions { display: -webkit-flex; display: flex; gap: 4px; flex-shrink: 0; }
.ic-btn { background: none; border: none; color: var(--txt3); padding: 4px; border-radius: 6px; cursor: pointer; font-size: 0.82rem; line-height: 1; }
.ic-btn:hover { color: var(--org); }
.ic-btn.del:hover { color: var(--red); }

/* FILTERS */
.filter-row { display: -webkit-flex; display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 1rem; }
.f-sel, .f-inp {
  background: var(--bg2);
  border: 1px solid var(--brd);
  border-radius: 8px;
  color: var(--txt);
  padding: 0.45rem 0.7rem;
  font-size: 0.78rem;
}
.f-sel {
  padding-right: 22px;
  background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%23888'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 7px center;
  cursor: pointer;
}
.f-inp { min-width: 140px; }

/* TABLE */
.tbl-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.dtbl { width: 100%; border-collapse: collapse; font-size: 0.78rem; min-width: 640px; }
.dtbl th { padding: 0.5rem 0.75rem; font-size: 0.63rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; color: var(--txt3); border-bottom: 1px solid var(--brd); text-align: left; white-space: nowrap; }
.dtbl td { padding: 0.55rem 0.75rem; border-bottom: 1px solid rgba(255,255,255,0.03); color: var(--txt2); vertical-align: middle; }
[data-theme="light"] .dtbl td { border-bottom-color: rgba(0,0,0,0.04); }
.dtbl tfoot td { border-top: 2px solid var(--brd); border-bottom: none; font-weight: 800; color: var(--txt); padding-top: 0.75rem; }
td.num { text-align: right; font-weight: 700; color: var(--txt); }
td.pos { color: var(--grn) !important; font-weight: 700; }
td.neg { color: var(--red) !important; font-weight: 700; }
.chip { display: inline-block; padding: 2px 8px; border-radius: 100px; font-size: 0.63rem; font-weight: 700; white-space: nowrap; }
.ch-personal   { background: rgba(96,165,250,0.12); color: var(--blu); }
.ch-compartido { background: rgba(192,132,252,0.12); color: var(--pur); }
.ch-extra      { background: rgba(251,146,60,0.12); color: var(--org); }
.ch-fijo       { background: rgba(74,222,128,0.12); color: var(--grn); }
.ch-variable   { background: rgba(234,179,8,0.12); color: #eab308; }
.icon-desc { display: -webkit-flex; display: flex; -webkit-align-items: center; align-items: center; gap: 7px; }
.icon-desc .ti { width: 20px; height: 20px; border-radius: 5px; overflow: hidden; display: -webkit-flex; display: flex; -webkit-align-items: center; align-items: center; -webkit-justify-content: center; justify-content: center; font-size: 0.9rem; flex-shrink: 0; background: var(--bg3); }
.icon-desc .ti img { width: 14px; height: 14px; object-fit: contain; }
.tbl-sum { display: -webkit-flex; display: flex; gap: 1.5rem; flex-wrap: wrap; padding: 0.75rem 0; font-size: 0.78rem; color: var(--txt2); }
.tbl-sum strong { color: var(--txt); }

/* BUTTONS */
.btn-add {
  background: var(--acc); color: #000;
  border: none; border-radius: 100px;
  padding: 0.5rem 1.1rem; font-size: 0.82rem; font-weight: 700;
  cursor: pointer; white-space: nowrap;
}
.btn-cancel {
  background: var(--bg3); border: 1px solid var(--brd);
  color: var(--txt2); border-radius: 8px;
  padding: 0.5rem 1rem; font-size: 0.82rem; font-weight: 500; cursor: pointer;
}
.btn-save {
  background: var(--acc); color: #000;
  border: none; border-radius: 8px;
  padding: 0.5rem 1.25rem; font-size: 0.82rem; font-weight: 700; cursor: pointer;
}

/* PROYECCIÓN */
.proy-hero {
  background: var(--bg2); border: 1px solid rgba(163,230,53,0.2);
  border-radius: 16px; padding: 1.5rem; text-align: center; margin-bottom: 1.25rem;
}
.proy-h-lbl { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 1px; color: var(--txt2); margin-bottom: 0.4rem; }
.proy-h-val { font-size: 3rem; font-weight: 900; letter-spacing: -2px; color: var(--acc); }
.proy-h-note { font-size: 0.68rem; color: var(--txt3); margin-top: 0.3rem; }
.stat-grid { display: -webkit-flex; display: flex; flex-wrap: wrap; gap: 0.65rem; }
.stat-card {
  background: var(--bg2); border: 1px solid var(--brd);
  border-radius: 12px; padding: 0.9rem 1rem;
  -webkit-flex: 1; flex: 1; min-width: calc(33% - 0.5rem);
}
.stat-card.warn { border-color: rgba(248,113,113,0.2); }
.stat-icon { font-size: 1.1rem; display: block; margin-bottom: 5px; }
.stat-lbl { font-size: 0.65rem; text-transform: uppercase; letter-spacing: 0.5px; color: var(--txt2); display: block; margin-bottom: 3px; }
.stat-val { font-size: 1rem; font-weight: 800; letter-spacing: -0.3px; display: block; }

/* CON ANA */
.ana-hero-row { display: -webkit-flex; display: flex; gap: 0.75rem; margin-bottom: 0.75rem; }
.ana-hero {
  -webkit-flex: 1; flex: 1;
  background: var(--bg2); border: 1px solid var(--brd);
  border-radius: 16px; padding: 1.25rem; text-align: center;
}
.ana-hero.blue   { border-color: rgba(96,165,250,0.25); }
.ana-hero.orange { border-color: rgba(251,146,60,0.25); }
.ah-icon { font-size: 1.4rem; margin-bottom: 4px; }
.ah-lbl { font-size: 0.65rem; text-transform: uppercase; letter-spacing: 0.5px; color: var(--txt2); margin-bottom: 4px; }
.ah-val { font-size: 1.7rem; font-weight: 900; letter-spacing: -1.5px; margin-bottom: 3px; }
.ana-hero.blue   .ah-val { color: var(--blu); }
.ana-hero.orange .ah-val { color: var(--org); }
.ah-sub { font-size: 0.65rem; color: var(--txt3); }
.neto-bar { background: var(--bg2); border: 1px solid var(--brd); border-radius: 10px; padding: 0.65rem 1rem; font-size: 0.78rem; color: var(--txt2); text-align: center; margin-bottom: 1rem; }
.ana-cols { display: -webkit-flex; display: flex; gap: 1rem; }
.ana-cols > div { -webkit-flex: 1; flex: 1; }

/* ANUAL */
.chart-card { background: var(--bg2); border: 1px solid var(--brd); border-radius: 16px; padding: 1.25rem; margin-bottom: 1rem; }
.chart-legend { display: -webkit-flex; display: flex; -webkit-align-items: center; align-items: center; gap: 6px; font-size: 0.72rem; color: var(--txt2); margin-bottom: 1rem; }
.leg-dot { width: 8px; height: 8px; border-radius: 50%; }
.leg-dot.green  { background: var(--grn); }
.leg-dot.orange { background: var(--org); }
.bar-chart { display: -webkit-flex; display: flex; -webkit-align-items: flex-end; align-items: flex-end; gap: 4px; height: 150px; }
.bg  { -webkit-flex: 1; flex: 1; display: -webkit-flex; display: flex; -webkit-flex-direction: column; flex-direction: column; -webkit-align-items: center; align-items: center; gap: 3px; height: 100%; }
.bp  { -webkit-flex: 1; flex: 1; width: 100%; display: -webkit-flex; display: flex; -webkit-align-items: flex-end; align-items: flex-end; gap: 2px; }
.bi  { -webkit-flex: 1; flex: 1; border-radius: 3px 3px 0 0; min-height: 2px; background: var(--grn); opacity: 0.75; }
.bj  { -webkit-flex: 1; flex: 1; border-radius: 3px 3px 0 0; min-height: 2px; background: var(--org); opacity: 0.7; }
.bm  { font-size: 0.55rem; color: var(--txt3); white-space: nowrap; }
.bg.act .bm { color: var(--acc); font-weight: 700; }

/* Anual mobile cards */
.anual-cards { display: none; -webkit-flex-direction: column; flex-direction: column; gap: 6px; margin-bottom: 0.5rem; }
.anual-row {
  display: -webkit-flex; display: flex;
  -webkit-align-items: center; align-items: center;
  -webkit-justify-content: space-between; justify-content: space-between;
  background: var(--bg2); border: 1px solid var(--brd);
  border-radius: 10px; padding: 0.7rem 1rem; gap: 0.5rem; flex-wrap: wrap;
}
.anr-mes { font-size: 0.82rem; font-weight: 700; min-width: 70px; }
.anr-stats { display: -webkit-flex; display: flex; gap: 1rem; -webkit-flex: 1; flex: 1; -webkit-justify-content: flex-end; justify-content: flex-end; flex-wrap: wrap; }
.anr-stat { text-align: right; }
.anr-slbl { font-size: 0.6rem; color: var(--txt3); text-transform: uppercase; letter-spacing: 0.5px; }
.anr-sval { font-size: 0.82rem; font-weight: 700; }

/* METAS */
.metas-grid { display: -webkit-flex; display: flex; flex-wrap: wrap; gap: 0.75rem; }
.meta-card { background: var(--bg2); border: 1px solid var(--brd); border-radius: 16px; padding: 1.1rem; min-width: 220px; -webkit-flex: 1; flex: 1; }
.meta-nm  { font-size: 0.9rem; font-weight: 700; margin-bottom: 3px; }
.meta-prc { font-size: 1.5rem; font-weight: 900; letter-spacing: -1px; color: var(--acc); }
.meta-sub { font-size: 0.68rem; color: var(--txt2); margin-bottom: 0.8rem; }
.meta-pb  { height: 5px; background: var(--bg3); border-radius: 10px; overflow: hidden; margin-bottom: 0.8rem; }
.meta-pf  { height: 100%; background: var(--acc); border-radius: 10px; }
.meta-row { display: -webkit-flex; display: flex; gap: 0.5rem; }

/* ── MODALS — Safari-safe: use display:none/block, not opacity/visibility ── */
.modal-wrap {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  z-index: 500;
  background: rgba(0,0,0,0.78);
  -webkit-align-items: center;
  align-items: center;
  -webkit-justify-content: center;
  justify-content: center;
  padding: 1rem;
  /* iOS scroll fix */
  -webkit-overflow-scrolling: touch;
}
.modal-wrap.open {
  display: -webkit-flex;
  display: flex;
}
.modal {
  background: var(--bg1);
  border: 1px solid var(--brd2);
  border-radius: 18px;
  width: 100%;
  max-width: 520px;
  max-height: 85vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.modal-top {
  display: -webkit-flex; display: flex;
  -webkit-align-items: center; align-items: center;
  -webkit-justify-content: space-between; justify-content: space-between;
  padding: 1.25rem 1.5rem 0.25rem;
}
.modal-top h2 { font-size: 0.95rem; font-weight: 800; letter-spacing: -0.3px; }
.modal-close {
  background: var(--bg3); border: none; color: var(--txt2);
  width: 26px; height: 26px; border-radius: 50%;
  display: -webkit-flex; display: flex;
  -webkit-align-items: center; align-items: center;
  -webkit-justify-content: center; justify-content: center;
  font-size: 0.82rem; cursor: pointer;
}
.modal-body {
  padding: 0.75rem 1.5rem;
  display: -webkit-flex;
  display: flex;
  -webkit-flex-direction: column;
  flex-direction: column;
  gap: 0.75rem;
}
/* Two column only on wide screens */
@media (min-width: 480px) {
  .modal-body {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }
  .fg.full { grid-column: 1 / -1; }
}
.fg { display: -webkit-flex; display: flex; -webkit-flex-direction: column; flex-direction: column; gap: 4px; }
.fg label { font-size: 0.65rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; color: var(--txt2); }

/* FORM INPUTS — explicit styles, no var() for background to avoid Safari bug */
.fi {
  display: block;
  width: 100%;
  background: #242424;
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 8px;
  color: #f0f0f0;
  padding: 0.6rem 0.75rem;
  font-size: 0.9rem;
  font-family: 'Inter', -apple-system, sans-serif;
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  outline: none;
  box-sizing: border-box;
}
[data-theme="light"] .fi {
  background: #ebebeb;
  border-color: rgba(0,0,0,0.12);
  color: #111111;
}
.fi:focus {
  border-color: #a3e635;
  outline: none;
}
[data-theme="light"] .fi:focus { border-color: #65a30d; }
select.fi {
  background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%23888'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 28px;
  cursor: pointer;
}
input[type="date"].fi::-webkit-calendar-picker-indicator { filter: invert(0.5); cursor: pointer; }
.highlight-fg .fi { color: #a3e635; font-weight: 700; }
[data-theme="light"] .highlight-fg .fi { color: #65a30d; }

.modal-foot {
  padding: 0.75rem 1.5rem 1.25rem;
  display: -webkit-flex; display: flex;
  -webkit-justify-content: flex-end; justify-content: flex-end;
  gap: 0.6rem;
  border-top: 1px solid var(--brd);
}

/* TOAST */
.toast {
  position: fixed;
  left: 50%;
  bottom: 80px;
  -webkit-transform: translateX(-50%) translateY(12px);
  transform: translateX(-50%) translateY(12px);
  background: var(--bg2);
  border: 1px solid #a3e635;
  color: #a3e635;
  border-radius: 100px;
  padding: 0.5rem 1.25rem;
  font-size: 0.78rem; font-weight: 700;
  z-index: 999;
  opacity: 0;
  pointer-events: none;
  white-space: nowrap;
  -webkit-transition: opacity 0.22s, -webkit-transform 0.22s;
  transition: opacity 0.22s, transform 0.22s;
}
.toast.show {
  opacity: 1;
  -webkit-transform: translateX(-50%) translateY(0);
  transform: translateX(-50%) translateY(0);
}
.toast.err { border-color: var(--red); color: var(--red); }

/* BOTTOM NAV */
.bnav {
  display: none;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 200;
  background: var(--bg1);
  border-top: 1px solid var(--brd);
  /* Height = base + home indicator */
  height: 58px;
  height: calc(58px + constant(safe-area-inset-bottom));
  height: calc(58px + env(safe-area-inset-bottom));
  padding-bottom: constant(safe-area-inset-bottom);
  padding-bottom: env(safe-area-inset-bottom);
  -webkit-justify-content: space-around; justify-content: space-around;
  -webkit-align-items: center; align-items: center;
}
.bn {
  display: -webkit-flex; display: flex;
  -webkit-flex-direction: column; flex-direction: column;
  -webkit-align-items: center; align-items: center;
  gap: 3px; -webkit-flex: 1; flex: 1;
  padding: 8px 4px;
  color: var(--txt3);
  font-size: 0.6rem; font-weight: 600; text-align: center;
}
.bn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.bn.active { color: var(--acc); }

/* SCROLLBAR */
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--bg3); border-radius: 10px; }

/* =============================================
   RESPONSIVE
   ============================================= */

/* Mobile */
@media (max-width: 900px) {
  .sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 250;
    -webkit-transform: translateX(-100%);
    transform: translateX(-100%);
    -webkit-transition: -webkit-transform 0.25s;
    transition: transform 0.25s;
    -webkit-box-shadow: 4px 0 30px rgba(0,0,0,0.5);
    box-shadow: 4px 0 30px rgba(0,0,0,0.5);
  }
  .sidebar.open {
    -webkit-transform: translateX(0);
    transform: translateX(0);
  }
  .topbar { display: -webkit-flex; display: flex; }
  .main {
    padding: 0.85rem;
    /* Top: topbar height (already includes safe area) + spacing */
    padding-top: calc(54px + 0.85rem);
    padding-top: calc(54px + constant(safe-area-inset-top) + 0.85rem);
    padding-top: calc(54px + env(safe-area-inset-top) + 0.85rem);
    /* Bottom: bnav height (already includes safe area) + spacing */
    padding-bottom: calc(58px + 0.5rem);
    padding-bottom: calc(58px + constant(safe-area-inset-bottom) + 0.5rem);
    padding-bottom: calc(58px + env(safe-area-inset-bottom) + 0.5rem);
  }
  .bnav { display: -webkit-flex; display: flex; }

  /* Hide tables, show cards */
  .tbl-wrap { display: none; }
  .anual-cards { display: -webkit-flex; display: flex; }

  /* Filters stack */
  .filter-row { -webkit-flex-direction: column; flex-direction: column; }
  .f-sel, .f-inp { width: 100%; }

  /* Compact */
  .ph-title { font-size: 1.4rem; letter-spacing: -1px; }
  .hero-amount { font-size: 2.1rem; }

  /* Ana cols stack */
  .ana-cols { -webkit-flex-direction: column; flex-direction: column; }

  /* Stat grid 2 col */
  .stat-card { min-width: calc(50% - 0.35rem); }

  /* Metas single col */
  .meta-card { min-width: 100%; }
}

@media (max-width: 480px) {
  .hero-ring-wrap .ring { width: 78px; height: 78px; }
  .ring-num { font-size: 12px; }
  .proy-h-val { font-size: 2.2rem; }
  .ana-hero-row { -webkit-flex-direction: column; flex-direction: column; }
  .bn span { font-size: 0.55rem; }
}

/* Desktop: hide mobile elements */
@media (min-width: 901px) {
  .topbar, .bnav, .sb-backdrop { display: none !important; }
  #gastos-cards, #ingresos-cards { display: none; }
  .anual-cards { display: none; }
  .tbl-wrap { display: block; }
}

/* ── TARJETAS ── */
.tarj-card {
  background: var(--bg2);
  border: 1px solid var(--brd);
  border-radius: 16px;
  padding: 1.25rem;
  overflow: hidden;
}
.tarj-card.bcp { border-color: rgba(0,120,200,0.3); }
.tarj-card.bbva { border-color: rgba(0,70,180,0.3); }
.tarj-header {
  display: -webkit-flex; display: flex;
  -webkit-align-items: center; align-items: center;
  gap: 12px; margin-bottom: 1rem;
}
.tarj-logo {
  width: 44px; height: 28px;
  border-radius: 6px;
  background: rgba(0,120,200,0.15);
  color: #3b82f6;
  font-size: 0.65rem; font-weight: 900;
  display: -webkit-flex; display: flex;
  -webkit-align-items: center; align-items: center;
  -webkit-justify-content: center; justify-content: center;
  letter-spacing: 0.5px; flex-shrink: 0;
}
.tarj-logo.bbva-logo { background: rgba(0,70,180,0.15); color: #818cf8; }
.tarj-name { font-size: 0.9rem; font-weight: 700; }
.tarj-sub { font-size: 0.68rem; color: var(--txt2); margin-top: 2px; }
.tarj-total {
  margin-left: auto;
  font-size: 1.3rem; font-weight: 900;
  letter-spacing: -1px; color: var(--acc);
  white-space: nowrap;
}
.tarj-note {
  font-size: 0.72rem; color: var(--txt2);
  margin-bottom: 0.75rem;
  padding: 0.5rem 0.75rem;
  background: var(--bg3);
  border-radius: 8px;
}
.tarj-resumen {
  background: var(--bg2);
  border: 1px solid var(--brd2);
  border-radius: 12px;
  padding: 1rem 1.25rem;
  margin-top: 1.25rem;
}
.tarj-res-row {
  display: -webkit-flex; display: flex;
  -webkit-align-items: center; align-items: center;
  -webkit-justify-content: space-between; justify-content: space-between;
  font-size: 0.85rem; font-weight: 600;
  margin-bottom: 4px;
}
.tarj-res-val { font-size: 1.2rem; font-weight: 900; color: var(--acc); }
.tarj-res-note { font-size: 0.68rem; color: var(--txt3); }

/* ── TARJETAS FILTRO FECHAS ── */
.tarj-filtro-card {
  background: var(--bg2);
  border: 1px solid var(--brd2);
  border-radius: 14px;
  padding: 1rem 1.25rem;
  margin-bottom: 1rem;
}
.tarj-filtro-title {
  display: -webkit-flex; display: flex;
  -webkit-align-items: center; align-items: center;
  gap: 6px;
  font-size: 0.75rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.5px;
  color: var(--txt2); margin-bottom: 0.85rem;
}
.tarj-filtro-row {
  display: -webkit-flex; display: flex;
  -webkit-align-items: flex-end; align-items: flex-end;
  gap: 0.6rem; flex-wrap: wrap;
}
.tarj-filtro-group {
  display: -webkit-flex; display: flex;
  -webkit-flex-direction: column; flex-direction: column;
  gap: 4px;
}
.tarj-filtro-label {
  font-size: 0.65rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.5px;
  color: var(--txt3);
}
.tarj-date-inp {
  background: var(--bg3);
  border: 1px solid var(--brd);
  border-radius: 8px;
  color: var(--txt);
  padding: 0.5rem 0.7rem;
  font-size: 0.82rem;
  font-family: inherit;
  outline: none;
  -webkit-appearance: none;
  transition: border-color 0.15s;
  min-width: 130px;
}
.tarj-date-inp:focus { border-color: var(--acc); }
.tarj-date-inp::-webkit-calendar-picker-indicator { filter: invert(0.5); cursor: pointer; }
.tarj-filtro-sep {
  font-size: 1rem; color: var(--txt3);
  padding-bottom: 0.5rem; flex-shrink: 0;
}
.tarj-filtro-btn {
  background: var(--acc); color: #000;
  border: none; border-radius: 8px;
  padding: 0.5rem 1.1rem;
  font-size: 0.82rem; font-weight: 700;
  cursor: pointer; white-space: nowrap;
  font-family: inherit;
  transition: opacity 0.15s;
}
.tarj-filtro-btn:hover { opacity: 0.85; }
.tarj-filtro-clear {
  background: none;
  border: 1px solid var(--brd);
  color: var(--txt2);
  border-radius: 8px;
  padding: 0.5rem 0.9rem;
  font-size: 0.78rem; font-weight: 500;
  cursor: pointer; white-space: nowrap;
  font-family: inherit;
  transition: border-color 0.15s, color 0.15s;
}
.tarj-filtro-clear:hover { border-color: var(--txt2); color: var(--txt); }
.tarj-filtro-info {
  margin-top: 0.6rem;
  font-size: 0.72rem;
  color: var(--txt3);
}
.tarj-filtro-info.active {
  color: var(--acc);
  font-weight: 600;
}
/* stack on mobile */
@media (max-width: 600px) {
  .tarj-filtro-row { -webkit-flex-direction: column; flex-direction: column; }
  .tarj-date-inp { min-width: 100%; width: 100%; }
  .tarj-filtro-btn, .tarj-filtro-clear { width: 100%; text-align: center; }
  .tarj-filtro-sep { display: none; }
}
/* spacing between tarj cards */
.tarj-card { margin-bottom: 1rem; }
