/* Gruzzolo — base design system: tokens, layout (phone first, desktop from 900px) and shared components.
   View-specific styles live in portfolio.css, report.css, report2.css and extra.css. */

/* ---------- Fonts (self-hosted variable fonts, SIL OFL 1.1: see fonts/OFL.txt) ----------
   Same files and unicode ranges as Google Fonts, served by the app itself: no third-party request,
   and the service worker keeps them for offline use. One file covers every weight. */
@font-face {
  font-family: "Manrope";
  font-style: normal;
  font-weight: 200 800;
  font-display: swap;
  src: url("../fonts/manrope-latin-ext.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "Manrope";
  font-style: normal;
  font-weight: 200 800;
  font-display: swap;
  src: url("../fonts/manrope-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Bricolage Grotesque";
  font-style: normal;
  font-weight: 200 800;
  font-display: swap;
  src: url("../fonts/bricolage-grotesque-latin-ext.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "Bricolage Grotesque";
  font-style: normal;
  font-weight: 200 800;
  font-display: swap;
  src: url("../fonts/bricolage-grotesque-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

/* ---------- Design tokens ---------- */
:root {
  --bg: #eef1f5;
  --surface: #ffffff;
  --surface-2: #e5e9f0;
  --line: #d8dee7;
  --grid: #e6e9ee;
  --ink: #0d1117;
  --ink-2: #465061;
  --muted: #687180;
  --accent: #f0b03a;
  --accent-ink: #1c1405;
  --accent-line: #b87a0e;
  --accent-soft: rgba(240, 176, 58, .18);
  --up: #0b8a4f;
  --up-soft: rgba(11, 138, 79, .12);
  --down: #c93636;
  --down-soft: rgba(201, 54, 54, .11);
  --warn: #9a6200;
  --warn-soft: rgba(240, 176, 58, .2);
  --c1: #2a78d6; --c2: #eb6834; --c3: #1baf7a; --c4: #eda100;
  --c5: #e87ba4; --c6: #008300; --c7: #4a3aa7; --c8: #e34948; --c-other: #9aa1ad;
  --chip-on: #ffffff;
  --chip-on-line: #d8dee7;
  --scrim: rgba(8, 12, 20, .42);
  --shadow: 0 18px 50px rgba(13, 20, 33, .18);
  --shadow-sm: 0 1px 3px rgba(13, 20, 33, .1);
  --statusbar: #0d1117;
  --font-ui: "Manrope", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-display: "Bricolage Grotesque", "Manrope", system-ui, -apple-system, sans-serif;
  --radius: 18px;
  --radius-sm: 12px;
  --sidebar-w: 248px;
  --tabbar-h: 62px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0c0e12; --surface: #15181e; --surface-2: #1f242c; --line: #272d37; --grid: #1d2128;
    --ink: #f2f4f7; --ink-2: #b4bcc8; --muted: #828b99;
    --accent: #f2b63d; --accent-ink: #1c1405; --accent-line: #f2b63d; --accent-soft: rgba(242, 182, 61, .15);
    --up: #3ccf86; --up-soft: rgba(60, 207, 134, .13); --down: #ff6b6b; --down-soft: rgba(255, 107, 107, .13);
    --warn: #f2b63d; --warn-soft: rgba(242, 182, 61, .14);
    --c1: #3987e5; --c2: #d95926; --c3: #199e70; --c4: #c98500;
    --c5: #d55181; --c6: #008300; --c7: #9085e9; --c8: #e66767; --c-other: #5d6573;
    --chip-on: #262c36; --chip-on-line: #323a46;
    --scrim: rgba(0, 0, 0, .62); --shadow: 0 18px 50px rgba(0, 0, 0, .55); --shadow-sm: 0 1px 3px rgba(0, 0, 0, .4);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0c0e12; --surface: #15181e; --surface-2: #1f242c; --line: #272d37; --grid: #1d2128;
  --ink: #f2f4f7; --ink-2: #b4bcc8; --muted: #828b99;
  --accent: #f2b63d; --accent-ink: #1c1405; --accent-line: #f2b63d; --accent-soft: rgba(242, 182, 61, .15);
  --up: #3ccf86; --up-soft: rgba(60, 207, 134, .13); --down: #ff6b6b; --down-soft: rgba(255, 107, 107, .13);
  --warn: #f2b63d; --warn-soft: rgba(242, 182, 61, .14);
  --c1: #3987e5; --c2: #d95926; --c3: #199e70; --c4: #c98500;
  --c5: #d55181; --c6: #008300; --c7: #9085e9; --c8: #e66767; --c-other: #5d6573;
  --chip-on: #262c36; --chip-on-line: #323a46;
  --scrim: rgba(0, 0, 0, .62); --shadow: 0 18px 50px rgba(0, 0, 0, .55); --shadow-sm: 0 1px 3px rgba(0, 0, 0, .4);
  color-scheme: dark;
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  background: var(--bg);
  scrollbar-color: var(--line) transparent;
  scrollbar-gutter: stable; /* no layout jump when a sheet locks the page */
}
/* Only the root: a body with overflow hidden would become the sticky container and hide the header */
html.locked { overflow: hidden; }
body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-tap-highlight-color: transparent;
}
h1, h2, h3, h4 { line-height: 1.2; }
p { margin: 0 0 .6em; }
p:last-child { margin-bottom: 0; }
a { color: var(--accent-line); text-underline-offset: 2px; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; -webkit-touch-callout: none; }
button:disabled { cursor: default; }
svg { display: block; }
img { display: block; max-width: 100%; }
::selection { background: var(--accent-soft); }
:focus-visible { outline: 2px solid var(--accent-line); outline-offset: 2px; }
:focus:not(:focus-visible) { outline: none; }
.ico { width: 22px; height: 22px; flex-shrink: 0; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Utilities ---------- */
.muted { color: var(--muted); }
.up { color: var(--up); }
.down { color: var(--down); }
.flat { color: var(--muted); }
.num { font-variant-numeric: tabular-nums; }
.sr-only {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; border: 0;
}
.stack { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.cluster { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; min-width: 0; }
.tri { font-size: .72em; }
.hint { font-size: 12.5px; color: var(--muted); }

/* ---------- App frame (phone) ---------- */
.app { min-height: 100vh; min-height: 100dvh; }
.sidebar { display: none; }
.shell { min-width: 0; overflow-x: clip; }

.top {
  position: sticky; top: 0; z-index: 30;
  transform: translateY(var(--vv-dy, 0px));
  padding-top: env(safe-area-inset-top, 0px);
  background: var(--bg);
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  -webkit-backdrop-filter: saturate(1.6) blur(16px);
  backdrop-filter: saturate(1.6) blur(16px);
  border-bottom: 1px solid transparent;
  transition: border-color .2s;
}
.top.scrolled { border-bottom-color: var(--line); }
/* Installed on iPhone in light mode the status bar text is white: give it a dark band */
.top::before {
  content: ""; position: absolute; left: 0; right: 0; top: 0;
  height: env(safe-area-inset-top, 0px); pointer-events: none;
}
@media (display-mode: standalone) {
  @media (prefers-color-scheme: light) {
    :root:not([data-theme="dark"]) .top::before { background: var(--statusbar); }
  }
  :root[data-theme="light"] .top::before { background: var(--statusbar); }
}
.top-inner {
  display: flex; align-items: center; gap: 4px; min-height: 56px;
  padding: 4px max(10px, env(safe-area-inset-right, 0px)) 4px max(16px, env(safe-area-inset-left, 0px));
}
.brand { display: flex; align-items: center; gap: 8px; min-width: 0; flex-shrink: 0; }
.brand-mark { width: 28px; height: 28px; flex-shrink: 0; }
.brand-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.1; }
.brand-name { font-family: var(--font-display); font-weight: 700; font-size: 19px; letter-spacing: -.01em; }
.brand-status { display: flex; align-items: center; gap: 5px; font-size: 11px; font-weight: 600; color: var(--muted); white-space: nowrap; min-height: 13px; }
.brand-status:empty { display: none; }
.st-alle { display: none; }
@media (min-width: 400px) { .st-alle { display: inline; } }
.top-crumb { display: none; }
.top-spacer { flex: 1; min-width: 4px; }
.top-actions { display: flex; align-items: center; gap: 0; min-width: 0; }
.top-actions .icon-btn { width: 40px; border-radius: 12px; }

.pill-btn {
  position: relative; display: inline-flex; align-items: center; gap: 4px; min-width: 0; min-height: 38px;
  border: 1px solid var(--line); background: var(--surface); border-radius: 999px;
  padding: 0 8px 0 12px; font-size: 13px; font-weight: 700; color: var(--ink);
}
.pill-btn::after { content: ""; position: absolute; inset: -4px -2px; }
.pill-btn span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 170px; }
.pill-btn .ico { width: 16px; height: 16px; color: var(--muted); }
.icon-btn {
  display: inline-grid; place-items: center; flex-shrink: 0;
  width: 44px; height: 44px; border-radius: 50%; border: 0; padding: 0;
  background: transparent; color: var(--ink-2);
}
.icon-btn:active { background: var(--surface-2); }
.icon-btn.spinning .ico { animation: spin .9s linear infinite; }
.icon-btn[aria-pressed="true"] { color: var(--accent-line); }

.dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--c-other); flex-shrink: 0; }
.dot.online { background: var(--up); box-shadow: 0 0 0 3px var(--up-soft); }
.dot.busy { background: var(--accent); animation: pulse 1.2s ease-in-out infinite; }
.dot.offline { background: var(--c-other); }
.dot.demo { background: var(--accent-line); }

#view {
  display: block; outline: none; min-height: 60vh;
  padding: 6px max(16px, env(safe-area-inset-right, 0px)) calc(var(--tabbar-h) + 36px + env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px));
}

