/* ==========================================================================
   NEST — Family Finance OS
   styles.css — complete design system. No CSS framework dependency.
   Mobile-first: 320px (iPhone SE) → 1440px+ desktop.
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. TOKENS
   -------------------------------------------------------------------------- */
:root {
  /* Surfaces */
  --ink-950: #080B14;
  --ink-900: #0B0F1A;
  --ink-850: #0F1424;
  --ink-800: #131A2E;
  --ink-750: #1A2238;

  /* Text */
  --mist-100: #EAEFF7;
  --mist-300: #B4BFD1;
  --mist-400: #94A3B8;
  --mist-500: #64748B;

  /* Accents */
  --emerald: #10B981;
  --emerald-400: #34D399;
  --rose: #F43F5E;
  --rose-400: #FB7185;
  --amber: #F59E0B;
  --amber-400: #FBBF24;
  --violet: #8B5CF6;
  --violet-400: #A78BFA;
  --sky: #3B82F6;
  --sky-400: #60A5FA;
  --pink: #EC4899;
  --pink-400: #F472B6;
  --teal-400: #2DD4BF;

  /* Glass */
  --glass-bg: linear-gradient(160deg, rgba(255,255,255,0.055), rgba(255,255,255,0.02));
  --glass-border: rgba(255,255,255,0.08);
  --glass-border-hi: rgba(255,255,255,0.16);

  /* Radii */
  --r-sm: 10px;
  --r-md: 14px;
  --r-lg: 18px;
  --r-xl: 24px;
  --r-full: 999px;

  /* Spacing scale */
  --s1: 4px;  --s2: 8px;  --s3: 12px; --s4: 16px;
  --s5: 20px; --s6: 24px; --s8: 32px; --s10: 40px;

  /* Type */
  --font-display: 'Sora', system-ui, -apple-system, sans-serif;
  --font-body: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', 'SF Mono', Menlo, monospace;

  /* Layout */
  --sidebar-w: 260px;
  --header-h: 58px;
  --bottomnav-h: 62px;

  /* Safe areas (0 fallback on non-notched devices) */
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);

  --shadow-glow: 0 0 40px -8px rgba(16,185,129,0.35);
  --shadow-lift: 0 10px 30px -12px rgba(0,0,0,0.6);
}

/* --------------------------------------------------------------------------
   2. RESET
   -------------------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
* { -webkit-tap-highlight-color: transparent; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.5;
  color: var(--mist-100);
  background:
    radial-gradient(circle at 12% 6%, rgba(16,185,129,0.10), transparent 42%),
    radial-gradient(circle at 88% 14%, rgba(139,92,246,0.10), transparent 46%),
    radial-gradient(circle at 50% 96%, rgba(59,130,246,0.08), transparent 42%),
    var(--ink-900);
  background-attachment: fixed;
  overscroll-behavior-y: none;
}

h1, h2, h3, h4 { font-family: var(--font-display); font-weight: 600; margin: 0; line-height: 1.25; }
p { margin: 0; }
button { font-family: inherit; font-size: inherit; color: inherit; border: none; background: none; cursor: pointer; }
a { color: var(--sky-400); text-decoration: none; }
ul { margin: 0; padding: 0; list-style: none; }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.12); border-radius: 8px; }
::-webkit-scrollbar-track { background: transparent; }

::selection { background: rgba(16,185,129,0.35); }

/* --------------------------------------------------------------------------
   3. UTILITY PRIMITIVES
   -------------------------------------------------------------------------- */
.hidden { display: none !important; }
.flex { display: flex; }
.grid { display: grid; }
.items-center { align-items: center; }
.items-start { align-items: flex-start; }
.items-end { align-items: flex-end; }
.justify-between { justify-content: space-between; }
.justify-center { justify-content: center; }
.justify-end { justify-content: flex-end; }
.flex-col { flex-direction: column; }
.flex-wrap { flex-wrap: wrap; }
.flex-1 { flex: 1 1 0%; min-width: 0; }
.shrink-0 { flex-shrink: 0; }
.w-full { width: 100%; }
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-left { text-align: left; }
.relative { position: relative; }
.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cap { text-transform: capitalize; }

.gap-1 { gap: var(--s1); } .gap-2 { gap: var(--s2); } .gap-3 { gap: var(--s3); }
.gap-4 { gap: var(--s4); } .gap-5 { gap: var(--s5); } .gap-6 { gap: var(--s6); }
.mt-1 { margin-top: var(--s1); } .mt-2 { margin-top: var(--s2); } .mt-3 { margin-top: var(--s3); }
.mt-4 { margin-top: var(--s4); } .mt-5 { margin-top: var(--s5); } .mt-6 { margin-top: var(--s6); }
.mb-2 { margin-bottom: var(--s2); } .mb-3 { margin-bottom: var(--s3); }
.mb-4 { margin-bottom: var(--s4); } .mb-5 { margin-bottom: var(--s5); } .mb-6 { margin-bottom: var(--s6); }

.t-xs { font-size: 11px; } .t-sm { font-size: 13px; } .t-md { font-size: 15px; }
.t-lg { font-size: 17px; } .t-xl { font-size: 20px; } .t-2xl { font-size: 25px; } .t-3xl { font-size: 31px; }
.fw-500 { font-weight: 500; } .fw-600 { font-weight: 600; } .fw-700 { font-weight: 700; } .fw-800 { font-weight: 800; }
.display { font-family: var(--font-display); }
.muted { color: var(--mist-400); }
.muted-2 { color: var(--mist-500); }
.leading-relaxed { line-height: 1.65; }

