/* Orbit Classroom Tools - admin portal.
   Orbit pink by default; after sign-in the school's own theme colours
   replace --brand* (app.js applySchoolColors). */

:root {
  --brand: #d63a78;
  --brand-dark: #a3124f;
  --brand-light: #fde8f0;
  --on-brand: #ffffff;
  /* Derived: highlighted backgrounds, and brand-coloured text on --surface. */
  --tint: var(--brand-light);
  --ink: var(--brand-dark);

  --bg: #f7f7f9;
  --surface: #ffffff;
  --text: #1f1f1f;
  --muted: #5f6368;
  --line: #e3e3e8;
  --ok: #1e8e4e;
  --bad: #c5221f;
  --warn-bg: #fff6df;
  --warn-line: #f0c75e;
  --bad-bg: #fdecea;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.06), 0 4px 16px rgba(0, 0, 0, 0.05);
  --font: "Google Sans", "Noto Sans Thai", "Segoe UI", Roboto, Arial, sans-serif;
  color-scheme: light;
}

/* Dark: the computer's setting unless the header toggle chose light, or
   the toggle chose dark (theme.js sets data-theme before first paint). */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #131316;
    --surface: #1d1d21;
    --text: #ececf1;
    --muted: #a3a3ad;
    --line: #34343b;
    /* The school's light/dark shades are made for white pages; on dark
       ones derive readable versions from the brand colour instead. */
    --tint: color-mix(in srgb, var(--brand) 26%, var(--surface));
    --ink: color-mix(in srgb, var(--brand) 40%, #ffffff);
    --warn-bg: #3a300f;
    --warn-line: #7a6320;
    --bad-bg: #3d1a19;
    --ok: #4cc27f;
    --bad: #f28b82;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #131316;
  --surface: #1d1d21;
  --text: #ececf1;
  --muted: #a3a3ad;
  --line: #34343b;
  /* The school's light/dark shades are made for white pages; on dark
     ones derive readable versions from the brand colour instead. */
  --tint: color-mix(in srgb, var(--brand) 26%, var(--surface));
  --ink: color-mix(in srgb, var(--brand) 40%, #ffffff);
  --warn-bg: #3a300f;
  --warn-line: #7a6320;
  --bad-bg: #3d1a19;
  --ok: #4cc27f;
  --bad: #f28b82;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}

h1 { font-size: 24px; font-weight: 600; margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 15px; font-weight: 600; margin: 0 0 12px; color: var(--muted); text-transform: none; }

a { color: var(--ink); }
:focus-visible { outline: 3px solid var(--brand); outline-offset: 2px; border-radius: 6px; }

.muted { color: var(--muted); }
.small { font-size: 13px; }
.block { display: block; }
.mono { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; }
.nowrap { white-space: nowrap; }
.boot { padding: 48px; text-align: center; color: var(--muted); }

/* ---------- Top bar ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 16px;
  min-height: 64px;
  padding: 10px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  border-top: 4px solid var(--brand);
}
.topbar--plain { background: transparent; border-bottom-color: transparent; }

.brand { display: flex; align-items: center; gap: 10px; }
.brand__logo { width: 36px; height: 36px; }
.brand__text { display: flex; flex-direction: column; line-height: 1.2; }
.brand__name { font-weight: 600; }
.brand__sub { font-size: 12px; color: var(--muted); }

.topbar__school {
  padding-left: 16px;
  border-left: 1px solid var(--line);
  font-weight: 600;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}
.topbar__actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }

.who { display: inline-flex; align-items: center; gap: 8px; max-width: 260px; }
.who__pic { width: 28px; height: 28px; border-radius: 50%; }
.who__email { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; color: var(--muted); }

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 40px;
  padding: 8px 20px;
  border: 1px solid var(--brand);
  border-radius: 999px;
  background: var(--brand);
  color: var(--on-brand);
  font: inherit;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}
.btn:hover:not(:disabled) { background: var(--brand-dark); border-color: var(--brand-dark); }
.btn:disabled { opacity: 0.6; cursor: default; }
.btn--ghost { background: var(--surface); color: var(--ink); }
.btn--ghost:hover:not(:disabled) { background: var(--tint); color: var(--ink); }
.btn--small { min-height: 32px; padding: 4px 14px; font-size: 13px; }
.btn--danger { border-color: var(--bad); color: var(--bad); }
.btn--danger:hover:not(:disabled) { background: var(--bad-bg); border-color: var(--bad); color: var(--bad); }

/* ---------- Layout ---------- */

.center { display: grid; place-items: start center; padding: 48px 16px; }

.layout {
  display: grid;
  grid-template-columns: 232px minmax(0, 1fr);
  min-height: calc(100vh - 68px);
}

.sidenav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 20px 12px;
  border-right: 1px solid var(--line);
  background: var(--surface);
}
.sidenav__item {
  display: block;
  padding: 10px 14px;
  border-radius: 999px;
  color: var(--text);
  text-decoration: none;
  font-weight: 500;
}
.sidenav__item:hover { background: var(--tint); }
.sidenav__item.is-active { background: var(--tint); color: var(--ink); font-weight: 600; }

.content { padding: 28px 32px 120px; max-width: 1040px; width: 100%; }

.pagehead { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; }
.pagehead__actions { margin-left: auto; }

@media (max-width: 760px) {
  .topbar { flex-wrap: wrap; padding: 10px 16px; }
  .topbar__school { order: 3; flex-basis: 100%; padding-left: 0; border-left: 0; }
  .who__email { display: none; }
  .layout { grid-template-columns: 1fr; }
  .sidenav { flex-direction: row; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--line); padding: 8px 12px; }
  .sidenav__item { white-space: nowrap; }
  .content { padding: 20px 16px 120px; }
}

