:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --text: #1c2330;
  --muted: #5d6675;
  --border: #d9dde4;
  --accent: #21468b;
  --accent-text: #ffffff;
  --accent-soft: #e3eaf7;
  --ok: #1d7a46;
  --ok-soft: #dff3e7;
  --warn-soft: #fff4d6;
  --danger: #b42318;
  --danger-soft: #fde7e5;
  --other: #c9ced6;
  --row: 13px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151b;
    --surface: #1b2029;
    --text: #e6e9ee;
    --muted: #9aa3b2;
    --border: #323a47;
    --accent: #7ea6ef;
    --accent-text: #0d1424;
    --accent-soft: #23314d;
    --ok: #6fd39b;
    --ok-soft: #1c3527;
    --warn-soft: #3a3220;
    --danger: #ff8a80;
    --danger-soft: #3d1f1d;
    --other: #4a5260;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); }
h1 { font-size: 1.5rem; margin: 0.5rem 0 0.75rem; }
h2 { font-size: 1.15rem; margin: 0 0 0.75rem; }
h3 { font-size: 1rem; margin: 1.25rem 0 0.5rem; }
.muted { color: var(--muted); }
.nowrap { white-space: nowrap; }

/* header */
.top {
  display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 1.5rem;
  padding: 0.6rem 16px;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; text-decoration: none; color: var(--text); }
.top nav { display: flex; gap: 1rem; flex-wrap: wrap; }
.top nav a { text-decoration: none; padding: 0.2rem 0; }
.top nav a[aria-current] { font-weight: 600; border-bottom: 2px solid var(--accent); }
.who { margin-left: auto; display: flex; gap: 0.75rem; align-items: center; color: var(--muted); }

main { max-width: 1100px; margin: 0 auto; padding: 1rem 16px 3rem; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  padding: 1rem; margin: 0 0 1rem;
}
.card.narrow { max-width: 40rem; }
details.card > summary { cursor: pointer; font-weight: 600; }
details.card[open] > summary { margin-bottom: 0.75rem; }

.flash { padding: 0.6rem 0.9rem; border-radius: 6px; margin-bottom: 1rem; background: var(--ok-soft); }
.flash.err { background: var(--danger-soft); }

/* forms */
label { display: inline-flex; flex-direction: column; gap: 0.2rem; font-size: 0.85rem; color: var(--muted); }
input, select, button, .button {
  font: inherit; color: var(--text);
  padding: 0.4rem 0.6rem; border-radius: 6px; border: 1px solid var(--border); background: var(--surface);
}
input:focus-visible, select:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
button, .button { cursor: pointer; text-decoration: none; display: inline-block; }
button:hover, .button:hover { border-color: var(--accent); }
button.primary, .button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
button.danger { color: var(--danger); }
button.linkish { border: none; background: none; color: var(--accent); padding: 0; }
fieldset { border: none; padding: 0; margin: 0; }
fieldset.roles { display: flex; gap: 0.75rem; align-items: end; }
fieldset.roles legend { font-size: 0.85rem; color: var(--muted); padding: 0; }
fieldset.roles label { flex-direction: row; align-items: center; color: var(--text); font-size: 0.95rem; }

.user-form, .group-form, .inline-form, .filters {
  display: flex; flex-wrap: wrap; gap: 0.75rem; align-items: end;
}
.user-form.row { padding: 0.75rem 0; border-top: 1px solid var(--border); }
.user-form input[name=email] { min-width: 16rem; }
.actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.group-form + form { margin-top: 1rem; }
.filters { margin-bottom: 0.5rem; }
.filters a { align-self: center; }

.login-form { display: flex; flex-direction: column; gap: 0.75rem; max-width: 22rem; }
.login-form label { display: flex; }
.login-form button { align-self: flex-start; }
.pw-state { align-self: center; font-size: 0.85rem; }
.copy { display: flex; gap: 0.5rem; }
.copy input { flex: 1; min-width: 0; font-family: ui-monospace, monospace; font-size: 0.85rem; }

