:root {
  --bg: #0f1115;
  --bg-elevated: #171a21;
  --card: #1c1f28;
  --card-alt: #22262f;
  --border: #2a2e38;
  --text: #f2f3f5;
  --text-dim: #9aa0ac;
  --text-faint: #676d79;
  --accent: #4f8cff;
  --green: #35c46a;
  --green-bg: rgba(53, 196, 106, 0.15);
  --yellow: #e8b93f;
  --yellow-bg: rgba(232, 185, 63, 0.15);
  --blue: #4f8cff;
  --blue-bg: rgba(79, 140, 255, 0.15);
  --red: #ef5350;
  --red-bg: rgba(239, 83, 80, 0.15);
  --radius: 14px;
  --radius-sm: 10px;
  --nav-height: 64px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
  --demo-height: 40px;
  --sidebar-width: 248px;
  --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.3);
}

:root[data-theme="light"] {
  --bg: #f5f6f8;
  --bg-elevated: #ffffff;
  --card: #ffffff;
  --card-alt: #eef0f3;
  --border: #e0e3e8;
  --text: #16181d;
  --text-dim: #5b616e;
  --text-faint: #8a909c;
  --accent: #3b6fe0;
  --green: #1f9d54;
  --green-bg: rgba(31, 157, 84, 0.12);
  --yellow: #b9860b;
  --yellow-bg: rgba(185, 134, 11, 0.12);
  --blue: #3b6fe0;
  --blue-bg: rgba(59, 111, 224, 0.12);
  --red: #d5433d;
  --red-bg: rgba(213, 67, 61, 0.12);
  --shadow-card: 0 1px 3px rgba(20, 20, 30, 0.08);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: contain;
}

button, input, select, textarea { font-family: inherit; }

a { color: inherit; text-decoration: none; }

#app {
  max-width: 560px;
  margin: 0 auto;
  min-height: 100%;
  padding-bottom: calc(var(--nav-height) + var(--safe-bottom) + 12px);
  padding-top: var(--safe-top);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 16px 8px;
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 5;
}
.topbar h1 { font-size: 20px; margin: 0; font-weight: 700; }
.topbar .icon-btn { background: none; border: none; color: var(--text); font-size: 20px; padding: 8px; cursor: pointer; }

.view { padding: 8px 16px 16px; animation: fadein 0.15s ease; }
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}
.card-title {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  margin: 0 0 10px;
  font-weight: 600;
}

.row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.stack { display: flex; flex-direction: column; gap: 8px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }

.metric-value { font-size: 22px; font-weight: 700; }
.metric-label { font-size: 12px; color: var(--text-dim); }
.muted { color: var(--text-dim); }
.faint { color: var(--text-faint); }
.small { font-size: 13px; }
.big { font-size: 28px; font-weight: 800; }

.progress-bar {
  height: 10px;
  border-radius: 6px;
  background: var(--card-alt);
  overflow: hidden;
  margin: 6px 0;
}
.progress-bar > div { height: 100%; border-radius: 6px; background: var(--accent); transition: width 0.25s ease; }
.progress-bar.green > div { background: var(--green); }
.progress-bar.yellow > div { background: var(--yellow); }
.progress-bar.blue > div { background: var(--blue); }
.progress-bar.red > div { background: var(--red); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: var(--radius-sm);
  padding: 14px 18px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  min-height: 48px;
  width: 100%;
}
.btn-primary { background: var(--accent); color: white; }
.btn-secondary { background: var(--card-alt); color: var(--text); border: 1px solid var(--border); }
.btn-danger { background: var(--red-bg); color: var(--red); }
.btn-ghost { background: transparent; color: var(--accent); }
.btn-sm { padding: 10px 14px; font-size: 14px; min-height: 40px; width: auto; }
.btn:disabled { opacity: 0.5; }
.btn-row { display: flex; gap: 10px; }
.btn-row .btn { flex: 1; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
}
.badge.green { background: var(--green-bg); color: var(--green); }
.badge.yellow { background: var(--yellow-bg); color: var(--yellow); }
.badge.blue { background: var(--blue-bg); color: var(--blue); }
.badge.red { background: var(--red-bg); color: var(--red); }

