/* ═══════════════════════════════════════════════════════════════════
   CLINIFY AI  ·  Design System v2
   Palette  : deep midnight · clinical teal · amber alert
   Type     : Sora (UI)  ·  Inter (body)  ·  JetBrains Mono (data)
   Signature: teal scan-line on card hover — monitor cursor sweeping
              across an ECG trace; one moment of atmosphere, rest clean
   ═══════════════════════════════════════════════════════════════════ */

/* ── 1. TOKENS — light is the default; dark overrides below ─────────── */
:root {
  /* Backgrounds */
  --bg:           #f0f5fb;
  --surface:      #ffffff;
  --surface-2:    #e6eef8;
  --surface-3:    #dce6f2;

  /* Borders */
  --border:       #c4d4e8;
  --border-hi:    #93b0cc;

  /* Accent — clinical teal */
  --accent:       #00bfa5;
  --accent-dim:   #008f7a;
  --accent-glow:  rgba(0,191,165,.13);
  --accent-text:  #ffffff;

  /* Amber — critical/warning */
  --amber:        #f0a820;
  --amber-glow:   rgba(240,168,32,.12);

  /* Semantic */
  --success:      #1e9e62;
  --danger:       #d03030;
  --warning:      #f0a820;
  --info:         #1a7fd4;

  /* Text */
  --text:         #172030;
  --text-sub:     #304d6a;
  --text-muted:   #6585a5;
  --text-dim:     #93b0cc;

  /* Typography */
  --font-ui:      "Sora", system-ui, sans-serif;
  --font-body:    "Inter", system-ui, sans-serif;
  --font-mono:    "JetBrains Mono", "Fira Code", monospace;

  /* Shape */
  --radius-xs:    4px;
  --radius-sm:    6px;
  --radius:       10px;
  --radius-lg:    14px;

  /* Shadow */
  --shadow:       0 2px 14px rgba(0,0,0,.45);
  --shadow-lg:    0 6px 28px rgba(0,0,0,.6);

  /* Layout */
  --max-w:        860px;
  --tool-max-w:   760px;
}

/* ── 2. RESET ──────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; -webkit-tap-highlight-color: transparent; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 0.94rem;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: #1dd9c2; }

strong, b { font-weight: 600; }

/* ── 3. SCROLLBAR ──────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-hi); border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ── 4. TYPOGRAPHY ─────────────────────────────────────────────────── */
h1, h2, h3, h4 {
  font-family: var(--font-ui);
  font-weight: 600;
  line-height: 1.25;
  color: var(--text);
}
h1 { font-size: 1.5rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.05rem; }
h4 { font-size: 0.95rem; }

code, pre {
  font-family: var(--font-mono);
  font-size: 0.88em;
}
code {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  padding: 0.15em 0.4em;
  color: var(--accent);
}
pre {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.9rem 1rem;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-word;
}
pre code {
  background: none;
  border: none;
  padding: 0;
  color: var(--text);
  font-size: 0.86rem;
}

/* ── 5. FORMS ──────────────────────────────────────────────────────── */
label {
  display: block;
  font-family: var(--font-ui);
  font-size: 0.83rem;
  font-weight: 500;
  color: var(--text-sub);
  letter-spacing: 0.03em;
  text-transform: uppercase;
  margin-bottom: 0.35rem;
}
label .muted, label small {
  text-transform: none;
  font-weight: 400;
  letter-spacing: 0;
  font-size: 0.82em;
  color: var(--text-muted);
}

input[type="text"],
input[type="email"],
input[type="number"],
input[type="search"],
select,
textarea {
  display: block;
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 0.94rem;
  padding: 0.6rem 0.8rem;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
  -webkit-appearance: none;
  appearance: none;
}
input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
input::placeholder, textarea::placeholder {
  color: var(--text-dim);
  font-style: italic;
}
input:disabled, select:disabled, textarea:disabled {
  opacity: .45;
  cursor: not-allowed;
}

/* select arrow */
select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 6'%3E%3Cpath d='M0 0l5 6 5-6' fill='none' stroke='%236585a5' stroke-width='1.4'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.7rem center;
  background-size: 10px;
  padding-right: 2.2rem;
  cursor: pointer;
}
select option {
  background: var(--surface-2);
  color: var(--text);
}

textarea {
  resize: vertical;
  min-height: 90px;
  line-height: 1.55;
}

/* ── 6. BUTTONS ────────────────────────────────────────────────────── */
button {
  font-family: var(--font-ui);
  cursor: pointer;
  border: none;
  outline: none;
  transition: background .15s, border-color .15s, transform .1s, opacity .15s;
}

.primary-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--accent);
  color: var(--accent-text);
  border: none;
  border-radius: var(--radius);
  padding: 0.68rem 1.5rem;
  font-size: 0.9rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  width: 100%;
  justify-content: center;
  box-shadow: 0 2px 10px rgba(0,191,165,.22);
}
.primary-btn:hover { background: #00d4b8; transform: translateY(-1px); box-shadow: 0 4px 16px rgba(0,191,165,.32); }
.primary-btn:active { transform: translateY(0); background: var(--accent-dim); box-shadow: none; }
.primary-btn:disabled {
  opacity: .4;
  cursor: not-allowed;
  transform: none;
  background: var(--accent);
  box-shadow: none;
}

.secondary-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent-dim);
  border-radius: var(--radius);
  padding: 0.55rem 1.25rem;
  font-size: 0.88rem;
  font-weight: 500;
}
.secondary-btn:hover {
  background: var(--accent-glow);
  border-color: var(--accent);
}
.secondary-btn:disabled { opacity: .4; cursor: not-allowed; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-sub);
  font-size: 1rem;
  flex-shrink: 0;
}
.icon-btn:hover {
  border-color: var(--border-hi);
  color: var(--text);
  background: var(--surface-2);
}

.link-btn {
  background: none;
  border: none;
  color: var(--accent);
  font-family: var(--font-body);
  font-size: 0.83rem;
  padding: 0;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
  vertical-align: baseline;
  display: inline;
}
.link-btn:hover { color: #1dd9c2; }

/* Set by Utils.copyWithFeedback when a clipboard write is refused, so the
   failure is visible on the button instead of being swallowed. */
.copy-error {
  color: var(--danger);
  font-weight: 600;
}

/* ── 7. UTILITY ────────────────────────────────────────────────────── */
.hidden { display: none !important; }

.muted { color: var(--text-muted); }
.small { font-size: 0.82rem; }

.hint {
  display: block;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 0.3rem;
  line-height: 1.4;
}

.req { color: var(--danger); margin-left: 1px; }

.disclaimer {
  display: block;
  text-align: center;
  font-size: 0.77rem;
  color: var(--text-dim);
  padding: 1rem 1rem 1.25rem;
  letter-spacing: 0.01em;
}

/* ── 8. DEV BANNER ─────────────────────────────────────────────────── */
.dev-banner {
  background: var(--amber);
  color: #2a1800;
  text-align: center;
  font-size: 0.78rem;
  font-weight: 700;
  padding: 0.35rem 0.5rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  position: sticky;
  top: 0;
  z-index: 200;
}

/* ── 9. HOME PAGE ──────────────────────────────────────────────────── */
.home {
  max-width: var(--max-w);
  margin: 0 auto;
  padding: 0 1rem 2rem;
  min-height: 100dvh;
}

.home-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.1rem 0 1.4rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1.5rem;
}

