/* =============================================================
   WhatsApp-Go Admin Panel — Filament-Inspired Design System
   ============================================================= */

/* ── Fonts: system-safe stack, Inter loaded async if available ── */

/* ── Design Tokens ── */
:root {
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', 'Consolas', monospace;

  /* Spacing scale */
  --s1: 4px;
  --s2: 8px;
  --s3: 12px;
  --s4: 16px;
  --s5: 20px;
  --s6: 24px;
  --s8: 32px;
  --s10: 40px;

  /* Radius */
  --r-sm: 6px;
  --r-md: 8px;
  --r-lg: 10px;

  /* Transition */
  --transition: 150ms ease;

  /* Semantic colors */
  --c-primary:     #059669;  /* emerald-600 */
  --c-primary-hover: #047857;
  --c-primary-light: rgba(5, 150, 105, 0.10);
  --c-primary-ring:  rgba(5, 150, 105, 0.30);

  --c-danger:        #dc2626;
  --c-danger-hover:  #b91c1c;
  --c-danger-light:  rgba(220, 38, 38, 0.10);

  --c-warning:       #d97706;
  --c-warning-light: rgba(217, 119, 6, 0.12);

  --c-info:          #2563eb;
  --c-info-light:    rgba(37, 99, 235, 0.10);

  --c-success:       #059669;
}

/* ── Dark Theme (default) ── */
[data-theme="dark"] {
  --bg-base:     #0f172a;   /* slate-900 — page background */
  --bg-surface:  #1e293b;   /* slate-800 — cards/sidebar */
  --bg-elevated: #273548;   /* slightly lighter surface */
  --bg-input:    #1a2640;   /* input fields */
  --bg-table-th: #172033;

  --border:      #334155;   /* slate-700 */
  --border-light: #253246;

  --text-primary:  #f1f5f9; /* slate-100 */
  --text-secondary:#94a3b8; /* slate-400 */
  --text-muted:    #64748b; /* slate-500 */

  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 8px 0 rgba(0, 0, 0, 0.4);
}

/* ── Light Theme ── */
[data-theme="light"] {
  --bg-base:     #f8fafc;   /* slate-50 */
  --bg-surface:  #ffffff;
  --bg-elevated: #f1f5f9;   /* slate-100 */
  --bg-input:    #ffffff;
  --bg-table-th: #f8fafc;

  --border:      #e2e8f0;   /* slate-200 */
  --border-light: #f1f5f9;

  --text-primary:  #0f172a; /* slate-900 */
  --text-secondary:#475569; /* slate-600 */
  --text-muted:    #94a3b8; /* slate-400 */

  --shadow-sm: 0 1px 3px 0 rgba(0, 0, 0, 0.07), 0 1px 2px -1px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.07), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
}

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

html { font-size: 14px; }

body {
  font-family: var(--font-sans);
  background-color: var(--bg-base);
  color: var(--text-primary);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  transition: background-color var(--transition), color var(--transition);
}

a { color: var(--c-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Alpine [x-cloak] ── */
[x-cloak] { display: none !important; }

/* ── Utility ── */
.hidden { display: none !important; }
.text-muted { color: var(--text-muted); }
.text-mono { font-family: var(--font-mono); }
.flex { display: flex; }
.items-center { align-items: center; }
.gap-2 { gap: var(--s2); }
.gap-3 { gap: var(--s3); }
.gap-4 { gap: var(--s4); }
.full-width { grid-column: 1 / -1; }
.w-full { width: 100%; }

/* ==========================================================
   AUTH PAGES (Login)
   ========================================================== */
.auth-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: var(--s6);
  background-color: var(--bg-base);
}

.auth-box {
  width: 100%;
  max-width: 400px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-md);
  padding: 36px 32px;
}

.auth-logo {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--s2);
  margin-bottom: var(--s8);
  text-align: center;
}

.auth-logo .logo-icon {
  font-size: 2rem;
  color: var(--c-primary);
}

.auth-logo h1 {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--text-primary);
}

.auth-logo p {
  font-size: 0.875rem;
  color: var(--text-secondary);
}

.auth-footer {
  margin-top: var(--s5);
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--s2);
}

/* ==========================================================
   LAYOUT: APP SHELL
   ========================================================== */
.app-shell {
  display: flex;
  /* Fixed viewport height (not min-height): the main area is bounded so the
     inner scroll containers (page-content and the chat panels) scroll
     instead of growing the whole page. */
  height: 100vh;
}

/* ── Sidebar ── */
.sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 100vh;
  position: sticky;
  top: 0;
  overflow-y: auto;
}

.sidebar-header {
  padding: var(--s4) var(--s5);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: var(--s3);
}

.sidebar-header .app-icon {
  color: var(--c-primary);
  font-size: 1.25rem;
}

.sidebar-header .app-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

.sidebar-header .app-version {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  background: var(--c-primary-light);
  color: var(--c-primary);
  padding: 2px 6px;
  border-radius: 10px;
  margin-left: auto;
}

.sidebar-nav {
  flex: 1;
  padding: var(--s3) var(--s3);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-group-label {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  padding: var(--s3) var(--s3) var(--s1);
  margin-top: var(--s2);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: var(--s3);
  padding: var(--s2) var(--s3);
  color: var(--text-secondary);
  font-size: 0.875rem;
  font-weight: 500;
  border-radius: var(--r-md);
  border: none;
  background: none;
  cursor: pointer;
  text-align: left;
  text-decoration: none;
  width: 100%;
  transition: background-color var(--transition), color var(--transition);
  border-left: 2px solid transparent;
}

.nav-item i {
  width: 16px;
  font-size: 0.9rem;
  flex-shrink: 0;
}

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

.nav-item.active {
  background: var(--c-primary-light);
  color: var(--c-primary);
  border-left-color: var(--c-primary);
  font-weight: 600;
}

.sidebar-footer {
  padding: var(--s3);
  border-top: 1px solid var(--border);
}

/* ── Main ── */
.main-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}

/* ── Topbar ── */
.topbar {
  height: 52px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 var(--s6);
  gap: var(--s4);
  position: sticky;
  top: 0;
  z-index: 50;
}

.topbar-title {
  font-size: 0.925rem;
  font-weight: 600;
  color: var(--text-primary);
}

.topbar-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: var(--s3);
}

/* Theme toggle */
.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: var(--r-md);
  border: 1px solid var(--border);
  background: var(--bg-surface);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition);
  font-size: 0.85rem;
}

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

/* User chip in topbar */
.user-chip {
  display: flex;
  align-items: center;
  gap: var(--s2);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 3px 10px 3px 6px;
}

.user-chip .user-avatar {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--c-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.65rem;
  font-weight: 700;
  color: white;
}

