:root {
  color-scheme: light;
  --ink: #18212f;
  --muted: #64748b;
  --line: #d8dee8;
  --paper: #f7f8fb;
  --panel: #ffffff;
  --accent: #0f8b4c;
  --accent-dark: #0a5f35;
  --blue: #2556a3;
  --warn: #9a5b00;
  --shadow: 0 18px 45px rgba(15, 23, 42, 0.1);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--paper);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select {
  font: inherit;
}

button,
.upload-zone {
  min-height: 42px;
  border: 1px solid transparent;
  border-radius: 8px;
}

button {
  cursor: pointer;
  background: var(--ink);
  color: #ffffff;
  padding: 0 16px;
  font-weight: 700;
}

button.secondary {
  color: var(--ink);
  background: #eef2f7;
  border-color: #d7dfe9;
}

/* Reset-demo: quiet outline by default, unmistakable once armed. */
button.danger {
  width: 100%;
  margin-top: 8px;
  color: #9a2424;
  background: #ffffff;
  border-color: #e4c4c4;
}

button.danger.armed {
  color: #ffffff;
  background: #b03030;
  border-color: #b03030;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.6;
}

.app-shell {
  width: min(1480px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 22px 0 36px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 18px;
}

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

.brand-logo {
  height: 52px;
  width: auto;
  /* The logo asset has a white (non-transparent) background; multiply blends it
     into the page background so it reads as a clean mark, not a white box. */
  mix-blend-mode: multiply;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 34px;
  line-height: 1.05;
}

h2 {
  margin-bottom: 10px;
  font-size: 16px;
}

.muted {
  color: var(--muted);
  line-height: 1.45;
}

.status-strip {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
  color: var(--muted);
  font-size: 13px;
}

.status-dot,
#mappingCount,
#durationBadge {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border-radius: 999px;
  padding: 0 10px;
  background: #ffffff;
  border: 1px solid var(--line);
}

/* Top-bar scan progress: the pill doubles as a progress bar so the fill level
   reads from across a conference booth, not just up close. */
#durationBadge {
  position: relative;
  justify-content: center;
  overflow: hidden;
  min-width: 240px;
  min-height: 34px;
  padding: 0;
  font-weight: 700;
  font-size: 14px;
  color: var(--ink);
}

.duration-fill {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 0%;
  background: rgba(15, 139, 76, 0.28);
  transition: width 240ms ease;
}

#durationBadge.is-done .duration-fill {
  background: rgba(15, 139, 76, 0.45);
}

#durationBadge.is-failed .duration-fill {
  background: rgba(176, 0, 32, 0.3);
}

#durationBadge.is-done {
  border-color: var(--accent);
}

.duration-label {
  position: relative;
  padding: 0 16px;
  white-space: nowrap;
}

.status-dot::before {
  content: "";
  width: 8px;
  height: 8px;
  margin-right: 7px;
  border-radius: 50%;
  background: var(--warn);
}

.status-dot.online::before {
  background: var(--accent);
}

.status-dot.problem::before {
  background: #d14343;
}

