:root {
  color-scheme: light;
  --bg: #f2efe7;
  --bg-accent: #dce7d2;
  --panel: rgba(255, 255, 255, 0.8);
  --text: #172018;
  --muted: #5d6a61;
  --accent: #2f6b44;
  --accent-strong: #1f4e31;
  --border: rgba(23, 32, 24, 0.12);
  --shadow: 0 18px 50px rgba(23, 32, 24, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Manrope", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(220, 231, 210, 0.95), transparent 42%),
    radial-gradient(circle at right 20%, rgba(196, 216, 188, 0.55), transparent 28%),
    linear-gradient(180deg, var(--bg), #fbfaf6 70%);
  min-height: 100vh;
}

.shell {
  width: min(1100px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 48px 0 56px;
}

.hero {
  max-width: 720px;
  margin-bottom: 24px;
}

.eyebrow {
  margin: 0 0 12px;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-size: 0.78rem;
  color: var(--accent-strong);
}

h1,
h2 {
  margin: 0;
  font-family: "Fraunces", serif;
  line-height: 1.04;
}

h1 {
  font-size: clamp(2.8rem, 7vw, 5.5rem);
  max-width: 10ch;
}

.lede {
  max-width: 60ch;
  margin: 18px 0 0;
  font-size: 1.05rem;
  color: var(--muted);
}

/* ── Stats bar (E3) ────────────────────────────────────────────── */
.stats-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 0;
  margin-bottom: 16px;
  padding: 10px 18px;
  border-radius: 99px;
  background: rgba(47, 107, 68, 0.09);
  border: 1px solid rgba(47, 107, 68, 0.18);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--accent-strong);
}

.stats-bar[hidden] {
  display: none;
}

.stats-sep {
  margin: 0 8px;
  color: rgba(47, 107, 68, 0.35);
}

.stats-item span {
  font-weight: 700;
}

/* ── Tabs ───────────────────────────────────────────────────────── */
.tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.tab-btn {
  font: inherit;
  font-weight: 700;
  padding: 10px 18px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.6);
  color: var(--muted);
  cursor: pointer;
}

.tab-btn[aria-selected="true"] {
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  color: white;
  border-color: transparent;
}

.tab-panel[data-active="false"] {
  display: none;
}

.demo-warning {
  margin: 0 0 16px;
  padding: 14px 18px;
  border-radius: 16px;
  background: rgba(165, 120, 20, 0.1);
  border: 1px solid rgba(165, 120, 20, 0.25);
  color: #6b4d10;
  font-size: 0.92rem;
  line-height: 1.5;
}

.panel-note {
  margin: -6px 0 14px;
  font-size: 0.88rem;
}

/* ── Panel + controls ──────────────────────────────────────────── */
.panel {
  background: var(--panel);
  backdrop-filter: blur(18px);
  border: 1px solid var(--border);
  border-radius: 24px;
  box-shadow: var(--shadow);
}

.controls {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
  padding: 18px;
  align-items: end;
}

label {
  display: grid;
  gap: 8px;
  font-weight: 700;
}

/* E1: IoT toggle styling — spans full width on its own row */
.toggle-label {
  display: flex;
  align-items: center;
  gap: 10px;
  grid-column: 1 / -1;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
}

.toggle-label input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
  cursor: pointer;
  flex-shrink: 0;
}

select,
input[type="number"],
button {
  font: inherit;
  border-radius: 16px;
  border: 1px solid var(--border);
  min-height: 48px;
}

select,
input[type="number"] {
  padding: 0 14px;
  background: #fff;
}

.sensor-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.sensor-grid button {
  grid-column: 1 / -1;
}

button {
  padding: 0 18px;
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  color: white;
  font-weight: 700;
  cursor: pointer;
}

/* ── Results panel ─────────────────────────────────────────────── */
.results {
  margin-top: 18px;
  padding: 22px;
}

.results-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 32px;
  padding: 0 12px;
  border-radius: 999px;
  background: rgba(47, 107, 68, 0.12);
  color: var(--accent-strong);
  font-size: 0.92rem;
  font-weight: 700;
}

.status-pill[data-state="loading"]::before {
  content: "";
  width: 12px;
  height: 12px;
  border-radius: 999px;
  border: 2px solid rgba(31, 78, 49, 0.25);
  border-top-color: var(--accent-strong);
  animation: spin 0.8s linear infinite;
}

.status-pill[data-state="error"] {
  background: rgba(165, 60, 49, 0.12);
  color: #8f2e26;
}

.edge-list {
  display: grid;
  gap: 14px;
}

