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

:root {
  --bg: #111b21;
  --bg-secondary: #1f2c33;
  --bg-hover: #2a3942;
  --bg-chat: #0b141a;
  --border: #2a3942;
  --text: #e9edef;
  --text-secondary: #8696a0;
  --green: #00a884;
  --green-dark: #005c4b;
  --green-light: #025144;
  --blue: #53bdeb;
  --orange: #f59e0b;
  --incoming: #1f2c33;
  --outgoing: #005c4b;
  --danger: #ef4444;
  --radius: 8px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
}

/* === LOGIN === */
#login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  background: linear-gradient(135deg, var(--bg) 0%, var(--bg-secondary) 100%);
}

.login-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 40px;
  width: 380px;
}

.login-card h1 {
  font-size: 22px;
  margin-bottom: 8px;
  color: var(--green);
}

.login-card p {
  color: var(--text-secondary);
  font-size: 14px;
  margin-bottom: 24px;
}

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.form-group input {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 14px;
  outline: none;
}

.form-group input:focus {
  border-color: var(--green);
}

.btn {
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius);
  font-size: 14px;
  cursor: pointer;
  font-weight: 500;
  transition: opacity 0.2s;
}

.btn:hover { opacity: 0.9; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
  background: var(--green);
  color: #fff;
  width: 100%;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 12px;
}

.login-error {
  color: var(--danger);
  font-size: 13px;
  margin-top: 12px;
  display: none;
}

/* === DASHBOARD === */
#dashboard {
  display: none;
  height: 100vh;
  height: 100dvh;
  flex-direction: column;
}

/* Stats Bar */
.stats-bar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 20px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  min-height: 52px;
}

.stats-bar .logo {
  font-weight: 700;
  font-size: 15px;
  color: var(--green);
  margin-right: auto;
  white-space: nowrap;
}

.stat-group {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  border-radius: 6px;
  background: var(--bg);
}

.stat-group-header {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.stat-group.meta .stat-group-header {
  color: var(--orange);
}

.stat-group.google .stat-group-header {
  color: #4285f4;
}

.stat-group-row {
  display: flex;
  align-items: baseline;
  gap: 6px;
}

.stat-big {
  font-weight: 700;
  font-size: 16px;
  color: var(--text);
}

.stat-small {
  font-size: 11px;
  color: var(--text-secondary);
}

.stat-divider {
  width: 1px;
  height: 28px;
  background: var(--border);
}

.stat-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-secondary);
  white-space: nowrap;
}

.stat-item .stat-value {
  font-weight: 600;
  color: var(--text);
}

.stat-item.highlight .stat-value {
  color: var(--orange);
}

.btn-logout {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  padding: 6px 14px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 12px;
}

.btn-logout:hover {
  border-color: var(--danger);
  color: var(--danger);
}

/* Main layout */
.main-layout {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* === LEFT SIDEBAR === */
.sidebar {
  width: 360px;
  min-width: 360px;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}

.sidebar-header {
  padding: 12px;
  border-bottom: 1px solid var(--border);
}

.search-box {
  width: 100%;
  padding: 8px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 13px;
  outline: none;
}

.search-box:focus { border-color: var(--green); }

.filter-tabs {
  display: flex;
  padding: 8px 12px;
  gap: 4px;
  border-bottom: 1px solid var(--border);
}

.filter-tab {
  padding: 5px 12px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 12px;
  border-radius: 20px;
  cursor: pointer;
  white-space: nowrap;
}

.filter-tab.active {
  background: var(--green-dark);
  color: var(--green);
}

.filter-tab:hover:not(.active) {
  background: var(--bg-hover);
}

.filter-tab.meta.active {
  background: rgba(245, 158, 11, 0.15);
  color: var(--orange);
}

.filter-tab.google.active {
  background: rgba(66, 133, 244, 0.15);
  color: #4285f4;
}

.conversation-list {
  flex: 1;
  overflow-y: auto;
}

.conv-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
}

