/* ─── Reset & Base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --orange:        #F26419;
  --orange-light:  #FDE8D8;
  --orange-dim:    rgba(242,100,25,0.15);
  --blue:          #1D4ED8;
  --blue-light:    #DBEAFE;
  --blue-dim:      rgba(29,78,216,0.12);

  --bg:            #F5F4EF;
  --bg-pane:       #FAFAF7;
  --border:        rgba(0,0,0,0.10);
  --border-strong: rgba(0,0,0,0.18);
  --text:          #111111;
  --text-muted:    #666660;
  --text-faint:    #999990;

  --grid-minor: rgba(0,0,0,0.045);
  --grid-major: rgba(0,0,0,0.08);

  --radius:    4px;
  --header-h:  48px;
  --font:      'DM Mono', 'Courier New', monospace;
}

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 12px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* ─── Header ───────────────────────────────────────────────────────────────── */
.header {
  height: var(--header-h);
  display: flex;
  align-items: center;
  padding: 0 16px;
  border-bottom: 1px solid var(--border-strong);
  background: var(--bg-pane);
  gap: 12px;
  flex-shrink: 0;
  position: relative;
  z-index: 10;
}

.header-left { display: flex; align-items: center; }
.header-left a { display: flex; text-decoration: none; color: inherit; }
.logo { height: 24px; width: auto; object-fit: contain; }

.header-tabs {
  display: flex;
  align-items: center;
  gap: 2px;
  flex: 1;
}

.tab-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text-muted);
  font-family: var(--font);
  font-size: 11px;
  cursor: pointer;
  transition: background 0.2s, color 0.2s, border-color 0.2s;
}
.tab-btn:hover {
  background: var(--grid-minor);
  color: var(--text);
}
.tab-btn.active {
  background: var(--bg-pane);
  color: var(--text);
  border-color: var(--border-strong);
}
.tab-btn .feature-tag { font-size: 9px; }
.tab-btn .feature-label { font-size: 11px; letter-spacing: 0.04em; }

.tab-pane.main-content {
  display: flex;
  flex: 1;
  height: 100%;
  overflow: hidden;
}
.tab-pane.main-content.hidden { display: none; }

.feature-tag {
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.08em;
  color: var(--orange);
  background: var(--orange-dim);
  border: 1px solid rgba(242,100,25,0.3);
  border-radius: 3px;
  padding: 1px 6px;
  text-transform: uppercase;
}

.feature-label {
  font-size: 11px;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  text-transform: uppercase;
}

