/* =========================================================================
   IQC · FIELD ATLAS — Terminal Design System
   One typeface (JetBrains Mono). One accent (#ffd600). No rounded corners.
   ========================================================================= */

:root {
  /* ----- INK ----- */
  --bg-primary:  #0a0a0a;
  --bg-surface:  #121212;
  --bg-hover:    #1a1a1a;
  --bg-active:   #1f1f1f;
  --border:      #2a2a2a;
  --border-soft: #1a1a1a;

  --text-mute:   #6b6b6b;
  --text-base:   #a8a8a8;
  --text-bright: #f0f0f0;
  --text-hi:     #ffffff;

  /* ----- ACCENT ----- */
  --accent:      #ffd600;
  --accent-dim:  #b89a00;
  --accent-soft: rgba(255, 214, 0, 0.08);
  --accent-mid:  rgba(255, 214, 0, 0.18);

  --pos:         #7fd488;
  --neg:         #e06c6c;

  /* ----- TYPE ----- */
  --mono: 'JetBrains Mono', 'SFMono-Regular', Consolas, monospace;

  /* ----- METRICS ----- */
  --hdr-h:    56px;
  --ftr-h:    28px;
  --sb-w:     300px;
  --dt-w:     360px;
}

/* ── reset ─────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  height: 100%;
  background: var(--bg-primary);
  color: var(--text-base);
  font-family: var(--mono);
  font-weight: 400;
  font-size: 12.5px;
  line-height: 1.5;
  font-feature-settings: "tnum", "zero", "cv02";
  -webkit-font-smoothing: antialiased;
}
button, input { font: inherit; color: inherit; background: transparent; border: 0; }
button { cursor: pointer; }
ul { list-style: none; }
a { color: inherit; text-decoration: none; }

::selection { background: var(--accent); color: var(--bg-primary); }
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg-primary); }
::-webkit-scrollbar-thumb { background: var(--border); }
::-webkit-scrollbar-thumb:hover { background: var(--text-mute); }

.hidden { display: none !important; }

/* =========================================================================
   APP GRID
   ┌─── header ───────────────────────┐
   │ sb  │ stage              │ dt    │
   └─── footer ───────────────────────┘
   ========================================================================= */
.app {
  display: grid;
  grid-template-columns: var(--sb-w) 1fr;
  grid-template-rows: var(--hdr-h) 1fr var(--ftr-h);
  grid-template-areas:
    "hdr hdr"
    "sb  stage"
    "ftr ftr";
  height: 100vh;
  overflow: hidden;
}
.app[data-detail-open="1"] {
  grid-template-columns: var(--sb-w) 1fr var(--dt-w);
  grid-template-areas:
    "hdr hdr hdr"
    "sb  stage dt"
    "ftr ftr  ftr";
}

/* =========================================================================
   HEADER
   ========================================================================= */
.hdr {
  grid-area: hdr;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px;
  background: var(--bg-primary);
  position: relative;
}
.hdr::after {
  content: ""; position: absolute; left: 0; bottom: -1px; height: 1px;
  width: var(--sb-w);
  background: var(--accent);
  opacity: 0.6;
}

.hdr-brand {
  display: flex; align-items: baseline; gap: 8px;
  user-select: none;
}
.hdr-brand-mark {
  font-weight: 600;
  font-size: 11px;
  color: var(--accent);
  letter-spacing: 0.18em;
  border: 1px solid var(--accent-dim);
  padding: 3px 6px;
  background: var(--accent-soft);
}
.hdr-brand-dot { color: var(--text-mute); font-weight: 500; }
.hdr-brand-name {
  font-weight: 500;
  font-size: 13.5px;
  letter-spacing: 0.14em;
  color: var(--text-hi);
}

.hdr-stats {
  display: flex; align-items: center; gap: 12px;
  font-size: 11.5px;
  color: var(--text-mute);
}
.hdr-stat { display: flex; gap: 6px; }
.hdr-stat em {
  font-style: normal;
  color: var(--text-mute);
  letter-spacing: 0.06em;
}
.hdr-stat span[data-stat] {
  color: var(--text-bright);
  font-weight: 500;
}
.hdr-stat-sep { color: var(--border); }

