:root {
  color-scheme: light dark;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial,
    sans-serif;

  --bg: #f7f7f5;
  --panel: #ffffff;
  --panel-2: #f1f1ee;
  --text: #1b1b19;
  --muted: #64645f;
  --faint: #8a8a84;

  --line: #cfcfc9;
  --line-soft: #e5e5e0;

  --accent: #2c5c8f;
  --accent-hover: #244d79;
  --on-accent: #ffffff;
  --focus: #2c5c8f;

  /* Heat levels: red is only ever "no room". Level 0 also carries a hatch
     pattern, so identity never rests on hue alone. */
  --heat-0: #efdad7;
  --heat-1: #e3f2da;
  --heat-2: #b6dd9f;
  --heat-3: #74bb55;

  --free: #dcecd9;
  --free-strong: #b9d8b4;

  --amber-bg: #f8eed8;
  --amber-line: #e2c894;
  --amber-text: #6f4a00;

  --ok-bg: #e2f1df;
  --ok-line: #b9d8b4;
  --ok-text: #23592c;

  --pending-bg: #f8ecd2;
  --pending-line: #e3cfa1;
  --pending-text: #6f4a00;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141517;
    --panel: #1b1d1f;
    --panel-2: #242629;
    --text: #e7e7e3;
    --muted: #a3a49f;
    --faint: #85867f;

    --line: #3a3d40;
    --line-soft: #2a2d30;

    --accent: #7fb2e3;
    --accent-hover: #97c2ec;
    --on-accent: #10151a;
    --focus: #8cc0f0;

    --heat-0: #2a1213;
    --heat-1: #1f3a1f;
    --heat-2: #327a35;
    --heat-3: #66b453;

    --free: #1e3224;
    --free-strong: #2f5238;

    --amber-bg: #332913;
    --amber-line: #5a4a24;
    --amber-text: #e6c07a;

    --ok-bg: #1f3a26;
    --ok-line: #2f5238;
    --ok-text: #9fd6a8;

    --pending-bg: #3c3016;
    --pending-line: #5a4a24;
    --pending-text: #e6c07a;
  }
}

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

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

body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.4;
  background: var(--bg);
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

[hidden] {
  display: none !important;
}

h1,
h2,
h3,
p {
  margin: 0;
}

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

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

.wrap {
  width: 100%;
  max-width: 1180px;
  margin: 0 auto;
  padding-left: 20px;
  padding-right: 20px;
}

.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;
}

/* Header */

.topbar {
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 52px;
}

.brand {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.topbar-right {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  min-width: 0;
}

.account {
  font-size: 12.5px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

main.wrap {
  padding-bottom: 56px;
}

/* Buttons and fields */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 30px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--panel);
  color: var(--text);
  font-size: 13px;
  line-height: 1;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
}

.btn:hover:not(:disabled) {
  background: var(--panel-2);
}

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

.btn.primary:hover:not(:disabled) {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--panel);
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
}

.icon-btn:hover:not(:disabled) {
  background: var(--panel-2);
}

.icon-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

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

input[type="date"],
input[type="datetime-local"],
input[type="email"],
input[type="password"],
input[type="text"],
select {
  height: 30px;
  min-width: 0;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--panel);
  font-size: 13px;
}

input[type="date"]:focus-visible,
input[type="datetime-local"]:focus-visible,
input[type="email"]:focus-visible,
input[type="password"]:focus-visible,
input[type="text"]:focus-visible,
select:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 1px;
}

input:disabled,
select:disabled {
  opacity: 0.6;
}

input[type="checkbox"] {
  accent-color: var(--accent);
}

/* Banner */

.banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 16px;
  padding: 8px 12px;
  border: 1px solid var(--amber-line);
  border-radius: 4px;
  background: var(--amber-bg);
  color: var(--amber-text);
  font-size: 13px;
}

/* Regions */

.region {
  margin-top: 22px;
}

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