.conv-item:hover { background: var(--bg-hover); }
.conv-item.active { background: var(--bg-hover); }

.conv-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--bg-hover);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}

.conv-avatar.ad { background: var(--orange); color: #000; font-size: 14px; }
.conv-avatar.google { background: var(--blue); color: #000; font-size: 14px; }

.conv-info {
  flex: 1;
  min-width: 0;
}

.conv-name {
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conv-preview {
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}

.conv-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  flex-shrink: 0;
}

.conv-time {
  font-size: 11px;
  color: var(--text-secondary);
}

.conv-badge {
  background: var(--green);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  border-radius: 50%;
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.source-tag {
  display: inline-block;
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 10px;
  font-weight: 600;
}

.source-tag.ad { background: var(--orange); color: #000; }
.source-tag.google { background: var(--blue); color: #000; }
.source-tag.organic { background: var(--border); color: var(--text-secondary); }
.source-tag.blocked { background: var(--danger); color: #fff; }

/* === RIGHT PANEL === */
.chat-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg-chat);
}

.chat-empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  font-size: 14px;
}

.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
}

.chat-header-info {
  flex: 1;
}

.chat-header-name {
  font-size: 15px;
  font-weight: 500;
}

.chat-header-phone {
  font-size: 12px;
  color: var(--text-secondary);
}

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

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 60px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.message-bubble {
  max-width: 65%;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 14px;
  line-height: 1.4;
  position: relative;
  word-wrap: break-word;
}

.message-bubble.incoming {
  background: var(--incoming);
  align-self: flex-start;
  border-top-left-radius: 0;
}

.message-bubble.outgoing {
  background: var(--outgoing);
  align-self: flex-end;
  border-top-right-radius: 0;
}

.message-time {
  font-size: 10px;
  color: var(--text-secondary);
  margin-top: 4px;
  text-align: right;
}

.message-status {
  font-size: 10px;
  margin-left: 4px;
}

.message-status.delivered { color: var(--text-secondary); }
.message-status.read { color: var(--blue); }
.message-status.failed { color: var(--danger); }

/* Chat error banner */
.chat-error-banner {
  background: rgba(239, 68, 68, 0.15);
  border: 1px solid rgba(239, 68, 68, 0.3);
  border-radius: var(--radius);
  padding: 10px 14px;
  margin: 8px 0;
  font-size: 12px;
  color: #fca5a5;
  text-align: center;
  align-self: center;
}

.chat-error-banner strong {
  color: var(--danger);
}

.chat-progress-banner {
  background: rgba(37, 211, 102, 0.12);
  border: 1px solid rgba(37, 211, 102, 0.25);
  border-radius: var(--radius);
  padding: 10px 14px;
  margin: 8px 0;
  font-size: 12px;
  color: var(--green);
  text-align: center;
  align-self: center;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.progress-spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid rgba(37, 211, 102, 0.3);
  border-top-color: var(--green);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* Chat input */
.chat-input-area {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 20px;
  padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
}

.chat-input {
  flex: 1;
  padding: 10px 16px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 24px;
  color: var(--text);
  font-size: 14px;
  outline: none;
  resize: none;
  max-height: 120px;
  line-height: 1.4;
}

.chat-input:focus { border-color: var(--green); }

.btn-send {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--green);
  border: none;
  color: #fff;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.btn-send:hover { opacity: 0.9; }
.btn-send:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-danger {
  background: var(--danger);
  color: #fff;
}

.btn-danger:hover { opacity: 0.85; }

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-secondary); }

/* Referral info banner */
.referral-banner {
  background: var(--green-light);
  border: 1px solid var(--green-dark);
  border-radius: var(--radius);
  padding: 10px 14px;
  margin: 8px 60px;
  font-size: 12px;
  color: var(--text-secondary);
}

.referral-banner strong { color: var(--orange); }

/* Loading spinner */
.spinner {
  width: 24px;
  height: 24px;
  border: 3px solid var(--border);
  border-top-color: var(--green);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 20px auto;
}

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

/* New message compose */
.new-msg-form {
  display: flex;
  gap: 8px;
  padding: 12px 20px;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  align-items: center;
}

.new-msg-form input {
  flex: 1;
  padding: 8px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 13px;
  outline: none;
}

.new-msg-form input:focus { border-color: var(--green); }

/* === SETTINGS BUTTON === */
.btn-settings {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  padding: 6px 10px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
}

.btn-settings:hover {
  border-color: var(--green);
  color: var(--green);
}

/* === MODAL === */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: 480px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
}

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

