*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --sidebar-width: 500px;
  --sidebar-bg: #1e2433;
  --sidebar-hover: #2d3448;
  --sidebar-active: #3b4a6b;
  --sidebar-border: #2d3448;
  --accent: #4f8ef7;
  --text-primary: #e2e8f0;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --header-height: 56px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: #f1f5f9;
  height: 100vh;
  overflow: hidden;
}

#app {
  display: flex;
  height: 100vh;
}

/* ── SIDEBAR ── */
#sidebar {
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow: hidden;
}

#collapse-all-btn {
  margin-left: auto;
  flex-shrink: 0;
  width: 26px;
  height: 26px;
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: background 0.15s, color 0.15s;
  padding: 0;
}

#collapse-all-btn:hover {
  background: var(--sidebar-hover);
  color: var(--text-primary);
}

#collapse-all-btn svg {
  width: 16px;
  height: 16px;
  transition: transform 0.25s;
}

#collapse-all-btn.expanded svg {
  transform: rotate(180deg);
}

#sidebar-resizer {
  width: 5px;
  cursor: col-resize;
  background: var(--sidebar-border);
  flex-shrink: 0;
  transition: background 0.15s;
}

#sidebar-resizer:hover,
#sidebar-resizer.dragging {
  background: var(--accent);
}

#sidebar-header {
  height: var(--header-height);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 16px;
  border-bottom: 1px solid var(--sidebar-border);
  flex-shrink: 0;
}

#logo {
  height: 30px;
  width: auto;
}

#brand {
  color: var(--text-primary);
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.3px;
}

#search-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--sidebar-border);
  flex-shrink: 0;
}

#search-bar svg {
  width: 15px;
  height: 15px;
  color: var(--text-muted);
  flex-shrink: 0;
}

#search-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-size: 13px;
  font-family: inherit;
}

#search-input::placeholder {
  color: var(--text-muted);
}

#search-clear {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 12px;
  padding: 0;
  display: none;
  line-height: 1;
}

#search-clear:hover {
  color: var(--text-primary);
}

.search-hidden { display: none !important; }

.search-highlight {
  background: #f0a500;
  color: #1e2433;
  border-radius: 2px;
  padding: 0 1px;
}

#tree {
  overflow-y: auto;
  overflow-x: hidden;
  flex: 1;
  padding: 8px 0;
}

#tree::-webkit-scrollbar { width: 4px; }
#tree::-webkit-scrollbar-track { background: transparent; }
#tree::-webkit-scrollbar-thumb { background: #3d4a63; border-radius: 2px; }

/* ── TREE NODES ── */
.tree-section { margin-bottom: 2px; }

.tree-node {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  cursor: pointer;
  border-radius: 4px;
  margin: 0 4px;
  color: var(--text-secondary);
  font-size: 13px;
  user-select: none;
  transition: background 0.12s, color 0.12s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tree-node:hover {
  background: var(--sidebar-hover);
  color: var(--text-primary);
}

.tree-node.active {
  background: var(--sidebar-active);
  color: var(--accent);
}

.tree-node.has-pdf:hover .node-label,
.tree-node.has-pdf.active .node-label {
  text-decoration: underline;
}

/* Indentation levels */
.tree-node[data-level="0"] { padding-left: 12px; font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-muted); cursor: default; margin-top: 8px; }
.tree-node[data-level="0"]:hover { background: transparent; color: var(--text-muted); }
.tree-node[data-level="1"] { padding-left: 16px; font-weight: 600; font-size: 13px; color: var(--text-primary); }
.tree-node[data-level="2"] { padding-left: 30px; }
.tree-node[data-level="3"] { padding-left: 44px; font-size: 12px; }

/* Toggle arrow */
.toggle {
  width: 16px;
  height: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: var(--text-muted);
  transition: transform 0.15s;
  font-size: 10px;
}

.toggle.open { transform: rotate(90deg); }
.toggle-placeholder { width: 16px; flex-shrink: 0; }

/* PDF icon */
.pdf-icon {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  opacity: 0.85;
}

/* Badge PDF / N.D. */
.badge {
  margin-left: auto;
  flex-shrink: 0;
  font-size: 10px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 10px;
  letter-spacing: 0.3px;
}

.badge-pdf {
  background: #1a3a1a;
  color: #4ade80;
  border: 1px solid #166534;
}

.badge-nd {
  background: #2a1f1f;
  color: #f87171;
  border: 1px solid #7f1d1d;
}

.tree-separator { height: 8px; }

.node-label {
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

/* Copy Link Button */
.copy-link-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 4px;
  background: var(--sidebar-hover);
  border: 1px solid var(--sidebar-border);
  cursor: pointer;
  opacity: 0;
  transition: all 0.2s;
  color: var(--text-secondary);
  flex-shrink: 0;
  margin: 0 2px;
}

.tree-node:hover .copy-link-btn {
  opacity: 1;
}

.copy-link-btn:hover {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.copy-link-btn svg {
  width: 12px;
  height: 12px;
}

/* Feedback "Copied" */
.copy-link-btn.copied {
  background: #166534 !important;
  color: #4ade80 !important;
  border-color: #4ade80 !important;
}

/* Children container */
.tree-children {
  overflow: hidden;
  transition: max-height 0.2s ease;
}

.tree-children.collapsed { max-height: 0 !important; }

/* ── CONTENT ── */
#content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#placeholder {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  color: #94a3b8;
}

#placeholder svg {
  width: 80px;
  height: 80px;
  opacity: 0.6;
}

#placeholder p {
  font-size: 14px;
  max-width: 260px;
  text-align: center;
  line-height: 1.5;
}

#pdf-viewer {
  flex: 1;
  width: 100%;
  border: none;
  background: #fff;
}
