/* sni-finder — HashiCorp-inspired dark theme.
   Reference: ./DESIGN-hashicorp.md (sections 2..6).
   Kept lean and token-driven so values can be re-tuned in one place. */

/* ---------- Tokens ---------- */
:root {
  /* Background */
  --bg-app:        #15181e;
  --bg-panel:      #0d0e12;
  --bg-card:       #1a1d24;
  --bg-elevated:   #20242c;

  /* Text */
  --tx-primary:    #efeff1;
  --tx-secondary:  #d5d7db;
  --tx-helper:     #656a76;
  --tx-muted:      #3b3d45;

  /* Borders */
  --bd-subtle:     rgba(178, 182, 189, 0.15);
  --bd-mid:        rgba(178, 182, 189, 0.4);
  --bd-strong:     rgb(97, 104, 117);

  /* Accents — single-product-color rule from the spec */
  --acc-active:    #1868f2;   /* Vagrant blue: running stages, focus rings */
  --acc-success:   #14c6cb;   /* Waypoint teal: good candidates / valid handshake */
  --acc-warning:   #bb5a00;   /* Amber: skipped / sub-par */
  --acc-warning-2: #fbeabf;
  --acc-error:     #c1373f;   /* lighter than spec #731e25 — better readability on dark */

  /* Score-band fills */
  --score-good:    #14c6cb;
  --score-mid:     #bb5a00;
  --score-bad:     #c1373f;
  --score-neutral: #656a76;

  /* Whisper shadows — system signature */
  --shadow-1:
    rgba(97, 104, 117, 0.05) 0 1px 1px,
    rgba(97, 104, 117, 0.05) 0 2px 2px;

  /* Radii */
  --r-1: 2px;
  --r-2: 3px;
  --r-3: 4px;
  --r-4: 5px;   /* primary radius */
  --r-5: 8px;   /* card radius */

  /* Type scale (Inter as HashiCorp Sans stand-in) */
  --font-brand: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
  --font-body:  system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
  --font-mono:  ui-monospace, 'SF Mono', Menlo, Consolas, 'Roboto Mono', monospace;
}

/* ---------- Reset / base ---------- */
* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  background: var(--bg-app);
  color: var(--tx-primary);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.63;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
a { color: #2b89ff; text-decoration: none; }
a:hover { text-decoration: underline; }

button { font-family: inherit; }

/* ---------- Layout ---------- */
.app-shell {
  max-width: 1280px;
  margin: 0 auto;
  padding: 24px 32px 80px;
  display: grid;
  grid-template-columns: 1fr;
  gap: 24px;
}
/* Top-candidates is now full-width with auto-fill grid; no 2-col split. */

/* ---------- Top bar ---------- */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 0;
  border-bottom: 1px solid var(--bd-subtle);
}
.brand {
  font-family: var(--font-brand);
  font-weight: 700;
  font-size: 19px;
  letter-spacing: 0;
  font-feature-settings: "kern" 1;
}
.brand .dot { color: var(--acc-success); }
.subtle { color: var(--tx-helper); font-size: 13px; }

/* ---------- Cards ---------- */
.card {
  background: var(--bg-card);
  border: 1px solid var(--bd-subtle);
  border-radius: var(--r-5);
  padding: 14px 16px;
  box-shadow: var(--shadow-1);
}
.card + .card { margin-top: 16px; }

.section-label {
  font-family: var(--font-brand);
  font-weight: 600;
  font-size: 13px;
  line-height: 1.69;
  letter-spacing: 1.3px;
  text-transform: uppercase;
  color: var(--tx-helper);
  font-feature-settings: "kern" 1;
  margin: 0 0 12px;
}
h1, h2, h3 {
  font-family: var(--font-brand);
  font-feature-settings: "kern" 1;
  letter-spacing: -0.01em;
  margin: 0;
}
h2 { font-size: 26px; line-height: 1.19; font-weight: 700; }
h3 { font-size: 19px; line-height: 1.21; font-weight: 700; }

/* ---------- Form ---------- */
.form-row {
  display: grid;
  grid-template-columns: 1.4fr 1fr auto;
  gap: 16px;
  align-items: end;
}
@media (max-width: 768px) {
  .form-row { grid-template-columns: 1fr; }
}
.field { display: flex; flex-direction: column; gap: 6px; }
.field label {
  font-family: var(--font-brand);
  font-weight: 600;
  font-size: 13px;
  letter-spacing: 1.3px;
  text-transform: uppercase;
  color: var(--tx-helper);
}
.input-dark {
  background: var(--bg-panel);
  color: var(--tx-primary);
  border: 1px solid var(--bd-strong);
  border-radius: var(--r-4);
  padding: 11px 12px;
  font-family: var(--font-mono);
  font-size: 15px;
  outline: none;
  transition: border-color 120ms ease;
}
.input-dark:focus {
  border-color: var(--acc-active);
  outline: 3px solid color-mix(in srgb, var(--acc-active) 35%, transparent);
}
.slider-row {
  display: flex; align-items: center; gap: 12px;
}
.slider-row input[type=range] {
  flex: 1;
  accent-color: var(--acc-active);
}
.slider-value {
  font-family: var(--font-mono);
  color: var(--tx-secondary);
  min-width: 4ch;
  text-align: right;
}

