:root {
  color-scheme: light;
  --bg: #eef3f1;
  --panel: #ffffff;
  --panel-soft: #f7faf9;
  --ink: #16221f;
  --muted: #66736e;
  --line: #d9e3df;
  --accent: #126c58;
  --accent-dark: #0e5747;
  --blue: #245f9f;
  --amber: #9b640f;
  --bad: #a33838;
  --shadow: 0 18px 50px rgba(22, 34, 31, 0.08);
}

* {
  box-sizing: border-box;
}

html {
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--ink);
}

body {
  margin: 0;
  min-width: 320px;
  overflow-x: hidden;
}

button,
input {
  font: inherit;
}

.lab-shell {
  width: min(1440px, calc(100% - 32px));
  margin: 0 auto;
  padding: 24px 0 40px;
  overflow-x: hidden;
}

.lab-header {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) minmax(420px, 720px);
  gap: 18px;
  align-items: center;
}

.brand-row {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.brand-row img {
  flex: 0 0 auto;
}

.eyebrow {
  margin: 0 0 2px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(1.8rem, 3vw, 2.8rem);
  line-height: 1;
  letter-spacing: 0;
}

h2 {
  font-size: 1rem;
  line-height: 1.2;
  letter-spacing: 0;
}

.control-panel,
.status-bar,
.metric-tile,
.quality-panel,
.quality-item,
.route-panel,
.observed-panel,
.observed-table,
.table-panel,
.history-panel,
.event-panel,
.lock-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.control-panel {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(160px, 220px) auto auto;
  gap: 10px;
  align-items: end;
  padding: 12px;
}

label {
  display: grid;
  gap: 6px;
  min-width: 0;
}

label span {
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

input {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 10px;
  color: var(--ink);
  background: var(--panel-soft);
}

input:focus {
  outline: 2px solid rgba(18, 108, 88, 0.25);
  border-color: var(--accent);
}

.btn {
  min-height: 40px;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 0 14px;
  font-weight: 800;
  cursor: pointer;
  white-space: nowrap;
}

.btn.primary {
  background: var(--accent);
  color: #ffffff;
}

.btn.primary:hover {
  background: var(--accent-dark);
}

.btn.secondary {
  background: #e9f3f0;
  border-color: #c6dbd4;
  color: var(--accent-dark);
}

.btn:disabled {
  cursor: wait;
  opacity: 0.62;
}

.status-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
  align-items: center;
  margin-top: 18px;
  padding: 12px 14px;
  color: var(--muted);
  font-size: 0.92rem;
}

.status-bar > span {
  min-width: 0;
  overflow-wrap: anywhere;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  border-radius: 999px;
  padding: 0 10px;
  font-weight: 800;
  color: var(--accent-dark);
  background: #dff1ec;
}

.status-pill.bad {
  color: var(--bad);
  background: #f7e3e3;
}

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

.metric-tile {
  min-height: 120px;
  padding: 16px;
}

.metric-tile span,
.metric-tile small {
  display: block;
  color: var(--muted);
}

.metric-tile span {
  font-size: 0.82rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.metric-tile strong {
  display: block;
  margin: 10px 0 4px;
  font-size: clamp(2rem, 4vw, 3.2rem);
  line-height: 1;
  letter-spacing: 0;
}

.quality-panel {
  margin-top: 18px;
  padding: 16px;
}

.quality-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.quality-item {
  min-height: 106px;
  padding: 12px;
  background: var(--panel-soft);
  box-shadow: none;
}

.quality-item span,
.quality-item small {
  display: block;
  color: var(--muted);
}

.quality-item span {
  font-size: 0.72rem;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.quality-item strong {
  display: block;
  margin: 9px 0 3px;
  font-size: 2rem;
  line-height: 1;
  letter-spacing: 0;
}

.route-panel,
.observed-panel,
.table-panel,
.history-panel,
.event-panel {
  margin-top: 18px;
  padding: 16px;
}

.observed-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 14px;
}

.observed-table {
  padding: 14px;
  background: var(--panel-soft);
  box-shadow: none;
}

.observed-table h3 {
  margin: 0 0 12px;
  font-size: 0.92rem;
  line-height: 1.2;
  letter-spacing: 0;
}

.observed-table table {
  min-width: 820px;
}

.observed-time {
  display: grid;
  gap: 2px;
}

.observed-time strong {
  font-size: 0.96rem;
}

.observed-time small {
  color: var(--muted);
}

.section-title {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: baseline;
  margin-bottom: 14px;
}

.section-title.full {
  grid-column: 1 / -1;
  margin: 4px 0 0;
}

.section-title p {
  color: var(--muted);
  font-size: 0.9rem;
}

.lock-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin-top: 18px;
}

.lock-cards {
  display: contents;
}

.lock-card {
  padding: 16px;
}

.lock-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.lock-head small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
}

.lock-total {
  min-width: 74px;
  text-align: right;
}

.lock-total strong {
  display: block;
  font-size: 2rem;
  line-height: 1;
}

.lock-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.lock-stat {
  min-height: 66px;
  border-radius: 6px;
  padding: 8px;
  background: var(--panel-soft);
}

.lock-stat span,
.lock-stat strong {
  display: block;
}

.lock-stat span {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
}

.lock-stat strong {
  margin-top: 4px;
  font-size: 1.45rem;
}

.group-list {
  display: grid;
  gap: 8px;
  margin-top: 14px;
}

.group-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
  font-size: 0.9rem;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 0 8px;
  color: var(--accent-dark);
  background: #dff1ec;
  font-size: 0.78rem;
  font-weight: 800;
  white-space: nowrap;
}

.badge.warn {
  color: var(--amber);
  background: #f8efd8;
}

.badge.blue {
  color: var(--blue);
  background: #e3edf8;
}

.table-scroll {
  overflow-x: auto;
  max-width: 100%;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 940px;
}

.history-table {
  min-width: 840px;
}

.section-table {
  min-width: 780px;
}

.section-table .lock-row {
  background: var(--panel-soft);
}

.section-table .lock-row td:first-child,
.section-table .lock-row td:nth-child(2) {
  font-weight: 900;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 10px 8px;
  text-align: left;
  vertical-align: top;
  font-size: 0.9rem;
}

th {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

td code {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 0.82rem;
}

.muted {
  color: var(--muted);
}

.event-log {
  display: grid;
  gap: 8px;
  margin: 0;
  padding-left: 20px;
}

.event-log li {
  color: var(--muted);
  font-size: 0.9rem;
}

@media (max-width: 1080px) {
  .lab-header,
  .lock-grid {
    grid-template-columns: 1fr;
  }

  .metric-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .quality-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 720px) {
  .lab-shell {
    width: min(100% - 20px, 1440px);
    padding-top: 14px;
  }

  .control-panel {
    grid-template-columns: 1fr;
  }

  .metric-grid {
    grid-template-columns: 1fr;
  }

  .quality-grid {
    grid-template-columns: 1fr;
  }

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

  .section-title {
    align-items: flex-start;
    flex-direction: column;
  }
}
