:root {
  /* Tells the browser to draw its own controls dark - the date picker icon, dropdown
     menus, scrollbars and focus rings. Without it the calendar icon renders black
     on a black field and all but disappears. */
  color-scheme: dark;

  --bg: #0b0d10;
  --panel: #14181d;
  --panel-2: #1b2026;
  --fg: #f4f6f8;
  --muted: #8a93a0;
  --accent: #4cc2ff;
  --accent-ink: #06202e;
  --border: #242a31;
  --danger: #ff6b6b;
  --ok: #56d364;
  --warn: #e3b341;
  --radius: 12px;
  /* One height for every control on a row, so buttons, fields and checkboxes line up. */
  --control-height: 38px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); }

/* ---------- shared chrome ---------- */

.app-header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px clamp(14px, 2vw, 28px);
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  flex-wrap: wrap;
}
.app-header h1 {
  font-size: 1.05rem;
  font-weight: 600;
  margin: 0;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}
.app-header .spacer { flex: 1; }
.app-header nav { display: flex; gap: 4px; flex-wrap: wrap; }

.language-switch { display: inline-flex; border: 1px solid var(--border); border-radius: 999px; overflow: hidden; }
.lang-button {
  background: transparent;
  border: 0;
  color: var(--muted);
  padding: 5px 12px;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  cursor: pointer;
}
.lang-button.is-active { background: var(--accent); color: var(--accent-ink); }

main { padding: clamp(14px, 2vw, 28px); max-width: 1400px; margin: 0 auto; }

/* ---------- controls ---------- */

button, .button {
  font: inherit;
  white-space: nowrap; /* button labels must never wrap onto a second line */
  min-height: var(--control-height);
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--fg);
  padding: 8px 14px;
  cursor: pointer;
  transition: border-color 0.12s ease, background 0.12s ease;
}
button:hover, .button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
button.ghost { background: transparent; }
button.danger { color: var(--danger); }
button.small { padding: 4px 9px; font-size: 0.82rem; }
button[disabled] { opacity: 0.45; cursor: not-allowed; }

.tab {
  background: transparent;
  border: 1px solid transparent;
  color: var(--muted);
  padding: 7px 14px;
  border-radius: 999px;
}
.tab.is-active { background: var(--panel-2); border-color: var(--border); color: var(--fg); }

