/* ============================================================================
   DESIGN TOKENS
   ============================================================================ */
:root {
  --bg: #0a0a0a;
  --surface: #161616;
  --surface-2: #1f1f1f;
  --border: #262626;
  --text: #f5f5f5;
  --text-muted: #8a8a8a;
  --text-subtle: #5a5a5a;
  --accent: #2DD587;
  --accent-dim: #2DD58722;
  --danger: #ef4444;
  --warn: #f59e0b;
  --radius: 16px;
  --radius-sm: 10px;
  --radius-lg: 24px;
  --gap: 12px;
  --pad: 16px;
  --tap: 48px;
  --nav-h: 64px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
  --shadow: 0 1px 0 rgba(255,255,255,0.04) inset, 0 8px 24px rgba(0,0,0,0.25);
  --transition: 150ms cubic-bezier(.2,.8,.2,1);
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #fafafa;
    --surface: #ffffff;
    --surface-2: #f3f3f3;
    --border: #e5e5e5;
    --text: #0a0a0a;
    --text-muted: #6b6b6b;
    --text-subtle: #9a9a9a;
    --shadow: 0 1px 0 rgba(0,0,0,0.02) inset, 0 4px 16px rgba(0,0,0,0.06);
  }
}

/* ============================================================================
   BASE
   ============================================================================ */
*, *::before, *::after { box-sizing: border-box; }

/* Wichtig: color-scheme synchronisiert native Form-Controls (iOS Safari rendert
   sonst weisse Schrift in light-mode-Inputs auf hellem Hintergrund). */
html { color-scheme: light dark; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  padding-bottom: calc(var(--nav-h) + var(--safe-bottom) + 12px);
}

button { font: inherit; color: inherit; cursor: pointer; }
a { color: inherit; text-decoration: none; }
input, textarea, select { font: inherit; color: inherit; }

h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 22px; }
h2 { font-size: 18px; }
h3 { font-size: 16px; }
p  { margin: 0; }

/* ============================================================================
   APP CONTAINER
   ============================================================================ */
.app {
  max-width: 480px;
  margin: 0 auto;
  padding: calc(var(--safe-top) + 16px) var(--pad) var(--pad);
  display: flex;
  flex-direction: column;
  gap: var(--gap);
}

/* ============================================================================
   HEADER (page header)
   ============================================================================ */
.page-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0 8px;
  min-height: 44px;
}
.page-header .back-btn {
  background: none;
  border: 0;
  width: 36px; height: 36px;
  display: inline-flex;
  align-items: center; justify-content: center;
  border-radius: 12px;
  margin-left: -6px;
  color: var(--text);
  transition: background var(--transition);
}
.page-header .back-btn:hover { background: var(--surface-2); }
.page-header .back-btn svg { width: 22px; height: 22px; fill: currentColor; }
.page-header .title-block { flex: 1; min-width: 0; }
.page-header .eyebrow {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.page-header h1 {
  font-size: 22px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ============================================================================
   CARD
   ============================================================================ */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--pad);
  box-shadow: var(--shadow);
}
.card + .card { /* no extra space, .stack handles it */ }

.card-link {
  display: block;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--pad);
  transition: transform var(--transition), border-color var(--transition);
}
.card-link:active { transform: scale(0.99); }
.card-link:hover { border-color: var(--accent); }

.card-title { font-size: 17px; font-weight: 600; margin-bottom: 4px; }
.card-meta  { font-size: 13px; color: var(--text-muted); }

