
:root {
  --cream:      #faf8f4;
  --off-white:  #f2efe9;
  --border:     #d8d3ca;
  --border-dark:#b8b0a5;
  --text:       #2c2820;
  --text-muted: #7a7168;
  --text-light: #a09890;
  --accent:     #2d6a4f;
  --accent-bg:  #e8f4f0;
  --accent-dark:#1b4332;
  --highlight:  #e76f51;
  --highlight-bg:#fdf0ec;
  --sidebar-w:  220px;
  --panel-w:    280px;
  --header-h:   52px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { width: 100%; height: 100%; overflow: hidden; }

body {
  font-family: 'Source Sans 3', sans-serif;
  font-size: 14px;
  background: var(--cream);
  color: var(--text);
  display: flex;
  flex-direction: column;
  transition: background 0.3s, color 0.3s;
}

body.dark-mode {
  --cream:      #121418;
  --off-white:  #1a1d24;
  --border:     #2a2f38;
  --border-dark:#3a3f48;
  --text:       #e0e0e0;
  --text-muted: #9aa0a6;
  --text-light: #7a8088;
  --accent:     #74c69d;
  --accent-bg:  #1e2b25;
  --accent-dark:#52b788;
  --highlight:  #e76f51;
  --highlight-bg:#3b1e16;
}

body.dark-mode #header {
  background: #0e1116;
}

body.dark-mode #info-panel {
  background: var(--cream);
}

body.dark-mode #search-dropdown {
  background: var(--off-white);
}

body.dark-mode .tag {
  background: #252a33;
  border-color: #363d4a;
}

/* ── HEADER ──────────────────────────────────── */
#header {
  height: var(--header-h);
  background: var(--text);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px;
  flex-shrink: 0;
  gap: 16px;
}

.site-title {
  font-family: 'Source Serif 4', serif;
  font-size: 18px;
  color: var(--cream);
  font-weight: 600;
  white-space: nowrap;
}
.title-accent {
  color: #74c69d;
}
.subtitle {
  font-size: 11px;
  color: #888;
  letter-spacing: 0.5px;
  margin-top: 1px;
}

/* Search */
#search-wrap {
  position: relative;
  flex: 1;
  max-width: 340px;
}
#search-input {
  width: 100%;
  padding: 7px 12px;
  background: #1e1e1e;
  border: 1px solid #444;
  border-radius: 4px;
  color: #ddd;
  font-family: 'Source Sans 3', sans-serif;
  font-size: 13px;
  outline: none;
  transition: border-color 0.15s;
}
#search-input:focus { border-color: #74c69d; }
#search-input::placeholder { color: #666; }

#search-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0; right: 0;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 4px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.12);
  display: none;
  z-index: 999;
  overflow: hidden;
}
#search-dropdown.open { display: block; }

.sd-row {
  padding: 9px 12px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  transition: background 0.1s;
}
.sd-row:last-child { border-bottom: none; }
.sd-row:hover { background: var(--accent-bg); }
.sd-name { font-size: 13px; color: var(--text); }
.sd-cat { font-size: 11px; color: var(--text-muted); }

/* ── LAYOUT ──────────────────────────────────── */
#layout {
  flex: 1;
  display: flex;
  overflow: hidden;
}

/* ── LEFT SIDEBAR ──────────────────────────────── */
#sidebar {
  width: var(--sidebar-w);
  background: var(--off-white);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  flex-shrink: 0;
}

#sidebar-resizer,
#panel-resizer {
  width: 4px;
  background: var(--border);
  cursor: col-resize;
  flex-shrink: 0;
  transition: background 0.15s;
  z-index: 10;
}
#sidebar-resizer:hover,
#sidebar-resizer.is-resizing,
#panel-resizer:hover,
#panel-resizer.is-resizing {
  background: var(--accent);
}

#sidebar::-webkit-scrollbar { width: 4px; }
#sidebar::-webkit-scrollbar-thumb { background: var(--border-dark); border-radius: 2px; }

