/* ── Reset ───────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  padding: 0;
  overflow: hidden;
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

/* ── App shell ───────────────────────────────────────────────── */
#app-layout {
  display: flex;
  height: 100vh;
  overflow: hidden;
  background: #f0fdf9;
}

/* ── Sidebar ─────────────────────────────────────────────────── */
#chat-list-panel {
  width: 28%;
  min-width: 260px;
  max-width: 340px;
  flex-shrink: 0;
  display: none;
  flex-direction: column;
  background: #0a2e2e;
  overflow: hidden;
}

@media (max-width: 767px) {
  #chat-list-panel {
    position: fixed;
    top: 0; left: 0;
    height: 100vh;
    z-index: 40;
    width: 82vw;
    min-width: unset;
    max-width: unset;
  }
}

/* ── Sidebar header ──────────────────────────────────────────── */
.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 16px 16px;
  flex-shrink: 0;
}
.sidebar-brand { display: flex; align-items: center; gap: 10px; }
.sidebar-brand-icon {
  width: 36px; height: 36px; border-radius: 10px;
  background: #0d9488;
  display: flex; align-items: center; justify-content: center;
  color: white; font-size: 15px; flex-shrink: 0;
}
.sidebar-brand-text { display: flex; flex-direction: column; gap: 2px; }
.sidebar-brand-name { color: white; font-weight: 700; font-size: 14px; letter-spacing: -0.2px; }
.sidebar-brand-sub  { color: rgba(255,255,255,0.35); font-size: 10.5px; }
.sidebar-close-btn {
  width: 30px; height: 30px; border-radius: 8px;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.08);
  color: rgba(255,255,255,0.4);
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  font-size: 11px; transition: all 0.15s;
}
.sidebar-close-btn:hover { background: rgba(255,255,255,0.12); color: white; }

/* ── New Chat button ─────────────────────────────────────────── */
.sidebar-new-chat-wrap { padding: 0 12px 16px; flex-shrink: 0; }
.sidebar-new-chat-btn {
  width: 100%; display: flex; align-items: center; justify-content: center;
  gap: 8px; padding: 11px 16px;
  background: #0d9488; border: none; border-radius: 10px;
  color: white; font-size: 13px; font-weight: 600;
  cursor: pointer; transition: background 0.15s, transform 0.1s;
  letter-spacing: 0.1px;
}
.sidebar-new-chat-btn:hover  { background: #0f766e; }
.sidebar-new-chat-btn:active { transform: scale(0.98); }
.sidebar-new-chat-icon {
  width: 20px; height: 20px; border-radius: 50%;
  background: rgba(255,255,255,0.2);
  display: flex; align-items: center; justify-content: center;
  font-size: 10px; flex-shrink: 0;
}

/* ── Section label ───────────────────────────────────────────── */
.sidebar-section-label {
  padding: 0 16px 8px;
  font-size: 10px; font-weight: 700;
  letter-spacing: 0.08em; text-transform: uppercase;
  color: rgba(255,255,255,0.22); flex-shrink: 0;
}

/* ── Sidebar: scrollable list ────────────────────────────────── */
#chat-list-items {
  flex: 1;
  overflow-y: auto;
  padding: 0 8px 12px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.1) transparent;
}
#chat-list-items::-webkit-scrollbar { width: 3px; }
#chat-list-items::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.12); border-radius: 3px; }

/* ── Empty / loading states ──────────────────────────────────── */
.sidebar-empty {
  text-align: center; padding: 3rem 1.5rem;
  color: rgba(255,255,255,0.25);
}
.sidebar-empty i { font-size: 28px; display: block; margin-bottom: 10px; opacity: 0.3; }
.sidebar-empty p { font-size: 12px; font-weight: 600; margin: 0 0 4px; }
.sidebar-empty small { font-size: 10.5px; opacity: 0.6; }
.sidebar-loading {
  text-align: center; padding: 2.5rem 1rem;
  color: rgba(255,255,255,0.25); font-size: 20px;
}

