/* ── Brand palette (extracted from DocuBuddy logo) ── */
:root {
  --db-blue:        #2563EB;   /* cobalt blue – primary */
  --db-blue-light:  #EFF6FF;   /* tint for backgrounds  */
  --db-blue-hover:  #1D4ED8;   /* darker on hover       */
  --db-orange:      #F59E0B;   /* amber – accent / AI   */
  --db-orange-light:#FFF7ED;
  --db-sidebar-bg:  #FFFFFF;
  --db-admin-bg:    #F8FAFC;
  --db-border:      #E2E8F0;
  --db-text:        #1E293B;
  --db-muted:       #64748B;
}

/* ── Global ────────────────────────────────────────── */
body { color: var(--db-text); background: #F8FAFC; }

/* ── Brand utilities ───────────────────────────────── */
.db-text-primary  { color: var(--db-blue) !important; }

.db-btn-primary {
  background: var(--db-blue);
  border-color: var(--db-blue);
  color: #fff;
}
.db-btn-primary:hover, .db-btn-primary:focus {
  background: var(--db-blue-hover);
  border-color: var(--db-blue-hover);
  color: #fff;
}

.db-badge-primary {
  background: var(--db-blue-light);
  color: var(--db-blue);
}
.db-badge-secondary {
  background: #F1F5F9;
  color: var(--db-muted);
}

/* ── Layout ────────────────────────────────────────── */
.app-layout { height: 100vh; overflow: hidden; }

/* ── Sidebar ───────────────────────────────────────── */
.sidebar {
  width: 260px;
  flex-shrink: 0;
  background: var(--db-sidebar-bg);
  border-right: 1px solid var(--db-border);
}
.sidebar-header {
  padding: 1rem 1.1rem;
  border-bottom: 1px solid var(--db-border);
}
.sidebar-body   { padding: 0.5rem; }
/* new chat button */
.new-chat-btn {
  background: none;
  border: 1px solid var(--db-border);
  border-radius: 8px;
  padding: 0.55rem 0.8rem;
  color: var(--db-text);
  font-size: 0.9rem;
  transition: background .15s, border-color .15s;
}
.new-chat-btn:hover {
  background: var(--db-blue-light);
  border-color: var(--db-blue);
  color: var(--db-blue);
}
.new-chat-icon { font-size: 1rem; }

/* chat history list */
.sidebar-section-label {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--db-muted);
}
.chat-list { scrollbar-width: thin; }
.chat-list-item {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  border-radius: 8px;
  padding: 0.1rem 0.4rem 0.1rem 0.7rem;
  margin-bottom: 2px;
  transition: background .12s;
}
.chat-list-item:hover  { background: var(--db-blue-light); }
.chat-list-item.active { background: var(--db-blue-light); }

.chat-list-label {
  flex: 1;
  font-size: 0.85rem;
  color: var(--db-text);
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 0.4rem 0;
}
.chat-list-item:hover  .chat-list-label,
.chat-list-item.active .chat-list-label { color: var(--db-blue); font-weight: 500; }

.chat-list-delete {
  flex-shrink: 0;
  display: none;
  background: none;
  border: none;
  border-radius: 4px;
  color: var(--db-muted);
  font-size: 1rem;
  line-height: 1;
  padding: 0.2rem 0.35rem;
  cursor: pointer;
  transition: background .12s, color .12s;
}
.chat-list-item:hover .chat-list-delete { display: block; }
.chat-list-delete:hover { background: #FEE2E2; color: #DC2626; }

.sidebar-footer {
  padding: 0.75rem;
  border-top: 1px solid var(--db-border);
}

/* user menu trigger */
.user-menu-btn {
  background: none;
  border: none;
  border-radius: 8px;
  padding: 0.5rem 0.6rem;
  cursor: pointer;
  color: var(--db-text);
}
.user-menu-btn:hover { background: var(--db-blue-light); }

.user-avatar {
  width: 30px; height: 30px;
  border-radius: 50%;
  background: var(--db-blue);
  color: #fff;
  font-size: 0.75rem;
}

/* user dropdown pops above footer */
.user-menu-dropdown {
  display: none;
  position: absolute;
  bottom: calc(100% + 8px);
  left: 8px; right: 8px;
  z-index: 200;
  border: 1px solid #E2E8F0;
  overflow: hidden;
  animation: menuFadeIn .12s ease;
}
.user-menu-dropdown.open { display: block; }

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

.user-menu-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.65rem 1rem;
  color: var(--db-text);
  font-size: 0.875rem;
  font-weight: 500;
  text-decoration: none;
  transition: background .12s;
}
.user-menu-item:hover { background: var(--db-blue-light); color: var(--db-blue); }
.user-menu-item--danger { color: #DC2626; }
.user-menu-item--danger:hover { background: #FEE2E2; color: #DC2626; }
.user-menu-icon { font-size: 1rem; width: 20px; text-align: center; }

/* ── Admin background ──────────────────────────────── */
.db-admin-bg { background: var(--db-admin-bg); }

/* ── Admin sidebar nav ─────────────────────────────── */
.admin-nav-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.55rem 0.75rem;
  border-radius: 8px;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--db-text);
  text-decoration: none;
  transition: background .12s, color .12s;
  margin-bottom: 2px;
}
.admin-nav-item:hover  { background: var(--db-blue-light); color: var(--db-blue); }
.admin-nav-item.active { background: var(--db-blue-light); color: var(--db-blue); font-weight: 600; }
.admin-nav-icon { font-size: 1rem; width: 20px; text-align: center; }
.sidebar-divider { border-top: 1px solid var(--db-border); }

