:root {
  --bg: #fafafa;
  --card: #ffffff;
  --text: #111827;
  --muted: #6b7280;
  --border: #e5e7eb;
  --accent: #16a34a;
  --accent-rgb: 22, 163, 74;
  --positive: #16a34a;
  --negative: #dc2626;
  --warn: #d97706;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 4px 12px rgba(0, 0, 0, 0.04);
  --radius: 14px;
  --radius-sm: 10px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

[hidden] { display: none !important; }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

main {
  padding: 0 16px calc(96px + env(safe-area-inset-bottom, 0px));
  max-width: 720px;
  margin: 0 auto;
}

button {
  font-family: inherit;
  font-size: inherit;
  cursor: pointer;
}

/* ---------- Gate ---------- */
.gate {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  padding: 24px;
  z-index: 10;
}
.gate-form {
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.gate-title {
  font-size: 32px;
  margin: 0 0 4px;
  text-align: center;
  letter-spacing: -0.02em;
  font-weight: 700;
}
.gate-sub {
  color: var(--muted);
  margin: 0 0 16px;
  text-align: center;
  font-size: 15px;
}
.gate-form input {
  height: 48px;
  padding: 0 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 16px;
  background: var(--card);
  color: var(--text);
  font-family: inherit;
}
.gate-form input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-color: transparent;
}
.gate-form button {
  height: 48px;
  border: none;
  background: var(--accent);
  color: white;
  font-weight: 600;
  font-size: 16px;
  border-radius: var(--radius-sm);
  transition: filter 0.15s;
}
.gate-form button:hover { filter: brightness(0.95); }
.gate-form button:active { filter: brightness(0.9); }
.gate-error {
  color: var(--negative);
  margin: 4px 0 0;
  font-size: 14px;
  text-align: center;
}

/* ---------- Hero ---------- */
.hero {
  padding: 56px 0 24px;
  text-align: center;
}
.hero-label {
  color: var(--muted);
  margin: 0 0 8px;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-weight: 500;
}
.hero-days {
  margin: 0;
  font-size: 80px;
  line-height: 1;
  font-weight: 800;
  letter-spacing: -0.04em;
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
}
.hero-days-unit {
  font-size: 20px;
  font-weight: 500;
  color: var(--muted);
  letter-spacing: 0;
}
.hero-sub {
  color: var(--muted);
  margin: 12px 0 0;
  font-size: 15px;
}

/* ---------- Sections ---------- */
.section { margin: 32px 0; }
.section-title {
  font-size: 20px;
  margin: 0 0 12px;
  letter-spacing: -0.01em;
  font-weight: 600;
}

/* ---------- Cards ---------- */
.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  margin-bottom: 12px;
}
.card-title {
  margin: 0 0 12px;
  font-size: 14px;
  color: var(--muted);
  font-weight: 500;
  letter-spacing: 0.02em;
}

/* ---------- Stats grid ---------- */
.stats {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}
.stat-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.stat-value {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.1;
}
.stat-label {
  color: var(--muted);
  font-size: 13px;
  margin-top: 4px;
}
.stat-delta {
  display: inline-block;
  font-size: 12px;
  margin-top: 8px;
  padding: 2px 8px;
  border-radius: 999px;
  font-weight: 500;
}
.stat-delta.positive { background: rgba(var(--accent-rgb), 0.12); color: var(--positive); }
.stat-delta.negative { background: rgba(220, 38, 38, 0.1); color: var(--negative); }
.stat-delta.neutral { background: rgba(107, 114, 128, 0.1); color: var(--muted); }

/* ---------- Charts ---------- */
.chart-wrap {
  position: relative;
  height: 240px;
}

/* ---------- Goals ---------- */
.goals-grid { display: grid; gap: 12px; }
.achieved-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.achieved-item {
  display: flex;
  gap: 10px;
  align-items: flex-start;
}
.checkmark {
  color: var(--accent);
  font-weight: 700;
  flex-shrink: 0;
  margin-top: 1px;
}
.achieved-title { font-size: 15px; }
.achieved-meta {
  color: var(--muted);
  font-size: 13px;
  margin-top: 2px;
}

