/* =============================================================
   Google Material Design 3 Design System for WhatsApp-Go
   ============================================================= */

@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700&family=Roboto:wght@400;500;700&family=JetBrains+Mono:wght@400;500&display=swap');

/* ── Design Tokens ── */
:root {
  --font-sans: 'Plus Jakarta Sans', 'Roboto', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;

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

  /* Border Radius */
  --r-xs: 4px;
  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;
  --r-xl: 24px;

  /* Transitions */
  --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ── Light Theme ── */
[data-theme="light"] {
  --bg-base:     #f0f4f9;   /* Google light gray-blue background */
  --bg-surface:  #ffffff;   /* Cards and sidebar background */
  --bg-elevated: #e9eef6;   /* Active item background */
  --bg-input:    #f0f4f9;
  --bg-table-th: #f3f6fc;

  --border:      #dadce0;   /* Thin Google borders */
  --border-light: #f1f3f4;

  --c-primary:     #0b57d0;  /* Google Blue */
  --c-primary-hover: #0842a0;
  --c-primary-light: #d3e3fd; /* Active pill tint */
  --c-primary-ring:  rgba(11, 87, 208, 0.25);

  --c-danger:        #b3261e;  /* MD3 Error */
  --c-danger-hover:  #8c1d18;
  --c-danger-light:  #f9dedc;

  --c-warning:       #b06000;
  --c-warning-light: #ffe0b2;

  --c-info:          #00639b;
  --c-info-light:    #c2e7ff;

  --c-success:       #146c36;
  --c-success-light: #cbf5db;

  --text-primary:  #1f1f1f; /* Google high contrast dark text */
  --text-secondary:#5f6368; /* Google gray */
  --text-muted:    #80868b;

  --shadow-sm: 0 1px 2px 0 rgba(60,64,67,0.3), 0 1px 3px 1px rgba(60,64,67,0.15);
  --shadow-md: 0 2px 6px 2px rgba(60,64,67,0.15), 0 1px 2px 0 rgba(60,64,67,0.3);
  
  /* Chat specifics */
  --chat-bubble-in:  #f1f3f4;
  --chat-bubble-out: #e3edfc;
  --chat-bubble-in-text:  #1f1f1f;
  --chat-bubble-out-text: #0b57d0;
}

/* ── Dark Theme ── */
[data-theme="dark"] {
  --bg-base:     #0f0f11;   /* Modern deep dark background */
  --bg-surface:  #1a1a1c;   /* Slightly lighter panels/cards */
  --bg-elevated: #2d2f31;   /* Active selection */
  --bg-input:    #2d2f31;
  --bg-table-th: #242526;

  --border:      #303134;   /* Dark thin borders */
  --border-light: #252627;

  --c-primary:     #a8c7fa;  /* Light Google Blue */
  --c-primary-hover: #c2e7ff;
  --c-primary-light: rgba(168, 199, 250, 0.15);
  --c-primary-ring:  rgba(168, 199, 250, 0.3);

  --c-danger:        #f2b8b5;
  --c-danger-hover:  #f9dedc;
  --c-danger-light:  rgba(242, 184, 181, 0.15);

  --c-warning:       #fdd663;
  --c-warning-light: rgba(253, 214, 99, 0.15);

  --c-info:          #7fcfff;
  --c-info-light:    rgba(127, 207, 255, 0.15);

  --c-success:       #81c784;
  --c-success-light: rgba(129, 199, 132, 0.15);

  --text-primary:  #e3e3e3; /* Light high-contrast text */
  --text-secondary:#c4c7c5; /* Secondary text */
  --text-muted:    #8e918f;

  --shadow-sm: 0 1px 3px 0 rgba(0,0,0,0.5);
  --shadow-md: 0 4px 12px 0 rgba(0,0,0,0.6);

  /* Chat specifics */
  --chat-bubble-in:  #2d2f31;
  --chat-bubble-out: rgba(168, 199, 250, 0.18);
  --chat-bubble-in-text:  #e3e3e3;
  --chat-bubble-out-text: #c2e7ff;
}

/* ── 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;
  transition: var(--transition);
}
a:hover {
  text-decoration: none;
  opacity: 0.85;
}

/* ── Utilities ── */
.hidden { display: none !important; }
.text-muted { color: var(--text-muted) !important; }
.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 / Register)
   ========================================================== */
