/* LearnHub - course administration
   Idea: a registrar's desk. Sections are binder divider tabs, courses are book spines.
   Colour is used for meaning only: each section owns one colour that reappears in its tab,
   its buttons and its focus ring. Everything else stays quiet. */

:root {
  --paper: #f3f6f8;
  --surface: #ffffff;
  --ink: #182433;
  --muted: #586777;
  --line: #d9e1e8;
  --line-strong: #b9c6d1;

  --courses: #2453c7;
  --courses-tint: #e6edfb;
  --students: #147a55;
  --students-tint: #dff3ea;
  --enroll: #a85a00;
  --enroll-tint: #fbebd3;
  --danger: #b3261e;
  --danger-tint: #fbe6e4;

  --accent: var(--courses);
  --accent-tint: var(--courses-tint);

  --font-display: "Bricolage Grotesque", "Segoe UI", system-ui, sans-serif;
  --font-body: "Figtree", "Segoe UI", system-ui, -apple-system, sans-serif;

  --radius: 6px;
  --radius-pill: 999px;
  --page: 1080px;
}

body[data-section="students"]    { --accent: var(--students); --accent-tint: var(--students-tint); }
body[data-section="enrollments"] { --accent: var(--enroll);   --accent-tint: var(--enroll-tint); }

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

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

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 1rem;
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

h1, h2 {
  font-family: var(--font-display);
  letter-spacing: -0.02em;
  margin: 0;
}

button, input, select, textarea { font: inherit; color: inherit; }

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

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

.skip-link {
  position: absolute; left: 12px; top: -48px; z-index: 50;
  background: var(--ink); color: #fff; padding: 8px 14px; border-radius: var(--radius);
}
.skip-link:focus { top: 12px; }

/* ------------------------------------------------------------ masthead + tabs */

.masthead { background: var(--surface); border-bottom: 1px solid var(--line); }

.masthead-inner {
  max-width: var(--page); margin: 0 auto; padding: 16px 24px 0;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
}

.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; }
.brand-mark { width: 32px; height: 32px; }
.brand-mark rect { fill: var(--courses); }
.brand-mark path { fill: #fff; }
.brand-name { font-family: var(--font-display); font-weight: 800; font-size: 1.6rem; letter-spacing: -0.03em; }

.api-status { margin: 0; display: inline-flex; align-items: center; gap: 8px; font-size: 0.875rem; color: var(--muted); }
.api-status .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--line-strong); }
.api-status.is-ok .dot { background: var(--students); }
.api-status.is-down .dot { background: var(--danger); }
.api-status.is-down { color: var(--danger); }

.tabs { margin-top: 14px; }
.tabs-inner {
  max-width: var(--page); margin: 0 auto; padding: 0 24px;
  display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none;
}
.tabs-inner::-webkit-scrollbar { display: none; }

.tab {
  --tab-color: var(--courses);
  --tab-tint: var(--courses-tint);
  flex: 0 0 auto;
  display: inline-flex; align-items: center; gap: 10px;
  padding: 11px 20px 12px;
  background: var(--tab-tint);
  border: 1px solid var(--line);
  border-top: 4px solid var(--tab-color);
  border-bottom: 0;
  border-radius: 8px 8px 0 0;
  color: var(--muted);
  font-weight: 600;
  cursor: pointer;
  margin-bottom: -1px;
}
.tab-students    { --tab-color: var(--students); --tab-tint: var(--students-tint); }
.tab-enrollments { --tab-color: var(--enroll);   --tab-tint: var(--enroll-tint); }

.tab:hover { color: var(--ink); }
.tab.is-active {
  background: var(--paper);
  color: var(--ink);
  border-color: var(--line);
  border-bottom: 1px solid var(--paper);
  padding-bottom: 13px;
}
.tab:focus-visible { outline-color: var(--tab-color); }

.tab .count {
  min-width: 24px; padding: 1px 8px; text-align: center;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-pill); font-size: 0.8125rem; font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* ------------------------------------------------------------ layout */

main { flex: 1; width: 100%; max-width: var(--page); margin: 0 auto; padding: 32px 24px 48px; }

.panel[hidden] { display: none; }

.panel-head {
  display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  margin-bottom: 24px;
}
.panel-head h1 { font-size: 1.75rem; line-height: 1.15; font-weight: 700; }
.lede { margin: 6px 0 0; color: var(--muted); font-size: 0.95rem; }

/* ------------------------------------------------------------ buttons + fields */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 40px; padding: 0 18px;
  border-radius: var(--radius); border: 1px solid transparent;
  font-weight: 600; cursor: pointer; text-decoration: none; line-height: 1;
}
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { filter: brightness(1.1); }

.btn-quiet { background: transparent; border-color: var(--line-strong); color: var(--ink); }
.btn-quiet:hover:not(:disabled) { background: var(--surface); }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { filter: brightness(1.1); }

