/* Paddle Power coach dashboard. Light by default for reading in sun; dark follows the
   phone setting or the toggle. Series colours are the validated categorical slots. */

:root {
  color-scheme: light;
  --bg: #f3f3f1;
  --surface: #fcfcfb;
  --surface-2: #efefec;
  --line: #dcdbd6;
  --grid: #e6e5e1;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #74736e;
  --accent: #2a78d6;
  --live: #008300;
  --warn: #b26b00;
  --error: #c62f2e;
  --band: rgba(42, 120, 214, 0.08);
  --band-pick: rgba(42, 120, 214, 0.18);
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100;
  --s5: #e87ba4; --s6: #008300; --s7: #6250d6; --s8: #e34948;
  --speed: var(--s1); --power: var(--s2); --hr: var(--s8); --rate: var(--s7);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121211; --surface: #1a1a19; --surface-2: #242422; --line: #34342f; --grid: #2a2a27;
    --text: #f0efec; --text-2: #c3c2b7; --muted: #8f8e86; --accent: #3987e5; --live: #2fb32f;
    --warn: #e0a030; --error: #e66767;
    --band: rgba(57, 135, 229, 0.12); --band-pick: rgba(57, 135, 229, 0.28);
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
    --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121211; --surface: #1a1a19; --surface-2: #242422; --line: #34342f; --grid: #2a2a27;
  --text: #f0efec; --text-2: #c3c2b7; --muted: #8f8e86; --accent: #3987e5; --live: #2fb32f;
  --warn: #e0a030; --error: #e66767;
  --band: rgba(57, 135, 229, 0.12); --band-pick: rgba(57, 135, 229, 0.28);
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
  --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
button, select, input { font: inherit; color: inherit; }
b, .tile-v, td { font-variant-numeric: tabular-nums; }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: min(360px, 100%); background: var(--surface); border: 1px solid var(--line);
  border-radius: 14px; padding: 28px 24px; display: grid; gap: 10px;
}
.login-card h1 { font-size: 22px; margin: 4px 0 8px; }
.login-card label { font-size: 13px; color: var(--text-2); }
.login-card input {
  padding: 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg);
  font-size: 17px;
}
.error { color: var(--error); min-height: 1.4em; margin: 0; font-size: 14px; }

.brand { display: flex; align-items: center; gap: 8px; font-weight: 650; }
.logo {
  width: 22px; height: 22px; border-radius: 6px; background: var(--accent);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Cpath d='M6 21c4-6 8-6 10 0s6 6 10 0' stroke='white' stroke-width='3' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-size: cover;
}

button.primary {
  background: var(--accent); color: #fff; border: 0; border-radius: 10px; padding: 12px;
  font-weight: 600; cursor: pointer;
}
button.ghost {
  background: transparent; border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px;
  cursor: pointer; color: var(--text-2);
}
button.ghost:hover { background: var(--surface-2); }

/* Layout */
main { max-width: 1100px; margin: 0 auto; padding: 0 16px 32px; }
.topbar {
  display: flex; align-items: center; gap: 12px; padding: 12px 0;
  position: sticky; top: 0; background: var(--bg); z-index: 5;
}
.session-pick { flex: 1; min-width: 0; }
.session-pick select {
  width: 100%; padding: 7px 10px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--surface); text-overflow: ellipsis;
}
.top-actions { display: flex; gap: 6px; }

.status {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; padding: 4px 0 12px;
  color: var(--text-2); font-size: 14px;
}
.status .k { color: var(--muted); }
.status b { color: var(--text); }
.status-sep { flex: 0 0 0; }
.who { font-weight: 600; color: var(--text); }
.fresh { margin-left: auto; font-size: 13px; color: var(--muted); }
.fresh.stale { color: var(--warn); }
.pill {
  display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 650;
  padding: 3px 10px; border-radius: 99px; background: var(--surface-2); color: var(--text-2);
}
.pill.live { background: color-mix(in srgb, var(--live) 16%, transparent); color: var(--live); }
.pill.live::before {
  content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--live);
  animation: pulse 1.4s infinite;
}
@keyframes pulse { 50% { opacity: 0.3; } }

.tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 14px; }
.tile {
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  padding: 10px 14px 12px; display: grid; grid-template-columns: 1fr auto; align-items: baseline;
  position: relative; overflow: hidden;
}
.tile::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; }
.tile[data-series="speed"]::before { background: var(--speed); }
.tile[data-series="power"]::before { background: var(--power); }
.tile[data-series="hr"]::before { background: var(--hr); }
.tile[data-series="rate"]::before { background: var(--rate); }
.tile-k { grid-column: 1 / -1; font-size: 13px; color: var(--text-2); }
.tile-v { font-size: 40px; font-weight: 700; line-height: 1.1; letter-spacing: -0.02em; }
.tile-u { font-size: 14px; color: var(--muted); }

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
  padding: 14px 16px; margin-bottom: 14px;
}
.card-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin-bottom: 8px; }
.card-head h2 { font-size: 17px; margin: 0; margin-right: auto; }
h3 { font-size: 15px; margin: 18px 0 6px; }
.muted { color: var(--muted); font-size: 13px; }
.hint { color: var(--muted); font-size: 13px; margin: 8px 0 0; }

.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; }
.seg button {
  border: 0; background: transparent; padding: 6px 11px; cursor: pointer; color: var(--text-2);
  font-size: 13px; white-space: nowrap;
}
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--text); color: var(--surface); font-weight: 600; }
.controls { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }

