/* ═══════════════════════════════════════════════
   CHAT APP - Exact design from original
═══════════════════════════════════════════════ */
#chatApp {
  display: none;
  flex-direction: column;
  height: 100vh;
  background: var(--bg-base);
}

#chatApp.active { display: flex; }

/* ─── Header ─── */
.chat-header {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 24px;
  height: 64px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  position: relative;
  z-index: 10;
}

.chat-header::after {
  content: '';
  position: absolute;
  bottom: -1px; left: 0; right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(30,106,168,.15), transparent);
}

.header-logo {
  width: 38px;
  height: 38px;
  border-radius: 11px;
  background: #fff;
  border: 1px solid rgba(30,106,168,.2);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
}

.header-logo img { width: 28px; height: 28px; object-fit: contain; }

.header-info { flex: 1; }

.header-info h1 {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -.1px;
}

#headerSubtitle {
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 5px;
}

.header-actions {
  margin-right: auto;
  display: flex;
  gap: 8px;
  align-items: center;
}

/* ─── Token Badge ─── */
.token-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-mid);
  border-radius: 99px;
  font-size: 12px;
}

.token-badge svg { width: 13px; height: 13px; color: var(--accent); }

#tokenCount { color: var(--text-primary); font-weight: 600; }

/* ─── Messages Area ─── */
.chat-messages {
  flex: 1;
  min-height: 0;       /* fix: flex child must be 0 to allow overflow-y to work */
  overflow-y: auto;
  padding: 32px 24px;
  flex-direction: column;
  gap: 6px;
  scroll-behavior: smooth;
  background:
    radial-gradient(ellipse 50% 30% at 20% 10%, rgba(30,106,168,.04) 0%, transparent 60%),
    radial-gradient(ellipse 40% 25% at 80% 90%, rgba(45,212,191,.03) 0%, transparent 60%),
    var(--bg-base);
}

/* ─── Welcome Block ─── */
.welcome-block {
  align-self: center;
  text-align: center;
  padding: 60px 24px 40px;
  max-width: 560px;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
}

.welcome-icon-wrap {
  width: 88px;
  height: 88px;
  border-radius: 26px;
  background: #fff;
  border: 1px solid rgba(30,106,168,.15);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 24px;
  box-shadow: 0 16px 48px rgba(30,106,168,.12), 0 0 0 12px rgba(30,106,168,.04);
}

.welcome-icon-wrap img { width: 56px; height: 56px; object-fit: contain; }

.welcome-block h2 {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -.4px;
  margin-bottom: 10px;
  color: #1e6aa8;
}

.welcome-block p {
  color: var(--text-secondary);
  font-size: 14px;
  line-height: 1.75;
  margin-bottom: 32px;
  max-width: 400px;
}

/* ─── Suggestions ─── */
.suggestions {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  width: 100%;
  max-width: 480px;
}

.suggestion-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 13px 16px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-mid);
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition);
  text-align: right;
  outline: none;
}

.suggestion-chip:hover {
  border-color: rgba(59,126,255,.4);
  color: var(--text-accent);
  background: var(--accent-soft);
  transform: translateY(-1px);
  box-shadow: 0 4px 16px rgba(59,126,255,.1);
}

