:root {
  --bg: #0f172a; --panel: #111827; --panel2: #1f2937; --line: #334155; --fg: #e5e7eb; --muted: #94a3b8;
  --accent: #22d3ee; --accent2: #0891b2; --ok: #22c55e; --warn: #f59e0b; --bad: #ef4444;
  --radius: 8px; font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--fg); font-size: 14px; }
#app { display: grid; grid-template-columns: 330px 1fr auto; grid-template-rows: 52px 1fr; height: 100vh; }
#top { grid-column: 1 / -1; display: flex; align-items: center; gap: 16px; padding: 0 14px; background: var(--panel); border-bottom: 1px solid var(--line); }
.brand { font-weight: 700; white-space: nowrap; }
.brand small { color: var(--muted); font-weight: 400; margin-left: 6px; }
.logo { color: var(--accent); }
.search { position: relative; flex: 1; max-width: 560px; }
.search input { width: 100%; }
#search-results { position: absolute; top: 100%; left: 0; right: 0; z-index: 30; background: var(--panel2); border: 1px solid var(--line); border-radius: var(--radius); margin-top: 4px; max-height: 320px; overflow: auto; }
#search-results:empty { display: none; }
#search-results button { display: block; width: 100%; text-align: left; padding: 8px 10px; background: none; border: 0; color: var(--fg); cursor: pointer; border-bottom: 1px solid var(--line); }
#search-results button:hover { background: #273449; }
.top-actions { display: flex; gap: 6px; margin-left: auto; }

