:root {
  /* Dark Mode (Default) */
  --bg-main: #0b0f19;
  --bg-radial-1: rgba(99, 102, 241, 0.12);
  --bg-radial-2: rgba(16, 185, 129, 0.08);
  --bg-card: rgba(18, 24, 38, 0.7);
  --bg-card-hover: rgba(23, 31, 48, 0.85);
  --border-subtle: rgba(255, 255, 255, 0.08);
  --border-highlight: rgba(99, 102, 241, 0.35);

  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;

  --accent-primary: #6366f1;
  --accent-primary-hover: #4f46e5;
  --accent-glow: rgba(99, 102, 241, 0.25);

  --status-pending: #e2e8f0;
  --status-pending-bg: rgba(226, 232, 240, 0.1);
  --status-step1: #38bdf8;
  --status-step1-bg: rgba(56, 189, 248, 0.12);
  --status-replied: #10b981;
  --status-replied-bg: rgba(16, 185, 129, 0.15);
  --status-step2: #a855f7;
  --status-step2-bg: rgba(168, 85, 247, 0.15);
  --status-human: #f59e0b;
  --status-human-bg: rgba(245, 158, 11, 0.15);
  --status-failed: #ef4444;
  --status-failed-bg: rgba(239, 68, 68, 0.15);

  --pill-bg: rgba(255, 255, 255, 0.04);
  --card-shadow: 0 4px 20px rgba(0, 0, 0, 0.25);
  --modal-bg: #131a2a;
  --table-border: rgba(255, 255, 255, 0.04);
  --table-hover: rgba(255, 255, 255, 0.02);
  --dropzone-bg: rgba(99, 102, 241, 0.03);
  --dropzone-hover: rgba(99, 102, 241, 0.08);
  --input-bg: rgba(18, 24, 38, 0.9);
  --callout-bg: rgba(255, 255, 255, 0.02);

  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --transition-smooth: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Light Mode Theme */
[data-theme="light"] {
  --bg-main: #f8fafc;
  --bg-radial-1: rgba(99, 102, 241, 0.08);
  --bg-radial-2: rgba(16, 185, 129, 0.06);
  --bg-card: rgba(255, 255, 255, 0.9);
  --bg-card-hover: #ffffff;
  --border-subtle: rgba(203, 213, 225, 0.8);
  --border-highlight: rgba(99, 102, 241, 0.4);

  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #64748b;

  --accent-primary: #4f46e5;
  --accent-primary-hover: #4338ca;
  --accent-glow: rgba(79, 70, 229, 0.2);

  --status-pending: #475569;
  --status-pending-bg: #f1f5f9;
  --status-step1: #0284c7;
  --status-step1-bg: #e0f2fe;
  --status-replied: #059669;
  --status-replied-bg: #d1fae5;
  --status-step2: #7c3aed;
  --status-step2-bg: #ede9fe;
  --status-human: #d97706;
  --status-human-bg: #fef3c7;
  --status-failed: #dc2626;
  --status-failed-bg: #fee2e2;

  --pill-bg: #ffffff;
  --card-shadow: 0 10px 30px rgba(0, 0, 0, 0.05);
  --modal-bg: #ffffff;
  --table-border: rgba(226, 232, 240, 0.8);
  --table-hover: rgba(241, 245, 249, 0.6);
  --dropzone-bg: rgba(99, 102, 241, 0.04);
  --dropzone-hover: rgba(99, 102, 241, 0.09);
  --input-bg: #ffffff;
  --callout-bg: #f1f5f9;
}

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

body {
  font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  background-color: var(--bg-main);
  background-image: 
    radial-gradient(circle at 15% 10%, var(--bg-radial-1) 0%, transparent 40%),
    radial-gradient(circle at 85% 25%, var(--bg-radial-2) 0%, transparent 45%);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  transition: background-color 0.3s ease, color 0.3s ease;
}

.app-container {
  max-width: 1380px;
  margin: 0 auto;
  padding: 32px 24px 64px 24px;
}

/* Header */
.main-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 32px;
  flex-wrap: wrap;
  gap: 16px;
}

.brand-section {
  display: flex;
  align-items: center;
  gap: 16px;
}

.logo-badge {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, #4f46e5, #06b6d4);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  box-shadow: 0 8px 24px rgba(79, 70, 229, 0.35);
}

.brand-title {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}

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

.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  border-radius: 9999px;
  font-size: 0.875rem;
  font-weight: 600;
  background: var(--pill-bg);
  border: 1px solid var(--border-subtle);
  box-shadow: var(--card-shadow);
  transition: var(--transition-smooth);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
}

.status-connected {
  border-color: rgba(16, 185, 129, 0.3);
  background: rgba(16, 185, 129, 0.1);
  color: #10b981;
}
.status-connected .status-dot {
  background: #10b981;
  box-shadow: 0 0 10px #10b981;
}