/* Bottom tab bar with the raised gold "+" */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 35;
  transform: translateY(var(--vv-dy, 0px)); /* iPhone: follow a shifted visible area (main.js) */
  background: var(--surface);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  -webkit-backdrop-filter: saturate(1.6) blur(16px);
  backdrop-filter: saturate(1.6) blur(16px);
  border-top: 1px solid var(--line);
  padding: 0 max(6px, env(safe-area-inset-right, 0px)) env(safe-area-inset-bottom, 0px) max(6px, env(safe-area-inset-left, 0px));
}
.tabbar-inner { max-width: 560px; margin: 0 auto; height: var(--tabbar-h); display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); align-items: center; }
.tab {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  min-height: 52px; padding: 4px 0; border: 0; background: none; border-radius: 12px;
  font-size: 11px; font-weight: 700; color: var(--muted); letter-spacing: .01em;
}
.tab .ico { width: 23px; height: 23px; }
.tab[aria-current="page"] { color: var(--ink); }
.tab[aria-current="page"] .ico { color: var(--accent-line); stroke-width: 2.3; }
.fab {
  justify-self: center; display: grid; place-items: center;
  width: 58px; height: 58px; margin-top: -26px; border-radius: 50%;
  border: 4px solid var(--bg); background: var(--accent); color: var(--accent-ink);
  box-shadow: 0 8px 20px rgba(184, 122, 14, .32);
  transition: transform .15s;
}
.fab .ico { width: 26px; height: 26px; stroke-width: 2.4; }
.fab:active { transform: scale(.94); }

