/* ===== FitCore Home — design tokens ===== */
:root {
  color-scheme: light;
  --bg: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #ffffff;
  --surface-sunken: #f1f0ec;
  --border: rgba(11, 11, 11, 0.10);
  --border-strong: rgba(11, 11, 11, 0.16);
  --text: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --gridline: #e1e0d9;

  --accent: #eb6834;
  --accent-ink: #1a1005;
  --accent-wash: rgba(235, 104, 52, 0.12);

  --cat-strength: #2a78d6;
  --cat-strength-wash: rgba(42, 120, 214, 0.12);
  --cat-cardio: #eb6834;
  --cat-cardio-wash: rgba(235, 104, 52, 0.12);
  --cat-core: #b6790a;
  --cat-core-wash: rgba(237, 161, 0, 0.16);
  --cat-recovery: #158a5f;
  --cat-recovery-wash: rgba(27, 175, 122, 0.14);

  --good: #0ca30c;
  --good-wash: rgba(12, 163, 12, 0.12);
  --miss: #c0453d;
  --miss-wash: rgba(192, 69, 61, 0.12);

  --shadow-sm: 0 1px 2px rgba(11, 11, 11, 0.06);
  --shadow-md: 0 4px 16px rgba(11, 11, 11, 0.08);

  --font-display: "Vazirmatn", "Segoe UI", Tahoma, sans-serif;
  --font-body: "Vazirmatn", "Segoe UI", Tahoma, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #201f1d;
    --surface-sunken: #141413;
    --border: rgba(255, 255, 255, 0.10);
    --border-strong: rgba(255, 255, 255, 0.18);
    --text: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #93918a;
    --gridline: #2c2c2a;

    --accent: #e46f2e;
    --accent-ink: #180d02;
    --accent-wash: rgba(228, 111, 46, 0.18);

    --cat-strength: #3987e5;
    --cat-strength-wash: rgba(57, 135, 229, 0.18);
    --cat-cardio: #e46f2e;
    --cat-cardio-wash: rgba(228, 111, 46, 0.18);
    --cat-core: #d99a1a;
    --cat-core-wash: rgba(201, 133, 0, 0.20);
    --cat-recovery: #2bb385;
    --cat-recovery-wash: rgba(25, 158, 112, 0.20);

    --good: #35c235;
    --good-wash: rgba(53, 194, 53, 0.16);
    --miss: #e2685f;
    --miss-wash: rgba(226, 104, 95, 0.18);

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 6px 20px rgba(0, 0, 0, 0.35);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #201f1d;
  --surface-sunken: #141413;
  --border: rgba(255, 255, 255, 0.10);
  --border-strong: rgba(255, 255, 255, 0.18);
  --text: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #93918a;
  --gridline: #2c2c2a;

  --accent: #e46f2e;
  --accent-ink: #180d02;
  --accent-wash: rgba(228, 111, 46, 0.18);

  --cat-strength: #3987e5;
  --cat-strength-wash: rgba(57, 135, 229, 0.18);
  --cat-cardio: #e46f2e;
  --cat-cardio-wash: rgba(228, 111, 46, 0.18);
  --cat-core: #d99a1a;
  --cat-core-wash: rgba(201, 133, 0, 0.20);
  --cat-recovery: #2bb385;
  --cat-recovery-wash: rgba(25, 158, 112, 0.20);

  --good: #35c235;
  --good-wash: rgba(53, 194, 53, 0.16);
  --miss: #e2685f;
  --miss-wash: rgba(226, 104, 95, 0.18);

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 6px 20px rgba(0, 0, 0, 0.35);
}