.header-tab-select {
  display: none;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
  font-size: 10px;
  color: var(--text-faint);
  letter-spacing: 0.04em;
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-faint);
  flex-shrink: 0;
  transition: background 0.4s;
}
.status-dot.ok  { background: #22c55e; }
.status-dot.err { background: #ef4444; }

/* ─── Main layout ──────────────────────────────────────────────────────────── */
.main {
  display: flex;
  height: calc(100vh - var(--header-h));
  overflow: hidden;
}

/* ─── Panes ────────────────────────────────────────────────────────────────── */
.pane {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

.pane-left  { width: 38%; min-width: 280px; background: var(--bg-pane); }
.pane-right { flex: 1; min-width: 320px; }

/* ─── Divider ──────────────────────────────────────────────────────────────── */
.divider {
  width: 5px;
  background: var(--border);
  cursor: col-resize;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
  position: relative;
  z-index: 5;
}
.divider:hover,
.divider.dragging { background: var(--orange); }

.divider-handle {
  width: 3px;
  height: 32px;
  border-radius: 2px;
  background: var(--border-strong);
  pointer-events: none;
  transition: background 0.15s;
}
.divider:hover .divider-handle,
.divider.dragging .divider-handle { background: var(--orange); }

/* ─── Search ───────────────────────────────────────────────────────────────── */
.search-wrap {
  padding: 12px 14px 10px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.search-row {
  display: flex;
  gap: 6px;
  align-items: center;
}

.search-field {
  flex: 1;
  display: flex;
  align-items: center;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--bg-pane);
  padding: 0 8px;
  gap: 6px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.search-field:focus-within {
  border-color: var(--orange);
  box-shadow: 0 0 0 2px var(--orange-dim);
}

.search-icon {
  width: 13px;
  height: 13px;
  stroke: var(--text-faint);
  flex-shrink: 0;
}

#search-input,
#subsets-input {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  font-family: var(--font);
  font-size: 12px;
  color: var(--text);
  padding: 7px 0;
  line-height: 1;
}
#search-input::placeholder,
#subsets-input::placeholder { color: var(--text-faint); }

.btn-clear {
  background: none;
  border: none;
  cursor: pointer;
  padding: 2px;
  display: flex;
  align-items: center;
  color: var(--text-faint);
  flex-shrink: 0;
}
.btn-clear:hover { color: var(--text); }
.btn-clear i { width: 12px; height: 12px; }

.btn-search {
  background: var(--orange);
  border: none;
  border-radius: var(--radius);
  padding: 0 10px;
  height: 32px;
  cursor: pointer;
  display: flex;
  align-items: center;
  color: white;
  flex-shrink: 0;
  transition: background 0.15s;
}
.btn-search:hover { background: #d9541a; }
.btn-search i { width: 14px; height: 14px; }

.search-meta {
  margin-top: 6px;
  font-size: 10px;
  color: var(--text-faint);
  letter-spacing: 0.03em;
  min-height: 14px;
}
.search-history {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 0 14px 10px;
  flex-wrap: wrap;
  border-bottom: 1px solid var(--border);
}
.search-history .examples-label {
  flex-shrink: 0;
}
.search-history-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.search-history-item {
  max-width: 220px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ─── Results ──────────────────────────────────────────────────────────────── */
.results {
  flex: 1;
  overflow-y: auto;
  padding: 10px 14px 14px;
  scroll-behavior: smooth;
}

.results::-webkit-scrollbar { width: 4px; }
.results::-webkit-scrollbar-track { background: transparent; }
.results::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 2px; }

/* Empty state */
.results-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  gap: 10px;
  color: var(--text-faint);
  text-align: center;
  padding: 24px;
}
.empty-icon { width: 28px; height: 28px; stroke: var(--text-faint); opacity: 0.5; }
.results-empty p { font-size: 11px; line-height: 1.5; }
.hint { font-size: 10px; font-style: italic; opacity: 0.7; }

/* Loading */
.loading-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
  color: var(--text-faint);
  gap: 10px;
  font-size: 11px;
}
.spinner {
  width: 14px; height: 14px;
  border: 2px solid var(--border);
  border-top-color: var(--orange);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Article card */
.article-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  margin-bottom: 8px;
  background: var(--bg-pane);
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s;
  position: relative;
}
.article-card:hover,
.article-card.active {
  border-color: var(--orange);
  box-shadow: 0 0 0 2px var(--orange-dim);
}

.card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 5px;
}

.card-title {
  font-size: 11px;
  font-weight: 500;
  line-height: 1.4;
  color: var(--text);
  flex: 1;
}

.card-score {
  font-size: 9px;
  color: var(--orange);
  background: var(--orange-dim);
  border-radius: 3px;
  padding: 1px 5px;
  flex-shrink: 0;
  letter-spacing: 0.05em;
  font-weight: 500;
  white-space: nowrap;
  margin-top: 1px;
}

.card-meta {
  font-size: 9px;
  color: var(--text-faint);
  letter-spacing: 0.04em;
  margin-bottom: 6px;
}

.card-snippet {
  font-size: 10px;
  color: var(--text-muted);
  line-height: 1.55;
  margin-bottom: 8px;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-bottom {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.card-entities {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  flex: 1;
}

.card-link {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  color: var(--text-faint);
  border-radius: var(--radius);
  transition: color 0.15s, background 0.15s;
}
.card-link:hover {
  color: var(--orange);
  background: var(--orange-dim);
}
.card-link i { width: 13px; height: 13px; }

.entity-tag {
  font-size: 9px;
  padding: 2px 6px;
  border-radius: 3px;
  background: var(--blue-light);
  color: var(--blue);
  border: 1px solid rgba(29,78,216,0.15);
  letter-spacing: 0.03em;
  white-space: nowrap;
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.entity-tag.matched {
  background: var(--orange-dim);
  color: var(--orange);
  border-color: rgba(242,100,25,0.3);
}

/* ─── Graph pane ───────────────────────────────────────────────────────────── */
.graph-wrap {
  position: relative;
  width: 100%;
  height: 100%;

  /* Architectural grid — minor lines every 20px, major every 100px */
  background-color: #F2F1EC;
  background-image:
    linear-gradient(var(--grid-major) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-major) 1px, transparent 1px),
    linear-gradient(var(--grid-minor) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-minor) 1px, transparent 1px);
  background-size: 100px 100px, 100px 100px, 20px 20px, 20px 20px;
  background-position: -1px -1px, -1px -1px, -1px -1px, -1px -1px;
}

#graph-svg {
  width: 100%;
  height: 100%;
  display: block;
  cursor: grab;
}
#graph-svg:active { cursor: grabbing; }

/* Graph edges */
.graph-link {
  stroke: rgba(0,0,0,0.25);
  stroke-width: 1;
  fill: none;
  pointer-events: none;
  transition: stroke 0.2s;
}
/* Entity→entity relation edges — teal */
.graph-link-relation {
  stroke: rgba(14,165,133,0.5);
  stroke-width: 1.2;
}
.graph-link.highlighted          { stroke: var(--orange); stroke-width: 1.8; stroke-opacity: 0.8; }
.graph-link-relation.highlighted { stroke: rgba(14,165,133,0.9); }

/* Graph nodes */
.graph-node { cursor: pointer; }
.graph-node circle {
  transition: r 0.3s, fill-opacity 0.3s;
}
.graph-node.dimmed circle { fill-opacity: 0.25; }
.graph-node.dimmed text   { opacity: 0.2; }
.graph-node:hover circle  { filter: url(#glow); }

.node-label {
  font-family: var(--font);
  font-size: 6px;
  fill: white;
  text-anchor: middle;
  dominant-baseline: central;
  pointer-events: none;
  user-select: none;
  letter-spacing: 0.03em;
}
.node-label.article-label { font-size: 7px; }

/* Tooltip */
.tooltip {
  position: absolute;
  background: var(--bg-pane);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 8px 10px;
  font-family: var(--font);
  font-size: 10px;
  line-height: 1.5;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.12s;
  max-width: 240px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
  z-index: 100;
}
.tooltip.visible { opacity: 1; }
.tooltip-type {
  font-size: 9px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  margin-bottom: 3px;
}
.tooltip-type.t-article  { color: var(--orange); }
.tooltip-type.t-entity   { color: var(--blue); }
.tooltip-type.t-relation { color: #0d9488; }
.tooltip-title { font-weight: 500; color: var(--text); margin-top: 1px; }
.tooltip-sub   { color: var(--text-faint); font-size: 9px; margin-top: 2px; }

/* Edge tooltip */
.tooltip-edge-header {
  font-size: 9px;
  letter-spacing: 0.03em;
  color: var(--text-faint);
  margin-bottom: 2px;
}
.tooltip-edge-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 5px;
  flex-wrap: wrap;
}

/* Relation category chips (search mode) */
.tooltip-cats {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
  margin-top: 6px;
}
.cat-chip {
  font-size: 8px;
  font-weight: 500;
  letter-spacing: 0.04em;
  padding: 2px 6px;
  border-radius: 3px;
  color: white;
  text-transform: lowercase;
}

/* ─── Recenter popup ───────────────────────────────────────────────────────── */
.recenter-popup {
  position: absolute;
  z-index: 200;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.25);
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 140px;
}
.recenter-label {
  font-size: 11px;
  font-weight: 500;
  color: var(--blue);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 200px;
}
.recenter-btn {
  font-family: inherit;
  font-size: 11px;
  padding: 5px 12px;
  border: none;
  border-radius: 5px;
  background: var(--blue);
  color: white;
  cursor: pointer;
  transition: background 0.15s;
}
.recenter-btn:hover {
  background: #1739A8;
}

/* ─── Evidence panel ────────────────────────────────────────────────────────── */
.evidence-panel {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 280px;
  max-height: calc(100% - 80px);
  background: var(--bg-pane);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0,0,0,0.12);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 50;
}
.evidence-panel.hidden { display: none; }

.evidence-panel-header {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}
.ev-relation { display: flex; flex-direction: column; gap: 4px; flex: 1; min-width: 0; }
.ev-names {
  font-size: 9px;
  color: var(--text-faint);
  letter-spacing: 0.03em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ev-type {
  font-size: 11px;
  font-weight: 500;
  color: var(--text);
}
.ev-close {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 14px;
  color: var(--text-faint);
  padding: 0;
  line-height: 1;
  flex-shrink: 0;
}
.ev-close:hover { color: var(--text); }

.evidence-panel-body {
  overflow-y: auto;
  padding: 8px 12px 12px;
  flex: 1;
}
.evidence-panel-body::-webkit-scrollbar { width: 3px; }
.evidence-panel-body::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 2px; }

.ev-article {
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}
.ev-article:last-child { border-bottom: none; }
.ev-article-title {
  font-size: 10px;
  font-weight: 500;
  color: var(--text);
  line-height: 1.4;
  margin-bottom: 2px;
}
.ev-article-date { font-size: 9px; color: var(--text-faint); margin-bottom: 4px; }
.ev-article-snippet {
  font-size: 9px;
  color: var(--text-muted);
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.ev-extra {
  font-size: 9px;
  color: var(--text-faint);
  margin-top: 8px;
  font-style: italic;
}
.ev-empty { font-size: 10px; color: var(--text-faint); padding: 8px 0; }

/* Graph controls */
.graph-controls {
  position: absolute;
  bottom: 14px;
  right: 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.graph-btn {
  width: 28px; height: 28px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--bg-pane);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  transition: border-color 0.15s, color 0.15s;
}
.graph-btn:hover { border-color: var(--orange); color: var(--orange); }
.graph-btn i { width: 12px; height: 12px; }

/* Legend */
.graph-legend {
  position: absolute;
  bottom: 14px;
  left: 14px;
  background: var(--bg-pane);
  backdrop-filter: blur(4px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 10px;
  font-size: 10px;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.legend-row {
  display: flex;
  align-items: center;
  gap: 6px;
}
.legend-hint {
  color: var(--text-faint);
  font-size: 9px;
  letter-spacing: 0.03em;
  margin-top: 2px;
  border-top: 1px solid var(--border);
  padding-top: 4px;
}
.legend-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.dot-article { background: var(--orange); }
.dot-entity  { background: var(--blue); }

/* ─── Document tab ─────────────────────────────────────────────────────────── */
.document-layout {
  display: flex;
  flex: 1;
  min-height: 0;
  gap: 0;
}
.document-editor {
  position: relative;
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 16px;
  min-width: 280px;
  border-right: 1px solid var(--border);
}
.doc-example-wrap {
  margin-bottom: 12px;
}
.doc-example-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: transparent;
  color: var(--text-muted);
  font-family: var(--font);
  font-size: 11px;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}
.doc-example-btn:hover {
  border-color: var(--orange);
  color: var(--orange);
  background: var(--orange-dim);
}
.doc-example-btn i {
  width: 14px;
  height: 14px;
}

.doc-title-input {
  width: 100%;
  border: none;
  border-bottom: 1px solid var(--border-strong);
  padding: 8px 0;
  font-family: var(--font);
  font-size: 14px;
  margin-bottom: 12px;
  background: transparent;
}
.doc-title-input::placeholder { color: var(--text-faint); }
/* Textarea + overlay wrapper */
.doc-body-wrap {
  position: relative;
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 200px;
}
.doc-body-input {
  flex: 1;
  min-height: 200px;
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  font-family: var(--font);
  font-size: 12px;
  line-height: 1.6;
  resize: vertical;
  background: var(--bg-pane);
  position: relative;
  z-index: 2;
  /* Make text transparent so overlay highlights show through background */
  color: var(--text);
  caret-color: var(--text);
}
.doc-body-input::placeholder { color: var(--text-faint); }

/* Overlay mirrors textarea exactly — sits behind it */
.doc-body-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 12px;
  font-family: var(--font);
  font-size: 12px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow: hidden;
  color: transparent;
  pointer-events: none;
  z-index: 3;
  border: 1px solid transparent;
  border-radius: var(--radius);
}

/* Highlight spans in overlay — pointer-events enabled so they can be hovered */
.link-highlight {
  background: var(--orange-dim);
  border-radius: 3px;
  color: transparent;
  pointer-events: auto;
  cursor: pointer;
  transition: background 0.15s;
}
.link-highlight:hover {
  background: rgba(242,100,25,0.30);
}

/* ─── Link hover card ─────────────────────────────────────────────────────── */
.link-hover-card {
  position: absolute;
  z-index: 100;
  width: 280px;
  background: var(--bg-pane);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.12);
  padding: 10px 12px;
  font-family: var(--font);
}
.link-hover-card.hidden { display: none; }

.link-hover-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}
.link-hover-card-counter {
  font-size: 9px;
  color: var(--text-faint);
  letter-spacing: 0.04em;
}
.link-hover-card-close {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 14px;
  color: var(--text-faint);
  padding: 0;
  line-height: 1;
}
.link-hover-card-close:hover { color: var(--text); }

