/* ═══════════════════════════════════════════════════
   MESSAGE BUBBLES
═══════════════════════════════════════════════════ */
.message {
  display: flex;
  flex-direction: column;
  max-width: 78%;
  min-width: 0; /* Prevents flex item from expanding beyond max-width (needed for table overflow) */
  margin-bottom: 20px;
}

/* ── Entrance keyframes ── */

/* User messages — late-braking manoeuvre from the right */
@keyframes msg-enter-user {
  from { opacity: 0; transform: translateX(48px) translateY(6px) scale(0.93); }
  to   { opacity: 1; transform: translateX(0)    translateY(0)   scale(1);    }
}

/* Apex messages — arrives from the left with spring overshoot */
@keyframes msg-enter-apex {
  from { opacity: 0; transform: translateX(-18px) translateY(24px) scale(0.96); }
  to   { opacity: 1; transform: translateX(0)     translateY(0)    scale(1);    }
}

/* Kept for typing indicator which still references this name */
@keyframes message-enter {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0);   }
}

/* Child stagger within Apex messages — direction-aware fade */
@keyframes child-fade-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0);   }
}

/* ── Exit — .is-exiting applied by JS before DOM removal ── */
@keyframes message-exit {
  from { opacity: 1; transform: translateY(0); }
  to   { opacity: 0; transform: translateY(-8px) scale(0.97); }
}

.is-exiting {
  animation: message-exit 160ms ease-in both !important;
  pointer-events: none;
}

/* ── USER MESSAGE (right-aligned) ── */
.message--user {
  align-self: flex-end;
  align-items: flex-end;
  animation: msg-enter-user 210ms cubic-bezier(0.22, 1, 0.36, 1) both;
}

.message--user .message__bubble {
  background: var(--bg-user-bubble);
  border: 1px solid rgba(232, 0, 13, 0.18);
  border-right: 2.5px solid var(--red);
  border-radius: var(--radius-lg) var(--radius-sm) var(--radius-lg) var(--radius-lg);
  color: var(--text-primary);
  position: relative;
  overflow: hidden;
}

.message--user .message__bubble::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(232, 0, 13, 0.04) 0%, transparent 60%);
  pointer-events: none;
}

/* ── APEX MESSAGE (left-aligned) ── */
.message--apex {
  align-self: flex-start;
  align-items: flex-start;
  animation: msg-enter-apex 360ms cubic-bezier(0.34, 1.45, 0.64, 1) both;
}

.message--apex .message__label {
  font-family: var(--font-display);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 3px;
  color: var(--red);
  text-transform: uppercase;
  margin-bottom: 5px;
  padding-left: 14px;
  display: flex;
  align-items: center;
  gap: 7px;
  animation: child-fade-in 260ms cubic-bezier(0.22, 1, 0.36, 1) 0ms both;
}

.message--apex .message__label::before {
  content: '';
  display: block;
  width: 16px;
  height: 1.5px;
  background: var(--red);
  opacity: 0.6;
}

.message--apex .message__bubble {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-left: 2.5px solid var(--red);
  border-radius: var(--radius-sm) var(--radius-lg) var(--radius-lg) var(--radius-lg);
  color: var(--text-primary);
  position: relative;
  box-shadow: 0 2px 16px rgba(0, 0, 0, 0.18);
  animation: child-fade-in 260ms cubic-bezier(0.22, 1, 0.36, 1) 40ms both;
}

/* Subtle top-left accent glow on Apex bubbles */
.message--apex .message__bubble::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 60px;
  height: 60px;
  background: radial-gradient(circle at 0% 0%, rgba(232, 0, 13, 0.08), transparent 70%);
  pointer-events: none;
}

/* ── BUBBLE CONTENT ── */
.message__bubble {
  padding: 13px 16px;
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.68;
  word-break: break-word;
  overflow-wrap: break-word;
}

.message__bubble p {
  margin-bottom: 0.85em;
}

.message__bubble p:last-child {
  margin-bottom: 0;
}

/* ── STREAMING CURSOR ── */
.message__bubble .stream-cursor {
  display: inline-block;
  width: 2px;
  height: 1em;
  background: var(--red);
  vertical-align: text-bottom;
  margin-left: 2px;
  border-radius: 1px;
  animation: cursor-breathe 900ms ease-in-out infinite;
}

