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

:root {
  --primary: #00a884;
  --primary-dark: #008f72;
  --primary-light: #e7f8f4;
  --bg: #f0f2f5;
  --bg-white: #ffffff;
  --bg-sidebar: #ffffff;
  --bg-hover: #f0f2f5;
  --bg-active: #e7f8f4;
  --border: #e9edef;
  --text: #111b21;
  --text-secondary: #667781;
  --text-muted: #8696a0;
  --incoming-bg: #ffffff;
  --outgoing-bg: #d9fdd3;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-lg: 0 2px 12px rgba(0,0,0,0.12);
  --radius: 8px;
  --radius-lg: 16px;
  --transition: 0.2s ease;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --pending-color: #dc3545;
  --pending-bg: #fff5f5;
  --responded-color: #28a745;
  --responded-bg: #f0fff4;
  --pinned-color: #ffc107;
  --sidebar-width: 360px;
  --header-h: 52px;
  --bottom-nav-h: 56px;
}

html, body {
  height: 100%;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.4;
  overflow: hidden;
}

#app {
  display: flex;
  height: 100vh;
  max-width: 100vw;
  overflow: hidden;
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ===== Mobile Header ===== */
#mobile-header {
  display: none;
  height: var(--header-h);
  background: var(--primary);
  color: white;
  align-items: center;
  padding: 0 8px;
  gap: 4px;
  z-index: 100;
}

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

.header-btn:hover { background: rgba(255,255,255,0.15); }
.header-btn svg { width: 22px; height: 22px; }

.header-title {
  flex: 1;
  min-width: 0;
  padding: 0 8px;
}

.header-title span:first-child {
  display: block;
  font-size: 16px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-title span:last-child {
  font-size: 11px;
  opacity: 0.85;
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ===== Sidebar ===== */
#sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 100vh;
}

#sidebar-header {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-white);
}

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

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

.brand-icon svg { width: 20px; height: 20px; }

.brand-text {
  flex: 1;
  min-width: 0;
}

.brand-text h1 {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.3;
}

.badge {
  font-size: 10px;
  padding: 1px 8px;
  border-radius: 10px;
  display: inline-block;
}

.badge-warning { background: #fff3cd; color: #856404; }
.badge-success { background: #d4edda; color: #155724; }
.badge-danger { background: #f8d7da; color: #721c24; }

#search-box {
  padding: 8px 12px;
  position: relative;
}

.search-icon {
  position: absolute;
  left: 22px;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  color: var(--text-muted);
  pointer-events: none;
}

#search-input {
  width: 100%;
  padding: 9px 12px 9px 36px;
  border: none;
  border-radius: 8px;
  background: var(--bg);
  font-size: 13px;
  color: var(--text);
  outline: none;
  transition: background var(--transition);
}

#search-input:focus { background: var(--bg-hover); }
#search-input::placeholder { color: var(--text-muted); }

/* ===== Bottom Nav (mobile) ===== */
#bottom-nav {
  display: none;
  height: var(--bottom-nav-h);
  background: var(--bg-white);
  border-top: 1px solid var(--border);
  align-items: center;
  justify-content: space-around;
  padding: 2px 0 env(safe-area-inset-bottom, 0);
  z-index: 100;
}

.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  padding: 4px 0;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 10px;
  font-family: var(--font);
  position: relative;
  transition: color var(--transition);
}

.nav-btn svg {
  width: 22px;
  height: 22px;
}

.nav-btn.active {
  color: var(--primary);
}

