/* ============================================================
   CrisChat - Sistema Multiagente WhatsApp
   ============================================================ */

:root {
  /* Brand */
  --primary: #1DA851;
  --primary-dark: #17803e;
  --primary-light: #1DA851;
  --accent: #2563eb;          /* Blue — transfers, links */

  /* Chat area — unchanged */
  --bg-chat: #ECE5DD;
  --msg-sent: #DCF8C6;
  --msg-received: #FFFFFF;

  /* Light surface depth scale */
  --bg-base: #f0f2f5;         /* App background */
  --bg-panel: #ffffff;        /* Main panels (sidebar, content) */
  --bg-elevated: #f7f9fb;     /* Slightly raised surfaces */
  --bg-input: #f0f2f5;        /* Input fields */
  --bg-hover: #f0f4f8;        /* Hover */
  --bg-active: #e8f4ee;       /* Active/selected — green tint */

  /* Legacy aliases (kept for compat) */
  --sidebar-bg: #ffffff;
  --sidebar-header: #f7f9fb;
  --sidebar-hover: #f0f4f8;
  --sidebar-active: #e8f4ee;

  /* Text — all dark now */
  --text-primary: #1a2330;
  --text-secondary: #6b7785;
  --text-light: #9aa5b1;
  --text-white: #1a2330;      /* Was bright-on-dark; now dark-on-light (compat alias) */

  /* Borders — light and subtle */
  --border: #e0e4e8;
  --border-dark: #e0e4e8;

  /* Semantic colors */
  --danger: #dc2626;
  --warning: #d97706;
  --success: #1DA851;
  --bot-color: #7c3aed;
  --waiting-color: #d97706;
  --active-color: #1DA851;
  --closed-color: #9aa5b1;

  --radius: 8px;
  --radius-msg: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.1), 0 2px 6px rgba(0,0,0,0.06);
  --transition: all 0.18s ease;
}

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

html, body {
  height: 100%;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  font-size: 14px;
  background: var(--bg-base);
  color: var(--text-primary);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ============================================================
   LOGIN
   ============================================================ */
#login-screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f0f2f5;
  background-image: radial-gradient(ellipse at 40% 20%, rgba(29,168,81,0.08) 0%, transparent 55%),
                    radial-gradient(ellipse at 75% 85%, rgba(37,99,235,0.06) 0%, transparent 50%);
  z-index: 9999;
}

.login-card {
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 48px 40px;
  width: 380px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.1), 0 2px 8px rgba(0,0,0,0.06);
  text-align: center;
}

.login-logo {
  width: 72px;
  height: 72px;
  background: var(--primary);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 24px;
  box-shadow: 0 0 0 6px rgba(29,168,81,0.12), 0 6px 20px rgba(29,168,81,0.2);
}

.login-logo svg { color: white; width: 40px; height: 40px; }

.login-card h1 {
  font-size: 24px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 8px;
}

.login-card p {
  color: var(--text-secondary);
  margin-bottom: 32px;
}

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

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

.form-group input {
  width: 100%;
  padding: 12px 16px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  transition: var(--transition);
  outline: none;
  background: #ffffff;
  color: var(--text-primary);
}

.form-group input::placeholder { color: var(--text-light); }

.form-group input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(29, 168, 81, 0.1);
}

.btn-primary {
  width: 100%;
  padding: 13px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: var(--radius);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  margin-top: 8px;
  box-shadow: 0 2px 8px rgba(29,168,81,0.25);
}

.btn-primary:hover { background: var(--primary-dark); box-shadow: 0 4px 12px rgba(29,168,81,0.35); }
.btn-primary:active { transform: scale(0.99); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; box-shadow: none; }

.login-error {
  background: #fef2f2;
  color: #dc2626;
  border: 1px solid #fecaca;
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 13px;
  margin-top: 12px;
  display: none;
}

/* ============================================================
   MAIN APP LAYOUT
   ============================================================ */
#app {
  display: none;
  height: 100vh;
  flex-direction: column;
}

#app.visible { display: flex; }

.app-layout {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ============================================================
   SIDEBAR IZQUIERDO
   ============================================================ */
.sidebar {
  width: 340px;
  min-width: 300px;
  flex-shrink: 0;
  background: var(--bg-panel);
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border-dark);
  overflow: hidden;
}

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

.agent-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  color: white;
  font-size: 16px;
  cursor: pointer;
  flex-shrink: 0;
  position: relative;
}

.agent-avatar .status-dot {
  position: absolute;
  bottom: 1px;
  right: 1px;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  border: 2px solid var(--bg-elevated);
}

.status-dot.online { background: var(--success); }
.status-dot.offline { background: var(--closed-color); }
.status-dot.busy { background: var(--warning); }

.sidebar-header .agent-info {
  flex: 1;
  min-width: 0;
}

.agent-info .name {
  font-weight: 600;
  color: var(--text-primary);
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.agent-info .role-badge {
  font-size: 11px;
  color: var(--text-light);
}

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

.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--text-light);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}

.icon-btn:hover {
  background: rgba(0,0,0,0.06);
  color: var(--text-primary);
}

/* WA Status */
.wa-status-bar {
  background: var(--bg-base);
  padding: 6px 16px;
  display: flex;
  align-items: center;
  gap: 8px;
  border-top: 1px solid var(--border-dark);
}

.wa-indicator {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--closed-color);
  flex-shrink: 0;
}

.wa-indicator.connected { background: var(--success); animation: pulse 2s infinite; }
.wa-indicator.qr { background: var(--warning); animation: pulse 1s infinite; }
.wa-indicator.disconnected { background: var(--danger); }

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

.wa-status-text {
  font-size: 12px;
  color: var(--text-light);
  flex: 1;
}

.wa-qr-btn {
  font-size: 11px;
  color: #ffffff;
  background: none;
  border: none;
  cursor: pointer;
  padding: 2px 8px;
  font-weight: 600;
  opacity: 0.9;
}

/* Filters */
.conv-filters {
  display: flex;
  flex-wrap: wrap;
  padding: 6px 8px;
  gap: 4px;
  background: var(--sidebar-header);
}

.filter-btn {
  padding: 4px 10px;
  border-radius: 20px;
  border: 1px solid var(--border-dark);
  background: transparent;
  color: var(--text-secondary);
  font-size: 11px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s, border-color 0.15s, box-shadow 0.15s;
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 1 1 auto;
  justify-content: center;
}

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

.filter-btn.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
  box-shadow: 0 2px 6px rgba(29,168,81,0.25);
}

/* Cerrados filter uses gray when active instead of green */
.filter-btn[data-filter="closed"].active {
  background: var(--closed-color);
  border-color: var(--closed-color);
}


.filter-count {
  background: rgba(0,0,0,0.12);
  border-radius: 10px;
  padding: 1px 6px;
  font-size: 10px;
  font-weight: 700;
}

.filter-btn:not(.active) .filter-count {
  background: var(--sidebar-hover);
  color: var(--text-light);
}

/* Search */
.conv-search {
  padding: 8px 12px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border-dark);
}

.search-input-wrap {
  position: relative;
}

.search-input-wrap svg {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-light);
  width: 16px;
  height: 16px;
}

.search-input-wrap input {
  width: 100%;
  padding: 8px 12px 8px 34px;
  background: var(--bg-input);
  border: 1px solid var(--border-dark);
  border-radius: 8px;
  color: var(--text-white);
  font-size: 13px;
  outline: none;
  transition: border-color 0.15s;
}

.search-input-wrap input:focus { border-color: var(--primary); box-shadow: 0 0 0 2px rgba(29,168,81,0.1); }
.search-input-wrap input::placeholder { color: var(--text-light); }

.search-row { display: flex; gap: 6px; align-items: center; }
.search-row .search-input-wrap { flex: 1; }

.search-filter-btn {
  position: relative;
  flex-shrink: 0;
  width: 34px;
  height: 34px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-input);
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.search-filter-btn:hover { background: var(--bg-hover); border-color: var(--primary); color: var(--primary); }
.search-filter-btn.active { background: var(--primary); border-color: var(--primary); color: #fff; }

.sfp-count {
  position: absolute;
  top: -5px;
  right: -5px;
  background: var(--danger);
  color: #fff;
  border-radius: 50%;
  font-size: 10px;
  width: 16px;
  height: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  line-height: 1;
}

.search-filter-panel {
  margin-top: 8px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sfp-row { display: flex; flex-direction: column; gap: 4px; }

.sfp-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.sfp-select {
  width: 100%;
  padding: 6px 8px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-primary);
  font-size: 13px;
}

.sfp-chips { display: flex; flex-wrap: wrap; gap: 4px; }

.sfp-chip {
  padding: 3px 9px;
  border-radius: 12px;
  border: 1px solid transparent;
  font-size: 12px;
  cursor: pointer;
  transition: opacity 0.15s, box-shadow 0.15s;
  color: var(--text-primary);
}
.sfp-chip:hover { opacity: 0.8; }
.sfp-chip.selected { box-shadow: 0 0 0 2px var(--primary); }

.sfp-actions { display: flex; justify-content: flex-end; }

.sfp-clear-btn {
  font-size: 12px;
  color: var(--text-secondary);
  background: none;
  border: none;
  cursor: pointer;
  padding: 2px 4px;
  text-decoration: underline;
}
.sfp-clear-btn:hover { color: var(--danger); }

.search-results-hdr {
  padding: 6px 12px 4px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-light);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border-dark);
}

/* Conversations List */
.conv-list {
  flex: 1;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border-dark) transparent;
}

.conv-list::-webkit-scrollbar { width: 4px; }
.conv-list::-webkit-scrollbar-track { background: transparent; }
.conv-list::-webkit-scrollbar-thumb { background: var(--border-dark); border-radius: 2px; }

.conv-item {
  display: flex;
  align-items: center;
  padding: 11px 16px;
  gap: 12px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background 0.15s, box-shadow 0.15s;
  position: relative;
}

.conv-item:hover { background: var(--bg-hover); }
.conv-item.active {
  background: #edf7f0;
  box-shadow: inset 4px 0 0 var(--primary);
}
.conv-item.starred {
  box-shadow: inset 3px 0 0 #f59e0b;
}
.conv-item.starred.active {
  box-shadow: inset 3px 0 0 var(--primary-light);
}
.conv-item.blocked {
  opacity: 0.72;
  box-shadow: inset 3px 0 0 #e53e3e;
}
.conv-item.blocked.active {
  box-shadow: inset 3px 0 0 #e53e3e;
}
.blocked-badge {
  font-size: 10px;
  font-weight: 600;
  padding: 1px 5px;
  border-radius: 4px;
  background: #fff0f0;
  color: #e53e3e;
  border: 1px solid #fecaca;
  white-space: nowrap;
}

/* Closed conversations appear muted */
.conv-item.conv-closed { opacity: 0.6; }
.conv-item.conv-closed .conv-avatar { filter: grayscale(0.6); }
.conv-item.conv-closed:hover { opacity: 0.8; }

.conv-avatar-wrap {
  position: relative;
  flex-shrink: 0;
}

.conv-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  color: white;
  font-size: 18px;
  flex-shrink: 0;
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0,0,0,0.12);
}

.conv-avatar.has-photo {
  background: transparent;
}

/* Profile photo inside any avatar circle */
.avatar-photo {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
  display: block;
}

/* Channel badge — small circle at bottom-right of avatar */
.channel-badge {
  position: absolute;
  bottom: -1px;
  right: -1px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid var(--bg-sidebar);
  display: flex;
  align-items: center;
  justify-content: center;
}

.channel-badge-lg {
  width: 22px;
  height: 22px;
  bottom: 0;
  right: 0;
}

.channel-whatsapp {
  background: #25D366;
}

.channel-internal {
  background: #3b82f6;
}

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

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

.conv-name {
  font-weight: 600;
  color: var(--text-primary);
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  letter-spacing: -0.1px;
}

.conv-time {
  font-size: 11.5px;
  color: var(--text-secondary);
  flex-shrink: 0;
  margin-left: 8px;
}

.conv-star-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  background: none;
  border: none;
  padding: 2px;
  margin-left: 4px;
  cursor: pointer;
  color: var(--text-light);
  opacity: 0;
  transition: opacity 0.15s, color 0.15s;
  border-radius: 4px;
}
.conv-item:hover .conv-star-btn,
.conv-item .conv-star-btn.active {
  opacity: 1;
}
.conv-star-btn.active {
  color: #f59e0b;
}
.conv-star-btn:hover {
  color: #f59e0b;
  background: rgba(245,158,11,0.1);
}

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

