/* AI Money — statistics site.
   Apple-style foundations (system type, grouped backgrounds, translucent chrome, springy
   but restrained motion) with the data-viz palette validated on these card surfaces
   (#ffffff / #1c1c1e): see the chart tokens below. */

:root {
  color-scheme: light dark;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;

  --bg: #f2f2f7;
  --card: #ffffff;
  --card-2: #f2f2f7;
  --fill: rgba(120, 120, 128, 0.12);
  --fill-2: rgba(120, 120, 128, 0.20);
  --label: #000000;
  --label-2: rgba(60, 60, 67, 0.62);
  --label-3: rgba(60, 60, 67, 0.32);
  --separator: rgba(60, 60, 67, 0.16);
  --accent: #007aff;
  --accent-press: #0062cc;
  --on-accent: #ffffff;
  --material: rgba(250, 250, 252, 0.74);
  --material-heavy: rgba(242, 242, 247, 0.86);
  --material-edge: rgba(255, 255, 255, 0.55);
  --material-line: rgba(0, 0, 0, 0.10);
  --shadow-card: 0 0.5px 0 rgba(0, 0, 0, 0.04), 0 1px 3px rgba(0, 0, 0, 0.04);
  --shadow-float: 0 10px 40px rgba(0, 0, 0, 0.14), 0 2px 8px rgba(0, 0, 0, 0.08);
  --scrim: rgba(0, 0, 0, 0.28);

  /* chart tokens (dataviz reference palette; validated on #ffffff) */
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --other: #aeaeb2;
  --pos: #2a78d6;
  --neg: #e34948;
  --grid: #ececf0;
  --axis: #c7c7cc;
  --muted: #8a8a8e;

  /* status (always with an icon + a word) and signed-number text */
  --good: #0ca30c;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --up-text: #006300;
  --down-text: #c4281c;

  --radius: 16px;
  --radius-s: 10px;
  --gap: 12px;
  --tabbar-h: 56px;
  --sidebar-w: 248px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --card: #1c1c1e;
    --card-2: #2c2c2e;
    --fill: rgba(118, 118, 128, 0.24);
    --fill-2: rgba(118, 118, 128, 0.34);
    --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);
    --accent: #0a84ff;
    --accent-press: #409cff;
    --material: rgba(28, 28, 30, 0.72);
    --material-heavy: rgba(18, 18, 20, 0.84);
    --material-edge: rgba(255, 255, 255, 0.08);
    --material-line: rgba(255, 255, 255, 0.10);
    --shadow-card: none;
    --shadow-float: 0 10px 40px rgba(0, 0, 0, 0.6);
    --scrim: rgba(0, 0, 0, 0.5);

    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --other: #636366;
    --pos: #3987e5;
    --neg: #e66767;
    --grid: #2c2c2e;
    --axis: #48484a;
    --muted: #8e8e93;

    --up-text: #2fbf4f;
    --down-text: #ff7a70;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
