/* ============================================================
   Fitness — visual language matched to bench_200_program
   Slate palette, red-gradient accent, premium iOS feel,
   light + auto dark mode.
   ============================================================ */

:root {
  --bg: #f8fafc;
  --bg-grad-a: #fbfcfe;
  --bg-grad-b: #f1f5f9;
  --bg-glow-1: rgba(91, 142, 255, 0.07);
  --bg-glow-2: rgba(239, 68, 68, 0.05);
  --card: #ffffff;
  --card-2: #f8fafc;
  --card-glass: rgba(255, 255, 255, 0.72);
  --text: #0f172a;
  --text-2: #475569;
  --subdued: #94a3b8;
  --border: #e2e8f0;
  --border-2: #cbd5e1;

  --accent1: #2563eb;
  --accent1-soft: #dbeafe;
  --accent1-grad: linear-gradient(135deg, #3b82f6 0%, #60a5fa 100%);

  --accentV: #0d9488;
  --accentV-soft: #ccfbf1;
  --accentV-grad: linear-gradient(135deg, #0d9488 0%, #5eead4 100%);

  --accent2: #d97706;
  --accent2-soft: #fef3c7;
  --accent2-grad: linear-gradient(135deg, #d97706 0%, #fbbf24 100%);

  --accent3: #ea580c;
  --accent3-soft: #ffedd5;
  --accent3-grad: linear-gradient(135deg, #ea580c 0%, #fb923c 100%);

  --accent4: #dc2626;
  --accent4-soft: #fecaca;
  --accent4-grad: linear-gradient(135deg, #b91c1c 0%, #ef4444 50%, #f59e0b 100%);

  --check: #16a34a;
  --check-soft: #dcfce7;
  --warn: #d97706;
  --warn-soft: #fef3c7;
  --danger: #dc2626;
  --danger-soft: #fecaca;

  --shadow-1: 0 1px 2px rgba(15, 23, 42, 0.06), 0 1px 1px rgba(15, 23, 42, 0.03);
  --shadow-2: 0 4px 24px -8px rgba(15, 23, 42, 0.12), 0 2px 6px -2px rgba(15, 23, 42, 0.06);
  --shadow-glass: 0 8px 32px -8px rgba(15, 23, 42, 0.12);

  --radius: 16px;
  --radius-sm: 10px;
  --radius-pill: 999px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0a0b10;
    --bg-grad-a: #0e1018;
    --bg-grad-b: #07080d;
    --bg-glow-1: rgba(91, 142, 255, 0.12);
    --bg-glow-2: rgba(239, 68, 68, 0.08);
    --card: #14161e;
    --card-2: #1a1d27;
    --card-glass: rgba(20, 22, 30, 0.72);
    --text: #f1f3f8;
    --text-2: #b4b9c5;
    --subdued: #6f7585;
    --border: #232631;
    --border-2: #2c303d;
    --accent1: #6c8df0;
    --accent1-soft: rgba(108, 141, 240, 0.15);
    --accentV: #2dd4bf;
    --accentV-soft: rgba(45, 212, 191, 0.15);
    --accent2: #f59e0b;
    --accent2-soft: rgba(245, 158, 11, 0.15);
    --accent3: #fb923c;
    --accent3-soft: rgba(251, 146, 60, 0.15);
    --accent4: #f87171;
    --accent4-soft: rgba(248, 113, 113, 0.15);
    --check: #4ade80;
    --check-soft: rgba(74, 222, 128, 0.15);
    --warn: #fbbf24;
    --warn-soft: rgba(251, 191, 36, 0.15);
    --danger: #f87171;
    --danger-soft: rgba(248, 113, 113, 0.15);
    --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-2: 0 4px 16px rgba(0, 0, 0, 0.45);
    --shadow-glass: 0 8px 32px rgba(0, 0, 0, 0.6);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "Inter", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  font-size: 16px;
  padding: 0 0 max(env(safe-area-inset-bottom), 40px);
  -webkit-font-smoothing: antialiased;
  position: relative;
  overflow-x: hidden;
}
body::before {
  content: "";
  position: fixed;
  inset: 0;
  background:
    radial-gradient(60% 50% at 15% 0%, var(--bg-glow-1) 0%, transparent 70%),
    radial-gradient(50% 40% at 85% 8%, var(--bg-glow-2) 0%, transparent 70%),
    linear-gradient(180deg, var(--bg-grad-a) 0%, var(--bg-grad-b) 100%);
  z-index: -1;
  pointer-events: none;
}

main, .screen { min-height: 100vh; }
.wrap { max-width: 720px; margin: 0 auto; padding: 8px 16px; }

/* =============== HERO / NAV =============== */
.hero {
  padding: calc(env(safe-area-inset-top) + 22px) 22px 14px;
  position: relative;
}
.hero-brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 5px 10px 5px 8px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  box-shadow: var(--shadow-1);
  font-size: 11px;
  font-weight: 700;
  color: var(--text-2);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin-bottom: 16px;
}
.hero-brand-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent4);
  box-shadow: 0 0 0 3px var(--accent4-soft);
}
.hero-eyebrow {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.18em;
  color: var(--subdued);
  text-transform: uppercase;
  margin-bottom: 8px;
}
.hero h1, h1.large {
  font-size: 36px;
  font-weight: 800;
  letter-spacing: -.025em;
  line-height: 1.05;
  margin: 0 0 6px;
  color: var(--text);
}
.hero-title-grad {
  background: var(--accent4-grad);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.hero-sub {
  font-size: 15px;
  color: var(--text-2);
  margin: 0 0 4px;
  font-weight: 500;
  line-height: 1.4;
}

.topbar-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

/* =============== Buttons =============== */
button, .btn {
  appearance: none; border: 0; cursor: pointer; font: inherit; font-family: inherit;
  background: var(--accent4-grad); color: #fff;
  padding: 11px 18px; border-radius: var(--radius-sm);
  font-weight: 700; font-size: 15px; letter-spacing: -.01em;
  box-shadow: 0 2px 8px rgba(220, 38, 38, 0.25);
  transition: transform .08s ease, opacity .12s ease, box-shadow .15s ease;
}
button:active, .btn:active { transform: scale(.97); opacity: .92; }
button.ghost, .btn-ghost {
  background: var(--card); color: var(--text);
  border: 1px solid var(--border); box-shadow: var(--shadow-1);
  font-weight: 600;
}
button.danger, .btn-danger {
  background: var(--danger-soft); color: var(--danger);
  box-shadow: none; font-weight: 600;
}
button.small, .btn-small {
  padding: 6px 12px; font-size: 13px; border-radius: 8px;
  background: var(--card); color: var(--text);
  border: 1px solid var(--border); box-shadow: var(--shadow-1); font-weight: 600;
}
button.small.danger, .btn-small.danger {
  background: var(--danger-soft); color: var(--danger); border-color: transparent;
}
button.small.primary, .btn-small.primary {
  background: var(--accent4-grad); color: #fff; border-color: transparent;
  box-shadow: 0 2px 6px rgba(220, 38, 38, 0.25);
}
.icon-btn {
  appearance: none; border: 1px solid var(--border); background: var(--card); color: var(--text-2);
  width: 32px; height: 32px; border-radius: 8px; cursor: pointer; font-size: 14px;
  display: inline-flex; align-items: center; justify-content: center;
  box-shadow: var(--shadow-1);
}
.icon-btn:active { transform: scale(.94); }
.link-btn, button.link-btn {
  appearance: none; border: 0; background: transparent; color: var(--accent4);
  font: inherit; font-size: 14px; font-weight: 700; padding: 6px 0; cursor: pointer; letter-spacing: -.01em;
  box-shadow: none;
}
.link-btn:active { opacity: .5; }
.logout-btn {
  appearance: none; border: 1px solid var(--border); background: var(--card); color: var(--text-2);
  font: inherit; font-size: 13px; font-weight: 600; padding: 7px 14px; border-radius: var(--radius-pill);
  cursor: pointer; box-shadow: var(--shadow-1);
}

/* =============== LOGIN =============== */
.login-screen {
  display: flex; align-items: flex-start; justify-content: center;
  padding: 12vh 20px 0;
}
.login-wrap { max-width: 420px; width: 100%; }
.login-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-2);
  padding: 18px;
  margin-top: 14px;
}
.login-form { display: flex; flex-direction: column; gap: 12px; }
.login-form input {
  appearance: none; border: 1px solid var(--border);
  background: var(--card-2); color: var(--text);
  font: inherit; font-size: 17px; letter-spacing: -.01em;
  padding: 14px 16px; border-radius: var(--radius-sm); outline: none;
  transition: border-color .15s ease, background .15s ease;
}
.login-form input::placeholder { color: var(--subdued); }
.login-form input:focus { border-color: var(--accent4); background: var(--card); }
.login-form button {
  padding: 14px 18px; font-size: 17px;
}
.error {
  margin-top: 14px; color: var(--danger);
  background: var(--danger-soft); border-radius: var(--radius-sm);
  padding: 10px 14px; font-size: 14px; font-weight: 500;
}

/* =============== TABS (segmented control) =============== */
.tabs {
  display: flex; gap: 4px;
  padding: 4px;
  margin: 6px 0 14px;
  background: var(--card-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-1);
}
.tab {
  flex: 1;
  appearance: none; border: 0; background: transparent;
  font: inherit; font-size: 14px; font-weight: 600;
  color: var(--text-2);
  padding: 9px 8px;
  border-radius: 7px;
  cursor: pointer;
  box-shadow: none;
  letter-spacing: -.01em;
  transition: background .15s ease, color .15s ease, box-shadow .15s ease;
}
.tab.active {
  background: var(--card);
  color: var(--text);
  box-shadow: 0 1px 3px rgba(15, 23, 42, .1);
}

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* =============== Section header =============== */
.section-head {
  display: flex; justify-content: space-between; align-items: flex-end;
  padding: 14px 4px 8px;
}
.section-head .title {
  font-size: 11px; font-weight: 700; color: var(--subdued);
  letter-spacing: .14em; text-transform: uppercase;
}
.section-head .aside {
  font-size: 12px; color: var(--subdued); font-variant-numeric: tabular-nums;
}

/* =============== Cards =============== */
.group-list, .list {
  display: flex; flex-direction: column; gap: 10px;
}
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow-1);
}
.card-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.card h3 {
  margin: 0 0 4px; font-size: 17px; font-weight: 700;
  letter-spacing: -.015em; color: var(--text);
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
}
.card p { margin: 0; font-size: 14px; color: var(--text-2); line-height: 1.45; }
.card .meta {
  font-size: 12px; color: var(--subdued); margin-top: 6px;
  font-variant-numeric: tabular-nums; font-weight: 600;
  letter-spacing: .02em;
}
.card .actions-col {
  display: flex; gap: 6px; flex-direction: column; flex-shrink: 0;
}