.status-disconnected {
  border-color: rgba(239, 68, 68, 0.3);
  background: rgba(239, 68, 68, 0.1);
  color: #ef4444;
}
.status-disconnected .status-dot {
  background: #ef4444;
}

.status-awaiting-qr {
  border-color: rgba(245, 158, 11, 0.4);
  background: rgba(245, 158, 11, 0.12);
  color: #f59e0b;
}
.status-awaiting-qr .status-dot {
  background: #f59e0b;
  box-shadow: 0 0 10px #f59e0b;
  animation: pulse-dot 1.5s infinite;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.8); }
}

.btn-pulse {
  animation: pulse-cta 2s infinite ease-in-out;
}

@keyframes pulse-cta {
  0%, 100% { box-shadow: 0 4px 16px var(--accent-glow); }
  50% { box-shadow: 0 0 24px rgba(99, 102, 241, 0.7); }
}

/* Metrics Grid */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}

.metric-card {
  background: var(--bg-card);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  box-shadow: var(--card-shadow);
  transition: var(--transition-smooth);
}

.metric-card:hover {
  background: var(--bg-card-hover);
  border-color: var(--border-highlight);
  transform: translateY(-2px);
}

.highlight-metric {
  background: linear-gradient(135deg, rgba(16, 185, 129, 0.1), var(--bg-card));
  border-color: rgba(16, 185, 129, 0.35);
}

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