.upcoming-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.upcoming-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
}
.upcoming-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 4px;
}
.upcoming-title { font-weight: 600; font-size: 15px; }

.tag {
  display: inline-block;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(107, 114, 128, 0.1);
  color: var(--muted);
  white-space: nowrap;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 600;
  flex-shrink: 0;
}
.tag.styrke { background: rgba(var(--accent-rgb), 0.12); color: var(--accent); }
.tag.fleksibilitet { background: rgba(59, 130, 246, 0.12); color: #2563eb; }
.tag.krop { background: rgba(249, 115, 22, 0.12); color: #ea580c; }
.tag.andet { background: rgba(107, 114, 128, 0.12); color: var(--muted); }

.tag.milepael { background: rgba(245, 158, 11, 0.14); color: #b45309; }
.tag.trening { background: rgba(var(--accent-rgb), 0.12); color: var(--accent); }
.tag.kost { background: rgba(168, 85, 247, 0.12); color: #9333ea; }
.tag.supplement { background: rgba(59, 130, 246, 0.12); color: #2563eb; }
.tag.maal { background: rgba(var(--accent-rgb), 0.12); color: var(--accent); }
.tag.maaling { background: rgba(107, 114, 128, 0.14); color: var(--muted); }

.progress {
  height: 6px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
  margin-top: 10px;
}
.progress-bar {
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
  transition: width 0.3s ease;
}
.upcoming-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 8px;
  font-size: 13px;
  color: var(--muted);
  gap: 8px;
}
.upcoming-note {
  margin-top: 6px;
  font-size: 13px;
  color: var(--muted);
}

/* ---------- Program ---------- */
.program-meta {
  font-size: 14px;
  color: var(--muted);
  margin-bottom: 12px;
  line-height: 1.5;
}
.program-meta strong { color: var(--text); }
.tabs {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.tab {
  padding: 8px 14px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  border-radius: 999px;
  font-size: 13px;
  font-weight: 500;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  transition: background 0.15s, color 0.15s;
}
.tab.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}
.session-warmup {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 12px;
  padding: 10px 12px;
  background: rgba(107, 114, 128, 0.06);
  border-radius: var(--radius-sm);
}
.exercise-list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.exercise-item {
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.exercise-item:last-child { border-bottom: 0; }
.exercise-name { font-weight: 500; }
.exercise-prescription {
  font-size: 13px;
  color: var(--muted);
  margin-top: 2px;
}
.exercise-notes {
  font-size: 12px;
  color: var(--muted);
  margin-top: 4px;
  font-style: italic;
}
.history-details {
  margin-top: 16px;
  font-size: 14px;
  border-top: 1px solid var(--border);
  padding-top: 8px;
}
.history-details summary {
  cursor: pointer;
  color: var(--muted);
  padding: 8px 0;
  min-height: 36px;
  font-size: 14px;
}
.history-details summary:hover { color: var(--text); }
.history-item {
  padding: 14px 0;
  border-top: 1px solid var(--border);
  font-size: 14px;
}
.history-item:first-child { border-top: 0; }
.history-header { margin-bottom: 2px; }
.history-desc { margin-top: 6px; }
.history-sessions { margin-top: 12px; }
.history-session + .history-session { margin-top: 16px; }
.history-session-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 6px;
}

/* ---------- Nutrition ---------- */
.protein-target {
  font-size: 32px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--accent);
}
.protein-unit {
  font-size: 15px;
  color: var(--muted);
  font-weight: 500;
  margin-left: 4px;
}
.protein-desc {
  font-size: 15px;
  line-height: 1.55;
}
.example-day { margin-top: 14px; }
.meal {
  display: grid;
  grid-template-columns: 1fr auto;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  gap: 12px;
  align-items: baseline;
}
.meal:last-of-type { border-bottom: 0; }
.meal-name { font-weight: 500; font-size: 14px; }
.meal-items { font-size: 13px; color: var(--muted); margin-top: 2px; }
.meal-protein {
  font-size: 13px;
  color: var(--accent);
  font-weight: 600;
  white-space: nowrap;
}
.protein-notes {
  margin-top: 14px;
  font-size: 13px;
  color: var(--muted);
  line-height: 1.5;
}

.supps {
  display: flex;
  flex-direction: column;
}
.supp {
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px 12px;
  align-items: start;
}
.supp:last-child { border-bottom: 0; }
.supp-name { font-weight: 500; }
.supp-meta { color: var(--muted); font-size: 13px; margin-top: 2px; }
.supp-status {
  font-size: 11px;
  padding: 3px 9px;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 600;
  align-self: start;
  white-space: nowrap;
}
.supp-status.active { background: rgba(var(--accent-rgb), 0.12); color: var(--accent); }
.supp-status.paused { background: rgba(245, 158, 11, 0.14); color: var(--warn); }
.supp-status.dropped { background: rgba(220, 38, 38, 0.1); color: var(--negative); }
.supp-notes {
  font-size: 13px;
  color: var(--muted);
  margin-top: 2px;
  grid-column: 1 / -1;
}

/* ---------- Timeline ---------- */
.filters {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.filter-btn {
  padding: 6px 12px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  border-radius: 999px;
  font-size: 12px;
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  font-weight: 500;
}
.filter-btn.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

.timeline {
  position: relative;
  padding-left: 32px;
}
.timeline::before {
  content: '';
  position: absolute;
  left: 11px;
  top: 6px;
  bottom: 6px;
  width: 2px;
  background: rgba(var(--accent-rgb), 0.25);
  border-radius: 1px;
}
.tl-event {
  position: relative;
  padding-bottom: 20px;
}
.tl-event:last-child { padding-bottom: 0; }
.tl-event::before {
  content: '';
  position: absolute;
  left: -27px;
  top: 6px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--card);
  border: 2px solid var(--accent);
  box-sizing: border-box;
}
.tl-event.now::before {
  width: 16px;
  height: 16px;
  left: -29px;
  top: 4px;
  background: var(--accent);
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(var(--accent-rgb), 0.18);
  animation: pulse 2.4s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 4px rgba(var(--accent-rgb), 0.18); }
  50% { box-shadow: 0 0 0 10px rgba(var(--accent-rgb), 0.05); }
}
.tl-meta {
  display: flex;
  gap: 8px;
  align-items: center;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
  flex-wrap: wrap;
}
.tl-day {
  font-weight: 600;
  color: var(--text);
}
.tl-card {
  background: var(--card);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  box-shadow: var(--shadow);
  cursor: default;
}
.tl-card.has-note { cursor: pointer; }
.tl-card.has-note:hover { background: #fcfcfc; }
.tl-card-title {
  font-weight: 500;
  font-size: 15px;
}
.tl-card-note {
  font-size: 13px;
  color: var(--muted);
  margin-top: 8px;
  display: none;
  line-height: 1.5;
}
.tl-card.expanded .tl-card-note { display: block; }
.tl-event.now .tl-card-title { color: var(--accent); font-weight: 600; }

/* ---------- Footer ---------- */
.footer {
  padding: 32px 0 16px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}

/* ---------- Bottom nav ---------- */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  z-index: 5;
}
.bottom-nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 8px 4px;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.02em;
  min-height: 56px;
  cursor: pointer;
  transition: color 0.15s ease;
  font-family: inherit;
}
.bottom-nav-item svg {
  width: 22px;
  height: 22px;
  display: block;
}
.bottom-nav-item.active { color: var(--accent); }
.bottom-nav-item:hover:not(.active) { color: var(--text); }
.bottom-nav-item:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -4px;
  border-radius: 8px;
}

/* ---------- Tab panel ---------- */
.tab-panel[hidden] { display: none; }

/* ---------- Tablet+ ---------- */
@media (min-width: 600px) {
  .stats { grid-template-columns: repeat(3, 1fr); }
  .goals-grid { grid-template-columns: 1fr 1fr; }
  .hero { padding: 72px 0 32px; }
  .hero-days { font-size: 96px; }
  .chart-wrap { height: 280px; }
}
@media (min-width: 800px) {
  main { padding: 0 24px 64px; }
}

@media (max-width: 380px) {
  .hero-days { font-size: 64px; }
  .stat-value { font-size: 24px; }
}
