/*
 * Detector Lab — internal fixture browser + timing dashboard.
 *
 * Neo-kinpaku tool shell. This is a genuinely page-specific app layout
 * (fixed sidebar + workspace + iframe + metrics), so it keeps its bespoke
 * structure rather than forcing the marketing kit's .ks-section grid onto it.
 * Every color, rule, and type value reads from kinpaku-tokens.css (--ks-*).
 * The fixture iframe renders untouched test HTML — only the lab chrome is themed.
 */

.detector-lab-page {
  background: var(--ks-lacquer);
  color: var(--ks-text);
  font-family: var(--ks-font);
  overflow: hidden;
}

.detector-main-shell {
  height: 100vh;
  min-height: 0;
}

.detector-workbench {
  --detector-sidebar-width: 320px;
  height: 100vh;
  min-height: 0;
  background: var(--ks-lacquer);
}

.detector-fixture-nav {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  width: var(--detector-sidebar-width);
  border-right: 1px solid var(--ks-rule);
  background: var(--ks-lacquer-deep);
}

.detector-nav-head {
  flex-shrink: 0;
  padding: var(--spacing-md);
  border-bottom: 1px solid var(--ks-rule);
}

.detector-home-link {
  color: var(--ks-kinpaku);
  text-decoration: none;
}

.detector-home-link .ks-mark { width: 30px; height: 30px; }
.detector-home-link .ks-mark svg { width: 26px; height: 26px; }

.detector-home-link .ks-wordmark {
  font-size: 1.05rem;
  letter-spacing: 0.16em;
}

.detector-nav-head h1 {
  margin-top: var(--spacing-md);
  color: var(--ks-champagne);
  font-family: var(--ks-font);
  font-size: 1.25rem;
  font-weight: 600;
  line-height: 1.15;
  letter-spacing: 0;
}

.detector-nav-head > p {
  margin-top: 6px;
  color: var(--ks-text-muted);
  font-size: 0.875rem;
  line-height: 1.5;
}

.detector-summary-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-top: var(--spacing-md);
  border: 1px solid var(--ks-rule);
}

.detector-summary-grid div {
  min-width: 0;
  padding: 10px;
  border-right: 1px solid var(--ks-rule);
  border-bottom: 1px solid var(--ks-rule);
}

.detector-summary-grid div:nth-child(2n) {
  border-right: 0;
}

.detector-summary-grid div:nth-last-child(-n + 2) {
  border-bottom: 0;
}

.detector-summary-grid dt,
.detector-panel-label,
.detector-nav-group h2,
.detector-live-stats dt {
  font-family: var(--ks-mono);
  font-size: 0.6875rem;
  font-weight: 500;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ks-text-muted);
}

.detector-summary-grid dd {
  margin-top: 4px;
  overflow-wrap: anywhere;
  color: var(--ks-champagne);
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.15;
}

.detector-nav-scroll {
  min-height: 0;
  overflow: auto;
  padding-bottom: var(--spacing-md);
}

.detector-nav-group {
  padding: var(--spacing-sm);
  border-bottom: 1px solid var(--ks-rule);
}

.detector-nav-group:last-child {
  border-bottom: 0;
}

.detector-nav-group h2 {
  letter-spacing: 0.2em;
  color: var(--ks-kinpaku-deep);
}

.detector-nav-list {
  display: grid;
  gap: 4px;
  margin-top: 10px;
}

.detector-fixture-button {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: var(--spacing-sm);
  align-items: center;
  width: 100%;
  min-height: 38px;
  padding: 8px 10px;
  border: 1px solid transparent;
  border-radius: 4px;
  background: transparent;
  color: var(--ks-text-muted);
  font-family: var(--ks-font);
  text-align: left;
  cursor: pointer;
  transition:
    background var(--duration-fast, 140ms) var(--ks-ease),
    border-color var(--duration-fast, 140ms) var(--ks-ease),
    color var(--duration-fast, 140ms) var(--ks-ease);
}

.detector-fixture-button:hover {
  background: var(--ks-graphite);
  color: var(--ks-champagne);
}

