@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
  color-scheme: dark;
  --bg: #08111f;
  --bg-elevated: #10203a;
  --bg-panel: #142846;
  --bg-muted: #1b3357;
  --border: rgba(148, 163, 184, 0.2);
  --text: #e2e8f0;
  --muted: #94a3b8;
  --accent: #60a5fa;
  --danger: #f87171;
  --success: #34d399;
  --warning: #fbbf24;
  --shadow: 0 18px 36px rgba(2, 6, 23, 0.28);
  font-family: 'Inter', ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at top, rgba(96, 165, 250, 0.16), transparent 28%),
    linear-gradient(180deg, #08111f 0%, #091728 100%);
  color: var(--text);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
  border: 1px solid transparent;
}

.shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  gap: 1rem;
  padding: 1.25rem;
}

.topbar,
.tool-tabs,
.panel,
.stat-card,
.legend,
.graph-shell,
.list-item,
.prompt-card {
  border: 1px solid var(--border);
  background: rgba(16, 32, 58, 0.9);
  box-shadow: var(--shadow);
}

.topbar {
  border-radius: 20px;
  padding: 1.25rem 1.5rem;
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) minmax(240px, 0.9fr);
  gap: 1rem;
}

.topbar h1 {
  margin: 0 0 0.35rem;
  font-size: 1.8rem;
  font-weight: 700;
}

.subtitle,
.microcopy,
.empty-state,
.selection-json pre {
  color: var(--muted);
}

.chip-row,
.stat-grid,
.prompt-grid,
.graph-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.chip,
.stat-pill {
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(15, 23, 42, 0.55);
  padding: 0.45rem 0.8rem;
  font-size: 0.88rem;
}

.actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  align-items: flex-start;
  flex-wrap: wrap;
}

.header-back-link {
  display: inline-flex;
  align-items: center;
  padding: 0.45rem 0.75rem;
  font-size: 0.85rem;
  color: var(--muted);
  text-decoration: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  white-space: nowrap;
  background: transparent;
  transition: color 0.15s, border-color 0.15s;
}
.header-back-link:hover {
  color: var(--text);
  border-color: var(--accent);
}

.header-field {
  min-width: 180px;
}

.button-primary,
.button-secondary,
.button-danger,
.tab-button,
.ghost-button {
  border-radius: 12px;
  padding: 0.7rem 1rem;
  transition: 0.18s ease;
}

.button-primary {
  background: linear-gradient(135deg, #3b82f6, #2563eb);
  color: white;
}

.button-secondary,
.ghost-button {
  background: rgba(15, 23, 42, 0.6);
  color: var(--text);
  border-color: var(--border);
}

.button-danger {
  background: rgba(127, 29, 29, 0.36);
  color: #fecaca;
  border-color: rgba(248, 113, 113, 0.3);
}

.button-primary:hover,
.button-secondary:hover,
.button-danger:hover,
.tab-button:hover,
.ghost-button:hover {
  transform: translateY(-1px);
  filter: brightness(1.08);
}

/* ─── Tab bar ─── */
.tool-tabs {
  border-radius: 18px;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.65rem 0.75rem;
  overflow-x: auto;
}

.tab-group {
  display: flex;
  gap: 0.4rem;
  align-items: center;
}

.tab-divider {
  width: 1px;
  height: 28px;
  background: var(--border);
  margin: 0 0.5rem;
  flex-shrink: 0;
}

.tab-group-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  padding: 0 0.35rem;
  white-space: nowrap;
  opacity: 0.7;
}

.tab-button {
  background: transparent;
  color: var(--muted);
  border-color: transparent;
  white-space: nowrap;
  font-size: 0.9rem;
}

.tab-button.active {
  background: rgba(59, 130, 246, 0.15);
  color: #dbeafe;
  border-color: rgba(96, 165, 250, 0.35);
}

.tab-button.analyst-tab {
  font-weight: 500;
}

