:root {
  --page: #0d0d0d;
  --surface: #1a1a19;
  --surface-raised: #212120;
  --panel: #17181c;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #898781;
  --gridline: #2c2c2a;
  --baseline: #383835;
  --border: rgba(255, 255, 255, 0.1);
  --blue: #3987e5;
  --serious: #ec835a;
  --critical: #d03b3b;
  --info-scale: 1;
  --tit-scale: 1;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--page);
  color: var(--text-primary);
  font-family: "Segoe UI", Inter, Arial, sans-serif;
  font-size: 13px;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* ---------------------------------------------------------------- tabs */
.tabbar {
  display: flex;
  padding: 0 18px;
  border-bottom: 1px solid transparent;
  flex-shrink: 0;
}

.tab-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  padding: 10px 18px;
  margin-right: 4px;
  font-size: 19px;
  font-weight: 400;
  font-family: inherit;
  border-bottom: 2px solid transparent;
  cursor: pointer;
}

.tab-btn:hover { color: var(--text-secondary); }

.tab-btn.active {
  color: var(--text-primary);
  border-bottom: 2px solid var(--blue);
}

.tab-page {
  display: none;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.tab-page.active { display: flex; }

/* -------------------------------------------------------------- generic */
.field-label {
  color: var(--text-muted);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 1px;
  display: block;
  margin-bottom: 4px;
}

.field-col { display: flex; flex-direction: column; }

select, .select-like {
  background-color: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 12px;
  min-width: 220px;
  color: var(--text-primary);
  font-size: 14px;
  font-weight: 500;
  font-family: inherit;
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--text-muted) 50%), linear-gradient(135deg, var(--text-muted) 50%, transparent 50%);
  background-position: calc(100% - 16px) center, calc(100% - 11px) center;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}

select:hover { border: 1px solid var(--text-muted); }
select:focus { outline: none; border: 1px solid var(--blue); }

input[type="text"], input[type="number"] {
  background-color: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 12px;
  color: var(--text-primary);
  font-size: 14px;
  font-family: inherit;
}
input[type="text"]:focus, input[type="number"]:focus { outline: none; border: 1px solid var(--blue); }

button.tool-btn {
  background-color: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 6px 12px;
  color: var(--text-primary);
  font-size: 12px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
}
button.tool-btn:hover { border: 1px solid var(--text-muted); }
button.tool-btn.active {
  background-color: rgba(57, 135, 229, 0.18);
  border: 1px solid var(--blue);
}

.checkbox-row { display: flex; align-items: center; gap: 6px; color: var(--text-secondary); font-size: 12px; cursor: pointer; user-select: none; }
.checkbox-row input[type="checkbox"] {
  width: 15px; height: 15px; border-radius: 4px; border: 1px solid var(--border);
  background-color: var(--surface-raised); appearance: none; cursor: pointer; position: relative;
}
.checkbox-row input[type="checkbox"]:checked { background-color: var(--blue); border-color: var(--blue); }
.checkbox-row input[type="checkbox"]:checked::after {
  content: ""; position: absolute; left: 4px; top: 1px; width: 4px; height: 8px;
  border: solid white; border-width: 0 2px 2px 0; transform: rotate(45deg);
}

.divider { background-color: var(--border); height: 1px; margin: 4px 0; }

.chart-card {
  background-color: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  padding: 16px 18px 12px;
  gap: 6px;
  min-width: 0;
  min-height: 0;
}

.section-header {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-secondary);
  letter-spacing: 1px;
  padding-top: 4px;
}

.caption-text { color: var(--text-muted); font-size: 10px; }

.hscroll { overflow-y: auto; overflow-x: hidden; }

