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

:root {
  --teal-500: #14b8a6;
  --teal-600: #0d9488;
  --teal-700: #0f766e;
  --emerald-500: #10b981;
  --emerald-600: #059669;
  --slate-50:  #f8fafc;
  --slate-100: #f1f5f9;
  --slate-200: #e2e8f0;
  --slate-300: #cbd5e1;
  --slate-400: #94a3b8;
  --slate-500: #64748b;
  --slate-600: #475569;
  --slate-700: #334155;
  --slate-800: #1e293b;
  --slate-900: #0f172a;
  --white: #ffffff;
  --header-h: 100px;
  --footer-h: 108px;
  --max-w: 60rem;
  /* Semantic tokens */
  --bg:           #f0f4f8;
  --surface:      #ffffff;
  --surface-2:    #f1f5f9;
  --border:       #cbd5e1;
  --text:         #0f172a;
  --text-muted:   #475569;
  --bubble-ai-bg: #e8faf7;
  --bubble-ai-fg: #0f172a;
  --header-bg-l:  #fffbeb;
  --header-bg-r:  #fef9c3;
  --header-border:rgba(234,179,8,0.3);
  --input-bg:     rgba(255,255,255,0.97);
  --code-bg:      #f1f5f9;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background-color: var(--bg);
  color: var(--text);
  font-size: 14px;
}

/* Fixed background */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  background: radial-gradient(ellipse at 50% 0%, rgba(20,184,166,0.08) 0%, transparent 55%),
              radial-gradient(ellipse at 85% 100%, rgba(16,185,129,0.06) 0%, transparent 50%);
  pointer-events: none;
  z-index: 0;
}

#app-header, #messages-container, #input-bar { position: relative; z-index: 1; }

/* ── Header ── */
#app-header {
  position: fixed;
  top: 0;
  left: 0; right: 0;
  z-index: 20;
  padding: 8px 1rem 0;
  background: var(--bg);
}

.header-inner {
  max-width: var(--max-w);
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem 1.5rem;
  background: linear-gradient(to right, #fffbeb, #fef3c7);
  border: 2px solid rgba(234,179,8,0.35);
  border-radius: 1rem;
  box-shadow: 0 4px 20px rgba(0,0,0,0.12), 0 1px 4px rgba(0,0,0,0.06);
}

.logo { height: 3.5rem; flex-shrink: 0; }

.header-title {
  flex: 1;
  text-align: center;
}

.header-title h1 {
  font-size: 1.9rem;
  font-weight: 800;
  color: var(--slate-900);
  letter-spacing: -0.01em;
}

.header-title p {
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--slate-600);
  margin-top: 0.1rem;
}

.lang-btn {
  background: white;
  border: 2px solid var(--slate-300);
  border-radius: 0.6rem;
  padding: 0.4rem 0.7rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  transition: background 0.15s, border-color 0.15s;
  flex-shrink: 0;
}
.lang-btn:hover { background: var(--slate-100); border-color: var(--teal-500); }
.flag-img { width: 24px; object-fit: cover; border-radius: 3px; display: block; }

/* ── Messages ── */
#messages-container {
  padding-top: calc(var(--header-h) + 0.75rem);
  padding-bottom: calc(var(--footer-h) + 0.75rem);
  min-height: 100vh;
}

#messages-list {
  max-width: var(--max-w);
  margin: 0 auto;
  padding: 0 1rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

/* ── Message Rows ── */
.msg-row {
  display: flex;
  gap: 0.6rem;
  align-items: flex-start;
}
.msg-user { justify-content: flex-end; }
.msg-assistant { justify-content: flex-start; }

/* Avatar column: sticky within the row bounds */
.avatar-col {
  flex-shrink: 0;
  width: 2.75rem;
  align-self: stretch;
  position: relative;
}

.avatar-sticky {
  position: sticky;
  top: calc(var(--header-h) + 1rem);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.agent-name {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  white-space: nowrap;
}

.msg-body {
  max-width: 80%;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}
.msg-user .msg-body { align-items: flex-end; }
.msg-assistant .msg-body { align-items: flex-start; }

/* ── Avatars ── */
.avatar {
  width: 2.75rem; height: 2.75rem;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}
.avatar-assistant {
  background: linear-gradient(135deg, var(--emerald-500), var(--teal-600));
  padding: 2px;
  box-shadow: 0 2px 8px rgba(20,184,166,0.35);
}
.avatar-assistant img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }
.avatar-user {
  background: linear-gradient(135deg, var(--slate-600), var(--slate-800));
  box-shadow: 0 2px 8px rgba(51,65,85,0.3);
}
.avatar-user svg { width: 1.3rem; height: 1.3rem; stroke: white; }

