/* CBE — Premium chat experience */
:root {
  --apex-navy: #071a2b;
  --apex-navy-2: #081427;
  --apex-blue: #0b5fff;
  --apex-cyan: #22d3ee;
  --apex-ink: #eaf2ff;
  --apex-muted: rgba(234, 242, 255, 0.72);
  --apex-border: rgba(234, 242, 255, 0.12);
  --apex-surface: rgba(255, 255, 255, 0.06);
  --apex-surface-2: rgba(255, 255, 255, 0.085);
  --neon-blue: #2f7bff;
  --neon-cyan: #22d3ee;
  --neon-cyan-2: #67f6ff;
  --glow-blue: rgba(47, 123, 255, 0.40);
  --glow-cyan: rgba(34, 211, 238, 0.32);
  --glass: rgba(255, 255, 255, 0.06);
  --glass-2: rgba(255, 255, 255, 0.085);

  --bg: var(--apex-navy);
  --surface: color-mix(in srgb, var(--apex-navy) 70%, #0b1633 30%);
  --surface-2: var(--apex-surface-2);
  --text: var(--apex-ink);
  --muted: var(--apex-muted);
  --border: var(--apex-border);
  --primary: var(--apex-blue);
  --primary-hover: color-mix(in srgb, var(--apex-blue) 80%, var(--apex-cyan) 20%);
  --user: rgba(11, 95, 255, 0.18);
  --assistant: rgba(255, 255, 255, 0.06);
  --danger: rgba(251, 113, 133, 0.14);
  --font: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-display: "Sora", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }

body {
  font-family: var(--font);
  color: var(--text);
  background:
    radial-gradient(1200px 700px at 14% 12%, rgba(11, 95, 255, 0.28), transparent 55%),
    radial-gradient(900px 620px at 86% 18%, rgba(34, 211, 238, 0.18), transparent 55%),
    var(--bg);
  line-height: 1.5;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(1200px 520px at 20% 8%, rgba(34, 211, 238, 0.12), transparent 60%),
    radial-gradient(980px 620px at 82% 22%, rgba(47, 123, 255, 0.14), transparent 60%);
  opacity: 0.9;
  mix-blend-mode: screen;
}

@media (prefers-reduced-motion: no-preference) {
  body::before {
    animation: aurora-shift 12s ease-in-out infinite alternate;
  }
  @keyframes aurora-shift {
    0% { transform: translate3d(0, 0, 0) scale(1); filter: blur(0px); }
    100% { transform: translate3d(0, -10px, 0) scale(1.02); filter: blur(0.5px); }
  }
}

/* Header with KAI logo (circle) */
.topbar {
  padding: 10px 18px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(8, 20, 39, 0.88) 0%, rgba(7, 26, 43, 0.70) 100%);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  box-shadow: 0 18px 55px rgba(2, 6, 23, 0.35), 0 0 40px rgba(34, 211, 238, 0.05);
  backdrop-filter: blur(10px);
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

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

.topbar-icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.045);
  color: var(--text);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.18s ease, background 0.18s ease, border-color 0.18s ease;
}

.topbar-icon-btn:hover {
  transform: translateY(-1px);
  background: rgba(255, 255, 255, 0.07);
  border-color: rgba(34, 211, 238, 0.32);
}

.topbar-icon-btn svg {
  width: 18px;
  height: 18px;
  display: block;
}

/* Light theme for full chat page */
body[data-theme="light"] {
  --bg: #f6f9ff;
  --surface: rgba(255, 255, 255, 0.9);
  --surface-2: #ffffff;
  --text: #071a2b;
  --muted: rgba(7, 26, 43, 0.72);
  --border: rgba(7, 26, 43, 0.12);
  --assistant: rgba(7, 26, 43, 0.04);
  --user: rgba(11, 95, 255, 0.12);
  --danger: rgba(251, 113, 133, 0.12);
}

/* Match launcher: same light circle and logo fit as bottom-right (smaller = sharper) */
.topbar-logo {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  object-fit: cover;
  flex-shrink: 0;
  background: #ffffff;
  padding: 4px;
  box-sizing: border-box;
  object-position: center 14%;
  border: 1px solid rgba(15, 23, 42, 0.14);
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.06);
}

.topbar-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.125rem;
  letter-spacing: 0.02em;
}

.topbar-subtitle {
  color: var(--muted);
  font-size: 0.75rem;
  margin-top: 2px;
}

.chat-shell {
  height: calc(100% - 64px);
  display: flex;
  flex-direction: column;
}

