:root {
  --bg: #0b0f19;
  --bg-card: #131b2e;
  --bg-input: #1a233a;
  --border: #233152;
  --border-focus: #3b82f6;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --success: #10b981;
  --success-hover: #059669;
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --warning: #f59e0b;
  --radius: 12px;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  --shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.4), 0 8px 10px -6px rgba(0, 0, 0, 0.3);
}

[data-theme="light"] {
  --bg: #f8fafc;
  --bg-card: #ffffff;
  --bg-input: #f1f5f9;
  --border: #cbd5e1;
  --border-focus: #2563eb;
  --text: #0f172a;
  --text-muted: #64748b;
  --shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.08);
}

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

body {
  font-family: var(--font-sans);
  background-color: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  padding: 16px;
  display: flex;
  justify-content: center;
}

.app-container {
  width: 100%;
  max-width: 760px;
  margin: 0 auto;
}

/* Header */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 0 24px 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 24px;
}

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

.brand-icon {
  font-size: 28px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.brand-title {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

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

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

.btn-icon {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-icon:hover {
  background: var(--border);
}

/* Cards */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 20px;
  box-shadow: var(--shadow);
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.section-title {
  font-size: 17px;
  font-weight: 600;
}

/* Form Elements */
.form-group {
  margin-bottom: 16px;
}

.form-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

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

.btn-text-link {
  background: none;
  border: none;
  color: var(--primary);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.btn-text-link:hover {
  text-decoration: underline;
}

.form-input, .form-select {
  width: 100%;
  padding: 12px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 15px;
  font-family: inherit;
  transition: border-color 0.2s;
}

.form-input:focus, .form-select:focus {
  outline: none;
  border-color: var(--border-focus);
}

.code-font {
  font-family: var(--font-mono);
}

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

.input-with-button .form-input {
  flex: 1;
}

.form-help {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 6px;
}

.form-row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px 18px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.2s;
  white-space: nowrap;
}

.btn:active {
  transform: scale(0.98);
}

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

.btn-success {
  background: var(--success);
  color: #fff;
}
.btn-success:hover {
  background: var(--success-hover);
}

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

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

.btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--text-muted);
}
.btn-ghost:hover {
  color: var(--text);
  background: var(--bg-input);
}

.btn-danger-ghost {
  background: transparent;
  border-color: rgba(239, 68, 68, 0.3);
  color: var(--danger);
}
.btn-danger-ghost:hover {
  background: rgba(239, 68, 68, 0.1);
}

.btn-small {
  padding: 6px 12px;
  font-size: 12px;
}

.btn-large {
  padding: 14px 24px;
  font-size: 16px;
  width: 100%;
}

.btn-tiny {
  padding: 4px 8px;
  font-size: 11px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 4px;
  cursor: pointer;
}
.btn-tiny:hover {
  color: var(--text);
  border-color: var(--border-focus);
}

/* Pairing Code Output Card */
.pairing-code-box {
  background: linear-gradient(135deg, rgba(37, 99, 235, 0.1), rgba(16, 185, 129, 0.05));
  border: 1px solid rgba(59, 130, 246, 0.3);
  border-radius: 10px;
  padding: 18px;
  margin: 16px 0;
}

.pairing-code-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.pairing-title {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  color: #60a5fa;
  letter-spacing: 0.05em;
}

.pairing-code-display {
  font-family: var(--font-mono);
  font-size: 36px;
  font-weight: 800;
  letter-spacing: 6px;
  text-align: center;
  background: var(--bg-card);
  border: 1px dashed rgba(59, 130, 246, 0.5);
  border-radius: 8px;
  padding: 14px;
  color: #93c5fd;
  text-shadow: 0 0 12px rgba(59, 130, 246, 0.5);
  user-select: all;
  margin-bottom: 14px;
}

.pairing-instructions {
  background: rgba(0, 0, 0, 0.2);
  border-radius: 8px;
  padding: 12px 16px;
  font-size: 13px;
}

.pairing-instructions h4 {
  font-size: 13px;
  margin-bottom: 6px;
  color: var(--text);
}

.pairing-instructions ol {
  padding-left: 20px;
  color: var(--text-muted);
}

.pairing-instructions li {
  margin-bottom: 4px;
}

/* Status rows */
.wa-status-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
  gap: 10px;
}

