/*
 * Palette: "doctoral blue" ink on cool paper for availability, with tassel gold
 * reserved for the times the whole committee can make it. Follows the system
 * light/dark setting.
 */
:root {
  color-scheme: light dark;
  --font-ui: "Source Sans 3", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-display: "Newsreader", "Iowan Old Style", "Palatino Linotype", Georgia, serif;

  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #eef1f5;
  --line: #d8dde6;
  --line-soft: #e9ecf1;
  --text: #172033;
  --text-2: #546073;
  --text-3: #7d8798;
  --ink: #1e3f8a;
  --ink-strong: #16316e;
  --ink-soft: #e5ebf7;
  --on-ink: #ffffff;
  --heat: #1e3f8a;
  --gold: #c08a10;
  --gold-soft: #fbf2dc;
  --danger: #b42318;
  --ok: #1d7a4c;
  --shadow-lift: 0 1px 2px rgb(16 24 40 / 0.06), 0 0 0 1px var(--line);
  --shadow-dialog: 0 24px 64px -16px rgb(16 24 40 / 0.35);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11161f;
    --surface: #171d28;
    --surface-2: #1f2633;
    --line: #2e3647;
    --line-soft: #232a37;
    --text: #e7eaf1;
    --text-2: #a7afbe;
    --text-3: #747d8e;
    --ink: #91aaf0;
    --ink-strong: #aec1f5;
    --ink-soft: #212c47;
    --on-ink: #0d1526;
    --heat: #7f9df2;
    --gold: #e6b845;
    --gold-soft: #33291a;
    --danger: #f2877c;
    --ok: #6cc596;
    --shadow-lift: 0 0 0 1px var(--line);
    --shadow-dialog: 0 24px 64px -16px rgb(0 0 0 / 0.7);
  }
}

/* ---- Base ------------------------------------------------------------------- */

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

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 16px/1.5 var(--font-ui);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3, p, ul, ol { margin: 0; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--ink); 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;
}

.icon { width: 18px; height: 18px; flex: none; }
.muted { color: var(--text-2); }
.small { font-size: 14px; }

.page {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px 24px 72px;
}

.topbar {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px 24px 0;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  text-decoration: none;
  font-weight: 700;
  font-size: 16px;
}
.logo { width: 26px; height: 26px; }

.display {
  font-family: var(--font-display);
  font-optical-sizing: auto;
  font-weight: 500;
  font-size: clamp(30px, 4.2vw, 42px);
  line-height: 1.1;
  letter-spacing: -0.012em;
  text-wrap: balance;
}

.lede {
  margin-top: 12px;
  font-size: 18px;
  line-height: 1.55;
  color: var(--text-2);
  max-width: 62ch;
}

.loading { color: var(--text-2); padding: 48px 0; }

.banner {
  padding: 10px 16px;
  font-size: 14px;
  text-align: center;
  background: var(--gold-soft);
  border-bottom: 1px solid color-mix(in srgb, var(--gold) 40%, transparent);
}

/* ---- Controls --------------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  font-size: 15px;
  text-decoration: none;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: 0.6; cursor: default; }
.btn.primary { background: var(--ink); border-color: var(--ink); color: var(--on-ink); }
.btn.primary:hover { background: var(--ink-strong); border-color: var(--ink-strong); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: var(--surface); }
.btn.danger:hover { filter: brightness(1.08); }

.link {
  padding: 0;
  border: 0;
  background: none;
  color: var(--ink);
  font-weight: 600;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

.icon-button {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  flex: none;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--text-3);
}
.icon-button:hover { background: var(--surface-2); color: var(--danger); }

.input {
  width: 100%;
  min-height: 42px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface);
  color: var(--text);
}
.input::placeholder { color: var(--text-3); }
.input:focus { outline: 2px solid color-mix(in srgb, var(--ink) 35%, transparent); outline-offset: 0; border-color: var(--ink); }
.input:disabled { opacity: 0.6; }
textarea.input { resize: vertical; line-height: 1.45; }
select.input { padding-right: 32px; }

/* ---- Create / edit form ----------------------------------------------------- */

