:root {
  --bg-primary: #0a0d14;
  --bg-secondary: #10141f;
  --bg-tertiary: #161c2b;
  --card-bg: rgba(22, 28, 43, 0.7);
  --border-color: rgba(255, 255, 255, 0.08);
  --border-glow: rgba(0, 204, 136, 0.3);
  --text-main: #f0f4f8;
  --text-muted: #8b9bb4;
  --accent-primary: #00e599;
  --accent-secondary: #00b4d8;
  --accent-gradient: linear-gradient(135deg, #00e599 0%, #00b4d8 100%);
  --danger: #ff4d6d;
  --warning: #ffb703;
  --font-sans: 'Plus Jakarta Sans', system-ui, -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --shadow-sm: 0 4px 12px rgba(0, 0, 0, 0.25);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.45);
}

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

body.dark-theme {
  background-color: var(--bg-primary);
  color: var(--text-main);
  font-family: var(--font-sans);
  min-height: 100vh;
  overflow: hidden;
}

.app-layout {
  display: flex;
  height: 100vh;
  width: 100vw;
}

/* Sidebar */
.sidebar {
  width: 260px;
  background-color: var(--bg-secondary);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.sidebar-brand {
  padding: 24px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--border-color);
}

.brand-icon {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-sm);
  background: var(--accent-gradient);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #000;
}

.brand-text h2 {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.brand-text span {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.sidebar-menu {
  padding: 20px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
  overflow-y: auto;
}

.nav-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 13.5px;
  font-weight: 500;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  transition: all 0.2s ease;
  width: 100%;
  text-align: left;
}

.nav-btn:hover {
  background-color: rgba(255, 255, 255, 0.04);
  color: var(--text-main);
}

.nav-btn.active {
  background-color: rgba(0, 229, 153, 0.12);
  color: var(--accent-primary);
  font-weight: 600;
}

.badge {
  margin-left: auto;
  background-color: var(--bg-tertiary);
  color: var(--text-main);
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
}

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

.model-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  background-color: var(--bg-tertiary);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  color: var(--text-muted);
}

.model-badge .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: var(--accent-primary);
  box-shadow: 0 0 8px var(--accent-primary);
}

/* Main Content Wrapper */
.main-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  background-color: var(--bg-primary);
  overflow: hidden;
}

/* Topbar */
.topbar {
  height: 68px;
  border-bottom: 1px solid var(--border-color);
  background-color: rgba(16, 20, 31, 0.8);
  backdrop-filter: blur(12px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 32px;
}

.topbar-left h1 {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.status-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  border: 1px solid transparent;
}

.status-connected {
  background-color: rgba(0, 229, 153, 0.12);
  color: var(--accent-primary);
  border-color: rgba(0, 229, 153, 0.3);
}

.status-disconnected {
  background-color: rgba(255, 183, 3, 0.12);
  color: var(--warning);
  border-color: rgba(255, 183, 3, 0.3);
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background-color: currentColor;
}

.toggle-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  background-color: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 12.5px;
  cursor: pointer;
}

.state-active {
  color: var(--accent-primary);
  font-weight: 700;
}

.state-paused {
  color: var(--danger);
  font-weight: 700;
}

/* Content Container */
.content-container {
  flex: 1;
  padding: 24px 32px;
  overflow-y: auto;
}

.tab-view {
  display: none;
  height: 100%;
}

.tab-view.active {
  display: block;
}

/* Cards & Grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 20px;
  margin-bottom: 24px;
}

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

.stat-icon {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
}

.icon-blue { background: rgba(0, 180, 216, 0.15); color: #00b4d8; }
.icon-green { background: rgba(0, 229, 153, 0.15); color: #00e599; }
.icon-amber { background: rgba(255, 183, 3, 0.15); color: #ffb703; }
.icon-red { background: rgba(255, 77, 109, 0.15); color: #ff4d6d; }

.stat-info .stat-title {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
  display: block;
  margin-bottom: 4px;
}

.stat-info h3 {
  font-size: 22px;
  font-weight: 700;
}

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

.hero-banner {
  background: linear-gradient(135deg, rgba(0, 229, 153, 0.08) 0%, rgba(0, 180, 216, 0.04) 100%);
  border-color: rgba(0, 229, 153, 0.2);
}

.hero-content h3 {
  font-size: 18px;
  margin-bottom: 6px;
}

.hero-content p {
  color: var(--text-muted);
  font-size: 13.5px;
  margin-bottom: 16px;
}

/* Status Pills */
.pill-stage {
  font-size: 10px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 4px;
  background-color: rgba(0, 180, 216, 0.15);
  color: #00b4d8;
  text-transform: uppercase;
  display: inline-block;
}