.link-card-title {
  font-size: 11px;
  font-weight: 500;
  color: var(--text);
  line-height: 1.4;
  margin-bottom: 3px;
}
.link-card-date {
  font-size: 9px;
  color: var(--text-faint);
  margin-bottom: 6px;
}
.link-card-snippet {
  font-size: 10px;
  color: var(--text-muted);
  line-height: 1.5;
  margin-bottom: 8px;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.link-card-ext {
  font-size: 10px;
  color: var(--orange);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.link-card-ext:hover { text-decoration: underline; }
.link-card-ext i { width: 11px; height: 11px; }

.link-hover-card-nav {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}
.link-hover-card-nav.hidden { display: none; }
.link-nav-btn {
  width: 24px;
  height: 24px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-pane);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  transition: border-color 0.15s, color 0.15s;
}
.link-nav-btn:hover { border-color: var(--orange); color: var(--orange); }
.link-nav-btn i { width: 12px; height: 12px; }
.document-graph-panel {
  width: 320px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  padding: 12px;
  background: var(--bg);
}
.doc-panel-header {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 8px;
}
.doc-graph-label {
  font-size: 10px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.doc-sort-view {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}
.doc-sort-tabs {
  display: flex;
  align-items: center;
  gap: 4px;
}
.doc-sort-tab {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text-muted);
  font-family: var(--font);
  font-size: 11px;
  cursor: pointer;
  transition: background 0.2s, color 0.2s, border-color 0.2s;
}
.doc-sort-tab:hover {
  background: var(--grid-minor);
  color: var(--text);
}
.doc-sort-tab.active {
  background: var(--bg-pane);
  color: var(--text);
  border-color: var(--border-strong);
}
.doc-sort-tag {
  font-size: 9px;
  font-weight: 500;
  letter-spacing: 0.08em;
  color: var(--orange);
  background: var(--orange-dim);
  border: 1px solid rgba(242,100,25,0.3);
  border-radius: 3px;
  padding: 1px 6px;
  text-transform: uppercase;
}
.doc-sort-tab-label {
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.doc-recommended-list {
  flex: 1;
  min-height: 200px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.doc-recommended-list::-webkit-scrollbar { width: 4px; }
.doc-recommended-list::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 2px; }
.doc-recommended-list .article-card { cursor: default; }
.doc-entity-hint { margin-top: 6px; font-size: 10px; color: var(--text-faint); line-height: 1.4; }

/* ─── Subsets tab ──────────────────────────────────────────────────────────── */
.subsets-examples {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  flex-wrap: wrap;
}
.subsets-history {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 6px 16px 10px;
  flex-wrap: wrap;
  border-bottom: 1px solid var(--border);
}
.subsets-history .examples-label {
  flex-shrink: 0;
}
.subsets-history-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.subsets-history-item {
  max-width: 220px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.examples-label {
  font-size: 10px;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 500;
}
.example-chip {
  font-family: inherit;
  font-size: 11px;
  padding: 5px 12px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--panel);
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s;
}
.example-chip:hover {
  border-color: var(--blue);
  color: var(--blue);
  background: var(--blue-dim);
}

.subsets-results {
  flex: 1;
  overflow-y: auto;
  padding: 0 16px 24px;
  -webkit-overflow-scrolling: touch;
}

/* Cypher block */
.cypher-block {
  margin-bottom: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}
.cypher-summary {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
  background: var(--surface);
}
.cypher-summary:hover { color: var(--text-main); }
.cypher-code {
  padding: 12px;
  font-family: "DM Mono", monospace;
  font-size: 11px;
  line-height: 1.5;
  color: var(--text-main);
  background: var(--bg);
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-all;
  border-top: 1px solid var(--border);
}

/* Query summary */
.subsets-query-summary {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 12px;
  line-height: 1.4;
}

/* Resolved entity chips */
.resolved-entities {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.resolved-chip {
  font-size: 11px;
  padding: 3px 10px;
  border-radius: 12px;
  background: var(--blue-dim);
  color: var(--blue);
  font-weight: 500;
}
.resolved-chip small {
  font-weight: 400;
  opacity: 0.7;
  margin-left: 4px;
  font-size: 9px;
  text-transform: uppercase;
}

/* Results table */
.subsets-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
}
.subsets-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 11px;
}
.subsets-table th {
  text-align: left;
  padding: 8px 12px;
  background: var(--surface);
  font-weight: 600;
  color: var(--text-main);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  text-transform: lowercase;
  font-size: 10px;
  letter-spacing: 0.03em;
}
.subsets-table td {
  padding: 7px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--text-muted);
  max-width: 300px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.subsets-table tr:last-child td { border-bottom: none; }
.subsets-table tr:hover td { background: var(--surface); }

/* Right pane: database results */
.subsets-db-pane {
  height: 100%;
  overflow-y: auto;
  padding: 16px 16px 32px;
  background: var(--bg);
  -webkit-overflow-scrolling: touch;
}
.subsets-db-pane .subsets-table-wrap {
  border-radius: 8px;
  border: 1px solid var(--border);
  overflow-x: auto;
}
.subsets-db-pane .subsets-table th {
  position: sticky;
  top: 0;
  z-index: 1;
}
.subsets-db-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-faint);
  gap: 8px;
}
.subsets-table-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 12px;
  padding-bottom: 8px;
}
.subsets-row-count {
  font-size: 10px;
  color: var(--text-faint);
}
.subsets-download-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-family: var(--font);
  font-size: 10px;
  padding: 4px 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--bg-pane);
  color: var(--text-muted);
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}
.subsets-download-btn:hover {
  border-color: var(--orange);
  color: var(--orange);
}
.subsets-download-btn i { width: 12px; height: 12px; }