/* custom scrollbar */
.hscroll::-webkit-scrollbar { width: 10px; }
.hscroll::-webkit-scrollbar-track { background: transparent; }
.hscroll::-webkit-scrollbar-thumb { background: #3a3b40; border-radius: 5px; }
.hscroll::-webkit-scrollbar-thumb:hover { background: #4a4b52; }

canvas { display: block; width: 100%; height: 100%; cursor: default; }

/* ------------------------------------------------------------- explore */
#page-explore { flex-direction: column; padding: 14px 18px 18px; gap: 12px; }

.controls-row { display: flex; gap: 28px; flex-shrink: 0; }

.explore-split { display: flex; gap: 16px; flex: 1; min-height: 0; }
.explore-split .chart-card { flex: 3; }
.explore-split .info-container { flex: 2; }

.chart-header { display: flex; align-items: center; gap: 8px; }
.chart-title { font-size: 15px; font-weight: 600; }
.chart-hint { color: var(--text-muted); font-size: 10.5px; margin-left: auto; }

.admin-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.concentration-canvas-wrap { flex: 3; min-height: 160px; position: relative; }
.receptor-canvas-wrap { flex: 2; min-height: 120px; position: relative; }

#info-panel-container {
  background-color: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.info-toolbar { display: flex; align-items: center; gap: 6px; padding: 12px 12px 0; flex-shrink: 0; }
.info-toolbar .spacer { flex: 1; }

#info-panel-content {
  padding: 20px 20px 24px;
  flex: 1;
  min-height: 0;
}

.med-name { font-size: calc(22px * var(--info-scale)); font-weight: 700; color: var(--text-primary); margin-bottom: 14px; }
.badge-row { margin-bottom: 14px; }
.class-badge { border-radius: 9px; padding: 3px 10px; font-size: calc(10px * var(--info-scale)); font-weight: 700; letter-spacing: 0.5px; }

.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 14px; }
.stat-tile { background-color: var(--surface-raised); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; }
.stat-value { font-size: calc(18px * var(--info-scale)); font-weight: 700; word-wrap: break-word; }
.stat-label { font-size: calc(10px * var(--info-scale)); font-weight: 600; color: var(--text-muted); letter-spacing: 0.5px; margin-top: 2px; }

#info-panel-content .divider { margin: 14px 0; }
#info-panel-content .section-header { font-size: calc(12px * var(--info-scale)); margin-bottom: 6px; }
.body-text { color: var(--text-secondary); font-size: calc(12.5px * var(--info-scale)); line-height: 1.5; margin-bottom: 14px; }
.black-box-head { color: var(--critical); font-size: calc(12px * var(--info-scale)); font-weight: 600; margin-bottom: 4px; }
.serious-text { color: var(--serious); font-size: calc(12.5px * var(--info-scale)); line-height: 1.5; margin-bottom: 14px; }

.bullet-list { margin-bottom: 14px; }
.bullet-row { display: flex; gap: 8px; margin-bottom: 5px; align-items: flex-start; }
.bullet-dot { font-size: 8px; margin-top: 5px; flex-shrink: 0; }
.bullet-row .bullet-text { color: var(--text-secondary); font-size: calc(12.5px * var(--info-scale)); line-height: 1.5; }
.bullet-row .serious-text { margin-bottom: 0; }

/* --------------------------------------------------------------- compare */
#page-compare { padding: 16px 18px 18px; gap: 16px; }
#page-compare .chart-card { flex: 1; }

.range-label { color: var(--text-muted); font-size: 10px; font-weight: 600; letter-spacing: 0.5px; margin-left: auto; }
#range-select { min-width: 150px; padding: 5px 10px; font-size: 12px; }

.interaction-notes {
  color: var(--serious);
  font-size: 12.5px;
  white-space: pre-wrap;
  display: none;
}

#picker-panel {
  width: 300px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
  position: relative;
}

.picker-header { display: flex; align-items: center; }
.picker-count { color: var(--text-muted); font-size: 10.5px; font-weight: 600; margin-left: auto; }

#picker-list { flex: 1; min-height: 0; padding-right: 4px; }
.picker-class-head { font-size: 10px; font-weight: 700; letter-spacing: 0.5px; padding-top: 8px; padding-bottom: 2px; }
.picker-med-row { display: flex; align-items: center; gap: 6px; padding: 3px 0; color: var(--text-secondary); font-size: 13px; cursor: pointer; }
.picker-med-row input { flex-shrink: 0; }
.picker-med-row.disabled { opacity: 0.4; pointer-events: none; }

