:root {
  --bg: #0f1115;
  --card: #181b22;
  --line: #262a33;
  --text: #f2f3f5;
  --muted: #9097a3;
  --accent: #5b8cff;
  --good: #34c77b;
  --warn: #f2b53a;
  --bad: #ff5d5d;
  color-scheme: dark;
}
:root[data-theme="light"] {
  --bg: #f4f5f7; --card: #ffffff; --line: #e3e5ea; --text: #14161a; --muted: #6b7280;
  color-scheme: light;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f4f5f7; --card: #ffffff; --line: #e3e5ea; --text: #14161a; --muted: #6b7280;
    color-scheme: light;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  padding: env(safe-area-inset-top) 16px calc(env(safe-area-inset-bottom) + 24px);
  max-width: 560px; margin: 0 auto;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.fine { color: var(--muted); font-size: 12px; text-align: center; margin: 20px 8px; }
.good { color: var(--good); } .warn { color: var(--warn); } .bad { color: var(--bad); }
.bg-good { background: var(--good); } .bg-warn { background: var(--warn); } .bg-bad { background: var(--bad); }

/* Login */
.login-wrap { min-height: 92vh; display: flex; flex-direction: column; justify-content: center; }
.brand { text-align: center; margin-bottom: 28px; }
.logo {
  width: 64px; height: 64px; border-radius: 18px; margin: 0 auto 12px; display: grid; place-items: center;
  background: var(--accent); color: #fff; font-size: 32px; font-weight: 700;
}
h1 { margin: 0 0 4px; font-size: 26px; }
form { display: grid; gap: 14px; }
label { display: grid; gap: 6px; font-size: 13px; color: var(--muted); }
input {
  font: inherit; font-size: 16px; /* 16px+ stops iOS zooming on focus */ color: var(--text); background: var(--card); border: 1px solid var(--line);
  border-radius: 12px; padding: 14px; outline: none;
}
input:focus { border-color: var(--accent); }
.primary {
  background: var(--accent); color: #fff; border: 0; border-radius: 12px; padding: 15px;
  font-weight: 600; display: flex; justify-content: center; align-items: center; gap: 10px;
}
.primary:disabled { opacity: .7; }
.link { background: none; border: 0; color: var(--accent); padding: 8px; }
.login-wrap .link { margin-top: 14px; }
.error { color: var(--bad); text-align: center; margin: 0; font-size: 14px; white-space: pre-line; }
.spinner {
  width: 18px; height: 18px; border-radius: 50%; border: 2px solid rgba(255,255,255,.4);
  border-top-color: #fff; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Header */
.top { display: flex; align-items: center; justify-content: space-between; padding: 16px 0 12px; gap: 10px; }
.title { font-size: 20px; font-weight: 700; text-align: center; flex: 1; }
.clip { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.spacer { width: 40px; flex: none; }
.actions { display: flex; gap: 8px; }
.icon {
  width: 40px; height: 40px; border-radius: 12px; border: 1px solid var(--line); flex: none;
  background: var(--card); font-size: 20px; display: grid; place-items: center;
}
.icon.spin { animation: spin .8s linear infinite; }
.back { font-size: 28px; line-height: 1; }
.term-wrap { display: grid; gap: 2px; }
#term {
  appearance: none; -webkit-appearance: none; font: inherit; font-size: 20px; font-weight: 700;
  color: var(--text); background: transparent; border: 0; padding: 0 22px 0 0; outline: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: right 6px center, right 0 center; background-size: 6px 6px; background-repeat: no-repeat;
  background-position: calc(100% - 8px) 55%, calc(100% - 2px) 55%;
}
.stale {
  background: color-mix(in srgb, var(--warn) 15%, transparent); color: var(--warn);
  border-radius: 10px; padding: 10px 12px; font-size: 13px; margin-bottom: 12px;
}

/* Cards */
.card {
  width: 100%; text-align: left; background: var(--card); border: 1px solid var(--line);
  border-radius: 20px; padding: 20px; margin-bottom: 8px; display: block;
}
button.card:active, button.row:active { transform: scale(.985); }
.hero { padding: 24px 22px; min-height: 170px; }
.card-label { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); display: flex; justify-content: space-between; }
.chev { font-size: 22px; line-height: .8; }
.big-num { font-size: 60px; font-weight: 800; letter-spacing: -.03em; line-height: 1.1; margin: 4px 0; }
.big-num .of { font-size: 28px; color: var(--muted); font-weight: 700; }

/* Sections and rows */
.sec-head { display: flex; justify-content: space-between; align-items: center; margin: 22px 0 8px; gap: 10px; }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0; }
.sec-head .link { padding: 0; }
.list { display: grid; gap: 10px; }
.row {
  width: 100%; text-align: left; display: block;
  background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 16px 18px;
  min-height: 72px;
}
.row.slim { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.row:disabled, .row.dim { opacity: .55; }
.row.absent { border-color: color-mix(in srgb, var(--bad) 45%, var(--line)); }
.row-top { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.row-name { font-weight: 600; font-size: 17px; line-height: 1.3; }
.row-val { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; text-align: right; }
.row-sub { color: var(--muted); font-size: 14px; margin-top: 4px; line-height: 1.35; }
.bar { height: 7px; background: var(--line); border-radius: 3px; margin-top: 10px; overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 3px; }
.pill {
  flex: none; font-size: 12px; font-weight: 600; padding: 4px 9px; border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 18%, transparent); color: var(--accent);
}
.pill.today { background: color-mix(in srgb, var(--bad) 18%, transparent); color: var(--bad); }
.pill.soon { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }
.chip { flex: none; font-size: 12px; font-weight: 700; padding: 4px 10px; border-radius: 999px; }
.chip.P { background: color-mix(in srgb, var(--good) 16%, transparent); color: var(--good); }
.chip.A { background: color-mix(in srgb, var(--bad) 18%, transparent); color: var(--bad); }
.chip.L { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }
.empty { color: var(--muted); text-align: center; padding: 16px; background: var(--card); border: 1px dashed var(--line); border-radius: 14px; font-size: 14px; }
.toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 20px); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px; z-index: 20;
  max-width: 90vw; text-align: center;
}
.spinner.dark { display: inline-block; vertical-align: -3px; margin-right: 8px; border-color: var(--line); border-top-color: var(--accent); }
#theme { font-size: 18px; }