.sidebar-title {
  padding: 14px 14px 10px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.section-group {
  border-bottom: 1px solid var(--border);
}

.group-header {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 9px 14px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  transition: background 0.1s;
  user-select: none;
}
.group-header:hover { background: #ebe8e2; }
.group-header.active-group { color: var(--accent-dark); }

.group-arrow {
  font-size: 10px;
  color: var(--text-muted);
  transition: transform 0.15s;
  display: inline-block;
}
.group-arrow.open { transform: rotate(90deg); }

.group-items {
  overflow: hidden;
}
.group-items.collapsed { display: none; }

.part-item {
  padding: 7px 14px 7px 28px;
  font-size: 12.5px;
  color: var(--text-muted);
  cursor: pointer;
  border-left: 3px solid transparent;
  transition: all 0.1s;
}
.part-item:hover {
  background: var(--accent-bg);
  color: var(--text);
  border-left-color: var(--accent);
}
.part-item.active {
  background: var(--accent-bg);
  color: var(--accent-dark);
  border-left-color: var(--accent);
  font-weight: 600;
}


/* ── VIEWPORT ──────────────────────────────────── */
#viewport {
  flex: 1;
  position: relative;
  background: #181c22;
  overflow: hidden;
}

#canvas-container {
  position: absolute;
  inset: 0;
  bottom: 44px; /* room for controls bar */
}
#canvas-container canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
}

/* Loading screen */
#loading-screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: #181c22;
  z-index: 200;
  transition: opacity 0.4s;
}
#loading-screen.done { opacity: 0; pointer-events: none; }

.ls-spinner {
  width: 36px; height: 36px;
  border: 3px solid #333;
  border-top-color: #74c69d;
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.ls-title {
  color: #ccc;
  font-size: 15px;
  font-weight: 500;
}
.ls-bar-wrap {
  width: 180px; height: 3px;
  background: #333;
  border-radius: 2px;
  overflow: hidden;
}
.ls-bar {
  height: 100%;
  background: #74c69d;
  width: 0%;
  transition: width 0.3s;
}
.ls-text { font-size: 11px; color: #666; }
.ls-credits { font-size: 10px; color: #444; font-style: italic; }

/* Controls bar at bottom */
#controls-bar {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 44px;
  background: rgba(14,17,22,0.95);
  border-top: 1px solid #2a2f38;
  display: flex;
  align-items: center;
  padding: 0 10px;
  gap: 5px;
  z-index: 20;
}

.ctrl-btn {
  padding: 5px 11px;
  background: #252a33;
  border: 1px solid #363d4a;
  border-radius: 4px;
  color: #aaa;
  font-family: 'Source Sans 3', sans-serif;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.12s;
}
.ctrl-btn:hover {
  background: #2d3441;
  border-color: #74c69d;
  color: #74c69d;
}
.ctrl-sep {
  width: 1px;
  height: 20px;
  background: #2a2f38;
  margin: 0 3px;
}

/* Selected label */
#selected-label {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(14,17,22,0.88);
  border: 1px solid #74c69d;
  border-radius: 4px;
  padding: 5px 16px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: #74c69d;
  pointer-events: none;
  z-index: 10;
  white-space: nowrap;
}
#selected-label.hidden { display: none; }

/* ── RIGHT INFO PANEL ──────────────────────────── */
#info-panel {
  width: var(--panel-w);
  background: #fff;
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow: hidden;
}

.ip-selected-label {
  padding: 14px 16px 4px;
  font-size: 10.5px;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--text-muted);
  font-weight: 600;
}

.ip-name {
  padding: 0 16px 4px;
  font-family: 'Source Serif 4', serif;
  font-size: 22px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.2;
}

.ip-latin {
  padding: 0 16px 12px;
  font-size: 12px;
  color: var(--text-muted);
  font-style: italic;
  border-bottom: 1px solid var(--border);
}

/* Tabs */
.ip-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  gap: 0;
}
.ip-tab {
  flex: 1;
  padding: 9px 0;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  font-family: 'Source Sans 3', sans-serif;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  letter-spacing: 0.5px;
  transition: all 0.12s;
}
.ip-tab:hover { color: var(--text); }
.ip-tab.active {
  color: var(--accent-dark);
  border-bottom-color: var(--accent);
}

/* Tab content */
.tab-content {
  flex: 1;
  overflow-y: auto;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.tab-content.hidden { display: none; }
.tab-content::-webkit-scrollbar { width: 4px; }
.tab-content::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.info-block { }
.info-block-title {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  color: var(--accent-dark);
  margin-bottom: 6px;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--border);
}

.info-text {
  font-size: 13px;
  line-height: 1.7;
  color: var(--text-muted);
}

/* Facts table */
.facts-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.facts-table tr {
  border-bottom: 1px solid var(--border);
}
.facts-table tr:last-child { border-bottom: none; }
.facts-table td {
  padding: 6px 4px;
  vertical-align: top;
}
.fact-key {
  color: var(--text-muted);
  width: 110px;
  font-size: 12px;
}
.facts-table td:last-child {
  color: var(--text);
  font-weight: 500;
}