.conv-preview {
  font-size: 13px;
  color: #7a8898;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

.conv-badges {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.status-badge {
  padding: 2px 7px;
  border-radius: 10px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  white-space: nowrap;
}

.status-badge.bot { background: rgba(123,97,255,0.12); color: var(--bot-color); border: 1px solid rgba(123,97,255,0.2); }
.status-badge.waiting { background: rgba(217,119,6,0.1); color: var(--waiting-color); border: 1px solid rgba(217,119,6,0.2); }
.status-badge.active { background: rgba(29,168,81,0.1); color: var(--active-color); border: 1px solid rgba(29,168,81,0.2); }
.status-badge.closed { background: rgba(154,165,177,0.12); color: var(--closed-color); border: 1px solid rgba(154,165,177,0.2); }

.unread-count {
  background: var(--primary);
  color: white;
  border-radius: 10px;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  flex-shrink: 0;
}

.conv-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 48px 24px;
  color: var(--text-light);
  text-align: center;
  gap: 10px;
}

.conv-empty svg {
  opacity: 0.18;
  color: var(--primary);
  margin-bottom: 4px;
}

.conv-empty strong {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
  display: block;
}

.conv-empty span {
  font-size: 13px;
  color: var(--text-light);
  line-height: 1.5;
}

/* ============================================================
   CHAT AREA
   ============================================================ */
.chat-area {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg-chat);
  position: relative;
  overflow: hidden;
}

/* Active chat fills the full column; min-height:0 lets it shrink to the
   container's height instead of growing to match message content */
#active-chat {
  display: none;
  flex: 1;
  min-height: 0;
  flex-direction: column;
}

.chat-empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  color: var(--text-secondary);
  text-align: center;
  padding: 40px;
  background: radial-gradient(ellipse at 50% 55%, rgba(29,168,81,0.05) 0%, transparent 68%);
}

.chat-empty-state svg {
  opacity: 0.16;
  color: var(--primary);
  filter: drop-shadow(0 4px 8px rgba(29,168,81,0.15));
}
.chat-empty-state h2 {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-primary);
  opacity: 0.55;
  letter-spacing: -0.3px;
}
.chat-empty-state p {
  font-size: 14px;
  color: var(--text-light);
  max-width: 280px;
  line-height: 1.6;
}

/* Chat Header */
.chat-header {
  background: #ffffff;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
  z-index: 10;
}

.chat-header-avatar-wrap {
  position: relative;
  flex-shrink: 0;
}

.chat-header-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  color: white;
  font-size: 16px;
  cursor: pointer;
  overflow: hidden;
}

.chat-header-avatar.has-photo {
  background: transparent;
}

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

.chat-header-phone {
  font-size: 11px;
  color: var(--text-secondary);
  line-height: 1.3;
}

.chat-header-name {
  font-weight: 600;
  color: var(--text-primary);
  font-size: 15px;
}

.chat-header-sub {
  font-size: 12px;
  color: var(--text-light);
  display: flex;
  align-items: center;
  gap: 6px;
}

.chat-header-sub .status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
}

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

/* Messages Area */
.messages-container {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  scroll-behavior: smooth;
}

.messages-container::-webkit-scrollbar { width: 4px; }
.messages-container::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.2); border-radius: 2px; }

.msg-date-separator {
  text-align: center;
  margin: 12px 0;
}

.msg-date-separator span {
  background: rgba(255,255,255,0.8);
  color: var(--text-secondary);
  font-size: 12px;
  padding: 4px 12px;
  border-radius: 12px;
  box-shadow: var(--shadow);
}

.msg-bubble {
  max-width: 65%;
  position: relative;
  margin-bottom: 2px;
}

.msg-bubble.from-contact { align-self: flex-start; }
.msg-bubble.from-agent, .msg-bubble.from-bot { align-self: flex-end; }

.msg-content {
  padding: 8px 12px;
  border-radius: 14px;
  position: relative;
  word-wrap: break-word;
  white-space: pre-wrap;
  line-height: 1.55;
  font-size: 14px;
}

.msg-bubble.from-contact .msg-content {
  background: var(--msg-received);
  border-top-left-radius: 4px;
  color: var(--text-primary);
  box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

.msg-bubble.from-agent .msg-content {
  background: var(--msg-sent);
  border-top-right-radius: 4px;
  color: var(--text-primary);
  box-shadow: 0 1px 2px rgba(0,0,0,0.08);
}

.msg-bubble.from-bot .msg-content {
  background: #F0EBFF;
  border-top-right-radius: 4px;
  color: var(--text-primary);
  box-shadow: 0 1px 2px rgba(0,0,0,0.08);
  border-left: 3px solid var(--bot-color);
}

.msg-meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  margin-top: 3px;
}

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

.msg-edited-badge {
  font-size: 11px;
  color: var(--text-secondary);
  font-style: italic;
  margin-right: 4px;
}

.msg-status {
  display: inline-flex;
  align-items: center;
  margin-left: 1px;
  color: var(--text-secondary);
  flex-shrink: 0;
}
.msg-si { display: block; }
.msg-si.status-read { color: var(--accent); }
.msg-si.status-failed { color: var(--danger, #e53e3e); }

.msg-retry-btn {
  background: none;
  border: none;
  padding: 0;
  margin: 0;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  line-height: 1;
}
.msg-retry-btn:hover .status-failed { opacity: 0.65; }

.msg-sender-tag {
  font-size: 11px;
  color: var(--primary);
  font-weight: 600;
  margin-bottom: 2px;
}

.msg-bubble.from-bot .msg-sender-tag { color: var(--bot-color); }

/* ── Message media elements ── */
.msg-media-img {
  max-width: 240px;
  border-radius: 8px;
  display: block;
  cursor: zoom-in;
}

.msg-media-video {
  max-width: 260px;
  border-radius: 8px;
  display: block;
}

.msg-media-audio {
  display: block;
  min-width: 200px;
  max-width: 280px;
  margin: 2px 0;
}

.msg-media-doc {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  background: rgba(0,0,0,0.05);
  border: 1px solid rgba(0,0,0,0.1);
  border-radius: 8px;
  color: var(--text-primary);
  text-decoration: none;
  font-size: 13px;
  max-width: 240px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: background 0.15s;
}

.msg-media-doc:hover { background: rgba(0,0,0,0.10); text-decoration: none; }

.msg-caption {
  display: block;
  margin-top: 4px;
  font-size: 13px;
}

.msg-no-media {
  color: var(--text-secondary);
  font-size: 13px;
  font-style: italic;
}
.msg-video-oversized {
  display: block;
  padding: 6px 10px;
  background: rgba(0,0,0,0.04);
  border-radius: 8px;
  border-left: 3px solid #f59e0b;
  font-style: normal;
}

.typing-indicator {
  align-self: flex-start;
  background: var(--msg-received);
  padding: 10px 14px;
  border-radius: 12px;
  border-top-left-radius: 3px;
  box-shadow: var(--shadow);
  display: none;
}

.typing-indicator.visible { display: flex; gap: 4px; align-items: center; }

.typing-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-light);
  animation: typingBounce 1.2s infinite;
}

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

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

/* Chat input section — never shrink so it's always visible */
#chat-input-section {
  flex-shrink: 0;
  position: relative;
}

/* Attachment preview strip — WhatsApp-like */
.attach-preview {
  background: #f0f2f5;
  border-top: 1px solid var(--border);
  padding: 10px 16px 8px;
  flex-shrink: 0;
}
.attach-thumbs {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding-bottom: 2px;
  scrollbar-width: thin;
}
.attach-thumbs::-webkit-scrollbar { height: 4px; }
.attach-thumbs::-webkit-scrollbar-track { background: transparent; }
.attach-thumbs::-webkit-scrollbar-thumb { background: rgba(0,0,0,.18); border-radius: 2px; }
.attach-thumb {
  position: relative;
  flex-shrink: 0;
  width: 80px;
}
.attach-thumb-img {
  width: 80px;
  height: 80px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid rgba(0,0,0,.08);
  display: block;
}
.attach-thumb-icon {
  width: 80px;
  height: 80px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 30px;
}
.attach-thumb-remove {
  position: absolute;
  top: -7px;
  right: -7px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--danger, #e53e3e);
  color: #fff;
  border: 2px solid #f0f2f5;
  cursor: pointer;
  font-size: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  padding: 0;
  box-shadow: 0 1px 3px rgba(0,0,0,.2);
}
.attach-thumb-remove:hover { opacity: 0.85; }

.attach-clear-btn {
  align-self: center;
  flex-shrink: 0;
  margin-left: 6px;
  padding: 4px 10px;
  border-radius: 6px;
  border: 1px solid var(--border-dark);
  background: #fff;
  color: var(--text-secondary);
  font-size: 11.5px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s;
}
.attach-clear-btn:hover { background: #fee2e2; color: #dc2626; border-color: #dc2626; }

/* Message Input */
.chat-input-area {
  background: #ffffff;
  padding: 10px 16px 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  border-top: 1px solid var(--border);
}

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

.chat-input-wrap {
  background: var(--bg-input);
  border: 1.5px solid var(--border);
  border-radius: 12px;
  padding: 8px 8px 8px 14px;
  display: flex;
  align-items: flex-end;
  gap: 6px;
  transition: border-color 0.15s;
}

.chat-input-wrap:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(29,168,81,0.1);
}

#message-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.5;
  resize: none;
  max-height: 260px;
  font-family: inherit;
}

#message-input::placeholder { color: var(--text-light); }

/* Bottom bar: toggle left, icons+send right */
.chat-input-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

/* Enter-sends toggle */
.enter-send-toggle {
  display: flex;
  align-items: center;
  gap: 7px;
  cursor: pointer;
  user-select: none;
  flex-shrink: 0;
}
.enter-send-toggle input[type="checkbox"] { display: none; }
.es-track {
  width: 32px;
  height: 18px;
  border-radius: 9px;
  background: #d1d5db;
  position: relative;
  transition: background 0.2s;
  flex-shrink: 0;
}
.enter-send-toggle input:checked + .es-track { background: var(--primary); }
.es-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #fff;
  transition: left 0.2s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.18);
}
.enter-send-toggle input:checked + .es-track .es-thumb { left: 16px; }
.es-label {
  font-size: 11.5px;
  color: var(--text-secondary);
  white-space: nowrap;
}

.send-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--primary);
  border: none;
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: var(--transition);
  box-shadow: 0 2px 6px rgba(29,168,81,0.3);
}

.send-btn:hover {
  background: var(--primary-dark);
  transform: scale(1.06);
  box-shadow: 0 3px 10px rgba(29,168,81,0.4);
}


@media (max-width: 640px) {
  .es-label { display: none; }
}

.chat-input-disabled {
  padding: 12px 16px;
  text-align: center;
  color: var(--text-secondary);
  font-size: 13px;
  background: #ffffff;
  border-top: 1px solid var(--border);
}

/* ============================================================
   INFO PANEL (Right)
   ============================================================ */
.info-panel {
  width: 280px;
  min-width: 260px;
  flex-shrink: 0;
  background: #ffffff;
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.info-panel::-webkit-scrollbar { width: 4px; }
.info-panel::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

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

.info-section-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

.contact-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 8px;
}

.contact-avatar-wrap {
  position: relative;
  display: inline-block;
}

.contact-big-avatar {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 26px;
  font-weight: 700;
  color: white;
  overflow: hidden;
}

.contact-big-avatar.has-photo {
  background: transparent;
}

.contact-name { font-weight: 700; font-size: 16px; }
.contact-phone { color: var(--text-secondary); font-size: 13px; }

.info-field {
  margin-bottom: 12px;
}

.info-field label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.info-field input,
.info-field select,
.info-field textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  outline: none;
  transition: var(--transition);
  font-family: inherit;
  resize: vertical;
}

.info-field input:focus,
.info-field select:focus,
.info-field textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(18, 140, 126, 0.1);
}

.info-save-btn {
  padding: 7px 16px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: var(--radius);
  font-size: 13px;
  cursor: pointer;
  transition: var(--transition);
  margin-top: 4px;
}

.info-save-btn:hover { background: var(--primary-dark); }