.home-brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-family: var(--font-ui);
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.01em;
}

/* ECG trace animation — the signature */
.ecg-icon {
  display: block;
  flex-shrink: 0;
}
.ecg-trace {
  stroke: var(--accent);
  stroke-dasharray: 120;
  stroke-dashoffset: 120;
  animation: ecg-draw 1.4s cubic-bezier(.4,0,.2,1) .2s forwards;
}
@keyframes ecg-draw {
  to { stroke-dashoffset: 0; }
}

.home-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.user-email {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-family: var(--font-mono);
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Tool grid */
.tool-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(168px, 1fr));
  gap: 0.85rem;
}

.tool-card {
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.1rem 1rem 1rem;
  color: var(--text);
  text-decoration: none;
  transition: border-color .2s, box-shadow .2s, transform .15s;
  min-height: 120px;
}
.tool-card:hover {
  border-color: var(--card-color, var(--accent));
  box-shadow: 0 6px 20px rgba(0,0,0,.08), 0 0 0 1px var(--card-color, var(--accent));
  transform: translateY(-2px);
  color: var(--text);
}

/* THE SCAN-LINE — signature hover effect */
.tool-card::after {
  content: "";
  position: absolute;
  bottom: 0;
  left: 0;
  height: 2px;
  width: 0;
  background: var(--card-color, var(--accent));
  transition: width .3s cubic-bezier(.4,0,.2,1);
}
.tool-card:hover::after { width: 100%; }

.tool-icon {
  width: 2.4rem;
  height: 2.4rem;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  flex-shrink: 0;
  margin-bottom: 0.25rem;
  position: relative;
}
.tool-icon::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: var(--card-color, var(--accent));
  opacity: 0.13;
  transition: opacity .2s;
}
.tool-card:hover .tool-icon::before { opacity: 0.2; }

.tool-title {
  font-family: var(--font-ui);
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.01em;
}

.tool-desc {
  font-size: 0.77rem;
  color: var(--text-muted);
  line-height: 1.4;
}

/* ── 10. LOGIN PAGE ────────────────────────────────────────────────── */
.login-app {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background:
    radial-gradient(ellipse 60% 50% at 60% 30%, rgba(0,191,165,.06), transparent),
    var(--bg);
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 2.2rem 1.8rem 1.8rem;
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
}

.login-card h1 {
  font-family: var(--font-ui);
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.login-card h1 svg { flex-shrink: 0; }

.login-card p.muted {
  font-size: 0.88rem;
  color: var(--text-muted);
  margin-top: -0.5rem;
}

.login-card form {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}
.login-card input[type="email"] {
  font-size: 0.94rem;
}

.login-card .small.muted {
  font-size: 0.78rem;
  color: var(--text-dim);
  line-height: 1.5;
  text-align: center;
}

/* ── 11. TOOL PAGES (shared) ───────────────────────────────────────── */
.tool-app {
  max-width: var(--tool-max-w);
  margin: 0 auto;
  padding: 0 1rem 2.5rem;
}

.tool-header {
  display: grid;
  grid-template-columns: 36px 1fr auto;
  align-items: center;
  gap: 0.5rem;
  padding: 1rem 0 1.1rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1.5rem;
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 10;
}
.tool-header strong {
  font-family: var(--font-ui);
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  text-align: center;
  letter-spacing: -0.01em;
}

.back-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  color: var(--text-sub);
  font-size: 1.05rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-decoration: none;
  transition: border-color .15s, color .15s, background .15s;
}
.back-link:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-glow);
}

/* ── 12. TOOL FORMS ────────────────────────────────────────────────── */
.tool-form {
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
}

.form-row {
  display: flex;
  flex-direction: column;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.9rem;
}

.form-row-inline {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.9rem;
}

.form-row.half { /* used inside form-row-inline */ }

/* input + unit toggle group */
.input-with-unit {
  display: flex;
  gap: 0;
}
.input-with-unit input {
  border-radius: var(--radius-sm) 0 0 var(--radius-sm);
  flex: 1;
  min-width: 0;
}

.unit-toggle {
  display: inline-flex;
  flex-shrink: 0;
}
.unit-btn {
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-left: none;
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 0.78rem;
  padding: 0 0.65rem;
  cursor: pointer;
  transition: background .12s, color .12s;
  white-space: nowrap;
}
.unit-btn:last-child { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.unit-btn.active {
  background: var(--accent-dim);
  color: #e0fff9;
  border-color: var(--accent-dim);
}
.unit-btn:hover:not(.active) {
  background: var(--surface-2);
  color: var(--text-sub);
}

/* ── 13. TOGGLES ───────────────────────────────────────────────────── */
.mode-toggle,
.concise-toggle {
  display: inline-flex;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 2px;
  gap: 1px;
}
.mode-toggle input,
.concise-toggle input { display: none; }

.mode-toggle label,
.concise-toggle label {
  padding: 0.28rem 0.7rem;
  border-radius: 4px;
  cursor: pointer;
  color: var(--text-muted);
  font-family: var(--font-ui);
  font-size: 0.78rem;
  font-weight: 500;
  text-transform: none;
  letter-spacing: 0;
  margin: 0;
  user-select: none;
  transition: background .12s, color .12s;
}
.mode-toggle input:checked + label {
  background: var(--accent-dim);
  color: #d0fff7;
}
.concise-toggle input:checked + label {
  background: var(--surface-3);
  color: var(--accent);
}
.mode-toggle label:hover:not(.active),
.concise-toggle label:hover {
  color: var(--text-sub);
}

/* ── 14. CHAT ──────────────────────────────────────────────────────── */
.chat-app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: var(--max-w);
  margin: 0 auto;
}

