:root {
  --accent: #f27d00;          /* UC orange */
  --accent-tint: #fff1e3;
  --accent-ink: #9a4a00;      /* orange dark enough for text on white */
  --ink: #17191c;
  --muted: #5a626d;
  --line: #e4e7eb;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --hover: #f1f3f5;
  --bad: #b42318;
  --bad-tint: #fdecea;

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, system-ui, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  --radius: 8px;
  --sidebar-w: 232px;
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --ease-drawer: cubic-bezier(0.32, 0.72, 0, 1);

  --z-sticky: 10;
  --z-scrim: 40;
  --z-drawer: 50;
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 400 0.9375rem/1.5 var(--font);
}

a { color: inherit; }
h1, h2 { text-wrap: balance; margin: 0; }
h1 { font-size: 1.5rem; font-weight: 700; letter-spacing: -0.01em; line-height: 1.25; }
h2 { font-size: 1.0625rem; font-weight: 650; margin-bottom: 0.75rem; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* --- shell --------------------------------------------------------------- */

.app { display: flex; min-height: 100dvh; }

.sidebar {
  position: sticky;
  top: 0;
  height: 100dvh;
  width: var(--sidebar-w);
  flex: none;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  padding: 1.25rem 0.75rem;
  background: var(--surface);
  border-right: 1px solid var(--line);
}

.brand {
  display: block;
  padding: 0 0.625rem;
  font-size: 1.125rem;
  font-weight: 800;
  letter-spacing: -0.015em;
  text-decoration: none;
  color: var(--ink);
}

.nav { display: flex; flex-direction: column; gap: 2px; }

.nav-link {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  width: 100%;
  padding: 0.5rem 0.625rem;
  border: 0;
  border-radius: 6px;
  background: none;
  color: var(--muted);
  font: inherit;
  font-weight: 500;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
  transition: background-color 150ms ease, color 150ms ease;
}
.nav-link.is-active { background: var(--accent-tint); color: var(--ink); font-weight: 600; }
.nav-link.is-active svg { color: var(--accent); }
@media (hover: hover) and (pointer: fine) {
  .nav-link:not(.is-active):hover { background: var(--hover); color: var(--ink); }
}

.logout { margin-top: auto; }

.content { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar { display: none; }

.main {
  width: 100%;
  max-width: 1080px;
  padding: 2rem 2.5rem 3rem;
}

.scrim { display: none; }

/* --- page parts ---------------------------------------------------------- */

.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1.25rem;
}

.count {
  display: inline-block;
  margin-left: 0.375rem;
  padding: 0 0.5rem;
  border-radius: 999px;
  background: var(--hover);
  color: var(--muted);
  font-size: 0.8125rem;
  font-weight: 500;
  vertical-align: 0.15em;
}

.list-controls { display: flex; flex: 1; flex-wrap: wrap; justify-content: flex-end; gap: 0.5rem; }
.filter {
  max-width: 12rem;
  height: 2.375rem;
  padding: 0 0.625rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
}
.filter:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-tint); }

.search { position: relative; width: min(280px, 100%); }
.search svg { position: absolute; left: 0.625rem; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.search input {
  width: 100%;
  height: 2.375rem;
  padding: 0 0.75rem 0 2.125rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  transition: border-color 150ms ease, box-shadow 150ms ease;
}
.search input::placeholder { color: var(--muted); }
.search input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-tint); }

.crumb {
  display: inline-block;
  margin-bottom: 0.5rem;
  color: var(--muted);
  font-size: 0.875rem;
  text-decoration: none;
}
.crumb::before { content: "← "; }
@media (hover: hover) and (pointer: fine) { .crumb:hover { color: var(--ink); } }

section { margin-top: 2.25rem; }
.section-head { margin-bottom: 0.75rem; }
.section-head h2 { margin-bottom: 0; }

.facts { display: flex; flex-wrap: wrap; gap: 0.5rem 2rem; margin: 0.875rem 0 0; }
.facts dt { color: var(--muted); font-size: 0.8125rem; }
.facts dd { margin: 0; font-weight: 500; overflow-wrap: anywhere; }

.profile { display: flex; align-items: flex-start; gap: 1.25rem; }
.avatar { width: 64px; height: 64px; border-radius: 50%; object-fit: cover; flex: none; background: var(--hover); }
.avatar-blank { display: grid; place-items: center; color: var(--accent-ink); background: var(--accent-tint); font-size: 1.5rem; font-weight: 700; }

.chips { display: flex; flex-wrap: wrap; gap: 0.5rem; margin: 0; padding: 0; list-style: none; }
.chips a {
  display: inline-block;
  padding: 0.375rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  text-decoration: none;
  font-weight: 500;
  transition: border-color 150ms ease, background-color 150ms ease;
}
@media (hover: hover) and (pointer: fine) { .chips a:hover { border-color: var(--accent); background: var(--accent-tint); } }

.empty {
  margin: 0;
  padding: 1.5rem;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  color: var(--muted);
  text-align: center;
}

/* --- table --------------------------------------------------------------- */

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

