:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --border: #e3e5ea;
  --text: #13161b;
  --text-2: #555b66;
  --muted: #8a909b;
  --accent: #1668e8;
  --accent-soft: #e8f0fd;
  --danger: #d33a3a;
  --warn: #e08a00;
  --ok: #1a9a62;
  --hr: #e0393e;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1115;
    --surface: #181b21;
    --surface-2: #1f232a;
    --border: #2b3038;
    --text: #f1f3f6;
    --text-2: #b7bcc6;
    --muted: #858c98;
    --accent: #4d8ff5;
    --accent-soft: #1b2a44;
    --shadow: none;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
h1 { font-size: 1.5rem; margin: 0 0 4px; }
h2 { font-size: 1.1rem; margin: 0 0 12px; }
h3 { font-size: .95rem; margin: 0 0 8px; }
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.num { font-variant-numeric: tabular-nums; }
.container { max-width: 1100px; margin: 0 auto; padding: 16px 16px 120px; }

/* top bar */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
  background: #0f2a5c; color: #fff;
}
.brand { display: flex; align-items: center; gap: 10px; color: #fff; font-weight: 700; letter-spacing: .2px; }
.brand img { border-radius: 7px; }
.topbar-right { display: flex; align-items: center; gap: 8px; }
.icon-btn { color: #fff; font-size: 1.25rem; padding: 4px 8px; border-radius: 8px; }
.icon-btn:hover { background: rgba(255, 255, 255, .12); }
.sensor-chip {
  display: flex; align-items: center; gap: 6px;
  background: rgba(255, 255, 255, .12); color: #fff; border: 0; border-radius: 999px;
  padding: 6px 12px; font: inherit; font-size: .85rem; cursor: pointer;
}
.sensor-chip .heart { color: #9aa6bd; }
.sensor-chip.connected .heart { color: #ff6b6f; animation: beat 1s infinite; }
@keyframes beat { 0%, 100% { transform: scale(1); } 15% { transform: scale(1.25); } }

/* layout */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin: 8px 0 16px; flex-wrap: wrap; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow); min-width: 0;
}
.card + .card { margin-top: 16px; }
.grid > .card + .card { margin-top: 0; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.spacer { flex: 1; }
.stack > * + * { margin-top: 10px; }

/* buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 600; font-size: .92rem;
  padding: 9px 14px; border-radius: 10px; cursor: pointer; min-height: 40px;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { color: var(--danger); }
.btn.warn { background: var(--warn); border-color: var(--warn); color: #fff; }
.btn.big { min-height: 56px; font-size: 1.05rem; padding: 12px 20px; border-radius: 14px; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn:disabled { opacity: .5; cursor: default; }
.btn.small { min-height: 32px; padding: 5px 10px; font-size: .82rem; }

/* forms */
label.field { display: block; }
label.field > span { display: block; font-size: .8rem; font-weight: 600; color: var(--text-2); margin-bottom: 4px; }
input, select, textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 10px; padding: 9px 11px; min-height: 40px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
textarea { min-height: 70px; resize: vertical; }
.form-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.seg button { border: 0; background: transparent; font: inherit; font-size: .85rem; font-weight: 600; color: var(--text-2); padding: 6px 12px; border-radius: 8px; cursor: pointer; }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

/* lists & tables */
.list { list-style: none; margin: 0; padding: 0; }
.list-item {
  display: flex; align-items: center; gap: 12px; padding: 12px 4px; border-bottom: 1px solid var(--border);
  color: inherit; cursor: pointer;
}
.list-item:last-child { border-bottom: 0; }
.list-item:hover { background: var(--surface-2); }
.avatar {
  width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent); font-weight: 700; flex: none;
}
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: .75rem; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); font-weight: 600; }
td.r, th.r { text-align: right; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--surface-2); }
.table-wrap { overflow-x: auto; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; vertical-align: middle; }
.tag { display: inline-block; font-size: .7rem; font-weight: 700; padding: 1px 6px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); margin-left: 4px; }
.tag.demo { background: #fff0db; color: #a45b00; }
.zone-badge { display: inline-grid; place-items: center; width: 34px; height: 30px; border-radius: 7px; color: #fff; font-weight: 700; font-size: .85rem; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; font-size: .8rem; font-weight: 600;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 999px; padding: 4px 10px; cursor: pointer;
}
.chip.off { opacity: .4; }
.chip:disabled { opacity: .25; cursor: default; }
.empty { text-align: center; padding: 40px 16px; }
.chart-box { position: relative; height: 320px; }
.chart-box.short { height: 220px; }
.chart-box.tiny { height: 170px; }

/* live test */
.live-top { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.hr-big { font-size: 5.2rem; font-weight: 800; line-height: 1; color: var(--hr); font-variant-numeric: tabular-nums; letter-spacing: -2px; }
.hr-big.none { color: var(--muted); }
.timer-big { font-size: 4.2rem; font-weight: 700; line-height: 1; font-variant-numeric: tabular-nums; letter-spacing: -1px; }
.timer-big.over { color: var(--warn); }
.progress { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin: 10px 0; }
.progress > div { height: 100%; background: var(--accent); width: 0; transition: width .25s linear; }
.progress.over > div { background: var(--warn); }
.intensity-ctl { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.intensity-ctl .val { font-size: 1.5rem; font-weight: 700; text-align: center; font-variant-numeric: tabular-nums; }
.round-btn { width: 48px; height: 48px; border-radius: 50%; border: 1px solid var(--border); background: var(--surface-2); font-size: 1.6rem; color: var(--accent); cursor: pointer; }
.bottom-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 15;
  background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(10px);
  border-top: 1px solid var(--border); padding: 12px 16px; padding-bottom: max(12px, env(safe-area-inset-bottom));
}
.bottom-bar .inner { max-width: 1100px; margin: 0 auto; display: flex; gap: 12px; }
.bottom-bar .inner .btn { flex: 1; }
.pulse { animation: pulse 1s infinite; }
@keyframes pulse { 50% { filter: brightness(1.2); } }
.warn-box { background: #fff4e0; color: #7a4a00; border: 1px solid #f3d29a; border-radius: 10px; padding: 10px 12px; font-size: .88rem; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .warn-box { background: #3a2a10; color: #f6d9a8; border-color: #5a4217; } }

/* modal */
.modal-backdrop { position: fixed; inset: 0; background: rgba(10, 14, 22, .45); z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
@media (min-width: 700px) { .modal-backdrop { align-items: center; } }
.modal {
  background: var(--surface); width: 100%; max-width: 560px; max-height: 92vh; overflow: auto;
  border-radius: 18px 18px 0 0; padding: 18px; box-shadow: 0 10px 40px rgba(0, 0, 0, .25);
}
@media (min-width: 700px) { .modal { border-radius: 18px; } }
.modal h2 { margin-bottom: 14px; }
.modal .actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 16px; flex-wrap: wrap; }
.lactate-input { font-size: 2rem; font-weight: 700; text-align: center; min-height: 64px; }
.rpe-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }
.rpe-grid button { border: 1px solid var(--border); background: var(--surface-2); border-radius: 8px; padding: 8px 0; font: inherit; font-weight: 700; cursor: pointer; color: var(--text); }
.rpe-grid button.on { background: var(--accent); color: #fff; border-color: var(--accent); }

.toast {
  position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%) translateY(20px);
  background: #1d2430; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: .9rem;
  opacity: 0; pointer-events: none; transition: all .2s; z-index: 60; max-width: 90vw;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { background: var(--danger); }

.auth { max-width: 380px; margin: 60px auto; }

/* print report */
.report { display: none; }
@media print {
  @page { size: A4; margin: 14mm; }
  body { background: #fff; color: #000; font-size: 10.5pt; }
  .topbar, .no-print, .bottom-bar, #modalRoot, .toast { display: none !important; }
  .container { max-width: none; padding: 0; }
  .card { box-shadow: none; border: 0; padding: 0; }
  .report { display: block; }
  .screen-only { display: none !important; }
  .page-break { break-before: page; }
  .chart-box { height: 300px; }
  .chart-box.short { height: 200px; }
  th, td { padding: 4px 5px; }
}
