/* Metro Planner — "Transit Authority / Control Room"
   Dark operations console + diagrammatic transit cartography.
   Chrome stays near-monochrome; the metro LINES carry the colour. */

:root {
  --bg: #0b0e13;
  --panel: #11161f;
  --panel-2: #161d28;
  --panel-3: #1c2531;
  --ink: #283142;
  --ink-soft: #1e2733;
  --text: #d8dee9;
  --text-dim: #8893a4;
  --text-faint: #5b6573;
  --accent: #4fd4c8;
  --accent-dim: #2f7d77;
  --danger: #e3573e;
  --ok: #6fcf7a;
  --warn: #e3b23e;

  --grid: rgba(79, 212, 200, 0.05);
  --grid-strong: rgba(79, 212, 200, 0.09);

  --font-display: 'Bricolage Grotesque', ui-sans-serif, system-ui, sans-serif;
  --font-mono: 'Martian Mono', ui-monospace, 'SF Mono', Menlo, monospace;

  --line-palette-0: #e3573e;
  --line-palette-1: #3e86e3;
  --line-palette-2: #46b04f;
  --line-palette-3: #e3b23e;
  --line-palette-4: #9b5be3;
  --line-palette-5: #e3589e;
  --line-palette-6: #2fbfb3;
  --line-palette-7: #e3793e;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-display);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

.app {
  height: 100vh;
  display: grid;
  grid-template-rows: 52px 1fr;
}

/* ---------- Status bar ---------- */
.statusbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 0 18px;
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border-bottom: 1px solid var(--ink);
  z-index: 600;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-name {
  font-weight: 800;
  letter-spacing: 0.16em;
  font-size: 14px;
}
.roundel {
  display: inline-grid;
  place-items: center;
  width: 26px; height: 26px;
  border-radius: 50%;
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 13px;
  color: #08120f;
  background: var(--accent);
  box-shadow: 0 0 0 3px rgba(79, 212, 200, 0.15);
}
.brand-roundel { background: var(--accent); }

.metrics { display: flex; gap: 26px; justify-self: center; }
.metric { display: flex; flex-direction: column; align-items: center; line-height: 1; }
.metric label {
  margin-top: 5px;
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--text-faint);
}

/* Split-flap-ish numeric readout */
.flap {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 20px;
  letter-spacing: 0.04em;
  color: var(--accent);
  background: #05080c;
  padding: 4px 8px;
  border-radius: 4px;
  border: 1px solid var(--ink);
  box-shadow: inset 0 -7px 10px rgba(0,0,0,0.45), inset 0 1px 0 rgba(255,255,255,0.04);
  min-width: 2.4ch;
  text-align: center;
  position: relative;
}
.flap::after {
  content: "";
  position: absolute; left: 6px; right: 6px; top: 50%;
  height: 1px; background: rgba(0,0,0,0.6);
}
.flap.flipping { animation: flap-flip 0.32s ease; }
@keyframes flap-flip {
  0% { transform: translateY(0) scaleY(1); }
  45% { transform: translateY(-2px) scaleY(0.82); filter: brightness(1.5); }
  100% { transform: translateY(0) scaleY(1); }
}

.session { display: flex; align-items: center; gap: 12px; justify-self: end; }
.conn { color: var(--danger); font-size: 12px; transition: color 0.3s; }
.conn.up { color: var(--ok); text-shadow: 0 0 8px rgba(111,207,122,0.6); }
.whoami {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-dim);
  letter-spacing: 0.04em;
}