.pill-ai {
  font-size: 10px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 4px;
  background-color: rgba(0, 229, 153, 0.15);
  color: var(--accent-primary);
  display: inline-block;
}

.pill-human {
  font-size: 10px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 4px;
  background-color: rgba(255, 77, 109, 0.15);
  color: var(--danger);
  display: inline-block;
}

/* Buttons */
.btn {
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all 0.2s;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.btn-primary {
  background: var(--accent-gradient);
  color: #000;
}

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

.btn-warning {
  background-color: rgba(255, 183, 3, 0.15);
  color: var(--warning);
  border: 1px solid rgba(255, 183, 3, 0.4);
}

.btn-success {
  background-color: rgba(0, 229, 153, 0.15);
  color: var(--accent-primary);
  border: 1px solid rgba(0, 229, 153, 0.4);
}

/* Kanban Board */
.pipeline-board {
  display: flex;
  gap: 16px;
  overflow-x: auto;
  height: calc(100vh - 130px);
  padding-bottom: 12px;
}

.pipeline-col {
  width: 270px;
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.pipeline-header {
  padding: 14px 16px;
  font-size: 13px;
  font-weight: 700;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
}

.pipeline-cards {
  padding: 12px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.lead-card {
  background-color: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.lead-name {
  font-size: 13px;
  font-weight: 600;
}

.lead-sub {
  font-size: 11.5px;
  color: var(--text-muted);
}

/* Data Table */
.table-card {
  padding: 0;
  overflow: hidden;
}

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

.data-table th, .data-table td {
  padding: 14px 18px;
  text-align: left;
  border-bottom: 1px solid var(--border-color);
}

.data-table th {
  background-color: var(--bg-tertiary);
  font-weight: 600;
  color: var(--text-muted);
  font-size: 12px;
  text-transform: uppercase;
}

/* Knowledge & Editors */
.knowledge-layout {
  display: flex;
  gap: 20px;
  height: calc(100vh - 130px);
}

.knowledge-sidebar {
  width: 260px;
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  overflow-y: auto;
}

.doc-item {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border-color);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
}

.doc-item.active {
  background-color: rgba(0, 229, 153, 0.1);
  color: var(--accent-primary);
  font-weight: 600;
}

.knowledge-editor-card {
  flex: 1;
  display: flex;
  flex-direction: column;
}

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

textarea {
  width: 100%;
  flex: 1;
  background-color: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 16px;
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.6;
  outline: none;
  resize: none;
}

/* Form Controls */
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 20px;
  margin-top: 16px;
}

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

.form-group label {
  font-size: 13px;
  font-weight: 600;
}

.form-group select, .form-group input {
  background-color: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  outline: none;
}

.form-group small {
  font-size: 11px;
  color: var(--text-muted);
}

.card-footer {
  margin-top: 24px;
  display: flex;
  justify-content: flex-end;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background-color: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999;
}

.modal-card {
  width: 440px;
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-lg);
}

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

.close-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 20px;
  cursor: pointer;
}

.modal-body {
  padding: 28px 24px;
}

#qr-image {
  width: 250px;
  height: 250px;
  border-radius: var(--radius-md);
  background: #fff;
  padding: 8px;
  margin: 0 auto 16px;
}

.qr-instructions {
  text-align: left;
  background-color: var(--bg-tertiary);
  padding: 14px 18px;
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  color: var(--text-muted);
}

.qr-instructions ol {
  padding-left: 18px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid rgba(255, 255, 255, 0.1);
  border-top-color: var(--accent-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 20px auto;
}

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

.success-icon {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--accent-gradient);
  color: #000;
  font-size: 28px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 10px auto 16px;
}

.hidden {
  display: none !important;
}

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

