/* ─── Design tokens ────────────────────────────────────── */
:root {
  --bg:          #0d1117;
  --bg-sidebar:  #141923;
  --bg-panel:    #161e2b;
  --bg-card:     #1c2638;
  --bg-hover:    #212d42;
  --bg-active:   #1b3a5c;
  --accent:      #4db8ff;
  --accent-dim:  #2575a0;
  --accent-glow: rgba(77,184,255,.12);
  --border:      #253040;
  --border-dim:  #1a2535;
  --txt1:        #dde4f0;
  --txt2:        #8aa0bc;
  --txt3:        #4d6080;
  --danger:      #f06060;
  --warn:        #f5a623;
  --ok:          #56c26e;
  --r:           7px;
  --r-lg:        12px;
  --sans:        -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --mono:        "Cascadia Code", "JetBrains Mono", "Fira Code", monospace;
  --ease:        150ms ease;
}

/* ─── Reset & base ─────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--txt1);
  height: 100dvh;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ─── App shell ────────────────────────────────────────── */
.app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
}

/* ─── Header ───────────────────────────────────────────── */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  height: 52px;
  background: var(--bg-sidebar);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  z-index: 20;
}
.brand { display: flex; align-items: center; gap: 11px; }
.brand-icon { width: 26px; height: 26px; color: var(--accent); flex-shrink: 0; }
.brand-text { display: flex; flex-direction: column; gap: 1px; }
.brand-name { font-size: 14px; font-weight: 700; letter-spacing: .01em; color: var(--txt1); }
.brand-sub  { font-size: 10.5px; color: var(--txt3); letter-spacing: .03em; }
.slide-badge {
  font-size: 11px; color: var(--txt3);
  background: var(--bg-card); border: 1px solid var(--border);
  padding: 3px 10px; border-radius: 20px;
}

/* ─── Main 3-col grid ──────────────────────────────────── */
.layout {
  display: grid;
  grid-template-columns: 256px 1fr 296px;
  flex: 1;
  overflow: hidden;
  min-height: 0;
}

/* ─── Sidebar ──────────────────────────────────────────── */
.sidebar {
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.search-wrap {
  position: relative;
  padding: 10px;
  border-bottom: 1px solid var(--border-dim);
  flex-shrink: 0;
}
.search-icon {
  position: absolute; left: 21px; top: 50%; transform: translateY(-50%);
  width: 14px; height: 14px; color: var(--txt3); pointer-events: none;
}
#searchInput {
  width: 100%;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 6px 10px 6px 32px;
  color: var(--txt1);
  font-size: 12.5px;
  outline: none;
  transition: border-color var(--ease);
}
#searchInput:focus { border-color: var(--accent-dim); }
#searchInput::placeholder { color: var(--txt3); }

.disease-nav {
  overflow-y: auto;
  flex: 1;
  padding: 6px 0 12px;
}
.disease-nav::-webkit-scrollbar { width: 3px; }
.disease-nav::-webkit-scrollbar-track { background: transparent; }
.disease-nav::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* Category groups */
.cat-group { margin-bottom: 2px; }

.cat-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 14px;
  cursor: pointer; user-select: none;
  font-size: 9.5px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase;
  color: var(--txt3);
  transition: color var(--ease);
}
.cat-header:hover { color: var(--txt2); }
.cat-header .cat-count {
  background: var(--bg-card); border-radius: 10px;
  padding: 1px 6px; font-size: 9.5px; color: var(--txt3);
}
.cat-chevron { font-size: 7px; transition: transform var(--ease); line-height: 1; }
.cat-group.collapsed .cat-chevron { transform: rotate(-90deg); }
.cat-group.collapsed .cat-diseases { display: none; }