/* Semantic colors */
.c-emerald { color: var(--emerald-400); } .c-rose { color: var(--rose-400); }
.c-amber  { color: var(--amber-400); }   .c-violet { color: var(--violet-400); }
.c-sky    { color: var(--sky-400); }     .c-pink { color: var(--pink-400); }
.c-teal   { color: var(--teal-400); }    .c-mist { color: var(--mist-100); }

/* --------------------------------------------------------------------------
   4. CARDS & GLASS
   -------------------------------------------------------------------------- */
.card {
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: var(--r-lg);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  padding: var(--s4);
}
.card-lg { padding: var(--s5); border-radius: var(--r-xl); }
.card-sm { padding: var(--s3); border-radius: var(--r-md); }
.card-flat { background: rgba(255,255,255,0.03); border: 1px solid rgba(255,255,255,0.06); border-radius: var(--r-md); padding: var(--s3); }
.card-hover { transition: border-color .2s, transform .2s, box-shadow .2s; }
@media (hover: hover) {
  .card-hover:hover { border-color: var(--glass-border-hi); transform: translateY(-2px); box-shadow: var(--shadow-lift); }
}
.card-title { font-family: var(--font-display); font-weight: 600; font-size: 15px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); margin-bottom: var(--s3); }

/* Accent left-border variants */
.acc-emerald { border-left: 3px solid var(--emerald); }
.acc-rose    { border-left: 3px solid var(--rose); }
.acc-amber   { border-left: 3px solid var(--amber); }
.acc-violet  { border-left: 3px solid var(--violet); }
.acc-sky     { border-left: 3px solid var(--sky); }
.acc-pink    { border-left: 3px solid var(--pink); }

/* --------------------------------------------------------------------------
   5. BUTTONS
   -------------------------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 var(--s4);
  border-radius: var(--r-md);
  font-size: 14px; font-weight: 600;
  transition: transform .12s, background-color .15s, border-color .15s, opacity .15s;
  user-select: none; -webkit-user-select: none;
  white-space: nowrap;
}
.btn:active { transform: scale(0.96); }
.btn:disabled { opacity: .5; pointer-events: none; }

.btn-primary { background: linear-gradient(120deg, var(--emerald), var(--sky)); color: var(--ink-950); box-shadow: var(--shadow-glow); }
.btn-ghost { background: rgba(255,255,255,0.06); border: 1px solid var(--glass-border); color: var(--mist-100); }
.btn-ghost:hover { background: rgba(255,255,255,0.1); }
.btn-sm { min-height: 36px; padding: 0 var(--s3); font-size: 13px; border-radius: var(--r-sm); }
.btn-xs { min-height: 30px; padding: 0 10px; font-size: 12px; border-radius: var(--r-sm); }
.btn-block { width: 100%; }
.btn-icon { min-width: 44px; padding: 0; border-radius: var(--r-full); }

.btn-emerald { background: rgba(16,185,129,0.16); color: var(--emerald-400); }
.btn-rose    { background: rgba(244,63,94,0.16);  color: var(--rose-400); }
.btn-amber   { background: rgba(245,158,11,0.16); color: var(--amber-400); }
.btn-violet  { background: rgba(139,92,246,0.16); color: var(--violet-400); }
.btn-sky     { background: rgba(59,130,246,0.16); color: var(--sky-400); }
.btn-pink    { background: rgba(236,72,153,0.16); color: var(--pink-400); }
.btn-emerald:hover { background: rgba(16,185,129,0.26); }
.btn-rose:hover    { background: rgba(244,63,94,0.26); }
.btn-amber:hover   { background: rgba(245,158,11,0.26); }
.btn-violet:hover  { background: rgba(139,92,246,0.26); }
.btn-sky:hover     { background: rgba(59,130,246,0.26); }
.btn-pink:hover    { background: rgba(236,72,153,0.26); }

.tap { min-height: 44px; min-width: 44px; }

/* --------------------------------------------------------------------------
   6. CHIPS / BADGES / PILLS
   -------------------------------------------------------------------------- */
.chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 4px 10px; border-radius: var(--r-full);
  font-size: 11.5px; font-weight: 600; line-height: 1.4;
  white-space: nowrap;
}
.chip-emerald { background: rgba(16,185,129,0.14); color: var(--emerald-400); }
.chip-rose    { background: rgba(244,63,94,0.14);  color: var(--rose-400); }
.chip-amber   { background: rgba(245,158,11,0.14); color: var(--amber-400); }
.chip-violet  { background: rgba(139,92,246,0.14); color: var(--violet-400); }
.chip-sky     { background: rgba(59,130,246,0.14); color: var(--sky-400); }
.chip-pink    { background: rgba(236,72,153,0.14); color: var(--pink-400); }
.chip-mist    { background: rgba(255,255,255,0.07); color: var(--mist-300); }

.chip-dot::before { content: ''; width: 6px; height: 6px; border-radius: var(--r-full); background: currentColor; flex-shrink: 0; }