.status-readout {
  display: flex;
  align-items: center;
  gap: 8px;
}

.status-label {
  font-size: 13px;
  color: var(--text-muted);
}

.status-value {
  font-weight: 600;
  font-size: 14px;
}

.status-offline {
  color: var(--danger);
}
.status-connected {
  color: var(--success);
}
.status-connecting {
  color: var(--warning);
}

.wa-actions {
  display: flex;
  gap: 6px;
}

.qr-container {
  margin-top: 16px;
  text-align: center;
  padding: 14px;
  background: var(--bg-input);
  border-radius: 8px;
}

.qr-image-wrap img {
  width: 200px;
  height: 200px;
  margin: 10px auto;
  border-radius: 8px;
  background: #fff;
  padding: 8px;
}

/* Dropzone & Upload */
.upload-drawer {
  margin-bottom: 16px;
}

.dropzone {
  display: block;
  border: 2px dashed var(--border);
  border-radius: 8px;
  padding: 24px;
  text-align: center;
  cursor: pointer;
  background: var(--bg-input);
  transition: all 0.2s;
}

.dropzone:hover {
  border-color: var(--border-focus);
  background: rgba(59, 130, 246, 0.05);
}

.dropzone-icon {
  font-size: 28px;
  display: block;
  margin-bottom: 6px;
}

.progress-wrap {
  margin-top: 10px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.progress-bar {
  flex: 1;
  height: 8px;
  background: var(--bg-input);
  border-radius: 4px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--primary);
  transition: width 0.2s;
}

.progress-text {
  font-size: 12px;
  font-family: var(--font-mono);
  color: var(--text-muted);
}

/* Selected Video Preview Card */
.selected-video-card {
  display: flex;
  gap: 12px;
  align-items: center;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  margin-bottom: 16px;
}

.sel-thumb {
  width: 72px;
  height: 48px;
  object-fit: cover;
  border-radius: 6px;
  background: #000;
}

.sel-name {
  font-weight: 600;
  font-size: 14px;
}

.sel-meta {
  font-size: 12px;
  color: var(--text-muted);
}

/* Checkboxes */
.checkboxes-row {
  display: flex;
  gap: 20px;
  margin: 16px 0;
  flex-wrap: wrap;
}

.checkbox-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  cursor: pointer;
  user-select: none;
}

.checkbox-label input {
  accent-color: var(--primary);
  width: 18px;
  height: 18px;
  cursor: pointer;
}

.action-buttons-row {
  margin-top: 12px;
}

/* LIVE STATUS MONITOR PANEL */
.status-panel-card {
  background: linear-gradient(180deg, var(--bg-card), rgba(19, 27, 46, 0.95));
  border: 1px solid var(--border);
}

.status-readout-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
}

.status-grid-item {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

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

.grid-label {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: 0.02em;
}

.status-pill-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 600;
}

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

.badge-wa-connected {
  background: rgba(16, 185, 129, 0.15);
  border: 1px solid rgba(16, 185, 129, 0.4);
  color: #34d399;
}
.badge-wa-connected .pill-dot {
  background: #10b981;
  box-shadow: 0 0 8px #10b981;
}

.badge-wa-offline {
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.3);
  color: #f87171;
}
.badge-wa-offline .pill-dot {
  background: #ef4444;
}

.status-pills-group {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.status-step-pill {
  padding: 6px 14px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-muted);
  transition: all 0.2s;
}

.status-step-pill.active {
  color: #fff;
  font-weight: 700;
}

