:root {
  --bg: #f4f6f8;
  --card-bg: #ffffff;
  --ink: #1c2733;
  --ink-muted: #64748b;
  --border: #e2e8f0;
  --primary: #2563a8;
  --primary-dark: #1d4d80;
  --accent-ok: #1a7f5a;
  --accent-warn: #b5551d;
  --accent-bad: #b1332e;
  --radius: 10px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1 { font-size: 1.35rem; margin: 0 0 1rem; }
h2 { font-size: 1rem; margin: 1.75rem 0 0.75rem; color: var(--ink); }
button { font-family: inherit; cursor: pointer; }
input, textarea { font-family: inherit; }

.muted { color: var(--ink-muted); }
.small { font-size: 0.82rem; }
.tiny { font-size: 0.7rem; padding: 2px 6px !important; }
.hidden { display: none !important; }

/* Topbar */
.topbar {
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem 0.5rem;
}
.brand { font-weight: 600; font-size: 0.95rem; }
.stepper {
  display: flex;
  overflow-x: auto;
  gap: 0.4rem;
  padding: 0 1rem 0.6rem;
  scrollbar-width: none;
}
.stepper::-webkit-scrollbar { display: none; }
.step {
  flex: 0 0 auto;
  font-size: 0.72rem;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--bg);
  color: var(--ink-muted);
  border: 1px solid var(--border);
  white-space: nowrap;
}
.step.active { background: var(--primary); color: #fff; border-color: var(--primary); font-weight: 600; }
.step.done { background: #e6f0ea; color: var(--accent-ok); border-color: #cde5d8; }

/* Buttons */
.btn-primary, .btn-secondary, .btn-ghost {
  border-radius: 8px;
  padding: 0.65rem 1.1rem;
  border: none;
  font-size: 0.9rem;
  font-weight: 600;
}
.btn-primary { background: var(--primary); color: #fff; margin-top: 1.25rem; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-primary:disabled { background: #a9b8c6; cursor: not-allowed; }
.btn-secondary { background: #eaf1f8; color: var(--primary-dark); border: 1px solid #cfe0ef; }
.btn-ghost { background: transparent; color: var(--primary); border: 1px solid var(--border); margin-top: 0.75rem; }
.btn-primary.small, .btn-secondary.small, .btn-ghost.small { padding: 0.4rem 0.75rem; font-size: 0.8rem; margin-top: 0; }

/* Layout */
.main { padding: 1rem; max-width: 1100px; margin: 0 auto; }
.content-wrap { display: flex; flex-direction: column-reverse; gap: 1rem; }
.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  flex: 1;
}

.side-panel {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  align-self: flex-start;
}
.panel-block + .panel-block { margin-top: 1.25rem; }
.panel-title { font-size: 0.78rem; font-weight: 700; color: var(--ink-muted); text-transform: uppercase; letter-spacing: 0.02em; margin-bottom: 0.5rem; }
.time-bar { background: var(--bg); border-radius: 999px; height: 8px; overflow: hidden; }
.time-bar-fill { background: var(--primary); height: 100%; transition: width 0.2s; }
.time-label { font-size: 0.8rem; margin-top: 0.35rem; color: var(--ink-muted); }
.hyp-list-mini { display: flex; flex-direction: column; gap: 0.35rem; }
.hyp-mini-row { display: flex; justify-content: space-between; font-size: 0.85rem; padding: 0.3rem 0; border-bottom: 1px dashed var(--border); }
.hyp-mini-pct { font-weight: 700; color: var(--primary-dark); }

@media (min-width: 800px) {
  .content-wrap { flex-direction: row; align-items: flex-start; }
  .side-panel { width: 280px; position: sticky; top: 110px; }
}

/* Intake */
.intake-grid { display: flex; gap: 1.5rem; flex-wrap: wrap; margin-bottom: 1rem; }
.big { font-size: 1.1rem; font-weight: 600; }
.chief-complaint {
  background: var(--bg);
  border-left: 3px solid var(--primary);
  padding: 0.85rem 1rem;
  border-radius: 6px;
  font-style: italic;
}

/* Chat */
.chat-thread { display: flex; flex-direction: column; gap: 0.5rem; margin-bottom: 1rem; }
.chat-bubble { max-width: 85%; padding: 0.6rem 0.85rem; border-radius: 12px; font-size: 0.9rem; }
.chat-bubble.question { align-self: flex-end; background: var(--primary); color: #fff; border-bottom-right-radius: 2px; }
.chat-bubble.answer { align-self: flex-start; background: var(--bg); border: 1px solid var(--border); border-bottom-left-radius: 2px; }

.ask-form { display: flex; gap: 0.5rem; margin: 0.75rem 0; }
.ask-form input {
  flex: 1;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.9rem;
}

.category-groups { margin-top: 1rem; }
.category-group { margin-bottom: 0.9rem; }
.category-label { font-size: 0.78rem; font-weight: 700; color: var(--ink-muted); text-transform: uppercase; letter-spacing: 0.02em; margin-bottom: 0.4rem; }
.category-btns { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.pill-btn {
  background: #eaf1f8;
  border: 1px solid #cfe0ef;
  color: var(--primary-dark);
  border-radius: 999px;
  padding: 0.4rem 0.8rem;
  font-size: 0.8rem;
}
.pill-btn.pill-asked { background: var(--bg); border-color: var(--border); color: var(--ink-muted); }

.hint-block { margin-top: 1.25rem; padding-top: 0.75rem; border-top: 1px dashed var(--border); }
.hint-text { background: #fdf6ec; border-left: 3px solid var(--accent-warn); padding: 0.6rem 0.85rem; border-radius: 6px; margin-bottom: 0.5rem; font-size: 0.87rem; }

/* Hypotheses */
.hyp-editor { display: flex; flex-direction: column; gap: 0.6rem; margin: 0.75rem 0; }
.hyp-row { display: grid; grid-template-columns: 1fr 2fr auto auto; align-items: center; gap: 0.6rem; }
.hyp-label { font-size: 0.88rem; }
.hyp-slider { width: 100%; }
.hyp-pct { font-weight: 700; width: 3ch; text-align: right; font-size: 0.85rem; }
.sum-row { font-weight: 700; margin-top: 0.5rem; }
.sum-row.sum-ok { color: var(--accent-ok); }
.sum-row.sum-bad { color: var(--accent-bad); }

/* Examination */
.test-group { margin-bottom: 1.25rem; }
.test-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 0.6rem; }
.test-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem;
  background: var(--bg);
}
.test-card.test-done { background: #eef6f1; border-color: #cde5d8; }
.test-name { font-weight: 600; font-size: 0.88rem; }
.test-cost { font-size: 0.75rem; color: var(--ink-muted); margin-bottom: 0.5rem; }
.test-result { font-size: 0.82rem; margin-top: 0.4rem; }

/* Therapy */
.therapy-list { display: flex; flex-direction: column; gap: 0.6rem; margin: 0.75rem 0; }
.therapy-item { border: 1px solid var(--border); border-radius: 8px; padding: 0.7rem 0.85rem; }
.therapy-check-label { display: flex; align-items: center; gap: 0.5rem; font-weight: 600; font-size: 0.9rem; }
.therapy-justification {
  width: 100%;
  margin-top: 0.6rem;
  min-height: 60px;
  padding: 0.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.85rem;
  resize: vertical;
}

/* Feedback */
.axes-list { display: flex; flex-direction: column; gap: 0.7rem; }
.axis-block { border-left: 3px solid var(--primary); padding: 0.5rem 0.85rem; background: var(--bg); border-radius: 0 6px 6px 0; }
.axis-title { font-weight: 700; font-size: 0.85rem; margin-bottom: 0.2rem; }
.axis-text { font-size: 0.87rem; }

.tags-list { display: flex; flex-direction: column; gap: 0.6rem; }
.tag-block { border-left: 3px solid var(--accent-warn); background: #fdf6ec; padding: 0.55rem 0.85rem; border-radius: 0 6px 6px 0; font-size: 0.85rem; }

.reasoning-map { display: flex; flex-direction: column; margin-top: 0.5rem; }
.map-node { display: flex; gap: 0.75rem; position: relative; padding-bottom: 1.25rem; }
.map-node:not(:last-child)::before {
  content: "";
  position: absolute;
  left: 5px;
  top: 14px;
  bottom: -6px;
  width: 2px;
  background: var(--border);
}
.map-node-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--primary); margin-top: 4px; flex: 0 0 auto; }
.map-node-body { cursor: pointer; }
.map-node-title { font-weight: 600; font-size: 0.88rem; }
.map-node-detail { font-size: 0.82rem; color: var(--ink-muted); margin-top: 0.3rem; max-width: 60ch; }

/* Mentor */
.mentor-wrap { position: fixed; right: 1rem; bottom: 1rem; z-index: 30; }
.mentor-fab {
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 999px;
  padding: 0.7rem 1.1rem;
  font-weight: 600;
  font-size: 0.85rem;
  box-shadow: 0 4px 14px rgba(0,0,0,0.18);
}
.mentor-panel {
  position: fixed;
  right: 1rem;
  bottom: 4.5rem;
  width: min(340px, calc(100vw - 2rem));
  max-height: 60vh;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 28px rgba(0,0,0,0.18);
  display: flex;
  flex-direction: column;
}
.mentor-header { display: flex; align-items: center; gap: 0.5rem; padding: 0.7rem 0.85rem; border-bottom: 1px solid var(--border); }
.mentor-header .muted { flex: 1; }
.mentor-log { padding: 0.75rem 0.85rem; overflow-y: auto; flex: 1; display: flex; flex-direction: column; gap: 0.4rem; }
.mentor-msg { padding: 0.5rem 0.7rem; border-radius: 10px; font-size: 0.82rem; max-width: 90%; }
.mentor-msg.user { align-self: flex-end; background: var(--primary); color: #fff; }
.mentor-msg.mentor { align-self: flex-start; background: var(--bg); border: 1px solid var(--border); }
.mentor-input-row { display: flex; gap: 0.4rem; padding: 0.6rem 0.7rem; border-top: 1px solid var(--border); }
.mentor-input-row input { flex: 1; padding: 0.5rem 0.6rem; border: 1px solid var(--border); border-radius: 8px; font-size: 0.85rem; }

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12181f;
    --card-bg: #1a222b;
    --ink: #e7edf3;
    --ink-muted: #93a3b3;
    --border: #2a3641;
    --primary: #5b9bd9;
    --primary-dark: #7db3e8;
    --accent-ok: #4cbf8f;
    --accent-warn: #d99a52;
    --accent-bad: #e2726d;
  }
  .pill-btn { background: #1e2a35; border-color: #2a3d4d; color: var(--primary-dark); }
  .pill-btn.pill-asked { background: var(--bg); color: var(--ink-muted); }
  .hint-text { background: #2b2417; }
  .tag-block { background: #2b2417; }
  .test-card.test-done { background: #16281f; }
  .btn-secondary { background: #1e2a35; border-color: #2a3d4d; }
}