.nav-badge {
  position: absolute;
  top: 0;
  right: 50%;
  transform: translateX(calc(50% + 14px));
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 8px;
  background: var(--primary);
  color: white;
  font-size: 9px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.nav-badge.badge-pending {
  background: var(--pending-color);
}

/* ===== Chat list ===== */
.chat-list {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.chat-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  cursor: pointer;
  transition: background var(--transition);
  border-bottom: 1px solid var(--border);
  position: relative;
}

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

/* Pending attention */
.chat-item.needs-attention {
  background: var(--pending-bg);
  border-left: 3px solid var(--pending-color);
}

.chat-item.needs-attention:hover { background: #fee; }
.chat-item.needs-attention.active { background: #fdd; }

/* Responded */
.chat-item.responded {
  border-left: 3px solid var(--responded-color);
}

/* Pinned */
.chat-item.pinned .pin-indicator {
  color: var(--pinned-color);
}

.chat-avatar {
  width: 44px;
  height: 44px;
  min-width: 44px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 15px;
  flex-shrink: 0;
  position: relative;
}

.chat-avatar.group {
  background: #dfe5e7;
  color: var(--text-secondary);
  font-size: 18px;
}

.pin-indicator {
  position: absolute;
  top: -4px;
  right: -4px;
  font-size: 12px;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,0.3));
  display: none;
}

.chat-item.pinned .pin-indicator { display: block; }

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

.chat-row1 {
  display: flex;
  align-items: center;
  gap: 6px;
}

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

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

.chat-row2 {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 2px;
}

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

.ct-tag {
  display: inline-block;
  font-size: 9px;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 4px;
  flex-shrink: 0;
  line-height: 1.4;
}

.ct-tag.ct-group { background: #fce4ec; color: #c62828; }
.ct-tag.ct-individual { background: #e3f2fd; color: #1565c0; }

.chat-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.chat-status-dot.pending { background: var(--pending-color); }
.chat-status-dot.responded { background: var(--responded-color); }

/* ===== Main ===== */
#main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100vh;
  background: var(--bg);
  min-width: 0;
}

.welcome {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--text-secondary);
  padding: 32px;
  text-align: center;
}

.welcome-icon {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: var(--primary-light);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--primary);
}

.welcome-icon svg { width: 36px; height: 36px; }
.welcome h2 { font-size: 20px; font-weight: 300; color: var(--text); }
.welcome p { font-size: 13px; color: var(--text-muted); }

#welcome-stats {
  display: flex;
  gap: 20px;
  margin-top: 12px;
}

.welcome-stat {
  text-align: center;
}

.welcome-stat .num {
  font-size: 24px;
  font-weight: 700;
  color: var(--primary);
  display: block;
}

.welcome-stat .lbl {
  font-size: 11px;
  color: var(--text-muted);
}

/* ===== Chat View ===== */
#chat-view {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

#chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  background: var(--bg-white);
  border-bottom: 1px solid var(--border);
  min-height: 52px;
}

#chat-header-info { flex: 1; min-width: 0; }
#chat-header-info h2 { font-size: 15px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#chat-header-info span { font-size: 11px; color: var(--text-secondary); }

#chat-actions {
  display: flex;
  gap: 2px;
  flex-shrink: 0;
}

#chat-actions .header-btn {
  color: var(--text-secondary);
}

/* ===== Messages ===== */
#messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 16px 40px;
  background: linear-gradient(135deg, #e8f5e9 0%, #e3f2fd 50%, #f3e5f5 100%);
  position: relative;
}

#messages-list {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.message {
  max-width: 75%;
  padding: 7px 12px;
  border-radius: var(--radius);
  position: relative;
  word-wrap: break-word;
  white-space: pre-wrap;
  font-size: 13.5px;
  line-height: 1.5;
  animation: msgIn 0.15s ease;
}

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

.message.incoming {
  align-self: flex-start;
  background: var(--incoming-bg);
  border-top-left-radius: 2px;
  box-shadow: var(--shadow);
}

.message.outgoing {
  align-self: flex-end;
  background: var(--outgoing-bg);
  border-top-right-radius: 2px;
  box-shadow: var(--shadow);
}

.message .msg-body { display: inline; }