.tab-button.analyst-tab.active {
  background: rgba(59, 130, 246, 0.2);
  color: #bfdbfe;
  border-color: rgba(96, 165, 250, 0.5);
}

/* ─── Severity badges ─── */
.severity-badge {
  border-radius: 999px;
  padding: 0.2rem 0.65rem;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  white-space: nowrap;
}

.severity-high {
  background: rgba(239, 68, 68, 0.18);
  color: #fca5a5;
  border: 1px solid rgba(239, 68, 68, 0.35);
}

.severity-medium {
  background: rgba(251, 191, 36, 0.15);
  color: #fcd34d;
  border: 1px solid rgba(251, 191, 36, 0.35);
}

.severity-low {
  background: rgba(52, 211, 153, 0.13);
  color: #6ee7b7;
  border: 1px solid rgba(52, 211, 153, 0.28);
}

/* ─── Entity type dot ─── */
.entity-dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  margin-right: 0.35rem;
  vertical-align: middle;
  flex-shrink: 0;
}

/* ─── Score bar ─── */
.score-bar-wrap {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-top: 0.5rem;
}

.score-bar-track {
  flex: 1;
  height: 6px;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.15);
  overflow: hidden;
}

.score-bar-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #3b82f6, #8b5cf6);
  transition: width 0.4s ease;
}

.score-label {
  font-size: 0.8rem;
  color: var(--muted);
  white-space: nowrap;
}

/* ─── Teaching tip ─── */
.teaching-tip {
  border-radius: 14px;
  border-left: 3px solid var(--accent);
  background: rgba(96, 165, 250, 0.08);
  padding: 0.75rem 1rem;
  font-size: 0.88rem;
  color: #bfdbfe;
  line-height: 1.5;
}

.teaching-tip strong {
  display: block;
  margin-bottom: 0.3rem;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--accent);
}

/* ─── Inspector toggle ─── */
.inspector-toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}

.inspector-toggle-row h3 {
  margin: 0;
}

.toggle-btn {
  font-size: 0.78rem;
  padding: 0.3rem 0.7rem;
  border-radius: 8px;
  background: rgba(15, 23, 42, 0.6);
  color: var(--muted);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: 0.15s ease;
}

.toggle-btn:hover {
  color: var(--text);
  border-color: rgba(148, 163, 184, 0.4);
}

.toggle-btn.active {
  color: var(--accent);
  border-color: rgba(96, 165, 250, 0.4);
  background: rgba(96, 165, 250, 0.08);
}

/* ─── Insight panel ─── */
.insight-section {
  margin-bottom: 0.85rem;
}

.insight-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
  margin-bottom: 0.4rem;
  font-weight: 600;
}

.insight-value {
  font-size: 0.9rem;
  line-height: 1.5;
}

.insight-evidence-list {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-top: 0.4rem;
}

.insight-evidence-item {
  font-size: 0.84rem;
  color: var(--muted);
  padding: 0.4rem 0.6rem;
  background: rgba(8, 17, 31, 0.5);
  border-radius: 8px;
  border: 1px solid var(--border);
  line-height: 1.4;
}

.insight-evidence-item::before {
  content: "→ ";
  color: var(--accent);
  font-weight: 600;
}

/* ─── Walkthrough card ─── */
.walkthrough-card {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  width: 320px;
  z-index: 1000;
  background: rgba(10, 22, 42, 0.97);
  border: 1px solid rgba(96, 165, 250, 0.4);
  border-radius: 20px;
  padding: 1.25rem;
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(96, 165, 250, 0.1);
  backdrop-filter: blur(12px);
  animation: walkthroughSlideIn 0.3s ease;
}

@keyframes walkthroughSlideIn {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}

.walkthrough-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.85rem;
}

.walkthrough-step-counter {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent);
  font-weight: 700;
}

.walkthrough-close {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 1.1rem;
  padding: 0;
  line-height: 1;
  cursor: pointer;
}

.walkthrough-close:hover {
  color: var(--text);
}