/* Focused mode — hide chrome, full viewport */
.chat-app.focused {
  max-width: 100%;
  position: fixed;
  inset: 0;
  z-index: 100;
  background: var(--bg);
}
.chat-app.focused .back-link,
.chat-app.focused .chat-header strong,
.chat-app.focused .mode-toggle,
.chat-app.focused .concise-toggle,
.chat-app.focused #save-thread-btn,
.chat-app.focused #copy-thread-btn,
.chat-app.focused #clear-btn { display: none; }
.chat-app.focused #focus-btn { opacity: 0.5; }
.chat-app.focused .chat-window { padding: 1.5rem 2rem 1rem; }
.chat-app.focused .chat-input-bar textarea { max-height: 50vh; }

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 10;
  flex-shrink: 0;
}
.chat-header strong {
  font-family: var(--font-ui);
  font-size: 0.92rem;
  font-weight: 600;
  flex: 1;
  text-align: center;
}

.chat-actions {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-shrink: 0;
}

.chat-window {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 1rem 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  scroll-behavior: smooth;
}

.msg-row {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
}
.msg-row.ai { justify-content: flex-start; }
.msg-row.me { justify-content: flex-end; }

.msg-bubble {
  max-width: 82%;
  padding: 0.7rem 0.95rem;
  border-radius: 14px;
  font-size: 0.92rem;
  line-height: 1.6;
  word-break: break-word;
}
.msg-row.ai .msg-bubble {
  background: var(--surface);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
  color: var(--text);
}
.msg-row.me .msg-bubble {
  background: var(--accent-dim);
  color: #d8fffa;
  border-bottom-right-radius: 4px;
}
.msg-row.error .msg-bubble {
  background: rgba(224,79,79,.1);
  border: 1px solid rgba(224,79,79,.3);
  color: #f08080;
}

/* markdown inside AI bubbles */
.msg-bubble h1, .msg-bubble h2, .msg-bubble h3, .msg-bubble h4 {
  font-size: 1em;
  font-weight: 600;
  color: var(--text);
  margin: 0.6em 0 0.2em;
}
.msg-bubble p { margin: 0.3em 0; }
.msg-bubble ul, .msg-bubble ol {
  padding-left: 1.25rem;
  margin: 0.3em 0;
}
.msg-bubble li { margin: 0.15em 0; }
.msg-bubble strong { color: var(--text); }
.msg-bubble hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 0.6em 0;
}
.msg-bubble table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88em;
  margin: 0.4em 0;
}
.msg-bubble th, .msg-bubble td {
  border: 1px solid var(--border);
  padding: 0.3rem 0.5rem;
  text-align: left;
}
.msg-bubble th {
  background: var(--surface-2);
  font-weight: 600;
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

/* streaming cursor — shown while AI is mid-response */
.msg-bubble.streaming {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-glow);
}
.msg-bubble.streaming::after {
  content: "▋";
  color: var(--accent);
  animation: blink .85s step-end infinite;
  font-size: 0.8em;
  vertical-align: text-bottom;
  margin-left: 1px;
}
@keyframes blink {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0; }
}

/* typing indicator */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 3px;
  padding: 0.55rem 0.75rem;
}
.typing-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: typing-bounce 1.2s infinite;
}
.typing-dot:nth-child(2) { animation-delay: .2s; }
.typing-dot:nth-child(3) { animation-delay: .4s; }
@keyframes typing-bounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-5px); }
}

/* chat input bar */
.chat-input-bar {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--border);
  background: var(--bg);
  flex-shrink: 0;
}
.chat-input-bar textarea {
  flex: 1;
  resize: none;
  min-height: 40px;
  max-height: 160px;
  border-radius: var(--radius);
  font-size: 0.93rem;
  line-height: 1.45;
  padding: 0.55rem 0.8rem;
  overflow-y: auto;
}
.chat-input-bar button {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent);
  color: var(--accent-text);
  border: none;
  font-weight: 700;
}
.chat-input-bar button:disabled {
  background: var(--surface-2);
  color: var(--text-muted);
}
.chat-input-bar #stop-btn {
  background: rgba(224,79,79,.15);
  border: 1px solid rgba(224,79,79,.3);
  color: #e88;
}

/* ── 15. ALERTS & BANNERS ──────────────────────────────────────────── */
.phi-warning {
  background: rgba(26,127,212,.05);
  border-left: 3px solid rgba(26,127,212,.4);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  padding: 0.6rem 0.9rem;
  font-size: 0.82rem;
  color: var(--text-sub);
  margin-bottom: 1rem;
  line-height: 1.45;
}
.phi-warning strong { color: var(--text); }

.ai-unavail,
.alert {
  background: rgba(224,79,79,.08);
  border: 1px solid rgba(224,79,79,.25);
  border-radius: var(--radius-sm);
  padding: 0.7rem 0.9rem;
  font-size: 0.87rem;
  color: #f08080;
  margin-bottom: 1rem;
}

/* ── result entrance animation ────────────────────────────────────── */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
.dd-result, .drug-result, .dose-result, .sw-output,
.ppt-preview, .score-result, .history-qa {
  animation: fadeUp .28s ease;
}

/* ── 16. DIFFERENTIAL DIAGNOSIS ────────────────────────────────────── */
.dd-result {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-top: 1.25rem;
}

.dd-summary {
  background: rgba(0,191,165,.06);
  border-left: 3px solid var(--accent);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  padding: 0.8rem 1rem;
  font-size: 0.9rem;
  line-height: 1.55;
  color: var(--text);
}

.dd-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.9rem 1rem;
  box-shadow: 0 1px 4px rgba(0,0,0,.05);
  transition: border-color .15s, box-shadow .15s;
}
.dd-card:hover { border-color: var(--border-hi); box-shadow: 0 3px 10px rgba(0,0,0,.08); }

.dd-card.red {
  border-left: 3px solid var(--danger);
  background: rgba(224,79,79,.04);
}

.dd-card-head {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 0.45rem;
}

.dd-rank {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-dim);
  flex-shrink: 0;
}

.dd-dx {
  font-family: var(--font-ui);
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
  flex: 1 1 auto;
  min-width: 0;
}

.dd-likelihood {
  font-family: var(--font-ui);
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 0.2rem 0.55rem;
  border-radius: 99px;
  white-space: nowrap;
  flex-shrink: 0;
}
.dd-likelihood.high         { background: rgba(52,178,122,.15); color: var(--success); }
.dd-likelihood.moderate     { background: var(--amber-glow);   color: var(--amber); }
.dd-likelihood.low          { background: var(--surface-2);    color: var(--text-muted); }
.dd-likelihood.unspecified  { background: var(--surface-2);    color: var(--text-muted); }

.dd-section {
  font-family: var(--font-ui);
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
  margin: 0.9rem 0 0.4rem;
}
.dd-section.red { color: var(--danger); }

