:root {
  --bg: #16181d;
  --panel: #1e2128;
  --panel-2: #262a33;
  --line: #333845;
  --text: #e4e6eb;
  --muted: #8b92a3;
  --accent: #fa9549;
  --accent-2: #ffb47a;
  --ok: #5cc98a;
  --warn: #f2b84b;
  --bad: #ef5f5f;
  --radius: 8px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex; flex-direction: column; overflow: hidden;
}
button, input, select { font: inherit; color: inherit; }
button {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px;
  padding: 5px 10px; cursor: pointer;
}
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); color: #1a1205; border-color: var(--accent); font-weight: 600; }
button.primary:hover { background: var(--accent-2); }
button.danger:hover { border-color: var(--bad); color: var(--bad); }
button.x { background: none; border: none; color: var(--muted); padding: 0 4px; }
button.x:hover { color: var(--bad); }
input, select {
  background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 4px 6px;
}
input:focus, select:focus { outline: none; border-color: var(--accent); }
input.num { width: 76px; }
em { font-style: normal; font-size: 11px; color: var(--accent); border: 1px solid var(--accent); border-radius: 4px; padding: 0 3px; margin-left: 3px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.ok { color: var(--ok); } .warn { color: var(--warn); } .bad { color: var(--bad); }
.hidden { display: none !important; }
h3 { margin: 18px 0 8px; font-size: 15px; }
h4 { margin: 14px 0 6px; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; }

/* top bar */
.topbar {
  display: flex; align-items: center; gap: 18px; flex-wrap: wrap;
  padding: 8px 16px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; color: var(--accent); white-space: nowrap; }
.tabs { display: flex; gap: 4px; }
.tabs button { background: none; border-color: transparent; }
.tabs button.active { background: var(--panel-2); border-color: var(--line); color: var(--accent); font-weight: 600; }
.progress { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-left: auto; }
.progress .tier { display: flex; align-items: center; gap: 8px; }
.progress input[type=range] { width: 150px; accent-color: var(--accent); }
.tier-label { font-weight: 600; min-width: 270px; }
.chk { display: flex; align-items: center; gap: 5px; white-space: nowrap; }
.chk input { accent-color: var(--accent); }

main { flex: 1; min-height: 0; display: flex; }
.tab { display: none; flex: 1; min-height: 0; min-width: 0; }
.tab.active { display: flex; }

/* chips */
.chip { display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; }
.chip i { width: 9px; height: 9px; border-radius: 2px; display: inline-block; flex: none; }

/* builder */
.palette {
  width: 250px; flex: none; background: var(--panel); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; min-height: 0;
}
.palette input { margin: 10px; }
#pal-list { overflow-y: auto; padding: 0 10px 16px; }
.pal-group h4 { margin: 12px 0 6px; }
.pal-item {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; margin-bottom: 5px;
  cursor: grab; user-select: none;
}
.pal-item:hover { border-color: var(--accent); }
.pal-item b { display: block; font-weight: 600; }
.pal-item small { color: var(--muted); font-size: 11px; }
.pal-item.special { border-style: dashed; }
.pal-item.resource b, .pal-item.resource .chip { font-weight: 600; }
.pal-item.resource small { display: block; }

.canvas-wrap { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.toolbar {
  display: flex; align-items: center; gap: 6px; padding: 6px 10px; flex-wrap: wrap;
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.toolbar .sep { width: 1px; height: 20px; background: var(--line); margin: 0 4px; }
.toolbar .hint { color: var(--muted); font-size: 12px; margin-left: 8px; }
#canvas {
  flex: 1; position: relative; overflow: hidden; cursor: grab;
  background-color: var(--bg);
  background-image: radial-gradient(circle, #2c313c 1px, transparent 1.2px);
  background-size: 24px 24px;
}
#canvas:active { cursor: grabbing; }
#world { position: absolute; left: 0; top: 0; width: 0; height: 0; transform-origin: 0 0; }
#links { position: absolute; left: 0; top: 0; width: 1px; height: 1px; overflow: visible; pointer-events: none; }
.canvas-empty {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; color: var(--muted); pointer-events: none;
}
.canvas-empty h2 { color: var(--text); margin: 0 0 6px; }

.link .hit { stroke: transparent; stroke-width: 14; fill: none; pointer-events: stroke; cursor: pointer; }
.wire { fill: none; stroke-width: 3; opacity: .85; pointer-events: none; }
.link.idle .wire { stroke-dasharray: 4 5; opacity: .5; }
.link.over .wire { stroke: var(--warn) !important; stroke-width: 5; }
.link.sel .wire { stroke-width: 5; opacity: 1; filter: drop-shadow(0 0 4px var(--accent)); }
.link text {
  font-size: 11px; fill: var(--text); text-anchor: middle; pointer-events: none;
  paint-order: stroke; stroke: var(--bg); stroke-width: 4px; stroke-linejoin: round;
}
.link.over text { fill: var(--warn); }
.wire.temp { stroke-dasharray: 6 4; stroke-width: 2.5; }

.node {
  position: absolute; width: 250px; background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: 0 6px 20px rgba(0,0,0,.35); cursor: default;
}
.node-source { border-top: 3px solid #6ea8fe; }
.node-sink { border-top: 3px solid var(--ok); }
.node-recipe { border-top: 3px solid var(--accent); }
.node.locked { opacity: .75; border-style: dashed; }
.node-head {
  display: flex; align-items: center; gap: 6px; padding: 6px 8px; cursor: move; user-select: none;
  border-bottom: 1px solid var(--line);
}
.node-head .title { font-weight: 600; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.node-head .mach { font-size: 11px; color: var(--muted); }
.lock { font-size: 11px; color: var(--warn); padding: 4px 8px 0; }
.node-ctrl { display: flex; align-items: center; gap: 6px; padding: 6px 8px; flex-wrap: wrap; }
.node-ctrl select { flex: 1 1 100%; min-width: 0; }
.node-recipe .node-ctrl select { order: 3; }
.node-ctrl input.num { width: 70px; }
.node-body { padding: 2px 0 6px; }
.node-foot { padding: 0 8px 8px; }
.node-foot button { font-size: 12px; padding: 2px 8px; }
.status { padding: 0 8px 4px; font-size: 12px; color: var(--muted); }
.status b { color: var(--text); }
.bar { height: 4px; background: var(--panel-2); border-radius: 2px; overflow: hidden; margin: 2px 0 4px; }
.bar i { display: block; height: 100%; }
.bar.ok i { background: var(--ok); } .bar.warn i { background: var(--warn); } .bar.bad i { background: var(--bad); }

.port { position: relative; display: flex; align-items: center; gap: 6px; padding: 3px 12px; font-size: 12.5px; }
.port.out { justify-content: flex-end; }
.port .pval { margin-left: auto; font-variant-numeric: tabular-nums; }
.port.out .pval { margin-left: 0; }
.port .spare { margin-right: auto; color: var(--warn); font-size: 11px; }
.dot {
  position: absolute; top: 50%; width: 13px; height: 13px; margin-top: -6.5px; border-radius: 50%;
  background: var(--c, #888); border: 2px solid var(--bg); cursor: crosshair; z-index: 2;
}
.port.in .dot { left: -7px; }
.port.out .dot { right: -7px; }
.dot:hover { transform: scale(1.35); box-shadow: 0 0 0 2px var(--accent); }
.port .add { padding: 0 6px; font-size: 12px; line-height: 16px; color: var(--accent); }
.hint-line { font-size: 11px; color: var(--muted); padding: 0 12px 4px; text-align: right; }

.summary {
  width: 270px; flex: none; background: var(--panel); border-left: 1px solid var(--line);
  padding: 4px 14px 20px; overflow-y: auto;
}
.srow { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 2px 0; font-variant-numeric: tabular-nums; }
.srow.total { border-top: 1px solid var(--line); margin-top: 6px; padding-top: 6px; font-weight: 600; }

/* context menu */
.ctx {
  position: fixed; z-index: 50; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: 0 10px 30px rgba(0,0,0,.5); padding: 4px; min-width: 220px; max-height: 60vh; overflow-y: auto;
}
.ctx-title { font-size: 11px; color: var(--muted); padding: 4px 8px; text-transform: uppercase; letter-spacing: .04em; }
.ctx button { display: flex; justify-content: space-between; gap: 10px; width: 100%; text-align: left; background: none; border: none; padding: 6px 8px; border-radius: 5px; }
.ctx button:hover { background: var(--panel-2); }

/* modal */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: flex; align-items: flex-start; justify-content: center; z-index: 40; padding: 5vh 16px; }
.modal-box {
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px; width: min(820px, 100%);
  max-height: 90vh; overflow-y: auto; padding: 0 20px 20px;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; background: var(--panel); padding: 14px 0 8px; z-index: 1; }
.modal-head h2 { margin: 0; font-size: 18px; }
.alt-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 4px 20px; }
.alt-group h4 { color: var(--text); text-transform: none; font-size: 13px; letter-spacing: 0; }
.alt-row { display: flex; gap: 8px; align-items: flex-start; padding: 4px 0; cursor: pointer; }
.alt-row input { margin-top: 3px; accent-color: var(--accent); }
.alt-row small { color: var(--muted); }
.alt-row.locked { opacity: .5; }
#alt-search { width: 100%; margin-bottom: 8px; }
.mam-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 4px 20px; }

.form-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.g-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 6px 16px; }
.g-grid label { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.g-grid select { max-width: 150px; }
.g-checks { display: flex; flex-wrap: wrap; gap: 4px 16px; }
.g-checks label { display: flex; align-items: center; gap: 5px; cursor: pointer; }
.g-checks input { accent-color: var(--accent); }
.g-totals { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.g-actions { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 18px; flex-wrap: wrap; }

.tbl { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.tbl th { text-align: left; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; font-weight: 600; padding: 6px 8px; border-bottom: 1px solid var(--line); }
.tbl td { padding: 6px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.tbl .io { white-space: nowrap; }

/* optimizer */
.opt-form { width: 340px; flex: none; background: var(--panel); border-right: 1px solid var(--line); padding: 4px 18px 24px; overflow-y: auto; }
.opt-form > select { width: 100%; margin-bottom: 6px; }
.in-row { display: flex; gap: 6px; align-items: center; margin-bottom: 6px; }
.in-row select { flex: 1; min-width: 0; }
.in-row input.num { width: 90px; }
.quick { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.quick button { font-size: 12px; padding: 2px 8px; }
.radio { display: flex; align-items: center; gap: 6px; padding: 3px 0; }
.radio input[type=radio] { accent-color: var(--accent); }
.opt-result { flex: 1; min-width: 0; overflow-y: auto; padding: 16px 28px 40px; }
.headline { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.headline .big { font-size: 40px; font-weight: 700; color: var(--accent); font-variant-numeric: tabular-nums; }
.headline button { margin-left: auto; }
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 32px; max-width: 900px; }
.use-row { margin-bottom: 4px; }
.tag { font-size: 10px; background: var(--warn); color: #1a1205; border-radius: 4px; padding: 0 4px; margin-left: 4px; }
.note, .error, .empty { padding: 10px 14px; border-radius: var(--radius); margin-bottom: 14px; }
.note { background: rgba(242,184,75,.12); border: 1px solid rgba(242,184,75,.4); }
.error { background: rgba(239,95,95,.12); border: 1px solid rgba(239,95,95,.4); }
.empty { color: var(--muted); }

/* save map */
.ic { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.ic.big { width: 44px; height: 44px; stroke-width: 1.4; color: var(--accent); }
#tab-map a { color: var(--accent-2); }
#tab-map button, #tab-map .btn { display: inline-flex; align-items: center; gap: 7px; }
#tab-map .btn {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; padding: 5px 10px; cursor: pointer;
}
#tab-map .btn:hover { border-color: var(--accent); }
button.icon-btn { background: none; border: none; color: var(--muted); padding: 4px; border-radius: 6px; }
button.icon-btn:hover { color: var(--text); background: var(--panel-2); }
button.icon-btn.inline { padding: 1px; vertical-align: -4px; }
button.icon-btn.inline .ic { width: 15px; height: 15px; }
i.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
i.ring { display: inline-block; width: 9px; height: 9px; border-radius: 50%; border: 2.5px solid; background: #8b92a3; flex: none; }

/* icon rail */
.map-rail {
  width: 68px; flex: none; background: #121418; border-right: 1px solid var(--line);
  display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 10px 0;
}
.map-rail button {
  position: relative; flex-direction: column; justify-content: center; gap: 4px !important;
  width: 56px; height: 54px; padding: 0; border: 1px solid transparent; border-radius: 10px;
  background: none; color: var(--muted); font-size: 11px; font-weight: 600;
}
.map-rail button .ic { width: 21px; height: 21px; }
.map-rail button:hover:not(:disabled) { color: var(--text); background: var(--panel); border-color: transparent; }
.map-rail button.on { color: var(--accent); background: rgba(250,149,73,.13); }
.map-rail button.on::before { content: ''; position: absolute; left: -6px; top: 12px; bottom: 12px; width: 3px; border-radius: 2px; background: var(--accent); }
.map-rail button:disabled { opacity: .35; cursor: default; }
.map-rail .badge {
  position: absolute; top: 4px; right: 6px; min-width: 17px; height: 17px; padding: 0 4px; border-radius: 9px;
  background: var(--bad); color: #fff; font-size: 10.5px; line-height: 17px; text-align: center; box-shadow: 0 0 0 2px #121418;
}

/* drawer (left) */
.map-drawer { width: 340px; flex: none; background: var(--panel); border-right: 1px solid var(--line); overflow-y: auto; }
.drawer-head {
  position: sticky; top: 0; z-index: 1; display: flex; align-items: center; gap: 9px;
  padding: 12px 10px 11px 16px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.drawer-head > .ic { color: var(--accent); }
.drawer-head h3 { margin: 0; flex: 1; font-size: 15px; }
.drawer-body { padding: 12px 16px 24px; }
.drawer-body > h4:first-child { margin-top: 2px; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-bottom: 12px; }
.stat { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; min-width: 0; }
.stat b { display: block; font-size: 17px; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat span { font-size: 11px; color: var(--muted); }
.stat.bad b { color: var(--bad); } .stat.ok b { color: var(--ok); } .stat.warn b { color: var(--warn); }

.callout { display: flex; gap: 9px; align-items: flex-start; padding: 8px 11px; border-radius: 8px; font-size: 13px; margin-bottom: 12px; }
.callout .ic { margin-top: 1px; }
.callout.ok { background: rgba(92,201,138,.1); border: 1px solid rgba(92,201,138,.35); color: var(--ok); }
.callout.bad { background: rgba(239,95,95,.1); border: 1px solid rgba(239,95,95,.4); color: #f39a9a; }
.callout.bad .ic { color: var(--bad); }

.card { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; margin-bottom: 12px; font-size: 13px; }
.save-title { display: flex; gap: 10px; align-items: flex-start; }
.save-title .ic { color: var(--accent); margin-top: 2px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 2px 12px; margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--line); }
.kv span { color: var(--muted); }
.kv b { font-weight: 500; }
.btn-col { display: flex; flex-direction: column; gap: 6px; }
.btn-col > * { justify-content: center; }
.btn-row { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
.save-list { display: flex; flex-direction: column; gap: 2px; max-height: 260px; overflow-y: auto; }
button.save-row {
  justify-content: space-between; width: 100%; text-align: left; background: none; border-color: transparent; padding: 5px 8px; font-size: 12.5px;
}
button.save-row span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
button.save-row small { color: var(--muted); white-space: nowrap; }
button.save-row:hover { background: var(--panel-2); border-color: transparent; }
button.save-row.on { background: rgba(250,149,73,.12); border-color: rgba(250,149,73,.5); }
.drawer-body code { background: var(--bg); border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; cursor: copy; word-break: break-all; }

/* train cards */
.tcards { display: flex; flex-direction: column; gap: 5px; margin-bottom: 10px; }
button.tcard {
  width: 100%; text-align: left; padding: 8px 10px 8px 12px; gap: 10px; border-radius: 8px;
  border-left: 4px solid var(--c);
}
button.tcard:hover { background: #2c313b; }
button.tcard.on { border-color: var(--accent); border-left-color: var(--c); background: rgba(250,149,73,.1); }
.tcard-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.tcard-main b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tcard-main small { color: var(--muted); font-size: 11.5px; }
.tcard-main small.tnow.stopped { color: #ffb648; }
.tcard-main small.tnow.docked { color: #c9ced8; }
.item-row.on-warn { border-color: #ffb648; background: rgba(255,182,72,.1); }
.map-rail .badge.plan { min-width: 10px; width: 10px; height: 10px; padding: 0; top: 7px; right: 10px; background: #5ee0ff; }

/* planning */
.callout.plan { background: rgba(94,224,255,.08); border: 1px solid rgba(94,224,255,.4); color: #bdefff; }
.callout.plan .ic { color: #5ee0ff; }
.seg { display: flex; flex-wrap: wrap; gap: 4px; }
.seg button { font-size: 12px; padding: 3px 9px; color: var(--muted); border-radius: 14px; }
.seg button.on { color: var(--text); border-color: #5ee0ff; background: rgba(94,224,255,.12); }
.plan-toggle { margin-bottom: 8px; }
.plan-link { background: var(--panel-2); border: 1px solid var(--line); border-left: 3px solid #5ee0ff; border-radius: 8px; padding: 7px 10px; margin-bottom: 6px; }
.plan-link-head { display: flex; align-items: center; gap: 6px; margin-bottom: 6px; font-size: 13px; }
.plan-link-head small { flex: 1; min-width: 0; }
.plan-warn { margin: 6px 0 0; display: flex; gap: 6px; align-items: flex-start; }
.plan-warn .ic { width: 14px; height: 14px; flex: none; margin-top: 1px; }
.plan-tbl { width: 100%; margin-bottom: 12px; table-layout: fixed; }
.plan-tbl th:first-child { width: 46%; }
.plan-tbl td:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.plan-tbl td, .plan-tbl th { padding: 4px 3px; }
.plan-tbl td:not(:first-child), .plan-tbl th:not(:first-child) { text-align: right; white-space: nowrap; }
.plan-tbl tr[data-line] { cursor: pointer; }
.plan-tbl tr[data-line]:hover td { background: var(--panel-2); }
.sug { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; margin-bottom: 6px; font-size: 13px; }
.sug.on, .sug:hover { border-color: #5ee0ff; }
.sug-head { display: flex; gap: 8px; align-items: flex-start; }
.sug-head .ic { color: #5ee0ff; margin-top: 1px; }
.sug-head span { display: flex; flex-direction: column; min-width: 0; }
.sug-head small { color: var(--muted); font-size: 11.5px; }
.sug-trains { display: flex; flex-wrap: wrap; gap: 2px 10px; margin: 6px 0; font-size: 12px; }
.sug-btns { display: flex; gap: 6px; justify-content: flex-end; }
.sug-btns button { font-size: 12px; padding: 3px 9px; }
.now-card p { margin: 0 0 6px; } .now-card p:last-child { margin-bottom: 0; }
.warn-text { color: #ffcf85; }
.warn-text .ic { color: #ffb648 !important; }
button.linkish { display: inline-flex; align-items: center; padding: 0 2px; border: 0; background: none; color: var(--text); font-weight: 600; text-decoration: underline dotted; }
button.linkish:hover { color: var(--accent); background: none; }
.pill { display: inline-flex; align-items: center; gap: 3px; padding: 2px 7px; border-radius: 10px; font-size: 12px; font-weight: 600; flex: none; }
.pill .ic { width: 14px; height: 14px; stroke-width: 2.2; }
.pill.ok { color: var(--ok); background: rgba(92,201,138,.12); }
.pill.bad { color: var(--bad); background: rgba(239,95,95,.14); }

/* list rows (dead track, idle extractors) */
.rows { display: flex; flex-direction: column; gap: 5px; margin-bottom: 10px; }
.item-row {
  display: flex; align-items: flex-start; gap: 9px; width: 100%; text-align: left; padding: 7px 10px;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; font-size: 13px; text-decoration: none;
}
#tab-map a.item-row { color: var(--text); }
.item-row > span { display: flex; flex-direction: column; min-width: 0; }
.item-row small { color: var(--muted); font-size: 11.5px; }
.item-row .ic { margin-top: 1px; }
.item-row.bad .ic { color: var(--bad); } .item-row.warn .ic { color: var(--warn); }
.item-row:hover { border-color: var(--accent); }
.item-row.on { border-color: var(--bad); background: rgba(239,95,95,.1); }

/* node filters and table */
.node-filters { display: flex; flex-direction: column; gap: 6px; margin-bottom: 8px; }
.node-filters .seg { display: flex; flex-wrap: wrap; gap: 4px; }
.node-filters button, .res-chips button { font-size: 12px; padding: 3px 9px; gap: 5px !important; color: var(--muted); border-radius: 14px; }
.node-filters button.on { color: var(--text); border-color: var(--accent); background: rgba(250,149,73,.12); }
.node-filters button.clear { padding: 3px 6px; }
.node-filters button.clear .ic { width: 13px; height: 13px; }
.res-chips { display: flex; flex-wrap: wrap; gap: 4px; }
.res-chips i.rdot { width: 9px; height: 9px; border-radius: 50%; }
.res-tbl td, .res-tbl th { text-align: right; padding: 5px 4px; letter-spacing: 0; }
.res-tbl td:first-child, .res-tbl th:first-child { text-align: left; }
.res-tbl tr[data-item] { cursor: pointer; }
.res-tbl tr[data-item]:hover td { background: var(--panel-2); }
.res-tbl tr.on td { background: rgba(250,149,73,.1); }

/* inspector (right) */
.map-inspect { width: 350px; flex: none; background: var(--panel); border-left: 1px solid var(--line); overflow-y: auto; }
.insp-head {
  position: sticky; top: 0; z-index: 1; background: var(--panel); padding: 12px 12px 12px 16px;
  border-top: 4px solid var(--c); border-bottom: 1px solid var(--line);
}
.insp-kind {
  display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .05em;
}
.insp-kind > .ic { color: var(--c); width: 16px; height: 16px; }
.insp-kind .icon-btn { margin-left: auto; margin-right: -4px; }
.insp-head h3 { margin: 2px 0 0; font-size: 18px; overflow-wrap: anywhere; }
.insp-body { padding: 12px 16px 24px; }
.insp-body > h4:first-child { margin-top: 2px; }
.tags { display: flex; flex-wrap: wrap; gap: 5px; margin-bottom: 4px; }
.tag-pill {
  display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 12px; font-size: 12px;
  background: var(--panel-2); border: 1px solid var(--line);
}
.tag-pill .ic { width: 14px; height: 14px; }
.tag-pill.ok { color: var(--ok); border-color: rgba(92,201,138,.4); }
.tag-pill.bad { color: var(--bad); border-color: rgba(239,95,95,.45); }
.tag-pill.warn { color: var(--warn); border-color: rgba(242,184,75,.45); }
.insp-body p .ic { width: 15px; height: 15px; vertical-align: -3px; color: var(--muted); }

/* timetable: stops joined by legs */
.route { position: relative; margin: 2px 0 10px; }
.route-stop { position: relative; padding: 4px 0 4px 22px; font-weight: 600; font-size: 13px; }
.route-stop::before {
  content: ''; position: absolute; left: 3px; top: 8px; width: 10px; height: 10px; border-radius: 2px;
  background: var(--accent); box-shadow: 0 0 0 2px var(--panel);
}
.route-stop.back { font-weight: 400; }
.route-stop.back::before { background: none; border: 2px solid var(--accent); width: 6px; height: 6px; }
button.route-leg {
  position: relative; display: flex; width: calc(100% - 22px); margin: 2px 0 2px 22px; padding: 4px 9px; font-size: 12.5px;
  background: none; text-align: left;
}
button.route-leg::before { content: ''; position: absolute; left: -15px; top: -6px; bottom: -6px; width: 2px; background: var(--line); }
button.route-leg .ic { width: 15px; height: 15px; stroke-width: 2.2; }
button.route-leg.ok { color: var(--muted); border-color: transparent; }
button.route-leg.ok .ic { color: var(--ok); }
button.route-leg.bad { color: var(--bad); border-color: rgba(239,95,95,.4); background: rgba(239,95,95,.06); }
button.route-leg:hover { border-color: var(--accent); }
button.route-leg.on { background: var(--panel-2); border-color: var(--accent); color: var(--text); }

.diag { background: var(--bg); border: 1px solid var(--line); border-left: 3px solid var(--bad); border-radius: var(--radius); padding: 8px 12px; margin: 12px 0; font-size: 13px; }
.diag.good { border-left-color: var(--ok); }
.diag-title { font-weight: 600; margin-bottom: 2px; }
.diag p { margin: 8px 0; }

/* map and its overlays */
.map-wrap { flex: 1; min-width: 0; position: relative; background: #121418; overflow: hidden; }
.map-wrap.drop { outline: 2px dashed var(--accent); outline-offset: -6px; }
#map-canvas { display: block; touch-action: none; cursor: grab; }
#map-canvas:active { cursor: grabbing; }
.map-tip { position: absolute; z-index: 3; pointer-events: none; background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 5px 8px; font-size: 12px; max-width: 260px; box-shadow: 0 6px 20px rgba(0,0,0,.4); }
.map-hud { position: absolute; top: 10px; z-index: 2; display: flex; gap: 6px; }
.map-hud-tl { left: 10px; max-width: calc(100% - 80px); }
.map-hud-tr { right: 10px; flex-direction: column; }
.hud-chip, .tool-group {
  display: flex; align-items: center; background: rgba(22,24,29,.92); border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 6px 18px rgba(0,0,0,.35); backdrop-filter: blur(4px);
}
.hud-chip { padding: 4px 6px 4px 4px; gap: 2px; font-size: 13px; min-width: 0; }
.hud-chip:not(:has(button)) { padding: 8px 12px; }
button.hud-save { background: none; border: none; padding: 4px 8px; text-align: left; min-width: 0; }
button.hud-save .ic { color: var(--accent); }
button.hud-save > span { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
button.hud-save b, button.hud-save small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
button.hud-save small { color: var(--muted); font-size: 11.5px; }
button.hud-save:hover b { color: var(--accent-2); }
.tool-group { flex-direction: column; padding: 3px; gap: 2px; }
button.tool { width: 34px; height: 34px; justify-content: center; padding: 0; background: none; border: none; border-radius: 7px; color: var(--muted); }
button.tool:hover { color: var(--text); background: var(--panel-2); }
button.tool.on { color: var(--accent); }
.tool-group:first-child button.tool:not(.on) { opacity: .5; }

.map-empty { position: absolute; inset: 0; z-index: 2; display: flex; align-items: center; justify-content: center; padding: 20px; pointer-events: none; }
.empty-card {
  pointer-events: auto; max-width: 440px; text-align: center; padding: 26px 28px 20px;
  background: rgba(30,33,40,.95); border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 20px 50px rgba(0,0,0,.5);
}
.empty-card h2 { margin: 10px 0 6px; font-size: 20px; }
.empty-card .btn-row { margin: 16px 0 10px; }
.empty-card .note, .empty-card .error { text-align: left; }

.map-legend { position: absolute; z-index: 2; left: 10px; bottom: 10px; right: 60px; max-width: max-content; background: rgba(22,24,29,.92); border: 1px solid var(--line); border-radius: 10px; padding: 7px 11px; pointer-events: none; box-shadow: 0 6px 18px rgba(0,0,0,.35); }
.map-legend div { display: flex; flex-wrap: wrap; gap: 3px 12px; }
.map-legend span { display: inline-flex; align-items: center; gap: 5px; }
.map-legend i { width: 14px; height: 3px; display: inline-block; }
.map-legend i.dash { height: 0; border-top: 2px dashed; }
.map-legend i.sq { width: 8px; height: 8px; background: var(--accent); }
.map-legend i.wait { width: 9px; height: 9px; border: 2px solid #ffb648; border-radius: 50%; }
.map-legend i.plan { width: 16px; height: 7px; border-radius: 4px; background: rgba(94,224,255,.45); box-shadow: inset 0 0 0 2px rgba(94,224,255,.2); }
.map-legend i.lines { width: 16px; height: 9px; background: linear-gradient(#4f9cf5 0 33%, #f5a623 33% 66%, #2ec4b6 66%); }
.map-legend b.chev { font-size: 16px; line-height: 10px; }
.map-legend i.ring { width: 8px; height: 8px; }
.map-legend i.badge { width: 8px; height: 8px; border-radius: 50%; background: #fff; border: 1px solid #000; }
.map-legend .credit { font-size: 10px; margin-top: 2px; }

@media (max-width: 900px) {
  body { overflow: auto; }
  main, .tab.active { flex-direction: column; }
  .palette, .summary, .opt-form, .map-drawer, .map-inspect { width: auto; border: none; border-bottom: 1px solid var(--line); }
  .map-drawer, .map-inspect { max-height: 45vh; }
  .map-rail { width: auto; flex-direction: row; justify-content: center; padding: 6px; border: none; border-bottom: 1px solid var(--line); }
  .map-rail button.on::before { left: 12px; right: 12px; top: auto; bottom: -6px; width: auto; height: 3px; }
  .map-wrap { min-height: 70vh; }
  .palette { max-height: 220px; }
  .canvas-wrap { min-height: 70vh; }
  .tier-label { min-width: 0; }
  .progress { margin-left: 0; }
  .cols, .g-totals { grid-template-columns: 1fr; }
  .toolbar .hint { display: none; }
}
