/* ============================================
   MyAI — Custom AI Chat Interface
   Aesthetic: Dark Luxury / Editorial
   ============================================ */

:root {
  --bg-base: #0a0a0f;
  --bg-surface: #111118;
  --bg-elevated: #16161f;
  --bg-hover: #1e1e2a;
  --border: #252535;
  --border-subtle: #1a1a28;

  --text-primary: #f0f0f8;
  --text-secondary: #8888aa;
  --text-muted: #555570;

  --accent: #7c6af7;
  --accent-glow: rgba(124, 106, 247, 0.25);
  --accent-dim: rgba(124, 106, 247, 0.12);
  --accent-hover: #9585ff;

  --user-bubble: #1a1a2e;
  --ai-bubble: transparent;

  --success: #34d399;
  --error: #f87171;

  --sidebar-w: 260px;
  --radius: 14px;
  --radius-sm: 8px;
  --radius-lg: 20px;

  --font-display: 'Syne', sans-serif;
  --font-body: 'DM Sans', sans-serif;

  --transition: 0.18s cubic-bezier(0.4, 0, 0.2, 1);
}

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

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: var(--font-body);
  background: var(--bg-base);
  color: var(--text-primary);
  display: flex;
  min-height: 100vh;
  position: relative;
}

/* Background effect */
body::before {
  content: '';
  position: fixed;
  top: -200px;
  right: -200px;
  width: 600px;
  height: 600px;
  background: radial-gradient(circle, rgba(124, 106, 247, 0.06) 0%, transparent 70%);
  pointer-events: none;
  z-index: 0;
}

/* ============================================
   SIDEBAR
   ============================================ */
.sidebar {
  width: var(--sidebar-w);
  height: 100vh;
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: fixed;
  left: 0;
  top: 0;
  z-index: 100;
  transform: translateX(0);
  transition: transform var(--transition);
}

.sidebar-header {
  padding: 20px 16px 16px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

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

.logo-icon {
  font-size: 22px;
  color: var(--accent);
  line-height: 1;
  filter: drop-shadow(0 0 8px var(--accent-glow));
}

.logo-text {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}

.btn-new-chat {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  background: var(--accent-dim);
  border: 1px solid rgba(124, 106, 247, 0.25);
  border-radius: var(--radius-sm);
  color: var(--accent);
  font-family: var(--font-body);
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  width: 100%;
}

.btn-new-chat:hover {
  background: rgba(124, 106, 247, 0.2);
  border-color: var(--accent);
  color: var(--accent-hover);
}

.sidebar-section {
  flex: 1;
  overflow-y: auto;
  padding: 14px 12px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.sidebar-label {
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 0 4px;
  display: block;
  margin-bottom: 8px;
}

.chat-history {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.history-empty {
  font-size: 13px;
  color: var(--text-muted);
  text-align: center;
  padding: 24px 8px;
  font-style: italic;
}

.history-item {
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: var(--transition);
  border: 1px solid transparent;
  display: flex;
  align-items: center;
  gap: 8px;
}

.history-item:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
  border-color: var(--border-subtle);
}

.history-item.active {
  background: var(--accent-dim);
  color: var(--text-primary);
  border-color: rgba(124, 106, 247, 0.2);
}

.history-item-icon {
  flex-shrink: 0;
  opacity: 0.5;
}

.sidebar-footer {
  padding: 14px 16px;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.btn-settings {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-family: var(--font-body);
  font-size: 13px;
  cursor: pointer;
  transition: var(--transition);
}

.btn-settings:hover {
  border-color: var(--accent);
  color: var(--text-primary);
  background: var(--accent-dim);
}

.version-badge {
  font-size: 11px;
  color: var(--text-muted);
  background: var(--bg-hover);
  padding: 3px 8px;
  border-radius: 99px;
}

/* ============================================
   SIDEBAR TOGGLE (Mobile)
   ============================================ */
.sidebar-toggle {
  display: none;
  position: fixed;
  top: 16px;
  left: 16px;
  z-index: 200;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  cursor: pointer;
  padding: 8px;
  transition: var(--transition);
}

.sidebar-toggle:hover {
  color: var(--text-primary);
  border-color: var(--accent);
}

/* ============================================
   MAIN CONTENT
   ============================================ */
.main {
  flex: 1;
  margin-left: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  height: 100vh;
  position: relative;
  z-index: 1;
  overflow: hidden;
  min-width: 0;
  max-width: 100%;
}

/* ============================================
   CHAT HEADER
   ============================================ */
.chat-header {
  padding: 16px 24px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-base);
  backdrop-filter: blur(10px);
  flex-shrink: 0;
}

.chat-title-area {
  display: flex;
  align-items: center;
  gap: 10px;
}

.chat-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 0 2px rgba(52, 211, 153, 0.2);
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 2px rgba(52, 211, 153, 0.2); }
  50% { box-shadow: 0 0 0 5px rgba(52, 211, 153, 0.05); }
}

