:root {
  --bg: #f8f5f2;
  --card-bg: #ffffff;
  --text: #1f2421;
  --muted: #68706c;
  --border: #e6dfd8;
  --primary: #8b2635;
  --primary-hover: #6f1d2a;
  --accent: #b8860b;
  --success: #1b8755;
  --warning: #d97706;
  --danger: #dc2626;
  --wa-dark-bg: #0b141a;
  --wa-bubble-bg: #202c33;
  --wa-doc-bg: #182229;
  --wa-text: #e9edef;
  --wa-subtext: #8696a0;
}

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

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

/* Header */
.topbar {
  background: linear-gradient(135deg, #5c1622 0%, #8b2635 100%);
  color: #fff;
  padding: 16px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.12);
}

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

.brand-icon {
  font-size: 32px;
  background: rgba(255, 255, 255, 0.14);
  width: 52px;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
}

.brand h1 {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.2px;
}

.subtitle {
  font-size: 13px;
  color: rgba(255, 255, 255, 0.85);
}

/* Status Badge */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 14px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
}

.status-badge .dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #fbbf24;
}

.status-badge.connected {
  background: rgba(27, 135, 85, 0.95);
}

.status-badge.connected .dot {
  background: #4ade80;
  box-shadow: 0 0 8px #4ade80;
}

.status-badge.disconnected .dot {
  background: #f87171;
}

/* Layout */
.container {
  max-width: 1440px;
  margin: 22px auto;
  padding: 0 22px;
  display: grid;
  grid-template-columns: 1.05fr 1fr;
  gap: 22px;
  align-items: start;
}

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

.left-col,
.right-col {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.03);
}

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

.card-header h2 {
  font-size: 16px;
  font-weight: 700;
  color: #2c1810;
}

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

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: all 0.15s ease;
}

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

.btn-xs {
  padding: 4px 10px;
  font-size: 12px;
  border-radius: 6px;
}

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

.btn-lg {
  padding: 10px 18px;
  font-size: 14px;
}

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

.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

.btn-accent {
  background: #1f2937;
  color: #fff;
}

.btn-accent:hover:not(:disabled) {
  background: #111827;
}

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

.btn-success:hover:not(:disabled) {
  background: #146c43;
}

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

.btn-outline {
  background: #fff;
  border-color: #d1c7be;
  color: var(--text);
}

.btn-outline:hover:not(:disabled) {
  background: #f5f0eb;
}

.btn-danger-outline {
  background: #fff;
  border-color: #fca5a5;
  color: var(--danger);
}

.btn-danger-outline:hover:not(:disabled) {
  background: #fef2f2;
}

.badge-pill {
  font-size: 11.5px;
  background: #fef3c7;
  color: #92400e;
  padding: 4px 10px;
  border-radius: 999px;
  font-weight: 600;
}

/* WhatsApp QR Box */
.wa-state-box {
  display: flex;
  gap: 20px;
  align-items: center;
}

.qr-wrapper {
  width: 190px;
  height: 190px;
  border: 2px dashed var(--border);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fafafa;
  flex-shrink: 0;
  overflow: hidden;
}

.qr-wrapper img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.qr-loader {
  text-align: center;
  padding: 14px;
  font-size: 12px;
  color: var(--muted);
}

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

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

.qr-instructions h3 {
  font-size: 15px;
  margin-bottom: 8px;
}