/* ---------- Boot and fallbacks ---------- */
.boot { display: flex; flex-direction: column; gap: 12px; padding-top: 10px; }
.boot-text { margin: 0 0 4px; color: var(--muted); font-weight: 600; font-size: 14px; }
.skeleton {
  background: linear-gradient(90deg, var(--surface-2) 0%, var(--surface) 50%, var(--surface-2) 100%);
  background-size: 200% 100%;
  animation: shimmer 1.4s linear infinite;
  border-radius: 10px;
}
.skel-line { height: 14px; }
.skel-title { height: 42px; width: 62%; }
.skel-block { height: 190px; border-radius: var(--radius); }
.boot-error, .error-card {
  border: 1px solid var(--down); background: var(--down-soft); border-radius: var(--radius);
  padding: 16px; display: flex; flex-direction: column; align-items: flex-start; gap: 8px; margin-top: 12px;
}
.boot-error p, .error-card p { margin: 0; color: var(--ink-2); font-size: 14px; overflow-wrap: anywhere; }
.error-card code { font-size: 12.5px; color: var(--muted); overflow-wrap: anywhere; }
.noscript { padding: 24px 0; font-weight: 700; }
.loading { padding: 48px 0; text-align: center; color: var(--muted); font-weight: 600; }

/* ---------- Page structure ---------- */
.page { display: flex; flex-direction: column; gap: 20px; min-width: 0; }
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 8px 16px; }
.page-title {
  font-family: var(--font-display); font-size: 28px; font-weight: 700; line-height: 1.1;
  letter-spacing: -.02em; margin: 2px 0 0; text-wrap: balance;
}
.eyebrow { margin: 0; font-size: 12px; font-weight: 800; letter-spacing: .07em; text-transform: uppercase; color: var(--muted); }
.section { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.sec-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.sec-head h2 { font-size: 17px; font-weight: 800; margin: 0; letter-spacing: -.01em; }
.group-label { font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 18px 4px 8px; }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; min-width: 0; }

