/* ═══════════════════════════════════════════════════════
   HAVEN WORKSPACE — style.css
═══════════════════════════════════════════════════════ */

/* ── TOKENS ── */
:root {
  --bg:        #0d1117;
  --surface:   #161b22;
  --surface2:  #21262d;
  --border:    #30363d;
  --text:      #e6edf3;
  --muted:     #8b949e;
  --accent:    #58a6ff;
  --radius:    10px;
  --font:      'Inter','Segoe UI',system-ui,sans-serif;
  --sidebar-w: 300px;
}
[data-theme="light"] {
  --bg:       #f6f8fa;
  --surface:  #ffffff;
  --surface2: #f0f3f6;
  --border:   #d0d7de;
  --text:     #1f2328;
  --muted:    #57606a;
  --accent:   #0969da;
}

/* ── RESET ── */
*,*::before,*::after{box-sizing:border-box;margin:0;padding:0}
html,body{height:100%;overflow:hidden;font-family:var(--font);background:var(--bg);color:var(--text);font-size:14px}
button{font-family:inherit;font-size:13px;cursor:pointer}
input,select,textarea{font-family:inherit;font-size:13px}
.hidden{display:none!important}

/* ── APP SHELL ── */
#app{display:grid;grid-template-rows:56px 1fr;height:100vh}

/* ── HEADER ── */
#header{
  background:var(--surface);border-bottom:1px solid var(--border);
  display:flex;align-items:center;gap:10px;padding:0 14px;z-index:100;
  flex-shrink:0;
}
.logo-wrap{display:flex;align-items:center;gap:10px;flex-shrink:0}
.logo-icon{width:28px;height:28px}
.logo-text{font-weight:700;font-size:15px;letter-spacing:-.3px}
.logo-sub{font-size:10px;color:var(--muted);margin-top:1px}
.header-sep{width:1px;height:26px;background:var(--border);flex-shrink:0}

#searchBox{
  flex:1;max-width:280px;
  background:var(--surface2);border:1px solid var(--border);border-radius:8px;
  padding:6px 11px;color:var(--text);outline:none;
}
#searchBox:focus{border-color:var(--accent)}

/* View tabs */
.view-tabs{display:flex;gap:2px;background:var(--surface2);border:1px solid var(--border);border-radius:8px;padding:3px}
.view-tab{
  display:flex;align-items:center;gap:5px;
  background:transparent;border:none;border-radius:6px;
  padding:4px 11px;color:var(--muted);font-weight:600;font-size:12px;
  transition:all .15s;
}
.view-tab:hover{color:var(--text)}
.view-tab.active{background:var(--surface);color:var(--text);box-shadow:0 1px 3px rgba(0,0,0,.2)}

/* Header buttons */
.hbtn{
  background:var(--surface2);border:1px solid var(--border);border-radius:7px;
  color:var(--text);padding:5px 10px;font-weight:600;font-size:12px;white-space:nowrap;
  transition:background .12s;
}
.hbtn:hover{background:var(--border)}
.hbtn.danger{color:#f85149}
.ml-auto{margin-left:auto;display:flex;align-items:center;gap:6px}

/* ── TREE VIEW ── */
#view-tree{
  display:grid;grid-template-columns:var(--sidebar-w) 1fr;
  overflow:hidden;height:100%;
}

/* Sidebar */
#sidebar{
  background:var(--surface);border-right:1px solid var(--border);
  overflow-y:auto;overflow-x:hidden;padding:0 0 24px;
  display:flex;flex-direction:column;
}
#sidebar::-webkit-scrollbar{width:4px}
#sidebar::-webkit-scrollbar-thumb{background:var(--border);border-radius:4px}

