@import url('https://fonts.googleapis.com/css2?family=Fraunces:wght@500;600;700&family=Inter:wght@400;500;600&family=IBM+Plex+Mono:wght@500&display=swap');

/* ---- Theming ----
   Colours are all variables so the whole interface can be re-skinned. Extra variables
   below (--muted, --surface-*, --tint-*) exist because a lot of colours used to be
   written inline; they'd have stayed light-on-light in dark mode. */
:root, [data-theme="light"] {
  --pine: #1E3A2B;
  --pine-light: #2C5540;
  --bark: #4A3728;
  --canvas: #EDE6D6;
  --canvas-light: #F7F3E9;
  --amber: #C68E17;
  --ember: #B5482C;
  --ink: #201C16;
  --line: #D9CFB8;
  --radius: 6px;

  --muted: #4A3728;          /* secondary text */
  --surface: #F7F3E9;        /* cards */
  --surface-alt: #E1DCC3;    /* hover, table stripes */
  --surface-sunken: #EDE6D6;
  --tint-good: #DCE9DD;      /* soft green background */
  --tint-warn: #F2E3C6;      /* soft amber background */
  --tint-bad: #FBEAE5;       /* soft red background */
  --on-accent: #F7F3E9;      /* text on a dark accent */
  --shadow: rgba(0,0,0,0.15);

  /* Site map illustration */
  --map-grass: #8FB56E;
  --map-grass-edge: #A8C78A;
  --map-path: #F7F4EC;
  --map-building: #C79E6B;
  --map-roof: #B08652;
  --map-tree-dark: #3E5A30;
  --map-tree-mid: #5E8244;
  --map-tree-light: #7FA75E;
  --map-label: #2A2116;
  --map-label-halo: #ffffff;

  --banner: #1E3A2B;         /* header background — always a deep colour */
  --on-banner: #F7F3E9;      /* text on the banner */
  --on-banner-muted: #A9BFAE;

  /* Chart bar colours — must stay clearly distinct from each other in both themes */
  --chart-paid: #2C5540;
  --chart-owing: #C68E17;
  --chart-overdue: #B5482C;
  --chart-unconfirmed: #7A8B99;
  --chart-pending: #7A6C9E;
  --chart-external: #4A6B7C;
  --chart-blocked-a: #D6D2C4;
  --chart-blocked-b: #C4BFAF;
  --chart-text: #ffffff;
}

/* Dark theme. Deliberately warm charcoal rather than pure black — this gets used at a
   reception desk at night, and pure black on a bright screen is harsh to read for long. */
[data-theme="dark"] {
  --pine: #7FB08F;           /* headings/accents must be light in dark mode to stay legible */
  --pine-light: #6FA37F;
  --bark: #B8AC9A;
  --canvas: #17150F;
  --canvas-light: #221F17;
  --amber: #E0A93A;
  --ember: #E2705A;
  --ink: #EDE6D6;
  --line: #3A352A;

  --muted: #A69B89;
  --surface: #221F17;
  --surface-alt: #2E2A20;
  --surface-sunken: #1B180F;
  --tint-good: #1F3327;
  --tint-warn: #3A2F14;
  --tint-bad: #3A211C;
  --on-accent: #17150F;
  --shadow: rgba(0,0,0,0.5);

  --map-grass: #2F4033;
  --map-grass-edge: #364A38;
  --map-path: #4A4639;
  --map-building: #6E5940;
  --map-roof: #5A4733;
  --map-tree-dark: #1B2619;
  --map-tree-mid: #263626;
  --map-tree-light: #324630;
  --map-label: #EDE6D6;
  --map-label-halo: #14201A;

  --banner: #14261C;         /* stays deep in dark mode, just darker still */
  --on-banner: #EDE6D6;
  --on-banner-muted: #8FA894;

  /* Lighter, less saturated versions — full-strength colours glow uncomfortably on dark */
  --chart-paid: #4E8A66;
  --chart-owing: #C9922B;
  --chart-overdue: #C25940;
  --chart-unconfirmed: #6C8093;
  --chart-pending: #7E70A2;
  --chart-external: #4E7488;
  --chart-blocked-a: #3A352A;
  --chart-blocked-b: #2E2A20;
  --chart-text: #F5F1E6;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--canvas);
  color: var(--ink);
  font-family: 'Inter', sans-serif;
  font-size: 16px;
  line-height: 1.5;
}

h1, h2, h3 { font-family: 'Fraunces', serif; font-weight: 600; margin: 0 0 0.4em; color: var(--pine); }
h1 { font-size: 2rem; }
h2 { font-size: 1.4rem; }
h3 { font-size: 1.1rem; }