/* Action buttons */
.action-buttons {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.action-btn {
  padding: 9px 14px;
  border-radius: var(--radius);
  border: none;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
}

.action-btn:hover { filter: brightness(0.96); transform: translateY(-1px); box-shadow: 0 3px 8px rgba(0,0,0,0.12); }
.action-btn:active { transform: scale(0.98); filter: none; box-shadow: none; }

.action-btn.take { background: var(--primary); color: white; box-shadow: 0 2px 6px rgba(29,168,81,0.25); }
.action-btn.take:hover { background: var(--primary-dark); }
.action-btn.close { background: var(--bg-elevated); color: var(--text-secondary); border: 1px solid var(--border); }
.action-btn.close:hover { background: #fef2f2; color: var(--danger); border-color: #fecaca; }
.action-btn.transfer { background: var(--accent); color: white; box-shadow: 0 2px 6px rgba(37,99,235,0.2); }
.action-btn.transfer:hover { background: #1d4ed8; }
.action-btn.reopen { background: #fffbeb; color: var(--warning); border: 1px solid #fde68a; }
.action-btn.reopen:hover { background: var(--warning); color: white; }
.action-btn.unblock { background: #f0fff4; color: #276749; border: 1px solid #9ae6b4; }
.action-btn.unblock:hover { background: #276749; color: white; border-color: #276749; }
.action-btn.unassign { background: #fff5f5; color: var(--danger); border: 1px solid #fed7d7; }
.action-btn.unassign:hover { background: var(--danger); color: white; border-color: var(--danger); }
.action-btn.skip-waiting { background: #f0fdf4; color: #3d7a57; border: 1px solid #bbf7d0; }
.action-btn.skip-waiting:hover { background: #dcfce7; color: #166534; border-color: #86efac; }

.block-contact-link {
  display: block;
  width: 100%;
  background: none;
  border: none;
  padding: 10px 16px 14px;
  text-align: center;
  font-size: 11px;
  color: var(--text-light);
  cursor: pointer;
  transition: color 0.15s;
  text-decoration: none;
}
.block-contact-link:hover {
  color: #e53e3e;
}

/* ============================================================
   BLOCK CONTACT MODAL
   ============================================================ */
.modal-box {
  background: var(--bg-primary);
  border-radius: 14px;
  width: 100%;
  max-width: 480px;
  box-shadow: 0 24px 64px rgba(0,0,0,0.25), 0 4px 16px rgba(0,0,0,0.1);
  animation: modalIn 0.22s cubic-bezier(0.34, 1.3, 0.64, 1);
  overflow: hidden;
}

.block-modal {
  background: white;
  border-radius: 14px;
  width: 100%;
  max-width: 420px;
  padding: 24px;
  box-shadow: 0 24px 64px rgba(0,0,0,0.22), 0 4px 16px rgba(0,0,0,0.08);
  animation: modalIn 0.22s cubic-bezier(0.34, 1.3, 0.64, 1);
}
.block-modal-header {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 17px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 14px;
}
.block-modal-desc {
  font-size: 13px;
  color: var(--text-secondary);
  margin: 0 0 8px;
}
.block-modal-list {
  font-size: 13px;
  color: var(--text-secondary);
  margin: 0 0 16px;
  padding-left: 18px;
  line-height: 1.7;
}
.block-wa-section {
  border-top: 1px solid var(--border);
  padding-top: 14px;
  margin-bottom: 20px;
}
.block-wa-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  cursor: pointer;
  user-select: none;
}
.block-wa-label input[type="checkbox"] {
  width: 15px;
  height: 15px;
  cursor: pointer;
  flex-shrink: 0;
}
.block-wa-warning {
  display: flex;
  align-items: flex-start;
  gap: 7px;
  margin-top: 10px;
  background: #fffbeb;
  border: 1px solid #fde68a;
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 12px;
  color: #92400e;
  line-height: 1.5;
}
.block-wa-warning svg { flex-shrink: 0; margin-top: 1px; color: #d97706; }
.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}
.modal-btn {
  padding: 8px 20px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: var(--transition);
}
.modal-btn-secondary {
  background: var(--bg-elevated);
  color: var(--text-secondary);
  border: 1px solid var(--border);
}
.modal-btn-secondary:hover { background: var(--bg-hover); }
.modal-btn-danger {
  background: #e53e3e;
  color: white;
}
.modal-btn-danger:hover { background: #c53030; }

.assigned-agent {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.assigned-agent .agent-avatar-sm {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  color: white;
  font-size: 14px;
}

.assigned-agent .agent-details { flex: 1; }
.assigned-agent .agent-details .agent-name { font-weight: 600; font-size: 14px; }
.assigned-agent .agent-details .agent-status-text { font-size: 12px; color: var(--text-secondary); }

/* Quick Replies Panel */
.qr-panel-inner {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.quick-replies-search {
  padding: 10px 12px 8px;
  flex-shrink: 0;
}

.qr-search-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.qr-search-wrap svg {
  position: absolute;
  left: 10px;
  color: var(--text-secondary);
  pointer-events: none;
  flex-shrink: 0;
}

.qr-search-wrap input {
  width: 100%;
  padding: 8px 12px 8px 32px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  background: var(--bg);
  color: var(--text-primary);
  outline: none;
  transition: border-color .15s;
  box-sizing: border-box;
}

.qr-search-wrap input:focus { border-color: var(--primary); }

#quick-replies-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 12px 8px;
}

.qr-panel-footer {
  padding: 8px 12px 10px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.qr-category {
  margin-bottom: 18px;
}

.qr-category-title {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 10px;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: .7px;
  margin-bottom: 8px;
  padding-top: 2px;
}

.qr-category-title::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

.qr-cat-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}

.qr-item {
  padding: 9px 11px;
  border-radius: 7px;
  cursor: pointer;
  margin-bottom: 6px;
  background: var(--surface, #fff);
  border: 1px solid var(--border);
  border-left: 3px solid var(--qr-accent, #94a3b8);
  transition: box-shadow .15s, background .15s;
}

.qr-item:hover {
  background: #f5f8ff;
  box-shadow: 0 2px 8px rgba(0,0,0,.07);
}

.qr-item:last-child { margin-bottom: 0; }

.qr-item-title {
  display: flex;
  align-items: center;
  gap: 5px;
  font-weight: 600;
  font-size: 13px;
  margin-bottom: 3px;
  color: var(--text-primary);
}

.qr-shortcut-badge {
  font-family: monospace;
  font-size: 10px;
  background: #E8F5E9;
  color: #17803e;
  border-radius: 3px;
  padding: 1px 4px;
  flex-shrink: 0;
}

.qr-item-preview {
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.4;
}

/* ============================================================
   ICON BAR (Far-left vertical navigation)
   ============================================================ */
.icon-bar {
  width: 52px;
  min-width: 52px;
  flex-shrink: 0;
  background: #f7f9fb;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 6px 0;
  gap: 2px;
  z-index: 10;
  overflow: hidden;
}

.ibar-btn {
  position: relative;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  border: none;
  background: transparent;
  color: #6b7785;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s, transform 0.12s;
  flex-shrink: 0;
}

.ibar-btn:hover {
  background: rgba(0,0,0,0.07);
  color: var(--text-primary);
  transform: scale(1.08);
}

.ibar-btn.active {
  background: rgba(29,168,81,0.12);
  color: var(--primary);
  box-shadow: inset 4px 0 0 var(--primary);
  border-radius: 0 10px 10px 0;
  transform: none;
}
[data-category="destacados"].ibar-btn.active {
  background: rgba(245,158,11,0.1);
  color: #f59e0b;
  box-shadow: inset 3px 0 0 #f59e0b;
}
[data-category="bloqueados"].ibar-btn.active {
  background: rgba(229,62,62,0.1);
  color: #e53e3e;
  box-shadow: inset 3px 0 0 #e53e3e;
}
.ibar-badge-danger {
  background: #e53e3e;
}

.ibar-badge {
  position: absolute;
  top: 3px;
  right: 3px;
  min-width: 16px;
  height: 16px;
  background: var(--danger);
  color: white;
  border-radius: 8px;
  font-size: 9px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 3px;
  line-height: 1;
  pointer-events: none;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.ibar-sep {
  width: 28px;
  height: 1px;
  background: var(--border);
  margin: 4px 0;
  flex-shrink: 0;
}

.ibar-spacer {
  flex: 1;
}

.ibar-new {
  background: var(--primary);
  color: white;
  margin-bottom: 2px;
}

.ibar-new:hover {
  background: var(--primary-dark) !important;
  color: white !important;
}

.ibar-internos.active {
  color: #3b82f6;
  background: rgba(59,130,246,0.10);
  box-shadow: inset 3px 0 0 #3b82f6;
}

.ibar-admin-toggle {
  height: auto;
  padding: 5px 0 4px;
  flex-direction: column;
  gap: 2px;
}
.ibar-admin-label {
  font-size: 8px;
  font-weight: 700;
  line-height: 1;
  letter-spacing: .03em;
}
.ibar-admin-toggle.admin-mode-on {
  background: rgba(37,99,235,0.12);
  color: var(--accent);
  box-shadow: inset 3px 0 0 var(--accent);
  border-radius: 0 10px 10px 0;
}

/* New chat warning */
.new-chat-warning {
  background: #FFF8E1;
  border: 1px solid #FBBC04;
  border-radius: var(--radius);
  padding: 10px 12px;
  font-size: 12px;
  color: #856404;
  line-height: 1.5;
  margin-bottom: 16px;
}

/* ============================================================
   TOP NAVIGATION BAR
   ============================================================ */
#top-nav {
  display: none;
  height: 50px;
  background: #1a54d4;
  border-bottom: 1px solid #1748c0;
  box-shadow: 0 2px 8px rgba(26,84,212,0.22);
  flex-shrink: 0;
  align-items: center;
  padding: 0 12px 0 16px;
  gap: 0;
  z-index: 100;
}

#app.visible #top-nav { display: flex; }

/* Logo */
.topnav-logo {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #ffffff;
  margin-right: 20px;
  flex-shrink: 0;
}

.topnav-brand {
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 1px;
  color: #ffffff;
}

/* Center nav area */
.topnav-center {
  display: flex;
  align-items: center;
  flex: 1;
  gap: 2px;
  overflow-x: auto;
  scrollbar-width: none;
}

.topnav-center::-webkit-scrollbar { display: none; }

/* ── Main nav buttons (Mensajería, Contactos, Historial…) ── */
.topnav-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0 13px;
  height: 38px;
  border: none;
  background: transparent;
  color: rgba(255,255,255,0.88);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border-radius: 7px;
  transition: color 0.15s, background 0.15s, box-shadow 0.15s;
  text-decoration: none;
  white-space: nowrap;
  flex-shrink: 0;
}

.topnav-btn:hover {
  background: rgba(255,255,255,0.12);
  color: #ffffff;
}

/* Active: white-tinted bg + white bottom stripe */
.topnav-btn.active {
  background: rgba(255,255,255,0.16);
  color: #ffffff;
  font-weight: 600;
  box-shadow: inset 0 -3px 0 rgba(255,255,255,0.85);
}

/* ── External tool buttons (Calendario, Cotizador) ── */
.topnav-ext {
  color: #ffffff;
  background: rgba(255,255,255,0.12);
  border: 1px solid rgba(255,255,255,0.25);
  border-radius: 7px;
  font-weight: 500;
}

.topnav-ext:hover {
  background: rgba(255,255,255,0.22);
  border-color: rgba(255,255,255,0.4);
  color: #ffffff;
  box-shadow: none;
}

.ext-icon {
  opacity: 0.75;
  flex-shrink: 0;
}

/* Separator */
.topnav-sep {
  width: 1px;
  height: 24px;
  background: rgba(255,255,255,0.25);
  margin: 0 8px;
  flex-shrink: 0;
}

/* Right section */
.topnav-right {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: 12px;
  flex-shrink: 0;
}

/* WA status pill */
.topnav-wa {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  border-radius: 20px;
  background: rgba(255,255,255,0.12);
  border: 1px solid rgba(255,255,255,0.22);
  margin-right: 4px;
}

.topnav-wa-text {
  font-size: 11px;
  color: rgba(255,255,255,0.85);
  white-space: nowrap;
  max-width: 130px;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* User info group */
.topnav-user {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 8px;
  border-radius: 7px;
  cursor: pointer;
  transition: var(--transition);
}

.topnav-user:hover { background: rgba(255,255,255,0.12); }

.topnav-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  color: white;
  font-size: 12px;
  position: relative;
  flex-shrink: 0;
}

.topnav-avatar .status-dot {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  border: 2px solid #1e5db8;
}

.topnav-user-info {
  display: flex;
  flex-direction: column;
}

.topnav-user-name {
  font-size: 12px;
  font-weight: 600;
  color: #ffffff;
  white-space: nowrap;
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topnav-user-role {
  font-size: 10px;
  color: rgba(255,255,255,0.7);
}

/* Icon-only buttons in topnav right */
.topnav-icon {
  color: rgba(255,255,255,0.8);
}

.topnav-icon:hover {
  background: rgba(255,255,255,0.12);
  color: #ffffff;
}

/* ============================================================
   CALCULATOR POPOVER
   ============================================================ */
.topnav-calc-btn {
  font-size: 13px;
  font-weight: 500;
  margin-left: auto;
}
.topnav-calc-btn.active {
  background: rgba(255,255,255,0.28) !important;
  border-color: rgba(255,255,255,0.5) !important;
}

#calc-popover {
  position: fixed;
  z-index: 9500;
  width: 232px;
  background: #ffffff;
  border-radius: 14px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.22), 0 2px 8px rgba(0,0,0,0.12);
  overflow: hidden;
  outline: none;
}
#calc-popover.hidden { display: none; }

.calc-display {
  background: #1a1a2e;
  padding: 14px 16px 10px;
  text-align: right;
  user-select: none;
}
.calc-expr {
  font-size: 12px;
  color: rgba(255,255,255,0.4);
  min-height: 16px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.calc-val {
  font-size: 30px;
  font-weight: 300;
  color: #ffffff;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-top: 2px;
  letter-spacing: -0.5px;
  line-height: 1.1;
}
.calc-val.calc-error {
  color: #fc8181;
  font-size: 22px;
}

.calc-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1px;
  background: #e0e0e0;
}
.calc-btn {
  background: #f8f8f8;
  border: none;
  padding: 0;
  height: 50px;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.08s;
  color: #1a1a2e;
  font-weight: 400;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.calc-btn:hover { background: #efefef; }
.calc-btn:active { background: #e0e0e0; transform: scale(0.96); }

.calc-btn.calc-span2 { grid-column: span 2; }

.calc-btn.calc-clear {
  background: #fff0f0;
  color: #e53e3e;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.5px;
}
.calc-btn.calc-clear:hover { background: #ffdede; }

.calc-btn.calc-back {
  background: #fff8f0;
  color: #c05621;
  font-size: 16px;
}
.calc-btn.calc-back:hover { background: #ffecd6; }

.calc-btn.calc-op {
  background: #f0f4ff;
  color: #2563eb;
  font-size: 20px;
  font-weight: 500;
}
.calc-btn.calc-op:hover { background: #dce7ff; }
.calc-btn.calc-op:active { background: #c7d7fc; }

.calc-btn.calc-equal {
  background: #2563eb;
  color: #ffffff;
  font-size: 22px;
  font-weight: 500;
}
.calc-btn.calc-equal:hover { background: #1d4ed8; }
.calc-btn.calc-equal:active { background: #1e40af; }

/* Utility row: %, $, Copiar */
.calc-util-row {
  display: grid;
  grid-template-columns: 1fr 1fr 2fr;
  gap: 1px;
  background: #c0ccd8;
  border-top: 2px solid #c0ccd8;
}
.calc-btn.calc-util {
  height: 44px;
  font-size: 15px;
  font-weight: 600;
}
.calc-btn.calc-pct {
  background: #f0fff4;
  color: #276749;
}
.calc-btn.calc-pct:hover { background: #c6f6d5; }
.calc-btn.calc-dollar {
  background: #e6fffa;
  color: #2c7a7b;
}
.calc-btn.calc-dollar:hover { background: #b2f5ea; }
.calc-btn.calc-copy {
  background: #ebf4ff;
  color: #2563eb;
  font-size: 13px;
  letter-spacing: 0.3px;
}
.calc-btn.calc-copy:hover { background: #dce7ff; }

/* Currency display state */
.calc-val.calc-currency {
  color: #68d391;
  font-size: 26px;
}

/* Contacts placeholder view */
#contacts-view {
  display: none;
  flex: 1;
  align-items: center;
  justify-content: center;
  background: var(--bg-chat);
}

.contacts-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  color: var(--text-secondary);
  text-align: center;
}

.contacts-placeholder svg { opacity: 0.3; }
.contacts-placeholder h2 { font-size: 20px; font-weight: 700; color: var(--text-secondary); }
.contacts-placeholder p { font-size: 14px; }

/* ============================================================
   INFO PANEL TABS
   ============================================================ */
.info-tabs {
  display: flex;
  background: #ffffff;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  overflow-x: auto;
}

.info-tabs::-webkit-scrollbar { height: 0; }

.info-tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 10px 4px 8px;
  border: none;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.2px;
  transition: var(--transition);
  min-width: 0;
}

.info-tab:hover {
  background: rgba(0,0,0,0.03);
  color: var(--text-primary);
}

.info-tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
  background: rgba(29,168,81,0.05);
}

.info-tab svg { flex-shrink: 0; }

.info-tab span {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
  padding: 0 2px;
}

#info-content {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
  min-height: 0;
}

.tab-panel {
  display: none;
  flex: 1;
  flex-direction: column;
  overflow-y: auto;
  min-height: 0;
}

.tab-panel::-webkit-scrollbar { width: 4px; }
.tab-panel::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.tab-panel.active { display: flex; }

/* Labels tab */
.labels-list {
  padding: 16px;
}

.label-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: var(--transition);
  margin-bottom: 6px;
  border: 1px solid var(--border);
  user-select: none;
}

.label-item:hover { background: #F5F5F5; }

.label-item input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--primary);
  cursor: pointer;
  flex-shrink: 0;
}

.label-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.label-name {
  font-size: 13px;
  font-weight: 500;
  flex: 1;
  color: var(--text-primary);
}

/* Label management — settings panel */
.labels-settings-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 10px;
  min-height: 0;
}

.labels-settings-form {
  padding-bottom: 4px;
}

.labels-existing-section {
  border-top: 1px solid var(--border);
  padding-top: 18px;
  margin-top: 20px;
}

.stab-section-title {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.label-manage-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg, #FAFAFA);
  transition: background .12s;
}

.label-manage-item:hover {
  background: var(--surface-hover, #f5f5f5);
}

.label-manage-name {
  flex: 1;
  font-size: 13px;
  font-weight: 500;
}

.label-manage-actions {
  display: flex;
  gap: 2px;
}

.label-manage-actions .icon-btn {
  width: 28px;
  height: 28px;
  color: var(--text-secondary);
}

.label-manage-actions .icon-btn:hover { background: #F0F2F5; }

/* Color swatches */
.color-swatches {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.color-swatch {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  cursor: pointer;
  border: 3px solid transparent;
  transition: var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.color-swatch:hover { transform: scale(1.15); }

.color-swatch.selected {
  border-color: var(--text-primary);
  box-shadow: 0 0 0 2px white, 0 0 0 4px var(--text-primary);
}

/* Calendar / Quoter tab tool panels */
.tab-tool-panel {
  padding: 32px 20px 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  text-align: center;
}

.tab-tool-icon {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  flex-shrink: 0;
}

.tab-tool-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
}

.tab-tool-desc {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.5;
  max-width: 220px;
}

.tab-tool-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 11px 22px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  text-decoration: none;
  margin-top: 4px;
}

.tab-tool-btn:hover {
  opacity: 0.88;
  transform: translateY(-1px);
  box-shadow: var(--shadow);
}

/* ============================================================
   MODALS
   ============================================================ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.48);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}

.modal-overlay.open {
  display: flex;
  animation: overlayFadeIn 0.2s ease;
}

.modal {
  background: white;
  border-radius: 14px;
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 24px 64px rgba(0,0,0,0.22), 0 4px 16px rgba(0,0,0,0.1);
  animation: modalIn 0.22s cubic-bezier(0.34, 1.3, 0.64, 1);
}

@keyframes modalIn {
  from { transform: scale(0.95) translateY(-10px); opacity: 0; }
  to { transform: scale(1) translateY(0); opacity: 1; }
}

@keyframes overlayFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-header {
  padding: 16px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 700;
  font-size: 16px;
  border-bottom: 1px solid var(--border);
}
.modal-close-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 18px;
  color: var(--text-secondary);
  padding: 2px 6px;
  border-radius: 4px;
  line-height: 1;
}
.modal-close-btn:hover { background: var(--bg-hover); color: var(--text-primary); }
.modal-btn-primary {
  background: var(--primary);
  color: #fff;
  border: none;
  padding: 9px 20px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.modal-btn-primary:hover { background: var(--primary-dark, #0a6b61); }

.modal-header h2 {
  font-size: 18px;
  font-weight: 700;
}

.modal-close {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: #F0F2F5;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  color: var(--text-secondary);
  transition: var(--transition);
}

.modal-close:hover { background: var(--danger); color: white; }

.modal-body { padding: 20px 24px; }
.modal-footer {
  padding: 0 24px 20px;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.btn-secondary {
  padding: 10px 20px;
  background: #F0F2F5;
  border: none;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  color: var(--text-primary);
}

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

.btn-danger {
  padding: 10px 20px;
  background: var(--danger);
  color: white;
  border: none;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
}

/* QR Modal */
.qr-container {
  text-align: center;
  padding: 20px 0;
}

.qr-image {
  width: 240px;
  height: 240px;
  object-fit: contain;
  border: 8px solid white;
  border-radius: 8px;
  box-shadow: var(--shadow-md);
}

.qr-instructions {
  margin-top: 16px;
  color: var(--text-secondary);
  font-size: 13px;
  line-height: 1.6;
}

/* Agents Modal */
.agents-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}

.agent-list-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #F9FAFB;
}

.agent-list-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  color: white;
  font-size: 16px;
  flex-shrink: 0;
}

.agent-list-info { flex: 1; }
.agent-list-name { font-weight: 600; }
.agent-list-email { font-size: 12px; color: var(--text-secondary); }

.agent-list-badges { display: flex; gap: 6px; margin-top: 4px; }
.role-badge-admin { background: rgba(255, 152, 0, 0.15); color: var(--warning); padding: 2px 8px; border-radius: 10px; font-size: 11px; font-weight: 700; }
.role-badge-agent { background: rgba(18, 140, 126, 0.1); color: var(--primary); padding: 2px 8px; border-radius: 10px; font-size: 11px; font-weight: 700; }

.agent-list-actions { display: flex; gap: 4px; }

/* Image Library Modal */
.image-library-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 12px;
  max-height: 360px;
  overflow-y: auto;
}

.image-grid-item {
  position: relative;
  aspect-ratio: 1;
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  border: 2px solid transparent;
  transition: var(--transition);
}

.image-grid-item:hover, .image-grid-item.selected { border-color: var(--primary); }
.image-grid-item img { width: 100%; height: 100%; object-fit: cover; }

.image-grid-item .img-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: flex-end;
  padding: 6px;
  opacity: 0;
  transition: var(--transition);
}

.image-grid-item:hover .img-overlay { opacity: 1; }
.image-grid-item .img-name { font-size: 10px; color: white; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Transfer Modal */
.transfer-agent-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 300px;
  overflow-y: auto;
}

.transfer-agent-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: var(--transition);
}

.transfer-agent-item:hover, .transfer-agent-item.selected { border-color: var(--primary); background: rgba(18, 140, 126, 0.05); }

/* Toast notifications */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: #323232;
  color: white;
  padding: 12px 20px;
  border-radius: var(--radius);
  font-size: 13px;
  box-shadow: var(--shadow-md);
  animation: slideIn 0.3s ease;
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: 360px;
  cursor: pointer;
}

.toast.success { background: #2E7D32; }
.toast.error { background: #C62828; }
.toast.warning { background: #E65100; }
.toast.info { background: var(--primary-dark); }

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* ============================================================
   UTILITY CLASSES
   ============================================================ */
.hidden { display: none !important; }
.flex { display: flex; }
.items-center { align-items: center; }
.gap-8 { gap: 8px; }

/* Upload zone */
.upload-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 32px;
  text-align: center;
  cursor: pointer;
  transition: var(--transition);
  color: var(--text-secondary);
}

.upload-zone:hover, .upload-zone.drag-over {
  border-color: var(--primary);
  background: rgba(18, 140, 126, 0.05);
  color: var(--primary);
}

.upload-zone input[type="file"] { display: none; }

/* Stats bar */
.stats-bar {
  display: flex;
  gap: 4px;
  padding: 4px 8px;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border-dark);
}

.stat-chip {
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  transition: var(--transition);
}

/* Quick replies manage */
.qr-manage-btn {
  width: 100%;
  padding: 7px;
  background: none;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  color: var(--text-secondary);
  font-size: 12px;
  cursor: pointer;
  transition: var(--transition);
}

.qr-manage-btn:hover { border-color: var(--primary); color: var(--primary); }

/* ============================================================
   CHAT TOOLBAR (right side of chat-input-bar)
   ============================================================ */
.chat-toolbar {
  display: flex;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
}

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

.toolbar-btn:hover {
  background: rgba(0,0,0,0.06);
  color: var(--text-primary);
}

.toolbar-btn.active {
  color: var(--primary-light);
  background: rgba(37, 211, 102, 0.12);
}

/* ============================================================
   EMOJI PICKER
   ============================================================ */
.emoji-picker {
  position: absolute;
  bottom: calc(100% + 4px);
  left: 0;
  width: 310px;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.12), 0 2px 6px rgba(0,0,0,0.07);
  z-index: 200;
  overflow: hidden;
}

.emoji-tabs {
  display: flex;
  border-bottom: 1px solid var(--border-dark);
  padding: 4px 6px 0;
  gap: 2px;
  overflow-x: auto;
  scrollbar-width: none;
}

.emoji-tabs::-webkit-scrollbar { display: none; }

.emoji-tab {
  flex-shrink: 0;
  padding: 5px 8px;
  border: none;
  background: transparent;
  font-size: 16px;
  cursor: pointer;
  border-radius: 6px 6px 0 0;
  border-bottom: 2px solid transparent;
  transition: var(--transition);
  line-height: 1;
}

.emoji-tab:hover { background: rgba(0,0,0,0.05); }

.emoji-tab.active {
  border-bottom-color: var(--primary-light);
  background: rgba(37, 211, 102, 0.1);
}

.emoji-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 2px;
  padding: 8px;
  max-height: 200px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border-dark) transparent;
}

.emoji-grid::-webkit-scrollbar { width: 4px; }
.emoji-grid::-webkit-scrollbar-thumb { background: var(--border-dark); border-radius: 2px; }

.emoji-item {
  font-size: 20px;
  line-height: 1;
  padding: 4px;
  border: none;
  background: transparent;
  cursor: pointer;
  border-radius: 6px;
  transition: background 0.1s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.emoji-item:hover { background: rgba(0,0,0,0.06); }

/* ============================================================
   MEDIA LIBRARY (Admin + Selector)
   ============================================================ */
.media-modal {
  max-width: 860px;
  height: 80vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.media-modal .modal-header { flex-shrink: 0; }

.media-admin-body {
  display: flex;
  flex: 1;
  overflow: hidden;
  border-top: 1px solid var(--border);
}

.media-tree-panel {
  width: 200px;
  min-width: 160px;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg-elevated);
}

.media-files-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.media-panel-hdr {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated);
  flex-shrink: 0;
  gap: 6px;
  min-height: 38px;
}

.media-panel-hdr > span {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--text-secondary);
  white-space: nowrap;
}

.media-hdr-btn {
  width: 26px;
  height: 26px;
  border-radius: 6px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: var(--transition);
}

.media-hdr-btn:hover { background: rgba(0,0,0,0.08); color: var(--text-primary); }

.media-upload-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  background: var(--primary);
  color: white;
  border-radius: var(--radius);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
}

.media-upload-btn:hover { background: var(--primary-dark); }

.media-tree-root {
  flex: 1;
  overflow-y: auto;
  padding: 6px 4px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.media-tree-root::-webkit-scrollbar { width: 4px; }
.media-tree-root::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.media-folder-item {
  display: block;
  position: relative;
}

.media-folder-header {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.12s;
}

.media-folder-item:hover > .media-folder-header { background: rgba(0,0,0,0.05); }
.media-folder-item.active > .media-folder-header { background: rgba(29,168,81,0.1); color: var(--primary); }

.media-folder-row {
  display: flex;
  align-items: center;
  gap: 5px;
  flex: 1;
  min-width: 0;
  cursor: pointer;
}

.media-folder-name {
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
  flex: 1;
}

.media-folder-actions {
  display: none;
  gap: 1px;
}

.media-folder-item:hover > .media-folder-header .media-folder-actions { display: flex; }

.media-folder-children {
  list-style: none;
  padding: 0;
  margin: 0;
  padding-left: 16px;
}

.media-fa-btn {
  width: 20px;
  height: 20px;
  border: none;
  background: transparent;
  border-radius: 4px;
  cursor: pointer;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  line-height: 1;
}

.media-fa-btn:hover { background: rgba(0,0,0,0.08); }
.media-fa-btn.danger:hover { background: rgba(234,67,53,0.1); color: var(--danger); }


.media-breadcrumb {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-primary);
  flex: 1;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 1px;
  min-width: 0;
}

.bc-part {
  cursor: pointer;
  padding: 1px 3px;
  border-radius: 3px;
  white-space: nowrap;
  transition: background 0.1s, color 0.1s;
}

.bc-part:hover { background: rgba(29,168,81,0.1); color: var(--primary); }

.bc-sep {
  color: var(--text-secondary);
  font-weight: 400;
  margin: 0 1px;
  user-select: none;
}

.media-files-grid {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: 8px;
  align-content: start;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.media-files-grid::-webkit-scrollbar { width: 4px; }
.media-files-grid::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.media-empty-msg {
  grid-column: 1 / -1;
  color: var(--text-secondary);
  font-size: 13px;
  text-align: center;
  padding: 32px 20px;
}

.media-file-card {
  position: relative;
  border-radius: 8px;
  border: 2px solid transparent;
  overflow: hidden;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s;
  background: var(--bg-input);
  aspect-ratio: 1;
}

.media-file-card:hover { border-color: var(--primary); box-shadow: var(--shadow); }
.media-file-card.selected { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(29,168,81,0.15); }

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

.media-file-video-thumb {
  width: 100%;
  height: 100%;
  background: #e2e8f0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  color: var(--text-secondary);
  font-size: 10px;
  text-align: center;
  padding: 4px;
}

.media-file-video-thumb svg { opacity: 0.8; }

.media-file-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.55);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  padding: 4px;
  opacity: 0;
  transition: opacity 0.15s;
}

.media-file-card:hover .media-file-overlay { opacity: 1; }

.media-file-name {
  font-size: 9px;
  color: white;
  font-weight: 600;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  width: 100%;
}

.media-file-actions {
  display: flex;
  gap: 2px;
  margin-bottom: 2px;
}

.media-file-act-btn {
  width: 22px;
  height: 22px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  background: rgba(255,255,255,0.15);
  color: white;
  transition: background 0.1s;
}

.media-file-act-btn:hover { background: rgba(255,255,255,0.3); }
.media-file-act-btn.danger:hover { background: rgba(234,67,53,0.7); }

/* ============================================================
   CLIENT IMAGES (Info Panel)
   ============================================================ */
.client-images-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  margin-top: 6px;
}

.client-img-thumb {
  aspect-ratio: 1;
  border-radius: 5px;
  overflow: hidden;
  cursor: zoom-in;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  transition: opacity 0.15s, border-color 0.15s;
}

.client-img-thumb:hover { opacity: 0.82; border-color: var(--primary); }

.client-img-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.client-images-empty {
  grid-column: 1 / -1;
  font-size: 12px;
  color: var(--text-secondary);
  text-align: center;
  padding: 6px 0 2px;
}

/* Lightbox */
.lightbox-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.88);
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.lightbox-overlay.hidden { display: none; }

.lightbox-img {
  max-width: 90vw;
  max-height: 88vh;
  object-fit: contain;
  border-radius: 6px;
  box-shadow: 0 8px 40px rgba(0,0,0,0.6);
}

.lightbox-close {
  position: absolute;
  top: 18px;
  right: 22px;
  background: rgba(255,255,255,0.15);
  border: none;
  color: #fff;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
  line-height: 1;
}

.lightbox-close:hover { background: rgba(255,255,255,0.28); }

/* Folder move picker */
.media-move-picker {
  position: absolute;
  top: 0;
  left: 100%;
  background: white;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  z-index: 300;
  min-width: 160px;
  max-height: 200px;
  overflow-y: auto;
  padding: 4px 0;
}

.media-move-opt {
  padding: 7px 12px;
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
}

.media-move-opt:hover { background: #F0F2F5; }

/* Responsive */
@media (max-width: 900px) {
  .info-panel { display: none; }
}

@media (max-width: 640px) {
  .sidebar { width: 100%; }
  .chat-area { display: none; }
  .sidebar.mobile-hidden { display: none; }
  .chat-area.mobile-visible { display: flex; }
}

/* ============================================================
   SETTINGS MODAL
   ============================================================ */
.settings-modal {
  width: min(1020px, 96vw);
  height: min(720px, 92vh);
  max-width: none;
  padding: 0;
  display: flex;
  flex-direction: row;
  overflow: hidden;
  animation: modalIn 0.25s cubic-bezier(0.34, 1.2, 0.64, 1);
  box-shadow: 0 32px 80px rgba(0,0,0,0.24), 0 8px 24px rgba(0,0,0,0.1);
}

/* Left navigation sidebar */
.settings-nav-col {
  width: 200px;
  flex-shrink: 0;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 20px 0 16px;
}

.settings-nav-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 14px;
  color: var(--text-primary);
  padding: 0 16px 20px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 8px;
}

.settings-nav-list {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 0 8px;
}

.settings-nav-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 12px;
  border: none;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text-primary);
  font-size: 13px;
  cursor: pointer;
  text-align: left;
  transition: background 0.15s;
}

