/* ============================================================
   Doctor Chat — chat.css
   Variables inherited from /css/style.css
   ============================================================ */

/* ── Full-screen lock — no page-level scroll ─────────────── */
html {
  height: 100%;
  overflow: hidden;
}
body {
  height: 100vh;
  height: 100dvh; /* mobile: excludes browser chrome/address bar */
  overflow: hidden;
  display: flex;
  flex-direction: column;
  margin: 0;
  padding: 0 !important;
}

/* ── Compact App Header ───────────────────────────────────── */
.chat-app-header {
  height: 48px;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 14px;
  background: var(--black-soft);
  border-bottom: 1px solid var(--black-border);
  flex-shrink: 0;        /* never compress the header */
  position: relative; z-index: 60;
  width: 100%; box-sizing: border-box;
}
.chat-logo img {
  height: 34px; width: auto; display: block; vertical-align: middle;
}
.chat-logo .logo-light { display: none; }
[data-theme="light"] .chat-logo .logo-dark  { display: none; }
[data-theme="light"] .chat-logo .logo-light { display: block; }

.chat-header-right {
  display: flex; align-items: center; gap: 6px;
}
.aml-lang-select {
  background: var(--black-card); color: var(--text-body);
  border: 1px solid var(--black-border); border-radius: var(--radius-sm);
  font-size: 0.75rem; padding: 4px 7px; cursor: pointer; max-width: 100px;
}
.hdr-btn {
  background: transparent; border: 1px solid var(--black-border);
  border-radius: var(--radius-sm); padding: 5px 8px;
  color: var(--text-body); cursor: pointer; font-size: 0.9rem; line-height: 1;
  transition: border-color var(--transition);
}
.hdr-btn:hover { border-color: var(--violet-mid); }
.theme-icon-light { display: none; }
[data-theme="light"] .theme-icon-dark  { display: none; }
[data-theme="light"] .theme-icon-light { display: inline; }

/* Header menu dropdown */
.hdr-menu-wrap { position: relative; }
.hdr-menu-drop {
  display: none; position: absolute; top: calc(100% + 6px); right: 0;
  min-width: 200px; background: var(--black-card);
  border: 1px solid var(--black-border); border-radius: var(--radius-md);
  padding: 6px; z-index: 200;
  box-shadow: 0 16px 48px rgba(0,0,0,0.8);
}
.hdr-menu-drop.open { display: block; }
.hdr-menu-drop a {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px; border-radius: var(--radius-sm);
  font-size: 0.83rem; color: var(--text-body); text-decoration: none;
  transition: background var(--transition);
}
.hdr-menu-drop a:hover { background: var(--violet-glow); color: var(--violet-pale); }
.hdr-divider { height: 1px; background: var(--black-border); margin: 4px 0; }

/* ── AdBlock Wall ─────────────────────────────────────── */
#adblock-wall {
  display: none; position: fixed; inset: 0; z-index: 9999;
  background: var(--black);
  align-items: center; justify-content: center;
  flex-direction: column; text-align: center; padding: 32px;
}
#adblock-wall.show { display: flex; }
#adblock-wall h2 { color: var(--text-primary); margin-bottom: 12px; }
#adblock-wall p  { color: var(--text-body); max-width: 420px; line-height: 1.7; }
.wall-icon { font-size: 3rem; margin-bottom: 20px; }

/* ── App Shell ─────────────────────────────────────────── */
#app {
  display: flex;
  flex: 1;           /* fill whatever body space remains after header */
  min-height: 0;     /* critical — allows flex children to shrink below content size */
  overflow: hidden;
  position: relative;
}

/* ── Sidebar ───────────────────────────────────────────── */
#sidebar {
  width: 260px; flex-shrink: 0;
  display: flex; flex-direction: column;
  background: var(--black-soft);
  border-right: 1px solid var(--black-border);
  overflow: hidden;
  transition: width 0.22s ease;
}
#sidebar.collapsed { width: 0; }