.chat-model-name {
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  letter-spacing: 0.02em;
}

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

.btn-clear {
  padding: 8px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: pointer;
  transition: var(--transition);
  display: flex;
  align-items: center;
}

.btn-clear:hover {
  border-color: var(--error);
  color: var(--error);
  background: rgba(248, 113, 113, 0.08);
}

/* ============================================
   MESSAGES AREA
   ============================================ */
.messages-area {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 24px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.messages-area::-webkit-scrollbar {
  width: 4px;
}
.messages-area::-webkit-scrollbar-track { background: transparent; }
.messages-area::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 99px;
}

/* ============================================
   WELCOME SCREEN
   ============================================ */
.welcome-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  min-height: 60vh;
  text-align: center;
  animation: fadeInUp 0.6s ease both;
}

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

.welcome-icon {
  font-size: 52px;
  color: var(--accent);
  margin-bottom: 20px;
  filter: drop-shadow(0 0 20px var(--accent-glow));
  animation: float 3s ease-in-out infinite;
}

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

.welcome-title {
  font-family: var(--font-display);
  font-size: 36px;
  font-weight: 800;
  letter-spacing: -0.04em;
  margin-bottom: 10px;
  background: linear-gradient(135deg, var(--text-primary) 0%, var(--accent) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.welcome-subtitle {
  font-size: 16px;
  color: var(--text-secondary);
  margin-bottom: 36px;
  font-weight: 300;
}

.quick-prompts {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  max-width: 520px;
  width: 100%;
}

.quick-prompt {
  padding: 13px 16px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-family: var(--font-body);
  font-size: 13px;
  text-align: left;
  cursor: pointer;
  transition: var(--transition);
  line-height: 1.4;
}

.quick-prompt:hover {
  background: var(--bg-hover);
  border-color: var(--accent);
  color: var(--text-primary);
  transform: translateY(-1px);
}

/* ============================================
   MESSAGE BUBBLES
   ============================================ */
.message {
  display: flex;
  gap: 14px;
  max-width: 800px;
  width: 100%;
  min-width: 0;
  margin: 0 auto;
  padding: 6px 0;
  animation: msgIn 0.25s ease both;
  overflow: hidden;
}

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

.message.user {
  flex-direction: row-reverse;
}

.msg-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
  font-family: var(--font-display);
  font-weight: 700;
}

.message.user .msg-avatar {
  background: linear-gradient(135deg, var(--accent) 0%, #a78bfa 100%);
  color: white;
}

.message.ai .msg-avatar {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--accent);
  font-size: 16px;
}

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

.msg-sender {
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 0 4px;
}

.message.user .msg-sender {
  text-align: right;
}

.msg-bubble {
  padding: 13px 16px;
  border-radius: var(--radius);
  font-size: 14.5px;
  line-height: 1.7;
  color: var(--text-primary);
  min-width: 0;
  width: 100%;
  overflow-x: hidden;
  word-break: break-word;
  overflow-wrap: break-word;
  box-sizing: border-box;
}

.message.user .msg-bubble {
  background: var(--user-bubble);
  border: 1px solid rgba(124, 106, 247, 0.15);
  border-radius: var(--radius) 4px var(--radius) var(--radius);
}

.message.ai .msg-bubble {
  background: transparent;
  border: none;
  padding-left: 0;
  padding-right: 0;
}

.msg-bubble pre {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  overflow-x: auto;
  margin: 10px 0;
  font-size: 13px;
}

.msg-bubble code {
  font-family: 'Fira Code', 'Cascadia Code', monospace;
  font-size: 0.9em;
  background: var(--bg-elevated);
  padding: 2px 6px;
  border-radius: 4px;
  border: 1px solid var(--border);
}

.msg-bubble pre code {
  background: none;
  border: none;
  padding: 0;
}

.msg-bubble p { margin-bottom: 8px; }
.msg-bubble p:last-child { margin-bottom: 0; }
.msg-bubble ul, .msg-bubble ol { padding-left: 20px; margin: 8px 0; }
.msg-bubble li { margin-bottom: 4px; }
.msg-bubble h1, .msg-bubble h2, .msg-bubble h3 {
  font-family: var(--font-display);
  margin: 12px 0 6px;
  color: var(--text-primary);
}
.msg-bubble strong { color: var(--text-primary); font-weight: 600; }

.msg-bubble hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 14px 0;
  width: 100%;
  max-width: 100%;
  display: block;
  box-sizing: border-box;
}
.msg-bubble em { color: var(--text-secondary); }