.create-page { max-width: 760px; }
.create-intro { margin: 20px 0 28px; }

.poll-form {
  display: grid;
  gap: 26px;
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
}
.dialog .poll-form { padding: 0; border: 0; background: none; }

.field { display: grid; gap: 8px; min-width: 0; margin: 0; padding: 0; border: 0; }
.label { padding: 0; font-weight: 600; font-size: 16px; }
.optional { margin-left: 6px; font-weight: 400; font-size: 14px; color: var(--text-3); }
.sublabel { display: grid; gap: 4px; font-size: 14px; color: var(--text-2); }
.field-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 16px; }
.help { font-size: 14px; color: var(--text-2); }
.help.warning { color: var(--text); padding: 8px 12px; border-radius: 8px; background: var(--gold-soft); }
.check { display: inline-flex; align-items: center; gap: 8px; font-size: 15px; width: fit-content; cursor: pointer; }
.check input { width: 18px; height: 18px; margin: 0; accent-color: var(--ink); }

.form-error, .field-error { color: var(--danger); font-size: 15px; font-weight: 600; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; }

.calendar {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 4px;
  max-width: 440px;
  margin-top: 4px;
}
.cal-weekday { padding-bottom: 2px; font-size: 12px; text-align: center; color: var(--text-3); }
.cal-day {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  border: 0;
  border-radius: 9px;
  font-size: 15px;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}
.cal-month { font-size: 11px; font-weight: 700; letter-spacing: 0.02em; }
button.cal-day { background: var(--surface-2); color: var(--text-3); text-decoration: line-through; text-decoration-color: color-mix(in srgb, var(--text-3) 60%, transparent); }
button.cal-day:hover { box-shadow: inset 0 0 0 1.5px var(--ink); }
button.cal-day[aria-pressed="true"] { background: var(--ink); color: var(--on-ink); font-weight: 600; text-decoration: none; }
.cal-day.outside { color: var(--text-3); opacity: 0.45; }

/* ---- Poll page header ------------------------------------------------------- */

.poll-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px 24px;
  margin-top: 16px;
}
.poll-heading { flex: 1 1 520px; min-width: 0; }
.poll-title { overflow-wrap: anywhere; }
.poll-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 22px;
  margin-top: 12px;
  padding: 0;
  list-style: none;
  color: var(--text-2);
}
.poll-meta li { display: inline-flex; align-items: center; gap: 8px; }
.poll-meta .icon { color: var(--text-3); }
.poll-notes { margin-top: 12px; max-width: 70ch; white-space: pre-line; overflow-wrap: anywhere; }
.poll-actions { display: flex; flex-wrap: wrap; gap: 8px; }

.zone-note {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  max-width: 820px;
  margin-top: 18px;
  padding: 10px 14px;
  border-radius: 10px;
  background: var(--surface-2);
  font-size: 15px;
  color: var(--text-2);
}
.zone-note .icon { margin-top: 2px; }

.poll-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 32px;
  align-items: start;
  margin-top: 24px;
}

/* ---- Board: identity, view switch, grid ------------------------------------- */

.board {
  min-width: 0;
  padding: 20px 22px 22px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface);
}

.who {
  display: grid;
  gap: 10px;
  margin-bottom: 18px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
}
.who-title { font: 500 23px/1.2 var(--font-display); }
.who-help { color: var(--text-2); }
.who-row { display: flex; gap: 8px; max-width: 460px; }
.who-row .input { flex: 1; }
.who.nudge { animation: nudge 0.45s ease; }
@keyframes nudge {
  20%, 60% { transform: translateX(-5px); }
  40%, 80% { transform: translateX(5px); }
}

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  font-weight: 600;
  font-size: 15px;
}
.chip:hover { border-color: var(--ink); color: var(--ink); background: var(--ink-soft); }
.chip .icon { width: 15px; height: 15px; color: var(--ink); }