.chat-view {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

/* Empty state (professional) */
.chat-empty {
  padding: 18px 18px;
  margin: 16px 20px 0;
  border-radius: 18px;
  border: 1px solid rgba(234, 242, 255, 0.14);
  background:
    radial-gradient(520px 220px at 20% 0%, rgba(103, 246, 255, 0.14), transparent 55%),
    radial-gradient(520px 240px at 90% 40%, rgba(47, 123, 255, 0.14), transparent 55%),
    rgba(255, 255, 255, 0.04);
  color: var(--text);
  box-shadow:
    0 1px 0 rgba(255,255,255,0.08) inset,
    0 26px 90px rgba(2, 6, 23, 0.28),
    0 0 40px rgba(34, 211, 238, 0.06);
  backdrop-filter: blur(10px);
}

.chat-welcome-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid rgba(34, 211, 238, 0.22);
  background: rgba(7, 26, 43, 0.35);
  color: rgba(234, 242, 255, 0.9);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  margin-bottom: 12px;
  box-shadow: 0 0 26px rgba(34, 211, 238, 0.10);
}

.chat-empty-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 26px;
  letter-spacing: -0.02em;
  margin-bottom: 6px;
  background: linear-gradient(90deg, rgba(234, 242, 255, 1), rgba(103, 246, 255, 0.9), rgba(47, 123, 255, 0.9));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.chat-empty-subtitle {
  font-size: 13.5px;
  color: var(--muted);
  line-height: 1.5;
  max-width: 56ch;
}
.chat-empty-powered {
  font-size: 12px;
  color: var(--muted);
  margin-top: 12px;
}

/* Arabic welcome: start from the right */
.chat-welcome[dir="rtl"] {
  direction: rtl;
  text-align: right;
}

.chat-welcome[dir="rtl"] .chat-welcome-badge {
  justify-content: flex-end;
}

.chat-welcome-actions {
  margin-top: 18px;
  padding: 14px;
  border: 1px solid rgba(234, 242, 255, 0.12);
  border-radius: 18px;
  background: rgba(7, 26, 43, 0.26);
  box-shadow: 0 14px 45px rgba(2, 6, 23, 0.18);
}

.chat-welcome-actions-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
  color: rgba(234, 242, 255, 0.94);
  font-weight: 800;
}

.chat-welcome-actions-head small {
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 600;
}

.chat-welcome-topic-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.chat-welcome-topic {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 64px;
  padding: 11px 12px;
  border: 1px solid rgba(234, 242, 255, 0.12);
  border-radius: 16px;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.085), rgba(255, 255, 255, 0.025)),
    rgba(7, 26, 43, 0.28);
  color: rgba(234, 242, 255, 0.94);
  text-align: right;
  cursor: pointer;
  transition: transform 160ms ease, border-color 160ms ease, background 160ms ease, box-shadow 160ms ease;
}

.chat-welcome-topic:hover,
.chat-welcome-topic.is-active {
  transform: translateY(-1px);
  border-color: color-mix(in srgb, var(--topic-accent) 58%, rgba(234, 242, 255, 0.16));
  box-shadow: 0 12px 34px color-mix(in srgb, var(--topic-accent) 20%, transparent);
}

.chat-welcome-topic.is-active {
  background:
    radial-gradient(180px 80px at 100% 0%, color-mix(in srgb, var(--topic-accent) 24%, transparent), transparent 64%),
    linear-gradient(135deg, rgba(255, 255, 255, 0.11), rgba(255, 255, 255, 0.035));
}

.chat-welcome-topic strong,
.chat-welcome-topic small {
  display: block;
}

.chat-welcome-topic strong {
  font-size: 0.95rem;
  line-height: 1.3;
}

.chat-welcome-topic small {
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.75rem;
}

.chat-welcome-topic-dot {
  width: 10px;
  height: 38px;
  border-radius: 999px;
  background: var(--topic-accent);
  box-shadow: 0 0 22px color-mix(in srgb, var(--topic-accent) 55%, transparent);
  flex: 0 0 auto;
}

