:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --border: #e3e6ea;
  --text: #1d2530;
  --muted: #5b6675;
  --accent: #2d5aa0;
  --accent-dark: #1e3e72;
  --green: #2f8f4e;
  --green-bg: #e7f5ec;
  --amber: #c47f14;
  --amber-bg: #fdf3e0;
  --red: #c23b3b;
  --red-bg: #fbe8e8;
  --purple: #6a3fa0;
  --purple-bg: #efe8fa;
  --grey-bg: #eceff2;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(0,0,0,0.05), 0 2px 4px rgba(0,0,0,0.04);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.45;
}

.page-header {
  background: linear-gradient(135deg, var(--accent-dark), var(--accent));
  color: #fff;
  padding: 24px 20px;
  text-align: center;
}
.page-header h1 { margin: 0; font-size: 1.55rem; font-weight: 600; }
.page-header .subtitle { margin: 6px 0 0; opacity: 0.85; font-size: 0.95rem; }

main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 20px 16px 60px;
}

/* Dashboard */
.dashboard {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
}
.stat-label { font-size: 0.82rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.stat-value { font-size: 1.6rem; font-weight: 600; margin: 4px 0 6px; }
.stat-sub { font-size: 0.85rem; color: var(--muted); }
.progress-bar {
  height: 8px;
  background: var(--grey-bg);
  border-radius: 4px;
  overflow: hidden;
  margin-top: 6px;
}
.progress-fill {
  height: 100%;
  background: var(--accent);
  width: 0%;
  transition: width 0.3s ease, background 0.3s ease;
}
.stat-card.complete .progress-fill { background: var(--green); }

/* Alerts */
.alerts { display: flex; flex-direction: column; gap: 8px; margin-bottom: 18px; }
.alert {
  padding: 12px 14px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  font-size: 0.93rem;
}
.alert a { color: inherit; }
.alert-success { background: var(--green-bg); border-color: #bfe2c9; color: #184a2a; }
.alert-warning { background: var(--amber-bg); border-color: #f0d49a; color: #724611; }
.alert-danger  { background: var(--red-bg);   border-color: #ecbdbd; color: #7a2222; }

/* Tabs */
.tabs {
  display: flex;
  border-bottom: 2px solid var(--border);
  margin-bottom: 16px;
  gap: 4px;
  overflow-x: auto;
}
.tab {
  background: none;
  border: none;
  padding: 10px 16px;
  font-size: 0.95rem;
  font-family: inherit;
  cursor: pointer;
  color: var(--muted);
  border-bottom: 3px solid transparent;
  margin-bottom: -2px;
  white-space: nowrap;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* Course groups */
.course-group { margin-bottom: 20px; }
.course-group-header {
  padding: 10px 14px;
  border-radius: var(--radius) var(--radius) 0 0;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  font-size: 0.95rem;
}
.course-group-header.challenge-phase { background: var(--green); }
.course-group-header .subtext { display: block; font-weight: 400; font-size: 0.82rem; opacity: 0.9; margin-top: 4px; }
.group-header-top { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.sr-progress-pill {
  background: rgba(255,255,255,0.2);
  border: 1px solid rgba(255,255,255,0.35);
  color: #fff;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 0.82rem;
  font-weight: 600;
  white-space: nowrap;
}
.sr-progress-pill.done { background: #fff; color: var(--green); border-color: #fff; }
.sr-progress-bar {
  width: 100%;
  height: 4px;
  background: rgba(255,255,255,0.2);
  border-radius: 2px;
  margin-top: 6px;
  overflow: hidden;
  flex-basis: 100%;
}
.sr-progress-fill { height: 100%; background: #fff; width: 0%; transition: width 0.3s ease; }

.course-list {
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 var(--radius) var(--radius);
}
.course {
  display: grid;
  grid-template-columns: 110px 1fr 160px 150px;
  gap: 14px;
  padding: 12px 14px;
  border-top: 1px solid var(--border);
  align-items: start;
}
.course:first-child { border-top: none; }
.course.challenge-row { background: #f2faf5; }
.course.under-revision { background: var(--amber-bg); }
.course.sr-path-row {
  background: #fffaea;
  border-left: 3px solid #e9c76a;
}
.course.sr-path-row.challenge-row { background: #f9f7ea; }

.course-code {
  font-weight: 600;
  font-family: "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.course-link {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.85rem;
  font-family: -apple-system, sans-serif;
}
.course-link:hover { color: var(--accent); }

.course-title-line { margin-bottom: 4px; }
.course-title-line strong { font-weight: 600; }
.course-cr {
  display: inline-block;
  margin-left: 4px;
  padding: 1px 6px;
  border-radius: 10px;
  background: var(--grey-bg);
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 500;
  vertical-align: 1px;
}
.course-overview {
  font-size: 0.85rem;
  color: var(--text);
  opacity: 0.8;
  margin-bottom: 4px;
  line-height: 1.4;
}
.course-prereq {
  font-size: 0.82rem;
  color: var(--muted);
  margin-bottom: 3px;
}
.prereq-label {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 3px;
  background: #e9f0fa;
  color: var(--accent-dark);
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-right: 4px;
}
.prereq-label.prereq-none { background: var(--grey-bg); color: var(--muted); }
.course-note-inline {
  font-size: 0.82rem;
  color: var(--amber);
  margin-top: 3px;
  font-style: italic;
}
.course-extras {
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: 3px;
}
.course-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  justify-content: flex-start;
  align-content: flex-start;
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 0.72rem;
  font-weight: 600;
  white-space: nowrap;
}
.badge-srpath {
  background: #fff5d9;
  color: #8a6200;
  border: 1px solid #e9c76a;
  font-weight: 700;
}
.badge-challenge { background: var(--green-bg); color: var(--green); border: 1px solid #bfe2c9; }
.badge-6cr      { background: var(--purple-bg); color: var(--purple); }
.badge-sr       { background: var(--red-bg); color: var(--red); }
.badge-revision { background: var(--amber-bg); color: var(--amber); border: 1px solid #f0d49a; }
.badge-approval { background: var(--grey-bg); color: var(--muted); }
.badge-required { background: #ffe9cf; color: #8a4b00; }

.status-select {
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  font-family: inherit;
  font-size: 0.88rem;
  cursor: pointer;
  width: 100%;
}
.status-select:disabled { opacity: 0.55; cursor: not-allowed; }
.status-select[data-status="complete"]    { background: var(--green-bg); border-color: #bfe2c9; }
.status-select[data-status="in_progress"] { background: var(--amber-bg); border-color: #f0d49a; }

/* Savings tracker */
.savings-tracker {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
  font-size: 0.93rem;
}
.savings-tracker h3 { margin: 0 0 6px; font-size: 1rem; }
.savings-line { display: flex; justify-content: space-between; margin-top: 4px; }
.savings-line .saved { color: var(--green); font-weight: 600; }
.savings-line .remaining { color: var(--muted); }

/* Timeline */
.timeline { position: relative; padding-left: 28px; }
.timeline::before {
  content: "";
  position: absolute;
  left: 10px;
  top: 6px;
  bottom: 6px;
  width: 2px;
  background: var(--border);
}
.milestone { position: relative; padding: 6px 0 18px; }
.milestone::before {
  content: "";
  position: absolute;
  left: -22px;
  top: 10px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--surface);
  border: 2px solid var(--border);
}
.milestone.done::before { background: var(--green); border-color: var(--green); }
.milestone.amber::before { background: var(--amber); border-color: var(--amber); }
.milestone.danger { color: var(--red); font-weight: 600; }
.milestone.goal::before { border-color: var(--accent); }

/* Cert cards */
.cert-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 12px; }
.cert-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
}
.cert-card.ready { border-left-color: var(--green); }
.cert-card.pending { border-left-color: var(--amber); }
.cert-card h3 { margin: 0 0 6px; font-size: 1.05rem; }
.cert-status { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 0.78rem; font-weight: 600; margin-bottom: 8px; }
.cert-status.ready { background: var(--green-bg); color: var(--green); }
.cert-status.pending { background: var(--amber-bg); color: var(--amber); }
.cert-card p { margin: 6px 0; font-size: 0.9rem; }
.cert-card .progress-bar { margin-top: 8px; }

/* Plan toggle */
.plan-toggle { margin-top: 16px; padding: 14px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.plan-toggle .note { margin: 0 0 8px; }
.plan-toggle ol { margin: 8px 0 0 20px; padding: 0; }
.btn-link {
  background: none;
  border: none;
  color: var(--accent);
  text-decoration: underline;
  cursor: pointer;
  padding: 0;
  font-family: inherit;
  font-size: inherit;
}

/* Actions */
.actions { margin-top: 24px; text-align: right; }
.btn-danger {
  background: var(--surface);
  border: 1px solid var(--red);
  color: var(--red);
  padding: 8px 14px;
  border-radius: 6px;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.9rem;
}
.btn-danger:hover { background: var(--red-bg); }

/* Footer */
.page-footer {
  max-width: 1100px;
  margin: 0 auto;
  padding: 16px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  font-size: 0.82rem;
  color: var(--muted);
  flex-wrap: wrap;
  gap: 8px;
}
.save-status { display: flex; align-items: center; gap: 8px; }
.storage-badge {
  background: var(--grey-bg);
  color: var(--muted);
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 0.72rem;
}
.storage-badge.local { background: var(--amber-bg); color: var(--amber); }

/* Mobile */
@media (max-width: 820px) {
  .course {
    grid-template-columns: 1fr;
    grid-template-areas: "code" "title" "badges" "status";
    gap: 8px;
  }
  .course-code { grid-area: code; }
  .course-title { grid-area: title; }
  .course-badges { grid-area: badges; justify-content: flex-start; }
  .course .status-select { grid-area: status; max-width: 240px; }
  .page-header h1 { font-size: 1.25rem; }
  .stat-value { font-size: 1.35rem; }
}