.dd-reason {
  font-size: 0.88rem;
  color: var(--text-sub);
  line-height: 1.5;
  margin-bottom: 0.4rem;
}

.dd-list {
  font-size: 0.87rem;
  color: var(--text-sub);
  line-height: 1.5;
  margin-top: 0.3rem;
}
.dd-list-label { font-weight: 600; color: var(--text-muted); }
.dd-list ul { padding-left: 1.1rem; margin: 0.15em 0; }
.dd-list.good ul li::marker { color: var(--success); }
.dd-list.bad  ul li::marker { color: var(--danger); }

.dd-mgmt {
  margin-top: 0.5rem;
  padding: 0.5rem 0.7rem;
  background: var(--accent-glow);
  border-radius: var(--radius-xs);
  font-size: 0.85rem;
  color: var(--text);
}
.dd-mgmt strong { color: var(--accent-dim); }

.dd-shared {
  padding-left: 1.1rem;
  font-size: 0.88rem;
  color: var(--text-sub);
  line-height: 1.55;
}

.dd-icd {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  padding: 0.1rem 0.35rem;
  color: var(--text-muted);
  flex-shrink: 0;
}

/* refine box */
.dd-refine-box {
  margin-top: 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.dd-refine-box summary {
  cursor: pointer;
  padding: 0.75rem 1rem;
  font-size: 0.88rem;
  font-weight: 500;
  color: var(--accent);
  list-style: none;
  user-select: none;
}
.dd-refine-box summary::-webkit-details-marker { display: none; }
.dd-refine-box[open] summary { border-bottom: 1px solid var(--border); }
.dd-refine-box[open] {
  border-color: var(--border-hi);
}
.dd-refine-box textarea {
  margin: 0.75rem 1rem 0.5rem;
  width: calc(100% - 2rem);
}
.dd-refine-box .muted {
  display: block;
  font-size: 0.8rem;
  padding: 0 1rem;
  margin-bottom: 0.5rem;
}

.refine-actions {
  padding: 0 1rem 0.75rem;
}
.refine-actions .primary-btn { width: auto; display: inline-flex; }

/* ── 17. DOSE & DRUG RESULTS ───────────────────────────────────────── */
.dose-result {
  margin-top: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}

.result-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: 0 1px 4px rgba(0,0,0,.05);
}
.result-card h3 {
  font-size: 0.83rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 0.4rem;
}
.result-card p, .result-card li { font-size: 0.9rem; color: var(--text-sub); }
.result-card ul { padding-left: 1.1rem; }

/* drug-specific */
.drug-result { margin-top: 1.25rem; }

.drug-head { margin-bottom: 0.7rem; }

.drug-name {
  font-family: var(--font-ui);
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 0.2rem;
}

.drug-class {
  font-size: 0.8rem;
  color: var(--text-muted);
  letter-spacing: 0.02em;
}

.drug-notes {
  margin-top: 0.7rem;
  padding: 0.6rem 0.8rem;
  background: var(--amber-glow);
  border-left: 3px solid var(--amber);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-size: 0.86rem;
  color: var(--text);
}
.drug-notes strong { color: var(--amber); }

.drug-dl {
  display: grid;
  grid-template-columns: minmax(6.5rem, auto) 1fr;
  gap: 0.3rem 0.9rem;
  margin: 0;
  font-size: 0.88rem;
}
.drug-dl dt {
  font-weight: 600;
  color: var(--text-muted);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding-top: 0.1rem;
}
.drug-dl dd { margin: 0; color: var(--text-sub); line-height: 1.5; }
.drug-dl dd.adj-specific {
  color: var(--text);
  background: var(--accent-glow);
  border-radius: var(--radius-xs);
  padding: 0.15rem 0.4rem;
}
.drug-dl dd.adj-avoid {
  color: var(--danger);
  background: rgba(208,48,48,.07);
  border-radius: var(--radius-xs);
  padding: 0.15rem 0.4rem;
}

/* interaction severity */
.se-serious { color: var(--danger); }
.se-serious li::marker { color: var(--danger); }

.drug-interactions { padding-left: 0; list-style: none; }
.drug-interactions li {
  padding: 0.55rem 0.7rem;
  margin-bottom: 0.4rem;
  background: var(--surface-2);
  border-left: 3px solid var(--border-hi);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}
.drug-interactions li:last-child { margin-bottom: 0; }
.int-drug {
  font-weight: 600;
  font-size: 0.87rem;
  color: var(--text);
}
.int-effect {
  font-size: 0.85rem;
  color: var(--text-sub);
  line-height: 1.45;
  margin-top: 0.1rem;
}
.int-action {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-top: 0.2rem;
}
.int-action strong { color: var(--accent-dim); }

/* dose result */
.dose-recommend { border-color: var(--accent); }

.dose-headline {
  font-family: var(--font-mono);
  font-size: 1.15rem;
  font-weight: 500;
  color: var(--accent-dim);
  line-height: 1.4;
  margin-bottom: 0.35rem;
}

.dose-calc {
  font-size: 0.83rem;
  color: var(--text-muted);
  line-height: 1.5;
  margin-top: 0.2rem;
}
.dose-calc strong { color: var(--text-sub); }

.dose-props {
  font-size: 0.84rem;
  color: var(--text-sub);
  margin-top: 0.45rem;
  padding-top: 0.45rem;
  border-top: 1px solid var(--border);
}
.dose-props strong { color: var(--text-muted); }

.dose-adj { padding-left: 1.1rem; font-size: 0.87rem; color: var(--text-sub); }
.dose-adj li { margin-bottom: 0.2rem; line-height: 1.5; }
.adj-type {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--amber);
  margin-right: 0.3rem;
}

.dose-crcl {
  font-size: 0.85rem;
  color: var(--text-sub);
  padding: 0.5rem 0.75rem;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
}
.dose-crcl strong { font-family: var(--font-mono); color: var(--text); }

.dose-max {
  font-size: 0.86rem;
  color: var(--text-sub);
  margin-bottom: 0.35rem;
}
.dose-max strong { color: var(--text); }

.dose-sublist { margin-top: 0.4rem; }
.dose-sublabel {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}
.dose-sublist ul {
  padding-left: 1.1rem;
  font-size: 0.86rem;
  color: var(--text-sub);
  line-height: 1.5;
}
.dose-sublist ul.adj-avoid { color: var(--danger); }
.dose-sublist ul.adj-avoid li::marker { color: var(--danger); }

.dose-ref {
  margin-top: 0.7rem;
  font-size: 0.78rem;
  color: var(--text-dim);
}

/* ── 18. SCORES ────────────────────────────────────────────────────── */