.chat-welcome-topic.is-red { --topic-accent: #ef4444; }
.chat-welcome-topic.is-blue { --topic-accent: #38bdf8; }
.chat-welcome-topic.is-green { --topic-accent: #22c55e; }
.chat-welcome-topic.is-yellow { --topic-accent: #facc15; }

.chat-welcome-prompt-panels {
  margin-top: 12px;
}

.chat-welcome-prompts[hidden] {
  display: none !important;
}

.chat-welcome-prompts {
  padding: 12px;
  border: 1px solid rgba(234, 242, 255, 0.10);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.045);
}

.chat-welcome-prompts-title {
  margin-bottom: 10px;
  color: rgba(234, 242, 255, 0.9);
  font-size: 0.85rem;
  font-weight: 800;
}

.chat-welcome-prompt-list {
  display: grid;
  gap: 8px;
}

.chat-welcome-prompt {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid rgba(34, 211, 238, 0.17);
  border-radius: 12px;
  background: rgba(2, 6, 23, 0.18);
  color: rgba(234, 242, 255, 0.9);
  font: inherit;
  font-size: 0.86rem;
  line-height: 1.45;
  text-align: right;
  cursor: pointer;
  transition: transform 150ms ease, border-color 150ms ease, background 150ms ease;
}

.chat-welcome-prompt:hover {
  transform: translateX(-2px);
  border-color: rgba(34, 211, 238, 0.42);
  background: rgba(34, 211, 238, 0.10);
}

/* Light theme: keep welcome title/badge high-contrast */
body[data-theme="light"] .chat-empty {
  border-color: rgba(15, 23, 42, 0.12);
  background:
    radial-gradient(520px 220px at 20% 0%, rgba(34, 211, 238, 0.12), transparent 55%),
    radial-gradient(520px 240px at 90% 40%, rgba(47, 123, 255, 0.10), transparent 55%),
    rgba(255, 255, 255, 0.92);
  box-shadow:
    0 1px 0 rgba(255,255,255,0.9) inset,
    0 26px 90px rgba(2, 6, 23, 0.14),
    0 0 40px rgba(34, 211, 238, 0.06);
}

body[data-theme="light"] .chat-welcome-badge {
  background: rgba(15, 23, 42, 0.06);
  color: rgba(7, 26, 43, 0.86);
  border-color: rgba(34, 211, 238, 0.28);
}

body[data-theme="light"] .chat-empty-title {
  background: none;
  -webkit-background-clip: initial;
  background-clip: initial;
  color: #071a2b;
  text-shadow: 0 1px 0 rgba(255,255,255,0.6);
}

body[data-theme="light"] .chat-welcome-actions {
  border-color: rgba(15, 23, 42, 0.10);
  background: rgba(255, 255, 255, 0.72);
}

body[data-theme="light"] .chat-welcome-actions-head {
  color: #071a2b;
}

body[data-theme="light"] .chat-welcome-topic {
  border-color: rgba(15, 23, 42, 0.10);
  background: rgba(255, 255, 255, 0.84);
  color: #071a2b;
}

body[data-theme="light"] .chat-welcome-prompts {
  border-color: rgba(15, 23, 42, 0.10);
  background: rgba(255, 255, 255, 0.82);
}

body[data-theme="light"] .chat-welcome-prompts-title {
  color: #071a2b;
}

body[data-theme="light"] .chat-welcome-prompt {
  border-color: rgba(15, 23, 42, 0.10);
  background: rgba(241, 247, 255, 0.92);
  color: #0f172a;
}

body[data-theme="light"] .chat-welcome-prompt:hover {
  border-color: rgba(15, 96, 168, 0.34);
  background: rgba(224, 242, 254, 0.9);
}

.chat-view[hidden],
.voice-view[hidden],
.chat-avatar-view[hidden] {
  display: none !important;
}

.voice-view {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-rows: auto 1fr;
  border: 1px solid var(--border);
  border-radius: 12px;
  margin: 0 20px 16px;
  background: rgba(0, 0, 0, 0.2);
}

.voice-top {
  min-height: 140px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 12px;
  border-bottom: 1px solid var(--border);
}

.voice-indicator {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.voice-mic-icon {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
  border: 2px solid var(--border);
  display: block;
  position: relative;
  color: var(--muted);
}

.voice-mic-icon::after {
  content: "";
  position: absolute;
  inset: 0;
  background: currentColor;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='black' d='M12 14a3 3 0 0 0 3-3V6a3 3 0 0 0-6 0v5a3 3 0 0 0 3 3z'/%3E%3Cpath fill='black' d='M19 11a7 7 0 0 1-14 0h2a5 5 0 0 0 10 0h2z'/%3E%3Cpath fill='black' d='M12 18v3h-2v-3h2z'/%3E%3Cpath fill='black' d='M8 21h8v2H8z'/%3E%3C/svg%3E") no-repeat center / 22px 22px;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='black' d='M12 14a3 3 0 0 0 3-3V6a3 3 0 0 0-6 0v5a3 3 0 0 0 3 3z'/%3E%3Cpath fill='black' d='M19 11a7 7 0 0 1-14 0h2a5 5 0 0 0 10 0h2z'/%3E%3Cpath fill='black' d='M12 18v3h-2v-3h2z'/%3E%3Cpath fill='black' d='M8 21h8v2H8z'/%3E%3C/svg%3E") no-repeat center / 22px 22px;
}

.voice-indicator[data-state="listening"] .voice-mic-icon {
  background: rgba(35, 55, 138, 0.25);
  border-color: var(--primary);
  color: var(--primary);
}

.voice-indicator[data-state="processing"] .voice-mic-icon {
  background: rgba(148, 163, 184, 0.2);
  border-color: var(--muted);
  color: var(--muted);
}

.voice-indicator[data-state="speaking"] .voice-mic-icon {
  background: rgba(16, 185, 129, 0.2);
  border-color: #10b981;
  color: #10b981;
}

.voice-state {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--muted);
}

.voice-actions {
  display: flex;
  gap: 8px;
}

.chat-btn-small {
  height: 32px;
  padding: 0 12px;
  font-size: 0.8125rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  cursor: pointer;
}

.chat-btn-small:hover {
  background: rgba(255, 255, 255, 0.1);
}

.chat-btn-icon {
  width: 44px;
  min-width: 44px;
  height: 44px;
  padding: 0;
  font-size: 0.75rem;
  font-weight: 600;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  cursor: pointer;
}

.chat-btn-icon:hover {
  background: rgba(255, 255, 255, 0.1);
}

.chat-btn-voice {
  border-radius: 999px;
  background: #0b0f1a;
  border-color: rgba(255, 255, 255, 0.14);
  color: #ffffff;
}

.chat-btn-icon.chat-btn-voice:hover {
  background: #0f172a;
  border-color: rgba(255, 255, 255, 0.22);
}

.chat-btn-voice:disabled {
  opacity: 0.55;
}

.chat-btn-icon .chat-icon {
  display: block;
}

.voice-view {
  background: rgba(0, 0, 0, 0.18);
}

.voice-top {
  background: var(--surface);
}

.voice-mic-icon {
  width: 64px;
  height: 64px;
  border-width: 1px;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.06);
}

.voice-state {
  font-size: 0.875rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  color: var(--text);
}

.voice-transcript-wrap {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 8px;
}

.voice-transcript-head {
  flex: 0 0 auto;
  padding: 10px 10px;
  border: 1px solid var(--border);
  border-bottom: 0;
  border-radius: 12px 12px 0 0;
  background: rgba(255,255,255,0.03);
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.voice-transcript {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  font-size: 0.9375rem;
  line-height: 1.5;
  border: 1px solid var(--border);
  border-radius: 0 0 12px 12px;
  background: rgba(0,0,0,0.18);
}

.voice-transcript-line {
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid transparent;
}

.voice-transcript-line.user {
  background: var(--user);
  border-color: rgba(37, 99, 235, 0.2);
  align-self: flex-end;
  max-width: 90%;
}

.voice-transcript-line.assistant {
  background: var(--assistant);
  border-color: var(--border);
  max-width: 90%;
}

.voice-transcript-line.partial {
  opacity: 0.8;
  border-style: dashed;
}

.voice-transcript-line .label {
  font-size: 0.6875rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin-bottom: 4px;
}

.chat-history {
  flex: 1;
  overflow: auto;
  padding: 12px 18px 10px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.chat-history::-webkit-scrollbar {
  width: 8px;
}

.chat-history::-webkit-scrollbar-thumb {
  background: rgba(248, 250, 252, 0.12);
  border-radius: 999px;
}

/* Source badge (Orchestrate direct) */
.msg-source-badge {
  display: inline-block;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 500;
  background: linear-gradient(135deg, #0f62fe 0%, #0043ce 100%);
  color: white;
  border-radius: 12px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  cursor: help;
}

@media (prefers-reduced-motion: no-preference) {
  @keyframes msg-in {
    from { opacity: 0; transform: translateY(10px) scale(0.99); filter: blur(1px); }
    to { opacity: 1; transform: translateY(0) scale(1); filter: blur(0px); }
  }
  .msg-row {
    animation: msg-in 240ms cubic-bezier(0.2, 0.8, 0.2, 1) both;
  }
}

/* Message row: avatar (KAI logo circle for assistant) + bubble */
.msg-row {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  max-width: 90%;
  min-width: 0;
}

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

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

/* Full logo visible in circle (same as launcher – contain, not zoom/crop) */
.msg-avatar-wrap {
  width: 30px;
  height: 30px;
  min-width: 30px;
  min-height: 30px;
  border-radius: 50%;
  overflow: hidden;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f8fafc;
  padding: 3px;
  box-sizing: border-box;
}

.msg-avatar-wrap img,
.msg-avatar {
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center;
  display: block;
}

.msg-row.user .msg-avatar-wrap {
  padding: 0;
  background: linear-gradient(135deg, rgba(11, 95, 255, 0.9), rgba(34, 211, 238, 0.75));
  border-color: rgba(34, 211, 238, 0.28);
  color: white;
  font-size: 0.75rem;
  font-weight: 800;
}

.msg-row.user .msg-avatar-wrap img {
  display: none;
}

.msg-bubble {
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 12px 14px;
  max-width: 100%;
  min-width: 0;
  overflow: hidden;
  overflow-wrap: anywhere;
  background:
    radial-gradient(560px 220px at 20% 10%, rgba(34, 211, 238, 0.10), transparent 55%),
    radial-gradient(520px 220px at 90% 30%, rgba(47, 123, 255, 0.12), transparent 55%),
    rgba(255, 255, 255, 0.05);
  box-shadow:
    0 1px 0 rgba(255,255,255,0.08) inset,
    0 18px 55px rgba(2, 6, 23, 0.22),
    0 0 24px rgba(34, 211, 238, 0.06);
  backdrop-filter: blur(8px);
}

.msg-row.user .msg-bubble {
  background:
    radial-gradient(540px 220px at 20% 0%, rgba(103, 246, 255, 0.16), transparent 55%),
    linear-gradient(135deg, rgba(47, 123, 255, 0.26), rgba(34, 211, 238, 0.12));
  border-color: rgba(34, 211, 238, 0.22);
  box-shadow:
    0 1px 0 rgba(255,255,255,0.10) inset,
    0 18px 55px rgba(2, 6, 23, 0.20),
    0 0 30px rgba(47, 123, 255, 0.14);
}

.msg-row.assistant .msg-bubble {
  background: rgba(255, 255, 255, 0.05);
  border-color: rgba(234, 242, 255, 0.14);
}

.msg-row.assistant .msg-bubble {
  position: relative;
}
.msg-row.assistant .msg-bubble::before {
  content: "";
  position: absolute;
  inset: -1px;
  border-radius: 16px;
  background: linear-gradient(135deg, rgba(34, 211, 238, 0.22), rgba(47, 123, 255, 0.16), rgba(34, 211, 238, 0.12));
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s ease;
  z-index: -1;
  filter: blur(10px);
}
.msg-row.assistant:hover .msg-bubble::before {
  opacity: 1;
}

.msg-row.error .msg-bubble {
  border-color: rgba(239, 68, 68, 0.35);
  background: var(--danger);
}

.msg-meta {
  font-size: 0.6875rem;
  color: var(--muted);
  margin-bottom: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.msg-latency { color: var(--muted); }
.msg-agent { color: var(--muted); font-size: 0.625rem; }

.msg-text {
  white-space: normal;
  line-height: 1.5;
  font-size: 0.9375rem;
  max-width: 100%;
  min-width: 0;
  overflow-wrap: anywhere;
  word-break: break-word;
}

/* Markdown styling inside bubbles */
.msg-text p { margin: 0 0 10px; }
.msg-text p:last-child { margin-bottom: 0; }
.msg-text h1, .msg-text h2, .msg-text h3, .msg-text h4 {
  margin: 0 0 10px;
  line-height: 1.2;
}
.msg-text h1 { font-size: 1.1rem; }
.msg-text h2 { font-size: 1.05rem; }
.msg-text h3 { font-size: 1.0rem; }
.msg-text h4 { font-size: 0.95rem; }
.msg-text ul, .msg-text ol { margin: 6px 0 10px 18px; padding: 0; }
.msg-text li { margin: 4px 0; }
.msg-text a { color: #60a5fa; text-decoration: underline; }
body[data-theme="light"] .msg-text a { color: var(--primary); }
.msg-text blockquote {
  margin: 8px 0;
  padding: 8px 10px;
  border-left: 3px solid rgba(255,255,255,0.18);
  background: rgba(255,255,255,0.04);
  border-radius: 10px;
  color: var(--muted);
}
body[data-theme="light"] .msg-text blockquote {
  border-left-color: rgba(15,23,42,0.18);
  background: rgba(15,23,42,0.03);
}
.msg-text code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 0.875em;
  padding: 1px 6px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.06);
}
body[data-theme="light"] .msg-text code { background: rgba(15,23,42,0.03); }
.msg-text pre {
  margin: 10px 0;
  padding: 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(0,0,0,0.25);
  overflow: auto;
}
body[data-theme="light"] .msg-text pre { background: rgba(15,23,42,0.04); }
.msg-text pre code { background: transparent; border: 0; padding: 0; }

.msg-text, .voice-transcript-line { direction: auto; unicode-bidi: plaintext; }
.msg-text[dir="rtl"] { text-align: right; }
.msg-text[dir="rtl"] ul,
.msg-text[dir="rtl"] ol { margin-left: 0; margin-right: 18px; }
.msg-text[dir="rtl"] blockquote { border-left: 0; border-right: 3px solid rgba(255,255,255,0.18); }
body[data-theme="light"] .msg-text[dir="rtl"] blockquote { border-right-color: rgba(15,23,42,0.18); }

.msg-text .md-table {
  margin: 12px 0;
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.02);
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
}

.msg-text .md-table::-webkit-scrollbar { height: 6px; }
.msg-text .md-table::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.18);
  border-radius: 3px;
}

.msg-text table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  table-layout: auto;
  min-width: max-content;
  font-size: 0.875rem;
  line-height: 1.45;
}