/* Typing indicator */
.typing-indicator {
  display: flex;
  gap: 5px;
  align-items: center;
  padding: 14px 0;
}

.typing-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  animation: typingBounce 1.2s ease infinite;
  opacity: 0.6;
}

.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-6px); opacity: 1; }
}

/* ============================================
   INPUT AREA
   ============================================ */
.input-area {
  padding: 16px 24px 20px;
  background: var(--bg-base);
  border-top: 1px solid var(--border-subtle);
  flex-shrink: 0;
}

.input-container {
  max-width: 800px;
  margin: 0 auto;
  display: flex;
  gap: 10px;
  align-items: flex-end;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 10px 10px 16px;
  transition: var(--transition);
}

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

.message-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  font-family: var(--font-body);
  font-size: 14.5px;
  color: var(--text-primary);
  resize: none;
  max-height: 160px;
  line-height: 1.6;
  padding: 2px 0;
}

.message-input::placeholder {
  color: var(--text-muted);
}

.btn-send {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: var(--accent);
  border: none;
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
  flex-shrink: 0;
}

.btn-send:hover:not(:disabled) {
  background: var(--accent-hover);
  transform: scale(1.05);
}

.btn-send:disabled {
  opacity: 0.3;
  cursor: not-allowed;
  transform: none;
}

.input-disclaimer {
  text-align: center;
  font-size: 11.5px;
  color: var(--text-muted);
  margin-top: 10px;
  max-width: 800px;
  margin-left: auto;
  margin-right: auto;
}