.region h2 {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.weeknav {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.week-label {
  display: inline-block;
  min-width: 116px;
  text-align: center;
  font-size: 13px;
  white-space: nowrap;
}

/* Legend */

.legend {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 8px;
  font-size: 11.5px;
  color: var(--muted);
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.swatch {
  display: inline-block;
  width: 12px;
  height: 12px;
  border: 1px solid var(--line);
  border-radius: 2px;
}

.swatch.lv0 {
  background: var(--heat-0);
}

.swatch.lv1 {
  background: var(--heat-1);
}

.swatch.lv2 {
  background: var(--heat-2);
}

.swatch.lv3 {
  background: var(--heat-3);
}

/* Heatmap */

.heat-wrap {
  overflow-x: auto;
  overflow-y: hidden;
}

.heatmap {
  min-height: 96px;
}

.grid-state {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
  padding: 22px;
}

.grid-state p {
  font-size: 13px;
}

.heat-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

.heat-table col.day-col {
  width: 176px;
}

.heat-table th,
.heat-table td {
  padding: 0;
  border-bottom: 1px solid var(--line-soft);
  border-right: 1px solid var(--line-soft);
}

.heat-table th:last-child,
.heat-table td:last-child {
  border-right: none;
}

.heat-table tbody tr:last-child th,
.heat-table tbody tr:last-child td {
  border-bottom: none;
}

.heat-table thead th {
  height: 22px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  font-size: 9.5px;
  font-weight: 500;
  color: var(--faint);
  text-align: center;
  vertical-align: middle;
  white-space: nowrap;
}

.heat-table thead th.heat-corner {
  border-right: 1px solid var(--line);
}

.heat-day {
  height: 33px;
  padding: 0 10px;
  background: var(--panel);
  border-right: 1px solid var(--line) !important;
  text-align: left;
  vertical-align: middle;
  font-size: 12.5px;
  font-weight: 500;
  white-space: nowrap;
}

.heat-day .day-name {
  color: var(--text);
}

.heat-day .day-dot,
.heat-day .day-hours {
  color: var(--muted);
  font-weight: 400;
}

.heat-cell-td {
  padding: 0;
}

.heat-cell {
  display: block;
  width: 100%;
  height: 33px;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: var(--panel-2);
  cursor: pointer;
}

.heat-cell.lv0 {
  background-color: var(--heat-0);
  background-image: repeating-linear-gradient(
    45deg,
    rgba(0, 0, 0, 0.22) 0 2px,
    transparent 2px 5px
  );
}

.heat-cell.lv1 {
  background: var(--heat-1);
}

.heat-cell.lv2 {
  background: var(--heat-2);
}

.heat-cell.lv3 {
  background: var(--heat-3);
}

@media (prefers-color-scheme: dark) {
  .heat-cell.lv0 {
    background-image: repeating-linear-gradient(
      45deg,
      rgba(255, 255, 255, 0.14) 0 2px,
      transparent 2px 5px
    );
  }
}

.heat-cell:hover {
  box-shadow: inset 0 0 0 1px var(--text);
}

.heat-cell:focus-visible {
  outline: none;
  box-shadow: inset 0 0 0 2px var(--focus);
}

.heat-cell.sel {
  box-shadow: inset 0 0 0 2px var(--accent);
}

.heat-summary {
  min-height: 18px;
  margin-top: 8px;
  font-size: 12.5px;
  color: var(--muted);
}

/* Plan form */

.card {
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--panel);
}

.plan-form {
  padding: 12px 14px;
}

.plan-controls {
  display: grid;
  grid-template-columns: minmax(170px, 190px) minmax(170px, 190px) 150px auto;
  gap: 10px;
  align-items: end;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.field > span {
  font-size: 10.5px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
}

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

.plan-submit {
  justify-self: start;
}

.plan-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 10px;
}

.plan-hint {
  font-size: 11.5px;
  color: var(--faint);
}

.error {
  font-size: 12.5px;
  color: var(--amber-text);
}

.plan-error {
  margin-top: 10px;
}

/* Plan card */

.plan-card {
  margin-top: 12px;
}

.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}

.card-title {
  font-size: 14px;
  font-weight: 600;
  line-height: 1.35;
}

.card-actions {
  display: flex;
  gap: 8px;
}

.card-body {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 12px 14px;
}

.plan-reason {
  font-size: 13px;
}

.gap-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.gap-list p {
  font-size: 13px;
}

.block-caption {
  font-size: 10.5px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
}

.plan-shifts {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.muted {
  color: var(--muted);
  font-size: 13px;
}

/* Data tables */

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.data-table th {
  padding: 0 8px 5px 0;
  border-bottom: 1px solid var(--line);
  font-size: 10.5px;
  font-weight: 500;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
  text-align: left;
  white-space: nowrap;
}

.data-table td {
  padding: 6px 8px 6px 0;
  border-bottom: 1px solid var(--line-soft);
  vertical-align: top;
}

.data-table tfoot td {
  padding-top: 6px;
  border-top: 1px solid var(--line);
  border-bottom: none;
  font-weight: 600;
}

.data-table .col-index {
  width: 28px;
  color: var(--muted);
}

.col-duration {
  text-align: right;
  white-space: nowrap;
}

.data-table th.col-duration {
  text-align: right;
}

.data-table td:last-child,
.data-table th:last-child {
  padding-right: 0;
}

.plan-table td.col-room {
  width: 44%;
  min-width: 170px;
}

.room-select {
  width: 100%;
  max-width: 300px;
}

.room-fit {
  display: block;
  margin-top: 3px;
  font-size: 11px;
  line-height: 1.3;
  color: var(--faint);
}

.plan-unbooked {
  display: block;
  margin-top: 2px;
  font-size: 12px;
  font-weight: 400;
  color: var(--muted);
}

/* Status chips */

.chip {
  display: inline-block;
  padding: 0 6px;
  border: 1px solid var(--line);
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  line-height: 18px;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.chip.booked {
  background: var(--ok-bg);
  border-color: var(--ok-line);
  color: var(--ok-text);
}

.chip.pending,
.chip.declined {
  background: var(--pending-bg);
  border-color: var(--pending-line);
  color: var(--pending-text);
}

.chip.failed {
  background: var(--panel-2);
  border-color: var(--line);
  color: var(--muted);
}

.status-cell {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 3px;
}

.status-detail {
  font-size: 12px;
  color: var(--muted);
}

/* Dialog */

dialog.modal {
  width: min(700px, calc(100vw - 32px));
  max-height: min(86vh, 780px);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--panel);
  color: var(--text);
}

dialog.modal:not([open]) {
  display: none;
}

dialog.modal::backdrop {
  background: rgba(16, 17, 18, 0.42);
}

dialog.rooms-modal {
  width: min(780px, calc(100vw - 32px));
}

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

.modal-head h2 {
  font-size: 15px;
  font-weight: 600;
}

.modal-body {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: calc(86vh - 120px);
  padding: 14px;
  overflow: auto;
}

.modal-foot {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
  padding: 10px 14px;
  border-top: 1px solid var(--line);
}

.progress {
  margin-right: auto;
  font-size: 12.5px;
  color: var(--muted);
}

.title-field input {
  max-width: 100%;
}

.warning {
  padding: 7px 9px;
  border: 1px solid var(--amber-line);
  border-radius: 4px;
  background: var(--amber-bg);
  color: var(--amber-text);
  font-size: 12.5px;
}

.note {
  font-size: 12.5px;
  color: var(--muted);
}

.long-booking {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--amber-line);
  border-radius: 4px;
  background: var(--amber-bg);
  color: var(--amber-text);
  font-size: 12.5px;
}

.long-booking-code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-weight: 600;
}