.msg-text th,
.msg-text td {
  text-align: start;
  vertical-align: middle;
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  border-inline-end: 1px solid var(--border);
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1, "lnum" 1;
  white-space: nowrap;
}

.msg-text th:last-child,
.msg-text td:last-child { border-inline-end: 0; }
.msg-text tbody tr:last-child td { border-bottom: 0; }

.msg-text th {
  font-size: 0.8125rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  color: #f8fafc;
  background: rgba(255, 255, 255, 0.08);
  text-transform: none;
}

.msg-text tbody tr:nth-child(even) td {
  background: rgba(255, 255, 255, 0.025);
}

.msg-text tbody tr:hover td {
  background: rgba(255, 255, 255, 0.05);
}

.msg-text .md-table[dir="rtl"] { direction: rtl; }
.msg-text .md-table[dir="rtl"] th,
.msg-text .md-table[dir="rtl"] td {
  text-align: right;
  font-family: "IBM Plex Sans Arabic", "Noto Sans Arabic", "Segoe UI", system-ui, sans-serif;
}

.msg-text .md-table[dir="rtl"] td:first-child,
.msg-text .md-table[dir="rtl"] th:first-child {
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.msg-text hr.md-hr {
  border: 0;
  height: 1px;
  background: var(--border);
  margin: 12px 0;
  opacity: 0.7;
}

/* Google Maps embed (assistant messages) */
.map-card {
  margin-top: 10px;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  background: rgba(0, 0, 0, 0.18);
}
.map-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
}
.map-title {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: 0.02em;
}
.map-open {
  font-size: 0.75rem;
  color: #60a5fa;
  text-decoration: underline;
}
.map-status {
  padding: 10px;
  font-size: 0.8125rem;
  color: var(--muted);
}
.map-iframe {
  width: 100%;
  height: 260px;
  border: 0;
  display: block;
  background: transparent;
}