#search-popup {
  position: absolute;
  top: 34px;
  left: 0;
  right: 0;
  background-color: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: 8px;
  z-index: 50;
  max-height: 260px;
  overflow-y: auto;
  display: none;
  padding: 4px;
}
.search-result {
  display: block;
  width: 100%;
  text-align: left;
  padding: 7px 10px;
  border: none;
  background: transparent;
  color: var(--text-primary);
  font-size: 12px;
  border-radius: 5px;
  cursor: pointer;
  font-family: inherit;
}
.search-result:hover { background: #2a2b30; }
.search-result.checked { color: var(--blue); }
.search-empty { color: var(--text-muted); font-size: 12px; padding: 8px; }

/* receptor hover popup, shared by explore/compare tabs */
.receptor-popup {
  position: fixed;
  display: none;
  background-color: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  z-index: 100;
  max-width: 300px;
}
.receptor-popup-title { color: var(--text-primary); font-size: 12.5px; font-weight: 700; margin-bottom: 4px; }
.receptor-popup-body { color: var(--text-secondary); font-size: 11.5px; line-height: 1.4; }

/* -------------------------------------------------------------- receptors */
#page-receptors { flex-direction: column; padding: 16px 18px 18px; gap: 10px; }
.receptors-toolbar { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.receptors-toolbar .caption-text { font-size: 10.5px; flex: 1; }

#receptors-table-wrap {
  background-color: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  flex: 1;
  min-height: 0;
  overflow: auto;
}

table.receptors-table {
  width: 100%;
  border-collapse: collapse;
  color: var(--text-secondary);
  font-size: calc(11px * var(--rec-scale, 1));
}
table.receptors-table th {
  background-color: var(--surface-raised);
  color: var(--text-muted);
  padding: 10px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  font-weight: 700;
  font-size: calc(10px * var(--rec-scale, 1));
  letter-spacing: 0.5px;
  position: sticky;
  top: 0;
}
table.receptors-table td {
  padding: 10px;
  border-bottom: 1px solid var(--gridline);
  vertical-align: top;
}
table.receptors-table td:first-child { color: var(--text-primary); font-weight: 500; width: 230px; }
table.receptors-table tr:hover { background-color: rgba(255,255,255,0.03); }
table.receptors-table tr.selected { background-color: rgba(57, 135, 229, 0.21); }
table.receptors-table tr.selected td:first-child { color: var(--text-primary); }

/* --------------------------------------------------------------- titration */
#page-titration { flex-direction: column; padding: 14px 18px 18px; gap: 12px; }
.mode-row { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

.tit-stack { flex: 1; min-height: 0; position: relative; }
.tit-page { display: none; height: 100%; gap: 0; }
.tit-page.active { display: flex; }

.tit-split { display: flex; gap: 16px; flex: 1; min-height: 0; width: 100%; }
.tit-split .chart-card { flex: 3; }
.tit-split .info-container { flex: 2; }

.tit-canvas-wrap { flex: 1; min-height: 160px; position: relative; }

#tit-single-controls, #tit-cross-controls { display: flex; gap: 28px; flex-shrink: 0; }
.cross-selector-row { display: flex; gap: 28px; align-items: flex-end; margin-bottom: 4px; }
.cross-role-label { width: 90px; color: var(--text-muted); font-size: 10px; font-weight: 600; letter-spacing: 1px; flex-shrink: 0; padding-bottom: 8px; }

.info-scroll-panel {
  background-color: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px 20px 24px;
  overflow-y: auto;
  min-height: 0;
}

.info-scroll-panel .field-label,
.info-scroll-panel .section-header,
.info-scroll-panel .body-text,
.info-scroll-panel .caption-text {
  font-size: calc(1em * var(--tit-scale));
}
.info-scroll-panel .section-header { font-size: calc(12px * 1.5 * var(--tit-scale)); }
.info-scroll-panel .body-text { font-size: calc(12.5px * 1.5 * var(--tit-scale)); color: var(--text-secondary); line-height: 1.5; }

/* --------------------------------------------------------------- converter */
#page-converter { flex-direction: column; padding: 14px 18px 18px; gap: 14px; overflow-y: auto; }
#conv-controls { display: flex; gap: 28px; align-items: flex-end; flex-wrap: wrap; }

.result-card {
  background-color: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px 20px;
  flex-shrink: 0;
}
#conv-result { font-weight: 700; font-size: calc(24px * var(--conv-scale, 1)); margin-bottom: 4px; }
#conv-result-sub { color: var(--text-secondary); font-size: calc(12.5px * var(--conv-scale, 1)); }

.table-card {
  background-color: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px 20px;
}
#conv-table-header { font-size: calc(12px * var(--conv-scale, 1)); }
.conv-row { display: grid; grid-template-columns: 1fr 3fr auto; gap: 10px; align-items: center; margin-top: 8px; }
.conv-row-name { font-size: calc(13px * var(--conv-scale, 1)); }
.conv-row-bar-track { height: 16px; background-color: var(--surface-raised); border-radius: 4px; overflow: hidden; }
.conv-row-bar-fill { height: 100%; border-radius: 4px; }
.conv-row-dose { text-align: right; font-size: calc(13px * var(--conv-scale, 1)); }

/* ----------------------------------------------------------------- misc */
.hidden { display: none !important; }
