/* ---------- tokens ---------- */
:root {
  --sidebar-w: 268px;
  --radius: 14px;
  --font: "Söhne", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto,
    "Noto Sans Georgian", "Noto Sans", Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

[data-theme="dark"] {
  --bg: #212121;
  --bg-side: #171717;
  --bg-elev: #2f2f2f;
  --bg-hover: #2a2a2a;
  --text: #ececec;
  --text-dim: #a1a1a1;
  --line: #3a3a3a;
  --accent: #4a94dd;
  --accent-ink: #0b1a2b;
  --danger: #f26d6d;
  --bubble-user: #303030;
}

[data-theme="light"] {
  --bg: #ffffff;
  --bg-side: #f9f9f9;
  --bg-elev: #ffffff;
  --bg-hover: #ececec;
  --text: #0d0d0d;
  --text-dim: #6b6b6b;
  --line: #e3e3e3;
  --accent: #1c68b3;
  --accent-ink: #ffffff;
  --danger: #d93a3a;
  --bubble-user: #f0f0f0;
}

* { box-sizing: border-box; }

/* Class-based display rules outrank the UA [hidden] style, so restate it. */
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

button { font: inherit; color: inherit; cursor: pointer; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- brand ---------- */
[data-theme="dark"] .light-only { display: none; }
[data-theme="light"] .dark-only { display: none; }

.brand {
  display: block;
  padding: 12px 10px 4px;
}
.brand-logo {
  width: 100%;
  max-width: 190px;
  height: auto;
  display: block;
}

.topbar-logo {
  height: 26px;
  width: auto;
  max-width: 200px;
}

.welcome-logo {
  width: min(320px, 76%);
  height: auto;
  margin: 0 auto 26px;
}

/* ---------- layout ---------- */
.app { display: flex; height: 100dvh; }

.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: var(--bg-side);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  padding: 10px;
  gap: 10px;
}

.sidebar-head { display: flex; gap: 6px; }

.new-chat {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-size: 14px;
  transition: background .15s ease;
}
.new-chat:hover { background: var(--bg-hover); }

.sidebar .sidebar-close { display: none; }

.history {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding-top: 6px;
}

.history-label {
  font-size: 12px;
  color: var(--text-dim);
  padding: 8px 10px 4px;
  letter-spacing: .02em;
}

.history-item {
  text-align: left;
  background: transparent;
  border: 0;
  padding: 9px 10px;
  border-radius: 10px;
  font-size: 14px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.history-item:hover { background: var(--bg-hover); }
.history-item[aria-current="true"] { background: var(--bg-hover); }

.sidebar-foot {
  border-top: 1px solid var(--line);
  padding-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.field-label {
  display: block;
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 6px;
  padding-left: 2px;
}

.select-wrap { position: relative; }

.select-wrap select {
  width: 100%;
  appearance: none;
  background: var(--bg-elev);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 34px 10px 12px;
  font: inherit;
  font-size: 14px;
  cursor: pointer;
}

.chev {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
  color: var(--text-dim);
  width: 16px;
  height: 16px;
}

.toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  cursor: pointer;
  padding: 4px 2px;
}
.toggle input { position: absolute; opacity: 0; pointer-events: none; }

.track {
  width: 34px;
  height: 20px;
  border-radius: 999px;
  background: var(--line);
  position: relative;
  flex: 0 0 auto;
  transition: background .18s ease;
}
.thumb {
  position: absolute;
  top: 2px; left: 2px;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: #fff;
  transition: transform .18s ease;
}
.toggle input:checked + .track { background: var(--accent); }
.toggle input:checked + .track .thumb { transform: translateX(14px); }
.toggle input:focus-visible + .track { outline: 2px solid var(--accent); outline-offset: 2px; }

.icon-row {
  display: flex;
  align-items: center;
  gap: 10px;
  background: transparent;
  border: 0;
  padding: 9px 2px;
  border-radius: 10px;
  font-size: 14px;
  color: var(--text-dim);
}
.icon-row:hover { color: var(--text); }
[data-theme="dark"] .icon-sun { display: block; }
[data-theme="dark"] .icon-moon { display: none; }
[data-theme="light"] .icon-sun { display: none; }
[data-theme="light"] .icon-moon { display: block; }

.sidebar-scrim { display: none; }

/* ---------- main ---------- */
.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-bottom: 1px solid transparent;
}

.topbar-title {
  flex: 1;
  font-size: 15px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}

.topbar-name {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.model-chip {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-dim);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 9px;
}

.icon-btn {
  background: transparent;
  border: 0;
  padding: 8px;
  border-radius: 10px;
  color: var(--text-dim);
  display: inline-flex;
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text); }
.topbar #sidebarOpen, .topbar #newChatTop { display: none; }
.topbar .topbar-logo { display: none; }

