/* ===== DM Drawer & Conversation List ===== */
.dm-drawer {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 600;
  background: var(--bg-card, #1a1b2e);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: drawerSlideIn 0.2s ease;
}
@keyframes drawerSlideIn {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}
.dm-drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 599;
}

.chat-reconnect-banner {
  display: none;
  padding: 8px 12px;
  font-size: 12px;
  text-align: center;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(30, 41, 59, 0.9);
  color: rgba(226, 232, 240, 0.95);
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}

.chat-reconnect-banner.is-visible {
  display: flex !important;
}

.chat-reconnect-banner.is-disconnected {
  background: rgba(127, 29, 29, 0.95);
  color: #fecaca;
}

.chat-reconnect-banner.is-reconnecting,
.chat-reconnect-banner.is-retrying {
  background: rgba(51, 65, 85, 0.95);
  color: #e2e8f0;
}

.chat-reconnect-banner.is-offline {
  background: rgba(124, 45, 18, 0.95);
  color: #fed7aa;
}

.chat-reconnect-banner.is-connected {
  background: rgba(6, 78, 59, 0.9);
  color: #bbf7d0;
}

.chat-reconnect-banner.is-recovered {
  background: rgba(4, 120, 87, 0.92);
  color: #d1fae5;
}

.chat-reconnect-banner__text {
  max-width: min(78ch, 100%);
}

.chat-reconnect-banner__action {
  border: 1px solid rgba(255, 255, 255, 0.35);
  background: rgba(15, 23, 42, 0.38);
  color: inherit;
  border-radius: 999px;
  font-size: 11px;
  line-height: 1;
  padding: 5px 10px;
  cursor: pointer;
}

.chat-reconnect-banner__action:hover {
  background: rgba(15, 23, 42, 0.55);
}

.chat-reconnect-banner__action:disabled {
  opacity: 0.65;
  cursor: default;
}

.chat-load-state .empty-state-title {
  margin-bottom: 6px;
}

.chat-load-retry-btn {
  margin-top: 10px;
  border: 1px solid rgba(96, 165, 250, 0.48);
  background: rgba(30, 58, 138, 0.35);
  color: #dbeafe;
  border-radius: 999px;
  font-size: 12px;
  line-height: 1;
  padding: 8px 14px;
  cursor: pointer;
}

.chat-load-retry-btn:hover {
  background: rgba(37, 99, 235, 0.44);
}
.dm-drawer-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border, rgba(255,255,255,0.08));
  flex-shrink: 0;
}
.dm-drawer-title {
  flex: 1;
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary, #e0e0e0);
}
.dm-drawer-close, .dm-new-btn {
  background: rgba(255,255,255,0.08);
  border: none;
  color: var(--text-primary, #ccc);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  font-size: 18px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}
.dm-drawer-close:hover, .dm-new-btn:hover {
  background: rgba(255,255,255,0.15);
}
.dm-drawer-list {
  flex: 1;
  overflow-y: auto;
  padding: 6px 0;
  direction: rtl;
}
.dm-conv-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  cursor: pointer;
  transition: background 0.15s;
  border-bottom: 1px solid rgba(255,255,255,0.04);
  position: relative;
}
.dm-conv-item:hover {
  background: rgba(255,255,255,0.06);
}
.dm-conv-item.active {
  background: rgba(96, 165, 250, 0.12);
  border-right: 3px solid #60a5fa;
}
.dm-conv-item.has-unread .dm-conv-name {
  font-weight: 700;
}
.dm-conv-item.has-unread {
  background: linear-gradient(90deg, rgba(96, 165, 250, 0.14), rgba(96, 165, 250, 0.04));
}
.dm-conv-general.has-unread {
  background: linear-gradient(90deg, rgba(34, 197, 94, 0.14), rgba(34, 197, 94, 0.05));
}
.dm-conv-item.channel-item.has-unread {
  background: linear-gradient(90deg, rgba(167, 139, 250, 0.16), rgba(167, 139, 250, 0.05));
}
.dm-conv-item.has-unread .dm-conv-last-msg {
  color: var(--text-primary, #e0e0e0);
  font-weight: 500;
}
.dm-conv-avatar {
  width: 44px;
  height: 44px;
  min-width: 44px;
  border-radius: 50%;
  background: linear-gradient(135deg, rgba(96,165,250,0.3), rgba(147,51,234,0.3));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}
.dm-conv-general .dm-conv-avatar {
  background: linear-gradient(135deg, rgba(34,197,94,0.3), rgba(16,185,129,0.3));
  font-size: 20px;
}
.dm-conv-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.dm-conv-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary, #e0e0e0);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.dm-conv-last-msg {
  font-size: 13px;
  color: var(--text-secondary, rgba(139,144,160,0.8));
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
  line-height: 1.3;
}
.dm-conv-meta {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
  min-width: 40px;
}
.dm-conv-time {
  font-size: 11px;
  color: var(--text-secondary, rgba(139,144,160,0.7));
  white-space: nowrap;
}
.dm-conv-item.has-unread .dm-conv-time {
  color: #60a5fa;
  font-weight: 600;
}
.dm-conv-badge {
  min-width: 20px;
  height: 20px;
  border-radius: 999px;
  background: #60a5fa;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 6px;
  box-shadow: 0 6px 18px rgba(96, 165, 250, 0.24);
}
.dm-total-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 18px;
  height: 18px;
  border-radius: 999px;
  background: #ef4444;
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 5px;
  border: 2px solid var(--bg-card, #1a1b2e);
}
.dm-new-user-list {
  padding: 8px 12px;
  border-top: 1px solid var(--border, rgba(255,255,255,0.08));
}
.dm-new-header {
  font-size: 13px;
  color: var(--text-secondary, #999);
  margin-bottom: 8px;
  padding: 0 4px;
}
.dm-user-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 8px;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.15s;
}
.dm-user-item:hover {
  background: rgba(255,255,255,0.06);
}
.dm-user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(96,165,250,0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  font-weight: 600;
  color: #93c5fd;
}
.dm-user-name {
  font-size: 14px;
  color: var(--text-primary, #e0e0e0);
}

/* ===== Smart Display Adaptation ===== */
/* Uses --ui-scale from zoom-detect.js to adapt all UI elements */

:root {
  --ui-scale: 1;
}

/* Desktop-only zoom adaptation — mobile has its own responsive rules */
@media (min-width: 769px) {
  #appContainer {
    font-size: calc(14px * var(--ui-scale));
  }
  .header {
    height: calc(56px * var(--ui-scale));
    padding: 0 calc(24px * var(--ui-scale));
  }
  .header h1 {
    font-size: calc(16px * var(--ui-scale));
    gap: calc(8px * var(--ui-scale));
  }
  .sidebar {
    width: calc(250px * var(--ui-scale));
  }
  .sidebar .nav-link {
    font-size: calc(14px * var(--ui-scale));
    padding: calc(12px * var(--ui-scale)) calc(15px * var(--ui-scale));
    gap: calc(10px * var(--ui-scale));
  }
  .sidebar .nav-link i {
    font-size: calc(16px * var(--ui-scale));
    width: calc(20px * var(--ui-scale));
  }
  .message {
    font-size: calc(13px * var(--ui-scale));
    padding: calc(10px * var(--ui-scale)) calc(12px * var(--ui-scale));
  }
  .chat-input {
    font-size: calc(14px * var(--ui-scale)) !important;
  }
  .btn {
    font-size: calc(13px * var(--ui-scale));
    padding: calc(8px * var(--ui-scale)) calc(16px * var(--ui-scale));
  }
}

/* Small screens on DESKTOP: collapse sidebar labels (not mobile — mobile has its own sliding sidebar) */
@media (min-width: 769px) {
  [data-ui-size="xs"] .sidebar .nav-link span,
  [data-ui-size="sm"] .sidebar .nav-link span {
    display: none;
  }

  [data-ui-size="xs"] .sidebar,
  [data-ui-size="sm"] .sidebar {
    width: calc(60px * var(--ui-scale));
  }
}

/* High zoom indicator */
[data-ui-zoom] .header::after {
  content: attr(data-ui-zoom) '% 🔍';
  font-size: 10px;
  opacity: 0.5;
  margin-right: 8px;
}

.editor-toolbar{display:flex;gap:8px;align-items:center;justify-content:center;padding:8px;background:rgba(0,0,0,0.6);border-radius:8px;margin-bottom:8px}
.ed-btn{background:rgba(255,255,255,0.15);border:none;color:#fff;font-size:18px;padding:6px 10px;border-radius:6px;cursor:pointer}
.ed-btn.active{background:rgba(255,255,255,0.35)}
.ed-btn:hover{background:rgba(255,255,255,0.25)}
.ed-color{width:32px;height:32px;border:none;border-radius:6px;cursor:pointer;padding:0;background:none}
.ed-size{background:rgba(255,255,255,0.15);color:#fff;border:1px solid rgba(255,255,255,0.3);border-radius:6px;padding:4px;font-size:13px}
.editor-canvas{z-index:10}

/* Desktop chat polish */
.chat-messages {
  scroll-behavior: smooth;
}

.message {
  transition: box-shadow 0.18s ease, transform 0.18s ease;
}

.message.own,
.message.other {
  padding: 11px 15px 10px;
}

.message.other {
  background: linear-gradient(180deg, rgba(16, 24, 40, 0.98), rgba(12, 18, 32, 0.94));
  border-color: rgba(96, 165, 250, 0.14);
}

.message-content {
  line-height: 1.68;
}

.message.group-last {
  margin-bottom: 2px;
}

.message.message-unread:not(.own) {
  box-shadow: 0 0 0 1px rgba(251, 191, 36, 0.28), 0 10px 22px rgba(15, 23, 42, 0.22);
}

/* Desktop-specific chat height fix for zoom levels */
/* Desktop chat height — pure flex, no pixel calculations */
/* .chat-mode is toggled by JS — no :has() dependency */
@media (min-width: 992px) {
  .main-content.chat-mode {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding: 0;
  }
  .main-content.chat-mode #moduleContent {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
  }
  .main-content.chat-mode .chat-container {
    flex: 1;
    min-height: 0;
    height: auto;
  }
}

.message-sender {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.message-sender-name {
  min-width: 0;
}

.message-time {
  font-size: 9px;
  color: rgba(139, 144, 160, 0.72);
  margin-top: 6px;
  opacity: 0.9;
  letter-spacing: 0.01em;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.message.own .message-time {
  color: rgba(255, 255, 255, 0.64);
}

.read-receipt {
  margin-right: 3px;
  font-size: 10px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  line-height: 1;
  padding: 2px 6px;
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.2);
  background: rgba(255, 255, 255, 0.06);
  font-weight: 700;
}

.read-receipt-count {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.02em;
  opacity: 0.9;
}

.read-receipt-sent {
  color: rgba(255, 255, 255, 0.82);
  border-color: rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.08);
}

.read-receipt-read {
  color: #7dd3fc;
  border-color: rgba(56, 189, 248, 0.35);
  background: rgba(14, 165, 233, 0.16);
  box-shadow: 0 0 0 1px rgba(14, 165, 233, 0.08);
}

.read-receipt .receipt-sent,
.read-receipt .receipt-read {
  letter-spacing: -0.08em;
}

.msg-delivery {
  font-size: 10px;
  line-height: 1;
  padding: 2px 6px;
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.35);
  background: rgba(51, 65, 85, 0.35);
  color: rgba(203, 213, 225, 0.95);
}

.msg-delivery-sending,
.message-delivery-sending .msg-delivery {
  border-color: rgba(125, 211, 252, 0.45);
  color: #bae6fd;
}

.msg-delivery-queued,
.message-delivery-queued .msg-delivery {
  border-color: rgba(250, 204, 21, 0.45);
  color: #fde68a;
}

.msg-delivery-sent,
.message-delivery-sent .msg-delivery {
  border-color: rgba(134, 239, 172, 0.45);
  color: #bbf7d0;
}

.msg-delivery-failed,
.message-delivery-failed .msg-delivery {
  border-color: rgba(248, 113, 113, 0.5);
  color: #fecaca;
  background: rgba(127, 29, 29, 0.32);
}

.msg-retry-btn {
  border: 1px solid rgba(248, 113, 113, 0.55);
  background: rgba(127, 29, 29, 0.36);
  color: #fecaca;
  border-radius: 999px;
  font-size: 10px;
  line-height: 1;
  padding: 3px 8px;
  cursor: pointer;
}

.msg-retry-btn:hover {
  background: rgba(153, 27, 27, 0.48);
}

/* Upload progress circle */
.upload-progress-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 8px;
  padding: 8px 12px;
  background: rgba(30, 41, 59, 0.55);
  border-radius: 10px;
}
.upload-progress-ring {
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  transform: rotate(-90deg);
}
.upload-progress-track {
  fill: none;
  stroke: rgba(148, 163, 184, 0.2);
  stroke-width: 3.5;
}
.upload-progress-fill {
  fill: none;
  stroke: #38bdf8;
  stroke-width: 3.5;
  stroke-linecap: round;
  transition: stroke-dashoffset 0.3s ease;
}
.upload-progress-pct {
  font-size: 13px;
  font-weight: 600;
  color: #e2e8f0;
  font-variant-numeric: tabular-nums;
  min-width: 36px;
}

.lenny-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  line-height: 1;
  filter: drop-shadow(0 2px 4px rgba(14, 165, 233, 0.25));
}

.message.lenny-message.other,
.message[data-user-id="3"].other {
  background: linear-gradient(180deg, rgba(59, 130, 246, 0.14), rgba(59, 130, 246, 0.08));
  border-color: rgba(96, 165, 250, 0.32);
}

.message.lenny-message .message-sender.lenny,
.message[data-user-id="3"] .message-sender.lenny {
  color: #9ec6ff;
}

.reply-quote {
  margin-bottom: 6px;
  padding: 4px 8px;
  border-radius: 7px;
  border-right-width: 2px;
  background: rgba(255, 255, 255, 0.045);
  line-height: 1.3;
}

.reply-quote-user {
  font-size: 9px;
  letter-spacing: 0.01em;
}

.reply-quote-text {
  font-size: 11px;
  max-width: 240px;
}

.reply-preview {
  padding: 6px 16px;
}

.reply-preview-user {
  font-size: 10px;
}

.reply-preview-text {
  font-size: 11px;
}

.chat-image-link {
  display: inline-flex;
  margin-top: 4px;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.28);
  border: 1px solid rgba(255, 255, 255, 0.07);
}

.chat-image-thumb {
  display: block;
  max-width: min(300px, 100%);
  max-height: 220px;
  border-radius: 12px;
  object-fit: cover;
  transition: transform 0.16s ease, filter 0.16s ease;
}

.chat-image-link:hover .chat-image-thumb {
  transform: translateY(-1px);
  filter: brightness(1.05);
}

/* ─── Agent message colors ─── */
.message.agent-message.other {
  background: linear-gradient(180deg, rgba(30, 30, 46, 0.95), rgba(24, 24, 38, 0.95));
  border-color: rgba(120, 120, 160, 0.25);
}

.message.message-streaming {
  position: relative;
  border-style: solid;
  border-color: rgba(96, 165, 250, 0.22);
  box-shadow: 0 8px 20px rgba(2, 6, 23, 0.24);
}