/* Disease items */
.disease-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 14px 6px 22px;
  cursor: pointer;
  font-size: 12.5px; color: var(--txt2);
  border-left: 2px solid transparent;
  transition: background var(--ease), color var(--ease);
  gap: 8px;
}
.disease-item:hover { background: var(--bg-hover); color: var(--txt1); }
.disease-item.active {
  background: var(--bg-active);
  color: var(--accent);
  border-left-color: var(--accent);
}
.disease-item .d-name { flex: 1; line-height: 1.35; }
.grade-dot {
  width: 6px; height: 6px; border-radius: 50%; flex-shrink: 0;
}
.grade-dot.g1 { background: #4caf50; }
.grade-dot.g2 { background: #ffc107; }
.grade-dot.g3 { background: #ff9800; }
.grade-dot.g4 { background: #f44336; }
.grade-dot.gx { background: var(--txt3); }

.no-results {
  padding: 24px 16px; text-align: center;
  color: var(--txt3); font-size: 12px; line-height: 1.6;
}

/* ─── Viewer ────────────────────────────────────────────── */
.viewer {
  display: flex; flex-direction: column; overflow: hidden;
  background: var(--bg);
}

.viewer-header {
  padding: 14px 18px 10px;
  border-bottom: 1px solid var(--border-dim);
  flex-shrink: 0;
}
.viewer-titlerow {
  display: flex; align-items: flex-start;
  justify-content: space-between; margin-bottom: 10px;
}
.viewer-disease { font-size: 16px; font-weight: 600; color: var(--txt1); line-height: 1.2; }
.viewer-cat {
  display: block; margin-top: 3px;
  font-size: 10px; color: var(--txt3);
  text-transform: uppercase; letter-spacing: .07em;
}

/* WHO grade badge */
.who-badge {
  font-size: 11px; font-weight: 700; letter-spacing: .04em;
  padding: 3px 10px; border-radius: 20px; flex-shrink: 0; margin-left: 12px;
}
.who-badge.g1 { background: rgba(76,175,80,.15); color: #4caf50; border: 1px solid rgba(76,175,80,.3); }
.who-badge.g2 { background: rgba(255,193,7,.15); color: #ffc107; border: 1px solid rgba(255,193,7,.3); }
.who-badge.g3 { background: rgba(255,152,0,.15); color: #ff9800; border: 1px solid rgba(255,152,0,.3); }
.who-badge.g4 { background: rgba(244,67,54,.15); color: #f44336; border: 1px solid rgba(244,67,54,.3); }

/* Stain tabs */
.stain-tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.stain-tab {
  padding: 3px 11px; border-radius: 20px;
  font-size: 11px; font-weight: 600; letter-spacing: .02em;
  cursor: pointer;
  background: var(--bg-card); border: 1px solid var(--border);
  color: var(--txt3); transition: all var(--ease);
}
.stain-tab:hover { border-color: var(--accent-dim); color: var(--txt2); }
.stain-tab.active {
  background: var(--accent-glow);
  border-color: var(--accent-dim);
  color: var(--accent);
}

/* Canvas area */
.canvas-area {
  position: relative; flex: 1; min-height: 0;
  display: flex; align-items: center; justify-content: center;
  background: #08090e;
  cursor: grab;
  overflow: hidden;
}
.canvas-area.dragging { cursor: grabbing; }
#slideCanvas {
  display: block;
  image-rendering: crisp-edges;
  max-width: 100%; max-height: 100%;
  border-radius: 4px;
}
.canvas-empty {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 14px;
  background: #08090e; color: var(--txt3);
  z-index: 3;
}
.canvas-empty p { font-size: 13px; text-align: center; line-height: 1.6; max-width: 220px; }

/* Viewer controls toolbar */
.viewer-controls {
  display: flex; align-items: center; justify-content: space-between;
  padding: 7px 14px;
  background: var(--bg-sidebar);
  border-top: 1px solid var(--border-dim);
  flex-shrink: 0;
}
.ctrl-group { display: flex; align-items: center; gap: 5px; }
.ctrl-btn {
  width: 28px; height: 28px;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--r); color: var(--txt2);
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  font-size: 15px; transition: all var(--ease);
}
.ctrl-btn:hover { border-color: var(--accent-dim); color: var(--accent); background: var(--bg-hover); }
.zoom-readout {
  font-size: 11.5px; color: var(--txt3); min-width: 38px;
  font-variant-numeric: tabular-nums; font-family: var(--mono);
}
.fov-toggle { display: flex; align-items: center; gap: 6px; cursor: pointer; }
.fov-toggle input { cursor: pointer; accent-color: var(--accent); }
.fov-toggle span { font-size: 11px; color: var(--txt3); }
.mag-chip {
  font-size: 11px; color: var(--txt3);
  background: var(--bg-card); border: 1px solid var(--border);
  padding: 2px 8px; border-radius: var(--r);
  font-family: var(--mono);
}

/* ─── Info Panel ────────────────────────────────────────── */
.info-panel {
  background: var(--bg-panel);
  border-left: 1px solid var(--border);
  overflow-y: auto; overflow-x: hidden;
}
.info-panel::-webkit-scrollbar { width: 3px; }
.info-panel::-webkit-scrollbar-track { background: transparent; }
.info-panel::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.info-empty {
  display: flex; align-items: center; justify-content: center;
  height: 100%; color: var(--txt3); font-size: 12.5px;
  text-align: center; padding: 24px; line-height: 1.6;
}

/* Info tabs */
.info-tabs {
  position: sticky;
  top: 0;
  z-index: 2;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  padding: 10px 12px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border-dim);
}
.info-tab {
  height: 28px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--r);
  color: var(--txt3);
  cursor: pointer;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .03em;
  text-transform: uppercase;
  transition: all var(--ease);
}
.info-tab:hover {
  border-color: var(--accent-dim);
  color: var(--txt2);
}
.info-tab.active {
  background: var(--accent-glow);
  border-color: var(--accent-dim);
  color: var(--accent);
}

/* Info sections */
.info-section {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border-dim);
  animation: fadeUp 180ms ease forwards;
}
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

.info-section-head {
  font-size: 9.5px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .1em; color: var(--txt3);
  margin-bottom: 9px;
  display: flex; align-items: center; gap: 5px;
}
.info-icon { font-size: 11px; }

/* Feature list */
.feat-list { list-style: none; display: flex; flex-direction: column; gap: 3px; }
.feat-list li {
  font-size: 12px; color: var(--txt2); line-height: 1.45;
  padding-left: 14px; position: relative;
}
.feat-list li::before {
  content: '';
  position: absolute; left: 0; top: 7px;
  width: 5px; height: 5px;
  background: var(--accent-dim); border-radius: 50%;
}

/* Stain table */
.stain-table { display: flex; flex-direction: column; gap: 5px; }
.stain-row { display: flex; align-items: flex-start; gap: 8px; }
.stain-label {
  font-size: 11px; font-weight: 600; color: var(--accent);
  min-width: 82px; flex-shrink: 0;
  padding-top: 1px; font-family: var(--mono);
}
.stain-result { font-size: 11.5px; color: var(--txt2); line-height: 1.4; }

/* Pearls */
.pearl-list { display: flex; flex-direction: column; gap: 6px; }
.pearl-item {
  font-size: 11.5px; color: var(--txt2); line-height: 1.45;
  background: rgba(77,184,255,.05);
  border-left: 2px solid var(--accent-dim);
  padding: 5px 9px;
  border-radius: 0 var(--r) var(--r) 0;
}

/* DDx tags */
.ddx-row { display: flex; flex-wrap: wrap; gap: 5px; }
.ddx-tag {
  font-size: 11px; color: var(--txt2);
  background: var(--bg-card); border: 1px solid var(--border);
  padding: 3px 9px; border-radius: 20px;
}

/* Audit tab */
.audit-card {
  display: flex;
  flex-direction: column;
  gap: 9px;
}
.audit-source {
  color: var(--txt3);
  font-size: 11px;
  line-height: 1.45;
  background: rgba(255,255,255,.025);
  border: 1px solid var(--border-dim);
  border-radius: var(--r);
  padding: 7px 8px;
}
.audit-status {
  align-self: flex-start;
  border-radius: 20px;
  border: 1px solid var(--border);
  font-size: 10.5px;
  font-weight: 800;
  letter-spacing: .06em;
  line-height: 1;
  padding: 5px 9px;
  text-transform: uppercase;
}
.audit-status.ok {
  background: rgba(86,194,110,.12);
  border-color: rgba(86,194,110,.35);
  color: var(--ok);
}
.audit-status.needs {
  background: rgba(245,166,35,.13);
  border-color: rgba(245,166,35,.35);
  color: var(--warn);
}
.audit-status.review {
  background: rgba(77,184,255,.1);
  border-color: rgba(77,184,255,.28);
  color: var(--accent);
}
.audit-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 7px;
}
.audit-list li {
  position: relative;
  padding-left: 15px;
  color: var(--txt2);
  font-size: 11.5px;
  line-height: 1.45;
}
.audit-list li::before {
  content: '';
  position: absolute;
  left: 0;
  top: 7px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--warn);
}
.audit-refs {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 4px;
  padding-top: 10px;
  border-top: 1px solid var(--border-dim);
}
.audit-refs-title {
  color: var(--txt3);
  font-size: 9.5px;
  font-weight: 800;
  letter-spacing: .1em;
  text-transform: uppercase;
}
.audit-ref {
  color: var(--accent);
  font-size: 11px;
  line-height: 1.35;
  text-decoration: none;
}
.audit-ref:hover {
  color: var(--txt1);
  text-decoration: underline;
}

/* Search highlight */
mark.hl {
  background: rgba(77,184,255,.22);
  border-radius: 2px; color: inherit; padding: 0 1px;
}
