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

:root {
  /* ── WhatsApp Dark Mode palette ── */
  --bg: #0B141A;
  --surface: #202C33;
  --surface-alt: #2A3942;
  --border: #3B4A54;
  --text: #E9EDEF;
  --text-muted: #8696A0;
  --accent: #00A884;
  --accent-hover: #00906F;
  --user-bubble: #005C4B;
  --ai-bubble: #1F2C33;
  --success: #00A884;
  --warning: #F7C948;
  --danger: #EA4335;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --mono: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
  --radius: 10px;
  --nav-height: 56px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);

  /* ── Premium polish tokens ── */
  --shadow-bubble: 0 1px 3px rgba(0,0,0,.25);
  --shadow-bubble-user: 0 1px 3px rgba(0,92,75,.3);
  --glow-accent: 0 0 0 2px rgba(0,168,132,.25);
  --transition-smooth: cubic-bezier(.4, 0, .2, 1);
}

html, body {
  height: 100%; width: 100%;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

/* ── Layout ── */
#app {
  display: flex; flex-direction: column;
  height: 100dvh; max-width: 800px; margin: 0 auto;
  position: relative;
}

/* ══════════════════════════════════
   Header — WhatsApp style
   ══════════════════════════════════ */
header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 10px;
  padding-top: calc(6px + var(--safe-top));
  background: var(--surface);
  box-shadow: 0 1px 4px rgba(0,0,0,.2);
  flex-shrink: 0;
  min-height: 48px;
}
.header-left { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1; }
header h1 {
  font-size: 16px; font-weight: 700; white-space: nowrap;
  color: var(--text); letter-spacing: -0.2px;
  margin: 0; line-height: 1.1;
}

/* ── Header avatar (WhatsApp/Telegram style) ── */
.header-avatar {
  width: 38px; height: 38px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #006e51);
  display: flex; align-items: center; justify-content: center;
  font-size: 15px; font-weight: 700; color: #fff;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(0,168,132,.25), inset 0 1px 0 rgba(255,255,255,.18);
  position: relative;
}
.header-avatar::after {
  content: '';
  position: absolute; inset: 0;
  border-radius: 50%;
  background: linear-gradient(180deg, rgba(255,255,255,.15) 0%, transparent 50%);
}
.header-info {
  display: flex; flex-direction: column; min-width: 0; gap: 1px;
}
.header-subtitle {
  font-size: 11px; color: #00d9a3;
  font-weight: 500; line-height: 1.1;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  transition: color .2s var(--transition-smooth);
}
.header-subtitle.typing { color: var(--accent); font-style: italic; }
.header-right { display: flex; gap: 2px; align-items: center; flex-shrink: 0; }
.icon-btn {
  background: none; border: none; color: var(--text-muted);
  cursor: pointer; padding: 8px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s;
  min-width: 40px; min-height: 40px;
}
.icon-btn:hover, .icon-btn:active { background: rgba(255,255,255,.08); }

/* ── Matter indicator pill ── */
#matter-indicator {
  font-size: 11px; padding: 4px 12px; border-radius: 14px;
  background: rgba(0,168,132,.08); color: var(--text-muted);
  border: 1px solid rgba(0,168,132,.15); cursor: pointer;
  max-width: 150px; overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap; transition: all .2s var(--transition-smooth);
  min-height: 26px; display: flex; align-items: center;
  font-weight: 500;
}
#matter-indicator:hover { border-color: var(--accent); color: var(--text); }
#matter-indicator.active {
  background: rgba(0,168,132,.15); color: var(--accent);
  border-color: var(--accent);
}

/* ══════════════════════════════════
   Chat area — WhatsApp style with wallpaper
   ══════════════════════════════════ */
#chat {
  flex: 1; overflow-y: auto; padding: 10px 14px;
  display: flex; flex-direction: column; gap: 4px;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
  background: #0B141A;
  /* Subtle doodle wallpaper like WhatsApp */
  background-image: url("data:image/svg+xml,%3Csvg width='60' height='60' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M15 5l5 5-5 5M40 10h10M5 30h10M45 25l5 5-5 5M20 45l-5 5 5 5M35 50h10' stroke='%23172229' stroke-width='1.2' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
}
#chat::-webkit-scrollbar { width: 3px; }
#chat::-webkit-scrollbar-thumb { background: rgba(255,255,255,.12); border-radius: 2px; }

/* ══════════════════════════════════
   Messages — WhatsApp bubbles
   ══════════════════════════════════ */
.msg { max-width: 85%; animation: fadeIn .25s var(--transition-smooth); margin: 3px 0; }
.msg.user { align-self: flex-end; }
.msg.ai { align-self: flex-start; }

.msg .bubble {
  padding: 9px 14px 8px; border-radius: 10px;
  line-height: 1.5; font-size: 14.5px; word-wrap: break-word;
  position: relative;
}
.msg.user .bubble {
  background: var(--user-bubble);
  border-top-right-radius: 0;
  box-shadow: var(--shadow-bubble-user);
  position: relative;
}
.msg.ai .bubble {
  background: var(--ai-bubble);
  border-top-left-radius: 0;
  box-shadow: var(--shadow-bubble);
  position: relative;
}

/* ── Bubble tails (the SVG triangle pointing to sender) ── */
.msg.has-tail .bubble::before {
  content: '';
  position: absolute;
  top: 0; width: 8px; height: 13px;
  pointer-events: none;
}
.msg.user.has-tail .bubble::before {
  right: -7px;
  background: var(--user-bubble);
  clip-path: polygon(0 0, 100% 0, 0 100%);
  filter: drop-shadow(1px 0 1px rgba(0,92,75,.2));
}
.msg.ai.has-tail .bubble::before {
  left: -7px;
  background: var(--ai-bubble);
  clip-path: polygon(0 0, 100% 0, 100% 100%);
  filter: drop-shadow(-1px 0 1px rgba(0,0,0,.2));
}

/* ── Message grouping (consecutive same-sender) ── */
.msg.grouped {
  margin-top: 1px;
}
.msg.grouped.user .bubble {
  border-top-right-radius: 10px; /* full corner since no tail */
}
.msg.grouped.ai .bubble {
  border-top-left-radius: 10px;
}
/* Hide timestamp on all but the LAST message in a group */
.msg.grouped-above .msg-time {
  display: none;
}