.modal-header h2 {
  font-size: 16px;
  font-weight: 600;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 22px;
  cursor: pointer;
  padding: 0 4px;
}

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

.modal-body {
  padding: 20px;
  overflow-y: auto;
}

.modal-body .form-group {
  margin-bottom: 14px;
}

.modal-body textarea {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 14px;
  outline: none;
  resize: vertical;
  font-family: inherit;
}

.modal-body textarea:focus { border-color: var(--green); }

.modal-body select {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 14px;
  outline: none;
}

.modal-body select:focus { border-color: var(--green); }

/* Profile picture */
.profile-pic-section {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.profile-pic-preview {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: var(--bg-hover);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  color: var(--text-secondary);
  overflow: hidden;
  flex-shrink: 0;
}

.profile-pic-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.profile-pic-actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.profile-pic-hint {
  font-size: 11px;
  color: var(--text-secondary);
}

.profile-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 8px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.profile-msg {
  font-size: 13px;
  flex: 1;
}

.profile-msg.success { color: var(--green); }
.profile-msg.error { color: var(--danger); }

/* === NEW CHAT BUTTON === */
.btn-new-chat {
  width: 36px;
  height: 36px;
  border-radius: var(--radius);
  background: var(--green);
  border: none;
  color: #fff;
  font-size: 20px;
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.btn-new-chat:hover { opacity: 0.9; }

/* New chat compose panel */
.new-chat-panel {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.new-chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
}

.new-chat-header h3 {
  font-size: 15px;
  font-weight: 500;
  flex: 1;
}

.new-chat-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 20px;
  gap: 14px;
}

.new-chat-body .form-group {
  margin-bottom: 0;
}

.new-chat-body .form-group input,
.new-chat-body .form-group textarea {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 14px;
  outline: none;
  font-family: inherit;
}

.new-chat-body .form-group input:focus,
.new-chat-body .form-group textarea:focus {
  border-color: var(--green);
}

.new-chat-body .form-group textarea {
  resize: vertical;
  min-height: 80px;
}

.new-chat-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.new-chat-msg {
  font-size: 13px;
  flex: 1;
}

.new-chat-msg.error { color: var(--danger); }
.new-chat-msg.success { color: var(--green); }

/* === IMAGE PREVIEW === */
.image-preview-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 20px;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
}

.image-preview-thumb {
  width: 48px;
  height: 48px;
  border-radius: 6px;
  object-fit: cover;
  border: 1px solid var(--border);
}

.image-preview-info {
  flex: 1;
  font-size: 13px;
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.image-preview-remove {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 18px;
  cursor: pointer;
  padding: 4px;
}

.image-preview-remove:hover { color: var(--danger); }

/* File attach button */
.btn-attach {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.btn-attach:hover {
  border-color: var(--green);
  color: var(--green);
}

/* === MEDIA MESSAGES === */
.media-message {
  cursor: pointer;
  border-radius: 6px;
  overflow: hidden;
  max-width: 280px;
}

.media-message img.message-image {
  display: block;
  max-width: 280px;
  max-height: 300px;
  border-radius: 6px;
  object-fit: cover;
}

.media-message video.message-video {
  display: block;
  max-width: 280px;
  max-height: 300px;
  border-radius: 6px;
  background: #000;
}

.media-caption {
  padding: 4px 0 0;
  font-size: 13px;
  line-height: 1.3;
}

.media-message.doc {
  cursor: default;
}

.doc-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: rgba(255,255,255,0.05);
  border-radius: 6px;
  text-decoration: none;
  color: var(--text);
  border: 1px solid var(--border);
}

.doc-link:hover {
  background: rgba(255,255,255,0.1);
}

.doc-icon {
  font-size: 28px;
  flex-shrink: 0;
}

/* === LIGHTBOX === */
.lightbox-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  cursor: pointer;
}