.mono { font-family: 'IBM Plex Mono', monospace; }

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

/* Contour-line header motif — a nod to site maps rather than decoration for its own sake */
header.topbar {
  background: var(--banner);
  color: var(--on-banner);
  padding: 1.4rem 1.5rem 2.2rem;
  position: relative;
  overflow: hidden;
}
header.topbar h1 { color: var(--on-banner); font-size: 1.5rem; margin: 0; }
header.topbar .subtitle { color: var(--on-banner-muted); font-size: 0.9rem; margin-top: 0.2rem; }
header.topbar::after {
  content: '';
  position: absolute;
  left: 0; right: 0; bottom: -1px;
  height: 18px;
  background-image:
    repeating-linear-gradient(to right, transparent 0 22px, rgba(237,230,214,0.35) 22px 23px),
    linear-gradient(to bottom, transparent, var(--canvas) 95%);
  opacity: 0.5;
}

.wrap { max-width: 960px; margin: 0 auto; padding: 1.5rem; }

.card {
  background: var(--canvas-light);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1rem;
}

.site-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 1rem; }
.site-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem;
  background: var(--canvas-light);
  cursor: pointer;
  transition: border-color 0.15s ease, transform 0.1s ease;
}
.site-card:hover { border-color: var(--amber); }
.site-card.selected { border-color: var(--amber); box-shadow: 0 0 0 2px var(--amber) inset; }
.site-card .type-tag {
  display: inline-block;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--pine);
  background: var(--surface-alt);
  padding: 0.15rem 0.5rem;
  border-radius: 100px;
  margin-bottom: 0.5rem;
}
.site-card .price { font-family: 'IBM Plex Mono', monospace; font-weight: 500; color: var(--bark); margin-top: 0.5rem; }

label { display: block; font-size: 0.85rem; font-weight: 500; margin: 0.75rem 0 0.3rem; color: var(--bark); }
input, select, textarea {
  width: 100%;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-family: 'Inter', sans-serif;
  font-size: 0.95rem;
  background: #fff;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--amber); outline-offset: 1px; }

button.btn {
  background: var(--amber);
  /* Fixed dark text, not var(--ink): the button is amber in BOTH themes, so flipping the
     text colour with the theme made it light-on-amber and unreadable in dark mode. */
  color: #201C16;
  border: none;
  padding: 0.7rem 1.3rem;
  border-radius: var(--radius);
  font-weight: 600;
  cursor: pointer;
  font-size: 0.95rem;
}
button.btn:hover { background: var(--amber); }
button.btn:disabled { background: var(--line); color: var(--muted); cursor: not-allowed; }
button.btn.secondary { background: transparent; border: 1px solid var(--pine); color: var(--pine); }
button.btn.danger { background: var(--ember); color: #fff; }

.price-summary { border-top: 1px dashed var(--line); margin-top: 1rem; padding-top: 0.75rem; }
.price-summary .row { display: flex; justify-content: space-between; font-family: 'IBM Plex Mono', monospace; font-size: 0.9rem; margin-bottom: 0.3rem; }
.price-summary .row.total { font-weight: 600; font-size: 1.05rem; color: var(--pine); }

.status-tag { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.04em; padding: 0.2rem 0.55rem; border-radius: 100px; font-weight: 600; }
.status-confirmed { background: var(--tint-good); color: var(--pine-light); }
.status-pending_payment { background: var(--tint-warn); color: var(--amber); }
.status-cancelled { background: var(--tint-bad); color: var(--ember); }
.status-completed { background: var(--surface-alt); color: var(--bark); }

.error-msg { color: var(--ember); font-size: 0.9rem; margin-top: 0.5rem; }
.success-msg { color: var(--pine-light); font-size: 0.9rem; margin-top: 0.5rem; }

table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
table th, table td { text-align: left; padding: 0.6rem 0.5rem; border-bottom: 1px solid var(--line); }
table th { font-family: 'IBM Plex Mono', monospace; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--bark); }

/* ---- Admin navigation ----
   24 sections is far too many for a row of pills across the top — it wrapped onto three
   lines and pushed the real content down the page. A grouped sidebar instead, which also
   makes it obvious which section you're in. */
/* The guest booking form wants a narrow, readable column; the dashboard needs room for
   a sidebar plus wide tables, so it gets more width. */
body.admin-page .wrap { max-width: 1500px; }
.admin-shell { display: flex; gap: 1.25rem; align-items: flex-start; }

nav.tabs {
  flex: 0 0 190px;
  position: sticky; top: 1rem;
  max-height: calc(100vh - 2rem);
  overflow-y: auto;
  background: var(--canvas-light);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.6rem;
}
.nav-group { margin-bottom: 0.9rem; }
.nav-group:last-child { margin-bottom: 0; }
.nav-group-title {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.62rem; text-transform: uppercase; letter-spacing: 0.09em;
  color: var(--bark); opacity: 0.7;
  padding: 0 0.4rem 0.25rem;
  border-bottom: 1px solid var(--line);
  margin-bottom: 0.3rem;
}
nav.tabs button {
  display: block; width: 100%; text-align: left;
  background: transparent; border: 0;
  padding: 0.4rem 0.5rem; margin-bottom: 1px;
  border-radius: 5px; cursor: pointer;
  font-size: 0.83rem; color: var(--ink);
  font-family: inherit;
}
nav.tabs button:hover { background: var(--surface-alt); }
nav.tabs button.active { background: var(--pine); color: var(--canvas-light); font-weight: 600; }

/* min-width:0 stops the wide booking tables from squeezing the sidebar off screen */
.admin-content { flex: 1; min-width: 0; }

.nav-toggle { display: none; }

@media (max-width: 900px) {
  .admin-shell { display: block; }
  /* Slide-out drawer on small screens — a permanent column costs too much width */
  nav.tabs {
    position: fixed; top: 0; left: 0; bottom: 0;
    width: 230px; z-index: 200;
    border-radius: 0;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    box-shadow: 2px 0 12px rgba(0,0,0,0.2);
    max-height: 100vh;
  }
  nav.tabs.open { transform: translateX(0); }
  .nav-toggle {
    display: block;
    position: fixed; top: 0.6rem; left: 0.6rem; z-index: 201;
    width: auto;
    background: var(--pine); color: var(--canvas-light);
    border-radius: 6px; padding: 0.5rem 0.8rem;
    font-size: 0.85rem; min-height: 40px;
  }
  .admin-content { padding-top: 3.2rem; }
  .nav-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,0.35); z-index: 199; }
}

