/* styles.css */

/* ── Variables ─────────────────────────────────────── */
:root {
  --bg:        #0d0f11;
  --bg2:       #13161a;
  --bg3:       #1c2028;
  --border:    #2a2f3a;
  --text:      #c9cdd6;
  --text-dim:  #5a6070;
  --text-hi:   #eaedf2;
  --accent:    #3b8eea;
  --accent2:   #1f5fa6;
  --danger:    #c0392b;
  --mark-bg:   #3b8eea33;
  --mark-fg:   #7ec8ff;
  --radius:    4px;
  --mono:      'JetBrains Mono', 'Fira Code', 'Consolas', monospace;
  --sans:      'Geist', 'DM Sans', 'Segoe UI', sans-serif;
  --topbar-h:  52px;
}

[data-theme="light"] {
  --bg:        #f4f5f7;
  --bg2:       #ffffff;
  --bg3:       #e8eaed;
  --border:    #d0d4db;
  --text:      #2c3140;
  --text-dim:  #8a92a3;
  --text-hi:   #0d0f11;
  --accent:    #1a6fd4;
  --accent2:   #104fa0;
  --mark-bg:   #1a6fd420;
  --mark-fg:   #1a5fb4;
}

/* ── Reset ──────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 14px; }
body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
  transition: background 0.2s, color 0.2s;
}
button { cursor: pointer; font-family: inherit; }
input  { font-family: inherit; }
a      { text-decoration: none; }

/* ── Topbar ─────────────────────────────────────────── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--topbar-h);
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  gap: 12px;
}

.topbar-left { display: flex; align-items: center; }
.topbar-right { display: flex; align-items: center; gap: 8px; flex: 1; justify-content: flex-end; }

.logo {
  font-family: var(--mono);
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: var(--text-hi);
  white-space: nowrap;
}

/* ── Search ─────────────────────────────────────────── */
.search-wrap {
  display: flex;
  align-items: center;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0 8px;
  gap: 6px;
  flex: 1;
  max-width: 340px;
  transition: border-color 0.15s;
}
.search-wrap:focus-within { border-color: var(--accent); }
.search-icon { color: var(--text-dim); font-size: 1.1rem; }
#searchInput {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: var(--text);
  font-size: 0.875rem;
  padding: 6px 0;
}
#searchInput::placeholder { color: var(--text-dim); }

/* ── Buttons ─────────────────────────────────────────── */
.btn-icon {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-dim);
  font-size: 1rem;
  width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s, color 0.15s;
}
.btn-icon:hover { background: var(--bg3); color: var(--text-hi); }

.btn-pill {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--text);
  font-size: 0.8rem;
  font-family: var(--mono);
  padding: 4px 14px;
  letter-spacing: 0.05em;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.btn-pill:hover { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-pill.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ── Dropdown menu ───────────────────────────────────── */
.menu-wrap { position: relative; }
.dropdown {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  min-width: 170px;
  box-shadow: 0 8px 24px #0008;
  z-index: 200;
  overflow: hidden;
}
.dropdown button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 10px 14px;
  background: none;
  border: none;
  color: var(--text);
  font-size: 0.82rem;
  transition: background 0.12s;
}
.dropdown button:hover { background: var(--bg3); color: var(--text-hi); }

/* ── Main layout ─────────────────────────────────────── */
main {
  max-width: 860px;
  margin: 0 auto;
  padding: 20px 16px 80px;
}

/* ── Tree ────────────────────────────────────────────── */
.tree-root { display: flex; flex-direction: column; gap: 6px; }

/* Section (level 0) */
.tree-section {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: border-color 0.15s;
}
.tree-section:hover { border-color: var(--accent2); }

/* Section header */
.node-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  cursor: pointer;
  user-select: none;
  transition: background 0.12s;
}
.node-header:hover { background: var(--bg3); }
.node-header:focus { outline: 2px solid var(--accent); outline-offset: -2px; }

.node-arrow {
  font-family: var(--mono);
  font-size: 0.7rem;
  color: var(--text-dim);
  width: 14px;
  transition: transform 0.18s ease;
  display: inline-block;
  flex-shrink: 0;
}
.node-arrow.open { transform: rotate(90deg); }

.node-name {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-hi);
  flex: 1;
  letter-spacing: 0.02em;
}

/* Subsection (level 1+) */
.node-children {
  padding: 0 0 4px 0;
}
.tree-subsection {
  border-top: 1px solid var(--border);
  margin: 0;
}
.tree-subsection > .node-header {
  padding-left: 32px;
  background: var(--bg);
}
.tree-subsection > .node-header .node-name { font-weight: 500; color: var(--text); }

