/* ══════════════════════════════════════════════
   WhatsApp AI Agent — Apple-Style Dashboard
   Dual Theme: Light (default) / Dark
   ══════════════════════════════════════════════ */

/* ── Light Theme (default) ── */
:root {
  --bg-primary: #f5f5f7;
  --bg-secondary: #ffffff;
  --bg-tertiary: #f0f0f2;
  --bg-card: #ffffff;
  --bg-hover: rgba(0, 0, 0, 0.04);
  --bg-input: #f5f5f7;

  --text-primary: rgba(0, 0, 0, 0.85);
  --text-secondary: rgba(0, 0, 0, 0.55);
  --text-muted: rgba(0, 0, 0, 0.35);

  --accent: #0A84FF;
  --accent-dim: rgba(10, 132, 255, 0.1);
  --accent-green: #34C759;
  --accent-green-dim: rgba(52, 199, 89, 0.1);
  --accent-orange: #FF9F0A;
  --accent-orange-dim: rgba(255, 159, 10, 0.1);
  --accent-red: #FF3B30;
  --accent-red-dim: rgba(255, 59, 48, 0.1);
  --accent-purple: #AF52DE;
  --accent-purple-dim: rgba(175, 82, 222, 0.1);

  --border: rgba(0, 0, 0, 0.06);
  --border-light: rgba(0, 0, 0, 0.1);

  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.08);

  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 18px;
  --radius-xl: 24px;

  --sidebar-width: 240px;
  --transition: all 0.3s cubic-bezier(0.25, 0.1, 0.25, 1);

  --phone-header: #075e54;
  --phone-bg: #e5ddd5;
  --phone-msg-out: #dcf8c6;
  --phone-msg-out-text: #111;
  --phone-msg-in: #ffffff;
  --phone-msg-in-text: #111;
}

/* ── Dark Theme ── */
[data-theme="dark"] {
  --bg-primary: #1c1c1e;
  --bg-secondary: #2c2c2e;
  --bg-tertiary: #3a3a3c;
  --bg-card: #2c2c2e;
  --bg-hover: rgba(255, 255, 255, 0.06);
  --bg-input: #1c1c1e;

  --text-primary: rgba(255, 255, 255, 0.87);
  --text-secondary: rgba(255, 255, 255, 0.55);
  --text-muted: rgba(255, 255, 255, 0.3);

  --border: rgba(255, 255, 255, 0.06);
  --border-light: rgba(255, 255, 255, 0.1);

  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.2);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.4);

  --phone-header: #1f2c34;
  --phone-bg: #0b141a;
  --phone-msg-out: #054d29;
  --phone-msg-out-text: rgba(255, 255, 255, 0.87);
  --phone-msg-in: #1e2a30;
  --phone-msg-in-text: rgba(255, 255, 255, 0.87);
}

/* ── Reset & Base ── */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'SF Pro Display', sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  display: flex;
}

/* ── Scrollbar ── */
::-webkit-scrollbar {
  width: 5px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border-light);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* ══════════════════════════════════════════════
   SVG ICON BASE
   ══════════════════════════════════════════════ */

.icon {
  width: 20px;
  height: 20px;
  stroke: currentColor;
  stroke-width: 1.5;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex-shrink: 0;
}

.icon-sm {
  width: 16px;
  height: 16px;
}

.icon-lg {
  width: 28px;
  height: 28px;
  stroke-width: 1.2;
}

.icon-xl {
  width: 36px;
  height: 36px;
  stroke-width: 1;
}

/* ══════════════════════════════════════════════
   SIDEBAR
   ══════════════════════════════════════════════ */

.sidebar {
  width: var(--sidebar-width);
  height: 100vh;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.sidebar-header {
  padding: 24px 20px;
}

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

.logo-icon {
  color: var(--accent);
}

.logo-text {
  font-size: 16px;
  font-weight: 500;
  letter-spacing: -0.3px;
  color: var(--text-primary);
}

.sidebar-nav {
  flex: 1;
  padding: 8px 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 12px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 13px;
  font-weight: 400;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: var(--transition);
  position: relative;
  letter-spacing: -0.1px;
}

.nav-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.nav-btn.active {
  background: var(--accent-dim);
  color: var(--accent);
  font-weight: 500;
}

.nav-icon {
  display: flex;
  align-items: center;
  transition: var(--transition);
}

.badge {
  margin-left: auto;
  background: var(--accent-red);
  color: white;
  font-size: 10px;
  font-weight: 500;
  padding: 1px 6px;
  border-radius: 10px;
  min-width: 18px;
  text-align: center;
  line-height: 1.5;
}

/* WA Status Indicator */
.wa-status {
  margin-top: 10px;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  background: var(--bg-tertiary);
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-secondary);
  border: 1px solid var(--border-light);
  transition: var(--transition);
}

.wa-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  background: #9ca3af;
  /* default grey */
}

.wa-status-ready .wa-status-dot {
  background: #4ade80;
  /* pastel green */
}