.detector-fixture-button:focus-visible {
  outline: 2px solid var(--ks-kinpaku);
  outline-offset: 2px;
}

.detector-fixture-button[aria-pressed="true"] {
  background: var(--ks-kinpaku);
  border-color: var(--ks-kinpaku);
  color: var(--ks-lacquer-deep);
}

.detector-fixture-button span:first-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 500;
}

.detector-fixture-button span:last-child {
  min-width: 2ch;
  font-family: var(--ks-mono);
  font-size: 0.75rem;
  color: currentColor;
  text-align: right;
  opacity: 0.72;
}

.detector-workspace {
  display: flex;
  flex-direction: column;
  min-width: 0;
  height: 100vh;
  min-height: 0;
  margin-left: var(--detector-sidebar-width);
  overflow: hidden;
}

.detector-preview-head {
  position: relative;
  z-index: 8;
  display: flex;
  flex-shrink: 0;
  justify-content: space-between;
  gap: var(--spacing-md);
  align-items: center;
  min-height: 72px;
  padding: 12px var(--spacing-md);
  border-bottom: 1px solid var(--ks-rule);
  background: var(--ks-lacquer-deep);
}

.detector-preview-head h2,
.detector-panel-head h2,
.detector-table-panel h2 {
  font-family: var(--ks-font);
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: 0;
  color: var(--ks-champagne);
}

.detector-preview-head p:not(.detector-panel-label) {
  max-width: 78ch;
  margin-top: 4px;
  color: var(--ks-text-muted);
  font-size: 0.875rem;
  line-height: 1.5;
}

.detector-preview-actions {
  display: flex;
  align-items: center;
  gap: var(--spacing-xs);
  flex-shrink: 0;
}

.detector-preview-actions a,
.detector-preview-actions button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  padding: 0 16px;
  border: 1px solid var(--ks-kinpaku);
  border-radius: 2px;
  background: transparent;
  color: var(--ks-kinpaku);
  font-family: var(--ks-font);
  font-size: 0.8125rem;
  font-weight: 500;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  transition:
    background var(--duration-fast, 140ms) var(--ks-ease),
    border-color var(--duration-fast, 140ms) var(--ks-ease),
    color var(--duration-fast, 140ms) var(--ks-ease),
    transform var(--duration-fast, 140ms) var(--ks-ease);
}

.detector-preview-actions a:hover,
.detector-preview-actions button:hover {
  background: oklch(77% 0.14 82 / 0.1);
  transform: translateY(-1px);
}

/* Run browser scan is the primary action: gold fill, dark text. */
.detector-preview-actions button[data-rerun-browser] {
  background: var(--ks-kinpaku);
  border-color: var(--ks-kinpaku);
  color: var(--ks-lacquer-deep);
}

.detector-preview-actions button[data-rerun-browser]:hover {
  background: var(--ks-kinpaku-pale);
  border-color: var(--ks-kinpaku-pale);
}

.detector-preview-actions a:focus-visible,
.detector-preview-actions button:focus-visible {
  outline: 2px solid var(--ks-patina);
  outline-offset: 3px;
}

.detector-content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: var(--spacing-sm);
  padding: var(--spacing-sm);
  align-items: start;
}

.detector-preview-column,
.detector-metric-panel,
.detector-table-panel {
  min-width: 0;
  border: 1px solid var(--ks-rule);
  background: var(--ks-lacquer-raised);
}

.detector-frame-wrap {
  background: var(--ks-lacquer-deep);
}

.detector-frame-wrap iframe {
  display: block;
  width: 100%;
  height: max(360px, calc(100vh - 156px));
  min-height: 0;
  border: 0;
  background: var(--ks-lacquer-deep);
}

.detector-workspace-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
}

.detector-metrics {
  position: sticky;
  top: var(--spacing-sm);
  display: grid;
  gap: var(--spacing-sm);
  max-height: calc(100vh - 104px);
  overflow: auto;
}

.detector-metric-panel {
  overflow: hidden;
}

.detector-panel-head {
  padding: var(--spacing-sm);
  border-bottom: 1px solid var(--ks-rule);
}