.link-btn {
  background: none; border: 0; padding: 4px 2px; cursor: pointer;
  font-weight: 600; font-size: 0.9rem; color: var(--accent);
  text-decoration: underline; text-underline-offset: 3px; text-decoration-color: transparent;
}
.link-btn:hover { text-decoration-color: currentColor; }
.link-btn.is-danger { color: var(--danger); }

.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field label { font-size: 0.875rem; font-weight: 600; }
.field input, .field select, .field textarea {
  width: 100%; min-height: 42px; padding: 9px 12px;
  background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--radius);
}
.field textarea { resize: vertical; line-height: 1.45; }
.field input:focus-visible, .field select:focus-visible, .field textarea:focus-visible {
  outline: 3px solid var(--accent); outline-offset: 0; border-color: var(--accent);
}
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.field-inline { flex-direction: row; align-items: center; gap: 10px; }
.field-inline select { width: auto; min-width: 190px; }

.form-error {
  margin: 0; padding: 10px 12px; border-radius: var(--radius);
  background: var(--danger-tint); color: var(--danger); font-size: 0.9rem; font-weight: 500;
}

/* ------------------------------------------------------------ courses: book spines */

.spines { display: grid; grid-template-columns: repeat(auto-fill, minmax(310px, 1fr)); gap: 18px; }

.spine-card {
  --h: 220;
  display: grid; grid-template-columns: 74px 1fr;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden; min-height: 176px;
}
.spine {
  background: hsl(var(--h) 55% 30%); color: #fff;
  display: flex; flex-direction: column; align-items: center; justify-content: space-between;
  padding: 14px 6px;
}
.spine-code {
  writing-mode: vertical-rl; transform: rotate(180deg);
  font-family: var(--font-display); font-weight: 800; font-size: 1.45rem; letter-spacing: 0.02em;
  white-space: nowrap;
}
.spine-weeks { font-size: 0.8125rem; font-weight: 600; text-align: center; line-height: 1.2; }
.spine-weeks strong { display: block; font-size: 1.15rem; font-family: var(--font-display); }