.wa-status-disconnected .wa-status-dot {
  background-color: var(--accent-red, #ef4444);
}

.wa-status-connecting .wa-status-dot {
  background-color: var(--accent-orange, #f59e0b);
  animation: pulse 1.5s infinite;
}

.wa-status-auth_failure .wa-status-dot {
  background-color: var(--accent-red, #ef4444);
}

.wa-status-qr_ready .wa-status-dot {
  background-color: var(--accent-blue, #3b82f6);
  animation: pulse 1.5s infinite;
}

.sidebar-footer {
  padding: 12px 12px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* ── Profile button (sidebar) ── */
.profile-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 10px;
  border-radius: 10px;
  border: none;
  background: transparent;
  cursor: pointer;
  color: var(--text-primary);
  transition: background 0.15s;
  text-align: left;
}
.profile-btn:hover { background: var(--bg-hover, rgba(0,0,0,0.05)); }

.profile-avatar {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  letter-spacing: 0.5px;
}
.profile-info {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
}
.profile-name {
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.profile-role {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: capitalize;
}
.profile-chevron {
  color: var(--text-muted);
  flex-shrink: 0;
  transition: transform 0.2s;
}
.profile-btn.open .profile-chevron { transform: rotate(180deg); }

.sidebar-footer-icons {
  display: flex;
  justify-content: flex-end;
  gap: 4px;
}

/* ── Profile Popover ── */
.profile-popover {
  position: fixed;
  bottom: 80px;
  left: 16px;
  width: 280px;
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: 16px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.18);
  z-index: 1000;
  padding: 6px;
  display: none;
  flex-direction: column;
  gap: 2px;
  animation: popover-in 0.18s ease;
}
.profile-popover.open { display: flex; }

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

.profile-popover-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 999;
}
.profile-popover-backdrop.open { display: block; }

/* Header */
.pp-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
}
.pp-avatar {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.pp-user-info { flex: 1; min-width: 0; }
.pp-user-name {
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.pp-user-email {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.pp-role-badge {
  font-size: 10px;
  padding: 2px 7px;
  border-radius: 20px;
  background: rgba(0,122,255,0.1);
  color: var(--accent);
  font-weight: 600;
  white-space: nowrap;
  text-transform: capitalize;
}

.pp-divider {
  height: 1px;
  background: var(--border-light);
  margin: 4px 0;
}

/* Plan section */
.pp-section { padding: 8px 12px; display: flex; flex-direction: column; gap: 6px; }
.pp-section-label { font-size: 11px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; }
.pp-plan-row { display: flex; align-items: center; justify-content: space-between; }
.pp-plan-limit { font-size: 12px; color: var(--text-secondary); }

.pp-usage-bar-track {
  width: 100%;
  height: 6px;
  background: var(--border-light);
  border-radius: 3px;
  overflow: hidden;
}
.pp-usage-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 3px;
  transition: width 0.4s ease;
}
.pp-usage-label { font-size: 11px; color: var(--text-muted); }

.pp-upgrade-btn {
  width: 100%;
  padding: 8px;
  border-radius: 8px;
  border: none;
  background: linear-gradient(135deg, #007AFF, #5856D6);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
}
.pp-upgrade-btn:hover { opacity: 0.9; }

/* Action buttons */
.pp-action-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 12px;
  border: none;
  background: transparent;
  border-radius: 10px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-primary);
  transition: background 0.15s;
  text-align: left;
}
.pp-action-btn:hover { background: var(--bg-hover, rgba(0,0,0,0.05)); }
.pp-logout-btn { color: #ef4444; }
.pp-logout-btn:hover { background: rgba(239,68,68,0.08); }

/* Password form */
.pp-password-form {
  padding: 4px 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.pp-input {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border-light);
  border-radius: 8px;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 13px;
  box-sizing: border-box;
}
.pp-input:focus { outline: none; border-color: var(--accent); }
.pp-save-btn {
  padding: 8px;
  border-radius: 8px;
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
}
.pp-save-btn:hover { opacity: 0.85; }

.status-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 400;
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent-green);
  animation: pulse-dot 3s ease infinite;
}

@keyframes pulse-dot {

  0%,
  100% {
    opacity: 1;
  }

  50% {
    opacity: 0.4;
  }
}

/* ── Theme Toggle ── */
.theme-toggle {
  width: 32px;
  height: 32px;
  border: none;
  background: var(--bg-hover);
  color: var(--text-secondary);
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}

.theme-toggle:hover {
  background: var(--accent-dim);
  color: var(--accent);
}

.theme-toggle .icon-sun,
.theme-toggle .icon-moon {
  transition: var(--transition);
}

/* Show sun in dark mode, moon in light mode */
.theme-toggle .icon-sun {
  display: none;
}

.theme-toggle .icon-moon {
  display: flex;
}

[data-theme="dark"] .theme-toggle .icon-sun {
  display: flex;
}

[data-theme="dark"] .theme-toggle .icon-moon {
  display: none;
}

/* ══════════════════════════════════════════════
   MAIN CONTENT
   ══════════════════════════════════════════════ */

.main-content {
  flex: 1;
  height: 100vh;
  overflow-y: auto;
  padding: 40px;
}

.view {
  display: none;
}

.view.active {
  display: block;
  animation: fadeIn 0.4s ease;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(6px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.view-header {
  margin-bottom: 32px;
}

.view-header h1 {
  font-size: 28px;
  font-weight: 600;
  letter-spacing: -0.5px;
  margin-bottom: 4px;
  color: var(--text-primary);
}

.subtitle {
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 300;
  letter-spacing: -0.1px;
}

/* ── Stats Grid ── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 40px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 22px;
  display: flex;
  align-items: center;
  gap: 16px;
  transition: var(--transition);
  box-shadow: var(--shadow-sm);
}

.stat-card:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.stat-total .stat-icon {
  color: var(--accent);
}

.stat-auto .stat-icon {
  color: var(--accent-green);
}

.stat-pending .stat-icon {
  color: var(--accent-orange);
}

.stat-rate .stat-icon {
  color: var(--accent-purple);
}

.stat-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.7;
}

.stat-info {
  display: flex;
  flex-direction: column;
}

.stat-number {
  font-size: 26px;
  font-weight: 600;
  letter-spacing: -0.5px;
  line-height: 1;
  color: var(--text-primary);
}

.stat-label {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
  font-weight: 400;
  letter-spacing: -0.1px;
}

/* ── Analytics / Chart Section ── */
.analytics-section {
  margin-bottom: 40px;
}

.analytics-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.analytics-header h2 {
  font-size: 17px;
  font-weight: 500;
  letter-spacing: -0.2px;
}

.chart-tabs {
  display: flex;
  gap: 4px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-sm);
  padding: 3px;
}

.chart-tab {
  background: transparent;
  border: none;
  font-family: inherit;
  font-size: 12px;
  font-weight: 400;
  color: var(--text-secondary);
  padding: 5px 12px;
  border-radius: 7px;
  cursor: pointer;
  transition: var(--transition);
}

.chart-tab:hover {
  color: var(--text-primary);
}

.chart-tab.active {
  background: var(--bg-card);
  color: var(--text-primary);
  font-weight: 500;
  box-shadow: var(--shadow-sm);
}

.chart-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 24px;
  box-shadow: var(--shadow-sm);
  position: relative;
  min-height: 160px;
}

.chart-empty {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 13px;
  gap: 8px;
}

.chart-empty span {
  font-size: 28px;
  opacity: 0.3;
}

/* ── Categories Section ── */
.categories-section h2 {
  font-size: 17px;
  font-weight: 500;
  margin-bottom: 16px;
  letter-spacing: -0.2px;
}

.categories-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
}

.category-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  transition: var(--transition);
  box-shadow: var(--shadow-sm);
}

.category-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.category-emoji {
  font-size: 22px;
}

.category-info {
  flex: 1;
}

.category-name {
  font-size: 13px;
  font-weight: 400;
  margin-bottom: 2px;
  color: var(--text-secondary);
}

.category-count {
  font-size: 20px;
  font-weight: 500;
  color: var(--accent);
}

/* ── Empty State ── */
.empty-state {
  color: var(--text-muted);
  text-align: center;
  padding: 48px 20px;
  font-size: 14px;
  font-weight: 300;
}

/* ══════════════════════════════════════════════
   CONVERSATIONS VIEW
   ══════════════════════════════════════════════ */

.conversations-layout {
  display: grid;
  grid-template-columns: 280px 1fr 300px;
  gap: 16px;
  height: calc(100vh - 160px);
}

.conv-left-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.conversations-list {
  flex: 1;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow-y: auto;
  padding: 8px;
  box-shadow: var(--shadow-sm);
}

.conv-item {
  padding: 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: var(--transition);
  display: flex;
  gap: 12px;
  border-bottom: 1px solid var(--border);
}

#conv-pagination {
  padding: 8px 4px 4px;
}

.conv-pag-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.conv-pag-info {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
}

.conv-item:last-child {
  border-bottom: none;
}

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

.conv-item.active {
  background: var(--accent-dim);
}

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

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

.conv-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}

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

.conv-time {
  font-size: 11px;
  color: var(--text-muted);
  flex-shrink: 0;
  font-weight: 400;
}

.conv-preview {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: 300;
}

.conv-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 10px;
  padding: 2px 8px;
  border-radius: 10px;
  font-weight: 500;
  margin-top: 4px;
}

.badge-auto {
  background: var(--accent-green-dim);
  color: var(--accent-green);
}

.badge-human {
  background: var(--accent-orange-dim);
  color: var(--accent-orange);
}

/* ── Panel Info (3rd column — contact & AI details) ── */
.panel-info {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.panel-info-placeholder {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  gap: 10px;
  font-size: 13px;
  text-align: center;
  padding: 20px;
}

.panel-info-content {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow-y: auto;
}

.panel-info-header {
  padding: 20px 16px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  text-align: center;
}

.panel-info-avatar {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--bg-tertiary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  margin-bottom: 4px;
}

.panel-info-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.2px;
}

.panel-info-phone {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 400;
}

.panel-info-section {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.panel-info-section:last-child {
  border-bottom: none;
}

.panel-info-section-title {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.7px;
  margin-bottom: 10px;
}

.panel-info-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  margin-bottom: 8px;
  gap: 8px;
}

.panel-info-row:last-child {
  margin-bottom: 0;
}

.panel-info-label {
  color: var(--text-muted);
  flex-shrink: 0;
}

.panel-info-value {
  color: var(--text-primary);
  font-weight: 500;
  text-align: right;
  word-break: break-word;
}