.settings-nav-btn:hover { background: var(--bg-hover); }
.settings-nav-btn.active {
  background: rgba(37,99,235,0.08);
  color: var(--accent);
  font-weight: 600;
}

.settings-nav-close {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 12px 8px 0;
  padding: 8px 12px;
  border: none;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text-secondary);
  font-size: 12px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.settings-nav-close:hover { background: var(--bg-hover); color: var(--danger); }

/* Right content panels */
.settings-panels {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.stab-panel {
  display: none;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}

.stab-panel.active { display: flex; }

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

.stab-header h2 {
  font-size: 18px;
  font-weight: 700;
  margin: 0;
}

.stab-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px;
}

/* Settings form box (create/edit forms) */
.settings-form-box {
  background: var(--bg-hover);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 20px;
}

.settings-form-title {
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 12px;
  color: var(--primary);
}

.settings-form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.settings-form-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

/* Settings table */
.settings-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.settings-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.settings-table th {
  text-align: left;
  padding: 10px 14px;
  background: var(--bg-hover);
  color: var(--text-secondary);
  font-weight: 600;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.settings-table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.settings-table tr:last-child td { border-bottom: none; }
.settings-table tbody tr:hover { background: var(--bg-hover); }

.st-user-cell {
  display: flex;
  align-items: center;
  gap: 10px;
}

.st-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  color: white;
  font-size: 13px;
  flex-shrink: 0;
}

