:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f3f2ee;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --accent: #2a78d6;
  --accent-ink: #1c5cab;
  --gain: #2a78d6;
  --loss: #e34948;
  --pos-text: #006300;
  --neg-text: #c22f2f;
  --bad: #d03b3b;
  --warn: #fab219;
  --warn-ink: #8a5a00;
  --good: #0ca30c;
  --wash-gain: rgba(42, 120, 214, 0.10);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 4px 16px rgba(0, 0, 0, 0.04);
  --radius: 12px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #222220;
    --text: #f0efec;
    --text-2: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --accent: #3987e5;
    --accent-ink: #86b6ef;
    --gain: #3987e5;
    --loss: #e66767;
    --pos-text: #0ca30c;
    --neg-text: #ef7b7b;
    --warn-ink: #fab219;
    --wash-gain: rgba(57, 135, 229, 0.12);
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--page);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
}
a { color: var(--accent-ink); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 12px; }
h1 { font-size: 24px; font-weight: 650; }
h2 { font-size: 17px; font-weight: 650; }
h3 { font-size: 15px; font-weight: 650; }
p { margin: 0 0 12px; }
small, .small { font-size: 13px; }
.muted { color: var(--muted); }
.secondary { color: var(--text-2); }
.pos { color: var(--pos-text); }
.neg { color: var(--neg-text); }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.right { text-align: right; }
.hidden { display: none !important; }

/* --- layout --- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: 1200px; margin: 0 auto; padding: 0 16px;
  display: flex; align-items: center; gap: 16px; height: 56px;
}
.brand { font-weight: 700; color: var(--text); white-space: nowrap; }
.brand:hover { text-decoration: none; }
.nav { display: flex; gap: 4px; overflow-x: auto; flex: 1; scrollbar-width: none; }
.nav::-webkit-scrollbar { display: none; }
.nav a {
  color: var(--text-2); padding: 6px 10px; border-radius: 8px; white-space: nowrap; font-size: 14px;
}
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a.active { color: var(--text); background: var(--surface-2); font-weight: 600; }
.logout button { background: none; border: 0; color: var(--muted); cursor: pointer; font: inherit; font-size: 14px; }
main { max-width: 1200px; margin: 0 auto; padding: 20px 16px 64px; }
@media (max-width: 640px) {
  .topbar-inner { flex-wrap: wrap; height: auto; padding-top: 8px; gap: 4px 12px; }
  .brand { flex: 1; }
  .nav { order: 3; flex: 0 0 100%; margin: 0 -16px; padding: 0 12px 6px; }
  .hide-sm { display: none; }
  .hero-value { font-size: 40px; }
  td.prod { min-width: 140px; }
  .badge .lbl { display: none; }
  .badge.bad, .badge.warn { padding: 2px 7px; }
}

.page-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.page-head h1 { margin: 0; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 16px;
  min-width: 0;
}
.card > h2:first-child { margin-bottom: 12px; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media (max-width: 860px) { .grid-2, .grid-3 { grid-template-columns: minmax(0, 1fr); } }

/* --- flash --- */
.flash { padding: 10px 14px; border-radius: 10px; margin-bottom: 16px; border: 1px solid var(--border); background: var(--surface); }
.flash.ok { border-left: 4px solid var(--good); }
.flash.error { border-left: 4px solid var(--bad); }

/* --- segmented control --- */
.seg { display: inline-flex; background: var(--surface-2); border-radius: 10px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.seg a { padding: 5px 10px; border-radius: 8px; color: var(--text-2); font-size: 14px; }
.seg a:hover { text-decoration: none; color: var(--text); }
.seg a.on { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: 0 0 0 1px var(--border); }

/* --- stats --- */
.hero { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 8px 24px; }
.hero-value { font-size: 48px; font-weight: 650; line-height: 1.05; letter-spacing: -0.02em; }
.hero-label { color: var(--text-2); font-size: 14px; margin-bottom: 4px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; margin-top: 16px; }
.tile { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; }
.tile-label { color: var(--text-2); font-size: 13px; }
.tile-value { font-size: 20px; font-weight: 650; }
.tile-value.compact { font-size: 16px; line-height: 1.5; }
.tile-sub { color: var(--muted); font-size: 12px; }

/* --- tables --- */
.table-wrap { overflow-x: auto; margin: 0 -16px; padding: 0 16px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-weight: 600; color: var(--text-2); font-size: 13px; padding: 6px 8px; border-bottom: 1px solid var(--grid); white-space: nowrap; }
td { padding: 8px; border-bottom: 1px solid var(--grid); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--surface-2); }
.day-head td { background: var(--surface-2); font-weight: 600; }

