/* Themes: Light is the base. No data-theme = System (Light or Dark from the device setting).
   The .tp-* classes carry the same tokens so the Settings previews show each theme whatever is active. */
:root, .tp-light, .tp-paper, .tp-mist {
  color-scheme: light;
  --page: #f6f6f3;
  --surface: #fcfcfb;
  --surface-2: #f1f0ec;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.08);
  --accent: #2a78d6;
  --accent-soft: rgba(42, 120, 214, 0.12);
  --glow-1: rgba(42, 120, 214, 0.14);
  --glow-2: rgba(235, 104, 52, 0.09);
  --good: #006300;
  --warn-bg: #fff4d6;
  --warn-ink: #6b4a00;
  --bad: #d03b3b;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;
  --series-5: #e87ba4;
  --series-6: #008300;
  --series-7: #6250d6;
  --series-8: #e34948;
  --other: #b5b3ab;
  --shadow: 0 1px 2px rgba(20, 20, 10, 0.04), 0 8px 24px -12px rgba(20, 20, 10, 0.10);
  --shadow-hover: 0 2px 4px rgba(20, 20, 10, 0.05), 0 18px 40px -16px rgba(20, 20, 10, 0.20);
  --glass: rgba(252, 252, 251, 0.72);

  /* Motion: one clean overshoot (no wobble) so short animations stay smooth. */
  --spring: cubic-bezier(0.32, 1.38, 0.58, 1);
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --radius: 18px;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme])) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #242422;
    --ink: #f0efec;
    --ink-2: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.08);
    --accent: #3987e5;
    --accent-soft: rgba(57, 135, 229, 0.18);
    --glow-1: rgba(57, 135, 229, 0.16);
    --glow-2: rgba(217, 89, 38, 0.08);
    --good: #0ca30c;
    --warn-bg: #3a2e10;
    --warn-ink: #f5d58a;
    --bad: #e66767;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
    --series-5: #d55181;
    --series-6: #008300;
    --series-7: #9085e9;
    --series-8: #e66767;
    --other: #5c5b56;
    --shadow: 0 1px 0 rgba(255, 255, 255, 0.03) inset, 0 10px 30px -14px rgba(0, 0, 0, 0.6);
    --shadow-hover: 0 1px 0 rgba(255, 255, 255, 0.05) inset, 0 22px 44px -16px rgba(0, 0, 0, 0.75);
    --glass: rgba(26, 26, 25, 0.68);
  }
}

:root[data-theme="dark"], :root[data-theme="midnight"], .tp-dark, .tp-midnight {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #242422;
  --ink: #f0efec;
  --ink-2: #c3c2b7;
  --muted: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.08);
  --accent: #3987e5;
  --accent-soft: rgba(57, 135, 229, 0.18);
  --glow-1: rgba(57, 135, 229, 0.16);
  --glow-2: rgba(217, 89, 38, 0.08);
  --good: #0ca30c;
  --warn-bg: #3a2e10;
  --warn-ink: #f5d58a;
  --bad: #e66767;
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --series-4: #c98500;
  --series-5: #d55181;
  --series-6: #008300;
  --series-7: #9085e9;
  --series-8: #e66767;
  --other: #5c5b56;
  --shadow: 0 1px 0 rgba(255, 255, 255, 0.03) inset, 0 10px 30px -14px rgba(0, 0, 0, 0.6);
  --shadow-hover: 0 1px 0 rgba(255, 255, 255, 0.05) inset, 0 22px 44px -16px rgba(0, 0, 0, 0.75);
  --glass: rgba(26, 26, 25, 0.68);
}

/* Paper: warm cream with a terracotta accent (light series colours). */
:root[data-theme="paper"], .tp-paper {
  --page: #f4efe6;
  --surface: #fbf8f2;
  --surface-2: #efe8dc;
  --ink: #1f1a14;
  --ink-2: #5a5145;
  --muted: #8a7f6f;
  --grid: #e4dccd;
  --axis: #cbbfa9;
  --border: rgba(60, 40, 10, 0.10);
  --accent: #b4532a;
  --accent-soft: rgba(180, 83, 42, 0.12);
  --glow-1: rgba(180, 83, 42, 0.10);
  --glow-2: rgba(27, 140, 122, 0.08);
  --good: #2f6b1f;
  --warn-bg: #f8e7c0;
  --warn-ink: #6b4a00;
  --bad: #b8322f;
  --other: #bdb4a3;
  --shadow: 0 1px 2px rgba(60, 40, 10, 0.05), 0 8px 24px -12px rgba(60, 40, 10, 0.14);
  --shadow-hover: 0 2px 4px rgba(60, 40, 10, 0.06), 0 18px 40px -16px rgba(60, 40, 10, 0.24);
  --glass: rgba(251, 248, 242, 0.74);
}

/* Mist: cool blue-grey with a teal accent (light series colours). */
:root[data-theme="mist"], .tp-mist {
  --page: #eef2f6;
  --surface: #f9fbfd;
  --surface-2: #e7edf3;
  --ink: #0e1622;
  --ink-2: #4a5869;
  --muted: #7b8798;
  --grid: #dbe3ec;
  --axis: #b9c5d3;
  --border: rgba(14, 30, 50, 0.09);
  --accent: #0f7c86;
  --accent-soft: rgba(15, 124, 134, 0.12);
  --glow-1: rgba(15, 124, 134, 0.12);
  --glow-2: rgba(98, 80, 214, 0.08);
  --good: #0b6e3a;
  --warn-bg: #fdf1d3;
  --warn-ink: #6b4a00;
  --bad: #c93a3a;
  --other: #aeb8c4;
  --shadow: 0 1px 2px rgba(14, 30, 50, 0.05), 0 8px 24px -12px rgba(14, 30, 50, 0.14);
  --shadow-hover: 0 2px 4px rgba(14, 30, 50, 0.06), 0 18px 40px -16px rgba(14, 30, 50, 0.24);
  --glass: rgba(249, 251, 253, 0.72);
}