.me { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; }
.me .link { white-space: nowrap; }
.avatar {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  flex: none;
  border-radius: 50%;
  background: var(--ink-soft);
  color: var(--ink);
  font-weight: 700;
  font-size: 13px;
}

.board-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px 16px;
  margin-bottom: 12px;
}

.switch { display: inline-flex; gap: 2px; padding: 3px; border-radius: 11px; background: var(--surface-2); }
.switch button {
  padding: 7px 14px;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--text-2);
  font-weight: 600;
  font-size: 15px;
}
.switch button:hover { color: var(--text); }
.switch button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow-lift); }

.board-status { min-height: 24px; font-size: 14px; color: var(--text-2); }
.status { display: inline-flex; align-items: center; gap: 6px; }
.status .icon { width: 16px; height: 16px; }
.status.ok .icon { color: var(--ok); }
.status.error, .status.warn { color: var(--danger); }

.legend { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; }
.legend-ramp { display: inline-flex; gap: 2px; }
.legend-ramp i, .legend-all i {
  display: inline-block;
  width: 16px;
  height: 12px;
  border-radius: 3px;
}
.legend-ramp i {
  background: color-mix(in oklab, var(--heat) calc(var(--level) * 100%), transparent);
  box-shadow: inset 0 0 0 1px var(--line-soft);
}
.legend-all { display: inline-flex; align-items: center; gap: 6px; margin-left: 4px; }
.legend-all i { background: var(--heat); box-shadow: inset 0 0 0 2px var(--gold); }

.board-hint { margin-bottom: 14px; font-size: 15px; color: var(--text-2); }

.focus-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 14px;
  margin-bottom: 12px;
  padding: 8px 12px;
  border-radius: 10px;
  background: var(--ink-soft);
  font-size: 15px;
}

/* ---- Grid -------------------------------------------------------------------- */

