/* =========================================================
   Vela — design system
   Tokens follow Apple's Human Interface palette.
   Edit colors here; every component reads these variables.
   ========================================================= */

:root {
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", system-ui, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-round: ui-rounded, "SF Pro Rounded", -apple-system, system-ui, sans-serif;

  --radius-xl: 22px;
  --radius-lg: 16px;
  --radius-md: 12px;
  --radius-sm: 8px;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --tabbar-h: 56px;

  --ease-out: cubic-bezier(.22, 1, .36, 1);
  --spring: cubic-bezier(.32, 1.25, .5, 1);

  /* ---------- dark (default) ---------- */
  --bg: #000000;
  --bg-grouped: #000000;
  --card: #1C1C1E;
  --card-2: #2C2C2E;
  --card-3: #3A3A3C;
  --label: #FFFFFF;
  --label-2: rgba(235, 235, 245, 0.62);
  --label-3: rgba(235, 235, 245, 0.32);
  --separator: rgba(84, 84, 88, 0.55);
  --fill: rgba(118, 118, 128, 0.24);
  --fill-2: rgba(118, 118, 128, 0.16);
  --material: rgba(22, 22, 24, 0.72);
  --material-strong: rgba(28, 28, 30, 0.92);

  --accent: #0A84FF;
  --up: #30D158;
  --down: #FF453A;
  --warn: #FF9F0A;
  --purple: #BF5AF2;
  --teal: #64D2FF;

  /* chart palette (validated: dataviz skill, dark surface) */
  --c-1: #3987E5;   /* blue   */
  --c-2: #D95926;   /* orange */
  --c-3: #9085E9;   /* violet */
  --c-4: #199E70;   /* aqua   */
  --c-grid: rgba(235, 235, 245, 0.10);

  --shadow-card: none;
  --hero-grad: radial-gradient(120% 120% at 100% 0%, rgba(10, 132, 255, .28) 0%, rgba(10, 132, 255, 0) 55%),
               radial-gradient(90% 90% at 0% 100%, rgba(48, 209, 88, .14) 0%, rgba(48, 209, 88, 0) 60%),
               #111114;

  color-scheme: dark;
}

:root[data-theme="light"] {
  --bg: #F2F2F7;
  --bg-grouped: #F2F2F7;
  --card: #FFFFFF;
  --card-2: #F2F2F7;
  --card-3: #E5E5EA;
  --label: #000000;
  --label-2: rgba(60, 60, 67, 0.62);
  --label-3: rgba(60, 60, 67, 0.30);
  --separator: rgba(60, 60, 67, 0.20);
  --fill: rgba(120, 120, 128, 0.16);
  --fill-2: rgba(120, 120, 128, 0.10);
  --material: rgba(249, 249, 251, 0.78);
  --material-strong: rgba(255, 255, 255, 0.94);

  --accent: #007AFF;
  --up: #1F9D47;
  --down: #E5352B;
  --warn: #E07800;

  --c-1: #2A78D6;
  --c-2: #EB6834;
  --c-3: #6250D6;
  --c-4: #1BAF7A;
  --c-grid: rgba(60, 60, 67, 0.10);

  --shadow-card: 0 1px 2px rgba(0, 0, 0, .04), 0 8px 24px rgba(0, 0, 0, .04);
  --hero-grad: radial-gradient(120% 120% at 100% 0%, rgba(0, 122, 255, .16) 0%, rgba(0, 122, 255, 0) 55%),
               radial-gradient(90% 90% at 0% 100%, rgba(52, 199, 89, .12) 0%, rgba(52, 199, 89, 0) 60%),
               #FFFFFF;
  color-scheme: light;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); }
body {
  font-family: var(--font);
  color: var(--label);
  font-size: 17px;
  line-height: 1.3;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}