/* ===== reset ===== */
* { box-sizing: border-box; }
html, body { height: 100%; }
html { direction: rtl; }
body {
  margin: 0;
  direction: rtl;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: contain;
}
h1, h2, h3, h4 { font-family: var(--font-display); text-wrap: balance; margin: 0; }
p { margin: 0; line-height: 1.7; }
button { font-family: inherit; }
input, select { font-family: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.tabular { font-variant-numeric: tabular-nums; }
.mono { font-family: var(--font-mono); }

/* ===== app shell ===== */
#app {
  max-width: 560px;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 20px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 10px;
  background: var(--accent);
  display: flex; align-items: center; justify-content: center;
  flex: none;
}
.brand-name { font-family: var(--font-display); font-weight: 800; font-size: 17px; letter-spacing: 0.2px; }
.brand-date { font-size: 12px; color: var(--text-muted); margin-top: 1px; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.icon-btn {
  width: 36px; height: 36px; border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  display: flex; align-items: center; justify-content: center;
  color: var(--text-secondary);
  cursor: pointer;
}
.icon-btn:hover { border-color: var(--border-strong); }

main#view-root {
  flex: 1;
  padding: 16px 16px 100px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.bottom-dock {
  position: sticky;
  bottom: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--border);
}
.tabbar {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 2px;
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
}
.rest-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  background: var(--accent-wash);
  border-bottom: 1px solid var(--accent);
}
.rest-bar-info { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.rest-bar-label { font-size: 11.5px; color: var(--text-secondary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rest-bar-clock { font-size: 22px; font-weight: 700; color: var(--accent); }
.rest-bar-actions { display: flex; gap: 8px; flex: none; }
.rest-bar.mode-work { background: var(--good-wash); border-bottom-color: var(--good); }
.rest-bar.mode-work .rest-bar-clock { color: var(--good); }
.tab-btn {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  background: none; border: none; color: var(--text-muted);
  font-size: 11px; padding: 6px 2px; border-radius: 10px; cursor: pointer;
}
.tab-btn svg { width: 20px; height: 20px; }
.tab-btn.active { color: var(--accent); }
.tab-btn.active .tab-dot { opacity: 1; }
.tab-dot {
  width: 4px; height: 4px; border-radius: 50%; background: var(--accent);
  opacity: 0; margin-top: -2px;
}

/* ===== generic building blocks ===== */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 18px;
  box-shadow: var(--shadow-sm);
}
.section-title {
  font-size: 13px; font-weight: 700; color: var(--text-muted);
  letter-spacing: 0.04em; text-transform: uppercase;
}
.stack { display: flex; flex-direction: column; gap: 10px; }
.row { display: flex; align-items: center; gap: 10px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.spacer { flex: 1; }

.badge {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 700; padding: 5px 10px; border-radius: 999px;
  white-space: nowrap;
}
.badge-dot { width: 7px; height: 7px; border-radius: 50%; flex: none; }
.badge-strength { background: var(--cat-strength-wash); color: var(--cat-strength); }
.badge-strength .badge-dot { background: var(--cat-strength); }
.badge-cardio { background: var(--cat-cardio-wash); color: var(--cat-cardio); }
.badge-cardio .badge-dot { background: var(--cat-cardio); }
.badge-core { background: var(--cat-core-wash); color: var(--cat-core); }
.badge-core .badge-dot { background: var(--cat-core); }
.badge-recovery { background: var(--cat-recovery-wash); color: var(--cat-recovery); }
.badge-recovery .badge-dot { background: var(--cat-recovery); }
.badge-rest { background: var(--surface-sunken); color: var(--text-muted); }
.badge-rest .badge-dot { background: var(--text-muted); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border-radius: 12px; padding: 12px 18px; font-weight: 700; font-size: 14px;
  border: 1px solid transparent; cursor: pointer;
}
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-secondary { background: var(--surface-2); color: var(--text); border-color: var(--border-strong); }
.btn-ghost { background: transparent; color: var(--text-secondary); }
.btn-block { width: 100%; }
.btn-sm { padding: 8px 12px; font-size: 12.5px; border-radius: 10px; }
.btn:disabled { opacity: 0.5; cursor: default; }

.chip {
  border: 1px solid var(--border-strong); background: var(--surface-2);
  color: var(--text-secondary); border-radius: 999px; padding: 7px 14px;
  font-size: 12.5px; font-weight: 600; cursor: pointer;
}
.chip.active { background: var(--accent-wash); border-color: var(--accent); color: var(--accent); }

hr.hairline { border: none; border-top: 1px solid var(--border); margin: 4px 0; }

/* ===== Today view ===== */
.hero-day {
  border-radius: 20px;
  padding: 20px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  position: relative;
  overflow: hidden;
}
.hero-day::before {
  content: "";
  position: absolute; inset-inline-start: 0; top: 0; bottom: 0; width: 5px;
  background: var(--cat-color, var(--accent));
}
.hero-day h2 { font-size: 21px; font-weight: 800; margin-top: 6px; }
.hero-day .hero-meta { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.hero-day .hero-desc { margin-top: 10px; color: var(--text-secondary); font-size: 14px; }

.week-pill-row {
  display: flex; gap: 8px; overflow-x: auto; padding-bottom: 2px;
  scrollbar-width: none;
}
.week-pill-row::-webkit-scrollbar { display: none; }
.week-pill {
  flex: none; width: 46px; padding: 10px 0; border-radius: 14px;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text-muted);
  font-size: 11px; font-weight: 700;
}
.week-pill .wp-dot { width: 8px; height: 8px; border-radius: 50%; }
.week-pill.is-today { border-color: var(--accent); color: var(--text); box-shadow: 0 0 0 1px var(--accent) inset; }
.week-pill.is-done .wp-dot { background: var(--good) !important; }

.exercise-card {
  border: 1px solid var(--border); background: var(--surface-2); border-radius: 14px; padding: 12px;
  border-inline-start: 3px solid var(--cat-color, var(--border));
}
.exercise-card + .exercise-card { margin-top: 10px; }
.ex-name { font-weight: 700; font-size: 14.5px; }
.ex-sub { font-size: 12.5px; color: var(--text-muted); margin-top: 2px; }
.ex-links { display: flex; align-items: center; gap: 8px; margin-top: 9px; flex-wrap: wrap; }
.video-link {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12.5px; font-weight: 700; color: var(--accent);
  background: var(--accent-wash); border-radius: 999px; padding: 6px 12px; text-decoration: none;
}
.video-link svg { width: 12px; height: 12px; }
.ex-cues { margin-top: 9px; font-size: 12.5px; color: var(--text-secondary); display: none; }
.ex-cues.open { display: block; }
.ex-cues ul { margin: 0; padding-inline-start: 18px; display: flex; flex-direction: column; gap: 4px; }

.set-list { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; }
.set-row {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 10px;
  background: var(--surface-sunken); border: 1px solid transparent;
}
.set-row.checked { background: var(--good-wash); border-color: var(--good); }
.set-check {
  width: 26px; height: 26px; border-radius: 8px; flex: none;
  border: 1.5px solid var(--border-strong); background: var(--surface);
  display: flex; align-items: center; justify-content: center; cursor: pointer; color: transparent;
}
.set-check.checked { background: var(--good); border-color: var(--good); color: #fff; }
.set-num { font-weight: 700; font-size: 12.5px; min-width: 42px; }
.set-target { font-size: 12.5px; color: var(--text-secondary); flex: 1; }
.set-timer-btn {
  width: 26px; height: 26px; border-radius: 8px; flex: none;
  border: 1.5px solid var(--accent); background: var(--accent-wash); color: var(--accent);
  display: flex; align-items: center; justify-content: center; cursor: pointer;
}
.set-timer-btn svg { width: 11px; height: 11px; }

.day-picker { display: flex; gap: 8px; flex-wrap: wrap; }

/* ===== Timer overlay ===== */
.timer-overlay {
  position: fixed; inset: 0; z-index: 50;
  background: color-mix(in srgb, var(--bg) 96%, transparent);
  backdrop-filter: blur(6px);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 22px; padding: 24px;
}
.timer-overlay[hidden] { display: none; }
.timer-phase {
  font-family: var(--font-display); font-weight: 800; font-size: 20px;
  padding: 8px 22px; border-radius: 999px; color: var(--accent-ink); background: var(--accent);
  transition: background 0.25s ease;
}
.timer-phase.is-rest { background: var(--cat-recovery); }
.timer-clock {
  font-family: var(--font-mono); font-size: 68px; font-weight: 700; letter-spacing: 1px;
  color: var(--text);
}
.timer-round { color: var(--text-muted); font-size: 14px; }
.timer-controls { display: flex; gap: 12px; margin-top: 8px; }
.timer-setup { width: 100%; max-width: 320px; display: flex; flex-direction: column; gap: 12px; }
.timer-field { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.timer-field label { font-size: 13.5px; color: var(--text-secondary); }
.num-stepper { display: flex; align-items: center; gap: 10px; }
.num-stepper button {
  width: 30px; height: 30px; border-radius: 9px; border: 1px solid var(--border-strong);
  background: var(--surface-2); color: var(--text); font-size: 16px; cursor: pointer;
}
.num-stepper .val { font-family: var(--font-mono); min-width: 34px; text-align: center; font-size: 15px; }
.close-x {
  position: absolute; top: 18px; inset-inline-end: 18px;
  width: 38px; height: 38px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text-secondary); cursor: pointer;
}

/* ===== Week view ===== */
.day-card { display: flex; flex-direction: column; gap: 10px; }
.day-card-head { display: flex; align-items: center; justify-content: space-between; }
.day-card-title { font-weight: 700; font-size: 14.5px; }
.day-card-sub { font-size: 12.5px; color: var(--text-muted); margin-top: 2px; }
.day-card-items { font-size: 12.5px; color: var(--text-secondary); }

/* ===== Library view ===== */
.filter-row { display: flex; gap: 8px; flex-wrap: wrap; }
.lib-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 420px) { .lib-grid { grid-template-columns: 1fr; } }
.lib-card { display: flex; flex-direction: column; gap: 8px; cursor: pointer; }
.lib-icon {
  width: 38px; height: 38px; border-radius: 11px; display: flex; align-items: center; justify-content: center;
  background: var(--cat-wash, var(--surface-sunken)); color: var(--cat-color, var(--text-muted));
  flex: none;
}
.lib-name { font-weight: 700; font-size: 13.5px; }
.lib-equipment { font-size: 11.5px; color: var(--text-muted); }
.lib-detail { display: none; }
.lib-detail.open { display: block; margin-top: 4px; }

/* ===== Progress view ===== */
.stat-tile { display: flex; flex-direction: column; gap: 4px; }
.stat-value { font-family: var(--font-mono); font-size: 26px; font-weight: 700; }
.stat-label { font-size: 12px; color: var(--text-muted); }

.log-form { display: flex; gap: 8px; }
.log-form input {
  flex: 1; border: 1px solid var(--border-strong); background: var(--surface-2);
  color: var(--text); border-radius: 10px; padding: 10px 12px; font-size: 14px;
}

.chart-wrap { width: 100%; overflow-x: auto; }
.chart-wrap svg { display: block; }
.chart-empty { color: var(--text-muted); font-size: 13px; text-align: center; padding: 20px 0; }

/* ===== training calendar ===== */
.cal-weekday-row, .cal-week-cells { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.cal-weekday-row span { text-align: center; font-size: 11px; font-weight: 700; color: var(--text-muted); }
.cal-week-block { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.cal-week-label { width: 62px; flex: none; font-size: 11px; color: var(--text-muted); }
.cal-week-cells { flex: 1; }
.cal-cell {
  aspect-ratio: 1; border-radius: 9px; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 1px; border: 1.5px solid var(--border); background: var(--surface-2); color: var(--text-muted);
}
.cal-cell.none { opacity: 0.5; border-style: dashed; }
.cal-cell.done { background: var(--good-wash); border-color: var(--good); color: var(--text); }
.cal-cell.done .cal-mark { color: var(--good); }
.cal-cell.missed { background: var(--miss-wash); border-color: var(--miss); color: var(--text); }
.cal-cell.missed .cal-mark { color: var(--miss); }
.cal-cell.upcoming { border-color: var(--cat-color, var(--border-strong)); border-style: dashed; color: var(--text-secondary); }
.cal-cell.today-pending { border-color: var(--accent); border-width: 2px; color: var(--text); }
.cal-daynum { font-weight: 700; font-size: 11.5px; font-family: var(--font-mono); }
.cal-mark { font-size: 10px; font-weight: 700; line-height: 1; }
.cal-legend { display: flex; flex-wrap: wrap; gap: 10px 14px; margin-top: 14px; font-size: 11.5px; color: var(--text-muted); }
.cal-legend-item { display: flex; align-items: center; gap: 5px; }
.cal-legend-dot { width: 10px; height: 10px; border-radius: 3px; flex: none; }

/* ===== weekly consistency bar chart ===== */
.bar-chart { display: flex; align-items: stretch; gap: 8px; height: 130px; margin-top: 12px; }
.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; min-width: 0; }
.bar-track { flex: 1; width: 100%; display: flex; align-items: flex-end; justify-content: center; }
.bar { width: 100%; max-width: 26px; min-height: 4px; border-radius: 6px 6px 3px 3px; }
.bar.full { background: var(--good); }
.bar.partial { background: var(--accent); }
.bar.zero { background: transparent; border: 1.5px dashed var(--border-strong); }
.bar-value { font-size: 10px; color: var(--text-muted); font-family: var(--font-mono); white-space: nowrap; }
.bar-week-label { font-size: 9.5px; color: var(--text-muted); white-space: nowrap; }

/* ===== Settings view ===== */
.seg { display: flex; border: 1px solid var(--border-strong); border-radius: 12px; overflow: hidden; }
.seg button {
  flex: 1; padding: 10px; background: var(--surface-2); border: none; color: var(--text-secondary);
  font-size: 13px; font-weight: 700; cursor: pointer; border-inline-start: 1px solid var(--border-strong);
}
.seg button:first-child { border-inline-start: none; }
.seg button.active { background: var(--accent); color: var(--accent-ink); }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 13px; color: var(--text-secondary); font-weight: 600; }
.field input, .field select {
  border: 1px solid var(--border-strong); background: var(--surface-2); color: var(--text);
  border-radius: 10px; padding: 10px 12px; font-size: 14px;
}
details.install-guide summary, details.collapsible summary {
  cursor: pointer; font-weight: 700; font-size: 13.5px; color: var(--text);
  list-style: none;
}
details.install-guide summary::-webkit-details-marker, details.collapsible summary::-webkit-details-marker { display: none; }
details.install-guide[open] summary, details.collapsible[open] summary { margin-bottom: 4px; }
.install-guide ol { margin: 0; padding-inline-start: 20px; display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--text-secondary); }

.toast {
  position: fixed; bottom: 92px; inset-inline-start: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 999px;
  font-size: 13px; font-weight: 600; box-shadow: var(--shadow-md); z-index: 60;
  opacity: 0; pointer-events: none; transition: opacity 0.2s ease, transform 0.2s ease;
}
:root[data-theme="dark"] .toast, :root:not([data-theme="light"]) .toast { }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(-4px); }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
