:root {
  color-scheme: light;
  --bg: #f4f4f2;
  --surface: #fcfcfb;
  --border: #e3e2de;
  --grid: #ecebe7;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #7a7974;
  --accent: #eb6834;
  --accent-ink: #b8461a;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --good: #13804e;
  --bad: #c43c3b;
  --warn: #a35f00;
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #111110;
    --surface: #1a1a19;
    --border: #2d2c2a;
    --grid: #262624;
    --text: #f0efec;
    --text-2: #c3c2b7;
    --muted: #8f8e88;
    --accent: #d95926;
    --accent-ink: #f08a5d;
    --series-1: #3987e5;
    --series-2: #d95926;
    --good: #4fbf85;
    --bad: #e66767;
    --warn: #e0a032;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111110; --surface: #1a1a19; --border: #2d2c2a; --grid: #262624;
  --text: #f0efec; --text-2: #c3c2b7; --muted: #8f8e88;
  --accent: #d95926; --accent-ink: #f08a5d;
  --series-1: #3987e5; --series-2: #d95926; --good: #4fbf85; --bad: #e66767; --warn: #e0a032;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
.wrap { max-width: 1120px; margin: 0 auto; padding: 20px 16px 64px; }
h1 { font-size: 22px; margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 15px; margin: 0 0 12px; font-weight: 600; }
a { color: var(--accent-ink); }
.muted { color: var(--muted); }
.small { font-size: 13px; }

header.top {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  margin-bottom: 18px;
}
header.top .brand { display: flex; align-items: center; gap: 10px; flex: 1 1 auto; min-width: 0; }
.logo {
  width: 30px; height: 30px; border-radius: 8px; background: var(--accent);
  display: grid; place-items: center; flex: none;
}
.logo svg { width: 18px; height: 18px; }
.sync-status { font-size: 13px; color: var(--muted); }
.sync-status.err { color: var(--bad); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

button, .btn {
  font: inherit; font-size: 14px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  border-radius: 8px; padding: 7px 12px; line-height: 1.2;
}
button:hover { border-color: var(--muted); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button:disabled { opacity: .55; cursor: default; }
input[type=text], input[type=email], input[type=password], input[type=number] {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; width: 100%;
}
input:focus-visible, button:focus-visible { outline: 2px solid var(--series-1); outline-offset: 1px; }

.filters {
  display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: center; margin-bottom: 16px;
}
.seg { display: inline-flex; background: var(--surface); border: 1px solid var(--border); border-radius: 9px; padding: 2px; flex-wrap: wrap; }
.seg button { border: 0; background: transparent; padding: 6px 11px; border-radius: 7px; color: var(--text-2); }
.seg button[aria-pressed="true"] { background: var(--text); color: var(--surface); font-weight: 600; }
.mindist { display: inline-flex; align-items: center; gap: 6px; color: var(--text-2); font-size: 14px; }
.mindist input { width: 72px; padding: 6px 8px; }

.tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 12px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; min-width: 0; }
.tile .label { font-size: 13px; color: var(--text-2); }
.tile .value { font-size: 28px; font-weight: 650; letter-spacing: -0.02em; margin-top: 2px; font-variant-numeric: tabular-nums; }
.tile .value .unit { font-size: 14px; font-weight: 500; color: var(--muted); margin-left: 3px; }
.tile .sub { font-size: 13px; color: var(--muted); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.delta { font-weight: 600; }
.delta.good { color: var(--good); }
.delta.bad { color: var(--bad); }

.grid2 { display: grid; grid-template-columns: 3fr 2fr; gap: 12px; margin-bottom: 12px; }
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: 280px; overflow: visible; }
.chart .axis text { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.legend { display: flex; gap: 14px; font-size: 13px; color: var(--text-2); margin: -4px 0 8px; flex-wrap: wrap; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { display: inline-block; }
.legend i.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--series-1); }
.legend i.line { width: 14px; height: 2px; background: var(--series-2); border-radius: 1px; }

.tooltip {
  position: absolute; pointer-events: none; z-index: 5;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 10px; font-size: 12px; box-shadow: 0 4px 16px rgb(0 0 0 / .12);
  min-width: 150px; max-width: 240px; opacity: 0; transition: opacity .08s;
}
.tooltip.show { opacity: 1; }
.tooltip .tt-title { color: var(--text-2); margin-bottom: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tooltip .tt-row { display: flex; align-items: center; gap: 6px; }
.tooltip .tt-row b { font-variant-numeric: tabular-nums; }
.tooltip .tt-row i { width: 10px; height: 2px; border-radius: 1px; flex: none; }
.tooltip .tt-row .lbl { color: var(--muted); }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-weight: 500; color: var(--muted); font-size: 12px; padding: 6px 8px; border-bottom: 1px solid var(--border); white-space: nowrap; }
td { padding: 8px; border-bottom: 1px solid var(--grid); font-variant-numeric: tabular-nums; white-space: nowrap; }
td.name { white-space: normal; min-width: 160px; }
tr:last-child td { border-bottom: 0; }
th.num, td.num { text-align: right; }
.table-scroll { overflow-x: auto; margin: 0 -8px; }
.more { margin-top: 10px; }

.empty { text-align: center; padding: 48px 16px; }
.empty p { color: var(--text-2); max-width: 460px; margin: 8px auto 18px; }

dialog {
  border: 1px solid var(--border); border-radius: 14px; background: var(--surface); color: var(--text);
  padding: 0; width: min(520px, calc(100vw - 32px)); max-height: calc(100vh - 32px);
}
dialog::backdrop { background: rgb(0 0 0 / .35); }
dialog .dlg-body { padding: 20px; }
dialog section + section { border-top: 1px solid var(--border); margin-top: 18px; padding-top: 18px; }
dialog form > * + * { margin-top: 10px; }
dialog .row { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.msg { font-size: 13px; min-height: 1em; }
.msg.err { color: var(--bad); }
.msg.ok { color: var(--good); }
.pill { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 99px; border: 1px solid var(--border); color: var(--text-2); }
.pill.on { border-color: var(--good); color: var(--good); }

.loading { opacity: .5; transition: opacity .15s; }

@media (max-width: 860px) {
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid2 { grid-template-columns: 1fr; }
  .chart svg { height: 240px; }
}
@media (max-width: 420px) {
  .tile .value { font-size: 23px; }
  .card { padding: 14px; }
}

textarea {
  font: 12px/1.4 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; width: 100%; resize: vertical;
}
details { margin-top: 12px; }
summary { cursor: pointer; font-size: 14px; color: var(--accent-ink); }
.steps { padding-left: 20px; color: var(--text-2); }
.steps li + li { margin-top: 6px; }
.steps code { font-size: 12px; background: var(--bg); border: 1px solid var(--border); border-radius: 5px; padding: 1px 5px; word-break: break-all; }
button.mini { font-size: 12px; padding: 2px 8px; margin-left: 4px; }

.grid2.even { grid-template-columns: 1fr 1fr; }
.note { font-size: 13px; color: var(--muted); margin: -6px 0 10px; }
.legend i.dot.prev { background: var(--muted); opacity: .6; }
.legend i.line.l1 { background: var(--series-1); }
.legend i.line.l0 { background: var(--muted); }
@media (max-width: 860px) { .grid2.even { grid-template-columns: 1fr; } }

tr.excluded td { color: var(--muted); }
tr.excluded td.name a { color: var(--muted); text-decoration: line-through; }
.flag { font-size: 12px; color: var(--bad); margin-top: 2px; }
.flag.ok { color: var(--muted); }

.hr-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.hr-row label { display: grid; gap: 4px; color: var(--text-2); }

.goal { margin-bottom: 12px; }
.goal-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.goal-head h2 { margin-bottom: 8px; }
.goal-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.goal-item { min-width: 0; }
.goal-item .label { font-size: 13px; color: var(--text-2); }
.goal-item .value { font-size: 28px; font-weight: 650; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.goal-item .value .unit { font-size: 14px; font-weight: 500; color: var(--muted); margin-left: 3px; }
.goal-item .sub { font-size: 13px; color: var(--muted); }
.chip { font-weight: 600; }
.chip.good { color: var(--good); }
.chip.warn { color: var(--warn); }
.legend i.bar { width: 10px; height: 10px; border-radius: 2px; background: var(--series-1); }
.legend i.dash { width: 16px; height: 0; border-top: 2px dashed var(--text-2); }
.chart .hline-label { fill: var(--text-2); font-size: 11px; font-weight: 600; paint-order: stroke; stroke: var(--surface); stroke-width: 3px; }
.barhit:focus { outline: none; }
.barhit:hover .bar, .barhit:focus .bar { filter: brightness(1.15); }
#chartWeeks svg { height: 200px; }
.hr-row { grid-template-columns: repeat(2, 1fr); }
@media (max-width: 700px) { .goal-grid { grid-template-columns: 1fr; } }

/* horizontal finger drags scrub the chart; vertical drags still scroll the page */
.chart svg { touch-action: pan-y; -webkit-tap-highlight-color: transparent; }