.auth-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: var(--s6);
  background-color: var(--bg-base);
  background-image: radial-gradient(circle at top right, var(--c-primary-light), transparent 400px);
}

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

.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: 2.8rem;
  color: var(--c-primary);
  background: var(--c-primary-light);
  width: 72px;
  height: 72px;
  border-radius: var(--r-lg);
  display: flex;
  align-items: center;
  justify-content: center;
}

.auth-logo h1 {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.02em;
  margin-top: var(--s2);
}

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

.auth-footer {
  margin-top: var(--s6);
  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;
  height: 100vh;
  overflow: hidden;
}

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

.sidebar-header {
  padding: var(--s5) var(--s6);
  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.4rem;
}

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

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

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

.nav-group-label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  padding: var(--s4) var(--s4) var(--s2);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: var(--s4);
  padding: 10px var(--s5);
  color: var(--text-secondary);
  font-size: 0.9rem;
  font-weight: 500;
  border-radius: var(--r-xl); /* Rounded Pill Style (MD3) */
  border: none;
  background: none;
  cursor: pointer;
  text-align: left;
  text-decoration: none;
  width: 100%;
  transition: var(--transition);
}

.nav-item i {
  width: 18px;
  font-size: 1.05rem;
  flex-shrink: 0;
  text-align: center;
}

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

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

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

/* ── Main Area ── */
.main-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
  background-color: var(--bg-base);
}

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

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

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

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg-surface);
  color: var(--text-secondary);
  cursor: pointer;
  transition: var(--transition);
  font-size: 0.95rem;
}

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

/* User chip */
.user-chip {
  display: flex;
  align-items: center;
  gap: var(--s2);
  background: var(--bg-elevated);
  border-radius: var(--r-xl);
  padding: 4px 12px 4px 6px;
}

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

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

/* ── Page Content ── */
.page-content {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: var(--s6);
  display: flex;
  flex-direction: column;
  gap: var(--s6);
}

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

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

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

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

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

.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);
  background: var(--bg-table-th);
}

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

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

/* Profile specific columns */
.profile-two-col {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: var(--s5);
}

/* ==========================================================
   STATS CARD
   ========================================================== */
.stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 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);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.stat-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.stat-value {
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--text-primary);
}

.stat-sub {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* ==========================================================
   BUTTONS (Outlined / Filled / Pill)
   ========================================================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s2);
  padding: 8px 20px;
  font-size: 0.9rem;
  font-weight: 600;
  border-radius: var(--r-xl); /* Fully Rounded (Pill) */
  border: 1px solid transparent;
  cursor: pointer;
  transition: var(--transition);
  text-decoration: none;
  white-space: nowrap;
}

.btn-primary {
  background-color: var(--c-primary);
  border-color: var(--c-primary);
  color: #ffffff;
}
.btn-primary:hover {
  background-color: var(--c-primary-hover);
  border-color: var(--c-primary-hover);
}
.btn-primary:disabled {
  background-color: var(--c-primary-light);
  border-color: var(--c-primary-light);
  color: var(--text-muted);
  cursor: not-allowed;
}

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

.btn-danger {
  background-color: var(--c-danger);
  border-color: var(--c-danger);
  color: #ffffff;
}
.btn-danger:hover {
  background-color: var(--c-danger-hover);
  border-color: var(--c-danger-hover);
}

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

.btn-sm {
  padding: 5px 12px;
  font-size: 0.8rem;
  border-radius: var(--r-xl);
}

.btn-xs {
  padding: 3px 8px;
  font-size: 0.75rem;
  border-radius: var(--r-sm);
  font-weight: 600;
}

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

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

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

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

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

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

.form-input,
.form-select,
.form-textarea {
  width: 100%;
  padding: 10px 14px;
  font-family: inherit;
  font-size: 0.9rem;
  background-color: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  color: var(--text-primary);
  transition: var(--transition);
  outline: none;
}

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

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

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