/* Midnight: deep navy with a bright blue accent (dark series colours, set above). */
:root[data-theme="midnight"], .tp-midnight {
  --page: #0a0f1c;
  --surface: #121a2b;
  --surface-2: #1a2438;
  --ink: #e8edf7;
  --ink-2: #b4bfd3;
  --muted: #7d89a0;
  --grid: #232f46;
  --axis: #314060;
  --border: rgba(160, 190, 255, 0.09);
  --accent: #5b9cff;
  --accent-soft: rgba(91, 156, 255, 0.18);
  --glow-1: rgba(91, 156, 255, 0.18);
  --glow-2: rgba(150, 110, 255, 0.10);
  --good: #2bb673;
  --bad: #ef6b6b;
  --series-1: #5b9cff;
  --other: #4a5670;
  --shadow: 0 1px 0 rgba(160, 190, 255, 0.04) inset, 0 10px 30px -14px rgba(0, 0, 10, 0.7);
  --shadow-hover: 0 1px 0 rgba(160, 190, 255, 0.06) inset, 0 22px 44px -16px rgba(0, 0, 10, 0.8);
  --glass: rgba(18, 26, 43, 0.70);
}

/* ==========================================================================
   Grant Analysis Mobile — layout and components.
   The theme blocks above are copied verbatim from the desktop site/styles.css; change them there first.
   Motion: one overshoot spring (--spring), transform and opacity only, off under reduced motion.
   ========================================================================== */
