:root {
  --primary: #25D366;
  --primary-dark: #128C7E;
  --primary-hover: #1ebd5d;
  --dark-teal: #075E54;
  --bg-main: #f0f2f5;
  --card-bg: #ffffff;
  --text-main: #111827;
  --text-muted: #6b7280;
  --border-color: #e5e7eb;
  --status-connected: #10b981;
  --status-waiting: #f59e0b;
  --status-disconnected: #ef4444;
  --status-connecting: #3b82f6;
  --radius-lg: 16px;
  --radius-md: 10px;
  --radius-sm: 6px;
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.07), 0 2px 4px -1px rgba(0, 0, 0, 0.04);
  --shadow-lg: 0 10px 25px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -2px rgba(0, 0, 0, 0.03);
}

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

body {
  font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background-color: var(--bg-main);
  color: var(--text-main);
  line-height: 1.5;
  min-height: 100vh;
}

.app-layout {
  max-width: 1240px;
  margin: 0 auto;
  padding: 24px 20px 48px;
}

/* Navbar */
.navbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background-color: var(--card-bg);
  padding: 16px 24px;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border-color);
  margin-bottom: 24px;
}

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

.brand-icon {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: #ffffff;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(37, 211, 102, 0.3);
}

.nav-brand h1 {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-main);
}

.brand-subtitle {
  font-size: 0.825rem;
  color: var(--text-muted);
}

/* Status Badges */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  border-radius: 9999px;
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: capitalize;
  border: 1px solid transparent;
  transition: all 0.2s ease;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}

.status-badge.status-connected {
  background-color: rgba(16, 185, 129, 0.12);
  color: #065f46;
  border-color: rgba(16, 185, 129, 0.25);
}
.status-badge.status-connected .status-dot { background-color: var(--status-connected); }

.status-badge.status-waiting_qr {
  background-color: rgba(245, 158, 11, 0.12);
  color: #92400e;
  border-color: rgba(245, 158, 11, 0.25);
}
.status-badge.status-waiting_qr .status-dot { background-color: var(--status-waiting); }

.status-badge.status-connecting {
  background-color: rgba(59, 130, 246, 0.12);
  color: #1e40af;
  border-color: rgba(59, 130, 246, 0.25);
}
.status-badge.status-connecting .status-dot { background-color: var(--status-connecting); }

.status-badge.status-disconnected {
  background-color: rgba(239, 68, 68, 0.12);
  color: #991b1b;
  border-color: rgba(239, 68, 68, 0.25);
}
.status-badge.status-disconnected .status-dot { background-color: var(--status-disconnected); }

/* Dashboard Grid */
.dashboard-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
}

.logs-section {
  grid-column: 1 / -1;
}

/* Cards */
.card {
  background-color: var(--card-bg);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
}

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

.card-header h2 {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-main);
}

.badge {
  font-size: 0.75rem;
  padding: 4px 10px;
  border-radius: 9999px;
  background-color: #f3f4f6;
  color: var(--text-muted);
  font-weight: 500;
}

/* QR Code Section */
.qr-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 380px;
  background: #fafafa;
  border-radius: var(--radius-md);
  border: 1px dashed var(--border-color);
  padding: 24px;
}

.qr-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  color: var(--text-muted);
}

.spinner {
  width: 42px;
  height: 42px;
  border: 3px solid rgba(37, 211, 102, 0.2);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

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

.small-hint {
  font-size: 0.8rem;
  color: #9ca3af;
}

.qr-display {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
}

.qr-wrapper {
  background: #ffffff;
  padding: 12px;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  margin-bottom: 20px;
  border: 1px solid var(--border-color);
}

.qr-wrapper img {
  display: block;
  width: 240px;
  height: 240px;
  image-rendering: pixelated;
}

.qr-steps {
  width: 100%;
  max-width: 380px;
  background: #ffffff;
  border-radius: var(--radius-sm);
  padding: 14px 18px;
  border: 1px solid var(--border-color);
}

.qr-steps ol {
  padding-left: 20px;
  font-size: 0.85rem;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.qr-steps strong {
  color: var(--text-main);
}

/* Connected View */
.connected-view {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 36px 20px;
  text-align: center;
  min-height: 380px;
  background: linear-gradient(180deg, #f0fdf4 0%, #ffffff 100%);
  border-radius: var(--radius-md);
  border: 1px solid #bbf7d0;
}

.connected-avatar {
  background-color: #dcfce7;
  color: #16a34a;
  width: 76px;
  height: 76px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 16px;
  box-shadow: 0 4px 12px rgba(22, 163, 74, 0.2);
}

.connected-view h3 {
  font-size: 1.35rem;
  font-weight: 700;
  color: #166534;
  margin-bottom: 4px;
}

.connected-phone {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-main);
}

.connected-name {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-bottom: 16px;
}

.bot-state-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.825rem;
  padding: 6px 14px;
  background: #ffffff;
  border: 1px solid #bbf7d0;
  border-radius: 9999px;
  color: #15803d;
  font-weight: 500;
  margin-bottom: 24px;
}

.status-dot.green {
  background-color: var(--status-connected);
}

.status-dot.pulsing {
  animation: pulse 1.5s infinite;
}

@keyframes pulse {
  0% { transform: scale(0.95); opacity: 0.7; }
  50% { transform: scale(1.15); opacity: 1; }
  100% { transform: scale(0.95); opacity: 0.7; }
}

/* Actions Section & Form */
.message-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-bottom: 24px;
}

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

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

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