.message.message-streaming.other {
  background: linear-gradient(180deg, rgba(17, 24, 39, 0.98), rgba(11, 17, 31, 0.95));
}

.message.message-streaming::before {
  content: none;
}

.message.message-streaming .message-sender {
  color: rgba(191, 219, 254, 0.98);
}

.message.message-streaming .message-time {
  color: rgba(191, 219, 254, 0.78);
}

.message.message-streaming .message-time:empty {
  display: none;
}

.message.message-streaming .message-content {
  white-space: normal;
  word-break: break-word;
}

.message-stream-state-thinking {
  border-color: rgba(96, 165, 250, 0.24);
}

.message-stream-state-thinking.other {
  background: linear-gradient(180deg, rgba(17, 24, 39, 0.99), rgba(15, 23, 42, 0.96));
}

.message-stream-state-streaming {
  border-color: rgba(125, 211, 252, 0.26);
}

.message-stream-state-streaming.other {
  background: linear-gradient(180deg, rgba(15, 23, 42, 0.98), rgba(17, 24, 39, 0.96));
}

.message-stream-state-finalizing,
.message-stream-state-done {
  border-color: rgba(74, 222, 128, 0.22);
}

.message-stream-state-error {
  border-color: rgba(248, 113, 113, 0.28);
}

.msg-live-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid rgba(125, 211, 252, 0.22);
  background: rgba(15, 23, 42, 0.38);
  color: rgba(191, 219, 254, 0.96);
  font-size: 10px;
  line-height: 1;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.msg-live-badge::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.92;
  animation: blink 1.1s infinite;
}

.msg-live-badge-thinking,
.msg-live-badge-waiting {
  border-color: rgba(96, 165, 250, 0.24);
  color: rgba(191, 219, 254, 0.96);
}

.msg-live-badge-finalizing {
  border-color: rgba(74, 222, 128, 0.24);
  color: rgba(187, 247, 208, 0.98);
}

.msg-live-badge-error {
  border-color: rgba(248, 113, 113, 0.28);
  color: rgba(254, 202, 202, 0.98);
}

.stream-inline-shell {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  min-width: 0;
}

.stream-inline-status {
  --stream-state-color: rgba(191, 219, 254, 0.96);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  align-self: flex-start;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--stream-state-color) 26%, rgba(148, 163, 184, 0.12));
  background: color-mix(in srgb, var(--stream-state-color) 12%, rgba(15, 23, 42, 0.58));
  color: var(--stream-state-color);
  font-size: 10px;
  line-height: 1;
  font-weight: 700;
  letter-spacing: 0.03em;
}

.stream-inline-status-thinking,
.stream-inline-status-queued {
  --stream-state-color: rgba(191, 219, 254, 0.96);
}

.stream-inline-status-typing,
.stream-inline-status-streaming {
  --stream-state-color: rgba(125, 211, 252, 0.98);
}

.stream-inline-status-finalizing,
.stream-inline-status-done {
  --stream-state-color: rgba(187, 247, 208, 0.98);
}

.stream-inline-status-error {
  --stream-state-color: rgba(254, 202, 202, 0.98);
}

.stream-inline-status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
  animation: blink 1.1s infinite;
}