.workspace {
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.control-panel,
.results-panel,
.analysis-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.control-panel {
  border-radius: 8px;
  overflow: hidden;
}

.panel-section {
  padding: 18px;
  border-bottom: 1px solid var(--line);
}

.panel-section:last-child {
  border-bottom: 0;
}

.upload-zone {
  display: grid;
  place-items: center;
  min-height: 158px;
  margin: 16px 0 12px;
  padding: 18px;
  text-align: center;
  background:
    linear-gradient(#ffffff, #ffffff) padding-box,
    repeating-linear-gradient(135deg, #89a4c7 0 10px, #d7e4f2 10px 20px) border-box;
  border: 2px dashed #89a4c7;
}

.upload-zone.dragging {
  border-color: var(--accent);
  background: #f1fbf5;
}

.upload-zone input {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.upload-title {
  display: block;
  font-weight: 800;
}

.upload-subtitle {
  display: block;
  max-width: 240px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.button-row {
  display: grid;
  grid-template-columns: 1fr 84px;
  gap: 10px;
}

.phone-link {
  display: grid;
  justify-items: start;
}

.qr-code {
  width: 132px;
  height: 132px;
  padding: 8px;
  border: 1px solid var(--line);
  background: #ffffff;
}

.phone-link a {
  display: inline-block;
  max-width: 100%;
  margin-top: 10px;
  color: var(--blue);
  font-weight: 700;
  overflow-wrap: anywhere;
}

.results-panel {
  min-width: 0;
  border-radius: 8px;
  padding: 18px;
}

.image-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

figure {
  min-width: 0;
  margin: 0;
}

figcaption {
  display: flex;
  align-items: center;
  min-height: 32px;
  padding: 0 2px;
  font-weight: 800;
}

.image-stage {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 420px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #eef1f5;
}

.image-stage img {
  display: none;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #f8fafc;
}

.image-stage.has-image img {
  display: block;
}

.image-stage.has-image .empty-state {
  display: none;
}

.empty-state,
.empty-table {
  color: var(--muted);
  text-align: center;
}

.analysis-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
  margin-top: 14px;
}

.analysis-panel {
  min-width: 0;
  border-radius: 8px;
  box-shadow: none;
  overflow: hidden;
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 52px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}

.section-heading h2 {
  margin-bottom: 0;
}

.table-wrap {
  max-height: 320px;
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

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

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f8fafc;
  color: #475569;
  font-size: 12px;
}

td {
  overflow-wrap: anywhere;
}

td:last-child {
  white-space: nowrap;
}

.type-pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  background: #e9f7ef;
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 800;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: min(420px, calc(100vw - 36px));
  padding: 12px 14px;
  border-radius: 8px;
  background: var(--ink);
  color: #ffffff;
  box-shadow: var(--shadow);
  transform: translateY(140%);
  transition: transform 160ms ease;
}

.toast:empty {
  display: none;
}

.toast.visible {
  display: block;
  transform: translateY(0);
}

body.capture-mode .phone-link {
  display: none;
}

body.capture-mode .control-panel {
  overflow: hidden;
}

body.capture-mode .panel-section {
  border-right: 0;
  border-bottom: 0;
}

/* Feature 1 — PII overlay on the original image */
.box-overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  display: none;
}

.image-stage.has-image .box-overlay {
  display: block;
}

.image-stage.boxes-off .box-overlay {
  display: none;
}

.box-overlay rect {
  pointer-events: visiblePainted;
  fill: currentColor;
  fill-opacity: 0;
  transition: fill-opacity 90ms ease;
}

.box-overlay rect.is-hover,
.box-overlay rect.is-active {
  fill-opacity: 0.12;
}

.box-tooltip {
  position: fixed;
  z-index: 30;
  max-width: 240px;
  padding: 6px 9px;
  border-radius: 8px;
  background: var(--ink);
  color: #ffffff;
  font-size: 12px;
  line-height: 1.35;
  box-shadow: var(--shadow);
  pointer-events: none;
  opacity: 0;
  transform: translateY(2px);
  transition: opacity 90ms ease;
}

.box-tooltip.visible {
  opacity: 1;
  transform: translateY(0);
}

.box-tooltip .tt-sub {
  color: #9fb3cd;
  font-size: 11px;
}

/* Quiet toolbar inside the original stage */
.stage-toolbar {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 5;
  display: none;
  align-items: center;
  gap: 8px;
  padding: 4px 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.86);
  border: 1px solid var(--line);
  backdrop-filter: blur(2px);
}

.image-stage.has-image .stage-toolbar {
  display: inline-flex;
}

.stage-toggle {
  min-height: 24px;
  padding: 0 10px;
  border-radius: 999px;
  background: #eef2f7;
  color: var(--muted);
  border: 1px solid transparent;
  font-size: 12px;
  font-weight: 700;
}

.stage-toggle.is-on {
  background: #e9f7ef;
  color: var(--accent-dark);
}

.stage-legend {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding-right: 3px;
}

.stage-legend .swatch {
  width: 10px;
  height: 10px;
  border-radius: 3px;
}

.swatch-text {
  background: var(--accent);
}

.swatch-pos {
  background: var(--blue);
}

.swatch-fallback {
  background: var(--warn);
}

/* Feature 2 — Leak-guard QA strip */
.qa-strip {
  padding: 8px 14px;
  border-bottom: 1px solid var(--line);
  background: #fbfcfe;
  font-size: 13px;
}

.qa-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.qa-leak {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.qa-leak::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
}

.qa-leak.is-clean {
  color: var(--accent-dark);
}

.qa-leak.is-clean::before {
  background: var(--accent);
}

.qa-leak.is-warn {
  color: var(--warn);
}

.qa-leak.is-warn::before {
  background: var(--warn);
}

.qa-leak .qa-sub {
  color: var(--muted);
  font-weight: 400;
}

.qa-box-toggle {
  min-height: 24px;
  padding: 0 9px;
  border-radius: 999px;
  background: #eef2f7;
  color: var(--muted);
  border: 1px solid var(--line);
  font-size: 12px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.qa-box-toggle.has-warn {
  background: #fff4e2;
  color: var(--warn);
  border-color: #f0dcbb;
}

.qa-caret {
  font-size: 9px;
  transition: transform 120ms ease;
}

.qa-box-toggle[aria-expanded="true"] .qa-caret {
  transform: rotate(90deg);
}

.qa-warnings {
  list-style: none;
  margin: 8px 0 2px;
  padding: 0;
  display: grid;
  gap: 7px;
}

.qa-warnings li {
  display: grid;
  grid-template-columns: 12px 1fr;
  gap: 8px;
  align-items: start;
  font-size: 12px;
  line-height: 1.4;
}

.qa-warnings li.is-linked {
  cursor: pointer;
}

.qa-warnings li.is-linked:hover .qa-code {
  text-decoration: underline;
}

.qa-sev {
  width: 8px;
  height: 8px;
  margin-top: 4px;
  border-radius: 50%;
  background: var(--warn);
}

.qa-sev.is-error {
  background: #b00020;
}

.qa-code {
  font-weight: 700;
  color: var(--ink);
}

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

/* Feature 3 — Segmented view switch + identity graph */
.view-switch {
  display: inline-flex;
  gap: 4px;
  margin-top: 14px;
  padding: 4px;
  border-radius: 999px;
  background: #eef2f7;
  border: 1px solid var(--line);
}

.view-pill {
  min-height: 32px;
  padding: 0 16px;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  border: 1px solid transparent;
  font-size: 13px;
  font-weight: 700;
}

.view-pill.is-active {
  background: var(--panel);
  color: var(--ink);
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.12);
}

.analysis-view {
  margin-top: 14px;
}

.analysis-view[hidden] {
  display: none;
}

.graph-panel .section-heading {
  border-bottom: 1px solid var(--line);
}

.graph-grid {
  display: grid;
  grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.2fr) minmax(0, 0.9fr);
  gap: 1px;
  background: var(--line);
}