/* Channel card */
.channel-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
  background: var(--bg-primary);
}

.channel-card-header {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 16px;
}

.channel-card-icon {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: #25D366;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.channel-card-info { flex: 1; min-width: 0; }
.channel-card-name {
  font-weight: 700;
  font-size: 15px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.channel-name-input {
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  background: var(--bg-input);
  outline: none;
  width: 180px;
}

.channel-card-status { font-size: 12px; color: var(--text-secondary); margin-top: 4px; }
.channel-card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

/* Settings sections (inside bot tab) */
.settings-section {
  margin-bottom: 28px;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--border);
}

.settings-section:last-child { border-bottom: none; margin-bottom: 0; }

.settings-section-title {
  font-weight: 700;
  font-size: 14px;
  margin-bottom: 12px;
  color: var(--text-primary);
}

.settings-hint {
  font-size: 12px;
  color: var(--text-secondary);
  margin: -8px 0 12px;
}

/* Toggle switch */
.toggle-label {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  font-size: 13px;
  font-weight: normal;
  user-select: none;
}

.toggle-cb { display: none; }

.toggle-slider {
  position: relative;
  width: 40px;
  height: 22px;
  background: var(--border-dark);
  border-radius: 11px;
  flex-shrink: 0;
  transition: background 0.2s;
}

.toggle-slider::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: white;
  transition: transform 0.2s;
}

.toggle-cb:checked + .toggle-slider { background: var(--primary); }
.toggle-cb:checked + .toggle-slider::after { transform: translateX(18px); }

/* Prevent .info-field label{display:block} from breaking toggles inside info-field */
.info-field .toggle-label {
  display: flex;
  align-items: center;
  font-size: inherit;
  font-weight: inherit;
  color: inherit;
  margin-bottom: 0;
  letter-spacing: normal;
  text-transform: none;
}

/* Topics list */
.topics-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 12px;
}

.topic-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-primary);
}

