/* ===== Reset & Variables ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --neu-red: #c8102e;
  --neu-dark: #1a1a2e;
  --text: #1f2937;
  --text-muted: #6b7280;
  --border: #e5e7eb;
  --bg: #f9fafb;
  --card-bg: #ffffff;
  --accent: #c8102e;
  --open: #16a34a;
  --closed: #dc2626;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md: 0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.06);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* ===== Header ===== */
header {
  background: var(--neu-red);
  color: white;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0,0,0,.2);
}
.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 24px;
  height: 60px;
  display: flex;
  align-items: center;
  gap: 24px;
}
.logo {
  text-decoration: none;
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-shrink: 0;
}
.logo-neu {
  font-size: 1.5rem;
  font-weight: 800;
  color: white;
  letter-spacing: -.5px;
}
.logo-text {
  font-size: 1rem;
  font-weight: 400;
  color: rgba(255,255,255,.88);
}
.header-nav { margin-left: auto; }

.term-selector {
  background: rgba(255,255,255,.15);
  border: 1px solid rgba(255,255,255,.3);
  color: white;
  padding: 6px 10px;
  border-radius: 6px;
  font-size: .9rem;
  cursor: pointer;
  outline: none;
}
.term-selector option { background: #333; }

/* ===== Views ===== */
.view { display: none; }
.view.active { display: block; }

/* ===== Hero ===== */
.hero {
  max-width: 800px;
  margin: 80px auto 60px;
  padding: 0 24px;
  text-align: center;
}
.hero h1 {
  font-size: 2.4rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 12px;
}
.hero-sub {
  font-size: 1.1rem;
  color: var(--text-muted);
  margin-bottom: 32px;
}
.hero-search {
  display: flex;
  gap: 0;
  max-width: 600px;
  margin: 0 auto 48px;
  box-shadow: var(--shadow-md);
  border-radius: var(--radius);
  overflow: hidden;
}
.hero-search input {
  flex: 1;
  padding: 14px 18px;
  border: 1px solid var(--border);
  border-right: none;
  font-size: 1rem;
  outline: none;
  border-radius: var(--radius) 0 0 var(--radius);
}
.hero-search input:focus { border-color: var(--neu-red); }
.hero-search button {
  background: var(--neu-red);
  color: white;
  border: none;
  padding: 14px 24px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  border-radius: 0 var(--radius) var(--radius) 0;
  transition: background .15s;
}
.hero-search button:hover { background: #a50d25; }
.search-mode-toggle {
  display: flex;
  margin: 0 auto 12px;
  max-width: 240px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--card-bg);
  box-shadow: var(--shadow);
}
.mode-btn {
  flex: 1;
  padding: 8px 16px;
  border: none;
  background: transparent;
  font-size: .9rem;
  cursor: pointer;
  color: var(--text-muted);
  transition: all .15s;
}
.mode-btn.active {
  background: var(--neu-red);
  color: white;
  font-weight: 600;
}
.mode-btn:not(.active):hover { background: #f3f4f6; color: var(--text); }

.instructor-link {
  color: var(--neu-red);
  text-decoration: none;
  font-weight: 500;
}
.instructor-link:hover { text-decoration: underline; }

.instructor-course-group {
  margin-bottom: 32px;
}
.instructor-course-header {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  border-bottom: 2px solid var(--neu-red);
  padding-bottom: 6px;
  margin-bottom: 12px;
}
.instructor-course-title {
  font-weight: 400;
  color: var(--text-muted);
}

/* Subject grid */
.alpha-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 16px;
}
.alpha-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 4px;
  font-size: .82rem;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  background: var(--card-bg);
  border: 1px solid var(--border);
  color: var(--neu-red);
  transition: background .15s, border-color .15s;
}
.alpha-btn:hover {
  background: var(--neu-red);
  border-color: var(--neu-red);
  color: #fff;
}
.alpha-btn--off {
  color: var(--text-muted);
  cursor: default;
  pointer-events: none;
  opacity: .4;
}
.subj-letter-header {
  grid-column: 1 / -1;
  font-size: .8rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .05em;
  padding: 6px 0 2px;
  border-bottom: 1px solid var(--border);
  scroll-margin-top: 16px;
}
.subject-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 10px;
  text-align: left;
}
.subject-chip {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  cursor: pointer;
  transition: border-color .15s, box-shadow .15s;
  text-align: left;
  text-decoration: none;
  color: inherit;
  display: block;
}
.subject-chip:hover {
  border-color: var(--neu-red);
  box-shadow: 0 0 0 2px rgba(200,16,46,.12);
}
.subject-chip .subj-code {
  font-weight: 700;
  font-size: .95rem;
  color: var(--neu-red);
}
.subject-chip .subj-name {
  font-size: .78rem;
  color: var(--text-muted);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ===== List layout ===== */
.list-layout {
  max-width: 1200px;
  margin: 32px auto;
  padding: 0 24px;
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 24px;
  align-items: start;
}
@media (max-width: 768px) {
  .list-layout { grid-template-columns: 1fr; }
  .sidebar { position: static; padding: 16px; }
}

.sidebar {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  position: sticky;
  top: 80px;
}
.sidebar h3 {
  font-size: 1rem;
  margin-bottom: 14px;
  color: var(--text);
}
.sidebar label {
  display: block;
  font-size: .82rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.sidebar select, .sidebar input {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: .9rem;
  outline: none;
}
.sidebar select:focus, .sidebar input:focus { border-color: var(--neu-red); }

/* Buttons */
.btn-primary {
  background: var(--neu-red);
  color: white;
  border: none;
  padding: 9px 16px;
  border-radius: 6px;
  font-size: .9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
}
.btn-primary:hover { background: #a50d25; }
.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
  padding: 9px 16px;
  border-radius: 6px;
  font-size: .9rem;
  cursor: pointer;
  transition: border-color .15s;
}
.btn-ghost:hover { border-color: #999; }

/* Course list header */
.list-header {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 16px;
}
.list-header h2 { font-size: 1.4rem; }
.count-badge {
  background: #f3f4f6;
  color: var(--text-muted);
  font-size: .8rem;
  padding: 3px 10px;
  border-radius: 12px;
}

/* Course cards */
.course-cards { display: flex; flex-direction: column; gap: 10px; }

.course-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  cursor: pointer;
  transition: border-color .15s, box-shadow .15s;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: start;
  text-decoration: none;
  color: inherit;
}
.course-card:hover {
  border-color: var(--neu-red);
  box-shadow: var(--shadow-md);
}
.course-card-left {}
.course-code {
  font-size: .82rem;
  font-weight: 700;
  color: var(--neu-red);
  text-transform: uppercase;
  letter-spacing: .04em;
}
.course-title {
  font-size: 1rem;
  font-weight: 600;
  margin: 3px 0 6px;
}
.course-meta {
  font-size: .82rem;
  color: var(--text-muted);
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
}
.course-desc-snippet {
  font-size: .85rem;
  color: var(--text-muted);
  margin-top: 6px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.course-card-right {
  text-align: right;
  flex-shrink: 0;
}
.section-count {
  font-size: .82rem;
  background: #f3f4f6;
  color: var(--text-muted);
  padding: 3px 10px;
  border-radius: 12px;
  white-space: nowrap;
}

/* ===== Pagination ===== */
.pagination {
  display: flex;
  gap: 8px;
  justify-content: center;
  padding: 24px 0;
  flex-wrap: wrap;
}
.page-btn {
  min-width: 36px;
  height: 36px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--card-bg);
  font-size: .9rem;
  cursor: pointer;
  transition: all .15s;
}
.page-btn:hover { border-color: var(--neu-red); color: var(--neu-red); }
.page-btn.active {
  background: var(--neu-red);
  border-color: var(--neu-red);
  color: white;
}
.page-btn:disabled { opacity: .4; cursor: not-allowed; }

/* ===== Detail view ===== */
.detail-layout {
  max-width: 960px;
  margin: 32px auto;
  padding: 0 24px;
}
.back-btn {
  background: none;
  border: none;
  color: var(--neu-red);
  font-size: .95rem;
  cursor: pointer;
  padding: 0;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.back-btn:hover { text-decoration: underline; }

.detail-header {
  margin-bottom: 24px;
}
.detail-code {
  font-size: .85rem;
  font-weight: 700;
  color: var(--neu-red);
  text-transform: uppercase;
  letter-spacing: .05em;
}
.detail-title {
  font-size: 1.8rem;
  font-weight: 700;
  margin: 6px 0 10px;
}
.detail-meta {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  font-size: .9rem;
  color: var(--text-muted);
}
.detail-meta span { display: flex; align-items: center; gap: 4px; }

.detail-body {
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 24px;
  align-items: start;
}
.detail-side {
  align-self: stretch;
  position: relative;
}
@media (max-width: 768px) {
  .detail-body {
    display: flex;
    flex-direction: column;
    gap: 24px;
  }
  .detail-main    { display: contents; }
  .detail-desc    { order: 1; min-width: 0; }
  .detail-prereqs { order: 2; min-width: 0; }
  .detail-side    { order: 3; min-width: 0; }
  .sections-wrap  { order: 4; min-width: 0; }
  .detail-toc     { position: static; }
}

.detail-toc {
  position: sticky;
  top: 20px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.detail-toc-label {
  font-size: .75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--text-muted);
  margin-bottom: 10px;
}
.detail-toc-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.detail-toc-list li {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}
.toc-link {
  font-size: .88rem;
  color: var(--neu-red);
  text-decoration: none;
  line-height: 1.4;
  flex: 1;
}
.toc-link:hover { text-decoration: underline; }
.toc-count {
  font-size: .78rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.detail-desc, .detail-prereqs {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 20px;
}
.detail-desc h3, .detail-prereqs h3 {
  font-size: .82rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-muted);
  margin-bottom: 10px;
}
.detail-desc p { line-height: 1.65; font-size: .95rem; }

/* Sections table */
.sections-wrap {
  margin-top: 8px;
}
.sections-wrap h3 {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 14px;
}
.section-group-title {
  font-size: 1rem;
  font-weight: 600;
  margin: 18px 0 10px;
  color: var(--text);
  border-bottom: 1px solid var(--border);
  padding-bottom: 6px;
}
.section-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 10px;
}
.section-card-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}
.section-title {
  font-size: .95rem;
  font-weight: 600;
  margin-bottom: 10px;
  color: var(--text);
}
.section-crn {
  font-size: .82rem;
  color: var(--text-muted);
}
.section-seq {
  font-weight: 700;
  font-size: 1rem;
}
.open-badge, .closed-badge {
  font-size: .75rem;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 12px;
}
.open-badge { background: #dcfce7; color: var(--open); }
.closed-badge { background: #fee2e2; color: var(--closed); }
.campus-badge {
  font-size: .75rem;
  background: #f3f4f6;
  color: var(--text-muted);
  padding: 3px 9px;
  border-radius: 12px;
}

.section-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 8px;
  font-size: .85rem;
}
.meeting-row {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.meeting-row .section-field {
  flex: 1 1 160px;
}
.section-field label {
  display: block;
  font-size: .75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-muted);
  margin-bottom: 2px;
}
.enroll-bar {
  height: 6px;
  background: #e5e7eb;
  border-radius: 3px;
  margin-top: 4px;
  overflow: hidden;
}
.enroll-fill {
  height: 100%;
  border-radius: 3px;
  background: var(--neu-red);
  transition: width .3s;
}

.faculty-list { font-size: .85rem; }
.faculty-list a { color: var(--neu-red); }

/* Day pills */
.days {
  display: flex;
  gap: 3px;
  flex-wrap: wrap;
  margin-top: 2px;
}
.day {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .7rem;
  font-weight: 700;
}
.day.on { background: var(--neu-red); color: white; }
.day.off { background: #f3f4f6; color: #bbb; }

/* Attribute tags */
.attr-tags { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 8px; }
.attr-tag {
  font-size: .75rem;
  background: #eff6ff;
  color: #1d4ed8;
  border: 1px solid #bfdbfe;
  padding: 2px 8px;
  border-radius: 12px;
}

/* ===== Loading ===== */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(255,255,255,.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999;
}
.loading-overlay.hidden { display: none; }
.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--neu-red);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== Empty state ===== */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}
.empty-state h3 { font-size: 1.1rem; margin-bottom: 8px; color: var(--text); }

/* ===== 404 page ===== */
.not-found {
  max-width: 560px;
  margin: 0 auto;
  padding: 96px 24px 64px;
  text-align: center;
}
.not-found-code {
  font-size: 6rem;
  font-weight: 800;
  color: var(--neu-red);
  line-height: 1;
  letter-spacing: -2px;
}
.not-found-title {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--text);
  margin: 16px 0 8px;
}
.not-found-desc {
  color: var(--text-muted);
  margin-bottom: 24px;
}
.not-found-cta {
  display: inline-block;
  text-decoration: none;
}
@media (max-width: 480px) {
  .not-found { padding: 64px 24px 48px; }
  .not-found-code { font-size: 4.5rem; }
  .not-found-title { font-size: 1.3rem; }
}

