:root {
  color-scheme: light dark;
  --text: #1c1f24;
  --muted: #5b626e;
  --surface: #ffffff;
  --raised: #f5f7f9;
  --line: #d9dde3;
  --accent: #2c6bc7;
  --accent-text: #ffffff;
  --danger: #b3261e;
  --error: #b3261e;
  --live: #1e7a3c;
  --live-bg: #e3f4e8;
  --upcoming: #1d5bb8;
  --upcoming-bg: #e4eefb;
  --off: #5b626e;
  --off-bg: #eceef1;
  --soon-bg: #fff6e0;
  --held: #8a5a00;
  --held-bg: #fff1cc;
}

@media (prefers-color-scheme: dark) {
  :root {
    --text: #e8eaed;
    --muted: #a6adb8;
    --surface: #16181c;
    --raised: #1f2228;
    --line: #34383f;
    --accent: #3a7ad4;
    --danger: #f2b8b5;
    --error: #f2b8b5;
    --live: #8fd6a4;
    --live-bg: #183323;
    --upcoming: #9cc1f5;
    --upcoming-bg: #1a2a43;
    --off: #a6adb8;
    --off-bg: #2a2e35;
    --soon-bg: #3a3014;
    --held: #f3c969;
    --held-bg: #3a3014;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--text);
  background: var(--surface);
}

[hidden] {
  display: none !important;
}

h1 {
  margin: 0;
  font-size: 1.2rem;
}

h2 {
  margin: 0;
  font-size: 1.05rem;
}

h3 {
  margin: 0;
  font-size: 1rem;
}

.top {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
}

#account {
  display: flex;
  gap: 12px;
  align-items: center;
  color: var(--muted);
}

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

.sign-in {
  padding: 32px 0;
}

/* Controls */

button,
select,
input,
textarea {
  font: inherit;
  color: inherit;
}

button {
  padding: 7px 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  cursor: pointer;
}

button:hover:not(:disabled) {
  background: var(--raised);
}

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

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

button.primary:hover:not(:disabled) {
  background: var(--accent);
  filter: brightness(1.08);
}

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

button.small {
  padding: 3px 10px;
  font-size: 0.9em;
}

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

button:focus-visible,
select:focus-visible,
input:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

select,
input[type="text"],
input[type="date"],
input[type="month"],
input[type="email"],
input[type="number"],
input[type="url"],
textarea {
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
}

label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-weight: 500;
}

label.check {
  flex-direction: row;
  align-items: center;
  gap: 6px;
  font-weight: 400;
}

label.block textarea {
  width: 100%;
  resize: vertical;
}

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

/* Layout pieces */

.tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
}

.tabs button {
  border: none;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  background: none;
  color: var(--muted);
}

.tabs button[aria-selected="true"] {
  border-bottom-color: var(--accent);
  color: var(--text);
  font-weight: 600;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-bottom: 12px;
}

.toolbar label {
  flex-direction: row;
  align-items: center;
  gap: 8px;
}

.spacer {
  flex: 1;
}

.summary {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 20px;
  margin: 0 0 12px;
  padding: 0;
  list-style: none;
  color: var(--muted);
}

.summary strong {
  color: var(--text);
}

.section-head {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  margin: 20px 0 8px;
}

.hint,
.meta {
  margin: 4px 0;
  color: var(--muted);
  font-size: 0.92em;
}

.error {
  margin: 4px 0;
  color: var(--error);
}

.error:empty {
  display: none;
}

.empty {
  padding: 24px 0;
  color: var(--muted);
}

.code {
  color: var(--muted);
  font-size: 0.85em;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

/* Tables */

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-size: 0.85em;
  font-weight: 600;
}

.number {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.nowrap {
  white-space: nowrap;
}

td.actions {
  white-space: nowrap;
  text-align: right;
}

td.actions button + button {
  margin-left: 6px;
}

/* An order can have four buttons, so they wrap rather than widen the table.
   Phones stack the rows instead. */
@media (min-width: 601px) {
  #orders-table td.actions {
    min-width: 180px;
    white-space: normal;
  }

  #orders-table td.actions button {
    margin: 0 0 6px 6px;
  }
}

tr.ending-soon td {
  background: var(--soon-bg);
}

.status {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 0.85em;
  font-weight: 600;
  white-space: nowrap;
}

.status.live {
  color: var(--live);
  background: var(--live-bg);
}

.status.upcoming {
  color: var(--upcoming);
  background: var(--upcoming-bg);
}

.status.off,
.status.ended {
  color: var(--off);
  background: var(--off-bg);
}

.status.held {
  color: var(--held);
  background: var(--held-bg);
}

.notice {
  margin: 0 0 12px;
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--soon-bg);
}

/* Brands */

.brand-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 12px;
}

.brand-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
}

.brand-card.archived {
  opacity: 0.75;
}

.brand-card h3 {
  display: flex;
  gap: 8px;
  align-items: center;
}

.brand-card .meta,
.brand-card .detail {
  margin: 0;
  overflow-wrap: anywhere;
}

.brand-card .notes {
  white-space: pre-line;
}

.brand-card .label {
  color: var(--muted);
}

.brand-card .with-action {
  display: flex;
  gap: 8px;
  align-items: baseline;
  justify-content: space-between;
}

.brand-card .with-action > span {
  min-width: 0;
}