/* ── Date separator pill ── */
.date-sep {
  align-self: center;
  background: rgba(32,44,51,.85);
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
  padding: 4px 12px;
  border-radius: 10px;
  margin: 12px 0 6px;
  text-shadow: 0 1px 2px rgba(0,0,0,.3);
  backdrop-filter: blur(6px);
  box-shadow: 0 1px 3px rgba(0,0,0,.3);
  letter-spacing: 0.2px;
}

/* ── Jump-to-bottom button ── */
#chat-wrap {
  position: relative;
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.j2b {
  position: absolute;
  right: 14px;
  bottom: 14px;
  width: 38px; height: 38px;
  border-radius: 50%;
  background: var(--surface);
  color: var(--text);
  border: 1px solid rgba(255,255,255,.08);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(0,0,0,.4);
  opacity: 0;
  transform: translateY(8px) scale(.9);
  pointer-events: none;
  transition: all .2s var(--transition-smooth);
  z-index: 5;
}
.j2b.visible {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}
.j2b:hover { background: var(--surface-alt); }
.j2b:active { transform: scale(.92); }
.j2b-count {
  position: absolute;
  top: -4px; right: -4px;
  background: var(--accent);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  min-width: 18px; height: 18px;
  border-radius: 9px;
  padding: 0 5px;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 2px 6px rgba(0,168,132,.4);
}
.j2b-count:empty { display: none; }

/* ── Empty state (prompt picker) ── */
.empty-state {
  align-self: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 20px 16px 40px;
  max-width: 480px;
  margin: 30px auto 0;
  animation: fadeIn .4s var(--transition-smooth);
}
.empty-state.hidden { display: none; }
.empty-state-avatar {
  width: 72px; height: 72px;
  border-radius: 18px;
  background: linear-gradient(135deg, var(--accent), #006e51);
  display: flex; align-items: center; justify-content: center;
  font-size: 32px; font-weight: 700; color: #fff;
  box-shadow: 0 8px 28px rgba(0,168,132,.35), inset 0 2px 0 rgba(255,255,255,.18);
  position: relative;
  margin-bottom: 18px;
}
.empty-state-avatar::after {
  content: '';
  position: absolute; inset: 0;
  border-radius: 18px;
  background: linear-gradient(180deg, rgba(255,255,255,.18) 0%, transparent 50%);
}
.empty-state-title {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.3px;
  margin: 0 0 6px;
  color: var(--text);
}
.empty-state-sub {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.5;
  margin: 0 0 24px;
  max-width: 320px;
}
.empty-state-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}
.empty-chip {
  font-size: 13px;
  padding: 9px 14px;
  border-radius: 18px;
  border: 1px solid rgba(0,168,132,.3);
  background: rgba(0,168,132,.06);
  color: var(--accent);
  cursor: pointer;
  font-weight: 500;
  transition: all .15s var(--transition-smooth);
  font-family: inherit;
  -webkit-tap-highlight-color: transparent;
  animation: chipsIn .35s var(--transition-smooth) both;
}
.empty-chip:nth-child(1) { animation-delay: .05s; }
.empty-chip:nth-child(2) { animation-delay: .1s; }
.empty-chip:nth-child(3) { animation-delay: .15s; }
.empty-chip:nth-child(4) { animation-delay: .2s; }
.empty-chip:nth-child(5) { animation-delay: .25s; }
.empty-chip:nth-child(6) { animation-delay: .3s; }
.empty-chip:hover {
  background: rgba(0,168,132,.15);
  border-color: var(--accent);
  transform: translateY(-1px);
}
.empty-chip:active { transform: scale(.96); }