/* --- MULTI-TENANT & PROVIDER EXTENSIONS --- */

.tenant-selector-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  padding: 4px 10px;
  border-radius: var(--radius-md);
}

.tenant-select {
  background: transparent;
  border: none;
  color: var(--text-main);
  font-weight: 700;
  font-size: 14px;
  outline: none;
  cursor: pointer;
  padding: 4px 0;
}

.tenant-select option {
  background: var(--bg-secondary);
  color: var(--text-main);
}

.btn-sm {
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 600;
  border-radius: var(--radius-sm);
  cursor: pointer;
}

/* Provider Cards Grid */
.providers-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 20px;
  margin-top: 16px;
}

.provider-card {
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  position: relative;
  transition: all 0.2s ease;
}

.provider-card:hover {
  border-color: rgba(0, 229, 153, 0.4);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
}

.provider-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.provider-title h4 {
  font-size: 17px;
  font-weight: 700;
  color: var(--text-main);
}

.provider-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 20px;
}

.provider-connected {
  background: rgba(0, 229, 153, 0.15);
  color: var(--accent-primary);
  border: 1px solid rgba(0, 229, 153, 0.3);
}

.provider-disconnected {
  background: rgba(255, 77, 109, 0.15);
  color: var(--danger);
  border: 1px solid rgba(255, 77, 109, 0.3);
}

.provider-body {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.masked-key-display {
  font-family: var(--font-mono);
  background: rgba(0, 0, 0, 0.3);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--text-muted);
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.provider-actions {
  display: flex;
  gap: 8px;
  margin-top: auto;
}

/* Speed Preset Buttons */
.speed-preset-group {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-top: 8px;
}

.preset-btn {
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  padding: 12px 14px;
  border-radius: var(--radius-md);
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  text-align: center;
  transition: all 0.2s ease;
}

.preset-btn:hover {
  border-color: rgba(255, 255, 255, 0.2);
  color: var(--text-main);
}

.preset-btn.active {
  background: rgba(0, 229, 153, 0.12);
  border-color: var(--accent-primary);
  color: var(--accent-primary);
}

/* Playground / Chat Preview */
.playground-box {
  display: flex;
  flex-direction: column;
  height: 480px;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  overflow: hidden;
}

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

.playground-input-row {
  display: flex;
  gap: 10px;
  padding: 12px;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border-color);
}

.playground-input {
  flex: 1;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  color: var(--text-main);
  outline: none;
}

/* Analytics Cards */
.analytics-metric-card {
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.analytics-metric-val {
  font-size: 26px;
  font-weight: 800;
  color: var(--text-main);
}

.analytics-metric-sub {
  font-size: 12px;
  color: var(--text-muted);
}

/* =========================================================================
   WHATSAPP WEB CHAT STYLING (COMMERCIAL-GRADE)
   ========================================================================= */
.chat-container {
  display: flex;
  height: calc(100vh - 120px);
  min-height: 580px;
  background-color: #0b141a;
  border: 1px solid rgba(134, 150, 160, 0.15);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.45);
}

.chat-sidebar {
  width: 380px;
  min-width: 320px;
  max-width: 440px;
  background-color: #111b21;
  border-right: 1px solid rgba(134, 150, 160, 0.15);
  display: flex;
  flex-direction: column;
}

.chat-sidebar-header {
  padding: 10px 14px 8px;
  background-color: #202c33;
  border-bottom: 1px solid rgba(134, 150, 160, 0.12);
}

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

.chat-brand-tag {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 15px;
  color: #e9edef;
}