.topic-item-body { flex: 1; min-width: 0; }
.topic-item-title { font-weight: 600; font-size: 13px; margin-bottom: 3px; }
.topic-item-preview { font-size: 12px; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.topic-item-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

/* Git versioning */
.git-status-badge {
  font-size: 12px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 12px;
}
.git-status-badge.clean { background: #dcfce7; color: #166534; }
.git-status-badge.dirty { background: #fef9c3; color: #854d0e; }

.git-commit-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-primary);
  margin-bottom: 6px;
}
.git-commit-info {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex: 1;
}
.git-commit-hash {
  font-family: monospace;
  font-size: 11px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 6px;
  color: var(--text-secondary);
  flex-shrink: 0;
}
.git-commit-msg {
  font-size: 13px;
  color: var(--text-primary);
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.git-commit-msg.git-auto { color: var(--text-secondary); font-style: italic; }
.git-commit-date {
  font-size: 11px;
  color: var(--text-secondary);
  flex-shrink: 0;
  white-space: nowrap;
}

/* Backup list */
.backup-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-primary);
  margin-bottom: 6px;
}
.backup-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.backup-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
}
.backup-meta {
  font-size: 12px;
  color: var(--text-secondary);
}
.backup-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}
.backup-btn {
  padding: 5px 10px;
  font-size: 12px;
  width: auto;
  text-decoration: none;
}

/* Knowledge base grouped list */
.knowledge-category-group {
  margin-bottom: 10px;
}
.knowledge-cat-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-secondary);
  padding: 2px 0 6px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 6px;
}

/* ── Bot welcome media preview ─────────────────────────────── */
.bot-welcome-media-preview {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: var(--bg-hover);
  border-radius: 8px;
  margin-bottom: 8px;
  border: 1px solid var(--border-color);
}
.bot-welcome-media-preview .bot-welcome-thumb-img {
  width: 56px;
  height: 56px;
  object-fit: cover;
  border-radius: 6px;
  flex-shrink: 0;
}
.bot-welcome-thumb-video,
.bot-welcome-thumb-doc {
  width: 56px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-secondary);
  border-radius: 6px;
  font-size: 22px;
  flex-shrink: 0;
}
.bot-welcome-media-name {
  flex: 1;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ============================================================
   SETTINGS — RESPUESTAS RÁPIDAS
   ============================================================ */

.qrs-search-wrap {
  margin-bottom: 16px;
}
.qrs-search-wrap input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  outline: none;
  background: var(--bg-base);
}
.qrs-search-wrap input:focus { border-color: var(--primary); }

.qrs-category-section { margin-bottom: 20px; }

.qrs-category-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-secondary);
  padding: 6px 4px 8px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 6px;
}
.qrs-cat-label {
  display: flex;
  align-items: center;
  gap: 6px;
}
.qrs-cat-move-btns {
  display: flex;
  gap: 2px;
  flex-shrink: 0;
}
.qrs-btn-cat-move {
  padding: 2px 6px !important;
  font-size: 11px !important;
  line-height: 1.4;
  color: var(--text-secondary) !important;
  background: var(--bg) !important;
  border: 1px solid var(--border) !important;
  border-radius: 4px !important;
  cursor: pointer;
  transition: background .12s, color .12s;
}
.qrs-btn-cat-move:hover:not(:disabled) {
  background: var(--primary) !important;
  color: #fff !important;
  border-color: var(--primary) !important;
}
.qrs-btn-cat-move:disabled {
  opacity: .35;
  cursor: default;
}
.qrs-cat-count {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1px 6px;
  font-size: 10px;
  font-weight: 600;
  color: var(--text-secondary);
}

.qrs-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-panel);
  margin-bottom: 5px;
  transition: box-shadow 0.15s;
}
.qrs-row:hover { box-shadow: 0 1px 4px rgba(0,0,0,0.08); }

.qrs-row-main { flex: 1; min-width: 0; }

.qrs-row-title {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 600;
  font-size: 13px;
  margin-bottom: 2px;
}
.qrs-shortcut {
  background: #E8F5E9;
  color: var(--primary-dark);
  border-radius: 4px;
  padding: 1px 6px;
  font-size: 11px;
  font-family: monospace;
  font-weight: 700;
  flex-shrink: 0;
}
.qrs-attach-badge {
  font-size: 13px;
  flex-shrink: 0;
}
.qrs-row-preview {
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.qrs-row-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
  align-items: center;
}
.qrs-btn {
  padding: 4px 10px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  font-size: 12px;
  cursor: pointer;
  color: var(--text-primary);
  transition: background 0.15s;
}
.qrs-btn:hover:not(:disabled) { background: var(--border); }
.qrs-btn:disabled { opacity: 0.35; cursor: default; }
.qrs-btn-move { padding: 4px 7px; font-size: 11px; }
.qrs-btn-edit { color: var(--accent); border-color: var(--accent); }
.qrs-btn-edit:hover { background: #EEF2FF; }
.qrs-btn-del { color: #E53E3E; border-color: #E53E3E; }
.qrs-btn-del:hover { background: #FFF5F5; }

.qrs-empty {
  text-align: center;
  color: var(--text-secondary);
  padding: 32px 16px;
  font-size: 13px;
}

/* Attach zone in form */
.qrs-attach-zone {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.qrs-attach-status {
  font-size: 12px;
  color: var(--text-secondary);
  min-height: 16px;
}
.qrs-attach-status.has-file {
  color: var(--primary-dark);
  font-weight: 500;
}

/* Chat panel QR items — attach indicator */
.qr-item-attach {
  font-size: 11px;
  color: var(--primary-dark);
  margin-top: 2px;
  display: flex;
  align-items: center;
  gap: 3px;
}

/* ── Auto Messages Panel ─────────────────────────────────────── */
.am-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}
.am-card-title {
  font-weight: 700;
  font-size: 14px;
  color: var(--text-primary);
  margin-bottom: 2px;
}
.am-card-desc {
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.4;
}
.am-media-preview {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius);
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  margin-bottom: 6px;
}
.am-media-thumb {
  width: 48px;
  height: 48px;
  border-radius: 4px;
  overflow: hidden;
  flex-shrink: 0;
  background: var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
}
.am-thumb-img { width: 100%; height: 100%; object-fit: cover; }
.am-thumb-video, .am-thumb-doc {
  font-size: 20px;
  line-height: 1;
}
.am-media-name {
  flex: 1;
  font-size: 12px;
  color: var(--text-secondary);
  word-break: break-all;
}
.am-schedule-box {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-top: 4px;
  background: var(--bg-secondary);
}
.am-schedule-fields.am-sched-disabled {
  opacity: .45;
  pointer-events: none;
}
.am-days-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.am-day-label {
  display: flex;
  flex-direction: column;
  align-items: center;
  cursor: pointer;
  user-select: none;
}
.am-day-label input { display: none; }
.am-day-label span {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  font-size: 12px;
  font-weight: 600;
  border: 2px solid var(--border);
  color: var(--text-secondary);
  transition: background .15s, border-color .15s, color .15s;
}
.am-day-label input:checked + span {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

/* ============================================================
   AGENDA PANEL (tab inline)
   ============================================================ */

.tab-panel[data-panel="agenda"] {
  overflow-y: auto;
  flex: 1;
}

.agenda-panel-wrap {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px 14px 20px;
}

.agenda-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.agenda-field label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: .4px;
}

.agenda-field input,
.agenda-field textarea,
.agenda-field select {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 7px 10px;
  font-size: 13px;
  color: var(--text-primary);
  font-family: inherit;
  transition: border-color .15s;
  width: 100%;
  box-sizing: border-box;
}

.agenda-field input:focus,
.agenda-field textarea:focus,
.agenda-field select:focus {
  outline: none;
  border-color: var(--primary);
}

.agenda-field textarea {
  resize: vertical;
  min-height: 60px;
}

.agenda-field select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M6 8L0 0h12z' fill='%23999'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 28px;
}

.agenda-row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.agenda-pago-group {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 2px;
}

.agenda-pago-btn {
  padding: 5px 12px;
  border: 1.5px solid var(--border);
  border-radius: 20px;
  background: transparent;
  color: var(--text-primary);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s, border-color .15s, color .15s;
}

.agenda-pago-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.agenda-pago-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.agenda-check-label {
  display: flex !important;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 13px !important;
  font-weight: 500 !important;
  color: var(--text-primary) !important;
  text-transform: none !important;
  letter-spacing: 0 !important;
}

.agenda-check-label input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--primary);
  cursor: pointer;
  flex-shrink: 0;
}

.agenda-dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 2px dashed var(--border);
  border-radius: 8px;
  padding: 20px 12px;
  cursor: pointer;
  transition: border-color .15s, background .15s;
  text-align: center;
}

.agenda-dropzone:hover,
.agenda-dropzone.drag-over {
  border-color: var(--primary);
  background: rgba(var(--primary-rgb, 0,120,212), .04);
}

.agenda-drop-label {
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 500;
}

.agenda-drop-sub {
  font-size: 11px;
  color: var(--text-tertiary, #aaa);
}

.agenda-drop-thumbs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}

.agenda-drop-thumb {
  width: 54px;
  height: 54px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--border);
}

.agenda-copy-panel-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  padding: 9px 0;
  background: var(--primary);
  border: none;
  border-radius: 8px;
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity .15s;
  margin-top: 4px;
}

.agenda-copy-panel-btn:hover {
  opacity: .88;
}

.agenda-save-row {
  display: flex;
  justify-content: flex-end;
  min-height: 16px;
  margin-top: 4px;
}

.agenda-save-status {
  font-size: 11px;
  color: var(--text-secondary);
  transition: opacity .2s;
}

.agenda-save-status.agenda-save-ok {
  color: #22c55e;
}

.agenda-save-status.agenda-save-error {
  color: #ef4444;
}

/* ============================================================
   HISTORY VIEW — closed conversation detail
   ============================================================ */

/* Info bar below chat header */
.history-info-bar {
  background: var(--surface, #fff);
  border-bottom: 1px solid var(--border);
  padding: 7px 16px 8px;
  flex-shrink: 0;
}
.history-info-bar.hidden { display: none; }

.hist-bar-stats-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-secondary);
}
.hist-bar-stat {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.hist-bar-stat strong {
  color: var(--text-primary);
}
.hist-bar-sep {
  color: var(--border);
  user-select: none;
}
.hist-bar-labels-row {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 5px;
}
.hist-bar-label {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  color: #fff;
  letter-spacing: 0.2px;
}

/* History right panel */
.history-panel-content {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.history-panel-content.hidden { display: none; }

.hist-loading {
  padding: 32px 16px;
  text-align: center;
  color: var(--text-secondary);
  font-size: 13px;
}

.hist-section {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}
.hist-section:last-child { border-bottom: none; }

.hist-section-title {
  font-size: 10px;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 10px;
}

/* Contact card inside history panel */
.hist-contact-card {
  display: flex;
  align-items: center;
  gap: 12px;
}
.hist-contact-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 18px;
  color: #fff;
  flex-shrink: 0;
  overflow: hidden;
}
.hist-contact-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.hist-contact-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 2px;
}
.hist-contact-phone {
  font-size: 12px;
  color: var(--text-secondary);
}

/* Stats grid */
.hist-stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.hist-stat-box {
  background: var(--bg, #F0F2F5);
  border-radius: 8px;
  padding: 8px 10px;
}
.hist-stat-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.3px;
  margin-bottom: 3px;
}
.hist-stat-value {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
}

/* Labels row */
.hist-labels-row {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}
.hist-label-chip {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 500;
  color: #fff;
}

/* Participants */
.hist-participant {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 0;
  border-bottom: 1px solid var(--border);
}
.hist-participant:last-child { border-bottom: none; }
.hist-participant-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}
.hist-participant-name {
  flex: 1;
  font-size: 13px;
  font-weight: 500;
}
.hist-participant-count {
  font-size: 11px;
  color: var(--text-secondary);
}

/* File list */
.hist-files-list { display: flex; flex-direction: column; }
.hist-file-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  text-decoration: none;
  color: inherit;
  cursor: pointer;
}
.hist-file-item:last-child { border-bottom: none; }
.hist-file-item:hover .hist-file-name { color: var(--primary); }

.hist-file-icon {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg, #F0F2F5);
  flex-shrink: 0;
  overflow: hidden;
  font-size: 18px;
}
.hist-file-icon img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 8px;
}
.hist-file-info { flex: 1; min-width: 0; }
.hist-file-name {
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: color .15s;
}
.hist-file-meta {
  font-size: 11px;
  color: var(--text-secondary);
  margin-top: 2px;
}
.hist-empty {
  font-size: 13px;
  color: var(--text-secondary);
  padding: 4px 0;
}
.hist-reopen-btn {
  width: 100%;
  text-align: center;
  justify-content: center;
}

