:root {
  --bg: #0f172a;
  --surface: #1e293b;
  --text: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-dim: #64748b;
  --accent: #6366f1;
  --accent2: #06b6d4;
  --border: rgba(255,255,255,0.08);
  --shadow: 0 4px 12px rgba(0,0,0,0.25);
  --shadow-sm: 0 2px 6px rgba(0,0,0,0.2);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.35);
  --radius-card: 12px;
  --radius-input: 8px;
  --font: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
}

[data-theme="light"] {
  --bg: #f8fafc;
  --surface: #ffffff;
  --text: #0f172a;
  --text-secondary: #64748b;
  --text-dim: #94a3b8;
  --accent: #4f46e5;
  --accent2: #0891b2;
  --border: rgba(0,0,0,0.08);
  --shadow: 0 4px 12px rgba(0,0,0,0.08);
  --shadow-sm: 0 2px 6px rgba(0,0,0,0.05);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.1);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.container {
  width: 100%;
  padding: 0 32px;
  box-sizing: border-box;
}

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 2rem;
}

header h1 {
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -0.025em;
}

#theme-toggle {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.5rem 0.875rem;
  border-radius: var(--radius-input);
  cursor: pointer;
  font-size: 1.125rem;
  transition: transform 0.2s;
}

#theme-toggle:hover {
  transform: scale(1.06);
}

.grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 24px;
  align-items: start;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: 24px;
  box-shadow: var(--shadow);
  min-height: auto;
  width: 100%;
  position: relative;
  overflow: hidden;
}

.card.wide {
  grid-column: 1 / -1;
  min-height: auto;
}

.card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--section-accent, var(--accent));
  border-radius: var(--radius-card) var(--radius-card) 0 0;
}

.card h2 {
  font-size: 28px;
  font-weight: 700;
  margin-bottom: 1.25rem;
  color: var(--section-accent, var(--accent));
}

/* Buttons */
.btn-primary {
  background: var(--accent);
  color: white;
  border: none;
  padding: 0.65rem 1.25rem;
  border-radius: var(--radius-input);
  cursor: pointer;
  font-weight: 600;
  font-size: 16px;
  transition: filter 0.2s, transform 0.2s;
}

.btn-primary:hover {
  filter: brightness(1.1);
  transform: translateY(-1px);
}

.btn-secondary {
  background: var(--surface);
  color: var(--text-secondary);
  border: 1.5px solid var(--border);
  padding: 0.5rem 1rem;
  border-radius: var(--radius-input);
  cursor: pointer;
  font-size: 16px;
  font-weight: 500;
  transition: border-color 0.2s, color 0.2s;
}

.btn-secondary:hover {
  color: var(--text);
  border-color: var(--text-secondary);
}

.btn-full { width: 100%; }
.btn-center { display: block; margin: 0 auto; }

/* Progress */
.progress-track {
  width: 100%;
  height: 8px;
  background: var(--bg);
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.progress-fill {
  height: 100%;
  background: var(--section-accent, var(--accent));
  transition: width 0.3s ease;
}

/* Profile */
#profile-section {
  --section-accent: #6366f1;
  grid-column: span 2;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  align-items: start;
}

#profile-section > h2 {
  grid-column: 1 / -1;
}

#profile-section > .profile-grid,
#profile-section > #calculate-calories,
#profile-section > .sleep-group {
  grid-column: 1;
}

#profile-section > .profile-results {
  grid-column: 2;
  grid-row: 2 / span 3;
  margin-top: 0;
  padding-top: 0;
  border-top: none;
}

#profile-section > .macro-calculator {
  grid-column: 1 / -1;
}

.profile-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 1rem;
}

.profile-grid .full {
  grid-column: 1 / -1;
}

.form-group {
  margin-bottom: 1rem;
}

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 4px;
}