#left { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.tabs { display: flex; border-bottom: 1px solid var(--line); }
.tabs button { flex: 1; padding: 10px 2px; background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 12.5px; border-bottom: 2px solid transparent; }
.tabs button.active { color: var(--fg); border-bottom-color: var(--accent); }
.tab-body { overflow: auto; padding: 12px; flex: 1; }
.tab-body h4 { margin: 16px 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.tab-body h4:first-child { margin-top: 0; }

#map-wrap { position: relative; min-width: 0; }
#map { position: absolute; inset: 0; }
#banner { position: absolute; top: 10px; left: 50%; transform: translateX(-50%); z-index: 5; background: rgba(17, 24, 39, .94); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 12px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; max-width: calc(100% - 120px); box-shadow: 0 6px 20px rgba(0,0,0,.35); }
#status { position: absolute; bottom: 0; left: 0; right: 0; z-index: 4; background: rgba(15, 23, 42, .85); color: var(--muted); font-size: 12px; padding: 3px 10px; display: flex; gap: 18px; pointer-events: none; }
.maplibregl-ctrl-bottom-right, .maplibregl-ctrl-bottom-left { bottom: 22px; }

#right { width: 360px; background: var(--panel); border-left: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
#right[hidden] { display: none; }
.panel-head { display: flex; align-items: center; justify-content: space-between; padding: 8px 12px; border-bottom: 1px solid var(--line); }
.panel-head h3 { margin: 0; font-size: 15px; }
#props { padding: 12px; overflow: auto; flex: 1; }

.btn { background: var(--panel2); color: var(--fg); border: 1px solid var(--line); border-radius: var(--radius); padding: 6px 10px; cursor: pointer; font: inherit; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; }
.btn:hover { border-color: var(--accent2); }
.btn.primary { background: var(--accent2); border-color: var(--accent2); color: #fff; }
.btn.danger { border-color: #7f1d1d; color: #fecaca; }
.btn.ghost { background: transparent; }
.btn.xs { padding: 1px 6px; font-size: 12px; }
.btn.active { background: #0e3a47; border-color: var(--accent); color: #fff; }
input, select, textarea { background: #0b1220; color: var(--fg); border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; font: inherit; min-width: 0; }
textarea { width: 100%; min-height: 60px; resize: vertical; }
input[type=range] { padding: 0; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }
.field > span { font-size: 12px; color: var(--muted); }
.field small { color: var(--muted); font-size: 11.5px; }
.field input, .field select { width: 100%; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row > .field { flex: 1; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.muted { color: var(--muted); }
.check { display: flex; align-items: center; gap: 8px; padding: 4px 0; cursor: pointer; }
.swatch { width: 12px; height: 12px; border-radius: 3px; display: inline-block; flex: none; }
.tool-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.tool-grid .btn { justify-content: flex-start; padding: 8px; }
.tool-grid kbd, .kbd { margin-left: auto; font-size: 11px; color: var(--muted); border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; }
.hint { background: #0b1220; border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; color: var(--muted); font-size: 12.5px; line-height: 1.5; }
.hint b { color: var(--fg); }
.stat { display: flex; justify-content: space-between; padding: 4px 0; border-bottom: 1px dashed var(--line); }
table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
td, th { padding: 4px 6px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { color: var(--muted); font-weight: 500; }
td.num { text-align: right; white-space: nowrap; }
.list-item { display: flex; align-items: center; gap: 8px; width: 100%; padding: 6px; background: none; border: 0; color: var(--fg); text-align: left; cursor: pointer; border-radius: 6px; }
.list-item:hover { background: var(--panel2); }
.list-item small { margin-left: auto; color: var(--muted); }
.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; background: var(--panel2); border: 1px solid var(--line); }
.badge.ok { border-color: var(--ok); color: #bbf7d0; }
.badge.bad { border-color: var(--bad); color: #fecaca; }
.budget td:last-child { text-align: right; }

#toast { position: fixed; bottom: 36px; left: 50%; transform: translateX(-50%) translateY(20px); opacity: 0; transition: .2s; background: var(--panel2); border: 1px solid var(--line); padding: 10px 16px; border-radius: var(--radius); z-index: 100; pointer-events: none; max-width: 80vw; }
#toast.show { opacity: 1; transform: translateX(-50%); }
#toast.warn { border-color: var(--warn); }
#toast.error { border-color: var(--bad); }

.modal-back { position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 50; display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; width: min(560px, 100%); max-height: 100%; display: flex; flex-direction: column; }
.modal.wide { width: min(1200px, 100%); height: 100%; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.modal-head h3 { margin: 0; font-size: 16px; }
.modal-body { padding: 14px; overflow: auto; flex: 1; display: flex; flex-direction: column; min-height: 0; }
.modal-body > div { display: flex; flex-direction: column; min-height: 0; flex: 1; }

.splice-tools { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding-bottom: 10px; border-bottom: 1px solid var(--line); flex: none !important; flex-direction: row !important; }
.splice-tools .sep { width: 1px; height: 22px; background: var(--line); }
.splice-tools .grow { flex: 1; }
.splice-wrap { position: relative; overflow: auto; flex: 1; min-height: 240px; margin: 10px 0; background: #0b1220; border-radius: var(--radius); }
.splice { display: grid; grid-template-columns: 1fr minmax(160px, .7fr) 1fr; gap: 60px; padding: 16px 20px; position: relative; z-index: 1; min-width: 720px; }
.splice .col { display: flex; flex-direction: column; gap: 14px; align-items: flex-start; }
.splice .col:last-child { align-items: flex-end; }
.splice .mid { align-items: center; }
.splice-svg { position: absolute; top: 0; left: 0; pointer-events: none; z-index: 2; }
.fusion-line { fill: none; stroke-width: 2.5; opacity: .9; }
.cable-block, .splitter-block { background: var(--panel2); border: 1px solid var(--line); border-radius: var(--radius); padding: 6px; min-width: 170px; }
.cable-head { display: flex; flex-direction: column; gap: 2px; padding: 2px 4px 6px; }
.cable-head small { color: var(--muted); }
.splitter-block .cable-head { flex-direction: row; justify-content: space-between; align-items: center; }
.fiber-row { display: flex; align-items: center; gap: 4px; }
.col:last-child .fiber-row { justify-content: flex-end; }
.tube { width: 6px; align-self: stretch; border-radius: 2px; }
.port { display: flex; align-items: center; gap: 6px; padding: 2px 8px; margin: 1px 0; background: #0b1220; color: var(--fg); border: 1px solid transparent; border-radius: 5px; cursor: pointer; font-size: 12px; min-width: 84px; }
.port.right { flex-direction: row-reverse; }
.port i { width: 12px; height: 12px; border-radius: 50%; border: 1px solid #475569; }
.port:hover { border-color: var(--accent2); }
.port.used { opacity: .65; border-color: #334155; }
.port.pending { border-color: var(--accent); background: #0e3a47; opacity: 1; }
.split-body { display: flex; justify-content: space-between; align-items: center; gap: 16px; }
.split-outs { display: flex; flex-direction: column; }
.fusion-list { flex: none !important; max-height: 30%; overflow: auto; }
.fusion-list h4 { margin: 4px 0; }

@media (max-width: 900px) {
  #app { grid-template-columns: 1fr; grid-template-rows: 52px 45vh 1fr; }
  #left { order: 3; }
  #right { position: fixed; right: 0; top: 52px; bottom: 0; width: min(360px, 100%); z-index: 20; }
  .brand small, .top-actions a { display: none; }
}