/* --- badges / flags --- */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 12px; padding: 2px 8px; border-radius: 999px;
  background: var(--surface-2); color: var(--text-2); white-space: nowrap;
}
.badge.bad { color: var(--text); box-shadow: inset 0 0 0 1px var(--bad); }
.badge.warn { color: var(--text); box-shadow: inset 0 0 0 1px var(--warn); }
.badge .ico { font-weight: 700; }
.badge.bad .ico { color: var(--bad); }
.badge.warn .ico { color: var(--warn-ink); }
.badge.score { font-weight: 650; color: var(--text); }
.flags { display: flex; flex-wrap: wrap; gap: 4px; }
.flag-list { list-style: none; margin: 0; padding: 0; }
.flag-list li { display: flex; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--grid); }
.flag-list li:last-child { border-bottom: 0; }
.flag-ico {
  flex: 0 0 22px; height: 22px; border-radius: 50%; display: grid; place-items: center;
  font-size: 13px; font-weight: 700; color: #fff;
}
.flag-ico.bad { background: var(--bad); }
.flag-ico.warn { background: var(--warn); color: #0b0b0b; }
.flag-ico.info { background: var(--axis); color: var(--text); }

/* --- forms --- */
label { display: block; font-size: 13px; color: var(--text-2); margin-bottom: 4px; font-weight: 500; }
input[type=text], input[type=password], input[type=number], input[type=date], input[type=tel], select, textarea {
  width: 100%; font: inherit; font-size: 16px; color: var(--text);
  background: var(--surface); border: 1px solid var(--axis); border-radius: 8px; padding: 8px 10px;
}
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
.field { margin-bottom: 12px; min-width: 0; }
.fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 0 12px; }
.hint { font-size: 12px; color: var(--muted); margin-top: 3px; }
.checks { display: flex; flex-wrap: wrap; gap: 6px; }
.checks label {
  display: inline-flex; align-items: center; gap: 6px; margin: 0; padding: 4px 10px;
  border: 1px solid var(--axis); border-radius: 999px; cursor: pointer; font-size: 13px; color: var(--text);
}
.checks input { margin: 0; }
.checks label:has(input:checked) { background: var(--surface-2); border-color: var(--text-2); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font: inherit; font-size: 15px; font-weight: 600; cursor: pointer;
  padding: 9px 16px; border-radius: 10px; border: 1px solid transparent;
  background: var(--accent); color: #fff; text-decoration: none;
}
.btn:hover { filter: brightness(1.06); text-decoration: none; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; filter: none; }
.btn.secondary { background: var(--surface); color: var(--text); border-color: var(--axis); }
.btn.danger { background: var(--surface); color: var(--neg-text); border-color: var(--axis); }
.btn.small { padding: 5px 10px; font-size: 13px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.inline { display: inline; }

.spinner {
  width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid currentColor; border-right-color: transparent;
  animation: spin 0.8s linear infinite; display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* --- facts --- */
.facts { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px 16px; }
.fact-label { font-size: 12px; color: var(--muted); }
.fact-value { font-weight: 600; }

/* --- review --- */
.review-head { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
.score-ring {
  width: 64px; height: 64px; border-radius: 50%; display: grid; place-items: center;
  font-size: 26px; font-weight: 700; background: var(--surface-2);
  box-shadow: inset 0 0 0 3px var(--accent);
}
.score-ring small { font-size: 11px; font-weight: 500; color: var(--muted); }
.cats { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; margin: 16px 0; }
.cat { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; }
.cat-head { display: flex; justify-content: space-between; font-weight: 600; margin-bottom: 4px; }
.meter { height: 6px; background: var(--grid); border-radius: 3px; margin-bottom: 6px; overflow: hidden; }
.meter > span { display: block; height: 100%; background: var(--accent); border-radius: 3px; }
.review ul { margin: 4px 0 12px; padding-left: 20px; }
.review li { margin-bottom: 4px; }
.lesson { border-left: 3px solid var(--accent); padding: 8px 12px; background: var(--surface-2); border-radius: 0 8px 8px 0; margin: 12px 0; }
details > summary { cursor: pointer; color: var(--text-2); }

/* --- screenshots --- */
.shots { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; }
.shot { border: 1px solid var(--border); border-radius: 10px; overflow: hidden; background: var(--surface-2); }
.shot img { width: 100%; height: 120px; object-fit: cover; display: block; }
.shot .cap { padding: 6px 8px; font-size: 12px; display: flex; justify-content: space-between; gap: 6px; align-items: center; }

/* --- charts --- */
.chart { position: relative; width: 100%; height: 240px; }
.chart.short { height: 180px; }
.chart svg { display: block; width: 100%; height: 100%; overflow: visible; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .baseline { stroke: var(--axis); stroke-width: 1; }
.chart .tick { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .line { fill: none; stroke: var(--gain); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .area { fill: var(--wash-gain); }
.chart .bar-gain { fill: var(--gain); }
.chart .bar-loss { fill: var(--loss); }
.chart .crosshair { stroke: var(--axis); stroke-width: 1; }
.chart .dot { fill: var(--gain); stroke: var(--surface); stroke-width: 2; }
.chart .hit { fill: transparent; }
.chart .dim { opacity: 0.45; }
.tooltip {
  position: absolute; pointer-events: none; z-index: 5;
  background: var(--surface); border: 1px solid var(--border); box-shadow: 0 4px 16px rgba(0,0,0,0.12);
  border-radius: 8px; padding: 6px 10px; font-size: 13px; white-space: nowrap;
}
.tooltip .tt-title { color: var(--text-2); font-size: 12px; }
.tooltip .tt-value { font-weight: 650; font-variant-numeric: tabular-nums; }
.legend { display: flex; gap: 12px; font-size: 12px; color: var(--text-2); margin-top: 6px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 4px; vertical-align: -1px; }
.legend .k-gain { background: var(--gain); }
.legend .k-loss { background: var(--loss); }

/* --- login --- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 360px; }

/* --- sync --- */
.status-box { border-radius: 10px; background: var(--surface-2); padding: 14px; display: flex; gap: 12px; align-items: center; }
.progress { height: 6px; background: var(--grid); border-radius: 3px; overflow: hidden; margin-top: 8px; }
.progress > span { display: block; height: 100%; background: var(--accent); width: 0; transition: width 0.3s; }
.warning-box { border-left: 4px solid var(--warn); background: var(--surface-2); padding: 10px 14px; border-radius: 0 10px 10px 0; margin-bottom: 16px; font-size: 14px; }

.empty { text-align: center; padding: 40px 16px; }
.empty h2 { font-size: 20px; }
ol.steps { padding-left: 20px; }
ol.steps li { margin-bottom: 6px; }