/* =============== Pills / Tags =============== */
.tagline, .dow {
  display: inline-block;
  font-size: 10px; padding: 3px 9px; border-radius: var(--radius-pill);
  background: var(--card-2); color: var(--text-2);
  font-weight: 700; letter-spacing: .08em; text-transform: uppercase;
  border: 1px solid var(--border);
}
.tagline.ok { background: var(--check-soft); color: var(--check); border-color: transparent; }
.tagline.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.dow { background: var(--accent1-soft); color: var(--accent1); border-color: transparent; }
.role-pill {
  font-size: 11px; text-transform: uppercase; letter-spacing: .08em;
  background: var(--accent4-soft); padding: 3px 9px; border-radius: var(--radius-pill);
  color: var(--accent4); font-weight: 700;
}

/* =============== Forms =============== */
label {
  display: block; font-size: 11px; color: var(--subdued);
  margin: 14px 2px 6px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .12em;
}
input, select, textarea, .ios-select {
  width: 100%; appearance: none; -webkit-appearance: none;
  border: 1px solid var(--border);
  background: var(--card); color: var(--text);
  font: inherit; font-size: 16px;
  padding: 11px 14px; border-radius: var(--radius-sm); outline: none;
  transition: border-color .15s ease, background .15s ease;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent4); }