.grid {
  --row-h: 22px;
  --head-h: 62px;
  --col-min: 50px;
  --col-max: 132px;
  --inset: 3px;
  display: flex;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
.grid.slot-15 { --row-h: 14px; }
.grid.slot-60 { --row-h: 36px; }
@media (pointer: coarse) {
  .grid { --row-h: 30px; --col-min: 54px; }
  .grid.slot-15 { --row-h: 20px; }
  .grid.slot-60 { --row-h: 44px; }
}

.grid-times { flex: none; width: 58px; }
.grid-corner { height: var(--head-h); }
.grid-rail { position: relative; height: calc(var(--rows) * var(--row-h)); }
.grid-label {
  position: absolute;
  right: 10px;
  top: calc(var(--row) * var(--row-h));
  transform: translateY(-50%);
  font-size: 12px;
  line-height: 1;
  color: var(--text-3);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.grid-label.hot { color: var(--text); font-weight: 700; }

.grid-scroll {
  flex: 1 1 auto;
  min-width: 0;
  overflow-x: auto;
  overflow-y: hidden;
  overscroll-behavior-x: contain;
  padding-bottom: 8px;
  border-radius: 6px;
  scrollbar-width: thin;
}
.grid-days { display: flex; min-width: min-content; }
.grid-day { flex: 1 0 var(--col-min); max-width: var(--col-max); min-width: 0; }
.grid-day.gap { margin-left: 10px; }

.grid-head {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  height: var(--head-h);
  padding-bottom: 8px;
  line-height: 1.15;
}
.grid-month { min-height: 14px; font-size: 12px; font-weight: 700; color: var(--ink); }
.grid-weekday { font-size: 12px; color: var(--text-2); }
.grid-date { font: 500 22px/1 var(--font-display); font-variant-numeric: lining-nums; }
.grid-day.hot .grid-weekday, .grid-day.hot .grid-date { color: var(--ink); }

.grid-cells {
  position: relative;
  border-left: 1px solid var(--line-soft);
  border-bottom: 1px solid var(--line);
}
.grid-day.end .grid-cells { border-right: 1px solid var(--line-soft); }

.cell {
  position: relative;
  height: var(--row-h);
  box-shadow: inset 0 1px 0 var(--line-soft);
}
.cell.hour { box-shadow: inset 0 1px 0 var(--line); }
.cell::before {
  content: "";
  position: absolute;
  inset: 0 var(--inset);
}
.cell.on.top::before { top: 2px; border-top-left-radius: 6px; border-top-right-radius: 6px; }
.cell.on.bottom::before { bottom: 1px; border-bottom-left-radius: 6px; border-bottom-right-radius: 6px; }

/* Your availability and one person's: solid blocks, with faint hour ticks inside. */
.grid.mine .cell.on::before, .grid.focus .cell.on::before { background: var(--ink); }
.grid.mine .cell.on.hour:not(.top)::after, .grid.focus .cell.on.hour:not(.top)::after {
  content: "";
  position: absolute;
  top: 0;
  left: var(--inset);
  right: var(--inset);
  height: 1px;
  background: color-mix(in srgb, var(--on-ink) 30%, transparent);
}
.grid.editable .cell { cursor: cell; }
@media (hover: hover) {
  .grid.editable .cell:not(.on):hover::before {
    border-radius: 4px;
    background: color-mix(in srgb, var(--ink) 14%, transparent);
  }
  .grid.group .cell:hover::before { outline: 2px solid var(--text); outline-offset: -1px; }
}

/* Group availability: ink density by how many people are free; gold frame where everyone is. */
.grid.group .cell.on::before { background: color-mix(in oklab, var(--heat) calc(var(--level) * 100%), transparent); }
.grid.group .cell.all::before { box-shadow: inset 2px 0 0 var(--gold), inset -2px 0 0 var(--gold); }
.grid.group .cell.all.all-top::before { box-shadow: inset 2px 0 0 var(--gold), inset -2px 0 0 var(--gold), inset 0 2px 0 var(--gold); }
.grid.group .cell.all.all-bottom::before { box-shadow: inset 2px 0 0 var(--gold), inset -2px 0 0 var(--gold), inset 0 -2px 0 var(--gold); }
.grid.group .cell.all.all-top.all-bottom::before { box-shadow: inset 0 0 0 2px var(--gold); }

.cell.cursor::before { outline: 2px solid var(--text); outline-offset: -1px; }
.grid-scroll:not(:focus-visible) .cell.cursor::before { outline: none; }

.grid-window {
  position: absolute;
  top: calc(var(--from) * var(--row-h));
  left: 0;
  right: 0;
  height: calc(var(--span) * var(--row-h) + 1px);
  border: 2px solid var(--text);
  border-radius: 8px;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--surface) 75%, transparent);
  pointer-events: none;
}

/* ---- Sidebar ------------------------------------------------------------------- */

.side { display: grid; gap: 22px; min-width: 0; }
.side-section + .side-section { padding-top: 22px; border-top: 1px solid var(--line); }
.side-title { margin-bottom: 6px; font: 500 21px/1.25 var(--font-display); }
.side-count { margin-left: 4px; font: 600 15px var(--font-ui); color: var(--text-2); }

.details { min-height: 150px; }
.details-time { font-weight: 600; }
.details-local { display: block; font-weight: 400; font-size: 15px; color: var(--text-2); }
.details-columns { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 12px; }
.details-heading { margin-bottom: 4px; font-size: 14px; font-weight: 600; color: var(--text-2); }
.details-heading .count { margin-left: 2px; color: var(--text); }
.names { padding: 0; list-style: none; font-size: 15px; line-height: 1.45; overflow-wrap: anywhere; }
.unavailable .names { color: var(--text-2); }
.names-empty { font-size: 15px; color: var(--text-3); }
.tag {
  margin-left: 6px;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--ink-soft);
  color: var(--ink);
  font-size: 12px;
  font-weight: 700;
  vertical-align: 1px;
}