.walkthrough-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  margin: 0 0 0.5rem;
}

.walkthrough-desc {
  font-size: 0.86rem;
  color: var(--muted);
  line-height: 1.55;
  margin: 0 0 1rem;
}

.walkthrough-progress {
  display: flex;
  gap: 4px;
  margin-bottom: 1rem;
}

.walkthrough-dot {
  flex: 1;
  height: 3px;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.2);
  transition: background 0.25s ease;
}

.walkthrough-dot.done {
  background: rgba(96, 165, 250, 0.5);
}

.walkthrough-dot.current {
  background: var(--accent);
}

.walkthrough-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
}

.walkthrough-btn {
  border-radius: 10px;
  padding: 0.5rem 1rem;
  font-size: 0.85rem;
  font-weight: 600;
  transition: 0.15s ease;
}

.walkthrough-btn-back {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
}

.walkthrough-btn-back:hover {
  color: var(--text);
}

.walkthrough-btn-next {
  background: linear-gradient(135deg, #3b82f6, #2563eb);
  color: white;
  border: none;
}

.walkthrough-btn-next:hover {
  filter: brightness(1.1);
  transform: translateY(-1px);
}

.walkthrough-launch-btn {
  font-size: 0.8rem;
  padding: 0.35rem 0.8rem;
  border-radius: 10px;
  background: rgba(59, 130, 246, 0.15);
  color: var(--accent);
  border: 1px solid rgba(96, 165, 250, 0.3);
  cursor: pointer;
  transition: 0.15s ease;
  white-space: nowrap;
}

.walkthrough-launch-btn:hover {
  background: rgba(59, 130, 246, 0.25);
}

/* ─── Layout ─── */
.layout {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(300px, 0.8fr);
  gap: 1rem;
  min-height: 0;
  flex: 1;
}

.workspace,
.inspector {
  min-height: 0;
}

.panel {
  border-radius: 20px;
  padding: 1rem;
}

.workspace .panel {
  height: 100%;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: flex-start;
  margin-bottom: 1rem;
}

.panel-header h2,
.panel-header h3,
.inspector h3,
.prompt-card h3 {
  margin: 0;
}

.editor-grid,
.instance-grid,
.mapping-grid,
.graph-layout {
  display: grid;
  gap: 1rem;
}

.editor-grid,
.mapping-grid {
  grid-template-columns: minmax(220px, 0.85fr) minmax(0, 1.35fr);
}

.instance-grid {
  grid-template-columns: minmax(220px, 0.8fr) minmax(0, 1.05fr) minmax(280px, 0.95fr);
}

.sidebar-list,
.inspector-stack,
.card-stack {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.sidebar-list {
  max-height: 72vh;
  overflow: auto;
  padding-right: 0.2rem;
}

.list-item {
  border-radius: 16px;
  padding: 0.85rem 0.95rem;
  text-align: left;
  width: 100%;
  color: var(--text);
}

.list-item.active {
  border-color: rgba(96, 165, 250, 0.55);
  background: rgba(30, 64, 175, 0.26);
}

.list-item-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  font-weight: 600;
}

.list-item small {
  display: block;
  margin-top: 0.35rem;
  color: var(--muted);
}

.form-grid,
.detail-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.9rem;
}