/* Memo markdown inside AI bubbles */
.msg.ai .bubble h3 { font-size: 14px; font-weight: 700; margin: 10px 0 4px; color: var(--accent); }
.msg.ai .bubble h4 { font-size: 13px; font-weight: 600; margin: 8px 0 4px; color: #aebac1; }
.msg.ai .bubble p { margin: 4px 0; }
.msg.ai .bubble ul, .msg.ai .bubble ol { padding-left: 18px; margin: 4px 0; }
.msg.ai .bubble blockquote {
  border-left: 3px solid var(--accent); padding-left: 10px;
  color: var(--text-muted); margin: 6px 0; font-style: italic;
}
.msg.ai .bubble code {
  background: rgba(0,0,0,.3); padding: 2px 5px; border-radius: 3px;
  font-family: var(--mono); font-size: 12px;
}
.msg.ai .bubble strong { color: #e9edef; }

/* ── Cross-reference note ── */
.crossref-note { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.crossref-note summary { cursor: pointer; color: var(--text-muted); font-style: italic; }
.crossref-note summary:hover { color: var(--text); }
.crossref-note p { margin-top: 6px; line-height: 1.5; color: var(--text-muted); }

/* ── Tables ── */
.table-wrap { overflow-x: auto; margin: 8px 0; -webkit-overflow-scrolling: touch; }
.memo-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.memo-table th, .memo-table td {
  padding: 6px 8px; text-align: left;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.memo-table th {
  background: rgba(0,0,0,.2); font-weight: 600; font-size: 11px;
  text-transform: uppercase; letter-spacing: .3px;
  color: var(--text-muted); white-space: nowrap;
}
.memo-table tr:hover td { background: rgba(255,255,255,.03); }

/* ── RAG priority badges ── */
.rag-badge {
  display: inline-block; padding: 2px 8px; border-radius: 4px;
  font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: .3px;
}
.rag-red { background: rgba(234,67,53,.15); color: #f87171; border: 1px solid rgba(234,67,53,.25); }
.rag-amber { background: rgba(247,201,72,.15); color: #fbbf24; border: 1px solid rgba(247,201,72,.25); }
.rag-green { background: rgba(0,168,132,.15); color: #00d9a3; border: 1px solid rgba(0,168,132,.25); }

/* ── Sources expandable ── */
.sources-toggle {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 12px; color: var(--accent); cursor: pointer;
  margin-top: 4px; padding: 4px 0; border: none; background: none;
}
.sources-list {
  display: none; margin-top: 4px; font-size: 12px;
  color: var(--text-muted); padding-left: 10px;
  border-left: 2px solid rgba(255,255,255,.1);
}
.sources-list.open { display: block; }
.sources-list div { padding: 2px 0; }

/* ── Usage / thinking badges ── */
.usage-badge {
  display: inline-flex; gap: 8px; margin-top: 3px;
  font-size: 10px; color: var(--text-muted); align-items: center;
}
.usage-badge span { opacity: .6; }
.usage-badge .cost-pill {
  opacity: 1; font-weight: 600; background: rgba(0,168,132,.15);
  color: #00d9a3; padding: 1px 6px; border-radius: 3px; font-size: 10px;
}
.thinking-badge {
  display: inline-block; font-size: 10px; padding: 2px 8px;
  border-radius: 4px; margin-top: 3px;
}
.thinking-badge.adaptive { background: rgba(0,168,132,.12); color: #00d9a3; }
.thinking-badge.disabled { background: rgba(255,255,255,.05); color: #8696a0; }

/* ══════════════════════════════════
   WhatsApp-style chat list rows (History panel)
   ══════════════════════════════════ */
.chat-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  cursor: pointer;
  border-bottom: 1px solid rgba(255,255,255,.04);
  transition: background .15s var(--transition-smooth);
  -webkit-tap-highlight-color: transparent;
}
.chat-row:hover { background: rgba(255,255,255,.03); }
.chat-row:active { background: rgba(255,255,255,.06); }
.chat-row.active { background: rgba(0,168,132,.08); }

.chat-row-avatar {
  width: 50px; height: 50px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: #fff;
  font-size: 17px;
  font-weight: 700;
  flex-shrink: 0;
  box-shadow: 0 2px 6px rgba(0,0,0,.3), inset 0 1px 0 rgba(255,255,255,.18);
  position: relative;
  overflow: hidden;
}
.chat-row-avatar::after {
  content: '';
  position: absolute; inset: 0;
  background: linear-gradient(180deg, rgba(255,255,255,.15) 0%, transparent 50%);
}
.chat-row-body {
  flex: 1; min-width: 0;
  display: flex; flex-direction: column; gap: 2px;
}
.chat-row-line1 {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}
.chat-row-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  min-width: 0;
}
.chat-row.active .chat-row-title { color: var(--accent); }
.chat-row-time {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 500;
  flex-shrink: 0;
}
.chat-row-line2 {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}
.chat-row-preview {
  font-size: 12.5px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  line-height: 1.3;
}
.chat-row-matter {
  font-size: 10px;
  color: rgba(0,168,132,.7);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  margin-top: 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-row-delete {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 18px;
  cursor: pointer;
  width: 24px; height: 24px;
  border-radius: 50%;
  opacity: 0;
  transition: all .15s;
  flex-shrink: 0;
}
.chat-row:hover .chat-row-delete {
  opacity: .6;
}
.chat-row-delete:hover {
  background: rgba(234,67,53,.15);
  color: var(--danger);
  opacity: 1;
}
@media (hover: none) {
  .chat-row-delete { opacity: .4; }
}

/* Loading state shown while a conversation is being fetched */
.chat-loading {
  align-self: center;
  display: flex;
  gap: 6px;
  padding: 60px 0;
}
.chat-loading .dot {
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--accent);
  opacity: .5;
  animation: bounce 1.2s ease-in-out infinite;
}
.chat-loading .dot:nth-child(2) { animation-delay: .2s; }
.chat-loading .dot:nth-child(3) { animation-delay: .4s; }

.empty-list-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 60px 24px;
  color: var(--text-muted);
  text-align: center;
}
.empty-list-icon {
  font-size: 40px;
  margin-bottom: 14px;
  opacity: .5;
}
.empty-list-state p {
  font-size: 14px;
  margin: 4px 0;
}
.empty-list-state .hint {
  font-size: 12px;
  opacity: .6;
}

/* ══════════════════════════════════
   Long-press action sheet
   ══════════════════════════════════ */
#action-sheet-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.5);
  opacity: 0;
  transition: opacity .2s var(--transition-smooth);
  z-index: 90;
  pointer-events: none;
}
#action-sheet-backdrop.visible { opacity: 1; pointer-events: auto; }
#action-sheet-backdrop.hidden { display: none; }

#action-sheet {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: var(--surface);
  border-radius: 16px 16px 0 0;
  padding: 8px 8px calc(20px + var(--safe-bottom));
  z-index: 91;
  transform: translateY(100%);
  transition: transform .25s var(--transition-smooth);
  box-shadow: 0 -4px 24px rgba(0,0,0,.5);
  max-width: 480px; margin: 0 auto;
}
#action-sheet.visible { transform: translateY(0); }
#action-sheet.hidden { display: none; }

.action-sheet-handle {
  width: 36px; height: 4px;
  background: rgba(255,255,255,.2);
  border-radius: 2px;
  margin: 6px auto 12px;
}

/* Emoji reaction row at top of action sheet */
.reaction-row {
  display: flex;
  justify-content: space-around;
  align-items: center;
  padding: 4px 12px 12px;
  margin-bottom: 4px;
  border-bottom: 1px solid rgba(255,255,255,.06);
}
.reaction-btn {
  width: 44px; height: 44px;
  border-radius: 50%;
  border: none;
  background: rgba(255,255,255,.04);
  font-size: 22px;
  cursor: pointer;
  transition: all .15s var(--transition-smooth);
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
}
.reaction-btn:hover {
  background: rgba(0,168,132,.15);
  transform: scale(1.15);
}
.reaction-btn:active {
  transform: scale(.92);
}

/* Reaction pill displayed below a message bubble */
.reaction-pill {
  position: absolute;
  bottom: -10px;
  right: 8px;
  background: var(--surface);
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 12px;
  padding: 1px 8px;
  font-size: 14px;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0,0,0,.4);
  transition: all .15s var(--transition-smooth);
  user-select: none;
  z-index: 2;
}
.msg.user .reaction-pill { right: auto; left: 8px; }
.reaction-pill:hover { transform: scale(1.1); }

.action-item {
  display: flex; align-items: center; gap: 14px;
  width: 100%;
  padding: 14px 16px;
  background: none;
  border: none;
  border-radius: 10px;
  color: var(--text);
  font-size: 15px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  text-align: left;
  transition: background .15s;
  -webkit-tap-highlight-color: transparent;
}
.action-item svg { color: var(--accent); flex-shrink: 0; }
.action-item:hover, .action-item:active { background: rgba(255,255,255,.06); }
.action-item.disabled { opacity: .4; pointer-events: none; }
.action-cancel {
  margin-top: 6px;
  justify-content: center;
  color: var(--text-muted);
  font-weight: 600;
  border-top: 1px solid rgba(255,255,255,.06);
  border-radius: 0;
  padding-top: 16px;
}
.action-cancel:hover { background: none; color: var(--text); }

/* Highlight the target message while sheet is open */
.msg.action-target .bubble {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Floating hint anchored to a message after an action */
.msg-hint {
  position: absolute;
  top: -22px; left: 50%;
  transform: translateX(-50%) translateY(4px);
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 12px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: all .2s var(--transition-smooth);
  box-shadow: 0 4px 12px rgba(0,168,132,.4);
  z-index: 5;
}
.msg-hint.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.msg { position: relative; }

/* ── Swipe-to-reply indicator ── */
.swipe-reply-indicator {
  position: absolute;
  left: -34px;
  top: 50%;
  transform: translateY(-50%);
  width: 28px; height: 28px;
  border-radius: 50%;
  background: rgba(0,168,132,.15);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: background .15s var(--transition-smooth);
  pointer-events: none;
}
.swipe-reply-indicator.ready {
  background: var(--accent);
  color: #fff;
}

/* ── Inline quoted reply (inside a message bubble) ── */
.quoted-reply {
  background: rgba(0,0,0,.18);
  border-left: 3px solid var(--accent);
  border-radius: 4px;
  padding: 6px 10px;
  margin-bottom: 6px;
  font-size: 11.5px;
}
.msg.user .quoted-reply { border-left-color: rgba(255,255,255,.5); }
.quoted-author {
  font-size: 11px;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 1px;
}
.msg.user .quoted-author { color: rgba(255,255,255,.85); }
.quoted-text {
  font-size: 11.5px;
  color: var(--text-muted);
  line-height: 1.35;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}
.msg.user .quoted-text { color: rgba(255,255,255,.7); }

/* ── Reply preview (above input area) ── */
#reply-preview {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(0,168,132,.08);
  border-left: 3px solid var(--accent);
  padding: 8px 12px;
  margin: 0 0 6px;
  border-radius: 6px;
  animation: slideDown .2s var(--transition-smooth);
}
@keyframes slideDown {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}
.reply-preview-bar {
  width: 3px; height: 32px;
  background: var(--accent);
  border-radius: 2px;
  flex-shrink: 0;
  display: none; /* the border-left handles this */
}
.reply-preview-body {
  flex: 1; min-width: 0;
}
.reply-preview-author {
  font-size: 11px;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 1px;
}
.reply-preview-text {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.reply-preview-close {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 22px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.reply-preview-close:hover {
  background: rgba(255,255,255,.05);
  color: var(--text);
}

/* ── Citation verification badge ── */
.citation-badge {
  display: inline-block; font-size: 10px; padding: 2px 8px;
  border-radius: 4px; margin-top: 3px; margin-left: 4px;
  font-weight: 600; cursor: help;
}
.citation-badge.ok   { background: rgba(0,168,132,.12); color: #00d9a3; }
.citation-badge.warn { background: rgba(247,201,72,.15); color: #fbbf24; }
.citation-badge.fail { background: rgba(234,67,53,.15); color: #f87171; }

/* ── Typing indicator ── */
.typing { align-self: flex-start; }
.typing .bubble { display: flex; gap: 4px; padding: 12px 18px; }
.typing .dot {
  width: 8px; height: 8px; border-radius: 50%; background: var(--accent);
  opacity: .5; animation: bounce 1.2s ease-in-out infinite;
}
.typing .dot:nth-child(2) { animation-delay: .2s; }
.typing .dot:nth-child(3) { animation-delay: .4s; }

/* ── Timestamps + status ticks ── */
.msg-time {
  font-size: 10px; color: rgba(255,255,255,.3);
  margin-top: 2px; text-align: right; user-select: none;
  display: flex; align-items: center; justify-content: flex-end; gap: 4px;
}
.msg.ai .msg-time { text-align: left; justify-content: flex-start; }

.msg-ticks {
  display: inline-flex;
  align-items: center;
  margin-left: 2px;
  transition: color .2s var(--transition-smooth);
}
.msg-ticks.sent { color: rgba(255,255,255,.35); }
.msg-ticks.retrieved { color: rgba(255,255,255,.55); }
.msg-ticks.done { color: #53bdeb; }  /* WhatsApp blue ticks */

/* ── Copy button ── */
.copy-btn {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11px; color: var(--text-muted);
  background: none; border: 1px solid rgba(255,255,255,.08);
  border-radius: 6px; padding: 3px 8px; cursor: pointer;
  transition: all .15s var(--transition-smooth);
  margin-top: 3px; opacity: 0; transform: translateY(2px);
}
.msg.ai:hover .copy-btn, .msg.ai .copy-btn.visible {
  opacity: 1; transform: translateY(0);
}
.copy-btn:hover { color: var(--accent); border-color: var(--accent); }
.copy-btn.copied { color: var(--success); border-color: var(--success); }
@media (hover: none) {
  .msg.ai .copy-btn { opacity: 1; transform: translateY(0); }
}

/* ── Feedback thumbs up/down ── */
.feedback-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 26px; height: 24px; padding: 0;
  font-size: 11px; color: var(--text-muted);
  background: none; border: 1px solid rgba(255,255,255,.08);
  border-radius: 6px; cursor: pointer;
  transition: all .15s var(--transition-smooth);
  margin-top: 3px; margin-left: 4px;
  opacity: 0; transform: translateY(2px);
}
.msg.ai:hover .feedback-btn { opacity: 1; transform: translateY(0); }
.feedback-btn:hover:not(:disabled) { color: var(--accent); border-color: var(--accent); }
.feedback-btn.active { color: var(--accent); border-color: var(--accent); background: rgba(0,168,132,.08); }
.feedback-btn.feedback-down.active { color: var(--warning); border-color: var(--warning); background: rgba(247,201,72,.08); }
.feedback-btn:disabled { cursor: default; }
@media (hover: none) {
  .msg.ai .feedback-btn { opacity: 1; transform: translateY(0); }
}

/* ── Follow-up suggestion chips ── */
.followup-chips {
  display: flex; flex-wrap: wrap; gap: 6px;
  padding: 4px 0 8px; max-width: 85%; align-self: flex-start;
}
.followup-chip {
  font-size: 12.5px; padding: 7px 14px; border-radius: 18px;
  border: 1px solid rgba(0,168,132,.3); background: rgba(0,168,132,.06);
  color: var(--accent); cursor: pointer;
  transition: all .15s var(--transition-smooth);
  white-space: nowrap; max-width: 240px;
  overflow: hidden; text-overflow: ellipsis;
  -webkit-tap-highlight-color: transparent;
  animation: chipsIn .3s var(--transition-smooth) both;
}
.followup-chip:hover {
  background: rgba(0,168,132,.15); border-color: var(--accent);
  transform: translateY(-1px);
}
.followup-chip:active { transform: scale(.96); }
.followup-chip:nth-child(1) { animation-delay: .05s; }
.followup-chip:nth-child(2) { animation-delay: .1s; }
.followup-chip:nth-child(3) { animation-delay: .15s; }
.followup-chip:nth-child(4) { animation-delay: .2s; }
@keyframes chipsIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes bounce {
  0%, 100% { opacity: .3; transform: translateY(0) scale(.85); }
  50% { opacity: 1; transform: translateY(-5px) scale(1); }
}
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ══════════════════════════════════
   WhatsApp-style input area
   ══════════════════════════════════ */
#input-area {
  padding: 6px 10px;
  background: var(--surface);
  border-top: 1px solid rgba(255,255,255,.06);
  flex-shrink: 0;
}
#input-row {
  display: flex; gap: 8px; align-items: flex-end;
}
#question {
  flex: 1; background: var(--surface-alt); border: none;
  border-radius: 22px; color: var(--text);
  padding: 10px 16px; font-size: 15px; font-family: var(--font);
  resize: none; min-height: 44px; max-height: 120px;
  line-height: 1.4; outline: none;
}
#question:focus { box-shadow: var(--glow-accent); background: rgba(42,57,66,.8); }
#question::placeholder { color: var(--text-muted); }

#send-btn, #mic-btn, #attach-btn {
  width: 44px; height: 44px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  border: none; cursor: pointer; flex-shrink: 0;
  transition: background .15s, transform .1s;
}
#send-btn {
  background: var(--accent); color: #fff;
}
#send-btn:hover { background: var(--accent-hover); transform: scale(1.05); }
#send-btn:active {
  transform: scale(.88);
  transition: transform .08s var(--transition-smooth);
}
#send-btn svg {
  transition: transform .2s var(--transition-smooth);
}
#send-btn:hover svg {
  transform: translateX(1px) translateY(-1px);
}
#send-btn:disabled { opacity: .4; cursor: not-allowed; }

