/* ── APP SHELL ── */
#app {
  display: grid;
  grid-template-rows: var(--header-h) 1fr;
  height: 100vh; overflow: hidden;
}

/* ══════════════════════════════════════
   HEADER
   ══════════════════════════════════════ */
#header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 6px;
  padding: 0 14px; z-index: 200;
  box-shadow: var(--shadow-sm);
}

.sidebar-toggle-btn {
  background: transparent; border: none;
  color: var(--muted); width: 30px; height: 30px;
  border-radius: 6px; font-size: 18px; line-height: 1;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.sidebar-toggle-btn:hover { background: var(--surface2); color: var(--text); }

.logo-wrap { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.logo-text {
  font-weight: 800; font-size: 15px; letter-spacing: -.6px;
  color: var(--accent); font-family: var(--font);
}
.logo-sub { font-size: 10px; color: var(--muted); margin-top: 1px; font-weight: 500; }

.header-search-wrap inner {
  flex: 1; display: flex; align-items: center; gap: 16px; padding: 0 20px;
}

#searchBox {
  flex: 1; max-width: 280px; height: 34px;
  background: var(--surface2);
  border: 1.5px solid var(--border);
  border-radius: 20px;
  padding: 0 14px;
  color: var(--text); outline: none;
  transition: border-color .15s, box-shadow .15s;
  font-size: 12.5px;
}
#searchBox:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-bg);
  background: var(--surface);
}

#realtime-clock {
  font-size: 11px; font-weight: 600; color: var(--muted);
  font-variant-numeric: tabular-nums;
  font-family: var(--font-mono);
}

/* View Tabs */
.view-tabs {
  display: flex; gap: 2px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px; padding: 3px;
}
.view-tab {
  background: transparent; border: none; border-radius: 5px;
  padding: 4px 12px; color: var(--muted);
  font-weight: 600; font-size: 12px;
  transition: all .15s; white-space: nowrap;
}
.view-tab:hover { color: var(--text); background: var(--surface3); }
.view-tab.active {
  background: var(--surface); color: var(--text);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
}

/* Header Buttons */
.hbtn {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text2);
  padding: 5px 11px;
  font-weight: 600; font-size: 12px;
  white-space: nowrap;
  display: flex; align-items: center; gap: 5px;
}
.hbtn:hover {
  background: var(--surface3);
  border-color: var(--border2);
  color: var(--text);
}
.hbtn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.hbtn.primary:hover { background: var(--accent-2); border-color: var(--accent-2); }
.hbtn.danger { color: var(--red); }
.hbtn.danger:hover { background: var(--red-bg); border-color: var(--red); }

.theme-btn { margin-left: 4px; }
.ml-auto { margin-left: auto; display: flex; align-items: center; gap: 5px; }

/* ══════════════════════════════════════
   TREE / SIDEBAR
   ══════════════════════════════════════ */
#view-tree {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  overflow: hidden; height: 100%;
  transition: grid-template-columns .22s cubic-bezier(.4,0,.2,1);
}
#view-tree.sidebar-collapsed { grid-template-columns: 0px 1fr; }

#sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow: hidden;
  display: flex; flex-direction: column;
}

#tree {
  flex: 1;
  overflow-y: auto;
  padding: 8px 6px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

/* Module / Group header */
.tree-section { margin-bottom: 2px; }

.tree-group-header {
  display: flex; align-items: center; gap: 5px;
  padding: 6px 8px; border-radius: 7px;
  cursor: pointer; user-select: none;
  transition: background .12s;
  position: relative;
}
.tree-group-header:hover { background: var(--surface2); }
.tree-group-header.selected {
  background: var(--accent-bg);
  box-shadow: inset 2px 0 0 var(--accent);
}

.tgh-label {
  flex: 1; font-weight: 600; font-size: 12.5px;
  color: var(--text); overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap;
}
.tree-group-header.selected .tgh-label { color: var(--accent-text); }

/* 3-state progress slider */
.status-track {
  width: 32px; height: 14px; background: var(--surface3);
  border-radius: 10px; position: relative; cursor: pointer;
  flex-shrink: 0; transition: background .2s;
}
.status-dot {
  width: 10px; height: 10px; background: #fff;
  border-radius: 50%; position: absolute; top: 2px; left: 2px;
  transition: transform .2s cubic-bezier(.4, 0, .2, 1);
  box-shadow: 0 1px 2px rgba(0,0,0,.2);
}

.status-track[data-status="red"] { background: var(--red); }
.status-track[data-status="red"] .status-dot { transform: translateX(0); }

.status-track[data-status="yellow"] { background: var(--yellow); }
.status-track[data-status="yellow"] .status-dot { transform: translateX(9px); }

.status-track[data-status="green"] { background: var(--green); }
.status-track[data-status="green"] .status-dot { transform: translateX(18px); }

.status-track:hover .status-dot { transform: scale(1.1); }
.status-track[data-status="yellow"]:hover .status-dot { transform: translateX(9px) scale(1.1); }
.status-track[data-status="green"]:hover .status-dot { transform: translateX(18px) scale(1.1); }