.best-list { display: grid; gap: 2px; margin-top: 12px; padding: 0; list-style: none; }
.best {
  display: grid;
  gap: 1px;
  width: 100%;
  padding: 10px 12px;
  border: 0;
  border-radius: 10px;
  background: none;
  text-align: left;
  box-shadow: inset 3px 0 0 var(--line);
}
.best:hover, .best.selected { background: var(--surface-2); }
.best.full { box-shadow: inset 3px 0 0 var(--gold); }
.best-date { font: 500 18px/1.3 var(--font-display); }
.best-time { font-weight: 600; }
.best-who { font-size: 14px; color: var(--text-2); }
.best-flex { font-size: 14px; color: var(--text-3); }

.people { margin-top: 10px; padding: 0; list-style: none; }
.person { display: flex; align-items: center; gap: 4px; }
.person-main {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
  min-height: 38px;
  padding: 6px 10px;
  border: 0;
  border-radius: 8px;
  background: none;
  text-align: left;
}
button.person-main:hover { background: var(--surface-2); }
.person.focused .person-main { background: var(--ink-soft); }
.person-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.person-note { margin-left: auto; padding-left: 8px; font-size: 14px; color: var(--text-3); white-space: nowrap; }
.dot { width: 9px; height: 9px; flex: none; border-radius: 50%; background: var(--ink); }
.person.pending .dot { background: none; box-shadow: inset 0 0 0 1.5px var(--text-3); }
.person.pending .person-name { color: var(--text-2); }
.people + .muted { margin-top: 8px; }

/* ---- Dialogs and toast --------------------------------------------------------- */

.dialog {
  width: min(540px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px);
  padding: 0;
  border: 0;
  border-radius: 18px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-dialog);
}
.dialog.dialog-wide { width: min(720px, calc(100vw - 24px)); }
.dialog::backdrop { background: rgb(8 12 20 / 0.5); }
.dialog-body { padding: 26px; }
.dialog-title { margin-bottom: 8px; font: 500 26px/1.2 var(--font-display); }
.dialog-subtitle { margin: 22px 0 4px; font-size: 16px; }
.dialog-text { margin-bottom: 12px; color: var(--text-2); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 24px; }
.copy-row { display: flex; gap: 8px; }
.copy-row .input { flex: 1; min-width: 0; font-size: 15px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: max(24px, env(safe-area-inset-bottom));
  z-index: 20;
  max-width: calc(100vw - 32px);
  padding: 10px 16px;
  border-radius: 10px;
  background: var(--text);
  color: var(--bg);
  font-weight: 600;
  font-size: 15px;
  opacity: 0;
  transform: translate(-50%, 12px);
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.message-page { max-width: 760px; padding-top: 64px; }
.message-page .btn { margin-top: 24px; }

@media (prefers-reduced-motion: no-preference) {
  .dialog[open] { animation: dialog-in 0.16s ease-out; }
  @keyframes dialog-in { from { opacity: 0; transform: translateY(8px) scale(0.98); } }
}
@media (prefers-reduced-motion: reduce) {
  .toast { transition: none; }
  .who.nudge { animation: none; }
}

/* ---- Small screens --------------------------------------------------------------- */

@media (max-width: 1000px) {
  .poll-body { grid-template-columns: minmax(0, 1fr); }
  .details { min-height: 0; }
  .side { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 22px 32px; }
  .side-section + .side-section { padding-top: 0; border-top: 0; }
}

@media (max-width: 640px) {
  .page { padding: 12px 16px 56px; }
  .topbar { padding: 16px 16px 0; }
  .poll-form { padding: 20px 16px; gap: 22px; }
  .field-row { grid-template-columns: minmax(0, 1fr); }
  .poll-actions { width: 100%; }
  .poll-actions .btn { flex: 1; }
  .board { margin: 0 -8px; padding: 16px 12px; border-radius: 14px; }
  .grid-times { width: 50px; }
  .grid-label { right: 7px; }
  .switch { width: 100%; }
  .switch button { flex: 1; padding: 8px 6px; }
  .who-row { max-width: none; }
  .dialog-body { padding: 22px 18px; }
  .copy-row { flex-direction: column; }
}