/* ── Login ─────────────────────────────────────────── */
.login-bg { background: linear-gradient(135deg, var(--db-blue-light) 0%, #FFF7ED 100%); }
.login-card { width: 420px; border-radius: 16px; }

/* ── Chat ──────────────────────────────────────────── */
.chat-main { overflow: hidden; background: #F8FAFC; }

#messagesScroll { background: #F8FAFC; }

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

.message { display: flex; gap: 0.75rem; width: 100%; }
.message.user { flex-direction: row-reverse; }
.message.ai   { flex-direction: row; }

.msg-avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.75rem; font-weight: 700; flex-shrink: 0;
}
.message.user .msg-avatar { background: var(--db-blue); color: #fff; }
.message.ai   .msg-avatar { background: transparent; overflow: hidden; }

.msg-bubble {
  padding: 0.75rem 1rem;
  border-radius: 12px;
  font-size: 0.95rem;
  line-height: 1.65;
  max-width: 660px;
  word-break: break-word;
}
.message.user .msg-bubble {
  background: var(--db-blue);
  color: #fff;
  border-bottom-right-radius: 4px;
  /* plain text (not markdown-rendered) — preserve the user's own line breaks */
  white-space: pre-wrap;
}
.message.ai .msg-bubble {
  background: #EFF6FF;
  color: var(--db-text);
  border: 1px solid #BFDBFE;
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 3px rgba(37,99,235,.08);
  /* markdown is rendered to real HTML (p/ul/li/etc.) — pre-wrap would also
     render whitespace inside that markup as extra visual line breaks,
     stacking on top of the elements' own spacing */
}
.msg-bubble.error {
  color: #DC2626;
  white-space: pre-wrap;
}

/* markdown inside AI bubbles */
.message.ai .msg-bubble p          { margin-bottom: .5rem; }
.message.ai .msg-bubble p:last-child { margin-bottom: 0; }
.message.ai .msg-bubble h1,
.message.ai .msg-bubble h2,
.message.ai .msg-bubble h3         { font-size: 1rem; font-weight: 700; margin: .75rem 0 .35rem; }
.message.ai .msg-bubble ul,
.message.ai .msg-bubble ol         { padding-left: 1.4rem; margin-bottom: .5rem; }
.message.ai .msg-bubble li         { margin-bottom: .2rem; }
.message.ai .msg-bubble strong     { font-weight: 700; color: var(--db-text); }
.message.ai .msg-bubble em         { font-style: italic; }
.message.ai .msg-bubble code       { background: #E0EDFF; color: var(--db-blue); padding: .1rem .35rem; border-radius: 4px; font-size: .85em; font-family: monospace; }
.message.ai .msg-bubble pre        { background: #1E293B; color: #E2E8F0; border-radius: 8px; padding: .85rem 1rem; overflow-x: auto; margin: .5rem 0; }
.message.ai .msg-bubble pre code   { background: none; color: inherit; padding: 0; font-size: .85rem; }
.message.ai .msg-bubble blockquote { border-left: 3px solid var(--db-blue); padding-left: .75rem; color: var(--db-muted); margin: .5rem 0; }
.message.ai .msg-bubble hr         { border-color: var(--db-border); margin: .75rem 0; }
.message.ai .msg-bubble table      { width: 100%; border-collapse: collapse; font-size: .875rem; margin: .5rem 0; }
.message.ai .msg-bubble th,
.message.ai .msg-bubble td         { border: 1px solid var(--db-border); padding: .35rem .6rem; }
.message.ai .msg-bubble th         { background: var(--db-blue-light); font-weight: 600; }

/* thinking dots */
.thinking-dots {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 0;
}
.thinking-dots span {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--db-blue);
  opacity: 0.3;
  animation: thinking-bounce 1.2s infinite ease-in-out;
}
.thinking-dots span:nth-child(1) { animation-delay: 0s; }
.thinking-dots span:nth-child(2) { animation-delay: 0.2s; }
.thinking-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes thinking-bounce {
  0%, 80%, 100% { transform: scale(0.7); opacity: 0.3; }
  40%           { transform: scale(1.1); opacity: 1; }
}

.chat-input-bar { background: #fff; box-shadow: 0 -1px 0 var(--db-border); }

/* provider toggle */
.provider-toggle {
  display: inline-flex;
  background: #F1F5F9;
  border-radius: 8px;
  padding: 3px;
  gap: 2px;
}
.provider-toggle-btn {
  background: none;
  border: none;
  border-radius: 6px;
  padding: .25rem .75rem;
  font-size: .8rem;
  font-weight: 500;
  color: var(--db-muted);
  cursor: pointer;
  transition: background .12s, color .12s;
}
.provider-toggle-btn.active {
  background: #fff;
  color: var(--db-blue);
  box-shadow: 0 1px 3px rgba(0,0,0,.1);
}
.chat-input {
  resize: none; max-height: 160px;
  font-family: inherit; line-height: 1.5;
  border-color: var(--db-border);
}
.chat-input:focus { border-color: var(--db-blue); box-shadow: 0 0 0 .2rem rgba(37,99,235,.15); }

/* ── Document status badges ────────────────────────── */
.badge-pending    { background: #FEF9C3 !important; color: #92400E !important; border: 1px solid #FDE68A; }
.badge-processing { background: #DBEAFE !important; color: #1D4ED8 !important; border: 1px solid #BFDBFE; }
.badge-done       { background: #DCFCE7 !important; color: #166534 !important; border: 1px solid #BBF7D0; }
.badge-error      { background: #FEE2E2 !important; color: #991B1B !important; border: 1px solid #FECACA; }

/* ── Upload area ───────────────────────────────────── */
.upload-area {
  border: 2px dashed var(--db-border);
  border-radius: 12px;
  padding: 2.5rem;
  text-align: center;
  background: var(--db-blue-light);
  cursor: pointer;
  transition: border-color .2s, background .2s;
}
.upload-area:hover, .upload-area.drag-over {
  border-color: var(--db-blue);
  background: #E0EDFF;
}
.upload-icon { font-size: 2rem; }

/* ── Cards in admin ────────────────────────────────── */
.card { border-radius: 12px !important; }
.card-header {
  border-radius: 12px 12px 0 0 !important;
  padding: .8rem 1.25rem;
  font-size: .9rem;
  letter-spacing: .02em;
  color: var(--db-muted);
  text-transform: uppercase;
}

/* ── Provider radio cards ──────────────────────────── */
.provider-radio {
  flex: 1;
  max-width: 180px;
  border: 2px solid var(--db-border);
  border-radius: 12px;
  padding: 1rem 1.25rem;
  cursor: pointer;
  transition: border-color .15s, background .15s;
  text-align: center;
  user-select: none;
}
.provider-radio:hover { border-color: var(--db-blue); background: var(--db-blue-light); }
.provider-radio.selected {
  border-color: var(--db-blue);
  background: var(--db-blue-light);
}
.provider-radio-icon { font-size: 1.6rem; margin-bottom: .4rem; }

.provider-active-badge {
  background: var(--db-blue-light);
  color: var(--db-blue);
  border: 1px solid #BFDBFE;
  font-size: 0.72rem;
  font-weight: 600;
  padding: .25rem .6rem;
  border-radius: 999px;
  align-items: center;
}

/* ── Form controls ─────────────────────────────────── */
.form-control:focus, .form-select:focus {
  border-color: var(--db-blue);
  box-shadow: 0 0 0 .2rem rgba(37,99,235,.15);
}
