:root {
  --bg: #f4f6f9; --surface: #ffffff; --border: #d9dee6; --text: #1b2430; --muted: #5d6b7c;
  --accent: #2563eb;
  --cad-fg: #3a4452; --plan-bg: #ffffff;
  --free: #16a34a; --occupied: #dc2626; --reserved: #2563eb; --oos: #6b7280;
  --shadow: 0 6px 24px rgba(15, 23, 42, .18);
  --bar-h: 52px; --panel-w: 300px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f141b; --surface: #171e28; --border: #2a3441; --text: #e6ebf2; --muted: #94a3b8;
    --accent: #60a5fa; --cad-fg: #e3e8ef; --plan-bg: #0c1117;
    --free: #22c55e; --occupied: #f87171; --reserved: #60a5fa; --oos: #9ca3af;
    --shadow: 0 6px 24px rgba(0, 0, 0, .6);
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); overflow: hidden; }
button, select, input { font: inherit; color: inherit; }

.app { display: grid; height: 100dvh; grid-template-columns: var(--panel-w) 1fr; grid-template-rows: var(--bar-h) 1fr;
  grid-template-areas: "bar bar" "panel stage"; }
.bar { grid-area: bar; display: flex; align-items: center; gap: 12px; padding: 0 16px; background: var(--surface); border-bottom: 1px solid var(--border); min-width: 0; }
.bar h1 { font-size: 16px; margin: 0; white-space: nowrap; }
.bar select { padding: 6px 8px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); max-width: 40vw; }
.stats { display: flex; gap: 14px; margin-left: auto; font-variant-numeric: tabular-nums; white-space: nowrap; }
.stats b { font-weight: 700; }
.stats .f b { color: var(--free); } .stats .o b { color: var(--occupied); }
.live { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); flex: none; }
.live.on { background: var(--free); animation: pulse 2s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 6px color-mix(in srgb, var(--free) 0%, transparent); opacity: .5; } }
.icon-btn { color: var(--text); border: 1px solid var(--border); background: var(--surface); border-radius: 8px; width: 36px; height: 36px; cursor: pointer; }
.only-narrow { display: none; }

.panel { grid-area: panel; background: var(--surface); border-right: 1px solid var(--border); padding: 14px 16px; overflow: auto; }
.panel section { margin-bottom: 18px; }
.panel h2 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 0 8px; }
.field { display: block; font-size: 12px; color: var(--muted); }
.field input { display: block; width: 100%; margin-top: 4px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); font-size: 14px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.chips button { padding: 5px 12px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; }
.chips button.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.legend { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.legend li { display: flex; align-items: center; gap: 8px; }
.sw { width: 18px; height: 18px; border-radius: 4px; border: 2px solid; display: inline-block; }
.sw.free { border-color: var(--free); background: color-mix(in srgb, var(--free) 18%, transparent); }
.sw.occupied { border-color: var(--occupied); background: color-mix(in srgb, var(--occupied) 22%, transparent); }
.sw.reserved { border-color: var(--reserved); background: color-mix(in srgb, var(--reserved) 22%, transparent); }
.sw.oos { border-color: var(--oos); background: repeating-linear-gradient(45deg, transparent 0 4px, color-mix(in srgb, var(--oos) 40%, transparent) 4px 6px); }
details summary { cursor: pointer; font-weight: 600; margin-bottom: 8px; }
.layers { display: grid; gap: 4px; max-height: 260px; overflow: auto; font-size: 13px; }
.layers label { display: flex; gap: 8px; align-items: center; }
.hint { color: var(--muted); font-size: 12px; }

.stage-wrap { grid-area: stage; position: relative; min-width: 0; min-height: 0; background: var(--plan-bg); }
.stage { position: absolute; inset: 0; touch-action: none; cursor: grab; outline: none; user-select: none; -webkit-user-select: none; }
.stage.dragging { cursor: grabbing; }
.stage svg { width: 100%; height: 100%; display: block; }
.zoom-ctl { position: absolute; right: 14px; bottom: 14px; display: grid; gap: 6px; }
.zoom-ctl button { width: 40px; height: 40px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); font-size: 20px; cursor: pointer; box-shadow: var(--shadow); }
.zoom-ctl button:hover { border-color: var(--accent); }
.loading { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); background: var(--plan-bg); transition: opacity .2s; }
.loading.done { opacity: 0; pointer-events: none; }

/* Bays: <g class="lot"> (id = LaneID) with an added rect.bay and either the SVG's own car art or our placeholder */
.lot { cursor: pointer; }
.lot rect.bay { stroke-width: 2; vector-effect: non-scaling-stroke; transition: fill .3s, stroke .3s; }
.lot.free rect.bay { fill: color-mix(in srgb, var(--free) 16%, transparent); stroke: var(--free); }
.lot.occupied rect.bay { fill: color-mix(in srgb, var(--occupied) 18%, transparent); stroke: var(--occupied); }
.lot.nosensor rect.bay { fill: color-mix(in srgb, var(--oos) 14%, transparent); stroke: var(--oos); stroke-dasharray: 5 4; }
.lot.t-handicap rect.bay { stroke-dasharray: 7 3; }
.lot.t-electric rect.bay { stroke-width: 3; }
.lot:hover rect.bay, .lot.sel rect.bay { stroke-width: 3.5; filter: brightness(1.2); }
.lot.dim { opacity: .18; }
.lot:not(.occupied) > :not(.bay) { display: none; }           /* the car is only drawn while the sensor says occupied */
.lot > :not(.bay) { pointer-events: none; }
.labels { pointer-events: none; display: none; }
.z-labels .labels { display: block; }
.labels text { font-weight: 700; text-anchor: middle; fill: var(--text); paint-order: stroke; stroke: var(--plan-bg); stroke-linejoin: round; }
.lot.flash rect.bay { animation: flash 1.2s ease-out; }
@keyframes flash { 0% { stroke-width: 7; } 100% { stroke-width: 2; } }

