:root {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-alt: #273549;
  --border: #334155;
  --text: #f8fafc;
  --muted: #94a3b8;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --accent: #10b981;
  --shift: #ef4444;
  --shift-bg: rgba(239, 68, 68, 0.14);
  --run-bg: rgba(59, 130, 246, 0.16);
  --done-bg: rgba(16, 185, 129, 0.18);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.hidden { display: none !important; }

.overlay {
  position: fixed; inset: 0;
  background: rgba(2, 6, 23, 0.85);
  display: flex; align-items: center; justify-content: center;
  z-index: 100; padding: 1rem;
}

.pin-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 2rem;
  max-width: 380px; width: 100%;
  text-align: center;
}

.pin-card input {
  width: 100%; padding: 0.75rem; margin: 1rem 0;
  font-size: 1.25rem; text-align: center; letter-spacing: 0.3em;
  border-radius: 8px; border: 1px solid var(--border);
  background: var(--bg); color: var(--text);
}

.topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 1.25rem 1.5rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap; gap: 1rem;
}

.topbar h1 { margin: 0; font-size: 1.25rem; }
.subtitle { margin: 0.25rem 0 0; color: var(--muted); font-size: 0.85rem; }
.topbar-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }

.summary-bar {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 1rem; padding: 1.25rem 1.5rem 0;
}

.stat-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 1rem;
  display: flex; flex-direction: column; gap: 0.25rem;
}
.stat-label { font-size: 0.75rem; text-transform: uppercase; color: var(--muted); letter-spacing: 0.05em; }
.stat-value { font-size: 1.1rem; font-weight: 700; }
.stat-sub { font-size: 0.8rem; color: var(--muted); }

.calendar-controls {
  display: flex; justify-content: space-between; align-items: center;
  padding: 1.25rem 1.5rem; flex-wrap: wrap; gap: 1rem;
}
.month-nav { display: flex; align-items: center; gap: 1rem; }
.month-nav h2 { margin: 0; min-width: 175px; text-align: center; font-size: 1.2rem; }
.legend { display: flex; gap: 0.5rem; flex-wrap: wrap; font-size: 0.8rem; }

.badge {
  padding: 0.25rem 0.55rem; border-radius: 6px; font-weight: 600;
  border: 1px solid var(--border);
}
.badge-shift { background: var(--shift-bg); color: #fca5a5; border-color: rgba(239,68,68,0.4); }
.badge-run { background: var(--run-bg); color: #93c5fd; border-color: rgba(59,130,246,0.4); }
.badge-treadmill { background: rgba(245, 158, 11, 0.16); color: #fcd34d; }
.badge-done { background: var(--done-bg); color: #6ee7b7; }

.calendar-wrapper { padding: 0 1.5rem 2rem; }
.weekdays {
  display: grid; grid-template-columns: repeat(7, 1fr);
  text-align: center; font-weight: 600; color: var(--muted);
  padding-bottom: 0.5rem; font-size: 0.85rem;
}
.calendar-grid {
  display: grid; grid-template-columns: repeat(7, 1fr);
  gap: 0.5rem;
}

.day-cell {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; min-height: 118px; padding: 0.5rem;
  display: flex; flex-direction: column; gap: 0.35rem;
  cursor: pointer; transition: border-color 0.15s, transform 0.1s;
}
.day-cell:hover { border-color: var(--primary); transform: translateY(-1px); }
.day-cell.empty { background: transparent; border-color: transparent; cursor: default; }
.day-cell.empty:hover { transform: none; }
.day-cell.on-shift { border-top: 3px solid var(--shift); }
.day-cell.race-day { border: 2px solid var(--accent); background: rgba(16, 185, 129, 0.12); }

.day-header { display: flex; justify-content: space-between; align-items: center; font-size: 0.85rem; }
.day-num { font-weight: 700; }
.shift-pill {
  font-size: 0.68rem; padding: 1px 5px; border-radius: 4px;
  background: var(--shift-bg); color: #fca5a5; font-weight: 600;
}

.workout-chip {
  background: var(--run-bg); border-left: 3px solid var(--primary);
  border-radius: 5px; padding: 0.35rem 0.45rem;
  font-size: 0.78rem; line-height: 1.3;
}
.workout-chip.treadmill { border-left-color: #f59e0b; background: rgba(245, 158, 11, 0.12); }
.workout-chip.completed { border-left-color: var(--accent); background: var(--done-bg); }
.workout-chip strong { display: block; font-size: 0.8rem; }
.workout-meta { color: var(--muted); font-size: 0.72rem; margin-top: 2px; }

.modal-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; max-width: 640px; width: 100%;
  max-height: 92vh; overflow-y: auto; padding: 1.5rem;
}
.modal-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 1rem; }
.modal-header h2 { margin: 0.2rem 0 0; font-size: 1.2rem; }

.shift-banner {
  display: flex; justify-content: space-between; align-items: center;
  padding: 0.6rem 0.85rem; border-radius: 8px;
  background: var(--surface-alt); margin-bottom: 1rem; font-size: 0.88rem;
}

form label { display: flex; flex-direction: column; gap: 0.3rem; font-size: 0.82rem; color: var(--muted); margin-bottom: 0.75rem; }
input, select, textarea {
  padding: 0.55rem 0.7rem; border-radius: 6px;
  border: 1px solid var(--border); background: var(--bg);
  color: var(--text); font-size: 0.9rem; font-family: inherit;
}

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }
.steps-box {
  border: 1px solid var(--border); border-radius: 8px;
  padding: 0.85rem; margin: 0.5rem 0 1rem;
}
.steps-box legend { padding: 0 0.4rem; font-size: 0.82rem; font-weight: 600; color: #93c5fd; }
.step-group { border-bottom: 1px solid var(--border); padding-bottom: 0.5rem; margin-bottom: 0.65rem; }
.step-group:last-child { border-bottom: none; margin-bottom: 0; padding-bottom: 0; }
.step-group h4 { margin: 0 0 0.5rem; font-size: 0.85rem; color: var(--text); }

.modal-footer {
  display: flex; justify-content: space-between; align-items: center;
  flex-wrap: wrap; gap: 0.75rem; margin-top: 1rem; padding-top: 1rem;
  border-top: 1px solid var(--border);
}
.left-actions, .right-actions { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }
.checkbox-inline { flex-direction: row; align-items: center; margin: 0; color: var(--text); cursor: pointer; }

button {
  cursor: pointer; border: none; border-radius: 7px;
  padding: 0.55rem 0.9rem; font-weight: 600; font-size: 0.85rem;
}
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--surface-alt); color: var(--text); border: 1px solid var(--border); }
.btn-accent { background: var(--accent); color: #052e16; }
.btn-danger { background: rgba(239, 68, 68, 0.2); color: #fca5a5; }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-small { padding: 0.35rem 0.65rem; font-size: 0.78rem; background: var(--surface); color: var(--text); border: 1px solid var(--border); }
.error { color: #fca5a5; font-size: 0.85rem; }
.muted { color: var(--muted); font-size: 0.82rem; }

@media (max-width: 760px) {
  .calendar-grid { grid-template-columns: repeat(1, 1fr); }
  .weekdays { display: none; }
  .day-cell { min-height: auto; }
  .form-row { grid-template-columns: 1fr; }
}