/* ---------- Cards ---------- */
/* border 1px + padding 15px = 16px per side: a full-width card's chart width is contentWidth() - 32 */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 15px; min-width: 0; }
.card-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px 12px; margin-bottom: 12px; }
.card-title { margin: 0; font-size: 15.5px; font-weight: 800; letter-spacing: -.01em; }

/* KPI tiles */
.kpi-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.kpi {
  position: relative; display: flex; flex-direction: column; gap: 4px; min-width: 0;
  background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 12px 14px;
}
.kpi.wide { grid-column: span 2; }
.kpi > .badge, .kpi > .pill { align-self: flex-start; }
.kpi.hero {
  background: linear-gradient(160deg, var(--accent-soft), transparent 70%), var(--surface);
  border-color: color-mix(in srgb, var(--accent) 40%, var(--line));
}
.kpi-label { font-size: 11.5px; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.kpi-value { font-size: 20px; font-weight: 800; line-height: 1.2; letter-spacing: -.01em; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.kpi.hero .kpi-value { font-family: var(--font-display); font-size: 28px; font-weight: 700; letter-spacing: -.02em; }
.kpi-sub { font-size: 12.5px; color: var(--muted); }

.badge {
  display: inline-flex; align-items: center; gap: 3px; white-space: nowrap;
  font-size: 11px; font-weight: 800; letter-spacing: .04em; text-transform: uppercase;
  border-radius: 999px; padding: 2px 8px;
}
.badge.up { background: var(--up-soft); color: var(--up); }
.badge.down { background: var(--down-soft); color: var(--down); }
.badge.flat { background: var(--surface-2); color: var(--muted); }

.info-btn {
  position: relative; display: inline-grid; place-items: center; flex-shrink: 0;
  width: 24px; height: 24px; padding: 0; border-radius: 50%;
  border: 1px solid var(--line); background: var(--surface); color: var(--muted);
  font-family: var(--font-display); font-size: 13px; font-weight: 700; line-height: 1;
}
.info-btn::after { content: ""; position: absolute; inset: -10px; }
.info-btn:active { background: var(--surface-2); color: var(--ink); }

/* Chart cards: 1 column on phones, 2 on desktop (gap 16px matches the width formula) */
.chart-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; }
.chart-grid > .full { grid-column: 1 / -1; }
.chart-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 15px; min-width: 0; }

/* Tables (scroll sideways on phones) */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; max-width: 100%; overscroll-behavior-x: contain; }
.table { width: 100%; border-collapse: collapse; font-size: 13.5px; font-variant-numeric: tabular-nums; }
.table th {
  text-align: left; white-space: nowrap; padding: 8px 10px;
  font-size: 11px; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; color: var(--muted);
  border-bottom: 1px solid var(--line);
}
.table td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table th:first-child, .table td:first-child { padding-left: 0; }
.table th:last-child, .table td:last-child { padding-right: 0; }
.table .num, .table .right, .table [data-align="right"] { text-align: right; white-space: nowrap; }
.table tfoot td { font-weight: 800; border-top: 1px solid var(--line); }

/* ---------- Controls ---------- */
.chips { display: flex; gap: 4px; max-width: 100%; overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch; padding: 1px; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; flex-shrink: 0; white-space: nowrap;
  min-height: 36px; padding: 0 13px; border-radius: 999px;
  border: 1px solid transparent; background: transparent; color: var(--muted);
  font-size: 13px; font-weight: 700;
}
.chip[aria-pressed="true"] { background: var(--chip-on); border-color: var(--chip-on-line); color: var(--ink); box-shadow: var(--shadow-sm); }
.chip .ico { width: 16px; height: 16px; }

