/* =========================================================================
   DhowCSD RAG Assistant — Stylesheet
   ========================================================================= */

:root {
  --primary:        #1D4ED8;
  --primary-hover:  #1E40AF;
  --primary-faint:  #EFF6FF;
  --primary-border: #BFDBFE;

  --bg:             #F9FAFB;
  --surface:        #FFFFFF;
  --border:         #E5E7EB;
  --text:           #111827;
  --text-muted:     #6B7280;
  --text-light:     #9CA3AF;

  --user-bg:        #1D4ED8;
  --ai-bg:          #FFFFFF;

  --success:        #10B981;
  --error:          #EF4444;

  --radius:         12px;
  --radius-sm:      8px;
  --radius-lg:      18px;
  --shadow:         0 1px 2px rgba(0,0,0,.06), 0 2px 8px rgba(0,0,0,.04);

  --header-h:       57px;
  --max-w:          720px;
  --transition:     140ms cubic-bezier(.4,0,.2,1);
}

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

html, body {
  height: 100%;
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  font-size: 15px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

/* ── App shell ──────────────────────────────────────────────────────────── */
.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* =========================================================================
   HEADER
   ========================================================================= */
.header {
  height: var(--header-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  padding: 0 20px;
}

.header-inner {
  width: 100%;
  max-width: var(--max-w);
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-text {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -.2px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 11px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 99px;
  font-size: 12px;
  color: var(--text-muted);
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-light);
  flex-shrink: 0;
  transition: background var(--transition);
}
.status-dot.online  {
  background: var(--success);
  box-shadow: 0 0 0 2px rgba(16,185,129,.18);
}
.status-dot.offline { background: var(--error); }

/* =========================================================================
   CHAT AREA
   ========================================================================= */
.chat {
  flex: 1;
  overflow-y: auto;
  padding: 32px 20px 16px;
  scroll-behavior: smooth;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.chat::-webkit-scrollbar       { width: 5px; }
.chat::-webkit-scrollbar-thumb { background: var(--border); border-radius: 5px; }

/* ── Welcome screen ─────────────────────────────────────────────────────── */
.welcome {
  max-width: var(--max-w);
  margin: 32px auto 0;
  text-align: center;
  animation: fadeUp .35s ease;
}

.welcome-avatar {
  display: flex;
  justify-content: center;
  margin-bottom: 18px;
}

.welcome h2 {
  font-size: 24px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -.4px;
  margin-bottom: 10px;
}

.welcome p {
  font-size: 14.5px;
  color: var(--text-muted);
  line-height: 1.65;
  max-width: 520px;
  margin: 0 auto 32px;
}

.suggestions {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  max-width: 600px;
  margin: 0 auto;
}

.suggestion {
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13.5px;
  color: var(--text);
  cursor: pointer;
  text-align: left;
  line-height: 1.45;
  transition: border-color var(--transition), box-shadow var(--transition), background var(--transition);
  font-family: inherit;
}
.suggestion:hover {
  border-color: var(--primary-border);
  background: var(--primary-faint);
  box-shadow: 0 0 0 3px rgba(29,78,216,.06);
  color: var(--primary);
}

/* ── Message rows ───────────────────────────────────────────────────────── */
.message-row {
  display: flex;
  gap: 12px;
  max-width: var(--max-w);
  margin: 0 auto 6px;
  padding: 4px 0;
  animation: fadeUp .2s ease;
}

.message-row.user {
  flex-direction: row-reverse;
}

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

/* ── Avatar ─────────────────────────────────────────────────────────────── */
.avatar {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 2px;
}
.avatar.ai {
  background: #1D4ED8;
}
.avatar.user {
  background: #E5E7EB;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
}

/* ── Bubble ─────────────────────────────────────────────────────────────── */
.bubble-wrap {
  display: flex;
  flex-direction: column;
  max-width: calc(100% - 44px);
}

.message-row.user .bubble-wrap {
  align-items: flex-end;
}

.bubble {
  padding: 11px 15px;
  border-radius: var(--radius-lg);
  font-size: 14.5px;
  line-height: 1.65;
  word-break: break-word;
  position: relative;
}

/* User bubble */
.message-row.user .bubble {
  background: var(--user-bg);
  color: #fff;
  border-bottom-right-radius: 5px;
}

/* AI bubble */
.message-row.ai .bubble {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  border-bottom-left-radius: 5px;
}

/* Markdown inside AI bubble */
.bubble-inner p               { margin-bottom: 9px; }
.bubble-inner p:last-child    { margin-bottom: 0; }
.bubble-inner h1,
.bubble-inner h2,
.bubble-inner h3              { font-size: 15px; font-weight: 700; margin: 12px 0 5px; }
.bubble-inner ul,
.bubble-inner ol              { padding-left: 20px; margin-bottom: 9px; }
.bubble-inner li              { margin-bottom: 4px; }
.bubble-inner code            {
  background: #F3F4F6;
  padding: 1px 5px;
  border-radius: 4px;
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 12.5px;
}
.bubble-inner pre             {
  background: #F3F4F6;
  padding: 10px 13px;
  border-radius: var(--radius-sm);
  overflow-x: auto;
  margin: 8px 0;
}
.bubble-inner pre code        { background: none; padding: 0; }
.bubble-inner a               { color: #3B82F6; text-decoration: underline; }
.bubble-inner strong          { font-weight: 600; }
.bubble-inner blockquote      {
  border-left: 3px solid var(--border);
  padding-left: 12px;
  color: var(--text-muted);
  margin: 6px 0;
}

/* ── Bubble actions (copy) ──────────────────────────────────────────────── */
.bubble-actions {
  display: none;
  gap: 4px;
  margin-top: 5px;
}
.message-row.ai:hover .bubble-actions { display: flex; }

.bubble-action {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 11.5px;
  color: var(--text-muted);
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
  font-family: inherit;
}
.bubble-action:hover { background: var(--bg); color: var(--text); }

/* ── Source pills ───────────────────────────────────────────────────────── */
.sources {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

.source-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 9px;
  background: var(--primary-faint);
  border: 1px solid var(--primary-border);
  border-radius: 99px;
  font-size: 11.5px;
  color: var(--primary);
  font-weight: 500;
  max-width: 210px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Feedback widget ────────────────────────────────────────────────────── */
.feedback-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  padding: 0 2px;
}
.feedback-label {
  font-size: 12px;
  color: var(--text-muted);
}
.fb-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 2px 8px;
  font-size: 14px;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition);
  line-height: 1.6;
}
.fb-btn:hover:not(:disabled) {
  background: var(--primary-faint);
  border-color: var(--primary-border);
}
.fb-btn.fb-active {
  background: var(--primary-faint);
  border-color: var(--primary);
}
.fb-btn:disabled { cursor: default; opacity: .7; }

/* ── Elapsed time ───────────────────────────────────────────────────────── */
.msg-meta {
  font-size: 11px;
  color: var(--text-light);
  margin-top: 5px;
  padding: 0 2px;
}

/* ── Typing indicator ───────────────────────────────────────────────────── */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 11px 15px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  border-bottom-left-radius: 5px;
  box-shadow: var(--shadow);
  width: fit-content;
}
.typing-dot {
  width: 7px;
  height: 7px;
  background: var(--text-light);
  border-radius: 50%;
  animation: tdot 1.2s infinite;
}
.typing-dot:nth-child(2) { animation-delay: .2s; }
.typing-dot:nth-child(3) { animation-delay: .4s; }
@keyframes tdot {
  0%, 60%, 100% { transform: translateY(0); background: var(--text-light); }
  30%           { transform: translateY(-5px); background: var(--primary); }
}

/* =========================================================================
   INPUT AREA
   ========================================================================= */
.input-wrap {
  flex-shrink: 0;
  background: var(--bg);
  padding: 12px 20px 18px;
}

.input-box {
  max-width: var(--max-w);
  margin: 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 10px 10px 10px 16px;
  box-shadow: var(--shadow);
  transition: border-color var(--transition), box-shadow var(--transition);
}
.input-box:focus-within {
  border-color: #93C5FD;
  box-shadow: 0 0 0 3px rgba(29,78,216,.07), var(--shadow);
}

textarea {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  resize: none;
  font-family: inherit;
  font-size: 14.5px;
  color: var(--text);
  line-height: 1.55;
  max-height: 150px;
  overflow-y: auto;
  scrollbar-width: thin;
}
textarea::placeholder { color: var(--text-light); }

.send-btn {
  flex-shrink: 0;
  width: 34px;
  height: 34px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition), transform var(--transition);
}
.send-btn:hover:not(:disabled) {
  background: var(--primary-hover);
  transform: scale(1.05);
}
.send-btn:disabled {
  background: #E5E7EB;
  color: var(--text-light);
  cursor: not-allowed;
  transform: none;
}

.input-hint {
  max-width: var(--max-w);
  margin: 7px auto 0;
  font-size: 11.5px;
  color: var(--text-light);
  text-align: center;
}
.input-hint kbd {
  display: inline-block;
  padding: 1px 5px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-family: inherit;
  font-size: 10.5px;
}

/* =========================================================================
   TOASTS
   ========================================================================= */
#toasts {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: flex-end;
}

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 15px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 4px 20px rgba(0,0,0,.1);
  font-size: 13px;
  color: var(--text);
  max-width: 300px;
  animation: toastIn .2s ease;
}
.toast.error   { border-left: 3px solid var(--error); }
.toast.success { border-left: 3px solid var(--success); }
.toast-icon    { font-size: 15px; line-height: 1; flex-shrink: 0; }

@keyframes toastIn {
  from { opacity: 0; transform: translateY(6px) scale(.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* =========================================================================
   RESPONSIVE
   ========================================================================= */
@media (max-width: 600px) {
  .suggestions { grid-template-columns: 1fr; }
  .welcome h2  { font-size: 20px; }
  .bubble      { font-size: 14px; }
}
