/* ------------------------------------------------------------------- theming
   Dark is the default. Light is applied either by the OS preference or by an
   explicit data-theme on <html>, which the toggle in theme.js writes and which
   must win over the media query in both directions.
   The plan canvas cannot use CSS variables, so map.js carries a matching palette. */
:root,
:root[data-theme="dark"] {
  --bg: #0e1117;
  --panel: #161b24;
  --panel-2: #1d2330;
  --line: #2a3140;
  --ink: #e7eaf0;
  --ink-dim: #98a2b3;
  --accent: #4f9dff;
  --ok: #3fb950;
  --warn: #d29922;
  --bad: #f85149;
  --map-bg: #0a0d13;
  --shadow: rgba(0, 0, 0, .45);
  /* Text drawn on the accent fill. Dark theme accent is light, so ink is dark. */
  --on-accent: #04121f;
  --sel-row: #1b2740;
  --radius: 10px;
  color-scheme: dark;
}

:root[data-theme="light"] {
  --bg: #f5f7fa;
  --panel: #ffffff;
  --panel-2: #eef1f6;
  --line: #d5dbe4;
  --ink: #17202e;
  --ink-dim: #5c6879;
  --accent: #1668d6;
  --ok: #1a7f37;
  --warn: #9a6700;
  --bad: #cf222e;
  --map-bg: #f7f9fc;
  --shadow: rgba(23, 32, 46, .16);
  /* Light theme accent is a strong blue, so its label must be white. */
  --on-accent: #ffffff;
  --sel-row: #dce8fb;
  color-scheme: light;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme]) {
    --bg: #f5f7fa;
    --panel: #ffffff;
    --panel-2: #eef1f6;
    --line: #d5dbe4;
    --ink: #17202e;
    --ink-dim: #5c6879;
    --accent: #1668d6;
    --ok: #1a7f37;
    --warn: #9a6700;
    --bad: #cf222e;
    --map-bg: #f7f9fc;
    --shadow: rgba(23, 32, 46, .16);
    --on-accent: #ffffff;
    --sel-row: #dce8fb;
    color-scheme: light;
  }
}

* { box-sizing: border-box; }

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

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ------------------------------------------------------------------- layout */
header.top {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 0 20px;
  height: 56px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
}
header.top .brand { font-weight: 650; letter-spacing: .2px; }
header.top .brand small { color: var(--ink-dim); font-weight: 400; margin-left: 8px; }
header.top nav { display: flex; gap: 4px; margin-left: auto; }
header.top nav a {
  padding: 7px 13px;
  border-radius: 8px;
  color: var(--ink-dim);
}
header.top nav a.on, header.top nav a:hover {
  background: var(--panel-2);
  color: var(--ink);
  text-decoration: none;
}

.wrap { padding: 20px; max-width: 1680px; margin: 0 auto; }
.grid { display: grid; gap: 16px; }
.cols-4 { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
}
.card h2 { margin: 0 0 12px; font-size: 15px; font-weight: 600; }
.card h2 .muted { color: var(--ink-dim); font-weight: 400; }

.stat .n { font-size: 30px; font-weight: 650; letter-spacing: -.5px; }
.stat .k { color: var(--ink-dim); font-size: 12px; text-transform: uppercase; letter-spacing: .6px; }

