/* =============================================================
   MedSNOMED — Clean Minimal
   Aesthetic: white ground, DM Sans, clinical cyan
   ============================================================= */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  /* Palette */
  --bg:           #ffffff;
  --surface:      #f6f7f9;
  --surface-2:    #eef0f4;
  --ink:          #111318;
  --ink-mid:      #3d4147;
  --muted:        #9399a6;
  --rule:         #e4e6eb;
  --rule-light:   #eff0f3;
  --accent:       #0891b2;
  --accent-pale:  #f0fafd;
  --accent-mid:   #0e7490;
  --red:          #dc2626;

  /* Typography */
  --sans:  'DM Sans', 'Segoe UI', sans-serif;
  --serif: 'Spectral', Georgia, serif;
  --mono:  'Fira Code', 'Courier New', monospace;

  /* Layout */
  --sw: 256px;
  --content-w: 680px;
  --radius: 6px;
}

html, body {
  height: 100%;
  font-family: var(--sans);
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

body { display: flex; overflow: hidden; }

/* =============================================================
   SIDEBAR
   ============================================================= */

.sidebar {
  width: var(--sw);
  min-width: var(--sw);
  background: var(--surface);
  border-right: 1px solid var(--rule);
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow-y: auto;
  overflow-x: hidden;
  transition: transform .22s ease, width .22s ease, min-width .22s ease;
  flex-shrink: 0;
}

.sidebar.collapsed {
  transform: translateX(calc(-1 * var(--sw)));
  width: 0;
  min-width: 0;
}

.sidebar-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 16px 14px;
  border-bottom: 1px solid var(--rule);
}

.brand {
  font-family: var(--serif);
  font-style: italic;
  font-weight: 600;
  font-size: 16px;
  letter-spacing: -0.01em;
  color: var(--ink);
}

.ghost-btn {
  background: none;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  cursor: pointer;
  font-family: var(--sans);
  font-size: 11px;
  font-weight: 500;
  color: var(--muted);
  padding: 4px 10px;
  letter-spacing: 0.02em;
  transition: border-color .15s, color .15s;
}
.ghost-btn:hover { color: var(--ink); border-color: var(--ink-mid); }

.sidebar-section {
  padding: 14px 16px;
  border-bottom: 1px solid var(--rule-light);
}

.section-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 10px;
}

/* Upload zone */
.upload-zone {
  border: 1px dashed var(--rule);
  border-radius: var(--radius);
  padding: 12px 10px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 3px;
  transition: border-color .15s, background .15s;
}
.upload-zone:hover, .upload-zone.drag-over {
  border-color: var(--accent);
  background: var(--accent-pale);
}
.upload-label { font-size: 12px; font-weight: 500; color: var(--ink-mid); }
.upload-sub   { font-size: 10px; color: var(--muted); }

.uploaded-file { display: flex; flex-direction: column; gap: 3px; }
.file-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.file-name { font-size: 12px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.file-meta { font-size: 10px; color: var(--muted); }
.remove-btn { font-size: 15px; line-height: 1; flex-shrink: 0; border: none; }

/* Quick questions */
.quick-questions { display: flex; flex-direction: column; gap: 1px; }
.quick-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-family: var(--sans);
  font-size: 12px;
  font-weight: 400;
  color: var(--muted);
  text-align: left;
  padding: 6px 0;
  transition: color .15s;
}
.quick-btn:hover { color: var(--accent); }

.sidebar-footer {
  margin-top: auto;
  padding: 14px 16px;
  font-size: 10px;
  color: var(--muted);
  letter-spacing: 0.02em;
  border-top: 1px solid var(--rule-light);
}

/* =============================================================
   MAIN
   ============================================================= */

.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  min-width: 0;
  background: var(--bg);
}

/* Topbar */
.topbar {
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  border-bottom: 1px solid var(--rule);
  background: var(--bg);
  flex-shrink: 0;
}

.icon-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--muted);
  padding: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color .15s;
  margin: -6px;
  border-radius: 4px;
}
.icon-btn:hover { color: var(--ink); background: var(--surface); }

.topbar-snomed {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.1em;
  color: var(--accent);
  text-transform: uppercase;
  opacity: .8;
}

/* =============================================================
   CHAT AREA
   ============================================================= */

.chat-area {
  flex: 1;
  overflow-y: auto;
  scroll-behavior: smooth;
  padding: 0 0 24px;
}

.chat-area::-webkit-scrollbar { width: 4px; }
.chat-area::-webkit-scrollbar-thumb { background: var(--rule); border-radius: 2px; }

/* Welcome */
.welcome {
  max-width: var(--content-w);
  margin: 64px auto 0;
  padding: 0 24px;
}

.welcome-title {
  font-family: var(--serif);
  font-style: italic;
  font-weight: 600;
  font-size: 44px;
  line-height: 1.1;
  letter-spacing: -0.02em;
  color: var(--ink);
  margin-bottom: 14px;
  animation: rise .45s ease both;
}

