/* Geist and Geist Mono, SIL Open Font License 1.1 (see fonts/OFL.txt). */
@font-face {
  font-family: "Geist";
  src: url("../fonts/geist-latin.woff2") format("woff2");
  font-weight: 100 900;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Geist";
  src: url("../fonts/geist-latin-ext.woff2") format("woff2");
  font-weight: 100 900;
  font-display: swap;
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "Geist Mono";
  src: url("../fonts/geist-mono-latin.woff2") format("woff2");
  font-weight: 100 900;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

/* Neutrals plus a single accent. Working hours use the accent, everything
   else is a shade of grey. light-dark() picks the value for the active
   colour scheme, which data-theme pins (or leaves to the device). */
:root {
  color-scheme: light dark;

  --bg: light-dark(#ffffff, #0b0b0c);
  --surface: var(--bg);
  --text: light-dark(#18181b, #f4f4f5);
  --muted: light-dark(#6b6b73, #a1a1aa);
  --border: light-dark(#e4e4e7, #27272a);
  --accent: light-dark(#4338ca, #8b93ff);
  --accent-text: light-dark(#ffffff, #11113a);
  --accent-soft: light-dark(
    color-mix(in srgb, var(--accent) 14%, var(--surface)),
    color-mix(in srgb, var(--accent) 26%, var(--surface))
  );
  --danger: light-dark(#b42318, #ff8a80);

  --work-bg: var(--accent-soft);
  --work-text: light-dark(
    color-mix(in srgb, var(--accent) 70%, var(--text)),
    color-mix(in srgb, var(--accent) 25%, var(--text))
  );
  --off-bg: light-dark(#f8f8f9, #121214);
  --off-text: light-dark(#3f3f46, #d4d4d8);
  --night-bg: light-dark(#ebebee, #1c1c1f);
  --night-text: light-dark(#8a8a93, #71717a);

  --font: "Geist", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "Geist Mono", ui-monospace, "SF Mono", Menlo, monospace;
  --radius: 8px;
  --cell-w: 2.85rem;
  --cell-h: 4rem;
  --person-w: 14rem;
}

:root[data-theme="light"] {
  color-scheme: light;
}
:root[data-theme="dark"] {
  color-scheme: dark;
}

[data-font="system"] {
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
[data-font="serif"] {
  --font: ui-serif, "Iowan Old Style", Charter, Georgia, serif;
}
[data-font="mono"] {
  --font: var(--mono);
}

/* --------------------------------------------------------------- base */

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

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 var(--font);
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
}

h1,
h2,
p {
  margin: 0;
}

h1,
h2 {
  line-height: 1.2;
}

button,
input,
select,
.button-like {
  font: inherit;
  color: inherit;
}

button,
.button-like {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  min-height: 2.5rem;
  padding: 0.4rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  cursor: pointer;
}

button:hover,
.button-like:hover {
  border-color: var(--muted);
}

button:disabled {
  opacity: 0.45;
  cursor: default;
}

button:disabled:hover {
  border-color: var(--border);
}

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
}

button.danger {
  color: var(--danger);
}

input,
select {
  min-height: 2.5rem;
  padding: 0.35rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

:focus-visible,
.button-like:focus-within {
  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: 1rem;
  top: -4rem;
  z-index: 10;
  padding: 0.5rem 1rem;
  background: var(--surface);
  border-radius: var(--radius);
}

.skip-link:focus {
  top: 1rem;
}

.muted {
  color: var(--muted);
  font-weight: normal;
}

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

.topbar,
main,
.footer {
  max-width: 120rem;
  margin: 0 auto;
  padding-inline: 1rem;
}

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem 1.5rem;
  padding-block: 1rem;
}

.topbar h1 {
  font-size: 1.5rem;
  letter-spacing: -0.01em;
}

.toolbar,
.date-nav,
.actions,
.banner-actions,
.sel-actions,
.settings-buttons {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

.toolbar {
  gap: 0.75rem 1.25rem;
}

.icon-button {
  justify-content: center;
  width: 2.5rem;
  padding: 0;
  font-size: 1.4rem;
  line-height: 1;
}

section {
  margin-bottom: 1.5rem;
}

section:focus {
  outline: none;
}

.section-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem 1rem;
  min-height: 2.25rem;
  margin-bottom: 0.75rem;
}

.section-head h2 {
  font-size: 1.15rem;
}

.best .link-button {
  min-height: 0;
  padding: 0 0.15rem;
  border: 0;
  border-radius: 4px;
  background: none;
  color: inherit;
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.sort-control {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  margin-left: auto;
  font-size: 0.85rem;
  color: var(--muted);
}

.sort-control select {
  min-height: 2.25rem;
  padding-block: 0.15rem;
  color: var(--text);
}

.banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1rem;
  padding: 0.75rem 1rem;
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  background: var(--accent-soft);
}

.banner[hidden] {
  display: none;
}

/* Legend and hint share one quiet line under the grid. */
.legend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem 1rem;
  margin-top: 0.75rem;
  font-size: 0.8rem;
  color: var(--muted);
}

.legend > span {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.legend .hint {
  flex: 1 1 18rem;
}

.swatch {
  display: inline-block;
  width: 0.85rem;
  height: 0.85rem;
  border-radius: 3px;
  border: 1px solid var(--border);
}

.swatch.work {
  background: var(--work-bg);
}
.swatch.off {
  background: var(--off-bg);
}
.swatch.night {
  background: var(--night-bg);
}

/* --------------------------------------------------------------- grid */

.grid-scroll {
  overflow: auto;
  max-height: max(24rem, calc(100vh - 12rem));
  overscroll-behavior-x: contain;
  scrollbar-width: thin;
}

.grid {
  border-collapse: separate;
  border-spacing: 0 4px;
  min-width: max-content;
  margin-top: -4px;
}

.grid th,
.grid td {
  padding: 0;
}

.grid thead th {
  position: sticky;
  top: 0;
  z-index: 3;
  background: var(--surface);
}

.grid thead .corner {
  z-index: 4;
}

.grid .corner,
.grid .person {
  position: sticky;
  left: 0;
  z-index: 2;
  width: var(--person-w);
  min-width: var(--person-w);
  max-width: var(--person-w);
  padding-right: 0.75rem;
  background: var(--surface);
  text-align: left;
  font-weight: normal;
  vertical-align: middle;
}

.grid .corner {
  line-height: 1.3;
}

.grid .corner span {
  display: block;
  font-weight: 600;
}

.grid .corner small {
  color: var(--muted);
  font-size: 0.8rem;
}

/* Person column: name, where they are, what time it is there. */

.person {
  line-height: 1.35;
}

.person-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.25rem;
}

.person-name {
  overflow: hidden;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.person-actions {
  display: flex;
  flex-shrink: 0;
}

/* With a mouse, the row actions float over the name on hover or focus;
   on touch screens they are always visible. */
@media (hover: hover) {
  .person-actions {
    position: absolute;
    top: 0.2rem;
    right: 0.5rem;
    background: var(--surface);
    opacity: 0;
  }
  tr:hover .person-actions,
  .person-actions:focus-within {
    opacity: 1;
  }
}

.mini {
  justify-content: center;
  width: 1.6rem;
  min-height: 1.6rem;
  padding: 0;
  border-color: transparent;
  background: transparent;
  color: var(--muted);
  font-size: 0.85rem;
}

.mini:hover {
  color: var(--text);
  border-color: var(--border);
}

.person-meta {
  overflow: hidden;
  font-size: 0.8rem;
  color: var(--muted);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.person-meta .lead {
  color: var(--text);
}

.person-now {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  font-size: 0.85rem;
}

.clock {
  font-weight: 600;
}

.status {
  font-size: 0.8rem;
}

.status::before {
  content: "";
  display: inline-block;
  width: 0.5rem;
  height: 0.5rem;
  margin-right: 0.3rem;
  border-radius: 50%;
  border: 2px solid currentColor;
}

.status-work {
  color: var(--accent);
}

.status-work::before {
  background: currentColor;
}

.status-off,
.status-night {
  color: var(--muted);
}

.status-night::before {
  border-radius: 1px;
}

/* Hour cells. The label sits at the left edge, like a tick on a ruler:
   the box labelled 15 is 15:00–16:00. */

.grid .cell {
  position: relative;
  isolation: isolate;
  width: var(--cell-w);
  min-width: var(--cell-w);
  height: var(--cell-h);
  padding: 0 0 0 0.45rem;
  text-align: left;
  vertical-align: middle;
  line-height: 1.2;
}

.cell.work {
  background: var(--work-bg);
  color: var(--work-text);
}

.cell.off {
  background: var(--off-bg);
  color: var(--off-text);
}

.cell.night {
  background: var(--night-bg);
  color: var(--night-text);
}

/* Each row is a rounded track; working blocks are rounded too. */
.person + .cell,
.cell.work:not(.work + .work) {
  border-top-left-radius: var(--radius);
  border-bottom-left-radius: var(--radius);
}
.cell:last-child,
.cell.work:has(+ .cell:not(.work)) {
  border-top-right-radius: var(--radius);
  border-bottom-right-radius: var(--radius);
}

/* Three fixed lines (day, hour, minutes or am/pm) keep every hour
   number on the same baseline. */
.cell > span:not(.sr-only) {
  position: relative;
  z-index: 1;
  display: block;
  overflow: hidden;
  white-space: nowrap;
}

.cell .day {
  height: 0.85rem;
  font-size: 0.62rem;
  font-weight: 700;
  line-height: 0.85rem;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.cell .hour {
  font-size: 1rem;
}

.cell.work .hour {
  font-weight: 600;
}

.cell .sub {
  height: 0.85rem;
  font-size: 0.7rem;
  line-height: 0.85rem;
  opacity: 0.85;
}

.cell.daystart {
  box-shadow: inset 2px 0 var(--muted);
}

.cell.now::after,
.slot.now::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: var(--now-pos, 0%);
  width: 2px;
  background: var(--accent);
  pointer-events: none;
}

.grid .cell.selected {
  box-shadow: inset 0 0 0 2px var(--text);
}

/* Availability header row: one chip per hour, darker as more people work. */

.grid .slot {
  position: relative;
  height: 2.75rem;
  padding: 0 1px 2px;
  vertical-align: bottom;
}

.slot-button {
  position: relative;
  z-index: 1;
  justify-content: center;
  width: 100%;
  height: 2.25rem;
  min-height: 0;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: color-mix(in srgb, var(--accent) var(--level), transparent);
  font-size: 0.85rem;
  font-weight: 600;
}

.slot-button:hover {
  box-shadow: inset 0 0 0 1px var(--muted);
}

.slot-button:focus-visible {
  outline-offset: -3px;
}

.slot.all .slot-button {
  background: var(--accent);
  color: var(--accent-text);
}

.slot.selected .slot-button {
  box-shadow: inset 0 0 0 2px var(--text);
}

.slot.now::after {
  z-index: 0;
}

.grid .empty {
  padding: 2rem 1rem;
  color: var(--muted);
  text-align: left;
}

/* ---------------------------------------------------------- selection */

.selection {
  padding-top: 1.25rem;
  border-top: 1px solid var(--border);
}

.selection[hidden] {
  display: none;
}

.sel-list {
  margin: 0 0 1rem;
  padding: 0;
  list-style: none;
}

.sel-list li {
  display: grid;
  grid-template-columns: minmax(8rem, 14rem) minmax(9rem, max-content) minmax(7rem, 10rem) auto;
  align-items: center;
  gap: 0.25rem 1rem;
  padding: 0.45rem 0.75rem;
  border-left: 3px solid var(--border);
  border-bottom: 1px solid var(--border);
}

.sel-list li.is-work {
  border-left-color: var(--accent);
}

.sel-name,
.sel-time {
  font-weight: 600;
}

.sel-day,
.sel-status {
  color: var(--muted);
}

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

dialog {
  width: min(30rem, calc(100vw - 2rem));
  padding: 1.25rem;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 20px 50px rgb(0 0 0 / 0.3);
}

dialog.wide {
  width: min(40rem, calc(100vw - 2rem));
  max-height: calc(100vh - 2rem);
  overflow-y: auto;
}

dialog::backdrop {
  background: rgb(10 12 16 / 0.55);
}

dialog h2 {
  margin-bottom: 1rem;
  font-size: 1.25rem;
}

.field {
  display: grid;
  gap: 0.25rem;
  margin-bottom: 0.75rem;
}

.field > span {
  font-weight: 600;
  font-size: 0.9rem;
}

.field input,
.field select {
  width: 100%;
  min-width: 0;
}

.field-hint {
  margin: -0.5rem 0 0.75rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(11rem, 1fr));
  gap: 0 0.75rem;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 0.75rem;
}

.field-row legend {
  grid-column: 1 / -1;
}

fieldset {
  margin: 0 0 1rem;
  padding: 0;
  border: 0;
}

fieldset fieldset {
  margin-bottom: 0.5rem;
}

fieldset.plain {
  margin: 0;
}

fieldset:disabled {
  opacity: 0.55;
}

legend {
  margin-bottom: 0.35rem;
  padding: 0;
  font-weight: 600;
  font-size: 0.9rem;
}

.sub-legend {
  font-weight: 500;
  color: var(--muted);
}

.check {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
  cursor: pointer;
}

.check input {
  width: 1.15rem;
  height: 1.15rem;
  min-height: 0;
  accent-color: var(--accent);
}

.day-boxes {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.day-box {
  position: relative;
}

.day-box input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.day-box span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 3rem;
  min-height: 2.5rem;
  padding: 0 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.day-box input:checked + span {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
}

.day-box input:checked + span::before {
  content: "✓ ";
  white-space: pre;
}

.day-box input:focus-visible + span {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.color-grid {
  display: grid;
  grid-template-columns: minmax(7rem, max-content) 3.5rem auto;
  align-items: center;
  justify-content: start;
  gap: 0.5rem 0.75rem;
}

.color-grid input[type="color"] {
  width: 3.5rem;
  height: 2.25rem;
  padding: 2px;
  cursor: pointer;
}

.color-grid button {
  min-height: 2.25rem;
  padding-block: 0.2rem;
  font-size: 0.85rem;
}

.settings-buttons {
  margin-top: 0.5rem;
}

.error {
  min-height: 1.5em;
  margin: 0 0 0.5rem;
  color: var(--danger);
  font-weight: 600;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 1rem;
}

/* -------------------------------------------------------------- misc */

.footer {
  padding-block: 0.75rem 1.25rem;
  border-top: 1px solid var(--border);
  font-size: 0.75rem;
  line-height: 1.45;
  color: var(--muted);
}

.footer a {
  color: inherit;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 1.25rem;
  z-index: 20;
  max-width: calc(100vw - 2rem);
  padding: 0.6rem 1rem;
  border-radius: 999px;
  background: var(--text);
  color: var(--bg);
  font-size: 0.9rem;
  opacity: 0;
  transform: translate(-50%, 1rem);
  transition:
    opacity 0.2s,
    transform 0.2s;
  pointer-events: none;
}

.toast.visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

@media (prefers-reduced-motion: reduce) {
  .toast {
    transition: none;
  }
}

@media (forced-colors: active) {
  .cell.work {
    border: 2px solid CanvasText;
  }
  .cell.selected,
  .slot.selected .slot-button {
    outline: 3px solid Highlight;
    outline-offset: -3px;
  }
  .slot-button {
    border: 1px solid CanvasText;
  }
}

@media (max-width: 40rem) {
  :root {
    --person-w: 9.5rem;
    --cell-w: 2.6rem;
  }
  .topbar h1 {
    font-size: 1.25rem;
  }
  .person-meta {
    font-size: 0.72rem;
    white-space: normal;
  }
  .person-line {
    flex-wrap: wrap;
  }
  .person-name {
    flex-basis: 100%;
  }
  .person-actions {
    order: 1;
  }
  .sel-list li {
    grid-template-columns: 1fr auto;
  }
  .sel-day,
  .sel-status {
    font-size: 0.85rem;
  }
}

@media print {
  .topbar .toolbar,
  .person-actions,
  .sel-actions,
  .legend .hint,
  .footer {
    display: none;
  }
}