.icon-refresh-btn {
  background: transparent;
  border: none;
  color: #8696a0;
  cursor: pointer;
  padding: 6px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.icon-refresh-btn:hover {
  background-color: rgba(255, 255, 255, 0.1);
  color: #e9edef;
  transform: rotate(180deg);
}

.chat-search {
  background-color: #111b21;
  border-radius: 8px;
  padding: 6px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px solid rgba(134, 150, 160, 0.12);
  margin-bottom: 8px;
}

.chat-search input {
  background: transparent;
  border: none;
  color: #d1d7db;
  font-size: 13.5px;
  width: 100%;
  outline: none;
}

.chat-search input::placeholder {
  color: #8696a0;
}

.chat-filter-chips {
  display: flex;
  align-items: center;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 2px;
}

.chat-filter-chips::-webkit-scrollbar {
  display: none;
}

.filter-chip {
  background: #202c33;
  border: 1px solid rgba(134, 150, 160, 0.2);
  border-radius: 16px;
  color: #8696a0;
  font-size: 12px;
  font-weight: 500;
  padding: 4px 12px;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s ease;
}

.filter-chip:hover {
  background: #2a3942;
  color: #e9edef;
}

.filter-chip.active {
  background: #0a332c;
  color: #00a884;
  border-color: #00a884;
  font-weight: 600;
}

/* Conversation List */
.conv-list {
  flex: 1;
  overflow-y: auto;
  background-color: #111b21;
}

.conv-item {
  display: flex !important;
  flex-direction: row !important;
  align-items: center !important;
  gap: 14px;
  padding: 10px 16px;
  border-bottom: 1px solid rgba(134, 150, 160, 0.1);
  border-left: none !important;
  cursor: pointer;
  transition: background-color 0.15s ease;
  position: relative;
  background-color: transparent;
}

.conv-item:hover {
  background-color: #202c33 !important;
}

.conv-item.active {
  background-color: #2a3942 !important;
  border-left: none !important;
}

.conv-avatar-wrapper {
  position: relative;
  width: 48px;
  height: 48px;
  flex-shrink: 0;
}

.conv-avatar-img {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  display: block;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

.contact-header-avatar-img {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  display: block;
}

.conv-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: #6b7b8a;
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 18px;
  flex-shrink: 0;
}

.conv-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 3px;
}

.conv-row-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.conv-name {
  font-weight: 500;
  font-size: 15.5px;
  color: #e9edef;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conv-time {
  font-size: 11.5px;
  color: #8696a0;
  flex-shrink: 0;
  margin-left: 6px;
}

.conv-row-phone {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.conv-phone {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  font-weight: 600;
  color: #00a884;
}

.conv-phone.is-lid {
  color: #38bdf8;
  font-size: 11px;
}

.conv-stage-badge {
  font-size: 10px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.stage-new {
  background: rgba(56, 189, 248, 0.15);
  color: #38bdf8;
}

.stage-qualified {
  background: rgba(16, 185, 129, 0.15);
  color: #10b981;
}

.stage-negotiating {
  background: rgba(245, 158, 11, 0.15);
  color: #f59e0b;
}

.stage-closed_won {
  background: rgba(34, 197, 94, 0.2);
  color: #22c55e;
}

.stage-closed_lost {
  background: rgba(239, 68, 68, 0.15);
  color: #ef4444;
}

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

.conv-preview-wrap {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
  flex: 1;
}

.conv-check-tick {
  color: #53bdeb;
  font-size: 12px;
  font-weight: bold;
  flex-shrink: 0;
}

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

.conv-item.active .conv-name {
  color: #ffffff;
}

.conv-item.active .conv-preview {
  color: #d1d7db;
}

/* Chat Main Area */
.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  background-color: #0b141a;
  position: relative;
  min-width: 0;
}

.chat-empty-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #8696a0;
  padding: 40px;
  text-align: center;
}

.wa-web-splash {
  display: flex;
  flex-direction: column;
  align-items: center;
  max-width: 420px;
}

.wa-splash-icon {
  width: 90px;
  height: 90px;
  border-radius: 50%;
  background: rgba(0, 168, 132, 0.1);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 20px;
}

.wa-web-splash h3 {
  color: #e9edef;
  font-size: 18px;
  margin-bottom: 8px;
}

.wa-web-splash p {
  font-size: 13.5px;
  line-height: 1.5;
  color: #8696a0;
}

.chat-active-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
}

.chat-header {
  height: 60px;
  padding: 10px 16px;
  background-color: #202c33;
  border-bottom: 1px solid rgba(134, 150, 160, 0.15);
  display: flex;
  justify-content: space-between;
  align-items: center;
  z-index: 2;
  box-sizing: border-box;
}