.welcome-sub {
  font-size: 14px;
  font-weight: 400;
  color: var(--muted);
  line-height: 1.7;
  max-width: 460px;
  animation: rise .45s .07s ease both;
}

.welcome-divider {
  width: 24px;
  height: 2px;
  background: var(--accent);
  margin: 22px 0;
  opacity: .4;
  animation: rise .45s .13s ease both;
}

.welcome-hint {
  font-size: 12px;
  color: var(--muted);
  animation: rise .45s .17s ease both;
}
.welcome-hint em {
  color: var(--ink-mid);
  font-style: normal;
  font-weight: 500;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: none; }
}

/* =============================================================
   MESSAGES
   ============================================================= */

.messages {
  max-width: var(--content-w);
  margin: 0 auto;
  padding: 28px 24px 0;
}

.message {
  margin-bottom: 28px;
  animation: rise .16s ease both;
}

/* User message */
.message.user { display: flex; justify-content: flex-end; }

.message.user .message-bubble {
  max-width: 72%;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: 14px;
  line-height: 1.6;
}

/* PDF attached badge */
.pdf-attached-badge {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 10px;
  font-weight: 500;
  color: var(--accent);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin-bottom: 6px;
}
.pdf-attached-badge svg {
  width: 11px;
  height: 11px;
  flex-shrink: 0;
}

/* Assistant message */
.message.assistant .message-bubble {
  width: 100%;
  padding-left: 14px;
  border-left: 2px solid var(--rule);
  transition: border-color .2s;
}
.message.assistant .message-bubble:hover {
  border-left-color: var(--accent);
}

/* Markdown inside assistant messages */
.message-content {
  font-size: 14px;
  font-weight: 400;
  line-height: 1.75;
  color: var(--ink);
}

.message-content h1 {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 20px;
  line-height: 1.3;
  margin: 22px 0 10px;
  color: var(--ink);
}
.message-content h2 {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 16px;
  line-height: 1.35;
  margin: 18px 0 7px;
  color: var(--ink-mid);
}
.message-content h3 {
  font-family: var(--sans);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  margin: 16px 0 5px;
  color: var(--muted);
}
.message-content p { margin-bottom: 10px; }
.message-content p:last-child { margin-bottom: 0; }
.message-content ul,
.message-content ol { margin: 6px 0 10px 18px; }
.message-content li { margin-bottom: 4px; }
.message-content strong { font-weight: 600; color: var(--ink); }
.message-content em { font-style: italic; color: var(--ink-mid); }
.message-content a { color: var(--accent); text-underline-offset: 2px; }
.message-content a:hover { color: var(--accent-mid); }
.message-content code {
  font-family: var(--mono);
  font-size: 12px;
  background: var(--surface);
  padding: 1px 5px;
  border: 1px solid var(--rule);
  border-radius: 3px;
  color: var(--accent-mid);
}
.message-content pre {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 12px 14px;
  overflow-x: auto;
  margin: 10px 0;
}
.message-content pre code {
  background: none;
  border: none;
  padding: 0;
  color: var(--ink-mid);
}
.message-content blockquote {
  border-left: 2px solid var(--rule);
  padding: 3px 0 3px 12px;
  color: var(--muted);
  font-style: italic;
  margin: 10px 0;
}
.message-content hr {
  border: none;
  border-top: 1px solid var(--rule);
  margin: 18px 0;
}
.message-content table {
  width: 100%;
  border-collapse: collapse;
  margin: 12px 0;
  font-size: 13px;
}
.message-content th {
  font-weight: 600;
  text-align: left;
  padding: 7px 10px;
  border-bottom: 1px solid var(--rule);
  color: var(--ink-mid);
  background: var(--surface);
}
.message-content td {
  padding: 6px 10px;
  border-bottom: 1px solid var(--rule-light);
  color: var(--ink-mid);
}

/* Streaming cursor */
.cursor-blink::after {
  content: '▋';
  animation: blink .65s step-end infinite;
  color: var(--accent);
  font-size: 0.85em;
  margin-left: 1px;
  vertical-align: baseline;
}
@keyframes blink { 0%,100%{opacity:1} 50%{opacity:0} }

/* =============================================================
   SNOMED CHIPS
   ============================================================= */

.snomed-section {
  margin-top: 14px;
  padding-top: 10px;
  border-top: 1px solid var(--rule-light);
}

.snomed-section-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 7px;
}

.snomed-chips { display: flex; flex-wrap: wrap; gap: 5px; }

.snomed-chip {
  background: var(--bg);
  border: 1px solid var(--rule);
  border-radius: 4px;
  padding: 3px 9px;
  font-family: var(--mono);
  font-size: 10px;
  color: var(--muted);
  cursor: pointer;
  transition: border-color .15s, color .15s, background .15s;
  letter-spacing: 0.02em;
}
.snomed-chip:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-pale);
}
.snomed-chip-id {
  opacity: .5;
  margin-left: 5px;
  font-size: 9px;
}

/* =============================================================
   THINKING INDICATOR
   ============================================================= */

.thinking {
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: var(--content-w);
  margin: 0 auto 16px;
  padding: 0 24px 0 38px;
  font-size: 12px;
  color: var(--muted);
  font-family: var(--sans);
}