/* ── Conversation Detail ── */
.conversation-detail {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.detail-placeholder {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  gap: 12px;
}

.placeholder-icon {
  font-size: 40px;
  opacity: 0.2;
}

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

.detail-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.msg-bubble {
  max-width: 75%;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  font-size: 13px;
  line-height: 1.5;
  font-weight: 400;
  position: relative;
}

.msg-incoming {
  align-self: flex-start;
  background: var(--bg-tertiary);
  border-bottom-left-radius: 4px;
}

.msg-outgoing {
  align-self: flex-end;
  background: var(--accent-dim);
  color: var(--accent);
  border-bottom-right-radius: 4px;
}

.msg-meta {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
  margin-top: 4px;
  font-size: 10px;
  color: var(--text-muted);
}

.msg-sticker {
  display: block;
  width: 120px;
  height: 120px;
  object-fit: contain;
  border-radius: 8px;
  margin-bottom: 4px;
}

.msg-category-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 10px;
  padding: 2px 8px;
  border-radius: 8px;
  background: var(--accent-dim);
  color: var(--accent);
  margin-top: 6px;
  font-weight: 500;
}

/* ══════════════════════════════════════════════
   PENDING VIEW
   ══════════════════════════════════════════════ */

.pending-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.pending-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 22px;
  transition: var(--transition);
  box-shadow: var(--shadow-sm);
}

.pending-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.pending-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}

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

.pending-contact-name {
  font-weight: 500;
  font-size: 14px;
  letter-spacing: -0.1px;
}

.pending-contact-phone {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 300;
}

.pending-category {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  padding: 4px 12px;
  border-radius: 20px;
  font-weight: 500;
}

.pending-category.cat-queja {
  background: var(--accent-red-dim);
  color: var(--accent-red);
}

.pending-category.cat-reclamo {
  background: var(--accent-orange-dim);
  color: var(--accent-orange);
}

.pending-category.cat-garantia {
  background: var(--accent-purple-dim);
  color: var(--accent-purple);
}

.pending-category.cat-mayorista {
  background: var(--accent-dim);
  color: var(--accent);
}

.pending-message {
  background: var(--bg-tertiary);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  margin-bottom: 14px;
  font-size: 13px;
  line-height: 1.6;
  color: var(--text-secondary);
  font-weight: 400;
}

.pending-ai-suggestion {
  margin-bottom: 16px;
}

.pending-ai-suggestion label {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  display: block;
  margin-bottom: 6px;
}

.pending-ai-suggestion p {
  font-size: 13px;
  color: var(--accent);
  background: var(--accent-dim);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  line-height: 1.5;
  font-weight: 400;
}

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

/* ══════════════════════════════════════════════
   SIMULATOR VIEW
   ══════════════════════════════════════════════ */

.simulator-container {
  display: grid;
  grid-template-columns: 380px 1fr;
  gap: 20px;
  margin-bottom: 32px;
}

.simulator-phone {
  background: var(--bg-secondary);
  border-radius: var(--radius-lg);
  overflow: hidden;
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 500px;
  box-shadow: var(--shadow-md);
}

.phone-header {
  background: var(--phone-header);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.phone-back {
  color: rgba(255, 255, 255, 0.8);
  font-size: 16px;
  font-weight: 300;
}

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

.phone-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
}

.phone-name {
  color: white;
  font-size: 14px;
  font-weight: 500;
  letter-spacing: -0.1px;
}

.phone-status {
  color: rgba(255, 255, 255, 0.5);
  font-size: 11px;
  font-weight: 300;
}

.phone-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px;
  background: var(--phone-bg);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.phone-date {
  text-align: center;
  font-size: 11px;
  color: var(--text-muted);
  background: var(--bg-hover);
  padding: 3px 12px;
  border-radius: 6px;
  align-self: center;
  margin: 8px 0;
  font-weight: 400;
}

.phone-msg {
  max-width: 85%;
  padding: 8px 12px;
  border-radius: 10px;
  font-size: 13px;
  line-height: 1.5;
  font-weight: 400;
  position: relative;
}

.phone-msg.incoming {
  background: var(--phone-msg-in);
  color: var(--phone-msg-in-text);
  align-self: flex-start;
  border-bottom-left-radius: 2px;
}

.phone-msg.outgoing {
  background: var(--phone-msg-out);
  color: var(--phone-msg-out-text);
  align-self: flex-end;
  border-bottom-right-radius: 2px;
}

.phone-msg p {
  margin-bottom: 2px;
}

.msg-time {
  font-size: 10px;
  color: var(--text-muted);
  float: right;
  margin-left: 8px;
  margin-top: 4px;
}

.phone-input-area {
  padding: 10px 12px;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
}

.phone-input-container {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-input);
  border-radius: 22px;
  padding: 6px 6px 6px 16px;
  border: 1px solid var(--border);
}

.phone-input-container input {
  flex: 1;
  border: none;
  background: none;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 13px;
  font-weight: 400;
  outline: none;
}

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

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

.phone-send-btn:hover {
  opacity: 0.85;
  transform: scale(1.03);
}

.phone-send-btn:active {
  transform: scale(0.97);
}

/* ── Simulator Result ── */
.simulator-result {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 24px;
  height: 500px;
  overflow-y: auto;
  box-shadow: var(--shadow-sm);
}

.simulator-result h3 {
  font-size: 15px;
  font-weight: 500;
  margin-bottom: 16px;
  letter-spacing: -0.2px;
}

.result-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 80%;
  color: var(--text-muted);
  gap: 12px;
  font-size: 14px;
  font-weight: 300;
}

.result-placeholder span {
  font-size: 40px;
  opacity: 0.2;
}

.result-detail {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.result-item {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.result-item label {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.result-item .value {
  font-size: 14px;
  color: var(--text-primary);
  font-weight: 400;
}

.result-category-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: 20px;
  font-weight: 500;
  font-size: 13px;
}

.result-category-badge.auto {
  background: var(--accent-green-dim);
  color: var(--accent-green);
}

.result-category-badge.human {
  background: var(--accent-orange-dim);
  color: var(--accent-orange);
}

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

.confidence-bar {
  flex: 1;
  height: 4px;
  background: var(--bg-tertiary);
  border-radius: 2px;
  overflow: hidden;
}

.confidence-fill {
  height: 100%;
  border-radius: 2px;
  background: var(--accent);
  transition: width 0.8s cubic-bezier(0.25, 0.1, 0.25, 1);
}

.result-response {
  background: var(--bg-tertiary);
  padding: 14px 18px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  line-height: 1.6;
  font-weight: 400;
}

.result-action-tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-weight: 500;
  font-size: 13px;
}

.result-action-tag.auto {
  background: var(--accent-green-dim);
  color: var(--accent-green);
}

.result-action-tag.human {
  background: var(--accent-orange-dim);
  color: var(--accent-orange);
}

/* ── Quick Messages ── */
.quick-messages {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 20px;
  box-shadow: var(--shadow-sm);
}

.quick-messages h3 {
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 14px;
  color: var(--text-secondary);
  letter-spacing: -0.1px;
}

.quick-messages-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 8px;
}

.quick-msg {
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 12px;
  font-weight: 400;
  cursor: pointer;
  transition: var(--transition);
  text-align: left;
}

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

/* ══════════════════════════════════════════════
   BUTTONS
   ══════════════════════════════════════════════ */

.btn {
  padding: 9px 18px;
  border: none;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  letter-spacing: -0.1px;
}

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

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

.btn-secondary {
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  border: 1px solid var(--border);
}

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

.btn-danger {
  background: var(--accent-red-dim);
  color: var(--accent-red);
}

.btn-danger:hover {
  background: var(--accent-red);
  color: white;
}

.btn-warning {
  background: #fff3cd;
  color: #856404;
  border: 1px solid #ffc107;
  font-size: 11px;
}

.btn-warning:hover {
  background: #ffc107;
  color: #212529;
}

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

/* ══════════════════════════════════════════════
   MODAL
   ══════════════════════════════════════════════ */

.modal-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  z-index: 1000;
  align-items: center;
  justify-content: center;
}

.modal-overlay.active {
  display: flex;
  animation: fadeIn 0.3s ease;
}

.modal {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  width: 90%;
  max-width: 520px;
  box-shadow: var(--shadow-lg);
}

/* Wide modal for conversation history */
.modal-wide {
  max-width: 960px;
  width: 95%;
}

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