.input-with-icon {
  position: relative;
  display: flex;
  align-items: center;
}

.input-prefix {
  position: absolute;
  left: 12px;
  font-size: 1rem;
  pointer-events: none;
}

.input-with-icon input {
  padding-left: 40px;
}

input[type="text"],
textarea {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.9rem;
  color: var(--text-main);
  background-color: #fafafa;
  transition: all 0.2s ease;
}

input[type="text"]:focus,
textarea:focus {
  outline: none;
  background-color: #ffffff;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 211, 102, 0.15);
}

textarea {
  resize: vertical;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all 0.2s ease;
}

.btn-primary {
  background-color: var(--primary);
  color: #ffffff;
}

.btn-primary:hover {
  background-color: var(--primary-hover);
  box-shadow: 0 4px 10px rgba(37, 211, 102, 0.3);
}

.btn-primary:active {
  transform: translateY(1px);
}

.btn-secondary {
  background-color: #f3f4f6;
  color: var(--text-main);
}

.btn-danger-soft {
  background-color: #fee2e2;
  color: #b91c1c;
}

.btn-danger-soft:hover {
  background-color: #fecaca;
}

.btn-sm {
  padding: 5px 12px;
  font-size: 0.775rem;
}

.btn-outline {
  background-color: transparent;
  border: 1px solid var(--border-color);
  color: var(--text-muted);
}

.btn-outline:hover {
  background-color: #f3f4f6;
  color: var(--text-main);
}

.send-feedback {
  font-size: 0.85rem;
  font-weight: 500;
  border-radius: var(--radius-sm);
  display: none;
  padding: 8px 12px;
}

.send-feedback.success {
  display: block;
  background-color: #dcfce7;
  color: #166534;
  border: 1px solid #bbf7d0;
}

.send-feedback.error {
  display: block;
  background-color: #fee2e2;
  color: #991b1b;
  border: 1px solid #fecaca;
}

/* Quick Commands Card */
.commands-card {
  background-color: #f9fafb;
  border-radius: var(--radius-md);
  padding: 16px;
  border: 1px solid var(--border-color);
}

.commands-card h3 {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 2px;
}

.commands-sub {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.commands-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.cmd-item {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #ffffff;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
}

.cmd-item code {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.75rem;
  font-weight: 600;
  background-color: #f3f4f6;
  color: var(--primary-dark);
  padding: 2px 6px;
  border-radius: 4px;
}

.cmd-item span {
  font-size: 0.75rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Logs Console */
.logs-header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logs-live-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  color: #166534;
  background-color: #dcfce7;
  padding: 2px 8px;
  border-radius: 9999px;
}

.logs-console {
  background-color: #111827;
  color: #e5e7eb;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.8rem;
  border-radius: var(--radius-md);
  padding: 16px;
  height: 280px;
  overflow-y: auto;
  display: flex;
  flex-direction: column-reverse; /* Newest logs visible at top or bottom */
  gap: 8px;
}

.log-entry {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  line-height: 1.4;
  word-break: break-word;
}

.log-time {
  color: #6b7280;
  font-size: 0.75rem;
  flex-shrink: 0;
}

.log-badge {
  font-size: 0.65rem;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 4px;
  text-transform: uppercase;
  flex-shrink: 0;
}

.log-badge.system {
  background-color: #374151;
  color: #9ca3af;
}

.log-badge.received {
  background-color: #1e3a8a;
  color: #93c5fd;
}

.log-badge.sent {
  background-color: #064e3b;
  color: #6ee7b7;
}

.log-badge.error {
  background-color: #7f1d1d;
  color: #fca5a5;
}

.log-text {
  color: #f3f4f6;
}

.log-entry.error .log-text {
  color: #f87171;
}

/* Responsive */
@media (max-width: 900px) {
  .dashboard-grid {
    grid-template-columns: 1fr;
  }
  .commands-grid {
    grid-template-columns: 1fr;
  }
}


/* Estilos de filtro exclusivo */
.target-user-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background-color: #eff6ff;
  color: #1d4ed8;
  border: 1px solid #bfdbfe;
  padding: 6px 12px;
  border-radius: 9999px;
  font-size: 0.825rem;
  font-weight: 600;
}