.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
@media (max-width: 640px) { .two-col { grid-template-columns: 1fr; } }

/* Calendar grid */
table.cal-table { border-collapse: collapse; font-size: 0.78rem; }
table.cal-table th, table.cal-table td { border: 1px solid var(--line); padding: 0.25rem 0.4rem; text-align: center; white-space: nowrap; }
table.cal-table th.cal-pitch-col, table.cal-table td.cal-pitch-col {
  position: sticky; left: 0; background: var(--canvas-light); text-align: left; z-index: 1; min-width: 110px;
}
table.cal-table td.cal-booked { background: var(--tint-good); color: var(--pine-light); font-weight: 500; cursor: grab; }
table.cal-table td.cal-booked:active { cursor: grabbing; }
table.cal-table td.cal-booked.cal-pending { background: var(--tint-warn); color: var(--amber); }
table.cal-table td.cal-free { background: var(--canvas-light); color: var(--line); }
table.cal-table th.cal-weekend { background: var(--surface-alt); }

/* Site map: grass field aesthetic instead of a plain grid — the actual grass/trees/
   buildings/paths are now one inline SVG illustration built in dashboard.js; this
   container just needs a neutral fallback background. */
.site-map-grass {
  background: var(--canvas-light);
}

/* Site map tiles — small, soft, semi-translucent so they read as pitches on grass
   rather than blocky UI squares. Slightly rectangular (not perfectly square) and a
   thin border rather than the thick 3px one used previously. */
.map-tile {
  position: absolute;
  width: 30px; height: 21px;
  border-radius: 2px;
  display: flex; align-items: center; justify-content: center;
  font-family: 'Inter', sans-serif;
  font-size: 0.46rem;
  font-weight: 700;
  color: var(--map-label);
  background: var(--surface);
  border: 1px solid var(--line);
  cursor: grab;
  user-select: none;
  box-shadow: 0 1px 2px rgba(0,0,0,0.22);
  text-align: center;
  z-index: 3;
  transition: transform 0.1s ease;
}
.map-tile:hover { transform: scale(1.35); z-index: 5; box-shadow: 0 2px 6px rgba(0,0,0,0.3); }
.map-tile.map-electric { background: var(--tint-warn); border-color: var(--amber); }
.map-tile.map-free { }
.map-tile.map-booked { background: var(--tint-bad); border-color: var(--ember); }
.map-tile:active { cursor: grabbing; z-index: 10; transform: scale(1.35); }

/* Dashboard stat cards — headline figure plus tomorrow/weekend/week breakdown,
   mirroring the four-across layout of a commercial system's main dashboard. */