.modal-header-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.modal-header h3 {
  font-size: 16px;
  font-weight: 500;
  letter-spacing: -0.2px;
}

.modal-contact-subtitle {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 400;
}

.modal-close {
  width: 28px;
  height: 28px;
  min-width: 28px;
  border: none;
  background: var(--bg-hover);
  color: var(--text-secondary);
  font-size: 16px;
  border-radius: 50%;
  cursor: pointer;
  transition: var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-close:hover {
  background: var(--accent-red-dim);
  color: var(--accent-red);
}

.modal-body {
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Split layout for wide modal */
.modal-body-split {
  padding: 0;
  flex-direction: row;
  gap: 0;
  height: 600px;
  max-height: 75vh;
}

/* Left: full conversation history */
.modal-chat-history {
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  min-width: 0;
}

.modal-chat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  background: var(--bg-tertiary);
  border-radius: 0;
}

.modal-chat-count {
  color: var(--text-muted);
  font-weight: 400;
}

.modal-chat-thread {
  flex: 1 1 0;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.modal-chat-loading,
.modal-chat-empty {
  text-align: center;
  font-size: 13px;
  color: var(--text-muted);
  padding: 24px 0;
}

/* Chat bubbles */
.chat-bubble-wrap {
  display: flex;
}

.chat-bubble-left {
  justify-content: flex-start;
}

.chat-bubble-right {
  justify-content: flex-end;
}

.chat-bubble {
  max-width: 78%;
  padding: 8px 12px;
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.chat-bubble-left .chat-bubble {
  background: var(--bg-tertiary);
  border-bottom-left-radius: 4px;
}

.chat-bubble-right .chat-bubble {
  background: var(--accent-dim);
  border-bottom-right-radius: 4px;
}

.chat-bubble-pending .chat-bubble {
  border-left: 3px solid var(--accent);
  background: var(--accent-dim);
  border-radius: 12px 12px 12px 4px;
}

.chat-bubble-text {
  font-size: 13px;
  color: var(--text-primary);
  line-height: 1.45;
  font-weight: 400;
  word-break: break-word;
}

.chat-bubble-meta {
  font-size: 10px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
}

.chat-bubble-right .chat-bubble-meta {
  justify-content: flex-end;
}

.chat-bubble-agent {
  color: var(--accent);
  font-weight: 500;
}

/* Right: reply panel */
.modal-reply-panel {
  width: 380px;
  min-width: 320px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 16px 20px;
  overflow-y: auto;
}

.modal-pending-label {
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
}

.modal-original-msg {
  background: var(--bg-tertiary);
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--text-secondary);
  font-weight: 400;
}

.modal-ai-suggestion label {
  display: block;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
}

.modal-ai-suggestion p {
  font-size: 13px;
  color: var(--accent);
  background: var(--accent-dim);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  line-height: 1.5;
  font-weight: 400;
}

.modal-input-group label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.modal-input-group textarea {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 13px;
  font-weight: 400;
  padding: 12px;
  resize: vertical;
  outline: none;
  transition: var(--transition);
}

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

.modal-footer {
  padding: 12px 0 0;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  border-top: 1px solid var(--border);
  margin-top: auto;
}


/* ══════════════════════════════════════════════
   LOADING SPINNER
   ══════════════════════════════════════════════ */

.loading-spinner {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 300;
}

.spinner {
  width: 16px;
  height: 16px;
  border: 1.5px solid var(--border-light);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* ══════════════════════════════════════════════
   CONFIG VIEW
   ══════════════════════════════════════════════ */

/* ── Config tabs ── */
.config-tabs {
  display: flex;
  gap: 4px;
  border-bottom: 2px solid var(--border);
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.config-tab-btn {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  padding: 10px 16px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  transition: var(--transition);
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
}

.config-tab-btn:hover {
  color: var(--text-primary);
  background: var(--bg-hover);
}

.config-tab-btn.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.config-tab-panel {
  display: none;
}

.config-tab-panel.active {
  display: block;
}

/* Botón guardar fijo debajo de los tabs */
.config-save-bar {
  margin-top: 28px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
  max-width: 640px;
}

/* Hints de campo */
.config-hint {
  font-weight: 400;
  color: var(--text-muted);
  font-size: 11px;
}

.config-hint-text {
  font-size: 12px;
  color: var(--text-muted);
  margin: 0;
  line-height: 1.4;
}

/* Select en config */
.config-group select {
  width: 100%;
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 13px;
  padding: 10px 14px;
  outline: none;
  transition: var(--transition);
  cursor: pointer;
}

.config-group select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

/* Range slider */
.config-group input[type="range"] {
  padding: 0;
  border: none;
  background: none;
  box-shadow: none;
  cursor: pointer;
  accent-color: var(--accent);
}

.config-group input[type="range"]:focus {
  box-shadow: none;
}

/* Toggle row (toggle + label alineados) */
.config-toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

/* Checkboxes de categorías */
.config-checkboxes {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
  background: var(--bg-hover);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

.config-checkboxes label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-primary);
  cursor: pointer;
  font-weight: 400;
}

.config-checkboxes input[type="checkbox"] {
  width: 15px;
  height: 15px;
  accent-color: var(--accent);
  cursor: pointer;
}

/* Días de la semana */
.config-days-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.day-check {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  color: var(--text-primary);
  cursor: pointer;
  background: var(--bg-hover);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
}

.day-check input[type="checkbox"] {
  accent-color: var(--accent);
  cursor: pointer;
}

/* Sección horarios (se oculta/muestra con JS) */
.config-biz-hours {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-top: 8px;
  padding: 16px;
  background: var(--bg-hover);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

.config-biz-hours.hidden {
  display: none;
}

/* Fila de dos columnas en config */
.config-form-row {
  display: flex;
  gap: 16px;
}

.config-form-row .config-group {
  flex: 1;
}

.config-form {
  max-width: 640px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.config-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.config-group label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  letter-spacing: -0.1px;
}

.config-group input,
.config-group textarea {
  width: 100%;
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 13px;
  font-weight: 400;
  padding: 10px 14px;
  outline: none;
  transition: var(--transition);
  resize: vertical;
}

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

.config-group input::placeholder,
.config-group textarea::placeholder {
  color: var(--text-muted);
}

.config-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-top: 8px;
}

.config-status {
  font-size: 13px;
  font-weight: 400;
  color: var(--accent-green);
  opacity: 0;
  transition: opacity 0.3s ease;
}

.config-status.visible {
  opacity: 1;
}

/* ══════════════════════════════════════════════
   RESPONSIVE
   ══════════════════════════════════════════════ */

/* ── Breakpoint: ocultar panel-info en pantallas medianas ── */
@media (max-width: 1280px) {
  .conversations-layout {
    grid-template-columns: 280px 1fr;
  }

  .panel-info {
    display: none;
  }
}

/* ── Breakpoint: simulator en tablet ── */
@media (max-width: 1024px) {
  .simulator-container {
    grid-template-columns: 1fr;
  }

  .simulator-result {
    height: auto;
  }
}

/* ══════════════════════════════════════════════
   MOBILE — < 768px
   Sidebar → bottom nav bar
   Conversations → single pane con slide
   ══════════════════════════════════════════════ */
@media (max-width: 767px) {

  /* ── Layout base ── */
  html, body {
    overflow: hidden;
  }

  body {
    flex-direction: column;
  }

  /* ── Main content: full width, deja espacio para bottom nav ── */
  .main-content {
    width: 100%;
    height: calc(100vh - 60px);
    padding: 16px;
    padding-bottom: 16px;
    overflow-y: auto;
    overflow-x: hidden;
  }

  /* ── Sidebar → fixed bottom tab bar ── */
  .sidebar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    height: 60px;
    flex-direction: row;
    border-right: none;
    border-top: 1px solid var(--border);
    z-index: 200;
    overflow: hidden;
  }

  /* Ocultar secciones del sidebar que no van en bottom nav */
  .sidebar-header,
  .sidebar-workspace-selector,
  .sidebar-mode-toggle,
  .sidebar-footer {
    display: none !important;
  }

  /* Nav horizontal */
  .sidebar-nav {
    flex-direction: row;
    padding: 0;
    gap: 0;
    width: 100%;
    align-items: stretch;
    overflow-x: auto;
    scrollbar-width: none;
  }

  .sidebar-nav::-webkit-scrollbar {
    display: none;
  }

  /* Separador del simulador: display:contents hace que el div sea transparente al flex,
     el .nav-btn interno participa directamente en el layout horizontal del sidebar-nav */
  .sidebar-nav > div {
    display: contents;
  }

  /* Botones del nav: columna icono + label */
  .nav-btn {
    flex: 1;
    flex-direction: column;
    gap: 2px;
    padding: 6px 2px;
    justify-content: center;
    border-radius: 0;
    min-width: 44px;
    font-size: 9px;
    position: relative;
  }

  /* Mostrar labels cortos en mobile */
  .nav-btn span:not(.nav-icon) {
    display: block;
    font-size: 9px;
    line-height: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 48px;
  }

  /* Badge reposicionado para bottom nav */
  .nav-btn .badge {
    position: absolute;
    top: 5px;
    right: calc(50% - 22px);
    margin-left: 0;
  }

  /* ── Stats grid: 2 columnas en mobile ── */
  .stats-grid {
    grid-template-columns: 1fr 1fr;
  }

  /* ── View header más compacto ── */
  .view-header {
    margin-bottom: 16px;
  }

  .view-header h1 {
    font-size: 22px;
  }

  /* ── Conversations view: position fixed cuando está activa (evita el bug de especificidad) ── */
  /* NOTA: #id tiene mayor especificidad que .class. Por eso usamos #id.active en lugar de #id
     para que `.view { display: none }` siga funcionando cuando la vista NO está activa. */
  #view-conversations.active {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 60px;
    height: auto;
    z-index: 100; /* por encima del mobile-topbar (z-50) */
    background: var(--bg-primary);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding: 16px 16px 0;
  }

  #view-conversations.active .view-header {
    flex-shrink: 0;
  }

  #view-conversations.active .conv-search-bar {
    flex-shrink: 0;
  }

  /* Cuando el chat está abierto: pantalla completa para el chat */
  #view-conversations.mobile-chat-open .view-header,
  #view-conversations.mobile-chat-open .conv-search-bar {
    display: none;
  }

  /* ── Conversations: layout single-pane con slide ── */
  .conversations-layout {
    display: block;
    position: relative;
    flex: 1;
    min-height: 0;
    overflow: hidden;
  }

  .conv-left-panel,
  .conversation-detail {
    position: absolute;
    inset: 0;
    transition: transform 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    overflow: hidden;
  }

  .conv-left-panel {
    transform: translateX(0);
    background: var(--bg-primary);
    display: flex;
    flex-direction: column;
  }

  /* El panel de detalle siempre existe en mobile (override del display:none anterior) */
  .conversation-detail {
    transform: translateX(100%);
    display: flex !important;
    background: var(--bg-card);
    border-radius: 0;
    border: none;
    box-shadow: none;
  }

  /* Cuando hay un chat abierto: slide a chat */
  .conversations-layout.mobile-chat-open .conv-left-panel {
    transform: translateX(-100%);
  }

  .conversations-layout.mobile-chat-open .conversation-detail {
    transform: translateX(0);
  }

  /* panel-info oculto en mobile */
  .panel-info {
    display: none !important;
  }

  /* ── Botón back en mobile (oculto en desktop) ── */
  .mobile-back-btn {
    display: flex;
    align-items: center;
    gap: 4px;
    background: none;
    border: none;
    color: var(--accent);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    padding: 0;
    font-family: inherit;
    flex-shrink: 0;
  }

  /* Toast: subir para que no quede debajo del bottom nav */
  .wa-toast {
    bottom: 72px;
  }

  /* Profile popover: ajustar posición */
  .profile-popover {
    bottom: 68px;
    left: 8px;
    width: calc(100vw - 16px);
  }
}