@keyframes cursor-breathe {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.08; }
}

/* ── MESSAGE TIMESTAMP ── */
.message__time {
  font-family: var(--font-display);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  margin-top: 5px;
  padding: 0 4px;
}

/* ── MESSAGE FOOTER (apex messages — holds time + copy btn) ── */
.message__footer {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 5px;
  padding: 0 4px;
  animation: child-fade-in 260ms cubic-bezier(0.22, 1, 0.36, 1) 80ms both;
}

.message__footer .message__time {
  margin-top: 0; /* footer handles the spacing */
  padding: 0;
}

/* ── COPY BUTTON ── */
.msg-copy-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px 4px 8px;
  border-radius: 5px;
  background: transparent;
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
  cursor: pointer;
  font-family: var(--font-display);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  transition: background 150ms ease, border-color 150ms ease, color 150ms ease;
  flex-shrink: 0;
}

.msg-copy-btn:hover {
  background: rgba(255, 255, 255, 0.05);
  border-color: rgba(255, 255, 255, 0.15);
  color: var(--text-secondary);
}

.msg-copy-btn.is-copied {
  color: #4CAF50;
  border-color: rgba(76, 175, 80, 0.35);
  background: rgba(76, 175, 80, 0.06);
}

.msg-copy-btn:disabled {
  pointer-events: none;
  opacity: 0;
}

.msg-action-label {
  font-family: var(--font-display);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.06em;
}

/* ── MESSAGE ACTIONS ROW ── */
.msg-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: auto; /* pushes to right inside .message__footer flex row */
}

/* ── FEEDBACK BUTTONS (thumbs up/down) ── */
.msg-feedback-btn,
.msg-pin-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 5px;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: background 150ms ease, border-color 150ms ease, color 150ms ease;
  flex-shrink: 0;
  padding: 0;
}

.msg-feedback-btn:hover,
.msg-pin-btn:hover {
  background: rgba(255, 255, 255, 0.05);
  border-color: var(--border-subtle);
  color: var(--text-secondary);
}

/* Thumbs-up selected — green */
.msg-feedback-btn.is-up {
  color: #4CAF50;
  border-color: rgba(76, 175, 80, 0.35);
  background: rgba(76, 175, 80, 0.07);
}

/* Thumbs-down selected — red */
.msg-feedback-btn.is-down {
  color: var(--red);
  border-color: rgba(232, 0, 13, 0.35);
  background: rgba(232, 0, 13, 0.06);
}

/* Pinned / bookmarked — amber */
.msg-pin-btn.is-pinned {
  color: #FFC107;
  border-color: rgba(255, 193, 7, 0.35);
  background: rgba(255, 193, 7, 0.06);
}

.msg-feedback-btn:disabled,
.msg-pin-btn:disabled {
  pointer-events: none;
  opacity: 0;
}

/* ── REGENERATE BUTTON ── */
.msg-regen-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px 4px 8px;
  border-radius: 5px;
  background: transparent;
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
  cursor: pointer;
  font-family: var(--font-display);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  transition: background 150ms ease, border-color 150ms ease, color 150ms ease;
  flex-shrink: 0;
}

.msg-regen-btn:hover {
  background: rgba(255, 255, 255, 0.05);
  border-color: rgba(255, 255, 255, 0.15);
  color: var(--text-secondary);
}

.msg-regen-btn:disabled {
  pointer-events: none;
  opacity: 0;
}

/* ── TYPING INDICATOR ── */
.typing-indicator {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  margin-bottom: 20px;
  animation: message-enter 200ms ease both;
}

.typing-indicator__label {
  font-family: var(--font-display);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 3px;
  color: var(--red);
  text-transform: uppercase;
  margin-bottom: 5px;
  padding-left: 14px;
  display: flex;
  align-items: center;
  gap: 7px;
}

.typing-indicator__label::before {
  content: '';
  display: block;
  width: 16px;
  height: 1.5px;
  background: var(--red);
  opacity: 0.6;
}

.typing-indicator__bubble {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-left: 2.5px solid var(--red);
  border-radius: var(--radius-sm) var(--radius-lg) var(--radius-lg) var(--radius-lg);
  padding: 14px 20px;
  display: flex;
  align-items: center;
  gap: 5px;
}

