/* ============================================================
   Threads — Idea Thread page
   ============================================================ */

.threads-body {
  height: 100vh;
  overflow: hidden;
}

.rail-item[data-active="true"]::before {
  background: var(--acc-threads, #a78bfa) !important;
}

/* Shell */
.threads-shell {
  display: grid;
  grid-template-columns: 240px 1fr;
  height: 100%;
  overflow: hidden;
}

/* ── Sidebar ── */
.threads-sidebar {
  border-right: 1px solid var(--line);
  background: var(--bg-soft);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.ts-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 14px 10px;
  flex-shrink: 0;
  border-bottom: 1px solid var(--line);
}

.ts-title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--fg-mute);
}

.ts-new-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  font: inherit;
  font-size: 12px;
  font-weight: 500;
  color: var(--fg-mute);
  background: none;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 4px 9px;
  cursor: pointer;
  transition: background 120ms, color 120ms, border-color 120ms;
}
.ts-new-btn:hover {
  background: var(--hover);
  color: var(--fg);
  border-color: var(--line-2, rgba(255,255,255,0.15));
}

.ts-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.ts-item {
  padding: 9px 10px;
  border-radius: var(--radius-xs);
  cursor: pointer;
  transition: background 100ms;
  border: 1px solid transparent;
}
.ts-item:hover { background: var(--hover); }
.ts-item.active {
  background: var(--hover);
  border-color: var(--line-2, rgba(255,255,255,0.12));
}

.ts-item-title {
  font-size: 13px;
  font-weight: 500;
  color: var(--fg);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-bottom: 3px;
}

.ts-item-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  color: var(--fg-dim);
}

.ts-item-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--acc-threads, #a78bfa);
  flex-shrink: 0;
}

.ts-empty {
  padding: 20px;
  text-align: center;
  font-size: 12px;
  color: var(--fg-mute);
}

.ts-search-wrap {
  position: relative;
  padding: 8px 10px 6px;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
.ts-search-icon {
  position: absolute;
  left: 18px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--fg-dim);
  pointer-events: none;
}
.ts-search {
  width: 100%;
  font: inherit;
  font-size: 12px;
  color: var(--fg);
  background: var(--bg-elev-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 8px 6px 26px;
  outline: none;
  transition: border-color 120ms;
}
.ts-search:focus { border-color: var(--accent); }
.ts-search::placeholder { color: var(--fg-dim); }
.ts-search::-webkit-search-cancel-button { cursor: pointer; }

.ts-item-snippet {
  font-size: 11px;
  color: var(--fg-mute);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-bottom: 3px;
  font-style: italic;
}

/* ── Detail: two-row split ── */
.threads-detail {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
  height: 100%;
}

/* Thread content */
.td-content {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.td-topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 24px 12px;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}

.td-title-input {
  font: inherit;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--fg);
  background: transparent;
  border: none;
  outline: none;
  flex: 1;
  caret-color: var(--acc-threads, #a78bfa);
}
.td-title-input::placeholder { color: var(--fg-dim); }

.td-topbar-actions { display: flex; gap: 8px; }

.td-delete-btn {
  font: inherit;
  font-size: 12px;
  padding: 5px 12px;
  border-radius: 6px;
  border: 1px solid rgba(248,113,113,0.2);
  background: none;
  color: var(--fg-dim);
  cursor: pointer;
  transition: background 120ms, color 120ms, border-color 120ms;
}
.td-delete-btn:hover {
  background: rgba(248,113,113,0.1);
  color: #f87171;
  border-color: rgba(248,113,113,0.4);
}

/* Graph visualization — top half, always present */
.td-graph-wrap {
  flex: 0 0 45%;
  min-height: 0;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
  position: relative;
  overflow: hidden;
}

#threadGraph {
  display: block;
  width: 100%;
  height: 100%;
}