/* ============================================
   SETTINGS MODAL
   ============================================ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition);
}

.modal-overlay.open {
  opacity: 1;
  pointer-events: all;
}

.modal {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 520px;
  max-height: 85vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transform: translateY(20px) scale(0.98);
  transition: transform var(--transition);
}

.modal-overlay.open .modal {
  transform: translateY(0) scale(1);
}

.modal-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-title {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
}

.modal-close {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 7px;
  display: flex;
  align-items: center;
  transition: var(--transition);
}

.modal-close:hover {
  border-color: var(--error);
  color: var(--error);
}

.modal-body {
  padding: 20px 24px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 20px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

.settings-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.settings-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  letter-spacing: 0.01em;
}

.api-key-input-wrap {
  display: flex;
  gap: 8px;
}

.settings-input, .settings-select, .settings-textarea {
  width: 100%;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 13.5px;
  transition: var(--transition);
  outline: none;
}

.settings-input:focus, .settings-select:focus, .settings-textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

.settings-textarea {
  resize: vertical;
  min-height: 100px;
  line-height: 1.6;
}

.settings-select {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%238888aa' stroke-width='2.5'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}

.settings-select option {
  background: var(--bg-elevated);
  color: var(--text-primary);
}

.settings-hint {
  font-size: 11.5px;
  color: var(--text-muted);
  line-height: 1.5;
}

.btn-toggle-key {
  padding: 0 12px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  flex-shrink: 0;
  transition: var(--transition);
}

.btn-toggle-key:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.settings-range {
  -webkit-appearance: none;
  width: 100%;
  height: 4px;
  border-radius: 99px;
  background: var(--border);
  outline: none;
  cursor: pointer;
}

.settings-range::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--bg-surface);
  box-shadow: 0 0 0 2px var(--accent-dim);
  cursor: pointer;
}

.btn-primary {
  padding: 10px 20px;
  background: var(--accent);
  border: none;
  border-radius: var(--radius-sm);
  color: white;
  font-family: var(--font-body);
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-secondary {
  padding: 10px 20px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-family: var(--font-body);
  font-size: 13.5px;
  cursor: pointer;
  transition: var(--transition);
}

.btn-secondary:hover {
  border-color: var(--text-secondary);
  color: var(--text-primary);
}

/* ============================================
   TOAST
   ============================================ */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  padding: 12px 18px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  font-weight: 500;
  z-index: 2000;
  opacity: 0;
  transform: translateY(10px);
  transition: all 0.3s ease;
  pointer-events: none;
  max-width: 300px;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.toast.success {
  background: rgba(52, 211, 153, 0.15);
  border: 1px solid rgba(52, 211, 153, 0.3);
  color: var(--success);
}

.toast.error {
  background: rgba(248, 113, 113, 0.15);
  border: 1px solid rgba(248, 113, 113, 0.3);
  color: var(--error);
}

.toast.info {
  background: var(--accent-dim);
  border: 1px solid rgba(124, 106, 247, 0.3);
  color: var(--accent);
}

/* ============================================
   NO API KEY WARNING
   ============================================ */
.api-warning {
  display: flex;
  align-items: center;
  gap: 12px;
  background: rgba(248, 113, 113, 0.08);
  border: 1px solid rgba(248, 113, 113, 0.2);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  margin: 0 auto 16px;
  max-width: 800px;
  width: 100%;
}

.api-warning-text {
  font-size: 13px;
  color: #fca5a5;
  flex: 1;
}

.api-warning-btn {
  padding: 6px 12px;
  background: rgba(248, 113, 113, 0.15);
  border: 1px solid rgba(248, 113, 113, 0.3);
  border-radius: 6px;
  color: var(--error);
  font-size: 12px;
  font-family: var(--font-body);
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: var(--transition);
}

.api-warning-btn:hover {
  background: rgba(248, 113, 113, 0.25);
}

/* ============================================
   RESPONSIVE
   ============================================ */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }

  .sidebar.open {
    transform: translateX(0);
    box-shadow: 4px 0 30px rgba(0, 0, 0, 0.5);
  }

  .sidebar-toggle {
    display: flex;
  }

  .main {
    margin-left: 0;
  }

  .chat-header {
    padding: 14px 16px 14px 52px;
  }

  .messages-area {
    padding: 16px;
  }

  .input-area {
    padding: 12px 16px 16px;
  }

  .welcome-title {
    font-size: 26px;
  }

  .quick-prompts {
    grid-template-columns: 1fr;
  }

  .modal {
    max-height: 90vh;
  }
}

/* Mobile overlay when sidebar open */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 50;
}

.sidebar-overlay.show {
  display: block;
}

/* ============================================
   TANDA SELESAI (Done Indicator)
   ============================================ */