.user-chip .user-name {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-primary);
}

/* ── Page content ── */
.page-content {
  flex: 1;
  /* min-height: 0 lets this flex item shrink below its content height, which
     is what makes overflow-y: auto scroll internally (WhatsApp-Web style). */
  min-height: 0;
  overflow-y: auto;
  padding: var(--s6);
  display: flex;
  flex-direction: column;
  gap: var(--s5);
}

/* ── Page header ── */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--s4);
}

.page-header-left h2 {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.3;
}

.page-header-left p {
  margin-top: 3px;
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.page-header-right {
  display: flex;
  align-items: center;
  gap: var(--s2);
  flex-shrink: 0;
}

/* ==========================================================
   CARDS
   ========================================================== */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
}

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

.card-header h3 {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: var(--s2);
}

.card-header h3 i {
  color: var(--text-muted);
  font-size: 0.85rem;
}

.card-body {
  padding: var(--s5);
}

/* ==========================================================
   FORMS
   ========================================================== */
.form-stack {
  display: flex;
  flex-direction: column;
  gap: var(--s4);
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--s4);
}

.form-field {
  display: flex;
  flex-direction: column;
  gap: var(--s1);
}

.form-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.form-label.required::after {
  content: ' *';
  color: var(--c-danger);
}

.form-input,
.form-select,
.form-textarea {
  width: 100%;
  height: 36px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 0.875rem;
  padding: 0 var(--s3);
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
}

.form-textarea {
  height: auto;
  padding: var(--s3);
  resize: vertical;
  min-height: 80px;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  border-color: var(--c-primary);
  box-shadow: 0 0 0 3px var(--c-primary-ring);
}

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

.form-input-group {
  position: relative;
  display: flex;
}

.form-input-group .form-input {
  padding-right: 36px;
}

.form-input-group .input-addon {
  position: absolute;
  right: 0;
  top: 0;
  height: 100%;
  width: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.85rem;
  border-radius: 0 var(--r-md) var(--r-md) 0;
}

.form-input-group .input-addon:hover { color: var(--text-primary); }

.form-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
  line-height: 1.4;
}

.form-hint code {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  background: var(--bg-elevated);
  padding: 1px 4px;
  border-radius: var(--r-sm);
  color: var(--c-primary);
}

/* Range sliders (TTS speed/pitch) */
.range-input {
  width: 100%;
  height: 24px;
  accent-color: var(--c-primary);
  background: transparent;
  cursor: pointer;
}

/* TTS audio preview player */
.tts-preview-audio {
  width: 100%;
  height: 38px;
  border-radius: var(--r-md);
}

/* Criar Voz (custom voice) tab */
.voice-script {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: var(--s3) var(--s4);
  font-size: 0.9rem;
  line-height: 1.7;
  color: var(--text-primary);
  max-height: 190px;
  overflow-y: auto;
  white-space: pre-wrap;
}

.voice-rec {
  display: flex;
  align-items: center;
  gap: var(--s2);
  flex-wrap: wrap;
}

.voice-list {
  display: flex;
  flex-direction: column;
  gap: var(--s1);
}

.voice-list-item {
  display: flex;
  align-items: center;
  gap: var(--s2);
  padding: var(--s2) var(--s3);
  border: 1px solid var(--border-light);
  border-radius: var(--r-md);
  background: var(--bg-elevated);
  font-size: 0.8rem;
}

.voice-list-item > i { color: var(--c-primary); flex-shrink: 0; }

.voice-list-item code {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-left: auto;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.voice-actions {
  display: flex;
  align-items: center;
  gap: var(--s2);
  margin-left: var(--s2);
  flex-shrink: 0;
}

/* ==========================================================
   BUTTONS
   ========================================================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s2);
  height: 34px;
  padding: 0 var(--s4);
  font-family: var(--font-sans);
  font-size: 0.8rem;
  font-weight: 600;
  border-radius: var(--r-md);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
  line-height: 1;
}

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

.btn-w-full { width: 100%; height: 38px; }

.btn-primary {
  background: var(--c-primary);
  color: white;
  border-color: var(--c-primary);
}
.btn-primary:hover:not(:disabled) { background: var(--c-primary-hover); border-color: var(--c-primary-hover); }

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

.btn-danger {
  background: var(--c-danger);
  color: white;
  border-color: var(--c-danger);
}
.btn-danger:hover:not(:disabled) { background: var(--c-danger-hover); }

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border-color: transparent;
}
.btn-ghost:hover:not(:disabled) { background: var(--bg-elevated); color: var(--text-primary); }

.btn-sm { height: 28px; padding: 0 var(--s3); font-size: 0.75rem; }

.btn-lg { height: 40px; padding: 0 var(--s5); font-size: 0.875rem; }

/* ==========================================================
   BADGES
   ========================================================== */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 0.72rem;
  font-weight: 600;
}

.badge::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}

