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

:root {
  --bg: #0a0e17;
  --bg-card: #111827;
  --bg-card-hover: #1a2332;
  --border: #1e293b;
  --text: #e2e8f0;
  --text-dim: #94a3b8;
  --text-bright: #f8fafc;
  --accent: #3b82f6;
  --accent-dim: #1e40af;
  --red: #ef4444;
  --orange: #f97316;
  --yellow: #eab308;
  --green: #22c55e;
  --cyan: #06b6d4;
  --purple: #a855f7;
  --font-mono: 'SF Mono', 'Cascadia Code', 'Fira Code', 'Consolas', monospace;
  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.6;
  min-height: 100vh;
}

/* === Header === */
header {
  background: linear-gradient(180deg, #0f1729 0%, var(--bg) 100%);
  border-bottom: 1px solid var(--border);
  padding: 24px 32px 16px;
}

.header-content h1 {
  font-size: 20px;
  font-weight: 600;
  color: var(--text-bright);
  letter-spacing: -0.02em;
}

.subtitle {
  color: var(--text-dim);
  font-size: 13px;
  margin-top: 4px;
}

.last-updated {
  color: var(--text-dim);
  font-size: 11px;
  font-family: var(--font-mono);
  margin-top: 8px;
}

/* === Navigation === */
nav {
  display: flex;
  gap: 4px;
  padding: 8px 32px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 100;
  overflow-x: auto;
}

.nav-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-dim);
  font-size: 12px;
  font-family: var(--font-sans);
  padding: 6px 14px;
  border-radius: 6px;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s ease;
}

.nav-btn:hover {
  color: var(--text);
  background: var(--bg-card);
}

.nav-btn.active {
  color: var(--text-bright);
  background: var(--bg-card);
  border-color: var(--border);
}

/* === Main Layout === */
main {
  padding: 24px 32px;
  max-width: 1400px;
  margin: 0 auto;
}

.dashboard-section {
  display: none;
}

.dashboard-section.active {
  display: block;
}

/* === Grid === */
.grid-2col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
}

@media (max-width: 900px) {
  .grid-2col {
    grid-template-columns: 1fr;
  }
  main { padding: 16px; }
  nav { padding: 8px 16px; }
  header { padding: 16px; }
}

/* === Cards === */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 20px;
}

.card h2 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-bright);
  margin-bottom: 4px;
}

.card-desc {
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 16px;
}

.card.full-width {
  margin-bottom: 16px;
}

/* === Charts (Chart.js canvases only — not force-graph) === */
.card > canvas {
  width: 100% !important;
  max-height: 300px;
}

/* === Timeline === */
.timeline {
  max-height: 320px;
  overflow-y: auto;
}

.timeline-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}

.timeline-item:last-child {
  border-bottom: none;
}

.timeline-date {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-dim);
  min-width: 80px;
  flex-shrink: 0;
}

.timeline-body {
  flex: 1;
}

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

.timeline-meta {
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 2px;
}

.tag {
  display: inline-block;
  font-size: 10px;
  font-family: var(--font-mono);
  padding: 1px 6px;
  border-radius: 3px;
  margin-right: 4px;
}

.tag-frontier-closed {
  background: var(--accent-dim);
  color: var(--accent);
}

.tag-open-weights, .tag-frontier-open {
  background: #14532d;
  color: var(--green);
}

.tag-fine-tune {
  background: #3b0764;
  color: var(--purple);
}

/* === Event Feed === */
.event-feed {
  max-height: 320px;
  overflow-y: auto;
}

.event-item {
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.event-item:last-child {
  border-bottom: none;
}

.event-header {
  display: flex;
  align-items: center;
  gap: 8px;
}

.event-date {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-dim);
}

.impact-badge {
  font-size: 9px;
  font-family: var(--font-mono);
  text-transform: uppercase;
  padding: 1px 5px;
  border-radius: 3px;
  font-weight: 600;
}