/* ── Bubbles ── */
.msg-bubble {
  padding: 1rem 1.2rem;
  border-radius: 1.1rem;
  font-size: 1rem;
  line-height: 1.7;
}

.bubble-user {
  background: linear-gradient(135deg, var(--teal-600), var(--teal-700));
  color: white;
  border-bottom-right-radius: 0.3rem;
  box-shadow: 0 3px 12px rgba(13,148,136,0.35);
  font-weight: 500;
}

.bubble-assistant {
  background: var(--surface);
  color: var(--text);
  border: 1.5px solid var(--slate-200);
  box-shadow: 0 3px 12px rgba(0,0,0,0.08);
  border-bottom-left-radius: 0.3rem;
}

/* Markdown inside assistant bubble */
.bubble-assistant .msg-content p { margin-bottom: 0.6rem; }
.bubble-assistant .msg-content p:last-child { margin-bottom: 0; }
.bubble-assistant .msg-content ul,
.bubble-assistant .msg-content ol { padding-left: 1.5rem; margin-bottom: 0.6rem; }
.bubble-assistant .msg-content li { margin-bottom: 0.35rem; }
.bubble-assistant .msg-content h1 { font-size: 1.15rem; font-weight: 700; margin-bottom: 0.5rem; color: var(--slate-900); }
.bubble-assistant .msg-content h2 { font-size: 1.05rem; font-weight: 700; margin-bottom: 0.5rem; color: var(--slate-900); }
.bubble-assistant .msg-content h3 { font-size: 0.95rem; font-weight: 700; margin-bottom: 0.4rem; color: var(--slate-900); }
.bubble-assistant .msg-content strong { font-weight: 700; color: var(--slate-900); }
.bubble-assistant .msg-content a { color: var(--teal-600); text-decoration: underline; font-weight: 500; }
.bubble-assistant .msg-content code {
  background: var(--slate-100);
  padding: 0.15em 0.4em;
  border-radius: 0.3rem;
  font-size: 0.88em;
  font-family: "Fira Code", "Courier New", monospace;
  color: var(--slate-800);
}
.bubble-assistant .msg-content pre {
  background: var(--slate-800);
  color: #e2e8f0;
  padding: 0.85rem 1.1rem;
  border-radius: 0.6rem;
  overflow-x: auto;
  margin-bottom: 0.6rem;
}
.bubble-assistant .msg-content pre code { background: none; padding: 0; color: inherit; }

/* ── Tables inside assistant bubble ── */
.bubble-assistant .msg-content table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 0.75rem;
  font-size: 0.82rem;
  overflow-x: auto;
  display: block;
}
.bubble-assistant .msg-content thead {
  background: linear-gradient(135deg, var(--teal-500), var(--emerald-600));
  color: white;
}
.bubble-assistant .msg-content th {
  padding: 0.5rem 0.75rem;
  text-align: left;
  font-weight: 600;
  white-space: nowrap;
}
.bubble-assistant .msg-content td {
  padding: 0.45rem 0.75rem;
  border-bottom: 1px solid var(--slate-200);
  color: var(--slate-700);
  vertical-align: top;
}
.bubble-assistant .msg-content tbody tr:last-child td {
  border-bottom: none;
}
.bubble-assistant .msg-content tbody tr:nth-child(even) {
  background: rgba(20, 184, 166, 0.05);
}
.bubble-assistant .msg-content tbody tr:hover {
  background: rgba(20, 184, 166, 0.1);
}

/* ── Typing indicator ── */
.typing-indicator {
  display: flex;
  gap: 6px;
  padding: 6px 0;
  align-items: center;
}
.typing-indicator span {
  width: 10px; height: 10px;
  background: var(--teal-500);
  border-radius: 50%;
  animation: bounce 1.2s infinite;
}
.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-6px); }
}

/* ── Message Controls ── */
.msg-controls {
  display: flex;
  gap: 0.3rem;
  flex-wrap: wrap;
  margin-top: 0.1rem;
}

.ctrl-btn {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.4rem 0.75rem;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--slate-600);
  background: var(--surface);
  border: 1.5px solid var(--slate-200);
  border-radius: 0.5rem;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.ctrl-btn:hover { background: var(--slate-100); color: var(--slate-900); border-color: var(--teal-500); }