/* ===== Prerequisites table ===== */
.prereq-table-wrap {
  margin-top: 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow-x: auto;
  background: var(--card-bg);
}
.prereq-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .9rem;
}
.prereq-table th, .prereq-table td {
  padding: 8px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  font-size: .9rem;
  font-weight: 400;
  line-height: 1.4;
  color: var(--text);
}
.prereq-table th {
  background: rgba(0,0,0,.025);
  font-weight: 600;
  font-size: .75rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-muted);
}
.prereq-table tbody tr:last-child td { border-bottom: none; }
.prereq-table .prereq-conn {
  color: var(--text-muted);
  font-weight: 600;
}
.prereq-table .prereq-num,
.prereq-table .prereq-grade { text-align: center; }

/* ===== About section (home) ===== */
.about-section {
  max-width: 760px;
  margin: 56px auto 24px;
  padding: 0 24px;
  color: var(--text);
  line-height: 1.65;
}
.about-section h2 {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 12px;
  color: var(--text);
}
.about-section h3 {
  font-size: 1.05rem;
  font-weight: 600;
  margin: 24px 0 8px;
  color: var(--text);
}
.about-section p {
  margin-bottom: 12px;
  color: var(--text-muted);
}
.about-section ul {
  margin: 0 0 12px 20px;
  color: var(--text-muted);
}
.about-section li {
  margin-bottom: 6px;
}
.about-section em {
  font-style: normal;
  background: rgba(200, 16, 46, .08);
  color: var(--neu-red);
  padding: 1px 6px;
  border-radius: 4px;
  font-size: .92em;
}
.about-disclaimer {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  font-size: .85rem;
  font-style: italic;
}

/* ===== Footer ===== */
.site-footer {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 24px 16px;
  margin-top: 48px;
  border-top: 1px solid var(--border);
  color: var(--text-muted);
  font-size: .88rem;
}
.footer-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-muted);
  text-decoration: none;
}
.footer-link:hover { color: var(--text); }
.footer-sep {
  color: var(--border);
  margin: 0 8px;
}
.github-icon {
  width: 18px;
  height: 18px;
  fill: currentColor;
  flex-shrink: 0;
}