input[type="text"], input[type="number"], input[type="date"], select, textarea {
  background: var(--card-alt);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 12px;
  font-size: 16px;
  width: 100%;
  min-height: 44px;
}
textarea { min-height: 60px; }
label { font-size: 13px; color: var(--text-dim); display: block; margin-bottom: 4px; }
.field { margin-bottom: 12px; }

.set-row {
  display: grid;
  grid-template-columns: 28px 1fr 1fr 32px;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
}
.set-row .set-num { color: var(--text-dim); font-weight: 700; text-align: center; }
.set-row input { text-align: center; }
.set-row.done input { border-color: var(--green); }

.exercise-card { padding: 16px; }
.exercise-name { font-size: 18px; font-weight: 800; margin: 0 0 2px; }
.exercise-target { font-size: 13px; color: var(--text-dim); margin-bottom: 10px; }
.last-time-box {
  background: var(--card-alt);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  margin-bottom: 12px;
  font-size: 14px;
}
.last-time-box .lt-label { font-size: 11px; text-transform: uppercase; color: var(--text-dim); letter-spacing: 0.05em; margin-bottom: 4px; }

.bottom-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: calc(var(--nav-height) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: var(--bg-elevated);
  border-top: 1px solid var(--border);
  display: flex;
  z-index: 10;
  max-width: 560px;
  margin: 0 auto;
}
.bottom-nav button {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-faint);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 11px;
  cursor: pointer;
  padding: 6px 0;
}
.bottom-nav button.active { color: var(--accent); }
.bottom-nav .nav-icon { font-size: 20px; }

.rest-timer-overlay {
  position: fixed;
  bottom: calc(var(--nav-height) + var(--safe-bottom) + 12px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--accent);
  color: white;
  padding: 12px 24px;
  border-radius: 999px;
  font-weight: 800;
  font-size: 18px;
  z-index: 20;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  gap: 12px;
}
.rest-timer-overlay button { background: rgba(255,255,255,0.25); border: none; color: white; border-radius: 999px; width: 28px; height: 28px; font-size: 14px; cursor: pointer; }

.day-list-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  background: var(--card-alt);
  margin-bottom: 8px;
  cursor: pointer;
}
.day-list-item.rest { opacity: 0.55; }
.day-list-item .day-name { font-weight: 700; }
.day-list-item .day-sub { font-size: 12px; color: var(--text-dim); }

.meal-section { margin-bottom: 14px; }
.meal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.meal-header h3 { font-size: 13px; text-transform: uppercase; color: var(--text-dim); margin: 0; letter-spacing: 0.05em; }
.food-entry-row { display: flex; justify-content: space-between; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--border); }
.food-entry-row:last-child { border-bottom: none; }
.food-entry-name { font-weight: 600; font-size: 15px; }
.food-entry-macros { font-size: 12px; color: var(--text-dim); }

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6);
  display: flex; align-items: flex-end; justify-content: center; z-index: 50;
}
.modal-sheet {
  background: var(--bg-elevated);
  width: 100%; max-width: 560px;
  border-radius: 18px 18px 0 0;
  padding: 20px 16px calc(20px + var(--safe-bottom));
  max-height: 85vh;
  overflow-y: auto;
}
.modal-sheet h2 { margin-top: 0; font-size: 18px; }

.search-result { padding: 12px; border-radius: var(--radius-sm); background: var(--card-alt); margin-bottom: 8px; cursor: pointer; }
.search-result:active { background: var(--border); }

.list-item { display: flex; justify-content: space-between; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--border); }
.list-item:last-child { border-bottom: none; }

.pill-tabs { display: flex; gap: 8px; margin-bottom: 12px; overflow-x: auto; }
.pill-tabs button {
  background: var(--card-alt);
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: 999px;
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
}
.pill-tabs button.active { background: var(--accent); color: white; border-color: var(--accent); }

.chart-wrap { width: 100%; overflow-x: auto; }
svg.chart { display: block; }

.toast {
  position: fixed; top: calc(var(--safe-top) + 12px); left: 50%; transform: translateX(-50%);
  background: var(--card); border: 1px solid var(--border); color: var(--text);
  padding: 12px 18px; border-radius: 999px; z-index: 60; font-size: 14px; font-weight: 600;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}