/* Tags */
.tags-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}
.tag {
  padding: 3px 9px;
  background: var(--off-white);
  border: 1px solid var(--border);
  border-radius: 12px;
  font-size: 11px;
  color: var(--text-muted);
}



.hidden { display: none !important; }


/* ════════════════════════════════════════════════════
   NEW ADDITIONS — Layer toggles, Muscle sidebar,
   AI Analyser panel
   ════════════════════════════════════════════════════ */

/* ── Header layout with centre slot ──────────────── */
#header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.header-center {
  flex: 1;
  display: flex;
  justify-content: center;
}

/* ── Layer toggle buttons ─────────────────────────── */
#layer-toggles { display: flex; gap: 6px; }

.layer-btn {
  padding: 5px 13px;
  border: 1px solid #3a7d44;
  border-radius: 14px;
  background: #1a2a1a;
  color: #3a7d44;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background .18s, color .18s, border-color .18s;
  white-space: nowrap;
}
.layer-btn:hover { background: #243424; }
.layer-btn.layer-off {
  background: #181818;
  color: #555;
  border-color: #333;
  text-decoration: line-through;
}

/* ── Circular Theme Button ────────────────────────── */
.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.theme-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: #1e1e1e;
  border: 1px solid #444;
  color: #ddd;
  font-size: 13px;
  font-weight: 700;
  font-family: 'Source Sans 3', sans-serif;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  flex-shrink: 0;
}
.theme-btn:hover {
  border-color: #74c69d;
  color: #74c69d;
}

body.dark-mode .theme-btn {
  background: var(--off-white);
  border-color: var(--border-dark);
  color: var(--text);
}
body.dark-mode .theme-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* ── Muscle sidebar loading note ──────────────────── */
.sidebar-loading-note {
  color: #666;
  font-size: 11px;
  padding: 6px 14px;
  font-style: italic;
}

/* ── AI SYMPTOM ANALYSER TAB ─────────────────────── */

/* Hint showing which structure is selected */
.ai-selected-hint {
  font-size: 12px;
  font-weight: 600;
  padding: 6px 10px;
  background: #111a11;
  border: 1px solid #2e4a2e;
  border-radius: 6px;
  margin-bottom: 10px;
  color: #3a7d44;
}

/* Patient Form */
.patient-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 10px;
}
.patient-form-row {
  display: flex;
  gap: 8px;
}
.patient-form input,
.patient-form select {
  width: 100%;
  box-sizing: border-box;
  background: #0f1218;
  border: 1px solid #2a3a2a;
  border-radius: 8px;
  color: #d8e0d8;
  padding: 8px 10px;
  font-size: 13px;
  font-family: inherit;
  transition: border-color .18s;
  appearance: none;
}
.patient-form input:focus,
.patient-form select:focus {
  outline: none;
  border-color: #3a7d44;
}
.patient-form input::placeholder { color: #445; }

/* Symptom textarea */
#symptom-input {
  width: 100%;
  box-sizing: border-box;
  background: #0f1218;
  border: 1px solid #2a3a2a;
  border-radius: 8px;
  color: #d8e0d8;
  padding: 10px 12px;
  font-size: 13px;
  font-family: inherit;
  line-height: 1.55;
  resize: vertical;
  transition: border-color .18s;
}
#symptom-input:focus {
  outline: none;
  border-color: #3a7d44;
}
#symptom-input::placeholder { color: #445; }