.chip-x {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 7px 8px 7px 12px; border-radius: var(--r-full);
  background: rgba(255,255,255,0.06); border: 1px solid var(--glass-border);
  font-size: 13px;
}
.chip-x button {
  width: 20px; height: 20px; border-radius: var(--r-full);
  display: flex; align-items: center; justify-content: center;
  background: rgba(255,255,255,0.08); color: var(--mist-400); font-size: 12px; line-height: 1;
}
.chip-x button:hover { background: rgba(244,63,94,0.3); color: #fff; }

/* --------------------------------------------------------------------------
   7. PROGRESS
   -------------------------------------------------------------------------- */
.bar { width: 100%; height: 7px; border-radius: var(--r-full); background: rgba(255,255,255,0.07); overflow: hidden; display: flex; }
.bar-sm { height: 5px; }
.bar-lg { height: 10px; }
.bar > span { height: 100%; display: block; transition: width .6s cubic-bezier(.2,.8,.2,1); }
.bar-emerald > span { background: linear-gradient(90deg, var(--emerald), var(--emerald-400)); }
.bar-rose > span    { background: linear-gradient(90deg, var(--rose), var(--rose-400)); }
.bar-amber > span   { background: linear-gradient(90deg, var(--amber), var(--amber-400)); }
.bar-violet > span  { background: linear-gradient(90deg, var(--violet), var(--violet-400)); }
.bar-sky > span     { background: linear-gradient(90deg, var(--sky), var(--sky-400)); }
.bar-pink > span    { background: linear-gradient(90deg, var(--pink), var(--pink-400)); }

/* --------------------------------------------------------------------------
   8. APP SHELL
   -------------------------------------------------------------------------- */
#app { display: flex; min-height: 100vh; min-height: 100dvh; }

.sidebar {
  display: none;
  width: var(--sidebar-w); flex-shrink: 0;
  border-right: 1px solid var(--glass-border);
  padding: var(--s6) var(--s4);
  position: sticky; top: 0; height: 100vh; height: 100dvh;
  flex-direction: column;
  overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: var(--s3); padding: 0 var(--s2); margin-bottom: var(--s6); }
.brand-mark {
  width: 40px; height: 40px; border-radius: var(--r-md);
  background: linear-gradient(135deg, var(--emerald-400), var(--sky));
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display); font-weight: 800; font-size: 18px; color: var(--ink-950);
  box-shadow: var(--shadow-glow); flex-shrink: 0;
}
.brand-mark-sm { width: 32px; height: 32px; font-size: 15px; border-radius: var(--r-sm); }

.nav-item {
  display: flex; align-items: center; gap: var(--s3);
  width: 100%; min-height: 44px; padding: 0 var(--s3);
  border-radius: var(--r-md); color: var(--mist-400);
  font-size: 14px; font-weight: 500; text-align: left;
  transition: background-color .15s, color .15s;
  margin-bottom: 2px;
}
.nav-item:hover { background: rgba(255,255,255,0.05); color: var(--mist-100); }
.nav-item.active { background: rgba(255,255,255,0.09); color: var(--mist-100); font-weight: 600; }
.nav-item .ic { width: 20px; text-align: center; font-size: 15px; flex-shrink: 0; }
.nav-badge { margin-left: auto; font-size: 10.5px; font-weight: 700; padding: 2px 7px; border-radius: var(--r-full); background: rgba(244,63,94,0.2); color: var(--rose-400); }

.main { flex: 1; min-width: 0; padding-bottom: calc(var(--bottomnav-h) + var(--sab) + 8px); }

.topbar {
  position: sticky; top: 0; z-index: 20;
  background: rgba(11,15,26,0.82);
  backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--glass-border);
  padding-top: var(--sat);
}
.topbar-inner {
  display: flex; align-items: center; gap: var(--s2);
  padding: 10px max(var(--s4), var(--sar)) 10px max(var(--s4), var(--sal));
  min-height: var(--header-h);
}
.content { padding: var(--s5) max(var(--s4), var(--sal)) var(--s8) max(var(--s4), var(--sar)); max-width: 1400px; margin: 0 auto; }

/* Status dot */
.dot { width: 9px; height: 9px; border-radius: var(--r-full); flex-shrink: 0; transition: background-color .3s; }
.dot-ok { background: var(--emerald); box-shadow: 0 0 8px rgba(16,185,129,0.8); }
.dot-bad { background: var(--rose); box-shadow: 0 0 8px rgba(244,63,94,0.8); }
.dot-wait { background: var(--amber); }

/* Mobile bottom nav */
.bottomnav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
  display: flex; justify-content: space-around; align-items: stretch;
  background: rgba(11,15,26,0.94);
  backdrop-filter: blur(24px); -webkit-backdrop-filter: blur(24px);
  border-top: 1px solid var(--glass-border);
  padding: 6px max(6px, var(--sal)) calc(6px + var(--sab)) max(6px, var(--sar));
}
.bn-item {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; min-height: 50px; border-radius: var(--r-md);
  color: var(--mist-500); font-size: 10px; font-weight: 600;
  transition: color .15s, background-color .15s;
  padding: 4px 2px;
}
.bn-item .ic { font-size: 17px; line-height: 1; }
.bn-item.active { color: var(--emerald-400); background: rgba(16,185,129,0.1); }
.bn-item:active { transform: scale(0.94); }

/* Tab panels */
.panel { display: none; }
.panel.active { display: block; animation: fadeUp .32s ease both; }
@keyframes fadeUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

.page-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); margin-bottom: var(--s4); flex-wrap: wrap; }
.page-head h2 { font-size: 19px; }

/* --------------------------------------------------------------------------
   9. FILTER CONTROLS
   -------------------------------------------------------------------------- */
.seg {
  display: flex; gap: 2px; padding: 3px;
  background: rgba(255,255,255,0.05); border: 1px solid var(--glass-border);
  border-radius: var(--r-full); overflow-x: auto; scrollbar-width: none;
  max-width: 100%;
}
.seg::-webkit-scrollbar { display: none; }
.seg button {
  padding: 7px 13px; border-radius: var(--r-full);
  font-size: 12.5px; font-weight: 600; color: var(--mist-400);
  white-space: nowrap; transition: background-color .15s, color .15s;
  min-height: 34px;
}
.seg button.active { background: rgba(255,255,255,0.12); color: var(--mist-100); }