#mic-btn, #attach-btn {
  background: transparent; color: var(--text-muted);
}
#mic-btn:hover, #attach-btn:hover { color: var(--text); }
#mic-btn.recording { background: var(--danger); color: #fff; animation: pulse 1s infinite; }
#attach-btn.has-image { color: var(--accent); }

/* Show send OR mic, not both */
#send-btn.hidden, #mic-btn.hidden { display: none; }

@keyframes pulse { 50% { opacity: .7; } }

/* ── Image preview ── */
#image-preview {
  padding: 6px 8px; background: var(--surface-alt);
  border-radius: 8px; margin-bottom: 6px;
}
#image-preview.hidden { display: none; }
#image-preview-list { display: flex; flex-wrap: wrap; gap: 6px; }
.image-preview-item {
  position: relative; display: flex; align-items: center; gap: 4px;
  background: var(--surface); border-radius: 6px; padding: 4px 6px;
}
.image-preview-item img { width: 36px; height: 36px; object-fit: cover; border-radius: 4px; }
.image-preview-name {
  font-size: 10px; color: var(--text-muted); max-width: 60px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.image-remove-btn {
  background: none; border: none; color: var(--text-muted);
  font-size: 16px; cursor: pointer; padding: 0 2px; line-height: 1;
}
.image-remove-btn:hover { color: var(--danger); }

/* ── Images in chat ── */
.chat-image {
  max-width: 180px; max-height: 130px; border-radius: 8px;
  margin-bottom: 4px;
}

/* ══════════════════════════════════
   Attach popup
   ══════════════════════════════════ */
#attach-popup {
  position: absolute; bottom: 70px; left: 10px;
  background: var(--surface); border-radius: 14px;
  padding: 8px; z-index: 40;
  box-shadow: 0 8px 28px rgba(0,0,0,.5);
  display: flex; flex-direction: column; gap: 2px;
}
#attach-popup.hidden { display: none; }
.attach-option {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px; border: none; background: none;
  color: var(--text); font-size: 14px; border-radius: 10px;
  cursor: pointer; white-space: nowrap;
  min-height: 44px;
}
.attach-option:hover, .attach-option:active { background: rgba(255,255,255,.06); }
.attach-option svg { color: var(--accent); flex-shrink: 0; }