#profile-section .form-group input,
#profile-section .form-group select {
  width: 100%;
  height: 44px;
  padding: 10px;
  font-size: 16px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-input);
  background: var(--bg);
  color: var(--text);
  outline: none;
}

.form-group input,
.form-group select {
  width: 100%;
  height: 44px;
  padding: 0.65rem 0.875rem;
  font-size: 16px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-input);
  background: var(--bg);
  color: var(--text);
  outline: none;
}

.form-group input:focus,
.form-group select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

.optional {
  text-transform: none;
  font-weight: 400;
  color: var(--text-dim);
  letter-spacing: 0;
  margin-left: 0.35rem;
  font-size: 0.7rem;
}

.sleep-group {
  margin-top: 0.5rem;
}

.profile-results {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 1.25rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border);
}

.profile-result-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-input);
  padding: 1rem;
  text-align: center;
}

.profile-result-label {
  display: block;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 0.25rem;
}

.profile-result-value {
  display: block;
  font-size: 32px;
  font-weight: 700;
  color: var(--section-accent, var(--accent));
}

/* Macro Calculator */
.macro-calculator {
  margin-top: 1.25rem;
  padding-top: 1.25rem;
  border-top: 1px dashed var(--border);
}

.macro-header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.macro-calories {
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--text);
}

.macro-calories strong {
  color: var(--section-accent, var(--accent));
  font-size: 1.125rem;
}

.macro-presets {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.macro-preset {
  background: var(--bg);
  border: 1.5px solid var(--border);
  color: var(--text-secondary);
  padding: 0.4rem 0.875rem;
  border-radius: var(--radius-input);
  cursor: pointer;
  font-size: 0.8125rem;
  font-weight: 600;
  transition: all 0.2s;
}

.macro-preset:hover,
.macro-preset.active {
  border-color: var(--section-accent, var(--accent));
  color: var(--section-accent, var(--accent));
  background: rgba(99, 102, 241, 0.08);
}

.macro-sliders {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.macro-slider-group {
  display: grid;
  grid-template-columns: 1fr 1.5fr auto;
  gap: 0.75rem;
  align-items: center;
}

.macro-slider-group label {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-secondary);
  display: flex;
  justify-content: space-between;
}

.macro-slider-group input[type="range"] {
  width: 100%;
  accent-color: var(--section-accent, var(--accent));
  cursor: pointer;
}

.macro-grams {
  font-size: 0.9375rem;
  font-weight: 700;
  color: var(--section-accent, var(--accent));
  min-width: 48px;
  text-align: right;
}

/* Workout */
#workout-section {
  --section-accent: #10b981;
  grid-column: span 4;
  overflow: visible;
}

#exercise-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 1rem;
}

.exercise-header {
  display: grid;
  grid-template-columns: 2fr 70px 70px 80px 1fr 36px;
  gap: 10px;
  align-items: center;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.exercise-header span:nth-child(2),
.exercise-header span:nth-child(3),
.exercise-header span:nth-child(4) {
  text-align: center;
}

.exercise-header span:nth-child(5) {
  text-align: right;
}

.exercise-header span:last-child {
  width: 36px;
  text-align: center;
}

.exercise-row {
  display: grid;
  grid-template-columns: 2fr 70px 70px 80px 1fr 36px;
  gap: 10px;
  align-items: center;
  min-height: 48px;
}

.exercise-name-wrap {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.exercise-row .exercise-name,
.exercise-row .exercise-custom,
.exercise-row .exercise-num {
  width: 100%;
  height: 44px;
  padding: 10px;
  font-size: 16px;
  border-radius: var(--radius-input);
  border: 1.5px solid var(--border);
  background: var(--bg);
  color: var(--text);
  outline: none;
}

.exercise-row .exercise-name:focus,
.exercise-row .exercise-custom:focus,
.exercise-row .exercise-num:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

.exercise-row .exercise-custom {
  margin-top: 4px;
}

.row-volume {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--section-accent, var(--accent));
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 10px 0;
}

.btn-remove {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #ef4444;
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-size: 1.1rem;
  font-weight: 700;
  line-height: 1;
  padding: 0;
  flex-shrink: 0;
  transition: background 0.2s, transform 0.2s;
}

.btn-remove:hover {
  background: #dc2626;
  transform: scale(1.05);
}

.volume-card {
  margin-top: 1.25rem;
  padding: 16px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-input);
  text-align: center;
}