.btn-primary {
  background: var(--bg-panel);
  color: var(--tx-secondary);
  border: 1px solid var(--bd-mid);
  border-radius: var(--r-4);
  padding: 11px 11px 11px 18px;       /* asymmetric per spec */
  font-family: var(--font-brand);
  font-weight: 600;
  font-size: 15px;
  letter-spacing: 0.02em;
  cursor: pointer;
  display: inline-flex; align-items: center; gap: 8px;
  box-shadow: var(--shadow-1);
  transition: background 120ms ease, color 120ms ease, border-color 120ms ease;
}
.btn-primary:hover { background: var(--bg-elevated); color: var(--tx-primary); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary:focus { outline: 3px solid color-mix(in srgb, var(--acc-active) 35%, transparent); }
.btn-primary .arrow { color: var(--acc-active); }

.btn-ghost {
  background: transparent;
  color: var(--tx-secondary);
  border: 1px solid var(--bd-subtle);
  border-radius: var(--r-3);
  padding: 6px 10px;
  font-size: 13px;
  cursor: pointer;
}
.btn-ghost:hover { border-color: var(--bd-mid); color: var(--tx-primary); }

/* ---------- Pipeline funnel ---------- */
.funnel { display: flex; flex-direction: column; gap: 4px; }
.lane {
  display: grid;
  grid-template-columns: 22px 92px 1fr auto;
  gap: 10px;
  padding: 5px 10px;
  background: var(--bg-panel);
  border: 1px solid var(--bd-subtle);
  border-radius: var(--r-3);
  align-items: center;
  min-height: 28px;
}
.lane[data-status="running"] { border-color: var(--acc-active); }
.lane[data-status="done"]    { border-color: var(--bd-subtle); opacity: 0.95; }
.lane[data-status="failed"]  { border-color: var(--acc-error); }

.lane-num {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--tx-helper);
  text-align: right;
}
.lane-name {
  font-family: var(--font-brand);
  font-weight: 600;
  font-size: 11px;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  color: var(--tx-secondary);
  white-space: nowrap;
}
.lane-detail {
  display: flex; gap: 6px; align-items: center;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--tx-secondary);
  flex-wrap: nowrap;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}
.lane-detail .pill {
  padding: 1px 6px;
  background: var(--bg-elevated);
  border-radius: var(--r-1);
  border: 1px solid var(--bd-subtle);
  font-size: 11.5px;
  white-space: nowrap;
  flex-shrink: 0;
}
.lane-detail .pill .v { color: var(--tx-primary); font-weight: 600; }
.lane-time { color: var(--tx-helper); font-family: var(--font-mono); font-size: 11.5px; white-space: nowrap; }

.progress {
  height: 4px;
  background: var(--bd-subtle);
  border-radius: 2px;
  overflow: hidden;
  margin-top: 6px;
}
.progress > .bar {
  height: 100%;
  background: var(--acc-active);
  width: 0%;
  transition: width 200ms ease;
}

/* ---------- Heatmap ---------- */
.heatmap {
  display: grid;
  grid-template-columns: repeat(auto-fill, 8px);
  gap: 1px;
  margin-top: 10px;
}
.heatmap .cell {
  width: 8px; height: 8px; border-radius: 1px;
  background: var(--score-neutral);
  transition: background 80ms ease;
}
.heatmap .cell[data-state="probing"] { background: var(--acc-active); }
.heatmap .cell[data-state="ok"]      { background: var(--acc-success); }
.heatmap .cell[data-state="skipped"] { background: var(--acc-warning); }
.heatmap .cell[data-state="junk"]    { background: var(--acc-error); }

/* ---------- Leaderboard ---------- */
.lb-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 12px; gap: 12px; flex-wrap: wrap;
}
.lb-actions { display: flex; gap: 8px; }
.leaderboard {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 6px;
}
.qual-legend { grid-column: 1 / -1; }
.cand {
  display: grid;
  grid-template-columns: 48px 1fr;
  grid-template-rows: auto auto;
  column-gap: 12px;
  row-gap: 4px;
  align-items: center;
  background: var(--bg-panel);
  border: 1px solid var(--bd-subtle);
  border-radius: var(--r-4);
  padding: 8px 12px;
  transition: border-color 120ms ease;
}
.cand:hover { border-color: var(--bd-mid); }
.cand .badge {
  grid-row: 1 / 3;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-family: var(--font-brand); font-weight: 700; font-size: 20px;
  line-height: 1.0;
}
.cand[data-band="good"] .badge { color: var(--score-good); }
.cand[data-band="mid"]  .badge { color: var(--score-mid); }
.cand[data-band="bad"]  .badge { color: var(--score-bad); }
.cand .badge .icon { width: 16px; height: 16px; margin-bottom: 3px; }