.results[data-state="loading"] .edge-list::before {
  content: "Loading results...";
  display: block;
  padding: 18px;
  border-radius: 18px;
  border: 1px dashed rgba(23, 32, 24, 0.16);
  color: var(--muted);
  background: rgba(255, 255, 255, 0.55);
}

/* ── Edge cards (E2: pathogen + source) ────────────────────────── */
.edge-card {
  padding: 16px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid rgba(23, 32, 24, 0.08);
}

.edge-card-error {
  border-color: rgba(165, 60, 49, 0.22);
  background: rgba(255, 245, 243, 0.9);
}

.edge-card-fired {
  border-color: rgba(31, 107, 68, 0.3);
  background: rgba(230, 244, 234, 0.85);
}

.condition-list {
  margin: 8px 0;
  padding-left: 20px;
  color: var(--muted);
  line-height: 1.6;
  font-size: 0.92rem;
}

.edge-card h3 {
  margin: 0 0 8px;
  font-size: 1.05rem;
}

.edge-meta {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

/* Confidence badge colouring */
.confidence-badge {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 6px;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.confidence-badge[data-level="Very High"] {
  background: rgba(31, 107, 68, 0.15);
  color: #1a5c3a;
}

.confidence-badge[data-level="High"] {
  background: rgba(47, 107, 68, 0.1);
  color: var(--accent-strong);
}

.confidence-badge[data-level="Medium"] {
  background: rgba(130, 100, 30, 0.12);
  color: #6b5310;
}

/* IoT badge */
.iot-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 0.78rem;
  font-weight: 700;
  background: rgba(30, 100, 160, 0.1);
  color: #1a4e7a;
}

/* Source citation */
.edge-source {
  margin: 6px 0 0;
  font-size: 0.82rem;
  color: var(--muted);
  font-style: italic;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ── Graph visualizer ──────────────────────────────────────────── */
.graph-controls {
  grid-template-columns: repeat(2, minmax(0, 1fr)) 2fr;
}

.graph-claim-types {
  font-weight: 700;
}

.graph-checkbox-group {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  font-weight: 500;
}

.graph-checkbox {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
}

.graph-checkbox input[type="checkbox"] {
  width: 15px;
  height: 15px;
  accent-color: var(--accent);
  cursor: pointer;
}

.graph-results {
  display: flex;
  flex-direction: column;
}

.graph-layout {
  display: flex;
  gap: 16px;
  align-items: flex-start;
}

.graph-canvas-wrap {
  position: relative;
  flex: 1;
  min-width: 0;
  height: 560px;
  border-radius: 18px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.9);
  overflow: hidden;
}

.graph-canvas {
  position: absolute;
  inset: 0;
}

.graph-zoom-controls {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 5;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.graph-zoom-controls button {
  width: 32px;
  height: 32px;
  min-height: 32px;
  padding: 0;
  border-radius: 8px;
  font-size: 1.05rem;
  font-weight: 700;
  line-height: 1;
  background: rgba(255, 255, 255, 0.95);
  color: var(--accent-strong);
  box-shadow: 0 4px 10px rgba(23, 32, 24, 0.14);
}

.graph-zoom-controls button:hover {
  background: #fff;
}

.graph-tooltip {
  position: absolute;
  z-index: 6;
  pointer-events: none;
  max-width: 240px;
  padding: 6px 10px;
  border-radius: 8px;
  background: rgba(23, 32, 24, 0.92);
  color: #fff;
  font-size: 0.78rem;
  line-height: 1.4;
  transform: translate(-50%, calc(-100% - 10px));
}

.graph-tooltip[hidden] {
  display: none;
}

.graph-legend {
  width: 160px;
  flex-shrink: 0;
  display: grid;
  gap: 8px;
  padding: 14px;
  border-radius: 18px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.72);
  align-self: stretch;
}

.graph-legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.82rem;
  color: var(--muted);
}

.graph-legend-swatch {
  width: 12px;
  height: 12px;
  border-radius: 999px;
  flex-shrink: 0;
}

.graph-detail {
  margin-top: 14px;
  padding: 16px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid rgba(23, 32, 24, 0.08);
}

.graph-detail[hidden] {
  display: none;
}

.graph-detail h3 {
  margin: 0 0 8px;
  font-size: 1.05rem;
}

@media (max-width: 820px) {
  .controls,
  .sensor-grid,
  .graph-controls {
    grid-template-columns: 1fr;
  }

  .stats-bar {
    border-radius: 16px;
  }

  .tabs {
    flex-wrap: wrap;
  }

  .graph-layout {
    flex-direction: column;
  }

  .graph-legend {
    width: 100%;
    flex-direction: row;
    flex-wrap: wrap;
  }

  .graph-canvas-wrap {
    flex: none;
    width: 100%;
    height: 420px;
  }
}