/* ══════════════════════════════════
   Bottom navigation bar
   ══════════════════════════════════ */
#bottom-nav {
  display: flex; justify-content: space-around; align-items: center;
  background: var(--surface);
  border-top: 1px solid rgba(255,255,255,.06);
  padding-bottom: var(--safe-bottom);
  height: calc(var(--nav-height) + var(--safe-bottom));
  flex-shrink: 0;
}
.nav-tab {
  display: flex; flex-direction: column; align-items: center;
  gap: 2px; padding: 6px 12px;
  background: none; border: none; color: var(--text-muted);
  font-size: 10px; cursor: pointer; min-width: 56px;
  min-height: 44px; justify-content: center;
  transition: color .15s;
  -webkit-tap-highlight-color: transparent;
}
.nav-tab:active { transform: scale(.95); }
.nav-tab.active { color: var(--accent); }
.nav-tab svg { width: 22px; height: 22px; }

/* ══════════════════════════════════
   Slide panels (full-screen)
   ══════════════════════════════════ */
.slide-panel {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  background: var(--bg); z-index: 50;
  display: flex; flex-direction: column;
  transform: translateX(100%);
  transition: transform .25s ease;
  max-width: 800px; margin: 0 auto;
}
.slide-panel::before {
  content: ''; position: fixed; inset: 0;
  background: rgba(0,0,0,.4); opacity: 0;
  transition: opacity .25s var(--transition-smooth);
  pointer-events: none; z-index: -1;
}
.slide-panel.open {
  transform: translateX(0);
}
.slide-panel.open::before { opacity: 1; }
.panel-header {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px;
  padding-top: calc(8px + var(--safe-top));
  background: var(--surface);
  border-bottom: 1px solid rgba(255,255,255,.06);
  flex-shrink: 0; min-height: 48px;
}
.panel-header h3 { font-size: 16px; flex: 1; }
.panel-back {
  background: none; border: none; color: var(--text);
  cursor: pointer; padding: 8px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  min-width: 40px; min-height: 40px;
}
.panel-back:hover, .panel-back:active { background: rgba(255,255,255,.08); }
.panel-body {
  flex: 1; overflow-y: auto; padding: 12px;
  -webkit-overflow-scrolling: touch;
}

