/* Katy Trail — styled after the Scriptorium visual style guide
   (flat grey "pro tool" UI, 11px type, 2px radii, yellow accent, cyan selection). */

:root {
  color-scheme: light;

  --bg: #a5a5a5;
  --chrome: #818181;
  --panel: #a5a5a5;
  --canvas: #b0b0b0;
  --button: #bdbdbd;
  --button-hover: #c8c8c8;
  --rack: #989898;
  --rack-head: #8c8c8c;
  --well: #dddddd;
  --well-hover: #e8e8e8;
  --well-border: #7a7a7a;
  --edge: #6f6f6f;
  --text: #121212;
  --text-dim: #3c3c3c;
  --value: #121212;
  --accent: #fbb814;
  --on-accent: #121212;
  --select: #03c9d6;
  --meter: #46d16e;
  --meter-off: #7d877f;
  --thumb: #2a2a2a;
  --paper: #ffffff;
  --ink: #121212;
  --error: #b3261e;

  /* Base map. Kept near-grey so the trail, sites and selection carry the colour. */
  --map-land: #efefef;
  --map-park: #dde3d8;
  --map-water: #c6d4db;
  --map-building: #dcdcdc;
  --map-road: #ffffff;
  --map-casing: #c2c2c2;
  --map-major-casing: #a4a4a4;
  --map-highway: #d2d2d2;
  --map-highway-casing: #8e8e8e;
  --map-path: #b4b4b4;
  --map-rail: #8a8a8a;
  --map-label: #3c3c3c;

  --side-w: 320px;
}

* { box-sizing: border-box; }

html, body { height: 100%; margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font: 400 11px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  user-select: none;
  -webkit-user-select: none;
  cursor: default;
  overflow: hidden;
}

button { font: inherit; color: inherit; cursor: default; }

svg { fill: none; stroke: currentColor; stroke-width: 1.3; stroke-linecap: round; stroke-linejoin: round; }

:focus-visible { outline: 1px solid var(--select); outline-offset: 1px; }

/* ---------- App frame ---------- */

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

/* ---------- Toolbar ---------- */

.toolbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
  padding: 0 6px;
  background: var(--chrome);
  border-bottom: 1px solid var(--edge);
}

.toolbar-left, .toolbar-right { display: flex; align-items: center; gap: 2px; min-width: 0; }
.toolbar-right { justify-content: flex-end; }

.brand { font-weight: 600; color: var(--value); padding: 0 6px; white-space: nowrap; }

.sep { width: 1px; height: 18px; background: var(--edge); margin: 0 4px; }

.tool {
  height: 26px;
  padding: 0 8px;
  background: transparent;
  border: 0;
  border-radius: 2px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.tool.icon { width: 28px; padding: 0; }
.tool svg { width: 16px; height: 16px; }
.tool:hover { background: var(--button-hover); }
.tool:disabled { opacity: .38; background: transparent; }

/* ---------- Workspace ---------- */

.workspace {
  display: grid;
  grid-template-columns: 1fr var(--side-w);
  min-height: 0;
}

.canvas {
  position: relative;
  background: var(--canvas);
  overflow: hidden;
  min-width: 0;
}

.view { position: absolute; inset: 0; }
.view[hidden] { display: none; }

#view-map { cursor: grab; touch-action: none; }
#view-map.panning { cursor: grabbing; }

/* Vector base map. World units are metres; strokes are non-scaling and grow
   gently with zoom through --z (set from JS). */
.basemap, .leaders, .markers { position: absolute; inset: 0; width: 100%; height: 100%; }
.basemap { display: block; background: var(--canvas); --z: 1; }
.basemap path { fill: none; vector-effect: non-scaling-stroke; stroke-linecap: round; stroke-linejoin: round; }

.basemap .land { fill: var(--map-land); }
.basemap .park { fill: var(--map-park); stroke: none; }
.basemap .water { fill: var(--map-water); stroke: none; }
.basemap .waterway { stroke: var(--map-water); stroke-width: calc(2px * var(--z)); }
.basemap .building { fill: var(--map-building); stroke: none; }

.basemap .road-service { stroke: var(--map-road); stroke-width: calc(1px * var(--z)); }
.basemap .road-path { stroke: var(--map-path); stroke-width: .8px; stroke-dasharray: 2 2; }
.basemap .rail { stroke: var(--map-rail); stroke-width: calc(1.2px * var(--z)); stroke-dasharray: 6 3; }

.basemap .casing-local   { stroke: var(--map-casing);         stroke-width: calc(3px * var(--z)); }
.basemap .casing-minor   { stroke: var(--map-casing);         stroke-width: calc(4px * var(--z)); }
.basemap .casing-major   { stroke: var(--map-major-casing);   stroke-width: calc(5.5px * var(--z)); }
.basemap .casing-highway { stroke: var(--map-highway-casing); stroke-width: calc(7px * var(--z)); }
.basemap .road-local     { stroke: var(--map-road);    stroke-width: calc(2px * var(--z)); }
.basemap .road-minor     { stroke: var(--map-road);    stroke-width: calc(3px * var(--z)); }
.basemap .road-major     { stroke: var(--map-road);    stroke-width: calc(4.5px * var(--z)); }
.basemap .road-highway   { stroke: var(--map-highway); stroke-width: calc(6px * var(--z)); }

.basemap .trail-casing { stroke: var(--ink); stroke-width: calc(6px * var(--z)); }
.basemap .trail { stroke: var(--accent); stroke-width: calc(4px * var(--z)); }

.basemap .labels {
  fill: var(--map-label);
  stroke: var(--map-land);
  paint-order: stroke;
  stroke-linejoin: round;
  font-family: inherit;
  letter-spacing: .02em;
  pointer-events: none;
}

.leaders { pointer-events: none; overflow: visible; }
.leaders line { stroke: var(--ink); stroke-width: 1; }
.leaders circle { fill: var(--ink); }
.markers { pointer-events: none; }
.markers[hidden] { display: none; }

.marker {
  position: absolute;
  left: 0;
  top: 0;
  width: 18px;
  height: 18px;
  margin: -9px 0 0 -9px;
  pointer-events: auto;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent);
  color: var(--on-accent);
  border: 1px solid var(--edge);
  border-radius: 2px;
  font-size: 10px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}