:root {
  --tabbar-h: 58px;
  --nav-h: 48px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --gutter: 16px;
  --r-card: 20px;
  --r-tile: 16px;
  --spring-soft: cubic-bezier(0.34, 1.26, 0.64, 1);
  --ease-in: cubic-bezier(0.4, 0, 1, 1);
  --press: cubic-bezier(0.2, 0.9, 0.3, 1.25);
  --scrim: rgba(10, 10, 12, 0.34);
  --hair: var(--border);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  background-color: var(--page);
  color: var(--ink);
  font: 15px/1.42 -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  overscroll-behavior: none;
  font-variant-numeric: tabular-nums;
}
body::before {
  content: ""; position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background:
    radial-gradient(600px 420px at 0% -8%, var(--glow-1), transparent 70%),
    radial-gradient(520px 380px at 100% 0%, var(--glow-2), transparent 70%);
}
button, input, select { font: inherit; color: inherit; }
button { background: none; border: 0; padding: 0; cursor: pointer; }
button:focus:not(:focus-visible), label:focus:not(:focus-visible) { outline: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
small { font-size: 0.6em; font-weight: 600; margin-left: 2px; color: var(--ink-2); }
b { font-weight: 650; }

/* Press feedback: a quick squeeze that springs back. */
.press { transition: transform 0.32s var(--press), background-color 0.2s, opacity 0.2s; will-change: transform; }
.press:active { transform: scale(0.965); transition-duration: 0.08s; }
.press.soft:active { transform: scale(0.985); }

/* ---------- Screens ---------- */
.screen {
  position: fixed; inset: 0;
  overflow-y: auto; overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
  padding-bottom: calc(var(--tabbar-h) + var(--safe-b) + 28px);
  scrollbar-width: none;
}
.screen::-webkit-scrollbar { display: none; }
.screen:not(.active) { visibility: hidden; pointer-events: none; }
.screen.enter .page { animation: screen-in 0.42s var(--spring) both; }
@keyframes screen-in { from { opacity: 0; transform: translate3d(0, 14px, 0) scale(0.988); } }

.page { max-width: 760px; margin: 0 auto; padding: 0 calc(var(--gutter) + var(--safe-r)) 0 calc(var(--gutter) + var(--safe-l)); }

/* Navigation bar: transparent over the large title, glass once the page scrolls under it. */
.nav {
  position: sticky; top: 0; z-index: 20;
  height: calc(var(--nav-h) + var(--safe-t));
  padding: var(--safe-t) calc(var(--gutter) + var(--safe-r)) 0 calc(var(--gutter) + var(--safe-l));
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
}
.nav::before {
  content: ""; position: absolute; inset: 0; z-index: -1;
  background: var(--glass);
  -webkit-backdrop-filter: blur(22px) saturate(1.7); backdrop-filter: blur(22px) saturate(1.7);
  border-bottom: 0.5px solid var(--hair);
  opacity: 0; transition: opacity 0.22s;
}
.screen.scrolled .nav::before { opacity: 1; }
.nav-title {
  position: absolute; left: 50%; bottom: 12px; transform: translate3d(-50%, 6px, 0);
  font-weight: 650; font-size: 16px; opacity: 0; transition: opacity 0.2s, transform 0.36s var(--spring);
  white-space: nowrap; max-width: 56%; overflow: hidden; text-overflow: ellipsis; pointer-events: none;
}
.screen.scrolled .nav-title { opacity: 1; transform: translate3d(-50%, 0, 0); }
.nav-side { display: flex; align-items: center; gap: 8px; min-width: 40px; }
.nav-side.right { justify-content: flex-end; }

.large-title { padding: 2px 0 12px; }
.large-title h1 { margin: 0; font-size: 33px; line-height: 1.1; letter-spacing: -0.02em; font-weight: 750; transform-origin: left center; }
.large-title .lt-sub { margin-top: 4px; color: var(--muted); font-size: 13px; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }

.icon-btn {
  width: 38px; height: 38px; border-radius: 50%;
  display: inline-grid; place-items: center;
  background: var(--surface); border: 0.5px solid var(--hair); box-shadow: var(--shadow);
  color: var(--ink);
}
.icon-btn svg { width: 19px; height: 19px; }
.icon-btn.accent { background: var(--accent); color: #fff; border-color: transparent; }

.brand-mark { width: 30px; height: 30px; border-radius: 9px; display: block; }

/* ---------- Tab bar ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  height: calc(var(--tabbar-h) + var(--safe-b));
  padding: 0 var(--safe-r) var(--safe-b) var(--safe-l);
  display: flex; justify-content: center;
  background: var(--glass);
  -webkit-backdrop-filter: blur(24px) saturate(1.8); backdrop-filter: blur(24px) saturate(1.8);
  border-top: 0.5px solid var(--hair);
}
.tabbar-in { position: relative; display: grid; grid-template-columns: repeat(5, 1fr); width: 100%; max-width: 560px; }
.tab-blob {
  position: absolute; top: 6px; left: 0; height: 32px; width: 56px; border-radius: 16px;
  background: var(--accent-soft);
  transition: transform 0.5s var(--spring);
  pointer-events: none;
}
.tab {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: flex-start; gap: 3px;
  padding-top: 10px; color: var(--muted); font-size: 10.5px; font-weight: 600; letter-spacing: 0.01em;
}
.tab svg { width: 24px; height: 24px; transition: transform 0.4s var(--spring); }
.tab[aria-selected="true"] { color: var(--accent); }
.tab.pop svg { animation: tab-pop 0.5s var(--spring); }
@keyframes tab-pop { 0% { transform: scale(1); } 35% { transform: scale(0.82); } 100% { transform: scale(1); } }
.tab .dot { position: absolute; top: 6px; right: calc(50% - 20px); min-width: 16px; height: 16px; padding: 0 4px; border-radius: 8px; background: var(--bad); color: #fff; font-size: 10px; line-height: 16px; text-align: center; }

/* ---------- Chips ---------- */
.chip-row {
  display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none;
  margin: 0 calc(-1 * var(--gutter)); padding: 2px var(--gutter) 12px;
  scroll-padding: 0 var(--gutter);
}
.chip-row::-webkit-scrollbar { display: none; }
.chip {
  flex: none; display: inline-flex; align-items: center; gap: 6px;
  height: 34px; padding: 0 13px; border-radius: 17px;
  background: var(--surface); border: 0.5px solid var(--hair); box-shadow: var(--shadow);
  font-size: 13.5px; font-weight: 550; color: var(--ink-2); white-space: nowrap;
}
.chip b { color: var(--ink); font-weight: 650; }
.chip svg { width: 15px; height: 15px; }
.chip.on { background: var(--accent); color: #fff; border-color: transparent; }
.chip.on b { color: #fff; }
.chip.excl { background: color-mix(in srgb, var(--bad) 14%, var(--surface)); color: var(--bad); border-color: color-mix(in srgb, var(--bad) 30%, transparent); }
.chip.excl b { color: var(--bad); }
.chip .x { opacity: 0.6; font-size: 11px; margin-left: 2px; }
.chip.new { animation: chip-in 0.46s var(--spring) both; }
@keyframes chip-in { from { opacity: 0; transform: scale(0.6); } }
.chip.leaving { animation: chip-out 0.2s var(--ease-in) forwards; }
@keyframes chip-out { to { opacity: 0; transform: scale(0.6); } }
.chip .n { min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--accent); color: #fff; font-size: 11px; line-height: 18px; text-align: center; }
.chip.on .n { background: #fff; color: var(--accent); }

/* ---------- Cards ---------- */
.card {
  background: var(--surface); border: 0.5px solid var(--hair); border-radius: var(--r-card);
  box-shadow: var(--shadow); padding: 16px; margin-bottom: 14px;
}
.card h2 { margin: 0; font-size: 17px; font-weight: 700; letter-spacing: -0.01em; }
.card .sub { margin: 3px 0 0; color: var(--muted); font-size: 12.5px; }
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.reveal { opacity: 0; transform: translate3d(0, 18px, 0) scale(0.985); }
.reveal.in { opacity: 1; transform: none; transition: opacity 0.36s var(--ease-out), transform 0.6s var(--spring); }
.link-btn { color: var(--accent); font-weight: 600; font-size: 14px; display: inline-flex; align-items: center; gap: 4px; padding: 6px 0; }
.link-btn svg { width: 14px; height: 14px; }

/* ---------- KPI tiles ---------- */
.tiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-bottom: 14px; }
.tile {
  position: relative; text-align: left; min-height: 104px;
  background: var(--surface); border: 0.5px solid var(--hair); border-radius: var(--r-tile);
  box-shadow: var(--shadow); padding: 12px 13px 13px; overflow: hidden;
  display: flex; flex-direction: column;
}
.tile.wide { grid-column: span 2; }
.tile .t-label { font-size: 12px; color: var(--muted); font-weight: 600; line-height: 1.25; }
.tile .t-value { font-size: 24px; font-weight: 750; letter-spacing: -0.02em; margin-top: 6px; line-height: 1.1; white-space: nowrap; overflow: hidden; }
.tile.wide .t-value { font-size: 32px; }
.tile .t-value.bump { animation: bump 0.42s var(--spring); }
@keyframes bump { 40% { transform: scale(1.06); } }
.tile .t-note { font-size: 11.5px; color: var(--ink-2); margin-top: auto; padding-top: 6px; line-height: 1.3; }
.tile .t-go { position: absolute; top: 12px; right: 12px; color: var(--muted); width: 14px; height: 14px; opacity: 0.6; }
.meter { height: 5px; border-radius: 3px; background: var(--surface-2); overflow: hidden; margin-top: 8px; }
.meter > span { display: block; height: 100%; width: 100%; background: var(--accent); border-radius: 3px; transform-origin: left center; transform: scaleX(0); transition: transform 0.8s var(--spring); }
.tiles.mini { display: flex; overflow-x: auto; scrollbar-width: none; margin: 0 calc(-1 * var(--gutter)) 12px; padding: 2px var(--gutter) 4px; gap: 10px; }
.tiles.mini::-webkit-scrollbar { display: none; }
.tiles.mini .tile { flex: none; width: 46%; min-width: 150px; min-height: 86px; }
.tiles.mini .tile .t-value { font-size: 20px; }

/* ---------- Segmented control ---------- */
.seg {
  position: relative; display: inline-grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  background: var(--surface-2); border-radius: 11px; padding: 3px; gap: 0;
}
.seg.full { display: grid; width: 100%; }
.seg-ink { position: absolute; top: 3px; bottom: 3px; left: 3px; border-radius: 9px; background: var(--surface); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12); transition: transform 0.46s var(--spring), width 0s; pointer-events: none; }
.seg button { position: relative; z-index: 1; height: 30px; padding: 0 12px; font-size: 13px; font-weight: 600; color: var(--ink-2); border-radius: 9px; white-space: nowrap; transition: color 0.2s; }
.seg button[aria-checked="true"] { color: var(--ink); }
.seg button .cnt { color: var(--muted); font-weight: 500; margin-left: 4px; }

/* ---------- Charts ---------- */
.chart-scroll { overflow-x: auto; overflow-y: hidden; scrollbar-width: none; margin: 0 -16px; padding: 0 16px; -webkit-overflow-scrolling: touch; }
.chart-scroll::-webkit-scrollbar { display: none; }
.chart-box { position: relative; height: 220px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 12px; margin: 0 0 10px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--ink-2); }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.readout {
  margin-top: 12px; padding: 11px 12px; border-radius: 14px; background: var(--surface-2);
  display: flex; align-items: center; gap: 12px;
}
.readout .ro-main { flex: 1; min-width: 0; }
.readout .ro-title { font-weight: 700; font-size: 14px; }
.readout .ro-lines { display: flex; flex-wrap: wrap; gap: 2px 14px; margin-top: 3px; font-size: 12.5px; color: var(--ink-2); }
.readout .ro-lines i { width: 8px; height: 8px; border-radius: 2px; display: inline-block; margin-right: 5px; }
.readout.flash { animation: ro-flash 0.42s var(--spring); }
@keyframes ro-flash { from { opacity: 0.4; transform: scale(0.97); } }
.go-btn { flex: none; height: 34px; padding: 0 13px; border-radius: 17px; background: var(--accent); color: #fff; font-size: 13px; font-weight: 650; display: inline-flex; align-items: center; gap: 4px; }
.go-btn svg { width: 13px; height: 13px; }
.go-btn.ghost { background: var(--surface); color: var(--accent); border: 0.5px solid var(--hair); }

/* ---------- Bar lists ---------- */
.bars { display: flex; flex-direction: column; gap: 2px; }
.bar-row { display: block; width: 100%; text-align: left; padding: 8px 4px; border-radius: 12px; }
/* Name and value share a line; a long value (full rupees) drops to its own line instead of squeezing the name out. */
.bar-row .br-top { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: 2px 10px; font-size: 13.5px; }
.bar-row .br-name { flex: 1 1 130px; font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: flex; align-items: center; gap: 7px; }
.bar-row .br-val { margin-left: auto; white-space: nowrap; }
.bar-row .br-txt { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-row .br-rank { color: var(--muted); font-weight: 600; width: 18px; flex: none; }
.bar-row .br-val { flex: none; font-weight: 650; }
.bar-row .br-val em { font-style: normal; color: var(--muted); font-weight: 500; margin-left: 6px; font-size: 12px; }
.track { position: relative; height: 7px; border-radius: 4px; background: var(--surface-2); margin-top: 6px; overflow: hidden; }
.track.thin { height: 5px; margin-top: 4px; }
.fill { position: absolute; inset: 0; border-radius: 4px; background: var(--series-1); transform-origin: left center; transform: scaleX(0); transition: transform 0.75s var(--spring); }
.fill.c2 { background: var(--series-2); }
.bar-row .dual .track { margin-top: 4px; }
.swatch { width: 9px; height: 9px; border-radius: 3px; flex: none; }

/* ---------- Rows (lines and grantees) ---------- */
.list { display: flex; flex-direction: column; }
.list.boxed { background: var(--surface); border: 0.5px solid var(--hair); border-radius: var(--r-card); box-shadow: var(--shadow); overflow: hidden; }
.row {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  padding: 12px 14px; min-height: 60px; position: relative;
}
.row + .row::before { content: ""; position: absolute; top: 0; left: 14px; right: 0; border-top: 0.5px solid var(--hair); }
.row:active { background: var(--surface-2); }
.row .r-main { flex: 1; min-width: 0; }
.row .r-title { font-weight: 620; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .r-sub { color: var(--muted); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 1px; }
.row .r-amt { flex: 0 1 auto; max-width: 58%; min-width: 0; text-align: right; font-weight: 680; font-size: 15px; white-space: nowrap; }
.row .r-amt .r-amt-sub { display: block; font-size: 11.5px; color: var(--muted); font-weight: 500; margin-top: 1px; overflow: hidden; text-overflow: ellipsis; }
.row .r-main { flex: 1 1 40%; }
html.full-amounts .row .r-amt { font-size: 13.5px; }
html.full-amounts .readout .ro-lines { font-size: 12px; }
.row .r-amt.due { color: var(--bad); }
.row .chev { width: 8px; height: 13px; color: var(--muted); opacity: 0.55; flex: none; }
.row .r-meter { margin-top: 6px; }
.row .tag { display: inline-block; font-size: 10.5px; font-weight: 700; letter-spacing: 0.02em; text-transform: uppercase; padding: 1px 6px; border-radius: 6px; background: var(--surface-2); color: var(--ink-2); margin-right: 6px; vertical-align: 1px; }
.row .tag.fwd { background: var(--accent-soft); color: var(--accent); }
.row .tag.cur { background: color-mix(in srgb, var(--good) 16%, transparent); color: var(--good); }
.row.in { animation: row-in 0.44s var(--spring) both; animation-delay: calc(var(--i, 0) * 22ms); }
@keyframes row-in { from { opacity: 0; transform: translate3d(0, 10px, 0); } }
.list-foot { text-align: center; color: var(--muted); font-size: 12.5px; padding: 14px 0 4px; }
.sentinel { height: 1px; }
.empty { text-align: center; color: var(--muted); padding: 34px 20px; font-size: 14px; }
.empty b { display: block; color: var(--ink); font-size: 16px; margin-bottom: 4px; }

/* ---------- Search fields ---------- */
.field-search {
  display: flex; align-items: center; gap: 8px; height: 40px; padding: 0 12px; border-radius: 12px;
  background: var(--surface-2); color: var(--muted); margin-bottom: 10px;
}
.field-search svg { width: 17px; height: 17px; flex: none; }
.field-search input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; font-size: 16px; color: var(--ink); -webkit-appearance: none; appearance: none; }
.field-search input::-webkit-search-cancel-button { -webkit-appearance: none; }
.field-search .clear { width: 20px; height: 20px; border-radius: 50%; background: var(--muted); color: var(--surface); font-size: 11px; display: grid; place-items: center; opacity: 0.7; }
.sticky-tools { position: sticky; top: calc(var(--nav-h) + var(--safe-t)); z-index: 10; padding: 6px 0 2px; margin: 0 calc(-1 * var(--gutter)); padding-left: var(--gutter); padding-right: var(--gutter); background: linear-gradient(var(--page) 78%, transparent); }

/* ---------- Ask ---------- */
.ask-box {
  display: flex; align-items: center; gap: 10px; padding: 0 8px 0 14px; height: 54px; border-radius: 18px;
  background: var(--surface); border: 1px solid var(--hair); box-shadow: var(--shadow);
  transition: box-shadow 0.25s, border-color 0.25s;
}
.ask-box:focus-within { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft), var(--shadow); }
.ask-box > svg { width: 20px; height: 20px; color: var(--accent); flex: none; }
.ask-box input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; font-size: 17px; color: var(--ink); -webkit-appearance: none; appearance: none; }
.ask-box input::-webkit-search-cancel-button { -webkit-appearance: none; }
.ask-go { width: 38px; height: 38px; border-radius: 13px; background: var(--accent); color: #fff; display: grid; place-items: center; flex: none; }
.ask-go svg { width: 18px; height: 18px; }
.sec-label { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 18px 4px 8px; }
.suggest { display: flex; flex-wrap: wrap; gap: 8px; }
.suggest .chip { box-shadow: none; }
.preview {
  margin-top: 12px; padding: 14px; border-radius: 16px; background: var(--surface); border: 0.5px solid var(--hair); box-shadow: var(--shadow);
  text-align: left; width: 100%; display: block;
}
.preview .p-head { font-size: 22px; font-weight: 750; letter-spacing: -0.02em; }
.preview .p-sub { font-size: 13px; color: var(--ink-2); margin-top: 3px; }
.preview .p-run { margin-top: 10px; color: var(--accent); font-weight: 650; font-size: 13.5px; display: inline-flex; gap: 4px; align-items: center; }
.s-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.s-chip {
  display: inline-flex; align-items: center; gap: 5px; height: 28px; padding: 0 10px; border-radius: 14px;
  background: var(--surface-2); color: var(--ink-2); font-size: 12.5px; font-weight: 600;
}
.s-chip i { font-style: normal; opacity: 0.55; font-size: 10px; }
.s-chip.metric { background: var(--accent-soft); color: var(--accent); }
.s-chip.neg { background: color-mix(in srgb, var(--bad) 13%, transparent); color: var(--bad); }
.s-chip.time { background: color-mix(in srgb, var(--series-3) 15%, transparent); color: var(--good); }
.s-chip.amt { background: color-mix(in srgb, var(--series-4) 18%, transparent); color: var(--warn-ink); }
.s-chip.shape { background: color-mix(in srgb, var(--series-7) 15%, transparent); color: var(--series-7); }
.s-chip.fuzzy { border: 1px dashed currentColor; }
.s-chip.scope { background: transparent; border: 1px solid var(--hair); }
.s-note { font-size: 12px; color: var(--muted); align-self: center; }
.answer { padding: 18px 16px; }
.answer .a-big { font-size: 34px; font-weight: 780; letter-spacing: -0.025em; line-height: 1.08; word-break: break-word; }
.answer .a-big.long { font-size: 24px; }
.a-big.fig, .p-head.fig { white-space: nowrap; overflow: hidden; word-break: normal; }
.answer .a-sub { margin-top: 8px; color: var(--ink-2); font-size: 14.5px; }
.answer.empty .a-big { color: var(--muted); }
.ask-results > * { animation: row-in 0.48s var(--spring) both; }
.ask-results > *:nth-child(2) { animation-delay: 40ms; }
.ask-results > *:nth-child(3) { animation-delay: 80ms; }
.ask-results > *:nth-child(4) { animation-delay: 120ms; }
.ask-results > *:nth-child(n+5) { animation-delay: 160ms; }
.complete { display: flex; flex-direction: column; margin-top: 8px; }
.complete .row { min-height: 50px; padding: 9px 12px; }

/* ---------- Settings ---------- */
.group-label { font-size: 12.5px; font-weight: 650; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); margin: 22px 6px 8px; }
.group { background: var(--surface); border: 0.5px solid var(--hair); border-radius: 16px; box-shadow: var(--shadow); overflow: hidden; }
.cell { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 52px; padding: 10px 14px; text-align: left; position: relative; }
.cell + .cell::before { content: ""; position: absolute; top: 0; left: 54px; right: 0; border-top: 0.5px solid var(--hair); }
.cell.plain + .cell::before, .cell + .cell.plain::before { left: 14px; }
.cell:active:not(.static) { background: var(--surface-2); }
.cell .c-ico { width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center; color: #fff; flex: none; }
.cell .c-ico svg { width: 17px; height: 17px; }
.cell .c-main { flex: 1; min-width: 0; }
.cell .c-title { font-weight: 560; font-size: 15.5px; }
.cell .c-sub { font-size: 12.5px; color: var(--muted); margin-top: 1px; overflow: hidden; text-overflow: ellipsis; }
.cell .c-val { color: var(--muted); font-size: 14.5px; flex: none; }
.cell .chev { width: 8px; height: 13px; color: var(--muted); opacity: 0.55; flex: none; }
.cell.danger .c-title { color: var(--bad); }

/* Switch */
.switch { position: relative; width: 51px; height: 31px; flex: none; }
.switch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; z-index: 1; }
.switch .sw-track { position: absolute; inset: 0; border-radius: 16px; background: var(--surface-2); box-shadow: inset 0 0 0 1px var(--hair); transition: background-color 0.25s; }
.switch .sw-thumb { position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%; background: #fff; box-shadow: 0 2px 6px rgba(0, 0, 0, 0.22); transition: transform 0.42s var(--spring); }
.switch input:checked ~ .sw-track { background: var(--good); }
.switch input:checked ~ .sw-thumb { transform: translateX(20px); }
.switch input:active ~ .sw-thumb { transform: scaleX(1.15); transform-origin: left; }
.switch input:checked:active ~ .sw-thumb { transform: translateX(16px) scaleX(1.15); }

/* Theme picker */
.themes { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; padding: 14px; }
.theme { text-align: center; font-size: 12.5px; font-weight: 600; color: var(--ink-2); }
.theme .tp {
  height: 74px; border-radius: 14px; background: var(--page); border: 2px solid transparent;
  box-shadow: inset 0 0 0 0.5px var(--border); padding: 9px; margin-bottom: 6px;
  display: flex; flex-direction: column; gap: 5px; transition: border-color 0.2s, transform 0.4s var(--spring);
}
.theme .tp i { display: block; height: 9px; border-radius: 4px; background: var(--surface); box-shadow: inset 0 0 0 0.5px var(--border); }
.theme .tp i.a { width: 60%; background: var(--series-1); box-shadow: none; }
.theme .tp i.b { width: 38%; background: var(--series-2); box-shadow: none; }
.theme .tp.sys { background: linear-gradient(135deg, #f6f6f3 50%, #0d0d0d 50%); }
.theme[aria-checked="true"] .tp { border-color: var(--accent); transform: scale(1.03); }
.theme[aria-checked="true"] { color: var(--ink); }

/* ---------- Sheets ---------- */
.sheet-layer { position: fixed; inset: 0; z-index: 60; }
.scrim { position: absolute; inset: 0; background: var(--scrim); -webkit-backdrop-filter: blur(5px); backdrop-filter: blur(5px); opacity: 0; transition: opacity 0.32s var(--ease-out); }
.sheet-layer.open .scrim { opacity: 1; }
.sheet-layer.closing .scrim { opacity: 0; transition-duration: 0.22s; }
.sheet {
  position: absolute; left: 0; right: 0; margin: 0 auto; max-width: 680px;
  bottom: -60px; padding-bottom: calc(60px + var(--safe-b));
  max-height: calc(100% - var(--safe-t) - 12px + 60px);
  background: var(--surface); border-radius: 24px 24px 0 0;
  box-shadow: 0 -10px 40px -12px rgba(0, 0, 0, 0.28);
  display: flex; flex-direction: column;
  transform: translate3d(0, 100%, 0);
  transition: transform 0.5s var(--spring), border-radius 0.3s;
  will-change: transform;
}
.sheet.tall { height: calc(100% - var(--safe-t) - 12px + 60px); }
.sheet-layer.open .sheet { transform: translate3d(0, 0, 0); }
.sheet-layer.closing .sheet { transform: translate3d(0, 100%, 0); transition: transform 0.26s var(--ease-in); }
.sheet-layer.dragging .sheet { transition: none; }
.sheet-layer.pushed .sheet { transform: translate3d(0, -8px, 0) scale(0.94); border-radius: 24px; }
.sheet-layer.pushed .scrim { opacity: 0; }
.grab { flex: none; padding: 8px 0 2px; touch-action: none; cursor: grab; }
.grab::before { content: ""; display: block; width: 38px; height: 5px; border-radius: 3px; background: var(--axis); margin: 0 auto; }
.sh-head { flex: none; padding: 6px 18px 12px; display: flex; align-items: flex-start; gap: 10px; touch-action: none; }
.sh-head .sh-titles { flex: 1; min-width: 0; }
.sh-eyebrow { font-size: 11.5px; font-weight: 700; color: var(--accent); text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 2px; }
.sh-title { font-size: 21px; font-weight: 750; letter-spacing: -0.02em; line-height: 1.2; word-break: break-word; }
.sh-sub { font-size: 13px; color: var(--muted); margin-top: 3px; }
.sh-close { width: 32px; height: 32px; border-radius: 50%; background: var(--surface-2); color: var(--ink-2); display: grid; place-items: center; flex: none; }
.sh-close svg { width: 13px; height: 13px; }
.sh-body { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 0 18px 18px; -webkit-overflow-scrolling: touch; }
.sh-foot { flex: none; display: flex; gap: 10px; padding: 12px 18px 4px; border-top: 0.5px solid var(--hair); }
.sh-actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 14px; }
.btn {
  height: 44px; padding: 0 18px; border-radius: 13px; font-weight: 650; font-size: 15px;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--surface-2); color: var(--ink);
}
.btn.primary { background: var(--accent); color: #fff; flex: 1; }
.btn.grow { flex: 1; }
.btn.sm { height: 34px; padding: 0 13px; font-size: 13.5px; border-radius: 11px; }
.btn.danger { color: var(--bad); }
.btn svg { width: 16px; height: 16px; }
.btn.share { background: var(--accent); color: #fff; }
.btn.xl svg, .chip.xl svg { width: 17px; height: 17px; }
/* Building a file: dim and show a spinner ring instead of the icon. */
.busy { pointer-events: none; opacity: 0.6; position: relative; }
.busy > svg:first-child { animation: spin 0.8s linear infinite; }
.icon-btn.busy svg { animation: spin 0.8s linear infinite; }

.dl { display: grid; grid-template-columns: 38% minmax(0, 1fr); gap: 0; background: var(--surface-2); border-radius: 14px; overflow: hidden; }
.dl > div { display: contents; }
.dl dt, .dl dd { margin: 0; padding: 10px 12px; font-size: 13.5px; border-top: 0.5px solid var(--hair); }
.dl > div:first-child dt, .dl > div:first-child dd { border-top: 0; }
.dl dt { color: var(--muted); }
.dl dd { font-weight: 560; word-break: break-word; }
.dl dd.amt { font-weight: 720; }

.entry-wrap { position: relative; }
.entry-wrap.slide-l { animation: slide-l 0.4s var(--spring); }
.entry-wrap.slide-r { animation: slide-r 0.4s var(--spring); }
@keyframes slide-l { from { opacity: 0; transform: translate3d(36px, 0, 0); } }
@keyframes slide-r { from { opacity: 0; transform: translate3d(-36px, 0, 0); } }
.pager { display: flex; align-items: center; gap: 6px; }
.pager .pg { width: 32px; height: 32px; border-radius: 50%; background: var(--surface-2); display: grid; place-items: center; }
.pager .pg svg { width: 12px; height: 12px; }
.pager .pg:disabled { opacity: 0.35; }
.pager span { font-size: 12.5px; color: var(--muted); min-width: 54px; text-align: center; }

/* Multi-select / option lists in sheets */
.opt { display: flex; align-items: center; gap: 12px; width: 100%; padding: 12px 4px; text-align: left; position: relative; min-height: 50px; }
.opt + .opt::before { content: ""; position: absolute; top: 0; left: 40px; right: 0; border-top: 0.5px solid var(--hair); }
.opt .o-main { flex: 1; min-width: 0; font-size: 15px; overflow: hidden; text-overflow: ellipsis; }
.opt .o-count { color: var(--muted); font-size: 13px; flex: none; }
.opt .o-count.zero { opacity: 0.5; }
.check {
  width: 24px; height: 24px; border-radius: 50%; border: 1.6px solid var(--axis); flex: none; display: grid; place-items: center;
  transition: background-color 0.18s, border-color 0.18s;
}
.check svg { width: 13px; height: 13px; color: #fff; transform: scale(0); transition: transform 0.38s var(--spring); }
.opt[aria-checked="true"] .check { background: var(--accent); border-color: var(--accent); }
.opt[aria-checked="true"] .check svg { transform: scale(1); }
.check.excl { border-radius: 7px; }
.opt[aria-checked="true"] .check.excl { background: var(--bad); border-color: var(--bad); }
.radio-tick { width: 18px; height: 18px; color: var(--accent); flex: none; transform: scale(0); transition: transform 0.38s var(--spring); }
.opt[aria-checked="true"] .radio-tick { transform: scale(1); }

.fy-strip { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; margin: 0 -18px; padding: 2px 18px 10px; scroll-snap-type: x proximity; }
.fy-strip::-webkit-scrollbar { display: none; }
.fy-strip .chip { scroll-snap-align: center; box-shadow: none; }
.fy-label { font-size: 13px; font-weight: 650; color: var(--ink-2); margin: 6px 2px 8px; display: flex; justify-content: space-between; }
.fy-label b { color: var(--accent); }
.presets { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.presets .chip { box-shadow: none; height: 30px; font-size: 12.5px; }

.amt-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.inp { display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; color: var(--muted); font-weight: 600; }
.inp input { height: 46px; border-radius: 12px; border: 1px solid var(--hair); background: var(--surface-2); padding: 0 12px; font-size: 16px; color: var(--ink); outline: 0; width: 100%; min-width: 0; }
.inp input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

/* Data checks */
.dq-row .r-title { white-space: normal; }
.flag { width: 9px; height: 9px; border-radius: 50%; flex: none; background: var(--series-4); }
.flag.ok { background: var(--good); }

.method { font-size: 13.5px; color: var(--ink-2); padding-left: 18px; margin: 0; }
.method li { margin: 6px 0; }
.method code { font-size: 12px; background: var(--surface-2); padding: 1px 5px; border-radius: 5px; }

/* ---------- Pull to refresh ---------- */
.ptr { position: absolute; left: 0; right: 0; top: calc(var(--safe-t) + var(--nav-h) - 6px); height: 0; display: flex; justify-content: center; pointer-events: none; z-index: 5; }
.ptr-ball { width: 34px; height: 34px; border-radius: 50%; background: var(--surface); box-shadow: var(--shadow-hover); display: grid; place-items: center; color: var(--accent); opacity: 0; transform: translate3d(0, -30px, 0) scale(0.6); }
.ptr-ball svg { width: 18px; height: 18px; }
.ptr.spin .ptr-ball svg { animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.ptr-wrap { will-change: transform; }
.ptr-wrap.settle, .ptr-ball.settle { transition: transform 0.5s var(--spring), opacity 0.3s; }

/* ---------- Banner, toasts, splash ---------- */
.banner { background: var(--warn-bg); color: var(--warn-ink); border-radius: 14px; padding: 11px 13px; font-size: 13px; margin-bottom: 12px; }
.toasts { position: fixed; left: 0; right: 0; bottom: calc(var(--tabbar-h) + var(--safe-b) + 12px); z-index: 80; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; padding: 0 16px; }
.toast {
  pointer-events: auto; max-width: 520px; width: max-content; display: flex; align-items: center; gap: 12px;
  padding: 11px 12px 11px 16px; border-radius: 16px; background: var(--ink); color: var(--page);
  font-size: 14px; font-weight: 550; box-shadow: 0 12px 30px -10px rgba(0, 0, 0, 0.45);
  animation: toast-in 0.5s var(--spring) both;
}
.toast button { color: var(--accent); font-weight: 700; padding: 4px 8px; filter: brightness(1.35); }
.toast.out { animation: toast-out 0.22s var(--ease-in) forwards; }
@keyframes toast-in { from { opacity: 0; transform: translate3d(0, 24px, 0) scale(0.9); } }
@keyframes toast-out { to { opacity: 0; transform: translate3d(0, 12px, 0) scale(0.95); } }

.splash { position: fixed; inset: 0; z-index: 100; background: var(--page); display: grid; place-items: center; transition: opacity 0.35s var(--ease-out); }
.splash.gone { opacity: 0; pointer-events: none; }
.splash-in { display: flex; flex-direction: column; align-items: center; gap: 14px; color: var(--muted); font-size: 13px; }
.splash-logo { width: 74px; height: 74px; border-radius: 22px; box-shadow: 0 18px 40px -14px rgba(42, 80, 214, 0.55); animation: logo-breathe 1.6s var(--spring-soft) infinite alternate; }
@keyframes logo-breathe { to { transform: scale(1.06); } }
.splash .lg-bar { transform-box: fill-box; transform-origin: bottom; animation: bar-grow 0.9s var(--spring) both infinite alternate; }
.splash .lg-bar:nth-child(2) { animation-delay: 0.12s; }
.splash .lg-bar:nth-child(3) { animation-delay: 0.24s; }
@keyframes bar-grow { from { transform: scaleY(0.35); } }

.cfy-pill { display: inline-flex; align-items: center; gap: 5px; height: 22px; padding: 0 8px; border-radius: 11px; background: var(--accent-soft); color: var(--accent); font-weight: 700; font-size: 11.5px; }
.src-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--good); display: inline-block; }
.src-dot.local { background: var(--series-4); }

/* Wider screens (tablets, desktop preview): a centred column, sheets as cards. */
@media (min-width: 700px) {
  .tiles { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .tile.wide { grid-column: span 2; }
  .sheet { bottom: auto; top: 50%; padding-bottom: 0; max-height: min(84vh, 760px); border-radius: 24px; transform: translate3d(0, 100vh, 0); }
  .sheet-layer.open .sheet { transform: translate3d(0, -50%, 0); }
  .sheet-layer.closing .sheet { transform: translate3d(0, 100vh, 0); }
  .sheet-layer.pushed .sheet { transform: translate3d(0, -52%, 0) scale(0.94); }
  .sheet.tall { height: min(84vh, 760px); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; animation-delay: 0s !important; transition-duration: 0.001ms !important; }
  .reveal { opacity: 1; transform: none; }
}