.lightbox-overlay img {
  max-width: 90vw;
  max-height: 90vh;
  object-fit: contain;
  border-radius: 4px;
  cursor: default;
}

.lightbox-close {
  position: absolute;
  top: 16px;
  right: 24px;
  background: none;
  border: none;
  color: #fff;
  font-size: 32px;
  cursor: pointer;
  z-index: 2001;
  opacity: 0.8;
}

.lightbox-close:hover { opacity: 1; }

/* === MOBILE BACK BUTTON === */
.btn-back {
  display: none;
  background: none;
  border: none;
  color: var(--text);
  font-size: 20px;
  cursor: pointer;
  padding: 4px;
  flex-shrink: 0;
}

/* === MOBILE RESPONSIVE === */
@media (max-width: 768px) {
  /* Stats bar: horizontal scroll, compact */
  .stats-bar {
    gap: 12px;
    padding: 8px 12px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .stats-bar .logo {
    font-size: 14px;
    margin-right: 0;
  }

  .stat-item {
    font-size: 12px;
    gap: 4px;
  }

  .stat-group {
    padding: 4px 10px;
    gap: 6px;
  }

  .stat-big {
    font-size: 14px;
  }

  .stat-small {
    font-size: 10px;
  }

  .stat-group-header {
    font-size: 10px;
  }

  /* Main layout: stack instead of side-by-side */
  .main-layout {
    position: relative;
  }

  /* Sidebar: full width */
  .sidebar {
    width: 100%;
    min-width: 100%;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 10;
    transition: transform 0.25s ease;
  }

  /* Chat panel: full width */
  .chat-panel {
    width: 100%;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 5;
  }

  /* Mobile view states - controlled via .mobile-chat-open on .main-layout */
  .main-layout .sidebar {
    transform: translateX(0);
  }

  .main-layout.mobile-chat-open .sidebar {
    transform: translateX(-100%);
  }

  .main-layout.mobile-chat-open .chat-panel {
    z-index: 15;
  }

  /* Back button visible on mobile */
  .btn-back {
    display: flex;
    align-items: center;
    justify-content: center;
  }

  /* Chat header: compact */
  .chat-header {
    gap: 8px;
    padding: 10px 12px;
  }

  .chat-header-actions {
    gap: 4px;
    flex-wrap: wrap;
    justify-content: flex-end;
  }

  .chat-header-actions .btn-sm {
    padding: 5px 8px;
    font-size: 11px;
  }

  /* Chat messages: less padding */
  .chat-messages {
    padding: 12px 12px;
  }

  .message-bubble {
    max-width: 85%;
  }

  /* Chat input: compact */
  .chat-input-area {
    gap: 8px;
    padding: 8px 10px;
  }

  .chat-input {
    padding: 8px 12px;
    font-size: 14px;
  }

  .btn-send {
    width: 38px;
    height: 38px;
    font-size: 16px;
  }

  .btn-attach {
    width: 38px;
    height: 38px;
    font-size: 18px;
  }

  /* Media messages: fit mobile */
  .media-message {
    max-width: 240px;
  }

  .media-message img.message-image {
    max-width: 240px;
    max-height: 260px;
  }

  .media-message video.message-video {
    max-width: 240px;
    max-height: 260px;
  }

  /* Image preview bar: compact */
  .image-preview-bar {
    padding: 8px 10px;
  }

  /* Referral banner: less margin */
  .referral-banner {
    margin: 8px 12px;
  }

  /* Login card: responsive */
  .login-card {
    width: calc(100% - 32px);
    max-width: 380px;
    padding: 28px 24px;
  }

  /* Modal: full width */
  .modal-card {
    width: calc(100% - 24px);
    max-height: 90vh;
    border-radius: 10px;
  }

  /* Conversation list items: compact */
  .conv-item {
    padding: 10px 12px;
    gap: 10px;
  }

  .conv-avatar {
    width: 40px;
    height: 40px;
    font-size: 16px;
  }

  /* New chat panel */
  .new-chat-body {
    padding: 16px 12px;
  }
}

/* Extra small screens (iPhone SE etc.) */
@media (max-width: 380px) {
  .stats-bar {
    gap: 8px;
    padding: 6px 8px;
  }

  .stat-item span:first-child {
    display: none;
  }

  .chat-header-actions .btn-sm {
    padding: 4px 6px;
    font-size: 10px;
  }

  .chat-messages {
    padding: 8px 8px;
  }

  .message-bubble {
    max-width: 90%;
    font-size: 13px;
  }
}

/* === MEDIA LIBRARY === */
.btn-media-library {
  width: 36px;
  height: 36px;
  border-radius: var(--radius);
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-media-library:hover {
  border-color: var(--green);
  color: var(--green);
}

/* Media Library Modal */
.media-library-modal .modal-card {
  width: 800px;
  max-width: 95vw;
  max-height: 85vh;
}

.media-library-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  gap: 12px;
}

.media-library-tabs {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.media-library-tabs .ml-tab {
  padding: 6px 14px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-secondary);
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
}

.media-library-tabs .ml-tab:hover {
  border-color: var(--text-secondary);
  color: var(--text);
}

.media-library-tabs .ml-tab.active {
  background: var(--green-dark);
  border-color: var(--green);
  color: var(--green);
}

.media-library-upload-btn {
  padding: 6px 14px;
  border-radius: 20px;
  background: var(--green-dark);
  border: 1px solid var(--green);
  color: var(--green);
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
}

.media-library-upload-btn:hover {
  background: var(--green);
  color: #000;
}

.media-library-body {
  padding: 16px 20px;
  overflow-y: auto;
  flex: 1;
}

.media-library-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}