/* ============================================================
   DASHBOARD
   ============================================================ */

.dashboard-view {
  flex: 1;
  overflow-y: auto;
  background: var(--bg);
  display: none;
}

.dash-container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 22px 24px 32px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

/* Header */
.dash-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}
.dash-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  margin: 0;
}
.dash-range-picker {
  display: flex;
  gap: 3px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 3px;
}
.dash-range-btn {
  background: none;
  border: none;
  padding: 5px 14px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.dash-range-btn:hover { background: var(--bg); }
.dash-range-btn.active { background: #2563eb; color: #fff; }

/* Summary cards */
.dash-cards {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 12px;
}
.dash-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px 18px;
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}
.dash-card-icon {
  width: 42px;
  height: 42px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.dash-icon-blue   { background: #dbeafe; color: #2563eb; }
.dash-icon-yellow { background: #fef3c7; color: #d97706; }
.dash-icon-green  { background: #d1fae5; color: #059669; }
.dash-icon-gray   { background: #f3f4f6; color: #6b7280; }
.dash-icon-purple { background: #ede9fe; color: #7c3aed; }
.dash-card-body { min-width: 0; }
.dash-card-label {
  font-size: 11px;
  color: var(--text-secondary);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.dash-card-value {
  font-size: 26px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.15;
  margin-top: 4px;
}

/* Charts */
.dash-charts-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.dash-chart-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px;
  min-width: 0;
}
.dash-chart-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 14px;
}
.dash-chart-wrap {
  position: relative;
  height: 190px;
}

/* Bottom row */
.dash-bottom-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 12px;
}
.dash-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px;
  min-width: 0;
}
.dash-section-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

/* List items */
.dash-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 60px;
}
.dash-list-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 8px;
  border-radius: 7px;
  background: var(--bg);
  min-width: 0;
}
.dash-list-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.dash-list-name {
  flex: 1;
  font-size: 13px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.dash-list-count {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  flex-shrink: 0;
}
.dash-list-bar-wrap {
  width: 50px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
  flex-shrink: 0;
}
.dash-list-bar {
  height: 100%;
  border-radius: 2px;
  background: #2563eb;
  transition: width 0.3s;
}

/* Agent status dot */
.dash-agent-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.dash-agent-dot.online  { background: #22c55e; }
.dash-agent-dot.busy    { background: #f59e0b; }
.dash-agent-dot.offline { background: #9ca3af; }

/* Agenda */
.dash-agenda-time {
  font-size: 12px;
  font-weight: 700;
  color: #2563eb;
  flex-shrink: 0;
  min-width: 38px;
}
.dash-agenda-badge {
  font-size: 11px;
  background: #dbeafe;
  color: #1d4ed8;
  padding: 2px 7px;
  border-radius: 20px;
  flex-shrink: 0;
  white-space: nowrap;
  max-width: 90px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.dash-agenda-item.completed .dash-list-name {
  text-decoration: line-through;
  opacity: 0.55;
}

.dash-empty, .dash-loading {
  text-align: center;
  color: var(--text-secondary);
  font-size: 13px;
  padding: 18px 0;
}

/* Responsive */
@media (max-width: 1100px) {
  .dash-cards { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 850px) {
  .dash-cards { grid-template-columns: repeat(2, 1fr); }
  .dash-charts-row, .dash-bottom-row { grid-template-columns: 1fr; }
}

/* ============================================================
   Montaje Tool
   ============================================================ */
.montaje-modal { max-width: 560px; }

.montaje-images-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 12px;
}

.montaje-img-section {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.montaje-img-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.6px;
}

/* Drop zone */
.montaje-drop-zone {
  width: 100%;
  aspect-ratio: 1;
  border: 2px dashed var(--border);
  border-radius: 10px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-secondary);
  cursor: pointer;
  position: relative;
  transition: border-color .15s, background .15s;
  outline: none;
}

.montaje-drop-zone:focus,
.montaje-drop-zone.drag-over {
  border-color: var(--primary);
  background: rgba(29, 168, 81, .06);
}

.montaje-drop-zone.has-image {
  border-style: solid;
  border-color: var(--primary);
}

.montaje-drop-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 12px;
  text-align: center;
  pointer-events: none;
  user-select: none;
}

.montaje-drop-empty span {
  font-size: 11px;
  color: var(--text-secondary);
  line-height: 1.3;
}

.montaje-slot-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  position: absolute;
  inset: 0;
}

.montaje-slot-actions {
  display: flex;
  gap: 6px;
}

.montaje-slot-actions .btn-secondary {
  flex: 1;
  font-size: 11px;
  padding: 5px 8px;
  white-space: nowrap;
}

.montaje-result {
  border-top: 1px solid var(--border);
  padding-top: 14px;
  margin-top: 8px;
}

/* Editor toolbar */
.montaje-editor-toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}

.montaje-editor-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: .6px;
  margin-right: 4px;
}

.montaje-tool-btn {
  font-size: 12px !important;
  padding: 5px 11px !important;
  width: auto !important;
}

/* Canvas container */
.montaje-canvas-wrap {
  width: 100%;
  max-height: 360px;
  overflow: hidden;
  border-radius: 8px;
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  background: #111;
  margin-bottom: 10px;
}

#montaje-canvas {
  max-width: 100%;
  max-height: 360px;
  display: block;
  cursor: default;
}

/* Send panel */
.montaje-send-panel {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 10px;
}

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

.montaje-send-panel-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.montaje-send-panel-actions .btn-primary { flex: 1; }
.montaje-send-panel-actions .btn-secondary { width: auto; padding: 8px 16px; }

.montaje-result-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  justify-content: center;
}

.montaje-result-actions .btn-primary { flex: 1; }
.montaje-result-actions .btn-secondary {
  width: auto;
  padding: 8px 18px;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.montaje-spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255,255,255,.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: montaje-spin 0.7s linear infinite;
  margin-left: 8px;
  vertical-align: middle;
}

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

/* ============================================================
   STICKER & DEMO VIDEO TOOLBAR BUTTONS
   ============================================================ */
.toolbar-btn-sticker { color: #7c3aed; }
.toolbar-btn-sticker:hover { background: rgba(124,58,237,0.1); color: #6d28d9; }
.toolbar-btn-sticker.active { color: #7c3aed; background: rgba(124,58,237,0.12); }

.toolbar-btn-demovideo { color: #dc2626; }
.toolbar-btn-demovideo:hover { background: rgba(220,38,38,0.1); color: #b91c1c; }
.toolbar-btn-demovideo.active { color: #dc2626; background: rgba(220,38,38,0.12); }

/* ============================================================
   SHARED MEDIA TOOL PANEL (stickers & videos)
   ============================================================ */
.media-tool-panel {
  position: absolute;
  bottom: calc(100% + 4px);
  right: 0;
  width: 320px;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.12), 0 2px 6px rgba(0,0,0,0.07);
  z-index: 200;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  max-height: 340px;
}

.mtp-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px 8px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.mtp-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
}

.mtp-upload-btn {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--primary);
  cursor: pointer;
  padding: 4px 10px;
  border-radius: 6px;
  border: 1.5px solid var(--primary);
  transition: background 0.15s;
  white-space: nowrap;
}
.mtp-upload-btn:hover { background: rgba(29,168,81,0.08); }

.mtp-empty {
  font-size: 12px;
  color: var(--text-light);
  text-align: center;
  padding: 20px;
  display: block;
}

/* Sticker grid */
.sticker-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  padding: 10px;
  overflow-y: auto;
  flex: 1;
}

.sticker-cell {
  position: relative;
  aspect-ratio: 1;
  border-radius: 8px;
  overflow: hidden;
  cursor: pointer;
  background: var(--bg-input);
  border: 1.5px solid transparent;
  transition: border-color 0.15s, transform 0.1s;
}
.sticker-cell:hover { border-color: var(--primary); transform: scale(1.05); }
.sticker-cell img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}
.sticker-cell .sticker-del {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: rgba(0,0,0,0.55);
  color: #fff;
  font-size: 9px;
  border: none;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  line-height: 1;
}
.sticker-cell:hover .sticker-del { display: flex; }

/* Video list */
.video-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 8px;
  overflow-y: auto;
  flex: 1;
}

.video-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  border: 1.5px solid transparent;
  transition: background 0.15s, border-color 0.15s;
}
.video-item:hover { background: var(--bg-input); border-color: var(--primary); }

.video-item-thumb {
  width: 44px;
  height: 44px;
  border-radius: 6px;
  background: #1e293b;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 20px;
}

.video-item-info {
  flex: 1;
  min-width: 0;
}
.video-item-title {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.video-item-meta {
  font-size: 11px;
  color: var(--text-secondary);
  margin-top: 2px;
}

.video-item-del {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--text-light);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 13px;
  transition: background 0.15s, color 0.15s;
}
.video-item-del:hover { background: rgba(220,38,38,0.1); color: #dc2626; }

/* Upload progress overlay in panel */
.mtp-uploading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px;
  font-size: 12.5px;
  color: var(--text-secondary);
  border-top: 1px solid var(--border);
}

/* ============================================================
   AI ASSISTANT PANEL
   ============================================================ */
.toolbar-btn-ai {
  color: #2563eb;
}
.toolbar-btn-ai:hover {
  background: rgba(37, 99, 235, 0.1);
  color: #1d4ed8;
}

.ai-assistant-panel {
  position: fixed;
  top: 50px;
  right: -360px;
  width: 350px;
  height: calc(100vh - 50px);
  background: #ffffff;
  border-left: 2px solid #2563eb;
  box-shadow: -4px 0 24px rgba(37, 99, 235, 0.18);
  display: flex;
  flex-direction: column;
  z-index: 500;
  transition: right 0.25s cubic-bezier(.4,0,.2,1);
}

.ai-assistant-panel.open { right: 0; }

.ai-assistant-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  height: 48px;
  background: #2563eb;
  color: white;
  flex-shrink: 0;
}

.ai-assistant-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 14px;
  letter-spacing: .2px;
}

.ai-assistant-close {
  background: none;
  border: none;
  color: rgba(255,255,255,.8);
  cursor: pointer;
  font-size: 17px;
  line-height: 1;
  padding: 5px 7px;
  border-radius: 5px;
  transition: background .15s;
}
.ai-assistant-close:hover { background: rgba(255,255,255,.2); color: #fff; }

.ai-assistant-messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: #f8fafc;
}
.ai-assistant-messages::-webkit-scrollbar { width: 4px; }
.ai-assistant-messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.ai-assistant-welcome {
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: 10px;
  padding: 11px 13px;
  font-size: 13px;
  color: #1e40af;
  line-height: 1.55;
}

.ai-msg { display: flex; flex-direction: column; }
.ai-msg-user { align-items: flex-end; }
.ai-msg-assistant { align-items: flex-start; }

.ai-msg-bubble {
  padding: 9px 13px;
  border-radius: 12px;
  font-size: 13.5px;
  line-height: 1.55;
  max-width: 92%;
  white-space: pre-wrap;
  word-break: break-word;
}

.ai-msg-user .ai-msg-bubble {
  background: #2563eb;
  color: #fff;
  border-bottom-right-radius: 4px;
}

.ai-msg-assistant .ai-msg-bubble {
  background: #ffffff;
  color: #1e293b;
  border: 1px solid #e2e8f0;
  border-bottom-left-radius: 4px;
}

.ai-msg-thinking {
  background: #f1f5f9 !important;
  border: 1px solid #e2e8f0 !important;
  color: #94a3b8 !important;
  font-style: italic;
  animation: ai-pulse 1.2s ease-in-out infinite;
}

@keyframes ai-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: .5; }
}

.ai-assistant-input-area {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--border);
  background: #fff;
  flex-shrink: 0;
}

#ai-assistant-input {
  flex: 1;
  resize: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 13.5px;
  font-family: inherit;
  line-height: 1.45;
  background: #f8fafc;
  outline: none;
  transition: border-color .15s;
  max-height: 110px;
  overflow-y: auto;
}
#ai-assistant-input:focus { border-color: #2563eb; background: #fff; }

#btn-ai-assistant-send {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  background: #2563eb;
  color: #fff;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s;
}
#btn-ai-assistant-send:hover { background: #1d4ed8; }
#btn-ai-assistant-send:disabled { background: #93c5fd; cursor: not-allowed; }

/* ── User sub-tabs (Personas / Bots) ── */
.user-subtabs {
  display: flex;
  gap: 4px;
  margin-bottom: 14px;
  border-bottom: 2px solid var(--border);
  padding-bottom: 0;
}
.user-subtab {
  background: none;
  border: none;
  padding: 7px 18px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  border-radius: 6px 6px 0 0;
  transition: color .15s, border-color .15s;
}
.user-subtab:hover { color: var(--primary); background: var(--bg-hover); }
.user-subtab.active { color: var(--primary); border-bottom-color: var(--primary); }