.select-mini {
  appearance: none; -webkit-appearance: none;
  background: rgba(255,255,255,0.05) url("data:image/svg+xml;charset=UTF-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath fill='%2394A3B8' d='M0 0l5 6 5-6z'/%3E%3C/svg%3E") no-repeat right 12px center;
  border: 1px solid var(--glass-border); border-radius: var(--r-md);
  color: var(--mist-100); font-weight: 500;
  padding: 0 30px 0 12px; min-height: 40px;
  color-scheme: dark;
  /* A <select> sizes itself to its widest option, so without a cap a long
     month label pushes the whole top bar past the edge of a phone screen. */
  max-width: 42vw;
  text-overflow: ellipsis;
  /* 16px keeps iOS Safari from zooming the page in when this is tapped.
     Desktop has no such behaviour, so it drops to a compact size below. */
  font-size: 16px;
}
.select-mini option { background: var(--ink-800); color: var(--mist-100); }
@media (min-width: 768px) {
  .select-mini { font-size: 13px; max-width: 260px; }
}

/* --------------------------------------------------------------------------
   10. KPI ROW
   -------------------------------------------------------------------------- */
.kpi-row {
  display: flex; gap: var(--s3);
  overflow-x: auto; scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch; scrollbar-width: none;
  margin: 0 calc(-1 * var(--s4)); padding: 2px var(--s4) var(--s2);
}
.kpi-row::-webkit-scrollbar { display: none; }
.kpi {
  scroll-snap-align: center; flex-shrink: 0;
  min-width: 78%; max-width: 78%;
  background: var(--glass-bg); border: 1px solid var(--glass-border);
  border-radius: var(--r-lg); padding: var(--s4);
  backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px);
}
.kpi-label { display: flex; align-items: center; justify-content: space-between; gap: var(--s2); }
.kpi-label > p { font-size: 12.5px; color: var(--mist-400); }
.kpi-value { font-family: var(--font-display); font-weight: 700; font-size: 26px; margin-top: 8px; letter-spacing: -0.02em; }
.kpi-sub { font-size: 11.5px; margin-top: 5px; font-variant-numeric: tabular-nums; }

/* --------------------------------------------------------------------------
   11. GRIDS
   -------------------------------------------------------------------------- */
.g { display: grid; gap: var(--s4); }
.g-1 { grid-template-columns: 1fr; }
.g-2, .g-3, .g-4 { grid-template-columns: 1fr; }
.g-auto { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.g-auto-sm { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }

/* --------------------------------------------------------------------------
   12. CHART WRAPPERS
   -------------------------------------------------------------------------- */
.chart-box { position: relative; height: 220px; }
.chart-box-sm { height: 180px; }
.chart-box-lg { height: 260px; }
.chart-fallback {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center; text-align: center;
  font-size: 13px; color: var(--mist-400); padding: var(--s4);
}

/* --------------------------------------------------------------------------
   13. PULSE RING
   -------------------------------------------------------------------------- */
.pulse-wrap { position: relative; width: 150px; height: 150px; margin: 0 auto; }
.pulse-svg { transform: rotate(-90deg); width: 150px; height: 150px; }
.pulse-svg circle { transition: stroke-dashoffset 1s cubic-bezier(.2,.8,.2,1); }
.pulse-center { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.pulse-score { font-family: var(--font-display); font-weight: 800; font-size: 34px; line-height: 1; letter-spacing: -0.02em; }

.pulse-breakdown { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--s2); margin-top: var(--s4); width: 100%; }
.pulse-metric { background: rgba(255,255,255,0.03); border-radius: var(--r-sm); padding: 8px 10px; text-align: left; }
.pulse-metric b { display: block; font-family: var(--font-mono); font-size: 14px; margin-top: 2px; }

/* --------------------------------------------------------------------------
   14. TABLES → responsive card fallback
   -------------------------------------------------------------------------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: var(--r-lg); }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.tbl thead th {
  position: sticky; top: 0; z-index: 1;
  background: var(--ink-850); color: var(--mist-400);
  font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em;
  padding: 11px var(--s3); text-align: left; white-space: nowrap;
}
table.tbl tbody td { padding: 11px var(--s3); border-top: 1px solid rgba(255,255,255,0.05); vertical-align: middle; }
table.tbl tbody tr:hover { background: rgba(255,255,255,0.025); }
table.tbl .num { text-align: right; font-family: var(--font-mono); font-variant-numeric: tabular-nums; white-space: nowrap; }

/* Mobile: transform rows into stacked cards */
@media (max-width: 767px) {
  table.tbl, table.tbl thead, table.tbl tbody, table.tbl tr, table.tbl td { display: block; width: 100%; }
  table.tbl thead { display: none; }
  table.tbl tbody tr {
    background: rgba(255,255,255,0.03); border: 1px solid var(--glass-border);
    border-radius: var(--r-md); padding: var(--s3); margin-bottom: var(--s2);
  }
  table.tbl tbody td { border: none; padding: 4px 0; display: flex; justify-content: space-between; align-items: center; gap: var(--s3); }
  table.tbl tbody td::before {
    content: attr(data-l); flex-shrink: 0;
    font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--mist-500);
  }
  table.tbl tbody td.num { text-align: right; }
  table.tbl tbody td[data-l=""]::before { display: none; }
  table.tbl tbody td.row-actions { justify-content: flex-end; padding-top: var(--s2); margin-top: var(--s2); border-top: 1px solid rgba(255,255,255,0.06); }
}

.row-actions { display: flex; gap: 6px; justify-content: flex-end; }
.icon-btn {
  width: 34px; height: 34px; border-radius: var(--r-sm);
  display: inline-flex; align-items: center; justify-content: center;
  background: rgba(255,255,255,0.05); color: var(--mist-400); font-size: 13px;
  transition: background-color .15s, color .15s;
}
.icon-btn:hover { background: rgba(255,255,255,0.12); color: var(--mist-100); }
.icon-btn.danger:hover { background: rgba(244,63,94,0.25); color: var(--rose-400); }