.form-grid.single,
.detail-grid.single {
  grid-template-columns: minmax(0, 1fr);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.field label {
  font-size: 0.88rem;
  color: var(--muted);
}

.field input,
.field select,
.field textarea {
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(8, 17, 31, 0.88);
  color: var(--text);
  padding: 0.75rem 0.85rem;
  min-width: 0;
}

.field textarea {
  min-height: 96px;
  resize: vertical;
}

.section-title {
  margin: 1.2rem 0 0.75rem;
  font-size: 1rem;
}

.table-shell {
  overflow: auto;
  border-radius: 18px;
  border: 1px solid var(--border);
  background: rgba(8, 17, 31, 0.72);
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  padding: 0.8rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-size: 0.84rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

tbody tr:last-child td {
  border-bottom: 0;
}

.inline-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-top: 1rem;
}

.property-card,
.edge-card,
.source-card,
.selection-json,
.stat-card,
.prompt-card,
.legend,
.scenario-card,
.timeline-item,
.fact-item,
.place-card {
  border-radius: 18px;
  padding: 1rem;
  background: rgba(8, 17, 31, 0.72);
  border: 1px solid var(--border);
}

.scenario-card {
  text-align: left;
  color: var(--text);
  transition: border-color 0.15s ease, background 0.15s ease;
}

.scenario-card:hover {
  border-color: rgba(96, 165, 250, 0.3);
}

.scenario-card.active {
  border-color: rgba(96, 165, 250, 0.55);
  background: rgba(30, 64, 175, 0.24);
}

.swatch {
  width: 14px;
  height: 14px;
  border-radius: 999px;
  display: inline-block;
  margin-right: 0.45rem;
  vertical-align: middle;
}

.small-grid {
  display: grid;
  gap: 0.75rem;
}

.selection-json pre {
  margin: 0;
  max-height: 320px;
  overflow: auto;
  font-size: 0.8rem;
  line-height: 1.4;
}

.graph-shell {
  border-radius: 20px;
  padding: 0.9rem;
  background: rgba(8, 17, 31, 0.82);
}

.scenario-grid,
.rule-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.9rem;
  margin-bottom: 1rem;
}

.copilot-layout {
  display: grid;
  grid-template-columns: minmax(0, 0.95fr) minmax(0, 1.05fr);
  gap: 1rem;
}

/* ─── Map layout — map first ─── */
.map-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 1rem;
}

.map-top-row {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(280px, 0.6fr);
  gap: 1rem;
  align-items: start;
}

.case-layout {
  display: grid;
  grid-template-columns: minmax(0, 0.95fr) minmax(0, 1.05fr);
  gap: 1rem;
}

.copilot-input {
  min-height: 128px;
}

.entity-jump-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.75rem;
  margin-top: 0.75rem;
}

.map-canvas {
  margin-top: 0.9rem;
  border-radius: 18px;
  overflow: hidden;
  border: 1px solid var(--border);
  background:
    radial-gradient(circle at top, rgba(96, 165, 250, 0.14), transparent 34%),
    linear-gradient(180deg, rgba(8, 17, 31, 0.92), rgba(15, 23, 42, 0.76));
}

.leaflet-map,
.map-canvas .leaflet-container {
  width: 100%;
  min-height: 520px;
}

.map-canvas .leaflet-container {
  background: #0f172a;
}

.map-canvas > svg {
  display: block;
  width: 100%;
  min-height: 520px;
}

.leaflet-popup-content-wrapper,
.leaflet-popup-tip {
  background: rgba(8, 17, 31, 0.96);
  color: var(--text);
  border: 1px solid rgba(148, 163, 184, 0.22);
}

.leaflet-popup-content {
  margin: 0.75rem 0.9rem;
}

.map-popup {
  font-size: 0.85rem;
  line-height: 1.45;
}

.map-surface {
  fill: rgba(15, 23, 42, 0.78);
}

.map-grid-line {
  stroke: rgba(148, 163, 184, 0.16);
  stroke-width: 1;
}

.map-route {
  fill: none;
  stroke: rgba(96, 165, 250, 0.46);
  stroke-width: 1.6;
}

.map-marker {
  cursor: pointer;
}

.map-marker circle {
  stroke: rgba(248, 250, 252, 0.26);
  stroke-width: 1.2;
}

.map-marker.selected circle {
  stroke: #f8fafc;
  stroke-width: 2.4;
}

.map-marker text {
  fill: #e2e8f0;
  font-size: 11px;
  pointer-events: none;
}

.map-list-button {
  width: 100%;
  text-align: left;
  color: var(--text);
  background: rgba(8, 17, 31, 0.72);
}