/* shared search bar — used in scores and guidelines */
.scores-search,
.tool-search {
  position: relative;
  margin-bottom: 1rem;
}
.scores-search input,
.tool-search input {
  padding-left: 2.4rem;
  font-size: 0.92rem;
}
.scores-search::before,
.tool-search::before {
  content: "⌕";
  position: absolute;
  left: 0.8rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: 1.15rem;
  pointer-events: none;
}

/* scores list */
.scores-list,
.score-list-grid {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

/* category header */
.score-category,
.score-category-label {
  font-family: var(--font-ui);
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  padding: 1.1rem 0 0.4rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 0.2rem;
  cursor: pointer;
  user-select: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.score-category::after {
  content: "▾";
  font-size: 0.8rem;
  transition: transform .2s;
}
.score-category.collapsed::after { transform: rotate(-90deg); }
.score-category .muted { font-weight: 400; text-transform: none; letter-spacing: 0; }

/* individual score card */
.score-card,
.score-item {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  text-decoration: none;
  color: var(--text);
  transition: border-color .15s, background .15s;
  position: relative;
  overflow: hidden;
}
.score-card:hover,
.score-item:hover {
  border-color: var(--border-hi);
  background: var(--surface-2);
  color: var(--text);
}
.score-card::after,
.score-item::after {
  content: "";
  position: absolute;
  bottom: 0; left: 0;
  height: 2px; width: 0;
  background: var(--accent);
  transition: width .3s cubic-bezier(.4,0,.2,1);
}
.score-card:hover::after,
.score-item:hover::after { width: 100%; }

.score-name,
.score-item-name {
  font-family: var(--font-ui);
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--text);
}
.score-desc,
.score-item-desc {
  font-size: 0.8rem;
  color: var(--text-muted);
  line-height: 1.4;
}
.score-item-abbr {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--accent);
}

/* score detail page */
.score-intro {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 0 var(--radius) var(--radius) 0;
  padding: 0.8rem 1rem;
  margin-bottom: 1.25rem;
  font-size: 0.88rem;
  color: var(--text-sub);
  line-height: 1.55;
}
.score-intro p { margin: 0; }
.score-intro small { display: block; margin-top: 0.4rem; font-size: 0.78rem; }

/* boolean field in score forms */
.bool-opt-wide {
  display: flex;
  align-items: flex-start;
  gap: 0.65rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.6rem 0.8rem;
  cursor: pointer;
  transition: border-color .12s, background .12s;
  font-size: 0.9rem;
  color: var(--text);
  font-family: var(--font-body);
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  margin: 0;
  line-height: 1.4;
}
.bool-opt-wide:hover { border-color: var(--border-hi); background: var(--surface-2); }
.bool-opt-wide input[type="checkbox"] {
  width: 16px; height: 16px;
  flex-shrink: 0;
  margin-top: 2px;
  accent-color: var(--accent);
  cursor: pointer;
}

/* score result */
.score-result {
  margin-top: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.score-headline {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.6rem 1rem 1.2rem;
  text-align: center;
}
.score-headline.success { border-top: 3px solid var(--success); }
.score-headline.warning { border-top: 3px solid var(--amber); }
.score-headline.danger  { border-top: 3px solid var(--danger); }
.score-headline.secondary { border-top: 3px solid var(--border-hi); }

/* JS outputs .score-num — support both names */
.score-number,
.score-num {
  font-family: var(--font-mono);
  font-size: 3rem;
  font-weight: 700;
  line-height: 1;
  margin-bottom: 0.35rem;
}
.score-headline.success .score-number,
.score-headline.success .score-num { color: var(--success); }
.score-headline.warning .score-number,
.score-headline.warning .score-num { color: var(--amber); }
.score-headline.danger  .score-number,
.score-headline.danger  .score-num { color: var(--danger); }
.score-headline.secondary .score-number,
.score-headline.secondary .score-num { color: var(--text-sub); }

.score-label {
  font-family: var(--font-ui);
  font-size: 0.85rem;
  color: var(--text-sub);
}

/* interpretation band below headline */
.score-interp {
  border-radius: var(--radius-sm);
  padding: 0.55rem 0.9rem;
  font-family: var(--font-ui);
  font-size: 0.88rem;
  font-weight: 600;
  text-align: center;
}
.score-interp.success  { background: rgba(30,158,98,.1);   color: var(--success); }
.score-interp.warning  { background: var(--amber-glow);    color: var(--amber); }
.score-interp.danger   { background: rgba(208,48,48,.1);   color: var(--danger); }
.score-interp.secondary { background: var(--surface-2);    color: var(--text-sub); }

/* breakdown */
.score-breakdown {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.score-breakdown summary {
  cursor: pointer;
  padding: 0.7rem 1rem;
  font-family: var(--font-ui);
  font-size: 0.82rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  list-style: none;
  user-select: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.score-breakdown summary::after { content: "▾"; transition: transform .2s; }
.score-breakdown[open] summary::after { transform: rotate(180deg); }
.score-breakdown summary::-webkit-details-marker { display: none; }
.score-breakdown[open] summary { border-bottom: 1px solid var(--border); }

.score-breakdown ul {
  list-style: none;
  padding: 0.4rem 0;
  margin: 0;
}
.score-breakdown ul li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.38rem 1rem;
  font-size: 0.87rem;
  color: var(--text-sub);
  border-bottom: 1px solid var(--border);
  gap: 0.5rem;
}
.score-breakdown ul li:last-child { border-bottom: none; }
.score-breakdown ul li span:last-child {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--accent);
  font-weight: 500;
  white-space: nowrap;
  flex-shrink: 0;
}

/* ── 19. GUIDELINES ────────────────────────────────────────────────── */

/* list page — reuse score-card pattern for consistency */
.guideline-list,
.scores-list:not(:has(.score-category)) { /* when no categories */
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

/* guideline card (same scan-line pattern as score-card) */
.guideline-item,
.scores-list .score-card { /* guidelines_list reuses score-card */
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.85rem 1rem;
  text-decoration: none;
  color: var(--text);
  transition: border-color .15s, background .15s;
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}
.guideline-item:hover,
.scores-list .score-card:hover {
  border-color: var(--border-hi);
  background: var(--surface-2);
  color: var(--text);
}

.guideline-title {
  font-family: var(--font-ui);
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--text);
}
.guideline-source,
.small-meta {
  font-size: 0.77rem;
  color: var(--text-muted);
}

.evidence-badge,
.gl-evidence {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.15rem 0.45rem;
  border-radius: var(--radius-xs);
  letter-spacing: 0.04em;
}
.evidence-badge.A, .gl-evidence { background: rgba(30,158,98,.12); color: var(--success); }
.evidence-badge.B              { background: rgba(77,166,255,.1);  color: var(--info); }
.evidence-badge.C              { background: var(--surface-2);    color: var(--text-muted); }
.evidence-badge.I              { background: var(--amber-glow);   color: var(--amber); }

/* ICD code chip */
.dd-icd {
  font-family: var(--font-mono);
  font-size: 0.74rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  padding: 0.1rem 0.38rem;
  color: var(--text-muted);
  vertical-align: middle;
}

/* guideline detail article */
.gl-article {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding-bottom: 1rem;
}

.gl-meta {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
  padding: 0.25rem 0 0.5rem;
}

.gl-overview {
  font-size: 0.92rem;
  color: var(--text-sub);
  line-height: 1.65;
  background: var(--surface);
  border-left: 3px solid var(--accent);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  padding: 0.8rem 1rem;
}

.gl-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.9rem 1rem;
}
.gl-section h2 {
  font-family: var(--font-ui);
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 0.7rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
}
.gl-section h3 {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-sub);
  margin: 0.75rem 0 0.35rem;
  font-family: var(--font-ui);
}
.gl-section ul {
  padding-left: 1.1rem;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}
