:root {
  --bg: #f3efe4;
  --panel: #fffaf1;
  --ink: #1f2933;
  --muted: #61707d;
  --line: #d4c4aa;
  --accent: #0b6e69;
  --accent-strong: #084d49;
  --danger: #9f2d2d;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Avenir Next", "Helvetica Neue", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(11, 110, 105, 0.15), transparent 28%),
    linear-gradient(180deg, #f8f4ea 0%, var(--bg) 100%);
}

.layout {
  display: grid;
  grid-template-columns: 360px 1fr;
  min-height: 100vh;
  height: 100vh;
}

.sidebar {
  padding: 24px;
  border-right: 1px solid var(--line);
  background: rgba(255, 250, 241, 0.92);
  backdrop-filter: blur(6px);
  overflow-y: auto;
  min-height: 0;
}

.canvasArea {
  padding: 20px;
  overflow: auto;
  min-height: 0;
  min-width: 0;
  height: 100vh;
  overscroll-behavior: contain;
  cursor: default;
}

.canvasContent {
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-width: fit-content;
}

h1,
h2 {
  margin: 0 0 12px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

h1 {
  font-size: 1.8rem;
}

h2 {
  font-size: 1rem;
}

.intro {
  margin: 0 0 20px;
  color: var(--muted);
  line-height: 1.45;
}

.field,
.panel label {
  display: block;
}

.field {
  margin-bottom: 16px;
}

.field span {
  display: block;
  margin-bottom: 6px;
  font-size: 0.92rem;
  font-weight: 600;
}

select,
button,
input {
  width: 100%;
  border-radius: 12px;
  border: 1px solid var(--line);
  font: inherit;
}

select {
  padding: 10px 12px;
  background: #fff;
}

input {
  padding: 10px 12px;
  background: #fff;
}

.actions {
  display: grid;
  gap: 10px;
  margin: 18px 0 22px;
}

.authBar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0 0 18px;
  color: var(--muted);
  flex-wrap: wrap;
}

.loginPage {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.loginCard {
  width: min(520px, 100%);
  padding: 28px;
  background: rgba(255, 250, 241, 0.95);
  border: 1px solid var(--line);
  border-radius: 24px;
  box-shadow: 0 18px 48px rgba(31, 41, 51, 0.14);
}

button {
  padding: 12px 14px;
  color: #fff;
  background: var(--accent);
  cursor: pointer;
  transition: background 140ms ease, transform 140ms ease;
}

button:hover {
  background: var(--accent-strong);
  transform: translateY(-1px);
}

.secondaryButton {
  width: auto;
  color: var(--ink);
  background: transparent;
}

.secondaryButton:hover {
  background: rgba(11, 110, 105, 0.1);
}

#runAiDraft {
  background: #84cc16;
  color: #17310a;
  font-weight: 700;
}

#runAiDraft:hover {
  background: #65a30d;
}

#clearLabel {
  background: var(--danger);
}

.panel {
  margin-top: 18px;
  padding: 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
}

.panel label {
  margin-bottom: 10px;
  font-size: 0.95rem;
}

.panel input[type="checkbox"] {
  margin-right: 8px;
}

.panel ul {
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
  line-height: 1.5;
}

#statusBox {
  margin: 0;
  white-space: pre-wrap;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.85rem;
  color: var(--muted);
}

canvas {
  display: block;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: 0 12px 36px rgba(31, 41, 51, 0.12);
}

.metricsPanel {
  background: rgba(255, 250, 241, 0.94);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 16px;
  box-shadow: 0 8px 24px rgba(31, 41, 51, 0.08);
}

.metricsEmpty {
  margin: 0;
  color: var(--muted);
}

.metricsTable {
  width: 100%;
  border-collapse: collapse;
  font-size: 1.2rem;
}

.metricsTable th,
.metricsTable td {
  padding: 8px 10px;
  border-bottom: 1px solid rgba(212, 196, 170, 0.75);
  text-align: left;
}

.metricsTable th {
  font-size: 1.07rem;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--muted);
}

.metricsTable tbody tr:last-child td {
  border-bottom: 0;
}

#instrumentDataTable td:first-child {
  width: 42%;
  color: var(--muted);
  font-weight: 600;
}