/* =========================================================================
   SIDEBAR
   ========================================================================= */
.sb {
  grid-area: sb;
  border-right: 1px solid var(--border);
  background: var(--bg-primary);
  overflow-y: auto;
  display: flex; flex-direction: column;
}
.sb-sec {
  padding: 14px 16px 16px;
  border-bottom: 1px solid var(--border-soft);
}
.sb-sec-grow { flex: 1; min-height: 0; }
.sb-sec-grow .legend { max-height: 100%; overflow-y: auto; }

.sb-title {
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-mute);
  margin-bottom: 10px;
  display: flex; align-items: baseline; gap: 6px;
}
.sb-title span { color: var(--text-bright); font-weight: 500; letter-spacing: 0.04em; }

/* view list */
.vl { display: flex; flex-direction: column; }
.vl-row {
  display: grid;
  grid-template-columns: 26px 1fr 14px;
  align-items: center;
  padding: 7px 8px;
  border-left: 2px solid transparent;
  color: var(--text-base);
  cursor: pointer;
  transition: background 100ms, color 100ms, border-color 100ms;
}
.vl-row:hover { background: var(--bg-hover); color: var(--text-bright); }
.vl-row:hover .vl-arrow { color: var(--accent); transform: translateX(1px); }
.vl-row.active {
  background: var(--bg-hover);
  color: var(--text-hi);
  border-left-color: var(--accent);
}
.vl-row.active .vl-num { color: var(--accent); }
.vl-row.active .vl-arrow { color: var(--accent); }
.vl-num {
  font-size: 10px;
  color: var(--text-mute);
  letter-spacing: 0.08em;
  font-weight: 500;
}
.vl-name {
  font-size: 12px;
  letter-spacing: 0.12em;
  font-weight: 500;
}
.vl-arrow {
  color: var(--text-mute);
  font-size: 12px;
  transition: color 100ms, transform 100ms;
}

/* search */
.sr {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  border: 1px solid var(--border);
  padding: 0 8px;
  background: var(--bg-surface);
  transition: border-color 100ms;
}
.sr:focus-within { border-color: var(--accent); }
.sr-input {
  padding: 7px 0;
  font-size: 12px;
  color: var(--text-bright);
  outline: 0;
  width: 100%;
}
.sr-input::placeholder { color: var(--text-mute); }
.sr-key {
  font-size: 10px;
  color: var(--text-mute);
  border: 1px solid var(--border);
  padding: 1px 5px;
  letter-spacing: 0.04em;
}
.sr-results {
  margin-top: 8px;
  max-height: 240px;
  overflow-y: auto;
  display: none;
}
.sr-results.open { display: block; }
.sr-result {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 2px 8px;
  padding: 7px 8px;
  border-left: 2px solid transparent;
  border-bottom: 1px solid var(--border-soft);
  cursor: pointer;
  transition: background 80ms, border-color 80ms;
}
.sr-result:hover, .sr-result.focused {
  background: var(--bg-hover);
  border-left-color: var(--accent);
}
.sr-result-id {
  font-size: 11.5px;
  color: var(--text-bright);
  font-weight: 500;
  word-break: break-all;
}
.sr-result-meta {
  font-size: 10px;
  color: var(--text-mute);
  letter-spacing: 0.04em;
  white-space: nowrap;
  text-align: right;
}
.sr-result-desc {
  grid-column: 1 / -1;
  font-size: 10.5px;
  color: var(--text-mute);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* chips */
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  font-size: 10.5px;
  letter-spacing: 0.1em;
  padding: 5px 9px;
  border: 1px solid var(--border);
  color: var(--text-mute);
  transition: all 100ms;
  font-weight: 500;
}
.chip:hover { color: var(--text-bright); border-color: var(--text-mute); }
.chip.on { color: var(--accent); border-color: var(--accent-dim); background: var(--accent-soft); }