.gl-section li {
  font-size: 0.88rem;
  color: var(--text-sub);
  line-height: 1.5;
}

.gl-redflags { border-left: 3px solid var(--danger); }
.gl-redflags h2 { color: var(--danger); border-bottom-color: rgba(208,48,48,.2); }
.gl-redflags li { color: #d06060; }

.gl-drug-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 0.5rem;
  font-size: 0.85rem;
}
.gl-drug-table th {
  background: var(--surface-2);
  text-align: left;
  padding: 0.4rem 0.65rem;
  font-family: var(--font-ui);
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}
.gl-drug-table td {
  padding: 0.45rem 0.65rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
  color: var(--text-sub);
  line-height: 1.45;
}
.gl-drug-table tr:last-child td { border-bottom: none; }
.gl-drug-table td strong { color: var(--text); font-weight: 600; }
.gl-drug-table .muted { color: var(--text-muted); font-size: 0.82rem; }

.gl-special {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.35rem 1rem;
  align-items: baseline;
}
.gl-special dt {
  font-family: var(--font-ui);
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
}
.gl-special dd {
  font-size: 0.87rem;
  color: var(--text-sub);
  line-height: 1.5;
  margin: 0;
}

/* ── 20. SCIWRITE & PPT ────────────────────────────────────────────── */
.sw-output, .ppt-preview {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem 1rem;
  margin-top: 1.25rem;
  font-size: 0.9rem;
  line-height: 1.7;
  color: var(--text);
}
.sw-output h1, .sw-output h2, .sw-output h3 {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--accent);
  margin: 0.9em 0 0.3em;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.sw-output p { margin: 0.4em 0; }
.sw-output blockquote {
  border-left: 3px solid var(--border-hi);
  padding-left: 0.9rem;
  margin: 0.5rem 0;
  color: var(--text-sub);
}
.sw-output cite {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* ── 21. CASES ─────────────────────────────────────────────────────── */
.cases-filter {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
}
.cases-filter label {
  font-size: 0.82rem;
  color: var(--text-muted);
  white-space: nowrap;
  text-transform: none;
  letter-spacing: 0;
  margin: 0;
}
.cases-filter select {
  width: auto;
  min-width: 130px;
  font-size: 0.87rem;
  padding: 0.4rem 2rem 0.4rem 0.7rem;
}

.cases-list {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.case-row {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.85rem 1rem;
  cursor: pointer;
  transition: border-color .15s, background .15s;
  text-decoration: none;
  color: var(--text);
  display: block;
  position: relative;
  overflow: hidden;
}
.case-row:hover { border-color: var(--border-hi); background: var(--surface-2); }
.case-row::after {
  content: "";
  position: absolute;
  bottom: 0; left: 0;
  height: 2px; width: 0;
  background: var(--accent);
  transition: width .3s cubic-bezier(.4,0,.2,1);
}
.case-row:hover::after { width: 100%; }

.case-row-body {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  min-width: 0;
}
.case-row-icon {
  font-size: 1.1rem;
  line-height: 1;
  flex-shrink: 0;
  margin-bottom: 0.35rem;
}
.case-row-title {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.case-row-meta {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.78rem;
  color: var(--text-muted);
}

/* case view */
.case-meta {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.82rem;
  margin-bottom: 0.5rem;
}

.case-body {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem;
  font-size: 0.9rem;
  line-height: 1.6;
  color: var(--text-sub);
  overflow-wrap: break-word;
}
.case-body h1, .case-body h2, .case-body h3 { font-family: var(--font-ui); color: var(--text); }
.case-body p { margin: 0.4em 0; }
.case-body ul, .case-body ol { padding-left: 1.2rem; }
.case-body table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
  margin: 0.6em 0;
}
.case-body th, .case-body td {
  border: 1px solid var(--border);
  padding: 0.35rem 0.5rem;
  text-align: left;
}
.case-body th { background: var(--surface-2); color: var(--text); }

.case-body .json-pre,
.json-pre {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  line-height: 1.5;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.75rem;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text-sub);
  margin: 0;
}

.case-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-top: 1rem;
}

/* ── 22. ACTIVITY ──────────────────────────────────────────────────── */
.activity-row {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.8rem 0.95rem;
  margin-bottom: 0.6rem;
  transition: border-color .15s;
}
.activity-row:hover { border-color: var(--border-hi); }

.activity-row-top {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  flex-wrap: wrap;
  font-size: 0.83rem;
  margin-bottom: 0.35rem;
}

.activity-icon { font-size: 1rem; }

.activity-mode {
  font-family: var(--font-ui);
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--accent);
}

.activity-status {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  font-weight: 600;
}
.activity-ok { color: var(--success); }
.activity-err { color: var(--danger); }

.activity-meta {
  font-family: var(--font-mono);
  font-size: 0.77rem;
  color: var(--text-muted);
}

.activity-date {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-dim);
  margin-left: auto;
}

.activity-prompt, .activity-response {
  font-size: 0.83rem;
  color: var(--text-muted);
  background: var(--surface-2);
  border-radius: var(--radius-xs);
  padding: 0.4rem 0.6rem;
  margin-top: 0.3rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.activity-error {
  font-size: 0.83rem;
  color: #f08080;
  background: rgba(224,79,79,.08);
  border-radius: var(--radius-xs);
  padding: 0.35rem 0.6rem;
  margin-top: 0.3rem;
}

.activity-full { margin-top: 0.5rem; }
.activity-full.hidden { display: none !important; }
.activity-pre {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.7rem;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--text-sub);
  white-space: pre-wrap;
  word-break: break-word;
  overflow-x: auto;
  max-height: 300px;
  overflow-y: auto;
  margin: 0.35rem 0;
}

