/**
 * WhatsApp Web Dark Design System & Layout Specification
 * High-fidelity styling matching official WhatsApp Web tokens and Number Audio branding.
 */

:root {
  --canvas: #111b21;
  --surface-1: #202c33;
  --surface-2: #2a3942;
  --surface-3: #182229;
  --surface-hover: #222e35;
  --surface-active: #2a3942;
  
  --wa-green: #00a884;
  --wa-green-hover: #06cf9c;
  --wa-green-light: #25d366;
  --wa-green-subtle: rgba(0, 168, 132, 0.15);
  
  --outgoing-bubble: #005c4b;
  --outgoing-bubble-hover: #026955;
  --incoming-bubble: #202c33;
  --incoming-bubble-hover: #26353d;
  
  --text-primary: #e9edef;
  --text-secondary: #8696a0;
  --text-muted: #667781;
  
  --border-hairline: rgba(134, 150, 160, 0.15);
  --border-active: rgba(0, 168, 132, 0.4);
  
  --ticks-blue: #53bdeb;
  --ticks-gray: #8696a0;
  
  --danger: #ef4444;
  --danger-subtle: rgba(239, 68, 68, 0.15);
  --warning: #f59e0b;
  --warning-subtle: rgba(245, 158, 11, 0.15);
  --info: #3b82f6;
  
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

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

body {
  font-family: var(--font-sans);
  background-color: var(--canvas);
  color: var(--text-primary);
  height: 100vh;
  width: 100vw;
  overflow: hidden;
  display: flex;
}

/* Custom Scrollbars */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: rgba(134, 150, 160, 0.25);
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
  background: rgba(134, 150, 160, 0.45);
}

/* ==========================================================================
   APP CONTAINER & 3-COLUMN STRUCTURE
   ========================================================================== */

#app-container {
  display: flex;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

/* Left Icon Rail */
#nav-rail {
  width: 68px;
  background-color: var(--surface-1);
  border-right: 1px solid var(--border-hairline);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px 0;
  gap: 16px;
  z-index: 20;
  flex-shrink: 0;
}

.brand-emblem {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: linear-gradient(135deg, #00a884, #005c4b);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: 800;
  font-size: 18px;
  letter-spacing: -0.5px;
  margin-bottom: 8px;
  box-shadow: 0 4px 12px rgba(0, 168, 132, 0.3);
}

.nav-item-btn {
  width: 48px;
  height: 48px;
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s ease;
  position: relative;
}

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

.nav-item-btn.active {
  background-color: var(--surface-2);
  color: var(--wa-green-light);
}

.nav-item-btn.active::before {
  content: '';
  position: absolute;
  left: -10px;
  width: 4px;
  height: 24px;
  border-radius: 0 4px 4px 0;
  background-color: var(--wa-green-light);
}

.nav-item-btn .nav-badge {
  position: absolute;
  top: 6px;
  right: 6px;
  background-color: var(--wa-green);
  color: #111b21;
  font-size: 10px;
  font-weight: 700;
  border-radius: 10px;
  padding: 1px 5px;
  min-width: 16px;
  text-align: center;
}

/* Secondary List Sidebar */
#sidebar-pane {
  width: 380px;
  background-color: var(--canvas);
  border-right: 1px solid var(--border-hairline);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow: hidden;
}

.sidebar-header {
  height: 60px;
  background-color: var(--surface-1);
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-hairline);
}

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

.sidebar-search-box {
  padding: 8px 12px;
  background-color: var(--canvas);
  border-bottom: 1px solid var(--border-hairline);
}

.search-input-wrapper {
  background-color: var(--surface-1);
  border-radius: 8px;
  padding: 6px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.search-input-wrapper input {
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-size: 13.5px;
  width: 100%;
}

.search-input-wrapper input::placeholder {
  color: var(--text-secondary);
}

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

/* Chat Item */
.chat-list-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid rgba(134, 150, 160, 0.08);
  cursor: pointer;
  transition: background-color 0.15s ease;
}