.badge-green { background: rgba(5,150,105,.12); color: #059669; }
.badge-green::before { background: #059669; }

.badge-red { background: rgba(220,38,38,.10); color: #dc2626; }
.badge-red::before { background: #dc2626; }

.badge-yellow { background: rgba(217,119,6,.12); color: #d97706; }
.badge-yellow::before { background: #d97706; }

.badge-blue { background: rgba(37,99,235,.10); color: #2563eb; }
.badge-blue::before { background: #2563eb; }

.badge-gray { background: var(--bg-elevated); color: var(--text-muted); }
.badge-gray::before { background: var(--text-muted); }

.role-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 0.7rem;
  font-weight: 700;
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.role-badge.admin { background: var(--c-info-light); color: var(--c-info); }
.role-badge.super-admin { background: var(--c-warning-light); color: var(--c-warning); }

/* ==========================================================
   TABLE
   ========================================================== */
.table-wrapper {
  width: 100%;
  overflow-x: auto;
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}

.table th {
  background: var(--bg-table-th);
  color: var(--text-muted);
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: var(--s3) var(--s4);
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.table td {
  padding: var(--s3) var(--s4);
  border-bottom: 1px solid var(--border-light);
  color: var(--text-primary);
  vertical-align: middle;
}

.table tr:last-child td { border-bottom: none; }

.table tr:hover td { background: var(--bg-elevated); }

/* ── Actions Dropdown ── */
.dropdown {
  position: relative;
  display: inline-block;
}

.dropdown-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 4px);
  z-index: 200;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-md);
  min-width: 160px;
  padding: var(--s1);
  overflow: hidden;
}

.dropdown-item {
  display: flex;
  align-items: center;
  gap: var(--s2);
  padding: var(--s2) var(--s3);
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-secondary);
  border-radius: var(--r-sm);
  cursor: pointer;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  transition: all var(--transition);
}

.dropdown-item:hover { background: var(--bg-elevated); color: var(--text-primary); }
.dropdown-item.danger { color: var(--c-danger); }
.dropdown-item.danger:hover { background: var(--c-danger-light); }
.dropdown-item i { width: 14px; font-size: 0.8rem; }

.dropdown-divider {
  height: 1px;
  background: var(--border);
  margin: var(--s1) 0;
}

/* ==========================================================
   INSTANCE CARDS GRID
   ========================================================== */
.instances-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: var(--s4);
}

.instance-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  border-left: 3px solid var(--border);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  transition: border-color var(--transition);
}

.instance-card.connected { border-left-color: var(--c-primary); }
.instance-card.disconnected { border-left-color: var(--border); }

.instance-card-header {
  padding: var(--s3) var(--s4);
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--s2);
}

.instance-name {
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--text-primary);
}

.instance-id {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.instance-owner {
  font-size: 0.75rem;
  color: var(--c-info);
  margin-top: 2px;
}

.instance-card-body {
  padding: var(--s3) var(--s4);
  display: flex;
  flex-direction: column;
  gap: var(--s3);
}

/* Token row */
.token-row {
  display: flex;
  align-items: center;
  gap: var(--s2);
  background: var(--bg-elevated);
  border: 1px solid var(--border-light);
  border-radius: var(--r-sm);
  padding: var(--s2) var(--s3);
}

.token-row .token-label {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  flex-shrink: 0;
}

.token-row .token-value {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
}

.btn-copy {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--bg-surface);
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.75rem;
  transition: all var(--transition);
}

.btn-copy:hover { color: var(--c-primary); border-color: var(--c-primary); }
.btn-copy.copied { color: var(--c-primary); border-color: var(--c-primary); }

.instance-card-footer {
  padding: var(--s3) var(--s4);
  border-top: 1px solid var(--border-light);
  display: flex;
  gap: var(--s2);
}

/* ==========================================================
   MODAL
   ========================================================== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: var(--s6);
}

.modal {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-md);
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
}

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

.modal-header h3 {
  font-size: 0.925rem;
  font-weight: 700;
  color: var(--text-primary);
}

.modal-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: var(--r-sm);
  border: none;
  background: none;
  color: var(--text-muted);
  font-size: 1rem;
  cursor: pointer;
}

.modal-close:hover { background: var(--bg-elevated); color: var(--text-primary); }

.modal-body { padding: var(--s5); }

.modal-footer {
  padding: var(--s4) var(--s5);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: var(--s2);
}

/* Tabs inside modal */
.modal-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  margin-bottom: var(--s5);
}

.modal-tab-btn {
  flex: 1;
  background: none;
  border: none;
  padding: var(--s3) var(--s4);
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all var(--transition);
}

.modal-tab-btn.active {
  color: var(--c-primary);
  border-bottom-color: var(--c-primary);
}

/* Pairing code display */
.pairing-code-box {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: var(--s5);
  text-align: center;
  margin-top: var(--s4);
}

.pairing-code-value {
  font-family: var(--font-mono);
  font-size: 2rem;
  font-weight: 700;
  color: var(--c-primary);
  letter-spacing: 0.1em;
  margin: var(--s2) 0;
}

/* QR Code area */
.qr-area {
  display: flex;
  justify-content: center;
  align-items: center;
  background: white;
  border-radius: var(--r-md);
  padding: var(--s4);
  min-height: 240px;
  margin: var(--s4) 0;
}

.modal-status {
  display: flex;
  align-items: center;
  gap: var(--s2);
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: var(--s4);
}

/* ==========================================================
   CONSOLE LOG
   ========================================================== */
.console-log {
  background: #0d1117;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: var(--s4);
  font-family: var(--font-mono);
  font-size: 0.775rem;
  line-height: 1.6;
  color: #58a6ff;
  min-height: 320px;
  max-height: 500px;
  overflow-y: auto;
}

.console-entry {
  display: flex;
  gap: var(--s2);
  border-left: 2px solid #30363d;
  padding-left: var(--s2);
  margin-bottom: 4px;
}

.console-entry.incoming { border-left-color: #3fb950; color: #3fb950; }
.console-entry.status { border-left-color: #f0883e; color: #f0883e; }

.console-ts { color: #484f58; flex-shrink: 0; }
.console-tag { color: #8b949e; flex-shrink: 0; }
.console-empty { color: #484f58; font-style: italic; }

/* ==========================================================
   EMPTY STATE
   ========================================================== */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--s10) var(--s6);
  text-align: center;
  gap: var(--s3);
}

.empty-state i {
  font-size: 2rem;
  color: var(--text-muted);
}

.empty-state h4 {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-primary);
}

.empty-state p {
  font-size: 0.8rem;
  color: var(--text-secondary);
  max-width: 300px;
}

/* ==========================================================
   TOAST NOTIFICATIONS
   ========================================================== */
.toast-area {
  position: fixed;
  bottom: var(--s5);
  right: var(--s5);
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: var(--s2);
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: var(--s3);
  padding: var(--s3) var(--s4);
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-md);
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-primary);
  min-width: 260px;
  max-width: 380px;
  pointer-events: auto;
  animation: toast-in 0.2s ease;
}

.toast i { flex-shrink: 0; font-size: 0.9rem; }
.toast.success { border-left: 3px solid var(--c-primary); }
.toast.success i { color: var(--c-primary); }
.toast.error { border-left: 3px solid var(--c-danger); }
.toast.error i { color: var(--c-danger); }
.toast.info { border-left: 3px solid var(--c-info); }
.toast.info i { color: var(--c-info); }

@keyframes toast-in {
  from { opacity: 0; transform: translateX(12px); }
  to   { opacity: 1; transform: translateX(0); }
}

/* ==========================================================
   PANEL SEARCH BAR
   ========================================================== */
.search-bar {
  display: flex;
  align-items: center;
  gap: var(--s3);
  flex-wrap: wrap;
}

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

.search-input-wrap i {
  position: absolute;
  left: var(--s3);
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: 0.8rem;
  pointer-events: none;
}

.search-input-wrap .form-input {
  padding-left: 30px;
}

/* ==========================================================
   STAT CARDS (Dashboard-like row)
   ========================================================== */
.stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: var(--s4);
}

.stat-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--s4) var(--s5);
  box-shadow: var(--shadow-sm);
}

.stat-label {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: var(--s1);
}

.stat-value {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.2;
}

.stat-sub {
  margin-top: var(--s1);
  font-size: 0.75rem;
  color: var(--text-secondary);
}

/* ==========================================================
   PROFILE SECTION GRID
   ========================================================== */
