/* ============================================================
   Results Workspace — bottom panel with tabs + master-detail
   ============================================================ */

/* --- Workspace container --- */
#results-workspace {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 0;
  z-index: 12;
  background: rgba(17, 17, 24, 0.96);
  backdrop-filter: blur(16px);
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: height var(--transition);
}
#results-workspace.ws-open {
  height: var(--ws-height, 40vh);
}

/* --- Resize handle --- */
.ws-resize-handle {
  height: 6px;
  cursor: ns-resize;
  flex-shrink: 0;
  position: relative;
  background: transparent;
  transition: background 0.15s ease;
}
.ws-resize-handle::after {
  content: '';
  position: absolute;
  left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  width: 40px; height: 3px;
  border-radius: 2px;
  background: var(--border);
  transition: background 0.15s ease;
}
.ws-resize-handle:hover,
.ws-resize-handle.ws-dragging {
  background: rgba(233, 69, 96, 0.08);
}
.ws-resize-handle:hover::after,
.ws-resize-handle.ws-dragging::after {
  background: var(--accent);
}

/* --- Tab bar --- */
.ws-tab-bar {
  display: flex;
  align-items: center;
  padding: 0 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  height: 36px;
  gap: 0;
}
.ws-tab {
  background: none; border: none; color: var(--muted);
  font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.8px;
  padding: 8px 14px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color 0.15s, border-color 0.15s;
  line-height: 1;
}
.ws-tab:hover { color: var(--text); }
.ws-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* Tab actions (right side) */
.ws-tab-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}
.ws-row-count {
  font-size: 11px;
  color: var(--muted);
  padding: 2px 8px;
  background: rgba(255,255,255,0.04);
  border-radius: 10px;
  font-variant-numeric: tabular-nums;
}
.ws-action-btn {
  background: none; border: none;
  color: var(--muted); cursor: pointer;
  padding: 4px; border-radius: 4px;
  display: flex; align-items: center;
  transition: color 0.15s, background 0.15s;
}
.ws-action-btn:hover {
  color: var(--text);
  background: rgba(255,255,255,0.06);
}
.ws-action-btn svg { width: 14px; height: 14px; }

/* --- Body (master-detail split) --- */
.ws-body {
  flex: 1;
  display: flex;
  overflow: hidden;
  min-height: 0;
}
#ws-table-pane {
  flex: 1;
  overflow: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
#ws-table-pane::-webkit-scrollbar { width: 6px; height: 6px; }
#ws-table-pane::-webkit-scrollbar-track { background: transparent; }
#ws-table-pane::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

#ws-preview-pane {
  width: 35%;
  min-width: 280px;
  max-width: 480px;
  border-left: 1px solid var(--border);
  overflow-y: auto;
  padding: 16px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
#ws-preview-pane::-webkit-scrollbar { width: 6px; }
#ws-preview-pane::-webkit-scrollbar-track { background: transparent; }
#ws-preview-pane::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* --- Data table --- */
.ws-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  table-layout: auto;
}
.ws-table thead { position: sticky; top: 0; z-index: 1; }
.ws-table th {
  background: var(--panel-alt);
  color: var(--muted);
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 6px 10px;
  text-align: left;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  border-bottom: 1px solid var(--border);
}
.ws-table th:hover { color: var(--text); }
.ws-table th .sort-arrow {
  display: inline-block;
  margin-left: 4px;
  font-size: 9px;
  opacity: 0.3;
}
.ws-table th.sorted .sort-arrow { opacity: 1; color: var(--accent); }

.ws-table td {
  padding: 6px 10px;
  border-bottom: 1px solid rgba(30, 30, 46, 0.5);
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
}
.ws-table tbody tr {
  cursor: pointer;
  transition: background 0.1s;
}
.ws-table tbody tr:hover {
  background: rgba(255, 255, 255, 0.03);
}
.ws-table tbody tr.selected {
  background: rgba(233, 69, 96, 0.08);
  border-left: 3px solid var(--accent);
}
.ws-table tbody tr.selected td:first-child {
  padding-left: 7px; /* compensate for 3px border */
}