/* ── Mobile back button: solo visible en mobile ── */
@media (min-width: 768px) {
  .mobile-back-btn {
    display: none !important;
  }
}

/* ══════════════════════════════════════════════
   MOBILE TOP BAR — workspace, toggle, perfil
   Solo visible en mobile (<768px)
   ══════════════════════════════════════════════ */

.mobile-topbar {
  display: none;
}

@media (max-width: 767px) {
  .mobile-topbar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 50;
    flex-shrink: 0;
  }

  .mobile-topbar-ws {
    flex: 1;
    min-width: 0;
  }

  .mobile-topbar-ws select {
    width: 100%;
    padding: 6px 10px;
    border: 1px solid var(--border-light);
    border-radius: 8px;
    background: var(--bg-input);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
  }

  .mobile-topbar-toggle {
    display: flex;
    align-items: center;
    gap: 5px;
    flex-shrink: 0;
  }

  .mobile-topbar-toggle-label {
    font-size: 10px;
    color: var(--text-muted);
    white-space: nowrap;
  }

  .mobile-profile-top {
    width: 30px;
    height: 30px;
    border-radius: 8px;
    background: var(--accent);
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-family: inherit;
  }
}

/* ── Conversation detail reply bar ── */
.detail-reply {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--border-light);
  background: var(--bg-secondary);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

.detail-reply input {
  flex: 1;
  padding: 10px 14px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 13px;
  outline: none;
  transition: var(--transition);
}

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

.detail-reply button {
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  min-width: auto;
}

/* ── Pending tag on messages ── */
.msg-pending-tag {
  display: inline-block;
  font-size: 11px;
  color: var(--accent-orange);
  margin-top: 4px;
  font-weight: 500;
}

/* ── Sidebar mode toggle ── */
.sidebar-mode-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-top: 1px solid var(--border-light);
  margin-top: auto;
}

.sidebar-toggle-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  white-space: nowrap;
  flex: 1;
}

.sidebar-toggle {
  display: flex;
  align-items: center;
  cursor: pointer;
  position: relative;
  flex-shrink: 0;
}

.sidebar-toggle input {
  display: none;
}

/* Tooltip on hover */
.sidebar-toggle[title]:hover::after {
  content: attr(title);
  position: absolute;
  left: 50px;
  bottom: 100%;
  margin-bottom: 8px;
  background: var(--bg-card);
  color: var(--text-primary);
  font-size: 11px;
  font-weight: 400;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-light);
  box-shadow: var(--shadow-lg);
  width: 200px;
  line-height: 1.4;
  z-index: 100;
  pointer-events: none;
}

.toggle-slider {
  width: 44px;
  height: 26px;
  background: #ccc;
  border: 1px solid var(--border-light);
  border-radius: 26px;
  position: relative;
  transition: var(--transition);
}

.toggle-slider::after {
  content: '';
  position: absolute;
  width: 20px;
  height: 20px;
  background: white;
  border-radius: 50%;
  top: 2px;
  left: 2px;
  transition: var(--transition);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
}

.sidebar-toggle input:checked+.toggle-slider,
.toggle-switch input:checked+.toggle-slider {
  background: #34c759;
  border-color: #34c759;
}

.sidebar-toggle input:checked+.toggle-slider::after,
.toggle-switch input:checked+.toggle-slider::after {
  left: 20px;
}

/* ── Team management ── */
.team-section {
  margin-bottom: 28px;
}

.team-section h2 {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 12px;
  color: var(--text-primary);
}

.team-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.team-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  transition: var(--transition);
}

.team-card:hover {
  border-color: var(--accent);
}

.team-card-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.team-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #5856d6);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 14px;
}

.team-card-info strong {
  display: block;
  font-size: 13px;
  color: var(--text-primary);
}

.team-email {
  font-size: 11px;
  color: var(--text-muted);
}

.team-card-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.team-role-badge {
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 12px;
  font-weight: 500;
}

.team-role-admin {
  background: rgba(255, 149, 0, 0.1);
  color: var(--accent-orange);
}