.marker:hover { filter: brightness(1.08); }
.marker.selected { box-shadow: 0 0 0 2px var(--select); z-index: 1; }

/* ---------- Side panel ---------- */

.side {
  background: var(--panel);
  border-left: 1px solid var(--edge);
  overflow-y: auto;
  min-height: 0;
}

.section { padding: 12px 12px 14px; border-bottom: 1px solid var(--edge); }
.section[hidden] { display: none; }

.section-head {
  display: flex;
  align-items: center;
  gap: 4px;
  height: 18px;
  margin-bottom: 10px;
  padding: 0;
  background: none;
  border: 0;
  width: 100%;
  text-align: left;
}
.section-title { font-weight: 600; color: var(--value); }
.chevron { width: 12px; height: 12px; color: var(--text-dim); transition: transform .1s ease; }
.collapsible.open .chevron { transform: rotate(90deg); }
.collapsible:not(.open) .section-head { margin-bottom: 0; }
.collapsible:not(.open) .section-body { display: none; }

.section-body { display: flex; flex-direction: column; gap: 6px; }

/* Site list */
.site-list {
  list-style: none;
  margin: 0;
  padding: 0;
  background: var(--well);
  border: 1px solid var(--well-border);
  border-radius: 2px;
}
.site-list button {
  display: grid;
  grid-template-columns: 22px 1fr;
  align-items: center;
  gap: 6px;
  width: 100%;
  height: 26px;
  padding: 0 8px;
  background: transparent;
  border: 0;
  text-align: left;
}
.site-list li + li button { border-top: 1px solid rgba(122, 122, 122, .35); }
.site-list .num { color: var(--text-dim); font-variant-numeric: tabular-nums; text-align: right; }
.site-list .name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.site-list button:hover { background: var(--well-hover); }
.site-list button[aria-current="true"] { background: var(--select); }
.site-list button[aria-current="true"] .num { color: var(--text); }

/* Layer rows */
.layer-list { display: flex; flex-direction: column; }
.layer-row {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  height: 26px;
}
.layer-row label { color: var(--text-dim); }

/* Switch */
.switch {
  position: relative;
  width: 30px;
  height: 16px;
  padding: 0;
  background: var(--well);
  border: 1px solid var(--well-border);
  border-radius: 2px;
}
.switch::after {
  content: "";
  position: absolute;
  top: 1px;
  left: 1px;
  width: 12px;
  height: 12px;
  background: var(--thumb);
  border-radius: 1px;
  transition: transform .12s ease;
}
.switch[aria-checked="true"] { background: var(--accent); }
.switch[aria-checked="true"]::after { background: var(--on-accent); transform: translateX(14px); }

/* Card */
.card {
  background: var(--button);
  border: 1px solid var(--edge);
  border-radius: 2px;
}
.card-head {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 28px;
  padding: 0 8px;
  border-bottom: 1px solid var(--well-border);
}
.chip {
  font-size: 10px;
  font-weight: 700;
  line-height: 15px;
  padding: 0 5px;
  background: var(--accent);
  color: var(--on-accent);
  border-radius: 2px;
  font-variant-numeric: tabular-nums;
}
.card-title { font-weight: 600; color: var(--value); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-body { padding: 8px 10px 10px; display: flex; flex-direction: column; gap: 8px; }

.detail-text { margin: 0; line-height: 1.5; }

.gallery { display: flex; flex-direction: column; gap: 4px; }
.gallery img {
  display: block;
  width: 100%;
  height: auto;
  border: 1px solid var(--edge);
  border-radius: 2px;
  background: var(--well);
}

/* ---------- Status bar ---------- */

.status {
  display: flex;
  align-items: center;
  background: var(--chrome);
  border-top: 1px solid var(--edge);
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
}
.status .cell { display: flex; align-items: center; gap: 6px; padding: 0 10px; height: 100%; min-width: 0; }
.status .cell + .cell { border-left: 1px solid var(--edge); }
.status .cell[hidden] { display: none; }
.status .spacer { flex: 1; }
.status .spacer + .cell { border-left: 1px solid var(--edge); }
.status b { color: var(--value); font-weight: 600; }
.status a { color: inherit; text-decoration: none; }
.status a:hover { color: var(--value); }

.led { width: 7px; height: 7px; border-radius: 50%; background: var(--meter-off); flex: none; }
.led.busy { background: var(--meter); }

.zoom { gap: 2px; }
.zoom button {
  width: 18px;
  height: 18px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 0;
  border-radius: 2px;
}
.zoom button svg { width: 12px; height: 12px; }
.zoom button:hover { background: var(--button-hover); }
.zoom span { min-width: 36px; text-align: center; color: var(--value); }
.zoom[hidden] { display: none; }

/* ---------- Narrow screens: panel below the canvas ---------- */

@media (max-width: 760px) {
  .workspace { grid-template-columns: 1fr; grid-template-rows: 1fr minmax(0, 42%); }
  .side { border-left: 0; border-top: 1px solid var(--edge); display: flex; flex-direction: column; }
  #section-detail { order: -1; } /* selected site first, list below */
  .section { padding: 10px 16px 12px; }
  .brand { display: none; }
  .toolbar-left .sep { display: none; }
  #status-geo, #status-site { display: none; }
}