/* ── History items ── */
.history-item {
  padding: 14px 12px; border-radius: 10px; cursor: pointer;
  border-bottom: 1px solid rgba(255,255,255,.06);
  margin-bottom: 2px;
  transition: background .15s;
  min-height: 44px;
}
.history-item:hover, .history-item:active { background: rgba(255,255,255,.04); }
.history-item.active {
  background: rgba(0,168,132,.08);
}
.history-item-top {
  display: flex; justify-content: space-between; align-items: flex-start; gap: 8px;
}
.history-title {
  font-size: 14px; font-weight: 500; color: var(--text);
  line-height: 1.4; flex: 1;
}
.history-meta {
  display: flex; gap: 12px; margin-top: 4px;
  font-size: 11px; color: var(--text-muted);
}
.history-delete {
  background: none; border: none; color: var(--text-muted);
  font-size: 18px; cursor: pointer; padding: 4px 8px;
  line-height: 1; border-radius: 50%; min-width: 36px; min-height: 36px;
  display: flex; align-items: center; justify-content: center;
  transition: color .15s, background .15s;
}
.history-delete:hover, .history-delete:active {
  color: var(--danger); background: rgba(234,67,53,.1);
}

/* ── Document items ── */
.doc-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 12px;
  border-bottom: 1px solid rgba(255,255,255,.06);
  font-size: 14px; min-height: 44px;
}
.doc-item .size { color: var(--text-muted); font-size: 12px; }

/* ── Upload progress ── */
#upload-status {
  display: none; padding: 6px 12px; font-size: 12px;
  color: var(--text-muted); background: var(--surface);
}
#upload-status.active { display: block; }
#upload-status.success { color: var(--success); }
#upload-status.error { color: var(--danger); }

/* ── Save response button ── */
.save-response-btn {
  display: inline-block; font-size: 11px; padding: 4px 12px;
  border-radius: 12px; margin-top: 4px;
  background: transparent; color: var(--text-muted);
  border: 1px solid rgba(255,255,255,.1); cursor: pointer;
  transition: all .15s; min-height: 28px;
}
.save-response-btn:hover { color: var(--accent); border-color: var(--accent); }
.save-response-btn.saved {
  background: rgba(0,168,132,.1); color: var(--success);
  border-color: var(--success); cursor: default;
}
.save-response-btn:disabled { opacity: .6; cursor: wait; }