.profile-grid {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: var(--s5);
  align-items: start;
}

/* ==========================================================
   SIDE + MAIN layout for instances tab
   ========================================================== */
.side-main-layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: var(--s5);
  align-items: start;
}

/* ==========================================================
   MISC
   ========================================================== */
.divider {
  height: 1px;
  background: var(--border);
  margin: var(--s4) 0;
}

.text-sm { font-size: 0.8rem; }
.text-xs { font-size: 0.75rem; }

.spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

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

/* ==========================================================
   RESPONSIVE
   ========================================================== */
@media (max-width: 900px) {
  .app-shell { flex-direction: column; height: auto; min-height: 100vh; }
  .sidebar { width: 100%; height: auto; position: static; border-right: none; border-bottom: 1px solid var(--border); }
  .sidebar-nav { flex-direction: row; flex-wrap: wrap; padding: var(--s2); gap: var(--s1); }
  .nav-group-label { display: none; }
  .nav-item { width: auto; flex: 1; justify-content: center; border-left: none; border-bottom: 2px solid transparent; border-radius: var(--r-sm); }
  .nav-item.active { border-bottom-color: var(--c-primary); border-left-color: transparent; }
  .side-main-layout { grid-template-columns: 1fr; }
  .profile-grid { grid-template-columns: 1fr; }
  .profile-two-col { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
}

/* ==========================================================
   AUTH ERROR + PROFILE GRID (React app additions)
   ========================================================== */
.error-msg {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(220, 38, 38, 0.1);
  border: 1px solid rgba(220, 38, 38, 0.25);
  border-radius: 6px;
  padding: 10px 14px;
  font-size: 0.8rem;
  color: #dc2626;
}

.profile-two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  max-width: 800px;
  align-items: start;
}

.qr-area img { width: 220px; height: 220px; }

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 3px 0;
}

.checkbox-row input {
  accent-color: var(--c-primary);
  width: 15px;
  height: 15px;
  cursor: pointer;
}

/* ==========================================================
   SEGMENTED TABS + FILE PICKER (SendMessage)
   ========================================================== */
.seg-tabs {
  display: flex;
  gap: var(--s1);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 3px;
}

.seg-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--s2);
  padding: 7px 10px;
  font-size: 0.8rem;
  font-weight: 600;
  border: none;
  border-radius: var(--r-sm);
  background: none;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition);
}

.seg-btn.active {
  background: var(--bg-surface);
  color: var(--c-primary);
  box-shadow: var(--shadow-sm);
}

.file-drop {
  border: 1.5px dashed var(--border);
  border-radius: var(--r-md);
  background: var(--bg-input);
  cursor: pointer;
  transition: border-color var(--transition);
  min-height: 96px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--s3);
}

.file-drop:hover { border-color: var(--c-primary); }

.file-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  color: var(--text-muted);
  text-align: center;
}

.file-empty i { font-size: 1.4rem; color: var(--text-muted); }

.file-item {
  display: flex;
  align-items: center;
  gap: var(--s3);
  width: 100%;
  padding: var(--s2) var(--s3);
}

.file-item > i { font-size: 1.2rem; color: var(--c-primary); flex-shrink: 0; }

.file-meta {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.file-name {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-size { font-size: 0.72rem; color: var(--text-muted); }

.file-remove {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--bg-surface);
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.75rem;
  transition: all var(--transition);
}

.file-remove:hover { color: var(--c-danger); border-color: var(--c-danger); }

/* ==========================================================
   CONVERSATIONS (chat list + chat view)
   ========================================================== */
.conv-layout {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: var(--s5);
  align-items: stretch;
  flex: 1;
  min-height: 480px;
}

.conv-sidebar {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.conv-sidebar-header {
  padding: var(--s3);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: var(--s2);
}

.conv-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.conv-item {
  display: flex;
  align-items: center;
  gap: var(--s3);
  padding: var(--s3) var(--s4);
  border: none;
  background: none;
  cursor: pointer;
  text-align: left;
  border-bottom: 1px solid var(--border-light);
  border-left: 2px solid transparent;
  transition: background-color var(--transition);
  width: 100%;
}

.conv-item:hover { background: var(--bg-elevated); }
.conv-item.active {
  background: var(--c-primary-light);
  border-left-color: var(--c-primary);
}

.conv-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  font-weight: 700;
  flex-shrink: 0;
}

.conv-avatar-loading {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 0.85rem;
}

.conv-item-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.conv-item-top,
.conv-item-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s2);
}

.conv-name {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
}

.conv-name i { font-size: 0.7rem; color: var(--text-muted); }

.conv-time {
  font-size: 0.68rem;
  color: var(--text-muted);
  flex-shrink: 0;
}

.conv-preview {
  font-size: 0.75rem;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
}

.conv-unread {
  flex-shrink: 0;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--c-primary);
  color: white;
  font-size: 0.65rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Chat panel */
.conv-chat {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

.chat-header {
  padding: var(--s3) var(--s5);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s3);
}

.chat-header-info {
  display: flex;
  align-items: center;
  gap: var(--s3);
  min-width: 0;
}

.chat-title {
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-title i { font-size: 0.75rem; color: var(--text-muted); }

.chat-sub {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: var(--s4) var(--s5);
  display: flex;
  flex-direction: column;
  gap: var(--s2);
  background: var(--bg-base);
}

.chat-load-older {
  display: flex;
  justify-content: center;
}

.chat-row {
  display: flex;
}

.chat-row.in { justify-content: flex-start; }
.chat-row.out { justify-content: flex-end; }

.chat-bubble {
  max-width: 75%;
  padding: var(--s2) var(--s3);
  border-radius: var(--r-md);
  font-size: 0.82rem;
  line-height: 1.45;
  word-break: break-word;
}

.chat-bubble.in {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-top-left-radius: 2px;
  color: var(--text-primary);
}

.chat-bubble.out {
  background: var(--c-primary);
  color: white;
  border-top-right-radius: 2px;
}

.chat-text { white-space: pre-wrap; }

.chat-media {
  display: flex;
  align-items: center;
  gap: var(--s2);
  font-size: 0.78rem;
}

.chat-media a {
  color: inherit;
  opacity: 0.85;
}

.chat-media a:hover { opacity: 1; }

.chat-meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  margin-top: 3px;
  font-size: 0.62rem;
  opacity: 0.75;
}

.chat-status.read { opacity: 1; }

.chat-revoked {
  display: flex;
  align-items: center;
  gap: 6px;
  font-style: italic;
  opacity: 0.85;
}

.chat-reactions {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 4px;
  flex-wrap: wrap;
}