.cand .info { grid-column: 2; min-width: 0; }
.cand-name {
  font-family: var(--font-brand);
  font-weight: 600;
  font-size: 15px;
  color: var(--tx-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cand-meta {
  color: var(--tx-helper);
  font-family: var(--font-mono);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.qual {
  grid-column: 2;
  display: flex; gap: 5px; align-items: center;
  flex-wrap: wrap; justify-content: flex-start;
  padding-top: 1px;
}
.qual .icon { width: 14px; height: 14px; display: block; }
.qual > span { display: inline-flex; line-height: 0; position: relative; cursor: help; }
.qual .on        { color: var(--acc-success); }
.qual .on-strong { color: var(--acc-active); }
.qual .off       { color: var(--tx-muted); }
.qual .off-warn  { color: var(--acc-warning); }
.qual .off-bad   { color: var(--acc-error); }

/* ---------- Styled tooltips (data-tip attribute) ---------- */
[data-tip] { position: relative; }
[data-tip]:hover::after,
[data-tip]:focus::after {
  content: attr(data-tip);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-elevated);
  color: var(--tx-primary);
  border: 1px solid var(--bd-mid);
  border-radius: var(--r-3);
  padding: 6px 10px;
  font-family: var(--font-body);
  font-size: 12px;
  font-weight: 500;
  line-height: 1.4;
  white-space: nowrap;
  pointer-events: none;
  z-index: 100;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}
[data-tip]:hover::before,
[data-tip]:focus::before {
  content: '';
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 5px solid transparent;
  border-top-color: var(--bd-mid);
  pointer-events: none;
  z-index: 100;
}

/* ---------- Quality legend ---------- */
.qual-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  padding: 10px 12px;
  margin-bottom: 10px;
  background: var(--bg-panel);
  border: 1px solid var(--bd-subtle);
  border-radius: var(--r-4);
  font-size: 11.5px;
  color: var(--tx-helper);
}
.qual-legend .legend-item {
  display: inline-flex; align-items: center; gap: 5px;
  font-family: var(--font-body);
}
.qual-legend .legend-item .icon { width: 13px; height: 13px; color: var(--tx-secondary); }
.qual-legend .legend-item span:last-child { color: var(--tx-secondary); }

/* ---------- Event log ---------- */
.eventlog {
  background: var(--bg-panel);
  border: 1px solid var(--bd-subtle);
  border-radius: var(--r-4);
  padding: 12px;
  max-height: 360px;
  overflow: auto;
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.5;
}
.eventlog .row { display: flex; gap: 12px; padding: 1px 0; }
.eventlog .ts { color: var(--tx-muted); min-width: 110px; }
.eventlog .stage {
  min-width: 80px;
  padding: 0 6px;
  border-radius: var(--r-1);
  background: var(--bg-elevated);
  color: var(--tx-helper);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  align-self: center;
}
.eventlog .type { color: var(--tx-secondary); min-width: 170px; }
.eventlog .summary { color: var(--tx-helper); flex: 1; word-break: break-all; }
.eventlog .row[data-type="candidate.new"]   .summary { color: var(--acc-success); }
.eventlog .row[data-type="ip.skipped"]      .summary { color: var(--acc-warning); }
.eventlog .row[data-type="scan.failed"]     .summary { color: var(--acc-error); }

/* ---------- Status messages ---------- */
.toast {
  background: var(--bg-elevated);
  border: 1px solid var(--bd-mid);
  border-radius: var(--r-4);
  padding: 10px 14px;
  color: var(--tx-secondary);
  font-size: 13px;
}
.toast.error { border-color: var(--acc-error); color: #fad9dc; }

/* ---------- History ---------- */
.history { display: flex; flex-direction: column; gap: 6px; }
.history .item {
  background: var(--bg-panel);
  border: 1px solid var(--bd-subtle);
  border-radius: var(--r-3);
  padding: 8px 10px;
  cursor: pointer;
  display: flex; justify-content: space-between; align-items: center;
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--tx-secondary);
}
.history .item:hover { border-color: var(--bd-mid); color: var(--tx-primary); }
.history .item .target { font-weight: 600; }
.history .item .when   { color: var(--tx-helper); }

/* ---------- Misc ---------- */
.spacer-sm { height: 8px; }
.muted     { color: var(--tx-helper); }
.mono      { font-family: var(--font-mono); }
.hidden    { display: none !important; }

details > summary {
  cursor: pointer;
  font-family: var(--font-brand);
  font-weight: 600;
  font-size: 13px;
  letter-spacing: 1.3px;
  text-transform: uppercase;
  color: var(--tx-helper);
  list-style: none;
}
details > summary::-webkit-details-marker { display: none; }
details > summary::after { content: " ▾"; color: var(--tx-muted); }
details[open] > summary::after { content: " ▴"; }