.stream-inline-note {
  color: rgba(148, 163, 184, 0.94);
  font-size: 12px;
  line-height: 1.55;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.stream-inline-text {
  white-space: pre-wrap;
  word-break: break-word;
  min-width: 0;
}

.stream-inline-caret {
  display: inline-block;
  width: 7px;
  height: 1.05em;
  margin-right: 2px;
  border-radius: 2px;
  vertical-align: -2px;
  background: rgba(147, 197, 253, 0.95);
  animation: streamCaretBlink 0.85s steps(1, end) infinite;
}

.message-streaming-settled .stream-inline-caret {
  display: none;
}

.message-streaming-paused .stream-inline-caret,
.message-streaming-paused .stream-inline-status-dot {
  animation-play-state: paused;
  opacity: 0.42;
}

@keyframes streamCaretBlink {
  0%, 48% { opacity: 1; }
  49%, 100% { opacity: 0.1; }
}

.message-sender.agent-dudu { color: #fb923c !important; }
.message-sender.agent-bodek { color: #22d3ee !important; }
.message-sender.agent-shira { color: #f472b6 !important; }
.message-sender.agent-seo { color: #a3e635 !important; }
.message-sender.agent-amit { color: #ff7f50 !important; }

.date-separator {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  margin: 10px 0;
  pointer-events: none;
}

.date-separator::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  height: 1px;
  background: rgba(139, 144, 160, 0.28);
}

.date-separator > span {
  position: relative;
  z-index: 1;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 11px;
  color: rgba(139, 144, 160, 0.9);
  background: var(--bg-secondary);
  border: 1px solid rgba(139, 144, 160, 0.25);
}

.chat-unread-divider {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  margin: 14px 0 10px;
  pointer-events: none;
}

.chat-unread-divider::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  height: 1px;
  background: linear-gradient(90deg, rgba(248, 113, 113, 0), rgba(248, 113, 113, 0.42), rgba(248, 113, 113, 0));
}

.chat-unread-divider > span {
  position: relative;
  z-index: 1;
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: #fecaca;
  background: rgba(69, 10, 10, 0.88);
  border: 1px solid rgba(248, 113, 113, 0.34);
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.22);
}

.scroll-to-bottom-btn {
  position: absolute;
  right: 18px;
  bottom: 88px;
  width: 42px;
  height: 42px;
  border: 1px solid rgba(139, 144, 160, 0.35);
  border-radius: 50%;
  background: rgba(18, 20, 30, 0.88);
  color: var(--text-primary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.28);
  z-index: 470;
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
}

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

.scroll-to-bottom-btn .scroll-to-bottom-icon {
  font-size: 17px;
  line-height: 1;
}

.scroll-to-bottom-badge {
  position: absolute;
  top: -6px;
  left: -6px;
  min-width: 18px;
  height: 18px;
  border-radius: 999px;
  display: none;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 700;
  color: #fff;
  background: #ef4444;
  border: 1px solid rgba(255, 255, 255, 0.5);
  padding: 0 5px;
  box-sizing: border-box;
}

/* ─── Multi-agent streaming bubbles ─── */
.agent-stream-bubble {
  align-self: flex-end;
  max-width: min(68%, 760px);
  margin: 8px 0 2px;
  padding: 12px 14px 10px;
  border-radius: 14px 14px 14px 4px;
  background: linear-gradient(180deg, rgba(14, 16, 22, 0.95), rgba(18, 20, 30, 0.95));
  border: 1px solid rgba(96, 165, 250, 0.24);
  border-left: 3px solid #60a5fa;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.3);
  animation: streamPulse 1.6s ease-in-out infinite;
}

.agent-stream-bubble .bubble-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.agent-stream-bubble .bubble-user {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 600;
}

.agent-stream-bubble .bubble-time {
  font-size: 10px;
  color: rgba(139, 144, 160, 0.8);
}

.agent-stream-bubble .bubble-text {
  color: var(--text-primary);
  font-size: 13px;
  line-height: 1.6;
}

.agent-stream-bubble .stream-indicator {
  font-size: 10px;
  margin-top: 7px;
  letter-spacing: 0.02em;
  animation: blink 1s infinite;
}

/* ─── Per-agent typing indicators ─── */
.agent-typing-container {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 4px 12px 6px;
  direction: rtl;
}

.agent-typing-indicator {
  display: inline-flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  min-width: 192px;
  max-width: min(100%, 320px);
  padding: 10px 12px;
  border-radius: 16px 16px 16px 6px;
  border: 1px solid color-mix(in srgb, var(--agent-typing-accent, #60a5fa) 32%, rgba(148, 163, 184, 0.18));
  border-right: 3px solid var(--agent-typing-accent, #60a5fa);
  background:
    linear-gradient(180deg, rgba(17, 24, 39, 0.96), rgba(12, 18, 32, 0.92)),
    radial-gradient(circle at top right, color-mix(in srgb, var(--agent-typing-accent, #60a5fa) 20%, transparent), transparent 58%);
  box-shadow: 0 14px 30px rgba(0, 0, 0, 0.24);
  animation: fadeIn 0.2s ease;
  box-sizing: border-box;
}

.agent-typing-header {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
}

.agent-typing-name {
  color: rgba(248, 250, 252, 0.98);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.2;
}

.agent-typing-status {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 3px 8px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--agent-typing-accent, #60a5fa) 22%, rgba(15, 23, 42, 0.7));
  color: color-mix(in srgb, var(--agent-typing-accent, #60a5fa) 88%, white);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.agent-typing-body {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
}

.agent-typing-dots {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.agent-typing-indicator .typing-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--agent-typing-accent, #60a5fa);
  animation: typingBounce 1.4s ease-in-out infinite;
}

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

.agent-typing-text {
  color: rgba(203, 213, 225, 0.92);
  font-size: 12px;
  font-weight: 500;
  line-height: 1.45;
}

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

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

/* Legacy lenny-stream-bubble compat */
/* OpenClaw Streaming bubble */
#lenny-stream-bubble {
  align-self: flex-end;
  max-width: min(68%, 760px);
  margin: 8px 0 2px;
  padding: 12px 14px 10px;
  border-radius: 14px 14px 14px 4px;
  background: linear-gradient(180deg, rgba(14, 16, 22, 0.95), rgba(18, 20, 30, 0.95));
  border: 1px solid rgba(96, 165, 250, 0.24);
  border-left: 3px solid #60a5fa;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.3);
}

#lenny-stream-bubble .bubble-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

#lenny-stream-bubble .bubble-user {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: #93c5fd;
  font-size: 11px;
  font-weight: 600;
}

#lenny-stream-bubble .bubble-time {
  font-size: 10px;
  color: rgba(139, 144, 160, 0.8);
}

#lenny-stream-bubble .bubble-text {
  color: var(--text-primary);
  font-size: 13px;
  line-height: 1.6;
}

#lenny-stream-bubble .stream-indicator {
  font-size: 10px;
  color: #7dc2ff;
  margin-top: 7px;
  letter-spacing: 0.02em;
  animation: blink 1s infinite;
}

.chat-bubble.streaming {
  animation: streamPulse 1.6s ease-in-out infinite;
}

@keyframes streamPulse {
  0%, 100% { border-left-color: #4fc3f7; }
  50% { border-left-color: #93c5fd; }
}

/* Dedicated stream/typing zone above composer */
.chat-stream-region {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 10px;
  width: 100%;
  padding: 0 16px 10px;
  box-sizing: border-box;
}

.stream-dock {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
  width: 100%;
  box-sizing: border-box;
}

.chat-stream-region:empty {
  display: none;
}

.stream-dock:empty {
  display: none;
}

.live-activity-feed {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px 13px;
  width: min(100%, 640px);
  background: linear-gradient(180deg, rgba(10, 15, 28, 0.96), rgba(9, 13, 24, 0.92));
  border: 1px solid rgba(96, 165, 250, 0.22);
  border-radius: 18px;
  box-shadow: 0 14px 30px rgba(0, 0, 0, 0.28), inset 0 0 0 1px rgba(148, 163, 184, 0.08);
  backdrop-filter: blur(12px);
  font-family: "Inter", sans-serif;
  position: relative;
  overflow: hidden;
}

.live-activity-feed.is-warning {
  border-color: rgba(251, 191, 36, 0.32);
}

.live-activity-feed.is-error {
  border-color: rgba(248, 113, 113, 0.38);
}

.live-activity-feed.is-done {
  width: min(100%, 560px);
  gap: 6px;
  padding: 11px 12px;
  border-color: rgba(74, 222, 128, 0.36);
  box-shadow: 0 10px 22px rgba(0, 0, 0, 0.2);
}

.live-activity-feed.is-compact {
  width: min(100%, 460px);
  gap: 6px;
  padding: 10px 11px;
}

.live-activity-feed.is-compact .live-activity-body {
  gap: 5px;
}

.live-activity-feed.is-compact .live-activity-current-command,
.live-activity-feed.is-compact .live-activity-current-output,
.live-activity-feed.is-compact .live-activity-log {
  display: none !important;
}

.live-activity-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  padding-bottom: 0;
  border-bottom: none;
}

.live-activity-head-main,
.live-activity-head-meta {
  display: flex;
  align-items: center;
  gap: 8px;
}

.live-activity-head-main {
  flex-wrap: wrap;
}

.live-activity-title {
  font-size: 11px;
  line-height: 1;
  letter-spacing: 0.06em;
  font-weight: 700;
  color: rgba(191, 219, 254, 0.94);
  font-family: "JetBrains Mono", "SFMono-Regular", Consolas, monospace;
}

.live-activity-run-label,
.live-activity-elapsed {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.22);
  background: rgba(15, 23, 42, 0.44);
  color: rgba(226, 232, 240, 0.9);
  padding: 4px 8px;
  font-size: 10px;
  font-weight: 700;
  line-height: 1;
}

.live-activity-run-label {
  color: rgba(148, 163, 184, 0.94);
}

.live-activity-elapsed {
  color: rgba(191, 219, 254, 0.98);
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}

.live-activity-state {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 72px;
  padding: 5px 9px;
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.28);
  background: rgba(15, 23, 42, 0.5);
  color: rgba(226, 232, 240, 0.92);
  font-size: 10px;
  line-height: 1;
  letter-spacing: 0.03em;
  font-weight: 700;
}

.live-activity-state.is-idle {
  border-color: rgba(148, 163, 184, 0.45);
  color: rgba(203, 213, 225, 0.9);
}

.live-activity-state.is-running {
  border-color: rgba(96, 165, 250, 0.7);
  background: rgba(30, 58, 138, 0.35);
  color: rgba(191, 219, 254, 0.98);
}

.live-activity-state.is-warning {
  border-color: rgba(245, 158, 11, 0.7);
  background: rgba(120, 53, 15, 0.34);
  color: rgba(254, 243, 199, 0.98);
}

.live-activity-state.is-error {
  border-color: rgba(248, 113, 113, 0.75);
  background: rgba(127, 29, 29, 0.36);
  color: rgba(254, 202, 202, 0.98);
}

.live-activity-state.is-done {
  border-color: rgba(74, 222, 128, 0.68);
  background: rgba(20, 83, 45, 0.32);
  color: rgba(187, 247, 208, 0.98);
}

.live-activity-body {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.live-activity-primary,
.live-activity-secondary {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  direction: rtl;
  unicode-bidi: plaintext;
  display: -webkit-box;
  -webkit-box-orient: vertical;
}

.live-activity-primary {
  color: rgba(248, 250, 252, 0.98);
  font-size: 13px;
  line-height: 1.45;
  font-weight: 600;
  -webkit-line-clamp: 2;
}

.live-activity-feed.is-done .live-activity-primary {
  font-size: 12px;
  -webkit-line-clamp: 1;
}

.live-activity-primary.is-info {
  color: rgba(191, 219, 254, 0.98);
}

.live-activity-primary.is-success {
  color: rgba(187, 247, 208, 0.98);
}

.live-activity-primary.is-error {
  color: rgba(254, 202, 202, 0.98);
}

.live-activity-primary.is-warn {
  color: rgba(253, 230, 138, 0.98);
}

.live-activity-primary.is-muted {
  color: rgba(203, 213, 225, 0.94);
}

.live-activity-secondary {
  display: none;
  color: rgba(148, 163, 184, 0.9);
  font-size: 11px;
  line-height: 1.35;
  -webkit-line-clamp: 1;
}

.live-activity-secondary.has-content {
  display: -webkit-box;
}

.live-activity-current-command {
  display: none;
}

.live-activity-current-output {
  display: none;
}

.live-activity-current-command-code {
  display: block;
  margin: 0;
  padding: 9px 10px;
  border-radius: 12px;
  border: 1px solid rgba(96, 165, 250, 0.24);
  background: rgba(2, 6, 23, 0.82);
  color: rgba(191, 219, 254, 0.98);
  font-size: 11px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
  direction: ltr;
  font-family: "JetBrains Mono", "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}

.live-activity-current-output-code {
  display: block;
  margin: 0;
  padding: 8px 10px;
  border-radius: 12px;
  border: 1px solid rgba(71, 85, 105, 0.3);
  background: rgba(15, 23, 42, 0.7);
  color: rgba(226, 232, 240, 0.94);
  font-size: 11px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: "JetBrains Mono", "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}

.live-activity-log {
  display: flex;
  flex-direction: column;
  gap: 7px;
  max-height: 180px;
  overflow-y: auto;
  padding-top: 4px;
  border-top: 1px solid rgba(148, 163, 184, 0.1);
}

.live-activity-log-entry {
  display: grid;
  grid-template-columns: 62px minmax(0, 1fr);
  gap: 10px;
  align-items: flex-start;
}

.live-activity-log-time {
  color: rgba(148, 163, 184, 0.75);
  font-size: 10px;
  line-height: 1.4;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  text-align: left;
  direction: ltr;
}

.live-activity-log-main {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.live-activity-log-label-wrap {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  min-width: 0;
}

.live-activity-log-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  min-width: 78px;
  padding: 3px 7px;
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.26);
  background: rgba(15, 23, 42, 0.46);
  color: rgba(226, 232, 240, 0.92);
  font-size: 9px;
  line-height: 1;
  letter-spacing: 0.08em;
  font-weight: 800;
  font-family: "JetBrains Mono", "SFMono-Regular", Consolas, monospace;
}

.live-activity-log-badge.is-command {
  border-color: rgba(96, 165, 250, 0.45);
  color: rgba(191, 219, 254, 0.98);
}

.live-activity-log-badge.is-step {
  border-color: rgba(148, 163, 184, 0.3);
  color: rgba(226, 232, 240, 0.92);
}

.live-activity-log-badge.is-error {
  border-color: rgba(248, 113, 113, 0.44);
  color: rgba(254, 202, 202, 0.98);
}

.live-activity-log-label {
  color: rgba(226, 232, 240, 0.96);
  font-size: 12px;
  line-height: 1.45;
  direction: rtl;
  unicode-bidi: plaintext;
  min-width: 0;
  flex: 1 1 auto;
}

.live-activity-log-entry.is-success .live-activity-log-label {
  color: rgba(187, 247, 208, 0.98);
}

.live-activity-log-entry.is-error .live-activity-log-label {
  color: rgba(254, 202, 202, 0.98);
}

.live-activity-log-entry.is-command .live-activity-log-label,
.live-activity-log-entry.is-info .live-activity-log-label {
  color: rgba(191, 219, 254, 0.98);
}

.live-activity-log-command {
  margin: 0;
  padding: 8px 10px;
  border-radius: 12px;
  border: 1px solid rgba(96, 165, 250, 0.18);
  background: rgba(2, 6, 23, 0.72);
  color: rgba(196, 181, 253, 0.98);
  font-size: 11px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: "JetBrains Mono", "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}

.live-activity-log-prompt {
  display: inline-block;
  margin-left: 6px;
  color: rgba(74, 222, 128, 0.98);
  font-weight: 800;
}

.live-activity-feed.is-done .live-activity-log {
  max-height: 132px;
}

/* ─── Legacy stream chip/dock UI is intentionally hidden in favor of inline message placeholders ─── */
.stream-chip,
#lennyTyping {
  display: none !important;
}

#userTypingIndicator {
  width: auto;
  margin: 0 14px 6px;
  padding: 0 4px 2px;
  border: none;
  background: transparent;
  box-shadow: none;
  color: rgba(148, 163, 184, 0.92);
  gap: 6px;
}

#userTypingIndicator .typing-dot {
  width: 6px;
  height: 6px;
  background: rgba(148, 163, 184, 0.82);
}

#userTypingIndicator .typing-text {
  margin-right: 0;
  color: rgba(148, 163, 184, 0.96);
  font-size: 12px;
  font-weight: 600;
}

.stream-chip.stream-chip-paused {
  opacity: 0.7;
  filter: saturate(0.75);
}

.stream-chip.stream-chip-paused .stream-chip-dot {
  animation-play-state: paused;
}

.agent-typing-indicator.agent-typing-paused {
  opacity: 0.7;
}

.agent-typing-indicator.agent-typing-paused .typing-dot {
  animation-play-state: paused;
}

#lennyTyping.typing-paused {
  opacity: 0.75;
}

#lennyTyping.typing-paused .typing-dot {
  animation-play-state: paused;
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

@media (min-width: 992px) {
  .chat-messages {
    gap: 12px;
    padding: 28px 32px;
  }

  .message {
    max-width: min(62%, 700px);
    box-shadow: 0 8px 18px rgba(0, 0, 0, 0.22);
  }

  .message.own {
    max-width: min(58%, 640px);
    border-radius: 18px 18px 6px 18px;
  }

  .message.other {
    max-width: min(62%, 700px);
    border-radius: 18px 18px 18px 6px;
  }

  .message-sender {
    font-size: 12px;
    margin-bottom: 7px;
  }

  .message-content {
    font-size: 14px;
    line-height: 1.72;
    letter-spacing: 0.004em;
  }

  .message-time {
    margin-top: 8px;
    font-size: 10px;
  }

  .message.is-grouped {
    margin-top: -1px;
  }

  .message.is-grouped .message-sender {
    display: none;
  }
}

@media (max-width: 768px) {
  :root {
    --chat-mobile-safe-bottom: env(safe-area-inset-bottom, 0px);
    --chat-mobile-keyboard-offset: 0px;
    --chat-mobile-input-height: calc(84px + env(safe-area-inset-bottom, 0px));
    --chat-mobile-reply-height: 0px;
    --chat-mobile-dock-height: 0px;
    --chat-mobile-typing-height: 0px;
    --chat-mobile-composer-stack: calc(
      var(--chat-mobile-input-height) +
      var(--chat-mobile-reply-height) +
      var(--chat-mobile-dock-height) +
      var(--chat-mobile-typing-height)
    );
    --chat-mobile-overlay-offset: calc(
      var(--chat-mobile-composer-stack) +
      var(--chat-mobile-keyboard-offset)
    );
  }

  .main-content.chat-mode {
    padding: 0 !important;
    overscroll-behavior: none;
    touch-action: pan-y;
  }

  .chat-container {
    position: relative;
    flex: 1 1 auto;
    min-height: 0;
    height: auto !important;
    border: none;
    border-radius: 0;
    overflow: hidden;
    background: var(--bg-card);
  }

  .chat-header-bar {
    min-height: 48px;
    padding: 6px 10px;
    gap: 8px;
  }

  .chat-header-info {
    min-width: 0;
    gap: 8px;
  }

  .chat-header-title {
    font-size: 14px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .online-indicator {
    display: none;
  }

  .chat-header-btn,
  .chat-search-close,
  .search-nav-btn {
    width: 44px;
    min-width: 44px;
    height: 44px;
    min-height: 44px;
    font-size: 18px;
    border-radius: 12px;
  }

  .chat-search-bar {
    padding: 6px 10px;
    gap: 6px;
  }

  .chat-search-input {
    min-height: 44px;
    font-size: 16px;
    border-radius: 16px;
    padding: 10px 14px;
  }

  .search-counter {
    min-width: 48px;
  }

  .chat-messages {
    flex: 1 1 auto;
    min-height: 0;
    height: auto;
    gap: 8px;
    padding: 10px 10px 0;
    /* Keep the last message fully above the composer even before JS metrics settle */
    padding-bottom: max(calc(var(--chat-mobile-composer-stack) + 18px), 126px);
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: contain;
    scroll-behavior: smooth;
    touch-action: pan-y;
  }

  .message {
    width: fit-content;
    max-width: 84%;
    margin-inline: 6px;
    padding: 11px 14px 10px;
    line-height: 1.62;
    font-size: 15px;
    box-shadow: 0 10px 24px rgba(2, 6, 23, 0.18);
    touch-action: pan-y;
  }

  .message.own {
    border-radius: 16px 16px 6px 16px;
  }

  .message.other {
    border-radius: 16px 16px 16px 6px;
  }

  .message-sender {
    font-size: 12px;
    margin-bottom: 6px;
  }

  .message-content {
    font-size: 15px;
    line-height: 1.66;
    word-break: break-word;
  }

  .message-time {
    font-size: 11px;
    margin-top: 6px;
  }

  .reply-quote {
    padding: 6px 8px;
  }

  /* Prevent native text selection on messages — use our WhatsApp-style long-press instead */
  .message .message-text,
  .message .message-content {
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
  }

  .reply-quote-text {
    max-width: none;
    font-size: 12px;
  }

  .chat-stream-region {
    padding: 0 12px 8px;
  }
  .stream-dock {
    display: flex;
  }
  .stream-chip {
    padding: 8px 10px;
    min-height: 48px;
    max-width: 100%;
    min-width: 0;
  }
  .stream-chip-name { font-size: 11px; }
  .stream-chip-text { font-size: 11px; -webkit-line-clamp: 2; }
  .live-activity-feed {
    padding: 8px 10px;
  }
  .live-activity-feed.is-done {
    width: calc(100% - 24px);
  }
  .live-activity-head { gap: 6px; }
  .live-activity-head-main,
  .live-activity-head-meta { gap: 6px; }
  .live-activity-title { font-size: 10px; letter-spacing: 0.04em; }
  .live-activity-run-label,
  .live-activity-elapsed { font-size: 9px; padding: 4px 7px; }
  .live-activity-state { min-width: 64px; font-size: 9px; padding: 4px 7px; }
  .live-activity-primary { font-size: 12px; }
  .live-activity-secondary { font-size: 10px; }
  .live-activity-log { max-height: 148px; }
  .live-activity-log-entry { grid-template-columns: 54px minmax(0, 1fr); gap: 8px; }
  .live-activity-log-time { font-size: 9px; }
  .live-activity-log-badge { min-width: 68px; font-size: 8px; padding: 3px 6px; }
  .live-activity-log-label-wrap { gap: 6px; }
  .live-activity-log-label,
  .live-activity-log-command { font-size: 10px; }
  .agent-typing-container {
    padding: 0 10px 8px;
  }
  .agent-typing-indicator {
    min-width: 0;
    width: calc(100% - 20px);
    max-width: 100%;
    padding: 10px 12px;
  }
  .agent-typing-name {
    font-size: 11px;
  }
  .agent-typing-status {
    font-size: 9px;
    padding: 2px 7px;
  }
  .agent-typing-text {
    font-size: 11px;
  }
  #lennyTyping {
    display: none !important;
  }
  #userTypingIndicator {
    width: auto;
    margin: 0 10px 6px;
    padding: 0 2px 2px;
  }
  #userTypingIndicator .typing-text {
    font-size: 11px;
  }

  .chat-input-area {
    position: fixed;
    left: 0;
    right: 0;
    bottom: var(--chat-mobile-keyboard-offset);
    z-index: 450;
    display: flex;
    flex-direction: row-reverse;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    padding: 10px 12px;
    padding-left: max(12px, env(safe-area-inset-left, 0px));
    padding-right: max(12px, env(safe-area-inset-right, 0px));
    padding-bottom: calc(10px + var(--chat-mobile-safe-bottom));
    border-top: 1px solid var(--border);
    background: var(--bg-secondary);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    box-shadow: 0 -12px 28px rgba(2, 6, 23, 0.24);
    overflow: visible;
    box-sizing: border-box;
    width: 100%;
    max-width: 100vw;
  }

  .chat-input-area > * {
    flex-shrink: 0;
  }

  .chat-input-area > .chat-input-wrapper {
    flex: 1 1 auto;
    min-width: 0;
    max-width: calc(100% - 60px);
  }

  .chat-send-btn,
  .chat-attach-btn,
  .chat-emoji-btn {
    flex-shrink: 0;
  }

  .chat-input-wrapper {
    flex: 1;
    min-width: 0;
    min-height: 46px;
    padding: 5px 10px;
    border-radius: 24px;
    gap: 6px;
  }

  .chat-input {
    width: 100%;
    min-height: 46px;
    max-height: 36vh;
    font-size: 16px !important;
    line-height: 1.58;
    padding: 10px 12px;
  }

  .chat-send-btn,
  .chat-attach-btn,
  .chat-emoji-btn,
  .voice-cancel-btn,
  .voice-send-btn,
  .reply-preview-close,
  .preview-close-btn,
  .preview-send-btn {
    width: 46px;
    min-width: 46px;
    height: 46px;
    min-height: 46px;
    flex-shrink: 0;
  }

  .reply-preview {
    position: fixed;
    left: 0;
    right: 0;
    bottom: calc(
      var(--chat-mobile-input-height) +
      var(--chat-mobile-keyboard-offset)
    );
    z-index: 451;
    padding: 8px 10px;
    min-height: 48px;
    max-width: 100%;
  }

  .reply-preview-user {
    font-size: 12px;
  }

  .scroll-to-bottom-btn {
    position: fixed;
    right: 10px;
    bottom: calc(var(--chat-mobile-overlay-offset) + 18px);
    width: 40px;
    height: 40px;
    z-index: 560;
    background: rgba(15, 23, 42, 0.88);
    border-color: rgba(148, 163, 184, 0.28);
    box-shadow: 0 10px 24px rgba(2, 6, 23, 0.28);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
  }

  .scroll-to-bottom-badge {
    left: auto;
    right: -4px;
  }

  .date-separator {
    margin: 8px 0;
  }

  .date-separator > span {
    font-size: 12px;
    padding: 3px 12px;
  }

  .reply-preview-text {
    font-size: 12px;
    max-width: 100%;
  }

  .typing-indicator {
    padding: 6px 10px;
    font-size: 12px;
  }

  .emoji-picker {
    position: fixed;
    left: 8px;
    right: 8px;
    bottom: calc(var(--chat-mobile-overlay-offset) + 8px);
    max-width: none;
    border-radius: 14px;
    padding: 10px;
    z-index: 500;
  }

  .emoji-grid {
    grid-template-columns: repeat(8, minmax(0, 1fr));
    gap: 4px;
  }

  .emoji-item {
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    border-radius: 10px;
  }

  .reaction-badge {
    min-height: 44px;
    padding: 8px 10px;
    font-size: 15px;
    gap: 4px;
    border-radius: 16px;
  }

  .reaction-picker-popup {
    position: fixed !important;
    left: 8px !important;
    right: 8px !important;
    bottom: calc(var(--chat-mobile-overlay-offset) + 16px) !important;
    top: auto !important;
    justify-content: center;
    gap: 10px;
    padding: 8px 12px;
    border-radius: 28px;
    z-index: 550;
  }

  .reaction-emoji-option {
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .msg-context-menu {
    min-width: 180px;
    max-width: min(92vw, 300px);
  }

  .msg-context-menu > div {
    min-height: 44px;
    font-size: 14px;
    padding: 10px 14px;
  }

  .chat-image-link,
  .chat-video-msg {
    display: block;
    width: 100%;
    max-width: 100%;
  }

  .chat-image-thumb {
    display: block;
    width: min(100%, 360px);
    max-width: 100%;
    max-height: 44vh;
    height: auto;
    object-fit: contain;
    border-radius: 10px;
  }

  .chat-video-msg video {
    width: 100%;
    max-width: 100%;
    max-height: 44vh;
    height: auto;
    border-radius: 10px !important;
  }

  .chat-audio-msg {
    width: 100%;
    min-width: 0;
    max-width: 100%;
  }

  .audio-custom-player {
    min-height: 44px;
  }

  .audio-progress-wrap {
    height: 8px;
  }

  .attach-menu {
    gap: 12px;
    padding: 10px 12px calc(14px + var(--chat-mobile-safe-bottom));
    border-radius: 16px 16px 0 0;
  }

  .attach-menu-handle {
    width: 40px;
    height: 4px;
  }

  .attach-menu-title {
    font-size: 15px;
  }

  .attach-menu-primary-row,
  .attach-menu-secondary-row {
    gap: 4px;
  }

  .attach-menu-item {
    min-height: 64px;
    padding: 8px 4px;
    gap: 6px;
  }

  .attach-menu-item span {
    font-size: 12px;
  }

  .attach-menu-icon {
    width: 62px;
    height: 62px;
    font-size: 28px;
  }

  .attach-menu-item--secondary .attach-menu-icon {
    width: 50px;
    height: 50px;
    font-size: 23px;
  }

  .voice-record-bar {
    min-height: 56px;
    padding: 8px 12px;
    gap: 10px;
    border-radius: 22px;
  }

  .voice-timer {
    font-size: 16px;
  }

  .image-preview-overlay {
    padding-top: max(env(safe-area-inset-top, 0px), 4px);
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }

  .preview-header {
    padding: 8px 10px;
  }

  .preview-title {
    font-size: 15px;
  }

  .preview-main {
    padding: 4px;
  }

  .preview-main-img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
  }

  .preview-thumbs {
    justify-content: flex-start;
    padding: 8px 10px;
    gap: 8px;
    -webkit-overflow-scrolling: touch;
  }

  .preview-thumb {
    width: 64px;
    height: 64px;
    min-width: 64px;
  }

  .preview-bottom {
    gap: 8px;
    padding: 8px 10px calc(10px + var(--chat-mobile-safe-bottom));
  }

  .preview-caption {
    min-height: 44px;
    font-size: 16px;
  }

  .editor-toolbar {
    flex-wrap: wrap;
    justify-content: flex-start;
    gap: 8px;
    padding: 8px;
  }

  .ed-btn,
  .ed-color {
    min-width: 44px;
    min-height: 44px;
  }

  .ed-btn {
    padding: 0 10px;
  }

  .ed-size {
    min-height: 44px;
    font-size: 14px;
    padding: 0 8px;
  }

  .editor-canvas {
    touch-action: none;
  }

  .message.swiping-reply {
    transition: transform 0.05s linear;
  }

  .message.reply-swipe-hit {
    animation: replySwipePulse 0.25s ease;
  }

  @keyframes replySwipePulse {
    from { transform: scale(1); }
    to { transform: scale(1.01); }
  }

  .dm-conv-item {
    padding: 13px 14px;
  }

  .dm-conv-badge,
  .channel-section-total,
  .dm-total-badge {
    min-width: 22px;
    height: 22px;
    font-size: 11px;
  }

  .message-time {
    gap: 8px;
    font-size: 10px;
  }

  .read-receipt {
    font-size: 12px;
    min-height: 22px;
    padding: 3px 8px;
    gap: 4px;
    border-width: 1px;
  }

  .read-receipt-count {
    font-size: 10px;
  }

  .read-receipt .receipt-sent,
  .read-receipt .receipt-read {
    font-weight: 800;
  }
}

/* ─── WhatsApp-style mobile message selection ─── */
.msg-selected {
  background: rgba(0, 150, 136, 0.15) !important;
  border-radius: 8px;
  transition: background 0.2s ease;
}

/* Keep text non-selectable even when message is selected (use "Select Text" dialog instead) */
.msg-selected .message-text,
.msg-selected .message-content {
  -webkit-user-select: none !important;
  user-select: none !important;
  -webkit-touch-callout: none !important;
}

/* Text selection dialog */
.text-select-dialog-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: dialogFadeIn 0.1s ease;
}
@keyframes dialogFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* Image lightbox */
.chat-lightbox-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.95);
  z-index: 3000;
  display: flex;
  flex-direction: column;
  animation: dialogFadeIn 0.15s ease;
}
.chat-lightbox-header {
  display: flex;
  justify-content: flex-end;
  padding: 12px 16px;
  flex-shrink: 0;
}
.chat-lightbox-close {
  background: rgba(255,255,255,0.15);
  border: none;
  color: #fff;
  font-size: 28px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* WhatsApp-style image send screen */
.image-preview-overlay {
  position: fixed;
  inset: 0;
  z-index: 3200;
  display: flex;
  flex-direction: column;
  direction: rtl;
  background:
    radial-gradient(circle at top, rgba(40, 40, 40, 0.45), rgba(6, 6, 6, 0.92)),
    linear-gradient(180deg, rgba(10, 10, 10, 0.98), rgba(0, 0, 0, 0.98));
  color: var(--text-primary);
  animation: previewOverlayIn 0.2s ease;
}

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

.preview-header {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 56px;
  padding: max(env(safe-area-inset-top, 0px), 8px) 16px 8px;
  flex-shrink: 0;
}

.preview-title {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: #fff;
}

.preview-close-btn {
  position: absolute;
  right: 12px;
  top: calc(max(env(safe-area-inset-top, 0px), 0px) + 8px);
  width: 42px;
  height: 42px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  font-size: 24px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.2s ease, transform 0.2s ease;
}

.preview-close-btn:active {
  transform: scale(0.96);
  background: rgba(255, 255, 255, 0.16);
}

.preview-edit-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  flex-shrink: 0;
}