.team-role-operador {
  background: rgba(0, 122, 255, 0.1);
  color: var(--accent);
}

.team-pending-badge {
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 12px;
  font-weight: 500;
  background: rgba(234, 179, 8, 0.12);
  color: #a16207;
  border: 1px solid rgba(234, 179, 8, 0.3);
}

.btn-sm {
  padding: 4px 8px;
  font-size: 11px;
  min-width: auto;
}

.btn-danger {
  background: var(--accent-red);
  color: white;
  border: none;
}

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

.btn-secondary {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border: 1px solid var(--border-light);
}

.btn-secondary:hover {
  background: var(--border-light);
}

.team-form {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: 16px;
}

.team-form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 12px;
}

.team-form select {
  width: 100%;
  padding: 8px 12px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 13px;
}

/* ── Audit trail tag ── */
.msg-responded-by {
  display: inline-block;
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 2px;
  font-style: italic;
}

/* ══════════════════════════════════════════════
   PENDING FILTERS
   ══════════════════════════════════════════════ */

.pending-filters {
  display: flex;
  gap: 16px;
  margin-bottom: 20px;
  flex-wrap: wrap;
  align-items: center;
}

.filter-group {
  display: flex;
  align-items: center;
  gap: 6px;
}

.filter-group label {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 400;
  white-space: nowrap;
}

.filter-group select {
  padding: 6px 10px;
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 12px;
  cursor: pointer;
  transition: var(--transition);
}

.filter-group select:hover {
  border-color: var(--accent);
}

.filter-group select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-dim);
}

/* ══════════════════════════════════════════════
   SLA BADGES
   ══════════════════════════════════════════════ */

.sla-badge {
  display: inline-flex;
  align-items: center;
  font-size: 11px;
  font-weight: 500;
  padding: 3px 10px;
  border-radius: 12px;
  white-space: nowrap;
}

.sla-green {
  background: var(--accent-green-dim);
  color: var(--accent-green);
}

.sla-yellow {
  background: var(--accent-orange-dim);
  color: var(--accent-orange);
}

.sla-red {
  background: var(--accent-red-dim);
  color: var(--accent-red);
  animation: sla-pulse 2s ease infinite;
}

@keyframes sla-pulse {

  0%,
  100% {
    opacity: 1;
  }

  50% {
    opacity: 0.65;
  }
}

/* ══════════════════════════════════════════════
   PENDING CARDS — Grouped
   ══════════════════════════════════════════════ */

.pending-starred {
  border-left: 3px solid var(--accent-orange) !important;
}

.pending-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 14px;
  gap: 12px;
}

.pending-header-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.platform-icon {
  font-size: 20px;
  flex-shrink: 0;
}

.pending-msg-count {
  font-size: 11px;
  font-weight: 500;
  color: var(--accent);
  background: var(--accent-dim);
  padding: 2px 8px;
  border-radius: 10px;
  white-space: nowrap;
}

.pending-messages-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 14px;
}

.pending-message-item {
  background: var(--bg-tertiary);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
}

.pending-message-item .pending-message {
  background: none;
  padding: 0;
  margin-bottom: 4px;
  font-size: 13px;
  line-height: 1.5;
  color: var(--text-secondary);
  font-weight: 400;
}

.pending-message-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 10px;
  color: var(--text-muted);
}

/* Botón inline "Ver más / Ver menos" dentro del texto */
.btn-inline-toggle {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 12px;
  font-family: inherit;
  font-weight: 500;
  cursor: pointer;
  padding: 0 2px;
  text-decoration: underline;
  transition: opacity 0.15s;
}

.btn-inline-toggle:hover {
  opacity: 0.75;
}

/* Botón para expandir mensajes adicionales del grupo */
.btn-expand-msgs {
  display: flex;
  align-items: center;
  gap: 6px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
  padding: 6px 0 2px;
  transition: color 0.15s;
}

.btn-expand-msgs:hover {
  color: var(--accent);
}

.btn-expand-msgs .expand-icon {
  font-size: 10px;
}

.pending-extra-msgs {
  margin-top: 6px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.pending-category-mini {
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 8px;
  background: var(--accent-dim);
  color: var(--accent);
}

/* ── Icon Buttons ── */
.btn-icon {
  width: 36px;
  height: 36px;
  border: 1px solid var(--border-light);
  background: var(--bg-tertiary);
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  transition: var(--transition);
  padding: 0;
  flex-shrink: 0;
}

.btn-icon:hover {
  background: var(--bg-hover);
  border-color: var(--accent);
  transform: scale(1.05);
}

.btn-dismiss:hover {
  border-color: var(--accent-red);
  color: var(--accent-red);
}

/* ══════════════════════════════════════════════
   QUICK REPLY TEMPLATES — Modal
   ══════════════════════════════════════════════ */

.modal-quick-replies {
  margin-bottom: 12px;
}

.modal-quick-replies label {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  display: block;
  margin-bottom: 8px;
}

.quick-replies-bar {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.btn-quick-reply {
  padding: 5px 12px;
  font-size: 11px;
  font-weight: 500;
  border: 1px solid var(--border-light);
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  border-radius: 20px;
  cursor: pointer;
  transition: var(--transition);
  font-family: inherit;
  white-space: nowrap;
}

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

/* ── Modal message items (grouped) ── */
.modal-msg-item {
  background: var(--bg-tertiary);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  margin-bottom: 6px;
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.5;
}

.modal-msg-time {
  font-size: 10px;
  color: var(--text-muted);
  margin-left: 6px;
}

/* ══════════════════════════════════════════════
   TEMPLATES — Config Section
   ══════════════════════════════════════════════ */

.templates-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 20px;
}

.template-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  transition: var(--transition);
}

.template-card:hover {
  box-shadow: var(--shadow-sm);
}

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

.template-info strong {
  font-size: 13px;
  font-weight: 500;
  display: block;
  margin-bottom: 4px;
  color: var(--text-primary);
}

.template-info p {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.5;
  word-break: break-word;
}

.template-add-form {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: 16px;
}

.config-section {
  margin-bottom: 40px;
}

.config-section .view-header {
  margin-bottom: 20px;
}

.config-section .view-header h2 {
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.3px;
}

/* ══════════════════════════════════════════════
   WORKSPACE SELECTOR
   ══════════════════════════════════════════════ */

.sidebar-workspace-selector {
  padding: 12px 16px;
  margin: 0 12px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-sm);
  border-left: 3px solid var(--accent);
}

.sidebar-ws-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 10px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.sidebar-ws-label .icon {
  color: var(--accent);
}

#workspace-selector {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border-light);
  border-radius: 8px;
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='none' stroke='%23666' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M2 4l4 4 4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 28px;
}

#workspace-selector:hover {
  border-color: var(--accent);
}

#workspace-selector:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

[data-theme="dark"] #workspace-selector {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='none' stroke='%23999' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M2 4l4 4 4-4'/%3E%3C/svg%3E");
}

/* ══════════════════════════════════════════════
   WHATSAPP INTEGRATION VIEW
   ══════════════════════════════════════════════ */

.wa-cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 20px;
  max-width: 900px;
}

.wa-connection-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-md);
  display: flex;
  flex-direction: column;
  transition: var(--transition);
}

.wa-card-connected {
  border-color: var(--accent-green);
  box-shadow: 0 0 0 1px var(--accent-green), var(--shadow-md);
}

