/*
  Design decisions (R-31):
  - Dark blue-gray base: requested by the owner; it also keeps a phone readable at night.
  - Blue (#5ea8ff) is the single action color: primary buttons, focus, links.
  - Cyan (#3fd6b4) only means "available / done": meters, filled team nodes, success.
  - System font stack: legible on every phone and needs no CDN, so the page works offline from external hosts.
  - Motif: the four-node team spine beside the member pickers, and 11-cell meters showing real counts.
  - Shadow only on the dialog and the open option list, the two layers that sit above the page.
*/

:root {
  --bg: #0d141d;
  --surface: #141e2a;
  --surface-raised: #1a2636;
  --line: #2b3b50;
  --line-strong: #5c7594;
  --text: #e8eef5;
  --muted: #a3b3c6;
  --blue: #5ea8ff;
  --on-blue: #07111d;
  --cyan: #3fd6b4;
  --danger-text: #ff9b94;
  --danger-bg: #b4342e;
  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: dark;
}

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

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 1rem;
  line-height: 1.5;
  min-height: 100vh;
}

a {
  color: var(--blue);
  text-underline-offset: 3px;
}

:focus-visible {
  outline: 3px solid var(--blue);
  outline-offset: 2px;
}

.skip-link {
  position: absolute;
  left: 1rem;
  top: -4rem;
  background: var(--blue);
  color: var(--on-blue);
  padding: 0.6rem 1rem;
  border-radius: var(--radius-sm);
  z-index: 10;
}

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

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.page {
  width: 100%;
  max-width: 44rem;
  margin: 0 auto;
  padding: 2rem 1rem 4rem;
}

.page--wide {
  max-width: 72rem;
}

/* Header */

.masthead {
  margin-bottom: 1.75rem;
}

.masthead__kicker {
  margin: 0 0 0.35rem;
  color: var(--cyan);
  font-weight: 600;
  font-size: 0.95rem;
}

.masthead h1 {
  margin: 0;
  font-size: clamp(1.75rem, 5vw, 2.4rem);
  line-height: 1.15;
  letter-spacing: -0.01em;
}

.masthead__lead {
  margin: 0.9rem 0 0;
  color: var(--muted);
  max-width: 38rem;
}

/* Counters: one row of three, each with an 11- or 44-cell meter from real data */

.counters {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.75rem;
  margin: 0 0 1.75rem;
  padding: 0;
  list-style: none;
}

.counter {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.85rem 0.9rem 0.9rem;
  min-width: 0;
}

.counter__label {
  display: block;
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1.3;
}

.counter__value {
  display: block;
  margin-top: 0.3rem;
  font-size: 1.45rem;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}

.counter__value small {
  color: var(--muted);
  font-weight: 500;
  font-size: 0.95rem;
}

.meter {
  display: grid;
  gap: 3px;
  margin-top: 0.6rem;
}

.meter--11 {
  grid-template-columns: repeat(11, 1fr);
}

.meter--44 {
  grid-template-columns: repeat(22, 1fr);
}

.meter span {
  height: 6px;
  border-radius: 2px;
  background: var(--line);
}

.meter span.is-on {
  background: var(--cyan);
}

/* Cards */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 1.5rem 1.25rem;
}

.card + .card {
  margin-top: 1rem;
}

.card h2 {
  margin: 0 0 0.35rem;
  font-size: 1.2rem;
}

.card__hint {
  margin: 0 0 1.25rem;
  color: var(--muted);
  font-size: 0.95rem;
}

/* Team spine: four linked nodes beside the member pickers */

.team {
  margin: 0;
  padding: 0;
  border: 0;
  min-width: 0;
}

.team legend {
  padding: 0;
  margin-bottom: 1rem;
  font-weight: 650;
  font-size: 1.05rem;
}

.slot {
  position: relative;
  padding: 0 0 1.25rem 2.5rem;
}

.slot::before {
  content: "";
  position: absolute;
  left: 0.8rem;
  top: 1.9rem;
  bottom: -0.2rem;
  width: 2px;
  background: var(--line);
}

.slot:last-of-type::before {
  display: none;
}

.slot.is-filled::before {
  background: var(--cyan);
}