/* ── quality row: don't let it shrink away ── */
.preview-quality-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 12px;
  flex-shrink: 0;
}

.preview-quality-row label {
  color: rgba(255, 255, 255, 0.7);
  font-size: 14px;
  white-space: nowrap;
}

.preview-quality-select {
  height: 38px;
  min-width: 108px;
  padding: 0 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  font-size: 14px;
  outline: none;
}

.preview-quality-select option {
  color: #111;
}

.preview-tool-btn {
  width: 38px;
  height: 38px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  font-size: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease, transform 0.2s ease;
}

.preview-tool-btn.active {
  background: rgba(37, 211, 102, 0.22);
  border-color: rgba(37, 211, 102, 0.55);
}

.preview-tool-btn:active {
  transform: scale(0.96);
}

.preview-tool-text {
  font-size: 18px;
  font-weight: 700;
  font-family: inherit;
}

/* ── preview-main-wrap: must flex-shrink so preview-bottom stays visible ── */
.preview-main-wrap {
  flex: 1 1 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.preview-main {
  position: relative;
  flex: 1 1 0;
  min-height: 0;
  margin: 0 8px;
  border-radius: 14px;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.preview-main-img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.image-preview-overlay .editor-toolbar {
  display: none !important;
}

.image-preview-overlay .editor-canvas {
  z-index: 2;
  border-radius: 12px;
}

.preview-thumbs {
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  flex-shrink: 0;
}

.preview-thumb {
  width: 62px;
  height: 62px;
  min-width: 62px;
  border-radius: 10px;
  object-fit: cover;
  border: 2px solid transparent;
  transition: border-color 0.2s ease, transform 0.2s ease;
  cursor: pointer;
}

.preview-thumb.active {
  border-color: #25D366;
  transform: translateY(-1px);
}

.preview-thumb.add-more {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  line-height: 1;
  color: #fff;
  background: rgba(255, 255, 255, 0.14);
}

.preview-bottom {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px calc(10px + var(--chat-mobile-safe-bottom));
  background: rgba(7, 7, 7, 0.86);
  border-top: 1px solid rgba(255, 255, 255, 0.07);
  flex-shrink: 0;
}

.preview-caption {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 44px;
  border-radius: 24px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-primary);
  padding: 0 16px;
  font-size: 16px;
  outline: none;
}

.preview-caption::placeholder {
  color: rgba(255, 255, 255, 0.45);
}

.preview-send-btn {
  width: 48px;
  height: 48px;
  border: none;
  border-radius: 50%;
  background: #25D366;
  color: #fff;
  font-size: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  box-shadow: 0 6px 16px rgba(37, 211, 102, 0.36);
  transition: transform 0.2s ease, filter 0.2s ease;
}

.preview-send-btn:disabled {
  opacity: 0.7;
  cursor: default;
  box-shadow: none;
}

.preview-send-btn:active {
  transform: scale(0.95);
  filter: brightness(0.95);
}

@media (min-width: 768px) {
  .preview-main {
    margin: 6px 16px;
  }
  .preview-thumbs {
    padding: 12px 18px;
  }
  .preview-bottom {
    padding: 12px 16px calc(12px + var(--chat-mobile-safe-bottom));
  }
}

/* --- Composer stability patch (typing line) --- */
.chat-input-area {
  align-items: flex-end;
}

.chat-input-wrapper {
  display: flex;
  align-items: flex-end;
  min-height: 46px;
  padding: 6px 10px;
  box-sizing: border-box;
}

.chat-input-wrapper .chat-input {
  flex: 1 1 auto;
  width: 100%;
  min-width: 0;
  margin: 0;
  min-height: 30px;
  max-height: 140px;
  padding: 8px 10px;
  line-height: 1.45;
  box-sizing: border-box;
}

@media (max-width: 768px) {
  .chat-input-area {
    align-items: center;
  }

  .chat-input-wrapper {
    min-height: 44px;
    padding: 4px 8px;
  }

  .chat-input-wrapper .chat-input {
    min-height: 44px;
    padding: 9px 10px;
  }
}

.chat-lightbox-body {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
  min-height: 0;
}
.chat-lightbox-img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 4px;
}
.text-select-dialog {
  background: var(--bg-card, #1e1e2e);
  border-radius: 16px;
  max-width: 90vw;
  max-height: 60vh;
  overflow-y: auto;
  padding: 20px;
  color: var(--text-primary, #e0e0e0);
  font-size: 16px;
  line-height: 1.6;
  -webkit-user-select: text;
  user-select: text;
  -webkit-touch-callout: default;
  direction: rtl;
}
.text-select-dialog-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  font-size: 14px;
  color: var(--text-secondary, #999);
}
.text-select-dialog-close {
  background: transparent;
  border: none;
  color: var(--text-secondary, #999);
  font-size: 20px;
  cursor: pointer;
  padding: 4px 8px;
}
.text-select-dialog-textarea {
  width: 100%;
  min-height: 60px;
  max-height: 50vh;
  background: var(--bg-input, #2a2a3e);
  color: var(--text-primary, #e0e0e0);
  border: 1px solid var(--border, #444);
  border-radius: 8px;
  padding: 12px;
  font-size: 16px;
  line-height: 1.6;
  font-family: inherit;
  direction: rtl;
  resize: none;
  outline: none;
  -webkit-user-select: text;
  user-select: text;
}

.text-select-dialog-content {
  -webkit-user-select: text;
  user-select: text;
  -webkit-touch-callout: none;
}

.text-select-dialog-actions {
  display: flex;
  gap: 8px;
  padding: 12px 0 0;
  direction: rtl;
}

.text-select-dialog-btn {
  flex: 1;
  padding: 10px 16px;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.text-select-dialog-btn.copy-all-btn {
  background: #075e54;
  color: #fff;
}

.text-select-dialog-btn.copy-selected-btn {
  background: var(--bg-input, #2a2a3e);
  color: var(--text-primary, #e0e0e0);
  border: 1px solid var(--border, #444);
}

.msg-action-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #075e54;
  color: #fff;
  padding: 8px 12px;
  z-index: 1000;
  direction: rtl;
  gap: 8px;
  min-height: 48px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

.msg-action-bar .action-bar-actions {
  display: flex;
  gap: 4px;
  align-items: center;
}

.msg-action-bar .action-bar-btn {
  background: none;
  border: none;
  color: #fff;
  font-size: 14px;
  padding: 8px 12px;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: inherit;
  white-space: nowrap;
}

.msg-action-bar .action-bar-btn:active {
  background: rgba(255,255,255,0.2);
}

.msg-action-bar .action-bar-close {
  font-size: 18px;
  padding: 8px;
}

.msg-action-bar .action-bar-delete {
  color: #ff6b6b;
}

/* ─── Thinking bubble (shows reasoning/thinking stream) ─── */
.agent-thinking-bubble {
  align-self: flex-end;
  max-width: min(68%, 760px);
  margin: 8px 0 2px;
  padding: 10px 14px 8px;
  border-radius: 14px 14px 14px 4px;
  background: linear-gradient(180deg, rgba(30, 20, 40, 0.85), rgba(25, 18, 35, 0.85));
  border: 1px dashed rgba(168, 130, 255, 0.3);
  border-left: 3px dashed rgba(168, 130, 255, 0.5);
  opacity: 0.75;
  animation: thinkPulse 2s ease-in-out infinite;
}
.agent-thinking-bubble .thinking-header {
  margin-bottom: 6px;
}
.agent-thinking-bubble .thinking-label {
  font-size: 11px;
  font-weight: 600;
}
.agent-thinking-bubble .thinking-text {
  color: rgba(200, 180, 255, 0.7);
  font-size: 12px;
  line-height: 1.5;
  max-height: 120px;
  overflow: hidden;
  font-style: italic;
  word-break: break-word;
}
@keyframes thinkPulse {
  0%, 100% { opacity: 0.6; }
  50% { opacity: 0.85; }
}

/* Inline code in messages */
.inline-code {
  background: rgba(255,255,255,0.08);
  padding: 1px 5px;
  border-radius: 4px;
  font-family: 'Courier New', monospace;
  font-size: 0.9em;
  direction: ltr;
  unicode-bidi: embed;
}

/* ─── Image Editor: Crop ratios & Draw controls ─── */
.preview-mode-controls {
  padding: 4px 12px;
  min-height: 42px;
}
.preview-crop-ratios, .preview-draw-controls {
  display: none;
  gap: 8px;
  align-items: center;
  padding: 6px 0;
}
.preview-crop-ratios.active, .preview-draw-controls.active {
  display: flex;
}
.preview-ratio-btn {
  height: 34px;
  padding: 0 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.06);
  color: #ccc;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s;
}
.preview-ratio-btn.active {
  background: rgba(37,211,102,0.2);
  border-color: rgba(37,211,102,0.5);
  color: #25d366;
}
.preview-color-row {
  display: flex;
  gap: 8px;
  align-items: center;
}
.preview-color-dot {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.15s;
}
.preview-color-dot.active {
  border-color: #fff;
  transform: scale(1.15);
}
.preview-brush-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-right: 12px;
}
.preview-brush-size {
  width: 80px;
  accent-color: #25d366;
}
.preview-brush-value {
  color: #888;
  font-size: 12px;
  min-width: 20px;
}
.preview-undo-btn {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.06);
  color: #ccc;
  font-size: 16px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* ===== Chat Workspace Overhaul ===== */
body.chat-mode-active {
  --chat-shell-border: rgba(148, 163, 184, 0.14);
  --chat-shell-shadow: 0 34px 84px rgba(2, 6, 23, 0.52);
  --chat-panel-bg: rgba(8, 11, 18, 0.88);
  --chat-panel-border: rgba(148, 163, 184, 0.14);
  --chat-panel-highlight: rgba(96, 165, 250, 0.12);
  --chat-agent-bg: linear-gradient(180deg, rgba(15, 23, 42, 0.88), rgba(8, 12, 24, 0.96));
  --chat-agent-border: rgba(96, 165, 250, 0.18);
  --chat-user-bg: linear-gradient(135deg, #2563eb 0%, #1d4ed8 48%, #1e3a8a 100%);
  --chat-user-border: rgba(147, 197, 253, 0.26);
  background:
    radial-gradient(circle at 12% 0%, rgba(37, 99, 235, 0.16), transparent 34%),
    radial-gradient(circle at 88% 18%, rgba(16, 185, 129, 0.12), transparent 26%),
    linear-gradient(180deg, #05070d 0%, #070b12 54%, #05070b 100%);
}

body.chat-mode-active #appContainer {
  background: transparent;
}

body.chat-mode-active .chat-container,
body.chat-mode-active .chat-header-bar,
body.chat-mode-active .chat-search-bar,
body.chat-mode-active .chat-messages,
body.chat-mode-active .chat-stream-region,
body.chat-mode-active .reply-preview,
body.chat-mode-active .chat-input-area,
body.chat-mode-active .scroll-to-bottom-btn,
body.chat-mode-active .chat-reconnect-banner,
body.chat-mode-active .typing-indicator {
  position: relative;
  z-index: 1;
}

body.chat-mode-active .message-content pre,
body.chat-mode-active .message-content code {
  font-family: var(--font-mono);
}

body.chat-mode-active .message-content pre {
  margin-top: 12px;
  padding: 14px 16px;
  border-radius: 18px;
  background: rgba(2, 6, 23, 0.72);
  border: 1px solid rgba(148, 163, 184, 0.16);
  overflow: auto;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

body.chat-mode-active .message-content code {
  background: rgba(148, 163, 184, 0.12);
  border-radius: 8px;
  padding: 2px 6px;
  font-size: 0.92em;
}

body.chat-mode-active .message-content pre code {
  background: transparent;
  border-radius: 0;
  padding: 0;
}

body.chat-mode-active .dm-drawer {
  background: linear-gradient(180deg, rgba(9, 13, 22, 0.98), rgba(6, 9, 16, 0.98));
  border-left: 1px solid rgba(148, 163, 184, 0.12);
  box-shadow: -22px 0 40px rgba(2, 6, 23, 0.34);
}

body.chat-mode-active .dm-drawer-backdrop {
  background: rgba(2, 6, 23, 0.58);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

@media (min-width: 992px) {
  body.chat-mode-active .main-container {
    gap: 18px;
    padding: 18px 20px 20px;
    background: transparent;
  }

  body.chat-mode-active .sidebar {
    position: relative;
    width: 216px;
    border: 1px solid rgba(148, 163, 184, 0.12);
    border-radius: 28px;
    background: linear-gradient(180deg, rgba(10, 14, 24, 0.98), rgba(7, 10, 16, 0.98));
    box-shadow: 0 24px 60px rgba(2, 6, 23, 0.42);
    overflow: hidden;
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
  }

  body.chat-mode-active .sidebar::before {
    content: 'SHOPLINE HQ';
    padding: 24px 24px 18px;
    border-bottom: 1px solid rgba(148, 163, 184, 0.08);
    color: #dbeafe;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.14em;
    font-family: var(--font-mono);
  }

  body.chat-mode-active .sidebar::after {
    top: 31px;
    right: 26px;
    width: 8px;
    height: 8px;
    background: #38bdf8;
    box-shadow: 0 0 0 6px rgba(56, 189, 248, 0.12);
  }

  body.chat-mode-active .nav-menu {
    padding: 16px 14px 18px;
    display: flex;
    flex-direction: column;
    gap: 6px;
  }

  body.chat-mode-active .nav-menu li {
    margin-bottom: 0;
  }

  body.chat-mode-active .nav-link {
    min-height: 48px;
    padding: 0 14px;
    border-radius: 16px;
    color: rgba(226, 232, 240, 0.74);
    font-weight: 600;
  }

  body.chat-mode-active .nav-link i {
    font-size: 16px;
    opacity: 0.75;
  }

  body.chat-mode-active .nav-link:hover {
    background: rgba(15, 23, 42, 0.72);
    color: #f8fafc;
  }

  body.chat-mode-active .nav-link.active {
    border-right: none;
    color: #eff6ff;
    background: linear-gradient(135deg, rgba(37, 99, 235, 0.28), rgba(30, 41, 59, 0.92));
    box-shadow: inset 0 0 0 1px rgba(147, 197, 253, 0.14), 0 16px 32px rgba(2, 6, 23, 0.3);
  }

  body.chat-mode-active .main-content.chat-mode {
    max-width: none;
    margin: 0;
    padding: 18px 0 18px 18px;
    background: transparent;
  }

  body.chat-mode-active .chat-container {
    border: 1px solid var(--chat-shell-border);
    border-radius: 32px;
    background:
      linear-gradient(180deg, rgba(11, 16, 28, 0.98), rgba(8, 11, 19, 0.97)),
      linear-gradient(135deg, rgba(59, 130, 246, 0.06), transparent 32%);
    box-shadow: var(--chat-shell-shadow);
    backdrop-filter: blur(22px);
    -webkit-backdrop-filter: blur(22px);
    isolation: isolate;
  }

  body.chat-mode-active .chat-container::before {
    content: "";
    position: absolute;
    inset: 0;
    background:
      radial-gradient(circle at 16% 0%, rgba(59, 130, 246, 0.12), transparent 26%),
      radial-gradient(circle at 84% 12%, rgba(16, 185, 129, 0.08), transparent 22%);
    opacity: 0.95;
    pointer-events: none;
    z-index: 0;
  }

  body.chat-mode-active .chat-header-bar {
    min-height: 88px;
    padding: 22px 28px 18px;
    gap: 14px;
    background: linear-gradient(180deg, rgba(11, 16, 27, 0.96), rgba(11, 16, 27, 0.76));
    border-bottom: 1px solid rgba(148, 163, 184, 0.08);
  }

  body.chat-mode-active .chat-header-avatar {
    width: 48px;
    height: 48px;
    min-width: 48px;
    border-radius: 16px;
    background: linear-gradient(135deg, #3b82f6, #0f172a 120%);
    border: 1px solid rgba(191, 219, 254, 0.22);
    box-shadow: 0 14px 28px rgba(37, 99, 235, 0.22);
    font-size: 15px;
  }

  body.chat-mode-active .chat-header-info {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 5px;
  }

  body.chat-mode-active .chat-header-title {
    font-size: 18px;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: #f8fafc;
  }

  body.chat-mode-active .online-indicator {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: 999px;
    border: 1px solid rgba(74, 222, 128, 0.14);
    background: rgba(5, 46, 22, 0.44);
    color: #bbf7d0;
    font-size: 11px;
    line-height: 1;
    font-family: var(--font-mono);
    letter-spacing: 0.03em;
  }

  body.chat-mode-active .chat-header-btn,
  body.chat-mode-active .chat-search-close,
  body.chat-mode-active .search-nav-btn {
    width: 44px;
    height: 44px;
    border-radius: 16px;
    border: 1px solid rgba(148, 163, 184, 0.12);
    background: rgba(15, 23, 42, 0.7);
    color: #cbd5e1;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.03);
  }

  body.chat-mode-active .chat-header-btn:hover,
  body.chat-mode-active .chat-search-close:hover,
  body.chat-mode-active .search-nav-btn:hover {
    background: rgba(30, 41, 59, 0.95);
    color: #fff;
    transform: translateY(-1px);
  }

  body.chat-mode-active .chat-search-bar {
    padding: 0 28px 18px;
    gap: 8px;
    background: linear-gradient(180deg, rgba(11, 16, 27, 0.76), rgba(11, 16, 27, 0));
  }

  body.chat-mode-active .chat-search-input {
    min-height: 48px;
    border-radius: 18px;
    background: rgba(8, 11, 18, 0.84);
    border: 1px solid rgba(148, 163, 184, 0.12);
    color: #e2e8f0;
  }

  body.chat-mode-active .chat-messages {
    gap: 16px;
    padding: 34px clamp(28px, 4vw, 56px) 28px;
    background:
      linear-gradient(rgba(148, 163, 184, 0.028) 1px, transparent 1px),
      linear-gradient(90deg, rgba(148, 163, 184, 0.024) 1px, transparent 1px),
      linear-gradient(180deg, rgba(8, 12, 21, 0.72), rgba(6, 10, 17, 0.28));
    background-size: 100% 34px, 34px 100%, 100% 100%;
    background-position: center top;
    scrollbar-color: rgba(148, 163, 184, 0.28) transparent;
  }

  body.chat-mode-active .empty-state {
    min-height: 52vh !important;
    border-radius: 28px;
    border: 1px dashed rgba(96, 165, 250, 0.2);
    background: linear-gradient(180deg, rgba(15, 23, 42, 0.62), rgba(8, 12, 21, 0.22));
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.03);
  }

  body.chat-mode-active .empty-state-icon {
    width: 72px;
    height: 72px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 22px;
    background: rgba(37, 99, 235, 0.12);
    border: 1px solid rgba(96, 165, 250, 0.18);
  }

  body.chat-mode-active .date-separator {
    margin: 2px 0 8px;
  }

  body.chat-mode-active .date-separator > span {
    padding: 5px 12px;
    background: rgba(8, 11, 18, 0.92);
    border-color: rgba(148, 163, 184, 0.14);
    font-family: var(--font-mono);
    letter-spacing: 0.03em;
  }

  body.chat-mode-active .message {
    max-width: min(70%, 840px);
    padding: 18px 20px 16px;
    border: 1px solid rgba(148, 163, 184, 0.12);
    border-radius: 26px;
    box-shadow: 0 18px 44px rgba(2, 6, 23, 0.28);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
  }

  body.chat-mode-active .message.own {
    max-width: min(58%, 640px);
    background: var(--chat-user-bg);
    border-color: var(--chat-user-border);
    border-radius: 26px 26px 12px 26px;
    box-shadow: 0 22px 40px rgba(29, 78, 216, 0.28);
  }

  body.chat-mode-active .message.own .message-sender {
    display: none;
  }

  body.chat-mode-active .message.other {
    background: linear-gradient(180deg, rgba(15, 20, 34, 0.88), rgba(9, 13, 22, 0.96));
    border-color: rgba(148, 163, 184, 0.12);
    border-radius: 26px 26px 26px 12px;
  }

  body.chat-mode-active .message.agent-message.other,
  body.chat-mode-active .message.lenny-message.other,
  body.chat-mode-active .message[data-user-id="3"].other {
    max-width: min(74%, 900px);
    background: var(--chat-agent-bg);
    border-color: var(--chat-agent-border);
    box-shadow: 0 24px 54px rgba(2, 6, 23, 0.3);
  }

  body.chat-mode-active .message.message-streaming.other {
    border-color: rgba(96, 165, 250, 0.26);
    box-shadow: 0 24px 56px rgba(15, 23, 42, 0.38);
  }

  body.chat-mode-active .message-sender {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    width: fit-content;
    margin-bottom: 10px;
    padding: 5px 10px;
    border-radius: 999px;
    border: 1px solid rgba(148, 163, 184, 0.1);
    background: rgba(15, 23, 42, 0.56);
    font-size: 11px;
    line-height: 1;
    font-weight: 700;
    letter-spacing: 0.03em;
    font-family: var(--font-mono);
  }

  body.chat-mode-active .message-content {
    font-size: 15px;
    line-height: 1.78;
    letter-spacing: 0.002em;
  }

  body.chat-mode-active .reply-quote {
    margin-bottom: 10px;
    padding: 10px 12px;
    border-radius: 16px;
    border: 1px solid rgba(148, 163, 184, 0.1);
    background: rgba(8, 11, 18, 0.52);
  }

  body.chat-mode-active .reply-quote-user {
    font-size: 10px;
    letter-spacing: 0.04em;
    font-family: var(--font-mono);
  }

  body.chat-mode-active .reply-quote-text {
    font-size: 12px;
    color: rgba(203, 213, 225, 0.82);
  }

  body.chat-mode-active .message-time {
    margin-top: 10px;
    font-size: 11px;
    color: rgba(148, 163, 184, 0.84);
  }

  body.chat-mode-active .message.own .message-time {
    color: rgba(239, 246, 255, 0.78);
  }

  body.chat-mode-active .msg-reply-btn {
    top: 14px;
    left: -14px;
    width: 34px;
    height: 34px;
    border: 1px solid rgba(148, 163, 184, 0.16);
    background: rgba(8, 11, 18, 0.92);
    color: #cbd5e1;
    box-shadow: 0 10px 24px rgba(2, 6, 23, 0.32);
  }

  body.chat-mode-active .msg-reply-btn:hover {
    background: rgba(15, 23, 42, 1);
  }

  body.chat-mode-active .chat-stream-region {
    padding: 0 clamp(28px, 4vw, 56px) 18px;
  }

  body.chat-mode-active .live-activity-feed {
    width: min(100%, 820px);
    border-radius: 24px;
    border-color: rgba(96, 165, 250, 0.2);
    background: linear-gradient(180deg, rgba(7, 11, 21, 0.98), rgba(5, 9, 17, 0.94));
    box-shadow: 0 24px 56px rgba(2, 6, 23, 0.34);
  }

  body.chat-mode-active .reply-preview {
    width: min(980px, calc(100% - 56px));
    margin: 0 auto 14px;
    padding: 12px 16px;
    border-radius: 20px;
    border: 1px solid rgba(148, 163, 184, 0.12);
    background: rgba(8, 11, 18, 0.84);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
  }

  body.chat-mode-active .chat-input-area {
    position: sticky;
    bottom: 22px;
    width: min(980px, calc(100% - 56px));
    margin: 0 auto 24px;
    padding: 14px;
    border: 1px solid rgba(148, 163, 184, 0.14);
    border-radius: 28px;
    background: linear-gradient(180deg, rgba(8, 11, 18, 0.92), rgba(8, 11, 18, 0.84));
    box-shadow: 0 28px 54px rgba(2, 6, 23, 0.34);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    gap: 12px;
  }

  body.chat-mode-active .chat-input-area > .chat-input-wrapper {
    max-width: none;
  }

  body.chat-mode-active .chat-input-wrapper {
    min-height: 58px;
    padding: 10px 14px;
    border-radius: 22px;
    border-color: rgba(148, 163, 184, 0.12);
    background: rgba(15, 23, 42, 0.52);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.03);
    gap: 8px;
  }

  body.chat-mode-active .chat-input {
    min-height: 38px;
    max-height: 180px;
    padding: 8px 10px;
    font-size: 15px;
    line-height: 1.68;
  }

  body.chat-mode-active .chat-send-btn,
  body.chat-mode-active .chat-attach-btn,
  body.chat-mode-active .chat-emoji-btn {
    width: 46px;
    height: 46px;
    min-width: 46px;
  }

  body.chat-mode-active .chat-send-btn {
    background: linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%);
    box-shadow: 0 14px 28px rgba(37, 99, 235, 0.3);
  }

  body.chat-mode-active .chat-attach-btn,
  body.chat-mode-active .chat-emoji-btn {
    border-radius: 16px;
    border: 1px solid rgba(148, 163, 184, 0.12);
    background: rgba(15, 23, 42, 0.56);
    color: #cbd5e1;
  }

  body.chat-mode-active .chat-attach-btn:hover,
  body.chat-mode-active .chat-emoji-btn:hover {
    background: rgba(30, 41, 59, 0.88);
    color: #fff;
  }

  body.chat-mode-active .scroll-to-bottom-btn {
    right: 28px;
    bottom: 132px;
    width: 48px;
    height: 48px;
    border-radius: 18px;
    background: rgba(8, 11, 18, 0.94);
    border-color: rgba(148, 163, 184, 0.16);
    box-shadow: 0 18px 34px rgba(2, 6, 23, 0.34);
  }
}

@media (max-width: 768px) {
  body.chat-mode-active .chat-container {
    background: linear-gradient(180deg, rgba(9, 13, 22, 0.98), rgba(7, 10, 17, 0.99));
  }

  body.chat-mode-active .chat-header-bar {
    min-height: 58px;
    padding: 10px 12px 8px;
    background: linear-gradient(180deg, rgba(9, 13, 22, 0.98), rgba(9, 13, 22, 0.78));
    border-bottom: 1px solid rgba(148, 163, 184, 0.08);
  }

  body.chat-mode-active .chat-header-avatar {
    width: 40px;
    height: 40px;
    min-width: 40px;
    border-radius: 14px;
    background: linear-gradient(135deg, #3b82f6, #1e3a8a);
    border: 1px solid rgba(191, 219, 254, 0.18);
  }

  body.chat-mode-active .chat-header-title {
    font-size: 15px;
    font-weight: 700;
  }

  body.chat-mode-active .chat-messages {
    gap: 12px;
    padding: 14px 12px 0;
    background: linear-gradient(180deg, rgba(8, 11, 18, 0.18), rgba(8, 11, 18, 0));
  }

  body.chat-mode-active .message {
    max-width: 86%;
    padding: 13px 15px 12px;
    border: 1px solid rgba(148, 163, 184, 0.12);
    border-radius: 22px;
    box-shadow: 0 16px 30px rgba(2, 6, 23, 0.22);
  }

  body.chat-mode-active .message.own {
    background: var(--chat-user-bg);
    border-color: rgba(147, 197, 253, 0.2);
    border-radius: 22px 22px 8px 22px;
  }

  body.chat-mode-active .message.other {
    background: linear-gradient(180deg, rgba(15, 20, 34, 0.9), rgba(9, 13, 22, 0.96));
    border-radius: 22px 22px 22px 8px;
  }

  body.chat-mode-active .message.own .message-sender {
    display: none;
  }

  body.chat-mode-active .message-sender {
    margin-bottom: 8px;
    padding: 4px 8px;
    border-radius: 999px;
    background: rgba(15, 23, 42, 0.44);
    border: 1px solid rgba(148, 163, 184, 0.08);
    font-size: 11px;
    font-family: var(--font-mono);
  }

  body.chat-mode-active .reply-quote {
    margin-bottom: 8px;
    padding: 8px 10px;
    border-radius: 14px;
    background: rgba(8, 11, 18, 0.48);
  }

  body.chat-mode-active .chat-stream-region {
    padding: 0 12px 10px;
  }

  body.chat-mode-active .live-activity-feed {
    border-radius: 20px;
    background: linear-gradient(180deg, rgba(7, 11, 21, 0.98), rgba(6, 9, 17, 0.94));
    box-shadow: 0 18px 34px rgba(2, 6, 23, 0.28);
  }

  body.chat-mode-active .chat-input-area {
    background: linear-gradient(180deg, rgba(8, 11, 18, 0.96), rgba(8, 11, 18, 0.9));
    border-top-color: rgba(148, 163, 184, 0.08);
    box-shadow: 0 -18px 34px rgba(2, 6, 23, 0.3);
  }

  body.chat-mode-active .chat-input-wrapper {
    border-radius: 22px;
    background: rgba(15, 23, 42, 0.56);
    border-color: rgba(148, 163, 184, 0.1);
  }

  body.chat-mode-active .chat-send-btn {
    background: linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%);
    box-shadow: 0 12px 22px rgba(37, 99, 235, 0.28);
  }

  body.chat-mode-active .chat-attach-btn,
  body.chat-mode-active .chat-emoji-btn {
    border-radius: 14px;
    border: 1px solid rgba(148, 163, 184, 0.1);
    background: rgba(15, 23, 42, 0.56);
    color: #cbd5e1;
  }
}

/* ===== Chat Workspace Layout v2 ===== */
body.chat-mode-active {
  --chat-workspace-border: rgba(148, 163, 184, 0.12);
  --chat-workspace-panel: linear-gradient(180deg, rgba(10, 14, 24, 0.98), rgba(7, 10, 17, 0.96));
  --chat-workspace-soft: rgba(15, 23, 42, 0.62);
  --chat-workspace-soft-strong: rgba(15, 23, 42, 0.82);
}

body.chat-mode-active .chat-header-leading,
body.chat-mode-active .chat-header-actions,
body.chat-mode-active .chat-header-meta-row,
body.chat-mode-active .chat-workspace-rail-head,
body.chat-mode-active .chat-context-pills,
body.chat-mode-active .chat-context-metrics {
  display: flex;
}

body.chat-mode-active .chat-header-leading,
body.chat-mode-active .chat-header-actions,
body.chat-mode-active .chat-header-meta-row,
body.chat-mode-active .chat-context-pills {
  align-items: center;
}

body.chat-mode-active .chat-header-meta-row,
body.chat-mode-active .chat-context-pills {
  flex-wrap: wrap;
}

body.chat-mode-active .chat-workspace-rail,
body.chat-mode-active .chat-main-stage,
body.chat-mode-active .chat-stage-shell,
body.chat-mode-active .chat-composer-shell {
  position: relative;
  min-height: 0;
}

body.chat-mode-active .chat-context-action {
  width: 100%;
  min-height: 46px;
  padding: 0 14px;
  border: 1px solid rgba(148, 163, 184, 0.12);
  border-radius: 16px;
  background: rgba(15, 23, 42, 0.68);
  color: #e2e8f0;
  text-align: right;
  font-size: 14px;
  font-weight: 600;
  transition: transform 0.18s ease, background 0.18s ease, border-color 0.18s ease;
}

body.chat-mode-active .chat-context-action:hover {
  transform: translateY(-1px);
  background: rgba(30, 41, 59, 0.9);
  border-color: rgba(96, 165, 250, 0.24);
}

body.chat-mode-active .chat-mobile-toolbar {
  display: none;
}

@media (min-width: 992px) {
  body.chat-mode-active .chat-menu-toggle {
    display: inline-flex;
  }

  body.chat-mode-active .main-container {
    display: block;
    padding: 0;
    gap: 0;
  }

  body.chat-mode-active .sidebar {
    position: fixed;
    top: 22px;
    right: 22px;
    bottom: 22px;
    width: 280px;
    transform: translateX(calc(100% + 36px));
    opacity: 0;
    pointer-events: none;
    z-index: 1400;
    transition: transform 0.28s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.18s ease;
  }

  body.chat-mode-active .sidebar.open {
    transform: translateX(0);
    opacity: 1;
    pointer-events: auto;
  }

  body.chat-mode-active .main-content.chat-mode {
    width: 100%;
    max-width: none;
    padding: 12px 14px 14px;
  }

  body.chat-mode-active .main-content.chat-mode #moduleContent {
    min-height: calc(100dvh - 26px);
    height: calc(100dvh - 26px);
    max-height: calc(100dvh - 26px);
  }

  body.chat-mode-active .chat-container.chat-workspace-shell {
    display: grid;
    grid-template-columns: minmax(212px, 248px) minmax(0, 1fr);
    gap: 12px;
    border: none;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
    overflow: visible;
    min-height: 100%;
    height: 100%;
    max-height: 100%;
    align-items: stretch;
  }

  body.chat-mode-active .chat-container.chat-workspace-shell::before {
    display: none;
  }

  body.chat-mode-active .chat-workspace-rail {
    display: flex;
    flex-direction: column;
    padding: 14px;
    border: 1px solid var(--chat-workspace-border);
    border-radius: 22px;
    background: var(--chat-workspace-panel);
    box-shadow: 0 30px 64px rgba(2, 6, 23, 0.38);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    overflow: hidden;
  }

  body.chat-mode-active .chat-workspace-rail-conversations {
    gap: 12px;
  }

  body.chat-mode-active .chat-workspace-rail-context {
    display: none;
  }

  body.chat-mode-active .chat-workspace-rail-head {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }

  body.chat-mode-active .chat-rail-kicker,
  body.chat-mode-active .chat-context-kicker,
  body.chat-mode-active .chat-rail-section-label,
  body.chat-mode-active .chat-header-eyebrow,
  body.chat-mode-active .chat-context-metric-label,
  body.chat-mode-active .chat-rail-metric-label {
    font-family: var(--font-mono);
    letter-spacing: 0.08em;
    text-transform: uppercase;
  }

  body.chat-mode-active .chat-rail-kicker,
  body.chat-mode-active .chat-context-kicker,
  body.chat-mode-active .chat-rail-section-label,
  body.chat-mode-active .chat-header-eyebrow {
    color: #93c5fd;
    font-size: 11px;
    font-weight: 700;
  }

  body.chat-mode-active .chat-rail-title {
    margin: 0;
    font-size: 21px;
    line-height: 1;
    color: #f8fafc;
    letter-spacing: -0.04em;
  }

  body.chat-mode-active .chat-rail-subtitle,
  body.chat-mode-active .chat-context-meta,
  body.chat-mode-active .chat-context-note,
  body.chat-mode-active .chat-header-context {
    margin: 0;
    color: rgba(203, 213, 225, 0.76);
    font-size: 11px;
    line-height: 1.45;
  }

  body.chat-mode-active .chat-rail-primary-btn {
    min-height: 42px;
    padding: 0 12px;
    border: 1px solid rgba(96, 165, 250, 0.22);
    border-radius: 16px;
    background: linear-gradient(135deg, rgba(37, 99, 235, 0.22), rgba(15, 23, 42, 0.96));
    color: #eff6ff;
    font-size: 13px;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    box-shadow: 0 18px 34px rgba(2, 6, 23, 0.24);
  }

  body.chat-mode-active .chat-rail-metrics,
  body.chat-mode-active .chat-context-metrics {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  body.chat-mode-active .chat-rail-metric,
  body.chat-mode-active .chat-context-metric {
    padding: 10px;
    border-radius: 14px;
    border: 1px solid rgba(148, 163, 184, 0.1);
    background: rgba(15, 23, 42, 0.46);
  }

  body.chat-mode-active .chat-rail-metric-label,
  body.chat-mode-active .chat-context-metric-label {
    display: block;
    margin-bottom: 8px;
    color: rgba(148, 163, 184, 0.72);
    font-size: 10px;
    font-weight: 700;
  }

  body.chat-mode-active .chat-rail-metric strong,
  body.chat-mode-active .chat-context-metric strong {
    display: block;
    color: #f8fafc;
    font-size: 18px;
    line-height: 1;
  }

  body.chat-mode-active .chat-rail-section-label {
    padding-top: 6px;
  }

  body.chat-mode-active .chat-desktop-conversation-list {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: 10px;
    overflow-y: auto;
    padding-inline-end: 4px;
  }

  body.chat-mode-active .chat-desktop-conversation-list .dm-conv-item {
    padding: 10px;
    border-radius: 16px;
    border: 1px solid rgba(148, 163, 184, 0.08);
    background: rgba(8, 11, 18, 0.54);
    transition: transform 0.18s ease, border-color 0.18s ease, background 0.18s ease;
  }

  body.chat-mode-active .chat-desktop-conversation-list .dm-conv-item:hover {
    transform: translateY(-1px);
    border-color: rgba(96, 165, 250, 0.18);
    background: rgba(15, 23, 42, 0.82);
  }

  body.chat-mode-active .chat-desktop-conversation-list .dm-conv-item.active {
    background: linear-gradient(135deg, rgba(37, 99, 235, 0.24), rgba(15, 23, 42, 0.92));
    border-color: rgba(96, 165, 250, 0.22);
    box-shadow: 0 18px 34px rgba(2, 6, 23, 0.26);
  }

  body.chat-mode-active .chat-main-stage {
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    height: 100%;
    max-height: 100%;
    border: 1px solid var(--chat-workspace-border);
    border-radius: 24px;
    background:
      linear-gradient(180deg, rgba(11, 16, 27, 0.98), rgba(7, 10, 17, 0.98)),
      radial-gradient(circle at top left, rgba(59, 130, 246, 0.08), transparent 32%);
    box-shadow: 0 34px 84px rgba(2, 6, 23, 0.46);
    overflow: hidden;
  }

  body.chat-mode-active .chat-header-bar {
    min-height: auto;
    padding: 12px 14px 8px;
    justify-content: space-between;
    gap: 10px;
    background: linear-gradient(180deg, rgba(10, 14, 24, 0.98), rgba(10, 14, 24, 0.76));
    border-bottom: 1px solid rgba(148, 163, 184, 0.08);
  }

  body.chat-mode-active .chat-header-leading {
    flex: 1 1 auto;
    min-width: 0;
    gap: 10px;
  }

  body.chat-mode-active .chat-header-actions {
    flex: 0 0 auto;
    gap: 8px;
  }

  body.chat-mode-active .chat-header-info {
    min-width: 0;
    align-items: flex-start;
    gap: 3px;
  }

  body.chat-mode-active .chat-header-title {
    font-size: clamp(20px, 1.7vw, 26px);
    line-height: 1.05;
    letter-spacing: -0.05em;
  }

  body.chat-mode-active .chat-header-avatar {
    width: 42px;
    height: 42px;
    min-width: 42px;
    border-radius: 14px;
    font-size: 15px;
  }

  body.chat-mode-active .chat-header-btn,
  body.chat-mode-active .chat-search-close,
  body.chat-mode-active .search-nav-btn {
    width: 40px;
    height: 40px;
    border-radius: 14px;
  }

  body.chat-mode-active .chat-stage-shell {
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
  }

  body.chat-mode-active .chat-search-bar {
    padding: 0 14px 10px;
  }

  body.chat-mode-active .chat-messages {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    padding: 12px clamp(14px, 2vw, 22px) 8px;
    background:
      linear-gradient(rgba(148, 163, 184, 0.03) 1px, transparent 1px),
      linear-gradient(90deg, rgba(148, 163, 184, 0.02) 1px, transparent 1px),
      linear-gradient(180deg, rgba(8, 12, 21, 0.82), rgba(6, 10, 17, 0.28));
    background-size: 100% 30px, 30px 100%, 100% 100%;
  }

  body.chat-mode-active .message {
    max-width: min(74%, 860px);
  }

  body.chat-mode-active .message.own {
    max-width: min(60%, 680px);
  }

  body.chat-mode-active .chat-composer-shell {
    flex: 0 0 auto;
    min-height: 0;
    padding: 0 14px 10px;
    border-top: 1px solid rgba(148, 163, 184, 0.08);
    background: linear-gradient(180deg, rgba(6, 10, 17, 0), rgba(6, 10, 17, 0.42) 18%, rgba(6, 10, 17, 0.82));
  }

  body.chat-mode-active .chat-stream-region {
    padding: 0 0 6px;
  }

  body.chat-mode-active .live-activity-feed,
  body.chat-mode-active .reply-preview,
  body.chat-mode-active .typing-indicator {
    width: 100%;
  }

  body.chat-mode-active .live-activity-feed {
    gap: 6px;
    padding: 8px 10px;
    border-radius: 14px;
    box-shadow: 0 10px 20px rgba(2, 6, 23, 0.22);
  }

  body.chat-mode-active .live-activity-feed.is-done,
  body.chat-mode-active .live-activity-feed.is-compact {
    width: 100%;
    gap: 4px;
    padding: 7px 9px;
  }

  body.chat-mode-active .live-activity-head,
  body.chat-mode-active .live-activity-head-main,
  body.chat-mode-active .live-activity-head-meta {
    gap: 6px;
  }

  body.chat-mode-active .live-activity-title {
    font-size: 10px;
  }

  body.chat-mode-active .live-activity-run-label,
  body.chat-mode-active .live-activity-elapsed {
    padding: 3px 6px;
    font-size: 9px;
  }

  body.chat-mode-active .live-activity-state {
    min-width: 60px;
    padding: 3px 6px;
    font-size: 9px;
  }

  body.chat-mode-active .live-activity-primary {
    font-size: 12px;
  }

  body.chat-mode-active .live-activity-secondary {
    font-size: 10px;
  }

  body.chat-mode-active .typing-indicator,
  body.chat-mode-active .reply-preview {
    margin: 0 0 6px;
  }

  body.chat-mode-active .chat-input-area {
    position: static;
    width: 100%;
    margin: 0;
    padding: 8px 10px;
    border-radius: 18px;
  }

  body.chat-mode-active .chat-input-wrapper {
    min-height: 46px;
  }

  body.chat-mode-active .scroll-to-bottom-btn {
    right: 24px;
    bottom: 104px;
  }

  body.chat-mode-active .chat-context-card {
    padding: 12px;
    border-radius: 16px;
    border: 1px solid rgba(148, 163, 184, 0.1);
    background: rgba(15, 23, 42, 0.54);
  }

  body.chat-mode-active .chat-context-card-primary {
    background: linear-gradient(180deg, rgba(17, 24, 39, 0.96), rgba(15, 23, 42, 0.8));
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
  }

  body.chat-mode-active .chat-context-name {
    display: block;
    margin-top: 8px;
    margin-bottom: 10px;
    color: #f8fafc;
    font-size: 18px;
    line-height: 1.1;
    letter-spacing: -0.04em;
  }

  body.chat-mode-active .chat-context-pills {
    gap: 8px;
    margin-top: 10px;
  }

  body.chat-mode-active .chat-context-pill {
    padding: 6px 10px;
    border-radius: 999px;
    border: 1px solid rgba(148, 163, 184, 0.12);
    background: rgba(8, 11, 18, 0.68);
    color: #cbd5e1;
    font-size: 11px;
    font-family: var(--font-mono);
  }

  body.chat-mode-active .chat-context-pill.is-accent {
    border-color: rgba(96, 165, 250, 0.18);
    background: rgba(30, 64, 175, 0.2);
    color: #dbeafe;
  }

  body.chat-mode-active .chat-context-pill.is-private {
    border-color: rgba(56, 189, 248, 0.16);
    background: rgba(8, 47, 73, 0.42);
    color: #bae6fd;
  }
}

@media (max-width: 1480px) and (min-width: 992px) {
  body.chat-mode-active .main-content.chat-mode {
    padding: 16px 18px 18px;
  }

  body.chat-mode-active .main-content.chat-mode #moduleContent {
    min-height: calc(100dvh - 34px);
    height: calc(100dvh - 34px);
    max-height: calc(100dvh - 34px);
  }

  body.chat-mode-active .chat-container.chat-workspace-shell {
    grid-template-columns: minmax(236px, 272px) minmax(0, 1fr);
    gap: 14px;
  }

  body.chat-mode-active .chat-workspace-rail-context {
    display: none;
  }

  body.chat-mode-active .chat-workspace-rail {
    padding: 18px;
    border-radius: 26px;
  }

  body.chat-mode-active .chat-rail-title {
    font-size: 23px;
  }

  body.chat-mode-active .chat-rail-subtitle,
  body.chat-mode-active .chat-context-meta,
  body.chat-mode-active .chat-context-note,
  body.chat-mode-active .chat-header-context {
    font-size: 12px;
    line-height: 1.55;
  }

  body.chat-mode-active .chat-rail-primary-btn {
    min-height: 46px;
    border-radius: 16px;
  }

  body.chat-mode-active .chat-rail-metric,
  body.chat-mode-active .chat-context-metric {
    padding: 12px;
  }

  body.chat-mode-active .chat-rail-metric strong,
  body.chat-mode-active .chat-context-metric strong {
    font-size: 20px;
  }

  body.chat-mode-active .chat-desktop-conversation-list .dm-conv-item {
    padding: 12px;
    border-radius: 18px;
  }

  body.chat-mode-active .chat-main-stage {
    border-radius: 28px;
  }

  body.chat-mode-active .chat-header-bar {
    padding: 18px 20px 14px;
    gap: 14px;
  }

  body.chat-mode-active .chat-header-leading {
    gap: 12px;
  }

  body.chat-mode-active .chat-header-info {
    gap: 4px;
  }

  body.chat-mode-active .chat-header-title {
    font-size: clamp(22px, 2vw, 28px);
  }

  body.chat-mode-active .chat-header-meta-row {
    gap: 8px 12px;
  }

  body.chat-mode-active .chat-header-avatar {
    width: 48px;
    height: 48px;
    min-width: 48px;
    border-radius: 16px;
    font-size: 16px;
  }

  body.chat-mode-active .chat-header-btn,
  body.chat-mode-active .chat-search-close,
  body.chat-mode-active .search-nav-btn {
    width: 44px;
    height: 44px;
    border-radius: 16px;
  }

  body.chat-mode-active .chat-search-bar {
    padding: 0 20px 14px;
  }

  body.chat-mode-active .chat-messages {
    padding: 20px clamp(18px, 2.2vw, 28px) 14px;
    background-size: 100% 30px, 30px 100%, 100% 100%;
  }

  body.chat-mode-active .message {
    max-width: min(80%, 760px);
  }

  body.chat-mode-active .message.own {
    max-width: min(66%, 620px);
  }

  body.chat-mode-active .chat-composer-shell {
    padding: 0 20px 18px;
  }

  body.chat-mode-active .typing-indicator,
  body.chat-mode-active .reply-preview {
    margin: 0 0 10px;
  }

  body.chat-mode-active .chat-input-area {
    padding: 12px;
    border-radius: 22px;
  }

  body.chat-mode-active .chat-input-wrapper {
    min-height: 56px;
  }

  body.chat-mode-active .scroll-to-bottom-btn {
    right: 24px;
    bottom: 132px;
  }
}

@media (max-width: 991px) {
  body.chat-mode-active .chat-container.chat-workspace-shell {
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    min-height: 0;
  }

  body.chat-mode-active .chat-workspace-rail {
    display: none;
  }

  body.chat-mode-active .chat-main-stage {
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
  }

  body.chat-mode-active .chat-stage-shell {
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    min-height: 0;
  }

  body.chat-mode-active .chat-composer-shell {
    flex-shrink: 0;
    padding-bottom: 0;
  }
}

@media (max-width: 768px) {
  body.chat-mode-active .chat-header-bar {
    min-height: auto;
    padding: 12px 12px 8px;
    gap: 10px;
    align-items: center;
  }

  body.chat-mode-active .chat-header-leading {
    display: grid;
    grid-template-columns: auto auto minmax(0, 1fr);
    align-items: center;
    gap: 10px;
    width: 100%;
  }

  body.chat-mode-active .chat-header-actions {
    display: none;
  }

  body.chat-mode-active .chat-menu-toggle {
    width: 42px;
    min-width: 42px;
    height: 42px;
    min-height: 42px;
    border-radius: 14px;
  }

  body.chat-mode-active .chat-header-avatar {
    width: 38px;
    height: 38px;
    min-width: 38px;
    border-radius: 13px;
  }

  body.chat-mode-active .chat-header-info {
    gap: 4px;
    min-width: 0;
  }

  body.chat-mode-active .chat-header-eyebrow {
    display: none;
  }

  body.chat-mode-active .chat-header-title {
    font-size: 18px;
    line-height: 1.1;
    letter-spacing: -0.03em;
  }

  body.chat-mode-active .chat-header-meta-row {
    display: block;
    min-width: 0;
  }

  body.chat-mode-active .chat-header-context {
    display: block;
    max-width: 100%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: rgba(191, 219, 254, 0.74);
    font-size: 12px;
    line-height: 1.35;
  }

  body.chat-mode-active .chat-mobile-toolbar {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 0 12px 12px;
    border-bottom: 1px solid rgba(148, 163, 184, 0.08);
    background: linear-gradient(180deg, rgba(9, 13, 22, 0.78), rgba(9, 13, 22, 0.42));
  }

  body.chat-mode-active .chat-mobile-toolbar-pills {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
  }

  body.chat-mode-active .chat-mobile-pill {
    display: inline-flex;
    align-items: center;
    min-height: 28px;
    padding: 0 10px;
    border-radius: 999px;
    border: 1px solid rgba(148, 163, 184, 0.14);
    background: rgba(15, 23, 42, 0.7);
    color: #cbd5e1;
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
  }

  body.chat-mode-active .chat-mobile-pill:first-child {
    border-color: rgba(96, 165, 250, 0.22);
    background: rgba(30, 64, 175, 0.22);
    color: #dbeafe;
  }

  body.chat-mode-active .chat-mobile-pill-context.is-accent {
    border-color: rgba(96, 165, 250, 0.18);
    background: rgba(30, 64, 175, 0.16);
    color: #dbeafe;
  }

  body.chat-mode-active .chat-mobile-pill-context.is-private {
    border-color: rgba(56, 189, 248, 0.16);
    background: rgba(8, 47, 73, 0.4);
    color: #bae6fd;
  }

  body.chat-mode-active .chat-mobile-toolbar-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  body.chat-mode-active .chat-mobile-action {
    width: 100%;
    min-height: 38px;
    padding: 0 12px;
    border-radius: 16px;
    border: 1px solid rgba(148, 163, 184, 0.12);
    background: rgba(15, 23, 42, 0.68);
    color: #e2e8f0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    font-size: 13px;
    font-weight: 700;
    box-shadow: 0 10px 24px rgba(2, 6, 23, 0.16);
  }

  body.chat-mode-active .chat-mobile-action i {
    font-size: 13px;
  }

  body.chat-mode-active .chat-mobile-action-badge {
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    border-radius: 999px;
    background: #2563eb;
    color: #eff6ff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    font-weight: 800;
    box-shadow: 0 8px 18px rgba(37, 99, 235, 0.28);
  }

  body.chat-mode-active .chat-search-bar {
    padding: 10px 12px;
  }

  body.chat-mode-active .chat-messages {
    padding: 12px 12px 0;
    /* Keep last message above the fixed input area */
    padding-bottom: max(calc(var(--chat-mobile-composer-stack) + 18px), 126px) !important;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: contain;
    touch-action: pan-y;
  }

  body.chat-mode-active .chat-input-area {
    position: fixed;
    left: 10px;
    right: 10px;
    bottom: calc(var(--chat-mobile-keyboard-offset) + 8px);
    z-index: 450;
    width: auto;
    margin: 0;
    gap: 8px;
    padding: 10px 10px calc(10px + var(--chat-mobile-safe-bottom));
    border: 1px solid rgba(148, 163, 184, 0.14);
    border-radius: 24px;
    background: linear-gradient(180deg, rgba(8, 11, 18, 0.96), rgba(8, 11, 18, 0.92));
    box-shadow: 0 20px 34px rgba(2, 6, 23, 0.32);
  }

  body.chat-mode-active .scroll-to-bottom-btn {
    position: fixed;
    right: 18px;
    bottom: calc(var(--chat-mobile-overlay-offset) + 20px);
    z-index: 460;
  }

  body.chat-mode-active .chat-input-wrapper {
    min-height: 46px;
    padding: 4px 8px 4px 10px;
  }
}

/* =============================================
   MOBILE FIX 2025-07 — Header, Input, Spacing
   ============================================= */
@media (max-width: 768px) {

  /* --- Header: tighter padding, less vertical bulk --- */
  body.chat-mode-active .chat-header-bar {
    padding: 8px 10px 4px !important;
    gap: 6px !important;
  }

  /* --- Leading row: smaller avatar + toggle --- */
  body.chat-mode-active .chat-header-leading {
    gap: 8px !important;
  }

  body.chat-mode-active .chat-menu-toggle {
    width: 36px !important;
    min-width: 36px !important;
    height: 36px !important;
    min-height: 36px !important;
    font-size: 16px !important;
    border-radius: 12px !important;
  }

  body.chat-mode-active .chat-header-avatar {
    width: 34px !important;
    height: 34px !important;
    min-width: 34px !important;
    font-size: 13px !important;
    border-radius: 11px !important;
  }

  /* --- Title: allow wrapping instead of truncation --- */
  body.chat-mode-active .chat-header-title {
    font-size: 16px !important;
    line-height: 1.2 !important;
    white-space: normal !important;
    overflow: visible !important;
    text-overflow: unset !important;
    display: -webkit-box !important;
    -webkit-line-clamp: 2 !important;
    -webkit-box-orient: vertical !important;
    word-break: break-word !important;
  }

  /* --- Subtitle context: allow wrapping or 2 lines --- */
  body.chat-mode-active .chat-header-context {
    white-space: normal !important;
    overflow: visible !important;
    text-overflow: unset !important;
    display: -webkit-box !important;
    -webkit-line-clamp: 2 !important;
    -webkit-box-orient: vertical !important;
    font-size: 11px !important;
    line-height: 1.3 !important;
    opacity: 0.72;
  }

  /* --- Info container: stack vertically on mobile --- */
  body.chat-mode-active .chat-header-info {
    display: flex !important;
    flex-direction: column !important;
    align-items: flex-start !important;
    gap: 1px !important;
    min-width: 0;
    overflow: hidden;
  }

  /* --- Meta row: full width --- */
  body.chat-mode-active .chat-header-meta-row {
    width: 100% !important;
    min-width: 0;
  }

  /* --- Mobile toolbar: reduce vertical footprint --- */
  body.chat-mode-active .chat-mobile-toolbar {
    gap: 6px !important;
    padding: 0 10px 8px !important;
  }

  body.chat-mode-active .chat-mobile-toolbar-pills {
    gap: 4px !important;
  }

  body.chat-mode-active .chat-mobile-pill {
    min-height: 24px !important;
    padding: 0 8px !important;
    font-size: 10px !important;
  }

  body.chat-mode-active .chat-mobile-toolbar-actions {
    gap: 6px !important;
  }

  body.chat-mode-active .chat-mobile-action {
    min-height: 34px !important;
    padding: 0 10px !important;
    font-size: 12px !important;
    border-radius: 14px !important;
  }

  /* --- Active context chip below toolbar: smaller --- */
  body.chat-mode-active .chat-mobile-context-line {
    font-size: 11px !important;
    padding: 4px 10px !important;
  }

  /* --- Input area: wider textarea, smaller buttons --- */
  body.chat-mode-active .chat-input-area {
    left: 6px !important;
    right: 6px !important;
    padding: 6px 8px calc(6px + var(--chat-mobile-safe-bottom)) !important;
    border-radius: 20px !important;
    gap: 6px !important;
  }

  body.chat-mode-active .chat-input-wrapper {
    padding: 2px 6px 2px 8px !important;
    min-height: 42px !important;
    gap: 4px !important;
  }

  body.chat-mode-active .chat-input-wrapper .chat-input {
    flex: 1 1 auto !important;
    width: 100% !important;
    min-width: 0 !important;
    font-size: 16px !important; /* iOS: prevent zoom */
    padding: 8px 6px !important;
    min-height: 38px !important;
  }

  /* Smaller action buttons in input bar */
  body.chat-mode-active .chat-send-btn,
  body.chat-mode-active .chat-attach-btn,
  body.chat-mode-active .chat-emoji-btn {
    width: 38px !important;
    height: 38px !important;
    min-width: 38px !important;
    font-size: 15px !important;
  }

  body.chat-mode-active .chat-send-btn {
    border-radius: 14px !important;
  }

  /* --- Scroll-to-bottom adjustment --- */
  body.chat-mode-active .scroll-to-bottom-btn {
    right: 14px !important;
  }

  /* --- CLI LIVE / stream region: fix above input area on mobile --- */
  body.chat-mode-active .chat-stream-region {
    position: fixed !important;
    left: 6px !important;
    right: 6px !important;
    bottom: calc(
      var(--chat-mobile-input-height) +
      var(--chat-mobile-reply-height) +
      var(--chat-mobile-keyboard-offset) +
      8px
    ) !important;
    z-index: 449 !important;
    padding: 4px 8px 6px !important;
    pointer-events: auto;
    background: transparent;
  }
}

/* ── Desktop: attach-menu z-index fix ─────────────────────────
   On desktop the attach-menu is moved to <body> via JS (chat-attach-fix.js)
   so it escapes the isolation:isolate stacking context of .chat-container.
   These styles ensure correct layering when it lives on <body>. */
body > .attach-menu-backdrop {
  z-index: 10000;
}
body > .attach-menu {
  z-index: 10001;
}

/* ── Drag & Drop overlay ─────────────────────────────────── */
.chat-drop-overlay {
  position: absolute;
  inset: 0;
  z-index: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(6, 10, 18, 0.82);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 3px dashed rgba(96, 165, 250, 0.5);
  border-radius: inherit;
  opacity: 0;
  transition: opacity 0.2s ease;
  pointer-events: none;
}

.chat-drop-overlay.visible {
  opacity: 1;
  pointer-events: auto;
}

.chat-drop-overlay-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  text-align: center;
  animation: dropPulse 1.5s ease-in-out infinite;
}

.chat-drop-icon {
  font-size: 56px;
  filter: drop-shadow(0 8px 24px rgba(96, 165, 250, 0.3));
}

.chat-drop-title {
  font-size: 20px;
  font-weight: 700;
  color: #e2e8f0;
  letter-spacing: -0.01em;
}

.chat-drop-subtitle {
  font-size: 14px;
  color: rgba(148, 163, 184, 0.8);
}

@keyframes dropPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.04); }
}

/* ===== Media Gallery ===== */
.media-gallery-header-trigger {
  cursor: pointer;
  border-radius: 16px;
  transition: background 0.18s ease, box-shadow 0.18s ease, transform 0.18s ease;
}

.media-gallery-header-trigger:hover,
.media-gallery-header-trigger:focus-visible {
  background: rgba(96, 165, 250, 0.10);
  box-shadow: 0 0 0 1px rgba(96, 165, 250, 0.20);
  outline: none;
}

.media-gallery-backdrop {
  position: fixed;
  inset: 0;
  z-index: 699;
  background: rgba(2, 6, 23, 0.56);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s ease;
}

.media-gallery-backdrop.is-visible {
  opacity: 1;
  pointer-events: auto;
}

.media-gallery-drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 360px;
  z-index: 700;
  display: flex;
  flex-direction: column;
  direction: rtl;
  background: linear-gradient(180deg, rgba(15, 23, 42, 0.96), rgba(9, 14, 24, 0.94));
  border-left: 1px solid rgba(148, 163, 184, 0.16);
  box-shadow: -18px 0 48px rgba(2, 6, 23, 0.44);
  backdrop-filter: blur(18px) saturate(1.2);
  -webkit-backdrop-filter: blur(18px) saturate(1.2);
  transform: translateX(100%);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.24s ease, opacity 0.24s ease;
  overflow: hidden;
}

.media-gallery-drawer.is-open {
  transform: translateX(0);
  opacity: 1;
  pointer-events: auto;
}

.media-gallery-header {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 16px 18px 14px;
  border-bottom: 1px solid rgba(148, 163, 184, 0.12);
  background: rgba(15, 23, 42, 0.48);
}

.media-gallery-heading {
  min-width: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.media-gallery-title {
  font-size: 16px;
  font-weight: 700;
  color: #f8fafc;
  line-height: 1.25;
}

.media-gallery-subtitle {
  font-size: 12px;
  color: rgba(148, 163, 184, 0.9);
  line-height: 1.5;
}

.media-gallery-close {
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  color: #cbd5e1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  transition: background 0.18s ease, transform 0.18s ease;
}

.media-gallery-close:hover,
.media-gallery-close:focus-visible {
  background: rgba(96, 165, 250, 0.18);
  transform: translateY(-1px);
  outline: none;
}

.media-gallery-tabs {
  display: flex;
  align-items: stretch;
  gap: 2px;
  padding: 8px 10px 10px;
  border-bottom: 1px solid rgba(148, 163, 184, 0.10);
  background: rgba(15, 23, 42, 0.38);
  overflow-x: auto;
}

.media-gallery-tabs::-webkit-scrollbar {
  display: none;
}

.media-gallery-tab {
  flex: 1 0 auto;
  min-width: 60px;
  border: 0;
  border-bottom: 2px solid transparent;
  border-radius: 12px 12px 0 0;
  background: transparent;
  color: rgba(148, 163, 184, 0.95);
  padding: 10px 8px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.18s ease, color 0.18s ease, border-color 0.18s ease;
}

.media-gallery-tab:hover,
.media-gallery-tab:focus-visible {
  color: #e2e8f0;
  background: rgba(255, 255, 255, 0.04);
  outline: none;
}

.media-gallery-tab.is-active {
  color: #7dd3fc;
  border-bottom-color: #38bdf8;
  background: rgba(56, 189, 248, 0.08);
}

.media-gallery-content {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scrollbar-width: thin;
  scrollbar-color: rgba(148, 163, 184, 0.28) transparent;
}

.media-gallery-content::-webkit-scrollbar {
  width: 6px;
}

.media-gallery-content::-webkit-scrollbar-thumb {
  background: rgba(148, 163, 184, 0.28);
  border-radius: 999px;
}

.media-gallery-footer {
  padding: 10px 14px 14px;
  border-top: 1px solid rgba(148, 163, 184, 0.10);
  background: rgba(15, 23, 42, 0.4);
}

.media-gallery-load-more {
  display: none;
  width: 100%;
  border: 1px solid rgba(56, 189, 248, 0.35);
  border-radius: 12px;
  background: linear-gradient(180deg, rgba(14, 165, 233, 0.18), rgba(37, 99, 235, 0.14));
  color: #e0f2fe;
  font-size: 13px;
  font-weight: 700;
  padding: 11px 14px;
  cursor: pointer;
  transition: transform 0.18s ease, background 0.18s ease;
}

.media-gallery-load-more.is-visible {
  display: block;
}

.media-gallery-load-more:hover,
.media-gallery-load-more:focus-visible {
  transform: translateY(-1px);
  background: linear-gradient(180deg, rgba(14, 165, 233, 0.24), rgba(37, 99, 235, 0.20));
  outline: none;
}

.media-gallery-load-more:disabled {
  opacity: 0.7;
  cursor: default;
  transform: none;
}

.media-gallery-status {
  min-height: 180px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  border-radius: 18px;
  padding: 24px;
  color: rgba(191, 219, 254, 0.86);
  background: rgba(15, 23, 42, 0.42);
  border: 1px dashed rgba(148, 163, 184, 0.18);
  line-height: 1.7;
}

.media-gallery-status.is-error {
  color: #fecaca;
  border-color: rgba(248, 113, 113, 0.35);
  background: rgba(127, 29, 29, 0.24);
}

.media-gallery-status.is-empty {
  color: rgba(191, 219, 254, 0.72);
}

.media-gallery-preview {
  position: relative;
  overflow: hidden;
  border-radius: 16px;
  background: linear-gradient(145deg, rgba(30, 41, 59, 0.95), rgba(15, 23, 42, 0.95));
  background-size: cover;
  background-position: center;
  color: #f8fafc;
  display: flex;
  align-items: center;
  justify-content: center;
}

.media-gallery-preview--mixed {
  width: 72px;
  min-width: 72px;
  height: 72px;
  font-size: 28px;
}

.media-gallery-preview--grid {
  width: 100%;
  height: 100%;
  border-radius: 0;
  font-size: 20px;
}

.media-gallery-preview--video::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(2, 6, 23, 0.06), rgba(2, 6, 23, 0.45));
}

.media-gallery-play-badge {
  position: relative;
  z-index: 1;
  width: 34px;
  height: 34px;
  border-radius: 999px;
  background: rgba(2, 6, 23, 0.56);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 18px rgba(2, 6, 23, 0.28);
}

.media-gallery-preview-label {
  position: absolute;
  inset-inline-end: 8px;
  bottom: 7px;
  z-index: 1;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: rgba(255, 255, 255, 0.82);
}

.media-gallery-mixed-list,
.media-gallery-doc-list,
.media-gallery-link-list,
.media-gallery-voice-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.media-gallery-mixed-card,
.media-gallery-doc-item,
.media-gallery-link-item,
.media-gallery-voice-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px;
  border-radius: 18px;
  background: rgba(15, 23, 42, 0.42);
  border: 1px solid rgba(148, 163, 184, 0.12);
  box-shadow: 0 12px 26px rgba(2, 6, 23, 0.18);
}

.media-gallery-mixed-card.is-clickable {
  cursor: pointer;
  transition: transform 0.18s ease, border-color 0.18s ease, background 0.18s ease;
}

.media-gallery-mixed-card.is-clickable:hover,
.media-gallery-mixed-card.is-clickable:focus-visible {
  transform: translateY(-1px);
  border-color: rgba(125, 211, 252, 0.24);
  background: rgba(15, 23, 42, 0.56);
  outline: none;
}

.media-gallery-mixed-body,
.media-gallery-doc-body,
.media-gallery-link-body,
.media-gallery-voice-body {
  min-width: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.media-gallery-mixed-kicker {
  font-size: 11px;
  font-weight: 700;
  color: #7dd3fc;
}

.media-gallery-mixed-title,
.media-gallery-doc-name,
.media-gallery-voice-title {
  font-size: 14px;
  font-weight: 700;
  color: #f8fafc;
  line-height: 1.45;
  word-break: break-word;
}

.media-gallery-mixed-meta,
.media-gallery-doc-meta,
.media-gallery-link-meta,
.media-gallery-voice-meta {
  font-size: 11px;
  color: rgba(148, 163, 184, 0.9);
}

.media-gallery-mixed-caption,
.media-gallery-doc-caption,
.media-gallery-link-text {
  font-size: 12px;
  line-height: 1.6;
  color: rgba(226, 232, 240, 0.88);
  word-break: break-word;
}

.media-gallery-inline-links {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 4px;
}

.media-gallery-inline-link {
  color: #7dd3fc;
  text-decoration: none;
  font-size: 12px;
  word-break: break-all;
}

.media-gallery-inline-link:hover {
  text-decoration: underline;
}

.media-gallery-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 2px;
}

.media-gallery-thumb {
  position: relative;
  aspect-ratio: 1;
  padding: 0;
  border: 0;
  border-radius: 12px;
  overflow: hidden;
  cursor: pointer;
  background: rgba(15, 23, 42, 0.5);
}

.media-gallery-thumb:hover,
.media-gallery-thumb:focus-visible {
  transform: translateY(-1px);
  outline: none;
}

.media-gallery-thumb::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(2, 6, 23, 0.04), rgba(2, 6, 23, 0.42));
  pointer-events: none;
}