/* drawings made for a white sheet: keep their black linework readable in the dark theme */
:root[data-theme="dark"] .stage svg :is([stroke="black"], [stroke="#000000"], [stroke="#000"]):not(.lot *) { stroke: var(--cad-fg); }
:root[data-theme="dark"] .stage svg :is([fill="black"], [fill="#000000"], [fill="#000"]):not(.lot *) { fill: var(--cad-fg); }
:root[data-theme="dark"] .stage svg text[style*="fill:#000000"] { fill: var(--cad-fg) !important; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .stage svg :is([stroke="black"], [stroke="#000000"], [stroke="#000"]):not(.lot *) { stroke: var(--cad-fg); }
  :root:not([data-theme="light"]) .stage svg :is([fill="black"], [fill="#000000"], [fill="#000"]):not(.lot *) { fill: var(--cad-fg); }
  :root:not([data-theme="light"]) .stage svg text[style*="fill:#000000"] { fill: var(--cad-fg) !important; }
}

.card { position: absolute; z-index: 5; min-width: 210px; max-width: 280px; padding: 12px 14px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; box-shadow: var(--shadow); pointer-events: none; font-size: 13px; }
.card h3 { margin: 0 0 6px; font-size: 16px; display: flex; align-items: center; gap: 8px; }
.card .badge { font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 999px; color: #fff; }
.badge.free { background: var(--free); } .badge.occupied { background: var(--occupied); } .badge.reserved { background: var(--reserved); } .badge.oos { background: var(--oos); }
.card dl { display: grid; grid-template-columns: auto 1fr; gap: 2px 12px; margin: 0; }
.card dt { color: var(--muted); } .card dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
.card.sheet { left: 12px !important; right: 12px; bottom: 12px; top: auto !important; max-width: none; pointer-events: auto; }

@media (max-width: 800px) {
  .app { grid-template-columns: 1fr; grid-template-areas: "bar" "stage"; }
  .only-narrow { display: inline-grid; place-items: center; }
  .bar { padding: 0 10px; gap: 8px; }
  .bar h1 { display: none; }
  .stats { gap: 8px; font-size: 13px; }
  .stats .t { display: none; }
  .panel { position: fixed; z-index: 20; top: var(--bar-h); left: 0; bottom: 0; width: min(86vw, 340px); transform: translateX(-102%); transition: transform .2s; box-shadow: var(--shadow); }
  .panel.open { transform: none; }
  .zoom-ctl { bottom: 90px; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
:root[data-theme="dark"] {
  --bg: #0f141b; --surface: #171e28; --border: #2a3441; --text: #e6ebf2; --muted: #94a3b8;
  --accent: #60a5fa; --cad-fg: #e3e8ef; --plan-bg: #0c1117;
  --free: #22c55e; --occupied: #f87171; --reserved: #60a5fa; --oos: #9ca3af;
  --shadow: 0 6px 24px rgba(0, 0, 0, .6);
}
.sw.nosensor { border-color: var(--oos); border-style: dashed; background: color-mix(in srgb, var(--oos) 14%, transparent); }
.badge.nosensor { background: var(--oos); }
.card img.plate { display: block; width: 100%; margin-top: 8px; border-radius: 6px; border: 1px solid var(--border); background: #000; }
.card.sheet img.plate { max-width: 320px; }
.lot.disabled rect.bay { stroke-dasharray: 2 5; opacity: .6; }

/* account menu (auth.js) */
#account { position: relative; flex: none; }
.acct summary { list-style: none; display: flex; align-items: center; gap: 8px; cursor: pointer; padding: 3px 10px 3px 3px; border: 1px solid var(--border); border-radius: 999px; background: var(--surface); }
.acct summary::-webkit-details-marker { display: none; }
.acct summary:hover { border-color: var(--accent); }
.avatar { width: 28px; height: 28px; border-radius: 50%; background: var(--accent); color: #fff; font-weight: 700; display: grid; place-items: center; font-size: 14px; }
.who { max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.acct .menu { position: absolute; right: 0; top: calc(100% + 8px); z-index: 50; min-width: 220px; padding: 6px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow); display: grid; }
.acct .menu a, .acct .menu button { display: block; text-align: left; padding: 9px 12px; border: 0; border-radius: 8px; background: none; color: var(--text); text-decoration: none; cursor: pointer; font-size: 14px; }
.acct .menu a:hover, .acct .menu button:hover { background: color-mix(in srgb, var(--accent) 12%, transparent); }
.acct .menu a[aria-current="page"] { font-weight: 700; }
.menu-head { display: grid; gap: 2px; padding: 8px 12px 10px; border-bottom: 1px solid var(--border); margin-bottom: 4px; font-size: 13px; }
.menu-head span { color: var(--muted); }
.menu-head .rolebadge { justify-self: start; margin-top: 4px; color: var(--text); font-size: 11.5px; font-weight: 700; padding: 2px 9px; border-radius: 999px; background: color-mix(in srgb, var(--muted) 22%, transparent); }
@media (max-width: 800px) { .who { display: none; } .acct summary { padding: 3px; } }