/* ── Sidebar chat items ──────────────────────────────────────── */
.chat-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 10px 10px 14px;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.15s;
  color: rgba(255,255,255,0.55);
  user-select: none;
  position: relative;
  margin-bottom: 2px;
}
.chat-item::before {
  content: ''; position: absolute;
  left: 0; top: 20%; height: 60%; width: 3px;
  border-radius: 0 3px 3px 0;
  background: transparent; transition: background 0.15s;
}
.chat-item:hover { background: rgba(255,255,255,0.06); color: rgba(255,255,255,0.85); }
.chat-item.active { background: rgba(13,148,136,0.18); color: white; }
.chat-item.active::before { background: #0d9488; }

.chat-item .chat-item-title {
  font-size: 12.5px; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  flex: 1; min-width: 0;
}
.chat-item .chat-item-date {
  font-size: 10px; color: rgba(255,255,255,0.28);
  margin-top: 2px; white-space: nowrap;
}
.chat-item-actions {
  display: flex; align-items: center; gap: 2px;
  flex-shrink: 0; opacity: 0; transition: opacity 0.15s;
}
.chat-item:hover .chat-item-actions { opacity: 1; }

.item-btn {
  width: 26px; height: 26px; border-radius: 7px; border: none;
  background: transparent; color: rgba(255,255,255,0.3);
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: all 0.15s; font-size: 11px;
}
.item-btn:hover { background: rgba(255,255,255,0.1); color: rgba(255,255,255,0.9); }
.item-btn.rename-btn:hover { color: #5eead4; }
.item-btn.delete-btn:hover { color: #f87171; }

/* ── Inline rename input ─────────────────────────────────────── */
.chat-rename-input {
  background: transparent; border: none;
  border-bottom: 1px solid rgba(255,255,255,0.35);
  outline: none; color: white;
  font-size: 12.5px; font-weight: 600;
  width: 100%; padding: 1px 0; caret-color: #5eead4;
}

/* ── Sidebar user (now at top of header) ────────────────────── */
.sidebar-user-top {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
}
.sidebar-user-avatar {
  flex-shrink: 0; width: 34px; height: 34px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; color: white;
  background: #0d9488; letter-spacing: 0.5px;
}
.sidebar-user-info { flex: 1; min-width: 0; }
.sidebar-user-name {
  color: white; font-weight: 600; font-size: 12.5px; margin: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sidebar-user-status {
  display: flex; align-items: center; gap: 4px;
  font-size: 10px; color: rgba(255,255,255,0.45); margin-top: 2px;
}
.sidebar-status-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: #34d399; flex-shrink: 0;
  box-shadow: 0 0 4px rgba(52,211,153,0.5);
}

/* ── Sidebar logo footer ─────────────────────────────────────── */
.sidebar-logo-footer {
  margin-top: auto;
  flex-shrink: 0;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.sidebar-logo-img {
  height: 28px;
  width: auto;
  object-fit: contain;
  filter: brightness(0) invert(1);
  opacity: 0.75;
  transition: opacity 0.15s;
}
.sidebar-logo-img:hover { opacity: 1; }

/* ── Main area ───────────────────────────────────────────────── */
#main-area {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: #f0fdf9;
}

/* ── Chat header ─────────────────────────────────────────────── */
.chat-header {
  background: linear-gradient(135deg, #0f3d3d 0%, #0d9488 100%);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 11px 16px;
}

/* Header icon buttons – hover via CSS (avoids inline handlers / CSP) */
.chat-header button {
  transition: background 0.15s;
}
.chat-header button:hover {
  background: rgba(255,255,255,0.22) !important;
}

/* ── Login modal logo ────────────────────────────────────────── */
.login-modal-logo {
  height: 32px;
  width: auto;
  object-fit: contain;
  filter: brightness(0) invert(1);
}

/* ── Messages area ───────────────────────────────────────────── */
.chat-container {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
  padding: 20px 20px;
  background: #f0fdf9;
}

/* ── Input area ──────────────────────────────────────────────── */
#input-area {
  flex-shrink: 0;
  background: white;
  border-top: 1px solid #e5e7eb;
  padding: 12px 16px 14px;
}

/* User input focus – CSS only, no inline handlers */
#user-input:focus {
  border-color: #0d9488 !important;
  box-shadow: 0 0 0 3px rgba(13,148,136,0.15) !important;
  outline: none;
}

/* More-suggestions button hover */
#more-suggestions-btn:hover { background: #ccfbf1 !important; }

/* Send / mic button hover */
#send-button { transition: background 0.15s; }
#send-button:hover { background: #0f766e !important; }
#mic-button  { transition: background 0.15s; }
#mic-button:hover  { background: #e5e7eb !important; }


/* ── Markdown / bot messages ─────────────────────────────────── */
.markdown-body {
  background: #0c5c5c !important;
  color: white !important;
  padding: 10px;
  border-radius: 10px;
}

.user-avatar-icon { cursor: default; }
.user-avatar-icon:hover { box-shadow: 0 0 0 2px #0d9488, 0 0 0 4px rgba(13,148,136,0.2); }

#toggle-password { background: none; border: none; cursor: pointer; line-height: 1; }
body.dark-mode #toggle-password { color: #9ca3af; }
body.dark-mode #toggle-password:hover { color: #d1d5db; }

/* Token-limit notice banner */
#token-limit-banner {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 14px;
  background: #fef3c7;
  border-bottom: 1px solid #fcd34d;
  color: #92400e;
  font-size: 12px;
  line-height: 1.4;
}
#token-limit-banner i.fa-triangle-exclamation { color: #d97706; flex-shrink: 0; }
#token-limit-banner span { flex: 1; }
#token-limit-dismiss {
  background: none; border: none; cursor: pointer;
  color: #92400e; opacity: 0.6; padding: 0 2px; flex-shrink: 0;
}
#token-limit-dismiss:hover { opacity: 1; }
body.dark-mode #token-limit-banner {
  background: #2d2006; border-bottom-color: #78450a; color: #fcd34d;
}
body.dark-mode #token-limit-dismiss { color: #fcd34d; }