.detector-live-stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.detector-live-stats div {
  padding: var(--spacing-sm);
  border-right: 1px solid var(--ks-rule);
  border-bottom: 1px solid var(--ks-rule);
}

.detector-live-stats div:nth-child(2n) {
  border-right: 0;
}

.detector-live-stats dd {
  margin-top: 4px;
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--ks-champagne);
}

.detector-rule-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: var(--spacing-sm);
}

.detector-rule-pill,
.detector-empty-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  padding: 5px 8px;
  border: 1px solid var(--ks-rule);
  border-radius: 2px;
  background: var(--ks-graphite);
  color: var(--ks-text);
  font-size: 0.75rem;
  line-height: 1.2;
}

.detector-rule-pill code {
  min-width: 0;
  padding: 0;
  overflow: hidden;
  background: transparent;
  color: var(--ks-code-fg);
  font-family: var(--ks-mono);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.detector-rule-pill span {
  font-family: var(--ks-mono);
  color: var(--ks-patina);
}

.detector-empty-pill {
  color: var(--ks-text-faint);
}

.detector-tables {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: var(--spacing-sm);
  padding: 0 var(--spacing-sm) var(--spacing-sm);
}

.detector-table-panel header {
  display: flex;
  justify-content: space-between;
  gap: var(--spacing-md);
  padding: var(--spacing-sm);
  border-bottom: 1px solid var(--ks-rule);
}

.detector-table-panel header p:not(.detector-panel-label) {
  max-width: 28ch;
  color: var(--ks-text-faint);
  font-size: 0.8125rem;
  line-height: 1.5;
  text-align: right;
}

.detector-table-scroll {
  max-height: 420px;
  overflow: auto;
}

.detector-table-panel table {
  width: 100%;
  min-width: 620px;
  border-collapse: collapse;
  font-size: 0.8125rem;
}

.detector-table-panel th,
.detector-table-panel td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--ks-rule);
  color: var(--ks-text);
  text-align: left;
  vertical-align: top;
}

.detector-table-panel th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--ks-lacquer-raised);
  font-family: var(--ks-mono);
  font-size: 0.6875rem;
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ks-text-muted);
}

.detector-table-panel td code {
  padding: 0;
  background: transparent;
  color: var(--ks-code-fg);
  font-family: var(--ks-mono);
  font-size: 0.8125rem;
}

@media (max-width: 1180px) {
  .detector-workbench {
    --detector-sidebar-width: 280px;
  }

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

  .detector-metrics {
    position: static;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    max-height: none;
    overflow: visible;
  }
}

@media (max-width: 860px) {
  .detector-lab-page {
    overflow: auto;
  }

  .detector-main-shell,
  .detector-workbench,
  .detector-workspace {
    height: auto;
    min-height: 100vh;
    overflow: visible;
  }

  .detector-fixture-nav {
    position: static;
    width: auto;
    border-right: 0;
    border-bottom: 1px solid var(--ks-rule);
  }

  .detector-nav-scroll {
    max-height: 340px;
  }

  .detector-workspace {
    margin-left: 0;
  }

  .detector-workspace-scroll {
    overflow: visible;
  }

  .detector-preview-head {
    position: static;
    flex-direction: column;
    align-items: stretch;
  }

  .detector-preview-actions {
    flex-wrap: wrap;
  }

  .detector-metrics,
  .detector-tables {
    grid-template-columns: 1fr;
  }

  .detector-frame-wrap iframe {
    height: 560px;
  }

  .detector-table-panel header {
    flex-direction: column;
  }

  .detector-table-panel header p:not(.detector-panel-label) {
    max-width: none;
    text-align: left;
  }
}

@media (max-width: 520px) {
  .detector-nav-head,
  .detector-content-grid,
  .detector-tables {
    padding-left: var(--spacing-sm);
    padding-right: var(--spacing-sm);
  }

  .detector-summary-grid,
  .detector-live-stats {
    grid-template-columns: 1fr;
  }

  .detector-summary-grid div,
  .detector-live-stats div {
    border-right: 0;
  }

  .detector-summary-grid div:nth-last-child(2) {
    border-bottom: 1px solid var(--ks-rule);
  }
}