/* ---------- Panels, cards ---------- */

.panel, .card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.panel { padding: 32px; }
.panel--narrow { width: min(460px, 100%); }

.signin { text-align: center; }
.signin h1 { margin: 12px 0 8px; }
.signin__mascot { width: 96px; height: 96px; }
.signin__button { display: flex; justify-content: center; min-height: 44px; margin: 24px 0 8px; }
.signin__notice:empty { display: none; }
.signin__notice { color: var(--bad); }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; }
.card { padding: 20px 22px; }
.card--wide { margin-top: 16px; }
.card__big { font-size: 20px; font-weight: 600; margin: 0 0 12px; overflow-wrap: anywhere; }
.card__head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.card__head h2 { margin: 0; }

.facts { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 6px 16px; margin: 0; }
.facts dt { color: var(--muted); font-size: 13px; }
.facts dd { margin: 0; overflow-wrap: anywhere; }
.facts--status { margin-top: 12px; }

.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 8px; vertical-align: 1px; }
.dot--ok { background: var(--ok); }
.dot--bad { background: var(--bad); }

.chips { display: inline-flex; flex-wrap: wrap; gap: 6px; }
.chip, .badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--tint);
  color: var(--ink);
  font-size: 12px;
  font-weight: 600;
}
.badge { margin-left: 8px; background: transparent; border: 1px solid var(--line); color: var(--muted); font-weight: 500; }

/* ---------- Alerts, toast ---------- */

.alert {
  margin: 0 0 16px;
  padding: 12px 16px;
  border: 1px solid var(--bad);
  border-radius: 10px;
  background: var(--bad-bg);
}
.alert ul { margin: 6px 0 0; padding-left: 20px; }
.alert--warn { border-color: var(--warn-line); background: var(--warn-bg); margin-top: 12px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translate(-50%, 20px);
  max-width: min(560px, calc(100vw - 32px));
  padding: 12px 18px;
  border-radius: 10px;
  background: #202124;
  color: #fff;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 30;
}
.toast.is-shown { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Forms ---------- */

.form { display: flex; flex-direction: column; gap: 16px; }
fieldset {
  margin: 0;
  padding: 18px 22px 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}
legend { padding: 0 6px; margin-left: -6px; font-weight: 600; }

.field { display: flex; flex-direction: column; gap: 6px; margin-top: 12px; max-width: 520px; }
.field label { font-size: 13px; font-weight: 600; }
.hint { margin: 0; font-size: 12px; color: var(--muted); }

input[type="text"], input[type="email"], input[type="number"], select {
  width: 100%;
  min-height: 40px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
}
input:focus, select:focus { border-color: var(--brand); outline: none; box-shadow: 0 0 0 3px var(--tint); }

.row3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
@media (max-width: 760px) { .row3 { grid-template-columns: 1fr; } }

.checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 8px 16px; margin-top: 8px; }
.checks--roles { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.check {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: start;
  column-gap: 10px;
  padding: 8px 10px;
  border-radius: 10px;
  cursor: pointer;
}
.check:hover { background: var(--tint); }
.check input { width: 18px; height: 18px; margin: 2px 0 0; accent-color: var(--brand); }
.check__hint { grid-column: 2; font-size: 12px; color: var(--muted); }
.check.is-disabled { cursor: default; opacity: 0.65; }
.check.is-disabled:hover { background: transparent; }

.themes { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin-top: 8px; }
.theme {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  cursor: pointer;
}
.theme input { position: absolute; opacity: 0; pointer-events: none; }
.theme:has(input:checked) { border-color: var(--brand); box-shadow: 0 0 0 2px var(--brand); }
.theme:has(input:focus-visible) { outline: 3px solid var(--brand); outline-offset: 2px; }
.theme__swatches { display: flex; }
.swatch { width: 28px; height: 28px; border-radius: 50%; border: 2px solid var(--surface); margin-right: -6px; box-shadow: 0 0 0 1px var(--line); }
.theme__name { font-size: 13px; font-weight: 500; }

.savebar {
  position: sticky;
  bottom: 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 16px;
  padding: 12px 16px 12px 20px;
  border: 1px solid var(--brand);
  border-radius: 999px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.savebar[hidden] { display: none; }
.savebar__actions { margin-left: auto; display: flex; gap: 8px; }

.inline { display: flex; align-items: flex-end; gap: 10px; flex-wrap: wrap; }
.inline .field { flex: 1 1 280px; margin-top: 0; }
.grantbox { margin-top: 16px; padding: 16px; border: 1px dashed var(--line); border-radius: 12px; }
.actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }

/* ---------- Tables ---------- */

.tablewrap { margin-top: 16px; overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 12px 16px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--line); }
.table th { font-size: 12px; font-weight: 600; color: var(--muted); background: var(--bg); }
.table tr:last-child td { border-bottom: 0; }
.cell-actions { white-space: nowrap; text-align: right; }
.cell-actions .btn + .btn { margin-left: 6px; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* ---------- Content: links and announcements ---------- */

textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  resize: vertical;
}
textarea:focus { border-color: var(--brand); outline: none; box-shadow: 0 0 0 3px var(--tint); }
input[type="url"], input[type="datetime-local"] {
  width: 100%;
  min-height: 40px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
}