.thread {
  flex: 1;
  overflow-y: auto;
  scroll-behavior: smooth;
  padding: 8px 0 20px;
}

/* ---------- welcome ---------- */
.welcome {
  max-width: 720px;
  margin: 0 auto;
  padding: 8vh 20px 0;
  text-align: center;
}

.welcome h1 {
  font-size: 28px;
  font-weight: 600;
  margin: 0 0 8px;
  letter-spacing: -0.01em;
}

.welcome p {
  color: var(--text-dim);
  font-size: 15px;
  margin: 0 auto 26px;
  max-width: 460px;
  line-height: 1.5;
}


/* ---------- messages ---------- */
.msg {
  max-width: 760px;
  margin: 0 auto;
  padding: 14px 20px;
  display: flex;
  gap: 14px;
  animation: rise .22s ease both;
}

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

.msg.user { justify-content: flex-end; }

.msg.user .bubble {
  background: var(--bubble-user);
  padding: 11px 16px;
  border-radius: 20px;
  max-width: 85%;
}

.avatar {
  width: 28px;
  height: 28px;
  flex: 0 0 28px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  color: var(--accent);
  margin-top: 2px;
}
.avatar svg { width: 15px; height: 15px; }

.bubble {
  min-width: 0;
  font-size: 15.5px;
  line-height: 1.65;
  word-wrap: break-word;
}

.bubble p { margin: 0 0 12px; }
.bubble p:last-child { margin-bottom: 0; }
.bubble ul, .bubble ol { margin: 0 0 12px; padding-left: 22px; }
.bubble li { margin-bottom: 4px; }
.bubble code {
  font-family: var(--mono);
  font-size: .88em;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 1px 5px;
}
.bubble pre {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 13px 15px;
  overflow-x: auto;
  margin: 0 0 12px;
}
.bubble pre code { background: none; border: 0; padding: 0; font-size: 13px; }
.bubble h1, .bubble h2, .bubble h3 { font-size: 1.05em; margin: 16px 0 8px; }

.voice-tag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11.5px;
  color: var(--text-dim);
  margin-bottom: 5px;
}
.voice-tag svg { width: 12px; height: 12px; }

.msg-tools {
  display: flex;
  gap: 4px;
  margin-top: 8px;
  opacity: 0;
  transition: opacity .15s ease;
}
.msg:hover .msg-tools, .msg-tools:focus-within { opacity: 1; }

.tool-btn {
  background: transparent;
  border: 0;
  padding: 5px;
  border-radius: 7px;
  color: var(--text-dim);
}
.tool-btn:hover { background: var(--bg-hover); color: var(--text); }
.tool-btn svg { width: 15px; height: 15px; }
.tool-btn.on { color: var(--accent); }

.cursor {
  display: inline-block;
  width: 7px;
  height: 16px;
  background: var(--text);
  vertical-align: text-bottom;
  margin-left: 2px;
  animation: blink 1s steps(2) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

.typing { display: inline-flex; gap: 4px; padding: 6px 0; }
.typing i {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--text-dim);
  animation: bounce 1.1s infinite;
}
.typing i:nth-child(2) { animation-delay: .16s; }
.typing i:nth-child(3) { animation-delay: .32s; }
@keyframes bounce {
  0%, 70%, 100% { transform: translateY(0); opacity: .45; }
  35% { transform: translateY(-4px); opacity: 1; }
}

/* ---------- composer ---------- */
.composer-area {
  padding: 0 20px 10px;
  background: linear-gradient(to top, var(--bg) 65%, transparent);
}

.banner {
  max-width: 760px;
  margin: 0 auto 10px;
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 13.5px;
  background: color-mix(in srgb, var(--danger) 14%, var(--bg));
  border: 1px solid color-mix(in srgb, var(--danger) 40%, transparent);
  color: var(--text);
}

.composer {
  max-width: 760px;
  margin: 0 auto;
}

.composer-inner {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 26px;
  padding: 8px 8px 8px 18px;
  transition: border-color .15s ease;
}
.composer-inner:focus-within { border-color: color-mix(in srgb, var(--accent) 55%, var(--line)); }