.chat-list-item:hover {
  background-color: var(--surface-hover);
}

.chat-list-item.active {
  background-color: var(--surface-active);
}

.chat-avatar {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background-color: var(--surface-2);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 16px;
  flex-shrink: 0;
}

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

.chat-top-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 4px;
}

.chat-name {
  font-size: 14.5px;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

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

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

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

.chat-unread-badge {
  background-color: var(--wa-green);
  color: #111b21;
  font-size: 11px;
  font-weight: 700;
  border-radius: 10px;
  padding: 1px 6px;
  min-width: 18px;
  text-align: center;
  flex-shrink: 0;
}

/* ==========================================================================
   MAIN WORKSPACE AREA
   ========================================================================== */

#main-workspace {
  flex: 1;
  display: flex;
  flex-direction: column;
  background-color: #0b141a;
  position: relative;
  overflow: hidden;
}

.view-pane {
  display: none;
  flex-direction: column;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

.view-pane.active {
  display: flex;
}

/* Chat Header */
.conversation-header {
  height: 60px;
  background-color: var(--surface-1);
  padding: 10px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-hairline);
  z-index: 10;
}

.conversation-contact {
  display: flex;
  align-items: center;
  gap: 12px;
}

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

.contact-details .contact-status {
  font-size: 12px;
  color: var(--wa-green-light);
}

/* Chat Feed */
.conversation-feed {
  flex: 1;
  padding: 18px 32px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background-color: #0b141a;
  background-image: radial-gradient(rgba(134, 150, 160, 0.08) 1px, transparent 0);
  background-size: 24px 24px;
}

.message-bubble {
  max-width: 65%;
  padding: 7px 12px 6px 12px;
  border-radius: 8px;
  position: relative;
  font-size: 13.5px;
  line-height: 19px;
  word-break: break-word;
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.2);
}

.message-bubble.incoming {
  align-self: flex-start;
  background-color: var(--incoming-bubble);
  border-top-left-radius: 0;
}

.message-bubble.outgoing {
  align-self: flex-end;
  background-color: var(--outgoing-bubble);
  border-top-right-radius: 0;
}

.message-reply-quote {
  background: rgba(0, 0, 0, 0.2);
  border-left: 3px solid var(--wa-green-light);
  padding: 5px 8px;
  border-radius: 4px;
  margin-bottom: 6px;
  font-size: 11.5px;
  color: var(--text-secondary);
}

.message-meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  margin-top: 2px;
  font-size: 11px;
  color: var(--text-secondary);
}

.message-bubble.outgoing .message-meta {
  color: rgba(233, 237, 239, 0.7);
}

.message-ticks {
  display: inline-flex;
}
.message-ticks.read {
  color: var(--ticks-blue);
}

/* Chat Input Bar */
.conversation-input-bar {
  background-color: var(--surface-1);
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-top: 1px solid var(--border-hairline);
  position: relative;
}

.input-action-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 8px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
}

.input-action-btn:hover {
  color: var(--text-primary);
  background-color: var(--surface-2);
}

.conversation-textarea {
  flex: 1;
  background-color: var(--surface-2);
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 9px 14px;
  color: var(--text-primary);
  font-size: 14px;
  font-family: var(--font-sans);
  resize: none;
  max-height: 140px;
  outline: none;
}

.conversation-textarea:focus {
  border-color: var(--border-active);
}

.send-btn {
  background-color: var(--wa-green);
  color: #111b21;
  border: none;
  border-radius: 50%;
  width: 42px;
  height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s ease;
}

.send-btn:hover {
  background-color: var(--wa-green-hover);
  transform: scale(1.05);
}

/* Reply Context Bar */
.reply-context-bar {
  display: none;
  background-color: var(--surface-2);
  padding: 8px 16px;
  border-left: 4px solid var(--wa-green);
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
}