.sidebar-header {
  padding: 12px 14px 10px;
  border-bottom: 1px solid var(--black-border);
  display: flex; align-items: center; gap: 8px;
  flex-shrink: 0;
}
.sidebar-header h3 {
  font-size: 0.75rem; font-weight: 600; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--text-muted); margin: 0; flex: 1;
}

.btn-new-chat {
  width: calc(100% - 24px); margin: 10px 12px 6px;
  padding: 8px 14px; box-sizing: border-box;
  background: var(--violet-main); color: #fff;
  border: none; border-radius: var(--radius-sm);
  font-size: 0.82rem; font-weight: 500; cursor: pointer;
  transition: background var(--transition); white-space: nowrap;
}
.btn-new-chat:hover { background: var(--violet-mid); }

/* Tool switcher */
#tool-switcher-wrap { position: relative; padding: 0 12px 8px; flex-shrink: 0; }
#tool-search-input {
  width: 100%; box-sizing: border-box; padding: 6px 10px;
  border-radius: var(--radius-sm); border: 1px solid var(--black-border);
  background: var(--black-card); color: var(--text-body);
  font-size: 0.82rem; outline: none;
}
#tool-search-input:focus { border-color: var(--violet-mid); }
#tool-dropdown {
  display: none; position: absolute; left: 12px; right: 12px; top: 100%;
  background: var(--black-card); border: 1px solid var(--black-border);
  border-radius: var(--radius-sm); max-height: 260px; overflow-y: auto;
  z-index: 100; box-shadow: 0 8px 32px rgba(0,0,0,0.6);
}
#tool-dropdown.open { display: block; }
.tool-option {
  padding: 8px 12px; cursor: pointer;
  display: flex; align-items: flex-start; gap: 9px;
  border-bottom: 1px solid var(--black-border);
  transition: background var(--transition);
}
.tool-option:last-child { border-bottom: none; }
.tool-option:hover, .tool-option.active { background: var(--violet-glow); }
.tool-option .tool-icon { font-size: 1rem; flex-shrink: 0; }
.tool-option .tool-name { font-size: 0.82rem; font-weight: 500; color: var(--text-primary); }
.tool-option .tool-desc { font-size: 0.72rem; color: var(--text-muted); margin-top: 1px; }

/* Active tool badge */
#active-tool-badge {
  margin: 0 12px 8px; padding: 6px 10px;
  border: 1px solid var(--black-border); border-radius: var(--radius-sm);
  display: flex; align-items: center; gap: 7px; cursor: pointer;
  background: var(--black-card); transition: border-color var(--transition);
  flex-shrink: 0;
}
#active-tool-badge:hover { border-color: var(--violet-mid); }
.badge-icon { font-size: 1rem; flex-shrink: 0; }
.badge-name { font-size: 0.8rem; font-weight: 500; color: var(--text-primary); flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge-change { font-size: 0.7rem; color: var(--violet-light); flex-shrink: 0; }

/* Chat list */
#chat-list { flex: 1; overflow-y: auto; padding: 4px 8px 8px; }
.chat-item {
  padding: 6px 8px; border-radius: var(--radius-sm); cursor: pointer;
  display: flex; align-items: center; gap: 6px;
  transition: background var(--transition);
}
.chat-item:hover { background: var(--violet-glow2); }
.chat-item.active { background: var(--violet-glow); }
.chat-item-icon { font-size: 0.85rem; flex-shrink: 0; }
.chat-item-title {
  font-size: 0.79rem; color: var(--text-body); flex: 1;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0;
}
/* Always visible — no hover hide */
.chat-item-pin, .chat-item-del {
  background: none; border: none;
  color: var(--text-muted); cursor: pointer; font-size: 0.78rem;
  padding: 2px 4px; flex-shrink: 0; line-height: 1;
  border-radius: 3px; transition: color var(--transition), background var(--transition);
}
.chat-item-pin:hover { color: var(--violet-light); background: var(--violet-glow); }
.chat-item-del:hover  { color: #f87171; }
.chat-item.pinned .chat-item-pin { color: var(--violet-mid); }

/* ── Main Chat Area ──────────────────────────────────────── */
#chat-main {
  flex: 1; display: flex; flex-direction: column;
  overflow: hidden; min-width: 0;
}

#chat-topbar {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 14px; border-bottom: 1px solid var(--black-border);
  background: var(--black-soft); flex-shrink: 0;
}
#sidebar-toggle {
  background: none; border: 1px solid var(--black-border);
  border-radius: var(--radius-sm); padding: 4px 9px;
  color: var(--text-body); cursor: pointer; font-size: 1rem;
  transition: border-color var(--transition); flex-shrink: 0;
}
#sidebar-toggle:hover { border-color: var(--violet-mid); }
#chat-title {
  font-size: 0.86rem; font-weight: 500; color: var(--text-primary); flex: 1;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0;
}
.topbar-tool-name {
  font-size: 0.72rem; color: var(--violet-light);
  padding: 3px 8px; border: 1px solid var(--black-border); border-radius: 100px;
  white-space: nowrap; flex-shrink: 0;
}