.spine-body { padding: 16px 18px 12px; display: flex; flex-direction: column; min-width: 0; }
.spine-title { font-family: var(--font-display); font-weight: 700; font-size: 1.125rem; line-height: 1.25; letter-spacing: -0.01em; margin: 0 0 6px; }
.spine-desc {
  margin: 0 0 12px; color: var(--muted); font-size: 0.9rem; line-height: 1.45;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.spine-foot { margin-top: auto; display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.fee { font-weight: 700; font-variant-numeric: tabular-nums; }
.fee small { font-weight: 500; color: var(--muted); font-size: 0.8125rem; margin-right: 4px; }
.row-actions { display: inline-flex; gap: 10px; }

/* ------------------------------------------------------------ students */

.people { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.person {
  display: grid; grid-template-columns: 56px 1fr auto; align-items: center; gap: 16px;
  padding: 14px 18px; border-top: 1px solid var(--line);
}
.person:first-child { border-top: 0; }

.avatar {
  --h: 160;
  width: 56px; height: 56px; border-radius: 50%; overflow: hidden;
  background: hsl(var(--h) 45% 88%); color: hsl(var(--h) 45% 26%);
  display: grid; place-items: center;
  font-family: var(--font-display); font-weight: 700; font-size: 1.15rem;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }

.person-name { margin: 0; font-weight: 600; }
.person-meta { margin: 2px 0 0; color: var(--muted); font-size: 0.9rem; overflow-wrap: anywhere; }
.person-meta span + span { margin-left: 14px; }
.person-actions { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; justify-content: flex-end; }

/* ------------------------------------------------------------ enrollments */

.enroll-bar {
  display: grid; grid-template-columns: 1fr 1fr auto; gap: 14px; align-items: end;
  padding: 16px 18px; margin-bottom: 22px;
  background: var(--enroll-tint); border: 1px solid #efd4a8; border-radius: var(--radius);
}

.table-tools { display: flex; justify-content: flex-end; margin-bottom: 10px; }

.table-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow-x: auto; }
table.enrollments { width: 100%; border-collapse: collapse; }
.enrollments th {
  text-align: left; font-size: 0.875rem; font-weight: 600; color: var(--muted);
  padding: 12px 18px; border-bottom: 1px solid var(--line); white-space: nowrap;
}
.enrollments td { padding: 12px 18px; border-top: 1px solid var(--line); vertical-align: middle; }
.enrollments tbody tr:first-child td { border-top: 0; }
.cell-strong { font-weight: 600; }
.cell-date { color: var(--muted); font-size: 0.9rem; white-space: nowrap; font-variant-numeric: tabular-nums; }
.cell-actions { text-align: right; white-space: nowrap; }

.status-select {
  appearance: none; -webkit-appearance: none;
  border: 1px solid transparent; border-radius: var(--radius-pill);
  padding: 5px 30px 5px 13px; font-weight: 600; font-size: 0.875rem; cursor: pointer;
  background-repeat: no-repeat; background-position: right 11px center; background-size: 10px 6px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%23182433' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}
.status-PENDING   { background-color: #fbebd3; color: #7a4300; }
.status-ACTIVE    { background-color: #dff3ea; color: #0e5e41; }
.status-COMPLETED { background-color: #e6edfb; color: #1d3f99; }
.status-CANCELLED { background-color: #eceff2; color: #4a5866; }

.empty {
  margin: 0; padding: 36px 24px; text-align: center; color: var(--muted);
  background: var(--surface); border: 1px dashed var(--line-strong); border-radius: var(--radius);
}
.empty strong { display: block; color: var(--ink); font-size: 1.05rem; margin-bottom: 4px; }
.empty .btn { margin-top: 14px; }
.enrollments-empty-wrap { margin-top: 12px; }

.activity { margin-top: 34px; }
.activity h2 { font-size: 1.15rem; font-weight: 700; }
.hint { margin: 4px 0 14px; color: var(--muted); font-size: 0.9rem; }
.activity-list { list-style: none; margin: 0; padding: 0 0 0 6px; border-left: 2px solid var(--line); }
.activity-item { position: relative; padding: 2px 0 14px 20px; }
.activity-item::before {
  content: ""; position: absolute; left: -8px; top: 7px; width: 12px; height: 12px; border-radius: 50%;
  background: var(--line-strong); border: 2px solid var(--paper);
}
.activity-item.ev-ENROLLED::before       { background: var(--students); }
.activity-item.ev-STATUS_CHANGED::before { background: var(--courses); }
.activity-item.ev-REMOVED::before        { background: var(--danger); }
.activity-text { margin: 0; }
.activity-time { margin: 0; color: var(--muted); font-size: 0.8125rem; }
.activity-empty { color: var(--muted); font-size: 0.9rem; padding-left: 4px; }

/* ------------------------------------------------------------ footer */

.footer { border-top: 1px solid var(--line); background: var(--surface); }
.footer p { max-width: var(--page); margin: 0 auto; padding: 0 24px; }
.footer p:first-child { padding-top: 18px; font-weight: 500; }
.footer-small { padding-top: 4px !important; padding-bottom: 20px; color: var(--muted); font-size: 0.875rem; }

/* ------------------------------------------------------------ dialogs */

dialog {
  width: min(480px, calc(100vw - 32px)); padding: 0;
  border: 0; border-radius: 10px; background: var(--surface); color: var(--ink);
  box-shadow: 0 18px 50px rgba(24, 36, 51, 0.28);
}
dialog::backdrop { background: rgba(24, 36, 51, 0.5); }
dialog[open] { animation: pop 140ms ease-out; }
dialog form { padding: 24px; display: flex; flex-direction: column; gap: 16px; }
dialog h2 { font-size: 1.35rem; font-weight: 700; }
dialog p { margin: 0; color: var(--muted); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 4px; }

@keyframes pop { from { opacity: 0; transform: translateY(6px) scale(0.98); } to { opacity: 1; transform: none; } }

/* ------------------------------------------------------------ toasts */

.toasts {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 8px; align-items: center;
  z-index: 100; width: min(460px, calc(100vw - 32px)); pointer-events: none;
}
.toast {
  pointer-events: auto; width: 100%;
  display: flex; align-items: flex-start; gap: 10px;
  padding: 12px 16px; background: var(--ink); color: #fff; border-radius: var(--radius);
  border-left: 5px solid var(--students); font-size: 0.95rem;
  box-shadow: 0 8px 24px rgba(24, 36, 51, 0.3);
  animation: toast-in 180ms ease-out;
}
.toast.is-error { border-left-color: #ff8a80; }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

/* ------------------------------------------------------------ small screens */

@media (max-width: 720px) {
  main { padding: 24px 16px 40px; }
  .masthead-inner { padding: 14px 16px 0; }
  .tabs-inner { padding: 0 16px; }
  .brand-name { font-size: 1.4rem; }
  .panel-head h1 { font-size: 1.5rem; }

  .field-row { grid-template-columns: 1fr; }
  .enroll-bar { grid-template-columns: 1fr; }
  .enroll-bar .btn { width: 100%; }

  .person { grid-template-columns: 48px 1fr; gap: 12px; padding: 14px; }
  .avatar { width: 48px; height: 48px; }
  .person-actions { grid-column: 1 / -1; justify-content: flex-start; }

  /* enrollments table becomes stacked rows */
  .enrollments thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); }
  .enrollments, .enrollments tbody, .enrollments tr, .enrollments td { display: block; width: 100%; }
  .enrollments tr { padding: 12px 14px; border-top: 1px solid var(--line); }
  .enrollments tbody tr:first-child { border-top: 0; }
  .enrollments td { border: 0; padding: 3px 0; }
  .enrollments td[data-label]::before {
    content: attr(data-label); display: block; color: var(--muted); font-size: 0.8125rem; font-weight: 600;
  }
  .cell-actions { text-align: left; padding-top: 8px !important; }
  .table-tools { justify-content: flex-start; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