/* ==========================================================================
   CAMPAIGN HUB & BULK SENDER PANE
   ========================================================================== */

.campaign-container {
  padding: 24px 32px;
  overflow-y: auto;
  height: 100%;
}

.campaign-header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
}

.campaign-title-wrap h2 {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 10px;
}

.campaign-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

.card {
  background-color: var(--surface-1);
  border: 1px solid var(--border-hairline);
  border-radius: 12px;
  padding: 20px;
}

.card-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}

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

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

.form-control {
  width: 100%;
  background-color: var(--surface-2);
  border: 1px solid var(--border-hairline);
  border-radius: 8px;
  padding: 9px 12px;
  color: var(--text-primary);
  font-size: 13.5px;
  font-family: var(--font-sans);
  outline: none;
}

.form-control:focus {
  border-color: var(--wa-green);
}

.csv-dropzone {
  border: 2px dashed var(--border-hairline);
  border-radius: 10px;
  padding: 24px;
  text-align: center;
  background-color: var(--surface-2);
  cursor: pointer;
  transition: all 0.2s ease;
}

.csv-dropzone:hover, .csv-dropzone.dragover {
  border-color: var(--wa-green);
  background-color: var(--surface-hover);
}

/* Anti-Ban Badge */
.anti-ban-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background-color: rgba(0, 168, 132, 0.12);
  border: 1px solid rgba(0, 168, 132, 0.3);
  color: var(--wa-green-light);
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 12px;
}

.progress-bar-wrap {
  width: 100%;
  height: 8px;
  background-color: var(--surface-2);
  border-radius: 4px;
  overflow: hidden;
  margin: 12px 0;
}

.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #00a884, #25d366);
  width: 0%;
  transition: width 0.3s ease;
}

/* ==========================================================================
   BUTTONS & TOASTS
   ========================================================================== */

.btn {
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: all 0.15s ease;
}

.btn-primary {
  background-color: var(--wa-green);
  color: #111b21;
}
.btn-primary:hover {
  background-color: var(--wa-green-hover);
}

.btn-secondary {
  background-color: var(--surface-2);
  color: var(--text-primary);
  border: 1px solid var(--border-hairline);
}
.btn-secondary:hover {
  background-color: var(--surface-hover);
}

.btn-danger {
  background-color: var(--danger);
  color: white;
}
.btn-danger:hover {
  background-color: #dc2626;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 11.5px;
  font-weight: 600;
}
.badge-green {
  background-color: rgba(0, 168, 132, 0.15);
  color: var(--wa-green-light);
  border: 1px solid rgba(0, 168, 132, 0.3);
}
.badge-amber {
  background-color: rgba(245, 158, 11, 0.15);
  color: #fbbf24;
  border: 1px solid rgba(245, 158, 11, 0.3);
}
.badge-red {
  background-color: rgba(239, 68, 68, 0.15);
  color: #f87171;
  border: 1px solid rgba(239, 68, 68, 0.3);
}
.badge-blue {
  background-color: rgba(59, 130, 246, 0.15);
  color: #60a5fa;
  border: 1px solid rgba(59, 130, 246, 0.3);
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  display: inline-block;
}
.status-dot.online {
  background-color: var(--wa-green-light);
  box-shadow: 0 0 8px rgba(37, 211, 102, 0.6);
}
.status-dot.offline {
  background-color: var(--danger);
}

/* ==========================================================================
   CATALOG STYLES
   ========================================================================== */