.ctrl-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.ctrl-btn svg { width: 0.85rem; height: 0.85rem; flex-shrink: 0; }
.ctrl-btn .chevron-icon { width: 0.75rem; height: 0.75rem; transition: transform 0.2s; }
.ctrl-btn.expanded .chevron-icon { transform: rotate(180deg); }

/* ── Citations ── */
.citations-list {
  background: var(--slate-50);
  border: 1px solid var(--slate-200);
  border-radius: 0.5rem;
  padding: 0.6rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  width: 100%;
}

.citation-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.8rem;
  color: var(--slate-700);
  gap: 0.5rem;
}

.citation-info {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex: 1;
  min-width: 0;
}

.citation-info svg { width: 0.75rem; height: 0.75rem; stroke: var(--slate-500); flex-shrink: 0; }
.citation-title { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.citation-page { color: var(--slate-500); white-space: nowrap; }

.citation-open-btn {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.15rem 0.5rem;
  font-size: 0.72rem;
  color: var(--slate-600);
  background: transparent;
  border: none;
  border-radius: 0.3rem;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s;
}
.citation-open-btn:hover { background: var(--slate-200); }
.citation-open-btn svg { width: 0.7rem; height: 0.7rem; }

/* ── Input Bar ── */
#input-bar {
  position: fixed;
  bottom: 0;
  left: 0; right: 0;
  z-index: 20;
  padding: 0 1rem 1rem;
  background: var(--bg);
}

.input-inner {
  max-width: var(--max-w);
  margin: 0 auto;
  position: relative;
}

.recording-indicator {
  position: absolute;
  top: -2.75rem;
  left: 50%;
  transform: translateX(-50%);
  background: #ef4444;
  color: white;
  padding: 0.4rem 1.1rem;
  border-radius: 9999px;
  font-size: 0.85rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  box-shadow: 0 2px 10px rgba(239,68,68,0.4);
  animation: pulse 1.5s infinite;
  white-space: nowrap;
}

.rec-dot {
  width: 9px; height: 9px;
  background: white;
  border-radius: 50%;
  animation: pulse 1s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

.chat-form {
  display: flex;
  gap: 0.6rem;
  align-items: center;
  padding: 0.85rem 1.1rem;
  background: var(--input-bg);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-radius: 1rem;
  border: 2px solid var(--slate-200);
  box-shadow: 0 4px 24px rgba(0,0,0,0.1);
}

.input-wrapper {
  flex: 1;
  position: relative;
}

#chat-input {
  width: 100%;
  height: 3.25rem;
  padding: 0 2.25rem 0 1rem;
  border: 2px solid var(--slate-300);
  border-radius: 0.65rem;
  font-size: 1rem;
  color: var(--text);
  background: white;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
#chat-input:focus {
  border-color: var(--teal-500);
  box-shadow: 0 0 0 3px rgba(20,184,166,0.15);
}
#chat-input:disabled { background: var(--slate-100); color: var(--slate-400); }
#chat-input::placeholder { color: var(--slate-400); font-size: 0.95rem; }

.listening-dots {
  position: absolute;
  right: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  gap: 3px;
  align-items: center;
}
.listening-dots span {
  width: 5px; height: 5px;
  background: var(--slate-400);
  border-radius: 50%;
  animation: bounce 1.2s infinite;
}
.listening-dots span:nth-child(2) { animation-delay: 0.2s; }
.listening-dots span:nth-child(3) { animation-delay: 0.4s; }

