:root {
  --bg: #f5f7f8;
  --surface: #ffffff;
  --surface-strong: #eef3f5;
  --ink: #1a2028;
  --muted: #68727d;
  --line: #d9e1e5;
  --accent: #136f63;
  --accent-strong: #0a534b;
  --accent-soft: #dff2ec;
  --blue: #1d5c96;
  --blue-soft: #dcebf7;
  --red: #b3261e;
  --red-soft: #fde7e4;
  --yellow-soft: #fff4c7;
  --shadow: 0 12px 36px rgba(21, 32, 43, 0.08);
  --radius: 8px;
  --hour-height: 76px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.topbar {
  min-height: 82px;
  padding: 18px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.eyebrow {
  margin: 0 0 3px;
  color: var(--accent-strong);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.brand {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
}

.last-updated {
  margin: 0;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(1.45rem, 2vw, 2rem);
}

h2 {
  font-size: 1.12rem;
}

.topbar-actions,
.import-actions,
.module-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.primary-button,
.secondary-button,
.icon-button {
  min-height: 38px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  padding: 0 14px;
  font-weight: 700;
}

.primary-button {
  background: var(--accent);
  color: white;
}

.primary-button:hover {
  background: var(--accent-strong);
}

.secondary-button,
.icon-button {
  background: var(--surface-strong);
  color: var(--ink);
  border-color: var(--line);
}

.secondary-button:hover,
.icon-button:hover {
  background: white;
}

.icon-button {
  min-width: 44px;
  padding: 0 10px;
}

label {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

input,
textarea {
  width: 100%;
  margin-top: 6px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: white;
  color: var(--ink);
  outline: none;
}

input {
  height: 40px;
  padding: 0 11px;
}

textarea {
  resize: vertical;
  min-height: 92px;
  padding: 10px 11px;
}

input:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(19, 111, 99, 0.15);
}

.import-actions {
  margin-top: 12px;
}

.workspace {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 338px;
  min-height: 0;
  overflow: hidden;
}

.schedule-area {
  min-width: 0;
  min-height: 0;
  padding: 18px 20px 24px 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow-y: auto;
}

.programme-bar {
  display: flex;
  align-items: flex-end;
  gap: 10px;
}

.programme-search {
  position: relative;
  flex: 1;
  min-width: 0;
}

.programme-search span {
  display: block;
}

.suggestion-list {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  width: 100%;
  z-index: 15;
  margin: 0;
  padding: 6px;
  list-style: none;
  max-height: 280px;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.suggestion-list[hidden] {
  display: none;
}

.suggestion-item {
  padding: 8px 10px;
  border-radius: calc(var(--radius) - 2px);
  color: var(--ink);
  font-size: 0.85rem;
  font-weight: 700;
  white-space: normal;
  line-height: 1.3;
  cursor: pointer;
}

.suggestion-item:hover,
.suggestion-item.is-active {
  background: var(--accent-soft);
}

.summary-band {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

.summary-band > div {
  flex: 0 0 auto;
}

.summary-band > div {
  min-height: 52px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.metric-value {
  display: block;
  font-size: 1.35rem;
  font-weight: 850;
  line-height: 1;
}

.metric-label {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 800;
  text-transform: uppercase;
}

.clash-metric.has-clashes {
  border-color: #f1b0aa;
  background: var(--red-soft);
}

.clash-list {
  border: 1px solid #efb0aa;
  border-radius: var(--radius);
  background: var(--red-soft);
  color: #5d1814;
  padding: 10px 12px;
}

.clash-list strong {
  display: block;
  margin-bottom: 4px;
}

.semester-groups {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.semester-block {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.semester-heading-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

.semester-heading {
  margin: 0;
  color: var(--accent-strong);
  font-size: 0.82rem;
  font-weight: 850;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.week-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.week-pill {
  min-width: 26px;
  height: 24px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 800;
}

.week-pill:hover {
  border-color: #aac4cc;
  color: var(--ink);
}

.week-pill.is-active {
  border-color: var(--accent);
  background: var(--accent);
  color: white;
}

.timetable-frame {
  min-height: calc(var(--hour-height) * 9 + 41px);
  overflow: auto;
  display: grid;
  grid-template-columns: 72px minmax(720px, 1fr);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.time-column {
  position: sticky;
  left: 0;
  z-index: 4;
  padding-top: 42px;
  border-right: 1px solid var(--line);
  background: #fbfcfc;
}

.time-label {
  height: var(--hour-height);
  padding: 5px 9px 0 0;
  text-align: right;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 800;
  border-top: 1px solid var(--line);
}

.days-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(144px, 1fr));
  min-width: 720px;
}

.day-column {
  position: relative;
  min-height: calc(var(--hour-height) * 9 + 42px);
  border-right: 1px solid var(--line);
  background:
    repeating-linear-gradient(
      to bottom,
      transparent 0,
      transparent calc(var(--hour-height) - 1px),
      var(--line) calc(var(--hour-height) - 1px),
      var(--line) var(--hour-height)
    );
  background-position: 0 42px;
}

.day-column:last-child {
  border-right: 0;
}

.day-heading {
  position: sticky;
  top: 0;
  z-index: 3;
  height: 42px;
  display: flex;
  align-items: center;
  padding: 0 10px;
  border-bottom: 1px solid var(--line);
  background: #fbfcfc;
  font-weight: 850;
}

.event {
  position: absolute;
  left: 8px;
  right: 8px;
  min-height: 42px;
  overflow: hidden;
  padding: 8px;
  border-radius: var(--radius);
  border: 1px solid rgba(29, 92, 150, 0.25);
  background: var(--blue-soft);
  color: #153650;
  box-shadow: 0 8px 16px rgba(21, 32, 43, 0.08);
}

.event.is-clash {
  border-color: #dd7d74;
  background: linear-gradient(135deg, var(--red-soft), var(--yellow-soft));
}

.event-time {
  display: block;
  font-size: 0.7rem;
  font-weight: 850;
}

.event-title {
  display: block;
  margin-top: 3px;
  font-size: 0.82rem;
  font-weight: 850;
  line-height: 1.15;
}

.event-detail {
  display: block;
  margin-top: 4px;
  color: rgba(21, 54, 80, 0.78);
  font-size: 0.7rem;
  font-weight: 700;
  line-height: 1.2;
}

.event-tooltip {
  position: fixed;
  z-index: 30;
  width: max-content;
  max-width: 280px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 24px 48px rgba(12, 18, 24, 0.22);
  padding: 12px 14px;
  pointer-events: none;
}

.event-tooltip[hidden] {
  display: none;
}

.event-tooltip h4 {
  margin: 0;
  font-size: 0.92rem;
  font-weight: 850;
  color: var(--ink);
}

.event-tooltip-name {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  line-height: 1.3;
}

.event-tooltip dl {
  margin: 8px 0 0;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 3px 10px;
}

.event-tooltip dt {
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 850;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.event-tooltip dd {
  margin: 0;
  color: var(--ink);
  font-size: 0.8rem;
  font-weight: 700;
  line-height: 1.3;
}

.empty-day {
  position: absolute;
  inset: 62px 12px auto;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.module-panel {
  min-height: 0;
  padding: 18px 18px 22px;
  border-left: 1px solid var(--line);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.module-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.search-box {
  position: relative;
  display: block;
}

.search-box span {
  display: block;
}

.module-list {
  flex: 1;
  min-height: 0;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-right: 2px;
}

.module-item {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr);
  gap: 9px;
  align-items: start;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fbfcfc;
}

.module-item:hover {
  border-color: #aac4cc;
}

.module-item input {
  width: 18px;
  height: 18px;
  margin: 2px 0 0;
  accent-color: var(--accent);
}

.module-code {
  display: block;
  color: var(--ink);
  font-size: 0.88rem;
  font-weight: 850;
}

.module-name {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
  line-height: 1.25;
}

.module-meta {
  display: flex;
  gap: 7px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  border-radius: 999px;
  padding: 0 8px;
  color: #164238;
  background: var(--accent-soft);
  font-size: 0.69rem;
  font-weight: 850;
}

.pill.warning {
  color: #691e18;
  background: var(--red-soft);
}

.pill.additional {
  color: #163d5c;
  background: var(--blue-soft);
}

.hidden {
  display: none;
}

/* No server.js on GitHub Pages, so anything hitting /api/... has nothing to talk to. Programme
   search and "Select" both still work there — they run off the baked-in static data instead
   (see selectProgramme's moduleIds branch in app.js) — so only Fetch Data/Upload are hidden. */
.is-static-deploy #fetchDataButton,
.is-static-deploy #uploadButton {
  display: none;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(12, 18, 24, 0.42);
}

.modal-backdrop[hidden] {
  display: none;
}

.login-modal {
  width: min(460px, 100%);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 24px 72px rgba(12, 18, 24, 0.24);
  padding: 18px;
}

.modal-header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.login-modal form {
  display: grid;
  gap: 12px;
}

.checkbox-field {
  display: flex !important;
  flex-direction: row;
  align-items: center;
  gap: 8px;
}

.checkbox-field input {
  width: auto;
}

.password-field {
  display: flex;
  gap: 8px;
  margin-top: 6px;
}

.password-field input {
  margin-top: 0;
  flex: 1;
  min-width: 0;
}

.password-field .icon-button {
  min-height: 40px;
  min-width: 56px;
}

.progress-modal {
  width: min(420px, 100%);
}

.progress-bar {
  position: relative;
  height: 6px;
  border-radius: 999px;
  background: var(--surface-strong);
  overflow: hidden;
  margin-bottom: 14px;
}

.progress-bar-fill {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 0;
  border-radius: inherit;
  background: var(--accent);
  transition: width 0.3s ease;
}

.progress-bar.is-busy .progress-bar-fill {
  width: 35%;
  animation: progress-sweep 1.1s ease-in-out infinite;
}

.progress-bar.is-done .progress-bar-fill {
  width: 100%;
  background: var(--accent);
}

.progress-bar.is-error .progress-bar-fill {
  width: 100%;
  background: var(--red);
}

@keyframes progress-sweep {
  0% {
    left: -35%;
  }
  100% {
    left: 100%;
  }
}

.progress-log {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 260px;
  overflow-y: auto;
}

.progress-line {
  padding: 8px 10px;
  border-radius: var(--radius);
  background: var(--surface-strong);
  color: var(--ink);
  font-size: 0.82rem;
  font-weight: 700;
  line-height: 1.35;
}

.progress-line.progress-success {
  background: var(--accent-soft);
  color: #164238;
}

.progress-line.progress-error {
  background: var(--red-soft);
  color: #5d1814;
}

.credential-note {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  line-height: 1.35;
}


@media (max-width: 980px) {
  .workspace {
    grid-template-columns: 1fr;
    overflow-y: auto;
  }

  .schedule-area {
    overflow: visible;
  }

  .module-panel {
    order: -1;
    border-left: 0;
    border-bottom: 1px solid var(--line);
    max-height: 42vh;
  }
}

@media (max-width: 720px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
    padding: 16px;
  }

  .schedule-area,
  .module-panel {
    padding-left: 14px;
    padding-right: 14px;
  }

  .timetable-frame {
    grid-template-columns: 58px minmax(660px, 1fr);
  }

  .time-label {
    font-size: 0.68rem;
  }
}