.seg { display: inline-flex; gap: 2px; padding: 3px; max-width: 100%; overflow-x: auto; scrollbar-width: none; background: var(--surface-2); border-radius: 12px; }
.seg::-webkit-scrollbar { display: none; }
.seg button {
  min-height: 38px; padding: 0 13px; border: 0; border-radius: 9px; background: transparent;
  font-size: 13px; font-weight: 700; color: var(--muted); white-space: nowrap;
}
.seg button[aria-pressed="true"], .seg button[aria-selected="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-sm); }
.seg.full { display: flex; width: 100%; }
.seg.full button, .seg.full label { flex: 1 1 0; }
.seg label { position: relative; display: flex; flex: 1 1 auto; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg-lbl {
  flex: 1; display: flex; align-items: center; justify-content: center; min-height: 38px; padding: 0 12px;
  border-radius: 9px; font-size: 13.5px; font-weight: 700; color: var(--muted); cursor: pointer; white-space: nowrap;
}
.seg input:checked + .seg-lbl { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-sm); }
.seg input:focus-visible + .seg-lbl { outline: 2px solid var(--accent-line); outline-offset: 1px; }

/* On/off switch: <button class="switch" role="switch" aria-checked="true|false">Label</button> */
.switch {
  position: relative; display: inline-flex; align-items: center; min-height: 44px; padding: 0 54px 0 0;
  border: 0; background: none; font-size: 14px; font-weight: 700; color: var(--ink-2); text-align: left;
}
.switch::before {
  content: ""; position: absolute; right: 0; top: 50%; width: 44px; height: 26px; margin-top: -13px;
  border-radius: 13px; background: var(--surface-2); border: 1px solid var(--line);
  transition: background-color .18s, border-color .18s;
}
.switch::after {
  content: ""; position: absolute; right: 21px; top: 50%; width: 20px; height: 20px; margin-top: -10px;
  border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .3);
  transition: transform .18s;
}
.switch[aria-checked="true"]::before { background: var(--accent); border-color: var(--accent); }
.switch[aria-checked="true"]::after { transform: translateX(18px); }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 16px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  font-size: 14.5px; font-weight: 800; line-height: 1.2; text-decoration: none; text-align: center;
  transition: transform .12s, background-color .15s, opacity .15s;
}
.btn:active:not(:disabled) { transform: scale(.98); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .5; }
.btn .ico { width: 18px; height: 18px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--down); }
.btn.danger.solid, .btn.danger.primary { background: var(--down); border-color: var(--down); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.sm { min-height: 36px; padding: 0 12px; font-size: 13px; border-radius: 10px; }
.btn.block { display: flex; width: 100%; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }
.btn-row > .btn { flex: 1 1 0; }
.link-btn {
  display: inline-flex; align-items: center; gap: 4px; min-height: 36px; padding: 0 2px;
  border: 0; background: none; color: var(--accent-line); font-size: 13.5px; font-weight: 800;
}
.link-btn .ico { width: 16px; height: 16px; }

/* ---------- Lists and rows ---------- */
.list { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.row {
  display: flex; align-items: center; gap: 12px; width: 100%; min-height: 56px;
  padding: 11px 14px; border: 0; border-top: 1px solid var(--line);
  background: transparent; color: inherit; text-align: left; text-decoration: none; font: inherit;
}
.row:first-child { border-top: 0; }
button.row:active, a.row:active { background: var(--surface-2); }
.row[aria-pressed="true"], .row[aria-current="true"] { background: var(--accent-soft); }
.row-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.row-title { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-sub { font-size: 12.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-variant-numeric: tabular-nums; }
.row-end { display: flex; flex-direction: column; align-items: flex-end; gap: 3px; flex-shrink: 0; text-align: right; }
.row-value { font-weight: 800; font-variant-numeric: tabular-nums; white-space: nowrap; }
.row .chev { width: 18px; height: 18px; color: var(--muted); }

.avatar {
  display: grid; place-items: center; flex-shrink: 0;
  width: 40px; height: 40px; border-radius: 50%;
  color: #fff; font-weight: 800; font-size: 12.5px; letter-spacing: .02em; line-height: 1;
  background: var(--c-other);
}
.avatar.sm { width: 34px; height: 34px; font-size: 11px; }
.avatar.l4 { font-size: 10.5px; letter-spacing: 0; }
.avatar.sm.l4 { font-size: 9px; }
.avatar.lg { width: 52px; height: 52px; font-size: 15px; }
.tx-ico { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; flex-shrink: 0; background: var(--surface-2); color: var(--ink-2); }
.tx-ico .ico { width: 19px; height: 19px; }
.tx-ico.buy { background: var(--accent-soft); color: var(--accent-line); }
.tx-ico.sell { background: var(--surface-2); color: var(--ink); }
.tx-ico.div, .tx-ico.interest, .tx-ico.deposit { background: var(--up-soft); color: var(--up); }
.tx-ico.fee, .tx-ico.tax, .tx-ico.withdraw { background: var(--down-soft); color: var(--down); }

/* Change indicators */
.pill {
  display: inline-flex; align-items: center; gap: 3px; white-space: nowrap;
  font-size: 12.5px; font-weight: 800; font-variant-numeric: tabular-nums;
  border-radius: 7px; padding: 2px 7px;
}
.pill.up { background: var(--up-soft); color: var(--up); }
.pill.down { background: var(--down-soft); color: var(--down); }
.pill.flat { background: var(--surface-2); color: var(--muted); }
.delta {
  display: inline-flex; align-items: center; gap: 4px; white-space: nowrap;
  font-weight: 800; font-variant-numeric: tabular-nums; border-radius: 8px; padding: 3px 8px;
}
.delta.up { background: var(--up-soft); color: var(--up); }
.delta.down { background: var(--down-soft); color: var(--down); }
.delta.flat { background: var(--surface-2); color: var(--muted); }
.tag {
  display: inline-flex; align-items: center; white-space: nowrap;
  font-size: 11.5px; font-weight: 800; color: var(--ink-2);
  background: var(--surface-2); border-radius: 6px; padding: 2px 7px;
}
.bar-track { height: 4px; border-radius: 2px; background: var(--surface-2); overflow: hidden; }
.bar-track i { display: block; height: 100%; border-radius: 2px; background: var(--accent); }

/* Detail blocks (asset / quote sheets) */
.detail-head { display: flex; align-items: center; gap: 12px; margin: 4px 0 14px; }
.detail-head h3 { margin: 0; font-family: var(--font-display); font-size: 22px; line-height: 1.15; letter-spacing: -.015em; }
.price-big { font-family: var(--font-display); font-size: 30px; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 16px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 4px 14px; }
.stat { display: flex; flex-direction: column; min-width: 0; padding: 10px 0; border-top: 1px solid var(--line); }
.stat:nth-child(-n+2) { border-top: 0; }
.stat span { font-size: 12.5px; color: var(--muted); font-weight: 600; }
.stat b { font-weight: 800; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }

/* ---------- Messages ---------- */
.banner {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px;
  background: var(--accent-soft); border-radius: 14px; padding: 10px 12px; font-size: 13.5px;
}
.banner p { margin: 0; flex: 1 1 200px; }
.banner strong { font-weight: 800; }
.banner .ico { width: 18px; height: 18px; color: var(--accent-line); }
.banner.warn { background: var(--warn-soft); }
.banner.danger { background: var(--down-soft); }
.banner.info { background: var(--surface); border: 1px solid var(--line); }
.empty {
  text-align: center; padding: 34px 20px;
  background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius);
}
.empty h2, .empty h3 { font-family: var(--font-display); font-size: 21px; margin: 8px 0 6px; letter-spacing: -.01em; text-wrap: balance; }
.empty p { margin: 0 auto 16px; max-width: 38ch; color: var(--ink-2); }
.empty .btns { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.empty-ill { width: 64px; height: 64px; margin: 0 auto; color: var(--accent-line); }
.empty-ill .ico { width: 100%; height: 100%; stroke-width: 1.4; }

/* ---------- Forms ---------- */
.form { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field > label, .field .label { font-size: 13px; font-weight: 700; color: var(--ink-2); }
.field input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]),
.field select,
.field textarea {
  width: 100%; min-width: 0; min-height: 46px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  padding: 10px 12px; font-size: 16px; font-weight: 600; color: var(--ink);
  -webkit-appearance: none; appearance: none;
}
.field textarea { min-height: 84px; resize: vertical; line-height: 1.4; }
.field select {
  padding-right: 36px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238a93a1' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; background-size: 16px;
}
.field input::placeholder, .field textarea::placeholder { color: var(--muted); font-weight: 500; opacity: .8; }
.field input:focus, .field select:focus, .field textarea:focus { outline: 2px solid var(--accent-line); outline-offset: 0; border-color: transparent; }
.field input[aria-invalid="true"], .field select[aria-invalid="true"] { border-color: var(--down); }
.field input[type="date"]::-webkit-date-and-time-value { text-align: left; }
.field input[type="date"] { display: block; }
.field .hint { font-size: 12px; color: var(--muted); }
.field input[type="checkbox"], .field input[type="radio"] { width: 20px; height: 20px; accent-color: var(--accent-line); }
.check { display: flex; align-items: center; gap: 10px; min-height: 44px; font-weight: 600; }
.check input { width: 20px; height: 20px; accent-color: var(--accent-line); flex-shrink: 0; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.fieldset { display: flex; flex-direction: column; gap: 12px; padding: 14px; border-radius: 14px; background: var(--surface); border: 1px solid var(--line); margin: 0; min-width: 0; }
.fieldset-title { font-size: 13px; font-weight: 800; }
.form-error { margin: 0; color: var(--down); font-weight: 700; font-size: 13.5px; }
.total-line { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 12px 14px; border-radius: 12px; background: var(--surface-2); font-weight: 700; }
.total-line strong { font-size: 18px; font-variant-numeric: tabular-nums; }
.inline-form { display: flex; gap: 8px; align-items: flex-end; }
.inline-form .field { flex: 1; }

/* ---------- Sheets (bottom sheets on phones, dialogs on desktop) ---------- */
.sheet-layer { position: fixed; inset: 0; z-index: 50; transform: translateY(var(--vv-dy, 0px)); display: flex; align-items: flex-end; justify-content: center; }
.backdrop { position: absolute; inset: 0; background: var(--scrim); animation: fade-in .2s ease-out; touch-action: none; }
.sheet {
  position: relative; display: flex; flex-direction: column; width: 100%; max-width: 640px;
  max-height: calc(100% - 24px - env(safe-area-inset-top, 0px));
  background: var(--bg); border-radius: 22px 22px 0 0; box-shadow: var(--shadow); outline: none;
  animation: rise .26s cubic-bezier(.2, .8, .2, 1);
}
.sheet.enter .sheet-body { animation: fade-in .18s ease-out; }
.grab { flex-shrink: 0; width: 38px; height: 5px; margin: 8px auto 0; border-radius: 3px; background: var(--line); }
.sheet-head { display: flex; align-items: center; gap: 4px; flex-shrink: 0; min-height: 52px; padding: 2px 8px 4px 18px; }
.sheet-head h2 { flex: 1; min-width: 0; margin: 0; font-size: 17px; font-weight: 800; letter-spacing: -.01em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sheet-head .back { margin-left: -12px; }
.sheet-body {
  flex: 1 1 auto; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
  padding: 4px max(16px, env(safe-area-inset-right, 0px)) calc(28px + env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px));
}
.sheet-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 18px; }
.sheet-actions > .btn { flex: 1 1 0; }
.confirm-text { margin: 0 0 4px; color: var(--ink-2); font-size: 15px; }

/* Scope picker */
.scope-list .row-title { display: flex; align-items: center; gap: 6px; }
.scope-ico { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; flex-shrink: 0; background: var(--surface-2); color: var(--ink-2); }
.scope-ico .ico { width: 20px; height: 20px; }
.row[aria-pressed="true"] .scope-ico { background: var(--accent); color: var(--accent-ink); }
.check-ico { display: grid; place-items: center; flex-shrink: 0; color: var(--accent-line); }
.check-ico .ico { width: 20px; height: 20px; stroke-width: 2.4; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; z-index: 70; transform: translate(-50%, var(--vv-dy, 0px));
  bottom: calc(var(--tabbar-h) + 18px + env(safe-area-inset-bottom, 0px));
  width: max-content; max-width: calc(100% - 32px);
  padding: 11px 16px; border-radius: 14px; box-shadow: var(--shadow);
  background: var(--ink); color: var(--bg); font-size: 14px; font-weight: 700; line-height: 1.35;
  animation: toast-in .22s cubic-bezier(.2, .8, .2, 1);
}

@media (max-width: 899px) {
  .sheet-layer:not([hidden]) ~ .toast { top: calc(12px + env(safe-area-inset-top, 0px)); bottom: auto; }
}

/* ---------- Desktop (≥ 900px): sidebar, top bar inside content, dialogs ---------- */
@media (min-width: 900px) {
  .sidebar {
    position: fixed; top: 0; bottom: 0; left: 0; z-index: 40;
    display: flex; flex-direction: column; width: var(--sidebar-w);
    padding: 22px 14px 16px; overflow-y: auto;
    background: var(--surface); border-right: 1px solid var(--line);
  }
  .side-brand { display: flex; align-items: center; gap: 10px; padding: 2px 10px 22px; font-family: var(--font-display); font-size: 21px; font-weight: 700; letter-spacing: -.01em; }
  .side-brand .brand-mark { width: 30px; height: 30px; }
  .side-nav { display: flex; flex-direction: column; gap: 2px; }
  .side-item {
    display: flex; align-items: center; gap: 12px; width: 100%; min-height: 44px; padding: 0 12px;
    border: 0; border-radius: 12px; background: transparent; color: var(--ink-2);
    font-size: 14.5px; font-weight: 700; text-align: left;
  }
  .side-item .ico { width: 20px; height: 20px; color: var(--muted); }
  .side-item[aria-current="page"] { background: var(--accent-soft); color: var(--ink); }
  .side-item[aria-current="page"] .ico { color: var(--accent-line); stroke-width: 2.2; }
  .side-add { margin-top: 18px; }
  .side-foot {
    margin-top: auto; padding: 14px 10px 0; border-top: 1px solid var(--line);
    display: flex; flex-direction: column; gap: 6px; font-size: 12.5px; color: var(--muted);
  }
  .side-status { display: flex; align-items: center; gap: 8px; font-weight: 700; color: var(--ink-2); }
  .side-foot .link-btn { min-height: 28px; font-size: 12.5px; align-self: flex-start; }

  .shell { margin-left: var(--sidebar-w); }
  .tabbar { display: none; }
  .top { padding-top: 0; }
  .top::before { display: none; }
  .top-inner { max-width: 1304px; margin: 0 auto; min-height: 64px; padding: 8px 32px; gap: 6px; }
  .top .brand { display: none; }
  .top-crumb { display: flex; align-items: center; gap: 8px; min-width: 0; font-size: 13px; font-weight: 700; color: var(--muted); }
  .top-crumb b { color: var(--ink); font-weight: 800; }
  .pill-btn { min-height: 40px; padding: 0 10px 0 14px; }
  .top-actions { gap: 4px; }
  .top-actions .icon-btn { width: 44px; border-radius: 50%; }

  #view { max-width: 1304px; margin: 0 auto; padding: 8px 32px 64px; }

  .page { gap: 24px; }
  .page-title { font-size: 34px; }
  .card, .chart-card { padding: 15px; }
  .kpi-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
  .chart-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }

  .sheet-layer { align-items: center; padding: 32px; }
  .sheet {
    max-width: 560px; max-height: min(88vh, 940px); border-radius: 20px;
    border: 1px solid var(--line); animation: pop .2s cubic-bezier(.2, .8, .2, 1);
  }
  .sheet.wide { max-width: 880px; }
  .grab { display: none; }
  .sheet-head { min-height: 60px; padding: 10px 12px 6px 22px; }
  .sheet-head .back { margin-left: -14px; }
  .sheet-body { padding: 4px 22px 24px; }

  .toast { left: auto; right: 24px; bottom: 24px; transform: none; max-width: 420px; }
}

/* Hover only where a mouse exists (no sticky hover on iPhone) */
@media (hover: hover) and (pointer: fine) {
  .icon-btn:hover { background: var(--surface-2); color: var(--ink); }
  .pill-btn:hover { border-color: var(--muted); }
  .btn:hover:not(:disabled) { border-color: var(--muted); }
  .btn.primary:hover:not(:disabled) { filter: brightness(1.05); border-color: var(--accent); }
  .btn.danger.solid:hover:not(:disabled) { filter: brightness(1.08); border-color: var(--down); }
  .chip:hover:not([aria-pressed="true"]) { color: var(--ink); background: var(--surface-2); }
  .seg button:hover:not([aria-pressed="true"]) { color: var(--ink); }
  button.row:hover, a.row:hover { background: var(--surface-2); }
  .side-item:hover:not([aria-current="page"]) { background: var(--surface-2); color: var(--ink); }
  .info-btn:hover { color: var(--ink); border-color: var(--muted); }
  .link-btn:hover { text-decoration: underline; }
  .tab:hover { color: var(--ink); }
}

/* Very narrow phones */
@media (max-width: 359px) {
  .brand-text { display: none; }
  .pill-btn span { max-width: 120px; }
  .kpi { padding: 10px 12px; }
  .kpi-value { font-size: 18px; }
}

/* ---------- Motion ---------- */
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 50% { opacity: .35; } }
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: -100% 0; } }
@keyframes rise { from { transform: translateY(48px); opacity: .5; } to { transform: none; opacity: 1; } }
@keyframes pop { from { transform: translateY(8px) scale(.98); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes toast-in { from { opacity: 0; translate: 0 8px; } to { opacity: 1; translate: 0 0; } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
  .skeleton { animation: none; }
  .icon-btn.spinning .ico { animation: none; }
}