/* Wave dots — GPU-only (transform + opacity only) */
.typing-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--red);
  opacity: 0.2;
  animation: dot-wave 0.95s ease-in-out infinite;
}

.typing-dot:nth-child(1) { animation-delay: 0s;     }
.typing-dot:nth-child(2) { animation-delay: 0.14s;  }
.typing-dot:nth-child(3) { animation-delay: 0.28s;  }

@keyframes dot-wave {
  0%, 60%, 100% {
    opacity: 0.2;
    transform: translateY(0)     scale(0.75);
  }
  30% {
    opacity: 1;
    transform: translateY(-11px) scale(1.25);
  }
}

/* ── ERROR MESSAGE ── */
.message--error .message__bubble {
  background: rgba(232, 0, 13, 0.07);
  border-left-color: var(--red);
  color: #FF6B6B;
  font-style: italic;
}

/* ── CACHE HIT BADGE ── */
.message--cached .message__label::after {
  content: '⚡ CACHED';
  font-size: 9px;
  letter-spacing: 1.5px;
  color: var(--sector-yellow);
  margin-left: 8px;
}

/* ── SCROLL-TO-BOTTOM BUTTON ── */
.scroll-btn {
  position: absolute;
  bottom: 0;
  right: 24px;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--bg-surface-2);
  border: 1px solid var(--border-mid);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
  transition: background var(--t-fast), border-color var(--t-fast),
              color var(--t-fast), box-shadow var(--t-fast),
              opacity var(--t-fast), transform var(--t-fast);
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  z-index: 10;
}

.scroll-btn.is-visible {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.scroll-btn:hover {
  background: var(--bg-surface);
  border-color: var(--red-border);
  color: var(--text-primary);
  box-shadow: var(--red-glow-sm);
}

.scroll-btn svg {
  width: 14px;
  height: 14px;
}

/* ═══════════════════════════════════════════════════
   MARKDOWN CONTENT (Apex bubbles only)
═══════════════════════════════════════════════════ */

/* ── Headings ── */
.message--apex .message__bubble h1,
.message--apex .message__bubble h2,
.message--apex .message__bubble h3,
.message--apex .message__bubble h4 {
  font-family: var(--font-display);
  font-weight: 700;
  letter-spacing: 0.4px;
  color: var(--text-primary);
  margin: 1em 0 0.35em;
  line-height: 1.3;
}

.message--apex .message__bubble h1 { font-size: 1.15em; }
.message--apex .message__bubble h2 { font-size: 1.08em; }
.message--apex .message__bubble h3 { font-size: 1em;    color: var(--text-secondary); }
.message--apex .message__bubble h4 { font-size: 0.9em;  color: var(--text-muted); text-transform: uppercase; letter-spacing: 1px; }

.message--apex .message__bubble h1:first-child,
.message--apex .message__bubble h2:first-child,
.message--apex .message__bubble h3:first-child {
  margin-top: 0;
}

/* ── Paragraphs ── */
.message--apex .message__bubble p {
  margin: 0 0 0.8em;
  line-height: 1.7;
}

.message--apex .message__bubble p:last-child {
  margin-bottom: 0;
}

/* ── Bold & Italic ── */
.message--apex .message__bubble strong {
  font-weight: 600;
  color: var(--text-primary);
}

.message--apex .message__bubble em {
  font-style: italic;
  color: var(--text-secondary);
}

/* ── Lists ── */
.message--apex .message__bubble ul,
.message--apex .message__bubble ol {
  margin: 0.4em 0 0.8em;
  padding-left: 1.4em;
}

.message--apex .message__bubble li {
  margin-bottom: 0.28em;
  line-height: 1.65;
  color: var(--text-secondary);
}

.message--apex .message__bubble li:last-child {
  margin-bottom: 0;
}

.message--apex .message__bubble li strong {
  color: var(--text-primary);
}

/* Custom red bullet for unordered lists */
.message--apex .message__bubble ul li::marker {
  color: var(--red);
}

.message--apex .message__bubble ol li::marker {
  color: var(--red);
  font-weight: 600;
  font-family: var(--font-display);
}

/* ── Tables ── */
.message--apex .message__bubble table {
  width: 100%;
  border-collapse: collapse;
  margin: 0.8em 0;
  font-size: 13.5px;
  display: block;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(255, 255, 255, 0.07);
}

.message--apex .message__bubble thead {
  background: rgba(232, 0, 13, 0.08);
}

.message--apex .message__bubble th {
  font-family: var(--font-display);
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--red);
  padding: 8px 14px;
  text-align: left;
  border-bottom: 1px solid rgba(232, 0, 13, 0.2);
  white-space: nowrap;
}