.target-user-pill strong {
  color: #1e40af;
}

.filter-card {
  background-color: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: var(--radius-md);
  padding: 16px;
  margin-bottom: 12px;
}

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

.filter-header h3 {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-main);
}

.active-badge {
  background-color: #dcfce7;
  color: #166534;
  font-weight: 700;
}

.filter-description {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 12px;
  line-height: 1.4;
}

.input-inline {
  display: flex;
  gap: 8px;
}

.input-inline input {
  flex: 1;
}

.nav-status {
  display: flex;
  align-items: center;
  gap: 12px;
}


/* Estilos de IA OpenRouter */
.ai-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background-color: #fdf2f8;
  color: #9d174d;
  border: 1px solid #fbcfe8;
  padding: 6px 12px;
  border-radius: 9999px;
  font-size: 0.825rem;
  font-weight: 600;
}

.ai-card {
  background: linear-gradient(135deg, #fdf4ff 0%, #ffffff 100%);
  border: 1px solid #f0abfc;
  border-radius: var(--radius-md);
  padding: 16px;
  margin-bottom: 12px;
}

.ai-meta {
  display: flex;
  gap: 16px;
  margin-top: 8px;
  padding: 8px 12px;
  background: #ffffff;
  border-radius: var(--radius-sm);
  border: 1px solid #f5d0fe;
}

.ai-meta-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.775rem;
}

.meta-label {
  color: var(--text-muted);
  font-weight: 500;
}

.meta-key {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.725rem;
  color: #a21caf;
  background-color: #fae8ff;
  padding: 2px 6px;
  border-radius: 4px;
}

.log-badge.ai {
  background-color: #701a75;
  color: #f5d0fe;
}


/* Estilos catálogo de frutas */
.products-card {
  background: #ffffff;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 16px;
  margin-bottom: 12px;
}

.products-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 10px;
}

.prod-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background-color: #f9fafb;
  border: 1px solid #e5e7eb;
  border-radius: var(--radius-sm);
}

.prod-item.combo {
  background-color: #fffbeb;
  border-color: #fde68a;
}

.prod-icon {
  font-size: 1.5rem;
}

.prod-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.prod-info strong {
  font-size: 0.875rem;
  color: var(--text-main);
}

.prod-price {
  font-weight: 700;
  font-size: 0.95rem;
  color: #059669;
}

.prod-price.highlight {
  color: #d97706;
}

.combo-tag {
  font-size: 0.725rem;
  color: #b45309;
  font-weight: 600;
}


/* Estilos de tarjeta modo humano */
.human-card {
  background: linear-gradient(135deg, #f5f3ff 0%, #ffffff 100%);
  border: 1px solid #c7d2fe;
  border-radius: var(--radius-md);
  padding: 16px;
  margin-bottom: 12px;
}


/* Estilos del Simulador de Chat */
.simulator-section {
  grid-column: 1 / -1;
  background-color: var(--card-bg);
}

.sim-container {
  display: flex;
  flex-direction: column;
  background-color: #f0f2f5;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.sim-chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background-color: #ffffff;
  padding: 12px 18px;
  border-bottom: 1px solid var(--border-color);
}

.sim-chat-user {
  display: flex;
  align-items: center;
  gap: 12px;
}

.sim-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: #fef08a;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  box-shadow: var(--shadow-sm);
}

.sim-user-details {
  display: flex;
  flex-direction: column;
}

.sim-username {
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--text-main);
}

.sim-user-status {
  font-size: 0.75rem;
  color: #10b981;
  font-weight: 500;
}