.chat-reaction {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 26px;
  height: 26px;
  padding: 0 6px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 0.85rem;
  cursor: default;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}

.chat-bubble.out .chat-reaction {
  background: rgba(255, 255, 255, 0.22);
  border-color: rgba(255, 255, 255, 0.35);
}

.chat-poll { min-width: 220px; }

.chat-poll-q {
  font-weight: 600;
  margin-bottom: 6px;
  white-space: pre-wrap;
}

.chat-poll-options {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.chat-poll-opt {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm, 6px);
  font-size: 0.78rem;
}

.chat-bubble.out .chat-poll-opt {
  border-color: rgba(255, 255, 255, 0.35);
  background: rgba(255, 255, 255, 0.1);
}

.chat-poll-opt-count {
  opacity: 0.8;
  white-space: nowrap;
  font-size: 0.7rem;
}

.chat-poll-meta {
  margin-top: 6px;
  font-size: 0.66rem;
  opacity: 0.75;
}

.chat-event {
  display: flex;
  gap: 10px;
  min-width: 200px;
}

.chat-event-icon {
  font-size: 1.3rem;
  opacity: 0.9;
}

.chat-event-main { flex: 1; }

.chat-event-name { font-weight: 600; }

.chat-event-desc {
  font-size: 0.78rem;
  opacity: 0.9;
  margin-top: 2px;
  white-space: pre-wrap;
}

.chat-event-loc {
  font-size: 0.72rem;
  opacity: 0.85;
  margin-top: 4px;
}

.chat-event-link {
  display: inline-block;
  margin-top: 6px;
  font-size: 0.72rem;
  text-decoration: underline;
}

.chat-loc-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-top: 5px;
  font-size: 0.72rem;
  text-decoration: underline;
}

.chat-composer {
  padding: var(--s3) var(--s4);
  border-top: 1px solid var(--border);
  display: flex;
  gap: var(--s2);
}

.chat-composer .form-input { flex: 1; }

.chat-disconnected {
  padding: var(--s2) var(--s4);
  font-size: 0.75rem;
  color: var(--c-warning);
  display: flex;
  align-items: center;
  gap: var(--s2);
  border-top: 1px solid var(--border);
}

@media (max-width: 900px) {
  .conv-layout { grid-template-columns: 1fr; }

  /* On small screens the stacked panels need natural height (page scrolls). */
  .conv-page { height: auto; overflow-y: auto; }
  .conv-page .conv-layout { min-height: 480px; }
}

/* ==========================================================
   CHAT UX UPGRADES (Conversations)
   ========================================================== */

/* The conversations page fills the viewport: only the inner panels scroll
   (sidebar list + chat messages), never the whole page — WhatsApp-Web style. */
.conv-page {
  overflow: hidden;
}

.conv-page .conv-layout {
  flex: 1;
  min-height: 0;
}

.conv-page .conv-sidebar,
.conv-page .conv-chat {
  min-height: 0;
}

/* The two inner scroll areas must be allowed to shrink below their content
   height, otherwise they overflow instead of scrolling internally. */
.conv-page .conv-list,
.conv-page .chat-messages {
  min-height: 0;
}

/* Reply quote block inside a bubble (shows which message was replied to). */
.chat-quote {
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: 4px 8px;
  margin-bottom: 5px;
  border-left: 3px solid currentColor;
  border-radius: var(--r-sm);
  background: rgba(0, 0, 0, 0.06);
  opacity: 0.92;
}

.chat-bubble.out .chat-quote {
  background: rgba(255, 255, 255, 0.16);
}

.chat-quote-name {
  font-size: 0.68rem;
  font-weight: 700;
  line-height: 1.3;
}

.chat-quote-text {
  font-size: 0.76rem;
  line-height: 1.35;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  word-break: break-word;
}

/* Day separators (Hoje / Ontem / dd/mm) */
.chat-day {
  display: flex;
  align-items: center;
  justify-content: center;
  margin: var(--s2) 0;
  flex-shrink: 0;
}

.chat-day span {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 0.68rem;
  font-weight: 600;
  padding: 2px 10px;
  border-radius: 999px;
}

/* Message grouping: consecutive messages from the same sender get tighter
   spacing and only the last one keeps the bubble tail + timestamp. */
.chat-bubble-wrap {
  position: relative;
  max-width: 78%;
  display: flex;
  flex-direction: column;
}

.chat-row.in .chat-bubble-wrap { align-items: flex-start; }
.chat-row.out .chat-bubble-wrap { align-items: flex-end; }

.chat-bubble { max-width: 100%; }

.chat-row.grouped { margin-top: -7px; }

.chat-bubble.grouped { border-radius: var(--r-md); }
.chat-row.in .chat-bubble.grouped { border-top-left-radius: 4px; }
.chat-row.out .chat-bubble.grouped { border-top-right-radius: 4px; }

/* Sender name shown on the first incoming message of a group (group chats) */
.chat-sender {
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--c-primary);
  margin-bottom: 2px;
}

/* Voice note transcription */
.chat-transcript {
  display: flex;
  gap: 6px;
  margin-top: 6px;
  padding: 6px 8px;
  background: rgba(0, 0, 0, 0.06);
  border-radius: var(--r-sm);
  font-size: 0.78rem;
  line-height: 1.45;
  color: var(--text-secondary);
}

.chat-bubble.out .chat-transcript {
  background: rgba(255, 255, 255, 0.15);
  color: rgba(255, 255, 255, 0.95);
}

.chat-transcript i { opacity: 0.6; flex-shrink: 0; margin-top: 1px; }

/* Inline media: audio player, image preview, video */
.chat-media-inline { margin: 2px 0; }

.chat-audio {
  width: 240px;
  max-width: 100%;
  height: 36px;
  border-radius: var(--r-md);
}

.chat-img-link { display: block; border-radius: var(--r-md); overflow: hidden; }

.chat-img {
  display: block;
  max-width: 280px;
  max-height: 320px;
  border-radius: var(--r-md);
  object-fit: cover;
}

.chat-video {
  max-width: 280px;
  max-height: 320px;
  border-radius: var(--r-md);
}

/* Per-message actions (hover menu) */
.chat-actions-btn {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  opacity: 0;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg-surface);
  color: var(--text-muted);
  cursor: pointer;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.72rem;
  transition: opacity var(--transition), color var(--transition);
}

.chat-row:hover .chat-actions-btn,
.chat-actions-btn.open { opacity: 1; }

.chat-row.in .chat-actions-btn { right: -34px; }
.chat-row.out .chat-actions-btn { left: -34px; }

.chat-actions-btn:hover { color: var(--text-primary); }

.chat-actions-menu {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 20;
  min-width: 180px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-md);
  padding: var(--s1);
  display: flex;
  flex-direction: column;
}