.message--apex .message__bubble td {
  padding: 7px 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  color: var(--text-secondary);
  line-height: 1.5;
  white-space: nowrap;
}

.message--apex .message__bubble tr:last-child td {
  border-bottom: none;
}

.message--apex .message__bubble tbody tr:nth-child(even) {
  background: rgba(255, 255, 255, 0.015);
}

.message--apex .message__bubble tbody tr:hover td {
  background: rgba(232, 0, 13, 0.04);
  color: var(--text-primary);
  transition: background 120ms ease, color 120ms ease;
}

/* First column emphasis (position numbers, driver names) */
.message--apex .message__bubble td:first-child {
  font-weight: 600;
  color: var(--text-primary);
  font-family: var(--font-display);
}

/* ── Inline code ── */
.message--apex .message__bubble code {
  font-family: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', 'Courier New', monospace;
  font-size: 0.865em;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 4px;
  padding: 1px 6px;
  color: #FF8A80;
}

/* ── Code blocks ── */
.message--apex .message__bubble pre {
  background: rgba(0, 0, 0, 0.45);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-left: 2.5px solid var(--red);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  margin: 0.75em 0;
  overflow-x: auto;
}

.message--apex .message__bubble pre code {
  background: none;
  border: none;
  padding: 0;
  color: var(--text-secondary);
  font-size: 13px;
  line-height: 1.6;
}

/* ── Blockquote ── */
.message--apex .message__bubble blockquote {
  border-left: 2.5px solid var(--red);
  margin: 0.75em 0;
  padding: 8px 14px;
  background: rgba(232, 0, 13, 0.04);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--text-secondary);
  font-style: italic;
}

.message--apex .message__bubble blockquote p:last-child {
  margin-bottom: 0;
}

/* ── Horizontal rule ── */
.message--apex .message__bubble hr {
  border: none;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  margin: 1em 0;
}

/* ── Links ── */
.message--apex .message__bubble a {
  color: var(--red);
  text-decoration: none;
  border-bottom: 1px solid rgba(232, 0, 13, 0.3);
  transition: border-color 150ms ease;
}

.message--apex .message__bubble a:hover {
  border-color: var(--red);
}

/* ── Strikethrough ── */
.message--apex .message__bubble del {
  color: var(--text-muted);
  text-decoration: line-through;
}

/* ═══════════════════════════════════════════════════
   SUGGESTION CHIPS
═══════════════════════════════════════════════════ */
.suggestion-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 10px;
  padding: 0 4px;
}

.suggestion-chip {
  display: inline-flex;
  align-items: center;
  padding: 5px 13px;
  background: var(--bg-surface);
  border: 1px solid var(--border-mid);
  border-radius: 99px;
  font-family: var(--font-body);
  font-size: 12.5px;
  color: var(--text-secondary);
  cursor: pointer;
  white-space: nowrap;
  transition: background 120ms ease, border-color 120ms ease, color 120ms ease, box-shadow 120ms ease;
  animation: chip-appear 360ms cubic-bezier(0.34, 1.55, 0.64, 1) both;
}

.suggestion-chip:hover {
  background: var(--bg-surface-2);
  border-color: var(--red-border);
  color: var(--text-primary);
  box-shadow: var(--red-glow-sm);
}

.suggestion-chip:active {
  transform: scale(0.95);
  background: var(--bg-surface-2);
  transition-duration: 60ms;
}

@keyframes chip-appear {
  from { opacity: 0; transform: translateY(14px) scale(0.86); }
  to   { opacity: 1; transform: translateY(0)    scale(1);    }
}

/* ── Button micro-interactions ── */
.msg-copy-btn:active,
.msg-feedback-btn:active,
.msg-pin-btn:active,
.msg-regen-btn:active {
  transform: scale(0.92);
  transition-duration: 60ms;
}

/* ── Ultrawide message cap ── */
@media (min-width: 1400px) {
  .message {
    max-width: 760px;
  }
}

/* ═══════════════════════════════════════════════════
   LIGHT MODE OVERRIDES
═══════════════════════════════════════════════════ */