/* Tool dropdown with export buttons */
#topbar-tool-wrap {
  position: relative;
}
.topbar-tool-btn {
  background: none; border: 1px solid var(--black-border);
  border-radius: var(--radius-sm); padding: 5px 10px;
  font-size: 0.72rem; color: var(--violet-light); cursor: pointer;
  display: inline-flex; align-items: center; gap: 5px;
  transition: all var(--transition); flex-shrink: 0;
  font-family: inherit;
  height: auto;
  box-sizing: border-box;
}
.topbar-tool-btn:hover { border-color: var(--violet-mid); color: var(--violet-pale); }
.tool-dropdown-arrow { font-size: 0.6rem; }
.topbar-tool-btn.active .tool-dropdown-arrow { transform: rotate(180deg); }

.tool-export-dropdown {
  display: none; position: absolute; top: calc(100% + 6px); left: 0;
  min-width: 140px; background: var(--black-card);
  border: 1px solid var(--black-border); border-radius: var(--radius-md);
  padding: 6px; z-index: 200;
  box-shadow: 0 8px 24px rgba(0,0,0,0.6);
}
.tool-export-dropdown.open { display: flex; flex-direction: column; gap: 4px; }

.export-btn {
  background: none; border: 1px solid var(--black-border);
  border-radius: var(--radius-sm); padding: 8px 10px;
  color: var(--text-body); font-size: 0.8rem; cursor: pointer;
  text-align: left; transition: all var(--transition);
  font-family: inherit;
  height: auto;
  display: flex;
  align-items: center;
  box-sizing: border-box;
}
.export-btn:hover { border-color: var(--violet-mid); color: var(--violet-light); background: var(--violet-glow); }

/* Messages */
#messages {
  flex: 1; overflow-y: auto; padding: 18px 16px;
  display: flex; flex-direction: column; gap: 14px;
}

/* ── Message Rows & Bubbles ──────────────────────────────── */
.msg-row {
  display: flex; gap: 10px;
  max-width: 820px; margin: 0 auto; width: 100%;
  align-items: flex-start;
}
.msg-row.user-row { flex-direction: row-reverse; }

