:root {
  --bg: #f4f5f8;
  --card: #ffffff;
  --chip: #eef0f4;
  --text: #0f172a;
  --text-2: #475569;
  --muted: #8a94a6;
  --line: #e9ecf1;
  --accent: #2563eb;
  --accent-2: #93b4f7;
  --accent-soft: #e9f0ff;
  --good: #15803d;
  --good-fill: #22c55e;
  --good-soft: #e6f6ec;
  --warn: #b45309;
  --warn-fill: #f59e0b;
  --warn-soft: #fdf2df;
  --bad: #dc2626;
  --bad-fill: #ef4444;
  --bad-soft: #fdebeb;
  --bad-deep: #991b1b;
  --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 4px 16px rgba(15, 23, 42, .04);
  --r: 20px;
  --nav-h: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1220; --card: #131b2c; --chip: #1c2638; --text: #e6eaf2; --text-2: #b4bfd0; --muted: #7d889c; --line: #222d42;
    --accent: #5b8cff; --accent-2: #36508a; --accent-soft: #1a2747;
    --good: #4ade80; --good-fill: #22c55e; --good-soft: #10291c;
    --warn: #fbbf24; --warn-fill: #f59e0b; --warn-soft: #2e230c;
    --bad: #f87171; --bad-fill: #ef4444; --bad-soft: #351416; --bad-deep: #fca5a5;
    --shadow: none;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { font: 15px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  min-height: 100vh; overscroll-behavior-y: contain; -webkit-font-smoothing: antialiased; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; padding: 0; }
input, select { font: inherit; color: inherit; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
a { color: inherit; text-decoration: none; }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.muted { color: var(--muted); }

/* ---------------- login */
.login { min-height: 100vh; display: flex; flex-direction: column; justify-content: center; padding: 32px 20px calc(24px + env(safe-area-inset-bottom)); max-width: 420px; margin: 0 auto; }
.login-top { text-align: center; margin-bottom: 24px; }
.login-logo { width: 72px; height: 72px; border-radius: 20px; box-shadow: 0 8px 24px rgba(15, 42, 74, .25); }
.login h1 { margin: 16px 0 4px; font-size: 28px; font-weight: 700; letter-spacing: -.5px; }
.login-top p { margin: 0; color: var(--text-2); }
.login-card { background: var(--card); border-radius: 24px; padding: 20px; box-shadow: var(--shadow); border: 1px solid var(--line); }
.field { display: block; margin-bottom: 14px; }
.field span { display: block; font-size: 13px; font-weight: 600; color: var(--text-2); margin-bottom: 6px; }
.field input { width: 100%; padding: 14px; border-radius: 14px; border: 1px solid var(--line); background: var(--bg); font-size: 16px; outline: none; transition: border-color .15s, box-shadow .15s; }
.field input:focus { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.err { color: var(--bad); font-size: 13px; min-height: 18px; margin: 10px 0 0; text-align: center; }
.login-foot { text-align: center; color: var(--muted); font-size: 12px; letter-spacing: 2px; margin-top: 28px; }
.btn { display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%; padding: 15px; border-radius: 14px; font-weight: 600; font-size: 16px; transition: transform .1s, opacity .15s; }
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--accent); color: #fff; }
.btn.primary:disabled { opacity: .6; }
.btn.ghost { color: var(--accent); margin-top: 12px; }
.btn.soft { background: var(--card); border: 1px solid var(--line); }
.btn.danger { color: var(--bad); background: var(--bad-soft); }

/* ---------------- layout */
main { max-width: 560px; margin: 0 auto; padding: calc(env(safe-area-inset-top) + 16px) 16px calc(var(--nav-h) + env(safe-area-inset-bottom) + 28px); }
.head { display: flex; align-items: center; gap: 12px; margin: 4px 0 16px; }
.head .t { flex: 1; min-width: 0; }
.head .kicker { font-size: 13px; color: var(--muted); font-weight: 500; }
.head h1 { margin: 0; font-size: 26px; font-weight: 700; letter-spacing: -.6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.avatar { width: 42px; height: 42px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 14px;
  background: var(--accent-soft); color: var(--accent); flex: none; }
.bar-row { display: flex; gap: 8px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
.pick { display: inline-flex; align-items: center; gap: 6px; padding: 8px 12px; border-radius: 12px; background: var(--card); border: 1px solid var(--line);
  font-size: 14px; font-weight: 600; position: relative; max-width: 100%; }
.pick svg { width: 16px; height: 16px; color: var(--muted); }
.pick select { position: absolute; inset: 0; opacity: 0; width: 100%; }
.pick span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.grow { flex: 1; }
.seg { display: inline-flex; background: var(--chip); border-radius: 12px; padding: 3px; }
.seg button { padding: 6px 12px; border-radius: 9px; font-size: 13px; font-weight: 600; color: var(--muted); transition: background .15s, color .15s; }
.seg button.on { background: var(--card); color: var(--text); box-shadow: 0 1px 3px rgba(15, 23, 42, .1); }

/* ---------------- cards */
.card { background: var(--card); border-radius: var(--r); padding: 16px; margin-bottom: 12px; box-shadow: var(--shadow); border: 1px solid var(--line); }
.card-h { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.card-h h2 { margin: 0; font-size: 16px; font-weight: 700; letter-spacing: -.2px; flex: 1; }
.card-h .aside { font-size: 13px; color: var(--muted); }
.label { font-size: 13px; color: var(--muted); font-weight: 500; }
.big { font-size: 34px; font-weight: 750; letter-spacing: -1px; line-height: 1.1; margin: 4px 0 2px; }
.mid { font-size: 22px; font-weight: 700; letter-spacing: -.5px; }
.sub { font-size: 13px; color: var(--text-2); }

.hero { display: flex; gap: 16px; align-items: center; }
.ring { position: relative; width: 112px; height: 112px; flex: none; }
.ring svg { width: 112px; height: 112px; transform: rotate(-90deg); }
.ring circle { stroke-width: 11; fill: none; }
.ring .track { stroke: var(--chip); }
.ring .val { stroke: var(--accent); transition: stroke-dashoffset .9s cubic-bezier(.2, .8, .2, 1); }
.ring .mark { stroke: var(--text); stroke-width: 3; }
.ring.good .val { stroke: var(--good-fill); } .ring.warn .val { stroke: var(--warn-fill); } .ring.bad .val { stroke: var(--bad-fill); }
.ring .in { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.ring .in b { font-size: 24px; font-weight: 750; letter-spacing: -.6px; }
.ring .in span { font-size: 11px; color: var(--muted); font-weight: 600; }

.tag { display: inline-flex; align-items: center; gap: 4px; padding: 3px 9px; border-radius: 99px; font-size: 12px; font-weight: 650; white-space: nowrap; }
.tag svg { width: 13px; height: 13px; stroke-width: 2.5; }
.tag.good { background: var(--good-soft); color: var(--good); } .tag.warn { background: var(--warn-soft); color: var(--warn); }
.tag.bad { background: var(--bad-soft); color: var(--bad); } .tag.grey { background: var(--chip); color: var(--muted); }
.tag.blue { background: var(--accent-soft); color: var(--accent); }
.delta { display: inline-flex; align-items: center; gap: 2px; font-size: 12px; font-weight: 650; }
.delta svg { width: 14px; height: 14px; stroke-width: 2.5; }
.delta.up { color: var(--good); } .delta.down { color: var(--bad); }

.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 12px; }
.tile { background: var(--card); border-radius: var(--r); padding: 14px; box-shadow: var(--shadow); border: 1px solid var(--line); text-align: left; display: block; min-width: 0; }
.tile .ic { width: 34px; height: 34px; border-radius: 11px; display: flex; align-items: center; justify-content: center; margin-bottom: 10px; }
.tile .ic svg { width: 18px; height: 18px; }
.ic.blue { background: var(--accent-soft); color: var(--accent); } .ic.red { background: var(--bad-soft); color: var(--bad); }
.ic.green { background: var(--good-soft); color: var(--good); } .ic.amber { background: var(--warn-soft); color: var(--warn); }
.tile .mid { margin: 2px 0; font-size: 20px; }

.segbar { display: flex; gap: 4px; margin: 14px 0 6px; }
.segbar i { flex: 1; height: 8px; border-radius: 4px; background: var(--chip); }
.segbar i.on { background: var(--accent); } .segbar.good i.on { background: var(--good-fill); } .segbar.warn i.on { background: var(--warn-fill); } .segbar.bad i.on { background: var(--bad-fill); }
.segbar i.half { background: linear-gradient(90deg, var(--seg-c, var(--accent)) var(--p), var(--chip) var(--p)); }
.segbar.good { --seg-c: var(--good-fill); } .segbar.warn { --seg-c: var(--warn-fill); } .segbar.bad { --seg-c: var(--bad-fill); }
.scale { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--line); }
.stats div span { display: block; font-size: 12px; color: var(--muted); font-weight: 500; }
.stats div b { font-size: 15px; font-weight: 700; }

.line { height: 6px; border-radius: 3px; background: var(--chip); overflow: hidden; margin-top: 8px; position: relative; }
.line i { display: block; height: 100%; border-radius: 3px; background: var(--accent); transition: width .6s cubic-bezier(.2, .8, .2, 1); }
.line i.good { background: var(--good-fill); } .line i.warn { background: var(--warn-fill); } .line i.bad { background: var(--bad-fill); }
.line em { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--text); opacity: .35; }

/* ---------------- rows */
.rows { margin: -4px -16px -16px; }
.r { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; padding: 12px 16px; border-top: 1px solid var(--line); }
.r:first-child { border-top: 0; }
.r .badge { width: 40px; height: 40px; border-radius: 12px; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 14px;
  background: var(--chip); color: var(--text-2); flex: none; }
.r .badge.round { border-radius: 50%; }
.r .badge.red { background: var(--bad-soft); color: var(--bad); } .r .badge.amber { background: var(--warn-soft); color: var(--warn); }
.r .badge.green { background: var(--good-soft); color: var(--good); } .r .badge.blue { background: var(--accent-soft); color: var(--accent); }
.r .badge.deep { background: var(--bad-fill); color: #fff; }
.r .badge svg { width: 18px; height: 18px; }
.r .mid-col { flex: 1; min-width: 0; }
.r .name { font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.r .meta { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.r .end { text-align: right; flex: none; min-width: 64px; }
.r .end b { display: block; font-size: 15px; font-weight: 700; }
.r .end small { font-size: 12px; color: var(--muted); }
.r .chev { width: 18px; height: 18px; color: var(--muted); transition: transform .2s; }
.r.open .chev { transform: rotate(90deg); }
.r .rank { width: 22px; font-size: 13px; font-weight: 700; color: var(--muted); text-align: center; flex: none; }
.r .acts { display: flex; gap: 8px; flex: none; }
.r .acts a { width: 38px; height: 38px; border-radius: 12px; background: var(--accent-soft); color: var(--accent); display: flex; align-items: center; justify-content: center; }
.r .acts a svg { width: 18px; height: 18px; }
.sub-rows { background: var(--bg); padding: 4px 16px 8px 68px; border-top: 1px solid var(--line); }
.sr { display: flex; gap: 10px; align-items: baseline; padding: 8px 0; font-size: 13px; border-top: 1px dashed var(--line); }
.sr:first-child { border-top: 0; }
.sr .n { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-2); }
.more { display: block; width: 100%; padding: 14px; color: var(--accent); font-weight: 650; border-top: 1px solid var(--line); text-align: center; }

.alert { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-top: 1px solid var(--line); width: 100%; text-align: left; }
.alert:first-child { border-top: 0; }
.alert .badge { width: 36px; height: 36px; border-radius: 11px; display: flex; align-items: center; justify-content: center; flex: none; }
.alert .badge svg { width: 18px; height: 18px; }

/* ---------------- chips, search */
.chips { display: flex; gap: 8px; overflow-x: auto; margin: 0 -16px 12px; padding: 0 16px 2px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chips button { flex: none; display: flex; flex-direction: column; align-items: flex-start; padding: 8px 14px; border-radius: 14px; background: var(--card); border: 1px solid var(--line); font-size: 13px; font-weight: 650; min-width: 76px; }
.chips button small { color: var(--muted); font-weight: 600; font-size: 12px; }
.chips button i { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 5px; }
.chips button.on { background: var(--text); color: var(--card); border-color: var(--text); }
.chips button.on small { color: var(--card); opacity: .7; }
.search { position: relative; margin-bottom: 8px; }
.search svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); width: 18px; height: 18px; color: var(--muted); }
.search input { width: 100%; padding: 11px 12px 11px 40px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg); font-size: 15px; outline: none; }
.search input:focus { border-color: var(--accent); }

/* ---------------- charts */
.cols { display: flex; align-items: flex-end; gap: 3px; height: 120px; position: relative; padding-top: 4px; }
.cols div { flex: 1; border-radius: 4px 4px 2px 2px; background: var(--accent-2); min-height: 3px; transition: height .6s cubic-bezier(.2, .8, .2, 1); }
.cols div.zero { background: var(--chip); }
.cols div.last { background: var(--accent); }
.cols .avg { position: absolute; left: 0; right: 0; border-top: 1.5px dashed var(--muted); opacity: .6; height: 0; }
.cols-axis { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); margin-top: 6px; }
.stack { display: flex; height: 12px; border-radius: 6px; overflow: hidden; gap: 2px; margin: 14px 0 8px; background: var(--chip); }
.stack i { display: block; height: 100%; }
.hbars .hb { display: flex; align-items: center; gap: 10px; padding: 6px 0; font-size: 14px; }
.hbars .hb span { width: 74px; flex: none; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hbars .hb .line { flex: 1; margin: 0; height: 8px; }
.hbars .hb b { width: 74px; text-align: right; font-size: 13px; flex: none; }

/* ---------------- nav */
.nav { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(env(safe-area-inset-bottom) + 12px); z-index: 10; display: flex; gap: 4px;
  background: color-mix(in srgb, var(--card) 88%, transparent); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--line); border-radius: 22px; padding: 6px; box-shadow: 0 8px 30px rgba(15, 23, 42, .12); width: min(calc(100% - 32px), 420px); }
.nav button { flex: 1; display: flex; align-items: center; justify-content: center; gap: 6px; height: 48px; border-radius: 16px; color: var(--muted); font-size: 13px; font-weight: 650; transition: background .2s, color .2s; }
.nav button span { display: none; }
.nav button svg { width: 22px; height: 22px; }
.nav button.on { background: var(--accent); color: #fff; flex: 1.6; }
.nav button.on span { display: inline; }

/* ---------------- me, sheet, misc */
.kv { display: flex; justify-content: space-between; gap: 12px; padding: 12px 0; border-top: 1px solid var(--line); font-size: 14px; }
.kv:first-child { border-top: 0; padding-top: 0; }
.kv span { color: var(--muted); }
.btns .btn { margin-top: 10px; }
.sheet { position: fixed; inset: 0; z-index: 20; background: rgba(8, 14, 26, .45); display: flex; align-items: flex-end; animation: fade .15s; }
.sheet-body { width: 100%; max-width: 560px; margin: 0 auto; max-height: 78vh; overflow: auto; background: var(--card); border-radius: 24px 24px 0 0;
  padding: 8px 0 calc(env(safe-area-inset-bottom) + 12px); animation: up .2s cubic-bezier(.2, .8, .2, 1); }
.sheet-grip { width: 40px; height: 5px; border-radius: 5px; background: var(--line); margin: 6px auto 10px; }
.sheet .opt { display: flex; align-items: center; width: 100%; padding: 14px 20px; text-align: left; font-size: 16px; }
.sheet .opt.on { color: var(--accent); font-weight: 700; }
.sheet .opt.on::after { content: "✓"; margin-left: auto; }
.sheet .grp { padding: 14px 20px 6px; font-size: 12px; font-weight: 700; color: var(--muted); letter-spacing: .5px; text-transform: uppercase; }
.loading { position: fixed; inset: 0; z-index: 30; display: flex; align-items: center; justify-content: center; background: color-mix(in srgb, var(--bg) 70%, transparent); }
.spinner { width: 38px; height: 38px; border: 4px solid var(--accent-soft); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
.empty { text-align: center; color: var(--muted); padding: 28px 12px; font-size: 14px; }
.toast { position: fixed; left: 50%; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 28px); transform: translateX(-50%); z-index: 25;
  background: var(--text); color: var(--card); padding: 11px 18px; border-radius: 14px; font-size: 14px; font-weight: 600; max-width: 90vw; animation: up .2s; }
.screen { animation: fade .25s ease-out; }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes up { from { transform: translateY(16px); opacity: 0; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
