:root {
  --bg: #0f1216; --panel: #171b21; --panel-2: #1e242c; --line: #2a313b; --text: #e6eaf0; --muted: #8b95a1;
  --accent: #4da3ff; --accent-ink: #04111f; --danger: #ef6a5b; --ok: #54c58a;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); overflow: hidden; }
body { font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, system-ui, sans-serif; -webkit-font-smoothing: antialiased; }
[hidden] { display: none !important; }
.muted { color: var(--muted); } .small { font-size: 12px; } .spacer { flex: 1; }
.error { color: var(--danger); min-height: 1.2em; margin: 0; font-size: 13px; }
code { font-family: var(--mono); font-size: 12px; background: var(--panel-2); padding: 1px 5px; border-radius: 4px; }
a { color: var(--accent); cursor: pointer; text-decoration: none; } a:hover { text-decoration: underline; }

.brand { display: flex; align-items: center; gap: 9px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; font-size: 13px; }
.brand-lg { font-size: 17px; }
.logo { width: 20px; height: 16px; position: relative; }
.logo::before, .logo::after { content: ""; position: absolute; width: 9px; height: 7px; border: 2px solid var(--accent); border-radius: 2px; }
.logo::before { left: 0; top: 0; } .logo::after { right: 0; bottom: 0; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 34px; padding: 0 12px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel-2); color: var(--text); font: inherit; font-weight: 550; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: #46515f; }
.btn.sm { height: 28px; padding: 0 10px; font-size: 12.5px; }
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; } .btn-primary:hover { filter: brightness(1.08); border-color: transparent; }
.btn-primary:disabled { opacity: .45; cursor: default; }
.btn-danger { color: var(--danger); }
.icon-btn { width: 30px; height: 30px; border-radius: 7px; border: 0; background: transparent; color: var(--muted); font-size: 16px; cursor: pointer; }
.icon-btn.sm { width: 24px; height: 24px; font-size: 13px; } .icon-btn:hover { background: var(--panel-2); color: var(--text); }
input, select, textarea { font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 7px; padding: 6px 9px; min-width: 0; }
input, select { height: 32px; } textarea { resize: vertical; width: 100%; }
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: -1px; }
input[type=checkbox] { height: auto; accent-color: var(--accent); }

/* gate */
.gate { height: 100%; display: grid; place-items: center; padding: 24px; }
.gate-card { width: min(380px, 100%); display: grid; gap: 14px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 28px; }
.gate-card label { display: grid; gap: 6px; font-size: 13px; color: var(--muted); } .gate-card input { height: 40px; } .gate-card p { margin: 0; } .gate-card .btn { height: 40px; }