.toggle-arrow {
  font-size: 10px; color: var(--muted); flex-shrink: 0;
  transition: transform .15s;
}

/* Inline action buttons — hidden until hover */
.hdr-add, .mod-del-tree, .mod-menu-btn {
  background: transparent; border: none;
  color: var(--muted); font-size: 13px;
  width: 22px; height: 22px; border-radius: 5px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; opacity: 0; transition: opacity .12s, background .12s;
}
.tree-group-header:hover .hdr-add,
.tree-group-header:hover .mod-del-tree,
.tree-group-header:hover .mod-menu-btn,
.tree-item:hover .mod-del-tree,
.tree-item:hover .mod-menu-btn { opacity: 1; }
.hdr-add:hover, .mod-menu-btn:hover { background: var(--surface3); color: var(--text); }
.mod-del-tree:hover { background: var(--red-bg); color: var(--red); }

/* Child items */
.tree-children {
  padding-left: 14px;
  margin: 1px 0;
  border-left: 1.5px solid var(--border);
  margin-left: 12px;
}

.tree-item {
  display: flex; align-items: center; gap: 6px;
  padding: 5px 8px; border-radius: 6px;
  cursor: pointer; transition: background .12s;
  position: relative;
}
.tree-item:hover { background: var(--surface2); }
.tree-item.selected {
  background: var(--accent-bg);
  box-shadow: inset 2px 0 0 var(--accent);
}

.ti-status-dot {
  width: 6px; height: 6px; border-radius: 50%;
  flex-shrink: 0; margin-top: 1px;
}
.ti-label {
  flex: 1; font-size: 12px; color: var(--text2);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-weight: 500;
}
.tree-item.selected .ti-label { color: var(--accent-text); font-weight: 600; }

/* Sidebar footer */
.sidebar-footer {
  padding: 8px 6px; border-top: 1px solid var(--border);
}
.add-module-btn {
  width: 100%; background: transparent;
  border: 1.5px dashed var(--border2);
  border-radius: 7px; color: var(--muted);
  padding: 7px 12px; font-size: 12px; font-weight: 600;
  transition: all .15s;
}
.add-module-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-bg);
}

/* ══════════════════════════════════════
   DETAIL PANEL
   ══════════════════════════════════════ */
#detail {
  background: var(--bg);
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.detail-scroll { padding: 24px 28px; max-width: 1000px; }

.detail-header {
  display: flex; align-items: flex-start; gap: 16px;
  margin-bottom: 24px;
}

.detail-title {
  font-size: 24px; font-weight: 700;
  letter-spacing: -.5px; color: var(--text);
  line-height: 1.3;
}

.detail-subtitle {
  font-size: 13.5px; color: var(--muted);
  margin-top: 4px; font-weight: 400;
  line-height: 1.5;
}

.detail-actions {
  display: flex; gap: 6px; flex-shrink: 0; padding-top: 4px;
  flex-wrap: wrap;
}

/* Context Menu */
.ctx-menu {
  position: fixed; z-index: 9000;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 4px; min-width: 140px;
  animation: ctx-in .1s ease;
}
@keyframes ctx-in {
  from { opacity: 0; transform: scale(.95); }
  to { opacity: 1; transform: scale(1); }
}
.ctx-item {
  padding: 7px 12px; border-radius: 6px;
  font-size: 12.5px; font-weight: 500;
  cursor: pointer; transition: background .1s;
  color: var(--text2);
}
.ctx-item:hover { background: var(--surface2); color: var(--text); }
.ctx-item.active { color: var(--accent); font-weight: 600; }
.ctx-item.danger { color: var(--red); }
.ctx-item.danger:hover { background: var(--red-bg); }
.ctx-sep { height: 1px; background: var(--border); margin: 3px 0; }

/* Mindmap view */
#view-map { height: 100%; overflow: hidden; }
#mm-container { height: 100%; display: flex; flex-direction: column; }
#mm-viewport-wrap {
  flex: 1; overflow: hidden; position: relative;
  background: var(--bg);
  background-image: radial-gradient(var(--border) 1px, transparent 1px);
  background-size: 20px 20px;
}
#mm-viewport { position: absolute; transform-origin: 0 0; }
#mm-nodes { position: absolute; top: 0; left: 0; }
#mm-svg { position: absolute; top: 0; left: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; }
#mm-help {
  padding: 8px 14px; background: var(--surface);
  border-top: 1px solid var(--border);
  font-size: 11px; color: var(--muted);
}

/* Filter bar */
#filterBar {
  display: flex; gap: 4px; flex-wrap: wrap;
  padding: 8px 8px 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: transparent;
  color: var(--muted); transition: all .12s; white-space: nowrap;
}
.fbtn:hover { color: var(--text); border-color: var(--border2); }
.fbtn.active { border-color: var(--accent); background: var(--accent-bg); color: var(--accent); }