textarea { min-height: 60px; resize: vertical; line-height: 1.4; }
.ios-select {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'><path fill='%2394a3b8' d='M1 1l5 5 5-5'/></svg>");
  background-repeat: no-repeat; background-position: right 14px center; background-size: 10px 7px;
  padding-right: 34px; font-weight: 600;
}

.row-inputs { display: flex; gap: 10px; }
.row-inputs > * { flex: 1; }
.actions, .form-actions {
  display: flex; gap: 10px; flex-wrap: wrap; margin-top: 18px;
}
.actions > *, .form-actions > * { flex: 1; min-width: 120px; }

/* =============== Exercise card (today) =============== */
.exercise {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow-1);
  transition: border-color .2s ease, background .2s ease;
}
.exercise.done {
  background: linear-gradient(180deg, var(--check-soft) 0%, var(--card) 60%);
  border-color: var(--check);
}
.exercise h3 {
  margin: 0 0 6px; font-size: 17px; font-weight: 700; letter-spacing: -.015em;
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
}
.exercise .target {
  color: var(--text-2); font-size: 13px; margin-bottom: 8px;
  font-variant-numeric: tabular-nums; font-weight: 600;
}
.exercise .description {
  font-size: 14px; color: var(--text-2); margin: 6px 0 8px; line-height: 1.5;
}
.exercise .inputs {
  display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; margin-top: 10px;
}
.exercise .inputs input {
  padding: 10px 12px; font-size: 15px; text-align: center; font-variant-numeric: tabular-nums; font-weight: 600;
}
.exercise textarea { margin-top: 8px; font-size: 15px; }
.exercise .video { margin-top: 10px; }
.exercise .video iframe, .exercise .video video {
  width: 100%; aspect-ratio: 16/9; border: 0; border-radius: 12px; background: #000; display: block;
}