.media-gallery-thumb-meta {
  position: absolute;
  inset-inline-end: 6px;
  bottom: 6px;
  z-index: 1;
  font-size: 9px;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.82);
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.55);
}

.media-gallery-doc-item,
.media-gallery-link-item {
  text-decoration: none;
}

.media-gallery-doc-item:hover,
.media-gallery-link-item:hover {
  background: rgba(15, 23, 42, 0.56);
}

.media-gallery-doc-icon,
.media-gallery-voice-icon {
  width: 44px;
  min-width: 44px;
  height: 44px;
  border-radius: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(56, 189, 248, 0.12);
  color: #e0f2fe;
  font-size: 20px;
}

.media-gallery-link-favicon {
  width: 20px;
  min-width: 20px;
  height: 20px;
  margin-top: 3px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.06);
}

.media-gallery-link-url {
  font-size: 13px;
  font-weight: 700;
  color: #7dd3fc;
  line-height: 1.45;
  word-break: break-all;
}

.media-gallery-voice-player {
  width: 100%;
  margin-top: 6px;
  filter: saturate(0.92) brightness(0.95);
}

.media-gallery-lightbox {
  position: fixed;
  inset: 0;
  z-index: 900;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(2, 6, 23, 0.92);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.media-gallery-lightbox.is-visible {
  opacity: 1;
  pointer-events: auto;
}

.media-gallery-lightbox-panel {
  position: relative;
  width: min(920px, 100%);
  max-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.media-gallery-lightbox-close {
  position: absolute;
  top: -10px;
  inset-inline-end: -10px;
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.82);
  color: #f8fafc;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
}

.media-gallery-lightbox-content {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.media-gallery-lightbox-image,
.media-gallery-lightbox-video {
  max-width: min(92vw, 920px);
  max-height: 78vh;
  border-radius: 18px;
  box-shadow: 0 22px 60px rgba(2, 6, 23, 0.44);
}

.media-gallery-lightbox-meta {
  width: 100%;
  text-align: center;
  color: rgba(226, 232, 240, 0.88);
  font-size: 13px;
  line-height: 1.6;
}

@media (max-width: 720px) {
  .media-gallery-drawer {
    width: 100%;
  }

  .media-gallery-tabs {
    padding-inline: 8px;
  }

  .media-gallery-content {
    padding: 10px;
  }

  .media-gallery-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .media-gallery-lightbox {
    padding: 12px;
  }

  .media-gallery-lightbox-close {
    top: 8px;
    inset-inline-end: 8px;
  }
}