.chat-row.in .chat-actions-menu { right: -34px; }
.chat-row.out .chat-actions-menu { left: -34px; }

.chat-actions-menu > button {
  display: flex;
  align-items: center;
  gap: var(--s2);
  padding: var(--s2) var(--s3);
  font-size: 0.78rem;
  border: none;
  background: none;
  color: var(--text-secondary);
  border-radius: var(--r-sm);
  cursor: pointer;
  text-align: left;
  width: 100%;
  font-family: var(--font-sans);
  transition: background-color var(--transition), color var(--transition);
}

.chat-actions-menu > button:hover:not(:disabled) { background: var(--bg-elevated); color: var(--text-primary); }
.chat-actions-menu > button.danger { color: var(--c-danger); }
.chat-actions-menu > button.danger:hover:not(:disabled) { background: var(--c-danger-light); }
.chat-actions-menu > button:disabled { opacity: 0.5; cursor: default; }
.chat-actions-menu > button i { width: 14px; text-align: center; font-size: 0.78rem; }

.chat-actions-reactions {
  display: flex;
  gap: 2px;
  padding: var(--s1) var(--s2);
  border-bottom: 1px solid var(--border-light);
  margin-bottom: var(--s1);
}

.chat-actions-reactions button {
  justify-content: center;
  font-size: 1rem;
  padding: 2px 6px;
  width: auto;
}

/* Floating "jump to bottom" button */
.conv-chat { position: relative; }

.chat-jump {
  position: absolute;
  right: 18px;
  bottom: 84px;
  z-index: 10;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg-surface);
  color: var(--text-secondary);
  box-shadow: var(--shadow-md);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  transition: color var(--transition), border-color var(--transition);
}

.chat-jump:hover { color: var(--c-primary); border-color: var(--c-primary); }

/* Composer: auto-growing textarea + reply quote chip */
.chat-composer {
  flex-direction: column;
  gap: var(--s1);
}

.chat-composer-box {
  display: flex;
  align-items: flex-end;
  gap: var(--s2);
}

.chat-input {
  flex: 1;
  min-height: 36px;
  max-height: 120px;
  resize: none;
  overflow-y: auto;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 0.875rem;
  line-height: 1.5;
  padding: 8px 12px;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.chat-input:focus {
  border-color: var(--c-primary);
  box-shadow: 0 0 0 3px var(--c-primary-ring);
}

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

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

.chat-composer-hint {
  font-size: 0.68rem;
  color: var(--text-muted);
  padding: 0 2px;
}

/* Reply-with-quote chip above the composer */
.chat-reply-chip {
  display: flex;
  align-items: center;
  gap: var(--s2);
  background: var(--bg-elevated);
  border-left: 3px solid var(--c-primary);
  border-radius: var(--r-md);
  padding: var(--s2) var(--s3);
  margin-bottom: var(--s2);
}

.chat-reply-chip-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.chat-reply-name {
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--c-primary);
  display: flex;
  align-items: center;
  gap: 5px;
}

.chat-reply-text {
  font-size: 0.78rem;
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-reply-close {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border: none;
  background: none;
  color: var(--text-muted);
  border-radius: var(--r-sm);
  cursor: pointer;
  font-size: 0.8rem;
}

.chat-reply-close:hover { background: var(--bg-surface); color: var(--text-primary); }

/* ==========================================================
   CONTACTS LIST (ContactsModal)
   ========================================================== */
.contacts-list {
  display: flex;
  flex-direction: column;
  gap: var(--s1);
  max-height: 420px;
  overflow-y: auto;
  margin-top: var(--s3);
}

.contact-row {
  display: flex;
  align-items: center;
  gap: var(--s3);
  padding: var(--s2) var(--s3);
  border: 1px solid var(--border-light);
  border-radius: var(--r-md);
  background: var(--bg-elevated);
}

.contact-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--c-primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  font-weight: 700;
  flex-shrink: 0;
}

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

.contact-name {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.contact-jid {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Location map ── */
.location-map-wrap {
  position: relative;
  width: 100%;
  height: 60vh;
  min-height: 400px;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border);
  z-index: 0; /* leaflet needs this to render tiles */
}
.leaflet-container { width: 100%; height: 100%; background: #e5e3df; }

/* ── Location map markers ── */
.location-marker { background: none !important; border: none !important; }

.location-marker-img {
  width: 40px; height: 40px; border-radius: 50%; overflow: hidden;
  border: 3px solid #fff; box-shadow: 0 2px 6px rgba(0,0,0,0.35);
  position: relative; background: var(--c-primary);
}
.location-marker-img img {
  width: 100%; height: 100%; object-fit: cover; display: block;
}
.location-marker-img .location-marker-fallback {
  position: absolute; inset: 0; display: none; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; font-size: 16px; background: var(--c-primary);
}
.location-marker-img.fallback .location-marker-fallback { display: flex; }

.location-marker-circle {
  width: 36px; height: 36px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; font-size: 15px;
  border: 3px solid #fff; box-shadow: 0 2px 6px rgba(0,0,0,0.35);
}

/* ==========================================================
   INSTANCE CARDS — NOVO DESIGN (inst-*)
   ========================================================== */
.inst-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  overflow: hidden;
  transition: box-shadow var(--transition), border-color var(--transition);
  display: flex;
  flex-direction: column;
}
.inst-card:hover {
  box-shadow: var(--shadow-md);
  border-color: var(--border);
}
.inst-card.connected { border-left: 3px solid var(--c-success); }
.inst-card.disconnected { border-left: 3px solid var(--border); }

.inst-card-header {
  display: flex;
  align-items: center;
  gap: var(--s3);
  padding: var(--s4);
}

.inst-avatar {
  position: relative;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  font-weight: 700;
  color: white;
  flex-shrink: 0;
  letter-spacing: 0.02em;
}

.inst-status-dot {
  position: absolute;
  bottom: 1px;
  right: 1px;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  border: 2px solid var(--bg-surface);
}
.inst-status-dot.online {
  background: var(--c-success);
  box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.4);
  animation: inst-pulse 2.5s ease infinite;
}
.inst-status-dot.offline { background: var(--text-muted); }

@keyframes inst-pulse {
  0%   { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.4); }
  70%  { box-shadow: 0 0 0 6px rgba(34, 197, 94, 0); }
  100% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0); }
}