.catalog-container {
  padding: 24px 32px;
  overflow-y: auto;
  height: 100%;
}
.catalog-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 20px;
  margin-top: 16px;
}
.product-card {
  background-color: var(--surface-1);
  border: 1px solid var(--border-hairline);
  border-radius: 12px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: transform 0.2s ease, border-color 0.2s ease;
}
.product-card:hover {
  transform: translateY(-2px);
  border-color: var(--border-active);
}
.product-img-wrap {
  width: 100%;
  height: 180px;
  background-color: #0b141a;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
  position: relative;
}
.product-img-wrap img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}
.product-body {
  padding: 16px;
  display: flex;
  flex-direction: column;
  flex: 1;
}
.product-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 4px;
}
.product-price {
  font-size: 17px;
  font-weight: 700;
  color: var(--wa-green-light);
  margin-bottom: 8px;
}
.product-specs {
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.5;
  margin-bottom: 12px;
  flex: 1;
}
.product-variants {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 14px;
}
.variant-chip {
  background-color: var(--surface-2);
  color: var(--text-secondary);
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 4px;
}

/* ==========================================================================
   AI AGENT COPILOT STYLES
   ========================================================================== */
.agent-container {
  display: flex;
  height: 100%;
  overflow: hidden;
}
.agent-sidebar {
  width: 280px;
  background-color: var(--surface-1);
  border-right: 1px solid var(--border-hairline);
  display: flex;
  flex-direction: column;
}
.agent-chat-pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  background-color: #0b141a;
  position: relative;
  overflow: hidden;
}
.agent-feed {
  flex: 1;
  padding: 20px 32px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.agent-bubble {
  max-width: 80%;
  padding: 12px 16px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.6;
}
.agent-bubble.user {
  align-self: flex-end;
  background-color: var(--outgoing-bubble);
  border-bottom-right-radius: 2px;
}
.agent-bubble.assistant {
  align-self: flex-start;
  background-color: var(--surface-1);
  border: 1px solid var(--border-hairline);
  border-bottom-left-radius: 2px;
}
.agent-thought-card {
  background-color: rgba(24, 34, 41, 0.8);
  border-left: 3px solid #60a5fa;
  border-radius: 6px;
  padding: 8px 12px;
  margin-bottom: 8px;
  font-size: 12px;
  color: var(--text-secondary);
  font-family: var(--font-mono);
}
.tool-call-card {
  background-color: var(--surface-2);
  border: 1px solid var(--border-hairline);
  border-radius: 6px;
  padding: 6px 10px;
  margin-bottom: 8px;
  font-size: 12px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: #38bdf8;
}

/* ==========================================================================
   AUTO-REPLY & DATA TABLES
   ========================================================================== */
.table-container {
  overflow-x: auto;
  border-radius: 8px;
  border: 1px solid var(--border-hairline);
}
.data-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 13px;
}
.data-table th {
  background-color: var(--surface-2);
  color: var(--text-secondary);
  padding: 10px 14px;
  font-weight: 600;
  border-bottom: 1px solid var(--border-hairline);
}
.data-table td {
  padding: 12px 14px;
  border-bottom: 1px solid rgba(134, 150, 160, 0.08);
  color: var(--text-primary);
}
.data-table tr:hover td {
  background-color: var(--surface-hover);
}

/* Modal styles */
.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background-color: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(2px);
}
.modal-box {
  background-color: var(--surface-1);
  border: 1px solid var(--border-hairline);
  border-radius: 12px;
  width: 90%;
  max-width: 540px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.6);
}
.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-hairline);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.modal-body {
  padding: 20px;
}
.modal-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border-hairline);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* Attachment Preview Bar */
.attachment-preview-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  background-color: var(--surface-2);
  border-top: 1px solid var(--border-hairline);
}
.attachment-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  background-color: var(--surface-3);
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 12px;
  color: var(--text-primary);
}

#toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 1000;
}

.toast {
  background-color: var(--surface-1);
  border: 1px solid var(--border-hairline);
  color: var(--text-primary);
  padding: 12px 18px;
  border-radius: 8px;
  font-size: 13px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 260px;
}
.toast.success { border-left: 4px solid var(--wa-green); }
.toast.error { border-left: 4px solid var(--danger); }
.toast.info { border-left: 4px solid var(--info); }