table { width: 100%; border-collapse: collapse; }
th, td { padding: 0.625rem 1rem; text-align: left; vertical-align: top; }
th {
  position: sticky;
  top: 0;
  z-index: var(--z-sticky);
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.8125rem;
  font-weight: 600;
  white-space: nowrap;
}
tbody tr + tr td { border-top: 1px solid var(--line); }
tbody tr { position: relative; transition: background-color 120ms ease; }
@media (hover: hover) and (pointer: fine) { tbody tr:hover { background: var(--hover); } }

.row-link { font-weight: 500; text-decoration: none; }
.row-link::after { content: ""; position: absolute; inset: 0; }
.row-link:focus-visible { outline: none; }
.row-link:focus-visible::after { outline: 2px solid var(--accent); outline-offset: -2px; border-radius: 4px; }

.num { text-align: right; font-variant-numeric: tabular-nums; }
.mono { font-family: var(--mono); font-size: 0.8125rem; white-space: nowrap; }
.muted { color: var(--muted); }
.nowrap { white-space: nowrap; }
.day { display: inline-block; min-width: 2.25rem; font-weight: 500; }
td > div + div { margin-top: 0.125rem; }


/* --- buttons & pager ----------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 2.25rem;
  padding: 0 0.875rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  transition: transform 140ms var(--ease-out), background-color 150ms ease, border-color 150ms ease;
}
.btn:active { transform: scale(0.97); }
.btn[aria-disabled="true"] { color: var(--muted); opacity: 0.55; cursor: default; pointer-events: none; }
@media (hover: hover) and (pointer: fine) { .btn:hover { background: var(--hover); } }

.btn-primary { border-color: var(--accent); background: var(--accent); color: var(--ink); font-weight: 600; }
@media (hover: hover) and (pointer: fine) { .btn-primary:hover { background: #e07300; } }

.pager { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-top: 1rem; }
.pager-pos { color: var(--muted); font-size: 0.875rem; font-variant-numeric: tabular-nums; }

/* --- login --------------------------------------------------------------- */

.login-body { display: grid; place-items: center; min-height: 100dvh; padding: 1rem; }
.login {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  width: min(340px, 100%);
  padding: 2rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
}
.login .brand { padding: 0; margin-bottom: 1rem; font-size: 1.375rem; }
.login label { font-size: 0.875rem; font-weight: 500; }
.login input {
  height: 2.5rem;
  padding: 0 0.75rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font: inherit;
  transition: border-color 150ms ease, box-shadow 150ms ease;
}
.login input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-tint); }
.login input[aria-invalid="true"] { border-color: var(--bad); }
.login .btn { height: 2.5rem; margin-top: 0.75rem; }
.error { margin: 0; color: var(--bad); font-size: 0.875rem; }

/* --- mobile: sidebar becomes a drawer ------------------------------------ */

@media (max-width: 860px) {
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: var(--z-drawer);
    transform: translateX(-100%);
    transition: transform 260ms var(--ease-drawer);
    box-shadow: none;
  }
  .sidebar.is-open { transform: translateX(0); box-shadow: 0 0 40px rgb(0 0 0 / 0.12); }

  .scrim {
    display: block;
    position: fixed;
    inset: 0;
    z-index: var(--z-scrim);
    background: rgb(23 25 28 / 0.32);
    opacity: 0;
    pointer-events: none;
    transition: opacity 200ms ease;
  }
  .scrim.is-open { opacity: 1; pointer-events: auto; }

  .topbar {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    position: sticky;
    top: 0;
    z-index: var(--z-sticky);
    height: 3.25rem;
    padding: 0 0.5rem;
    background: var(--surface);
    border-bottom: 1px solid var(--line);
  }
  .topbar-title { font-weight: 800; letter-spacing: -0.015em; }

  .hamburger {
    display: grid;
    place-items: center;
    width: 2.5rem;
    height: 2.5rem;
    border: 0;
    border-radius: var(--radius);
    background: none;
    color: var(--ink);
    cursor: pointer;
    transition: transform 140ms var(--ease-out);
  }
  .hamburger:active { transform: scale(0.94); }
  .hamburger svg { width: 22px; height: 22px; }

  .main { padding: 1.25rem 1rem 2.5rem; }
  .hide-sm { display: none; }
  .search, .list-controls { width: 100%; }
  .filter { flex: 1 1 0; min-width: 0; max-width: none; }
  th, td { padding: 0.625rem 0.75rem; }
  body.drawer-open { overflow: hidden; }

  /* course tables become one labelled block per course */
  .stack thead { display: none; }
  .stack tr { display: block; padding: 0.75rem 0.875rem; }
  .stack tbody tr + tr { border-top: 1px solid var(--line); }
  .stack tbody tr + tr td { border-top: 0; }
  .stack td { display: grid; grid-template-columns: 5.5rem 1fr; column-gap: 0.5rem; padding: 0.125rem 0; text-align: left; white-space: normal; }
  .stack td:first-child, .stack td.hide-sm { display: block; padding-bottom: 0.375rem; }
  .stack td > div, .stack td > span { grid-column: 2; }
  .stack td[data-label]::before { content: attr(data-label); color: var(--muted); font-size: 0.8125rem; }
}

@media (prefers-reduced-motion: reduce) {
  .sidebar, .scrim, .btn, .hamburger, .nav-link, tbody tr { transition-duration: 0ms; }
  .scrim { transition: opacity 120ms ease; }
}