/* ---------- Buttons ---------- */
.btn {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.04em;
  color: var(--text);
  background: var(--panel-3);
  border: 1px solid var(--ink);
  border-radius: 5px;
  padding: 6px 10px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.05s;
}
.btn:hover { background: #232d3b; border-color: var(--accent-dim); }
.btn:active { transform: translateY(1px); }
.btn.small { padding: 2px 8px; font-size: 13px; }
.btn.primary { background: var(--accent); color: #06100d; border-color: var(--accent); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); border-color: rgba(227,87,62,0.4); }
.btn.danger:hover { background: rgba(227,87,62,0.12); }

/* ---------- Workspace ---------- */
.workspace {
  display: grid;
  grid-template-columns: 256px 1fr 326px;
  min-height: 0;
}

/* ---------- Rail ---------- */
.rail {
  background: var(--panel);
  border-right: 1px solid var(--ink);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.rail-head, .insp-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.2em;
  color: var(--text-dim);
  border-bottom: 1px solid var(--ink-soft);
}
.line-list { list-style: none; margin: 0; padding: 6px; overflow-y: auto; flex: 1; }
.line-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
  border: 1px solid transparent;
}
.line-item:hover { background: var(--panel-2); }
.line-item.selected { background: var(--panel-3); border-color: var(--accent-dim); }
.line-bullet {
  width: 16px; height: 16px; border-radius: 50%;
  flex: 0 0 auto;
  box-shadow: 0 0 0 2px rgba(255,255,255,0.06);
}
.line-name { font-size: 13px; font-weight: 600; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.line-count { font-family: var(--font-mono); font-size: 10px; color: var(--text-faint); }

.rail-foot { border-top: 1px solid var(--ink-soft); padding: 10px; }
.tool-group { display: flex; gap: 6px; margin-bottom: 10px; }
.tool {
  flex: 1;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-dim);
  background: var(--panel-2);
  border: 1px solid var(--ink);
  border-radius: 5px;
  padding: 7px 4px;
  cursor: pointer;
}
.tool.active { color: #06100d; background: var(--accent); border-color: var(--accent); font-weight: 600; }
.presence { display: flex; flex-wrap: wrap; gap: 6px; min-height: 18px; }
.presence .who {
  font-family: var(--font-mono);
  font-size: 10px;
  padding: 2px 7px;
  border-radius: 10px;
  background: var(--panel-3);
  border: 1px solid var(--ink);
}

/* ---------- Map ---------- */
.map-wrap { position: relative; min-width: 0; background: #070a0e; }
#map {
  position: absolute; inset: 0;
  background-color: #070a0e;
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px),
    linear-gradient(var(--grid-strong) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-strong) 1px, transparent 1px);
  background-size: 32px 32px, 32px 32px, 256px 256px, 256px 256px;
  cursor: grab;
}
#map.tool-station { cursor: crosshair; }
.leaflet-container { background: transparent; font-family: var(--font-mono); }
.coord-readout {
  position: absolute; left: 12px; bottom: 12px; z-index: 500;
  font-family: var(--font-mono); font-size: 11px;
  color: var(--accent);
  background: rgba(5,8,12,0.8);
  border: 1px solid var(--ink);
  padding: 5px 9px; border-radius: 5px;
  pointer-events: none;
}
.hint {
  position: absolute; left: 50%; top: 14px; transform: translateX(-50%);
  z-index: 500;
  font-family: var(--font-mono); font-size: 11px;
  color: var(--text);
  background: rgba(79,212,200,0.12);
  border: 1px solid var(--accent-dim);
  padding: 6px 12px; border-radius: 20px;
  pointer-events: none;
  opacity: 0; transition: opacity 0.3s;
}
.hint.show { opacity: 1; }

/* Station + line graphics (divIcons / leaflet layers) */
.station-icon { display: grid; place-items: center; }
.station-dot {
  width: 12px; height: 12px; border-radius: 50%;
  background: #0b0e13; border: 3px solid #fff;
  box-shadow: 0 0 0 1px rgba(0,0,0,0.6);
}
.station-dot.interchange { width: 15px; height: 15px; border-radius: 4px; }
.station-dot.terminus { border-radius: 2px; }
.station-dot.depot { background: var(--warn); }
.station-label {
  position: absolute; left: 16px; top: -3px;
  white-space: nowrap;
  font-family: var(--font-display); font-weight: 700; font-size: 12px;
  color: var(--text);
  text-shadow: 0 1px 3px #000, 0 0 2px #000;
  pointer-events: none;
}
.station-icon.selected .station-dot { border-color: var(--accent); box-shadow: 0 0 0 4px rgba(79,212,200,0.3); }
.cursor-ghost {
  font-family: var(--font-mono); font-size: 10px;
  padding: 1px 6px; border-radius: 8px; white-space: nowrap;
  transform: translate(8px, -50%);
  color: #06100d; font-weight: 600;
}

