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

html {
  height: 100%;
  height: -webkit-fill-available;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: #fff;
  color: #1a1a1a;
  font-size: 14px;
  overflow: hidden;
  height: 100%;
  height: -webkit-fill-available;
}

/* ── Auth pages ─────────────────────────────────────────────────────────────── */
.auth-wrapper {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f8f9fa;
  padding: 1rem;
  overflow: auto;
}

.auth-card {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  padding: 2rem;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 1px 6px rgba(0,0,0,.06);
}

.auth-card .btn-primary {
  background: #92278f;
  border: none;
}

.auth-card .btn-primary:hover {
  background: linear-gradient(135deg, #c1121f, #e07b3a, #d4a843, #1e7a6e, #1a323d, #5e1f6e);
  border: none;
}

.auth-logo { text-align: center; margin-bottom: 1.5rem; }
.auth-logo img { height: 52px; object-fit: contain; }

/* ── Navbar ─────────────────────────────────────────────────────────────────── */
.app-navbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 80px;
  background: #fff;
  border-bottom: 1px solid #e5e7eb;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  z-index: 100;
  gap: 8px;
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex-shrink: 1;
}

.nav-logo {
  height: 50px;
  width: auto;
  flex-shrink: 0;
  object-fit: contain;
}

.nav-title {
  font-weight: 600;
  font-size: 14px;
  color: #1a1a1a;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.nav-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.nav-actions .btn-outline-primary:hover {
  background: linear-gradient(135deg, #c1121f, #e07b3a, #d4a843, #1e7a6e, #1a323d, #5e1f6e);
  border-color: transparent;
  color: #fff;
}

/* ── Chat layout ────────────────────────────────────────────────────────────── */
.chat-wrapper {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  padding-top: 80px;
  overflow: hidden;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1.25rem 0 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.chat-messages-inner {
  max-width: 800px;
  width: 100%;
  margin: 0 auto;
  padding: 0 1rem;
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex: 1;
}

/* ── Messages ───────────────────────────────────────────────────────────────── */
.msg { display: flex; align-items: flex-end; gap: 8px; }
.msg-user { flex-direction: row-reverse; }

.msg-avatar {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: #f0f0f0;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px;
  flex-shrink: 0;
  color: #555;
}

.msg-bubble {
  max-width: 75%;
  padding: 9px 13px;
  border-radius: 14px;
  line-height: 1.55;
  font-size: 13.5px;
  white-space: pre-wrap;
  word-break: break-word;
}

.msg-bubble-user {
  background: #462C7D;
  color: #fff;
  border-bottom-right-radius: 4px;
}

.msg-bubble-assistant {
  background: #f4f4f4;
  color: #1a1a1a;
  border-bottom-left-radius: 4px;
}

#uploadBtn {
  background: linear-gradient(135deg, #5e1f6e);
  border: none;
}

#uploadBtn:hover {
  opacity: 0.9;
  background: linear-gradient(135deg, #c1121f, #e07b3a, #d4a843, #1e7a6e, #1a323d, #5e1f6e);
  border: none;
}

#reingestBtn {
  background: linear-gradient(135deg, #077459);
  border: none;
}

#reingestBtn:hover {
  opacity: 0.9;
  background: linear-gradient(135deg, #c1121f, #e07b3a, #d4a843, #1e7a6e, #1a323d, #5e1f6e);
  border: none;
}

.admin-card .btn-primary {
  background: #5e1f6e;
  border: none;
}

.admin-card .btn-primary:hover {
  background: linear-gradient(135deg, #c1121f, #e07b3a, #d4a843, #1e7a6e, #1a323d, #5e1f6e);
  border: none;
}

.profile-card .btn-primary {
  background: #5e1f6e;
  border: none;
}

.profile-card .btn-primary:hover {
  background: linear-gradient(135deg, #c1121f, #e07b3a, #d4a843, #1e7a6e, #1a323d, #5e1f6e);
  border: none;
}

/* ── Welcome ────────────────────────────────────────────────────────────────── */
.welcome-icon { font-size: 2rem; color: #0d6efd; }
.suggestion-btn { font-size: 12px; border-radius: 20px; }

/* ── Typing indicator ───────────────────────────────────────────────────────── */
.typing-dots {
  display: inline-flex;
  gap: 4px;
  align-items: center;
  height: 16px;
}

.typing-dots span {
  width: 6px; height: 6px;
  background: #aaa;
  border-radius: 50%;
  animation: bounce 1.2s infinite ease-in-out;
}

.typing-dots span:nth-child(1) { animation-delay: 0s; }
.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: scale(0.7); opacity: .5; }
  40%            { transform: scale(1.1); opacity: 1; }
}

/* ── Input bar ──────────────────────────────────────────────────────────────── */
.chat-input-bar {
  background: #fff;
  border-top: 1px solid #e5e7eb;
  padding: 10px 12px 12px;
}

.chat-input-inner {
  display: flex;
  gap: 8px;
  max-width: 800px;
  margin: 0 auto;
  width: 100%;
  align-items: center;
}

.chat-textarea {
  flex: 1;
  resize: none;
  border-radius: 10px;
  border: 1px solid #d1d5db;
  padding: 9px 13px;
  font-size: 13.5px;
  line-height: 20px;
  height: 38px; /* 9px + 9px padding + 20px line-height — matches rows="1" exactly */
  max-height: 140px;
  overflow-y: auto;
}

.chat-textarea:focus {
  outline: none;
  border-color: #0d6efd;
  box-shadow: 0 0 0 3px rgba(13,110,253,.12);
}

.send-btn {
  height: 40px; width: 40px;
  border-radius: 10px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  background: linear-gradient(135deg, #e63946, #f4a261, #e9c46a, #2a9d8f, #264653, #7b2d8b);
  border: none;
}

.send-btn:hover {
  background: linear-gradient(135deg, #c1121f, #e07b3a, #d4a843, #1e7a6e, #1a323d, #5e1f6e);
  border: none;
}

/* ── Scrollbar — hidden until hover/scroll ───────────────────────────────── */
.chat-messages {
  scrollbar-width: thin;
  scrollbar-color: transparent transparent;
  transition: scrollbar-color 0.3s;
}

.chat-messages:hover,
.chat-messages:focus-within {
  scrollbar-color: #d1d5db transparent;
}

.chat-messages::-webkit-scrollbar { width: 5px; }
.chat-messages::-webkit-scrollbar-track { background: transparent; }
.chat-messages::-webkit-scrollbar-thumb { background: transparent; border-radius: 10px; transition: background 0.3s; }
.chat-messages:hover::-webkit-scrollbar-thumb,
.chat-messages:focus-within::-webkit-scrollbar-thumb { background: #d1d5db; }

/* ── Admin scrollbar ─────────────────────────────────────────────────────── */
.admin-wrapper {
  scrollbar-width: thin;
  scrollbar-color: transparent transparent;
  transition: scrollbar-color 0.3s;
}

.admin-wrapper:hover,
.admin-wrapper:focus-within {
  scrollbar-color: #d1d5db transparent;
}

.admin-wrapper::-webkit-scrollbar { width: 5px; }
.admin-wrapper::-webkit-scrollbar-track { background: transparent; }
.admin-wrapper::-webkit-scrollbar-thumb { background: transparent; border-radius: 10px; }
.admin-wrapper:hover::-webkit-scrollbar-thumb,
.admin-wrapper:focus-within::-webkit-scrollbar-thumb { background: #d1d5db; }

/* ── Modal ──────────────────────────────────────────────────────────────────── */
.modal-content { border-radius: 12px; }

/* ── Form ───────────────────────────────────────────────────────────────────── */
.form-control:focus {
  border-color: #0d6efd;
  box-shadow: 0 0 0 3px rgba(13,110,253,.12);
}

/* ── Mobile ─────────────────────────────────────────────────────────────────── */
@media (max-width: 480px) {
  body { overflow: hidden; }
  .nav-title { font-size: 13px; max-width: 120px; }
  .chat-messages { padding: 1rem 0.75rem 0.5rem; }
  .msg-bubble { max-width: 85%; font-size: 13px; }
  .chat-input-bar { padding: 8px 10px 10px; }
  .modal-dialog { margin: 0.5rem; }
  .suggestion-btn { font-size: 11px; }
}

/* ── Welcome screen ─────────────────────────────────────────────────────────── */
.welcome-screen {
  position: fixed;
  top: 80px; left: 0; right: 0; bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fff;
  padding: 1rem;
  padding-bottom: 8rem;
  z-index: 10;
}

.welcome-body {
  width: 100%;
  max-width: 680px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
}

.welcome-greeting { text-align: center; }

.welcome-brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}

.welcome-logo { height: 48px; object-fit: contain; }

.welcome-title {
  font-size: 36px;
  font-weight: 600;
  color: #1a1a1a;
  line-height: 1;
}

.welcome-sub {
  font-size: 14px;
  color: #6b7280;
  margin: 0;
}

.welcome-input-wrap { width: 100%; }

.welcome-input-wrap .chat-input-inner {
  max-width: 100%;
  box-shadow: 0 2px 12px rgba(0,0,0,.08);
  border-radius: 14px;
  padding: 6px 6px 6px 4px;
  background: #fff;
  border: 1px solid #e5e7eb;
  align-items: center;
}

.welcome-input-wrap .chat-textarea {
  border: none;
  border-radius: 10px;
  background: transparent;
  font-size: 16px;
  line-height: 24px;
  padding: 16px 18px;
  height: 56px; /* 16px + 16px padding + 24px line-height — matches rows="1" exactly */
  overflow: hidden;
  resize: none;
}

.welcome-input-wrap .chat-textarea:focus {
  box-shadow: none;
  border: none;
}

.welcome-input-wrap .send-btn {
  height: 48px;
  width: 48px;
  border-radius: 10px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  background-color: #0d6efd;
  border-color: #0d6efd;
}

.welcome-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

.chip-btn {
  background: #f9fafb;
  border: 1px solid #e5e7eb;
  border-radius: 20px;
  padding: 7px 16px;
  font-size: 13px;
  color: #374151;
  cursor: pointer;
  transition: all .15s;
  white-space: nowrap;
}

.chip-btn:hover {
  background: #f0f4ff;
  border-color: #c7d7fd;
  color: #0d6efd;
}

@media (max-width: 480px) {
  .welcome-title { font-size: 18px; }
  .chip-btn { font-size: 12px; padding: 6px 12px; }
}

/* ── Welcome bot illustration ───────────────────────────────────────────────── */
.welcome-bot {
  display: flex;
  justify-content: center;
  margin-bottom: 8px;
}

.welcome-bot-img { height: 160px; width: auto; }

@media (max-width: 480px) {
  .welcome-bot-img { height: 110px; }
}

/* ── Admin panel ─────────────────────────────────────────────────────────────── */
.admin-wrapper {
  padding-top: 80px;
  min-height: 100vh;
  background: #f8f9fa;
  overflow-y: auto;
  height: 100vh;
  height: 100dvh;
}

.admin-container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 2rem 1rem;
}

.admin-card {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  overflow: hidden;
}

.admin-card-header {
  padding: 12px 16px;
  font-weight: 500;
  font-size: 13.5px;
  background: #f9fafb;
  border-bottom: 1px solid #e5e7eb;
}

.admin-card-body { padding: 16px; }

.btn-xs {
  padding: 2px 7px;
  font-size: 11px;
  border-radius: 6px;
}

/* ── Profile page ────────────────────────────────────────────────────────────── */
.profile-wrapper {
  padding-top: 80px;
  min-height: 100vh;
  background: #f8f9fa;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-left: 1rem;
  padding-right: 1rem;
  padding-bottom: 2rem;
}

.profile-card {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  padding: 2rem;
  width: 100%;
  max-width: 440px;
  margin-top: 2rem;
  box-shadow: 0 1px 6px rgba(0,0,0,.06);
}

.profile-header {
  display: flex;
  align-items: center;
  gap: 16px;
}

.profile-avatar {
  font-size: 2.5rem;
  color: #6b7280;
  line-height: 1;
}
/* ── Session sidebar ─────────────────────────────────────────────────────────── */
.app-sidebar {
  --bs-offcanvas-width: 260px;
  background: #faf9fb;
  border-right: 1px solid #e5e7eb;
  z-index: 90; /* below navbar (100), above page content */
}

.sidebar-body {
  padding: 12px;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.new-chat-btn {
  border: 1px solid #d1d5db;
  background: #fff;
  color: #1a1a1a;
  border-radius: 10px;
  font-size: 13.5px;
  padding: 9px 12px;
  text-align: left;
  font-weight: 500;
}

.new-chat-btn:hover {
  background: #f4f4f5;
}

.sidebar-session-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-top: 4px;
}

.session-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  color: #374151;
}

.session-item:hover {
  background: #eef0f3;
}

.session-item.active {
  background: #ece5f5;
  color: #462C7D;
  font-weight: 500;
}

.session-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
}

.session-delete-btn {
  border: none;
  background: transparent;
  color: #9ca3af;
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  border-radius: 6px;
  display: none;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  padding: 0;
}

.session-item:hover .session-delete-btn {
  display: inline-flex;
}

.session-delete-btn:hover {
  background: #e5e7eb;
  color: #dc2626;
}

/* Desktop (Bootstrap's `lg` breakpoint, matching `offcanvas-lg`): make the
   sidebar a real fixed column below the navbar, and shift main content over.
   We force position:fixed ourselves because Bootstrap's own responsive
   offcanvas behavior switches to position:static at this breakpoint, which
   would otherwise let the sidebar collide with the fixed navbar above it. */
@media (min-width: 992px) {
  .app-sidebar {
    position: fixed !important;
    top: 80px;
    left: 0;
    bottom: 0;
    width: 260px;
    visibility: visible !important;
    transform: none !important;
  }

  .chat-wrapper {
    margin-left: 260px;
  }

  .welcome-screen {
    left: 260px;
  }
}

@media (max-width: 991.98px) {
  .app-sidebar { top: 80px; }
}