.undo-toast { display: flex; align-items: center; gap: 12px; }
.undo-toast .undo-btn {
  background: none; border: none; color: var(--accent); font-weight: 800; font-size: 13px;
  letter-spacing: 0.04em; cursor: pointer; padding: 4px;
}

.rir-input { padding: 6px 2px; font-size: 13px; min-height: 34px; }
.stepper-row { display: flex; align-items: center; gap: 4px; }
.stepper-row input { flex: 1; min-width: 0; text-align: center; padding: 12px 2px; }
.stepper-btn {
  width: 30px; height: 30px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--card-alt); color: var(--text); font-size: 16px; font-weight: 700;
  display: flex; align-items: center; justify-content: center; cursor: pointer; flex-shrink: 0;
}
.stepper-btn:active { background: var(--border); }

.plate-row { display: flex; align-items: center; justify-content: center; gap: 6px; flex-wrap: wrap; margin: 14px 0; min-height: 60px; }
.plate-disc {
  border-radius: 8px; display: flex; align-items: center; justify-content: center;
  color: white; font-weight: 800; font-size: 12px; background: var(--accent);
}

.cardio-card { background: linear-gradient(135deg, #1f9d54, #2fbf71); color: white; border-radius: var(--radius); padding: 16px; margin-bottom: 12px; }
.cardio-card .btn-primary { background: white; color: #1f9d54; }
:root[data-theme="light"] .cardio-card { color: white; }

.superset-badge {
  display: inline-block; font-size: 10px; font-weight: 800; letter-spacing: 0.05em;
  background: var(--yellow-bg); color: var(--yellow); padding: 3px 8px; border-radius: 999px; margin-bottom: 8px;
}
.superset-block { border-left: 3px solid var(--yellow); padding-left: 10px; margin-bottom: 4px; }

.program-item { display: flex; justify-content: space-between; align-items: center; padding: 12px; border-radius: var(--radius-sm); background: var(--card-alt); margin-bottom: 8px; }
.program-item.active { border: 1.5px solid var(--accent); }

.pr-banner {
  background: linear-gradient(135deg, #ffb347, #ff5e62);
  color: white; border-radius: var(--radius); padding: 16px; margin-bottom: 10px;
  font-weight: 700;
}

.empty-state { text-align: center; padding: 40px 20px; color: var(--text-dim); }
.empty-state .emoji { font-size: 40px; margin-bottom: 12px; }

.calendar-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.calendar-day {
  aspect-ratio: 1;
  border-radius: 8px;
  background: var(--card-alt);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-size: 12px; cursor: pointer; position: relative;
}
.calendar-day .dots { display: flex; gap: 2px; position: absolute; bottom: 4px; }
.calendar-day .dot { width: 4px; height: 4px; border-radius: 50%; }
.calendar-day.today { border: 2px solid var(--accent); }
.calendar-day.empty { background: transparent; cursor: default; }

.photo-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.photo-grid img { width: 100%; aspect-ratio: 3/4; object-fit: cover; border-radius: 8px; }

.switch { position: relative; display: inline-block; width: 44px; height: 26px; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider { position: absolute; cursor: pointer; inset: 0; background: var(--card-alt); border: 1px solid var(--border); border-radius: 999px; transition: 0.2s; }
.switch .slider:before { content: ""; position: absolute; height: 18px; width: 18px; left: 3px; bottom: 3px; background: var(--text-dim); border-radius: 50%; transition: 0.2s; }
.switch input:checked + .slider { background: var(--accent); }
.switch input:checked + .slider:before { background: white; transform: translateX(18px); }

.loading { text-align: center; padding: 40px; color: var(--text-dim); }

.ex-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--ic, var(--accent));
  background: color-mix(in srgb, var(--ic, var(--accent)) 16%, transparent);
  border-radius: 10px;
  flex-shrink: 0;
  padding: 4px;
  box-sizing: content-box;
}
.exercise-name-row { display: flex; align-items: center; gap: 10px; }
.set-row.warmup input { opacity: 0.7; }
.set-row-wrap { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.set-row-wrap .set-row { flex: 1; margin-bottom: 0; }
.warmup-toggle {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: 9px; color: var(--text-faint); cursor: pointer; width: 30px; flex-shrink: 0;
}
.warmup-toggle input { width: auto; min-height: auto; }
.warmup-tag { font-size: 10px; color: var(--yellow); font-weight: 700; }

.demo-banner {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: calc(var(--demo-height) + var(--safe-top));
  padding-top: var(--safe-top);
  background: repeating-linear-gradient(135deg, #7c5cff, #7c5cff 12px, #6a4ce8 12px, #6a4ce8 24px);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  font-size: 13px;
  font-weight: 800;
  z-index: 100;
  box-shadow: 0 2px 12px rgba(0,0,0,0.3);
}
.demo-banner button {
  background: rgba(0,0,0,0.25);
  color: white;
  border: 1px solid rgba(255,255,255,0.4);
  border-radius: 999px;
  padding: 4px 14px;
  font-size: 11px;
  font-weight: 800;
  cursor: pointer;
}
body.demo-active #app { padding-top: calc(var(--demo-height) + var(--safe-top)); }
body.demo-active .topbar { top: calc(var(--demo-height) + var(--safe-top)); }
body.demo-active .modal-backdrop { padding-top: calc(var(--demo-height) + var(--safe-top)); }

/* ============================================================
   Desktop (≥900px) — this app is still phone-first (gym/on-the-go
   is the main use case), but it should feel like a real desktop
   app rather than a stretched phone screen when used on a PC.
   Everything below is additive and only applies above the
   breakpoint; phone layout is completely untouched.
   ============================================================ */
.sidebar-nav { display: none; }

@media (min-width: 900px) {
  body { overscroll-behavior-y: auto; }

  /* Bottom tab bar → left sidebar */
  .bottom-nav { display: none; }

  .sidebar-nav {
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: var(--sidebar-width);
    background: var(--bg-elevated);
    border-right: 1px solid var(--border);
    padding: 20px 12px;
    z-index: 10;
    overflow-y: auto;
  }
  .sidebar-brand {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 16px;
    font-weight: 800;
    padding: 8px 12px 20px;
    color: var(--text);
  }
  .sidebar-brand svg { flex-shrink: 0; }
  .sidebar-group {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding-bottom: 16px;
    margin-bottom: 16px;
    border-bottom: 1px solid var(--border);
  }
  .sidebar-group:last-of-type { border-bottom: none; }
  .sidebar-nav button {
    display: flex;
    align-items: center;
    gap: 12px;
    background: none;
    border: none;
    color: var(--text-dim);
    font-size: 14px;
    font-weight: 600;
    text-align: left;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
  }
  .sidebar-nav button .nav-icon { font-size: 17px; }
  .sidebar-nav button:hover { background: var(--card-alt); color: var(--text); }
  .sidebar-nav button.active { background: var(--blue-bg); color: var(--accent); }
  .sidebar-footer { margin-top: auto; padding: 8px 12px 0; }

  /* Content area shifts right of the sidebar and gets real breathing room instead of
     staying pinned to a 560px phone-width column. */
  #app {
    max-width: 760px;
    margin: 0;
    margin-left: calc(var(--sidebar-width) + 48px);
    padding-bottom: 48px;
  }
  body.demo-active .sidebar-nav { top: calc(var(--demo-height) + var(--safe-top)); }

  .topbar {
    padding: 28px 0 16px;
    background: var(--bg);
  }
  .topbar h1 { font-size: 24px; }
  .view { padding: 8px 0 16px; }

  .card { padding: 20px; box-shadow: var(--shadow-card); }

  /* Home dashboard: independent tiles reflow into a real grid instead of one long column. */
  .dash-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; align-items: start; }
  .dash-grid > .card { margin-bottom: 0; }

  /* Bottom-sheet modals read as a mobile pattern — a centered dialog fits a mouse+keyboard
     screen better. */
  .modal-backdrop { align-items: center; padding: 24px; }
  .modal-sheet {
    max-width: 480px;
    border-radius: var(--radius);
    max-height: 80vh;
    padding: 24px;
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
  }

  /* Buttons/lists get pointer-appropriate hover feedback instead of relying on touch :active. */
  .btn-primary:hover { filter: brightness(1.08); }
  .btn-secondary:hover { background: var(--border); }
  .btn-ghost:hover { text-decoration: underline; }
  .list-item, .day-list-item, .program-item, .search-result { cursor: pointer; }
  .day-list-item:hover, .search-result:hover, .program-item:hover { background: var(--border); }
}