.impact-critical { background: #450a0a; color: var(--red); }
.impact-high { background: #431407; color: var(--orange); }
.impact-medium { background: #422006; color: var(--yellow); }
.impact-low { background: #052e16; color: var(--green); }

/* RSI potential badges */
.rsi-badge {
  font-size: 9px;
  font-family: var(--font-mono);
  text-transform: uppercase;
  padding: 1px 5px;
  border-radius: 3px;
  font-weight: 600;
}
.rsi-none   { background: #1e293b; color: var(--text-dim); }
.rsi-low    { background: #052e16; color: var(--green); }
.rsi-medium { background: #422006; color: var(--yellow); }
.rsi-high   { background: #450a0a; color: var(--red); }

.event-title {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  margin-top: 4px;
}

.event-detail {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 2px;
}

.event-subtitle {
  font-size: 11px;
  color: var(--text-dim);
  opacity: 0.7;
  margin-top: 1px;
  font-family: var(--font-mono);
}

/* === Data Tables === */
.data-table-container {
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.data-table th {
  text-align: left;
  font-weight: 600;
  color: var(--text-dim);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.data-table th[data-sort]:hover {
  color: var(--text);
  background: var(--bg-card-hover);
}

.data-table td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  vertical-align: top;
}

.data-table tr:hover td {
  background: var(--bg-card-hover);
}

.data-table a {
  color: var(--accent);
  text-decoration: none;
}

.data-table a:hover {
  text-decoration: underline;
}

/* === Status indicators === */
.status {
  font-size: 10px;
  font-family: var(--font-mono);
  padding: 2px 6px;
  border-radius: 3px;
}

.status-enacted, .status-in-effect {
  background: #052e16;
  color: var(--green);
}

.status-proposed {
  background: #422006;
  color: var(--yellow);
}

.status-repealed {
  background: #1c1917;
  color: var(--text-dim);
}

/* === Log badges === */
.tag-collector { background: #1e3a5f; color: var(--cyan); }
.tag-curator   { background: #3b0764; color: var(--purple); }
.tag-manual    { background: #422006; color: var(--yellow); }
.tag-scheduler { background: #1c1917; color: var(--text-dim); }

.action-badge {
  font-size: 9px;
  font-family: var(--font-mono);
  text-transform: uppercase;
  padding: 1px 5px;
  border-radius: 3px;
  font-weight: 600;
}

.action-added     { background: #052e16; color: var(--green); }
.action-updated   { background: #1e3a5f; color: var(--accent); }
.action-removed   { background: #450a0a; color: var(--red); }
.action-refreshed { background: #1c1917; color: var(--text-dim); }
.action-error     { background: #450a0a; color: var(--red); }

.log-details {
  cursor: help;
  color: var(--text-dim);
  font-size: 10px;
}

/* === Footer === */
footer {
  border-top: 1px solid var(--border);
  padding: 16px 32px;
  text-align: center;
  font-size: 12px;
  color: var(--text-dim);
}

footer a {
  color: var(--accent);
  text-decoration: none;
}

footer a:hover {
  text-decoration: underline;
}

/* === Print === */
@media print {
  /* Force dark background and colors to print */
  * {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
    color-adjust: exact !important;
  }

  body {
    background: var(--bg) !important;
    color: var(--text) !important;
    font-size: 11px;
    min-height: auto !important;
  }

  header {
    background: #0f1729 !important;
    padding: 4px 16px !important;
    border: none !important;
  }

  .header-content h1 {
    font-size: 16px !important;
  }

  .subtitle, .last-updated {
    margin: 0 !important;
    font-size: 10px !important;
  }

  /* Hide nav — not useful on paper */
  nav {
    display: none !important;
    height: 0 !important;
  }

  main {
    padding: 4px 16px !important;
    margin: 0 !important;
  }

  /* Only show the active section */
  .dashboard-section {
    display: none !important;
    height: 0 !important;
    overflow: hidden !important;
  }

  .dashboard-section.active {
    display: block !important;
    height: auto !important;
    overflow: visible !important;
  }

  /* Cards */
  .card {
    background: var(--bg-card) !important;
    border-color: var(--border) !important;
    page-break-inside: avoid;
  }

  /* Charts — give them a fixed height so they render */
  canvas {
    max-height: 250px !important;
  }

  /* Grids — keep side by side if space allows */
  .grid-2col {
    grid-template-columns: 1fr 1fr;
  }

  /* Keep scrollable containers compact for print */
  .timeline, .event-feed {
    max-height: 300px !important;
    overflow: hidden !important;
  }

  /* Tables — allow content to show fully in print */
  .data-table-container {
    max-height: none !important;
    overflow: visible !important;
  }

  .data-table th {
    color: var(--text-dim) !important;
    border-bottom-color: var(--border) !important;
  }

  .data-table td {
    color: var(--text) !important;
    border-bottom-color: var(--border) !important;
  }

  .data-table tr:hover td {
    background: transparent !important;
  }

  /* Tags and badges — force colors */
  .tag, .impact-badge, .status {
    border: 1px solid var(--border);
  }

  /* Footer */
  footer {
    page-break-before: avoid;
    padding: 4px 16px !important;
  }

  /* Prevent canvases from overflowing */
  .card {
    overflow: hidden !important;
  }

  /* Avoid page breaks inside chart cards */
  .card:has(canvas) {
    page-break-inside: avoid;
  }

  /* Margins for paper */
  @page {
    margin: 1cm;
  }
}

/* === Focus-visible === */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
.data-table th[data-sort]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* === Scrollbar === */
/* Firefox */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--border) var(--bg);
}

/* Chromium / Safari */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: var(--bg);
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: #334155;
}

/* === Knowledge Graph Browser === */

.kb-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.kb-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  flex: 1;
}

.kb-type-btn {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 11px;
  padding: 4px 10px;
  border-radius: 4px;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s;
}

.kb-type-btn:hover {
  border-color: var(--type-color, var(--accent));
  color: var(--text);
}

.kb-type-btn.active {
  background: var(--bg-card);
  border-color: var(--type-color, var(--accent));
  color: var(--type-color, var(--accent));
}

.kb-search {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 13px;
  padding: 6px 12px;
  width: 220px;
  outline: none;
}

.kb-search:focus {
  border-color: var(--accent);
}

.kb-view-toggle {
  display: flex;
  gap: 4px;
}

.kb-view-btn {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 11px;
  padding: 4px 10px;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.15s;
}

.kb-view-btn.active {
  background: var(--bg-card);
  border-color: var(--accent);
  color: var(--accent);
}

.kb-status-bar {
  font-size: 11px;
  font-family: var(--font-mono);
  color: var(--text-dim);
  margin-top: 4px;
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 18px;
}

@keyframes kb-spin {
  to { transform: rotate(360deg); }
}

.kb-spinner {
  display: inline-block;
  width: 11px;
  height: 11px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: kb-spin 0.7s linear infinite;
  flex-shrink: 0;
}

/* Node list (table view) */
.kb-node-list {
  max-height: 600px;
  overflow-y: auto;
}

.kb-node-row {
  display: grid;
  grid-template-columns: 90px 1fr 2fr 2fr;
  gap: 12px;
  align-items: baseline;
  padding: 7px 4px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.1s;
}

.kb-node-row:hover {
  background: var(--bg-card-hover);
}

.kb-node-type {
  font-size: 11px;
  font-family: var(--font-mono);
  font-weight: 600;
  flex-shrink: 0;
}

.kb-node-label {
  font-size: 13px;
  color: var(--text-bright);
  font-weight: 500;
}

.kb-node-summary {
  font-size: 12px;
  color: var(--text-dim);
}

.kb-node-edges {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  align-items: flex-start;
}

.kb-edge-pill {
  display: inline-block;
  font-size: 11px;
  font-family: var(--font-mono);
  color: var(--text-dim);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 1px 5px;
  cursor: pointer;
  white-space: nowrap;
  transition: color 0.1s, border-color 0.1s;
}

.kb-edge-pill:hover {
  color: var(--accent);
  border-color: var(--accent);
}

.kb-empty {
  padding: 24px;
  text-align: center;
  color: var(--text-dim);
  font-size: 13px;
}

/* Graph view */
.kb-graph-card {
  position: relative;
}

.kb-graph-container {
  width: 100%;
  height: calc(100vh - 280px);
  min-height: 500px;
  background: var(--bg);
  border-radius: 6px;
  border: 1px solid var(--border);
  overflow: hidden;
}

.kb-graph-canvas {
  width: 100%;
  height: 100%;
}



/* Force-graph tooltip (2D — positioned near cursor) */
.kb-graph-tooltip {
  position: fixed;
  z-index: 300;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 12px;
  font-size: 12px;
  color: var(--text);
  line-height: 1.5;
  max-width: 300px;
  pointer-events: none;
  box-shadow: 0 4px 16px rgba(0,0,0,0.5);
}

.kb-graph-tooltip strong {
  color: var(--text-bright);
}

.kb-graph-tooltip em {
  color: var(--text-dim);
  font-style: normal;
}

/* 3D graph tooltip (generated by force-graph nodeLabel) */
.graph-tooltip {
  background: var(--bg-card) !important;
  border: 1px solid var(--border) !important;
  border-radius: 6px !important;
  padding: 8px 12px !important;
  font-size: 12px !important;
  color: var(--text) !important;
  line-height: 1.5 !important;
  max-width: 300px !important;
  box-shadow: 0 4px 16px rgba(0,0,0,0.5) !important;
  font-family: var(--font-sans) !important;
}

/* Graph legend */
.kb-graph-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
  padding: 8px 0;
  font-size: 11px;
  color: var(--text-dim);
}

.kb-legend-section {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 10px;
}

.kb-legend-title {
  font-weight: 600;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  margin-right: 4px;
}

.kb-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
}

.kb-legend-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.kb-legend-line {
  display: inline-block;
  width: 14px;
  height: 2px;
  border-radius: 1px;
  flex-shrink: 0;
}

/* Detail sidebar — fixed right panel, slides in over content */
.kb-detail {
  position: fixed;
  top: 0;
  right: 0;
  width: 380px;
  height: 100vh;
  background: var(--bg-card);
  border-left: 1px solid var(--border);
  z-index: 200;
  display: flex;
  flex-direction: column;
  box-shadow: -4px 0 24px rgba(0,0,0,0.4);
}

.kb-type-badge {
  font-size: 11px;
  font-family: var(--font-mono);
  font-weight: 600;
  margin-left: 8px;
  vertical-align: middle;
}

.kb-detail-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  padding: 16px 16px 0 16px;
  flex-shrink: 0;
}

.kb-detail-header h2 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-bright);
  line-height: 1.4;
}

.kb-close-btn {
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 16px;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  flex-shrink: 0;
  line-height: 1;
}

.kb-close-btn:hover {
  color: var(--text);
  background: var(--bg);
}

.kb-detail-summary {
  font-size: 12px;
  color: var(--text-dim);
  line-height: 1.5;
  padding: 8px 16px 12px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.kb-detail-body {
  flex: 1;
  overflow-y: auto;
  padding: 0 16px 16px 16px;
}

@media (max-width: 900px) {
  .kb-detail {
    width: 100vw;
    top: auto;
    bottom: 0;
    height: 60vh;
    border-left: none;
    border-top: 1px solid var(--border);
    box-shadow: 0 -4px 24px rgba(0,0,0,0.4);
  }
}

.kb-detail-section {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  margin: 16px 0 8px;
}

.kb-edge-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
}

.kb-edge-rel {
  font-family: var(--font-mono);
  color: var(--accent);
  min-width: 120px;
}

.kb-edge-dir {
  color: var(--text-dim);
}

.kb-edge-other {
  color: var(--text);
  cursor: pointer;
  text-decoration: underline;
  text-decoration-color: var(--border);
}

.kb-edge-other:hover {
  color: var(--accent);
}

.kb-data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.kb-data-key {
  font-family: var(--font-mono);
  color: var(--text-dim);
  padding: 4px 12px 4px 0;
  vertical-align: top;
  white-space: nowrap;
  width: 160px;
}

.kb-data-group {
  color: var(--text);
  font-weight: 600;
  padding-top: 10px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.kb-data-sub {
  padding-left: 16px;
  color: var(--text-dim);
}

.kb-data-val {
  color: var(--text);
  padding: 4px 0;
  word-break: break-word;
}

.kb-source {
  font-size: 11px;
  padding: 2px 0;
}

.kb-source a {
  color: var(--accent);
  text-decoration: none;
  word-break: break-all;
}

.kb-source a:hover {
  text-decoration: underline;
}