.long-booking-field > span {
  color: var(--amber-text);
}

.retry-block {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.retry-block h3 {
  font-size: 13px;
  font-weight: 600;
}

.retry-block .btn {
  align-self: flex-start;
}

/* Rooms dialog */

.rooms-list {
  border-top: 1px solid var(--line);
}

.room-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  min-height: 34px;
  padding: 5px 2px;
  border-bottom: 1px solid var(--line-soft);
  font-size: 13px;
}

.room-row-name {
  flex: 1 1 220px;
  min-width: 0;
  overflow-wrap: anywhere;
}

.room-capacity {
  min-width: 24px;
  color: var(--muted);
  font-size: 12px;
  text-align: right;
}

.tag {
  display: inline-block;
  padding: 0 5px;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: var(--panel-2);
  color: var(--muted);
  font-size: 10px;
  line-height: 16px;
  letter-spacing: 0.04em;
  text-transform: lowercase;
  white-space: nowrap;
}

.tag-not-bookable {
  border-color: var(--amber-line);
  background: var(--amber-bg);
  color: var(--amber-text);
}

/* Login */

.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 340px;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--panel);
}

.login-card h1 {
  margin-bottom: 16px;
  font-size: 15px;
  font-weight: 600;
}

.login-card form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.login-card .btn {
  width: 100%;
}

/* Small screens */

@media (max-width: 860px) {
  .plan-controls {
    grid-template-columns: 1fr 1fr;
  }

  .plan-submit {
    grid-column: 1 / -1;
  }

  .heat-table col.day-col {
    width: 132px;
  }
}

@media (max-width: 640px) {
  .wrap {
    padding-left: 14px;
    padding-right: 14px;
  }

  .topbar-inner {
    padding-top: 8px;
    padding-bottom: 8px;
    flex-wrap: wrap;
  }

  .heat-table col.day-col {
    width: 86px;
  }

  .heat-table thead th {
    font-size: 8.5px;
  }

  /* Show an hour label only every two hours. */
  .heat-hour.h-even {
    visibility: hidden;
  }

  .heat-table thead th.heat-hour:nth-child(4n + 2) {
    visibility: visible;
  }

  .heat-day {
    padding: 0 6px;
    font-size: 11px;
  }

  .heat-day .day-dot,
  .heat-day .day-hours {
    display: none;
  }

  .heat-cell {
    height: 28px;
  }

  .heat-day {
    height: 28px;
  }

  .heat-summary {
    font-size: 12px;
  }

  .plan-controls {
    grid-template-columns: 1fr;
  }

  .plan-submit {
    justify-self: start;
  }
}