/* Filter bar */
#filterBar{
  display:flex;gap:5px;flex-wrap:wrap;padding:8px 10px 6px;
  border-bottom:1px solid var(--border);flex-shrink:0;
}
.fbtn{
  font-size:11px;font-weight:600;padding:3px 9px;border-radius:20px;
  border:1px solid var(--border);background:var(--surface2);color:var(--muted);
  cursor:pointer;transition:all .12s;
}
.fbtn:hover{color:var(--text)}
.fbtn.active{border-color:var(--accent);background:rgba(88,166,255,.1);color:var(--text)}

/* Tree items */
#tree{padding:6px 0}
.tree-section{margin-bottom:2px}
.tree-group-header{
  display:flex;align-items:center;gap:7px;
  padding:6px 10px;font-size:12px;font-weight:700;
  text-transform:uppercase;letter-spacing:.7px;color:var(--muted);
  cursor:pointer;user-select:none;border-radius:7px;margin:2px 6px;
  transition:background .12s;position:relative;
}
.tree-group-header:hover{background:var(--surface2)}
.tree-group-header .mod-dot{width:7px;height:7px;border-radius:50%;flex-shrink:0}
.tree-group-header .tgh-label{flex:1;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.toggle-arrow{font-size:10px;transition:transform .2s;flex-shrink:0}
.tree-group-header.collapsed .toggle-arrow{transform:rotate(-90deg)}

/* Add child btn */
.hdr-add{
  width:18px;height:18px;border-radius:50%;background:var(--surface2);
  border:1px solid var(--border);color:var(--muted);
  display:flex;align-items:center;justify-content:center;
  font-size:13px;cursor:pointer;flex-shrink:0;
  transition:border-color .12s,color .12s;
}
.hdr-add:hover{border-color:var(--accent);color:var(--accent)}

/* Edit inline */
.tgh-label[contenteditable="true"],
.ti-label[contenteditable="true"]{
  outline:1px solid var(--accent);border-radius:3px;padding:0 2px;
  background:var(--surface2);color:var(--text);
}

/* Badges */
.ti-badge{
  flex-shrink:0;font-size:10px;font-weight:700;padding:1px 6px;border-radius:20px;
}
.badge-current{background:rgba(35,134,54,.25);color:#3fb950}
.badge-plan   {background:rgba(158,106,3,.25); color:#d29922}
.badge-done   {background:rgba(31,111,235,.25);color:#58a6ff}
.badge-wip    {background:rgba(218,54,51,.25); color:#f85149}
.badge-paper  {background:rgba(137,87,229,.25);color:#bc8cff}
.badge-hot    {background:rgba(249,115,22,.25);color:#fb923c}

/* Child items */
.tree-children{overflow:hidden;transition:max-height .28s cubic-bezier(.4,0,.2,1)}
.tree-children.collapsed{max-height:0!important}
.tree-item{
  display:flex;align-items:flex-start;gap:5px;
  padding:5px 10px 5px calc(10px + 18px);
  cursor:pointer;user-select:none;border-radius:6px;margin:1px 6px;
  font-size:12px;line-height:1.4;transition:background .1s;
}
.tree-item:hover{background:var(--surface2)}
.tree-item.selected{background:rgba(88,166,255,.1)}
.ti-icon{color:var(--muted);flex-shrink:0;font-size:12px;margin-top:2px}
.ti-label{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}

/* ── DETAIL PANEL ── */
#detail{overflow-y:auto;padding:22px 24px 40px;background:var(--bg)}
#detail::-webkit-scrollbar{width:5px}
#detail::-webkit-scrollbar-thumb{background:var(--border);border-radius:4px}

/* Empty state */
.d-empty{display:flex;flex-direction:column;align-items:center;justify-content:center;height:60vh;gap:10px;color:var(--muted);text-align:center}
.d-empty-icon{font-size:44px}

/* Detail header */
.d-header{margin-bottom:18px;position:relative}
.d-edit-btn{
  position:absolute;top:0;right:0;
  background:var(--surface2);border:1px solid var(--border);border-radius:7px;
  color:var(--muted);padding:4px 10px;font-size:11px;font-weight:600;cursor:pointer;
  transition:all .12s;
}
.d-edit-btn:hover{border-color:var(--accent);color:var(--accent)}
.d-module-tag{display:inline-flex;align-items:center;font-size:11px;font-weight:700;text-transform:uppercase;letter-spacing:.8px;padding:3px 10px;border-radius:20px;margin-bottom:6px}
.d-title{font-size:20px;font-weight:700;line-height:1.3}
.d-subtitle{font-size:13px;color:var(--muted);margin-top:4px;line-height:1.5}

.d-section{margin-bottom:18px}
.d-section-title{font-size:10px;font-weight:700;text-transform:uppercase;letter-spacing:.8px;color:var(--muted);margin-bottom:8px;padding-bottom:5px;border-bottom:1px solid var(--border)}

/* I/O boxes */
.io-row{display:grid;grid-template-columns:1fr 1fr;gap:8px;margin-bottom:8px}
.io-box{background:var(--surface);border:1px solid var(--border);border-radius:8px;padding:10px 12px}
.io-box-label{font-size:10px;font-weight:700;text-transform:uppercase;color:var(--muted);margin-bottom:5px}
.io-box-val{font-size:12px;line-height:1.6;font-family:'SF Mono','Fira Code',monospace;white-space:pre-wrap}

/* Spec cards */
.info-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(130px,1fr));gap:7px}
.info-card{background:var(--surface);border:1px solid var(--border);border-radius:8px;padding:9px 11px}
.info-card-label{font-size:10px;font-weight:700;text-transform:uppercase;color:var(--muted)}
.info-card-val{font-size:16px;font-weight:700;margin-top:2px}
.info-card-sub{font-size:11px;color:var(--muted);margin-top:1px}

/* Insights */
.insight{background:rgba(88,166,255,.07);border:1px solid rgba(88,166,255,.2);border-radius:8px;padding:10px 12px;font-size:13px;line-height:1.6;margin-bottom:7px}
.insight.warn{background:rgba(249,115,22,.07);border-color:rgba(249,115,22,.2)}
.insight.success{background:rgba(34,197,94,.07);border-color:rgba(34,197,94,.2)}
.insight.paper{background:rgba(137,87,229,.07);border-color:rgba(137,87,229,.2)}

/* Benchmark table */
.table-wrap{background:var(--surface);border:1px solid var(--border);border-radius:8px;overflow:hidden;overflow-x:auto;margin-bottom:8px}
.bench-table{width:100%;border-collapse:collapse;font-size:12px}
.bench-table th{background:var(--surface2);padding:6px 9px;text-align:left;font-size:10px;font-weight:700;text-transform:uppercase;letter-spacing:.5px;color:var(--muted);border-bottom:1px solid var(--border)}
.bench-table td{padding:6px 9px;border-bottom:1px solid var(--border);vertical-align:middle}
.bench-table tr:last-child td{border-bottom:none}
.bench-table tr:hover td{background:var(--surface2)}
.bench-table .row-current td{color:#3fb950;font-weight:600}
.bench-table .row-reco td:first-child{color:#d29922;font-weight:700}

/* Paper cards */
.paper-card{background:var(--surface);border:1px solid var(--border);border-radius:8px;padding:10px 12px;margin-bottom:7px}
.paper-card-head{display:flex;align-items:flex-start;justify-content:space-between;gap:8px}
.paper-card-title{font-weight:600;font-size:12px;line-height:1.4}
.paper-card-venue{font-size:11px;color:var(--muted);margin-top:2px}
.paper-card-key{font-size:12px;color:var(--muted);margin-top:7px;line-height:1.5}
.paper-card-link{font-size:11px;color:var(--accent);text-decoration:none;display:inline-block;margin-top:4px}
.paper-card-link:hover{text-decoration:underline}

/* Code block */
.code-block{background:var(--surface);border:1px solid var(--border);border-radius:8px;padding:10px 12px;font-family:'SF Mono','Fira Code',monospace;font-size:12px;line-height:1.6;overflow-x:auto;color:#79c0ff;white-space:pre}

/* Media in detail */
.d-media-row{display:flex;flex-wrap:wrap;gap:8px;margin-bottom:10px}
.d-media-img{border-radius:8px;max-width:100%;max-height:220px;object-fit:contain;border:1px solid var(--border)}
.d-media-video{border-radius:8px;max-width:100%;max-height:220px;border:1px solid var(--border)}
.d-media-yt{width:100%;aspect-ratio:16/9;border-radius:8px;border:none}

/* Chips */
.chip-row{display:flex;flex-wrap:wrap;gap:6px}
.chip{display:inline-block;font-size:12px;padding:3px 10px;border-radius:20px;border:1px solid var(--border);color:var(--muted)}
.chip.hl{border-color:var(--accent);color:var(--accent)}

/* ── MINDMAP VIEW ── */
#view-map{height:100%;position:relative}
#mm-container{width:100%;height:100%;position:relative;overflow:hidden;background:var(--bg)}

/* Dotted grid */
#mm-container::before{
  content:'';position:absolute;inset:0;pointer-events:none;z-index:0;
  background-image:radial-gradient(circle,var(--border) 1px,transparent 1px);
  background-size:36px 36px;
  background-position:var(--mm-gx,0px) var(--mm-gy,0px);
}

#mm-viewport-wrap{position:absolute;inset:0;cursor:grab;overflow:hidden;z-index:1}
#mm-viewport-wrap.panning{cursor:grabbing}
#mm-viewport{position:absolute;inset:0;transform-origin:0 0}
#mm-svg{position:absolute;inset:0;overflow:visible;pointer-events:none}
#mm-svg .mm-edge-path{pointer-events:stroke}
#mm-nodes{position:absolute;inset:0;pointer-events:none}

/* Mindmap nodes */
.mm-node{
  position:absolute;
  background:var(--surface);
  border:2px solid var(--border);
  border-radius:10px;
  padding:10px 16px;
  min-width:100px;
  max-width:280px;
  transform:translate(-50%,-50%);
  cursor:grab;
  pointer-events:auto;
  box-shadow:0 4px 16px rgba(0,0,0,.18);
  user-select:none;
  transition:border-color .15s,box-shadow .15s;
  color:var(--text);
  font-size:14px;
  word-break:break-word;
}
.mm-node:active{cursor:grabbing}
.mm-node.selected{border-color:var(--accent);box-shadow:0 0 0 3px rgba(88,166,255,.2)}
.mm-node.editing{cursor:text;border-color:var(--accent)}
.mm-node-text{min-width:48px;outline:none;line-height:1.4;white-space:pre-wrap}
.mm-node.editing .mm-node-text{user-select:text;cursor:text}
/* Collapse badge */
.mm-node .mm-collapse{
  position:absolute;right:-9px;top:50%;transform:translateY(-50%);
  width:18px;height:18px;border-radius:50%;
  background:var(--surface);border:1.5px solid var(--border);
  color:var(--muted);font-size:9px;cursor:pointer;
  display:flex;align-items:center;justify-content:center;z-index:3;
  pointer-events:auto;transition:all .12s;
}
.mm-node .mm-collapse:hover{border-color:var(--accent);color:var(--accent)}
/* Image / Video inside node */
.mm-node img,.mm-node video{
  display:block;max-width:240px;max-height:160px;
  border-radius:6px;margin-top:6px;object-fit:contain;
  pointer-events:none;
}
/* Connection handles */
.mm-handle{
  position:absolute;width:12px;height:12px;border-radius:50%;
  background:#fff;border:2px solid #94a3b8;
  box-shadow:0 0 0 2px rgba(255,255,255,.9);
  cursor:crosshair;z-index:4;pointer-events:auto;
  transition:background .12s,border-color .12s,transform .12s;
}
.mm-handle:hover{background:var(--accent);border-color:var(--accent);transform:scale(1.2)}
.mm-handle[data-s="top"]   {top:0;left:50%;transform:translate(-50%,-50%)}
.mm-handle[data-s="right"] {top:50%;right:0;transform:translate(50%,-50%)}
.mm-handle[data-s="bottom"]{bottom:0;left:50%;transform:translate(-50%,50%)}
.mm-handle[data-s="left"]  {top:50%;left:0;transform:translate(-50%,-50%)}
.mm-handle[data-s="top"]:hover   {transform:translate(-50%,-50%) scale(1.2)}
.mm-handle[data-s="right"]:hover {transform:translate(50%,-50%) scale(1.2)}
.mm-handle[data-s="bottom"]:hover{transform:translate(-50%,50%) scale(1.2)}
.mm-handle[data-s="left"]:hover  {transform:translate(-50%,-50%) scale(1.2)}

/* Edge paths */
.mm-edge-path{fill:none;stroke:#4b5563;stroke-width:2;stroke-linecap:round;cursor:pointer;transition:stroke .15s}
[data-theme="light"] .mm-edge-path{stroke:#94a3b8}
.mm-edge-path:hover,.mm-edge-path.selected{stroke:var(--accent);stroke-width:2.5}
.mm-edge-path.preview{stroke:var(--accent);stroke-dasharray:6 4;stroke-width:2}
/* Edge endpoint draggables */
.mm-ep{fill:#fff;stroke:var(--accent);stroke-width:2;cursor:grab;pointer-events:auto}
.mm-ep:hover{fill:#dbeafe}

/* Edge label */
.mm-edge-label{
  position:absolute;background:var(--surface);border:1px solid var(--border);
  padding:2px 6px;border-radius:4px;font-size:11px;color:var(--muted);
  transform:translate(-50%,-50%);cursor:text;pointer-events:auto;
}

/* Shortcuts */
#mm-help{
  position:absolute;bottom:14px;right:14px;z-index:20;
  background:var(--surface);border:1px solid var(--border);border-radius:10px;
  padding:10px 13px;font-size:11px;line-height:1.8;color:var(--muted);
  box-shadow:0 6px 20px rgba(0,0,0,.2);
}
#mm-help strong{color:var(--text)}

/* ── MODALS ── */
.modal-backdrop{
  display:none;position:fixed;inset:0;z-index:1000;
  background:rgba(0,0,0,.55);align-items:center;justify-content:center;
}
.modal-backdrop.visible{display:flex}
.modal-box{
  background:var(--surface);border:1px solid var(--border);border-radius:14px;
  padding:22px;width:min(440px,96vw);
  box-shadow:0 24px 64px rgba(0,0,0,.45);max-height:90vh;overflow-y:auto;
}
.modal-title{font-size:15px;font-weight:700;margin-bottom:14px}
.modal-label{display:block;font-size:11px;font-weight:700;color:var(--muted);margin-bottom:4px;text-transform:uppercase;letter-spacing:.5px}
.modal-input{
  width:100%;background:var(--surface2);border:1px solid var(--border);border-radius:8px;
  padding:7px 11px;color:var(--text);outline:none;margin-bottom:10px;
}
.modal-input:focus{border-color:var(--accent)}
textarea.modal-input{resize:vertical}
.modal-actions{display:flex;gap:8px;justify-content:flex-end;margin-top:6px}
.modal-btn{padding:6px 14px;border-radius:8px;font-weight:600;cursor:pointer;border:1px solid var(--border);background:var(--surface2);color:var(--text);transition:opacity .12s}
.modal-btn:hover{opacity:.8}
.modal-btn.primary{background:var(--accent);border-color:var(--accent);color:#fff}