.stack { display: flex; flex-direction: column; gap: var(--gap); }
.row   { display: flex; align-items: center; gap: 8px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.spread { flex: 1; }

/* ============================================================================
   CHIP / BADGE
   ============================================================================ */
.chip {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 500;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.chip.accent { background: var(--accent-dim); color: var(--accent); border-color: transparent; }
.chip.warn   { background: #f59e0b22; color: var(--warn); border-color: transparent; }
.chip.danger { background: #ef444422; color: var(--danger); border-color: transparent; }

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 600;
  border-radius: 999px;
}
.status-pill.up   { background: #2DD58722; color: #2DD587; }
.status-pill.down { background: #ef444422; color: #ef4444; }
.status-pill.same { background: #8a8a8a22; color: var(--text-muted); }
.status-pill.new  { background: #3b82f622; color: #60a5fa; }

/* ============================================================================
   BUTTON
   ============================================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: var(--tap);
  padding: 0 18px;
  border-radius: 12px;
  border: 1px solid transparent;
  font-weight: 600;
  font-size: 15px;
  transition: background var(--transition), transform var(--transition);
}
.btn:active { transform: scale(0.98); }

.btn-primary {
  background: var(--accent);
  color: #052e1a;
}
.btn-primary:hover { background: #3ee596; }

.btn-ghost {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--border);
}
.btn-ghost:hover { background: var(--surface); }

.btn-block { width: 100%; }

.btn-icon {
  width: 40px; height: 40px;
  border-radius: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  display: inline-flex;
  align-items: center; justify-content: center;
}
.btn-icon svg { width: 20px; height: 20px; fill: currentColor; }

/* ============================================================================
   EXERCISE CARD
   ============================================================================ */
.exercise {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.exercise-head {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: var(--pad);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.exercise-thumb {
  width: 56px; height: 56px;
  border-radius: 12px;
  background: var(--surface-2);
  display: inline-flex;
  align-items: center; justify-content: center;
  font-size: 22px;
  font-weight: 700;
  color: var(--text-muted);
  flex-shrink: 0;
}
.exercise-info { flex: 1; min-width: 0; }
.exercise-name { font-size: 16px; font-weight: 600; }
.exercise-meta {
  font-size: 13px; color: var(--text-muted);
  margin-top: 2px;
  display: flex; gap: 8px; flex-wrap: wrap;
}
.exercise-status {
  display: flex; align-items: center; gap: 6px;
  font-size: 13px; color: var(--text-muted);
  margin-top: 4px;
}
.exercise-status .check {
  width: 14px; height: 14px;
  border-radius: 50%;
  border: 1.5px solid var(--text-subtle);
  display: inline-flex; align-items: center; justify-content: center;
}
.exercise-status.done .check {
  background: var(--accent);
  border-color: var(--accent);
}
.exercise-status.done .check::after {
  content: "";
  width: 6px; height: 3px;
  border-left: 2px solid #052e1a;
  border-bottom: 2px solid #052e1a;
  transform: rotate(-45deg) translate(0, -1px);
}
.exercise-toggle {
  background: none; border: 0;
  width: 32px; height: 32px;
  border-radius: 8px;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--text-muted);
  flex-shrink: 0;
  transition: transform var(--transition);
}
.exercise-toggle svg { width: 18px; height: 18px; fill: currentColor; }
.exercise.open .exercise-toggle { transform: rotate(180deg); }

.exercise-body {
  display: none;
  padding: 0 var(--pad) var(--pad);
  border-top: 1px solid var(--border);
}
.exercise.open .exercise-body { display: block; }

.exercise-desc {
  font-size: 14px;
  color: var(--text-muted);
  padding: 12px 0 0;
  line-height: 1.5;
}
.cue-list {
  list-style: none;
  padding: 8px 0 0;
  margin: 0;
  display: flex; flex-direction: column; gap: 4px;
}
.cue-list li {
  font-size: 13px;
  color: var(--text-muted);
  padding-left: 16px;
  position: relative;
}
.cue-list li::before {
  content: "·";
  position: absolute;
  left: 4px;
  color: var(--accent);
  font-weight: 700;
}

/* ============================================================================
   SET ROW
   ============================================================================ */
.sets {
  margin-top: 14px;
  display: flex; flex-direction: column; gap: 8px;
}
.set-row {
  display: grid;
  grid-template-columns: 24px 1fr 1fr 56px 36px;
  gap: 6px;
  align-items: center;
}
.set-row.header {
  font-size: 11px;
  color: var(--text-subtle);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 0 2px;
}
.set-row .num {
  text-align: center;
  font-weight: 600;
  color: var(--text-muted);
  font-size: 14px;
}

.set-input {
  appearance: none;
  -webkit-appearance: none;
  width: 100%;
  height: 44px;
  padding: 0 10px;
  border-radius: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  text-align: center;
  font-size: 15px;
  font-weight: 500;
  transition: border-color var(--transition), background var(--transition);
}
.set-input::placeholder { color: var(--text-subtle); opacity: 1; }
.set-input:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--surface);
}
.set-input.filled {
  border-color: var(--accent);
}

.set-rpe {
  appearance: none;
  -webkit-appearance: none;
  height: 44px;
  padding: 0 6px;
  border-radius: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  text-align: center;
  font-size: 14px;
  width: 100%;
}

.set-remove {
  background: none;
  border: 0;
  color: var(--text-subtle);
  width: 36px; height: 36px;
  border-radius: 8px;
  display: inline-flex; align-items: center; justify-content: center;
  transition: color var(--transition), background var(--transition);
}
.set-remove:hover { color: var(--danger); background: var(--surface-2); }
.set-remove svg { width: 16px; height: 16px; fill: currentColor; }

.set-actions {
  margin-top: 10px;
  display: flex; gap: 8px;
}
.set-actions .btn { flex: 1; min-height: 40px; padding: 0 12px; font-size: 14px; }

/* ============================================================================
   NOTES + ALT
   ============================================================================ */
.notes-block {
  margin-top: 14px;
  display: flex; flex-direction: column; gap: 8px;
}
.notes-block label {
  font-size: 12px;
  color: var(--text-subtle);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.notes-block input,
.notes-block textarea,
.notes-block select {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  color: var(--text);
  font-size: 14px;
  resize: vertical;
}
.notes-block textarea { min-height: 60px; }
.notes-block input::placeholder,
.notes-block textarea::placeholder { color: var(--text-subtle); opacity: 1; }
.notes-block input:focus,
.notes-block textarea:focus,
.notes-block select:focus {
  outline: none;
  border-color: var(--accent);
}

/* ============================================================================
   SUMMARY (Tagesabschluss)
   ============================================================================ */
.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--gap);
}
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}
.stat .label {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.stat .value {
  font-size: 26px;
  font-weight: 700;
  margin-top: 4px;
  letter-spacing: -0.02em;
}
.stat .value small { font-size: 14px; font-weight: 500; color: var(--text-muted); }

/* ============================================================================
   PROGRESS / HISTORY
   ============================================================================ */
.progress-list { display: flex; flex-direction: column; gap: var(--gap); }

.progress-item {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px var(--pad);
  transition: border-color var(--transition);
}
.progress-item:hover { border-color: var(--accent); }
.progress-item .info { flex: 1; min-width: 0; }
.progress-item .name { font-weight: 600; font-size: 15px; }
.progress-item .sub  { font-size: 13px; color: var(--text-muted); margin-top: 2px; }
.progress-item .arrow { color: var(--text-subtle); }
.progress-item .arrow svg { width: 18px; height: 18px; fill: currentColor; }

.history-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.history-row:last-child { border-bottom: 0; }
.history-row .date {
  font-size: 13px;
  color: var(--text-muted);
  min-width: 80px;
}
.history-row .summary {
  font-size: 14px;
  font-weight: 500;
}
.history-row .summary small {
  display: block;
  font-size: 12px;
  font-weight: 400;
  color: var(--text-muted);
  margin-top: 2px;
}

/* simple bar chart */
.chart {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  height: 100px;
  padding: 8px 0 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 8px;
}
.chart .bar {
  flex: 1;
  background: var(--accent-dim);
  border-radius: 4px 4px 0 0;
  position: relative;
  min-height: 4px;
  transition: height var(--transition);
}
.chart .bar.peak { background: var(--accent); }
.chart-meta {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-subtle);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

/* ============================================================================
   EMPTY STATE
   ============================================================================ */
.empty {
  text-align: center;
  padding: 32px 16px;
  color: var(--text-muted);
}
.empty .icon {
  width: 48px; height: 48px;
  border-radius: 50%;
  background: var(--surface-2);
  margin: 0 auto 12px;
  display: inline-flex;
  align-items: center; justify-content: center;
  color: var(--text-subtle);
}
.empty .icon svg { width: 24px; height: 24px; fill: currentColor; }
.empty p { margin-top: 4px; font-size: 14px; }

/* ============================================================================
   BOTTOM NAV
   ============================================================================ */
.bottom-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: calc(var(--nav-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: rgba(10, 10, 10, 0.85);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-top: 1px solid var(--border);
  display: flex;
  z-index: 100;
}
@media (prefers-color-scheme: light) {
  .bottom-nav { background: rgba(255, 255, 255, 0.85); }
}
.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 500;
  transition: color var(--transition);
  -webkit-tap-highlight-color: transparent;
}
.nav-item svg {
  width: 22px; height: 22px;
  fill: currentColor;
}
.nav-item.active { color: var(--accent); }

/* ============================================================================
   LAST-WORKOUT HINT (unter jeder Set-Row)
   ============================================================================ */
.last-hint {
  font-size: 11px;
  color: var(--text-subtle);
  padding: 2px 0 4px 30px;          /* aligned mit num-Spalte */
  letter-spacing: 0.01em;
  margin-top: -4px;
}
.last-hint strong {
  color: var(--text-muted);
  font-weight: 600;
}

/* ============================================================================
   SYNC PILL (im Page-Header rechts)
   ============================================================================ */
.sync-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px 4px 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: lowercase;
  letter-spacing: 0.02em;
  margin-left: auto;
  -webkit-tap-highlight-color: transparent;
  cursor: pointer;
  transition: background var(--transition);
  flex-shrink: 0;
}
.sync-pill:active { background: var(--surface); }
.sync-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--text-subtle);
}
.sync-pill.ok   .sync-dot { background: var(--accent); box-shadow: 0 0 6px var(--accent-dim); }
.sync-pill.warn .sync-dot { background: var(--warn); }
.sync-pill.err  .sync-dot { background: var(--danger); }
.sync-pill.off  .sync-dot { background: var(--text-subtle); }

/* ============================================================================
   MODAL
   ============================================================================ */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 200;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 16px;
  padding-bottom: calc(16px + var(--safe-bottom));
  animation: fade-in 180ms ease-out;
}
.modal {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px 20px 16px 16px;
  padding: 20px;
  box-shadow: 0 -4px 32px rgba(0, 0, 0, 0.4);
  animation: slide-up 220ms cubic-bezier(.2,.8,.2,1);
}
@media (min-width: 480px) {
  .modal-backdrop { align-items: center; }
  .modal { border-radius: 16px; }
}
.modal h2 { font-size: 18px; margin-bottom: 4px; }
.modal input[type="text"] {
  width: 100%;
  height: 44px;
  padding: 0 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-size: 14px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  margin: 8px 0 12px;
}
.modal input[type="text"]:focus {
  outline: none;
  border-color: var(--accent);
}
.modal-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}
.modal-actions .btn { flex: 1; }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes slide-up {
  from { opacity: 0; transform: translateY(20px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ============================================================================
   PAUSE-TIMER (Floating Pill am unteren Rand, ueber der Bottom-Nav)
   ============================================================================ */
.pause-timer {
  position: fixed;
  left: 50%;
  bottom: calc(var(--nav-h) + var(--safe-bottom) + 12px);
  transform: translateX(-50%) translateY(120%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
  z-index: 90;
  opacity: 0;
  transition: transform 240ms cubic-bezier(.2,.8,.2,1), opacity 240ms;
  pointer-events: none;
  min-width: 240px;
}
.pause-timer.active {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
  pointer-events: auto;
}
.pause-timer.done {
  border-color: var(--accent);
  box-shadow: 0 12px 32px rgba(45, 213, 135, 0.35);
}
.pause-label {
  font-size: 10px;
  color: var(--text-subtle);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  min-width: 50px;
}
.pause-timer.done .pause-label { color: var(--accent); }
.pause-time {
  font-size: 22px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  color: var(--text);
  flex: 1;
  text-align: center;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
}
.pause-timer.done .pause-time {
  color: var(--accent);
  font-size: 16px;
  letter-spacing: 0.04em;
}
.pause-actions { display: flex; gap: 6px; }
.pause-btn {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  -webkit-tap-highlight-color: transparent;
}
.pause-btn:active { background: var(--surface); }

/* ============================================================================
   UTILITIES
   ============================================================================ */
.muted { color: var(--text-muted); }
.subtle { color: var(--text-subtle); font-size: 13px; }
.section-title {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-subtle);
  font-weight: 600;
  margin: 4px 4px 0;
}
hr.divider {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 4px 0;
}