.icon-total { background: rgba(99, 102, 241, 0.15); color: #6366f1; }
.icon-step1 { background: rgba(56, 189, 248, 0.15); color: #0284c7; }
.icon-replied { background: rgba(16, 185, 129, 0.15); color: #10b981; }
.icon-step2 { background: rgba(168, 85, 247, 0.15); color: #9333ea; }
.icon-human { background: rgba(245, 158, 11, 0.15); color: #d97706; }

.metric-info {
  display: flex;
  flex-direction: column;
}

.metric-label {
  font-size: 0.8125rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.metric-value-group {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.metric-value {
  font-size: 1.625rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--text-primary);
}

.metric-subtag {
  font-size: 0.8125rem;
  font-weight: 700;
  color: #10b981;
  background: rgba(16, 185, 129, 0.2);
  padding: 2px 8px;
  border-radius: 999px;
}

/* Panels Grid */
.panels-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-bottom: 28px;
}

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

.card {
  background: var(--bg-card);
  backdrop-filter: blur(16px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--card-shadow);
  transition: var(--transition-smooth);
}

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

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

.card-desc {
  font-size: 0.875rem;
  color: var(--text-secondary);
  margin-bottom: 20px;
}

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

/* Control Actions */
.control-actions {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.badge {
  font-size: 0.75rem;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 9999px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.badge-idle { background: rgba(148, 163, 184, 0.15); color: #64748b; }
.badge-running { background: rgba(16, 185, 129, 0.15); color: #059669; }
.badge-paused { background: rgba(245, 158, 11, 0.15); color: #d97706; }

@keyframes pulse-ring {
  0% { box-shadow: 0 0 0 0 rgba(79, 70, 229, 0.6); }
  70% { box-shadow: 0 0 0 10px rgba(79, 70, 229, 0); }
  100% { box-shadow: 0 0 0 0 rgba(79, 70, 229, 0); }
}

.btn-pulse {
  animation: pulse-ring 2s infinite cubic-bezier(0.4, 0, 0.6, 1);
}

.info-callout {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  background: var(--callout-bg);
  border: 1px dashed var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 0.8125rem;
  color: var(--text-secondary);
}

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

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

.btn-primary {
  background: linear-gradient(135deg, var(--accent-primary), #4338ca);
  color: #fff;
  box-shadow: 0 4px 16px var(--accent-glow);
}
.btn-primary:hover:not(:disabled) {
  background: linear-gradient(135deg, var(--accent-primary-hover), #3730a3);
  transform: translateY(-1px);
}

.btn-warning {
  background: #f59e0b;
  color: #000;
}
.btn-warning:hover:not(:disabled) {
  background: #d97706;
}

.btn-success {
  background: #10b981;
  color: #fff;
}
.btn-success:hover:not(:disabled) {
  background: #059669;
}

.btn-danger {
  background: linear-gradient(135deg, #ef4444, #b91c1c);
  color: #fff;
  box-shadow: 0 4px 14px rgba(239, 68, 68, 0.25);
}
.btn-danger:hover:not(:disabled) {
  background: linear-gradient(135deg, #dc2626, #991b1b);
  transform: translateY(-1px);
}

.btn-secondary {
  background: var(--pill-bg);
  color: var(--text-primary);
  border: 1px solid var(--border-subtle);
}
.btn-secondary:hover:not(:disabled) {
  border-color: var(--border-highlight);
  background: var(--bg-card-hover);
}

.btn-outline {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border-subtle);
  padding: 8px;
}
.btn-outline:hover {
  color: var(--text-primary);
  background: var(--bg-card-hover);
}

/* Drop Zone */
.drop-zone {
  border: 2px dashed var(--border-highlight);
  border-radius: var(--radius-md);
  padding: 32px 16px;
  text-align: center;
  cursor: pointer;
  background: var(--dropzone-bg);
  transition: var(--transition-smooth);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.drop-zone:hover, .drop-zone.drag-over {
  border-color: var(--accent-primary);
  background: var(--dropzone-hover);
}

.drop-text {
  font-size: 0.9375rem;
  color: var(--text-primary);
}

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

.upload-feedback {
  margin-top: 14px;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 500;
}
.upload-feedback.success {
  background: rgba(16, 185, 129, 0.15);
  border: 1px solid rgba(16, 185, 129, 0.3);
  color: #059669;
}
.upload-feedback.error {
  background: rgba(239, 68, 68, 0.15);
  border: 1px solid rgba(239, 68, 68, 0.3);
  color: #dc2626;
}

/* Table Section */
.table-header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 16px;
}

.table-filters {
  display: flex;
  gap: 10px;
  align-items: center;
}

.select-input {
  background: var(--input-bg);
  color: var(--text-primary);
  border: 1px solid var(--border-subtle);
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  outline: none;
}
.select-input:focus {
  border-color: var(--accent-primary);
}

.table-responsive {
  overflow-x: auto;
}

.leads-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 0.875rem;
}

.leads-table th {
  padding: 12px 16px;
  color: var(--text-muted);
  font-weight: 600;
  border-bottom: 1px solid var(--border-subtle);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.leads-table td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--table-border);
  color: var(--text-primary);
}

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

.empty-state {
  text-align: center;
  padding: 40px !important;
  color: var(--text-muted);
}

/* Status Badges */
.status-badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.status-badge.PENDING { background: var(--status-pending-bg); color: var(--status-pending); }
.status-badge.SENT_STEP1 { background: var(--status-step1-bg); color: var(--status-step1); }
.status-badge.REPLIED { background: var(--status-replied-bg); color: var(--status-replied); }
.status-badge.SENT_STEP2 { background: var(--status-step2-bg); color: var(--status-step2); }
.status-badge.HUMAN_INTERVENTION_REQUIRED { background: var(--status-human-bg); color: var(--status-human); }
.status-badge.FAILED { background: var(--status-failed-bg); color: var(--status-failed); }

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(8px);
}

.modal-content {
  position: relative;
  background: var(--modal-bg);
  border: 1px solid var(--border-highlight);
  border-radius: var(--radius-lg);
  padding: 28px;
  width: 90%;
  max-width: 440px;
  z-index: 1000;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.4);
}

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

.modal-title {
  font-size: 1.25rem;
  font-weight: 700;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  cursor: pointer;
}
.modal-close:hover {
  color: var(--text-primary);
}

.modal-instruction {
  font-size: 0.875rem;
  color: var(--text-secondary);
  margin-bottom: 20px;
}

.qrcode-container {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 250px;
  background: #fff;
  border-radius: var(--radius-md);
  padding: 16px;
  border: 1px solid var(--border-subtle);
}

.qrcode-container img {
  max-width: 100%;
  height: auto;
  border-radius: var(--radius-sm);
}

.qrcode-loader {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: #333;
  font-weight: 600;
  font-size: 0.9375rem;
  padding: 30px 10px;
  text-align: center;
}

.qr-steps {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
  background: var(--bg-card);
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
  font-size: 0.84rem;
  color: var(--text-secondary);
}

.qr-step {
  display: flex;
  align-items: center;
  gap: 10px;
}

.step-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--accent-primary);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 700;
  flex-shrink: 0;
}

.qrcode-footer-status {
  text-align: center;
  margin-top: 12px;
  font-size: 0.8125rem;
  color: var(--text-muted);
}

.btn-sm {
  padding: 6px 12px;
  font-size: 0.8125rem;
}

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

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

/* Table Actions & Icon Buttons */
.table-actions {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border-radius: var(--radius-sm);
  background: var(--pill-bg);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  cursor: pointer;
  transition: var(--transition-smooth);
}
.btn-icon:hover {
  background: var(--bg-card-hover);
  color: var(--text-primary);
  border-color: var(--border-highlight);
}
.btn-icon.delete:hover {
  background: rgba(239, 68, 68, 0.15);
  color: #ef4444;
  border-color: rgba(239, 68, 68, 0.4);
}

/* Form Styles */
.form-group {
  margin-bottom: 14px;
  text-align: left;
}
.form-label {
  display: block;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
}
.form-input {
  width: 100%;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  background: var(--bg-body);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  font-size: 0.875rem;
  box-sizing: border-box;
  transition: var(--transition-smooth);
}
.form-input:focus {
  outline: none;
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
