*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --font-mono: "SF Mono", "Fira Code", "Consolas", monospace;

  --bg: #ffffff;
  --surface: #fafafa;
  --border: #e5e5e5;
  --border-strong: #d0d0d0;

  --text-primary: #111111;
  --text-secondary: #555555;
  --text-muted: #888888;

  --accent: #5c6bc0;
  --accent-light: #ede7f6;

  --badge-confirmed-bg: #e8f5e9;
  --badge-confirmed-text: #2e7d32;
  --badge-possible-bg: #fff8e1;
  --badge-possible-text: #f57f17;
  --badge-ruled-out-bg: #fce4ec;
  --badge-ruled-out-text: #c62828;
  --badge-prn-bg: #e3f2fd;
  --badge-prn-text: #1565c0;
  --badge-conf-high-bg: #e8f5e9;
  --badge-conf-high-text: #2e7d32;
  --badge-conf-med-bg: #fff8e1;
  --badge-conf-med-text: #f57f17;
  --badge-conf-low-bg: #fce4ec;
  --badge-conf-low-text: #c62828;

  --radius: 6px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
}

html, body {
  height: 100%;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ── Header ─────────────────────────────────────────────── */

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 32px;
  height: 56px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  font-size: 15px;
  color: var(--text-primary);
  text-decoration: none;
}

.header-logo-mark {
  width: 26px;
  height: 26px;
  background: var(--text-primary);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: -0.5px;
}

.header-badge {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 100px;
  padding: 2px 10px;
}

/* ── Layout ─────────────────────────────────────────────── */

.workspace {
  display: grid;
  grid-template-columns: 1fr 1fr;
  height: calc(100vh - 56px);
  overflow: hidden;
}

.panel {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.panel-left {
  border-right: 1px solid var(--border);
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.panel-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
}

/* ── Note textarea ──────────────────────────────────────── */

.note-wrapper {
  height: 100%;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.note-textarea {
  flex: 1;
  width: 100%;
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.7;
  color: var(--text-primary);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  resize: none;
  outline: none;
  transition: border-color 0.15s;
}

.note-textarea:focus {
  border-color: var(--accent);
  background: var(--bg);
}

.highlighted-span {
  background: #fff3cd;
}

.note-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.btn-extract {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 20px;
  background: var(--text-primary);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-family: var(--font);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
}

.btn-extract:hover {
  opacity: 0.88;
}

.btn-extract:active {
  transform: scale(0.98);
}

.btn-extract:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

.btn-extract .spinner {
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: none;
}

.btn-extract.loading .spinner {
  display: block;
}

.btn-extract.loading .btn-label {
  opacity: 0.8;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.extract-meta {
  font-size: 12px;
  color: var(--text-muted);
}

/* ── Right panel ────────────────────────────────────────── */

.panel-right {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.results-area {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.section {
  border-bottom: 1px solid var(--border);
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  cursor: pointer;
  user-select: none;
}

.section-header:hover {
  background: var(--surface);
}

.section-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  display: flex;
  align-items: center;
  gap: 8px;
}

.count-pill {
  font-size: 11px;
  font-weight: 500;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 100px;
  padding: 1px 8px;
  letter-spacing: 0;
  text-transform: none;
}

.section-toggle {
  font-size: 12px;
  color: var(--text-muted);
  transition: transform 0.2s;
}

.section.collapsed .section-toggle {
  transform: rotate(-90deg);
}

.section-body {
  overflow: hidden;
}

.section.collapsed .section-body {
  display: none;
}

/* ── Tables ─────────────────────────────────────────────── */

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
}

.data-table th {
  text-align: left;
  padding: 8px 16px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.data-table td {
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  color: var(--text-primary);
  vertical-align: middle;
}

.data-table tbody tr {
  cursor: pointer;
  transition: background 0.1s;
}

.data-table tbody tr:hover {
  background: #f5f5f5;
}

.data-table tbody tr.selected {
  background: var(--accent-light);
}

.data-table tbody tr:last-child td {
  border-bottom: none;
}

.empty-state {
  padding: 32px 24px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
}

/* ── Badges ─────────────────────────────────────────────── */

.badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 500;
  padding: 2px 8px;
  border-radius: 100px;
  white-space: nowrap;
}

.badge-confirmed {
  background: var(--badge-confirmed-bg);
  color: var(--badge-confirmed-text);
}

.badge-possible, .badge-suspected {
  background: var(--badge-possible-bg);
  color: var(--badge-possible-text);
}

.badge-ruled-out, .badge-historical {
  background: var(--badge-ruled-out-bg);
  color: var(--badge-ruled-out-text);
}

.badge-prn {
  background: var(--badge-prn-bg);
  color: var(--badge-prn-text);
}

.badge-neutral {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-muted);
}

/* Per-field confidence — extraction-quality signal (ADR-0011), not a
   clinical-correctness probability. */
.badge-conf-high {
  background: var(--badge-conf-high-bg);
  color: var(--badge-conf-high-text);
}

.badge-conf-med {
  background: var(--badge-conf-med-bg);
  color: var(--badge-conf-med-text);
}

.badge-conf-low {
  background: var(--badge-conf-low-bg);
  color: var(--badge-conf-low-text);
}

.review-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #ef6c00;
  margin-right: 4px;
  vertical-align: middle;
}

/* ── Graph section ──────────────────────────────────────── */

.graph-section {
  flex: 1;
  min-height: 280px;
  display: flex;
  flex-direction: column;
}

.graph-section .section-body {
  flex: 1;
  display: flex;
  flex-direction: column;
}

#graph-container {
  flex: 1;
  min-height: 240px;
  position: relative;
}

.graph-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 13px;
  gap: 8px;
  pointer-events: none;
}

.graph-placeholder-icon {
  font-size: 28px;
  opacity: 0.3;
}

/* ── Error banner ───────────────────────────────────────── */

.error-banner {
  margin: 16px 24px;
  padding: 12px 16px;
  background: #fff3f3;
  border: 1px solid #f5c6cb;
  border-radius: var(--radius);
  font-size: 13px;
  color: #c62828;
  display: none;
}

.error-banner.visible {
  display: block;
}

/* ── Scrollbars ─────────────────────────────────────────── */

::-webkit-scrollbar {
  width: 5px;
  height: 5px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 10px;
}