.chip-icon {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: rgba(59,126,255,.1);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.chip-icon svg { width: 15px; height: 15px; color: var(--accent); }

/* ─── Messages ─── */
.msg {
  display: flex;
  gap: 12px;
  max-width: 76%;
  animation: msgIn .28s cubic-bezier(.34,1.2,.64,1) both;
}

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

.msg.user {
  align-self: flex-start;
  flex-direction: row;
}

.msg.assistant {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.msg-avatar {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 2px;
}

.msg.user .msg-avatar {
  background: rgba(30,106,168,.1);
  border: 1px solid rgba(30,106,168,.2);
}

.msg.assistant .msg-avatar {
  background: #fff;
  border: 1px solid rgba(30,106,168,.2);
  box-shadow: 0 4px 12px rgba(30,106,168,.15);
  overflow: hidden;
}

.msg-avatar img { width: 24px; height: 24px; object-fit: contain; }

.msg-avatar svg { width: 15px; height: 15px; color: #1e6aa8; }

.msg.user .msg-avatar svg { color: rgba(30,106,168,.8); }

.msg-bubble-wrap {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
  min-width: 0;
}

.msg-body {
  padding: 13px 18px;
  border-radius: var(--radius);
  font-size: 14px;
  line-height: 1.8;
  word-break: break-word;
  position: relative;
}

.msg.user .msg-body {
  background: var(--user-bg);
  border: 1px solid rgba(30,106,168,.2);
  border-bottom-right-radius: 5px;
  color: #fff;
  --user-bg: linear-gradient(135deg,#1e6aa8,#164d7a);
}

.msg.assistant .msg-body {
  background: var(--bot-bg);
  border: 1px solid var(--border-mid);
  border-bottom-left-radius: 5px;
  box-shadow: var(--shadow-sm);
  --bot-bg: #ffffff;
}

.msg-time {
  font-size: 10.5px;
  color: var(--text-muted);
  padding: 0 4px;
}

.msg.user .msg-time { text-align: right; }
.msg.assistant .msg-time { text-align: left; }

/* ─── Markdown rendering inside assistant messages ─── */
.msg-body h1, .msg-body h2, .msg-body h3, .msg-body h4 {
  margin: 16px 0 10px;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.4;
}
.msg-body h1 { font-size: 18px; border-bottom: 1px solid var(--border); padding-bottom: 6px; }
.msg-body h2 { font-size: 16px; }
.msg-body h3 { font-size: 15px; color: var(--accent); }
.msg-body h4 { font-size: 14px; }

.msg-body p { margin: 8px 0; }

.msg-body ul, .msg-body ol {
  margin: 8px 0;
  padding-right: 20px;
}
.msg-body li { margin: 4px 0; }

.msg-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 12px 0;
  font-size: 13px;
}
.msg-body th, .msg-body td {
  border: 1px solid var(--border-mid);
  padding: 8px 10px;
  text-align: right;
}
.msg-body th {
  background: var(--bg-elevated);
  font-weight: 600;
  color: var(--text-primary);
}
.msg-body tr:nth-child(even) { background: rgba(30,106,168,.04); }

.msg-body blockquote {
  margin: 10px 0;
  padding: 10px 14px;
  border-right: 3px solid var(--accent);
  background: var(--accent-soft);
  border-radius: 0 6px 6px 0;
  color: var(--text-secondary);
}

.msg-body pre {
  background: #0f172a;
  color: #e2e8f0;
  padding: 14px;
  border-radius: 10px;
  overflow-x: auto;
  margin: 10px 0;
  font-size: 13px;
  line-height: 1.6;
}
.msg-body code {
  background: rgba(30,106,168,.1);
  color: var(--accent);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 13px;
  font-family: 'IBM Plex Mono', monospace;
}
.msg-body pre code {
  background: transparent;
  color: inherit;
  padding: 0;
  border-radius: 0;
}

.msg-body hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 16px 0;
}

.msg-body a {
  color: var(--accent);
  text-decoration: none;
}
.msg-body a:hover { text-decoration: underline; }

.msg-body img {
  max-width: 100%;
  border-radius: 8px;
  margin: 8px 0;
}

/* ─── Tool Status ─── */
.tool-status {
  align-self: center;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 18px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-mid);
  border-radius: 99px;
  font-size: 12px;
  color: var(--text-secondary);
  animation: msgIn .28s ease both;
  margin: 4px 0;
}

.tool-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--warning);
  box-shadow: 0 0 8px var(--warning);
  animation: toolPulse 1.2s ease infinite;
}

@keyframes toolPulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: .4; transform: scale(.8); }
}

.tool-status.done .tool-dot {
  background: var(--success);
  box-shadow: 0 0 8px var(--success);
  animation: none;
}

.tool-status.done {
  border-color: var(--success);
}

.tool-status.error {
  border-color: #fca5a5;
  background: #fef2f2;
  border-radius: 12px;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
}

.tool-status.error .tool-dot {
  background: #dc2626;
  box-shadow: 0 0 8px #dc2626;
  animation: none;
}

.tool-status-icon { width: 14px; height: 14px; color: var(--text-muted); }

/* ─── Typing Indicator ─── */
.typing-indicator {
  align-self: flex-end;
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 14px 18px;
  background: var(--bot-bg);
  border: 1px solid var(--border-mid);
  border-radius: var(--radius);
  border-bottom-left-radius: 5px;
  animation: msgIn .28s ease both;
  box-shadow: var(--shadow-sm);
  --bot-bg: #131f35;
}

