/* ===========================
   Global & Reset
   =========================== */
* { box-sizing: border-box; }

html, body {
  width: 100%;
  max-width: 100%;
  overflow-x: hidden; /* Prevent horizontal scroll */
}

body {
  font-family: system-ui, sans-serif;
}

/* Media defaults to avoid intrinsic overflow */
img, video, canvas, svg, iframe, table {
  max-width: 100%;
  height: auto;
}

/* ===========================
   Scrollbars
   =========================== */
.scrollbar-thin::-webkit-scrollbar { height: 8px; width: 8px; }
.scrollbar-thin::-webkit-scrollbar-thumb { background: #9ca3af; border-radius: 8px; }
.scrollbar-thin::-webkit-scrollbar-track { background: transparent; }

/* ===========================
   Mobile tweaks
   =========================== */
@media (max-width: 640px) {
  .mobile-padding { padding-left: 0.5rem; padding-right: 0.5rem; }
  .mobile-text { font-size: 0.875rem; }
  .mobile-compact { gap: 0.25rem; }
  .mobile-tabs { flex-direction: column; }
  .mobile-tab-btn { flex: none; width: 100%; text-align: center; }

  .code-container { margin: 0.5rem 0; }
  .code-header { padding: 0.25rem 0.5rem; font-size: 0.625rem; }
  .code-content { padding: 0.5rem; font-size: 0.75rem; }
  .copy-btn { padding: 0.125rem 0.25rem; font-size: 0.625rem; }
  .collapse-icon { font-size: 0.625rem; min-width: 0.75rem; }
  .delete-btn { font-size: 0.625rem; padding: 0.125rem 0.25rem; }

  .code-header { padding: 0.5rem; min-height: 2rem; }
  .code-content { padding: 0.5rem; font-size: 0.75rem; min-height: 1.5rem; }
  .copy-btn { min-height: 1.5rem; min-width: 2rem; }
  .delete-btn { min-height: 1.5rem; min-width: 1.5rem; }
}

/* ===========================
   Transcript & bubbles
   =========================== */
.message-wrapper {
  position: relative;
  display: flex;
  gap: .5rem;
  min-width: 0; /* Important for flex shrink */
}

.bubble {
  max-width: 95%;
  border-radius: 1rem;
  padding: .5rem .75rem;
  box-shadow: 0 1px 2px rgba(0,0,0,.05);
  border: 1px solid rgba(0,0,0,.08);
  min-width: 0;
}

@media (min-width: 640px) {
  .bubble { max-width: 85%; }
}

/* Make sure content doesn’t overflow */
.bubble, .bubble * {
  overflow-wrap: anywhere;
  word-break: break-word;
}

/* ===========================
   Code block UI (for chat-rendered <pre><code>)
   =========================== */
.code-container {
  position: relative;
  background: #1f2937;
  border-radius: 0.75rem;
  overflow: hidden;
  margin: 1rem 0;
  max-width: 100%;
}

.code-header {
  background: #374151;
  padding: 0.5rem 1rem;
  font-size: 0.75rem;
  color: #d1d5db;
  border-bottom: 1px solid #4b5563;
  display: flex; justify-content: space-between; align-items: center;
  user-select: none; -webkit-user-select: none; -webkit-tap-highlight-color: transparent;
}

.code-header:hover { background: #4b5563; }

.code-header-left { display: flex; align-items: center; gap: 0.5rem; cursor: pointer; flex: 1; min-width: 0; }
.code-header-right { display: flex; align-items: center; gap: 0.5rem; }

.collapse-icon { transition: transform 0.2s; font-size: 0.75rem; min-width: 1rem; text-align: center; }
.collapse-icon.collapsed { transform: rotate(-90deg); }

.copy-btn, .stitch-btn {
  background: #6b7280; color: white; border: none;
  padding: 0.25rem 0.5rem;
  border-radius: 0.25rem;
  font-size: 0.75rem;
  cursor: pointer;
  transition: background-color 0.2s;
  margin-left: 0.25rem;
}

.copy-btn:hover, .stitch-btn:hover { background: #9ca3af; }
.stitch-btn { background: #059669; }
.stitch-btn:hover { background: #047857; }
.stitch-btn.added { background: #dc2626; }
.stitch-btn.added:hover { background: #b91c1c; }

.code-content {
  padding: 1rem;
  font-family: 'Courier New', monospace;
  font-size: 0.875rem;
  line-height: 1.5;
  color: #e5e7eb;
  transition: max-height 0.3s ease, opacity 0.2s ease;
  min-height: 2rem;
  max-width: 100%;
  overflow-x: auto;
}

/* Collapse behavior */
.code-content.collapsed {
  max-height: 0 !important;
  padding-top: 0;
  padding-bottom: 0;
  opacity: 0;
  overflow: hidden;
}

/* Pre tags should wrap text */
pre, .prose pre {
  white-space: pre-wrap;
  word-break: break-word;
  max-width: 100%;
}

/* ===========================
   Delete buttons
   =========================== */
.message-actions {
  position: absolute;
  top: 0.25rem;
  right: 0.25rem;
  opacity: 0;
  transition: opacity 0.2s;
  z-index: 10;
}
.message-wrapper:hover .message-actions { opacity: 1; }

@media (max-width: 640px) {
  .message-actions { opacity: 0.7; }
  .message-wrapper:active .message-actions { opacity: 1; }
}

.delete-btn {
  background: #ef4444;
  color: white;
  border: none;
  padding: 0.25rem 0.5rem;
  border-radius: 0.25rem;
  font-size: 0.75rem;
  cursor: pointer;
  transition: background-color 0.2s;
}
.delete-btn:hover { background: #dc2626; }

/* ===========================
   Overlays
   =========================== */
#stitcherOverlay > div > div[role="dialog"],
#settingsOverlay  > div > div[role="dialog"] {
  width: 100%;
  max-width: min(100vw, 64rem); /* Fit mobile viewport */
}

/* ===========================
   Debug area
   =========================== */
#debugArea {
  display: block;
  max-width: 100%;
  overflow-x: auto;
}

/* ===========================
   Tables in prose
   =========================== */
.prose table {
  display: block;
  width: 100%;
  overflow-x: auto;
}