/* -------------------------------------------------------------------- forms */
label { display: block; font-size: 12px; color: var(--ink-dim); margin: 12px 0 5px; }
input[type=text], input[type=email], input[type=password], input[type=file], select, textarea {
  width: 100%;
  padding: 9px 11px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  font: inherit;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
textarea { min-height: 78px; resize: vertical; }

button, .btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 9px 16px;
  background: var(--accent);
  color: var(--on-accent);
  border: 0;
  border-radius: 8px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
button:hover, .btn:hover { filter: brightness(1.08); text-decoration: none; }
button.ghost, .btn.ghost {
  background: var(--panel-2);
  color: var(--ink);
  border: 1px solid var(--line);
}
button[disabled] { opacity: .5; cursor: not-allowed; }

/* ------------------------------------------------------------------- tables */
table { width: 100%; border-collapse: collapse; }
th, td { padding: 9px 10px; text-align: left; border-bottom: 1px solid var(--line); }
th {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .6px;
  color: var(--ink-dim);
  position: sticky;
  top: 0;
  background: var(--panel);
}
tbody tr:hover { background: var(--panel-2); }
tbody tr.sel { background: var(--sel-row); }
td.code { font-family: ui-monospace, Consolas, monospace; }

.pill {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
}
.pill.occupied { background: rgba(63,185,80,.16); color: var(--ok); }
.pill.vacant   { background: rgba(210,153,34,.16); color: var(--warn); }
.pill.common   { background: rgba(152,162,179,.16); color: var(--ink-dim); }
.pill.reserved { background: rgba(79,157,255,.16); color: var(--accent); }

.muted { color: var(--ink-dim); }
.mono { font-family: ui-monospace, Consolas, monospace; font-size: 12px; }
pre.log {
  background: var(--map-bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  overflow: auto;
  max-height: 340px;
  font-size: 12px;
  white-space: pre-wrap;
}

/* --------------------------------------------------------------- map canvas */
.mapbox {
  position: relative;
  background: var(--map-bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
.mapbox canvas { display: block; width: 100%; touch-action: none; cursor: grab; }
.mapbox canvas.dragging { cursor: grabbing; }
.mapbox .tools {
  position: absolute;
  top: 10px;
  right: 10px;
  display: flex;
  gap: 6px;
}
.mapbox .tools button { padding: 6px 11px; font-size: 12px; }
.mapbox .legend {
  position: absolute;
  left: 10px;
  bottom: 10px;
  display: flex;
  gap: 14px;
  padding: 8px 12px;
  background: color-mix(in srgb, var(--panel) 88%, transparent);
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 12px;
}
.mapbox .legend i {
  display: inline-block;
  width: 11px;
  height: 11px;
  border-radius: 3px;
  margin-right: 6px;
  vertical-align: -1px;
}
.mapbox .hint {
  position: absolute;
  top: 10px;
  left: 10px;
  padding: 6px 11px;
  background: color-mix(in srgb, var(--panel) 88%, transparent);
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 12px;
  color: var(--ink-dim);
}

.split { display: grid; grid-template-columns: 1fr 380px; gap: 16px; align-items: start; }
@media (max-width: 1100px) { .split { grid-template-columns: 1fr; } }

.scroll-y { max-height: 62vh; overflow: auto; }

.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  padding: 11px 20px;
  background: var(--ok);
  color: var(--on-accent);
  border-radius: 999px;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s;
  z-index: 60;
}
.toast.show { opacity: 1; }
.toast.err { background: var(--bad); color: #fff; }

.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
}
.login-wrap .card { width: 360px; }
.err {
  background: rgba(248,81,73,.12);
  border: 1px solid rgba(248,81,73,.4);
  color: #ffb4ae;
  padding: 9px 12px;
  border-radius: 8px;
  font-size: 13px;
}

/* --------------------------------------------------------------- theme toggle */
.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  background: var(--panel-2);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 8px;
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
.theme-toggle .icon { font-size: 13px; line-height: 1; }
/* Show only the glyph for whichever theme the button would switch *to*. */
:root[data-theme="light"] .theme-toggle .to-dark,
:root:not([data-theme="light"]) .theme-toggle .to-light { display: inline; }
:root[data-theme="light"] .theme-toggle .to-light,
:root:not([data-theme="light"]) .theme-toggle .to-dark { display: none; }

/* --------------------------------------------------------------------- modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(6, 9, 14, .62);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 80;
  padding: 18px;
}
.modal-backdrop.open { display: flex; }
.modal {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 18px 50px var(--shadow);
  width: 100%;
  max-width: 460px;
  max-height: 88vh;
  overflow-y: auto;
  padding: 20px 22px 22px;
  position: relative;
}
.modal h2 { margin: 0 0 2px; font-size: 18px; }
.modal .sub { color: var(--ink-dim); font-size: 12.5px; margin-bottom: 14px; }
.modal .x {
  position: absolute;
  top: 12px;
  right: 14px;
  background: none;
  border: 0;
  color: var(--ink-dim);
  font-size: 22px;
  line-height: 1;
  padding: 2px 6px;
  cursor: pointer;
}
.modal .row { display: flex; gap: 10px; }
.modal .row > * { flex: 1; }
.field-note { color: var(--ink-dim); font-size: 11.5px; margin: 5px 0 0; }