/* Call states */
.status-step-pill[data-state="Connecting"].active {
  background: rgba(245, 158, 11, 0.2);
  border-color: #f59e0b;
  color: #fbbf24;
  box-shadow: 0 0 10px rgba(245, 158, 11, 0.3);
}

.status-step-pill[data-state="Ringing"].active {
  background: rgba(245, 158, 11, 0.25);
  border-color: #f59e0b;
  color: #fde047;
  animation: pulse-ring 1.5s infinite;
}

.status-step-pill[data-state="Connected"].active {
  background: rgba(16, 185, 129, 0.25);
  border-color: #10b981;
  color: #6ee7b7;
  box-shadow: 0 0 10px rgba(16, 185, 129, 0.4);
}

.status-step-pill[data-state="Ended"].active {
  background: rgba(239, 68, 68, 0.2);
  border-color: #ef4444;
  color: #fca5a5;
}

/* Video & Audio states */
.status-step-pill[data-state="Waiting"].active {
  background: rgba(245, 158, 11, 0.2);
  border-color: #f59e0b;
  color: #fbbf24;
}

.status-step-pill[data-state="Playing"].active {
  background: rgba(16, 185, 129, 0.25);
  border-color: #10b981;
  color: #6ee7b7;
  box-shadow: 0 0 10px rgba(16, 185, 129, 0.4);
}

.status-step-pill[data-state="Stopped"].active {
  background: rgba(148, 163, 184, 0.15);
  border-color: rgba(148, 163, 184, 0.3);
  color: var(--text-muted);
}

@keyframes pulse-ring {
  0% { transform: scale(1); box-shadow: 0 0 0 0 rgba(245, 158, 11, 0.5); }
  70% { transform: scale(1.02); box-shadow: 0 0 0 8px rgba(245, 158, 11, 0); }
  100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(245, 158, 11, 0); }
}

.live-pill {
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 4px;
  text-transform: uppercase;
}

.live-pill.idle {
  background: rgba(148, 163, 184, 0.15);
  color: var(--text-muted);
}

.live-pill.live {
  background: rgba(239, 68, 68, 0.2);
  border: 1px solid #ef4444;
  color: #ef4444;
  animation: pulse-ring 2s infinite;
}

.call-simulation-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 14px;
  padding-top: 10px;
  border-top: 1px dashed var(--border);
  flex-wrap: wrap;
}

.auto-answer-card {
  margin: 14px 0 16px 0;
  padding: 12px 14px;
  background: rgba(37, 211, 102, 0.06);
  border: 1px solid rgba(37, 211, 102, 0.25);
  border-radius: 8px;
}

.auto-answer-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.ring-delay-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.ring-delay-input {
  width: 58px;
  padding: 4px 8px;
  text-align: center;
  font-weight: 700;
  color: #25d366;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 4px;
}

.auto-answer-desc {
  margin-top: 8px;
  margin-bottom: 0;
  line-height: 1.4;
  color: var(--text-muted);
}

.btn-highlight {
  background: rgba(37, 211, 102, 0.18);
  border: 1px solid #25d366;
  color: #25d366;
  font-weight: 700;
}

.btn-highlight:hover {
  background: #25d366;
  color: #000;
}

/* Stream Output & Player */
.stream-url-box {
  margin-bottom: 16px;
}

.stream-player-container {
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #000;
  border-radius: 8px;
  overflow: hidden;
  margin-bottom: 16px;
  border: 1px solid var(--border);
}

.stream-video {
  width: 100%;
  height: 100%;
  display: block;
}

/* Guide Steps */
.vcam-guide {
  background: var(--bg-input);
  border-radius: 8px;
  padding: 16px;
}

.vcam-guide h3 {
  font-size: 14px;
  margin-bottom: 12px;
  color: var(--text);
}