.media-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: border-color 0.15s;
}

.media-card:hover {
  border-color: var(--text-secondary);
}

.media-card.selectable {
  cursor: pointer;
}

.media-card.selectable:hover {
  border-color: var(--green);
}

.media-card-thumb {
  width: 100%;
  height: 120px;
  background: var(--bg-hover);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.media-card-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.media-card-thumb .thumb-icon {
  font-size: 36px;
  opacity: 0.5;
}

.media-card-info {
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.media-card-name {
  font-size: 12px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.media-card-meta {
  font-size: 11px;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.media-card-actions {
  display: flex;
  gap: 4px;
}

.media-card-actions button {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 13px;
  padding: 2px 4px;
  border-radius: 4px;
}

.media-card-actions button:hover {
  color: var(--danger);
  background: rgba(239, 68, 68, 0.1);
}

.media-card-actions .btn-select-media {
  color: var(--green);
  font-size: 11px;
  font-weight: 600;
}

.media-card-actions .btn-select-media:hover {
  background: rgba(0, 168, 132, 0.1);
  color: var(--green);
}

.media-library-empty {
  text-align: center;
  color: var(--text-secondary);
  padding: 40px 20px;
  font-size: 14px;
}

/* Attach Dropdown Menu */
.attach-menu-wrapper {
  position: relative;
}

.attach-menu {
  position: absolute;
  bottom: 50px;
  left: 0;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 4px 0;
  min-width: 180px;
  z-index: 100;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

.attach-menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}

.attach-menu-item:hover {
  background: var(--bg-hover);
}

.attach-menu-item .menu-icon {
  font-size: 16px;
  width: 20px;
  text-align: center;
}

/* Media Library Modal responsive */
@media (max-width: 768px) {
  .media-library-modal .modal-card {
    width: 100%;
    max-width: 100%;
    height: 100vh;
    max-height: 100vh;
    border-radius: 0;
  }

  .media-library-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .media-library-header-row {
    flex-direction: column;
    align-items: stretch;
  }

  .media-library-tabs {
    justify-content: center;
  }

  .media-library-upload-btn {
    text-align: center;
  }
}

@media (max-width: 380px) {
  .media-library-grid {
    grid-template-columns: 1fr;
  }
}

/* === AI Bot Styles === */

/* Bot indicator in conversation list */
.bot-indicator {
  font-size: 12px;
  line-height: 1;
  opacity: 0.4;
}
.bot-indicator.active {
  opacity: 1;
}

/* Bot toggle button in chat header */
.btn-bot {
  background: var(--border) !important;
  color: var(--text-secondary) !important;
  font-size: 12px;
  gap: 2px;
}
.btn-bot.active {
  background: rgba(0, 168, 132, 0.2) !important;
  color: var(--green) !important;
}

/* AI settings button in stats bar */
.btn-ai-settings {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 20px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  transition: background 0.2s;
}
.btn-ai-settings:hover {
  background: var(--bg-hover);
  color: var(--text);
}

/* Toggle switch for AI enabled */
.toggle-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 500;
  color: var(--text);
}
.switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
}
.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}
.slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: var(--border);
  border-radius: 24px;
  transition: 0.3s;
}
.slider::before {
  content: "";
  position: absolute;
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background: white;
  border-radius: 50%;
  transition: 0.3s;
}
.switch input:checked + .slider {
  background: var(--green);
}
.switch input:checked + .slider::before {
  transform: translateX(20px);
}