.map-list-button.active {
  border-color: rgba(96, 165, 250, 0.55);
  background: rgba(30, 64, 175, 0.24);
}

.map-controls-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: flex-end;
}

.map-controls-row .field {
  min-width: 160px;
}

.map-bottom-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1rem;
}

.stack-list,
.timeline-list,
.place-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-top: 0.75rem;
}

.timeline-item,
.fact-item,
.place-card {
  padding: 0.85rem 0.95rem;
}

.graph-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 0.9rem;
}

.graph-controls .field {
  min-width: 180px;
}

.graph-canvas {
  border-radius: 18px;
  overflow: auto;
  border: 1px solid var(--border);
  background:
    linear-gradient(180deg, rgba(15, 23, 42, 0.35), rgba(15, 23, 42, 0.2)),
    radial-gradient(circle at top, rgba(96, 165, 250, 0.08), transparent 38%);
}

.graph-canvas svg {
  display: block;
  width: 100%;
  min-height: 520px;
}

.graph-node rect {
  stroke: rgba(148, 163, 184, 0.32);
  stroke-width: 1;
}

.graph-node.selected rect {
  stroke: #f8fafc;
  stroke-width: 2.2;
}

.graph-node text {
  fill: #e2e8f0;
  font-size: 12px;
  pointer-events: none;
}

.graph-edge {
  stroke: rgba(148, 163, 184, 0.4);
  stroke-width: 1.3;
}

.graph-edge-label {
  fill: #cbd5e1;
  font-size: 11px;
}

.legend-list {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  margin-top: 0.7rem;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 0.55rem;
}

.muted {
  color: var(--muted);
}

@media (max-width: 1200px) {
  .layout,
  .topbar,
  .editor-grid,
  .mapping-grid,
  .instance-grid,
  .copilot-layout,
  .case-layout,
  .map-top-row {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (max-width: 760px) {
  .shell {
    padding: 0.85rem;
  }

  .form-grid,
  .detail-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .walkthrough-card {
    width: calc(100vw - 2rem);
    right: 1rem;
    bottom: 1rem;
  }
}

/* ─── Action log ─── */
.action-log {
  margin-top: 1rem;
  border-top: 1px solid var(--border);
  padding-top: 0.75rem;
  min-height: 1.5rem;
}

.action-log-entry {
  font-family: "SF Mono", "Fira Mono", "Roboto Mono", monospace;
  font-size: 0.78rem;
  color: var(--muted);
  padding: 0.2rem 0;
  line-height: 1.5;
}

.action-log-ts {
  color: rgba(96, 165, 250, 0.7);
}

.action-log-empty {
  font-size: 0.8rem;
  color: var(--muted);
  font-style: italic;
}

/* ─── Grounding badge & summary ─── */
.grounding-badge {
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  background: rgba(16, 185, 129, 0.12);
  color: #34d399;
  border: 1px solid rgba(52, 211, 153, 0.35);
  white-space: nowrap;
  letter-spacing: 0.02em;
}

.grounding-summary {
  margin-top: 0.75rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--border);
  color: #34d399;
  font-size: 0.78rem;
}

/* ─── Before / after comparison card ─── */
.comparison-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin-top: 0.75rem;
}

.comparison-label {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--muted);
  text-transform: uppercase;
  margin-bottom: 0.4rem;
}

.comparison-pre {
  font-family: "SF Mono", "Fira Mono", "Roboto Mono", monospace;
  font-size: 0.75rem;
  line-height: 1.5;
  white-space: pre-wrap;
  margin: 0;
}

/* ─── Walkthrough bullets ─── */
.walkthrough-bullets {
  margin: 0.5rem 0 0 0;
  padding-left: 1.1rem;
  font-size: 0.82rem;
  color: var(--muted);
  line-height: 1.6;
}

.walkthrough-bullets li {
  margin-bottom: 0.4rem;
}