html, body { margin: 0; height: 100%; }
body {
  font: 400 1.0625rem/1.4 var(--font);
  color: var(--label);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
button, input { font: inherit; color: inherit; }
button { -webkit-appearance: none; appearance: none; border: 0; background: none; padding: 0; cursor: pointer; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 60%, transparent); outline-offset: 2px; border-radius: 8px; }
svg { display: block; }
.num { font-variant-numeric: tabular-nums; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------------------------------------------------------------- type */
.t-large { font-size: 2.125rem; line-height: 1.12; font-weight: 700; letter-spacing: -0.022em; }
.t-title2 { font-size: 1.375rem; line-height: 1.2; font-weight: 700; letter-spacing: -0.016em; }
.t-title3 { font-size: 1.25rem; line-height: 1.25; font-weight: 600; letter-spacing: -0.012em; }
.t-headline { font-size: 1.0625rem; line-height: 1.3; font-weight: 600; letter-spacing: -0.008em; }
.t-sub { font-size: 0.9375rem; line-height: 1.35; }
.t-foot { font-size: 0.8125rem; line-height: 1.38; letter-spacing: 0.002em; }
.t-cap { font-size: 0.75rem; line-height: 1.35; letter-spacing: 0.01em; }
.t-hero { font-size: clamp(2.75rem, 9vw, 3.5rem); line-height: 1.02; font-weight: 700; letter-spacing: -0.03em; }
.c2 { color: var(--label-2); }
.c3 { color: var(--label-3); }
.up { color: var(--up-text); }
.down { color: var(--down-text); }

/* ---------------------------------------------------------------- layout */
.shell { min-height: 100%; }
.main { padding: calc(var(--safe-t) + 8px) 16px calc(var(--tabbar-h) + var(--safe-b) + 28px); max-width: 1180px; margin: 0 auto; }
.view-head { padding: 44px 4px 8px; display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; }
.view-head .sub { margin-top: 2px; }
.filters { position: sticky; top: calc(var(--safe-t) + 52px); z-index: 4; padding: 6px 0 12px; }
.stack { display: grid; gap: var(--gap); }
.grid { display: grid; gap: var(--gap); }
@media (min-width: 900px) {
  .main { padding: 24px 32px 48px calc(var(--sidebar-w) + 32px); }
  .view-head { padding-top: 28px; }
  .grid.two { grid-template-columns: 1fr 1fr; align-items: start; }
  .span-2 { grid-column: 1 / -1; }
  .filters { top: 0; }
}
.view { transition: opacity 180ms ease; }
.view.refreshing { opacity: 0.62; }

/* ---------------------------------------------------------------- materials: nav, tab bar, sidebar */
.navbar {
  position: fixed; inset: 0 0 auto 0; z-index: 20;
  height: calc(var(--safe-t) + 44px); padding: var(--safe-t) 16px 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--material);
  -webkit-backdrop-filter: blur(20px) saturate(180%); backdrop-filter: blur(20px) saturate(180%);
  border-bottom: 0.5px solid transparent;
  opacity: 0; pointer-events: none; transition: opacity 160ms ease, border-color 160ms ease;
}
.navbar.on { opacity: 1; pointer-events: auto; border-bottom-color: var(--material-line); }
.navbar .t-headline { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.tabbar {
  position: fixed; inset: auto 0 0 0; z-index: 20;
  height: calc(var(--tabbar-h) + var(--safe-b)); padding: 6px 4px var(--safe-b);
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--material-heavy);
  -webkit-backdrop-filter: blur(24px) saturate(180%); backdrop-filter: blur(24px) saturate(180%);
  border-top: 0.5px solid var(--material-line);
}
.tab {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  color: var(--muted); font-size: 0.625rem; font-weight: 500; letter-spacing: 0.01em;
  border-radius: 10px; transition: transform 100ms ease-out, color 120ms ease;
}
.tab svg { width: 26px; height: 26px; }
.tab[aria-current="page"] { color: var(--accent); }
.tab:active { transform: scale(0.94); }

.sidebar { display: none; }
@media (min-width: 900px) {
  .navbar, .tabbar { display: none; }
  .sidebar {
    display: flex; flex-direction: column; gap: 4px;
    position: fixed; inset: 0 auto 0 0; width: var(--sidebar-w); z-index: 10;
    padding: 28px 14px 20px;
    background: var(--material-heavy);
    -webkit-backdrop-filter: blur(30px) saturate(160%); backdrop-filter: blur(30px) saturate(160%);
    border-right: 0.5px solid var(--material-line);
  }
  .brand { display: flex; align-items: center; gap: 10px; padding: 0 10px 18px; }
  .brand img { width: 30px; height: 30px; border-radius: 8px; }
  .side-item {
    display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 10px;
    color: var(--label); font-size: 0.9375rem; font-weight: 500; text-align: left;
    transition: transform 100ms ease-out, background-color 120ms ease;
  }
  .side-item svg { width: 22px; height: 22px; color: var(--accent); }
  .side-item:hover { background: var(--fill); }
  .side-item[aria-current="page"] { background: var(--accent); color: var(--on-accent); }
  .side-item[aria-current="page"] svg { color: var(--on-accent); }
  .side-item:active { transform: scale(0.98); }
  .side-foot { margin-top: auto; padding: 10px; }
}