.volume-label {
  display: block;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 0.5rem;
}

.volume-value {
  display: block;
  font-size: 2rem;
  font-weight: 700;
  color: var(--section-accent, var(--accent));
}

#add-exercise {
  width: 100%;
  height: 46px;
  margin-top: 16px;
}

/* Water */
#water-section {
  --section-accent: #06b6d4;
  --water-accent: #06b6d4;
  grid-column: 1 / -1;
  width: 100%;
  padding: 24px;
}

.cups-grid {
  display: flex;
  flex-wrap: nowrap;
  justify-content: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.cup {
  width: 52px;
  height: 68px;
  background: var(--bg);
  border: 2px solid var(--border);
  border-radius: var(--radius-input);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  user-select: none;
}

.cup.filled {
  background: rgba(6, 182, 212, 0.15);
  border-color: var(--water-accent);
  box-shadow: 0 0 8px rgba(6, 182, 212, 0.2);
}

.water-info {
  margin-bottom: 1rem;
}

.water-display-text {
  display: block;
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 0.5rem;
  text-align: center;
}

.water-track {
  margin-bottom: 0;
}

.btn-reset {
  display: block;
  margin: 0.75rem 0 0;
  background: transparent;
  color: var(--text-dim);
  border: none;
  font-size: 0.75rem;
  font-weight: 500;
  cursor: pointer;
  padding: 0.2rem 0.4rem;
  transition: color 0.2s;
}

.btn-reset:hover {
  color: #ef4444;
}

/* Results */
#results-section {
  --section-accent: #8b5cf6;
  grid-column: span 3;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 1.5rem;
}

.stat-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-input);
  padding: 1rem;
  text-align: center;
}

.stat-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 0.5rem;
}

.stat-value {
  font-size: 22px;
  font-weight: 700;
  color: var(--section-accent, var(--accent));
  margin-bottom: 0.5rem;
}

.charts-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
}

.chart-container {
  position: relative;
  max-height: 180px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-input);
  padding: 1rem;
}

/* Calendar */
#calendar-section {
  --section-accent: #7c3aed;
  grid-column: span 3;
}

.calendar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

.calendar-month-label {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
}

.calendar-header .btn-secondary {
  font-size: 14px;
  padding: 4px 10px;
}

.calendar-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 0.5rem;
  margin-bottom: 0.5rem;
  text-align: center;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
}

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 0.5rem;
}

.calendar-day {
  aspect-ratio: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-input);
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  position: relative;
  padding: 0.25rem;
  max-height: 60px;
}

.calendar-day.empty {
  background: transparent;
  border: none;
  cursor: default;
}

.calendar-day.has-data::after {
  content: '';
  position: absolute;
  bottom: 6px;
  width: 6px;
  height: 6px;
  background: var(--section-accent, var(--accent));
  border-radius: 50%;
}

.calendar-day.today {
  border-color: var(--section-accent, var(--accent));
  color: var(--section-accent, var(--accent));
  background: rgba(99, 102, 241, 0.08);
}

/* History */
#history-section {
  --section-accent: #7c3aed;
  grid-column: 1 / -1;
}

.streak-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.4rem 1rem;
  margin-bottom: 1.25rem;
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--text);
}