.message-sender {
  display: block;
  margin-bottom: 2px;
  color: #087f5b;
  font-size: 11.5px;
  font-weight: 700;
  line-height: 1.3;
}

.message .msg-media {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  background: rgba(0,0,0,0.03);
  border-radius: 6px;
  margin-bottom: 2px;
  font-size: 13px;
}

.message .msg-media .media-icon { font-size: 20px; }
.message .msg-media .media-label { color: var(--text-secondary); font-size: 12px; }

.message-time {
  display: block;
  text-align: right;
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 3px;
}

.message-dir {
  font-size: 10px;
  font-weight: 600;
  margin-right: 3px;
}

.message-dir.in { color: var(--primary); }
.message-dir.out { color: #1976d2; }

.message-date-divider {
  text-align: center;
  margin: 10px 0;
}

.message-date-divider span {
  background: rgba(225, 245, 254, 0.92);
  padding: 3px 12px;
  border-radius: 6px;
  font-size: 11px;
  color: var(--text-secondary);
  box-shadow: var(--shadow);
}

.message-empty {
  text-align: center;
  color: var(--text-muted);
  padding: 40px;
  font-size: 13px;
}

/* ===== Message input ===== */
#message-input-area {
  padding: 6px 12px;
  background: var(--bg-white);
  border-top: 1px solid var(--border);
}

#message-input-wrapper {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--bg);
  border-radius: 8px;
  padding: 2px 2px 2px 14px;
}

#message-input {
  flex: 1;
  border: none;
  background: transparent;
  padding: 8px 0;
  font-size: 14px;
  font-family: var(--font);
  color: var(--text);
  resize: none;
  outline: none;
  max-height: 100px;
  line-height: 1.4;
}

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

#btn-send {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity var(--transition), background var(--transition);
  flex-shrink: 0;
}

#btn-send:hover:not(:disabled) { background: var(--primary-dark); }
#btn-send:disabled { opacity: 0.4; cursor: not-allowed; }
#btn-send svg { width: 18px; height: 18px; }

/* ===== Loading ===== */
#messages-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 40px;
  color: var(--text-secondary);
}

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

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

/* ===== Toast ===== */
#toast-container {
  position: fixed;
  top: 12px;
  right: 12px;
  left: 12px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
  pointer-events: none;
}

.toast {
  padding: 10px 18px;
  border-radius: var(--radius);
  background: var(--text);
  color: white;
  font-size: 13px;
  box-shadow: var(--shadow-lg);
  animation: toastIn 0.3s ease;
  max-width: 360px;
  pointer-events: auto;
}

.toast.success { background: #155724; }
.toast.error { background: #721c24; }
.toast.info { background: #004085; }

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

.hidden { display: none !important; }

/* ===== Sidebar Dashboard button ===== */
#sidebar-dashboard-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  margin: 4px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-white);
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 600;
  font-family: var(--font);
  cursor: pointer;
  transition: all var(--transition);
}

#sidebar-dashboard-btn:hover {
  background: var(--bg-hover);
  color: var(--text);
  border-color: var(--primary);
}

#sidebar-dashboard-btn svg {
  width: 18px;
  height: 18px;
}

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

/* ===== PWA / Standalone ===== */
@media (display-mode: standalone) {
  #mobile-header { padding-top: env(safe-area-inset-top, 0); }
  #bottom-nav { padding-bottom: env(safe-area-inset-bottom, 0); }
}

/* ===== Dashboard ===== */
#dashboard-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100vh;
  background: var(--bg);
  overflow: hidden;
}

#dashboard-content {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
}

.dashboard-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 60px;
  color: var(--text-secondary);
}

.dash-header {
  margin-bottom: 20px;
}

.dash-header h2 {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 4px;
}

.dash-header .dash-total {
  font-size: 13px;
  color: var(--text-muted);
}

.dash-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px;
}

.dash-card {
  background: var(--bg-white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  cursor: pointer;
  transition: box-shadow var(--transition), transform var(--transition);
}

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

.dash-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}

