:root {
  --lab-ink: #131820;
  --lab-paper: #f2f2ed;
  --lab-line: rgba(19, 24, 32, 0.12);
  --lab-blue: #2b63d9;
  --lab-blue-soft: #8db6ff;
  --lab-orange: #e07932;
  --lab-cyan: #55b8bd;
  --lab-green: #4c8d6c;
  --lab-panel: #171d25;
  --lab-numeric: "DIN Alternate", "Avenir Next Condensed", "Avenir Next", sans-serif;
}

.device-lab-page {
  background:
    radial-gradient(circle at 86% 2%, rgba(43, 99, 217, 0.12), transparent 23%),
    radial-gradient(circle at 3% 32%, rgba(224, 121, 50, 0.08), transparent 18%),
    linear-gradient(rgba(19, 24, 32, 0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(19, 24, 32, 0.025) 1px, transparent 1px),
    var(--lab-paper);
  background-size: auto, auto, 34px 34px, 34px 34px, auto;
}

.lab-header,
.lab-footer,
.lab-layout {
  width: min(1380px, calc(100% - 48px));
}

.lab-header { border-bottom: 1px solid var(--lab-line); }

.lab-layout {
  margin: 0 auto;
  padding: 48px 0 90px;
}

.lab-hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 310px;
  gap: clamp(34px, 7vw, 100px);
  align-items: center;
}

.lab-kicker,
.panel-kicker {
  margin: 0;
  color: var(--lab-blue);
  font-family: var(--lab-numeric);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.2em;
}

.lab-kicker { display: flex; align-items: center; gap: 10px; }
.lab-kicker > span { width: 22px; height: 2px; background: var(--lab-blue); }

.lab-hero h1 {
  max-width: 860px;
  margin: 17px 0 0;
  font-family: var(--serif);
  font-size: clamp(42px, 6.3vw, 76px);
  font-weight: 600;
  letter-spacing: -0.07em;
  line-height: 1.04;
}

.lab-hero h1 em { color: var(--lab-blue); font-style: normal; }

.lab-hero-copy > p:last-child {
  max-width: 760px;
  margin: 22px 0 0;
  color: #6d747d;
  font-size: 12px;
  line-height: 1.9;
}

.lab-source-card {
  position: relative;
  min-height: 224px;
  overflow: hidden;
  padding: 27px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 28px;
  color: #fff;
  background:
    radial-gradient(circle at 110% -10%, rgba(85, 184, 189, 0.3), transparent 42%),
    var(--lab-panel);
  box-shadow: 0 30px 70px rgba(24, 32, 43, 0.2);
  animation: lab-rise 600ms cubic-bezier(0.2, 0.75, 0.2, 1) both;
}

.source-orbit {
  position: absolute;
  top: -65px;
  right: -57px;
  width: 190px;
  height: 190px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 50%;
}

.source-orbit::before,
.source-orbit::after {
  position: absolute;
  inset: 22px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: inherit;
  content: "";
}