.streak-icon { font-size: 1.125rem; }
.streak-number { color: #f59e0b; font-weight: 700; }
.streak-label { color: var(--text-secondary); font-weight: 500; }

.history-charts {
  margin-bottom: 1.5rem;
}

.history-days {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.day-row {
  display: grid;
  grid-template-columns: 80px 1fr auto;
  gap: 1rem;
  align-items: center;
  padding: 0.75rem 1rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-input);
  cursor: pointer;
}

.day-row.active {
  border-color: var(--section-accent, var(--accent));
  background: rgba(99, 102, 241, 0.08);
}

.day-date {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text);
}

.day-cups {
  display: flex;
  gap: 4px;
}

.day-cup {
  width: 12px;
  height: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 2px;
}

.day-cup.filled {
  background: var(--water-accent, var(--accent2));
  border-color: var(--water-accent, var(--accent2));
}

.day-stats {
  font-size: 0.75rem;
  color: var(--text-secondary);
  line-height: 1.5;
  font-weight: 500;
}

.day-stats strong {
  color: var(--text);
  font-weight: 700;
}

/* Mobile */
@media (max-width: 768px) {
  .grid { grid-template-columns: 1fr; }
  #profile-section { order: 1; }
  #workout-section { order: 2; }
  #water-section { order: 3; }
  .container { padding: 1rem; }
  header h1 { font-size: 1.5rem; }
}

@media (max-width: 640px) {
  .profile-grid { grid-template-columns: 1fr; }
  .profile-results { grid-template-columns: 1fr 1fr; }
  .exercise-header { display: none; }
  .exercise-row {
    grid-template-columns: 1fr 1fr 1fr auto auto;
    row-gap: 0.5rem;
  }
  .exercise-row .exercise-name-wrap { grid-column: 1 / -1; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .charts-row { grid-template-columns: 1fr; }
  .day-row { grid-template-columns: 60px 1fr; gap: 0.5rem; }
  .day-cups { display: none; }
}

/* ── Weekly Calendar ── */
.week-tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}
.wk-tab {
  background: var(--bg);
  border: 1.5px solid var(--border);
  color: var(--text-secondary);
  padding: 0.4rem 0.875rem;
  border-radius: var(--radius-input);
  cursor: pointer;
  font-size: 0.8125rem;
  font-weight: 600;
  transition: all 0.2s;
}
.wk-tab:hover {
  color: var(--text);
  border-color: var(--text-secondary);
}
.wk-tab.active {
  border-color: var(--section-accent, var(--accent));
  color: var(--section-accent, var(--accent));
  background: rgba(99, 102, 241, 0.08);
}
.wk-tab.current {
  box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.25);
}
.calendar-day.out-of-month {
  opacity: 0.4;
}
.calendar-day.current-day {
  border-color: #10b981;
  color: #10b981;
}