.dash-card-title {
  font-weight: 600;
  font-size: 14px;
  color: var(--text);
}

.dash-card-count {
  font-size: 11px;
  font-weight: 700;
  color: white;
  padding: 2px 10px;
  border-radius: 10px;
  line-height: 1.5;
}

.dash-card-list {
  padding: 4px 0;
}

.dash-card-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 14px;
  transition: background var(--transition);
}

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

.dash-item-name {
  font-size: 13px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  min-width: 0;
}

.dash-item-meta {
  font-size: 11px;
  color: var(--text-muted);
  flex-shrink: 0;
  margin-left: 8px;
}

.dash-card-more {
  padding: 6px 14px 8px;
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
}

@media (max-width: 640px) {
  #dashboard-view {
    height: calc(100vh - var(--header-h) - var(--bottom-nav-h));
  }
  #dashboard-content {
    padding: 14px;
  }
  .dash-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }
}

/* ===== Tag buttons in info panel ===== */
.info-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px 0;
}

.tag-btn {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 14px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  border: 2px solid var(--tag-color, #ccc);
  color: var(--tag-color, #666);
  background: transparent;
  transition: all 0.15s ease;
  user-select: none;
}

.tag-btn.active {
  background: var(--tag-color, #ccc);
  color: white;
}

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

/* ===== RESPONSIVE ===== */

/* Tablet */
@media (max-width: 900px) {
  #sidebar { width: 300px; min-width: 300px; }
  #messages-container { padding: 14px 20px; }
  .message { max-width: 85%; }
}

/* Mobile */
@media (max-width: 640px) {
  #mobile-header { display: flex; }
  #bottom-nav { display: flex; }

  #sidebar { display: none; }

  #app {
    flex-direction: column;
  }

  #main-content {
    height: calc(100vh - var(--header-h) - var(--bottom-nav-h));
  }

  #chat-view {
    height: calc(100vh - var(--header-h) - var(--bottom-nav-h));
  }

  /* Mobile chat list */
  #mobile-chat-list {
    height: calc(100vh - var(--header-h) - var(--bottom-nav-h));
    overflow-y: auto;
    background: var(--bg-white);
  }

  #mobile-chat-list .chat-item:last-child {
    border-bottom: none;
  }

  #messages-container {
    padding: 10px 12px;
  }

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

  .welcome { padding: 24px; }
  .welcome-icon { width: 56px; height: 56px; }
  .welcome-icon svg { width: 28px; height: 28px; }
  .welcome h2 { font-size: 17px; }

  #chat-header { padding: 6px 12px; min-height: 46px; }
  #chat-header-info h2 { font-size: 14px; }

  #message-input-area { padding: 4px 8px; }
  #message-input-wrapper { padding: 2px 2px 2px 10px; }
  #message-input { font-size: 15px; padding: 6px 0; }
  #btn-send { width: 38px; height: 38px; }

  /* Scrollbar smaller on mobile */
  ::-webkit-scrollbar { width: 3px; }
}

/* Extra small */
@media (max-width: 400px) {
  #messages-container { padding: 6px 8px; }
  .message { max-width: 95%; padding: 6px 10px; font-size: 12.5px; }
  #chat-header { padding: 4px 8px; }
}

/* ===== Info Panel ===== */
#info-panel-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 1000;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 60px;
  animation: fadeIn 0.15s ease;
}

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

#info-panel {
  background: var(--bg-white);
  border-radius: 12px;
  width: min(420px, calc(100% - 32px));
  max-height: calc(100vh - 80px);
  overflow-y: auto;
  box-shadow: 0 8px 32px rgba(0,0,0,0.2);
  position: relative;
  animation: slideUp 0.2s ease;
}

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

#info-close {
  position: absolute;
  top: 8px;
  right: 12px;
  background: none;
  border: none;
  font-size: 24px;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 4px 8px;
  line-height: 1;
  z-index: 1;
}

