/* Dense, high-contrast application layer on top of Blueprint v5. */

:root {
  --brand: #e0ad58;
  --brand-strong: #f0c675;
  --canvas: #0b100f;
  --surface: #121918;
  --surface-raised: #18211f;
  --surface-elevated: #202a27;
  --control: #1d2624;
  --text-primary: #f2f5f3;
  --text-secondary: #bdc6c1;
  --text-tertiary: #9eaaa4;
  --link: #75c5f7;
  --line: rgba(255, 255, 255, 0.09);
  --line-strong: rgba(255, 255, 255, 0.17);
  --focus: #8dd3ff;
  --danger: #ff949a;
  --danger-surface: rgba(205, 66, 70, 0.12);
  --shadow-border: 0 0 0 1px rgba(255, 255, 255, 0.09);
  --shadow-border-hover: 0 0 0 1px rgba(255, 255, 255, 0.15);
  --shadow-elevated:
    0 0 0 1px rgba(255, 255, 255, 0.11),
    0 12px 36px rgba(0, 0, 0, 0.38);
  --copilot-width: 26rem;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html {
  min-width: 320px;
  background: var(--canvas);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  min-width: 320px;
  margin: 0;
  background: var(--canvas);
  color: var(--text-primary);
}

html.bp5-dark .bp5-text-muted { color: var(--text-secondary); }
html.bp5-dark .bp5-input,
html.bp5-dark select { color: var(--text-primary); }
html.bp5-dark .bp5-input::placeholder { color: var(--text-tertiary); opacity: 1; }

h1, h2, h3 { text-wrap: balance; }
p, li, figcaption { text-wrap: pretty; }
button, a, input, select { touch-action: manipulation; }

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.skip-link { position: absolute; inset-inline-start: -9999px; }
.skip-link:focus {
  inset-inline-start: 10px;
  top: 10px;
  z-index: 100;
  padding: 8px 12px;
  border-radius: 8px;
  background: var(--surface-elevated);
  color: var(--text-primary);
}

/* ---------- Shared controls ---------- */
.inline-icon { display: inline-flex; align-items: center; vertical-align: -2px; }
.inline-icon svg { fill: currentColor; }
.icon-button { min-width: 40px; min-height: 40px; padding: 0; place-content: center; }
.icon-busy { animation: icon-spin 0.9s linear infinite; }
@keyframes icon-spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: no-preference) {
  .bp5-button {
    transition-property: scale, background-color, box-shadow;
    transition-duration: 150ms;
    transition-timing-function: ease-out;
  }
  .bp5-button:not(:disabled):active { scale: 0.96; }
}