.wa-card-header {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.wa-card-footer {
  margin-top: auto;
  padding-top: 16px;
  display: flex;
  justify-content: center;
}

.wa-operator-alert {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 12px 0 4px;
  padding: 10px 14px;
  border-radius: 8px;
  background: rgba(245, 158, 11, 0.1);
  border: 1px solid rgba(245, 158, 11, 0.3);
  color: #b45309;
  font-size: 13px;
}
.wa-operator-alert svg { flex-shrink: 0; stroke: #b45309; }

.wa-status-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 24px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.wa-status-indicator {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* Scoped to the dot inside WA panel cards only — not the sidebar indicator */
.wa-status-indicator.wa-status-ready {
  background: var(--accent-green);
  box-shadow: 0 0 8px var(--accent-green);
  animation: pulse-dot 2s ease infinite;
}

.wa-status-indicator.wa-status-qr {
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent);
  animation: pulse-dot 1s ease infinite;
}

.wa-status-indicator.wa-status-connecting {
  background: var(--accent-orange);
  animation: pulse-dot 0.8s ease infinite;
}

.wa-status-indicator.wa-status-off {
  background: var(--text-muted);
}

.wa-status-text {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
}

.wa-status-text-small {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 400;
}

.wa-qr-container {
  display: flex;
  justify-content: center;
  align-items: center;
  margin-bottom: 16px;
  min-height: 200px;
}

.wa-qr-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--text-muted);
  text-align: center;
  padding: 40px;
}

.wa-qr-placeholder p {
  font-size: 14px;
  font-weight: 300;
}

.wa-qr-image {
  border-radius: var(--radius-md);
  border: 4px solid var(--bg-tertiary);
  box-shadow: var(--shadow-lg);
}

.wa-controls {
  display: flex;
  align-items: flex-end;
  gap: 16px;
  margin-bottom: 24px;
}

.wa-controls .config-group {
  flex: 1;
}

.wa-controls .config-group label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.wa-controls .config-group select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border-light);
  border-radius: 8px;
  background: var(--bg-input);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 13px;
}

.wa-buttons {
  display: flex;
  gap: 8px;
}

.btn-danger {
  background: var(--accent-red);
  color: white;
  border: none;
  padding: 10px 16px;
  border-radius: 8px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
}

.btn-danger:hover {
  opacity: 0.9;
  transform: translateY(-1px);
}

.wa-instructions {
  background: var(--bg-tertiary);
  border-radius: var(--radius-sm);
  padding: 20px;
}

.wa-instructions h3 {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 12px;
  color: var(--text-primary);
}

.wa-instructions ol {
  margin: 0;
  padding-left: 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.wa-instructions li {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.5;
  font-weight: 400;
}

/* ══════════════════════════════════════════════
   WORKSPACE MANAGEMENT
   ══════════════════════════════════════════════ */

.ws-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--bg-tertiary);
  border-radius: 8px;
  margin-bottom: 8px;
}

.ws-item-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

.ws-item-id {
  font-size: 11px;
  color: var(--text-muted);
  background: var(--bg-card);
  padding: 2px 8px;
  border-radius: 4px;
  font-family: monospace;
}

.ws-item-channels {
  font-size: 14px;
}

.ws-item-actions {
  display: flex;
  gap: 6px;
}

.btn-sm {
  padding: 4px 10px;
  font-size: 12px;
  min-width: auto;
}

/* ── Conversation search bar ── */
.conv-search-bar {
  display: flex;
  gap: 8px;
  padding: 12px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  align-items: center;
}

.conv-search-input-wrap {
  position: relative;
  flex: 1;
  min-width: 160px;
}

.conv-search-input-wrap input {
  width: 100%;
  box-sizing: border-box;
}

#conv-filter-category {
  font-size: 13px;
  padding: 6px 8px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-input, var(--bg-card));
  color: var(--text-primary);
  cursor: pointer;
}

.conv-toggle-pending {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
  white-space: nowrap;
}

/* ── Pending: AI Suggestion clickable block ── */
.pending-ai-suggestion {
  margin: 12px 0 4px;
  padding: 12px 14px;
  background: var(--accent-dim, rgba(10,132,255,0.06));
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: var(--transition);
  position: relative;
}

.pending-ai-suggestion:hover {
  border-color: var(--accent);
  background: var(--accent-dim, rgba(10,132,255,0.10));
  box-shadow: 0 0 0 2px var(--accent-dim, rgba(10,132,255,0.12));
}

.pending-ai-suggestion-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.pending-ai-suggestion-header label {
  font-size: 11px;
  font-weight: 600;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  cursor: pointer;
}

.pending-ai-suggestion-hint {
  font-size: 10px;
  color: var(--text-muted);
  opacity: 0;
  transition: opacity 0.2s ease;
  white-space: nowrap;
}

.pending-ai-suggestion:hover .pending-ai-suggestion-hint {
  opacity: 1;
}

.pending-ai-suggestion p {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.5;
  margin: 0;
  pointer-events: none;
}

/* Dark mode adjustments */
[data-theme="dark"] .pending-ai-suggestion {
  background: rgba(10,132,255,0.08);
  border-color: rgba(10,132,255,0.2);
}

[data-theme="dark"] .pending-ai-suggestion:hover {
  background: rgba(10,132,255,0.14);
  border-color: var(--accent);
}



/* ══════════════════════════════════════════════
   SIMULATOR VIEW
   ══════════════════════════════════════════════ */

/* View header with reset button on the right */
.simulator-view-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.simulator-view-header h1 {
  font-size: 28px;
  font-weight: 600;
  letter-spacing: -0.5px;
  margin-bottom: 4px;
  color: var(--text-primary);
}

/* Reset / Nueva conversación button */
.simulator-reset-btn {
  display: flex;
  align-items: center;
  gap: 7px;
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  padding: 9px 16px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
  flex-shrink: 0;
  align-self: flex-start;
  margin-top: 6px;
}

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

.simulator-reset-btn svg {
  flex-shrink: 0;
  transition: transform 0.4s ease;
}

.simulator-reset-btn:hover svg {
  transform: rotate(-360deg);
}

/* Quick messages section (now on top) */
.quick-messages {
  margin-bottom: 20px;
}

.quick-messages h3 {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 12px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
}

.quick-messages-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.quick-msg {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 12px;
  font-weight: 400;
  padding: 7px 14px;
  border-radius: 20px;
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
}

.quick-msg:hover {
  background: var(--accent-dim);
  color: var(--accent);
  border-color: var(--accent);
  transform: translateY(-1px);
}

/* Divider between quick messages and the phone */
.simulator-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 4px 0 20px;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.7px;
}

.simulator-divider::before,
.simulator-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* Main layout: phone left, result right */
.simulator-container {
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 24px;
  align-items: start;
}

/* Phone mockup */
.simulator-phone {
  background: var(--phone-bg);
  border-radius: 20px;
  overflow: hidden;
  box-shadow: var(--shadow-lg), 0 0 0 1px rgba(0,0,0,0.08);
  display: flex;
  flex-direction: column;
  height: 560px;
}

.phone-header {
  background: var(--phone-header);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.phone-back {
  color: rgba(255,255,255,0.85);
  font-size: 18px;
  cursor: pointer;
}

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

.phone-avatar {
  font-size: 22px;
}

.phone-name {
  font-weight: 600;
  font-size: 14px;
  color: #fff;
  line-height: 1.2;
}

.phone-status {
  font-size: 11px;
  color: rgba(255,255,255,0.65);
  font-weight: 400;
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.phone-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.phone-date {
  text-align: center;
  font-size: 11px;
  color: rgba(0,0,0,0.45);
  background: rgba(255,255,255,0.55);
  padding: 3px 10px;
  border-radius: 10px;
  align-self: center;
  margin: 4px 0 8px;
  font-weight: 500;
}

[data-theme="dark"] .phone-date {
  color: rgba(255,255,255,0.45);
  background: rgba(255,255,255,0.08);
}

.phone-msg {
  max-width: 82%;
  padding: 8px 12px;
  border-radius: 14px;
  font-size: 13px;
  line-height: 1.45;
  word-break: break-word;
  animation: fadeIn 0.2s ease;
}

.phone-msg.outgoing {
  background: var(--phone-msg-out);
  color: var(--phone-msg-out-text);
  align-self: flex-end;
  border-bottom-right-radius: 4px;
}

.phone-msg.incoming {
  background: var(--phone-msg-in);
  color: var(--phone-msg-in-text);
  align-self: flex-start;
  border-bottom-left-radius: 4px;
}

.msg-time {
  display: block;
  font-size: 10px;
  opacity: 0.55;
  text-align: right;
  margin-top: 4px;
}

.phone-input-area {
  background: var(--phone-header);
  padding: 10px 12px;
  flex-shrink: 0;
}

.phone-input-container {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(255,255,255,0.9);
  border-radius: 24px;
  padding: 4px 4px 4px 14px;
}

[data-theme="dark"] .phone-input-container {
  background: rgba(255,255,255,0.12);
}

.phone-input-container input {
  flex: 1;
  border: none;
  background: transparent;
  font-family: inherit;
  font-size: 13px;
  color: #111;
  outline: none;
}

[data-theme="dark"] .phone-input-container input {
  color: rgba(255,255,255,0.87);
}

.phone-input-container input::placeholder {
  color: rgba(0,0,0,0.35);
}

[data-theme="dark"] .phone-input-container input::placeholder {
  color: rgba(255,255,255,0.3);
}

.phone-send-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: #25d366;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  transition: var(--transition);
  flex-shrink: 0;
}

.phone-send-btn:hover {
  background: #1ebe5a;
  transform: scale(1.08);
}

/* Session info badge below the phone input */
.sim-session-info {
  background: var(--phone-header);
  padding: 6px 16px 10px;
  text-align: center;
}

#sim-session-badge {
  font-size: 10px;
  color: rgba(255,255,255,0.5);
  font-weight: 400;
  letter-spacing: 0.2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: block;
}