/* ── Char Counter ── */
.char-counter {
  position: absolute;
  bottom: 0.4rem;
  right: 0.65rem;
  font-size: 0.68rem;
  font-weight: 500;
  color: var(--slate-400);
  pointer-events: none;
  transition: color 0.15s;
  line-height: 1;
}
.char-counter.warn  { color: #f59e0b; }
.char-counter.limit { color: #ef4444; font-weight: 700; }

/* ── Icon Buttons ── */
.icon-btn {
  width: 3.25rem; height: 3.25rem;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: opacity 0.15s, transform 0.1s, box-shadow 0.15s;
}
.icon-btn:hover { opacity: 0.9; transform: scale(1.05); }
.icon-btn:active { transform: scale(0.93); }
.icon-btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }
.icon-btn svg { width: 1.3rem; height: 1.3rem; stroke: white; }

.mic-btn {
  background: linear-gradient(135deg, var(--slate-600), var(--slate-800));
  box-shadow: 0 3px 10px rgba(51,65,85,0.35);
}
.mic-btn.listening {
  background: #ef4444;
  box-shadow: 0 3px 14px rgba(239,68,68,0.5);
}

.send-btn {
  background: linear-gradient(135deg, var(--teal-500), var(--emerald-600));
  box-shadow: 0 3px 10px rgba(20,184,166,0.4);
}

/* ── Utilities ── */
.hidden { display: none !important; }

/* ── Scrollbar ── */
#messages-list::-webkit-scrollbar { width: 4px; }
#messages-list::-webkit-scrollbar-track { background: transparent; }
#messages-list::-webkit-scrollbar-thumb { background: var(--slate-200); border-radius: 2px; }

/* ── Responsive ── */
@media (max-width: 380px) {
  .header-title h1 { font-size: 1.5rem; }
  .header-title p { display: none; }
  .logo { height: 2.75rem; }
  .msg-bubble { font-size: 0.95rem; }
}

/* ── Sidebar ── (removed — clock moved into header) */

/* ── Suggested Prompts ── */
#suggested-prompts {
  max-width: var(--max-w);
  margin: 1.75rem auto 0;
  padding: 0 1rem;
  animation: fadeIn 0.4s ease;
}

#suggested-label {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--slate-500);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  margin-bottom: 0.75rem;
}

#prompts-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
}

.prompt-chip {
  padding: 0.6rem 1.1rem;
  font-size: 0.88rem;
  font-weight: 500;
  color: var(--slate-700);
  background: white;
  border: 2px solid var(--slate-300);
  border-radius: 9999px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s, transform 0.1s, box-shadow 0.15s;
  text-align: left;
  line-height: 1.4;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}
.prompt-chip:hover {
  background: #f0fdfa;
  border-color: var(--teal-500);
  color: var(--teal-700);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(20,184,166,0.2);
}
.prompt-chip:active { transform: translateY(0); }

/* ── Message Timestamps ── */
.msg-meta {
  display: flex;
  align-items: center;
  padding: 0 0.4rem;
  min-height: 1.2rem;
}

.msg-meta-user {
  justify-content: flex-end;
}

.msg-timestamp {
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--text-muted);
  white-space: nowrap;
  line-height: 1;
}

/* ── Header Clock ── */
.header-clock {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.1rem;
  flex-shrink: 0;
  line-height: 1.2;
  padding: 0 0.75rem;
  border-left: 2px solid rgba(234,179,8,0.3);
  border-right: 2px solid rgba(234,179,8,0.3);
}

#clock-time {
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--slate-900);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
}

#clock-date {
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--slate-600);
  white-space: nowrap;
}

/* Hide clock when header gets too narrow (subtitle already hides at 580px) */
@media (max-width: 580px) {
  .header-clock { display: none; }
}

/* ── New Chat Button ── */
.header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

.new-chat-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2.4rem;
  height: 2.4rem;
  padding: 0;
  color: var(--slate-600);
  background: white;
  border: 2px solid var(--slate-300);
  border-radius: 0.6rem;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  flex-shrink: 0;
}
.new-chat-btn:hover { background: var(--slate-100); color: var(--slate-900); border-color: var(--teal-500); }
.new-chat-btn svg {
  width: 1.1rem;
  height: 1.1rem;
  stroke: currentColor;
  transition: transform 0.4s ease;
}
.new-chat-btn:active svg { transform: rotate(360deg); }
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.new-chat-btn,
.lang-btn {
  transition:
    background 0.15s,
    border-color 0.15s,
    color 0.15s,
    opacity 0.15s,
    transform 0.1s;
}

.new-chat-btn:disabled,
.lang-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  pointer-events: none;
  transform: none;
  box-shadow: none;
}

.new-chat-btn:disabled:hover,
.lang-btn:disabled:hover {
  background: white;
  border-color: var(--slate-300);
  color: var(--slate-600);
}

.tooltip-wrapper {
  position: relative;
  display: inline-block;
}

.tooltip {
  position: absolute;
  bottom: -35px; /* below the button */
  left: 50%;
  transform: translateX(-50%);
  background: #222;
  color: #fff;
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 12px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  transform: translateX(-50%) translateY(-5px);
  z-index: 100;
}

.tooltip-wrapper:hover .tooltip {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.msg-row {
  animation: fadeIn 0.25s ease;
}