/* layout */
#app { height: 100%; display: flex; flex-direction: column; }
.top { display: flex; align-items: center; gap: 8px; padding: 9px 14px; border-bottom: 1px solid var(--line); background: var(--panel); flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
.top > * { flex: none; }
.map-btn { max-width: 220px; } #map-name { overflow: hidden; text-overflow: ellipsis; max-width: 170px; }
.status { font-size: 12px; min-width: 90px; } .status.ok { color: var(--ok); } .status.bad { color: var(--danger); }
#search { width: 260px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { height: 32px; padding: 0 11px; border: 0; border-right: 1px solid var(--line); background: var(--panel-2); color: var(--muted); font: inherit; font-weight: 550; cursor: pointer; }
.seg button:last-child { border-right: 0; } .seg button:hover { color: var(--text); }
.seg.layers button.on { color: var(--text); background: #26405e; }
.seg.layers button:not(.on) { text-decoration: line-through; opacity: .6; }
.banner { padding: 9px 16px; background: #3a2a14; color: #ffd9a0; border-bottom: 1px solid #5a4020; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; font-size: 13px; }
.shell { flex: 1; min-height: 0; display: grid; grid-template-columns: 250px 1fr 410px; }
.side { background: var(--panel); overflow-y: auto; min-height: 0; }
.side.left { border-right: 1px solid var(--line); } .side.right { border-left: 1px solid var(--line); padding: 14px 16px 30px; }

/* canvas */
.canvas { position: relative; overflow: hidden; background-color: var(--bg); background-image: radial-gradient(circle, #2a323d 1.1px, transparent 1.2px); cursor: grab; touch-action: none; user-select: none; }
.canvas.panning { cursor: grabbing; }
.world { position: absolute; left: 0; top: 0; transform-origin: 0 0; will-change: transform; }
#gboxes, #nodes { position: absolute; left: 0; top: 0; width: 0; height: 0; }
.edges { position: absolute; left: 0; top: 0; overflow: visible; pointer-events: none; }
.eg .ehit { fill: none; stroke: transparent; stroke-width: 14px; pointer-events: stroke; cursor: pointer; }
.edge { fill: none; stroke-width: 1.6px; vector-effect: non-scaling-stroke; opacity: .75; }
.edge.tmp { opacity: 1; stroke-dasharray: 5 4; }
.eg.hl .edge, .eg.sel .edge { opacity: 1; stroke-width: 2.4px; } .eg.faded .edge { opacity: .14; } .eg:hover .edge { opacity: 1; }
.elabel { fill: var(--text); font-size: 12px; text-anchor: middle; paint-order: stroke; stroke: var(--bg); stroke-width: 4px; pointer-events: none; }

.node { position: absolute; background: var(--panel); border: 1px solid var(--line); border-top: 3px solid var(--c); border-radius: 9px; box-shadow: 0 4px 14px rgba(0,0,0,.35); cursor: pointer; }
.node:hover { border-color: #46515f; border-top-color: var(--c); }
.node.sel { box-shadow: 0 0 0 2px var(--accent), 0 6px 20px rgba(0,0,0,.5); }
.node.hit { box-shadow: 0 0 0 2px #ffd166, 0 4px 14px rgba(0,0,0,.35); } .node.dim, .gcard.dim { opacity: .2; }
.n-head { display: flex; align-items: center; gap: 7px; padding: 8px 10px 7px; }
.n-title { font-weight: 650; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.n-sub { color: var(--muted); font-size: 11px; } .n-path { padding: 0 10px 9px; font: 12px var(--mono); color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.n-notes { padding: 0 10px 9px; font-size: 12px; color: var(--muted); }
.badge { font: 10.5px var(--mono); color: var(--muted); background: var(--panel-2); border-radius: 4px; padding: 1px 5px; }
.chip { display: inline-block; min-width: 20px; text-align: center; font-size: 10px; font-weight: 800; letter-spacing: .03em; padding: 2px 5px; border-radius: 4px; color: #05121f; background: #8b95a1; }
.chip.page { background: #4da3ff; } .chip.screen { background: #9b7bff; } .chip.api { background: #f2a93b; } .chip.service { background: #ef6a5b; } .chip.table { background: #3fc7a5; } .chip.note { background: #e0c75a; }
.cols { border-top: 1px solid var(--line); padding: 3px 0 4px; }
.col { display: flex; align-items: center; gap: 6px; height: 21px; padding: 0 10px; font-size: 12px; }
.col:hover { background: var(--panel-2); } .col.more { color: var(--muted); font-style: italic; }
.col .k { width: 20px; font-size: 9px; font-weight: 800; color: var(--muted); } .k.pk { color: #ffd166; } .k.fk { color: #3fc7a5; } .k.uq { color: #9b7bff; }
.cn { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } .ct { font: 10.5px var(--mono); color: var(--muted); max-width: 45%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.t-note { background: #3b3820; border-color: #5b5630; border-top-color: #e0c75a; } .note-text { padding: 10px 12px; font-size: 13px; white-space: pre-wrap; }
.handle { position: absolute; right: -7px; top: 13px; width: 13px; height: 13px; border-radius: 50%; background: var(--accent); border: 2px solid var(--bg); opacity: 0; cursor: crosshair; }
.node:hover .handle, .node.sel .handle { opacity: 1; } .node.drop-target, .gcard.drop-target { box-shadow: 0 0 0 2px #ffd166; }

.gbox { position: absolute; border: 1.5px dashed color-mix(in srgb, var(--c) 45%, transparent); background: color-mix(in srgb, var(--c) 5%, transparent); border-radius: 18px; pointer-events: none; }
.gbox.sel { border-style: solid; border-color: var(--c); }
.glabel { position: absolute; left: 14px; top: 11px; display: flex; align-items: center; gap: 8px; pointer-events: auto; cursor: grab; color: var(--c); font-weight: 700; font-size: 14px; padding: 2px 6px 2px 2px; border-radius: 6px; }
.glabel:hover { background: color-mix(in srgb, var(--c) 14%, transparent); }
.gfold { border: 0; background: transparent; color: var(--c); cursor: pointer; font-size: 14px; padding: 0 3px; }
.gkind { font-size: 11px; font-weight: 500; color: var(--muted); }
.gcard { position: absolute; width: 250px; padding: 14px 16px 14px; background: var(--panel); border: 1px solid var(--line); border-left: 6px solid var(--c); border-radius: 12px; box-shadow: 0 6px 20px rgba(0,0,0,.4); cursor: grab; }
.gcard.sel { box-shadow: 0 0 0 2px var(--accent), 0 6px 20px rgba(0,0,0,.4); }
.g-kind { font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); } .g-name { font-size: 18px; font-weight: 700; margin: 2px 0; } .g-count { font-size: 12.5px; color: var(--muted); }
.g-open { margin-top: 10px; height: 28px; padding: 0 11px; border-radius: 7px; border: 1px solid var(--line); background: var(--panel-2); color: var(--text); font: inherit; font-size: 12.5px; cursor: pointer; }
.canvas.lod-low .cols, .canvas.lod-low .n-notes { display: none; }
.canvas.lod-low .n-title { font-size: 15px; } .canvas.lod-low .node { border-top-width: 5px; }
.canvas.lod-min .n-path, .canvas.lod-min .n-sub, .canvas.lod-min .badge, .canvas.lod-min .handle { display: none; }
.canvas.lod-min .n-title { font-size: 24px; } .canvas.lod-min .glabel { font-size: 30px; } .canvas.lod-min .gkind { display: none; }
.canvas.lod-min .edge { opacity: .5; }

.empty { position: absolute; left: 50%; top: 42%; transform: translate(-50%, -50%); text-align: center; max-width: 420px; }
.empty h2 { margin: 0 0 6px; font-size: 22px; } .empty-actions { display: flex; gap: 8px; justify-content: center; margin-top: 16px; }
.legend { position: absolute; left: 12px; bottom: 12px; display: flex; gap: 12px; flex-wrap: wrap; font-size: 11.5px; color: var(--muted); background: rgba(15,18,22,.85); padding: 6px 10px; border-radius: 8px; border: 1px solid var(--line); pointer-events: none; }
.legend span { display: inline-flex; align-items: center; gap: 5px; } .legend i { width: 14px; height: 3px; border-radius: 2px; display: inline-block; }
.zoom { position: absolute; right: 12px; bottom: 12px; display: flex; align-items: center; background: var(--panel); border: 1px solid var(--line); border-radius: 9px; overflow: hidden; }
.zoom button { height: 32px; min-width: 32px; border: 0; background: transparent; color: var(--text); font: inherit; font-size: 16px; cursor: pointer; } .zoom button:hover { background: var(--panel-2); }
.zoom span { font: 12px var(--mono); color: var(--muted); min-width: 46px; text-align: center; }

/* outline */
.o-head { padding: 12px 14px 8px; font-weight: 700; display: flex; justify-content: space-between; position: sticky; top: 0; background: var(--panel); z-index: 1; }
.o-note { padding: 0 14px 8px; font-size: 12px; }
.o-ghead { display: flex; align-items: center; gap: 6px; padding: 5px 8px 5px 6px; cursor: pointer; font-weight: 600; } .o-ghead:hover, .o-ghead.sel { background: var(--panel-2); }
.o-ghead i { width: 9px; height: 9px; border-radius: 3px; flex: none; } .o-gname { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.o-fold, .o-eye { border: 0; background: transparent; color: var(--muted); cursor: pointer; width: 20px; padding: 0; } .o-eye:hover, .o-fold:hover { color: var(--text); }
.o-item { display: flex; align-items: center; gap: 7px; padding: 3px 12px 3px 28px; cursor: pointer; font-size: 13px; } .o-item:hover { background: var(--panel-2); } .o-item.sel { background: #1f3550; }
.o-item .chip { font-size: 9px; padding: 1px 4px; min-width: 18px; } .o-t { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.o-item em { font-style: normal; font-size: 11px; color: #ffd166; max-width: 90px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* detail panel */
.p-head { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; font-size: 15px; } .dot { width: 11px; height: 11px; border-radius: 3px; display: inline-block; }
.side.right label { display: grid; gap: 4px; font-size: 12px; color: var(--muted); margin-bottom: 10px; }
.side.right label.check { display: flex; gap: 7px; align-items: center; margin: 4px 0 8px; font-size: 12.5px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; } .row2 label.narrow { grid-column: auto; }
.side.right section { border-top: 1px solid var(--line); margin-top: 14px; padding-top: 12px; } .side.right h4 { margin: 0 0 8px; font-size: 13px; }
.crow { display: grid; grid-template-columns: 1.15fr 1fr 52px 50px 1.1fr 24px; gap: 4px; margin-bottom: 8px; align-items: center; }
.crow input, .crow select { height: 28px; padding: 3px 6px; font-size: 12px; } .crow .c-type { font-family: var(--mono); font-size: 11.5px; }
.crow .c-null { display: flex; align-items: center; gap: 3px; font-size: 11px; margin: 0; } .crow .c-note { grid-column: 1 / -1; height: 24px; font-size: 11.5px; color: var(--muted); border-color: transparent; background: transparent; padding-left: 6px; }
.crow:hover .c-note, .crow .c-note:focus { border-color: var(--line); background: var(--bg); }
.btnrow { display: flex; gap: 8px; flex-wrap: wrap; margin: 8px 0; } .p-foot { margin-top: 22px; border-top: 1px solid var(--line); padding-top: 14px; }
.conn { display: flex; align-items: center; gap: 7px; padding: 3px 0; font-size: 13px; } .conn .arrow { color: var(--muted); } .conn .kind { font-size: 11.5px; width: 56px; } .conn a { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.addconn { display: grid; grid-template-columns: 105px 1fr auto; gap: 6px; margin-top: 8px; } .addconn select { height: 28px; padding: 2px 6px; font-size: 12.5px; }
.snip { margin-bottom: 12px; } .snip-head { display: grid; grid-template-columns: 1fr 66px 24px 24px 24px; gap: 4px; margin-bottom: 4px; align-items: center; } .snip-head input, .snip-head select { height: 26px; font-size: 12px; padding: 2px 6px; }
textarea.code { font: 12px/1.45 var(--mono); tab-size: 2; white-space: pre; overflow: auto; background: #0b0e12; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 4px; } .stats div { background: var(--panel-2); border-radius: 8px; padding: 8px 10px; } .stats b { display: block; font-size: 20px; } .stats span { font-size: 11px; color: var(--muted); }
.grow { display: flex; align-items: center; gap: 8px; padding: 3px 0; } .grow i { width: 10px; height: 10px; border-radius: 3px; } .grow a { flex: 1; }
.swatches { display: flex; gap: 7px; margin: 4px 0 12px; } .sw { width: 22px; height: 22px; border-radius: 6px; border: 2px solid transparent; cursor: pointer; } .sw.on { border-color: #fff; }

/* dialogs, menus */
.modal { width: min(780px, 94vw); max-height: 92vh; padding: 0; border: 1px solid var(--line); border-radius: 14px; background: var(--panel); color: var(--text); } .modal.narrow { width: min(520px, 94vw); }
.modal::backdrop { background: rgba(4,6,9,.7); } .modal-in { padding: 18px 20px 16px; display: grid; gap: 10px; }
.modal header { display: flex; justify-content: space-between; align-items: center; } .modal h2 { margin: 0; font-size: 18px; } .modal p { margin: 0; }
#imp-text { height: 230px; font: 12px/1.45 var(--mono); white-space: pre; background: #0b0e12; }
.imp-opts { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; } .imp-opts label { display: grid; gap: 4px; font-size: 12px; color: var(--muted); } .imp-opts label.check { display: flex; align-items: center; gap: 7px; grid-column: 1 / -1; font-size: 12.5px; }
.imp-page { grid-column: 1 / -1; display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }
.imp-preview { background: var(--panel-2); border-radius: 9px; padding: 10px 12px; font-size: 13px; min-height: 44px; max-height: 150px; overflow: auto; }
.chips { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 7px; } .chips span { font: 11px var(--mono); background: var(--bg); border: 1px solid var(--line); padding: 1px 6px; border-radius: 5px; color: #aab4c0; } .chips.api span { color: #f2c06b; }
.modal footer { display: flex; align-items: center; gap: 8px; }
.hrow { display: flex; align-items: center; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line); } .hrow span:first-child { flex: 1; }
.menu { position: fixed; z-index: 80; min-width: 210px; max-height: 70vh; overflow: auto; background: var(--panel); border: 1px solid #3a4452; border-radius: 10px; padding: 5px; box-shadow: 0 14px 40px rgba(0,0,0,.5); }
.menu button { display: flex; width: 100%; justify-content: space-between; gap: 18px; text-align: left; border: 0; background: transparent; color: var(--text); font: inherit; padding: 7px 10px; border-radius: 6px; cursor: pointer; } .menu button:hover { background: var(--panel-2); }
.menu button.danger { color: var(--danger); } .menu em { font-style: normal; color: var(--muted); font-size: 12px; } .menu hr { border: 0; border-top: 1px solid var(--line); margin: 5px 4px; }
.drop { position: fixed; inset: 0; z-index: 90; display: grid; place-items: center; background: rgba(8,10,14,.8); pointer-events: none; }
.drop div { border: 2px dashed var(--accent); color: var(--accent); border-radius: 18px; padding: 46px 70px; font-weight: 650; font-size: 20px; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 100; background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-weight: 550; box-shadow: 0 10px 30px rgba(0,0,0,.4); max-width: 90vw; }

@media (max-width: 1100px) { .shell { grid-template-columns: 0 1fr 360px; } .side.left { display: none; } }
@media (max-width: 760px) { .shell { grid-template-columns: 1fr; grid-template-rows: 1fr 46%; } .side.right { border-left: 0; border-top: 1px solid var(--line); } #search { width: 150px; } }

.crow input[type=checkbox], .side.right input[type=checkbox] { width: 14px; height: 14px; padding: 0; }