/* Apex bubble depth shadow — softer in light mode */
[data-theme="light"] .message--apex .message__bubble {
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
}

/* Tables */
[data-theme="light"] .message--apex .message__bubble table {
  border-color: rgba(0, 0, 0, 0.1);
}

[data-theme="light"] .message--apex .message__bubble td {
  border-bottom-color: rgba(0, 0, 0, 0.06);
}

[data-theme="light"] .message--apex .message__bubble tbody tr:nth-child(even) {
  background: rgba(0, 0, 0, 0.03);
}

/* Inline code */
[data-theme="light"] .message--apex .message__bubble code {
  background: rgba(0, 0, 0, 0.06);
  border-color: rgba(0, 0, 0, 0.1);
  color: #CC0000;
}

/* Code blocks */
[data-theme="light"] .message--apex .message__bubble pre {
  background: rgba(0, 0, 0, 0.05);
  border-color: rgba(0, 0, 0, 0.08);
}

[data-theme="light"] .message--apex .message__bubble pre code {
  color: var(--text-secondary);
}

/* Horizontal rule */
[data-theme="light"] .message--apex .message__bubble hr {
  border-top-color: rgba(0, 0, 0, 0.1);
}


/* ═══════════════════════════════════════════════════
   F1 IDENTITY — team chips & driver badges
═══════════════════════════════════════════════════ */

/**
 * Team livery chip — replaces the plain team name in text.
 * The diagonal gradient (applied via inline style) mimics a racing stripe.
 */
.team-chip {
  display: inline-block;
  padding: 2px 7px 1px 6px;
  border-radius: 3px;
  font-family: var(--font-display);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  vertical-align: middle;
  white-space: nowrap;
  cursor: default;
  user-select: none;
  line-height: 1.55;
  /* gradient + shadow injected via inline style in identityRenderer.js */
}

/**
 * Driver name span — carries the team-coloured glow / underline.
 * Keeps its inherited font weight so it blends with surrounding text.
 */
.driver-name {
  font-weight: inherit;
  /* text-shadow or border-bottom injected via inline style */
}

/**
 * Driver racing-number badge — appears immediately after the driver name.
 */
.driver-num-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.06em;
  padding: 1px 5px 0 4px;
  border-radius: 3px;
  border: 1px solid transparent;
  margin-left: 3px;
  vertical-align: middle;
  line-height: 1.5;
  white-space: nowrap;
  cursor: default;
  user-select: none;
  /* background + border-color + color injected via inline style */
}

/* ═══════════════════════════════════════════════════
   APEX CHARTS
═══════════════════════════════════════════════════ */

/* Outer card — sits inside the message bubble */
.apex-chart-wrapper {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.07);
  border-radius: 8px;
  padding: 14px 14px 10px;
  margin: 10px 0 4px;
  animation: message-enter 300ms cubic-bezier(0.34, 1.2, 0.64, 1) both;
}

/* Title row above the canvas */
.apex-chart-title {
  font-family: var(--font-display);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 12px;
  padding-left: 2px;
}

/* The div that controls chart height — Chart.js fills it via maintainAspectRatio:false */
.apex-chart-canvas-wrap {
  position: relative;
  height: 260px; /* default for bar and line charts */
  width: 100%;
}

/* ── CHART TYPE SWITCHER ── */
.apex-chart-switcher {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  padding: 8px 2px 2px;
}

.apex-chart-type-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 11px;
  border-radius: 99px;
  background: transparent;
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
  cursor: pointer;
  font-family: var(--font-display);
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  transition: background 140ms ease, border-color 140ms ease, color 140ms ease;
  white-space: nowrap;
}

.apex-chart-type-btn:hover {
  background: rgba(255, 255, 255, 0.05);
  border-color: var(--border-mid);
  color: var(--text-secondary);
}

/* Active pill — purple (intelligence accent) with dot indicator */
.apex-chart-type-btn.is-active {
  background: var(--purple-dim);
  border-color: var(--purple-border);
  color: var(--sector-purple);
  cursor: default;
}

.apex-chart-type-btn.is-active::before {
  content: '';
  display: inline-block;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--sector-purple);
  flex-shrink: 0;
}

[data-theme="light"] .apex-chart-type-btn:hover {
  background: rgba(0, 0, 0, 0.04);
  border-color: rgba(0, 0, 0, 0.15);
}