/* --------------------------------------------------------------------------
   15. EMPTY STATES
   -------------------------------------------------------------------------- */
.empty {
  text-align: center; padding: var(--s8) var(--s4);
  color: var(--mist-400); font-size: 13.5px; line-height: 1.6;
}
.empty .em-icon { font-size: 30px; opacity: .35; display: block; margin-bottom: var(--s3); }
.empty a, .empty button.linkish { color: var(--emerald-400); font-weight: 600; text-decoration: underline; }

/* --------------------------------------------------------------------------
   16. MODALS & BOTTOM SHEETS
   -------------------------------------------------------------------------- */
.overlay {
  position: fixed; inset: 0; z-index: 60;
  display: none; align-items: flex-end; justify-content: center;
  background: rgba(4,6,12,0.7);
  backdrop-filter: blur(5px); -webkit-backdrop-filter: blur(5px);
}
.overlay.open { display: flex; animation: fadeIn .2s ease both; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.sheet {
  width: 100%; max-height: 92vh; max-height: 92dvh;
  overflow-y: auto; -webkit-overflow-scrolling: touch;
  background: linear-gradient(180deg, var(--ink-850), var(--ink-900));
  border: 1px solid var(--glass-border); border-bottom: none;
  border-radius: var(--r-xl) var(--r-xl) 0 0;
  padding: var(--s4) var(--s5) calc(var(--s6) + var(--sab));
  animation: sheetUp .3s cubic-bezier(.2,.8,.2,1) both;
}
.sheet-wide { max-width: 100%; }
@keyframes sheetUp { from { transform: translateY(100%); } to { transform: translateY(0); } }

.sheet-grip { width: 42px; height: 5px; border-radius: var(--r-full); background: rgba(255,255,255,0.2); margin: 0 auto var(--s4); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); margin-bottom: var(--s4); }
.sheet-head h3 { font-size: 17px; }

/* --------------------------------------------------------------------------
   17. FORMS
   -------------------------------------------------------------------------- */
.field { margin-bottom: var(--s4); }
.field label { display: block; font-size: 12.5px; font-weight: 600; color: var(--mist-400); margin-bottom: 6px; }
.field .hint { font-size: 11.5px; color: var(--mist-500); margin-top: 5px; }

input[type=text], input[type=number], input[type=date], input[type=password],
input[type=email], input[type=url], select, textarea {
  width: 100%;
  /* 16px prevents iOS Safari auto-zoom on focus */
  font-size: 16px;
  font-family: inherit;
  color: var(--mist-100);
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--glass-border);
  border-radius: var(--r-md);
  padding: 11px var(--s3);
  min-height: 46px;
  color-scheme: dark;
  transition: border-color .15s, background-color .15s;
}
textarea { min-height: 80px; resize: vertical; line-height: 1.5; }
input:focus, select:focus, textarea:focus {
  outline: none; border-color: rgba(16,185,129,0.6);
  background: rgba(255,255,255,0.07);
}
input::placeholder, textarea::placeholder { color: var(--mist-500); }

/* Native pickers on iOS/Android otherwise render light-on-light */
select {
  appearance: none; -webkit-appearance: none;
  background-image: url("data:image/svg+xml;charset=UTF-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath fill='%2394A3B8' d='M0 0l5 6 5-6z'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 14px center;
  padding-right: 34px;
}
select option, select optgroup { background-color: var(--ink-800); color: var(--mist-100); }
input[type=date] { min-height: 46px; }
input[type=date]::-webkit-calendar-picker-indicator { filter: invert(0.7); }

input[type=range] {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 6px; border-radius: var(--r-full);
  background: rgba(255,255,255,0.1); padding: 0; min-height: 0;
  border: none; margin: var(--s3) 0;
}
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 26px; height: 26px; border-radius: var(--r-full);
  background: linear-gradient(135deg, var(--emerald-400), var(--sky));
  border: 3px solid var(--ink-900); cursor: pointer;
  box-shadow: 0 2px 10px rgba(0,0,0,0.5);
}
input[type=range]::-moz-range-thumb {
  width: 22px; height: 22px; border-radius: var(--r-full);
  background: var(--emerald-400); border: 3px solid var(--ink-900); cursor: pointer;
}

.form-error {
  background: rgba(244,63,94,0.1); border: 1px solid rgba(244,63,94,0.3);
  border-radius: var(--r-md); padding: var(--s3); margin-bottom: var(--s4);
  font-size: 13px; color: var(--rose-400); line-height: 1.5;
}
.form-note {
  background: rgba(59,130,246,0.08); border: 1px solid rgba(59,130,246,0.22);
  border-radius: var(--r-md); padding: var(--s3);
  font-size: 12.5px; color: var(--sky-400); line-height: 1.55;
}

.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s3); }

/* --------------------------------------------------------------------------
   18. TOASTS
   -------------------------------------------------------------------------- */
#toast {
  position: fixed; z-index: 90;
  bottom: calc(var(--bottomnav-h) + var(--sab) + 16px);
  left: 50%; transform: translateX(-50%);
  padding: 11px var(--s4); border-radius: var(--r-md);
  background: rgba(19,26,46,0.97); border: 1px solid var(--glass-border);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  font-size: 13.5px; font-weight: 500; max-width: min(92vw, 420px);
  box-shadow: var(--shadow-lift);
  animation: toastIn .25s ease both;
}
#toast.err { border-color: rgba(244,63,94,0.5); color: var(--rose-400); }
#toast.ok { border-color: rgba(16,185,129,0.5); color: var(--emerald-400); }
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 12px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* --------------------------------------------------------------------------
   19. INSIGHTS / AI COACH
   -------------------------------------------------------------------------- */