/* ── Save to matter modal ── */
.save-modal-box { max-width: 400px; }
.save-modal-hint { font-size: 13px; color: var(--text-muted); margin-bottom: 12px; }
.save-matter-list {
  max-height: 280px; overflow-y: auto; margin-bottom: 14px;
  border-radius: 10px; border: 1px solid var(--border);
}
.save-matter-option {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px; cursor: pointer;
  border-bottom: 1px solid rgba(255,255,255,.06);
  transition: background .15s; width: 100%;
  background: transparent; border-left: none; border-right: none; border-top: none;
  color: var(--text); font-size: 14px; text-align: left;
}
.save-matter-option:last-child { border-bottom: none; }
.save-matter-option:hover { background: rgba(0,168,132,.08); }
.save-matter-option .matter-radio {
  width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid var(--text-muted); flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
}
.save-matter-option.active .matter-radio {
  border-color: var(--accent);
}
.save-matter-option.active .matter-radio::after {
  content: ''; width: 10px; height: 10px; border-radius: 50%;
  background: var(--accent);
}
.save-matter-option .matter-info { flex: 1; min-width: 0; }
.save-matter-option .matter-info .matter-opt-name {
  font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.save-matter-option .matter-info .matter-opt-detail {
  font-size: 11px; color: var(--text-muted); margin-top: 2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* ── Matter items (WhatsApp chat list style) ── */
.matter-row {
  position: relative; overflow: hidden;
  border-bottom: 1px solid rgba(255,255,255,.06);
}
.matter-row:last-child { border-bottom: none; }

.matter-card {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px; min-height: 72px;
  background: var(--surface); cursor: pointer;
  transition: transform .2s ease, background .15s;
  position: relative; z-index: 1;
}
.matter-card:active { background: rgba(255,255,255,.04); }

.matter-avatar {
  width: 48px; height: 48px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #00796b);
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; font-weight: 700; color: #fff;
  flex-shrink: 0; letter-spacing: .5px;
}
.matter-body { flex: 1; min-width: 0; }
.matter-row-top {
  display: flex; align-items: center; gap: 6px; margin-bottom: 3px;
}
.matter-name {
  font-size: 15px; font-weight: 600; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.matter-active-badge {
  font-size: 10px; font-weight: 600; color: var(--accent);
  background: rgba(0,168,132,.12); border-radius: 4px;
  padding: 1px 6px; text-transform: uppercase; letter-spacing: .3px;
  flex-shrink: 0;
}
.matter-subtitle {
  font-size: 13px; color: var(--text-muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  display: block;
}
.matter-meta {
  flex-shrink: 0; display: flex; align-items: center;
}
.matter-chevron { color: var(--text-muted); opacity: .5; }
.matter-saved-link { color: var(--accent); font-size: 12px; cursor: pointer; text-decoration: none; padding: 4px 8px; border-radius: 4px; }
.matter-saved-link:hover { background: rgba(0,168,132,.15); }
.matter-card { cursor: pointer; }
.matter-card:hover { background: rgba(255,255,255,.04); }

/* Swipe-to-reveal actions behind the card */
.matter-swipe-actions {
  position: absolute; right: 0; top: 0; bottom: 0;
  display: flex; z-index: 0;
}
.matter-swipe-actions button {
  border: none; color: #fff; font-size: 12px; font-weight: 600;
  width: 60px; cursor: pointer; display: flex;
  align-items: center; justify-content: center;
  text-transform: uppercase; letter-spacing: .3px;
}
.matter-action-use { background: var(--accent); }
.matter-action-edit { background: #5c6bc0; }
.matter-action-del { background: var(--danger); }

/* Row active highlight */
.matter-row.active .matter-card {
  border-left: 3px solid var(--accent);
}

/* ══════════════════════════════════
   Saved responses panel (WhatsApp chat style)
   ══════════════════════════════════ */
#saved-panel .panel-header {
  background: linear-gradient(135deg, #00a884, #00796b);
}
#saved-panel .panel-header h3 { color: #fff; }
#saved-panel .panel-header .panel-back svg { stroke: #fff; }
#saved-panel .panel-body {
  background: #0b141a url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23ffffff' fill-opacity='0.02'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
  padding: 8px 12px;
}

/* Loading dots animation */
.saved-loading {
  display: flex; gap: 6px; justify-content: center;
  padding: 40px 0;
}
.saved-loading-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--accent); opacity: .4;
  animation: savedDotPulse .8s ease-in-out infinite alternate;
}
.saved-loading-dot:nth-child(2) { animation-delay: .2s; }
.saved-loading-dot:nth-child(3) { animation-delay: .4s; }
@keyframes savedDotPulse { to { opacity: 1; transform: scale(1.2); } }

/* Empty state */
.saved-empty-state {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; padding: 60px 20px; text-align: center;
}
.saved-empty-state p {
  color: var(--text-muted); font-size: 15px; font-weight: 500; margin: 0 0 6px;
}
.saved-empty-state span {
  color: var(--text-muted); font-size: 13px; opacity: .7; line-height: 1.4;
}

/* Date pill separator */
.saved-date-pill {
  text-align: center; margin: 12px 0;
}
.saved-date-pill {
  display: inline-block; width: auto;
  background: rgba(255,255,255,.08); color: var(--text-muted);
  font-size: 11px; padding: 4px 14px; border-radius: 8px;
  margin: 12px auto; display: block; width: fit-content;
}

/* Chat bubble pair */
.saved-chat-pair { margin-bottom: 4px; }

/* Bubbles */
.saved-bubble {
  max-width: 85%; padding: 8px 12px 4px;
  border-radius: 8px; margin-bottom: 3px;
  position: relative; word-wrap: break-word;
}
.saved-bubble-user {
  background: #005c4b; color: var(--text);
  margin-left: auto; border-top-right-radius: 2px;
  font-size: 14px; line-height: 1.4;
}
.saved-bubble-bot {
  background: var(--surface); color: var(--text);
  margin-right: auto; border-top-left-radius: 2px;
  font-size: 14px; line-height: 1.5;
}
.saved-bubble-text { margin-bottom: 2px; }
.saved-bubble-preview {
  margin-bottom: 2px; color: rgba(255,255,255,.8);
}
.saved-bubble-preview.hidden { display: none; }
.saved-bubble-full { margin-bottom: 4px; }
.saved-bubble-full.hidden { display: none; }
.saved-bubble-full h1, .saved-bubble-full h2, .saved-bubble-full h3 {
  font-size: 14px; font-weight: 600; color: var(--accent);
  margin: 10px 0 4px;
}
.saved-bubble-full p { margin: 4px 0; }
.saved-bubble-full ul, .saved-bubble-full ol { padding-left: 18px; margin: 4px 0; }
.saved-bubble-full li { margin: 2px 0; }
.saved-bubble-full strong { color: #fff; }

.saved-bubble-time {
  display: flex; align-items: center; justify-content: flex-end;
  gap: 3px; font-size: 11px; color: rgba(255,255,255,.45);
  margin-top: 2px;
}
.saved-read-more {
  background: none; border: none;
  color: var(--accent); font-size: 13px; font-weight: 500;
  padding: 4px 0; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

/* ══════════════════════════════════
   Settings panel
   ══════════════════════════════════ */
.settings-group {
  padding: 16px 0; border-bottom: 1px solid rgba(255,255,255,.06);
}
.settings-group:last-child { border-bottom: none; }
.settings-label {
  display: block; font-size: 14px; font-weight: 500;
  color: var(--accent); margin-bottom: 10px;
  text-transform: uppercase; font-size: 12px; letter-spacing: .5px;
}
.settings-hint {
  font-size: 13px; color: var(--text-muted); margin-bottom: 12px;
  line-height: 1.4;
}

/* Style toggle */
.settings-toggle {
  display: flex; background: rgba(255,255,255,.05); border-radius: 10px;
  padding: 3px; gap: 3px;
}
.settings-toggle button {
  flex: 1; padding: 10px; border-radius: 8px; border: none;
  background: none; color: var(--text-muted); font-size: 14px;
  font-weight: 500; cursor: pointer; min-height: 44px;
  transition: background .15s, color .15s;
}
.settings-toggle button.active {
  background: var(--accent); color: #fff;
}

/* Model options */
.settings-options {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px;
}
.settings-options button {
  display: flex; flex-direction: column; align-items: center;
  gap: 2px; padding: 14px 8px; border-radius: 12px;
  border: 1px solid rgba(255,255,255,.08); background: rgba(255,255,255,.03);
  color: var(--text-muted); cursor: pointer;
  transition: all .15s; min-height: 60px;
}
.settings-options button:hover, .settings-options button:active {
  border-color: var(--accent); background: rgba(0,168,132,.06);
}
.settings-options button.active {
  border-color: var(--accent); background: rgba(0,168,132,.1);
  color: var(--text);
}
.opt-name { font-size: 14px; font-weight: 600; }
.opt-desc { font-size: 11px; opacity: .6; }

/* Knowledge source — 3 columns */
.knowledge-source-options { grid-template-columns: 1fr 1fr 1fr; }
.knowledge-source-options button { min-height: 54px; padding: 10px 6px; }

/* ── Buttons ── */
.btn-small {
  font-size: 12px; padding: 8px 14px; border-radius: 20px;
  background: var(--accent); color: #fff; border: none;
  cursor: pointer; font-weight: 500; min-height: 36px;
}
.btn-small:hover { background: var(--accent-hover); }
.btn-primary {
  padding: 12px 20px; background: var(--accent); color: #fff;
  border: none; border-radius: 12px; font-size: 14px;
  font-weight: 600; cursor: pointer; min-height: 48px;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  transition: background .15s;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { opacity: .5; cursor: wait; }
.btn-full { width: 100%; }
.btn-secondary {
  padding: 12px 20px; background: transparent; color: var(--text);
  border: 1px solid rgba(255,255,255,.12); border-radius: 12px; font-size: 14px;
  cursor: pointer; min-height: 48px;
}
.btn-secondary:hover { background: rgba(255,255,255,.05); }

/* ── Matter form modal ── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.6);
  z-index: 60; display: flex; align-items: center; justify-content: center;
  padding: 16px;
}
.modal-overlay.hidden { display: none; }
.modal-box {
  background: var(--surface); padding: 20px; border-radius: 16px;
  width: 100%; max-width: 520px; max-height: 85vh; overflow-y: auto;
}
.modal-box h3 { font-size: 18px; margin-bottom: 14px; }
.form-group { margin-bottom: 10px; }
.form-group label {
  display: block; font-size: 12px; color: var(--text-muted);
  margin-bottom: 4px; font-weight: 500;
}
.form-group input, .form-group textarea {
  width: 100%; padding: 10px 12px; background: var(--surface-alt);
  border: none; border-radius: 10px;
  color: var(--text); font-size: 14px; font-family: var(--font);
  outline: none; resize: vertical; min-height: 44px;
}
.form-group input:focus, .form-group textarea:focus {
  box-shadow: 0 0 0 2px var(--accent);
}
.form-row {
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px;
}
.modal-actions {
  display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px;
}

/* ── Capture context status ── */
#capture-status {
  margin-top: 10px; padding: 12px; border-radius: 10px;
  font-size: 13px; line-height: 1.5;
  background: rgba(255,255,255,.03);
}
#capture-status.hidden { display: none; }
#capture-status.loading { color: var(--accent); }
#capture-status.success { color: var(--success); }
#capture-status.error { color: var(--danger); }

/* ── Auth overlay ── */
#auth-overlay {
  position: fixed; inset: 0; background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  z-index: 100; padding: 20px;
}
#auth-overlay.hidden { display: none; }
#auth-box {
  background: var(--surface); padding: 32px; border-radius: 16px;
  width: 100%; max-width: 380px; text-align: center;
}
#auth-box h2 {
  font-size: 24px; margin-bottom: 8px; color: var(--text);
}
#auth-box p { font-size: 14px; color: var(--text-muted); margin-bottom: 20px; }
#auth-box input {
  width: 100%; padding: 12px 14px; background: var(--surface-alt);
  border: none; border-radius: 10px;
  color: var(--text); font-size: 15px; margin-bottom: 12px;
  outline: none; min-height: 48px;
}
#auth-box input:focus { box-shadow: 0 0 0 2px var(--accent); }
#auth-box button {
  width: 100%; padding: 14px; background: var(--accent);
  color: #fff; border: none; border-radius: 10px;
  font-size: 15px; font-weight: 600; cursor: pointer;
  min-height: 48px;
}
#auth-box button:hover { background: var(--accent-hover); }
#auth-error { color: var(--danger); font-size: 12px; margin-top: 8px; display: none; }