/* range */
.rng {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 1px;
  background: var(--border);
  outline: 0;
  margin-top: 2px;
}
.rng::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 8px; height: 14px;
  background: var(--accent);
  cursor: ew-resize;
  border: 0;
}
.rng::-moz-range-thumb {
  width: 8px; height: 14px;
  background: var(--accent);
  cursor: ew-resize;
  border: 0;
}

/* dataset legend */
.legend { display: flex; flex-direction: column; }
.legend-row {
  display: grid;
  grid-template-columns: 8px 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
  font-size: 11px;
  cursor: pointer;
  border-left: 2px solid transparent;
  padding-left: 6px;
  transition: opacity 100ms, border-color 100ms;
}
.legend-row[data-active="0"] { opacity: 0.32; }
.legend-row:hover { border-left-color: var(--accent); }
.legend-swatch { width: 8px; height: 8px; border: 1px solid rgba(255,255,255,0.04); }
.legend-name { color: var(--text-base); }
.legend-count {
  color: var(--text-mute);
  font-size: 10.5px;
  font-weight: 500;
}

/* =========================================================================
   STAGE (main view container)
   ========================================================================= */
.stage {
  grid-area: stage;
  position: relative;
  background: var(--bg-primary);
  overflow: hidden;
}

.vc {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
}
.vc-canvas { position: absolute; inset: 0; display: block; }

.vc-controls {
  position: absolute;
  top: 12px;
  right: 16px;
  z-index: 4;
  display: flex;
  gap: 12px;
  background: rgba(10, 10, 10, 0.86);
  backdrop-filter: blur(6px);
  border: 1px solid var(--border);
  padding: 6px;
}
.vc-controls-groups {
  top: 12px; left: 16px; right: 16px;
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap;
}

.gctl { display: flex; align-items: center; gap: 8px; }
.gctl-label {
  font-size: 9.5px;
  letter-spacing: 0.16em;
  color: var(--text-mute);
  font-weight: 500;
}

/* segmented control */
.seg { display: inline-flex; border: 1px solid var(--border); }
.seg-btn {
  padding: 5px 10px;
  font-size: 10.5px;
  letter-spacing: 0.06em;
  color: var(--text-mute);
  border-right: 1px solid var(--border);
  transition: color 80ms, background 80ms;
  font-weight: 500;
}
.seg-btn:last-child { border-right: 0; }
.seg-btn:hover { color: var(--text-bright); background: var(--bg-hover); }
.seg-btn.on {
  color: var(--bg-primary);
  background: var(--accent);
}

/* big yellow button */
.btn-yellow {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 6px 14px;
  font-size: 11px;
  letter-spacing: 0.14em;
  font-weight: 600;
  color: var(--accent);
  background: transparent;
  border: 1px solid var(--accent-dim);
  transition: all 100ms;
}
.btn-yellow:hover {
  color: var(--bg-primary);
  background: var(--accent);
  border-color: var(--accent);
}
.btn-yellow .btn-arrow { font-size: 13px; line-height: 1; }
.btn-yellow.firing { animation: fire 280ms ease-out; }
@keyframes fire {
  0%   { transform: scale(1); }
  45%  { transform: scale(0.95); background: var(--accent); color: var(--bg-primary); }
  100% { transform: scale(1); }
}

/* HUD readout */
.hud {
  position: absolute;
  left: 16px;
  bottom: 12px;
  z-index: 3;
  padding: 4px 10px;
  border: 1px solid var(--border);
  background: rgba(10, 10, 10, 0.7);
  backdrop-filter: blur(6px);
  font-size: 10.5px;
  letter-spacing: 0.04em;
  color: var(--text-mute);
  pointer-events: none;
}

/* loading overlay */
.vc-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-primary);
  z-index: 4;
  transition: opacity 320ms;
}
.vc-overlay.hidden { opacity: 0; pointer-events: none; }