.typing-indicator span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: rgba(110,168,254,.5);
  animation: typingBounce 1.4s ease infinite;
}

.typing-indicator span:nth-child(2) { animation-delay: .2s; }
.typing-indicator span:nth-child(3) { animation-delay: .4s; }

@keyframes typingBounce {
  0%, 80%, 100% { transform: translateY(0); background: rgba(110,168,254,.4); }
  40% { transform: translateY(-6px); background: rgba(110,168,254,.9); }
}

/* ─── Agent Colors ─── */
.agent-1 { color: #1e6aa8; background: rgba(30,106,168,.1);  border-color: rgba(30,106,168,.25); }
.agent-2 { color: #0ea5e9; background: rgba(14,165,233,.1);  border-color: rgba(14,165,233,.25); }
.agent-3 { color: #8b5cf6; background: rgba(139,92,246,.1);  border-color: rgba(139,92,246,.25); }
.agent-4 { color: #f59e0b; background: rgba(245,158,11,.1);  border-color: rgba(245,158,11,.25); }

/* ─── Agent Thinking Card (replaces plain typing indicator) ─── */
.agent-thinking {
  align-self: flex-end;
  display: flex;
  gap: 10px;
  padding: 11px 15px;
  background: var(--bg-surface);
  border: 1px solid var(--border-mid);
  border-radius: var(--radius);
  border-bottom-left-radius: 5px;
  box-shadow: var(--shadow-sm);
  animation: msgIn .28s ease both;
  max-width: min(320px, 76%);
  width: fit-content;
  position: relative;
  overflow: hidden;
  box-sizing: border-box;
}

.agent-thinking::after {
  content: '';
  position: absolute;
  right: 0; top: 0; bottom: 0;
  width: 3px;
  background: currentColor;
  opacity: 0.45;
}

.thinking-avatar {
  width: 30px; height: 30px;
  border-radius: 9px;
  background: #fff;
  border: 1px solid rgba(30,106,168,.2);
  display: flex; align-items: center; justify-content: center;
  overflow: hidden; flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(30,106,168,.12);
}

.thinking-avatar img { width: 20px; height: 20px; object-fit: contain; }

.thinking-content { flex: 1; min-width: 0; }

.thinking-top {
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 5px;
}

.thinking-name {
  font-size: 13px; font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
}

.thinking-dots { display: flex; gap: 3px; align-items: center; }

.thinking-dots span {
  width: 5px; height: 5px; border-radius: 50%;
  background: rgba(110,168,254,.5);
  animation: typingBounce 1.4s ease infinite;
}

.thinking-dots span:nth-child(2) { animation-delay: .2s; }
.thinking-dots span:nth-child(3) { animation-delay: .4s; }

.thinking-bottom {
  display: flex; align-items: center; gap: 5px;
  font-size: 11px;
}

.thinking-tier {
  display: inline-block;
  padding: 1px 7px; border-radius: 4px;
  font-size: 10px; font-weight: 700;
  border: 1px solid; letter-spacing: .3px;
}

.thinking-model { color: var(--text-muted); font-size: 10.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.thinking-sep { opacity: 0.3; font-size: 11px; }

.thinking-status-text {
  font-size: 11px;
  color: var(--text-secondary);
  font-style: italic;
}

/* ─── Message Footer ─── */
.msg-footer {
  display: flex; align-items: center; gap: 5px;
  padding: 2px 4px; flex-wrap: wrap;
  font-size: 11px; color: var(--text-muted);
}

.msg-agent-badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; border-radius: 99px;
  font-size: 10.5px; font-weight: 600;
  white-space: nowrap; border: 1px solid;
}

.msg-agent-badge::before {
  content: ''; width: 5px; height: 5px;
  border-radius: 50%; background: currentColor; flex-shrink: 0;
}

.msg-tier-tag {
  font-size: 10px; padding: 1px 5px; border-radius: 3px;
  background: var(--bg-elevated); border: 1px solid var(--border);
  color: var(--text-muted); font-weight: 500;
}

.msg-stat-sep { opacity: 0.35; }
.msg-stat { font-size: 10.5px; }
.msg-stat.cost { color: #10b981; font-weight: 500; }

/* ─── Response Rating (soft / subtle, yet visible) ─── */
.msg-rating {
  display: flex; align-items: center; gap: 8px;
  padding: 2px 4px; margin-top: 2px; flex-wrap: wrap;
  animation: msgIn .35s ease both;
}
.msg-rating-q {
  font-size: 11px; color: var(--text-muted); opacity: .85;
}
.msg-rating-q.rated { color: #10b981; opacity: 1; font-weight: 500; }
.rating-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; padding: 0;
  border: 1px solid var(--border); border-radius: 9px;
  background: transparent; color: var(--text-muted);
  cursor: pointer; opacity: .7;
  transition: all .18s ease;
}
.rating-btn svg { width: 15px; height: 15px; }
.rating-btn:hover { opacity: 1; transform: translateY(-1px); }
.rating-btn.up:hover    { color: #10b981; border-color: #10b98155; background: #10b9810f; }
.rating-btn.down:hover  { color: #ef4444; border-color: #ef444455; background: #ef44440f; }
.rating-btn.selected { opacity: 1; }
.rating-btn.up.selected   { color: #10b981; border-color: #10b98166; background: #10b9811a; }
.rating-btn.down.selected { color: #ef4444; border-color: #ef444466; background: #ef44441a; }
.rating-btn:disabled { cursor: default; }
.msg-rating-stars {
  display: inline-flex; align-items: center; gap: 2px;
  padding-right: 4px; border-right: 1px solid var(--border);
  margin-right: 2px; animation: msgIn .3s ease both;
}
.rating-star {
  background: none; border: none; padding: 1px; cursor: pointer;
  font-size: 16px; line-height: 1; color: #d1d5db; opacity: .9;
  transition: transform .12s ease, color .12s ease;
}
.rating-star:hover { transform: scale(1.18); }
.rating-star.on { color: #f59e0b; }
.msg-rating-thanks {
  font-size: 11px; color: #10b981; font-weight: 500;
  display: inline-flex; align-items: center; gap: 4px;
  animation: msgIn .35s ease both;
}

/* ─── Header Per-Model Stats Row ─── */
.agent-stats-row {
  display: flex; gap: 6px;
  align-items: center; flex-wrap: wrap;
}

.agent-stat-chip {
  display: flex; align-items: center; gap: 4px;
  padding: 4px 10px; border-radius: 99px;
  font-size: 11px; font-weight: 500; border: 1px solid;
  white-space: nowrap; animation: msgIn .3s ease both;
}

.chip-dot {
  width: 5px; height: 5px; border-radius: 50%;
  background: currentColor; opacity: 0.7; flex-shrink: 0;
}

.chip-name { font-weight: 600; }
.chip-val::before, .chip-cost::before { content: '·'; margin-left: 4px; opacity: 0.4; }

/* ─── Input Bar ─── */
.chat-input-bar {
  padding: 16px 24px 20px;
  background: var(--bg-surface);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  position: relative;
}

.chat-input-bar::before {
  content: '';
  position: absolute;
  top: -1px; left: 0; right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(59,126,255,.15), transparent);
}

.input-wrapper {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  max-width: 820px;
  margin: 0 auto;
  background: var(--bg-input);
  border: 1px solid var(--border-mid);
  border-radius: var(--radius-lg);
  padding: 8px 10px 8px 8px;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.input-wrapper:focus-within {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

#chatInput {
  flex: 1;
  padding: 8px 12px;
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 14px;
  line-height: 1.6;
  resize: none;
  min-height: 40px;
  max-height: 140px;
  outline: none;
}

#chatInput::placeholder { color: var(--text-muted); }

.send-btn {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  border: none;
  background: linear-gradient(135deg, var(--accent), var(--accent-dim));
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all var(--transition);
  box-shadow: 0 4px 14px rgba(59,126,255,.4);
}

.send-btn:hover:not(:disabled) {
  transform: scale(1.05);
  box-shadow: 0 6px 20px rgba(59,126,255,.5);
}

.send-btn:disabled {
  opacity: .4;
  cursor: not-allowed;
  box-shadow: none;
  transform: none;
}

.send-btn svg { width: 16px; height: 16px; }

/* Mic button */
.mic-btn {
  width: 38px; height: 38px;
  border-radius: 10px; border: none;
  background: var(--bg-elevated);
  border: 1px solid var(--border-mid);
  color: var(--text-muted);
  cursor: pointer; display: flex;
  align-items: center; justify-content: center;
  flex-shrink: 0; transition: all var(--transition);
}
.mic-btn:hover { border-color: var(--accent); color: var(--accent); }
.mic-btn.recording {
  background: rgba(239,68,68,.15);
  border-color: #ef4444;
  color: #ef4444;
  animation: micPulse 1.2s ease infinite;
}
@keyframes micPulse {
  0%,100% { box-shadow: 0 0 0 0 rgba(239,68,68,.3); }
  50% { box-shadow: 0 0 0 8px rgba(239,68,68,0); }
}
.mic-btn svg { width: 16px; height: 16px; }

/* Image attach preview bar */
.image-preview-bar {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 14px;
  background: rgba(59,126,255,.08);
  border: 1px solid rgba(59,126,255,.25);
  border-radius: var(--radius);
  margin-bottom: 8px; animation: msgIn .2s ease;
  font-size: 13px; color: var(--text-primary);
}
.image-preview-bar span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.image-preview-bar button {
  background: none; border: none; color: var(--text-muted);
  cursor: pointer; font-size: 14px; line-height: 1;
}
.image-preview-bar button:hover { color: #ef4444; }

/* Invoice "view" button inside a chat bubble */
.inv-view-btn {
  display: inline-flex; align-items: center; gap: 6px;
  margin-top: 8px; padding: 7px 14px;
  background: linear-gradient(135deg, var(--accent), var(--accent-dim));
  color: #fff; border: none; border-radius: 9px;
  font-family: inherit; font-size: 13px; font-weight: 600;
  cursor: pointer; transition: all var(--transition);
  box-shadow: 0 3px 10px rgba(59,126,255,.35);
}
.inv-view-btn:hover { transform: translateY(-1px); box-shadow: 0 5px 16px rgba(59,126,255,.45); }

/* Invoice modal */
.inv-modal {
  position: fixed; inset: 0; z-index: 1000;
  display: none; align-items: center; justify-content: center;
  background: rgba(0,0,0,.55); padding: 20px;
}
.inv-modal.open { display: flex; animation: msgIn .15s ease; }
.inv-modal-card {
  background: var(--bg-elevated, #fff); color: var(--text-primary);
  border: 1px solid var(--border-mid); border-radius: 14px;
  width: 100%; max-width: 560px; max-height: 85vh;
  display: flex; flex-direction: column; overflow: hidden;
  box-shadow: 0 20px 60px rgba(0,0,0,.4);
}
.inv-modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px; border-bottom: 1px solid var(--border-mid);
  font-weight: 700; font-size: 15px;
}
.inv-modal-close {
  background: none; border: none; color: var(--text-muted);
  font-size: 18px; cursor: pointer; line-height: 1;
}
.inv-modal-close:hover { color: #ef4444; }
.inv-modal-body { padding: 16px 18px; overflow-y: auto; }
.inv-modal-foot { padding: 10px 18px; border-top: 1px solid var(--border-mid); }
.inv-raw-toggle {
  background: var(--bg-base, #f4f6fb); border: 1px solid var(--border-mid);
  color: var(--text-muted); border-radius: 8px; padding: 6px 12px;
  font-family: inherit; font-size: 12px; cursor: pointer;
}
.inv-raw {
  margin: 0; padding: 14px 18px; max-height: 240px; overflow: auto;
  background: #0f172a; color: #cbd5e1; font-size: 12px;
  direction: ltr; text-align: left; white-space: pre-wrap; word-break: break-all;
}

/* Invoice tables */
.inv-table {
  width: 100%; border-collapse: collapse; margin-bottom: 12px; font-size: 13px;
}
.inv-table th, .inv-table td {
  border: 1px solid var(--border-mid); padding: 7px 10px; text-align: right;
  vertical-align: top;
}
.inv-table > tbody > tr > th {
  background: var(--bg-base, #f4f6fb); width: 38%; font-weight: 600; color: var(--text-muted);
}
.inv-items thead th { background: rgba(59,126,255,.12); font-weight: 700; }
.inv-section-title { font-weight: 700; font-size: 13px; margin: 6px 0; color: var(--accent); }
.inv-empty { color: var(--text-muted); font-size: 12px; }

/* Recording bar */
.recording-bar {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 16px;
  background: rgba(239,68,68,.08);
  border: 1px solid rgba(239,68,68,.2);
  border-radius: var(--radius);
  margin-bottom: 8px; animation: msgIn .2s ease;
}
.recording-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: #ef4444;
  animation: micPulse 1s ease infinite;
}
.recording-timer { font-size: 13px; color: #ef4444; font-weight: 600; font-variant-numeric: tabular-nums; }
.recording-label { font-size: 12px; color: var(--text-muted); flex: 1; }
.recording-cancel {
  font-size: 12px; color: var(--text-muted);
  background: none; border: none; cursor: pointer;
  text-decoration: underline;
}

/* STT notice */
.stt-notice {
  align-self: center;
  display: flex; align-items: center; gap: 8px;
  padding: 6px 14px;
  background: rgba(16,185,129,.08);
  border: 1px solid rgba(16,185,129,.2);
  border-radius: 99px;
  font-size: 11px; color: #10b981;
  animation: msgIn .28s ease both;
  margin: 4px 0;
}

.input-hint {
  text-align: center;
  color: var(--text-muted);
  font-size: 11px;
  margin-top: 10px;
  max-width: 820px;
  margin-inline: auto;
}

/* ─── Modal ─── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.6);
  backdrop-filter: blur(6px);
  z-index: 300;
  align-items: center;
  justify-content: center;
}

.modal-overlay.open { display: flex; }

.modal {
  background: var(--bg-elevated);
  border: 1px solid var(--border-mid);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 400px;
  margin: 20px;
  animation: cardIn .25s cubic-bezier(.34,1.2,.64,1) both;
}

.modal-body {
  padding: 32px;
  text-align: center;
}

.modal-title {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 8px;
}

.modal-desc {
  color: var(--text-muted);
  font-size: 13px;
  margin-bottom: 20px;
}

/* ─── Analysis / report modals ─── */
.an-overlay { position: fixed; inset: 0; z-index: 1100; display: none; align-items: center; justify-content: center; background: rgba(0,0,0,.55); padding: 20px; }
.an-overlay.open { display: flex; animation: msgIn .15s ease; }
.an-card { background: var(--bg-elevated,#fff); color: var(--text-primary); border: 1px solid var(--border-mid); border-radius: 14px; width: 100%; max-width: 720px; max-height: 88vh; display: flex; flex-direction: column; overflow: hidden; box-shadow: 0 20px 60px rgba(0,0,0,.4); }
.an-card.small { max-width: 460px; }
.an-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--border-mid); font-weight: 700; font-size: 15px; }
.an-head .an-title { display: flex; align-items: center; gap: 8px; min-width: 0; }
.an-close { background: none; border: none; color: var(--text-muted); font-size: 18px; cursor: pointer; line-height: 1; }
.an-close:hover { color: #ef4444; }
.an-badge { font-size: 11px; font-weight: 600; padding: 2px 9px; border-radius: 999px; background: var(--accent-soft); color: var(--text-accent); white-space: nowrap; }
.an-body { padding: 16px 18px; overflow-y: auto; flex: 1; min-height: 180px; }
.an-foot { padding: 10px 14px; border-top: 1px solid var(--border-mid); display: flex; gap: 8px; align-items: flex-end; }
.an-foot textarea { flex: 1; resize: none; border: 1px solid var(--border-mid); border-radius: 10px; padding: 9px 12px; font-family: inherit; font-size: 13px; background: var(--bg-base,#fff); color: var(--text-primary); max-height: 120px; }
.an-send { background: linear-gradient(135deg,var(--accent),var(--accent-dim)); color:#fff; border:none; border-radius:10px; padding: 10px 16px; font-family: inherit; font-weight:600; font-size:13px; cursor:pointer; }
.an-send:disabled { opacity: .5; cursor: default; }
/* setup form */
.an-field { margin-bottom: 14px; }
.an-field > label { display: block; font-size: 12px; font-weight: 600; color: var(--text-muted); margin-bottom: 6px; }
.an-field select, .an-field input { width: 100%; box-sizing: border-box; border: 1px solid var(--border-mid); border-radius: 9px; padding: 9px 11px; font-family: inherit; font-size: 13px; background: var(--bg-base,#fff); color: var(--text-primary); }
.an-grid2 { display: flex; gap: 10px; }
.an-grid2 > div { flex: 1; }
.an-toggle { display: flex; gap: 8px; }
.an-toggle button { flex: 1; padding: 9px; border: 1px solid var(--border-mid); border-radius: 9px; background: var(--bg-base,#fff); color: var(--text-secondary); font-family: inherit; font-size: 13px; font-weight:600; cursor: pointer; }
.an-toggle button.active { border-color: var(--accent); color: var(--text-accent); background: var(--accent-soft); }
.an-start { width: 100%; margin-top: 4px; background: linear-gradient(135deg,var(--accent),var(--accent-dim)); color:#fff; border:none; border-radius:10px; padding: 11px; font-family: inherit; font-weight:700; font-size:14px; cursor:pointer; }
.an-start:disabled { opacity:.5; cursor:default; }
/* modal chat bubbles */
.an-msg { margin-bottom: 12px; display: flex; }
.an-msg.user { justify-content: flex-start; }
.an-msg.assistant { justify-content: flex-end; }
.an-bub { max-width: 92%; padding: 10px 13px; border-radius: 12px; font-size: 13.5px; line-height: 1.75; word-wrap: break-word; overflow-wrap: anywhere; }
.an-msg.assistant .an-bub { background: var(--bg-base,#f4f6fb); color: var(--text-primary); }
.an-msg.user .an-bub { background: var(--accent-soft); color: var(--text-accent); }
.an-bub table { border-collapse: collapse; width: 100%; margin: 8px 0; font-size: 12.5px; }
.an-bub th, .an-bub td { border: 1px solid var(--border-mid); padding: 5px 8px; text-align: right; }
.an-status { font-size: 12px; color: var(--text-muted); margin: 6px 0; display:flex; align-items:center; gap:6px; }
.an-meta { font-size: 11px; color: var(--text-muted); margin-top: 4px; }

/* Structured Phase-1 questions (general analysis) */
.anq { border: 1px solid var(--border-mid); border-radius: 12px; padding: 14px; margin: 10px 0 14px; background: var(--bg-base,#fff); }
.anq-head { font-size: 13.5px; font-weight: 700; margin-bottom: 4px; }
.anq-intro { font-size: 12.5px; color: var(--text-secondary); line-height: 1.7; margin-bottom: 12px; }
.anq-item { border-top: 1px dashed var(--border-mid); padding: 11px 0 4px; }
.anq-item:first-of-type { border-top: none; }
.anq-top { display: flex; align-items: flex-start; gap: 7px; margin-bottom: 4px; }
.anq-num { flex: none; width: 20px; height: 20px; border-radius: 999px; background: var(--accent-soft); color: var(--text-accent); font-size: 11px; font-weight: 700; display: flex; align-items: center; justify-content: center; }
.anq-q { font-size: 13px; font-weight: 600; line-height: 1.65; flex: 1; }
.anq-item textarea { width: 100%; box-sizing: border-box; resize: vertical; min-height: 38px; border: 1px solid var(--border-mid); border-radius: 9px; padding: 8px 10px; font-family: inherit; font-size: 12.5px; background: var(--bg-elevated,#fff); color: var(--text-primary); }
.anq-actions { display: flex; gap: 8px; margin-top: 14px; }
.anq-actions button { flex: 1; border-radius: 10px; padding: 10px; font-family: inherit; font-weight: 700; font-size: 13px; cursor: pointer; border: 1px solid var(--border-mid); }
.anq-submit { background: linear-gradient(135deg,var(--accent),var(--accent-dim)); color: #fff; border-color: transparent !important; }
.anq-skip { background: var(--bg-elevated,#fff); color: var(--text-secondary); }
.anq.locked { opacity: .6; }
.anq.locked textarea, .anq.locked button { pointer-events: none; }


/* ─── Responsive ─── */
@media (max-width: 640px) {
  .msg { max-width: 90%; }
  .chat-messages { padding: 20px 16px; }
  .auth-card { padding: 32px 22px; }
  .suggestions { grid-template-columns: 1fr; }
  .chat-input-bar { padding: 12px 16px 16px; }
  .an-card { max-width: 100%; }
}