.chat-header-user {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.contact-avatar-circle {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: #6b7b8a;
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 16px;
  overflow: hidden;
  flex-shrink: 0;
}

.contact-avatar-circle img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.chat-contact-info h4 {
  margin: 0;
  font-size: 15.5px;
  font-weight: 500;
  color: #e9edef;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-contact-subline {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 1px;
}

.phone-tag {
  font-size: 12px;
  color: #8696a0;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.contact-phone-val {
  color: #00a884;
  font-weight: 600;
  font-size: 12.5px;
}

.contact-phone-val.is-lid {
  color: #38bdf8;
}

.badge-lid {
  background: rgba(56, 189, 248, 0.12);
  color: #38bdf8;
  border: 1px solid rgba(56, 189, 248, 0.25);
  border-radius: 4px;
  padding: 2px 7px;
  font-size: 11px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.badge-lid-sm {
  background: rgba(56, 189, 248, 0.1);
  color: #38bdf8;
  border: 1px solid rgba(56, 189, 248, 0.2);
  border-radius: 4px;
  padding: 1px 6px;
  font-size: 10.5px;
  font-weight: 600;
  display: inline-block;
}

.btn-add-phone-tag {
  background: transparent;
  color: #00a884;
  border: 1px dashed rgba(0, 168, 132, 0.5);
  border-radius: 4px;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-add-phone-tag:hover {
  background: rgba(0, 168, 132, 0.12);
  border-color: #00a884;
}

.btn-icon-edit-phone {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 12px;
  opacity: 0.7;
  padding: 0 4px;
  transition: opacity 0.2s, transform 0.2s;
  vertical-align: middle;
}

.btn-icon-edit-phone:hover {
  opacity: 1;
  transform: scale(1.15);
}

.btn-table-action {
  background: rgba(0, 168, 132, 0.1);
  color: #00a884;
  border: 1px solid rgba(0, 168, 132, 0.3);
  border-radius: 4px;
  padding: 2px 6px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-table-action:hover {
  background: rgba(0, 168, 132, 0.2);
}

.online-indicator {
  font-size: 11px;
  color: #8696a0;
}

.chat-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.chat-messages {
  flex: 1;
  padding: 20px 24px;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background-color: #0b141a;
  background-image: radial-gradient(rgba(255, 255, 255, 0.035) 1px, transparent 1px);
  background-size: 24px 24px;
}

.bubble {
  max-width: 65%;
  min-width: 90px;
  padding: 7px 12px 6px;
  border-radius: 8px;
  font-size: 14px;
  line-height: 1.45;
  position: relative;
  word-break: break-word;
  overflow-wrap: anywhere;
  box-sizing: border-box;
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.25);
}

.bubble-user {
  align-self: flex-start;
  background-color: #202c33;
  color: #e9edef;
  border-top-left-radius: 0;
}

.bubble-agent {
  align-self: flex-end;
  background-color: #005c4b;
  color: #e9edef;
  border-top-right-radius: 0;
}

.bubble-human {
  align-self: flex-end;
  background-color: #025144;
  color: #e9edef;
  border-top-right-radius: 0;
}

.bubble-sender {
  font-size: 10px;
  font-weight: 700;
  margin-bottom: 3px;
  opacity: 0.85;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.bubble-meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  margin-top: 3px;
  font-size: 10.5px;
  color: rgba(255, 255, 255, 0.6);
}

.double-tick {
  color: #53bdeb;
  font-size: 12px;
  font-weight: bold;
}

/* Chat Input Bar */
.chat-input-bar {
  min-height: 62px;
  padding: 10px 16px;
  background-color: #202c33;
  border-top: 1px solid rgba(134, 150, 160, 0.12);
  display: flex;
  gap: 8px;
  align-items: center;
  box-sizing: border-box;
}

.chat-tool-btn {
  background: transparent;
  border: none;
  color: #8696a0;
  cursor: pointer;
  padding: 6px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
}

.chat-tool-btn:hover {
  color: #d1d7db;
  background-color: rgba(255, 255, 255, 0.08);
}

.chat-input-bar input {
  flex: 1;
  background-color: #2a3942;
  border: none;
  color: #e9edef;
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 14px;
  outline: none;
  transition: background 0.2s;
}

.chat-input-bar input::placeholder {
  color: #8696a0;
}

.chat-input-bar input:focus {
  background-color: #32444f;
}

.chat-send-btn {
  background-color: #00a884;
  border: none;
  color: #ffffff;
  cursor: pointer;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease, transform 0.1s ease;
  flex-shrink: 0;
}

.chat-send-btn:hover {
  background-color: #029474;
  transform: scale(1.05);
}

/* =========================================================================
   IOS / SAAS SWITCH & TYPING TOGGLE CARD
   ========================================================================= */
.typing-toggle-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(0, 229, 153, 0.05);
  border: 1px solid rgba(0, 229, 153, 0.25);
  border-radius: 12px;
  padding: 16px 20px;
  margin-bottom: 20px;
  gap: 16px;
}

.toggle-card-left {
  display: flex;
  align-items: center;
  gap: 16px;
  flex: 1;
}

.toggle-icon-wrap {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  background: rgba(0, 229, 153, 0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.toggle-card-text {
  flex: 1;
}

.toggle-card-title {
  display: flex;
  align-items: center;
  gap: 10px;
}

.toggle-card-title h4 {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  color: #ffffff;
}

.badge-active {
  background: rgba(0, 229, 153, 0.2);
  color: #00e599;
  border: 1px solid rgba(0, 229, 153, 0.4);
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.5px;
}

.badge-inactive {
  background: rgba(255, 255, 255, 0.08);
  color: #8696a0;
  border: 1px solid rgba(255, 255, 255, 0.15);
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.5px;
}

.toggle-card-desc {
  margin: 4px 0 0;
  font-size: 12.5px;
  color: var(--text-muted);
  line-height: 1.4;
}

.toggle-card-right {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-shrink: 0;
}

/* Switch iOS style */
.switch-ios {
  position: relative;
  display: inline-block;
  width: 52px;
  height: 28px;
}

.switch-ios input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider-ios {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #374151;
  transition: .25s ease;
  border-radius: 34px;
  border: 1px solid rgba(255, 255, 255, 0.15);
}

.slider-ios:before {
  position: absolute;
  content: "";
  height: 20px;
  width: 20px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: .25s ease;
  border-radius: 50%;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.switch-ios input:checked + .slider-ios {
  background-color: #00e599;
  border-color: #00e599;
}

.switch-ios input:checked + .slider-ios:before {
  transform: translateX(24px);
}

/* Floating Toast Notifications */
#toast-container {
  position: fixed;
  top: 24px;
  right: 24px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  background-color: #1e293b;
  color: #f8fafc;
  padding: 12px 18px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
  font-size: 13.5px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 10px;
  animation: slideInRight 0.25s ease forwards;
}

.toast.toast-success {
  border-left: 4px solid #00e599;
}

.toast.toast-error {
  border-left: 4px solid #ff4d6d;
}

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

/* Multi-Tenant Management Styles */
.tenants-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 20px;
  margin-top: 20px;
}

.tenant-card {
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 22px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 16px;
  position: relative;
  transition: all 0.25s ease;
  backdrop-filter: blur(12px);
}

.tenant-card:hover {
  transform: translateY(-2px);
  border-color: rgba(255, 255, 255, 0.18);
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.4);
}

.tenant-card.active-tenant {
  border-color: var(--accent-primary);
  box-shadow: 0 0 20px rgba(0, 229, 153, 0.15);
}

.tenant-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
}

.tenant-card-title {
  font-size: 17px;
  font-weight: 700;
  color: var(--text-main);
}

.tenant-card-slug {
  font-size: 11px;
  font-family: var(--font-mono);
  color: var(--text-muted);
  margin-top: 2px;
}

.tenant-card-details {
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: rgba(0, 0, 0, 0.2);
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(255, 255, 255, 0.04);
}

.tenant-detail-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12.5px;
}