/* === REPLY/QUOTE FEATURE === */

/* Reply button on message hover */
.message-bubble {
  position: relative;
}

.reply-btn {
  position: absolute;
  top: 4px;
  opacity: 0;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  width: 28px;
  height: 28px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  transition: opacity 0.15s;
  z-index: 5;
}

.message-bubble.incoming .reply-btn {
  right: -36px;
}

.message-bubble.outgoing .reply-btn {
  left: -36px;
}

.message-bubble:hover .reply-btn {
  opacity: 1;
}

.reply-btn:hover {
  background: var(--bg-hover);
  color: var(--green);
  border-color: var(--green);
}

/* Quoted message inside bubble */
.quoted-message {
  background: rgba(0, 0, 0, 0.15);
  border-left: 3px solid var(--green);
  border-radius: 4px;
  padding: 5px 8px;
  margin-bottom: 6px;
  font-size: 12px;
  color: var(--text-secondary);
  max-height: 48px;
  overflow: hidden;
  cursor: pointer;
}

.message-bubble.outgoing .quoted-message {
  background: rgba(0, 0, 0, 0.2);
}

.quoted-message-text {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Reply preview bar above input */
.reply-preview-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 20px;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  border-left: 3px solid var(--green);
}

.reply-preview-content {
  flex: 1;
  min-width: 0;
}

.reply-preview-label {
  font-size: 11px;
  color: var(--green);
  font-weight: 600;
  margin-bottom: 2px;
}

.reply-preview-text {
  font-size: 13px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.reply-preview-close {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 18px;
  cursor: pointer;
  padding: 4px;
  flex-shrink: 0;
}

.reply-preview-close:hover {
  color: var(--danger);
}

@media (max-width: 768px) {
  .reply-preview-bar {
    padding: 8px 10px;
  }

  .reply-btn {
    opacity: 0.5;
    width: 24px;
    height: 24px;
    font-size: 12px;
  }

  .message-bubble.incoming .reply-btn {
    right: -28px;
  }

  .message-bubble.outgoing .reply-btn {
    left: -28px;
  }
}