.graph-list,
.graph-canvas,
.graph-details {
  background: var(--panel);
  min-height: 320px;
  padding: 12px;
}

.graph-list {
  max-height: 380px;
  overflow: auto;
}

.graph-list-summary {
  margin: 0 0 10px;
  font-size: 12px;
  color: var(--muted);
}

.cluster-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 8px;
  width: 100%;
  margin-bottom: 6px;
  padding: 8px 10px;
  text-align: left;
  border-radius: 8px;
  background: #f8fafc;
  border: 1px solid var(--line);
  color: var(--ink);
  font-weight: 400;
}

.cluster-row:hover {
  border-color: #c4d0e0;
}

.cluster-row.is-selected {
  background: #e9f7ef;
  border-color: var(--accent);
}

.cluster-chip {
  display: inline-flex;
  align-items: center;
  min-height: 20px;
  padding: 0 7px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 800;
  background: #e9f7ef;
  color: var(--accent-dark);
}

.cluster-chip.is-location {
  background: #e7eefb;
  color: var(--blue);
}

.cluster-main {
  min-width: 0;
}

.cluster-surrogate {
  font-weight: 800;
  overflow-wrap: anywhere;
}

.cluster-primary {
  display: block;
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.cluster-count {
  display: inline-flex;
  align-items: center;
  min-height: 20px;
  padding: 0 7px;
  border-radius: 999px;
  background: #eef2f7;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.graph-canvas {
  position: relative;
  display: grid;
  place-items: center;
}

.graph-svg {
  width: 100%;
  height: 100%;
  min-height: 300px;
}

.graph-svg .gnode-label {
  font-size: 11px;
  font-weight: 700;
  font-family: Inter, ui-sans-serif, system-ui, sans-serif;
}

.graph-svg .gedge {
  stroke: var(--line);
  stroke-width: 1.5;
}

.graph-fade {
  animation: graphFade 180ms ease;
}

@keyframes graphFade {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.graph-details {
  font-size: 13px;
}

.graph-details .gd-surrogate {
  font-size: 15px;
  font-weight: 800;
  overflow-wrap: anywhere;
}

.graph-details .gd-meta {
  margin: 4px 0 12px;
  color: var(--muted);
  font-size: 12px;
}

.graph-details table {
  font-size: 12px;
}

.graph-details .gd-address {
  margin-top: 12px;
  padding: 8px 10px;
  border-radius: 8px;
  background: #f8fafc;
  border: 1px solid var(--line);
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 12px;
  line-height: 1.5;
  white-space: pre-wrap;
}

.role-tag {
  display: inline-flex;
  align-items: center;
  min-height: 20px;
  padding: 0 7px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  background: #eef2f7;
  color: var(--muted);
}

.role-tag.is-primary {
  background: #e9f7ef;
  color: var(--accent-dark);
}

.role-tag.is-alias {
  background: #e7eefb;
  color: var(--blue);
}

.graph-empty {
  padding: 18px 4px;
}

@media (max-width: 1050px) {
  .workspace,
  .analysis-row {
    grid-template-columns: 1fr;
  }

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

  .control-panel {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

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

  .panel-section:last-child {
    border-right: 0;
  }
}

@media (max-width: 760px) {
  .app-shell {
    width: min(100vw - 20px, 720px);
    padding-top: 12px;
  }

  .topbar,
  .status-strip {
    align-items: flex-start;
    justify-content: flex-start;
  }

  .topbar {
    flex-direction: column;
  }

  h1 {
    font-size: 28px;
  }

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

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

  .image-stage {
    min-height: 310px;
  }
}