/* Footer bar below the canvas — holds Save + Share buttons */
.apex-chart-footer {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
  padding: 8px 2px 2px;
}

/* "Save as image" button */
.apex-chart-save-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px 4px 8px;
  border-radius: 5px;
  background: transparent;
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
  cursor: pointer;
  font-family: var(--font-display);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  transition: background 150ms ease, border-color 150ms ease, color 150ms ease;
}

.apex-chart-save-btn:hover {
  background: rgba(255, 255, 255, 0.05);
  border-color: rgba(255, 255, 255, 0.15);
  color: var(--text-secondary);
}

.apex-chart-save-btn.is-saved {
  color: #4CAF50;
  border-color: rgba(76, 175, 80, 0.35);
  background: rgba(76, 175, 80, 0.06);
}

/* Light mode */
[data-theme="light"] .apex-chart-save-btn:hover {
  background: rgba(0, 0, 0, 0.04);
  border-color: rgba(0, 0, 0, 0.15);
}

/* "Share" button — same base as Save, distinct active color */
.apex-chart-share-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px 4px 8px;
  border-radius: 5px;
  background: transparent;
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
  cursor: pointer;
  font-family: var(--font-display);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  transition: background 150ms ease, border-color 150ms ease, color 150ms ease;
}

.apex-chart-share-btn:hover {
  background: rgba(255, 255, 255, 0.05);
  border-color: rgba(255, 255, 255, 0.15);
  color: var(--text-secondary);
}

/* Active feedback — blue for "Shared!" / "Copied!" */
.apex-chart-share-btn.is-shared {
  color: #64B5F6;
  border-color: rgba(100, 181, 246, 0.35);
  background: rgba(100, 181, 246, 0.07);
}

[data-theme="light"] .apex-chart-share-btn:hover {
  background: rgba(0, 0, 0, 0.04);
  border-color: rgba(0, 0, 0, 0.15);
}

[data-theme="light"] .apex-chart-share-btn.is-shared {
  color: #1976D2;
  border-color: rgba(25, 118, 210, 0.3);
  background: rgba(25, 118, 210, 0.05);
}

[data-theme="light"] .msg-copy-btn:hover {
  background: rgba(0, 0, 0, 0.04);
  border-color: rgba(0, 0, 0, 0.15);
}

[data-theme="light"] .msg-feedback-btn:hover,
[data-theme="light"] .msg-pin-btn:hover {
  background: rgba(0, 0, 0, 0.04);
  border-color: rgba(0, 0, 0, 0.12);
}

[data-theme="light"] .msg-regen-btn:hover {
  background: rgba(0, 0, 0, 0.04);
  border-color: rgba(0, 0, 0, 0.15);
}

/* Error block shown when JSON is malformed or Chart.js throws */
.apex-chart-error {
  background: rgba(232, 0, 45, 0.06);
  border: 1px solid rgba(232, 0, 45, 0.18);
  border-left: 2.5px solid var(--red);
  border-radius: 6px;
  padding: 9px 13px;
  font-size: 12.5px;
  color: rgba(232, 80, 80, 0.9);
  font-style: italic;
  margin: 8px 0;
}

/* Light mode */
[data-theme="light"] .apex-chart-wrapper {
  background: rgba(0, 0, 0, 0.03);
  border-color: rgba(0, 0, 0, 0.09);
}

[data-theme="light"] .apex-chart-error {
  background: rgba(232, 0, 45, 0.04);
}

/* ═══════════════════════════════════════════════════
   MOBILE — table + bubble constraints
═══════════════════════════════════════════════════ */
@media (max-width: 768px) {
  .message {
    max-width: 96%;
  }

  /* Compact table cells so tables fit on smaller screens */
  .message--apex .message__bubble table {
    font-size: 12px;
  }

  .message--apex .message__bubble th {
    padding: 6px 9px;
    font-size: 10px;
  }

  .message--apex .message__bubble td {
    padding: 5px 9px;
    white-space: normal; /* Allow cell text to wrap rather than force scroll */
  }

  /* Always show all action buttons on mobile (no hover state on touch) */
  .msg-copy-btn,
  .msg-regen-btn,
  .msg-feedback-btn,
  .msg-pin-btn {
    opacity: 1;
  }
}