input, select, textarea {
  font: inherit;
  background: var(--bg);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 8px 11px;
  width: 100%;
}
input:not([type="checkbox"]), select { min-height: var(--control-height); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

/* The picker icon still sits at low contrast by default; lift it and make it feel clickable. */
::-webkit-calendar-picker-indicator { opacity: 0.55; cursor: pointer; }
::-webkit-calendar-picker-indicator:hover { opacity: 1; }
label { display: block; font-size: 0.82rem; color: var(--muted); margin-bottom: 5px; }
.field { margin-bottom: 12px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.row > * { flex: 1 1 180px; }
.row > .shrink { flex: 0 0 auto; }
.checkbox {
  display: flex; align-items: center; gap: 9px;
  margin-bottom: 0; cursor: pointer; color: var(--fg); font-size: 0.9rem; line-height: 1.35;
}
/* The row bottom-aligns its children. Giving the checkbox the same height as the other
   controls puts it on their centre line instead of down at their baseline. */
.row > .checkbox { min-height: var(--control-height); }
.checkbox:hover input[type="checkbox"] { border-color: var(--accent); }

input[type="checkbox"] {
  appearance: none; -webkit-appearance: none;
  flex: 0 0 auto; width: 18px; height: 18px; padding: 0;
  border: 1px solid var(--border); border-radius: 5px; background: var(--bg);
  display: inline-grid; place-content: center; cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease;
}
input[type="checkbox"]::before {
  content: ""; width: 11px; height: 11px;
  background: var(--accent-ink);
  transform: scale(0); transition: transform 0.12s ease-out;
  /* A drawn checkmark rather than a font glyph, so it stays crisp at any size. */
  clip-path: polygon(14% 44%, 0 65%, 50% 100%, 100% 16%, 80% 0%, 43% 62%);
}
input[type="checkbox"]:checked { background: var(--accent); border-color: var(--accent); }
input[type="checkbox"]:checked::before { transform: scale(1); }
input[type="checkbox"]:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
input[type="checkbox"]:disabled { opacity: 0.45; cursor: not-allowed; }

@media (prefers-reduced-motion: reduce) {
  input[type="checkbox"], input[type="checkbox"]::before { transition: none; }
}

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: clamp(14px, 1.6vw, 22px);
  margin-bottom: 18px;
}
.card h2 { font-size: 1rem; margin: 0 0 14px; letter-spacing: 0.05em; text-transform: uppercase; color: var(--muted); }
.card h3 { font-size: 0.9rem; margin: 18px 0 10px; color: var(--muted); }
.help { color: var(--muted); font-size: 0.85rem; line-height: 1.5; margin: 0 0 14px; }
.empty { color: var(--muted); font-style: italic; padding: 10px 0; }

table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
th { text-align: left; color: var(--muted); font-weight: 600; font-size: 0.78rem;
     text-transform: uppercase; letter-spacing: 0.06em; padding: 8px 10px; }
td { padding: 9px 10px; border-top: 1px solid var(--border); vertical-align: middle; }
tr.is-inactive td { opacity: 0.5; }
/* Keeps the link column from squeezing the action buttons onto two lines. */
td.links { width: 1%; }
td.actions { width: 1%; text-align: right; white-space: nowrap; }
.link-button {
  display: block;
  max-width: 150px;
  margin: 2px 0;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 0.78rem;
}

.badge {
  display: inline-block; padding: 2px 9px; border-radius: 999px;
  font-size: 0.75rem; font-weight: 600; border: 1px solid var(--border); color: var(--muted);
}
.badge.pending { color: var(--warn); border-color: var(--warn); }
.badge.accepted { color: var(--ok); border-color: var(--ok); }
.badge.declined, .badge.cancelled { color: var(--danger); border-color: var(--danger); }

.copy-row { display: flex; gap: 8px; align-items: center; }
.copy-row input { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.82rem; }

.toasts {
  position: fixed; bottom: 24px; right: 24px; z-index: 50;
  display: flex; flex-direction: column; gap: 10px;
  max-width: min(420px, calc(100vw - 48px));
}
.toast {
  display: flex; align-items: flex-start; gap: 10px;
  /* Solid fill with dark text - a notice should not be mistaken for a panel or a button. */
  background: var(--accent); color: var(--accent-ink);
  border: 0; border-radius: 12px;
  padding: 13px 14px 13px 16px;
  font-size: 0.92rem; font-weight: 600; line-height: 1.4;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.5);
  animation: toast-in 0.18s ease-out;
}
.toast-ok { background: var(--ok); color: #05230c; }
.toast-error { background: var(--danger); color: #2e0606; }
/* Icon and close button occupy exactly one text line, so all three sit on the same
   centre line for a short message and stay on the first line for a long one. The height
   is pinned to the text line rather than to each element's own em, since both carry a
   different font-size for their glyph. */
.toast { --toast-line: 1.288rem; } /* 0.92rem font-size x 1.4 line-height */
.toast .toast-icon,
.toast .toast-close {
  flex: 0 0 auto;
  display: inline-flex; align-items: center; justify-content: center;
  height: var(--toast-line); line-height: 1;
}
.toast .toast-icon { width: 1.1em; font-size: 1rem; }
.toast .toast-text { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.toast .toast-close {
  width: 1.5em; min-height: 0; padding: 0;
  background: transparent; border: 0; color: inherit;
  opacity: 0.6; font-size: 1.1rem; cursor: pointer; border-radius: 6px;
}
.toast .toast-close:hover { opacity: 1; background: rgba(0, 0, 0, 0.12); }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) {
  .toast { animation: none; }
}

/* ---------- schedule grid (admin) ---------- */

.planner { display: grid; grid-template-columns: 260px minmax(0, 1fr); gap: 18px; align-items: start; }
@media (max-width: 900px) { .planner { grid-template-columns: 1fr; } }

.person-chip {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 999px;
  padding: 7px 14px; margin-bottom: 7px; cursor: grab; user-select: none;
}
.person-chip:active { cursor: grabbing; }
.person-chip.is-dragging { opacity: 0.4; }
/* The marker is not a person, so it is drawn as an outline rather than a filled chip. */
.person-chip.is-marker,
.assignment.is-marker {
  background: transparent;
  border-style: dashed;
  border-color: var(--muted);
  color: var(--muted);
  font-style: italic;
}
.person-chip.is-marker { margin-bottom: 12px; }
.person-chip.is-marker:hover, .assignment.is-marker:hover { border-color: var(--accent); color: var(--fg); }
.person-chip .count { color: var(--muted); font-size: 0.78rem; }

.week-list { display: flex; flex-direction: column; gap: 6px; }
.week-row {
  display: grid; grid-template-columns: 150px minmax(0, 1fr);
  gap: 14px; align-items: center;
  background: var(--panel); border: 1px solid var(--border); border-radius: 10px;
  padding: 9px 14px; cursor: pointer;
}
.week-row.is-selected { border-color: var(--accent); background: var(--panel-2); }
.week-row.is-drop-target { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.week-row.is-current { border-left: 3px solid var(--accent); }
.week-row.is-past { opacity: 0.55; }
.week-row .when { color: var(--muted); font-size: 0.88rem; white-space: nowrap; }
.week-row .when strong { color: var(--fg); display: block; font-size: 0.98rem; }
.week-row .slots { display: flex; gap: 7px; flex-wrap: wrap; min-height: 30px; align-items: center; }

.assignment {
  display: inline-flex; align-items: center; gap: 7px;
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 999px;
  padding: 4px 6px 4px 13px; font-size: 0.9rem; cursor: grab;
}
.assignment button {
  border: 0; background: transparent; color: var(--muted); padding: 0 4px;
  line-height: 1; font-size: 1rem; border-radius: 999px;
}
.assignment button:hover { color: var(--danger); }

.selection-bar {
  position: sticky; bottom: 0; margin-top: 12px;
  background: var(--panel-2); border: 1px solid var(--accent); border-radius: 10px;
  padding: 10px 14px; display: flex; gap: 12px; align-items: center; font-size: 0.9rem;
}

/* ---------- statistics ---------- */

/* Single hue for magnitude, validated against the dark panel surface. */
:root { --series: #1f8fd4; --series-muted: #5a646f; }

.stat-grid {
  display: grid; gap: 12px; margin-bottom: 22px;
  grid-template-columns: repeat(auto-fit, minmax(165px, 1fr));
}
.stat {
  background: var(--panel-2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 16px;
}
.stat .stat-value { font-size: 1.9rem; font-weight: 700; letter-spacing: -0.02em; line-height: 1.15; }
.stat .stat-label { color: var(--muted); font-size: 0.78rem; margin-top: 4px; line-height: 1.35; }
.stat .stat-note { color: var(--muted); font-size: 0.75rem; margin-top: 6px; opacity: 0.8; }
.stat.is-warning .stat-value { color: var(--warn); }

.bars { display: flex; flex-direction: column; gap: 3px; }
.bar-row {
  display: grid; grid-template-columns: minmax(120px, 190px) minmax(0, 1fr);
  gap: 12px; align-items: center; padding: 3px 0; border-radius: 6px;
}
.bar-row:hover { background: var(--panel-2); }
.bar-row .bar-name {
  font-size: 0.88rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.bar-row .bar-name .muted-tag { color: var(--muted); font-size: 0.75rem; margin-left: 6px; }
.bar-track { display: flex; align-items: center; gap: 9px; min-width: 0; }
.bar-fill {
  height: 15px;
  /* Rounded data-end only, so the bar stays anchored to its baseline. */
  border-radius: 0 4px 4px 0;
  background: var(--series);
  min-width: 2px;
}
.bar-row.is-inactive .bar-fill { background: var(--series-muted); }
.bar-value { font-size: 0.85rem; font-weight: 600; color: var(--fg); white-space: nowrap; }
.bar-row.is-zero .bar-value { color: var(--muted); font-weight: 500; }

/* The average marker gives every bar something to be read against. */
.bars-scale { position: relative; margin: 0 0 8px; height: 1px; }
.chart-note { color: var(--muted); font-size: 0.78rem; margin: 12px 0 0; display: flex; gap: 16px; flex-wrap: wrap; }
.chart-note .swatch { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; }

.segmented { display: inline-flex; gap: 4px; flex-wrap: wrap; align-items: center; }
.segmented button { padding: 5px 12px; font-size: 0.85rem; min-height: 0; }
.segmented-label { color: var(--muted); font-size: 0.8rem; margin-right: 4px; }

.list-toolbar {
  display: flex; gap: 16px; align-items: center; justify-content: space-between;
  flex-wrap: wrap; margin-bottom: 12px;
}
.segmented button.is-active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }

.week-people { color: var(--muted); }
.week-people strong { color: var(--fg); font-weight: 600; }

/* ---------- wall display ---------- */

body.screen { padding: clamp(10px, 1.2vw, 24px); min-height: 100vh; }
.screen-header { display: flex; justify-content: space-between; align-items: baseline;
  margin-bottom: clamp(10px, 1.2vw, 20px); flex-wrap: wrap; gap: 8px; }
.screen-header h1 { font-size: clamp(1.2rem, 1.6vw, 1.8rem); font-weight: 600; margin: 0;
  color: var(--muted); letter-spacing: 0.04em; text-transform: uppercase; }
.screen-date { color: var(--muted); font-size: clamp(1.2rem, 1.6vw, 1.8rem); }

.current {
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border: 1px solid var(--border); border-radius: 20px;
  padding: clamp(16px, 2vw, 32px) clamp(16px, 2vw, 32px) clamp(6px, 0.8vw, 14px);
  margin-bottom: clamp(16px, 2vw, 28px);
}
.current .label { color: var(--accent); font-size: clamp(1rem, 1.4vw, 1.4rem); text-transform: uppercase;
  letter-spacing: 0.12em; font-weight: 600; margin-bottom: 0.3em; text-align: center; }
.current .week { color: var(--muted); font-size: clamp(1rem, 1.4vw, 1.5rem); margin-bottom: 0.4em; text-align: center; }
.current .names { display: grid; grid-template-columns: 1fr 1fr; gap: clamp(10px, 1.2vw, 24px); }
.current .name {
  font-size: clamp(2rem, 4.5vw, 4.5rem); font-weight: 700; line-height: 1.3; letter-spacing: -0.02em;
  white-space: nowrap; min-width: 0; overflow: hidden; text-overflow: ellipsis;
  padding-bottom: 0.2em; text-align: center;
}
.current .name:only-child { grid-column: 1 / -1; }

.upcoming h2 { color: var(--muted); font-size: clamp(1rem, 1.3vw, 1.3rem); text-transform: uppercase;
  letter-spacing: 0.12em; font-weight: 600; margin: 0 0 clamp(8px, 1vw, 14px) 4px; }
#upcoming { column-count: 2; column-width: 640px; column-gap: clamp(8px, 1vw, 16px); }
.screen-row {
  display: grid; grid-template-columns: clamp(15em, 18vw, 21em) minmax(0, 1fr) minmax(0, 1fr);
  gap: clamp(14px, 1.6vw, 28px); align-items: center;
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: clamp(10px, 1.1vw, 14px) clamp(14px, 1.4vw, 20px);
  margin-bottom: clamp(6px, 0.7vw, 8px); break-inside: avoid;
}
.screen-row .when { color: var(--muted); font-size: clamp(1.1rem, 1.5vw, 1.6rem); font-weight: 500; white-space: nowrap; }
.screen-row .person { font-size: clamp(1.2rem, 1.7vw, 1.8rem); font-weight: 600;
  min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.screen-footer { color: var(--muted); font-size: 0.85rem; margin-top: 32px; text-align: right; opacity: 0.6; }

@media (max-width: 720px) {
  .current .names { grid-template-columns: 1fr; }
  .current .name { white-space: normal; }
  #upcoming { column-width: auto; columns: 1; }
  .screen-row { grid-template-columns: 1fr; gap: 4px; padding: 14px 18px; }
  .screen-row .person { font-size: 1.2rem; white-space: normal; overflow: visible; }
}

/* ---------- sign-in ---------- */

.signin-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.signin-card { width: min(400px, 100%); }
.divider { display: flex; align-items: center; gap: 12px; color: var(--muted);
  font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.1em; margin: 18px 0; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }

/* Per-row menu. The people list had six controls on every row, which made each row
   several lines tall; collapsing them behind one button keeps it to a single line. */
td.rowmenu { width: 1%; text-align: right; white-space: nowrap; }

details.menu { position: relative; display: inline-block; }

details.menu > summary {
  list-style: none;
  cursor: pointer;
  user-select: none;
  padding: 4px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--muted);
  line-height: 1.2;
}
details.menu > summary::-webkit-details-marker { display: none; }
details.menu > summary:hover { color: var(--fg); }
details.menu[open] > summary { background: var(--panel-2); color: var(--fg); }

details.menu > .menu-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 4px);
  z-index: 30;
  min-width: 210px;
  display: flex;
  flex-direction: column;
  padding: 4px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.45);
}

details.menu > .menu-panel button {
  width: 100%;
  text-align: left;
  background: none;
  border: 0;
  color: var(--fg);
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 0.85rem;
  cursor: pointer;
}
details.menu > .menu-panel button:hover { background: var(--panel); }
details.menu > .menu-panel button.danger { color: var(--danger); }
details.menu > .menu-panel hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 4px 2px;
}