.input-addon {
  position: absolute;
  right: var(--s3);
  cursor: pointer;
  color: var(--text-secondary);
  transition: var(--transition);
}
.input-addon:hover {
  color: var(--text-primary);
}

.form-hint {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ==========================================================
   TABLES
   ========================================================== */
.table-container {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.table-responsive {
  width: 100%;
  overflow-x: auto;
}

.table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
}

.table th {
  background-color: var(--bg-table-th);
  padding: var(--s3) var(--s4);
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-secondary);
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border);
}

.table td {
  padding: var(--s4) var(--s4);
  font-size: 0.9rem;
  color: var(--text-primary);
  border-bottom: 1px solid var(--border-light);
  transition: var(--transition);
}

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

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

/* ==========================================================
   BADGES & CHIPS
   ========================================================== */
.role-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  font-size: 0.72rem;
  font-weight: 700;
  border-radius: var(--r-sm);
  text-transform: uppercase;
}

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

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

.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 8px;
  font-size: 0.75rem;
  font-weight: 600;
  border-radius: var(--r-sm);
}
.badge-success { background: var(--c-success-light); color: var(--c-success); }
.badge-danger  { background: var(--c-danger-light); color: var(--c-danger); }
.badge-warning { background: var(--c-warning-light); color: var(--c-warning); }

/* ==========================================================
   SEARCH BAR
   ========================================================== */
.search-bar {
  margin-bottom: var(--s2);
}

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

.search-input-wrap i {
  position: absolute;
  left: 14px;
  color: var(--text-secondary);
}

.search-input-wrap .form-input {
  padding-left: var(--s8);
  border-radius: var(--r-xl);
}

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

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

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

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

.instance-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  transition: var(--transition);
  position: relative;
}

.instance-card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 4px;
  height: 100%;
  border-radius: var(--r-lg) 0 0 var(--r-lg);
}

.instance-card.connected::before {
  background-color: var(--c-success);
}

.instance-card.disconnected::before {
  background-color: var(--text-muted);
}

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

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

.instance-id {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 1px;
}

.instance-owner {
  margin-top: 4px;
  font-size: 0.75rem;
  color: var(--text-secondary);
}

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

.info-item {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.info-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  font-weight: 600;
}

.info-val {
  font-size: 0.85rem;
  color: var(--text-primary);
  word-break: break-all;
}

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

/* ==========================================================
   CONVERSATIONS CHAT LAYOUT (WhatsApp-Web Style)
   ========================================================== */
.chat-layout {
  display: flex;
  flex: 1;
  min-height: 0;
  background-color: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

/* ── Chat Sidebar (Incoming Lists) ── */
.chat-sidebar {
  width: 320px;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  background-color: var(--bg-surface);
}

.chat-sidebar-header {
  padding: var(--s4);
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: var(--s3);
}

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

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

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

.chat-item.active {
  background-color: var(--c-primary-light);
}

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

.chat-item-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}

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

.chat-item-time {
  font-size: 0.75rem;
  color: var(--text-muted);
  flex-shrink: 0;
}

.chat-item-bottom {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 2px;
}

.chat-item-preview {
  font-size: 0.8rem;
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  margin-right: var(--s2);
}

.unread-badge {
  background-color: var(--c-primary);
  color: white;
  font-size: 0.72rem;
  font-weight: 700;
  min-width: 16px;
  height: 16px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
}

/* ── Chat Main Area ── */
.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--bg-base);
}