body[data-theme="light"] .map-card {
  background: rgba(15, 23, 42, 0.02);
}
body[data-theme="light"] .map-open {
  color: var(--primary);
}

body[data-theme="light"] .msg-text .md-table {
  border-color: #e2e8f0;
  background: #fff;
}
body[data-theme="light"] .msg-text th,
body[data-theme="light"] .msg-text td {
  border-bottom-color: #e2e8f0;
  border-inline-end-color: #e2e8f0;
}
body[data-theme="light"] .msg-text th {
  background: #f1f5f9;
  color: #0f172a;
}
body[data-theme="light"] .msg-text tbody tr:nth-child(even) td { background: rgba(15,23,42,0.025); }
body[data-theme="light"] .msg-text tbody tr:hover td { background: rgba(15,23,42,0.05); }
body[data-theme="light"] .msg-text hr.md-hr { background: #e2e8f0; }

.msg-row.thinking-placeholder .msg-text {
  font-style: italic;
  color: var(--muted);
}

.msg-row.thinking-placeholder .msg-text {
  position: relative;
}
@media (prefers-reduced-motion: no-preference) {
  .msg-row.thinking-placeholder .msg-text::after {
    content: "";
    display: inline-block;
    width: 14px;
    height: 14px;
    margin-left: 10px;
    border-radius: 50%;
    border: 2px solid rgba(234, 242, 255, 0.22);
    border-top-color: rgba(34, 211, 238, 0.85);
    border-right-color: rgba(47, 123, 255, 0.85);
    animation: apex-spin 0.85s linear infinite;
    vertical-align: -2px;
  }
}

/* Artifacts */
details.artifacts {
  margin-top: 10px;
  border-top: 1px solid var(--border);
  padding-top: 8px;
}

details.artifacts summary {
  cursor: pointer;
  color: var(--text);
  font-weight: 700;
  font-size: 0.75rem;
}

.thinking-list {
  margin: 8px 0 0;
  padding-left: 18px;
  color: var(--muted);
  font-size: 0.8125rem;
}

.thinking-list li { margin: 6px 0; }

/* Like / unlike feedback under assistant messages */
.msg-feedback {
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.75rem;
  color: var(--muted);
}
.msg-feedback-label { flex-shrink: 0; }
.msg-feedback-btn {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 10px;
  cursor: pointer;
  font-size: 1rem;
  opacity: 0.8;
  transition: opacity 0.15s, background 0.15s, border-color 0.15s;
}
.msg-feedback-btn:hover {
  opacity: 1;
  background: rgba(255,255,255,0.06);
  border-color: var(--muted);
}
.msg-feedback-btn.selected {
  opacity: 1;
  background: rgba(34, 197, 94, 0.15);
  border-color: rgba(34, 197, 94, 0.5);
}
.msg-feedback-unlike.selected {
  background: rgba(239, 68, 68, 0.15);
  border-color: rgba(239, 68, 68, 0.5);
}

.msg-feedback-comment-wrap {
  display: none;
  margin-top: 8px;
}
.msg-feedback-comment-wrap.visible {
  display: block;
}
.msg-feedback-comment-label {
  display: block;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 2px;
}
.msg-feedback-comment-subtext {
  font-size: 0.75rem;
  color: var(--muted);
  margin-bottom: 6px;
}
.msg-feedback-comment {
  width: 100%;
  box-sizing: border-box;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.8125rem;
  resize: vertical;
  min-height: 56px;
  margin-bottom: 8px;
}
.msg-feedback-comment::placeholder {
  color: var(--muted);
}
.msg-feedback-comment:focus {
  outline: none;
  border-color: var(--muted);
}
.msg-feedback-comment-btns {
  display: flex;
  gap: 8px;
}
.msg-feedback-comment-btn {
  padding: 6px 14px;
  border-radius: 6px;
  font-size: 0.8125rem;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  transition: background 0.15s, border-color 0.15s;
}
.msg-feedback-comment-btn:hover {
  background: var(--assistant);
  border-color: var(--muted);
}
.msg-feedback-comment-submit {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
.msg-feedback-comment-submit:hover {
  filter: brightness(1.1);
}
.msg-feedback-comment-cancel {
  background: transparent;
}
.msg-feedback-comment-cancel:hover {
  background: rgba(239, 68, 68, 0.15);
  border-color: rgba(239, 68, 68, 0.5);
}

/* Form */
.chat-form {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  padding: 10px 18px;
  border-top: 1px solid var(--border);
  background:
    linear-gradient(180deg, rgba(7, 26, 43, 0.10), rgba(7, 26, 43, 0.55));
  backdrop-filter: blur(10px);
  position: relative;
}

.chat-form::before {
  content: "";
  position: absolute;
  left: 12px;
  right: 12px;
  top: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(34, 211, 238, 0.35), rgba(47, 123, 255, 0.25), transparent);
  opacity: 0.9;
}

.chat-form-extra {
  width: 100%;
  flex-basis: 100%;
  margin-top: -4px;
}
.chat-attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 8px;
}
.chat-attachment {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: 100%;
  padding: 6px 9px;
  border: 1px solid rgba(34, 211, 238, 0.28);
  border-radius: 999px;
  background: rgba(34, 211, 238, 0.10);
  color: var(--text);
  font-size: 0.75rem;
}
.chat-attachment-name {
  max-width: min(260px, 70vw);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chat-attachment-remove {
  width: 18px;
  height: 18px;
  border: 0;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.14);
  color: inherit;
  cursor: pointer;
  line-height: 1;
}
.chat-upload-request {
  margin-top: 14px;
  padding: 14px;
  border: 1px solid rgba(34, 211, 238, 0.22);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.045);
}
.chat-upload-request-title {
  font-weight: 700;
  margin-bottom: 6px;
}
.chat-upload-request-hint {
  color: var(--muted);
  font-size: 0.8125rem;
  margin-bottom: 12px;
}
.chat-upload-request-btn {
  min-height: 38px;
  padding: 0 20px;
  border: 0;
  border-radius: 999px;
  background: linear-gradient(135deg, rgba(11, 95, 255, 0.98), rgba(34, 211, 238, 0.72));
  color: #ffffff;
  font-weight: 800;
  cursor: pointer;
}
.chat-upload-request-btn:disabled {
  opacity: 0.65;
  cursor: wait;
}
.chat-link.chat-new-topic-btn {
  background: none;
  border: none;
  padding: 0;
  font-size: 0.8125rem;
  color: var(--muted);
  cursor: pointer;
  text-decoration: underline;
}
.chat-link.chat-new-topic-btn:hover { color: var(--primary); }
.chat-link.chat-new-topic-btn[aria-pressed="true"] { color: var(--primary); }