.tabs { display: flex; gap: 0.25rem 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.tabs a[aria-current] { font-weight: 600; }

/* exam window range picker */
.rangepicker { flex: 1 1 100%; display: flex; flex-direction: column; gap: 0.3rem; }
.rp-label { font-size: 0.85rem; color: var(--muted); }
.rp-fallback { display: flex; flex-wrap: wrap; gap: 0.75rem; }
.rp-fallback[hidden] { display: none; }
.rp { position: relative; max-width: 36rem; }
.rp-nav { position: absolute; top: 0; left: 0; right: 0; display: flex; justify-content: space-between; pointer-events: none; }
.rp-step { pointer-events: auto; padding: 0 0.6rem; font-size: 1.1rem; line-height: 1.6; }
.rp-months { display: flex; gap: 1.5rem; }
.rp-month { flex: 1; min-width: 0; }
.rp-title { text-align: center; font-weight: 600; line-height: 1.9; margin-bottom: 0.25rem; }
.rp-grid { display: grid; grid-template-columns: repeat(7, 1fr); row-gap: 2px; }
.rp-dow { text-align: center; font-size: 0.75rem; color: var(--muted); padding: 0.2rem 0; }
.rp-day {
  border: none; border-radius: 0; background: transparent; padding: 0; height: 2.2rem;
  font-variant-numeric: tabular-nums;
}
.rp-day:hover { background: var(--accent-soft); border-radius: 6px; }
.rp-day.weekend { color: var(--muted); }
.rp-day.today { font-weight: 700; text-decoration: underline; }
.rp-day.in { background: var(--accent-soft); color: var(--text); }
.rp-day.in.preview { background: transparent; background-image: linear-gradient(var(--accent-soft), var(--accent-soft)); opacity: 0.85; }
.rp-day.start, .rp-day.end { background: var(--accent); color: var(--accent-text); }
.rp-day.start { border-radius: 6px 0 0 6px; }
.rp-day.end { border-radius: 0 6px 6px 0; }
.rp-day.solo { border-radius: 6px; }
.rp-day.end.preview { background: var(--accent-soft); color: var(--text); outline: 1px dashed var(--accent); outline-offset: -1px; }
.rp-summary { margin: 0.5rem 0 0; font-size: 0.9rem; }
.rp-summary.rp-error { color: var(--danger); }

/* tables and lists */
.table-scroll { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: 0.5rem; border-top: 1px solid var(--border); vertical-align: top; }
th { border-top: none; font-size: 0.85rem; color: var(--muted); }
td.actions form { display: inline; }

.badge { display: inline-block; padding: 0.05rem 0.5rem; border-radius: 999px; font-size: 0.85rem; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.open { background: var(--accent-soft); color: var(--accent); }
.badge.none { background: var(--warn-soft); }
.badge.warn { background: var(--danger-soft); color: var(--danger); }

.group-list { list-style: none; padding: 0; margin: 0 0 1rem; display: grid; gap: 0.75rem; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.group-list .card { margin: 0; display: flex; flex-direction: column; gap: 0.5rem; }
.group-link { display: flex; flex-direction: column; text-decoration: none; color: var(--text); }
.group-link strong { color: var(--accent); font-size: 1.05rem; }

.slot-list { list-style: none; padding: 0; margin: 0; }
.slot-list li {
  display: flex; flex-wrap: wrap; gap: 0.25rem 1rem; align-items: center;
  padding: 0.5rem 0; border-top: 1px solid var(--border);
}
.slot-list li:first-child { border-top: none; }
.slot-list li > form { margin-left: auto; }
.day .slot-list { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 0 0.75rem; }
.slot-list li.conflict { opacity: 0.6; }

/* week calendar */
.week { margin-bottom: 1.5rem; }
.week h3 { margin-top: 1.5rem; }
.grid-scroll { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; }
.grid {
  --colmin: max(5.5rem, calc(var(--lanes, 1) * 4.5rem));
  display: grid;
  grid-template-columns: 3.2rem repeat(var(--cols), minmax(var(--colmin), 1fr));
  grid-template-rows: 2rem repeat(var(--rows), var(--row));
  min-width: calc(3.2rem + var(--cols) * var(--colmin));
  position: relative;
}
.dayhead { font-size: 0.85rem; font-weight: 600; padding: 0.4rem; border-bottom: 1px solid var(--border); border-left: 1px solid var(--border); white-space: nowrap; overflow: hidden; }
.dayhead.out { color: var(--muted); font-weight: 400; }
.dcol { border-left: 1px solid var(--border); pointer-events: none; }
.dcol.out { background: repeating-linear-gradient(45deg, transparent 0 6px, var(--bg) 6px 12px); }
.hour { grid-column: 1; font-size: 0.75rem; color: var(--muted); padding: 0 0.3rem; transform: translateY(-0.5em); text-align: right; }
.hline { grid-column: 2 / -1; border-top: 1px solid var(--border); pointer-events: none; }
.cell { border: none; border-radius: 0; background: transparent; padding: 0; position: relative; z-index: 2; }
.cell:hover, .cell:focus-visible { z-index: 5; }
.cell:hover::after, .cell:focus-visible::after {
  content: ""; position: absolute; left: 2px; right: 2px; top: 0;
  height: calc(var(--span) * var(--row));
  background: var(--accent-soft); border: 1px dashed var(--accent); border-radius: 4px;
  pointer-events: none;
}

/* the viewer's marked availability */
.avband { background: color-mix(in srgb, var(--ok) 16%, transparent); border-left: 3px solid var(--ok); pointer-events: none; }

/* availability editor */
.avnav { display: flex; flex-wrap: wrap; gap: 0.5rem 1rem; align-items: center; margin: 0.5rem 0; }
.avnav a[aria-current] { font-weight: 700; }
.avgrid { user-select: none; -webkit-user-select: none; }
.avgrid .dayhead { cursor: pointer; }
.avgrid .dayhead:hover { background: var(--accent-soft); }
.acell { border-left: 1px solid var(--border); cursor: crosshair; touch-action: none; }
.acell.on { background: color-mix(in srgb, var(--ok) 35%, transparent); }
.acell.past { opacity: 0.45; }
.acell.sel-add { background: color-mix(in srgb, var(--ok) 60%, transparent); }
.acell.sel-remove { background: var(--danger-soft); }

/* blocks: positioned inside their day by row (--top, --len) and lane */
.dayitems { position: relative; z-index: 3; pointer-events: none; }
.item {
  position: absolute; pointer-events: auto; overflow: hidden;
  top: calc(var(--top) * var(--row) + 1px);
  height: calc(var(--len) * var(--row) - 2px);
  left: calc(100% * var(--lane) / var(--nlanes) + 2px);
  width: calc(100% / var(--nlanes) - 4px);
  padding: 0.15rem 0.35rem; border-radius: 4px; font-size: 0.78rem; line-height: 1.25;
  text-align: left; font-family: inherit;
}
.item .t { font-weight: 600; display: block; }
.item .resize {
  position: absolute; left: 0; right: 0; bottom: 0; height: 8px;
  cursor: ns-resize; touch-action: none;
}
.item .resize::after {
  content: ""; position: absolute; left: 50%; bottom: 2px; width: 1.6rem; height: 3px; margin-left: -0.8rem;
  border-radius: 2px; background: currentColor; opacity: 0.35;
}
.item.own:hover .resize::after, .item.resizing .resize::after { opacity: 0.9; }
.item.resizing { z-index: 6; outline: 2px dashed var(--text); outline-offset: 1px; }
.item .extra { font-size: 0.72rem; border: 1px solid currentColor; border-radius: 3px; padding: 0 0.2rem; white-space: nowrap; }
.viewopts { margin: 0.5rem 0 0.25rem; display: flex; flex-direction: column; gap: 0.5rem; }
.viewopts .toggles { display: flex; flex-wrap: wrap; gap: 0.25rem 1.5rem; }
.lengthpick .muted { align-self: center; font-size: 0.85rem; }
.slot-list li > form.slot-length { margin-left: auto; display: flex; gap: 0.4rem; }
.slot-list li > form.slot-length + form { margin-left: 0; }
.slot-length select { max-width: 15rem; }
.item .x {
  position: absolute; top: 1px; right: 1px; padding: 0 0.35rem; line-height: 1.2;
  background: transparent; border: none; color: inherit; font-size: 1rem;
}
.item .x:hover { background: rgba(0, 0, 0, 0.2); }
.item.other {
  pointer-events: none; color: var(--muted);
  background: repeating-linear-gradient(45deg, var(--surface) 0 5px, var(--other) 5px 7px);
  border: 1px solid var(--other);
}
.item.other.busy { background: var(--other); color: var(--text); }
.item.own { background: var(--accent); color: var(--accent-text); padding-right: 1.5rem; }
.item.own.booked { background: var(--ok); }
.item.own.unused { background: var(--accent-soft); color: var(--muted); }
.item.own.blocked {
  color: var(--text); border: 1px solid var(--danger);
  background: repeating-linear-gradient(45deg, var(--danger-soft) 0 5px, var(--surface) 5px 10px);
}
/* censor calendar */
button.item { border: none; cursor: pointer; display: flex; flex-direction: column; justify-content: flex-start; align-items: flex-start; }
.item.avail { background: var(--accent); color: var(--accent-text); }
.item.avail:hover, .item.avail:focus-visible { filter: brightness(1.15); z-index: 1; outline: 2px solid var(--text); outline-offset: 1px; }
.item.avail.nofit { opacity: 0.45; }
.item.avail.nofit:hover, .item.avail.nofit:focus-visible { opacity: 0.8; }
.fitmark { display: inline-block; background: var(--accent-text); color: var(--accent); border-radius: 3px; padding: 0 0.2rem; line-height: 1.2; }
.item.mine { background: var(--ok); color: var(--accent-text); padding-right: 1.5rem; }
.item.clash { background: var(--other); color: var(--muted); }
.item .sub { display: block; opacity: 0.9; }
/* matched exams */
.item.msup { background: var(--accent); color: var(--accent-text); }
.item.mcen { background: var(--ok); color: var(--accent-text); }
.item.mother { background: var(--accent-soft); color: var(--text); border: 1px solid var(--border); }
.legend .msup { background: var(--accent); }
.legend .mcen { background: var(--ok); }
.legend .mother { background: var(--accent-soft); border: 1px solid var(--border); }

.viewtoggle { display: inline-flex; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; margin-bottom: 0.75rem; }
.viewtoggle a { padding: 0.3rem 0.9rem; text-decoration: none; }
.viewtoggle a[aria-current] { background: var(--accent); color: var(--accent-text); }
.legend { display: flex; flex-wrap: wrap; gap: 0.25rem 1rem; font-size: 0.85rem; color: var(--muted); margin: 0.5rem 0; }
.legend i { display: inline-block; width: 0.9rem; height: 0.9rem; border-radius: 3px; vertical-align: -0.15rem; margin-right: 0.3rem; }
.legend .avail { background: var(--accent); }
.legend .mine { background: var(--ok); }
.legend .clash { background: var(--other); }
.legend .band { background: color-mix(in srgb, var(--ok) 35%, transparent); border-left: 3px solid var(--ok); }
label.check { flex-direction: row; align-items: center; gap: 0.4rem; color: var(--text); font-size: 0.95rem; align-self: center; }

@media (max-width: 600px) {
  .who { margin-left: 0; }
  .user-form input[name=email] { min-width: 0; }
  .user-form label, .group-form label { flex: 1 1 100%; }
  .slot-list li > form { margin-left: 0; }
}