.user-subtab-panel { display: none; }
.user-subtab-panel.active { display: block; }

/* ── Team badge in conversation list ── */
.team-badge {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 10px;
  font-size: 10px;
  font-weight: 700;
  color: #fff;
  margin-left: 5px;
  vertical-align: middle;
  line-height: 1.5;
  opacity: 0.92;
}

/* ── Team card in settings list ── */
.team-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 13px 16px;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 10px;
  cursor: pointer;
  transition: border-color .15s, box-shadow .15s;
}
.team-card:hover { border-color: var(--primary); box-shadow: 0 2px 8px rgba(0,0,0,.08); }
.team-color-dot {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  flex-shrink: 0;
}
.team-card-info { flex: 1; }
.team-card-name { font-weight: 700; font-size: 14px; }
.team-card-meta { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }
.team-card-actions { display: flex; gap: 6px; }

/* ── Chat header team info ── */
.chat-header-team {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 2px;
}
.chat-header-team .team-badge { font-size: 11px; }

/* ── role-badge-bot ── */
.role-badge-bot { background: rgba(59, 130, 246, 0.12); color: #2563eb; padding: 2px 8px; border-radius: 10px; font-size: 11px; font-weight: 700; }

/* ── Multi-channel: channel name badge (conv list + header) ── */
.channel-name-badge {
  display: inline-flex;
  align-items: center;
  padding: 1px 6px;
  border-radius: 8px;
  font-size: 10px;
  font-weight: 700;
  color: #fff;
  margin-left: 5px;
  vertical-align: middle;
  white-space: nowrap;
  letter-spacing: 0.02em;
}

/* ── Multi-channel card improvements ── */
.channel-card {
  border-left-width: 4px !important;
  border-left-style: solid;
  padding: 16px 20px;
  margin-bottom: 16px;
}
.ch-config-panel {
  margin-top: 4px;
}
.channel-card-header {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  flex-wrap: wrap;
}
.channel-card-icon {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.channel-card-info {
  flex: 1;
  min-width: 0;
}
.channel-card-name {
  font-weight: 700;
  font-size: 15px;
}
.channel-card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

/* ── Channel filter row in sidebar ── */
#channel-filter-row {
  margin-top: 2px;
}
#channel-filter-select {
  font-size: 12px;
  padding: 5px 8px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg-secondary);
  color: var(--text-primary);
  cursor: pointer;
  width: 100%;
}

/* ── Message reply / quote ── */
.msg-reply-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  /* Agent/bot messages are right-aligned → button goes to the LEFT of the bubble */
  left: -40px;
  right: auto;
  width: 30px;
  height: 30px;
  border: 1px solid rgba(0,0,0,.12);
  border-radius: 50%;
  background: #fff;
  color: #555;
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  box-shadow: 0 1px 4px rgba(0,0,0,.18);
  padding: 0;
  z-index: 2;
  opacity: 1;
  pointer-events: auto;
  background: #f0f0f0;
  color: #aaa;
  border: 1px solid rgba(0,0,0,.08);
  box-shadow: none;
}
/* Contact messages are left-aligned → button goes to the RIGHT of the bubble */
.msg-bubble.from-contact .msg-reply-btn {
  left: auto;
  right: -40px;
}
.msg-reply-btn:hover {
  background: #e0e0e0;
  color: #555;
  box-shadow: 0 1px 4px rgba(0,0,0,.15);
}

/* Botones de editar / borrar (a la izquierda del de responder, en mensajes propios) */
.msg-edit-btn, .msg-del-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: #f0f0f0;
  border: 1px solid rgba(0,0,0,.08);
  color: #888;
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
  padding: 0;
  z-index: 2;
}
.msg-edit-btn { left: -76px; }
.msg-del-btn  { left: -112px; }
.msg-bubble:not(:has(.msg-edit-btn)) .msg-del-btn { left: -76px; }
.msg-edit-btn:hover { background: #e0e0e0; color: #2563eb; }
.msg-del-btn:hover  { background: #fde8e8; color: #dc2626; }

/* Caja de edición en línea */
.msg-edit-box {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 4px;
}
.msg-edit-input {
  width: 100%;
  min-width: 220px;
  resize: vertical;
  border: 1px solid rgba(0,0,0,.2);
  border-radius: 8px;
  padding: 6px 8px;
  font-family: inherit;
  font-size: 14px;
  box-sizing: border-box;
}
.msg-edit-actions {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
}
.msg-edit-actions button {
  border: none;
  border-radius: 6px;
  padding: 4px 12px;
  font-size: 13px;
  cursor: pointer;
  font-family: inherit;
}
.msg-edit-save { background: var(--primary, #128C7E); color: #fff; }
.msg-edit-cancel { background: #e0e0e0; color: #555; }

/* Mensaje eliminado para todos */
.msg-revoked {
  font-style: italic;
  color: #888;
  opacity: .85;
}

/* Quote block inside a message bubble */
.msg-quote-block {
  background: rgba(0,0,0,.06);
  border-left: 3px solid var(--primary);
  border-radius: 4px;
  padding: 4px 8px;
  margin-bottom: 4px;
  cursor: pointer;
  max-width: 100%;
  overflow: hidden;
}
.msg-bubble.from-contact .msg-quote-block { background: rgba(0,0,0,.06); }
.msg-bubble.from-agent  .msg-quote-block { background: rgba(255,255,255,.35); }
.msg-quote-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--primary);
  display: block;
  margin-bottom: 2px;
}
.msg-quote-content {
  font-size: 12px;
  color: var(--text-secondary);
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.msg-quote-thumb {
  width: 40px;
  height: 40px;
  object-fit: cover;
  border-radius: 3px;
  display: block;
}

/* Quote preview bar above the input */
.quote-preview-bar {
  display: none;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  border-left: 3px solid var(--primary);
}
.quote-preview-bar.visible { display: flex; }
.quote-preview-inner {
  flex: 1;
  min-width: 0;
}
.quote-preview-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--primary);
}
.quote-preview-content {
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.quote-preview-text { display: block; }
.quote-preview-thumb {
  width: 36px;
  height: 36px;
  object-fit: cover;
  border-radius: 3px;
}
.quote-preview-cancel {
  border: none;
  background: none;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 16px;
  padding: 0 4px;
  flex-shrink: 0;
}
.quote-preview-cancel:hover { color: var(--text-primary); }

/* Highlight animation when scrolling to quoted message */
@keyframes msgHighlight {
  0%   { box-shadow: 0 0 0 3px var(--primary); }
  100% { box-shadow: none; }
}
.msg-highlight { animation: msgHighlight 1.5s ease-out; }

/* ── Assignment badge & release button in chat header ── */
.chat-header-assignment {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 14px;
  font-size: 12px;
  color: var(--text-secondary);
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  height: 28px;
  flex-shrink: 0;
}
.btn-release-conv {
  font-size: 11px;
  padding: 2px 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  font-family: inherit;
  transition: background .12s, color .12s, border-color .12s;
}
.btn-release-conv:hover {
  background: #fee2e2;
  color: #b91c1c;
  border-color: #fca5a5;
}

/* ── Waiting / blocked input panel ── */
.chat-input-waiting {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  border-top: 1px solid var(--border);
  background: var(--bg-secondary);
  flex-shrink: 0;
}
.conv-unassigned-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  text-align: center;
  max-width: 360px;
}
.conv-unassigned-card p {
  margin: 0;
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.5;
}
.btn-take-conv {
  padding: 9px 28px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: opacity .15s;
}
.btn-take-conv:hover { opacity: .88; }


/* ============================================================
   SOUND SETTINGS PANEL
   ============================================================ */
.sound-global-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.sound-global-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.sound-global-label {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
}

.sound-volume-row {
  display: flex;
  align-items: center;
  gap: 12px;
  transition: opacity 0.2s;
}

.sound-volume-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-secondary);
  white-space: nowrap;
  min-width: 72px;
}

.sound-slider {
  flex: 1;
  -webkit-appearance: none;
  height: 4px;
  background: var(--border);
  border-radius: 4px;
  outline: none;
  cursor: pointer;
}
.sound-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--primary);
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(0,0,0,0.15);
  transition: transform 0.1s;
}
.sound-slider::-webkit-slider-thumb:hover { transform: scale(1.15); }
.sound-slider::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--primary);
  border: none;
  cursor: pointer;
}

.sound-volume-val {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  min-width: 38px;
  text-align: right;
}

/* Sound toggle (reusing ES toggle styles as base) */
.sound-toggle { display: inline-flex; align-items: center; cursor: pointer; }
.sound-toggle input { display: none; }
.sound-toggle-track {
  width: 40px; height: 22px;
  border-radius: 11px;
  background: #d1d5db;
  position: relative;
  transition: background 0.2s;
  flex-shrink: 0;
}
.sound-toggle input:checked + .sound-toggle-track { background: var(--primary); }
.sound-toggle-thumb {
  position: absolute;
  top: 3px; left: 3px;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: #fff;
  transition: left 0.2s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.18);
}
.sound-toggle input:checked + .sound-toggle-track .sound-toggle-thumb { left: 21px; }
.sound-toggle-sm .sound-toggle-track { width: 32px; height: 18px; border-radius: 9px; }
.sound-toggle-sm .sound-toggle-thumb { width: 12px; height: 12px; top: 3px; left: 3px; }
.sound-toggle-sm input:checked + .sound-toggle-track .sound-toggle-thumb { left: 17px; }

/* Sound cards */
.sound-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  transition: opacity 0.2s;
}
.sound-card.sound-card-disabled { opacity: 0.45; pointer-events: none; }

.sound-card-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated);
}

.sound-card-icon {
  width: 36px; height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.sound-icon-new { background: rgba(37,99,235,0.1); color: var(--accent); }
.sound-icon-reply { background: rgba(29,168,81,0.1); color: var(--primary); }

.sound-card-title {
  flex: 1;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}

.sound-card-body {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 18px;
}

.sound-select {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  color: var(--text-primary);
  background: var(--bg-input);
  outline: none;
  cursor: pointer;
  transition: border-color 0.15s;
}
.sound-select:focus { border-color: var(--primary); }

.sound-preview-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  flex-shrink: 0;
}
.sound-preview-btn:hover {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

/* Mensaje de error al cargar un chat */
.chat-load-error {
  text-align: center;
  color: #888;
  padding: 40px 20px;
  font-size: 14px;
}
.chat-load-error button {
  display: inline-block;
  margin-top: 12px;
  background: var(--primary, #128C7E);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 8px 20px;
  cursor: pointer;
  font-size: 14px;
}

/* ===== Probar bot (chat de prueba en panel Bot IA) ===== */
.bot-test-chat {
  background: var(--bg-chat);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  height: 320px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 12px;
}
.bot-test-empty {
  margin: auto;
  color: var(--text-secondary);
  font-size: 13px;
  text-align: center;
}
.bot-test-row { display: flex; }
.bot-test-row.client { justify-content: flex-end; }
.bot-test-row.bot { justify-content: flex-start; }
.bot-test-row.system { justify-content: center; }
.bot-test-bubble {
  max-width: 76%;
  padding: 8px 12px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.4;
  white-space: pre-wrap;
  word-wrap: break-word;
  box-shadow: 0 1px 1px rgba(0,0,0,0.06);
}
.bot-test-row.client .bot-test-bubble {
  background: var(--msg-sent);
  color: var(--text-primary);
  border-bottom-right-radius: 4px;
}
.bot-test-row.bot .bot-test-bubble {
  background: var(--msg-received);
  color: var(--text-primary);
  border-bottom-left-radius: 4px;
}
.bot-test-row.system .bot-test-bubble {
  background: transparent;
  box-shadow: none;
  color: var(--text-secondary);
  font-size: 12px;
  font-style: italic;
}
.bot-test-bubble .bot-test-author {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: var(--primary);
  margin-bottom: 2px;
}
.bot-test-input-row { display: flex; gap: 10px; align-items: center; }
.bot-test-input {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-input);
  color: var(--text-primary);
  font-size: 14px;
}
.bot-test-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(29,168,81,0.1);
}

/* ===== Tono del panel: claro / medio / oscuro (baja el brillo) ===== */
html[data-theme="medio"]  { filter: brightness(0.88) contrast(1.02); }
html[data-theme="oscuro"] { filter: brightness(0.68) contrast(1.06); }
