/* ===== RESET ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  display: flex;
  flex-direction: column;
}

/* ===== NAV CENTER LABEL ===== */
.knav-center-label {
  flex: 1;
  text-align: center;
  font-size: 12px;
  color: var(--muted);
  font-weight: 500;
}

/* ===== 3-COLUMN LAYOUT ===== */
.app-layout {
  flex: 1;
  display: grid;
  grid-template-columns: 260px 1fr 320px;
  overflow: hidden;
}

/* ===== LEFT SIDEBAR ===== */
.sidebar-left {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.search-wrap { position: relative; padding: 10px 12px; border-bottom: 1px solid var(--border); }
.search-icon { position: absolute; left: 22px; top: 50%; transform: translateY(-50%); font-size: 15px; color: var(--muted); pointer-events: none; }
.search-input { width: 100%; background: var(--surface2); border: 1px solid var(--border); border-radius: var(--radius-sm); color: var(--text); font-family: var(--font); font-size: 12px; padding: 7px 10px 7px 28px; outline: none; transition: var(--t); }
.search-input::placeholder { color: var(--muted); }
.search-input:focus { border-color: var(--border-glow); box-shadow: 0 0 0 2px rgba(78,158,255,0.1); }
.node-list { flex: 1; overflow-y: auto; padding: 4px 0; }
.node-list::-webkit-scrollbar { width: 4px; }
.node-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
.nl-item { display: flex; align-items: center; gap: 8px; padding: 6px 12px; cursor: pointer; transition: var(--t); }
.nl-item:hover { background: rgba(255,255,255,0.04); }
.nl-item.active { background: rgba(78,158,255,0.08); }
.nl-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.nl-label { font-size: 11px; color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; }
.nl-item.active .nl-label { color: var(--text); }
.nl-type { font-size: 9px; color: var(--muted); flex-shrink: 0; font-family: var(--font-mono); }
.sidebar-section { border-top: 1px solid var(--border); padding: 10px 12px; }
.sidebar-section-title { font-size: 10px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); margin-bottom: 8px; }
.legend { display: flex; flex-direction: column; gap: 4px; }
.legend-item { display: flex; align-items: center; gap: 7px; font-size: 11px; color: var(--text-dim); }
.legend-dot { width: 10px; height: 10px; border-radius: 3px; flex-shrink: 0; }
.stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.stat-item { background: var(--surface2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 6px 8px; text-align: center; }
.stat-num { font-size: 18px; font-weight: 800; line-height: 1.1; }
.stat-label { font-size: 9px; color: var(--muted); margin-top: 1px; }

/* ===== CANVAS + TOOLBAR ===== */
.canvas-wrap { position: relative; display: flex; flex-direction: column; overflow: hidden; }
.canvas { flex: 1; }
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 14px; background: linear-gradient(0deg, #080d18, var(--surface)); border-top: 1px solid var(--border); flex-wrap: wrap; }
.toolbar-left, .toolbar-right { display: flex; align-items: center; gap: 8px; }
.toolbar-label { font-size: 11px; color: var(--muted); white-space: nowrap; }
.segmented { display: inline-flex; background: var(--surface2); border: 1px solid var(--border); border-radius: 9px; padding: 2px; gap: 2px; }
.seg { cursor: pointer; padding: 5px 12px; border: none; border-radius: 6px; background: transparent; color: var(--muted); font-family: var(--font); font-size: 11px; font-weight: 500; transition: var(--t); }
.seg:hover { color: var(--text); background: var(--surface3); }
.seg.active { background: var(--surface3); color: var(--text); box-shadow: 0 1px 4px rgba(0,0,0,0.4); }
.tbtn { cursor: pointer; padding: 5px 10px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); color: var(--text-dim); font-family: var(--font); font-size: 11px; font-weight: 500; transition: var(--t); }
.tbtn:hover { border-color: var(--border-glow); color: var(--text); }
.key-hints { font-size: 10px; color: var(--muted); font-family: var(--font-mono); border: 1px solid var(--border); border-radius: 4px; padding: 3px 7px; background: var(--surface2); }

/* ===== RIGHT SIDEBAR ===== */
.sidebar-right { background: var(--surface); border-left: 1px solid var(--border); display: flex; flex-direction: column; overflow: hidden; }
.itabs { display: flex; border-bottom: 1px solid var(--border); padding: 0 4px; background: linear-gradient(180deg, #0a1426, var(--surface)); }
.itab { cursor: pointer; flex: 1; padding: 12px 0; border: none; background: transparent; color: var(--muted); font-family: var(--font); font-size: 12px; font-weight: 600; border-bottom: 2px solid transparent; transition: var(--t); margin-bottom: -1px; }
.itab:hover { color: var(--text); }
.itab.active { color: var(--text); border-bottom-color: var(--primary); }
.itab-panel { display: none; flex: 1; overflow: hidden; flex-direction: column; }
.itab-panel.active { display: flex; }

/* Inspector */
.inspector-empty { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; padding: 32px 20px; text-align: center; }
.empty-glyph { font-size: 40px; color: var(--border); }
.empty-text { font-size: 14px; font-weight: 600; color: var(--text-dim); }
.empty-hint { font-size: 12px; color: var(--muted); }
.inspector-wrap { display: flex; flex-direction: column; height: 100%; overflow: hidden; }
.inspector-head { padding: 14px 14px 10px; border-bottom: 1px solid var(--border); background: var(--surface2); }
.insp-badges { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
.insp-badge { font-size: 10px; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--border); color: var(--muted); background: rgba(255,255,255,0.04); }
.insp-title { font-size: 14px; font-weight: 700; line-height: 1.3; letter-spacing: -0.01em; }
.insp-id { font-family: var(--font-mono); font-size: 10px; color: var(--muted); margin-top: 3px; }
.inspector-body { flex: 1; overflow-y: auto; padding: 12px 14px; }
.inspector-body::-webkit-scrollbar { width: 4px; }
.inspector-body::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
.insp-text { font-size: 12px; color: var(--text-dim); line-height: 1.65; white-space: pre-wrap; margin-bottom: 14px; }
.insp-section { margin-bottom: 12px; }
.insp-section-title { font-size: 9px; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); margin-bottom: 6px; }
.insp-connections { display: flex; flex-direction: column; gap: 4px; }
.insp-conn { display: flex; align-items: center; gap: 6px; padding: 5px 8px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface2); cursor: pointer; font-size: 11px; transition: var(--t); }
.insp-conn:hover { border-color: var(--border-glow); }
.insp-conn-arrow { font-size: 10px; color: var(--muted); flex-shrink: 0; }
.insp-conn-label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-dim); }
.insp-conn-type { font-size: 9px; color: var(--muted); font-family: var(--font-mono); }
.inspector-actions { padding: 10px 14px; border-top: 1px solid var(--border); display: flex; flex-wrap: wrap; gap: 6px; background: rgba(255,255,255,0.02); }
.insp-btn { cursor: pointer; padding: 6px 10px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); color: var(--text-dim); font-family: var(--font); font-size: 11px; font-weight: 500; transition: var(--t); }
.insp-btn:hover { border-color: var(--border-glow); color: var(--text); }
.insp-btn-blue { border-color: rgba(78,158,255,0.4); color: var(--blue); }
.insp-btn-blue:hover { background: rgba(78,158,255,0.08); }