/* Charts */
.live-charts { display: grid; gap: 2px; }
.chart-label {
  display: flex; align-items: baseline; gap: 8px; font-size: 13px; color: var(--text-2);
  margin: 6px 0 0 4px;
}
.chart-label .key { width: 14px; height: 2px; border-radius: 2px; display: inline-block; transform: translateY(-3px); }
.chart-label b { color: var(--text); }
.uplot { font-family: inherit; }
.uplot .u-legend { display: none; }
.u-select { background: var(--band-pick); }
.compare-chart { min-height: 300px; }
.compare-legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 13px; margin: 6px 0 0; }
.compare-legend span { display: inline-flex; align-items: center; gap: 6px; color: var(--text-2); }
.compare-legend i { width: 16px; height: 3px; border-radius: 2px; display: inline-block; }
.empty {
  display: grid; place-items: center; min-height: 200px; color: var(--muted); font-size: 14px;
  border: 1px dashed var(--line); border-radius: 10px; text-align: center; padding: 16px;
}

/* Tables */
.table-wrap { overflow-x: auto; margin: 0 -4px; }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { padding: 7px 8px; text-align: right; white-space: nowrap; }
th { font-size: 12px; font-weight: 600; color: var(--muted); border-bottom: 1px solid var(--line); }
th:nth-child(-n+2), td:nth-child(-n+2) { text-align: left; }
.starts th:first-child, .starts td:first-child { text-align: left; }
tbody tr { border-bottom: 1px solid var(--grid); }
.efforts tbody tr { cursor: pointer; }
.efforts tbody tr:hover { background: var(--surface-2); }
.efforts tbody tr.picked { background: var(--band); }
.efforts tbody tr.dim td { color: var(--muted); }
.c-pick { width: 28px; }
.swatch {
  width: 14px; height: 14px; border-radius: 4px; border: 1.5px solid var(--line);
  display: inline-block; vertical-align: middle;
}
.picked .swatch { border-color: transparent; }
.delta { font-size: 12px; margin-left: 4px; }
.delta.up { color: var(--live); }
.delta.down { color: var(--error); }
.ref-tag { font-size: 11px; color: var(--muted); margin-left: 4px; }
.row-actions { display: flex; gap: 8px; margin-top: 10px; }
.eff-name { display: inline-flex; align-items: center; gap: 6px; }
.eff-name i { width: 14px; height: 3px; border-radius: 2px; display: inline-block; }

.tooltip {
  position: fixed; z-index: 20; pointer-events: none; background: var(--surface);
  border: 1px solid var(--line); border-radius: 8px; padding: 6px 9px; font-size: 13px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.12); min-width: 110px;
}
.tooltip .tt-x { color: var(--muted); font-size: 12px; margin-bottom: 2px; }
.tooltip .tt-row { display: flex; align-items: center; gap: 6px; }
.tooltip .tt-row i { width: 12px; height: 2px; border-radius: 2px; flex: none; }
.tooltip .tt-row b { margin-right: 4px; }
.tooltip .tt-row span { color: var(--text-2); }

/* Tabs */
.tabs {
  display: flex; gap: 4px; margin: 0 0 12px; border-bottom: 1px solid var(--line);
  position: sticky; top: 56px; background: var(--bg); z-index: 4;
}
.tabs button {
  background: none; border: 0; border-bottom: 2px solid transparent; padding: 9px 14px 8px;
  font-weight: 600; color: var(--text-2); cursor: pointer; margin-bottom: -1px;
}
.tabs button.on { color: var(--text); border-bottom-color: var(--accent); }
.tab-count {
  font-size: 11px; background: var(--surface-2); border-radius: 99px; padding: 1px 6px;
  color: var(--text-2);
}
.tab-count:empty { display: none; }

/* Left and right */
:root { --left: var(--s1); --right: var(--s2); }
.k-left { background: var(--left); }
.k-right { background: var(--right); }
.inline-pick select {
  padding: 6px 9px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface);
  max-width: 100%;
}
.sides-table td:first-child, .sides-table th:first-child { text-align: left; color: var(--text-2); }
.sides-table td:nth-child(2), .sides-table th:nth-child(2) { text-align: right; }
.sides-table td b { font-weight: 650; }
.side-chart { margin-top: 10px; }
.side-mode-note { margin: 0 0 8px; }
.live-legend:empty { display: none; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line);
  background: var(--surface); border-radius: 99px; padding: 4px 10px; cursor: pointer;
  font-size: 13px; color: var(--text-2);
}
.chip i { width: 14px; height: 3px; border-radius: 2px; display: inline-block; }
.chip b { color: var(--text); }
.chip.off { opacity: 0.45; text-decoration: line-through; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px; margin: 12px 0; }
.stat {
  border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; background: var(--bg);
}
.stat .k { display: block; font-size: 12px; color: var(--muted); }
.stat b { font-size: 20px; }
.stat .u { font-size: 12px; color: var(--muted); margin-left: 3px; }

/* Change password */
.dialog { border: 0; padding: 0; background: transparent; max-width: calc(100vw - 32px); }
.dialog::backdrop { background: rgba(0, 0, 0, 0.45); }
.dialog .login-card { width: min(380px, calc(100vw - 32px)); }
.dialog .muted { margin: 0 0 4px; }
.ok-msg { color: var(--live); }

.foot { color: var(--muted); font-size: 12px; text-align: center; padding: 8px 0; }

@media (max-width: 720px) {
  .tiles { grid-template-columns: repeat(2, 1fr); }
  .tile-v { font-size: 34px; }
  .brand-name { display: none; }
  .card { padding: 12px; }
  .fresh { margin-left: 0; width: 100%; }
  .tabs { top: 52px; }
  .tabs button { padding: 9px 10px 8px; flex: 1; }
}