.copy-button { transition: all 0.2s ease; }
.copy-button:hover { transform: scale(1.1); }
.copy-button.copied { color: #10b981; }

.thinking-dots span {
  display: inline-block;
  animation: thinking 1.4s infinite both;
}
.thinking-dots span:nth-child(2) { animation-delay: 0.2s; }
.thinking-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes thinking {
  0%   { opacity: 0.2; transform: translateY(0); }
  20%  { opacity: 1;   transform: translateY(-3px); }
  100% { opacity: 0.2; transform: translateY(0); }
}

.message-container { overflow: auto; }

.user-message:before {
  right: -10px; top: 15px;
  border-width: 10px 0 10px 10px;
  border-color: transparent transparent transparent #0d9488;
}

.bot-message:before {
  left: -10px; top: 15px;
  border-width: 10px 10px 10px 0;
  border-color: transparent #f3f4f6 transparent transparent;
}

/* ── Profile popup ───────────────────────────────────────────── */
#profile-popup {
  position: fixed;
  transform-origin: top right;
  transition: transform 0.2s ease-out, opacity 0.2s ease-out;
  opacity: 0;
  transform: scale(0.95);
  z-index: 1000;
  box-shadow: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -1px rgba(0,0,0,0.06);
}
#profile-popup.show { opacity: 1; transform: scale(1); }
#profile-popup button { transition: all 0.2s ease; width: 100%; text-align: left; padding: 0.5rem 1rem; border-radius: 0.375rem; }
#profile-popup button:hover { background-color: #f3f4f6; }
#profile-popup button i { width: 20px; text-align: center; margin-right: 0.5rem; }

/* ── Clear-history modal ─────────────────────────────────────── */
#clear-history-modal { transition: opacity 0.3s ease; }
#clear-history-modal .bg-white { transform: scale(0.95); transition: transform 0.3s ease; }
#clear-history-modal.show .bg-white { transform: scale(1); }

/* ── More suggestions modal ──────────────────────────────────── */
.more-suggestions-container { overflow: auto; height: 500px; }

/* ── LLM selector pill button ────────────────────────────────── */
#llm-selector-btn:hover {
  border-color: #0d9488 !important;
  box-shadow: 0 0 0 3px rgba(13,148,136,0.12) !important;
}