.chat-input {
  flex: 1;
  height: 44px;
  padding: 0 14px;
  border-radius: 14px;
  border: 1px solid rgba(234, 242, 255, 0.14);
  background:
    radial-gradient(520px 180px at 20% 20%, rgba(34, 211, 238, 0.08), transparent 55%),
    rgba(255, 255, 255, 0.04);
  color: var(--text);
  font-family: inherit;
  font-size: 0.9375rem;
  box-shadow:
    0 1px 0 rgba(255,255,255,0.08) inset,
    0 18px 55px rgba(2, 6, 23, 0.18);
  transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.18s ease;
}

.chat-input:focus {
  outline: none;
  border-color: rgba(34, 211, 238, 0.45);
  box-shadow: 0 0 0 3px rgba(34, 211, 238, 0.16);
  transform: translateY(-1px);
}

.chat-send {
  height: 44px;
  padding: 0 18px;
  border-radius: 14px;
  border: 1px solid rgba(34, 211, 238, 0.22);
  background: linear-gradient(135deg, rgba(11, 95, 255, 0.95), rgba(34, 211, 238, 0.65));
  color: #ffffff;
  font-weight: 700;
  font-size: 0.875rem;
  cursor: pointer;
  box-shadow: 0 18px 55px rgba(11, 95, 255, 0.18);
  transition: transform 0.18s ease, background 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease;
}