.activity-expand {
  font-size: 0.78rem;
  padding: 0.2rem 0.6rem;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  color: var(--text-muted);
  cursor: pointer;
  margin-top: 0.35rem;
  font-family: var(--font-body);
  transition: border-color .12s, color .12s;
}
.activity-expand:hover { border-color: var(--border-hi); color: var(--text-sub); }

/* ── 23. CALCULATOR PANELS ─────────────────────────────────────────── */
.cp-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 0 var(--radius) var(--radius) 0;
  padding: 1rem;
  margin: 0.5rem 0;
}
.cp-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}
.cp-result {
  margin-top: 0.75rem;
  padding: 0.55rem 0.75rem;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 0.88rem;
  color: var(--text-sub);
}
.cp-result.result-a { color: var(--success); }
.cp-result.result-b { color: var(--amber); }
.cp-result.result-c { color: var(--danger); }

/* ── 24. ACTION ROWS ───────────────────────────────────────────────── */
.sw-actions {
  display: flex;
  gap: 0.6rem;
  margin-top: 1.25rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
}
.sw-actions .secondary-btn { flex: 1; min-width: 130px; justify-content: center; }

/* ── 25. HISTORY / Q&A ─────────────────────────────────────────────── */
.history-qa {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-top: 1.25rem;
}
.qa-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.85rem 1rem;
}
.qa-question {
  font-family: var(--font-ui);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 0.35rem;
}
.qa-answer {
  font-size: 0.9rem;
  color: var(--text-sub);
  line-height: 1.55;
}

/* ── 26. PAGINATION / LOAD MORE ────────────────────────────────────── */
#activity-pagination,
#cases-pagination {
  padding: 0.75rem 0;
  text-align: center;
}
#load-more, #cases-load-more {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-muted);
  font-size: 0.85rem;
  padding: 0.55rem 1.5rem;
  font-family: var(--font-ui);
  width: 100%;
}
#load-more:hover, #cases-load-more:hover {
  border-color: var(--border-hi);
  color: var(--text-sub);
}

/* ── 27. RESPONSIVE ────────────────────────────────────────────────── */
@media (max-width: 600px) {
  .tool-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.65rem;
  }
  .tool-card { min-height: 100px; padding: 0.85rem 0.75rem 0.75rem; }
  .tool-title { font-size: 0.83rem; }
  .tool-desc { display: none; }

  .form-grid,
  .form-row-inline { grid-template-columns: 1fr; }
  .cp-grid { grid-template-columns: 1fr; }

  .chat-header { flex-wrap: wrap; row-gap: 0.3rem; }
  .chat-actions { flex-wrap: wrap; }

  .msg-bubble { max-width: 92%; }

  .user-email { display: none; }

  .home-header { padding: 0.85rem 0 1.1rem; }
  .home { padding: 0 0.75rem 1.5rem; }
}

@media (max-width: 400px) {
  .tool-grid { grid-template-columns: repeat(2, 1fr); gap: 0.5rem; }
}

/* ── 28. FOCUS / A11Y ──────────────────────────────────────────────── */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ── 29. DARK MODE ─────────────────────────────────────────────────── */
@media (prefers-color-scheme: dark) {
  :root {
    --bg:           #060c18;
    --surface:      #0c1525;
    --surface-2:    #111e33;
    --surface-3:    #16253f;
    --border:       #1a2d47;
    --border-hi:    #264668;

    --text:         #c2d4ea;
    --text-sub:     #7191b5;
    --text-muted:   #44637f;
    --text-dim:     #263d54;

    --accent-text:  #021a17;

    --success:      #34b27a;
    --danger:       #e04f4f;
    --info:         #4da6ff;

    --shadow:       0 2px 14px rgba(0,0,0,.45);
    --shadow-lg:    0 6px 28px rgba(0,0,0,.6);
  }

  select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 6'%3E%3Cpath d='M0 0l5 6 5-6' fill='none' stroke='%237191b5' stroke-width='1.4'/%3E%3C/svg%3E");
  }

  .phi-warning { background: rgba(26,127,212,.06); color: var(--text-muted); }
  .phi-warning strong { color: var(--text); }

  .primary-btn { color: var(--accent-text); }

  .login-app {
    background:
      radial-gradient(ellipse 60% 50% at 60% 30%, rgba(0,191,165,.06), transparent),
      var(--bg);
  }
}

/* ── 30. HISTORY BUILDER ───────────────────────────────────────────── */
.history-trail {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.notes-trail {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-bottom: 0.75rem;
}
.notes-trail .note-chip {
  display: inline-flex;
  align-items: center;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 99px;
  padding: 0.2rem 0.65rem;
  font-size: 0.78rem;
  color: var(--text-muted);
  gap: 0.3rem;
}

.history-intro {
  background: var(--surface);
  border-left: 3px solid var(--accent);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  padding: 0.65rem 0.9rem;
  font-size: 0.88rem;
  color: var(--text-sub);
  margin-bottom: 1rem;
  line-height: 1.5;
}

#step-questions {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  margin-bottom: 1rem;
}

.physician-note-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 1rem;
}
.physician-note-box summary {
  cursor: pointer;
  padding: 0.65rem 0.9rem;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--accent);
  list-style: none;
  user-select: none;
}
.physician-note-box summary::-webkit-details-marker { display: none; }
.physician-note-box[open] summary { border-bottom: 1px solid var(--border); }
.physician-note-box textarea {
  margin: 0.65rem 0.9rem 0.5rem;
  width: calc(100% - 1.8rem);
}
.physician-note-box .muted {
  display: block;
  font-size: 0.79rem;
  padding: 0 0.9rem 0.65rem;
}

.complete-actions {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  margin-top: 1.25rem;
}
.complete-actions .primary-btn,
.complete-actions .secondary-btn {
  width: 100%;
  justify-content: center;
}

/* ── 31. REDUCED MOTION ────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .ecg-trace { animation: none; stroke-dashoffset: 0; }
  * { transition-duration: .01ms !important; animation-duration: .01ms !important; }
}

/* ═══════════════════════════════════════════════════════════════════
   32. RENDERED-OUTPUT CLASSES
   The renderers in static/js build their markup with these names. They were
   styled in a parallel stylesheet that was merged away, leaving whole results
   — the DDx list, the dose recommendation, the drug interactions, the PPT
   outline, the history trail — rendering as unstyled block flow.
   Run tools/css_audit.py to check this list against the markup again.
   ═══════════════════════════════════════════════════════════════════ */