/* Nested children of subsection */
.tree-subsection > .node-children {
  padding-left: 0;
}

/* ── Links list ──────────────────────────────────────── */
.links-list {
  list-style: none;
  padding: 4px 0;
}
/* indent based on depth */
.depth-0 > .node-children > .links-list { padding-left: 14px; }
.depth-1 > .node-children > .links-list { padding-left: 46px; }
.depth-2 > .node-children > .links-list { padding-left: 78px; }

.link-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 2px 14px 2px 0;
  position: relative;
}

.link-item a {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1;
  padding: 6px 10px;
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.82rem;
  transition: background 0.12s, color 0.12s;
  position: relative;
}
.link-item a:hover { background: var(--bg3); color: var(--accent); }
.link-item a.active-link { background: var(--mark-bg); color: var(--accent); }
.link-item a:focus { outline: 2px solid var(--accent); }

.link-dot {
  width: 5px; height: 5px;
  border-radius: 50%;
  background: var(--text-dim);
  flex-shrink: 0;
}
.link-item a:hover .link-dot,
.link-item a.active-link .link-dot { background: var(--accent); }

/* ── CSS Tooltip ─────────────────────────────────────── */
.has-tooltip { position: relative; }
.has-tooltip::after {
  content: attr(data-tooltip);
  position: absolute;
  left: 100%;
  top: 50%;
  transform: translateY(-50%);
  margin-left: 10px;
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 0.72rem;
  font-family: var(--mono);
  padding: 4px 8px;
  border-radius: var(--radius);
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
  z-index: 50;
}
.has-tooltip:hover::after { opacity: 1; }

/* ── Collapsed / expanded state ─────────────────────── */
.node-children.collapsed { display: none; }

/* ── Search highlight ────────────────────────────────── */
mark {
  background: var(--mark-bg);
  color: var(--mark-fg);
  border-radius: 2px;
  padding: 0 1px;
}

/* ── Empty state ─────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-dim);
  font-size: 0.85rem;
  font-family: var(--mono);
}

/* ── Edit mode bar ───────────────────────────────────── */
.edit-bar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: var(--bg2);
  border-top: 1px solid var(--accent2);
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  z-index: 100;
}

.btn-add {
  background: none;
  border: 1px dashed var(--accent2);
  border-radius: var(--radius);
  color: var(--accent);
  font-size: 0.8rem;
  font-family: var(--mono);
  padding: 5px 12px;
  transition: background 0.15s, border-color 0.15s;
}
.btn-add:hover { background: var(--accent2); border-color: var(--accent); color: #fff; }

/* ── Edit controls inline ────────────────────────────── */
.edit-controls {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: auto;
}
.edit-controls button {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 0.85rem;
  padding: 2px 5px;
  border-radius: var(--radius);
  transition: background 0.1s, color 0.1s;
}
.edit-controls button:hover { background: var(--bg3); color: var(--text-hi); }
.edit-controls .del-btn:hover { color: var(--danger); }

/* Drag handle */
.drag-handle {
  cursor: grab;
  color: var(--text-dim);
  font-size: 0.85rem;
  padding: 2px 4px;
  user-select: none;
}
.drag-handle:active { cursor: grabbing; }

/* Mobile up/down buttons */
.move-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 3px;
  color: var(--text-dim);
  font-size: 0.7rem;
  width: 22px; height: 22px;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.1s, color 0.1s;
}
.move-btn:hover { background: var(--bg3); color: var(--text-hi); }

/* Inline edit input */
.inline-input {
  background: var(--bg3);
  border: 1px solid var(--accent2);
  border-radius: var(--radius);
  color: var(--text-hi);
  font-size: inherit;
  font-family: inherit;
  padding: 2px 6px;
  outline: none;
  min-width: 80px;
}
.inline-input:focus { border-color: var(--accent); }

/* Drag-over highlight */
.drag-over { outline: 2px dashed var(--accent); outline-offset: -2px; }

/* ── Responsive ──────────────────────────────────────── */
@media (max-width: 600px) {
  .topbar { padding: 0 10px; gap: 8px; }
  .logo { display: none; }
  .search-wrap { max-width: 100%; }
  main { padding: 12px 8px 80px; }
  .has-tooltip::after { display: none; }

  .depth-0 > .node-children > .links-list { padding-left: 10px; }
  .depth-1 > .node-children > .links-list { padding-left: 32px; }
}