.dash-stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 1rem;
}
.dash-stat {
  background: var(--canvas-light);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
}
.dash-stat .label {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--bark);
}
.dash-stat .headline {
  font-family: 'Fraunces', serif;
  font-size: 2.1rem;
  font-weight: 700;
  color: var(--pine);
  line-height: 1.1;
  margin: 0.2rem 0 0.5rem;
}
.dash-stat .breakdown {
  display: flex;
  gap: 0.9rem;
  border-top: 1px dashed var(--line);
  padding-top: 0.5rem;
}
.dash-stat .breakdown div { font-size: 0.72rem; color: var(--bark); }
.dash-stat .breakdown strong {
  display: block;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.95rem;
  color: var(--ink);
  font-weight: 600;
}
.dash-stat.occupancy .headline { color: var(--amber); }

/* Occupancy bar used in the coming-days strip */
.occ-bar {
  height: 6px;
  background: var(--surface-alt);
  border-radius: 100px;
  overflow: hidden;
  margin-top: 3px;
}
.occ-bar span { display: block; height: 100%; background: var(--pine-light); border-radius: 100px; }
.occ-bar span.high { background: var(--ember); }
.occ-bar span.mid { background: var(--amber); }

/* Blocked pitches — deliberately taken out of use by staff (maintenance, owner use, etc).
   Visually distinct from "booked" so it's obvious at a glance which is which. */
table.cal-table td.cal-blocked {
  background: repeating-linear-gradient(45deg, var(--surface-alt), var(--surface-alt) 4px, var(--line) 4px, var(--line) 8px);
  color: var(--bark);
  font-weight: 700;
  cursor: pointer;
}
.map-tile.map-blocked {
  background: repeating-linear-gradient(45deg, var(--surface-alt), var(--surface-alt) 3px, var(--line) 3px, var(--line) 6px);
  border-color: var(--muted);
  color: var(--muted);
}

/* ---- Mobile / tablet ----
   The dashboard is used on a phone at the gate as much as on a desktop in the office,
   so tables scroll horizontally rather than squashing, tap targets grow, and the
   multi-column layouts collapse to single column. */
@media (max-width: 820px) {
  body { font-size: 15px; }
  .wrap { padding: 0.75rem; }
  .card { padding: 0.9rem; }
  .two-col { grid-template-columns: 1fr !important; }
  .dash-stat-grid { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
  .dash-stat .headline { font-size: 1.7rem; }

  /* Tables scroll sideways instead of crushing columns to unreadable widths */
  .card table { display: block; overflow-x: auto; white-space: nowrap; }

  /* Bigger tap targets — 44px is the usual minimum for reliable finger taps */
  button.btn { padding: 0.75rem 1.1rem; min-height: 44px; }
  input, select, textarea { padding: 0.7rem; font-size: 16px; } /* 16px stops iOS zooming on focus */
  nav.tabs { gap: 0.4rem; }
  nav.tabs button { padding: 0.55rem 0.85rem; min-height: 40px; }

  header.topbar { padding: 1rem 0.9rem 1.8rem; }
  header.topbar h1 { font-size: 1.2rem; }

  .site-grid { grid-template-columns: 1fr; }
  #site-map-canvas { height: 460px !important; }
}

@media (max-width: 480px) {
  .dash-stat-grid { grid-template-columns: 1fr 1fr; }
  .dash-stat { padding: 0.75rem; }
  .dash-stat .headline { font-size: 1.5rem; }
  .dash-stat .breakdown { gap: 0.5rem; }
  .dash-stat .breakdown div { font-size: 0.66rem; }
}

/* Autocomplete dropdown for finding existing customers when taking a booking */
.autocomplete-results {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  z-index: 50;
  background: var(--canvas-light);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  max-height: 260px;
  overflow-y: auto;
}
.autocomplete-results .ac-item {
  padding: 0.55rem 0.7rem;
  cursor: pointer;
  border-bottom: 1px solid var(--line);
}
.autocomplete-results .ac-item:last-child { border-bottom: none; }
.autocomplete-results .ac-item:hover,
.autocomplete-results .ac-item.active { background: var(--surface-alt); }
.autocomplete-results .ac-name { font-weight: 600; }
.autocomplete-results .ac-meta { font-size: 0.78rem; color: var(--bark); }
.linked-customer {
  background: var(--tint-good);
  border: 1px solid var(--pine-light);
  border-radius: var(--radius);
  padding: 0.6rem 0.75rem;
  margin-top: 0.5rem;
  font-size: 0.85rem;
}

/* --- Outstanding balance flagging ---
   Amber = owes money but not yet due; red = overdue. Distinct from the "booked" red
   border used elsewhere, so a full pitch isn't mistaken for one that owes money. */
.map-tile.map-owing {
  background: var(--tint-bad) !important;
  border-color: var(--amber) !important;
  border-width: 2px;
  font-weight: 700;
}
.map-tile.map-owing-overdue {
  background: var(--tint-bad) !important;
  border-color: var(--ember) !important;
  border-width: 2.5px;
  font-weight: 700;
  color: var(--ember);
  animation: owingPulse 2.5s ease-in-out infinite;
}
@keyframes owingPulse {
  0%, 100% { box-shadow: 0 1px 2px rgba(0,0,0,0.2); }
  50% { box-shadow: 0 0 0 3px rgba(181, 72, 44, 0.35); }
}

table.cal-table td.cal-owing {
  background: var(--tint-warn);
  color: var(--amber);
  font-weight: 700;
}
table.cal-table td.cal-overdue {
  background: var(--tint-bad);
  color: var(--ember);
  font-weight: 700;
}

/* Respect a reduced-motion preference — a pulsing tile shouldn't be forced on anyone */
@media (prefers-reduced-motion: reduce) {
  .map-tile.map-owing-overdue { animation: none; box-shadow: 0 0 0 3px rgba(181, 72, 44, 0.35); }
}

/* ---- Charts: whole-site booking grid ----
   A wide scrolling grid: pitch rows down the side, days across the top, booking bars
   spanning their dates. Sticky headers so the pitch name and date stay visible while
   scrolling a full year. */
.chart-table { border-collapse: separate; border-spacing: 0; font-size: 0.72rem; }
.chart-table th, .chart-table td { border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); }