.ldr { text-align: center; min-width: 320px; }
.ldr-pct {
  font-size: 48px;
  font-weight: 500;
  color: var(--accent);
  letter-spacing: -0.02em;
  line-height: 1;
  font-feature-settings: "tnum";
  margin-bottom: 18px;
}
.ldr-bar {
  width: 320px;
  height: 1px;
  background: var(--border);
  margin: 0 auto;
  position: relative;
}
.ldr-bar-fill {
  height: 1px;
  width: 0%;
  background: var(--accent);
  transition: width 90ms linear;
  box-shadow: 0 0 8px rgba(255, 214, 0, 0.4);
}
.ldr-stage {
  margin-top: 14px;
  font-size: 11px;
  letter-spacing: 0.1em;
  color: var(--text-mute);
  text-transform: lowercase;
}

/* groups grid */
.grid-cards {
  position: absolute;
  inset: 72px 16px 16px 16px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(244px, 1fr));
  gap: 10px;
  overflow-y: auto;
  padding-right: 4px;
}
.gcard {
  display: grid;
  grid-template-rows: auto auto 1fr;
  gap: 7px;
  border: 1px solid var(--border);
  border-left: 4px solid var(--group-color, var(--accent));
  background: var(--bg-surface);
  padding: 12px;
  cursor: pointer;
  position: relative;
  transition: background 100ms, border-right-color 100ms;
}
.gcard::before {
  content: "";
  position: absolute;
  top: 0; right: 0; bottom: 0;
  width: 0;
  background: var(--accent);
  transition: width 100ms;
}
.gcard:hover {
  background: var(--bg-active);
}
.gcard:hover::before { width: 1px; }
.gcard:hover .gcard-field { color: var(--text-base); }

.gcard-head { display: flex; align-items: baseline; justify-content: space-between; }
.gcard-id {
  font-size: 11px;
  color: var(--text-bright);
  letter-spacing: 0.08em;
  font-weight: 500;
}
.gcard-n {
  font-size: 14px;
  color: var(--text-hi);
  font-weight: 500;
}
.gcard-n em {
  font-size: 9.5px;
  letter-spacing: 0.06em;
  color: var(--text-mute);
  font-style: normal;
  margin-left: 4px;
}

.gcard-meta {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 2px 8px;
  font-size: 10.5px;
  color: var(--text-mute);
  padding-bottom: 7px;
  border-bottom: 1px solid var(--border-soft);
}
.gcard-meta-val { color: var(--text-base); }

.gcard-fields { display: flex; flex-direction: column; gap: 1px; }
.gcard-field {
  font-size: 10.5px;
  color: var(--text-mute);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: color 100ms;
}

/* =========================================================================
   FOOTER
   ========================================================================= */
.ftr {
  grid-area: ftr;
  border-top: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px;
  padding: 0 16px;
  font-size: 10px;
  color: var(--text-mute);
  letter-spacing: 0.06em;
  background: var(--bg-surface);
}
.ftr-item { display: flex; gap: 5px; }
.ftr-item em { font-style: normal; color: #4a4a4a; }
.ftr-sep { color: var(--border); }
.ftr-spacer { flex: 1; }
.ftr-hint { color: var(--text-mute); }

/* =========================================================================
   DETAIL PANEL
   ========================================================================= */
.dt {
  grid-area: dt;
  border-left: 1px solid var(--border);
  background: var(--bg-primary);
  overflow-y: auto;
  display: none;
  padding: 16px 18px 32px;
  position: relative;
}
.app[data-detail-open="1"] .dt { display: block; }

.dt-close {
  position: absolute; top: 10px; right: 14px;
  font-size: 18px; line-height: 1;
  color: var(--text-mute);
  width: 22px; height: 22px;
  display: flex; align-items: center; justify-content: center;
  transition: color 100ms;
}
.dt-close:hover { color: var(--accent); }

.dt-overline {
  font-size: 10px;
  letter-spacing: 0.12em;
  color: var(--text-mute);
  font-weight: 500;
}
.dt-sep { color: var(--border); margin: 0 4px; }

.dt-title {
  margin: 6px 0 10px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-hi);
  word-break: break-all;
  line-height: 1.3;
  letter-spacing: -0.005em;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--accent-dim);
}