/* ── Weekly Summary ── */
#weekly-summary { margin-top: 1.5rem; }
.wk-summary-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  flex-wrap: wrap;
  gap: 0.5rem;
}
.wk-summary-header h3 {
  font-size: 1.125rem;
  color: var(--text);
}
.wk-summary-dates {
  font-size: 0.8125rem;
  color: var(--text-dim);
  font-weight: 500;
}
.wk-summary-table-wrap { overflow-x: auto; }
.wk-summary-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9375rem;
}
.wk-summary-table th {
  text-align: left;
  padding: 0.75rem;
  color: var(--text-secondary);
  font-weight: 600;
  border-bottom: 1px solid var(--border);
  text-transform: uppercase;
  font-size: 0.75rem;
  letter-spacing: 0.05em;
}
.wk-summary-table td {
  padding: 0.75rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.wk-summary-table tbody tr:nth-child(odd) {
  background: rgba(255,255,255,0.03);
}
[data-theme="light"] .wk-summary-table tbody tr:nth-child(odd) {
  background: rgba(0,0,0,0.02);
}
.wk-td-exercise { font-weight: 600; }
.wk-change-up { color: #10b981; font-weight: 700; }
.wk-change-down { color: #ef4444; font-weight: 700; }
.wk-change-same { color: var(--text-dim); font-weight: 700; }
.wk-row-progressed { border-left: 3px solid #10b981; }
.wk-row-maintained { border-left: 3px solid #f59e0b; }
.wk-row-regressed { border-left: 3px solid #ef4444; }
.wk-row-new { border-left: 3px solid #6366f1; }
.wk-target { display: inline-block; font-size: 0.8125rem; font-weight: 600; padding: 0.25rem 0.5rem; border-radius: 6px; }
.wk-target-new { background: rgba(99,102,241,0.12); color: #6366f1; }
.wk-target-repeat { background: rgba(239,68,68,0.12); color: #ef4444; }
.wk-target-options { display: flex; flex-direction: column; gap: 0.35rem; }
.wk-target-option {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8125rem;
  color: var(--text);
}
.wk-target-label {
  font-size: 0.6875rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-secondary);
  background: var(--bg);
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  border: 1px solid var(--border);
}

/* ── Modal ── */
.wk-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(4px);
}
.wk-modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: 1.5rem;
  width: 90%;
  max-width: 400px;
  box-shadow: var(--shadow-lg);
}
.wk-modal h3 { margin-bottom: 0.5rem; color: var(--text); }
.wk-modal-sub { color: var(--text-secondary); font-size: 0.875rem; margin-bottom: 1rem; }
.wk-days { display: flex; flex-direction: column; gap: 0.5rem; margin-bottom: 1.25rem; }
.wk-day-label { display: flex; align-items: center; gap: 0.5rem; cursor: pointer; color: var(--text); font-size: 0.9375rem; padding: 0.4rem; border-radius: 6px; transition: background 0.15s; }
.wk-day-label:hover { background: rgba(255,255,255,0.04); }
[data-theme="light"] .wk-day-label:hover { background: rgba(0,0,0,0.03); }
.wk-day-label input { width: 18px; height: 18px; accent-color: var(--accent); cursor: pointer; }
.wk-day-label small { color: var(--text-dim); font-size: 0.75rem; }
.wk-modal-actions { display: flex; justify-content: flex-end; gap: 0.75rem; }

/* ── Toast ── */
.wk-toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--surface);
  color: var(--text);
  padding: 0.75rem 1.5rem;
  border-radius: var(--radius-input);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  font-weight: 600;
  font-size: 0.9375rem;
  z-index: 2000;
  opacity: 0;
  transition: opacity 0.3s, transform 0.3s;
  pointer-events: none;
}
.wk-toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ================================
   RESPONSIVE - Tablet
   ================================ */
@media (max-width: 1024px) {
  .grid { grid-template-columns: 1fr 1fr; }
  #water-section { grid-column: 1 / -1; }
  #overload-section { grid-column: 1 / -1; }
}

/* ================================
   RESPONSIVE - Mobile Overrides
   ================================ */
@media (max-width: 768px) {
  body { overflow-x: hidden; font-size: 14px; line-height: 1.5; }
  .container { padding: 16px; }

  .grid { grid-template-columns: 1fr; gap: 16px; }
  #profile-section { order: 1; grid-column: auto; }
  #workout-section { order: 2; grid-column: auto; }
  #water-section { order: 3; grid-column: auto; }

  .card { padding: 16px; border-radius: 10px; }
  .card h2 { font-size: 20px; margin-bottom: 1rem; }
  .card.wide { grid-column: auto; }

  header { margin-bottom: 1.25rem; }
  header h1 { font-size: 1.5rem; }

  /* Inputs & selects */
  .form-group input,
  .form-group select,
  #profile-section .form-group input,
  #profile-section .form-group select,
  .exercise-row .exercise-name,
  .exercise-row .exercise-custom,
  .exercise-row .exercise-num {
    font-size: 16px;
    height: 48px;
    width: 100%;
    -webkit-appearance: none;
    border-radius: 8px;
    touch-action: manipulation;
  }

  /* Buttons */
  .btn-primary,
  .btn-secondary,
  .macro-preset,
  #add-exercise,
  #calculate-calories,
  #reset-water,
  .btn-reset {
    font-size: 16px;
    padding: 14px;
    width: 100%;
    min-height: 44px;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
  }

  /* Profile */
  #profile-section { display: block; }
  .profile-grid { grid-template-columns: 1fr; gap: 0; }
  .profile-results {
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-top: 1rem;
    padding-top: 1rem;
  }
  .profile-result-value { font-size: 24px; }
  .profile-result-label { font-size: 11px; }

  /* Workout */
  .exercise-header { display: none; }
  .exercise-row {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 8px;
    padding: 12px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    margin-bottom: 8px;
  }
  .exercise-row .exercise-name-wrap { grid-column: 1 / -1; }
  .exercise-row .exercise-name,
  .exercise-row .exercise-custom {
    height: 44px;
  }
  .exercise-row .exercise-num {
    height: 44px;
    text-align: center;
  }
  .row-volume {
    grid-column: 1 / span 2;
    justify-content: flex-start;
    font-size: 0.875rem;
    padding: 4px 0;
  }
  .btn-remove {
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
    justify-self: end;
  }
  #add-exercise { margin-top: 8px; height: auto; }

  /* Water */
  .cups-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 8px;
    justify-items: center;
  }
  .cup {
    width: 40px;
    height: 56px;
    font-size: 1rem;
    min-width: 44px;
    min-height: 44px;
  }

  /* Results / Stats */
  .stats-grid {
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 1rem;
  }
  .stat-card { padding: 12px; }
  .stat-value { font-size: 24px; }
  .stat-label { font-size: 11px; }

  /* Calendar */
  .week-tabs { gap: 6px; }
  .wk-tab {
    font-size: 12px;
    padding: 6px 10px;
    min-height: 36px;
    flex: 1 1 auto;
  }
  .calendar-weekdays { gap: 4px; font-size: 10px; }
  .calendar-grid { gap: 4px; }
  .calendar-day {
    height: 40px;
    font-size: 11px;
    max-height: 40px;
    min-height: 40px;
    min-width: 40px;
  }

  /* Weekly summary table */
  .wk-summary-table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .wk-summary-table { font-size: 13px; }
  .wk-summary-table th,
  .wk-summary-table td {
    padding: 10px 8px;
    white-space: nowrap;
  }
  .wk-summary-table td:last-child {
    white-space: normal;
    min-width: 140px;
  }

  /* Progressive Overload */
  .overload-table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .overload-table { font-size: 13px; }
  .overload-table th,
  .overload-table td {
    padding: 10px 8px;
    white-space: nowrap;
  }
  .rec-grid { grid-template-columns: 1fr; }
  .wk-target-options {
    flex-direction: column;
    gap: 6px;
  }
  .wk-target-option {
    flex-wrap: wrap;
  }

  /* History */
  .charts-row { grid-template-columns: 1fr; gap: 1rem; }
  .chart-container { max-height: 160px; padding: 12px; }
  .history-days { gap: 8px; }
  .day-row {
    grid-template-columns: 60px 1fr;
    gap: 8px;
    padding: 10px 12px;
  }
  .day-cups { display: none; }

  /* Macros */
  .macro-sliders { gap: 12px; }
  .macro-slider-group {
    grid-template-columns: 1fr;
    gap: 6px;
  }
  .macro-slider-group label { font-size: 13px; }
  .macro-presets { gap: 8px; }
  .macro-preset { width: auto; padding: 8px 12px; font-size: 13px; }

  /* Volume card */
  .volume-card { padding: 12px; }
  .volume-value { font-size: 1.5rem; }

  /* General touch targets */
  button, a, input, select, .cup, .calendar-day, .day-row, .wk-tab {
    min-height: 44px;
    min-width: 44px;
  }

  /* No horizontal scroll on sections */
  .card, .grid, .container { overflow-x: hidden; }

  /* Minimum font-size */
  * { font-size: clamp(13px, 1rem, 18px); }
  .stat-value, .profile-result-value, .volume-value, .macro-grams {
    font-size: 24px;
  }
}

/* ================================
   Small Mobile (360px - Android)
   ================================ */
@media (max-width: 390px) {
  .container { padding: 12px; }
  .card { padding: 12px; border-radius: 8px; }
  .card h2 { font-size: 18px; }
  .stats-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .stat-value { font-size: 20px; }
  .profile-results { grid-template-columns: 1fr 1fr; gap: 8px; }
  .profile-result-value { font-size: 20px; }
  .exercise-row { padding: 10px; gap: 6px; }
  .wk-tab { font-size: 11px; padding: 5px 8px; }
  .calendar-day { height: 36px; min-height: 36px; font-size: 10px; }
  .cup { width: 36px; height: 48px; }
}

/* ================================
   iOS Specific Fixes
   ================================ */
@supports (-webkit-touch-callout: none) {
  input, select, textarea {
    -webkit-appearance: none;
    border-radius: 8px;
  }
  button, [role="button"], .btn-primary, .btn-secondary, .macro-preset, .wk-tab, .cup, .calendar-day, .day-row {
    -webkit-tap-highlight-color: transparent;
  }
}

/* ── Schedule System ── */
#schedule-ui { margin-bottom: 1rem; }
.sch-setup {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-input);
  padding: 1rem;
}
.sch-setup-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--section-accent, var(--accent));
  margin-bottom: 0.75rem;
}
.sch-setup-question {
  font-size: 0.875rem;
  color: var(--text-secondary);
  margin-bottom: 0.75rem;
}
.sch-setup-warning {
  font-size: 0.8125rem;
  color: var(--text-dim);
  margin-bottom: 0.75rem;
}
.sch-days-count {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}
.sch-count-btn {
  background: var(--surface);
  border: 1.5px solid var(--border);
  color: var(--text-secondary);
  padding: 0.5rem 1rem;
  border-radius: var(--radius-input);
  cursor: pointer;
  font-size: 0.9375rem;
  font-weight: 600;
  min-height: 44px;
  min-width: 44px;
  transition: all 0.2s;
}
.sch-count-btn:hover, .sch-count-btn.active {
  border-color: var(--section-accent, var(--accent));
  color: var(--section-accent, var(--accent));
  background: rgba(99, 102, 241, 0.08);
}
.sch-checks-row {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}
.sch-check-label {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  cursor: pointer;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-input);
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text);
  min-height: 44px;
  transition: all 0.15s;
  user-select: none;
}
.sch-check-label:hover {
  border-color: var(--text-secondary);
}
.sch-check-label input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
  cursor: pointer;
}
.sch-save-btn { width: 100%; margin-top: 0.5rem; }
.sch-edit-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.5rem;
}
.sch-edit-actions .btn-secondary,
.sch-edit-actions .btn-primary { flex: 1; }
.sch-summary {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-input);
  padding: 0.75rem 1rem;
  gap: 0.75rem;
}
.sch-summary-text {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}
.sch-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.sch-days {
  font-size: 0.9375rem;
  font-weight: 700;
  color: var(--text);
}
.sch-edit-btn {
  font-size: 0.8125rem;
  padding: 0.4rem 0.875rem;
  white-space: nowrap;
}
.sch-rest-day {
  margin-top: 0.5rem;
  padding: 0.75rem;
  background: rgba(16, 185, 129, 0.08);
  border: 1px solid rgba(16, 185, 129, 0.25);
  border-radius: var(--radius-input);
  color: #10b981;
  font-size: 0.9375rem;
  font-weight: 600;
  text-align: center;
}
.sch-future-prompt {
  margin-top: 0.75rem;
  padding: 0.75rem 1rem;
  background: var(--bg);
  border: 1.5px solid var(--section-accent, var(--accent));
  border-radius: var(--radius-input);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  animation: sch-fade-in 0.25s ease;
}
@keyframes sch-fade-in {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}
.sch-prompt-text {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text);
}
.sch-prompt-actions {
  display: flex;
  gap: 0.5rem;
  flex-shrink: 0;
}
.sch-prompt-actions button {
  font-size: 0.8125rem;
  padding: 0.4rem 1rem;
}
@media (max-width: 768px) {
  .sch-future-prompt {
    flex-direction: column;
    align-items: flex-start;
  }
  .sch-prompt-actions {
    width: 100%;
  }
  .sch-prompt-actions button {
    flex: 1;
  }
}