.guide-steps {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.step-card {
  display: flex;
  gap: 12px;
  background: var(--bg-card);
  padding: 10px 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
}

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

.step-card p {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: #1e293b;
  color: #fff;
  padding: 12px 20px;
  border-radius: 8px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
  border: 1px solid var(--border);
  font-size: 14px;
  font-weight: 500;
  z-index: 1000;
  transition: opacity 0.3s, transform 0.3s;
}

.toast.err {
  background: #7f1d1d;
  border-color: #ef4444;
}

.hidden {
  display: none !important;
}

.error-msg {
  color: var(--danger);
  font-size: 13px;
  margin-top: 8px;
  font-weight: 500;
}

/* Call Rules & Whitelist Styles */
.tags-container {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
  min-height: 42px;
  padding: 8px 12px;
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid var(--border);
  border-radius: 8px;
  align-items: center;
}

.number-tag {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: rgba(37, 211, 102, 0.12);
  color: #25d366;
  border: 1px solid rgba(37, 211, 102, 0.3);
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.5px;
}

.btn-remove-tag {
  background: none;
  border: none;
  color: #ef4444;
  cursor: pointer;
  font-weight: bold;
  font-size: 14px;
  line-height: 1;
  padding: 0 2px;
  transition: transform 0.15s, color 0.15s;
}

.btn-remove-tag:hover {
  color: #f87171;
  transform: scale(1.2);
}

.empty-tag-msg {
  color: var(--text-muted);
  font-style: italic;
}

/* Upload Drawer Tabs & URL Import */
.upload-drawer {
  margin-bottom: 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
}

.upload-tabs-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 10px;
}

.upload-tab-buttons {
  display: flex;
  gap: 8px;
}

.upload-tab-btn {
  background: transparent;
  border: 1px solid var(--border);
  padding: 6px 14px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s ease;
}

.upload-tab-btn:hover {
  color: var(--text-main);
  background: var(--bg-hover);
}

.upload-tab-btn.active {
  color: #fff;
  background: var(--primary);
  border-color: var(--primary);
}

.btn-close-drawer {
  background: transparent;
  border: none;
  font-size: 16px;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
  line-height: 1;
}

.btn-close-drawer:hover {
  color: #ef4444;
  background: rgba(239, 68, 68, 0.1);
}

.url-upload-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.url-action-row {
  display: flex;
  gap: 10px;
  align-items: center;
}

.url-status-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: rgba(59, 130, 246, 0.08);
  border: 1px solid rgba(59, 130, 246, 0.2);
  border-radius: 6px;
  margin-top: 6px;
}

.spinner-inline {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(59, 130, 246, 0.3);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin-inline 0.8s linear infinite;
}

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

.btn-xs {
  padding: 5px 11px;
  font-size: 0.8rem;
  font-weight: 600;
  border-radius: 6px;
  cursor: pointer;
  line-height: 1.2;
}

/* Video Library Manager Drawer */
.library-drawer {
  background: var(--bg-card, #1e293b);
  border: 1px solid var(--border-color, rgba(255, 255, 255, 0.1));
  border-radius: var(--radius-md, 8px);
  margin-top: 10px;
  margin-bottom: 16px;
  overflow: hidden;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.video-library-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.video-lib-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 12px;
  border-radius: 6px;
  border-bottom: 1px solid var(--border-color, rgba(255, 255, 255, 0.05));
  transition: background 0.15s ease;
}

.video-lib-item:last-child {
  border-bottom: none;
}

.video-lib-item:hover {
  background: rgba(255, 255, 255, 0.04);
}

.video-lib-left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  flex: 1;
}

.video-lib-thumb {
  width: 52px;
  height: 34px;
  object-fit: cover;
  border-radius: 4px;
  background: #000;
  border: 1px solid rgba(255, 255, 255, 0.1);
  flex-shrink: 0;
}

.video-lib-details {
  min-width: 0;
  flex: 1;
}

.video-lib-title {
  font-weight: 600;
  font-size: 0.88rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text-main, #f8fafc);
}

.video-lib-sub {
  font-size: 0.76rem;
  color: var(--text-muted, #94a3b8);
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 2px;
}

.video-lib-actions {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-shrink: 0;
}

