:root {
  --bg: #f4f6f5;
  --surface: #ffffff;
  --surface-2: #eef2f1;
  --text: #15201d;
  --muted: #64716d;
  --border: #dde3e1;
  --accent: #0f766e;
  --accent-strong: #0b5f58;
  --accent-soft: #d6efec;
  --on-accent: #ffffff;
  --danger: #c2410c;
  --danger-soft: #fdeee6;
  --ok: #15803d;
  --shadow: 0 1px 2px rgb(16 24 22 / 0.06), 0 2px 8px rgb(16 24 22 / 0.04);
  --radius: 14px;
  --nav-h: 64px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1412;
    --surface: #161e1b;
    --surface-2: #1f2925;
    --text: #e7eeeb;
    --muted: #93a29d;
    --border: #2b3632;
    --accent: #2dd4bf;
    --accent-strong: #5eead4;
    --accent-soft: #123f3a;
    --on-accent: #062925;
    --danger: #fb923c;
    --danger-soft: #3a2116;
    --ok: #4ade80;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 Inter, system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
}
body.modal-open { overflow: hidden; }
a { color: var(--accent); text-decoration: none; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 24px; font-weight: 700; letter-spacing: -0.01em; }
h2 { font-size: 18px; font-weight: 600; }
h3 { font-size: 15px; font-weight: 600; margin-bottom: 8px; }
p { margin: 0 0 10px; }
code { background: var(--surface-2); padding: 1px 6px; border-radius: 6px; font-size: 13px; }