/* ================================
   MOBILE OVERRIDE — iPhone Fix
   ================================ */
@media (max-width: 768px) {
  /* Force single column - override everything */
  .main-grid,
  [class*="grid"],
  [class*="container"],
  [class*="layout"],
  [class*="wrapper"] {
    display: flex !important;
    flex-direction: column !important;
    width: 100% !important;
    gap: 16px !important;
  }

  /* All cards full width */
  [class*="card"],
  [class*="section"],
  [class*="panel"] {
    width: 100% !important;
    min-width: unset !important;
    max-width: 100% !important;
    margin: 0 !important;
    padding: 16px !important;
    box-sizing: border-box !important;
  }

  /* No horizontal overflow */
  body, html {
    overflow-x: hidden !important;
    width: 100% !important;
  }

  /* Inputs prevent iOS zoom */
  input, select, textarea {
    font-size: 16px !important;
    height: 48px !important;
    width: 100% !important;
    box-sizing: border-box !important;
    -webkit-appearance: none !important;
  }

  /* Buttons full width */
  button {
    width: 100% !important;
    min-height: 48px !important;
    font-size: 16px !important;
    -webkit-tap-highlight-color: transparent !important;
    touch-action: manipulation !important;
  }

  /* Workout exercise rows: stack as cards */
  [class*="exercise-row"],
  [class*="exercise_row"],
  [class*="workout-row"] {
    display: flex !important;
    flex-direction: column !important;
    gap: 8px !important;
    padding: 12px !important;
    background: rgba(255,255,255,0.05) !important;
    border-radius: 8px !important;
    margin-bottom: 8px !important;
  }

  /* Workout inputs row: sets/reps/weight in one row */
  [class*="exercise-row"] input,
  [class*="exercise-row"] select {
    width: auto !important;
    flex: 1 !important;
  }

  /* Typography */
  h1, h2, [class*="title"] { font-size: 20px !important; }
  [class*="stat-number"], [class*="result-number"] { font-size: 24px !important; }
  [class*="stat-label"], [class*="result-label"] { font-size: 11px !important; }

  /* Charts */
  canvas {
    max-width: 100% !important;
    height: auto !important;
  }

  /* Week tabs wrap */
  [class*="week-tabs"],
  [class*="tabs"] {
    flex-wrap: wrap !important;
    gap: 6px !important;
  }

  [class*="week-tab"],
  [class*="tab"] {
    flex: 1 1 calc(33% - 6px) !important;
    min-width: 60px !important;
    font-size: 13px !important;
    padding: 8px 4px !important;
  }

  /* Progressive overload table scroll */
  [class*="overload"],
  [class*="progress-table"],
  table {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch !important;
    display: block !important;
  }

  /* Water cups */
  [class*="cups"],
  [class*="water-grid"] {
    display: grid !important;
    grid-template-columns: repeat(5, 1fr) !important;
    gap: 6px !important;
  }
}

@media (max-width: 768px) {
  /* Fix any remaining side-by-side elements */
  * {
    max-width: 100vw !important;
  }
}