.msg-done-tag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-top: 10px;
  padding: 4px 10px;
  background: rgba(52, 211, 153, 0.08);
  border: 1px solid rgba(52, 211, 153, 0.2);
  border-radius: 99px;
  font-size: 11.5px;
  font-weight: 500;
  color: var(--success);
  letter-spacing: 0.02em;
  animation: fadeInDone 0.4s ease both;
}

.msg-done-icon {
  font-size: 12px;
  font-weight: 700;
}

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

/* ============================================
   FIX: Scroll horizontal & overflow tabel
   ============================================ */
.msg-bubble {
  overflow-x: hidden;
  word-break: break-word;
  overflow-wrap: break-word;
}

.msg-bubble table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  overflow-x: auto;
  display: block;
  white-space: nowrap;
}

.msg-bubble table th,
.msg-bubble table td {
  border: 1px solid var(--border);
  padding: 7px 12px;
  text-align: left;
}

.msg-bubble table th {
  background: var(--bg-elevated);
  font-weight: 600;
  color: var(--text-primary);
}

.msg-bubble table tr:nth-child(even) td {
  background: rgba(255,255,255,0.02);
}



/* ============================================
   MESSAGE FOOTER: Done + Copy Button
   ============================================ */
.msg-footer {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--border-subtle);
}

/* Override old standalone done tag to be inline span */
.msg-footer .msg-done-tag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  background: rgba(52, 211, 153, 0.08);
  border: 1px solid rgba(52, 211, 153, 0.2);
  border-radius: 99px;
  font-size: 11.5px;
  font-weight: 500;
  color: var(--success);
  letter-spacing: 0.02em;
  margin: 0;
  animation: fadeInDone 0.4s ease both;
}

.btn-copy-msg {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 99px;
  color: var(--text-secondary);
  font-family: var(--font-body);
  font-size: 11.5px;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  letter-spacing: 0.02em;
  margin-left: auto;
}

.btn-copy-msg:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-dim);
}

.btn-copy-msg.copied {
  border-color: var(--success);
  color: var(--success);
  background: rgba(52, 211, 153, 0.08);
}

/* ============================================
   FIX: Horizontal rule margin & overflow
   ============================================ */


/* Remove old standalone .msg-done-tag (now inside .msg-footer) */
.msg-content > .msg-done-tag {
  display: none;
}

/* ============================================
   FIX: Table wrap – no horizontal page scroll
   ============================================ */
.table-wrap {
  width: 100%;
  overflow-x: auto;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  margin: 12px 0;
  -webkit-overflow-scrolling: touch;
}

.msg-bubble table {
  width: max-content;
  min-width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  display: table;
  white-space: normal;
}

.msg-bubble table th,
.msg-bubble table td {
  border: none;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  padding: 9px 14px;
  text-align: left;
  white-space: nowrap;
}

.msg-bubble table th:last-child,
.msg-bubble table td:last-child {
  border-right: none;
}

.msg-bubble table tr:last-child td {
  border-bottom: none;
}

.msg-bubble table th {
  background: var(--bg-elevated);
  font-weight: 600;
  color: var(--text-primary);
  font-family: var(--font-display);
  font-size: 12px;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  position: sticky;
  top: 0;
}

.msg-bubble table tr:nth-child(even) td {
  background: rgba(255,255,255,0.015);
}

.msg-bubble table tr:hover td {
  background: var(--bg-hover);
}

/* ============================================
   FIX: Message content spacing
   ============================================ */
.msg-bubble p {
  margin-bottom: 10px;
  line-height: 1.75;
}

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

.msg-bubble h1 { font-size: 1.3em; margin: 18px 0 8px; }
.msg-bubble h2 { font-size: 1.15em; margin: 16px 0 7px; }
.msg-bubble h3 { font-size: 1.05em; margin: 14px 0 6px; }

.msg-bubble ul,
.msg-bubble ol {
  padding-left: 22px;
  margin: 10px 0;
}

.msg-bubble li {
  margin-bottom: 5px;
  line-height: 1.65;
}

.msg-bubble pre {
  margin: 12px 0;
}