#input {
  flex: 1;
  border: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 15.5px;
  line-height: 1.5;
  resize: none;
  max-height: 180px;
  padding: 9px 0;
  outline: none;
}
#input::placeholder { color: var(--text-dim); }

.composer-actions { display: flex; gap: 6px; align-items: center; }

.mic, .send {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 0;
  display: grid;
  place-items: center;
  flex: 0 0 38px;
  transition: background .15s ease, transform .12s ease, opacity .15s ease;
}

.mic { background: transparent; color: var(--text-dim); }
.mic:hover { background: var(--bg-hover); color: var(--text); }
.mic .icon-stop { display: none; }

.mic.recording {
  background: var(--danger);
  color: #fff;
  animation: pulse 1.4s ease-in-out infinite;
}
.mic.recording .icon-mic { display: none; }
.mic.recording .icon-stop { display: block; }

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--danger) 55%, transparent); }
  50% { box-shadow: 0 0 0 7px transparent; }
}

.send { background: var(--accent); color: var(--accent-ink); }
.send:disabled { opacity: .35; cursor: not-allowed; }
.send:not(:disabled):hover { transform: scale(1.05); }

.recorder {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 9px;
  padding: 9px 16px;
  border-radius: 999px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  font-size: 13.5px;
  color: var(--text-dim);
}

.rec-dot {
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--danger);
  flex: 0 0 auto;
  animation: blink 1.1s ease-in-out infinite;
}
.rec-label { flex: 0 0 auto; color: var(--text); }
.wave { flex: 1; height: 28px; min-width: 60px; }
.rec-time { font-variant-numeric: tabular-nums; flex: 0 0 auto; }
.rec-cancel {
  background: transparent;
  border: 0;
  color: var(--text-dim);
  text-decoration: underline;
  padding: 2px;
  font-size: 13px;
}
.rec-cancel:hover { color: var(--text); }

.disclaimer {
  max-width: 760px;
  margin: 9px auto 0;
  text-align: center;
  font-size: 11.5px;
  color: var(--text-dim);
}

/* ---------- responsive ---------- */
@media (max-width: 860px) {
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 30;
    transform: translateX(-100%);
    transition: transform .22s ease;
  }
  .sidebar.open { transform: none; }
  .sidebar .sidebar-close { display: inline-flex; }
  .sidebar-scrim {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.5);
    z-index: 25;
    opacity: 0;
    pointer-events: none;
    transition: opacity .22s ease;
  }
  .sidebar-scrim.show { opacity: 1; pointer-events: auto; }
  .topbar #sidebarOpen, .topbar #newChatTop { display: inline-flex; }
  [data-theme="dark"] .topbar .topbar-logo.dark-only,
  [data-theme="light"] .topbar .topbar-logo.light-only { display: block; }
  .topbar-name { display: none; }
  .topbar { border-bottom-color: var(--line); }
  .welcome { padding-top: 6vh; }
  .brand { display: none; }
  .welcome h1 { font-size: 23px; }
  .msg { padding: 12px 14px; }
  .composer-area { padding: 0 12px 8px; }
  .recorder { gap: 9px; padding: 8px 12px; }
  .wave { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
    scroll-behavior: auto !important;
  }
}

/* ---------- radiology report output ---------- */
/* Reports are Word-bound, so they render on a paper surface in both themes.
   This keeps bold/underline legible and previews what actually gets pasted. */
.bubble .body.report {
  background: #ffffff;
  color: #111111;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 26px 30px;
  margin-top: 2px;
  font-family: "Times New Roman", Times, Georgia, serif;
  font-size: 15px;
  line-height: 1.5;
}

.bubble .body.report p { margin: 0 0 8px; }
.bubble .body.report u { text-decoration: underline; }
.bubble .body.report ul,
.bubble .body.report ol { margin: 0 0 10px; padding-left: 26px; }
.bubble .body.report li { margin-bottom: 3px; }
.bubble .body.report table { border-collapse: collapse; width: 100%; margin: 0 0 10px; }
.bubble .body.report td,
.bubble .body.report th { border: 1px solid #c9c9c9; padding: 5px 8px; }
.bubble .body.report h1,
.bubble .body.report h2,
.bubble .body.report h3 { font-size: 1.05em; margin: 14px 0 7px; }

/* Report mode is a document workspace — give it the full column width. */
body[data-mode="report"] .msg { max-width: 900px; }

body[data-mode="report"] .disclaimer {
  color: var(--danger);
  font-weight: 500;
}

@media (max-width: 860px) {
  .bubble .body.report { padding: 18px 16px; font-size: 14px; }
}
