:root {
  --bg: #0f172a;
  --panel: #1e293b;
  --panel-2: #273449;
  --border: #334155;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --accent: #38bdf8;
  --accent-ink: #04283a;
  --green: #22c55e;
  --red: #ef4444;
  --amber: #f59e0b;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

#topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  padding-top: max(10px, env(safe-area-inset-top));
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; }
#nav { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
#nav a {
  color: var(--muted);
  text-decoration: none;
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 14px;
}
#nav a.active { color: var(--text); background: var(--panel-2); }
.linkbtn { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 14px; }

main { padding: 16px; max-width: 900px; margin: 0 auto; }

h1 { font-size: 20px; margin: 4px 0 16px; }
h2 { font-size: 16px; margin: 20px 0 10px; color: var(--muted); font-weight: 600; }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 12px;
}

.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spread { justify-content: space-between; }
.muted { color: var(--muted); font-size: 13px; }

label { display: block; font-size: 13px; color: var(--muted); margin: 10px 0 4px; }
input, select {
  width: 100%;
  padding: 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  font-size: 15px;
}

button.btn {
  padding: 10px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
}
button.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
button.btn.danger { color: var(--red); }
button.btn:disabled { opacity: 0.5; cursor: default; }

.chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; font-size: 12px; background: var(--panel-2); }
.dot { width: 8px; height: 8px; border-radius: 50%; }
.dot.ok { background: var(--green); }
.dot.bad { background: var(--red); }
.dot.unknown { background: var(--muted); }

.banner { border-radius: 10px; padding: 10px 12px; margin-bottom: 14px; font-size: 14px; }
.banner.warn { background: #422006; border: 1px solid var(--amber); color: #fde68a; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 600; }

.slotgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px; }
.slot {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px;
  text-align: center;
  font-size: 13px;
  background: var(--panel-2);
}
.slot.free { border-color: var(--green); }
.slot.booked { opacity: 0.45; }
.slot .t { font-weight: 600; }
.slot button { margin-top: 6px; width: 100%; }

.center { min-height: 70vh; display: flex; align-items: center; justify-content: center; }
.login-card { width: 100%; max-width: 360px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 16px;
  font-size: 14px;
  max-width: 90vw;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
  z-index: 100;
}
.toast.ok { border-color: var(--green); }
.toast.err { border-color: var(--red); }

.modal-back {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px;
  max-width: 380px;
  width: 100%;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
}
.modal p { margin: 0; white-space: pre-line; }

.pillbtns { display: flex; gap: 6px; }
.pillbtns button { flex: 1; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg button { background: var(--panel-2); border: none; color: var(--muted); padding: 8px 12px; cursor: pointer; }
.seg button.active { background: var(--accent); color: var(--accent-ink); }
.spin { color: var(--muted); padding: 20px; text-align: center; }

/* ---- Landing page: status, quick-action tiles, rule summary ---- */
.card.status .dot { width: 10px; height: 10px; margin-right: 6px; display: inline-block; }

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
  margin-bottom: 20px;
}
.tile {
  display: block;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--panel);
  text-decoration: none;
  color: var(--text);
}
.tile:hover { border-color: var(--accent); }
.tile b { display: block; font-size: 15px; margin-bottom: 4px; }
.tile span { color: var(--muted); font-size: 13px; }

.daysub { font-size: 13px; color: var(--muted); margin: 14px 0 8px; font-weight: 600; }
ul.rules { margin: 0; padding-left: 18px; font-size: 14px; }
ul.rules li { margin-bottom: 4px; }

/* ---- Reservation grid (courts x time), mirroring how the venues' own sites look ---- */
.gridwrap {
  overflow-x: auto;               /* the grid scrolls, never the page */
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--panel);
  padding: 6px;
  width: fit-content;             /* no dead space to the right of a narrow grid */
  max-width: 100%;
}
/* border-spacing (not borders) makes each slot read as its own tile, the way the venues' own
   grids look — a 1px border in the background colour just vanishes on the green cells. */
table.grid { border-collapse: separate; border-spacing: 2px; font-size: 12px; width: max-content; }
table.grid th, table.grid td { border: none; padding: 0; }

table.grid .hourhead {
  text-align: center;
  font-weight: 700;
  color: var(--text);
  padding: 5px 0;
  background: var(--panel-2);
  border-radius: 3px;
}
table.grid .minhead {
  text-align: center;
  color: var(--muted);
  font-weight: 500;
  font-size: 10px;
  padding: 3px 0;
  background: var(--panel-2);
  border-radius: 3px;
}
/* Court name stays visible while the times scroll sideways. */
table.grid .courthead {
  position: sticky;
  left: 0;
  z-index: 2;
  background: var(--panel);       /* matches the wrapper so scrolled cells slide under it */
  color: var(--text);
  font-weight: 600;
  text-align: left;
  padding: 0 12px 0 4px;
  white-space: nowrap;
}
table.grid .corner { position: sticky; left: 0; z-index: 3; background: var(--panel); }

.cell {
  width: 32px;
  height: 32px;
  border-radius: 3px;
  background: #39465a;            /* taken / no data */
}
.cell.free { background: #86e01e; }              /* venue-style green */
.cell.free.bookable { cursor: pointer; }
.cell.free.bookable:hover { background: #a5f04a; }
/* Already-started slots are neither free nor worth scanning, so they drop out of the colour
   language entirely — otherwise an evening view is one big dim-green blob of dead time. */
.cell.past, .cell.free.past { background: #232b38; }
/* Marks the half-hours that can start a whole hour — the only ones worth clicking. */
.cell.bookable { box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.55); }

.daytabs { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; }
.daytab {
  flex: 0 0 auto;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--muted);
  border-radius: 10px;
  padding: 8px 10px;
  cursor: pointer;
  font-size: 13px;
  line-height: 1.25;
  text-align: center;
}
.daytab.active { border-color: var(--accent); color: var(--text); background: #0b3446; }
.daytab b { display: block; font-size: 14px; }
.daytab .cnt { font-size: 11px; }

.legend { display: flex; gap: 14px; align-items: center; margin: 10px 2px; font-size: 12px; color: var(--muted); }
.legend i { display: inline-block; width: 14px; height: 14px; border-radius: 3px; vertical-align: -2px; margin-right: 5px; }

/* Multi-select checkbox rows (courts, weekdays) — tap targets sized for a phone. */
.checks { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; }
.check {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 0;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--panel-2);
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
  user-select: none;
}
.check input { width: auto; margin: 0; accent-color: var(--accent); }
.check:has(input:checked) { border-color: var(--accent); background: #0b3446; }