/* Agents */
.agents-wrap { padding: 14px; display: flex; flex-direction: column; gap: 10px; overflow-y: auto; flex: 1; }
.agents-desc { font-size: 12px; color: var(--muted); line-height: 1.6; }
.agents-wrap textarea { width: 100%; background: var(--surface2); border: 1px solid var(--border); border-radius: var(--radius-sm); color: var(--text); font-family: var(--font); font-size: 12px; padding: 9px 10px; resize: vertical; outline: none; transition: var(--t); line-height: 1.5; }
.agents-wrap textarea:focus { border-color: var(--border-glow); }
.agents-wrap textarea::placeholder { color: var(--muted); }
.agent-btns { display: flex; flex-wrap: wrap; gap: 6px; }
.abtn { cursor: pointer; padding: 7px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface2); color: var(--text-dim); font-family: var(--font); font-size: 11px; font-weight: 500; transition: var(--t); }
.abtn:hover { border-color: var(--border-glow); color: var(--text); }
.agent-output { background: rgba(0,0,0,0.25); border: 1px dashed var(--border); border-radius: var(--radius-sm); padding: 10px; font-size: 11px; color: var(--text-dim); line-height: 1.6; min-height: 60px; white-space: pre-wrap; }
.proposal-bar { display: flex; gap: 8px; }
.proposal-bar.hidden { display: none; }
.prop-btn { flex: 1; cursor: pointer; padding: 8px; border-radius: var(--radius-sm); font-family: var(--font); font-size: 12px; font-weight: 600; transition: var(--t); }
.prop-btn-ok { border: 1px solid rgba(52,211,153,0.5); background: rgba(52,211,153,0.08); color: var(--green); }
.prop-btn-ok:hover { background: rgba(52,211,153,0.14); }
.prop-btn-ghost { border: 1px solid var(--border); background: var(--surface); color: var(--muted); }
.prop-btn-ghost:hover { color: var(--text); }