/* Loading state — shown by dd, dose and drug while a request is in flight. */
.loading {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 1rem 0;
  color: var(--text-muted);
  font-size: 0.88rem;
}
.loading::before {
  content: "";
  width: 15px;
  height: 15px;
  flex-shrink: 0;
  border: 2px solid var(--border-hi);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Urgent presentation banner — the one thing that must never read as ordinary
   text, so it is the loudest element in the system. */
.urgent-banner {
  background: rgba(208,48,48,.10);
  border: 1px solid var(--danger);
  border-left: 4px solid var(--danger);
  border-radius: var(--radius);
  padding: 0.8rem 1rem;
  margin-bottom: 1rem;
}
.urgent-title {
  font-family: var(--font-ui);
  font-size: 0.92rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--danger);
}
.urgent-sub {
  font-size: 0.84rem;
  color: var(--text-sub);
  margin-top: 0.2rem;
  line-height: 1.45;
}

/* History trail */
.trail-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-top: 0.9rem;
  overflow: hidden;
}
.trail-box summary {
  cursor: pointer;
  padding: 0.6rem 0.9rem;
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--accent);
  background: var(--surface-2);
  list-style: none;
  user-select: none;
}
.trail-box summary::-webkit-details-marker { display: none; }
.trail-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem 0.75rem;
  padding: 0.5rem 0.9rem;
  border-top: 1px solid var(--border);
  font-size: 0.85rem;
  line-height: 1.5;
}
.trail-row:first-of-type { border-top: none; }
.trail-q { font-weight: 500; color: var(--text-muted); min-width: 8rem; }
.trail-a { color: var(--text-sub); flex: 1; min-width: 0; overflow-wrap: break-word; }
.trail-empty { color: var(--text-dim); font-style: italic; }
.note-step {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--accent-dim);
}
.note-text { color: var(--text-sub); width: 100%; }

/* Physician note box */
.note-text + .note-text { margin-top: 0.4rem; }

/* Question rendering in the History Builder */
.bool-row, .multi-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}
.multi-row { flex-direction: column; gap: 0.35rem; }
.bool-opt {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.87rem;
  color: var(--text-sub);
  cursor: pointer;
  text-transform: none;
  letter-spacing: 0;
  margin: 0;
  padding: 0.35rem 0.6rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.bool-opt:hover { border-color: var(--border-hi); }
.bool-opt input { width: auto; margin: 0; }
.bool-row { flex-direction: column; align-items: stretch; }

.form-row-group {
  padding: 0.85rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 0.8rem;
}
.form-row-group > legend,
.form-row-group > .group-label {
  font-family: var(--font-ui);
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
}

/* PPT preview */
.preview-slides {
  list-style: none;
  padding: 0;
  margin: 0.7rem 0 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  counter-reset: none;
}
.preview-slide {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--border-hi);
  border-radius: var(--radius-sm);
  padding: 0.65rem 0.85rem;
}
.preview-slide.preview-title, .preview-slide.preview-closing {
  border-left-color: var(--accent);
}
.preview-slide.preview-section { border-left-color: var(--amber); }
.preview-slide.preview-image   { border-left-color: var(--info); }
.preview-num {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--text-dim);
  margin-bottom: 0.15rem;
}
.preview-title {
  font-family: var(--font-ui);
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
}
.preview-type {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-dim);
  margin-top: 0.1rem;
}
.preview-body ul {
  padding-left: 1.1rem;
  margin: 0.35rem 0 0;
  font-size: 0.85rem;
  color: var(--text-sub);
  line-height: 1.5;
}
.preview-notes {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 0.35rem;
  padding-top: 0.3rem;
  border-top: 1px dashed var(--border);
}
.preview-header {
  padding-bottom: 0.6rem;
  border-bottom: 1px solid var(--border);
}
.preview-deck-title {
  font-family: var(--font-ui);
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text);
}
.preview-deck-subtitle {
  font-size: 0.87rem;
  color: var(--text-sub);
  margin-top: 0.15rem;
}
.preview-count {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--text-dim);
  margin-top: 0.25rem;
}

/* PubMed reference list */
.sw-refs {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.9rem 1rem;
  margin-top: 0.9rem;
}
.sw-refs h3 {
  font-family: var(--font-ui);
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}
.sw-refs ol { padding-left: 1.2rem; }
.sw-refs li { margin-bottom: 0.55rem; font-size: 0.85rem; line-height: 1.5; }
.sw-refs a { color: var(--accent); text-decoration: none; }
.sw-refs a:hover { text-decoration: underline; }
.ref-title { color: var(--text-sub); margin-top: 0.15rem; }
.ref-journal { font-style: italic; color: var(--text-muted); font-size: 0.8rem; }
.ref-pubtype {
  font-size: 0.72rem;
  color: var(--text-dim);
  margin-left: 0.3rem;
}

/* Chat per-message copy button */
.bubble-copy {
  position: absolute;
  top: 0.4rem;
  right: 0.4rem;
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  line-height: 1;
  color: var(--text-dim);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  cursor: pointer;
  opacity: 0;
  transition: opacity .15s, color .15s;
}
.msg-row:hover .bubble-copy,
.bubble-copy:focus-visible { opacity: 1; }
.bubble-copy:hover { color: var(--accent); border-color: var(--border-hi); }

.ai-markdown > *:first-child { margin-top: 0; }
.ai-markdown > *:last-child  { margin-bottom: 0; }

/* Login errors and form controls */
.login-error {
  color: var(--danger);
  font-size: 0.83rem;
  margin-top: 0.6rem;
  padding: 0.45rem 0.6rem;
  background: rgba(208,48,48,.08);
  border-radius: var(--radius-sm);
}
.block { display: block; width: 100%; }
.block + .block { margin-top: 0.5rem; }

input[aria-invalid="true"],
textarea[aria-invalid="true"],
select[aria-invalid="true"] {
  border-color: var(--danger);
  background: rgba(208,48,48,.05);
}

/* Small shared bits */
.tool-header-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.5rem;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.87rem;
  color: var(--text-sub);
  cursor: pointer;
  text-transform: none;
  letter-spacing: 0;
  margin: 0;
}
.checkbox-row input { width: auto; margin: 0; }

.opt { display: block; }

.tool-intro {
  font-size: 0.88rem;
  color: var(--text-muted);
  line-height: 1.55;
  margin-bottom: 0.9rem;
}

.outline {
  background: transparent;
  border: 1px solid var(--border-hi);
  color: var(--text-sub);
}
.outline:hover { background: var(--surface-2); }

.ppt-app, .sciwrite-app { max-width: var(--tool-max-w); margin: 0 auto; }

.ppt-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-top: 1.25rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}