#info-close:hover { color: var(--text); }

#info-content { padding: 24px; }

#info-content .info-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 40px;
  color: var(--text-secondary);
}

.info-field {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}

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

.info-field .label {
  color: var(--text-secondary);
  flex-shrink: 0;
  margin-right: 12px;
}

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

.info-field .value .tag {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
}

.tag-individual { background: #e3f2fd; color: #1565c0; }
.tag-group { background: #fce4ec; color: #c62828; }
.tag-lid { background: #fff3e0; color: #e65100; }

.info-section-title {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  margin: 12px 0 4px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

.info-rename-btn {
  background: none;
  border: 1px solid var(--border);
  padding: 4px 12px;
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
  color: var(--text-secondary);
}

.info-rename-btn:hover { background: var(--bg); color: var(--text); }

#info-panel .chat-type {
  display: flex;
  align-items: center;
  gap: 6px;
}

@media (max-width: 640px) {
  #info-panel-overlay { padding-top: 20px; align-items: stretch; }
  #info-panel { width: 100%; border-radius: 12px 12px 0 0; max-height: calc(100vh - 20px); margin-top: auto; }
  #info-content { padding: 20px 16px; }
}

/* ======================================================================
   TICKET CONSOLE ADDITIONS (2026-07-08)
   ====================================================================== */

/* --- Console section tabs (Clientes / Grupos) --- */
#console-tabs {
  display: flex;
  gap: 6px;
  padding: 10px 12px 6px;
  background: var(--bg-white);
}
.ctab {
  flex: 1;
  padding: 8px 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text-secondary);
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
}
.ctab:hover { background: var(--bg-hover); }
.ctab.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

/* --- Status tabs (Abiertos / Cerrados / Todos) --- */
#status-tabs {
  display: flex;
  gap: 4px;
  padding: 4px 12px 8px;
  background: var(--bg-white);
}
.stab {
  flex: 1;
  padding: 6px 4px;
  border: none;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: var(--text-secondary);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
}
.stab.active { color: var(--primary); border-bottom-color: var(--primary); }
.stab-badge {
  background: var(--pending-color);
  color: #fff;
  border-radius: 10px;
  font-size: 10px;
  padding: 1px 6px;
  font-weight: 700;
}

/* --- Category chips --- */
#category-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  padding: 6px 12px 10px;
  background: var(--bg-white);
  border-bottom: 1px solid var(--border);
}
.cat-chip {
  padding: 4px 10px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text-secondary);
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
}
.cat-chip:hover { background: var(--bg-hover); }
.cat-chip.active {
  color: #fff;
  background: var(--cat, var(--primary));
  border-color: var(--cat, var(--primary));
}