/* ===== ADD-NODE MODAL ===== */
.modal { position: fixed; inset: 0; z-index: 200; display: flex; align-items: center; justify-content: center; padding: 24px; }
.modal.hidden { display: none; }
.modal-bd { position: absolute; inset: 0; background: rgba(6,9,15,0.85); backdrop-filter: blur(8px); cursor: pointer; }
.modal-card { position: relative; background: var(--surface2); border: 1px solid var(--border-glow); border-radius: var(--radius-lg); width: 100%; max-width: 480px; box-shadow: 0 24px 80px rgba(0,0,0,0.7); animation: modal-pop 0.2s cubic-bezier(0.4,0,0.2,1); }
@keyframes modal-pop { from { opacity:0; transform: scale(0.95) translateY(6px); } to { opacity:1; transform: scale(1) translateY(0); } }
.modal-hd { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px 14px; border-bottom: 1px solid var(--border); }
.modal-title { font-size: 15px; font-weight: 700; }
.modal-x { cursor: pointer; background: none; border: 1px solid var(--border); border-radius: 6px; color: var(--muted); font-size: 13px; width: 26px; height: 26px; display: flex; align-items: center; justify-content: center; transition: var(--t); }
.modal-x:hover { border-color: var(--border-glow); color: var(--text); }
.modal-body { padding: 16px 20px; display: flex; flex-direction: column; gap: 12px; }
.mrow { display: flex; gap: 12px; }
.mfield { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.mlabel { font-size: 10px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.minput, .mselect, .mtextarea { background: var(--surface3); border: 1px solid var(--border); border-radius: var(--radius-sm); color: var(--text); font-family: var(--font); font-size: 12px; padding: 8px 10px; outline: none; transition: var(--t); width: 100%; }
.minput:focus, .mselect:focus, .mtextarea:focus { border-color: var(--border-glow); }
.minput::placeholder, .mtextarea::placeholder { color: var(--muted); }
.mtextarea { resize: vertical; line-height: 1.5; }
.mselect { cursor: pointer; appearance: none; }
.modal-ft { display: flex; gap: 8px; padding: 12px 20px 16px; border-top: 1px solid var(--border); }
.mbtn { flex: 1; cursor: pointer; padding: 9px; border-radius: var(--radius-sm); font-family: var(--font); font-size: 13px; font-weight: 600; transition: var(--t); }
.mbtn-blue { border: 1px solid rgba(78,158,255,0.5); background: rgba(78,158,255,0.1); color: var(--blue); }
.mbtn-blue:hover { background: rgba(78,158,255,0.18); }
.mbtn-ghost { border: 1px solid var(--border); background: var(--surface); color: var(--muted); }
.mbtn-ghost:hover { color: var(--text); }

/* ===== MOBILE: drawer sidebars ===== */
@media (max-width: 768px) {
  html, body { overflow: auto; }
  .app-layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto 60vw auto;
    overflow: auto;
    height: auto;
  }
  .sidebar-left, .sidebar-right {
    overflow-y: auto;
    max-height: 50vw;
    border: none;
    border-bottom: 1px solid var(--border);
  }
  .canvas-wrap { min-height: 60vw; }
  .toolbar { flex-wrap: wrap; }
  .knav-center-label { display: none; }
}