/* ---------- Brand ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  min-height: 50px;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-title { margin: 0; font-size: 15px; font-weight: 650; line-height: 1.15; }
.brand small { display: block; font-size: 11px; letter-spacing: 0.035em; }
.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--brand), #b9812f);
  color: #211807;
  font-weight: 800;
  font-size: 13px;
  letter-spacing: 0.02em;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.1);
}
.system-state { max-width: min(30vw, 280px); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.system-state .status-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-inline-end: 6px;
  border-radius: 50%;
  background: var(--bp5-gray3);
}
.system-state .status-dot.ready { background: var(--bp5-green4); box-shadow: 0 0 6px var(--bp5-green4); }
.system-state .status-dot.blocked { background: var(--bp5-orange4); }
.intent-accent { color: var(--brand-strong) !important; }
.intent-accent-bg { background: rgba(224, 173, 88, 0.18) !important; color: var(--brand-strong) !important; }

main {
  max-width: 1920px;
  margin: 0 auto;
  padding: 12px 16px 28px;
}

/* ---------- Search deck ---------- */
.search-deck { margin-bottom: 12px; }
.search-form {
  display: grid;
  grid-template-columns: minmax(24rem, 46rem) minmax(0, 1fr);
  gap: 7px 12px;
  align-items: end;
}
.search-form > .bp5-label { grid-column: 1 / -1; margin: 0; color: var(--text-primary); }
.search-form > .bp5-label .bp5-text-muted { font-weight: 400; }
.search-form .search-row { grid-column: 1; width: 100%; }
.bp5-input-group > .inline-icon:first-child {
  position: absolute;
  top: 50%;
  inset-inline-start: 12px;
  z-index: 1;
  transform: translateY(-50%);
  color: var(--text-tertiary);
  pointer-events: none;
}
.bp5-input-group > .inline-icon:first-child + .bp5-input { padding-inline-start: 36px; }
.search-row input.bp5-input {
  background: var(--control);
  box-shadow: inset 0 0 0 1px var(--line-strong);
}
.query-examples {
  grid-column: 2;
  display: flex;
  gap: 7px;
  margin: 0;
  flex-wrap: wrap;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
  margin-top: 10px;
}
.metrics .metric-card {
  min-width: 0;
  padding: 8px 12px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: baseline;
  gap: 8px;
  border-radius: 10px;
  background: var(--surface-raised);
  color: var(--text-primary);
  box-shadow: var(--shadow-border);
}
.metric-card strong {
  color: var(--text-primary);
  font-size: 18px;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.metric-card span {
  overflow: hidden;
  color: var(--text-secondary) !important;
  font-size: 10px;
  text-transform: uppercase;
  text-overflow: ellipsis;
  white-space: nowrap;
  letter-spacing: 0.065em;
}

/* ---------- Workbench panels ---------- */
.workbench {
  display: grid;
  grid-template-columns: minmax(15.5rem, 0.78fr) minmax(30rem, 2.45fr) minmax(17rem, 0.9fr);
  gap: 10px;
  height: clamp(31rem, calc(100dvh - 15.75rem), 43rem);
  min-height: 31rem;
  align-items: stretch;
}
.panel {
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  border-radius: 16px;
  background: var(--surface);
  box-shadow: var(--shadow-border);
}
.panel-heading {
  min-height: 44px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  gap: 8px;
}
.panel-heading h2 { margin: 0; color: var(--text-primary); font-size: 14px; }
.count-pill { min-width: 24px; text-align: center; font-variant-numeric: tabular-nums; }
.result-list {
  min-height: 0;
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  list-style: none;
  margin: 0;
  padding: 8px;
  scrollbar-color: var(--line-strong) transparent;
}
.result-list li + li { margin-top: 3px; }
.result-card {
  width: 100%;
  min-height: 52px;
  padding: 7px 9px;
  display: grid;
  gap: 1px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--text-primary);
  font: inherit;
  text-align: start;
  cursor: pointer;
  transition-property: background-color, border-color, box-shadow;
  transition-duration: 150ms;
  transition-timing-function: ease-out;
}
.result-card:hover { background: rgba(255, 255, 255, 0.055); }
.result-card.active {
  border-color: rgba(117, 197, 247, 0.58);
  background: rgba(63, 166, 218, 0.16);
  box-shadow: 0 0 0 1px rgba(63, 166, 218, 0.08);
}
.result-card strong { color: var(--text-primary); font-weight: 650; font-size: 12.5px; }
.result-card small { color: var(--text-secondary); font-size: 11px; }
.result-meta { color: var(--brand-strong); font-size: 11px; font-variant-numeric: tabular-nums; }