.chat-header {
  height: 60px;
  background-color: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  padding: 0 var(--s5);
  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-header-name {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.chat-header-actions {
  display: flex;
  align-items: center;
  gap: var(--s2);
}

/* ── Chat Messages Stream ── */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: var(--s6);
  display: flex;
  flex-direction: column;
  gap: var(--s4);
}

.chat-date-separator {
  align-self: center;
  background-color: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 0.75rem;
  font-weight: 600;
  padding: 4px 12px;
  border-radius: var(--r-xl);
  margin: var(--s3) 0;
}

.chat-bubble-wrap {
  display: flex;
  flex-direction: column;
  max-width: 70%;
}

.chat-bubble-wrap.out {
  align-self: flex-end;
}

.chat-bubble-wrap.in {
  align-self: flex-start;
}

.chat-bubble {
  position: relative;
  padding: var(--s2) var(--s4);
  border-radius: var(--r-lg);
  box-shadow: 0 1px 1px 0 rgba(0,0,0,0.1);
  word-break: break-word;
  transition: var(--transition);
}

.chat-bubble-wrap.out .chat-bubble {
  background-color: var(--chat-bubble-out);
  color: var(--chat-bubble-out-text);
  border-top-right-radius: var(--r-xs);
}

.chat-bubble-wrap.in .chat-bubble {
  background-color: var(--chat-bubble-in);
  color: var(--chat-bubble-in-text);
  border-top-left-radius: var(--r-xs);
}

.chat-sender {
  font-size: 0.75rem;
  font-weight: 700;
  margin-bottom: 2px;
}
.chat-bubble-wrap.in .chat-sender { color: var(--c-primary); }
.chat-bubble-wrap.out .chat-sender { color: var(--c-info); }

.chat-text {
  font-size: 0.9rem;
  line-height: 1.45;
}

.chat-meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--s1);
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: var(--s1);
  text-align: right;
}

.chat-status {
  font-size: 0.8rem;
}
.chat-status.read { color: var(--c-info); }

/* Reactions list */
.chat-reactions {
  display: flex;
  gap: 2px;
  position: absolute;
  bottom: -10px;
  right: var(--s4);
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  padding: 1px 4px;
  box-shadow: var(--shadow-sm);
  z-index: 10;
}

.chat-reaction-item {
  font-size: 0.85rem;
}

/* Quoted message preview */
.chat-quote {
  background-color: rgba(0, 0, 0, 0.05);
  border-left: 3px solid var(--c-primary);
  padding: 6px 8px;
  border-radius: var(--r-xs);
  font-size: 0.8rem;
  margin-bottom: var(--s2);
}

.chat-quote-sender {
  font-weight: 700;
  font-size: 0.75rem;
  color: var(--text-primary);
}

.chat-quote-body {
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Revoked messages */
.chat-revoked {
  font-style: italic;
  color: var(--text-muted);
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  gap: var(--s1);
}

/* Media styling inside chat */
.chat-media-inline {
  margin-top: var(--s1);
  border-radius: var(--r-sm);
  overflow: hidden;
  max-width: 100%;
}

.chat-img-link {
  display: block;
}

.chat-img {
  max-width: 100%;
  max-height: 240px;
  object-fit: contain;
  display: block;
}

.chat-video {
  max-width: 100%;
  max-height: 240px;
  display: block;
}

.chat-audio {
  max-width: 100%;
  height: 36px;
  display: block;
}

.chat-media {
  display: flex;
  align-items: center;
  gap: var(--s3);
  padding: var(--s2) var(--s3);
  background-color: rgba(0,0,0,0.03);
  border-radius: var(--r-sm);
  font-size: 0.85rem;
  border: 1px solid var(--border);
}

/* ── Chat Action Controls (reactions, reply popups) ── */
.chat-actions-popup {
  display: flex;
  gap: var(--s2);
  padding: var(--s2);
  background-color: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-md);
  margin-top: var(--s2);
  align-self: flex-end;
}

.chat-actions-popup button {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-secondary);
  padding: 4px;
  font-size: 0.8rem;
  transition: var(--transition);
}
.chat-actions-popup button:hover {
  color: var(--text-primary);
  background: var(--bg-elevated);
  border-radius: 50%;
}