.brand-card .with-action button {
  flex-shrink: 0;
}

.brand-card .actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: auto;
  padding-top: 6px;
}

/* A checked backdrop shows where a logo is transparent */
.logo-box {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 72px;
  border-radius: 6px;
  background: repeating-conic-gradient(#e6e8eb 0 25%, #ffffff 0 50%) 0 0 / 16px 16px;
}

.logo-box img {
  max-width: 90%;
  max-height: 48px;
}

/* Dialogs */

dialog {
  width: min(560px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--text);
  background: var(--surface);
}

dialog.wide {
  width: min(820px, calc(100vw - 32px));
}

dialog::backdrop {
  background: rgb(0 0 0 / 45%);
}

dialog form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

dialog h2 {
  margin-bottom: 4px;
}

.fields {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.fields label {
  flex: 1 1 200px;
}

.dialog-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 8px;
}

pre.summary {
  display: block;
  margin: 8px 0;
  padding: 12px;
  border-radius: 8px;
  background: var(--raised);
  white-space: pre-wrap;
  font: inherit;
}

/* Fieldsets won't shrink below their content unless told to */
fieldset {
  min-width: 0;
}

.logo-field {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

/* Station pickers */

.stations {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}

.stations.single {
  grid-template-columns: 1fr;
}

.stations fieldset {
  margin: 0;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.stations fieldset.red legend {
  color: #d0342c;
}

.stations fieldset.blue legend {
  color: #2c6bc7;
}

.stations fieldset.green legend {
  color: #2e8b57;
}

.station-choice {
  flex-direction: row;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 2px 8px;
  padding: 2px 0;
  font-weight: 400;
}

.station-choice .held {
  flex-basis: 100%;
  padding-left: 22px;
  color: var(--muted);
  font-size: 0.85em;
}

.station-choice .held:empty {
  display: none;
}

/* Previews in the app's own colours, at the sizes phones draw them */

.previews {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
}

.preview {
  display: flex;
  flex: 1 1 340px;
  flex-direction: column;
  gap: 10px;
  margin: 0;
}

.preview figcaption {
  color: var(--muted);
  font-size: 0.85em;
}

.screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px 24px;
  border-radius: 12px;
  text-align: center;
}

.screen.arrival {
  min-height: 210px;
}

.preview.light .screen {
  background: linear-gradient(#f5f7f9, #eff6ff, #f5f7f9);
}

.preview.dark .screen {
  background: linear-gradient(#121212, #1a2638, #121212);
}

.plate {
  display: inline-flex;
}

.preview.dark .plate {
  padding: 2px 4px;
  border-radius: 8px;
  background: #ffffff;
}

.screen.arrival .preview-logo {
  max-width: 100%;
  max-height: 128px;
}

.screen.interchange .preview-logo {
  max-width: 256px;
  max-height: 64px;
}

.preview-sponsor {
  margin: 4px 0 0;
  font-size: 14px;
}

.preview.light .preview-sponsor {
  color: #6b7280;
}

.preview.dark .preview-sponsor {
  color: #b8b8b8;
}

.preview-card {
  margin: 0;
  padding: 14px 25px;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 600;
}

.preview.light .preview-card {
  border: 1px solid #e5e7eb;
  color: #1f2937;
  background: #ffffff;
}

.preview.dark .preview-card {
  border: 1px solid #2f3742;
  color: #e8e8e8;
  background: #222830;
}

/* Activity */

.activity {
  margin: 0 0 12px;
  padding: 0;
  list-style: none;
}

.activity li {
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}

.activity-head {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
  align-items: baseline;
}

.activity-head .meta {
  margin: 0;
}

.activity pre.summary {
  margin: 6px 0 0;
  padding: 8px 10px;
}

@media (max-width: 600px) {
  main {
    padding: 12px;
  }

  dialog {
    padding: 16px;
  }

  .toolbar .spacer {
    display: none;
  }

  /* Each booking becomes a block, so its buttons stay on screen */
  #bookings-table thead {
    display: none;
  }

  #bookings-table,
  #bookings-table tbody,
  #bookings-table tr,
  #bookings-table td {
    display: block;
  }

  #bookings-table tr {
    padding: 10px 8px;
    border-bottom: 1px solid var(--line);
  }

  #bookings-table td {
    padding: 2px 0;
    border: none;
    text-align: left;
  }

  #bookings-table td.number:empty {
    display: none;
  }

  #bookings-table td.number::before {
    content: "Days left ";
    color: var(--muted);
  }

  #bookings-table td.actions {
    padding-top: 6px;
    white-space: normal;
  }

  #bookings-table td.actions button {
    margin: 0 6px 6px 0;
  }

  /* Other tables that turn each row into a block on phones */
  table.stack thead {
    display: none;
  }

  table.stack,
  table.stack tbody,
  table.stack tr,
  table.stack td {
    display: block;
  }

  table.stack tr {
    padding: 10px 8px;
    border-bottom: 1px solid var(--line);
  }

  table.stack td {
    padding: 2px 0;
    border: none;
    text-align: left;
  }

  table.stack td.number:empty {
    display: none;
  }

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

  table.stack td.actions {
    padding-top: 6px;
    white-space: normal;
  }

  table.stack td.actions button {
    margin: 0 6px 6px 0;
  }
}