.empty-state { padding: 22px 16px; color: var(--text-secondary) !important; font-size: 12px; line-height: 1.5; }
.graph-stage { position: relative; min-height: 0; flex: 1; }
#graph-canvas { width: 100%; height: 100%; display: block; cursor: crosshair; }
.graph-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  text-align: center;
  pointer-events: none;
}
.graph-controls { display: flex; align-items: center; gap: 6px; }
.graph-controls .bp5-label { margin: 0; color: var(--text-secondary); font-size: 11px; }
.graph-controls select { min-height: 30px; }
.legend {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  padding: 7px 12px;
  border-top: 1px solid var(--line);
  color: var(--text-secondary);
  font-size: 10.5px;
}
.legend i { display: inline-block; width: 8px; height: 8px; margin-inline-end: 5px; border-radius: 50%; }
.legend .organization { background: #e0ad58; }
.legend .person { background: #cf8aa5; }
.legend .flow { background: #6ab6a1; }
.legend .role { background: #7ea5d8; }
.legend .evidence { background: #a6ad9d; }

.inspector { min-height: 0; flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: 10px 12px; }
.inspector-title { margin: 0 0 2px; color: var(--text-primary); font-size: 14px; }
.inspector-key {
  margin: 0 0 9px;
  color: var(--text-tertiary);
  font-family: ui-monospace, monospace;
  font-size: 10.5px;
  overflow-wrap: anywhere;
}
.property-list { margin: 0; display: grid; gap: 0; font-size: 11.5px; }
.property-list > div { display: grid; grid-template-columns: minmax(6.5rem, 0.7fr) minmax(0, 1fr); gap: 10px; padding: 5px 0; border-bottom: 1px solid var(--line); }
.property-list dt { color: var(--text-secondary); text-transform: capitalize; }
.property-list dd { margin: 0; color: var(--text-primary); overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.source-link { display: inline-block; margin-top: 10px; color: var(--link); font-size: 12px; text-underline-offset: 2px; }

/* ---------- Timeline and evidence ---------- */
.timeline-room { margin-top: 12px; }
.timeline-stage { position: relative; height: 190px; }
#timeline-canvas { width: 100%; height: 100%; display: block; cursor: pointer; }
.timeline-tooltip { position: absolute; max-width: 220px; padding: 8px 10px; pointer-events: none; font-size: 11.5px; }
.evidence-room {
  display: grid;
  grid-template-columns: 15rem minmax(0, 1fr);
  gap: 14px;
  margin-top: 12px;
  padding: 14px;
  border-radius: 16px;
  background: var(--surface);
  box-shadow: var(--shadow-border);
}
.evidence-room h2 { margin: 3px 0; color: var(--text-primary); font-size: 15px; }
.evidence-intro p { color: var(--text-secondary); font-size: 11.5px; line-height: 1.45; }
.evidence-output { min-width: 0; min-height: 72px; }
.evidence-summary { display: flex; gap: 18px; margin-bottom: 10px; flex-wrap: wrap; }
.evidence-summary div { display: flex; flex-direction: column; }
.evidence-summary strong { color: var(--text-primary); font-size: 18px; font-variant-numeric: tabular-nums; }
.evidence-summary span { color: var(--text-secondary); font-size: 10px; text-transform: uppercase; letter-spacing: 0.06em; }
.evidence-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr)); gap: 7px; }
.evidence-item { padding: 8px 10px; border-radius: 10px; background: var(--surface-raised); box-shadow: var(--shadow-border); color: var(--text-primary); font-size: 11.5px; }
.evidence-item p { margin: 3px 0; color: var(--text-secondary); }
.evidence-item .source-link { margin-top: 5px; }

footer {
  max-width: 1920px;
  margin: 0 auto;
  padding: 0 16px 20px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  color: var(--text-secondary);
  font-size: 11px;
}

/* ---------- Login ---------- */
.login-body { display: grid; place-items: center; min-height: 100vh; }
.login-card {
  width: min(380px, calc(100vw - 32px));
  padding: 32px 28px;
  display: flex;
  flex-direction: column;
  align-items: center;
  border-radius: 16px;
  text-align: center;
}
.login-logo { display: block; margin-bottom: 14px; outline: 1px solid rgba(255, 255, 255, 0.1); outline-offset: -1px; }
.login-card h1 { margin: 0 0 4px; color: var(--text-primary); font-size: 17px; }
.login-tagline { margin: 0 0 22px; color: var(--text-secondary); font-size: 12px; }
.login-input { width: 100%; text-align: center; }
.login-error { width: 100%; margin-top: 12px; text-align: start; }
#login-submit { margin-top: 16px; }
.login-footnote { margin-top: 16px; color: var(--text-secondary); font-size: 11px; }

/* ---------- Copilot drawer ---------- */
.copilot {
  position: fixed;
  top: 62px;
  right: 12px;
  bottom: 12px;
  z-index: 60;
  width: var(--copilot-width);
  max-width: calc(100vw - 24px);
  min-height: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  visibility: hidden;
  opacity: 0;
  transform: translateX(14px);
  pointer-events: none;
  border-radius: 16px;
  background: #20262f;
  color: var(--text-primary);
  box-shadow: var(--shadow-elevated);
}
body.copilot-open .copilot { visibility: visible; opacity: 1; transform: translateX(0); pointer-events: auto; }
.copilot-backdrop {
  position: fixed;
  inset: 0;
  z-index: 55;
  visibility: hidden;
  opacity: 0;
  background: rgba(0, 0, 0, 0.48);
  pointer-events: none;
}
.copilot-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  padding: 11px 12px;
  border-bottom: 1px solid var(--line);
}
.copilot-header h2 { margin: 0; display: flex; align-items: center; gap: 6px; color: var(--text-primary); font-size: 14px; }
.copilot-sub { margin: 3px 0 0; color: var(--text-secondary) !important; font-size: 11px; line-height: 1.45; }
.copilot-header-actions { display: flex; flex: 0 0 auto; gap: 2px; }
.copilot-messages {
  min-height: 0;
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 7px;
  scrollbar-color: var(--line-strong) transparent;
}
.chat-note { color: var(--text-secondary); font-size: 11.5px; line-height: 1.45; }
.chat-bubble {
  max-width: 96%;
  padding: 8px 10px;
  border-radius: 10px;
  color: var(--text-primary);
  font-size: 12px;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.chat-user { align-self: flex-end; border: 1px solid rgba(117, 197, 247, 0.4); background: rgba(63, 166, 218, 0.17); }
.chat-assistant { align-self: flex-start; background: var(--surface-raised); box-shadow: var(--shadow-border); }
.chat-error { border: 1px solid rgba(255, 148, 154, 0.72); background: var(--danger-surface); color: #ffd7d9; box-shadow: none; }
.copilot-context {
  min-height: 26px;
  padding: 6px 12px;
  border-top: 1px solid var(--line);
  color: var(--text-secondary) !important;
  font-size: 10.5px;
  line-height: 1.35;
}
.copilot-form { display: flex; gap: 8px; padding: 9px 10px 10px; }
.copilot-form .bp5-input-group { min-width: 0; flex: 1; }
.copilot-form .bp5-input { min-height: 40px; background: var(--control); box-shadow: inset 0 0 0 1px var(--line-strong); }
.copilot-powered {
  padding: 0 12px 9px;
  color: color-mix(in srgb, var(--text-secondary) 72%, transparent) !important;
  font-size: 9.5px;
  line-height: 1;
  text-align: end;
}
.copilot-powered a {
  color: inherit;
  text-decoration-color: color-mix(in srgb, currentColor 45%, transparent);
  text-underline-offset: 2px;
}
.copilot-powered a:hover,
.copilot-powered a:focus-visible { color: var(--text-secondary); }

@media (prefers-reduced-motion: no-preference) {
  .copilot,
  .copilot-backdrop {
    transition-property: transform, opacity, visibility;
    transition-duration: 180ms, 180ms, 0s;
    transition-delay: 0s, 0s, 180ms;
    transition-timing-function: cubic-bezier(0.2, 0, 0, 1);
  }
  body.copilot-open .copilot,
  body.copilot-open .copilot-backdrop { transition-delay: 0s; }
}

@media (min-width: 90rem) {
  body.copilot-open main,
  body.copilot-open footer {
    margin-inline-start: auto;
    margin-inline-end: calc(var(--copilot-width) + 24px);
  }
  body.copilot-open .workbench {
    grid-template-columns: minmax(14rem, 0.75fr) minmax(24rem, 2.4fr) minmax(15rem, 0.9fr);
  }
}

@media (max-width: 89.99rem) {
  body.copilot-open .copilot-backdrop { visibility: visible; opacity: 1; pointer-events: auto; }
}

@media (max-width: 72rem) {
  .search-form { grid-template-columns: minmax(0, 1fr); }
  .search-form .search-row,
  .query-examples { grid-column: 1; }
  .metrics { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .workbench { height: auto; min-height: 0; grid-template-columns: minmax(0, 1fr); }
  .results-panel,
  .inspector-panel { min-height: 22rem; max-height: 32rem; }
  .graph-panel { min-height: 34rem; }
}

@media (max-width: 48rem) {
  main { padding-inline: 10px; }
  .brand .bp5-navbar-divider,
  .system-state { display: none; }
  .topbar { padding-inline: 8px; }
  .topbar .bp5-navbar-group { gap: 2px; }
  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .metrics .metric-card { grid-template-columns: 1fr; gap: 4px; }
  .query-examples { flex-wrap: nowrap; overflow-x: auto; padding: 2px; scroll-padding-inline: 2px; }
  .query-examples > * { flex: 0 0 auto; }
  .graph-heading { align-items: flex-start; }
  .graph-controls { justify-content: flex-end; flex-wrap: wrap; }
  .legend { gap: 9px; }
  .evidence-room { grid-template-columns: minmax(0, 1fr); }
  .copilot { inset-inline: 8px; width: auto; max-width: none; }
  .results-panel,
  .inspector-panel { min-height: 18rem; max-height: 24rem; }
  .graph-panel { min-height: 30rem; }
}

@media (max-width: 34rem) {
  .brand small { display: none; }
  #toggle-copilot { min-width: 40px; font-size: 0; }
  #toggle-copilot .inline-icon { font-size: 14px; }
  .metrics { grid-template-columns: 1fr 1fr; }
  .metric-card strong { font-size: 16px; }
}

@media (prefers-contrast: more) {
  :root {
    --text-secondary: #e0e6e2;
    --text-tertiary: #c9d2cd;
    --line: rgba(255, 255, 255, 0.2);
    --line-strong: rgba(255, 255, 255, 0.34);
  }
}

@media (forced-colors: active) {
  :focus-visible { outline-color: Highlight; }
  .panel,
  .evidence-room,
  .copilot { border: 1px solid CanvasText; box-shadow: none; }
  .result-card.active { border-color: Highlight; }
}