.qr-instructions ol {
  padding-left: 18px;
  font-size: 13px;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.wa-connected-box {
  display: flex;
  align-items: center;
  gap: 16px;
  background: #ecfdf5;
  border: 1px solid #a7f3d0;
  padding: 14px 18px;
  border-radius: 10px;
}

.connected-icon {
  font-size: 28px;
}

.connected-details h3 {
  font-size: 15px;
  color: #065f46;
}

.connected-details p {
  font-size: 13.5px;
  font-weight: 600;
  color: #047857;
}

.connected-hint {
  font-size: 12px;
  color: #059669;
}

/* PDF Upload Area */
.pdf-upload-area {
  border: 2px dashed #d6cbc1;
  border-radius: 12px;
  padding: 16px;
  background: #fcfaf8;
  cursor: pointer;
  transition: border-color 0.2s;
}

.pdf-upload-area:hover {
  border-color: var(--primary);
}

.pdf-upload-prompt {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.pdf-icon-large {
  font-size: 30px;
}

.upload-title {
  font-size: 14px;
  font-weight: 600;
}

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

.pdf-active-banner {
  margin-top: 12px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: #fff8f6;
  border: 1px solid #f3d8d4;
  border-radius: 10px;
}

.pdf-badge-icon {
  background: #e11d48;
  color: #fff;
  font-weight: 800;
  font-size: 11px;
  padding: 8px 7px;
  border-radius: 6px;
  letter-spacing: 0.5px;
}

.pdf-meta-text {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
}

.pdf-meta-text strong {
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

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

.tag-ready {
  background: #dcfce7;
  color: #166534;
  font-size: 11.5px;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 999px;
}

/* Template & WhatsApp Live Preview */
.template-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

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

.field-label {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 6px;
}

.field-label code {
  background: #f3e8e5;
  color: var(--primary);
  padding: 1px 5px;
  border-radius: 4px;
}

textarea#templateInput {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  font-family: inherit;
  font-size: 13.5px;
  line-height: 1.5;
  resize: vertical;
  background: #fffdfb;
}

.template-helper {
  margin-top: 8px;
  font-size: 12px;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.preview-name-control {
  display: flex;
  align-items: center;
  gap: 8px;
}

.preview-name-control input {
  flex: 1;
  padding: 5px 9px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 12.5px;
}

/* Authentic WhatsApp Dark Bubble Preview */
.wa-preview-wrapper {
  display: flex;
  flex-direction: column;
}

.wa-preview-label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 6px;
}

.wa-chat-bg {
  background-color: var(--wa-dark-bg);
  background-image: radial-gradient(rgba(255, 255, 255, 0.04) 1px, transparent 0);
  background-size: 18px 18px;
  border-radius: 12px;
  padding: 14px;
  flex: 1;
  display: flex;
  align-items: flex-start;
  justify-content: center;
}

.wa-bubble {
  background: var(--wa-bubble-bg);
  color: var(--wa-text);
  border-radius: 10px;
  padding: 6px;
  width: 100%;
  max-width: 330px;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.35);
  position: relative;
}

.wa-doc-card {
  background: var(--wa-doc-bg);
  border-radius: 8px;
  overflow: hidden;
  margin-bottom: 8px;
}

.wa-doc-thumb {
  width: 100%;
  height: 105px;
  background: linear-gradient(135deg, #fce7f3 0%, #f3e8ff 50%, #fef3c7 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.wa-doc-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: top center;
}

.wa-doc-thumb-placeholder {
  color: #6b21a8;
  font-size: 12px;
  font-weight: 600;
  text-align: center;
  padding: 10px;
}

.wa-doc-info {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
}

.wa-pdf-badge {
  background: #ef4444;
  color: #fff;
  font-size: 10px;
  font-weight: 800;
  padding: 7px 5px;
  border-radius: 5px;
  line-height: 1;
}

.wa-doc-meta {
  min-width: 0;
  flex: 1;
}

.wa-doc-filename {
  font-size: 13.5px;
  color: #e9edef;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.wa-doc-sub {
  font-size: 11.5px;
  color: var(--wa-subtext);
}

.wa-caption {
  padding: 2px 6px 16px 6px;
  font-size: 13.2px;
  line-height: 1.42;
  white-space: pre-wrap;
  word-break: break-word;
}

.wa-time {
  position: absolute;
  bottom: 5px;
  right: 10px;
  font-size: 10.5px;
  color: var(--wa-subtext);
}

/* Test Send Bar */
.test-send-bar {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.test-send-title {
  font-size: 13px;
  font-weight: 700;
  color: #374151;
}

.test-send-inputs {
  display: grid;
  grid-template-columns: 1fr 1.2fr auto;
  gap: 8px;
}

.test-send-inputs input {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
}

/* Settings & Campaign Controls */
.settings-row {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.setting-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.setting-field label {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--muted);
}

.setting-field input {
  width: 95px;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13.5px;
}

.input-prefix-wrap {
  display: flex;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding-left: 9px;
  background: #fff;
}

.input-prefix-wrap span {
  color: var(--muted);
  font-weight: 600;
  font-size: 13.5px;
}

.input-prefix-wrap input {
  border: none;
  width: 65px;
  padding-left: 3px;
  outline: none;
}

.setting-actions {
  margin-left: auto;
  display: flex;
  gap: 8px;
}

.countdown-badge {
  background: #eff6ff;
  color: #1d4ed8;
  border: 1px solid #bfdbfe;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
}

/* Stats Grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-bottom: 12px;
}

.stat-box {
  background: #f9fafb;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  text-align: center;
}

.stat-box.pending {
  background: #fffbeb;
  border-color: #fde68a;
}

.stat-box.sent {
  background: #ecfdf5;
  border-color: #a7f3d0;
}

.stat-box.failed {
  background: #fef2f2;
  border-color: #fecaca;
}

.stat-num {
  display: block;
  font-size: 20px;
  font-weight: 800;
}

.stat-label {
  font-size: 11.5px;
  color: var(--muted);
  font-weight: 600;
}

.progress-bar-outer {
  height: 8px;
  background: #e5e7eb;
  border-radius: 999px;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--success));
  transition: width 0.3s ease;
}

/* Guest Table */
.add-guest-bar {
  display: grid;
  grid-template-columns: 0.8fr 1.4fr auto;
  gap: 8px;
  margin-bottom: 12px;
}

.add-guest-bar input {
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
}

.table-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
  gap: 8px;
  flex-wrap: wrap;
}

.table-hint {
  font-size: 12px;
  color: var(--muted);
}

.table-toolbar-btns {
  display: flex;
  gap: 6px;
}

.table-scroll {
  max-height: 390px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 10px;
}

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

.guest-table thead {
  position: sticky;
  top: 0;
  background: #f5f0eb;
  z-index: 1;
}

.guest-table th,
.guest-table td {
  padding: 9px 10px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.guest-table tbody tr {
  cursor: pointer;
  transition: background 0.12s;
}

.guest-table tbody tr:hover {
  background: #fdf8f6;
}

.guest-table .empty-row td {
  text-align: center;
  padding: 28px;
  color: var(--muted);
}

.status-tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}

.status-tag.pending {
  background: #fef3c7;
  color: #92400e;
}

.status-tag.sending {
  background: #dbeafe;
  color: #1e40af;
}

.status-tag.sent {
  background: #dcfce7;
  color: #166534;
}

.status-tag.failed {
  background: #fee2e2;
  color: #991b1b;
}

.row-actions {
  display: flex;
  gap: 5px;
}

/* Logs */
.log-container {
  background: #18181b;
  color: #e4e4e7;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 12px;
  padding: 12px;
  border-radius: 10px;
  height: 170px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.log-item {
  line-height: 1.4;
}

.log-item .log-time {
  color: #71717a;
  margin-right: 6px;
}

.log-item.success {
  color: #4ade80;
}

.log-item.error {
  color: #f87171;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 22px;
  right: 22px;
  background: #1f2937;
  color: #fff;
  padding: 12px 18px;
  border-radius: 10px;
  font-size: 13.5px;
  font-weight: 600;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
  z-index: 999;
}

.hidden {
  display: none !important;
}