.msg-avatar {
  width: 30px; height: 30px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.8rem; font-weight: 600; margin-top: 2px;
}
.user-row .msg-avatar { background: var(--violet-main); color: #fff; }
.ai-row   .msg-avatar { background: var(--black-card2); color: var(--violet-light); border: 1px solid var(--black-border); }

/* IMPORTANT: flex:1 + min-width:0 prevents letter-stacking */
.msg-wrap {
  flex: 1; min-width: 0;
  display: flex; flex-direction: column;
}
.user-row .msg-wrap { align-items: flex-end; }
.ai-row   .msg-wrap { align-items: flex-start; }

.msg-bubble {
  padding: 10px 14px; border-radius: var(--radius-md);
  max-width: 85%; line-height: 1.65; font-size: 0.9rem;
  word-break: break-word; overflow-wrap: break-word;
}
.user-row .msg-bubble {
  background: var(--violet-main); color: #fff;
  border-bottom-right-radius: 4px;
}
.ai-row .msg-bubble {
  background: var(--black-card); color: var(--text-body);
  border: 1px solid var(--black-border); border-bottom-left-radius: 4px;
}
/* Markdown inside AI bubble */
/* Headings inside AI bubble — bold, distinct, not oversized */
.ai-row .msg-bubble h1,
.ai-row .msg-bubble h2,
.ai-row .msg-bubble h3 {
  color: var(--text-primary);
  font-weight: 700;
  margin: 14px 0 5px;
  font-size: 0.95em;
  line-height: 1.3;
}
.ai-row .msg-bubble h1:first-child,
.ai-row .msg-bubble h2:first-child,
.ai-row .msg-bubble h3:first-child { margin-top: 2px; }

/* Bold inline text */
.ai-row .msg-bubble strong {
  color: var(--text-primary);
  font-weight: 700;
}

/* Lists — each item on its own line, well-spaced */
.ai-row .msg-bubble ul,
.ai-row .msg-bubble ol {
  padding-left: 20px;
  margin: 6px 0;
}
.ai-row .msg-bubble li {
  margin-bottom: 5px;
  line-height: 1.6;
}
.ai-row .msg-bubble li > p { margin: 0; } /* prevent double-spacing inside li */

/* Paragraphs — breathing room between sections */
.ai-row .msg-bubble p {
  margin: 5px 0;
  line-height: 1.7;
}
/* Consecutive paragraphs get more space */
.ai-row .msg-bubble p + p { margin-top: 8px; }

/* Horizontal rule as section divider */
.ai-row .msg-bubble hr {
  border: none;
  border-top: 1px solid var(--black-border);
  margin: 10px 0;
}

/* Code */
.ai-row .msg-bubble code { background: var(--black-card2); padding: 1px 5px; border-radius: 3px; font-size: 0.85em; color: var(--violet-pale); }
.ai-row .msg-bubble pre  { background: var(--black-card2); padding: 10px; border-radius: var(--radius-sm); overflow-x: auto; font-size: 0.82em; border: 1px solid var(--black-border); margin: 8px 0; }

/* Blockquote — used for notes/caveats */
.ai-row .msg-bubble blockquote {
  border-left: 3px solid var(--violet-mid);
  padding: 4px 10px;
  margin: 8px 0;
  color: var(--text-muted);
  font-size: 0.88em;
}

/* Message actions */
.msg-actions {
  display: flex; margin-top: 5px; gap: 4px; flex-wrap: wrap;
  opacity: 0; transition: opacity 0.15s;
}
.msg-row:hover .msg-actions,
.msg-row.actions-visible .msg-actions { opacity: 1; }
/* Always visible on touch / mobile */
@media (hover: none) {
  .msg-actions { opacity: 0.6; }
}
.msg-action-btn {
  background: none; border: 1px solid var(--black-border); border-radius: var(--radius-sm);
  padding: 2px 9px; font-size: 0.7rem; color: var(--text-muted); cursor: pointer;
  transition: all var(--transition);
}
.msg-action-btn:hover { border-color: var(--violet-mid); color: var(--violet-light); }

/* Typing indicator */
#typing-indicator { display: none; }

/* Error states */
.msg-bubble.msg-error {
  border-color: #f87171 !important;
  background: rgba(239,68,68,0.08) !important;
  color: #fca5a5;
}
[data-theme="light"] .msg-bubble.msg-error {
  background: #fff1f1 !important;
  color: #b91c1c;
}
.file-preview.file-error {
  border-color: #f87171;
  color: #fca5a5;
  background: rgba(239,68,68,0.08);
}
[data-theme="light"] .file-preview.file-error {
  background: #fff1f1;
  color: #b91c1c;
}
#typing-indicator.show { display: flex; }
.typing-dots { display: flex; gap: 4px; align-items: center; padding: 2px 0; }
.typing-dots span {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--violet-mid); display: block;
  animation: bounce 1.2s infinite;
}
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes bounce {
  0%,80%,100% { transform: translateY(0); opacity: 0.4; }
  40%          { transform: translateY(-6px); opacity: 1; }
}