/* =============== Chat =============== */
.chat {
  margin-top: 14px; padding-top: 12px;
  border-top: 1px dashed var(--border);
}
.bubble {
  background: var(--card-2);
  border: 1px solid var(--border);
  padding: 8px 12px;
  border-radius: 14px;
  margin: 6px 0;
  font-size: 14px; line-height: 1.45; color: var(--text);
  max-width: 88%;
}
.bubble.mine {
  background: var(--accent4-soft); border-color: transparent; color: var(--text);
  margin-left: auto;
}
.bubble .who {
  font-size: 10px; color: var(--text-2);
  margin-bottom: 3px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase;
}
.chat-form { display: flex; gap: 8px; margin-top: 10px; }
.chat-form input { flex: 1; padding: 10px 14px; font-size: 14px; }
.chat-form button { flex: 0 0 auto; padding: 10px 16px; font-size: 14px; }

/* =============== History chart =============== */
#history-chart {
  width: 100%; height: 220px; background: transparent;
  display: block; margin-top: 12px;
}

/* =============== Modal =============== */
.modal {
  position: fixed; inset: 0; background: rgba(15, 23, 42, .42);
  display: flex; align-items: flex-end; justify-content: center; z-index: 20;
  backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
  animation: fadeIn .2s ease;
}
@media (min-width: 640px) { .modal { align-items: center; } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.modal-card {
  width: 100%; max-width: 540px;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--border);
  border-bottom: 0;
  border-radius: 22px 22px 0 0;
  padding: 8px 18px 24px;
  max-height: 92vh; overflow-y: auto;
  box-shadow: 0 -20px 60px rgba(0, 0, 0, .15);
  animation: slideUp .25s cubic-bezier(.2, .8, .2, 1);
}
@media (min-width: 640px) {
  .modal-card { border-radius: 18px; border-bottom: 1px solid var(--border); padding: 18px 22px 22px; }
}
@keyframes slideUp { from { transform: translateY(40px); } to { transform: translateY(0); } }
.modal-grabber {
  width: 36px; height: 5px; background: var(--border-2); border-radius: 99px;
  margin: 8px auto 6px;
}
@media (min-width: 640px) { .modal-grabber { display: none; } }
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 0 14px;
}
.modal-head h3 {
  margin: 0; font-size: 18px; font-weight: 800; letter-spacing: -.02em;
}

/* =============== Toast =============== */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: rgba(15, 23, 42, .94); color: #fff;
  padding: 11px 18px; border-radius: var(--radius-pill); z-index: 30;
  font-size: 14px; font-weight: 600; letter-spacing: -.005em;
  backdrop-filter: blur(20px);
  box-shadow: 0 12px 40px rgba(0, 0, 0, .25);
}

/* =============== Misc =============== */
hr { border: none; border-top: 1px solid var(--border); margin: 14px 0; }
.muted { color: var(--text-2); }
.small { font-size: 14px; }
.right { text-align: right; }

/* legacy aliases */
.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; padding: 14px 4px 8px;
}
.panel-head h2 {
  margin: 0; font-size: 11px; font-weight: 700; color: var(--subdued);
  text-transform: uppercase; letter-spacing: .14em;
}
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px;
}
.topbar-title { display: flex; align-items: center; gap: 10px; }

/* ensure native buttons inside forms also use our pill style */
form button[type="submit"] { width: 100%; }