/* ══════════════════════════════════
   Desktop (> 600px)
   ══════════════════════════════════ */
@media (min-width: 601px) {
  .msg { max-width: 70%; }

  /* Slide panels become side sheets on desktop */
  .slide-panel {
    max-width: 420px; left: auto; right: 0;
    box-shadow: -8px 0 24px rgba(0,0,0,.4);
  }

  #chat { padding: 12px 20px; }
  #input-area { padding: 8px 16px; }
  header { padding: 8px 16px; }
}

/* ══════════════════════════════════
   Wide desktop (≥ 900px) — WhatsApp Web split-pane
   ══════════════════════════════════ */
@media (min-width: 900px) {
  /* Pin the chat list as a permanent left sidebar */
  #history-panel {
    position: fixed;
    top: 0; left: 0; right: auto; bottom: 0;
    width: 340px;
    max-width: 340px;
    transform: none !important;
    box-shadow: 1px 0 0 rgba(255,255,255,.06);
    border-right: 1px solid rgba(255,255,255,.06);
    background: var(--surface);
    z-index: 30;
  }
  #history-panel::before { display: none !important; }
  #history-panel .panel-back { display: none; }

  /* Main app shifts right to leave space for the sidebar */
  #app {
    margin-left: 340px;
    max-width: calc(800px + 340px);
  }

  /* Bottom nav is replaced by the sidebar — hide on desktop */
  #bottom-nav { display: none; }

  /* Other slide panels (matters, docs, settings) still slide in over the main column */
  .slide-panel:not(#history-panel) {
    max-width: 420px;
    left: 340px;
  }
}

/* ══════════════════════════════════
   Mobile (≤ 600px)
   ══════════════════════════════════ */
@media (max-width: 600px) {
  #matter-indicator { max-width: 110px; font-size: 10px; }

  .form-row { grid-template-columns: 1fr; }

  .modal-box { padding: 16px; border-radius: 12px; }
}

/* ══════════════════════════════════
   Agent Mode — Step Progress UI
   ══════════════════════════════════ */
.agent-steps {
  max-width: 85%; align-self: flex-start;
  background: rgba(0, 168, 132, .06);
  border: 1px solid rgba(0, 168, 132, .15);
  border-radius: 10px;
  margin: 4px 0;
  overflow: hidden;
  transition: all .2s ease;
}
.agent-steps.completed {
  border-color: rgba(0, 168, 132, .25);
  background: rgba(0, 168, 132, .04);
}

.agent-steps-header {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px;
  font-size: 12px; font-weight: 600;
  color: var(--accent);
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.agent-steps-header:hover { background: rgba(0, 168, 132, .06); }
.agent-steps-icon { font-size: 14px; }

.agent-steps-list {
  padding: 0 12px 8px;
  display: flex; flex-direction: column; gap: 4px;
  transition: max-height .25s ease, opacity .2s ease;
  max-height: 600px; opacity: 1;
  overflow: hidden;
}

.agent-steps.collapsed .agent-steps-list {
  max-height: 0; opacity: 0; padding: 0 12px;
}

.agent-step {
  display: flex; align-items: center; gap: 8px;
  font-size: 12px; color: var(--text-muted);
  padding: 3px 0;
  animation: fadeIn .15s ease;
}

.agent-step-spinner {
  width: 14px; height: 14px; flex-shrink: 0;
  border: 2px solid rgba(0, 168, 132, .3);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: agentSpin .6s linear infinite;
  display: inline-block;
  font-size: 0; /* hide text while spinning */
}

.agent-step.done .agent-step-spinner {
  animation: none;
  border: none;
  color: var(--accent);
  font-size: 12px;
  width: auto; height: auto;
  display: flex; align-items: center; justify-content: center;
}

.agent-step.done .agent-step-label {
  color: var(--text-muted);
  opacity: .7;
}

.agent-step-label {
  flex: 1;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

@keyframes agentSpin {
  to { transform: rotate(360deg); }
}