/* Thought block */
.thought-block {
  font-size: 0.73rem; color: var(--text-muted);
  border-left: 2px solid var(--black-border);
  padding: 3px 9px; margin-bottom: 7px; font-style: italic;
}

/* Ad units */
.ad-unit {
  display: flex; flex-direction: column; align-items: center;
  margin: 2px auto; max-width: 340px; width: 100%;
}
.ad-label { font-size: 0.63rem; color: var(--text-muted); letter-spacing: 0.06em; text-transform: uppercase; margin-bottom: 2px; align-self: flex-start; }

/* File preview */
.file-preview {
  display: flex; align-items: center; gap: 8px;
  background: var(--black-card); border: 1px solid var(--black-border);
  border-radius: var(--radius-sm); padding: 6px 10px;
  font-size: 0.8rem; color: var(--text-body); max-width: 240px;
}
.file-rm { background: none; border: none; color: var(--text-muted); cursor: pointer; font-size: 0.9rem; margin-left: auto; }

/* ── Input Bar ─────────────────────────────────────────── */
#input-area {
  border-top: 1px solid var(--black-border);
  background: var(--black-soft); padding: 10px 14px; flex-shrink: 0;
}
#input-row {
  display: flex; align-items: center; gap: 7px;
  max-width: 820px; margin: 0 auto;
  height: 42px;
}
#file-preview-area { max-width: 820px; margin: 0 auto 6px; display: flex; flex-wrap: wrap; gap: 6px; }

#msg-input {
  flex: 1; padding: 8px 12px;
  background: var(--black-card); border: 1px solid var(--black-border);
  border-radius: var(--radius-md); color: var(--text-body);
  font-family: inherit; font-size: 0.9rem; resize: none;
  height: 42px; line-height: 1.4;
  outline: none; transition: border-color var(--transition);
  overflow-y: auto;
  box-sizing: border-box;
}
#msg-input:focus { border-color: var(--violet-mid); }
#msg-input::placeholder { color: var(--text-muted); }

.input-btn {
  background: none; border: 1px solid var(--black-border);
  border-radius: var(--radius-sm); padding: 8px 10px;
  color: var(--text-muted); cursor: pointer; font-size: 1rem;
  flex-shrink: 0; transition: all var(--transition); line-height: 1;
  height: 42px; width: 42px;
  display: flex; align-items: center; justify-content: center;
  box-sizing: border-box;
}
.input-btn:hover { border-color: var(--violet-mid); color: var(--violet-light); }
.input-btn.active { border-color: var(--violet-mid); color: var(--violet-mid); background: var(--violet-glow); }