/* --- Chat list item: row3 (status + category) --- */
.chat-row3 {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 3px;
  flex-wrap: wrap;
}
.ci-status {
  font-size: 10px;
  font-weight: 700;
  padding: 1px 7px;
  border-radius: 10px;
  text-transform: uppercase;
  letter-spacing: .3px;
}
.ci-status.open { background: #fff3e0; color: #e65100; }
.ci-status.closed { background: #eceff1; color: #607d8b; }
.ci-cat {
  font-size: 10px;
  font-weight: 600;
  padding: 1px 7px;
  border-radius: 10px;
  color: #fff;
}
.ci-ai { font-size: 11px; }
.chat-status-dot.closed { background: var(--text-muted); }
.chat-item.ticket-closed { opacity: .78; }
.chat-item.ticket-closed .chat-name { color: var(--text-secondary); }

/* --- Ticket panel (in chat view) --- */
#ticket-panel {
  padding: 10px 16px;
  background: var(--bg-white);
  border-bottom: 1px solid var(--border);
}
#tk-row1 {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.tk-spacer { flex: 1; }
.tk-status {
  font-size: 12px;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 12px;
}
.tk-status.open { background: #fff3e0; color: #e65100; }
.tk-status.closed { background: #eceff1; color: #607d8b; }
#tk-category {
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font-size: 12.5px;
  font-family: inherit;
  cursor: pointer;
  max-width: 190px;
}
.tk-btn {
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-white);
  color: var(--text);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
}
.tk-btn:hover { background: var(--bg-hover); }
.tk-btn:disabled { opacity: .6; cursor: default; }
.tk-btn-ai { background: #ede7f6; border-color: #d1c4e9; color: #5e35b1; }
.tk-btn-ai:hover { background: #e1d5f5; }
.tk-btn-close { background: #ffebee; border-color: #ffcdd2; color: #c62828; }
.tk-btn-open { background: #e8f5e9; border-color: #c8e6c9; color: #2e7d32; }
.tk-title {
  margin-top: 8px;
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
}
.tk-title.empty { font-weight: 500; font-style: italic; color: var(--text-muted); font-size: 13px; }
.tk-desc {
  margin-top: 3px;
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.45;
}

/* --- Media in messages --- */
.msg-media-img img {
  max-width: 260px;
  max-height: 320px;
  border-radius: 8px;
  display: block;
  cursor: zoom-in;
  background: var(--bg);
}
.msg-media-video video {
  max-width: 300px;
  max-height: 340px;
  border-radius: 8px;
  display: block;
  background: #000;
}
.msg-media-audio {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
}
.msg-media-audio audio { max-width: 240px; height: 36px; }
.msg-media-doc {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  background: var(--bg);
  border-radius: 8px;
  color: var(--text);
  text-decoration: none;
  font-size: 13px;
  font-weight: 600;
}
.msg-media.placeholder {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: var(--bg);
  border-radius: 8px;
  color: var(--text-secondary);
  font-size: 12.5px;
}
.msg-media.placeholder .media-icon { font-size: 18px; }

/* --- Lightbox / carousel --- */
#lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.92);
  z-index: 4000;
  display: flex;
  align-items: center;
  justify-content: center;
}
#lightbox.hidden { display: none; }
.lb-stage {
  max-width: 90vw;
  max-height: 88vh;
  display: flex;
  align-items: center;
  justify-content: center;
}
#lb-img {
  max-width: 90vw;
  max-height: 88vh;
  object-fit: contain;
  border-radius: 4px;
}
.lb-btn {
  position: absolute;
  background: rgba(255,255,255,0.12);
  color: #fff;
  border: none;
  cursor: pointer;
  border-radius: 50%;
  width: 48px;
  height: 48px;
  font-size: 30px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}
.lb-btn:hover { background: rgba(255,255,255,0.25); }
.lb-close { top: 18px; right: 18px; width: 42px; height: 42px; font-size: 26px; }
.lb-prev { left: 16px; top: 50%; transform: translateY(-50%); }
.lb-next { right: 16px; top: 50%; transform: translateY(-50%); }
.lb-counter {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  color: #fff;
  font-size: 13px;
  background: rgba(0,0,0,0.5);
  padding: 4px 12px;
  border-radius: 12px;
}

/* --- Dashboard KPIs --- */
.dash-kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  padding: 4px 0 8px;
}
.dash-kpi {
  background: var(--bg-white);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  box-shadow: var(--shadow);
}
.kpi-num { font-size: 30px; font-weight: 800; line-height: 1; }
.kpi-lbl { font-size: 12.5px; color: var(--text-secondary); font-weight: 600; }

/* --- Mobile tweaks --- */
@media (max-width: 640px) {
  #tk-category { max-width: 130px; }
  .tk-btn-ai .tk-btn-label { display: none; }
  .msg-media-img img, .msg-media-video video { max-width: 72vw; }
}

/* --- AutoFarm platform lookup (2026-07-09) --- */
.af-search-box {
  background: var(--bg-white);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}
.af-search-row { display: flex; gap: 8px; }
#af-search-input {
  flex: 1;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  font-size: 13.5px;
  font-family: inherit;
  outline: none;
}
#af-search-input:focus { border-color: var(--primary); }
.af-result-header { font-weight: 700; font-size: 15px; margin: 12px 0 6px; }
.af-bot {
  background: var(--bg);
  border-radius: var(--radius);
  padding: 8px 12px;
  margin-top: 6px;
}
.af-bot-name { font-weight: 600; font-size: 13.5px; }
.af-igg {
  font-weight: 500;
  font-size: 11.5px;
  color: var(--text-muted);
  background: var(--bg-white);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1px 7px;
  margin-left: 6px;
}
.af-bot-meta { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }
.af-email { word-break: break-all; }
.af-empty { padding: 10px 4px; color: var(--text-muted); font-size: 13px; font-style: italic; }
.af-exp-red { color: #c62828; font-weight: 700; }
.af-exp-orange { color: #e65100; font-weight: 600; }

/* --- Right detail panel + auto-AI cards (2026-07-09) --- */
#chat-body {
  flex: 1;
  display: flex;
  min-height: 0;
}
#chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}
#detail-panel {
  width: 320px;
  flex-shrink: 0;
  border-left: 1px solid var(--border);
  background: var(--bg-white);
  overflow-y: auto;
  padding: 14px 16px 24px;
}
.detail-title {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--text-muted);
  margin-bottom: 10px;
}
@media (max-width: 1024px) {
  #detail-panel { display: none; }
}