/* ─── Mobile layout (max-width: 768px) ───────────────────────────────────────── */
@media (max-width: 768px) {
  .header {
    padding: 0 10px;
    gap: 8px;
    flex-wrap: nowrap;
  }
  .header-tabs {
    display: none !important;
  }
  .header-tab-select {
    display: flex;
    flex: 1;
    max-width: 180px;
    padding: 6px 10px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    background: var(--bg-pane);
    color: var(--text);
    font-family: var(--font);
    font-size: 11px;
    cursor: pointer;
    -webkit-appearance: none;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23999990' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 8px center;
    padding-right: 28px;
  }
  .header-tab-select:focus {
    outline: none;
    border-color: var(--orange);
    box-shadow: 0 0 0 2px var(--orange-dim);
  }
  .header-right {
    font-size: 9px;
  }
  .main {
    flex-direction: column;
    height: calc(100vh - var(--header-h));
  }
  .tab-pane.main-content {
    flex-direction: column;
    min-height: 0;
  }
  /* Mobile pane toggle bar (Results | Graph, or Query | Data) */
  .mobile-pane-toggle {
    display: flex;
    gap: 0;
    padding: 0 12px;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
  }
  .mobile-toggle-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 12px;
    border: none;
    border-bottom: 2px solid transparent;
    background: transparent;
    color: var(--text-muted);
    font-family: var(--font);
    font-size: 11px;
    cursor: pointer;
    transition: color 0.2s, border-color 0.2s, background 0.15s;
  }
  .mobile-toggle-btn i {
    width: 14px;
    height: 14px;
  }
  .mobile-toggle-btn.active {
    color: var(--orange);
    border-bottom-color: var(--orange);
    background: var(--orange-dim);
  }
  /* Graph Search tab: one pane at a time */
  #tab-graph-search .divider {
    display: none;
  }
  #tab-graph-search .pane-left,
  #tab-graph-search .pane-right {
    width: 100%;
    min-width: 0;
    flex: 1;
    min-height: 200px;
  }
  body.mobile-view-graph #tab-graph-search .pane-left {
    display: none;
  }
  body.mobile-view-results #tab-graph-search .pane-right {
    display: none;
  }
  /* Subsets tab: stack query on top, database below; scroll to see both */
  #tab-subsets .divider,
  #tab-subsets .subsets-divider {
    display: none;
  }
  #tab-subsets.tab-pane.main-content {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  #tab-subsets .pane-left,
  #tab-subsets .pane-right {
    width: 100%;
    min-width: 0;
    flex: none;
  }
  #tab-subsets .pane-left {
    border-bottom: 1px solid var(--border);
  }
  #tab-subsets .subsets-db-pane {
    padding-bottom: 48px;
  }
  /* Document tab: stack editor and panel — no overlap, clearly separate */
  .document-layout {
    flex-direction: column;
    overflow: hidden;
  }
  .document-editor {
    flex: none;
    min-height: 200px;
    max-height: 50vh;
    border-right: none;
    border-bottom: 1px solid var(--border);
    overflow: hidden;
    display: flex;
    flex-direction: column;
  }
  .document-editor .doc-body-wrap {
    min-height: 0;
    overflow: auto;
  }
  .document-graph-panel {
    flex: 1;
    width: 100%;
    min-height: 180px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  .document-graph-panel .doc-recommended-list {
    overflow: visible;
  }
  .link-hover-card-close {
    padding: 8px;
    margin: -8px -8px -8px 0;
  }
  /* Graph controls and legend: compact on mobile */
  .graph-controls {
    bottom: 8px;
    right: 8px;
  }
  .graph-legend {
    padding: 6px 8px;
    max-width: 140px;
  }
  .evidence-panel {
    width: 100%;
    max-width: none;
    max-height: 50vh;
  }
}

/* Hide mobile toggle on desktop only (so it doesn't override the mobile rule) */
@media (min-width: 769px) {
  .mobile-pane-toggle {
    display: none !important;
  }
}