/* ---------- Inspector ---------- */
.inspector { background: var(--panel); border-left: 1px solid var(--ink); overflow-y: auto; min-height: 0; }
.inspector-empty { padding: 24px 18px; color: var(--text-faint); font-size: 13px; line-height: 1.6; }
.inspector-body { padding: 0 0 24px; }
.field { padding: 10px 16px; border-bottom: 1px solid var(--ink-soft); }
.field label {
  display: block;
  font-family: var(--font-mono); font-size: 9px; letter-spacing: 0.16em;
  text-transform: uppercase; color: var(--text-faint); margin-bottom: 6px;
}
.field input[type=text], .field select, .field input[type=number] {
  width: 100%;
  background: #05080c; color: var(--text);
  border: 1px solid var(--ink); border-radius: 5px;
  padding: 7px 9px; font-family: var(--font-display); font-size: 13px;
}
.field .row { display: flex; gap: 8px; align-items: center; }
.swatches { display: flex; flex-wrap: wrap; gap: 6px; }
.swatch { width: 22px; height: 22px; border-radius: 50%; cursor: pointer; border: 2px solid transparent; }
.swatch.active { border-color: #fff; }
.stop-list { list-style: none; margin: 0; padding: 0; }
.stop-list li {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 16px; font-size: 13px;
}
.stop-list .stop-tick { width: 9px; height: 9px; border-radius: 50%; border: 2px solid var(--text-dim); flex: 0 0 auto; }
.insp-title { padding: 14px 16px 6px; font-size: 17px; font-weight: 800; display: flex; align-items: center; gap: 10px; }
.coords-mono { font-family: var(--font-mono); font-size: 11px; color: var(--text-dim); }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 1000;
  background: rgba(4,6,10,0.7); backdrop-filter: blur(4px);
  display: grid; place-items: center;
}
.modal {
  width: 360px; background: var(--panel-2);
  border: 1px solid var(--ink); border-radius: 10px;
  padding: 22px; box-shadow: 0 24px 60px rgba(0,0,0,0.6);
}
.modal h2 { margin: 0 0 8px; font-size: 18px; }
.modal p { color: var(--text-dim); font-size: 13px; line-height: 1.5; }
.modal code { font-family: var(--font-mono); color: var(--accent); background: #05080c; padding: 2px 6px; border-radius: 4px; }
.modal input {
  width: 100%; margin-top: 10px;
  background: #05080c; color: var(--text);
  border: 1px solid var(--ink); border-radius: 6px;
  padding: 12px; font-family: var(--font-mono); font-size: 22px;
  letter-spacing: 0.3em; text-align: center; text-transform: uppercase;
}
.modal-error { color: var(--danger); font-size: 12px; min-height: 1em; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }

/* ---------- Bill of materials ---------- */
.bom { border-top: 2px solid var(--ink); background: linear-gradient(180deg, var(--panel-2), var(--panel)); }
.bom-head {
  padding: 12px 16px 8px;
  font-family: var(--font-mono); font-size: 10px; letter-spacing: 0.16em;
  color: var(--accent);
}
.bom-totals { display: flex; flex-wrap: wrap; gap: 8px; padding: 0 14px 12px; }
.bom-chip {
  display: flex; flex-direction: column; align-items: center;
  background: #05080c; border: 1px solid var(--ink); border-radius: 6px;
  padding: 7px 10px; min-width: 56px;
}
.bom-chip-val { font-family: var(--font-mono); font-size: 17px; font-weight: 600; color: var(--text); }
.bom-chip-lbl { font-family: var(--font-mono); font-size: 8.5px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-faint); margin-top: 3px; }
.bom-list { list-style: none; margin: 0; padding: 6px 0 16px; }
.bom-list li {
  display: flex; justify-content: space-between; align-items: baseline;
  padding: 5px 16px; font-size: 13px;
  border-bottom: 1px solid var(--ink-soft);
}
.bom-name { color: var(--text-dim); }
.bom-note { font-family: var(--font-mono); font-size: 9px; color: var(--text-faint); margin-left: 4px; }
.bom-qty { font-family: var(--font-mono); font-weight: 600; color: var(--accent); }

.editor-only { display: none; }
body.can-edit .editor-only { display: inline-flex; }

/* hide leaflet attribution flag clutter but keep credit small */
.leaflet-control-attribution { background: rgba(5,8,12,0.6) !important; color: var(--text-faint) !important; }
.leaflet-control-attribution a { color: var(--text-dim) !important; }