.slot__node {
  position: absolute;
  left: 0;
  top: 0.05rem;
  width: 1.7rem;
  height: 1.7rem;
  border-radius: 50%;
  border: 2px solid var(--line-strong);
  background: var(--bg);
  color: var(--muted);
  display: grid;
  place-items: center;
  font-size: 0.8rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.slot.is-filled .slot__node {
  background: var(--cyan);
  border-color: var(--cyan);
  color: var(--on-blue);
}

.slot--lead .slot__node {
  width: 1.9rem;
  height: 1.9rem;
  left: -0.1rem;
}

.field-label {
  display: block;
  font-weight: 600;
  margin-bottom: 0.15rem;
}

.field-note {
  display: block;
  color: var(--muted);
  font-size: 0.875rem;
  margin-bottom: 0.45rem;
}

/* Combobox */

.combo {
  position: relative;
}

.combo__input,
.input {
  width: 100%;
  min-height: 48px;
  padding: 0.7rem 0.85rem;
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
}

.combo__input {
  padding-left: 2.5rem;
  padding-right: 2.75rem;
  text-transform: none;
}

.combo__input::placeholder,
.input::placeholder {
  color: var(--muted);
  opacity: 1;
}

.combo__input:focus-visible,
.input:focus-visible {
  outline: 3px solid var(--blue);
  outline-offset: 0;
  border-color: var(--blue);
}

.combo__icon {
  position: absolute;
  left: 0.8rem;
  top: 50%;
  width: 1.1rem;
  height: 1.1rem;
  transform: translateY(-50%);
  color: var(--muted);
  pointer-events: none;
}

.combo__clear {
  position: absolute;
  right: 2px;
  top: 2px;
  bottom: 2px;
  width: 44px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 1.25rem;
  cursor: pointer;
}

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

.combo.has-value .combo__input {
  border-color: var(--cyan);
  font-weight: 600;
}

.combo.is-invalid .combo__input {
  border-color: var(--danger-text);
}

.combo__list {
  position: absolute;
  z-index: 5;
  left: 0;
  right: 0;
  top: calc(100% + 4px);
  max-height: min(18rem, 50vh);
  overflow-y: auto;
  margin: 0;
  padding: 0.3rem;
  list-style: none;
  background: var(--surface-raised);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  box-shadow: 0 12px 28px rgb(0 0 0 / 0.45);
}

.combo__option {
  padding: 0.65rem 0.7rem;
  min-height: 44px;
  border-radius: 4px;
  cursor: pointer;
  overflow-wrap: anywhere;
}

.combo__option[aria-selected="true"],
.combo__option:hover {
  background: #23344a;
}

.combo__option[aria-selected="true"] {
  outline: 2px solid var(--blue);
  outline-offset: -2px;
}

.combo__option mark {
  background: none;
  color: var(--cyan);
  font-weight: 700;
}

.combo__empty {
  padding: 0.75rem;
  color: var(--muted);
}

.combo__chosen {
  margin: 0.4rem 0 0;
  color: var(--cyan);
  font-size: 0.9rem;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.field-error {
  margin: 0.45rem 0 0;
  color: var(--danger-text);
  font-size: 0.925rem;
}

.field-error:empty {
  display: none;
}

/* Topics as a radio list: every option visible at once, easy to tap */

.topics {
  margin: 1.5rem 0 0;
  padding: 1.25rem 0 0;
  border: 0;
  border-top: 1px solid var(--line);
  min-width: 0;
}

.topics legend {
  float: left;
  width: 100%;
  padding: 0;
  margin-bottom: 0.25rem;
  font-weight: 650;
  font-size: 1.05rem;
}

.topics .card__hint {
  clear: both;
}

.topic-list {
  display: grid;
  gap: 0.5rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.topic {
  position: relative;
}

.topic input {
  position: absolute;
  top: 0.9rem;
  left: 0.9rem;
  width: 1px;
  height: 1px;
  margin: 0;
  opacity: 0;
}

.topic label {
  display: flex;
  gap: 0.75rem;
  align-items: flex-start;
  min-height: 48px;
  padding: 0.75rem 0.85rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--bg);
  cursor: pointer;
}

.topic__num {
  flex: none;
  min-width: 1.6rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

.topic input:checked + label {
  border-color: var(--cyan);
  background: #12302d;
}

.topic input:checked + label .topic__num {
  color: var(--cyan);
}

.topic input:focus-visible + label {
  outline: 3px solid var(--blue);
  outline-offset: 2px;
}

.empty-note {
  color: var(--muted);
  padding: 0.75rem 0;
}

/* Buttons */

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: 1.5rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 48px;
  padding: 0.7rem 1.25rem;
  font: inherit;
  font-weight: 650;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
}

.btn[disabled],
.btn[aria-disabled="true"] {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn--primary {
  background: var(--blue);
  color: var(--on-blue);
}

.btn--primary:hover:not([disabled]) {
  background: #7ab8ff;
}

.btn--ghost {
  background: transparent;
  color: var(--text);
  border-color: var(--line-strong);
}

.btn--ghost:hover {
  background: var(--surface-raised);
}

.btn--danger {
  background: var(--danger-bg);
  color: #fff;
}

.btn--small {
  min-height: 44px;
  padding: 0.45rem 0.85rem;
  font-size: 0.925rem;
}

.btn--block {
  width: 100%;
}

/* Status and alerts */

.alert {
  border-radius: var(--radius);
  padding: 0.9rem 1rem;
  margin: 0 0 1.25rem;
  border: 1px solid var(--line-strong);
  background: var(--surface-raised);
}

.alert--error {
  border-color: var(--danger-text);
  color: var(--danger-text);
}

.alert--ok {
  border-color: var(--cyan);
}

.alert:empty {
  display: none;
}

.closed {
  text-align: left;
}

.closed p {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 600;
}

.closed .card__hint {
  margin-top: 0.5rem;
  font-weight: 400;
  font-size: 0.95rem;
}

.loading-note {
  color: var(--muted);
  font-size: 0.9rem;
  margin: 0.75rem 0 0;
  min-height: 1.4em;
}

/* Review dialog */

dialog {
  width: min(34rem, calc(100vw - 2rem));
  max-height: calc(100dvh - 2rem);
  overflow-y: auto;
  padding: 0;
  color: var(--text);
  background: var(--surface-raised);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-lg);
  box-shadow: 0 24px 60px rgb(0 0 0 / 0.55);
}

dialog::backdrop {
  background: rgb(4 8 13 / 0.78);
}

.dialog__body {
  padding: 1.5rem 1.25rem 1.25rem;
}

.dialog__body h2 {
  margin: 0 0 1rem;
  font-size: 1.25rem;
}

.summary {
  margin: 0;
}

.summary dt {
  color: var(--muted);
  font-size: 0.875rem;
  font-weight: 600;
  margin-top: 0.9rem;
}

.summary dt:first-child {
  margin-top: 0;
}

.summary dd {
  margin: 0.2rem 0 0;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.summary ol {
  margin: 0.2rem 0 0;
  padding-left: 1.25rem;
  font-weight: 600;
}

.summary li + li {
  margin-top: 0.15rem;
}

.dialog__warning {
  margin: 1.25rem 0 0;
  padding: 0.8rem 0.9rem;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
}

.dialog__actions {
  display: flex;
  flex-wrap: wrap-reverse;
  justify-content: flex-end;
  gap: 0.75rem;
  padding: 1rem 1.25rem 1.25rem;
  border-top: 1px solid var(--line);
}

/* Receipt */

.receipt__title {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin: 0 0 1.25rem;
  font-size: 1.4rem;
}

.receipt__check {
  flex: none;
  width: 2rem;
  height: 2rem;
  color: var(--cyan);
}

.receipt__note {
  margin: 1.5rem 0 0;
  color: var(--muted);
}

/* Access + login */

.narrow {
  max-width: 26rem;
  margin: 0 auto;
}

.form-row + .form-row {
  margin-top: 1rem;
}

/* Admin */

.admin-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.admin-bar h1 {
  margin: 0;
  font-size: 1.5rem;
}

.admin-bar form {
  margin: 0;
}

.state {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.state__label {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 600;
}

.state__value {
  font-weight: 800;
  letter-spacing: 0.02em;
}

.state__value--open {
  color: var(--cyan);
}

.state__value--closed {
  color: var(--danger-text);
}

.state form {
  margin: 0;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.925rem;
}

th,
td {
  text-align: left;
  vertical-align: top;
  padding: 0.7rem 0.75rem;
  border-bottom: 1px solid var(--line);
}

th {
  color: var(--muted);
  font-weight: 600;
  background: var(--surface-raised);
  white-space: nowrap;
}

tbody tr:last-child td {
  border-bottom: 0;
}

td ul {
  margin: 0;
  padding-left: 1rem;
}

.num {
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.section-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.section-head h2 {
  margin: 0;
}

.audit {
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 0.9rem;
}

.audit li {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 1rem;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--line);
}

.audit time {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.audit code {
  color: var(--text);
  font-weight: 600;
}

.audit span {
  color: var(--muted);
  overflow-wrap: anywhere;
}

.site-foot {
  margin-top: 2.5rem;
  color: var(--muted);
  font-size: 0.875rem;
}

@media (max-width: 540px) {
  .page {
    padding-top: 1.25rem;
  }

  .counters {
    gap: 0.5rem;
  }

  .counter {
    padding: 0.7rem 0.6rem;
  }

  .counter__value {
    font-size: 1.2rem;
  }

  .counter__label {
    font-size: 0.78rem;
  }

  .card {
    padding: 1.25rem 1rem;
  }

  .dialog__actions .btn,
  .actions .btn {
    flex: 1 1 100%;
  }

  .mobile-stack td {
    display: block;
    border-bottom: 0;
    padding: 0.35rem 0.75rem;
  }

  .mobile-stack thead {
    display: none;
  }

  .mobile-stack tr {
    display: block;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--line);
  }

  .mobile-stack td[data-label]::before {
    content: attr(data-label) ": ";
    color: var(--muted);
    font-weight: 600;
  }
}

@media (prefers-reduced-motion: no-preference) {
  .slot::before,
  .slot__node,
  .btn {
    transition: background-color 120ms ease, border-color 120ms ease;
  }
}

.counters--spaced {
  margin-top: 1rem;
}