.insight {
  display: flex; gap: var(--s3); align-items: flex-start;
  padding: var(--s3); border-radius: var(--r-md);
  background: rgba(255,255,255,0.03); border: 1px solid rgba(255,255,255,0.05);
  margin-bottom: var(--s2);
}
.insight-ic {
  width: 30px; height: 30px; border-radius: var(--r-sm); flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; font-size: 14px;
}
.insight-body { flex: 1; min-width: 0; }
.insight-body h4 { font-size: 13.5px; font-weight: 600; margin-bottom: 3px; font-family: var(--font-body); }
.insight-body p { font-size: 12.5px; color: var(--mist-400); line-height: 1.6; }
.insight-action { margin-top: var(--s2); }

.sev-critical .insight-ic { background: rgba(244,63,94,0.16); color: var(--rose-400); }
.sev-warn .insight-ic { background: rgba(245,158,11,0.16); color: var(--amber-400); }
.sev-good .insight-ic { background: rgba(16,185,129,0.16); color: var(--emerald-400); }
.sev-info .insight-ic { background: rgba(59,130,246,0.16); color: var(--sky-400); }
.sev-idea .insight-ic { background: rgba(139,92,246,0.16); color: var(--violet-400); }
.sev-critical { border-left: 3px solid var(--rose); }
.sev-warn { border-left: 3px solid var(--amber); }
.sev-good { border-left: 3px solid var(--emerald); }
.sev-info { border-left: 3px solid var(--sky); }
.sev-idea { border-left: 3px solid var(--violet); }

/* Chat */
.chat-log {
  min-height: 180px; max-height: 46vh; overflow-y: auto;
  display: flex; flex-direction: column; gap: var(--s3);
  padding: var(--s3); border-radius: var(--r-md);
  background: rgba(0,0,0,0.2); margin-bottom: var(--s3);
}
.msg { max-width: 88%; padding: 10px var(--s3); border-radius: var(--r-md); font-size: 13.5px; line-height: 1.6; white-space: pre-wrap; word-wrap: break-word; }
.msg-user { align-self: flex-end; background: rgba(16,185,129,0.16); border: 1px solid rgba(16,185,129,0.25); border-bottom-right-radius: 4px; }
.msg-ai { align-self: flex-start; background: rgba(255,255,255,0.05); border: 1px solid var(--glass-border); border-bottom-left-radius: 4px; }
.msg-sys { align-self: center; font-size: 12px; color: var(--mist-500); text-align: center; max-width: 100%; }
.chat-input-row { display: flex; gap: var(--s2); align-items: flex-end; }
.chat-input-row textarea { min-height: 46px; max-height: 120px; }

.typing span {
  display: inline-block; width: 6px; height: 6px; border-radius: 50%;
  background: var(--mist-400); margin-right: 4px; animation: blink 1.4s infinite both;
}
.typing span:nth-child(2) { animation-delay: .2s; }
.typing span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

/* --------------------------------------------------------------------------
   20. STREAKS / ACHIEVEMENTS
   -------------------------------------------------------------------------- */
.achv-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: var(--s3); }
.achv {
  text-align: center; padding: var(--s3) var(--s2); border-radius: var(--r-md);
  background: rgba(255,255,255,0.03); border: 1px solid rgba(255,255,255,0.06);
  transition: transform .2s;
}
.achv.unlocked { border-color: rgba(245,158,11,0.35); background: rgba(245,158,11,0.07); }
.achv .em { font-size: 24px; display: block; margin-bottom: 6px; }
.achv.locked .em { filter: grayscale(1); opacity: .3; }
.achv b { font-size: 12px; display: block; }
.achv small { font-size: 10.5px; color: var(--mist-500); display: block; margin-top: 3px; line-height: 1.4; }

/* --------------------------------------------------------------------------
   21. LOAN DETAIL / STRATEGY
   -------------------------------------------------------------------------- */
.stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--s2); }
.stat {
  background: rgba(255,255,255,0.03); border: 1px solid rgba(255,255,255,0.06);
  border-radius: var(--r-md); padding: var(--s3);
}
.stat small { font-size: 11px; color: var(--mist-400); display: block; }
.stat b { font-family: var(--font-display); font-size: 17px; font-weight: 700; display: block; margin-top: 4px; letter-spacing: -0.01em; }

.strategy-card { border-radius: var(--r-lg); padding: var(--s4); border: 1px solid var(--glass-border); background: rgba(255,255,255,0.03); }
.strategy-card.best { border-color: rgba(16,185,129,0.45); background: rgba(16,185,129,0.06); }
.strategy-badge { position: absolute; top: -10px; right: var(--s3); }

.amort-scroll { max-height: 340px; overflow-y: auto; -webkit-overflow-scrolling: touch; border-radius: var(--r-md); }
.amort-scroll table { font-size: 12px; }
.amort-scroll td, .amort-scroll th { padding: 8px 10px !important; }
@media (max-width: 767px) {
  .amort-scroll table, .amort-scroll thead, .amort-scroll tbody, .amort-scroll tr, .amort-scroll td { display: revert; }
  .amort-scroll thead { display: table-header-group; }
  .amort-scroll tbody tr { display: table-row; background: none; border: none; border-radius: 0; padding: 0; margin: 0; }
  .amort-scroll tbody td { display: table-cell; border-top: 1px solid rgba(255,255,255,0.05); }
  .amort-scroll tbody td::before { display: none; }
}

/* --------------------------------------------------------------------------
   22. CALCULATORS
   -------------------------------------------------------------------------- */