.source-orbit::after { inset: 53px; }
.source-orbit i { position: absolute; width: 5px; height: 5px; border-radius: 50%; background: #69d3ac; }
.source-orbit i:nth-child(1) { top: 83px; left: -3px; }
.source-orbit i:nth-child(2) { right: 20px; bottom: 36px; background: var(--lab-orange); }
.source-orbit i:nth-child(3) { top: 52px; right: 51px; background: var(--lab-blue-soft); }

.source-label {
  position: relative;
  color: rgba(255, 255, 255, 0.42);
  font-family: var(--lab-numeric);
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.17em;
}

.lab-source-card > strong {
  position: relative;
  display: block;
  max-width: 200px;
  margin-top: 18px;
  font-size: 19px;
  letter-spacing: -0.02em;
}

.lab-source-card > p {
  position: relative;
  max-width: 220px;
  margin: 12px 0 0;
  color: rgba(255, 255, 255, 0.53);
  font-size: 10px;
  line-height: 1.75;
}

.source-state {
  position: absolute;
  right: 27px;
  bottom: 24px;
  left: 27px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding-top: 17px;
  border-top: 1px solid rgba(255, 255, 255, 0.09);
  color: rgba(255, 255, 255, 0.64);
  font-size: 9px;
}

.source-state i { width: 6px; height: 6px; border-radius: 50%; background: #69d3ac; box-shadow: 0 0 0 5px rgba(105, 211, 172, 0.1); }

.lab-control-deck {
  display: grid;
  grid-template-columns: minmax(230px, 1.35fr) minmax(150px, 0.7fr) minmax(360px, 1.4fr) auto;
  gap: 10px;
  align-items: stretch;
  margin-top: 48px;
  padding: 10px;
  border: 1px solid var(--lab-line);
  border-radius: 21px;
  background: rgba(255, 255, 255, 0.72);
  box-shadow: 0 17px 52px rgba(26, 35, 46, 0.07);
}

.control-field,
.range-switcher {
  min-width: 0;
  margin: 0;
  padding: 11px 13px;
  border: 0;
  border-right: 1px solid var(--lab-line);
}

.control-field > span,
.range-switcher legend {
  display: block;
  margin-bottom: 7px;
  padding: 0;
  color: #8a9098;
  font-family: var(--lab-numeric);
  font-size: 8px;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.control-field select {
  width: 100%;
  height: 25px;
  padding: 0 26px 0 0;
  overflow: hidden;
  border: 0;
  outline: 0;
  color: var(--lab-ink);
  background: transparent;
  font-size: 11px;
  font-weight: 700;
  text-overflow: ellipsis;
}

.range-switcher > div { display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; }

.range-switcher button {
  height: 29px;
  padding: 0 7px;
  border: 1px solid transparent;
  border-radius: 8px;
  color: #777e87;
  background: transparent;
  cursor: pointer;
  font-size: 9px;
  transition: 160ms ease;
}

.range-switcher button:hover { color: var(--lab-blue); background: rgba(43, 99, 217, 0.06); }
.range-switcher button.is-active { border-color: rgba(43, 99, 217, 0.18); color: #fff; background: var(--lab-blue); box-shadow: 0 7px 16px rgba(43, 99, 217, 0.18); }

.control-actions { display: grid; grid-template-columns: 1fr auto; gap: 6px; min-width: 218px; }
.control-actions button { border: 0; border-radius: 12px; cursor: pointer; font-size: 9px; font-weight: 750; }
.import-button { display: flex; align-items: center; justify-content: space-between; gap: 13px; padding: 0 14px; color: #fff; background: var(--lab-ink); }
.import-button b { font-size: 17px; font-weight: 400; }
.template-button { padding: 0 12px; color: #69717a; background: #edf0ec; }
.control-actions button:hover { filter: brightness(1.08); }

.device-strip {
  display: grid;
  grid-template-columns: minmax(260px, 1.45fr) minmax(0, 2fr) auto;
  gap: 28px;
  align-items: center;
  margin-top: 18px;
  padding: 16px 20px;
  border: 1px solid var(--lab-line);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.48);
}

.device-strip > div:first-child span { display: block; color: var(--lab-blue); font-family: var(--lab-numeric); font-size: 8px; font-weight: 800; letter-spacing: 0.18em; }
.device-strip > div:first-child strong { display: block; margin-top: 6px; overflow: hidden; font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.device-strip dl { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); margin: 0; }
.device-strip dl > div { min-width: 0; padding: 0 13px; border-left: 1px solid var(--lab-line); }
.device-strip dt { color: #8a9098; font-size: 8px; }
.device-strip dd { margin: 5px 0 0; overflow: hidden; font-size: 10px; font-weight: 700; text-overflow: ellipsis; white-space: nowrap; }
.device-strip > a { color: var(--lab-blue); font-size: 9px; font-weight: 750; white-space: nowrap; }

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-top: 34px;
}

.metric-card {
  position: relative;
  min-height: 158px;
  overflow: hidden;
  padding: 20px;
  border: 1px solid var(--lab-line);
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.73);
  box-shadow: 0 13px 38px rgba(26, 35, 46, 0.055);
}

.metric-card::after { position: absolute; top: 0; right: 0; left: 0; height: 3px; background: #b6bcc4; content: ""; }
.metric-card-primary::after { background: var(--lab-blue); }
.metric-card-danger::after { background: var(--lab-orange); }
.metric-card-dark { color: #fff; border-color: var(--lab-panel); background: var(--lab-panel); }
.metric-card-dark::after { background: var(--lab-cyan); }
.metric-index { color: #90969e; font-family: var(--lab-numeric); font-size: 8px; font-weight: 800; letter-spacing: 0.14em; }
.metric-card > div { display: flex; align-items: baseline; gap: 6px; margin-top: 21px; }
.metric-card > div strong { font-family: var(--lab-numeric); font-size: clamp(32px, 4vw, 46px); line-height: 1; letter-spacing: -0.045em; }
.metric-card > div small { color: #878e97; font-size: 10px; }
.metric-card p { margin: 14px 0 0; color: #7d848d; font-size: 9px; line-height: 1.55; }
.metric-card-dark .metric-index,
.metric-card-dark p,
.metric-card-dark > div small { color: rgba(255, 255, 255, 0.5); }

.analysis-grid {
  display: grid;
  grid-template-columns: minmax(0, 2.55fr) minmax(270px, 0.75fr);
  gap: 14px;
  margin-top: 14px;
}

.chart-panel,
.question-panel,
.event-panel,
.insight-panel,
.method-panel {
  border: 1px solid var(--lab-line);
  border-radius: 24px;
  background: rgba(255, 255, 255, 0.72);
  box-shadow: 0 18px 50px rgba(26, 35, 46, 0.06);
}

.chart-panel { overflow: hidden; }

.panel-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 20px;
  padding: 22px 24px 18px;
}

.panel-heading h2,
.question-panel h2,
.insight-panel h2,
.method-panel h2 {
  margin: 8px 0 0;
  font-family: var(--serif);
  font-weight: 600;
  letter-spacing: -0.04em;
}

.panel-heading h2 { font-size: 23px; }
.chart-legend { display: flex; gap: 15px; color: #737b84; font-size: 9px; }
.chart-legend span { display: flex; align-items: center; gap: 6px; }
.chart-legend i { width: 15px; height: 2px; background: currentColor; }
.legend-min { color: var(--lab-blue) !important; }
.legend-mean { color: #dfe6ed !important; }
.legend-max { color: var(--lab-orange) !important; }

.chart-shell {
  position: relative;
  height: 430px;
  margin: 0 12px;
  overflow: hidden;
  border-radius: 18px;
  background:
    radial-gradient(circle at 82% 4%, rgba(85, 184, 189, 0.13), transparent 25%),
    linear-gradient(rgba(255, 255, 255, 0.045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.045) 1px, transparent 1px),
    var(--lab-panel);
  background-size: auto, 40px 40px, 40px 40px, auto;
}

#envelope-chart { display: block; width: 100%; height: 100%; }

.chart-tooltip {
  position: absolute;
  z-index: 3;
  width: 176px;
  padding: 12px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  color: #fff;
  background: rgba(8, 12, 17, 0.92);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.3);
  pointer-events: none;
  font-size: 9px;
  line-height: 1.65;
}

.chart-tooltip strong { display: block; margin-bottom: 4px; font-size: 10px; }
.chart-tooltip span { display: flex; justify-content: space-between; color: rgba(255, 255, 255, 0.65); }
.chart-tooltip b { color: #fff; font-family: var(--lab-numeric); }
.chart-empty { position: absolute; inset: 0; display: grid; place-items: center; color: rgba(255, 255, 255, 0.5); font-size: 11px; }
.chart-empty[hidden] { display: none; }

.chart-footer { display: flex; justify-content: space-between; gap: 20px; padding: 15px 24px 19px; color: #8a9098; font-size: 8px; }

.question-panel {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  color: #fff;
  border-color: var(--lab-panel);
  background: var(--lab-panel);
}

.question-panel > header { padding: 23px 23px 17px; }
.question-panel .panel-kicker { color: var(--lab-cyan); }
.question-panel h2 { font-size: 27px; }
.question-list { display: grid; border-top: 1px solid rgba(255, 255, 255, 0.08); }
.question-list button {
  display: grid;
  grid-template-columns: 26px 1fr auto;
  gap: 12px;
  align-items: center;
  min-height: 75px;
  padding: 12px 21px;
  border: 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  color: #fff;
  background: transparent;
  cursor: pointer;
  text-align: left;
  transition: 170ms ease;
}

.question-list button:hover,
.question-list button.is-active { background: rgba(85, 184, 189, 0.11); }
.question-list button span { color: #65717d; font-family: var(--lab-numeric); font-size: 9px; }
.question-list button strong { font-size: 10px; line-height: 1.55; }
.question-list button i { color: #606c76; font-style: normal; }
.question-list button:hover i,
.question-list button.is-active i { color: var(--lab-cyan); transform: translateX(3px); }

.question-answer { margin: auto 14px 14px; padding: 17px; border-radius: 15px; background: rgba(255, 255, 255, 0.06); }
.question-answer span { color: var(--lab-cyan); font-family: var(--lab-numeric); font-size: 8px; font-weight: 800; letter-spacing: 0.14em; }
.question-answer strong { display: block; margin-top: 10px; font-size: 12px; line-height: 1.55; }
.question-answer p { margin: 8px 0 0; color: rgba(255, 255, 255, 0.46); font-size: 9px; line-height: 1.6; }

.evidence-grid {
  display: grid;
  grid-template-columns: minmax(0, 2.15fr) minmax(280px, 0.85fr);
  gap: 14px;
  margin-top: 14px;
}

.event-panel { overflow: hidden; }
.event-heading { align-items: center; border-bottom: 1px solid var(--lab-line); }
.threshold-controls { display: flex; gap: 7px; }
.threshold-controls label { min-width: 86px; padding: 8px 10px; border: 1px solid var(--lab-line); border-radius: 10px; background: rgba(247, 248, 245, 0.85); }
.threshold-controls span { display: block; color: #90969e; font-size: 7px; }
.threshold-controls input,
.threshold-controls select { width: 100%; height: 20px; margin-top: 3px; padding: 0; border: 0; outline: 0; background: transparent; font-family: var(--lab-numeric); font-size: 10px; font-weight: 800; }

.event-summary { display: flex; gap: 24px; padding: 13px 23px; border-bottom: 1px solid var(--lab-line); color: #777e87; background: rgba(246, 247, 243, 0.75); font-size: 8px; }
.event-summary strong { margin-left: 4px; color: var(--lab-ink); font-family: var(--lab-numeric); font-size: 11px; }
.event-table-wrap { overflow-x: auto; }
.event-panel table { width: 100%; border-collapse: collapse; font-size: 9px; }
.event-panel th { padding: 11px 14px; color: #949aa1; font-size: 7px; font-weight: 750; letter-spacing: 0.08em; text-align: left; }
.event-panel td { padding: 12px 14px; border-top: 1px solid rgba(19, 24, 32, 0.075); color: #626a73; white-space: nowrap; }
.event-panel tbody tr:hover { background: rgba(43, 99, 217, 0.035); }
.event-type { display: inline-flex; align-items: center; gap: 6px; font-weight: 800; }
.event-type::before { width: 6px; height: 6px; border-radius: 50%; background: currentColor; content: ""; }
.event-type-low { color: var(--lab-blue); }
.event-type-high { color: var(--lab-orange); }
.event-panel td a { color: var(--lab-blue); font-weight: 750; }
.event-empty { margin: 0; padding: 28px; color: #858c94; font-size: 10px; text-align: center; }

.insight-panel { padding: 24px; }
.insight-panel h2 { font-size: 28px; }
.insight-list { display: grid; margin-top: 21px; border-top: 1px solid var(--lab-line); }
.insight-item { display: grid; grid-template-columns: 28px 1fr; gap: 10px; padding: 15px 0; border-bottom: 1px solid var(--lab-line); }
.insight-item > span { display: grid; place-items: center; width: 25px; height: 25px; border-radius: 8px; color: var(--lab-blue); background: rgba(43, 99, 217, 0.08); font-family: var(--lab-numeric); font-size: 8px; font-weight: 800; }
.insight-item strong { display: block; font-size: 10px; line-height: 1.55; }
.insight-item p { margin: 5px 0 0; color: #7f868e; font-size: 9px; line-height: 1.65; }
.insight-boundary { margin-top: 19px; padding: 15px; border-radius: 13px; background: #eef1ed; }
.insight-boundary span { color: var(--lab-green); font-size: 8px; font-weight: 800; }
.insight-boundary p { margin: 7px 0 0; color: #6e767d; font-size: 9px; line-height: 1.7; }

.method-panel {
  display: grid;
  grid-template-columns: minmax(230px, 0.8fr) minmax(0, 2fr);
  gap: 42px;
  margin-top: 14px;
  padding: 29px;
}

.method-panel h2 { max-width: 320px; font-size: 29px; line-height: 1.2; }
.method-panel ol { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0; margin: 0; padding: 0; list-style: none; }
.method-panel li { padding: 0 17px; border-left: 1px solid var(--lab-line); }
.method-panel li span { color: var(--lab-blue); font-family: var(--lab-numeric); font-size: 9px; }
.method-panel li strong { display: block; margin-top: 10px; font-size: 10px; }
.method-panel li p { margin: 7px 0 0; color: #7d848c; font-size: 8px; line-height: 1.7; }

.lab-toast {
  position: fixed;
  z-index: 20;
  right: 22px;
  bottom: 22px;
  max-width: min(380px, calc(100% - 44px));
  padding: 13px 16px;
  border-radius: 13px;
  color: #fff;
  background: rgba(19, 24, 32, 0.95);
  box-shadow: 0 16px 42px rgba(0, 0, 0, 0.23);
  font-size: 10px;
}

.lab-toast.is-error { background: #9a3f32; }
.lab-toast[hidden] { display: none; }

@keyframes lab-rise {
  from { opacity: 0; transform: translateY(14px) rotate(0.6deg); }
  to { opacity: 1; transform: translateY(0) rotate(0); }
}

@media (max-width: 1180px) {
  .lab-control-deck { grid-template-columns: 1fr 0.65fr 1.35fr; }
  .control-actions { grid-column: 1 / -1; min-height: 45px; }
  .device-strip { grid-template-columns: minmax(250px, 1fr) minmax(0, 1.8fr); }
  .device-strip > a { grid-column: 1 / -1; }
}

@media (max-width: 960px) {
  .lab-hero { grid-template-columns: 1fr; }
  .lab-source-card { width: min(100%, 500px); }
  .analysis-grid,
  .evidence-grid { grid-template-columns: 1fr; }
  .question-panel { min-height: 560px; }
  .method-panel { grid-template-columns: 1fr; }
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 760px) {
  .lab-header,
  .lab-footer,
  .lab-layout { width: calc(100% - 28px); }
  .lab-header nav { gap: 11px; font-size: 9px; }
  .lab-header nav a:nth-child(2) { display: none; }
  .lab-layout { padding-top: 31px; }
  .lab-hero h1 { font-size: 43px; }
  .lab-control-deck { grid-template-columns: 1fr; }
  .control-field,
  .range-switcher { border-right: 0; border-bottom: 1px solid var(--lab-line); }
  .control-actions { grid-column: auto; min-height: 46px; }
  .range-switcher > div { grid-template-columns: repeat(5, minmax(0, 1fr)); }
  .device-strip { grid-template-columns: 1fr; gap: 16px; }
  .device-strip dl { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 11px 0; }
  .device-strip dl > div:nth-child(4) { border-left: 0; }
  .metric-grid { gap: 8px; }
  .metric-card { min-height: 136px; padding: 16px; }
  .metric-card > div strong { font-size: 34px; }
  .panel-heading { align-items: start; flex-direction: column; }
  .chart-shell { height: 340px; }
  .chart-footer { align-items: start; flex-direction: column; gap: 5px; }
  .event-heading { align-items: stretch; }
  .threshold-controls { width: 100%; }
  .threshold-controls label { min-width: 0; flex: 1; }
  .event-summary { gap: 13px; overflow-x: auto; }
  .method-panel ol { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 22px 0; }
}

@media (max-width: 460px) {
  .lab-hero h1 { font-size: 37px; }
  .lab-hero-copy > p:last-child { font-size: 10px; }
  .metric-grid { grid-template-columns: 1fr; }
  .metric-card { min-height: 126px; }
  .device-strip dl { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .device-strip dl > div:nth-child(3),
  .device-strip dl > div:nth-child(5) { border-left: 0; }
  .device-strip dl > div:nth-child(4) { border-left: 1px solid var(--lab-line); }
  .range-switcher button { padding: 0 2px; font-size: 8px; }
  .chart-legend { gap: 9px; }
  .threshold-controls { display: grid; grid-template-columns: repeat(3, 1fr); }
  .method-panel { padding: 22px; }
  .method-panel ol { grid-template-columns: 1fr; }
  .method-panel li { padding: 0 0 16px; border-bottom: 1px solid var(--lab-line); border-left: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .lab-source-card { animation: none; }
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: 0.01ms !important; }
}