.thinking-dots { display: flex; gap: 3px; align-items: center; }
.thinking-dot {
  width: 4px; height: 4px;
  background: var(--accent);
  border-radius: 50%;
  animation: pulse 1.1s ease-in-out infinite;
  opacity: .4;
}
.thinking-dot:nth-child(2) { animation-delay: .15s; }
.thinking-dot:nth-child(3) { animation-delay: .30s; }
@keyframes pulse { 0%,80%,100%{opacity:.25; transform:scale(.8)} 40%{opacity:.9; transform:scale(1)} }

/* =============================================================
   INPUT AREA
   ============================================================= */

.input-area {
  padding: 10px 20px 18px;
  border-top: 1px solid var(--rule);
  background: var(--bg);
  flex-shrink: 0;
}

.active-pdf {
  max-width: var(--content-w);
  margin: 0 auto 7px;
  font-size: 11px;
  font-weight: 500;
  color: var(--accent-mid);
  display: flex;
  align-items: center;
  gap: 5px;
}
.pdf-icon { font-size: 12px; opacity: .6; }
.active-pdf-label { color: var(--muted); font-weight: 400; }

.input-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  max-width: var(--content-w);
  margin: 0 auto;
  background: var(--bg);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 10px 12px;
  transition: border-color .2s, box-shadow .2s;
}
.input-row:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(8, 145, 178, .08);
}

textarea {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: var(--ink);
  font-family: var(--sans);
  font-size: 14px;
  font-weight: 400;
  line-height: 1.5;
  resize: none;
  max-height: 160px;
  overflow-y: auto;
}
textarea::placeholder { color: var(--muted); font-style: italic; }
textarea::-webkit-scrollbar { width: 3px; }
textarea::-webkit-scrollbar-thumb { background: var(--rule); }

.send-btn {
  background: var(--accent);
  border: none;
  border-radius: 5px;
  cursor: pointer;
  color: #ffffff;
  padding: 5px 7px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background .15s, opacity .15s;
}
.send-btn:hover:not(:disabled) { background: var(--accent-mid); }
.send-btn:disabled { opacity: .3; cursor: not-allowed; }

.input-footer {
  display: flex;
  justify-content: space-between;
  max-width: var(--content-w);
  margin: 5px auto 0;
  font-size: 10px;
  color: var(--muted);
  letter-spacing: 0.02em;
}

/* =============================================================
   MODAL
   ============================================================= */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(17, 19, 24, 0.4);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: fadein .15s ease;
}
@keyframes fadein { from{opacity:0} to{opacity:1} }

.modal {
  background: var(--bg);
  border: 1px solid var(--rule);
  border-radius: 10px;
  width: 90%;
  max-width: 520px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: rise .18s ease both;
  box-shadow: 0 8px 48px rgba(17,19,24,.12);
}

.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 16px 18px 13px;
  border-bottom: 1px solid var(--rule);
}
.modal-title {
  font-family: var(--serif);
  font-style: italic;
  font-size: 16px;
  font-weight: 600;
  line-height: 1.3;
  color: var(--ink);
}
.modal-subtitle {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--muted);
  margin-top: 3px;
  letter-spacing: 0.05em;
}

.modal-body {
  padding: 16px 18px;
  overflow-y: auto;
  font-size: 13px;
  font-weight: 400;
  line-height: 1.6;
}
.modal-body::-webkit-scrollbar { width: 4px; }
.modal-body::-webkit-scrollbar-thumb { background: var(--rule); border-radius: 2px; }

.concept-row { margin-bottom: 14px; }
.concept-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 4px;
}
.concept-value { color: var(--ink-mid); line-height: 1.6; }
.concept-id {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--accent);
  letter-spacing: 0.04em;
}

.concept-tags { display: flex; flex-wrap: wrap; gap: 4px; }
.concept-tag {
  border: 1px solid var(--rule);
  border-radius: 3px;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 400;
  color: var(--muted);
}

.snomed-link {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--accent);
  font-size: 11px;
  font-weight: 500;
  text-decoration: none;
  margin-top: 12px;
  letter-spacing: 0.03em;
}
.snomed-link:hover { color: var(--accent-mid); text-decoration: underline; text-underline-offset: 3px; }
.snomed-link svg { width: 11px; height: 11px; }

/* Loading */
.loading-spinner {
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--muted);
  font-size: 12px;
}
.spinner {
  width: 14px;
  height: 14px;
  border: 1.5px solid var(--rule);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* =============================================================
   UTILITIES
   ============================================================= */

.hidden { display: none !important; }

/* =============================================================
   RESPONSIVE
   ============================================================= */

@media (max-width: 640px) {
  :root { --sw: 100vw; }
  .sidebar { position: fixed; top: 0; left: 0; height: 100vh; z-index: 200; }
  .sidebar:not(.collapsed) { box-shadow: 4px 0 32px rgba(17,19,24,.12); }
  .message.user .message-bubble { max-width: 88%; }
  .welcome-title { font-size: 34px; }
}