/* Status badges in table */
.ws-badge {
  display: inline-block;
  padding: 2px 6px;
  border-radius: 3px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.ws-badge-uploaded   { background: rgba(74,158,255,0.15); color: #4a9eff; }
.ws-badge-extracted  { background: rgba(0,212,138,0.15); color: var(--success); }
.ws-badge-parsed     { background: rgba(78,205,196,0.15); color: #4ECDC4; }
.ws-badge-linked     { background: rgba(187,134,252,0.15); color: #BB86FC; }
.ws-badge-failed     { background: rgba(233,69,96,0.15); color: var(--accent); }

/* Confidence bar */
.ws-confidence-cell {
  display: flex;
  align-items: center;
  gap: 6px;
}
.ws-confidence-bar {
  width: 50px; height: 4px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
}
.ws-confidence-fill {
  height: 100%;
  border-radius: 2px;
  transition: width 0.3s;
}

/* --- Preview pane --- */
.ws-preview-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--muted);
  font-size: 13px;
  gap: 8px;
}
.ws-preview-empty svg { opacity: 0.4; }

.ws-preview-section {
  margin-bottom: 16px;
}
.ws-preview-section h4 {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--muted);
  margin-bottom: 8px;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--border);
}
.ws-field-grid {
  display: grid;
  grid-template-columns: 100px 1fr;
  gap: 4px 8px;
  font-size: 12px;
}
.ws-field-label {
  color: var(--muted);
  font-size: 11px;
}
.ws-field-value {
  color: var(--text);
  word-break: break-word;
}

.ws-preview-confidence {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 8px 0;
}
.ws-preview-confidence-bar {
  flex: 1;
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
}
.ws-preview-confidence-fill {
  height: 100%;
  border-radius: 3px;
}
.ws-preview-confidence-label {
  font-size: 12px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.ws-json-block {
  background: rgba(0,0,0,0.3);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px;
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 11px;
  line-height: 1.5;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 200px;
  color: var(--text);
}

.ws-preview-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: rgba(233, 69, 96, 0.12);
  color: var(--accent);
  border: 1px solid rgba(233, 69, 96, 0.25);
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
  margin-top: 8px;
}
.ws-preview-btn:hover {
  background: rgba(233, 69, 96, 0.2);
}

/* --- Loading state --- */
.ws-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
  color: var(--muted);
  font-size: 13px;
  gap: 10px;
}
.ws-loading .loading-spinner {
  width: 20px; height: 20px;
  margin: 0;
  border-width: 2px;
}

/* Empty state */
.ws-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px;
  color: var(--muted);
  font-size: 13px;
  gap: 8px;
}

/* --- Layout overrides when workspace is open --- */
body.ws-active #map {
  bottom: var(--ws-height, 40vh);
}
body.ws-active #sidebar {
  bottom: var(--ws-height, 40vh);
}
body.ws-active #timeline-bar {
  display: none;
}
body.ws-active #map-legend {
  bottom: calc(var(--ws-height, 40vh) + 12px);
}

/* Prevent text selection during resize drag */
body.ws-resizing {
  user-select: none;
  cursor: ns-resize;
}

/* ── AI Insights ── */
.ai-chip {
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: all 0.15s;
}
.ai-chip:hover { border-color: var(--accent); color: var(--text); }
.ai-chip.active {
  background: rgba(233, 69, 96, 0.12);
  border-color: var(--accent);
  color: var(--accent);
}

/* ── Spatial panels ── */
.sp-panel {
  padding: 12px;
  background: rgba(255,255,255,0.02);
  border: 1px solid var(--border);
  border-radius: 8px;
}

/* ── Entity results ── */
#ent-results .ws-table { margin-top: 0; }
#ent-results h4 { margin-top: 12px; }

/* ── Cytoscape Graph ── */
#cy-graph {
  width: 100%;
  height: 100%;
  min-height: 300px;
  background: #0a0a0f;
  position: relative;
}
.cy-legend {
  position: absolute;
  bottom: 8px;
  left: 8px;
  right: 8px;
  pointer-events: none;
  z-index: 2;
}
.cy-legend-inner {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 10px;
  background: rgba(10, 10, 15, 0.85);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 11px;
  color: var(--text);
  backdrop-filter: blur(8px);
}
.cy-legend-item {
  display: flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
}
.cy-legend-swatch {
  display: inline-block;
  width: 10px;
  height: 10px;
  flex-shrink: 0;
}

/* --- Responsive --- */
@media (max-width: 900px) {
  #ws-preview-pane {
    display: none; /* hide detail on narrow screens, table fills width */
  }
}
@media (max-width: 600px) {
  #results-workspace.ws-open {
    height: 50vh;
  }
  .ws-tab { padding: 8px 10px; font-size: 10px; }
}