#send-btn {
  background: var(--violet-main); border: 1px solid var(--violet-main);
  color: #fff; padding: 8px 18px; font-size: 0.87rem; font-weight: 500;
  border-radius: var(--radius-sm); cursor: pointer; flex-shrink: 0;
  transition: background var(--transition);
  height: 42px;
  display: flex; align-items: center; justify-content: center;
  box-sizing: border-box;
}
#send-btn:hover { background: var(--violet-mid); }
#send-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Mode toggle button — lives in topbar */
.mode-btn {
  background: transparent;
  border: 1px solid var(--black-border);
  border-radius: var(--radius-sm);
  padding: 4px 10px;
  font-size: 0.7rem; font-family: inherit;
  color: var(--text-muted); cursor: pointer;
  white-space: nowrap; flex-shrink: 0;
  transition: all var(--transition);
  height: auto;
  display: inline-flex;
  align-items: center;
  box-sizing: border-box;
}
.mode-btn:hover { border-color: var(--violet-mid); color: var(--violet-light); }
.mode-btn.mode-short  { border-color: #f59e0b;            color: #f59e0b; }
.mode-btn.mode-normal { border-color: var(--black-border); color: var(--text-muted); }
.mode-btn.mode-long   { border-color: var(--violet-mid);   color: var(--violet-light); }

/* Meta label above AI response bubble */
.msg-meta {
  font-size: 0.75rem; color: var(--text-muted);
  display: flex; align-items: center; gap: 6px;
  margin-bottom: 6px; padding: 0 2px;
  opacity: 0.85;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.meta-tool { color: var(--text-body); font-weight: 500; }
.meta-sep  { color: var(--black-border); }
.meta-mode { color: var(--violet-light); font-weight: 500; }
[data-theme="light"] .meta-mode { color: var(--violet-mid); }

/* ── Inline message edit ────────────────────────────────── */
.edit-textarea {
  width: 100%; min-height: 60px; max-height: 200px;
  background: var(--black-input, var(--black-card)); color: var(--text-body);
  border: 1px solid var(--violet-mid); border-radius: var(--radius-sm);
  padding: 8px 10px; font-size: 0.87rem; font-family: inherit;
  resize: vertical; box-sizing: border-box; margin-bottom: 6px;
  line-height: 1.5;
}
.edit-textarea:focus { outline: none; border-color: var(--violet-light); }
.edit-btns { display: flex; gap: 6px; }
.edit-save, .edit-cancel {
  padding: 5px 14px; font-size: 0.8rem; border-radius: var(--radius-sm);
  cursor: pointer; border: 1px solid; font-family: inherit;
  transition: opacity var(--transition);
}
.edit-save {
  background: var(--violet-main); border-color: var(--violet-main); color: #fff;
}
.edit-save:hover { opacity: 0.85; }
.edit-cancel {
  background: transparent; border-color: var(--black-border); color: var(--text-muted);
}
.edit-cancel:hover { border-color: var(--text-muted); color: var(--text-body); }
[data-theme="light"] .edit-textarea {
  background: #fff; border-color: #a0aec0; color: #334155;
}

/* Welcome screen */
#welcome-screen {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 24px; text-align: center;
}
#welcome-screen h2 { color: var(--text-primary); margin-bottom: 8px; }
#welcome-screen p  { color: var(--text-body); max-width: 400px; margin-bottom: 20px; }
.suggested-prompts { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; max-width: 580px; }
.suggested-prompt {
  padding: 6px 14px; border: 1px solid var(--black-border);
  border-radius: 100px; font-size: 0.79rem; color: var(--text-body);
  cursor: pointer; background: var(--black-card); transition: all var(--transition);
}
.suggested-prompt:hover { border-color: var(--violet-mid); color: var(--violet-light); background: var(--violet-glow); }

/* ── Mobile overlay for sidebar ────────────────────────── */
#sidebar-overlay {
  display: none; position: fixed; inset: 0; z-index: 40;
  background: rgba(0,0,0,0.5);
}
#sidebar-overlay.show { display: block; }

/* ── Responsive ─────────────────────────────────────────── */
@media (max-width: 768px) {
  #sidebar {
    position: absolute; z-index: 50;
    height: 100%; top: 0; left: 0;
    box-shadow: none;
  }
  #sidebar:not(.collapsed) { box-shadow: 4px 0 24px rgba(0,0,0,0.7); }
  #msg-input { font-size: 16px; } /* Prevents iOS zoom on focus */
  .msg-bubble { max-width: 92%; }
  #messages { padding: 10px 8px; }
  .aml-lang-select { max-width: 80px; font-size: 0.7rem; }
  /* Compact input row on small screens */
  #input-area { padding: 8px 10px; }
}

/* ── Light mode ─────────────────────────────────────────── */
[data-theme="light"] .chat-app-header { background: #e8eeff; border-color: #c8d4f0; }
[data-theme="light"] .ai-row .msg-bubble { background: #fff; border-color: #c8d4f0; }
[data-theme="light"] #sidebar { background: #f0f4ff; border-color: #c8d4f0; }
[data-theme="light"] #chat-topbar { background: #e8eeff; border-color: #c8d4f0; }
[data-theme="light"] #input-area { background: #e8eeff; border-color: #c8d4f0; }
[data-theme="light"] #msg-input { background: #fff; border-color: #c8d4f0; color: #334155; }
[data-theme="light"] .hdr-menu-drop { background: #fff; border-color: #c8d4f0; }
[data-theme="light"] .aml-lang-select { background: #fff; border-color: #c8d4f0; color: #334155; }