.dt-badges { display: flex; gap: 5px; flex-wrap: wrap; margin: 10px 0 12px; }
.badge {
  font-size: 9.5px;
  letter-spacing: 0.14em;
  padding: 3px 7px;
  border: 1px solid var(--border);
  color: var(--text-mute);
  font-weight: 500;
}
.badge[data-tone="matrix"] { color: var(--pos); border-color: rgba(127, 212, 136, 0.3); }
.badge[data-tone="vector"] { color: #d4a04a; border-color: rgba(212, 160, 74, 0.3); }
.badge[data-tone="dataset"] { color: var(--accent); border-color: var(--accent-dim); }

.dt-desc {
  font-size: 11.5px;
  color: var(--text-mute);
  line-height: 1.55;
  margin: 2px 0 16px;
}

.dt-section { margin-bottom: 20px; }
.dt-section-title {
  font-size: 9.5px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-mute);
  margin-bottom: 8px;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--border-soft);
  font-weight: 500;
}

.metrics { display: flex; flex-direction: column; }
.m-row {
  display: flex; justify-content: space-between; align-items: baseline;
  padding: 6px 0;
  border-bottom: 1px dotted var(--border);
  font-size: 11.5px;
}
.m-row:last-child { border-bottom: 0; }
.m-key { color: var(--text-mute); letter-spacing: 0.04em; }
.m-val {
  color: var(--text-bright);
  font-weight: 500;
  font-feature-settings: "tnum";
}
.m-val[data-tone="pos"] { color: var(--pos); }
.m-val[data-tone="neg"] { color: var(--neg); }

.chart-wrap {
  position: relative;
  height: 140px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
}
.chart-wrap canvas { display: block; width: 100%; height: 100%; }
.chart-empty {
  position: absolute; inset: 0; display: none;
  align-items: center; justify-content: center;
  font-size: 10.5px;
  color: var(--text-mute);
  letter-spacing: 0.1em;
}
.chart-wrap[data-empty="1"] .chart-empty { display: flex; }

.code {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  padding: 9px 12px;
  font-size: 11px;
  color: var(--accent);
  white-space: pre-wrap;
  word-break: break-all;
  font-weight: 500;
}
.dt-meta-row {
  display: flex; justify-content: space-between; align-items: baseline;
  margin-top: 6px;
  font-size: 10.5px;
}
.dt-meta-row em {
  font-style: normal;
  color: var(--text-mute);
  letter-spacing: 0.06em;
}
.dt-meta-row span { color: var(--text-base); }

.nb-list { display: flex; flex-direction: column; }
.nb {
  display: grid;
  grid-template-columns: 22px 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px solid var(--border-soft);
  cursor: pointer;
  transition: padding-left 100ms, color 100ms;
}
.nb:hover { padding-left: 4px; }
.nb:hover .nb-id { color: var(--accent); }
.nb-num {
  font-size: 10px;
  color: var(--text-mute);
  font-weight: 500;
}
.nb-id {
  font-size: 11px;
  color: var(--text-bright);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: color 100ms;
}
.nb-r {
  font-size: 11px;
  color: var(--accent);
  font-weight: 500;
  font-feature-settings: "tnum";
}

/* =========================================================================
   RESPONSIVE (minimal — desktop tool)
   ========================================================================= */
@media (max-width: 1100px) {
  :root { --sb-w: 244px; --dt-w: 320px; }
}
@media (max-width: 880px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-areas: "hdr" "stage" "ftr";
  }
  .sb { display: none; }
  .app[data-detail-open="1"] {
    grid-template-columns: 1fr;
    grid-template-areas: "hdr" "stage" "ftr";
  }
  .dt {
    position: fixed;
    top: var(--hdr-h);
    right: 0;
    bottom: var(--ftr-h);
    width: 92vw;
    max-width: var(--dt-w);
    z-index: 50;
    box-shadow: -8px 0 24px rgba(0, 0, 0, 0.6);
  }
}