.metricsLabel {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.metricsSwatch {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  flex: 0 0 auto;
}

.modalBackdrop {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(15, 23, 42, 0.48);
  z-index: 30;
}

.modalBackdrop[hidden] {
  display: none;
}

.modalCard {
  width: min(560px, 100%);
  max-height: min(80vh, 760px);
  overflow: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 22px;
  box-shadow: 0 20px 48px rgba(31, 41, 51, 0.28);
  padding: 20px;
}

.modalHeader {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
}

.modalHeader h2 {
  margin-bottom: 0;
}

.modalClose {
  width: auto;
  min-width: 96px;
}

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

.modalTable td:first-child {
  width: 28%;
  color: var(--ink);
}

.opsLayout {
  display: grid;
  grid-template-columns: 360px 1fr;
  min-height: 100vh;
}

.opsMain {
  display: grid;
  grid-template-columns: minmax(280px, 360px) minmax(0, 1fr);
  gap: 18px;
  padding: 20px;
  min-width: 0;
  align-items: start;
}

.opsPanel {
  min-height: calc(100vh - 40px);
  display: flex;
  flex-direction: column;
}

.opsPanelHeader {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.opsHint {
  color: var(--muted);
  font-size: 0.92rem;
}

.opsFieldGrid {
  display: grid;
  gap: 10px;
}

.opsSummary {
  display: grid;
  gap: 12px;
  margin: 0;
}

.opsSummary div {
  display: grid;
  gap: 4px;
}

.opsSummary dt {
  font-weight: 700;
  font-size: 0.88rem;
  color: var(--muted);
}

.opsSummary dd {
  margin: 0;
  word-break: break-word;
}

.jobList {
  display: grid;
  gap: 10px;
  overflow: auto;
}

.jobCard {
  display: grid;
  gap: 6px;
  text-align: left;
  background: #fff;
  color: var(--ink);
  border: 1px solid var(--line);
  padding: 14px;
}

.jobCard:hover {
  background: #f7f1e6;
}

.jobCard.is-selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(11, 110, 105, 0.12);
}

.jobCardTitle {
  font-weight: 700;
}

.jobCardMeta {
  font-size: 0.84rem;
  color: var(--muted);
}

.statusPill {
  display: inline-flex;
  width: fit-content;
  align-items: center;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.status-queued {
  background: #ede9fe;
  color: #5b21b6;
}

.status-running {
  background: #dcfce7;
  color: #166534;
}

.status-completed {
  background: #dbeafe;
  color: #1d4ed8;
}

.status-failed {
  background: #fee2e2;
  color: #991b1b;
}

.opsMeta {
  display: grid;
  gap: 8px;
  margin-bottom: 12px;
  color: var(--muted);
}

.opsLog {
  flex: 1 1 auto;
  min-height: 320px;
  margin: 0;
  padding: 16px;
  border-radius: 16px;
  background: #17212b;
  color: #f8fafc;
  overflow: auto;
  white-space: pre-wrap;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.85rem;
  line-height: 1.45;
}

.secondaryButton {
  width: auto;
  padding-inline: 14px;
  background: #fff;
  color: var(--ink);
}

.secondaryButton:hover {
  background: #f7f1e6;
}

@media (max-width: 960px) {
  .layout,
  .opsLayout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

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

.postprocessLayout {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(280px, 350px) 1fr;
  background:
    radial-gradient(circle at 72% 8%, rgba(31, 130, 123, 0.16), transparent 30%),
    #edf0e8;
}

.postprocessSidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  background: #fffaf0;
}

.eyebrow {
  margin: 0 0 5px;
  color: #b64928;
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}

.labControlGroup {
  display: grid;
  gap: 10px;
  padding: 16px;
  border: 1px solid #ddd2bd;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.62);
}

.labControlGroup h2 {
  margin: 0 0 3px;
  font-size: 1rem;
}

.labToggle {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 10px;
  align-items: start;
  cursor: pointer;
}

.labToggle input {
  margin-top: 3px;
  accent-color: #087b70;
}

.labToggle span,
.labToggle small {
  display: block;
}

.labToggle small {
  margin-top: 2px;
  color: var(--muted);
  line-height: 1.25;
}

#labStatus {
  min-height: 54px;
  margin: 0;
  padding: 12px;
  border-radius: 14px;
  background: #18252b;
  color: #d9f3e9;
  white-space: pre-wrap;
}

.postprocessMain {
  min-width: 0;
  padding: 28px;
}

.labHeader,
.diagnosticsHeader {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: end;
  margin-bottom: 18px;
}

.labHeader h2,
.diagnosticsHeader h2 {
  margin: 0;
}

.countStrip {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.countStrip div {
  min-width: 68px;
  padding: 9px 12px;
  border-radius: 14px;
  background: #193039;
  color: white;
  text-align: center;
}

.countStrip strong,
.countStrip span {
  display: block;
}

.countStrip strong {
  font-size: 1.3rem;
}

.countStrip span {
  color: #a8c9c5;
  font-size: 0.72rem;
  text-transform: uppercase;
}

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

.stageCard {
  overflow: hidden;
  border: 1px solid #d5cbb8;
  border-radius: 20px;
  background: #fffaf0;
  box-shadow: 0 12px 28px rgba(38, 52, 52, 0.08);
}

.stageCard > div {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 15px;
}

.stageCard h3 {
  margin: 0;
  font-size: 1rem;
}

.stageCard span {
  color: #b64928;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-weight: 800;
}

.stageCard img {
  display: block;
  width: 100%;
  min-height: 180px;
  background: #17212b;
  object-fit: contain;
}

.stageCardFinal {
  grid-column: 1 / -1;
}

.diagnosticsPanel {
  margin-top: 22px;
  padding: 20px;
  border-radius: 20px;
  background: #fffaf0;
  border: 1px solid #d5cbb8;
}

.diagnosticsHeader p:last-child {
  max-width: 420px;
  margin: 0;
  color: var(--muted);
}

.diagnosticsTableWrap {
  overflow-x: auto;
}

.diagnosticsTable {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.86rem;
}

.diagnosticsTable th,
.diagnosticsTable td {
  padding: 10px;
  border-bottom: 1px solid #e3d9c7;
  text-align: left;
  vertical-align: top;
}

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

.decisionPill {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 999px;
  background: #efe5d3;
  font-size: 0.74rem;
  font-weight: 700;
}

.diagnostic-selected .decisionPill {
  background: #caeee2;
  color: #075e55;
}

.diagnostic-quality,
.diagnostic-duplicate,
.diagnostic-geometry,
.diagnostic-limit {
  color: #7d2d21;
}

@media (max-width: 980px) {
  .postprocessLayout {
    grid-template-columns: 1fr;
  }

  .postprocessSidebar {
    position: static;
    height: auto;
  }

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

  .stageCardFinal {
    grid-column: auto;
  }
}
