/* Invigilation dashboards: Google-style light theme (spec §12.1).
   System fonts only -- the page makes no external requests. */
:root {
  --bg: #ffffff;
  --surface: #ffffff;
  --surface-2: #f8f9fa;
  --border: #dadce0;
  --text: #202124;
  --muted: #5f6368;
  --primary: #1a73e8;
  --green: #188038;
  --amber: #f9ab00;
  --red: #d93025;
  --yellow: #feefc3;
  --black: #202124;
  --grey: #f1f3f4;
  --radius: 8px;
  --gutter: 16px;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
h1 { margin: 0; font-size: 22px; font-weight: 500; }
h2 { margin: 0; font-size: 16px; font-weight: 500; }
a { color: var(--primary); }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.wrap-anywhere { overflow-wrap: anywhere; }

/* Every flex or grid child that holds text gets min-width: 0, so long
   unbroken names and emails shrink instead of widening the page. */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: var(--gutter); min-width: 0;
  padding: 10px var(--gutter);
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { color: var(--text); font-size: 18px; font-weight: 500; text-decoration: none; white-space: nowrap; }
.topbar-context { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); }
.view { min-width: 0; padding: var(--gutter); }
.page-head {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: var(--gutter);
}

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 36px; padding: 0 16px;
  border: 1px solid var(--border); border-radius: 18px;
  background: var(--surface); color: var(--primary);
  font: inherit; font-weight: 500; text-decoration: none; white-space: nowrap; cursor: pointer;
}
.btn:hover { background: #f1f6fe; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: #1765cc; }
.btn:focus-visible, input:focus-visible, select:focus-visible,
textarea:focus-visible, summary:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

.form { display: grid; gap: var(--gutter); max-width: 880px; }
.form label { display: grid; gap: 4px; min-width: 0; font-weight: 500; }
.form small { color: var(--muted); font-weight: 400; }
.form input, .form select, .form textarea {
  width: 100%; min-width: 0; padding: 8px 10px;
  border: 1px solid var(--border); border-radius: 4px;
  background: var(--surface); color: var(--text); font: inherit;
}
.form textarea { resize: vertical; font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; }
.form-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 200px), 1fr)); }
.form-row { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
.form fieldset, .form details { min-width: 0; padding: 12px; border: 1px solid var(--border); border-radius: var(--radius); }
.form legend { padding: 0 4px; font-weight: 500; }
.form summary { cursor: pointer; font-weight: 500; }
.panel { max-width: 880px; margin-top: var(--gutter); padding: var(--gutter); border: 1px solid var(--border); border-radius: var(--radius); }
.panel h2 { margin-bottom: 8px; }
.panel label { display: grid; gap: 4px; min-width: 0; margin: 8px 0; font-weight: 500; }
label.check { display: flex; align-items: center; gap: 8px; padding: 4px; font-weight: 400; overflow-wrap: anywhere; }
label.check input { flex: none; width: auto; }

.config-list { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 340px), 1fr)); }
.config-card { min-width: 0; padding: var(--gutter); border: 1px solid var(--border); border-radius: var(--radius); }
.config-card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.config-card p { margin: 8px 0 0; }
.config-card-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.pill { display: inline-block; padding: 2px 10px; border-radius: 12px; font-size: 12px; font-weight: 500; white-space: nowrap; }
.pill-on { background: #e6f4ea; color: var(--green); }
.pill-off, .pill-ended { background: var(--grey); color: var(--muted); }
.describe-list { margin: 8px 0 0; padding-left: 20px; }

.banner { margin-bottom: 12px; padding: 10px 14px; border-radius: var(--radius); overflow-wrap: anywhere; }
.banner-error { background: #fce8e6; color: #a50e0e; }
.banner-warn { background: #fef7e0; color: #7a4f01; }
.empty { padding: 24px 0; color: var(--muted); }

.toast {
  position: fixed; left: 50%; bottom: 24px; z-index: 60; transform: translateX(-50%);
  max-width: calc(100% - 32px); padding: 10px 16px; border-radius: 4px;
  background: #323232; color: #fff; overflow-wrap: anywhere;
}
.toast-error { background: #a50e0e; }

/* ------------------------------------------------------------ dashboard -- */
.dash { min-width: 0; }
.dash-head { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: 12px; min-width: 0; margin-bottom: 12px; }
.dash-title { min-width: 0; }
.dash-title h1 { overflow-wrap: anywhere; }
.dash-meta { margin: 4px 0 0; color: var(--muted); overflow-wrap: anywhere; }
.dash-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; min-width: 0; }
.switcher { max-width: 100%; min-height: 36px; padding: 0 8px; border: 1px solid var(--border); border-radius: 4px; background: var(--surface); color: var(--text); font: inherit; }
.empty h2 { margin-bottom: 4px; color: var(--text); }

.tabs { display: flex; gap: 4px; margin-bottom: 12px; overflow-x: auto; border-bottom: 1px solid var(--border); }
.tab { padding: 10px 16px; border-bottom: 3px solid transparent; color: var(--muted); font-weight: 500; text-decoration: none; white-space: nowrap; }
.tab:hover { color: var(--text); }
.tab[aria-current="page"] { border-bottom-color: var(--primary); color: var(--primary); }

.summary { display: grid; gap: 8px; margin-bottom: 12px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 140px), 1fr)); }
.stat { min-width: 0; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-2); }
.stat-value { font-size: 20px; font-weight: 500; }
.stat-label { color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.stat-red .stat-value { color: var(--red); }
.stat-amber .stat-value { color: #b06000; }
.stat-green .stat-value { color: var(--green); }

.toolbar { position: relative; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; min-width: 0; margin-bottom: 12px; }
.search { flex: 1 1 220px; min-width: 0; max-width: 360px; min-height: 36px; padding: 0 14px; border: 1px solid var(--border); border-radius: 18px; background: var(--surface); color: var(--text); font: inherit; }
.multi > summary { list-style: none; }
.multi > summary::-webkit-details-marker { display: none; }
/* Positioned against the toolbar, not the button, so an open list can never
   reach past the right edge of the page. */
.multi-list { position: absolute; top: 100%; left: 0; z-index: 20; width: min(320px, 100%); max-height: 320px; overflow-y: auto; margin-top: 4px; padding: 8px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); box-shadow: 0 2px 6px rgba(60, 64, 67, .3); }
.quick { display: flex; flex-wrap: wrap; gap: 6px; }
.chip-toggle { min-height: 32px; padding: 0 12px; border: 1px solid var(--border); border-radius: 16px; background: var(--surface); color: var(--text); font: inherit; white-space: nowrap; cursor: pointer; }
.chip-toggle[aria-pressed="true"] { border-color: #d2e3fc; background: #e8f0fe; color: #174ea6; }
.group-by { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); white-space: nowrap; }
.group-by select { min-height: 32px; border: 1px solid var(--border); border-radius: 4px; background: var(--surface); color: var(--text); font: inherit; }

/* Colour chips: every chip carries its word, so colour is never the only signal. */
.chip { display: inline-block; padding: 2px 8px; border-radius: 12px; font-size: 12px; font-weight: 500; line-height: 18px; white-space: nowrap; }
.c-green { background: var(--green); color: #fff; }
.c-amber { background: var(--amber); color: var(--text); }
.c-red { background: var(--red); color: #fff; }
.c-yellow { background: var(--yellow); color: var(--text); }
.c-black { background: var(--black); color: #fff; }
.c-neutral { background: var(--grey); color: var(--muted); }
.set-by-admin { margin-left: 4px; color: var(--primary); font-size: 10px; vertical-align: middle; }
.new-badge { margin-left: 6px; padding: 0 6px; border-radius: 8px; background: #fce8e6; color: #a50e0e; font-size: 11px; font-weight: 700; }
.in-progress .chip { font-style: italic; }

/* The table scrolls inside its own box; the page never does (spec §12.3). */
.table-wrap { max-width: 100%; max-height: calc(100vh - 200px); overflow: auto; border: 1px solid var(--border); border-radius: var(--radius); }
.grid { border-collapse: separate; border-spacing: 0; font-size: 13px; }
.grid th, .grid td { padding: 6px; border-bottom: 1px solid var(--border); background: var(--surface); text-align: left; vertical-align: middle; }
.grid thead th { position: sticky; top: 0; z-index: 3; background: var(--surface-2); font-weight: 500; white-space: nowrap; }
.head-stat { color: var(--muted); font-size: 11px; font-weight: 400; }
.sort { padding: 0; border: 0; background: none; color: inherit; font: inherit; cursor: pointer; }
.grid .pin { position: sticky; z-index: 1; }
.grid thead .pin { z-index: 4; }
.grid .pin-0 { left: var(--pin-0, 0px); }
.grid .pin-1 { left: var(--pin-1, 0px); }
.grid .pin-2 { left: var(--pin-2, 0px); }
.grid .pin-3 { left: var(--pin-3, 0px); }
.grid .pin-last { box-shadow: inset -1px 0 0 var(--border); }
.grid tbody tr[data-key] { cursor: pointer; }
.grid tbody tr[data-key]:not(.row-black):not(.row-yellow):hover td { background: var(--surface-2); }
.grid tr.row-red td:first-child { box-shadow: inset 4px 0 0 var(--red); }
.grid tr.row-amber td:first-child { box-shadow: inset 4px 0 0 var(--amber); }
.grid tr.row-green td:first-child { box-shadow: inset 4px 0 0 var(--green); }
.grid tr.row-yellow td { background: var(--yellow); }
.grid tr.row-black td { background: var(--black); color: #fff; }
.grid tr.row-black .chip { background: #5f6368; color: #fff; }
.grid tr.row-black .muted { color: #dadce0; }
.group-row th { background: var(--grey); text-align: left; }
.group-toggle { position: sticky; left: 8px; display: inline-flex; flex-wrap: wrap; align-items: baseline; gap: 8px; padding: 2px 0; border: 0; background: none; color: var(--text); font: inherit; text-align: left; cursor: pointer; }

/* Every cell that can hold long text has a maximum width. max-width, not
   width: it bounds the cell's contribution to the table's column sizing. */
.clip { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.clip-email { max-width: 150px; }
.clip-flag { max-width: 170px; }
.clip-reg { max-width: 120px; }
.clip-text { max-width: 140px; }
.wrap-name { max-width: 150px; overflow-wrap: anywhere; }

/* -------------------------------------------------------------- cards -- */
.cards { display: grid; gap: 8px; margin: 0; padding: 0; list-style: none; }
.card { min-width: 0; padding: 12px; border: 1px solid var(--border); border-left-width: 6px; border-radius: var(--radius); background: var(--surface); cursor: pointer; }
.card-red { border-left-color: var(--red); }
.card-amber { border-left-color: var(--amber); }
.card-green { border-left-color: var(--green); }
.card-neutral { border-left-color: var(--grey); }
.card-yellow { border-left-color: #f9d56e; background: var(--yellow); }
.card-black { border-color: var(--black); background: var(--black); color: #fff; }
.card-black .chip { background: #5f6368; color: #fff; }
.card-black .muted, .card-black .card-flag { color: #dadce0; }
.card-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-width: 0; }
.card-seat { min-width: 0; font-size: 18px; font-weight: 500; overflow-wrap: anywhere; }
.card-name { margin-top: 4px; font-weight: 500; overflow-wrap: anywhere; }
.card-chips { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 8px; }
.card-flag { margin-top: 8px; color: var(--muted); overflow-wrap: anywhere; }
.card-group { padding: 8px 4px 0; }
.card:focus-visible, .grid tbody tr[data-key]:focus-visible { outline: 2px solid var(--primary); outline-offset: -2px; }

.filters-toggle, .sheet-done { display: none; }

@media (max-width: 767px) {
  .view { padding: 12px; }
  .dash-actions .btn { flex: 1 1 auto; }
  .filters-toggle { display: inline-flex; margin-bottom: 12px; }
  .toolbar { display: none; }
  /* On a phone the filters open as a bottom sheet. */
  .toolbar.sheet-open {
    position: fixed; right: 0; bottom: 0; left: 0; z-index: 40;
    display: flex; max-height: 75vh; overflow-y: auto; margin: 0; padding: 16px;
    border-top: 1px solid var(--border); border-radius: 12px 12px 0 0;
    background: var(--surface); box-shadow: 0 -2px 8px rgba(60, 64, 67, .3);
  }
  .toolbar .search { flex-basis: 100%; max-width: none; }
  .toolbar .multi { flex: 1 1 100%; }
  .toolbar .multi-list { position: static; width: auto; max-height: none; margin-top: 8px; box-shadow: none; }
  .sheet-done { display: inline-flex; flex-basis: 100%; }
}

/* ------------------------------------------------------------- drawer -- */
.drawer-backdrop { position: fixed; inset: 0; z-index: 49; background: rgba(32, 33, 36, .4); }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 50;
  width: min(480px, 100%); overflow-y: auto; padding: 16px;
  background: var(--surface); box-shadow: -2px 0 8px rgba(60, 64, 67, .3);
}
body.drawer-open { overflow: hidden; }
.drawer-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.drawer-title { min-width: 0; }
.drawer-title h2 { font-size: 20px; overflow-wrap: anywhere; }
.drawer-title p { margin: 4px 0 0; }
.drawer-section { margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--border); }
.drawer-section h3 { margin: 12px 0 8px; font-size: 14px; font-weight: 500; }
.drawer-section h3:first-child { margin-top: 0; }
.drawer-section p { margin: 6px 0; overflow-wrap: anywhere; }
.facts { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 4px 12px; margin: 0; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; overflow-wrap: anywhere; }
.mini { width: 100%; border-collapse: collapse; table-layout: fixed; font-size: 13px; }
.mini th, .mini td { padding: 4px; border-bottom: 1px solid var(--border); text-align: left; overflow-wrap: anywhere; }
.status-form { display: grid; gap: 8px; }
.status-form label { display: grid; gap: 4px; font-weight: 500; }
.status-form select, .status-form textarea { width: 100%; padding: 8px; border: 1px solid var(--border); border-radius: 4px; background: var(--surface); color: var(--text); font: inherit; }
.history { margin: 0; padding-left: 20px; }
.history li { margin-bottom: 8px; overflow-wrap: anywhere; }
.flag-text { color: var(--muted); }

/* ------------------------------------------------------------ sign-in -- */
.topbar-user { display: flex; align-items: center; gap: 8px; min-width: 0; margin-left: auto; }
.topbar-name { min-width: 0; max-width: 40vw; overflow: hidden; color: var(--muted); text-overflow: ellipsis; white-space: nowrap; }
.topbar-link { color: var(--primary); font-weight: 500; text-decoration: none; white-space: nowrap; }
.btn-small { min-height: 30px; padding: 0 12px; }
.login { max-width: 420px; margin: 32px auto; }
.login h1 { margin-bottom: 8px; }

/* -------------------------------------------------------- invigilators -- */
.password { font-size: 20px; letter-spacing: 1px; user-select: all; }
.check-list { display: grid; gap: 4px; margin: 8px 0; }
.grid.invigilators td.actions { white-space: nowrap; }