.inst-card-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.inst-card-name {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.inst-card-jid {
  font-size: 0.72rem;
  color: var(--text-secondary);
  font-family: var(--font-mono);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 4px;
}
.inst-card-jid--empty { color: var(--text-muted); font-style: italic; font-family: var(--font-sans); }

.inst-card-owner {
  font-size: 0.68rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 4px;
}

.inst-card-badges {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  flex-shrink: 0;
}

.inst-status-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}
.inst-status-pill.online {
  background: rgba(34, 197, 94, 0.12);
  color: #16a34a;
  border: 1px solid rgba(34, 197, 94, 0.25);
}
.inst-status-pill.offline {
  background: var(--bg-elevated);
  color: var(--text-muted);
  border: 1px solid var(--border-light);
}
.inst-status-pill-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.inst-card-token {
  display: flex;
  align-items: center;
  gap: var(--s2);
  padding: var(--s2) var(--s4);
  border-top: 1px solid var(--border-light);
  border-bottom: 1px solid var(--border-light);
  background: var(--bg-elevated);
}

.inst-token-label {
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  flex-shrink: 0;
}

.inst-token-value {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--text-secondary);
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.inst-token-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.inst-card-footer {
  display: flex;
  gap: 4px;
  padding: var(--s3) var(--s4);
  align-items: center;
}

.inst-action-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  border-radius: var(--r-md);
  border: 1px solid transparent;
  font-size: 0.75rem;
  font-weight: 600;
  font-family: var(--font-sans);
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
}
.inst-action-btn span { display: none; }
@media (min-width: 1100px) { .inst-action-btn span { display: inline; } }

.inst-action-btn.primary {
  background: var(--c-primary);
  color: white;
  border-color: var(--c-primary);
}
.inst-action-btn.primary:hover:not(:disabled) {
  background: var(--c-primary-hover, #1557b0);
}
.inst-action-btn.success {
  background: rgba(34, 197, 94, 0.1);
  color: #16a34a;
  border-color: rgba(34, 197, 94, 0.3);
}
.inst-action-btn.success:hover:not(:disabled) {
  background: rgba(34, 197, 94, 0.2);
}
.inst-action-btn.warning {
  background: var(--c-warning-light);
  color: var(--c-warning);
  border-color: rgba(217, 119, 6, 0.3);
}
.inst-action-btn.warning:hover:not(:disabled) {
  background: rgba(217, 119, 6, 0.2);
}
.inst-action-btn.ghost {
  background: transparent;
  color: var(--text-secondary);
  border-color: var(--border);
}
.inst-action-btn.ghost:hover:not(:disabled) {
  background: var(--bg-elevated);
  color: var(--text-primary);
}
.inst-action-btn.danger {
  background: transparent;
  color: var(--c-danger);
  border-color: transparent;
  margin-left: auto;
}
.inst-action-btn.danger:hover:not(:disabled) {
  background: var(--c-danger-light);
  border-color: var(--c-danger);
}
.inst-action-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ==========================================================
   INSTANCE SEARCH BAR
   ========================================================== */
.inst-search-wrap {
  display: flex;
  align-items: center;
  gap: var(--s2);
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  padding: 6px 14px;
  flex: 1;
  margin-bottom: 0;
}
.inst-search-wrap i { color: var(--text-muted); font-size: 0.85rem; flex-shrink: 0; }
.inst-search-wrap .form-input {
  border: none;
  background: transparent;
  padding: 0;
  height: auto;
  box-shadow: none;
  font-size: 0.875rem;
}
.inst-search-wrap .form-input:focus { box-shadow: none; border: none; }
.inst-search-count {
  font-size: 0.72rem;
  color: var(--text-muted);
  white-space: nowrap;
  font-family: var(--font-mono);
  flex-shrink: 0;
}
.inst-search-clear {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 0.8rem;
  padding: 2px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.inst-search-clear:hover { color: var(--text-primary); background: var(--bg-elevated); }

.inst-filters {
  display: flex;
  align-items: center;
  gap: var(--s3);
  margin-bottom: var(--s4);
}

.inst-owner-filter {
  display: flex;
  align-items: center;
  gap: var(--s2);
  min-width: 230px;
}

.inst-owner-filter > i {
  color: var(--text-muted);
}

.inst-owner-filter .form-select {
  min-width: 200px;
}

/* ==========================================================
   INSTANCE WORKSPACE
   ========================================================== */
.workspace-nav {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--s3);
  margin-bottom: var(--s5);
}

.workspace-nav-item {
  display: flex;
  align-items: center;
  gap: var(--s3);
  padding: var(--s4);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  background: var(--bg-surface);
  color: var(--text-secondary);
  text-align: left;
  cursor: pointer;
  transition: var(--transition);
}

.workspace-nav-item:hover { border-color: var(--c-primary); color: var(--text-primary); }
.workspace-nav-item.active {
  border-color: var(--c-primary);
  background: var(--c-primary-light);
  color: var(--c-primary);
  box-shadow: var(--shadow-sm);
}

.workspace-nav-icon {
  width: 40px;
  height: 40px;
  border-radius: var(--r-md);
  display: grid;
  place-items: center;
  background: var(--bg-elevated);
  flex-shrink: 0;
}

.workspace-nav-item.active .workspace-nav-icon { background: var(--bg-surface); }
.workspace-nav-item strong { display: block; font-size: .85rem; }
.workspace-nav-item small { display: block; margin-top: 2px; color: var(--text-muted); font-size: .7rem; }
.page-content-embedded { padding: 0; }

/* ==========================================================
   INTEGRATION SKILL
   ========================================================== */
.skill-guide-grid {
  display: grid;
  grid-template-columns: minmax(240px, 320px) minmax(0, 1fr);
  gap: var(--s4);
  align-items: start;
}

.skill-steps {
  display: flex;
  flex-direction: column;
  gap: var(--s3);
  padding-left: 20px;
  margin: 0 0 var(--s4);
  color: var(--text-secondary);
  font-size: .85rem;
  line-height: 1.5;
}

.skill-textarea {
  width: 100%;
  min-height: 560px;
  resize: vertical;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--bg-elevated);
  color: var(--text-primary);
  padding: var(--s4);
  font: .78rem/1.55 var(--font-mono);
  outline: none;
}

.skill-textarea:focus { border-color: var(--c-primary); box-shadow: 0 0 0 2px var(--c-primary-light); }

@media (max-width: 900px) {
  .workspace-nav { grid-template-columns: 1fr; }
  .skill-guide-grid { grid-template-columns: 1fr; }
  .skill-textarea { min-height: 420px; }
}

@media (max-width: 720px) {
  .inst-filters { align-items: stretch; flex-direction: column; }
  .inst-owner-filter, .inst-owner-filter .form-select { width: 100%; min-width: 0; }
  .inst-action-btn span { display: inline; }
  .inst-card-footer { flex-wrap: wrap; }
}

/* ==========================================================
   INSTANCE EMPTY STATE
   ========================================================== */