.chat-send.chat-send-icon {
  width: 44px;
  min-width: 44px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.chat-btn-icon .chat-icon,
.chat-send.chat-send-icon .chat-icon {
  width: 22px;
  height: 22px;
}

body[data-theme="light"] .chat-send.chat-send-icon .chat-icon {
  color: #fff;
}

.chat-send:hover,
.chat-send:focus-visible {
  background: linear-gradient(135deg, #2563eb 0%, #22d3ee 100%);
  border-color: rgba(103, 246, 255, 0.55);
  color: #ffffff;
  transform: translateY(-1px);
  box-shadow: 0 12px 32px rgba(11, 95, 255, 0.42);
}

body[data-theme="light"] .chat-send:hover,
body[data-theme="light"] .chat-send:focus-visible {
  background: linear-gradient(135deg, #0b5fff 0%, #06b6d4 100%);
  border-color: rgba(11, 95, 255, 0.55);
  box-shadow: 0 10px 26px rgba(11, 95, 255, 0.34);
}

.chat-send:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}.trust-footer {
  font-size: 0.6875rem;
  color: var(--muted);
  padding: 6px 18px 8px;
  border-top: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.1);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.trust-footer-madeby {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
  color: var(--muted);
}

.logo-on-white {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #ffffff;
  border-radius: 999px;
  padding: 6px 10px;
  box-shadow: 0 10px 30px rgba(2, 6, 23, 0.16);
}

.isys-logo {
  height: 18px;
  width: auto;
  display: block;
}

@media (max-width: 520px) {
  .trust-footer {
    flex-direction: column;
    align-items: flex-start;
  }
  .trust-footer-madeby {
    width: 100%;
    justify-content: flex-start;
  }
}

/* Avatar view: same size as chat area, replaces chat when Avatar button is used */
.chat-avatar-view {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

.chat-avatar-view-bar {
  flex-shrink: 0;
  padding: 10px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.chat-avatar-back-btn {
  padding: 8px 14px;
  font-size: 0.875rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  cursor: pointer;
}

.chat-avatar-back-btn:hover {
  background: rgba(255, 255, 255, 0.1);
}

.avatar-stt-lang {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px;
  border-radius: 999px;
  border: 1px solid rgba(234, 242, 255, 0.14);
  background: rgba(7, 26, 43, 0.25);
  backdrop-filter: blur(10px);
}
.avatar-stt-lang-label {
  font-size: 0.75rem;
  color: var(--muted);
  padding: 0 8px 0 10px;
  user-select: none;
  white-space: nowrap;
}
.avatar-stt-lang-btn {
  appearance: none;
  border: 1px solid transparent;
  background: transparent;
  color: rgba(234, 242, 255, 0.88);
  font: inherit;
  font-size: 0.8125rem;
  font-weight: 800;
  letter-spacing: 0.01em;
  padding: 8px 10px;
  border-radius: 999px;
  cursor: pointer;
  transition: transform 0.16s ease, background 0.16s ease, border-color 0.16s ease, filter 0.16s ease;
}
.avatar-stt-lang-btn:hover {
  transform: translateY(-1px);
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(34, 211, 238, 0.22);
}
.avatar-stt-lang-btn[aria-pressed="true"] {
  background: linear-gradient(135deg, rgba(11, 95, 255, 0.85), rgba(34, 211, 238, 0.45));
  border-color: rgba(34, 211, 238, 0.28);
  color: #ffffff;
  filter: saturate(1.08);
  box-shadow: 0 0 0 3px rgba(34, 211, 238, 0.12);
}
.avatar-stt-lang-btn:active { transform: translateY(0px); }

.chat-avatar-view-stage {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px 16px 20px;
  background: var(--bg);
}

.chat-avatar-player-area {
  flex: 1;
  min-height: 0;
  position: relative;
  width: 100%;
  align-self: stretch;
  background: var(--bg);
}

#chat-avatar-player {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  background: var(--bg);
}

#chat-avatar-player video {
  position: absolute !important;
  left: 0 !important;
  top: 0 !important;
  width: 100% !important;
  height: 100% !important;
  object-fit: contain;
}

.chat-avatar-loading {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background:
    radial-gradient(700px 360px at 18% 25%, rgba(11, 95, 255, 0.22), transparent 60%),
    radial-gradient(700px 360px at 84% 35%, rgba(34, 211, 238, 0.16), transparent 60%),
    rgba(7, 26, 43, 0.65);
  color: var(--muted);
  font-size: 0.9rem;
  backdrop-filter: blur(10px);
}

.chat-avatar-loading::before {
  content: "";
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid rgba(234, 242, 255, 0.22);
  border-top-color: rgba(34, 211, 238, 0.85);
  border-right-color: rgba(11, 95, 255, 0.85);
  animation: apex-spin 0.9s linear infinite;
}

@keyframes apex-spin {
  to { transform: rotate(360deg); }
}


.chat-avatar-loading[hidden] {
  display: none !important;
}

.chat-avatar-mic-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  flex-shrink: 0;
  margin-top: 8px;
}

.chat-avatar-mic {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  background: var(--primary);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s, opacity 0.15s;
  flex-shrink: 0;
}

.chat-avatar-status {
  font-size: 0.875rem;
  color: var(--muted);
  min-width: 5em;
}

.chat-avatar-mic:hover:not(:disabled) {
  opacity: 0.9;
  transform: scale(1.05);
}

.chat-avatar-mic:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.chat-avatar-mic.listening {
  animation: chat-avatar-pulse 1.2s ease-in-out infinite;
}

@keyframes chat-avatar-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(35, 55, 138, 0.5); }
  50% { box-shadow: 0 0 0 14px rgba(35, 55, 138, 0); }
}

/* CBE launch: hide avatar/voice entry points — remove this block and `hidden` on buttons to re-enable. */
#chat-avatar-btn,
#voice-btn {
  display: none !important;
}