.sim-typing-box {
  display: flex;
  align-items: center;
  gap: 8px;
  background-color: #dcfce7;
  color: #166534;
  padding: 6px 12px;
  border-radius: 9999px;
  font-size: 0.8rem;
  font-weight: 600;
  border: 1px solid #bbf7d0;
}

.typing-dots {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.typing-dots span {
  width: 6px;
  height: 6px;
  background-color: #16a34a;
  border-radius: 50%;
  animation: typingBounce 1.4s infinite ease-in-out both;
}

.typing-dots span:nth-child(1) { animation-delay: -0.32s; }
.typing-dots span:nth-child(2) { animation-delay: -0.16s; }

@keyframes typingBounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40% { transform: scale(1.1); opacity: 1; }
}

.sim-messages-body {
  padding: 20px;
  height: 360px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background-color: #efeae2;
  background-image: radial-gradient(#cbd5e1 1px, transparent 1px);
  background-size: 20px 20px;
}

.sim-msg {
  display: flex;
  width: 100%;
}

.sim-msg.assistant {
  justify-content: flex-start;
}

.sim-msg.user {
  justify-content: flex-end;
}

.sim-bubble {
  max-width: 75%;
  padding: 10px 14px;
  border-radius: 12px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 4px;
  word-break: break-word;
  white-space: pre-wrap;
  line-height: 1.45;
  font-size: 0.875rem;
}

.sim-msg.assistant .sim-bubble {
  background-color: #ffffff;
  color: #111827;
  border-top-left-radius: 2px;
}

.sim-msg.user .sim-bubble {
  background-color: #d9fdd3;
  color: #111827;
  border-top-right-radius: 2px;
}

.sim-sender {
  font-size: 0.725rem;
  font-weight: 700;
  color: #16a34a;
}

.sim-msg.user .sim-sender {
  color: #15803d;
  text-align: right;
}

.sim-time {
  font-size: 0.675rem;
  color: #6b7280;
  align-self: flex-end;
  margin-top: 2px;
}

.sim-quick-tests {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px 16px;
  background-color: #f8fafc;
  border-top: 1px solid var(--border-color);
}

.quick-title {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-muted);
}

.btn-chip {
  background-color: #ffffff;
  border: 1px solid var(--border-color);
  padding: 5px 12px;
  border-radius: 9999px;
  font-size: 0.775rem;
  font-weight: 600;
  color: var(--text-main);
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-chip:hover {
  background-color: #f1f5f9;
  border-color: #cbd5e1;
}

.btn-chip.burst-chip {
  background-color: #fef3c7;
  border-color: #fde68a;
  color: #92400e;
}

.btn-chip.burst-chip:hover {
  background-color: #fde68a;
}

.sim-input-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background-color: #ffffff;
  border-top: 1px solid var(--border-color);
}

.sim-input-bar input {
  flex: 1;
  padding: 10px 16px;
  border: 1px solid var(--border-color);
  border-radius: 9999px;
  font-size: 0.875rem;
  outline: none;
  background-color: #f9fafb;
}

.sim-input-bar input:focus {
  background-color: #ffffff;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 211, 102, 0.15);
}

.sim-input-bar .btn {
  border-radius: 9999px;
  padding: 8px 18px;
}

/* Contactos autorizados */
.contacts-section {
  grid-column: 1 / -1;
}

.contacts-form {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 12px 16px;
  align-items: end;
  margin-bottom: 18px;
}

.contacts-form .form-group {
  margin-bottom: 0;
}

.contacts-form .send-feedback {
  grid-column: 1 / -1;
}

.contacts-list {
  display: grid;
  gap: 10px;
}

.contacts-empty {
  font-size: 0.85rem;
  color: var(--text-muted);
  padding: 8px 2px;
}

.contact-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background-color: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: var(--radius-md);
  padding: 12px 16px;
}

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

.contact-name {
  font-weight: 700;
  color: var(--text-main);
}

.contact-phone {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.btn-delete-contact {
  background-color: #fee2e2;
  color: #b91c1c;
  border: 1px solid rgba(239, 68, 68, 0.25);
  border-radius: 9999px;
  padding: 6px 14px;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.15s ease;
  white-space: nowrap;
}

.btn-delete-contact:hover {
  background-color: #fecaca;
}

@media (max-width: 780px) {
  .contacts-form {
    grid-template-columns: 1fr;
  }
}