/* Reply input box wrapper */
.chat-reply-wrap {
  background-color: var(--bg-elevated);
  border-top: 1px solid var(--border);
  padding: var(--s3) var(--s5);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.chat-reply-body {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.chat-reply-close {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ── Chat Input Area ── */
.chat-input-area {
  padding: var(--s4) var(--s5);
  background-color: var(--bg-surface);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: var(--s3);
}

.chat-input-wrap {
  flex: 1;
}

/* Avatar helper */
.conv-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--c-primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.95rem;
  font-weight: 700;
  position: relative;
  flex-shrink: 0;
  overflow: hidden;
}

.conv-avatar-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.conv-avatar-loading {
  position: absolute;
  inset: 0;
  background-color: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ==========================================================
   CONSOLE EVENT LOG
   ========================================================== */
.console-logs {
  background-color: #0f0f11;
  color: #a8c7fa;
  font-family: var(--font-mono);
  padding: var(--s5);
  border-radius: var(--r-md);
  border: 1px solid #303134;
  height: 460px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: var(--s2);
  font-size: 0.85rem;
}

.log-row {
  display: flex;
  align-items: flex-start;
  gap: var(--s3);
  padding: 4px 0;
  border-bottom: 1px solid #202124;
}

.log-time {
  color: var(--text-muted);
  flex-shrink: 0;
}

.log-badge {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  padding: 2px 6px;
  border-radius: var(--r-xs);
  flex-shrink: 0;
}

.log-badge.event { background-color: #3b3005; color: #fdd663; }
.log-badge.error { background-color: #3c1e1e; color: #f2b8b5; }
.log-badge.info  { background-color: #1e2b3c; color: #7fcfff; }

.log-msg {
  word-break: break-all;
  flex: 1;
  color: #e3e3e3;
}

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

.modal-content {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg); /* Rounded (MD3 dialog) */
  box-shadow: var(--shadow-md);
  width: 90%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  animation: modal-enter 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes modal-enter {
  from { transform: scale(0.95); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

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

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

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

.modal-body {
  padding: var(--s5) var(--s6);
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  padding: var(--s4) var(--s6);
  border-top: 1px solid var(--border);
  background-color: var(--bg-table-th);
  display: flex;
  justify-content: flex-end;
  gap: var(--s3);
}

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

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

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

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

.contact-name {
  font-size: 0.9rem;
  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.72rem;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ==========================================================
   REAL-TIME LOCATION MAP (Leaflet Integration)
   ========================================================== */
.location-map-wrap {
  position: relative;
  width: 100%;
  height: 60vh;
  min-height: 420px;
  border-radius: var(--r-lg);
  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 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: var(--shadow-sm);
  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: var(--shadow-sm);
}

/* ==========================================================
   SEGMENTED TABS + FILE PICKER (MD3 Refined)
   ========================================================== */
.seg-tabs {
  display: flex;
  gap: var(--s1);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--r-xl); /* Rounded Pill (MD3) */
  padding: 4px;
}

.seg-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--s2);
  padding: 8px 16px;
  font-size: 0.85rem;
  font-weight: 600;
  border: none;
  border-radius: var(--r-xl); /* Rounded Pill */
  background: none;
  color: var(--text-secondary);
  cursor: pointer;
  transition: var(--transition);
}

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

[data-theme="dark"] .seg-btn:hover {
  background-color: rgba(255, 255, 255, 0.05);
}

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

/* File Drop Input */
.file-drop {
  border: 2px dashed var(--border);
  border-radius: var(--r-lg);
  background: var(--bg-input);
  cursor: pointer;
  transition: var(--transition);
  min-height: 110px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--s4);
}

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

.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.8rem;
  color: var(--c-primary);
}

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

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

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

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

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

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

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

/* Checkbox Row */
.checkbox-row {
  display: flex;
  align-items: center;
  gap: var(--s2);
  font-size: 0.85rem;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 4px 0;
  user-select: none;
}

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

/* Form Grid */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--s4);
}

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

/* TTS Preview Audio */
.tts-preview-audio {
  width: 100%;
  height: 40px;
  border-radius: var(--r-md);
  margin-top: var(--s2);
}

.voice-script {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: var(--s3) var(--s4);
  font-family: var(--font-mono);
  font-size: 0.82rem;
  color: var(--text-primary);
  white-space: pre-wrap;
  word-break: break-all;
}

/* Error Messages */
.error-msg {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--c-danger-light);
  border: 1px solid var(--c-danger);
  border-radius: var(--r-sm);
  padding: 10px 14px;
  font-size: 0.85rem;
  color: var(--c-danger);
}