/* Single-node action popup (overlaid on graph) */
.node-popup {
  position: absolute;
  z-index: 25;
  width: 240px;
  background: var(--bg-elev);
  border: 1px solid var(--line-2);
  border-radius: 10px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.55);
  animation: nodePopupIn 140ms ease;
  pointer-events: all;
}
@keyframes nodePopupIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: none; }
}
.node-popup-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px 6px;
  border-bottom: 1px solid var(--line);
}
.node-popup-badge {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .05em;
  text-transform: uppercase;
  padding: 2px 7px;
  border-radius: 4px;
}
.node-popup-close {
  background: none;
  border: none;
  color: var(--fg-mute);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  padding: 0 2px;
}
.node-popup-close:hover { color: var(--fg); }
.node-popup-body {
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.node-popup-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--fg);
  line-height: 1.4;
}
.node-popup-textarea {
  width: 100%;
  background: var(--bg-soft);
  border: 1px solid var(--line-2);
  border-radius: 6px;
  color: var(--fg);
  font: inherit;
  font-size: 13px;
  padding: 7px 9px;
  resize: vertical;
  outline: none;
  box-sizing: border-box;
}
.node-popup-textarea:focus { border-color: var(--acc-threads, #a78bfa); }
.node-popup-save {
  align-self: flex-end;
  background: var(--acc-threads, #a78bfa);
  color: #fff;
  border: none;
  border-radius: 6px;
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  padding: 5px 12px;
  cursor: pointer;
  transition: filter .15s;
}
.node-popup-save:hover { filter: brightness(1.12); }
.node-popup-open {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--acc-threads, #a78bfa);
  text-decoration: none;
  padding: 5px 0;
}
.node-popup-open:hover { text-decoration: underline; }
.node-popup-hint {
  font-size: 12px;
  color: var(--fg-dim);
}

/* Multi-select action bar (overlaid on graph) */
.graph-selection-bar {
  position: absolute;
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-elev, #1e2233);
  border: 1px solid var(--acc-threads, #a78bfa);
  border-radius: 10px;
  padding: 8px 12px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
  z-index: 20;
  animation: gsbSlideUp 160ms ease;
}
@keyframes gsbSlideUp {
  from { opacity: 0; transform: translateX(-50%) translateY(8px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

.gsb-info {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--acc-threads, #a78bfa);
}

.gsb-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: 4px;
}

.gsb-clear-btn {
  font: inherit;
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: none;
  color: var(--fg-mute);
  cursor: pointer;
  transition: background 100ms, color 100ms;
}
.gsb-clear-btn:hover { background: var(--hover); color: var(--fg); }

.gsb-branch-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  padding: 5px 12px;
  border-radius: 6px;
  border: 1px solid var(--line-2);
  background: var(--bg-elev-2);
  color: var(--fg);
  cursor: pointer;
  transition: border-color 100ms, background 100ms;
}
.gsb-branch-btn:hover { border-color: var(--acc-threads, #a78bfa); background: var(--hover); }

.gsb-chat-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  padding: 5px 12px;
  border-radius: 6px;
  border: none;
  background: var(--acc-threads, #a78bfa);
  color: #fff;
  cursor: pointer;
  transition: opacity 120ms;
}
.gsb-chat-btn:hover { opacity: 0.85; }

/* Resize handle between graph and content */
.td-resize-handle {
  flex-shrink: 0;
  height: 6px;
  cursor: ns-resize;
  background: var(--line);
  position: relative;
  z-index: 10;
  transition: background 120ms;
}
.td-resize-handle:hover,
.td-resize-handle.active {
  background: var(--acc-threads, #a78bfa);
}
.td-resize-handle::after {
  content: '';
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 28px;
  height: 2px;
  background: rgba(255, 255, 255, 0.25);
  border-radius: 1px;
}

/* Tree */
.td-tree-wrap {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
}

.td-tree {
  display: flex;
  flex-direction: column;
  gap: 0;
}

/* Individual node */
.tn-row {
  display: flex;
  align-items: flex-start;
  gap: 0;
  position: relative;
}

.tn-lines {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex-shrink: 0;
  width: 32px;
  position: relative;
}

/* Vertical connector line from parent to child */
.tn-line-v {
  width: 1px;
  background: var(--line);
  flex: 1;
  min-height: 16px;
}

.tn-line-h {
  width: 14px;
  height: 1px;
  background: var(--line);
  margin-top: 20px;
  flex-shrink: 0;
}

/* Node card */
.tn-card {
  flex: 1;
  min-width: 0;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px;
  margin-bottom: 10px;
  transition: border-color 150ms;
  position: relative;
}
.tn-card:hover { border-color: var(--line-2, rgba(255,255,255,0.15)); }

.tn-card-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.tn-type-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 2px 7px;
  border-radius: 4px;
}

/* Type colors */
.tn-type-note    { background: rgba(167,139,250,0.12); color: #a78bfa; }
.tn-type-doc     { background: rgba(99,102,241,0.12);  color: #818cf8; }
.tn-type-slides  { background: rgba(236,72,153,0.12);  color: #f472b6; }
.tn-type-canvas  { background: rgba(59,130,246,0.12);  color: #60a5fa; }
.tn-type-chart   { background: rgba(153,206,154,0.12); color: #999cea; }
.tn-type-board   { background: rgba(16,185,129,0.12);  color: #34d399; }

.tn-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
  font-size: 10.5px;
  color: var(--fg-dim);
  white-space: nowrap;
}

.tn-branch-count {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 10.5px;
  color: var(--fg-dim);
}
.tn-branch-count svg { opacity: 0.5; }

.tn-body {
  font-size: 13px;
  line-height: 1.55;
  color: var(--fg-mute);
  white-space: pre-wrap;
  word-break: break-word;
}

.tn-title {
  font-size: 13px;
  font-weight: 500;
  color: var(--fg);
}

.tn-link {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11.5px;
  color: var(--acc-threads, #a78bfa);
  text-decoration: none;
  margin-top: 4px;
  transition: opacity 150ms;
}
.tn-link:hover { opacity: 0.75; }

.tn-actions {
  display: flex;
  gap: 5px;
  margin-top: 10px;
}

.tn-btn {
  font: inherit;
  font-size: 11px;
  font-weight: 500;
  padding: 3px 9px;
  border-radius: 5px;
  border: 1px solid var(--line);
  background: none;
  color: var(--fg-mute);
  cursor: pointer;
  transition: background 100ms, color 100ms, border-color 100ms;
}
.tn-btn:hover {
  background: var(--hover);
  color: var(--fg);
  border-color: var(--line-2, rgba(255,255,255,0.15));
}
.tn-btn.danger:hover {
  background: rgba(248,113,113,0.1);
  color: #f87171;
  border-color: rgba(248,113,113,0.3);
}

/* Children indentation wrapper */
.tn-children {
  padding-left: 32px;
  border-left: 1px solid var(--line);
  margin-left: 16px;
  margin-bottom: 4px;
  display: flex;
  flex-direction: column;
  gap: 0;
}

/* Add to thread button */
.td-add-root {
  margin-top: 8px;
}

.td-add-node-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font: inherit;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--fg-mute);
  background: none;
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 8px 14px;
  cursor: pointer;
  transition: background 120ms, color 120ms, border-color 120ms;
}
.td-add-node-btn:hover {
  background: var(--hover);
  color: var(--fg);
  border-color: var(--acc-threads, #a78bfa);
  border-style: solid;
}

/* ── Responsive ── */
@media (max-width: 700px) {
  /* Layout */
  .app { grid-template-columns: 1fr; }
  .rail { display: none; }

  /* Stack sidebar above detail */
  .threads-shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }

  .threads-sidebar {
    border-right: none;
    border-bottom: 1px solid var(--line);
    max-height: 220px;
  }

  /* Graph takes less vertical space on mobile */
  .td-graph-wrap { flex: 0 0 220px; }

  /* Topbar adapts */
  .td-topbar { padding: 12px 16px 10px; gap: 8px; }
  .td-title-input { font-size: 16px; }

  /* Tree content padding */
  .td-tree-wrap { padding: 16px; }

  /* Node popup full width */
  .node-popup { width: calc(100vw - 32px); }

  /* Selection bar adapts */
  .graph-selection-bar {
    width: calc(100% - 24px);
    flex-wrap: wrap;
    gap: 8px;
  }
  .gsb-actions { flex-wrap: wrap; width: 100%; }
  .gsb-branch-btn, .gsb-chat-btn { flex: 1; justify-content: center; }

  /* Bottom padding for nav bar */
  .threads-body { padding-bottom: 60px; }
}

/* Bottom nav (mobile only) */
.mobile-bottom-nav { display: none; }
@media (max-width: 700px) {
  .mobile-bottom-nav {
    display: flex;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    height: 60px;
    background: var(--bg-elev);
    border-top: 1px solid var(--line);
    z-index: 100;
    align-items: center;
    overflow-x: auto; -webkit-overflow-scrolling: touch;
    padding: 0 12px; gap: 0;
    padding-bottom: env(safe-area-inset-bottom);
  }
  .mobile-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    font-size: 10px;
    color: var(--fg-mute);
    text-decoration: none;
    padding: 6px 10px;
    border-radius: var(--radius-xs);
    transition: color var(--dur);
    min-width: 56px; flex-shrink: 0;
    text-align: center;
  }
  .mobile-nav-item[data-active] { color: var(--acc-threads, #a78bfa); }
  .mobile-nav-item svg { flex-shrink: 0; }
}

/* ── Node composer modal ── */
.node-composer-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 900;
  backdrop-filter: blur(2px);
}
.node-composer-backdrop.open { display: block; }

.node-composer {
  display: none;
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 901;
  width: 440px;
  max-width: calc(100vw - 32px);
  background: var(--bg-elev);
  border: 1px solid var(--line-2, rgba(255,255,255,0.12));
  border-radius: 14px;
  box-shadow: 0 24px 64px rgba(0,0,0,0.6);
  flex-direction: column;
  gap: 0;
  overflow: hidden;
}
.node-composer.open { display: flex; }

.nc-header {
  display: flex;
  align-items: center;
  padding: 14px 16px 12px;
  border-bottom: 1px solid var(--line);
}

.nc-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--fg);
  flex: 1;
}

.nc-close {
  background: none;
  border: none;
  color: var(--fg-mute);
  font-size: 18px;
  cursor: pointer;
  padding: 0 2px;
  line-height: 1;
  border-radius: 4px;
  transition: color 100ms;
}
.nc-close:hover { color: var(--fg); }

.nc-type-row {
  display: flex;
  gap: 4px;
  padding: 12px 16px;
  flex-wrap: wrap;
  border-bottom: 1px solid var(--line);
}

.nc-type-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font: inherit;
  font-size: 12px;
  font-weight: 500;
  padding: 5px 10px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: none;
  color: var(--fg-mute);
  cursor: pointer;
  transition: background 100ms, color 100ms, border-color 100ms;
}
.nc-type-btn:hover { background: var(--hover); color: var(--fg); }
.nc-type-btn.active {
  background: rgba(167,139,250,0.12);
  color: #a78bfa;
  border-color: rgba(167,139,250,0.3);
}

.nc-note-body,
.nc-output-body {
  padding: 12px 16px;
}

.nc-textarea {
  font: inherit;
  font-size: 13px;
  line-height: 1.55;
  color: var(--fg);
  background: var(--bg-elev-2, #1b1f2a);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  outline: none;
  resize: none;
  width: 100%;
  box-sizing: border-box;
  transition: border-color 150ms;
}
.nc-textarea:focus { border-color: var(--acc-threads, #a78bfa); }
.nc-textarea::placeholder { color: var(--fg-dim); }

.nc-output-title {
  font: inherit;
  font-size: 13px;
  color: var(--fg);
  background: var(--bg-elev-2, #1b1f2a);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 12px;
  outline: none;
  width: 100%;
  box-sizing: border-box;
  margin-bottom: 8px;
  transition: border-color 150ms;
}
.nc-output-title:focus { border-color: var(--acc-threads, #a78bfa); }

.nc-output-hint {
  font-size: 12px;
  color: var(--fg-mute);
  margin: 0;
  line-height: 1.4;
}

.nc-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--line);
}

.nc-cancel {
  font: inherit;
  font-size: 13px;
  padding: 6px 14px;
  border-radius: 7px;
  border: 1px solid var(--line);
  background: none;
  color: var(--fg-mute);
  cursor: pointer;
  transition: background 100ms, color 100ms;
}
.nc-cancel:hover { background: var(--hover); color: var(--fg); }

.nc-submit {
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 6px 18px;
  border-radius: 7px;
  border: none;
  background: var(--acc-threads, #a78bfa);
  color: #fff;
  cursor: pointer;
  transition: opacity 150ms;
}
.nc-submit:hover { opacity: 0.85; }

@media (max-width: 700px) {
  .node-composer {
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    transform: none;
    width: 100%;
    max-width: 100%;
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
    border-top-left-radius: 14px;
    border-top-right-radius: 14px;
    max-height: 85vh;
    overflow-y: auto;
  }
  .nc-type-row { gap: 6px; }
  .nc-type-btn { flex: 1 1 auto; justify-content: center; font-size: 11px; padding: 6px 8px; }
}