/* AI Result Panel */
.simulator-result {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 20px;
  box-shadow: var(--shadow-sm);
}

.simulator-result h3 {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 16px;
  color: var(--text-primary);
  letter-spacing: -0.2px;
}

.result-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 40px 20px;
  color: var(--text-muted);
  font-size: 13px;
  text-align: center;
}

.result-placeholder span {
  font-size: 32px;
  opacity: 0.4;
}

.result-detail {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.result-item {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.result-item label {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.result-item .value {
  font-size: 13px;
  color: var(--text-secondary);
}

.result-category-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 12px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 500;
  width: fit-content;
}

.result-category-badge.auto {
  background: var(--accent-green-dim);
  color: var(--accent-green);
}

.result-category-badge.human {
  background: var(--accent-orange-dim);
  color: var(--accent-orange);
}

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

.confidence-bar {
  flex: 1;
  height: 6px;
  background: var(--bg-tertiary);
  border-radius: 99px;
  overflow: hidden;
}

.confidence-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), #5856d6);
  border-radius: 99px;
  transition: width 0.5s ease;
}

.result-response {
  font-size: 13px;
  color: var(--text-secondary);
  background: var(--bg-tertiary);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  line-height: 1.6;
  border-left: 3px solid var(--accent);
}

.result-action-tag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 12px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 500;
  width: fit-content;
}

.result-action-tag.auto {
  background: var(--accent-green-dim);
  color: var(--accent-green);
}

.result-action-tag.human {
  background: var(--accent-orange-dim);
  color: var(--accent-orange);
}

/* Loading spinner */
.loading-spinner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  color: var(--text-muted);
  font-size: 13px;
}

.spinner {
  width: 24px;
  height: 24px;
  border: 2px solid var(--border-light);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* Responsive: stack on smaller screens */
@media (max-width: 900px) {
  .simulator-container {
    grid-template-columns: 1fr;
  }

  .simulator-phone {
    height: 460px;
  }
}

/* ── Toast Notifications ── */
.wa-toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  padding: 12px 20px;
  border-radius: 8px;
  color: #fff;
  font-size: 14px;
  font-weight: 500;
  z-index: 9999;
  opacity: 0;
  transform: translateY(12px);
  transition: opacity 0.25s ease, transform 0.25s ease;
  max-width: 360px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  pointer-events: none;
}

.wa-toast.wa-toast-visible {
  opacity: 1;
  transform: translateY(0);
}

.wa-toast.wa-toast-success { background: #22c55e; }
.wa-toast.wa-toast-error   { background: #ef4444; }
.wa-toast.wa-toast-info    { background: #3b82f6; }

/* ── Control IA — tabla de modos por categoría ── */
.control-ia-table {
  border: 1px solid var(--border-light);
  border-radius: 10px;
  overflow: hidden;
  margin-top: 8px;
}
.control-ia-header {
  display: grid;
  grid-template-columns: 1fr 200px;
  padding: 8px 16px;
  background: var(--bg-hover, rgba(0,0,0,0.03));
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border-light);
}
.control-ia-row {
  display: grid;
  grid-template-columns: 1fr 200px;
  align-items: center;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border-light);
}
.control-ia-row:last-child { border-bottom: none; }
.control-ia-row:hover { background: var(--bg-hover, rgba(0,0,0,0.02)); }
.control-ia-cat {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 500;
}
.control-ia-cat-emoji { font-size: 16px; }
.control-ia-legend {
  margin-top: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px 20px;
  font-size: 11px;
  color: var(--text-muted);
}

/* ── Password visibility toggle ── */
.pw-wrap {
  position: relative;
  display: flex;
  align-items: center;
}
.pw-wrap input {
  flex: 1;
  padding-right: 36px !important;
}
.pw-eye-btn {
  position: absolute;
  right: 8px;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  padding: 4px;
  display: flex;
  align-items: center;
  transition: color 0.15s;
}
.pw-eye-btn:hover { color: var(--text-primary); }

/* ── Section card (generic) ── */
.section-card {
  background: var(--bg-card);
  border-radius: 12px;
  border: 1px solid var(--border-light);
  padding: 20px 24px;
  box-shadow: var(--shadow-sm);
}
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.section-header h3 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
}

/* ── Super Admin ── */
.team-role-free {
  background: rgba(108, 117, 125, 0.12);
  color: #6c757d;
}
.team-role-pro {
  background: rgba(0, 122, 255, 0.12);
  color: var(--accent);
}
.team-role-business {
  background: rgba(255, 149, 0, 0.12);
  color: var(--accent-orange);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.data-table th {
  text-align: left;
  padding: 8px 12px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border-light);
}
.data-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-light);
  vertical-align: middle;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--bg-hover, rgba(0,0,0,0.02)); }

.table-responsive { overflow-x: auto; }

.usage-bar-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 100px;
}
.usage-bar-fill {
  height: 6px;
  background: var(--accent);
  border-radius: 3px;
  min-width: 2px;
  flex-shrink: 0;
  max-width: 80px;
}
.usage-bar-label {
  font-size: 11px;
  color: var(--text-secondary);
  white-space: nowrap;
}

.input-sm {
  padding: 4px 8px;
  font-size: 12px;
  border-radius: 6px;
  border: 1px solid var(--border-light);
  background: var(--bg-primary);
  color: var(--text-primary);
  cursor: pointer;
}

/* ── Equipo (gestión de miembros por workspace) ── */
.team-panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.team-add-row {
  display: flex;
  gap: 8px;
  align-items: center;
}
.team-add-row select {
  flex: 1;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border-light);
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 13px;
}
.team-add-row .btn-sm {
  white-space: nowrap;
}

.team-members-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 40px;
}

.team-member-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: 10px;
  transition: background 0.15s;
}
.team-member-row:hover { background: var(--bg-hover, var(--bg-sidebar)); }

.team-member-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--accent-primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 600;
  flex-shrink: 0;
}

.team-member-info {
  flex: 1;
  min-width: 0;
}
.team-member-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.team-member-email {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.team-member-role {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 10px;
  background: var(--bg-sidebar);
  color: var(--text-muted);
  border: 1px solid var(--border-light);
  white-space: nowrap;
}

.team-member-remove {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  padding: 4px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  transition: color 0.15s, background 0.15s;
  flex-shrink: 0;
}
.team-member-remove:hover {
  color: #ef4444;
  background: rgba(239,68,68,0.08);
}

.empty-state-small {
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
  padding: 20px 0;
}

/* Ocultar tabs/secciones solo para admins cuando el usuario es operador */
.admin-only-tab { display: inline-flex; }
.operator-mode .admin-only-tab { display: none; }