.tenant-detail-label {
  color: var(--text-muted);
}

.tenant-detail-val {
  font-weight: 600;
  color: var(--text-main);
}

.tenant-card-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 4px;
}

/* Guided activation, scoped to the dashboard so the existing workspace stays intact. */
.setup-panel { background: var(--surface, #172129); border: 1px solid rgba(255,255,255,.10); border-radius: 18px; padding: 24px; margin-bottom: 24px; }
.setup-heading { display: flex; justify-content: space-between; gap: 18px; align-items: flex-start; margin-bottom: 18px; }
.setup-heading h2 { margin: 5px 0 7px; font-size: 22px; }
.setup-heading p, .setup-live-note { color: var(--text-muted, #a8b3bd); margin: 0; line-height: 1.45; }
.setup-eyebrow { font-size: 11px; font-weight: 800; letter-spacing: .14em; color: var(--accent-primary, #00e599); }
.setup-progress { flex-shrink: 0; border-radius: 100px; padding: 7px 12px; background: rgba(0,229,153,.11); color: var(--accent-primary, #00e599); font-size: 12px; font-weight: 700; }
.setup-steps { display: grid; grid-template-columns: repeat(auto-fit, minmax(215px, 1fr)); gap: 10px; }
.setup-step { display: flex; align-items: flex-start; gap: 11px; min-height: 82px; padding: 13px; color: inherit; text-align: left; background: rgba(255,255,255,.035); border: 1px solid rgba(255,255,255,.09); border-radius: 12px; cursor: pointer; }
.setup-step:hover, .setup-step:focus-visible { border-color: var(--accent-primary, #00e599); outline: none; }
.setup-check { display: grid; place-items: center; width: 22px; height: 22px; flex: 0 0 22px; border-radius: 50%; color: #aab5bd; border: 1px solid #66747e; }
.setup-step.is-done .setup-check { color: #071c17; background: var(--accent-primary, #00e599); border-color: transparent; }
.setup-copy { display: grid; gap: 5px; min-width: 0; }
.setup-copy strong { font-size: 13px; }
.setup-copy small { color: var(--text-muted, #a8b3bd); line-height: 1.35; }
.setup-arrow { margin-left: auto; color: var(--text-muted, #a8b3bd); }
.setup-live-note { font-size: 12px; margin-top: 15px; }
@media (max-width: 650px) { .setup-panel { padding: 18px; } .setup-heading { flex-direction: column; } .setup-steps { grid-template-columns: 1fr; } }

/* Automazy identity and operator workspace */
:root {
  --bg-primary: #0d1211;
  --bg-secondary: #101715;
  --bg-tertiary: #1b2521;
  --card-bg: #17201c;
  --border-color: rgba(222, 247, 225, .10);
  --border-glow: rgba(196, 247, 91, .25);
  --text-main: #f1f6ef;
  --text-muted: #9baaa0;
  --accent-primary: #c7f46e;
  --accent-secondary: #96dac1;
  --accent-gradient: linear-gradient(135deg, #d7f88d, #9cd956);
  --radius-sm: 10px;
  --radius-md: 16px;
  --radius-lg: 22px;
}
body.dark-theme { background: radial-gradient(circle at 100% 0%, #1a2a1e 0, #0d1211 34%); }
.sidebar { width: 252px; background: #101715; }
.sidebar-brand { padding: 26px 22px 24px; gap: 13px; }
.brand-icon { width: 43px; height: 43px; border-radius: 13px; font-size: 30px; font-weight: 800; letter-spacing: -.14em; line-height: 1; }
.brand-icon-dot { color: #47632d; }
.brand-text h2 { font-size: 21px; font-weight: 800; letter-spacing: -.065em; line-height: 1.1; }
.brand-period { color: var(--accent-primary); }
.brand-text span { font-size: 10px; letter-spacing: .08em; font-weight: 800; }
.sidebar-menu { padding: 22px 12px; gap: 4px; }
.nav-btn { min-height: 41px; border-radius: 10px; font-size: 12.5px; }
.nav-btn.active { background: rgba(199, 244, 110, .12); box-shadow: inset 2px 0 var(--accent-primary); }
.topbar { background: rgba(16, 23, 21, .84); backdrop-filter: blur(16px); }
.content-container { padding: 34px 38px 50px; }
.dashboard-intro { display: flex; justify-content: space-between; align-items: flex-end; gap: 20px; margin-bottom: 27px; }
#view-dashboard.tab-view.active { display: flex; flex-direction: column; height: auto; }
#view-dashboard .dashboard-intro { order: 0; }
#view-dashboard .stats-grid { order: 1; }
#view-dashboard .dashboard-columns { order: 2; }
#view-dashboard .setup-panel { order: 3; }
#view-dashboard .legacy-hero { order: 4; }
.eyebrow { display: inline-flex; align-items: center; gap: 8px; color: var(--accent-primary); font-size: 10px; font-weight: 800; letter-spacing: .16em; }
.eyebrow-line { width: 16px; height: 1px; background: currentColor; }
.dashboard-intro h2 { font-size: clamp(25px, 3vw, 37px); letter-spacing: -.055em; margin: 9px 0 6px; }
.dashboard-intro h2 span { color: var(--accent-primary); }
.dashboard-intro p { color: var(--text-muted); font-size: 13px; }
.dashboard-intro .btn { white-space: nowrap; }
.stat-card { background: var(--card-bg); border: 1px solid var(--border-color); border-radius: 18px; min-height: 118px; box-shadow: none; }
.stat-value { letter-spacing: -.07em; }
.dashboard-columns { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(280px, .75fr); gap: 18px; margin: 22px 0 24px; }
.attention-panel, .operation-panel { min-height: 260px; border-radius: 20px; padding: 25px; border: 1px solid var(--border-color); background: var(--card-bg); }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 14px; margin-bottom: 18px; }
.panel-head h3, .operation-panel h3 { font-size: 19px; letter-spacing: -.04em; margin-top: 9px; }
.attention-count { display: inline-block; vertical-align: middle; font-size: 11px; border-radius: 7px; padding: 4px 8px; margin-left: 6px; background: rgba(199,244,110,.14); color: var(--accent-primary); letter-spacing: 0; }
.text-action { background: none; border: 0; color: var(--accent-primary); cursor: pointer; font: inherit; font-size: 12px; white-space: nowrap; }
.attention-list { max-height: 266px; overflow-y: auto; }
.attention-item { display: flex; width: 100%; align-items: center; gap: 12px; border: 0; border-top: 1px solid var(--border-color); background: transparent; color: var(--text-main); text-align: left; padding: 13px 3px; cursor: pointer; font: inherit; }
.attention-item:hover, .attention-item:focus-visible { background: rgba(199,244,110,.055); outline: 1px solid rgba(199,244,110,.25); }
.attention-avatar { display: grid; place-items: center; flex: 0 0 37px; height: 37px; background: #314435; border-radius: 11px; color: var(--accent-primary); font-size: 14px; font-weight: 800; }
.attention-detail { display: grid; gap: 4px; min-width: 0; flex: 1; }
.attention-detail strong { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attention-detail small { color: var(--text-muted); font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attention-time { white-space: nowrap; color: var(--accent-primary); font-size: 11px; }
.attention-empty { text-align: center; color: var(--text-muted); padding: 26px 8px; font-size: 12px; }
.attention-empty strong { display: block; color: var(--text-main); font-size: 14px; margin: 9px 0 5px; }
.attention-empty p { line-height: 1.5; }
.empty-check { display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 50%; background: rgba(199,244,110,.15); color: var(--accent-primary); }
.operation-panel { position: relative; overflow: hidden; background: linear-gradient(150deg, #263a29, #18251d 65%, #142019); }
.operation-panel h3 { font-size: 23px; margin: 18px 0 8px; position: relative; z-index: 1; }
.operation-panel p { max-width: 260px; min-height: 42px; color: #bfcec1; line-height: 1.55; font-size: 12px; position: relative; z-index: 1; }
.operation-actions { display: flex; flex-wrap: wrap; gap: 9px; margin-top: 20px; position: relative; z-index: 1; }
.operation-actions .btn { font-size: 11px; }
.operation-watermark { position: absolute; right: -10px; bottom: -70px; font-size: 220px; font-weight: 800; line-height: 1; letter-spacing: -.2em; color: rgba(199,244,110,.05); pointer-events: none; }
.legacy-hero { display: none; }
.setup-panel { background: #17201c; border-radius: 20px; }
.setup-step { background: #1d2821; }
.btn-primary { color: #152015; font-weight: 800; }
.btn-secondary { border-color: rgba(222,247,225,.16); }
@media (max-width: 1150px) { .dashboard-columns { grid-template-columns: 1fr; } }