.chart-table thead th {
  position: sticky; top: 0; z-index: 3;
  background: var(--canvas-light);
  font-family: 'IBM Plex Mono', monospace;
  font-weight: 600; font-size: 0.66rem;
  padding: 2px 0; text-align: center; white-space: nowrap;
}
.chart-table thead tr:first-child th { top: 0; }
.chart-table thead tr:nth-child(2) th { top: 20px; }

/* Pitch name column stays put when scrolling sideways */
.chart-pitch {
  position: sticky; left: 0; z-index: 2;
  background: var(--canvas-light);
  font-family: 'IBM Plex Mono', monospace;
  font-weight: 600;
  padding: 0 0.5rem; white-space: nowrap;
  border-right: 2px solid var(--line);
}
.chart-table thead .chart-pitch { z-index: 4; }

.chart-category-row td {
  background: var(--pine); color: var(--canvas-light);
  font-family: 'Fraunces', serif; font-weight: 600;
  padding: 0.25rem 0.5rem; position: sticky; left: 0;
}

.chart-day { width: 26px; min-width: 26px; height: 22px; padding: 0; position: relative; }
.chart-day.chart-weekend { background: rgba(44, 85, 64, 0.06); }
.chart-day.chart-today { box-shadow: inset 2px 0 0 var(--ember); }
.chart-day:hover { background: rgba(198, 142, 23, 0.15); cursor: crosshair; }

/* Booking bars sit on top of the day cells */
.chart-bar {
  position: absolute; top: 2px; bottom: 2px; left: 1px;
  border-radius: 3px; padding: 0 4px;
  font-size: 0.66rem; line-height: 18px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  cursor: grab; z-index: 1; color: #fff;
  box-shadow: 0 1px 2px rgba(0,0,0,0.25);
}
.chart-bar:hover { filter: brightness(1.1); z-index: 5; }
.chart-bar:active { cursor: grabbing; }
.chart-bar.dragging { opacity: 0.45; }

.chart-paid       { background: var(--chart-paid); color: var(--chart-text); }
.chart-owing      { background: var(--chart-owing); color: #201C16; }
.chart-overdue    { background: var(--chart-overdue); color: var(--chart-text); }
.chart-unconfirmed{ background: var(--chart-unconfirmed); color: var(--chart-text); }
.chart-pending    { background: var(--chart-pending); color: var(--chart-text); }
.chart-blocked    { background: repeating-linear-gradient(45deg,var(--chart-blocked-a),var(--chart-blocked-a) 4px,var(--chart-blocked-b) 4px,var(--chart-blocked-b) 8px); color: var(--ink); }
.chart-external   { background: var(--chart-external); color: var(--chart-text); }

.chart-key {
  display: inline-block; width: 14px; height: 14px;
  border-radius: 3px; vertical-align: middle; margin-right: 3px;
}

/* Where a booking can be dropped */
.chart-day.drop-ok { background: rgba(44, 85, 64, 0.3); }
.chart-day.drop-bad { background: rgba(181, 72, 44, 0.3); }