.row2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 16px; }
.row2 .field, .row3 .field { max-width: none; }
.row3 .check { margin-top: 30px; }
@media (max-width: 760px) { .row2 { grid-template-columns: 1fr; } .row3 .check { margin-top: 8px; } }

.editor {
  margin: 12px 0;
  padding: 16px 18px;
  border: 1px solid var(--brand);
  border-radius: 12px;
  background: var(--bg);
}
.editor .field:first-child { margin-top: 0; }

.h2--strong { color: var(--text); font-size: 16px; display: flex; align-items: center; gap: 4px; }

.items { list-style: none; margin: 8px 0 12px; padding: 0; }
.item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 4px 12px;
  padding: 12px 0;
  border-top: 1px solid var(--line);
}
.item:first-child { border-top: 0; }
.item__main { min-width: 0; }
.item__title { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-weight: 600; }
.item__title .badge { margin-left: 0; }
.item__url { display: block; font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }
a.item__url { color: var(--ink); }
.item__meta { display: flex; flex-wrap: wrap; gap: 4px 14px; margin-top: 4px; font-size: 13px; color: var(--muted); }
.item__body { margin: 8px 0 4px; white-space: pre-line; overflow-wrap: anywhere; }
.item__actions { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: flex-end; gap: 6px; }
.item__edit { grid-column: 1 / -1; }
.item__edit:empty { display: none; }

.items--cards .item {
  margin-bottom: 12px;
  padding: 16px 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.chip--new { background: #e3f1ff; color: #0b57d0; }
.chip--important { background: var(--bad-bg); color: var(--bad); }

.status {
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  border: 1px solid var(--line);
  color: var(--muted);
}
.status--published { border-color: var(--ok); color: var(--ok); }
.status--archived { border-style: dashed; }

.filters { display: flex; flex-wrap: wrap; gap: 8px; margin: 16px 0 12px; }
.filter {
  min-height: 34px;
  padding: 4px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}
.filter:hover { border-color: var(--brand); }
.filter.is-on { background: var(--tint); border-color: var(--brand); color: var(--ink); font-weight: 600; }

/* ---------- Terms, groups, course links ---------- */

.pick { margin-top: 12px; padding: 12px 16px 14px; background: var(--surface); }
.pick legend { font-size: 13px; }
.spans { display: flex; flex-direction: column; gap: 8px; margin: 8px 0; }
.span { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.span select { width: auto; min-width: 140px; }
.span input[type="date"] { width: auto; }
input[type="date"] {
  min-height: 40px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
}
.item__chips { margin-top: 6px; }
.or { align-self: center; padding-bottom: 10px; }

/* Header appearance toggle. */
.btn--theme { gap: 6px; }
.btn__icon { font-size: 15px; line-height: 1; }
@media (max-width: 760px) { .btn--theme { padding: 4px 10px; } }