.calc-tabs { display: flex; gap: var(--s2); overflow-x: auto; scrollbar-width: none; padding-bottom: var(--s2); margin-bottom: var(--s4); }
.calc-tabs::-webkit-scrollbar { display: none; }
.calc-tabs button {
  padding: 9px var(--s4); border-radius: var(--r-full); white-space: nowrap;
  background: rgba(255,255,255,0.05); border: 1px solid var(--glass-border);
  font-size: 13px; font-weight: 600; color: var(--mist-400); min-height: 40px;
}
.calc-tabs button.active { background: rgba(16,185,129,0.16); border-color: rgba(16,185,129,0.4); color: var(--emerald-400); }

.calc-result {
  background: linear-gradient(135deg, rgba(16,185,129,0.1), rgba(59,130,246,0.08));
  border: 1px solid rgba(16,185,129,0.25); border-radius: var(--r-lg);
  padding: var(--s4); margin-top: var(--s4);
}
.calc-big { font-family: var(--font-display); font-size: 28px; font-weight: 800; letter-spacing: -0.02em; }

/* --------------------------------------------------------------------------
   23. ADMIN
   -------------------------------------------------------------------------- */
.admin-sec { margin-bottom: var(--s6); }
.admin-sec > h3 { font-size: 15px; margin-bottom: var(--s3); display: flex; align-items: center; gap: var(--s2); }
.chip-wrap { display: flex; flex-wrap: wrap; gap: var(--s2); margin-bottom: var(--s3); }
.add-row { display: flex; gap: var(--s2); }
.add-row input { flex: 1; min-height: 42px; }

.member-row {
  display: flex; align-items: center; gap: var(--s3);
  padding: var(--s3); border-radius: var(--r-md);
  background: rgba(255,255,255,0.03); border: 1px solid rgba(255,255,255,0.06);
  margin-bottom: var(--s2);
}
.avatar {
  width: 38px; height: 38px; border-radius: var(--r-full); flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display); font-weight: 700; font-size: 15px; color: var(--ink-950);
}

/* --------------------------------------------------------------------------
   24. MISC
   -------------------------------------------------------------------------- */
.divider { height: 1px; background: rgba(255,255,255,0.07); margin: var(--s4) 0; }
.banner {
  border-radius: var(--r-md); padding: var(--s3) var(--s4);
  font-size: 13px; line-height: 1.6; margin-bottom: var(--s4);
  display: flex; align-items: flex-start; gap: var(--s3);
}
.banner-warn { background: rgba(245,158,11,0.1); border: 1px solid rgba(245,158,11,0.3); color: var(--amber-400); }
.banner-info { background: rgba(59,130,246,0.1); border: 1px solid rgba(59,130,246,0.3); color: var(--sky-400); }
.banner-err  { background: rgba(244,63,94,0.1); border: 1px solid rgba(244,63,94,0.3); color: var(--rose-400); }

.skeleton {
  background: linear-gradient(90deg, rgba(255,255,255,0.04) 25%, rgba(255,255,255,0.09) 50%, rgba(255,255,255,0.04) 75%);
  background-size: 200% 100%; animation: shimmer 1.4s infinite; border-radius: var(--r-sm);
}
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

.stagger > * { animation: fadeUp .4s ease both; }
.stagger > *:nth-child(1) { animation-delay: .02s; } .stagger > *:nth-child(2) { animation-delay: .06s; }
.stagger > *:nth-child(3) { animation-delay: .10s; } .stagger > *:nth-child(4) { animation-delay: .14s; }
.stagger > *:nth-child(5) { animation-delay: .18s; } .stagger > *:nth-child(6) { animation-delay: .22s; }

.fab {
  position: fixed; z-index: 35;
  right: max(16px, var(--sar)); bottom: calc(var(--bottomnav-h) + var(--sab) + 16px);
  width: 54px; height: 54px; border-radius: var(--r-full);
  background: linear-gradient(135deg, var(--violet), var(--pink));
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; box-shadow: 0 8px 26px -6px rgba(139,92,246,0.7);
  transition: transform .15s;
}
.fab:active { transform: scale(0.92); }

/* --------------------------------------------------------------------------
   25. RESPONSIVE BREAKPOINTS
   -------------------------------------------------------------------------- */

/* ---- ≥480px: larger phones / small tablets ---- */
@media (min-width: 480px) {
  .kpi { min-width: 62%; max-width: 62%; }
  .g-2 { grid-template-columns: repeat(2, 1fr); }
  .field-row { grid-template-columns: 1fr 1fr; }
}

/* ---- ≥768px: tablets ---- */
@media (min-width: 768px) {
  body { font-size: 15px; }
  .main { padding-bottom: 0; }
  .bottomnav { display: none; }
  .fab { display: none; }
  #toast { bottom: 24px; }

  .sidebar { display: flex; }
  .topbar-inner { padding: 12px var(--s6); }
  .content { padding: var(--s6); }

  .kpi-row {
    display: grid; grid-template-columns: repeat(2, 1fr);
    overflow: visible; margin: 0; padding: 0 0 var(--s2);
  }
  .kpi { min-width: 0; max-width: none; }

  .g-2 { grid-template-columns: repeat(2, 1fr); }
  .g-3 { grid-template-columns: repeat(3, 1fr); }
  .stat-grid { grid-template-columns: repeat(4, 1fr); }
  .pulse-breakdown { grid-template-columns: repeat(4, 1fr); }

  .overlay { align-items: center; padding: var(--s5); }
  .sheet {
    max-width: 540px; border-radius: var(--r-xl); border-bottom: 1px solid var(--glass-border);
    max-height: 88vh; padding-bottom: var(--s6);
    animation: fadeUp .25s ease both;
  }
  .sheet-wide { max-width: 900px; }
  .sheet-grip { display: none; }

  /* Inputs can shrink below 16px on desktop — no iOS zoom risk there */
  input[type=text], input[type=number], input[type=date], input[type=password],
  input[type=email], input[type=url], select, textarea { font-size: 14px; min-height: 42px; }

  .chart-box { height: 250px; }
  .chart-box-sm { height: 200px; }
  .chart-box-lg { height: 300px; }
  .kpi-value { font-size: 28px; }
  .page-head h2 { font-size: 21px; }
}