input, textarea, select, button { font: inherit; color: inherit; }
input, textarea { user-select: text; -webkit-user-select: text; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
svg { display: block; }
.num { font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.hidden { display: none !important; }
.muted { color: var(--label-2); }
.faint { color: var(--label-3); }
.up { color: var(--up); }
.down { color: var(--down); }
.warn { color: var(--warn); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------------- app shell ---------------- */
#app { position: fixed; inset: 0; display: flex; flex-direction: column; }
#views { position: relative; flex: 1; overflow: hidden; }
.view {
  position: absolute; inset: 0;
  overflow-y: auto; overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
  padding: calc(var(--safe-top) + 8px) calc(16px + var(--safe-right)) calc(var(--tabbar-h) + var(--safe-bottom) + 28px) calc(16px + var(--safe-left));
  opacity: 0; visibility: hidden;
  transform: translateY(6px) scale(.995);
  transition: opacity .28s var(--ease-out), transform .36s var(--ease-out), visibility 0s linear .28s;
}
.view.active { opacity: 1; visibility: visible; transform: none; transition: opacity .28s var(--ease-out), transform .36s var(--ease-out); }
.view-inner { max-width: 760px; margin: 0 auto; }

/* compact nav bar that fades in on scroll (iOS large-title behavior) */
.navbar {
  position: fixed; left: 0; right: 0; top: 0; z-index: 30;
  padding: var(--safe-top) 16px 0;
  height: calc(var(--safe-top) + 44px);
  display: flex; align-items: center; justify-content: center;
  background: var(--material);
  -webkit-backdrop-filter: saturate(180%) blur(24px);
  backdrop-filter: saturate(180%) blur(24px);
  border-bottom: .5px solid var(--separator);
  font-weight: 600; font-size: 17px;
  opacity: 0; pointer-events: none;
  transition: opacity .2s ease;
}
.navbar.show { opacity: 1; }

.large-title {
  display: flex; align-items: flex-end; justify-content: space-between; gap: 12px;
  padding: 10px 2px 14px;
}
.large-title h1 { margin: 0; font-size: 34px; line-height: 1.1; font-weight: 700; letter-spacing: -0.022em; }
.large-title > div:first-child { min-width: 0; flex: 1; }
.large-title .subtitle { font-size: 15px; color: var(--label-2); margin: 0 0 4px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.title-actions { display: flex; gap: 10px; padding-bottom: 2px; }
.icon-btn {
  width: 36px; height: 36px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--fill-2); color: var(--accent);
  transition: transform .15s ease, background .2s;
}
.icon-btn:active { transform: scale(.9); background: var(--fill); }
.icon-btn svg { width: 20px; height: 20px; }
.icon-btn.primary { background: var(--accent); color: #fff; }
.icon-btn.spin svg { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------- tab bar ---------------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  display: flex; justify-content: space-around;
  padding: 6px calc(8px + var(--safe-right)) calc(var(--safe-bottom) + 4px) calc(8px + var(--safe-left));
  background: var(--material);
  -webkit-backdrop-filter: saturate(180%) blur(24px);
  backdrop-filter: saturate(180%) blur(24px);
  border-top: .5px solid var(--separator);
}
.tab {
  flex: 1; max-width: 120px;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 4px 0 2px;
  color: var(--label-3);
  font-size: 10.5px; font-weight: 600; letter-spacing: .01em;
  transition: color .2s;
}
.tab svg { width: 26px; height: 26px; transition: transform .25s var(--spring); }
.tab.active { color: var(--accent); }
.tab:active svg { transform: scale(.86); }

/* ---------------- cards & sections ---------------- */
.card {
  background: var(--card);
  border-radius: var(--radius-xl);
  padding: 16px;
  margin-bottom: 14px;
  box-shadow: var(--shadow-card);
  position: relative;
  overflow: hidden;
}
.card.tight { padding: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.card-title { font-size: 17px; font-weight: 600; letter-spacing: -0.01em; display: flex; align-items: center; gap: 8px; }
.card-title .dot { width: 8px; height: 8px; border-radius: 50%; }
.card-title svg { width: 19px; height: 19px; color: var(--accent); flex: 0 0 auto; }
.card-sub { font-size: 13px; color: var(--label-2); }
.card-link { color: var(--accent); font-size: 15px; font-weight: 500; display: inline-flex; align-items: center; gap: 2px; }
.card-link svg { width: 14px; height: 14px; }
.section-label {
  font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--label-2);
  margin: 22px 16px 8px; font-weight: 500;
}
.section-foot { font-size: 13px; color: var(--label-2); margin: 8px 16px 0; line-height: 1.4; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 14px; }
.grid-2 > .card { margin-bottom: 0; }
@media (min-width: 720px) {
  .wide-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
  .wide-2 > .card { margin-bottom: 0; }
  .wide-2 { margin-bottom: 14px; }
}

/* hero */
.hero { background: var(--hero-grad); padding: 20px 18px 18px; }
.hero-label { font-size: 14px; color: var(--label-2); font-weight: 500; display: flex; align-items: center; gap: 6px; }
.hero-value { font-size: 40px; font-weight: 700; letter-spacing: -0.03em; margin: 4px 0 6px; line-height: 1.05; }
.hero-value .cents { font-size: 24px; letter-spacing: -0.02em; opacity: .9; }
.hero-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.hero-meta { display: flex; justify-content: space-between; gap: 12px; margin-top: 14px; padding-top: 14px; border-top: .5px solid var(--separator); }
.hero-meta > div { flex: 1; min-width: 0; }
.hero-meta .k { font-size: 12px; color: var(--label-2); margin-bottom: 2px; }
.hero-meta .v { font-size: 16px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.pill {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 9px; border-radius: 999px;
  font-size: 13px; font-weight: 600;
  background: var(--fill-2); color: var(--label-2);
  white-space: nowrap;
}
.pill.up { background: color-mix(in srgb, var(--up) 16%, transparent); color: var(--up); }
.pill.down { background: color-mix(in srgb, var(--down) 16%, transparent); color: var(--down); }
.pill.warn { background: color-mix(in srgb, var(--warn) 16%, transparent); color: var(--warn); }
.pill.accent { background: color-mix(in srgb, var(--accent) 16%, transparent); color: var(--accent); }
.pill svg { width: 12px; height: 12px; }

.stat-tile .k { font-size: 13px; color: var(--label-2); display: flex; align-items: center; gap: 6px; font-weight: 500; }
.stat-tile .v { font-size: 22px; font-weight: 700; letter-spacing: -0.02em; margin: 6px 0 4px; }
.stat-tile .s { font-size: 12px; color: var(--label-2); }
.stat-icon { width: 26px; height: 26px; border-radius: 8px; display: grid; place-items: center; color: #fff; }
.stat-icon svg { width: 15px; height: 15px; }

/* ---------------- segmented control ---------------- */
.segmented {
  position: relative; display: flex;
  background: var(--fill-2); border-radius: 9px; padding: 2px;
  gap: 0;
}
.segmented button {
  position: relative; z-index: 1; flex: 1;
  padding: 6px 8px; font-size: 13px; font-weight: 500; border-radius: 7px;
  color: var(--label); white-space: nowrap;
  transition: color .2s;
}
.segmented .thumb {
  position: absolute; top: 2px; bottom: 2px; left: 2px; z-index: 0;
  background: var(--card-3); border-radius: 7px;
  box-shadow: 0 3px 8px rgba(0, 0, 0, .12), 0 3px 1px rgba(0, 0, 0, .04);
  transition: transform .3s var(--ease-out), width .3s var(--ease-out);
}
:root[data-theme="light"] .segmented .thumb { background: #fff; }
.segmented button.on { font-weight: 600; }
.segmented.small button { padding: 4px 6px; font-size: 12px; }

/* chips */
.chips { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; padding: 2px 0 2px; margin: 0 -16px; padding-left: 16px; padding-right: 16px; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto; padding: 7px 13px; border-radius: 999px; font-size: 14px; font-weight: 500;
  background: var(--card); color: var(--label);
  border: .5px solid var(--separator);
  transition: background .2s, color .2s, transform .15s;
}
.chip:active { transform: scale(.96); }
.chip.on { background: var(--label); color: var(--bg); border-color: transparent; }

/* ---------------- lists (inset grouped) ---------------- */
.list { background: var(--card); border-radius: var(--radius-lg); overflow: hidden; margin-bottom: 14px; box-shadow: var(--shadow-card); }
.row {
  position: relative;
  display: flex; align-items: center; gap: 12px;
  min-height: 50px; padding: 10px 16px;
  background: var(--card);
  transition: background .15s;
}
.row + .row::before {
  content: ""; position: absolute; top: 0; right: 0; left: 16px;
  border-top: .5px solid var(--separator);
}
.row.with-icon + .row.with-icon::before { left: 62px; }
.row.tap:active { background: var(--card-2); }
.row .grow { flex: 1; min-width: 0; }
.row .title { font-size: 16px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .sub { font-size: 13px; color: var(--label-2); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .trail { text-align: right; flex: 0 0 auto; }
.row .trail .title { font-weight: 600; }
.row .chev { color: var(--label-3); width: 14px; height: 14px; flex: 0 0 auto; }
.row .value { color: var(--label-2); font-size: 16px; }
.row.danger .title { color: var(--down); }
.row.action .title { color: var(--accent); }
.row-icon {
  width: 34px; height: 34px; border-radius: 10px; flex: 0 0 auto;
  display: grid; place-items: center; font-size: 18px;
  background: var(--fill-2);
}
.row-icon svg { width: 18px; height: 18px; color: #fff; }
.settings-icon { width: 29px; height: 29px; border-radius: 7px; color: #fff; display: grid; place-items: center; flex: 0 0 auto; }
.settings-icon svg { width: 17px; height: 17px; }

/* swipe to delete */
.swipe { position: relative; overflow: hidden; }
.swipe .swipe-action {
  position: absolute; top: 0; right: 0; bottom: 0; width: 88px;
  background: var(--down); color: #fff; font-weight: 600; font-size: 15px;
  display: grid; place-items: center;
}
.swipe .row { transition: transform .3s var(--ease-out); will-change: transform; }
.swipe.dragging .row { transition: none; }

.day-head { display: flex; justify-content: space-between; font-size: 13px; color: var(--label-2); margin: 18px 6px 7px; font-weight: 500; }
.day-head:first-child { margin-top: 6px; }

/* ---------------- market rows ---------------- */
.mrow { gap: 10px; min-height: 64px; }
.mrow .sym { font-size: 17px; font-weight: 700; letter-spacing: -0.01em; display: flex; align-items: center; gap: 6px; }
.mrow .spark { width: 64px; height: 30px; flex: 0 0 auto; }
.mrow .price { font-size: 16px; font-weight: 600; }
.chg {
  display: inline-block; min-width: 74px; text-align: right;
  padding: 4px 8px; border-radius: 7px; margin-top: 3px;
  font-size: 13.5px; font-weight: 600; color: #fff;
  background: var(--label-3);
  transition: background .3s;
}
.chg.up { background: var(--up); color: #fff; }
.chg.down { background: var(--down); color: #fff; }
.flash-up { animation: flashUp .9s ease-out; }
.flash-down { animation: flashDown .9s ease-out; }
@keyframes flashUp { 0% { color: var(--up); text-shadow: 0 0 12px color-mix(in srgb, var(--up) 60%, transparent); } 100% { color: inherit; text-shadow: none; } }
@keyframes flashDown { 0% { color: var(--down); text-shadow: 0 0 12px color-mix(in srgb, var(--down) 60%, transparent); } 100% { color: inherit; text-shadow: none; } }

.src {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 10.5px; font-weight: 600; letter-spacing: .02em; text-transform: uppercase;
  color: var(--label-3);
}
.src .led { width: 6px; height: 6px; border-radius: 50%; background: var(--label-3); }
.src.live { color: var(--up); }
.src.live .led { background: var(--up); box-shadow: 0 0 0 0 var(--up); animation: pulse 1.8s infinite; }
.src.delayed { color: var(--warn); }
.src.delayed .led { background: var(--warn); }
.src.demo { color: var(--purple); }
.src.demo .led { background: var(--purple); }
.src.error { color: var(--down); }
.src.error .led { background: var(--down); }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--up) 70%, transparent); }
  70% { box-shadow: 0 0 0 6px color-mix(in srgb, var(--up) 0%, transparent); }
  100% { box-shadow: 0 0 0 0 transparent; }
}

.logo {
  width: 38px; height: 38px; border-radius: 11px; flex: 0 0 auto;
  display: grid; place-items: center; overflow: hidden;
  font-size: 12px; font-weight: 700; color: #fff; letter-spacing: -0.02em;
  background: linear-gradient(135deg, #3a3a3c, #1c1c1e);
}
.logo img { width: 100%; height: 100%; object-fit: cover; background: #fff; }

.ticker-strip { display: flex; gap: 10px; overflow-x: auto; scrollbar-width: none; margin: 0 -16px; padding: 0 16px 2px; scroll-snap-type: x mandatory; }
.ticker-strip::-webkit-scrollbar { display: none; }
.tcard {
  flex: 0 0 148px; scroll-snap-align: start;
  background: var(--card); border-radius: var(--radius-lg); padding: 12px;
  box-shadow: var(--shadow-card);
}
.tcard .sym { font-weight: 700; font-size: 15px; }
.tcard .price { font-weight: 600; font-size: 15px; margin-top: 6px; }
.tcard canvas { width: 100%; height: 34px; margin-top: 6px; }

/* ---------------- charts ---------------- */
.chart { position: relative; width: 100%; touch-action: pan-y; }
.chart canvas { width: 100%; height: 100%; display: block; }
.chart-tip {
  position: absolute; top: 0; pointer-events: none;
  transform: translateX(-50%);
  background: var(--material-strong);
  -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px);
  border: .5px solid var(--separator);
  border-radius: 10px; padding: 6px 9px; font-size: 12px; white-space: nowrap;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .18);
  opacity: 0; transition: opacity .12s;
  z-index: 2;
}
.chart-tip.show { opacity: 1; }
.chart-tip b { display: block; font-size: 14px; font-weight: 700; }
.chart-empty { display: grid; place-items: center; height: 100%; color: var(--label-3); font-size: 14px; text-align: center; padding: 0 20px; }

.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 13px; color: var(--label-2); margin-top: 10px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.legend b { color: var(--label); font-weight: 600; margin-left: 4px; }

.stackbar { display: flex; gap: 2px; height: 12px; border-radius: 6px; overflow: hidden; background: var(--fill-2); }
.stackbar > span { display: block; height: 100%; min-width: 4px; transition: flex-grow .6s var(--ease-out); }
.stackbar > span:first-child { border-radius: 4px 0 0 4px; }
.stackbar > span:last-child { border-radius: 0 4px 4px 0; }
.stackbar > span:only-child { border-radius: 4px; }

.hbar-row { display: grid; grid-template-columns: 30px 1fr auto; gap: 4px 10px; align-items: center; padding: 7px 0; }
.hbar-row .emoji { font-size: 18px; text-align: center; }
.hbar-row .name { font-size: 14px; font-weight: 500; display: flex; justify-content: space-between; gap: 8px; }
.hbar-row .name small { color: var(--label-2); font-weight: 500; font-size: 12px; }
.hbar-row .amt { font-size: 14px; font-weight: 600; text-align: right; }
.hbar-track { grid-column: 2 / 4; height: 6px; border-radius: 3px; background: var(--fill-2); overflow: hidden; position: relative; }
.hbar-fill { height: 100%; border-radius: 3px; background: var(--c-1); transition: width .7s var(--ease-out); }
.hbar-fill.over { background: var(--down); }
.hbar-budget { position: absolute; top: -2px; bottom: -2px; width: 2px; background: var(--label-2); border-radius: 1px; }

.ring { position: relative; width: 92px; height: 92px; flex: 0 0 auto; }
.ring svg { width: 92px; height: 92px; transform: rotate(-90deg); }
.ring .ring-label { position: absolute; inset: 0; display: grid; place-items: center; font-weight: 700; font-size: 20px; letter-spacing: -0.02em; }
.ring circle { transition: stroke-dashoffset 1s var(--ease-out); }

/* insights */
.insight { display: flex; gap: 12px; padding: 12px 0; }
.insight + .insight { border-top: .5px solid var(--separator); }
.insight .ic { width: 32px; height: 32px; border-radius: 10px; display: grid; place-items: center; flex: 0 0 auto; font-size: 17px; background: var(--fill-2); }
.insight .t { font-size: 15px; font-weight: 600; margin-bottom: 2px; }
.insight .d { font-size: 14px; color: var(--label-2); line-height: 1.35; }

/* ---------------- banners ---------------- */
.banner {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 12px 14px; border-radius: var(--radius-lg);
  background: color-mix(in srgb, var(--purple) 14%, var(--card));
  font-size: 14px; line-height: 1.35; margin-bottom: 14px;
}
.banner.info { background: color-mix(in srgb, var(--accent) 12%, var(--card)); }
.banner.warn { background: color-mix(in srgb, var(--warn) 14%, var(--card)); }
.banner b { display: block; font-size: 15px; margin-bottom: 2px; }
.banner .ic { font-size: 18px; line-height: 1.2; }
.banner button { color: var(--accent); font-weight: 600; margin-top: 6px; font-size: 14px; }

/* ---------------- search ---------------- */
.search {
  display: flex; align-items: center; gap: 6px;
  background: var(--fill-2); border-radius: 10px; padding: 0 10px; height: 38px;
  margin-bottom: 12px;
}
.search svg { width: 17px; height: 17px; color: var(--label-2); flex: 0 0 auto; }
.search input { flex: 1; border: 0; outline: 0; background: transparent; font-size: 17px; min-width: 0; }
.search input::placeholder { color: var(--label-2); }

/* ---------------- sheets ---------------- */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(0, 0, 0, 0);
  transition: background .35s var(--ease-out);
}
.sheet-backdrop.show { background: rgba(0, 0, 0, .45); }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 61;
  max-width: 680px; margin: 0 auto;
  height: calc(100% - var(--safe-top) - 12px);
  background: var(--bg-grouped);
  border-radius: 14px 14px 0 0;
  display: flex; flex-direction: column;
  transform: translateY(105%);
  transition: transform .42s var(--ease-out);
  box-shadow: 0 -10px 40px rgba(0, 0, 0, .3);
}
:root[data-theme="light"] .sheet { background: #F2F2F7; }
:root:not([data-theme="light"]) .sheet { background: #1C1C1E; }
:root:not([data-theme="light"]) .sheet .list,
:root:not([data-theme="light"]) .sheet .card,
:root:not([data-theme="light"]) .sheet .row { background: #2C2C2E; }
:root:not([data-theme="light"]) .sheet .row.tap:active { background: #3A3A3C; }
:root:not([data-theme="light"]) .sheet .segmented .thumb { background: #636366; }
:root:not([data-theme="light"]) .sheet .chip { background: #2C2C2E; }
:root:not([data-theme="light"]) .sheet .chip.on { background: var(--label); }
.sheet.medium { height: auto; max-height: calc(100% - var(--safe-top) - 12px); }
.sheet.show { transform: translateY(0); }
.sheet.dragging { transition: none; }
.sheet-grab { position: absolute; top: 6px; left: 50%; width: 36px; height: 5px; margin-left: -18px; border-radius: 3px; background: var(--label-3); }
.sheet-nav {
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  padding: 16px 16px 10px; flex: 0 0 auto; touch-action: none;
}
.sheet-nav .l { justify-self: start; }
.sheet-nav .r { justify-self: end; }
.sheet-nav h2 { margin: 0; font-size: 17px; font-weight: 600; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 56vw; }
.nav-btn { color: var(--accent); font-size: 17px; padding: 4px 0; }
.nav-btn.bold { font-weight: 600; }
.nav-btn:disabled { color: var(--label-3); }
.sheet-body {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
  padding: 4px 16px calc(var(--safe-bottom) + 28px);
}

/* forms */
.amount-field { text-align: center; padding: 10px 0 18px; }
.amount-field .cur { font-size: 22px; font-weight: 600; color: var(--label-2); vertical-align: 14px; margin-right: 4px; }
.amount-field input {
  width: 100%; max-width: 100%; border: 0; outline: 0; background: transparent; text-align: center;
  font-size: 52px; font-weight: 700; letter-spacing: -0.03em; caret-color: var(--accent);
  font-variant-numeric: tabular-nums;
}
.amount-field.expense input { color: var(--label); }
.amount-field.income input { color: var(--up); }
.field-row { display: flex; align-items: center; gap: 12px; min-height: 48px; padding: 6px 16px; position: relative; }
.field-row + .field-row::before { content: ""; position: absolute; top: 0; left: 16px; right: 0; border-top: .5px solid var(--separator); }
.field-row label { flex: 0 0 auto; font-size: 16px; }
.field-row input, .field-row select, .field-row textarea {
  flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; text-align: right; font-size: 16px; color: var(--label-2);
  -webkit-appearance: none; appearance: none;
}
.field-row input:focus, .field-row textarea:focus { color: var(--label); }
.field-row textarea { text-align: left; resize: none; min-height: 64px; padding: 8px 0; }
.field-row input[type="date"] { min-height: 30px; display: flex; justify-content: flex-end; }
.field-row input::-webkit-date-and-time-value { text-align: right; }
.field-block { padding: 12px 16px; }
.field-block .lbl { font-size: 13px; color: var(--label-2); margin-bottom: 8px; font-weight: 500; }

.cat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.cat {
  display: flex; flex-direction: column; align-items: center; gap: 5px;
  padding: 10px 2px 8px; border-radius: 12px; font-size: 11px; font-weight: 500; color: var(--label-2);
  border: 1.5px solid transparent; transition: border-color .2s, background .2s, transform .15s;
  text-align: center; line-height: 1.15;
}
.cat .e { font-size: 24px; }
.cat:active { transform: scale(.94); }
.cat.on { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, transparent); color: var(--label); }

.need-seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.need-seg button {
  padding: 10px 6px; border-radius: 12px; font-size: 13px; font-weight: 600;
  background: var(--fill-2); color: var(--label-2);
  border: 1.5px solid transparent;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  transition: all .2s;
}
.need-seg button .e { font-size: 18px; }
.need-seg button.on { color: var(--label); }
.need-seg button.on[data-v="essential"] { border-color: var(--c-1); background: color-mix(in srgb, var(--c-1) 16%, transparent); }
.need-seg button.on[data-v="important"] { border-color: var(--c-4); background: color-mix(in srgb, var(--c-4) 16%, transparent); }
.need-seg button.on[data-v="unnecessary"] { border-color: var(--c-2); background: color-mix(in srgb, var(--c-2) 16%, transparent); }

/* iOS switch */
.switch { position: relative; width: 51px; height: 31px; flex: 0 0 auto; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; z-index: 1; }
.switch span { position: absolute; inset: 0; border-radius: 16px; background: var(--fill); transition: background .25s; }
.switch span::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%;
  background: #fff; box-shadow: 0 3px 8px rgba(0, 0, 0, .15), 0 3px 1px rgba(0, 0, 0, .06);
  transition: transform .3s var(--spring);
}
.switch input:checked + span { background: var(--up); }
.switch input:checked + span::after { transform: translateX(20px); }

.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; height: 50px; border-radius: 14px;
  background: var(--accent); color: #fff; font-size: 17px; font-weight: 600;
  transition: transform .15s, opacity .2s;
}
.btn:active { transform: scale(.98); opacity: .9; }
.btn.secondary { background: var(--fill-2); color: var(--accent); }
.btn.danger { background: color-mix(in srgb, var(--down) 14%, transparent); color: var(--down); }
.btn svg { width: 20px; height: 20px; }
.btn-row { display: flex; gap: 10px; margin-top: 10px; }
.btn-row .btn { flex: 1; }

/* stats grid in detail */
.stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 18px; }
.stats-grid > div { display: flex; justify-content: space-between; padding: 9px 0; border-bottom: .5px solid var(--separator); font-size: 14px; }
.stats-grid > div span:first-child { color: var(--label-2); }
.stats-grid > div span:last-child { font-weight: 600; text-align: right; }
.stats-grid.one { grid-template-columns: 1fr; }
.stats-grid > div span:first-child { white-space: nowrap; margin-right: 8px; }

.detail-price { font-size: 38px; font-weight: 700; letter-spacing: -0.03em; line-height: 1.05; }
.detail-change { font-size: 16px; font-weight: 600; margin-top: 4px; }
.detail-when { font-size: 13px; color: var(--label-2); margin-top: 2px; }

/* ---------------- alert dialog ---------------- */
.alert-back { position: fixed; inset: 0; z-index: 90; background: rgba(0, 0, 0, .4); display: grid; place-items: center; opacity: 0; transition: opacity .2s; }
.alert-back.show { opacity: 1; }
.alert {
  width: 270px; border-radius: 14px; overflow: hidden; text-align: center;
  background: var(--material-strong);
  -webkit-backdrop-filter: blur(30px); backdrop-filter: blur(30px);
  transform: scale(1.12); transition: transform .3s var(--spring);
}
.alert-back.show .alert { transform: scale(1); }
.alert .a-body { padding: 18px 16px 16px; }
.alert h3 { margin: 0 0 4px; font-size: 17px; font-weight: 600; }
.alert p { margin: 0; font-size: 13px; line-height: 1.35; }
.alert .a-btns { display: flex; border-top: .5px solid var(--separator); }
.alert .a-btns button { flex: 1; height: 44px; color: var(--accent); font-size: 17px; }
.alert .a-btns button + button { border-left: .5px solid var(--separator); }
.alert .a-btns button.bold { font-weight: 600; }
.alert .a-btns button.destructive { color: var(--down); }

/* ---------------- toast ---------------- */
.toast {
  position: fixed; left: 50%; top: calc(var(--safe-top) + 10px); z-index: 95;
  transform: translate(-50%, -140%);
  display: flex; align-items: center; gap: 10px;
  min-width: 180px; max-width: calc(100% - 32px);
  padding: 11px 16px; border-radius: 999px;
  background: #1C1C1E; color: #fff;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .35);
  font-size: 15px; font-weight: 500;
  transition: transform .45s var(--spring);
}
:root[data-theme="light"] .toast { background: #1C1C1E; }
.toast.show { transform: translate(-50%, 0); }
.toast button { color: #0A84FF; font-weight: 600; margin-left: auto; padding-left: 8px; }
.toast .t-ic { font-size: 18px; }

/* ---------------- onboarding ---------------- */
.onb {
  position: fixed; inset: 0; z-index: 80; background: var(--bg);
  display: flex; flex-direction: column;
  padding: calc(var(--safe-top) + 24px) 24px calc(var(--safe-bottom) + 20px);
  overflow-y: auto;
}
.onb-step { flex: 1; display: flex; flex-direction: column; max-width: 460px; width: 100%; margin: 0 auto; animation: rise .5s var(--ease-out); }
@keyframes rise { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: none; } }
.onb-logo { width: 104px; height: 104px; border-radius: 24px; margin: 8vh auto 26px; box-shadow: 0 20px 50px rgba(10, 132, 255, .35); overflow: hidden; }
.onb-logo img { width: 100%; height: 100%; }
.onb h1 { font-size: 34px; text-align: center; margin: 0 0 10px; letter-spacing: -0.025em; }
.onb .lead { text-align: center; color: var(--label-2); font-size: 17px; margin: 0 0 28px; line-height: 1.4; }
.onb-feat { display: flex; gap: 14px; align-items: flex-start; margin: 0 6px 20px; }
.onb-feat .fi { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; flex: 0 0 auto; color: #fff; }
.onb-feat .fi svg { width: 22px; height: 22px; }
.onb-feat b { display: block; font-size: 16px; margin-bottom: 2px; }
.onb-feat span { color: var(--label-2); font-size: 14px; line-height: 1.35; }
.onb-actions { margin-top: auto; padding-top: 20px; display: flex; flex-direction: column; gap: 10px; }
.onb-q { font-size: 28px; font-weight: 700; letter-spacing: -0.02em; margin: 6vh 0 8px; }
.onb-hint { color: var(--label-2); font-size: 15px; margin: 0 0 24px; line-height: 1.4; }
.onb-input {
  width: 100%; border: 0; outline: 0; background: var(--card); border-radius: 14px;
  padding: 16px; font-size: 20px; font-weight: 600; margin-bottom: 12px;
}
.onb-dots { display: flex; gap: 6px; justify-content: center; margin-bottom: 8px; }
.onb-dots i { width: 7px; height: 7px; border-radius: 50%; background: var(--label-3); transition: all .3s; }
.onb-dots i.on { width: 20px; border-radius: 4px; background: var(--accent); }
.link-btn { color: var(--accent); font-size: 16px; font-weight: 500; padding: 10px; }

/* empty states */
.empty { text-align: center; padding: 34px 20px; color: var(--label-2); }
.empty .e { font-size: 44px; margin-bottom: 8px; }
.empty b { display: block; color: var(--label); font-size: 18px; margin-bottom: 4px; }
.empty p { margin: 0 0 16px; font-size: 15px; line-height: 1.4; }
.empty .btn { max-width: 260px; margin: 0 auto; }

.month-switch { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.month-switch .m { font-size: 17px; font-weight: 600; }

.foot-note { text-align: center; color: var(--label-3); font-size: 12px; line-height: 1.5; margin: 18px 10px 0; }
.foot-note a { color: var(--label-2); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
@media (hover: hover) {
  .row.tap:hover { background: var(--card-2); }
}

/* ---------------- assistente (chat) ---------------- */
.fab {
  position: fixed; right: calc(16px + var(--safe-right)); bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 14px); z-index: 39;
  width: 52px; height: 52px; border-radius: 50%;
  display: grid; place-items: center; color: #fff;
  background: linear-gradient(135deg, #0A84FF, #BF5AF2);
  box-shadow: 0 8px 24px rgba(10, 132, 255, .38), 0 2px 6px rgba(0, 0, 0, .25);
  transition: transform .25s var(--spring);
}
.fab:active { transform: scale(.9); }
.fab svg { width: 24px; height: 24px; }
.sheet-body.chat-body { display: flex; flex-direction: column; padding: 0; overflow: hidden; }
.chat-list { flex: 1; overflow-y: auto; padding: 8px 16px 12px; display: flex; flex-direction: column; gap: 8px; overscroll-behavior: contain; }
.chat-hello { margin: auto; text-align: center; max-width: 320px; color: var(--label-2); font-size: 14px; line-height: 1.45; }
.chat-hello .big { font-size: 40px; }
.chat-hello b { display: block; color: var(--label); font-size: 18px; margin: 6px 0; }
.bubble { max-width: 86%; padding: 10px 13px; border-radius: 18px; font-size: 15.5px; line-height: 1.4; word-break: break-word; animation: pop .25s var(--ease-out); }
.bubble.me { align-self: flex-end; background: var(--accent); color: #fff; border-bottom-right-radius: 5px; }
.bubble.bot { align-self: flex-start; background: var(--card); border-bottom-left-radius: 5px; }
:root:not([data-theme="light"]) .sheet .bubble.bot { background: #2C2C2E; }
.bubble.err { background: color-mix(in srgb, var(--down) 16%, var(--card)); }
.bubble .li { padding-left: 14px; text-indent: -14px; }
.bubble .msg-text { white-space: pre-wrap; }
.bubble .msg-text > div { white-space: normal; }
.bubble.typing { display: flex; gap: 4px; padding: 14px; }
.bubble.typing span { width: 7px; height: 7px; border-radius: 50%; background: var(--label-3); animation: blink 1.2s infinite; }
.bubble.typing span:nth-child(2) { animation-delay: .15s; } .bubble.typing span:nth-child(3) { animation-delay: .3s; }
@keyframes blink { 0%, 60%, 100% { opacity: .3; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-3px); } }
@keyframes pop { from { opacity: 0; transform: translateY(6px) scale(.98); } to { opacity: 1; transform: none; } }
.chat-chips { flex: 0 0 auto; padding: 0 16px 8px; margin: 0; }
.chat-chips:empty { display: none; }
.chat-bar {
  flex: 0 0 auto; display: flex; align-items: flex-end; gap: 8px;
  padding: 8px 12px calc(var(--safe-bottom) + 10px); border-top: .5px solid var(--separator);
  background: var(--material-strong);
}
.chat-bar textarea {
  flex: 1; resize: none; border: 0; outline: 0; border-radius: 19px; padding: 9px 14px; font-size: 16px; line-height: 1.3;
  background: var(--fill-2); max-height: 110px;
}
.chat-send { width: 36px; height: 36px; border-radius: 50%; background: var(--accent); color: #fff; display: grid; place-items: center; flex: 0 0 auto; transition: opacity .2s, transform .2s var(--spring); }
.chat-send:disabled { opacity: .3; }
.chat-send:not(:disabled):active { transform: scale(.88); }
.chat-send svg { width: 18px; height: 18px; }