.muted { color: var(--muted); }
.small { font-size: 13px; }
.pad { padding: 12px 4px; }
.pre { white-space: pre-wrap; }
.grow { flex: 1; min-width: 0; }
.spacer { flex: 1; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.row-gap { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- Layout ---------- */
.boot { min-height: 100vh; display: grid; place-items: center; color: var(--muted); }
.shell { min-height: 100vh; }
.main {
  max-width: 860px;
  margin: 0 auto;
  padding: 16px 16px calc(var(--nav-h) + 32px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.brand { font-weight: 700; font-size: 18px; color: var(--text); letter-spacing: -0.01em; }
.brand span { color: var(--accent); margin-left: 4px; font-weight: 600; }
.brand-lg { font-size: 26px; margin-bottom: 4px; }

/* Mobile: bottom tab bar */
.sidebar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface);
  border-top: 1px solid var(--border);
}
.sidebar .brand, .sidebar-foot { display: none; }
.nav-links { display: flex; height: var(--nav-h); }
.nav-link {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; color: var(--muted); font-size: 12px; font-weight: 500;
}
.nav-link.active { color: var(--accent); }
.nav-icon { font-size: 20px; line-height: 1; }

/* Desktop: sidebar */
@media (min-width: 900px) {
  .sidebar {
    top: 0; right: auto; width: 230px; height: auto; padding: 22px 14px;
    border-top: 0; border-right: 1px solid var(--border);
    display: flex; flex-direction: column; gap: 22px;
  }
  .sidebar .brand { display: block; padding: 0 10px; }
  .nav-links { flex-direction: column; height: auto; gap: 4px; }
  .nav-link {
    flex: none; flex-direction: row; justify-content: flex-start; gap: 10px;
    padding: 10px 12px; border-radius: 10px; font-size: 15px; color: var(--text);
  }
  .nav-link:hover { background: var(--surface-2); }
  .nav-link.active { background: var(--accent-soft); color: var(--accent-strong); }
  .nav-icon { font-size: 17px; }
  .sidebar-foot { display: flex; flex-direction: column; gap: 8px; margin-top: auto; padding: 0 10px; }
  .main { margin-left: 230px; padding: 32px 40px 48px; max-width: 980px; }
  @supports (margin-left: max(0px)) {
    .main { margin-left: max(230px, calc(230px + (100vw - 230px - 980px) / 2)); }
  }
}

/* ---------- Header ---------- */
.page-header { display: flex; flex-direction: column; gap: 6px; }
.page-header-row { display: flex; align-items: flex-start; gap: 12px; justify-content: space-between; flex-wrap: wrap; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.back { font-size: 14px; font-weight: 500; }
.title-with-avatar { display: inline-flex; align-items: center; gap: 12px; }
.title-input {
  font: inherit; color: inherit; border: 1px solid transparent; background: transparent;
  border-radius: 8px; padding: 2px 6px; margin-left: -7px; width: 100%; max-width: 520px;
}
.title-input:hover, .title-input:focus { border-color: var(--border); background: var(--surface); outline: none; }
.notice { background: var(--accent-soft); color: var(--accent-strong); padding: 8px 12px; border-radius: 10px; font-size: 13px; }

/* ---------- Cards & lists ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow);
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 6px; }
.card-head h3 { margin: 0; }
.card-list { display: flex; flex-direction: column; gap: 8px; }
.row-card {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px; color: var(--text);
  text-align: left; width: 100%; font: inherit; cursor: pointer;
}
.row-card:hover { border-color: var(--accent); }
.row-title { font-weight: 600; }
.chev { color: var(--muted); font-size: 22px; line-height: 1; }
.avatar {
  width: 40px; height: 40px; border-radius: 50%; flex: none;
  display: grid; place-items: center; font-weight: 600; font-size: 14px;
  background: var(--accent-soft); color: var(--accent-strong);
}
.avatar-lg { width: 48px; height: 48px; font-size: 17px; }
.video-dot { color: var(--accent); font-size: 11px; margin-left: 4px; }
.date-badge {
  width: 46px; flex: none; text-align: center; border-radius: 10px; padding: 4px 0;
  background: var(--surface-2); line-height: 1.1;
}
.date-badge span { display: block; font-weight: 700; font-size: 17px; }
.date-badge small { color: var(--muted); font-size: 11px; text-transform: uppercase; }

.info-card { display: flex; flex-direction: column; gap: 14px; }
.info-grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.label { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 2px; }

.empty {
  text-align: center; padding: 36px 20px; border: 1.5px dashed var(--border); border-radius: var(--radius);
  display: flex; flex-direction: column; align-items: center; gap: 6px;
}
.empty-title { font-weight: 600; font-size: 17px; }
.empty .row-gap { justify-content: center; }

.tags { display: flex; gap: 6px; flex-wrap: wrap; }
.tag { font-size: 12px; font-weight: 600; padding: 3px 10px; border-radius: 999px; background: var(--accent-soft); color: var(--accent-strong); }
.tag-soft { background: var(--surface-2); color: var(--muted); }

/* ---------- Tabs, chips, filters ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); overflow-x: auto; }
.tab {
  font: inherit; font-weight: 500; background: none; border: 0; color: var(--muted); cursor: pointer;
  padding: 10px 12px; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap;
}
.tab.on { color: var(--accent); border-bottom-color: var(--accent); }
.filters { display: flex; flex-direction: column; gap: 10px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  font: inherit; font-size: 13px; font-weight: 500; padding: 5px 12px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
}
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }

/* ---------- Forms ---------- */
input, select, textarea {
  font: inherit; font-size: 16px; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
textarea { resize: vertical; }
.search { background: var(--surface); }
.form { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field-label { font-size: 13px; font-weight: 600; }
.field-hint { font-size: 12px; color: var(--muted); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding-top: 4px; }
.form-error { color: var(--danger); font-size: 14px; }
.switch { display: flex; align-items: center; gap: 8px; font-weight: 500; cursor: pointer; }
.switch input { width: 18px; height: 18px; accent-color: var(--accent); }

/* ---------- Buttons ---------- */
.btn {
  font: inherit; font-weight: 600; font-size: 14px; display: inline-flex; align-items: center; justify-content: center;
  gap: 6px; padding: 10px 16px; border-radius: 10px; cursor: pointer; white-space: nowrap;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
}
.btn:hover { border-color: var(--accent); }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn-primary:hover { background: var(--accent-strong); border-color: var(--accent-strong); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--accent); }
.btn-ghost:hover { background: var(--accent-soft); border-color: transparent; }
.btn-danger-ghost { background: transparent; border-color: transparent; color: var(--danger); }
.btn-danger-ghost:hover { background: var(--danger-soft); border-color: transparent; }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-block { width: 100%; }
.icon-btn {
  font: inherit; background: none; border: 0; cursor: pointer; color: var(--muted);
  width: 36px; height: 36px; border-radius: 8px; display: grid; place-items: center; flex: none; font-size: 16px;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn:disabled { opacity: 0.3; cursor: default; }
.icon-btn.sm { width: 28px; height: 24px; font-size: 10px; }
.link-btn { font: inherit; font-size: 14px; background: none; border: 0; color: var(--accent); cursor: pointer; padding: 0; text-align: left; }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 50; background: rgb(0 0 0 / 0.45);
  display: flex; align-items: flex-end; justify-content: center;
}
.modal {
  background: var(--surface); width: 100%; max-height: 92vh; overflow: auto;
  border-radius: 18px 18px 0 0; padding: 18px 16px calc(20px + env(safe-area-inset-bottom));
  animation: slide-up 0.18s ease-out;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; }
.modal-body { display: flex; flex-direction: column; gap: 12px; }
@keyframes slide-up { from { transform: translateY(24px); opacity: 0; } }
@media (min-width: 640px) {
  .modal-backdrop { align-items: center; padding: 24px; }
  .modal { max-width: 520px; border-radius: 18px; padding: 22px 24px; }
  .modal-wide { max-width: 640px; }
}

.pick-list { display: flex; flex-direction: column; gap: 4px; max-height: 55vh; overflow: auto; }
.pick-item {
  font: inherit; text-align: left; display: flex; flex-direction: column; gap: 1px; cursor: pointer;
  background: none; border: 1px solid transparent; border-radius: 10px; padding: 10px 12px; color: var(--text);
}
.pick-item:hover { background: var(--surface-2); border-color: var(--border); }
.pick-name { font-weight: 600; }

.media { border-radius: 12px; overflow: hidden; background: #000; aspect-ratio: 16 / 9; }
.media iframe, .media img { width: 100%; height: 100%; border: 0; object-fit: contain; display: block; }

/* ---------- Routine editor ---------- */
.routine-meta { display: flex; flex-direction: column; gap: 12px; }
.notes-input { font-size: 14px; }
.days { display: grid; gap: 14px; }
@media (min-width: 1100px) { .days { grid-template-columns: 1fr 1fr; align-items: start; } }
.day { display: flex; flex-direction: column; gap: 8px; }
.day-head { display: flex; align-items: center; gap: 6px; }
.day-name {
  font-size: 17px; font-weight: 700; border-color: transparent; background: transparent; padding: 4px 6px; margin-left: -6px;
}
.day-name:hover { border-color: var(--border); }
.ex-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.ex-item { display: flex; align-items: center; gap: 10px; background: var(--surface-2); border-radius: 12px; padding: 8px 6px 8px 10px; }
.ex-num {
  width: 24px; height: 24px; border-radius: 50%; background: var(--surface); flex: none;
  display: grid; place-items: center; font-size: 12px; font-weight: 700; color: var(--muted);
}
.ex-main {
  flex: 1; min-width: 0; font: inherit; text-align: left; background: none; border: 0; padding: 0;
  color: var(--text); cursor: pointer; display: flex; flex-direction: column; gap: 3px;
}
.ex-specs { display: flex; gap: 6px; flex-wrap: wrap; }
.spec { font-size: 12px; background: var(--surface); border-radius: 6px; padding: 1px 8px; color: var(--muted); }
.spec b { color: var(--text); }
.ex-move { display: flex; flex-direction: column; }
.add-day {
  font: inherit; font-weight: 600; color: var(--accent); cursor: pointer; border-style: dashed;
  background: transparent; box-shadow: none; padding: 18px; width: 100%;
}
.add-day:hover { background: var(--accent-soft); }
.danger-zone { display: flex; justify-content: flex-end; padding-top: 8px; }

/* ---------- Session logger ---------- */
.logger { display: flex; flex-direction: column; gap: 14px; }
.block { display: flex; flex-direction: column; gap: 10px; }
.block-head { display: flex; gap: 6px; align-items: flex-start; }
.prev { color: var(--accent-strong); margin-top: 2px; }
.sets { display: flex; flex-direction: column; gap: 6px; }
.set-row { display: grid; grid-template-columns: 40px 1fr 1fr 48px; gap: 8px; align-items: center; }
.set-row input { text-align: center; font-weight: 600; padding: 10px 6px; }
.set-head { font-size: 12px; font-weight: 600; color: var(--muted); text-align: center; text-transform: uppercase; }
.set-num {
  font: inherit; font-weight: 700; color: var(--muted); background: var(--surface-2); border: 0;
  border-radius: 8px; height: 44px; cursor: pointer;
}
.check {
  height: 44px; border-radius: 10px; border: 1.5px solid var(--border); background: var(--surface);
  color: var(--muted); font-size: 18px; font-weight: 700; cursor: pointer;
}
.check.on { background: var(--ok); border-color: var(--ok); color: #fff; }
.set-row.done input { background: var(--surface-2); }
.save-bar {
  position: sticky; bottom: calc(var(--nav-h) + 10px + env(safe-area-inset-bottom)); z-index: 10;
  display: flex; align-items: center; gap: 8px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 10px 12px; box-shadow: 0 6px 24px rgb(0 0 0 / 0.12);
}
.save-bar .muted { white-space: nowrap; }
@media (min-width: 900px) { .save-bar { bottom: 16px; } }
.rest-timer {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 30;
  top: calc(12px + env(safe-area-inset-top)); width: min(420px, calc(100% - 32px));
  background: var(--text); color: var(--bg); border-radius: 14px; padding: 10px 8px 10px 16px;
  display: flex; align-items: center; justify-content: space-between; overflow: hidden;
  font-weight: 700; font-size: 17px; box-shadow: 0 8px 30px rgb(0 0 0 / 0.25);
}
.rest-timer .icon-btn { color: inherit; }
.rest-timer.over { background: var(--ok); color: #fff; }
.rest-bar { position: absolute; left: 0; bottom: 0; height: 4px; background: var(--accent); transition: width 0.25s linear; }

/* ---------- Session view & progress ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; }
.stat { padding: 12px 14px; }
.stat-num { font-size: 22px; font-weight: 700; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; margin-top: 6px; }
.table th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; padding: 6px 8px; border-bottom: 1px solid var(--border); }
.table td { padding: 8px; border-bottom: 1px solid var(--border); }
.table tr:last-child td { border-bottom: 0; }
.chart { width: 100%; height: auto; display: block; margin-top: 6px; }
.chart .grid-line { stroke: var(--border); stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 11px; }
.chart .line { fill: none; stroke: var(--accent); stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; }
.chart .dot { fill: var(--surface); stroke: var(--accent); stroke-width: 2.5; }
.card-head select { width: auto; max-width: 100%; font-size: 14px; padding: 6px 10px; }

/* ---------- Feedback ---------- */
.spinner {
  width: 28px; height: 28px; margin: 40px auto; border-radius: 50%;
  border: 3px solid var(--border); border-top-color: var(--accent); animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.error-box { background: var(--danger-soft); color: var(--text); border-radius: var(--radius); padding: 14px 16px; display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.toasts {
  position: fixed; z-index: 60; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--nav-h) + 16px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 8px; width: min(420px, calc(100% - 32px));
}
.toast { background: var(--text); color: var(--bg); padding: 12px 16px; border-radius: 12px; font-weight: 500; font-size: 14px; box-shadow: 0 6px 24px rgb(0 0 0 / 0.2); }
.toast-error { background: var(--danger); color: #fff; }
@media (min-width: 900px) { .toasts { bottom: 24px; left: auto; right: 24px; transform: none; } }

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login { width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 14px; padding: 28px 24px; }