/* ---- ≥1024px: desktop ---- */
@media (min-width: 1024px) {
  .kpi-row { grid-template-columns: repeat(4, 1fr); }
  .g-4 { grid-template-columns: repeat(4, 1fr); }
  .span-2 { grid-column: span 2; }
  .content { padding: var(--s6) var(--s8); }
}

/* ---- ≥1280px ---- */
@media (min-width: 1280px) {
  .g-lg-3 { grid-template-columns: repeat(3, 1fr); }
}

/* ---- Very small phones (≤360px: iPhone SE 1st gen, small Androids) ---- */
@media (max-width: 360px) {
  :root { --s4: 13px; --s5: 16px; --s6: 20px; }
  .kpi { min-width: 84%; max-width: 84%; }
  .kpi-value { font-size: 23px; }
  .bn-item { font-size: 9px; }
  .bn-item .ic { font-size: 16px; }
  .content { padding-left: 13px; padding-right: 13px; }
  .btn { padding: 0 12px; font-size: 13px; }
  .pulse-wrap, .pulse-svg { width: 132px; height: 132px; }
  .pulse-score { font-size: 30px; }
}

/* ---- Landscape phones: shrink vertical chrome ---- */
@media (max-height: 480px) and (orientation: landscape) {
  .sheet { max-height: 96vh; }
  .chart-box { height: 180px; }
  .bottomnav { padding-top: 3px; padding-bottom: calc(3px + var(--sab)); }
  .bn-item { min-height: 42px; }
}

/* ---- Reduced motion ---- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; scroll-behavior: auto !important; }
}

/* ---- Print ---- */
@media print {
  .sidebar, .bottomnav, .topbar, .fab, .row-actions, #toast { display: none !important; }
  body { background: #fff; color: #000; }
  .card { border: 1px solid #ccc; background: #fff; }
  .panel { display: block !important; }
}


/* --------------------------------------------------------------------------
   20. SIGN IN
   -------------------------------------------------------------------------- */
body.locked { overflow: hidden; }

.auth-screen {
  position: fixed; inset: 0; z-index: 200;
  display: flex; align-items: center; justify-content: center;
  padding: max(var(--s5), var(--sat)) var(--s5) max(var(--s5), var(--sab));
  background:
    radial-gradient(circle at 15% 10%, rgba(16,185,129,0.14), transparent 42%),
    radial-gradient(circle at 85% 20%, rgba(139,92,246,0.13), transparent 45%),
    radial-gradient(circle at 50% 95%, rgba(59,130,246,0.10), transparent 40%),
    var(--ink-900);
  overflow-y: auto;
}
.auth-card {
  width: 100%; max-width: 380px;
  background: linear-gradient(160deg, rgba(255,255,255,0.06), rgba(255,255,255,0.025));
  border: 1px solid var(--glass-border);
  backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  border-radius: var(--r-xl);
  padding: var(--s6) var(--s5) var(--s5);
  text-align: center;
  animation: fadeUp .4s ease both;
}
.auth-mark { width: 54px; height: 54px; font-size: 24px; margin: 0 auto; }
.auth-field { text-align: left; margin-bottom: var(--s4); }
.auth-field label {
  display: block; font-size: 12.5px; font-weight: 600;
  color: var(--mist-400); margin-bottom: 6px;
}
.auth-go { min-height: 50px; font-size: 15px; margin-top: var(--s2); }
.auth-go:disabled { opacity: .6; }
.auth-err {
  text-align: left; font-size: 13px; line-height: 1.5;
  color: var(--rose-400); background: rgba(244,63,94,0.1);
  border: 1px solid rgba(244,63,94,0.3); border-radius: var(--r-md);
  padding: 10px 12px; margin-bottom: var(--s3);
}
.auth-note {
  text-align: left; background: rgba(245,158,11,0.08);
  border: 1px solid rgba(245,158,11,0.28);
  border-radius: var(--r-md); padding: var(--s4);
}
.auth-note code {
  font-family: var(--font-mono); font-size: 12px;
  background: rgba(255,255,255,0.08); padding: 1px 5px; border-radius: 4px;
}

/* Signed-in identity chip */
.who {
  display: flex; align-items: center; gap: var(--s2);
  padding: 10px; margin-top: var(--s4);
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--glass-border);
  border-radius: var(--r-lg);
}
.who-avatar {
  width: 32px; height: 32px; flex-shrink: 0;
  border-radius: var(--r-full);
  background: linear-gradient(135deg, var(--emerald), var(--sky));
  color: var(--ink-950); font-weight: 700; font-size: 14px;
  display: flex; align-items: center; justify-content: center;
}

/* Account list in Admin -> Logins */
.acct-list { display: flex; flex-direction: column; gap: var(--s2); }
.acct {
  display: flex; align-items: center; gap: var(--s3);
  padding: 12px; border-radius: var(--r-lg);
  background: rgba(255,255,255,0.035);
  border: 1px solid var(--glass-border);
  flex-wrap: wrap;
}
.acct-actions { display: flex; gap: 4px; flex-wrap: wrap; margin-left: auto; }
.acct-actions .btn { min-height: 36px; }
.acct-actions .danger { color: var(--rose-400); }
@media (max-width: 520px) {
  .acct-actions { width: 100%; margin-left: 0; }
  .acct-actions .btn { flex: 1; }
}