/* ---------------------------------------------------------------- cards */
.card { background: var(--card); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow-card); min-width: 0; }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.card-head .t-headline { min-width: 0; }
.card-note { margin-top: 10px; }
.section-title { padding: 18px 4px 6px; }
.callout { display: flex; gap: 10px; align-items: flex-start; background: var(--card); border-radius: var(--radius); padding: 14px 16px; }
.callout svg { flex: none; width: 20px; height: 20px; margin-top: 1px; color: var(--accent); }

/* ---------------------------------------------------------------- hero + tiles */
.hero .label { margin-bottom: 4px; }
.hero .delta { margin-top: 6px; font-weight: 600; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.hero .meta { margin-top: 10px; display: flex; flex-wrap: wrap; gap: 6px 16px; }
.tiles { display: grid; gap: var(--gap); grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (min-width: 640px) { .tiles { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (min-width: 1100px) { .tiles.four { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.tile { background: var(--card); border-radius: var(--radius); padding: 14px 14px 13px; box-shadow: var(--shadow-card); min-width: 0; }
.tile .value { font-size: 1.5rem; line-height: 1.15; font-weight: 700; letter-spacing: -0.02em; margin-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile .hint { margin-top: 4px; }

/* ---------------------------------------------------------------- segmented control */
.segmented {
  position: relative; display: inline-grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  background: var(--fill); border-radius: 9px; padding: 2px; min-width: min(100%, 320px);
  touch-action: manipulation; user-select: none;
}
.segmented .thumb {
  position: absolute; top: 2px; bottom: 2px; left: 0; border-radius: 7px;
  background: var(--card); box-shadow: 0 3px 8px rgba(0, 0, 0, 0.12), 0 0.5px 1px rgba(0, 0, 0, 0.08);
  will-change: transform;
}
@media (prefers-color-scheme: dark) { .segmented .thumb { background: #636366; } }
.segmented button { position: relative; z-index: 1; padding: 6px 14px; font-size: 0.8125rem; font-weight: 500; border-radius: 7px; white-space: nowrap; transition: opacity 100ms ease; }
.segmented button[aria-pressed="true"] { font-weight: 600; }
.segmented button:active { opacity: 0.6; }

/* ---------------------------------------------------------------- buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 18px; border-radius: 12px;
  font-weight: 600; font-size: 1.0625rem;
  transition: transform 100ms ease-out, background-color 120ms ease, opacity 120ms ease;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--accent); color: var(--on-accent); }
.btn-primary:active { background: var(--accent-press); }
.btn-primary[disabled] { opacity: 0.4; }
.btn-plain { color: var(--accent); min-height: 32px; padding: 0 6px; font-weight: 400; font-size: 1rem; }
.btn-chip { min-height: 28px; padding: 0 10px; border-radius: 14px; background: var(--fill); color: var(--label); font-size: 0.8125rem; font-weight: 500; }
.icon-btn { width: 36px; height: 36px; border-radius: 18px; display: inline-flex; align-items: center; justify-content: center; color: var(--accent); background: var(--fill); transition: transform 100ms ease-out; }
.icon-btn:active { transform: scale(0.92); }
.icon-btn svg { width: 20px; height: 20px; }

/* ---------------------------------------------------------------- status pill */
.pill {
  display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 12px 0 10px;
  border-radius: 15px; background: var(--card); box-shadow: var(--shadow-card);
  font-size: 0.8125rem; font-weight: 600; white-space: nowrap;
  transition: transform 100ms ease-out;
}
.pill:active { transform: scale(0.96); }
.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.dot.good { background: var(--good); }
.dot.warning { background: var(--warning); }
.dot.critical { background: var(--critical); }
.dot.idle { background: var(--muted); }

/* ---------------------------------------------------------------- lists */
.list { margin: 0 -16px; }
.row {
  position: relative; display: flex; align-items: center; gap: 12px; padding: 11px 16px; min-height: 44px;
  text-align: left; width: 100%; transition: background-color 120ms ease;
}
.row + .row::before { content: ""; position: absolute; top: 0; left: 16px; right: 0; height: 0.5px; background: var(--separator); }
.row.tap:active { background: var(--fill); }
.row .grow { flex: 1; min-width: 0; }
.row .title { font-weight: 500; display: flex; align-items: center; gap: 8px; min-width: 0; }
.row .title span:first-child { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .right { text-align: right; flex: none; }
.row .chev { width: 8px; height: 13px; color: var(--label-3); flex: none; }
.kv { display: flex; justify-content: space-between; gap: 16px; padding: 10px 0; }
.kv + .kv { border-top: 0.5px solid var(--separator); }
.kv .k { color: var(--label-2); }
.kv .v { text-align: right; font-weight: 500; }

.tag { display: inline-flex; align-items: center; gap: 3px; height: 20px; padding: 0 7px; border-radius: 6px; font-size: 0.6875rem; font-weight: 700; letter-spacing: 0.02em; background: var(--fill); color: var(--label-2); text-transform: uppercase; }
.tag.long svg, .tag.short svg { width: 9px; height: 9px; }

/* ---------------------------------------------------------------- meters & tracks */
.meter { height: 8px; border-radius: 4px; background: color-mix(in srgb, var(--series-1) 18%, transparent); overflow: hidden; }
.meter > i { display: block; height: 100%; border-radius: 4px; background: var(--series-1); }
.meter.warning > i { background: var(--warning); }
.meter.critical > i { background: var(--critical); }
.meter-row { display: grid; gap: 6px; padding: 10px 0; }
.meter-row + .meter-row { border-top: 0.5px solid var(--separator); }
.meter-row .line { display: flex; justify-content: space-between; gap: 12px; }

.track { position: relative; height: 22px; margin-top: 8px; }
.track .rail { position: absolute; left: 0; right: 0; top: 9px; height: 4px; border-radius: 2px; background: var(--fill-2); }
.track .loss { position: absolute; top: 9px; height: 4px; border-radius: 2px 0 0 2px; background: color-mix(in srgb, var(--neg) 45%, transparent); }
.track .gain { position: absolute; top: 9px; height: 4px; border-radius: 0 2px 2px 0; background: color-mix(in srgb, var(--pos) 45%, transparent); }
.track .entry { position: absolute; top: 4px; width: 2px; height: 14px; margin-left: -1px; border-radius: 1px; background: var(--label-2); }
.track .now { position: absolute; top: 4px; width: 14px; height: 14px; margin-left: -7px; border-radius: 50%; background: var(--label); border: 2px solid var(--card); box-sizing: content-box; transform: translateY(-2px); }
.track-labels { display: flex; justify-content: space-between; margin-top: 2px; }

/* ---------------------------------------------------------------- charts */
.chart { position: relative; width: 100%; touch-action: pan-y; user-select: none; -webkit-user-select: none; }
.chart text { font-family: var(--font); fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .label-strong { fill: var(--label); font-weight: 600; }
.chart .label-2 { fill: var(--label-2); }
.tooltip {
  position: absolute; z-index: 5; pointer-events: none; min-width: 120px; max-width: 240px;
  padding: 8px 10px; border-radius: 12px;
  background: var(--material); -webkit-backdrop-filter: blur(20px) saturate(180%); backdrop-filter: blur(20px) saturate(180%);
  box-shadow: var(--shadow-float); border: 0.5px solid var(--material-line);
  opacity: 0; transform: translateY(4px) scale(0.98); transition: opacity 120ms ease, transform 160ms ease;
}
.tooltip.on { opacity: 1; transform: none; }
.tooltip .tt-v { font-weight: 700; font-size: 0.9375rem; font-variant-numeric: tabular-nums; }
.tooltip .tt-row { display: flex; align-items: center; gap: 6px; }
.tooltip .tt-key { width: 12px; height: 3px; border-radius: 2px; flex: none; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin: 2px 0 8px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; font-size: 0.8125rem; color: var(--label-2); }
.legend i { width: 14px; height: 3px; border-radius: 2px; display: inline-block; }
.legend i.box { height: 10px; width: 10px; border-radius: 3px; }
.table-wrap { overflow-x: auto; margin: 0 -4px; }
table.data { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
table.data th { text-align: left; font-weight: 600; color: var(--label-2); font-size: 0.75rem; padding: 6px 4px; border-bottom: 0.5px solid var(--separator); }
table.data td { padding: 7px 4px; border-bottom: 0.5px solid var(--separator); font-variant-numeric: tabular-nums; white-space: nowrap; }
table.data td.l, table.data th.l { text-align: left; }
table.data td.r, table.data th.r { text-align: right; }
.empty { padding: 26px 8px; text-align: center; color: var(--label-2); }

/* ---------------------------------------------------------------- sheet */
.scrim { position: fixed; inset: 0; z-index: 40; background: var(--scrim); opacity: 0; }
.sheet {
  position: fixed; z-index: 41; left: 0; right: 0; bottom: 0;
  max-height: calc(100% - var(--safe-t) - 36px); display: flex; flex-direction: column;
  background: var(--card); border-radius: 14px 14px 0 0; box-shadow: var(--shadow-float);
  padding-bottom: var(--safe-b); will-change: transform; touch-action: none;
}
@media (prefers-color-scheme: dark) { .sheet { background: #1c1c1e; } }
.sheet .grabber-zone { padding: 6px 0 2px; cursor: grab; flex: none; }
.sheet .grabber { width: 36px; height: 5px; border-radius: 3px; background: var(--label-3); margin: 0 auto; }
.sheet .sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 16px 6px; flex: none; }
.sheet .sheet-body { overflow-y: auto; padding: 4px 16px 20px; touch-action: pan-y; overscroll-behavior: contain; }
@media (min-width: 900px) {
  .sheet { left: 50%; right: auto; bottom: auto; top: 50%; width: min(560px, 92vw); max-height: 80vh; border-radius: 18px; margin-left: calc(min(560px, 92vw) / -2); }
  .sheet .grabber-zone { display: none; }
}

/* ---------------------------------------------------------------- login */
.login { min-height: 100%; display: grid; place-items: center; padding: 32px 20px calc(32px + var(--safe-b)); }
.login-card { width: min(400px, 100%); text-align: center; }
.login-card img { width: 76px; height: 76px; border-radius: 18px; box-shadow: 0 6px 24px rgba(0, 0, 0, 0.16); }
.login-card .t-large { margin-top: 18px; }
.login-card p { margin: 8px 0 0; }
.code-field { margin-top: 26px; display: grid; gap: 12px; }
.code-input {
  width: 100%; height: 56px; border-radius: 14px; border: 0; background: var(--card); box-shadow: var(--shadow-card);
  text-align: center; font-size: 1.625rem; font-weight: 600; letter-spacing: 0.18em; text-transform: uppercase;
  font-variant-numeric: tabular-nums; outline: none;
}
.code-input:focus { box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 45%, transparent); }
.login-error { min-height: 20px; color: var(--down-text); font-size: 0.875rem; display: flex; gap: 6px; align-items: center; justify-content: center; }
.login-error svg { width: 16px; height: 16px; flex: none; }

/* ---------------------------------------------------------------- accessibility preferences */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 1ms !important; animation-duration: 1ms !important; }
  .tab:active, .btn:active, .pill:active, .icon-btn:active, .side-item:active { transform: none; }
}
@media (prefers-reduced-transparency: reduce) {
  .navbar, .tabbar, .sidebar, .tooltip { -webkit-backdrop-filter: none; backdrop-filter: none; background: var(--card); }
}
@media (prefers-contrast: more) {
  :root { --separator: rgba(60, 60, 67, 0.5); --label-2: rgba(60, 60, 67, 0.85); }
  .card, .tile, .pill { border: 1px solid var(--separator); }
  .navbar, .tabbar, .sidebar { background: var(--card); -webkit-backdrop-filter: none; backdrop-filter: none; }
}
@media (forced-colors: active) {
  .meter > i, .dot { forced-color-adjust: none; }
}