/* Tarjetas: preview con título IA + descripción */
.chat-preview.has-ai-title { font-weight: 600; color: var(--text); }
.chat-row-desc {
  font-size: 11.5px;
  color: var(--text-muted);
  margin-top: 1px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding-left: 14px;
}


/* ===== Groups sidebar (columna derecha, solo desktop ancho) ===== */
#groups-sidebar {
  width: 320px;
  min-width: 300px;
  background: var(--bg-sidebar);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 100vh;
}

#groups-sidebar-header {
  padding: 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-white);
}

#groups-sidebar-header h2 { font-size: 15px; font-weight: 700; flex: 1; }

.badge-groups {
  background: var(--primary-light);
  color: var(--primary-dark);
  border-radius: 10px;
  padding: 2px 9px;
  font-size: 12px;
  font-weight: 700;
}

#groups-search-box { padding: 8px 10px; border-bottom: 1px solid var(--border); }

#groups-search {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 13px;
  outline: none;
  background: var(--bg);
}

#groups-search:focus { border-color: var(--primary); background: var(--bg-white); }

#groups-list { flex: 1; overflow-y: auto; }

.groups-label {
  padding: 10px 12px 4px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--text-muted);
}

.grp-item { position: relative; padding-right: 36px !important; }

.grp-pin {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 15px;
  opacity: 0.25;
  padding: 4px 5px;
  border-radius: 6px;
  transition: opacity var(--transition), background var(--transition);
}

.grp-item:hover .grp-pin { opacity: 0.75; }
.grp-pin.on { opacity: 1; }
.grp-pin:hover { background: var(--bg-hover); }

.grp-item.pinned { background: #fffbe8; }
.grp-item.pinned:hover { background: #fff6d6; }

/* En desktop ancho los grupos tienen su propia columna: se ocultan las
   pestanas Clientes/Grupos de la columna izquierda. */
@media (min-width: 1101px) {
  #console-tabs { display: none; }
}

/* En pantallas medianas/moviles se mantiene la navegacion por pestanas. */
@media (max-width: 1100px) {
  #groups-sidebar { display: none; }
}

/* ===== Avatares reales (foto de perfil) ===== */
.chat-avatar { position: relative; }
.avatar-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
}
.chat-avatar .pin-indicator { z-index: 2; }