/* ── Chat wrapper entrance animation ─────────────────────────── */
.chat-wrapper { animation: fadeIn 0.4s ease-in-out; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Tailwind blue → teal overrides (modal buttons, badges, etc.) ── */
.bg-blue-600  { background-color: #0d9488 !important; }
.bg-blue-50   { background-color: #f0fdfa !important; }
.bg-blue-100  { background-color: #ccfbf1 !important; }
.hover\:bg-blue-700:hover { background-color: #0f766e !important; }
.hover\:bg-blue-200:hover { background-color: #99f6e4 !important; }
.text-blue-700   { color: #0f766e !important; }
.text-blue-600   { color: #0d9488 !important; }
.text-blue-500   { color: #14b8a6 !important; }
.text-blue-400   { color: #2dd4bf !important; }
.text-blue-200   { color: #99f6e4 !important; }
.text-blue-800   { color: #134e4a !important; }
.border-blue-100 { border-color: #99f6e4 !important; }
.border-blue-400 { border-color: #2dd4bf !important; }
.focus\:ring-blue-500:focus { --tw-ring-color: rgba(13,148,136,0.5) !important; }
.focus\:ring-blue-500 { --tw-ring-color: rgba(13,148,136,0.5) !important; }

/* ── Suggestion pills ────────────────────────────────────────── */
.suggestion-btn {
  background: #ccfbf1;
  color: #134e4a;
  border: none;
  cursor: pointer;
}
.suggestion-btn:hover { background: #99f6e4; }

/* ── Mobile overrides ────────────────────────────────────────── */
@media (max-width: 767px) {
  .chat-container { padding: 12px; }

  #input-area { padding: 10px 12px 12px; }

  .suggestion-container,
  #more-suggestions-btn { display: none !important; }

  #main-area .chat-header { padding: 10px 12px; }
}

/* ── Find-in-chat highlights ─────────────────────────────────── */
mark.find-highlight {
  background: #fde68a;
  color: #111827;
  border-radius: 2px;
  padding: 0 1px;
}
mark.find-highlight-active {
  background: #f59e0b;
  color: white;
  outline: 2px solid #d97706;
}

/* ── Bot message footer ──────────────────────────────────────── */
.msg-footer {
  margin-top: 8px;
  padding-top: 6px;
  border-top: 1px solid #f3f4f6;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  font-size: 11px;
  color: #9ca3af;
  position: relative;
}

.msg-footer-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

/* Action buttons: hidden, fade in on message hover */
.msg-footer-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
  opacity: 0;
  transform: translateY(3px);
  transition: opacity 0.15s ease, transform 0.15s ease;
  pointer-events: none;
}

.message-container:hover .msg-footer-actions,
.message-container:focus-within .msg-footer-actions {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

/* Touch devices have no hover — always show action buttons */
@media (hover: none) {
  .msg-footer-actions {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
  }
}

/* thin vertical separator between groups */
.msg-footer-sep {
  display: inline-block;
  width: 1px;
  height: 14px;
  background: #e5e7eb;
  border-radius: 1px;
  flex-shrink: 0;
}

body.dark-mode .msg-footer { border-top-color: #374151; }
body.dark-mode .msg-footer-sep { background: #4b5563; }

/* ── Chat ID badge ───────────────────────────────────────────── */
.copy-chat-id-btn {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 1px 6px;
  border-radius: 4px;
  border: 1px solid #e5e7eb;
  background: transparent;
  color: #9ca3af;
  font-size: 10px;
  font-family: monospace;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}
.copy-chat-id-btn:hover {
  border-color: #0d9488;
  color: #0d9488;
  background: #f0fdfa;
}
body.dark-mode .copy-chat-id-btn {
  border-color: #374151;
  color: #6b7280;
}
body.dark-mode .copy-chat-id-btn:hover {
  border-color: #0d9488;
  color: #5eead4;
  background: #0f3d3d;
}

/* ── Feedback buttons ────────────────────────────────────────── */
.feedback-btn {
  width: 24px;
  height: 24px;
  border-radius: 6px;
  border: 1px solid #e5e7eb;
  background: transparent;
  color: #9ca3af;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  transition: all 0.15s;
  padding: 0;
}
.feedback-btn:hover { border-color: #0d9488; color: #0d9488; background: #f0fdfa; }
.feedback-btn.feedback-active.feedback-up   { background: #ccfbf1; color: #0d9488; border-color: #0d9488; }
.feedback-btn.feedback-active.feedback-down { background: #fee2e2; color: #ef4444; border-color: #ef4444; }

/* ── Dark mode ───────────────────────────────────────────────── */
body.dark-mode,
body.dark-mode #app-layout,
body.dark-mode #main-area {
  background: #111827 !important;
  color: #f3f4f6 !important;
}

body.dark-mode .chat-container {
  background: #111827 !important;
}

body.dark-mode #input-area {
  background: #1f2937 !important;
  border-top-color: #374151 !important;
}

body.dark-mode #user-input {
  background: #374151 !important;
  border-color: #4b5563 !important;
  color: #f3f4f6 !important;
}
body.dark-mode #user-input::placeholder { color: #6b7280 !important; }
body.dark-mode #user-input:focus {
  border-color: #0d9488 !important;
  box-shadow: 0 0 0 3px rgba(13,148,136,0.25) !important;
}

body.dark-mode .bg-white.rounded-2xl.bot-message,
body.dark-mode .bg-white.rounded-2xl {
  background: #1f2937 !important;
}

body.dark-mode .message-container .bg-white { background: #1f2937 !important; }

body.dark-mode .text-gray-500 { color: #9ca3af !important; }
body.dark-mode .text-gray-400 { color: #6b7280 !important; }

body.dark-mode #llm-selector-btn {
  background: #374151 !important;
  border-color: #4b5563 !important;
  color: #f3f4f6 !important;
}

body.dark-mode #llm-selector-dropdown {
  background: #1f2937 !important;
  border-color: #374151 !important;
}
body.dark-mode #llm-selector-dropdown p { color: #f3f4f6 !important; }
body.dark-mode .llm-option:hover { background: #374151 !important; }

body.dark-mode .suggestion-btn {
  background: #1f2937 !important;
  color: #5eead4 !important;
  border: 1px solid #374151 !important;
}
body.dark-mode .suggestion-btn:hover { background: #374151 !important; }

body.dark-mode .feedback-btn {
  border-color: #374151;
  color: #6b7280;
}
body.dark-mode .feedback-btn:hover { border-color: #0d9488; color: #5eead4; background: #0f3d3d; }

body.dark-mode mark.find-highlight { background: #92400e; color: #fde68a; }
body.dark-mode mark.find-highlight-active { background: #d97706; color: white; }

/* ── Dark mode: login / 2FA modal ────────────────────────────── */
body.dark-mode #login-modal > div {
  background: #1f2937 !important;
}
body.dark-mode #login-modal label,
body.dark-mode #login-modal .text-gray-500 {
  color: #9ca3af !important;
}
body.dark-mode #login-modal input[type="text"],
body.dark-mode #login-modal input[type="password"] {
  background: #374151 !important;
  border-color: #4b5563 !important;
  color: #f3f4f6 !important;
}
body.dark-mode #login-modal input::placeholder {
  color: #6b7280 !important;
}
body.dark-mode #login-modal .bg-gray-100,
body.dark-mode #login-modal .hover\:bg-gray-200 {
  background: #374151 !important;
  color: #d1d5db !important;
}
body.dark-mode #login-modal .text-gray-700 {
  color: #d1d5db !important;
}

/* ── LLM response tables (inside .markdown-body only) ────────── */
.markdown-body table {
  border-collapse: separate;
  border-spacing: 0;
  font-size: 13px;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 1px 4px rgba(0,0,0,0.07);
  margin: 14px 0;
}

.markdown-body table thead tr {
  background: #0f3d3d;
}

.markdown-body table thead th {
  background: transparent !important;
  color: #ffffff !important;
  font-weight: 600;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 10px 14px;
  text-align: left;
  border: none !important;
  white-space: nowrap;
}

.markdown-body table tbody tr {
  background: #ffffff;
  transition: background 0.12s;
}

.markdown-body table tbody tr:nth-child(even) {
  background: #f0fdf9;
}

.markdown-body table tbody tr:hover {
  background: #ccfbf1;
}

.markdown-body table tbody td {
  padding: 9px 14px;
  color: #374151;
  border: none !important;
  border-bottom: 1px solid #e5e7eb !important;
  font-size: 13px;
  vertical-align: middle;
}

.markdown-body table tbody tr:last-child td {
  border-bottom: none !important;
}

/* ── Dark mode: LLM response tables ─────────────────────────── */
body.dark-mode .markdown-body table {
  box-shadow: 0 1px 4px rgba(0,0,0,0.3);
}

body.dark-mode .markdown-body table thead tr {
  background: #0f3d3d;
}

body.dark-mode .markdown-body table tbody tr {
  background: #1f2937;
}

body.dark-mode .markdown-body table tbody tr:nth-child(even) {
  background: #111827;
}

body.dark-mode .markdown-body table tbody tr:hover {
  background: #0f3d3d;
}

body.dark-mode .markdown-body table tbody td {
  color: #e5e7eb;
  border-bottom-color: #374151 !important;
}