.inst-empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--s3);
  padding: var(--s8) var(--s4);
  text-align: center;
  color: var(--text-muted);
}
.inst-empty-icon {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: var(--c-primary-light);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  color: var(--c-primary);
  margin-bottom: var(--s2);
}
.inst-empty-state h3 { font-size: 1.1rem; font-weight: 700; color: var(--text-primary); margin: 0; }
.inst-empty-state p { font-size: 0.875rem; max-width: 340px; margin: 0; }

/* ==========================================================
   INSTANCE CREATE MODAL HINT
   ========================================================== */
.inst-create-preview {
  display: flex;
  align-items: flex-start;
  gap: var(--s2);
  background: var(--c-primary-light);
  border: 1px solid rgba(26, 115, 232, 0.2);
  border-radius: var(--r-md);
  padding: var(--s3);
  font-size: 0.8rem;
  color: var(--c-primary);
  margin-top: var(--s2);
}
.inst-create-preview i { flex-shrink: 0; margin-top: 1px; }

/* ==========================================================
   INSTANCE TOKEN ALERT (inside modal)
   ========================================================== */
.inst-token-alert {
  display: flex;
  align-items: flex-start;
  gap: var(--s2);
  background: rgba(217, 119, 6, 0.1);
  border: 1px solid rgba(217, 119, 6, 0.3);
  border-radius: var(--r-md);
  padding: var(--s3);
  font-size: 0.82rem;
  color: var(--c-warning);
}
.inst-token-alert i { flex-shrink: 0; margin-top: 1px; }

/* ==========================================================
   EXTRA UTILITIES (used by new JSX classes, not in original)
   ========================================================== */
.btn-ghost { background: transparent; color: var(--text-secondary); border-color: transparent; }
.btn-ghost:hover:not(:disabled) { background: var(--bg-elevated); color: var(--text-primary); }
.badge-green { background: rgba(5, 150, 105, 0.12); color: #16a34a; }
.badge-blue  { background: rgba(37, 99, 235, 0.10); color: #2563eb; }
.alert { display: flex; align-items: flex-start; gap: var(--s3); padding: var(--s3) var(--s4); border-radius: var(--r-md); font-size: 0.85rem; border: 1px solid transparent; }
.alert-warning { background: var(--c-warning-light); border-color: var(--c-warning); color: var(--c-warning); }
.divider { height: 1px; background: var(--border); margin: var(--s4) 0; }
.table-wrapper { overflow-x: auto; width: 100%; }

/* Sendjob */
.sendjob-layout { display: grid; grid-template-columns: 1fr 380px; gap: var(--s5); align-items: start; }
.sendjob-form { display: flex; flex-direction: column; gap: var(--s4); }
.sendjob-recipients { display: flex; flex-direction: column; gap: var(--s2); }
.sendjob-recipient-chip { display: flex; align-items: center; gap: var(--s2); background: var(--bg-elevated); border: 1px solid var(--border-light); border-radius: var(--r-xl); padding: 3px 10px; font-size: 0.78rem; }
.sendjob-recipient-name { flex: 1; color: var(--text-primary); }
.sendjob-recipient-remove { background: none; border: none; cursor: pointer; color: var(--text-muted); font-size: 0.75rem; padding: 0; }
.sendjob-recipient-remove:hover { color: var(--c-danger); }
.sendjob-contacts { display: flex; flex-direction: column; gap: var(--s2); }
.sendjob-contacts-list { display: flex; flex-direction: column; gap: var(--s1); max-height: 260px; overflow-y: auto; }
.sendjob-no-recipients { color: var(--text-muted); font-size: 0.82rem; font-style: italic; padding: var(--s4); text-align: center; }
.sendjob-preview { display: flex; flex-direction: column; gap: var(--s3); background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--r-md); padding: var(--s4); }
.sendjob-preview-header { font-size: 0.78rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); }
.sendjob-preview-select { margin-bottom: var(--s2); }
.sendjob-preview-text { font-size: 0.85rem; line-height: 1.5; white-space: pre-wrap; word-break: break-word; color: var(--text-primary); background: var(--bg-surface); border: 1px solid var(--border); border-radius: var(--r-sm); padding: var(--s3) var(--s4); min-height: 80px; }
.sendjob-progress-bar { width: 100%; height: 6px; background: var(--bg-elevated); border-radius: var(--r-xl); overflow: hidden; border: 1px solid var(--border); }
.sendjob-progress-fill { height: 100%; background: var(--c-primary); border-radius: var(--r-xl); transition: width 0.4s ease; }
.sendjob-live-info { font-size: 0.78rem; color: var(--text-secondary); display: flex; align-items: center; gap: var(--s2); }
.sendjob-vars-hint { font-size: 0.78rem; color: var(--text-muted); background: var(--bg-elevated); border: 1px solid var(--border-light); border-radius: var(--r-sm); padding: var(--s2) var(--s3); font-family: var(--font-mono); }
.sendjob-var-custom { color: var(--c-primary); }
.sendjob-custom-editor { background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--r-md); padding: var(--s3); display: flex; flex-direction: column; gap: var(--s2); }
.sendjob-custom-editor-header { display: flex; align-items: center; justify-content: space-between; font-size: 0.78rem; font-weight: 700; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.05em; }
.sendjob-custom-editor-close { background: none; border: none; cursor: pointer; color: var(--text-muted); font-size: 0.85rem; }
.sendjob-custom-editor-close:hover { color: var(--text-primary); }
.sendjob-custom-fields-list { display: flex; flex-direction: column; gap: var(--s2); }
.sendjob-custom-field-row { display: flex; gap: var(--s2); align-items: center; }
.sendjob-custom-field-key, .sendjob-custom-field-val { flex: 1; }
.sendjob-custom-field-remove { background: none; border: none; cursor: pointer; color: var(--text-muted); font-size: 0.85rem; padding: 4px; }
.sendjob-custom-field-remove:hover { color: var(--c-danger); }
.sendjob-custom-add { font-size: 0.8rem; color: var(--c-primary); background: none; border: none; cursor: pointer; padding: 0; font-family: var(--font-sans); display: flex; align-items: center; gap: var(--s1); }
.sendjob-custom-add:hover { text-decoration: underline; }

/* Toast */
.toast-area { position: fixed; bottom: var(--s5); right: var(--s5); z-index: 2000; display: flex; flex-direction: column; gap: var(--s2); pointer-events: none; }

/* Console extras */
.console-ts { color: #6e7681; flex-shrink: 0; font-size: 0.72rem; }

/* Responsive */
@media (max-width: 720px) {
  .sendjob-layout { grid-template-columns: 1fr; }
  .inst-action-btn span { display: none; }
}