/* Analyse button */
.analyse-btn {
  width: 100%;
  margin-top: 10px;
  padding: 10px 0;
  background: #3a7d44;
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background .18s;
  letter-spacing: .3px;
}
.analyse-btn:hover:not(:disabled) { background: #2c6234; }
.analyse-btn:disabled { background: #252525; color: #555; cursor: not-allowed; }

/* Loading indicator */
.ai-loading {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 4px;
  color: #6a8a6a;
  font-size: 13px;
}
.ai-loading.hidden { display: none !important; }

.ai-spinner {
  width: 18px; height: 18px;
  border: 2px solid #2a3a2a;
  border-top-color: #3a7d44;
  border-radius: 50%;
  animation: ai-spin .75s linear infinite;
  flex-shrink: 0;
}
@keyframes ai-spin { to { transform: rotate(360deg); } }

/* Result container */
#ai-result.hidden { display: none !important; }

.ai-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}
.ai-icon  { font-size: 20px; }
.ai-title { font-size: 14px; color: #b0c0b0; }
.ai-title strong { color: #dde; }

.ai-section { margin-bottom: 14px; }
.ai-section-title {
  font-size: 10.5px;
  font-weight: 700;
  color: #3a7d44;
  text-transform: uppercase;
  letter-spacing: .9px;
  margin-bottom: 8px;
}

.ai-cause {
  background: #0f1a0f;
  border: 1px solid #1e301e;
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 8px;
}
.ai-cause-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 4px;
}
.ai-cause-name { font-size: 13px; font-weight: 600; color: #d8e0d8; }
.ai-likelihood { font-size: 11px; font-weight: 700; }
.ai-cause-desc { font-size: 12px; color: #7a9a7a; line-height: 1.5; margin: 0; }

.ai-flags {
  margin: 0;
  padding-left: 18px;
}
.ai-flags li { font-size: 12px; color: #e74c3c; line-height: 1.65; }

.ai-action {
  font-size: 13px;
  color: #99b899;
  line-height: 1.55;
  margin: 0;
}

.ai-related {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 5px;
  margin-top: 8px;
}
.ai-related-label { font-size: 11px; color: #556; }

.ai-disclaimer {
  font-size: 10.5px;
  color: #445;
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid #1a2a1a;
  line-height: 1.5;
  font-style: italic;
}

.ai-error {
  padding: 12px;
  background: #1a0808;
  border: 1px solid #5a2222;
  border-radius: 8px;
  color: #e74c3c;
  font-size: 12px;
  line-height: 1.5;
}

.ai-footer-note {
  font-size: 10px;
  color: #333;
  text-align: center;
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid #181818;
  line-height: 1.4;
}

/* ── Loading screen done state ────────────────────── */
#loading-screen.done {
  opacity: 0;
  pointer-events: none;
  transition: opacity .5s ease;
}

/* ── TEST REFINE TAB STYLES ─────────────────────────── */
.patient-select-wrapper {
  margin-bottom: 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.patient-select {
  width: 100%;
  box-sizing: border-box;
  background: #0f1218;
  border: 1px solid #2a3a2a;
  border-radius: 8px;
  color: #d8e0d8;
  padding: 8px 10px;
  font-size: 13px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.18s;
  cursor: pointer;
  height: 36px;
}

body.dark-mode .patient-select {
  background: #0f1218;
  border-color: #2a3a2a;
  color: #d8e0d8;
}

.patient-preview-card {
  background: rgba(45, 106, 79, 0.05);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

body.dark-mode .patient-preview-card {
  background: rgba(116, 198, 157, 0.05);
  border-color: var(--border);
}

.card-row {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.4;
}
.card-row strong {
  color: var(--text);
  margin-right: 4px;
}

.file-dropzone {
  border: 2px dashed var(--border);
  border-radius: 8px;
  padding: 14px 10px;
  text-align: center;
  cursor: pointer;
  background: rgba(0, 0, 0, 0.01);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  transition: border-color 0.18s, background-color 0.18s;
}

.file-dropzone:hover,
.file-dropzone.dragover {
  border-color: var(--accent);
  background: rgba(45, 106, 79, 0.03);
}

body.dark-mode .file-dropzone:hover,
body.dark-mode .file-dropzone.dragover {
  background: rgba(116, 198, 157, 0.03);
}

.file-status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--accent-bg);
  border: 1px solid var(--accent);
  border-radius: 6px;
  padding: 6px 10px;
  margin-top: 5px;
}

.file-status .file-name {
  font-weight: 500;
  font-size: 12px;
  color: var(--accent-dark) !important;
  word-break: break-all;
}

/* ── Custom Professional Checkbox ────────────────────── */
.report-checkbox {
  appearance: none;
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  border: 2px solid var(--border);
  border-radius: 4px;
  background-color: transparent;
  cursor: pointer;
  position: relative;
  transition: all 0.2s ease;
  margin: 0 !important;
  flex-shrink: 0;
  display: inline-block;
  vertical-align: middle;
}

.report-checkbox:checked {
  background-color: var(--accent);
  border-color: var(--accent);
}

.report-checkbox[data-type="issue"]:checked {
  background-color: #d35400;
  border-color: #d35400;
}

.report-checkbox[data-type="icd10"]:checked {
  background-color: #3a7d44;
  border-color: #3a7d44;
}

.report-checkbox[data-type="test"]:checked {
  background-color: #5b7c5b;
  border-color: #5b7c5b;
}

.report-checkbox[data-type="warning"]:checked {
  background-color: #c0392b;
  border-color: #c0392b;
}

.report-checkbox:checked::after {
  content: '';
  position: absolute;
  left: 5px;
  top: 2px;
  width: 4px;
  height: 9px;
  border: solid white;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

.report-checkbox:hover {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-bg);
}
