*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
.hidden { display: none !important; }

:root {
  --blue: #1F93FF;
  --blue-dark: #0d7ee8;
  --blue-light: #e8f4ff;
  --green: #44CE4B;
  --red: #F94B4B;
  --orange: #FF7E00;
  --gray-50: #F9FAFB;
  --gray-100: #F3F4F6;
  --gray-200: #E5E7EB;
  --gray-300: #D1D5DB;
  --gray-500: #6B7280;
  --gray-700: #374151;
  --gray-900: #111827;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,.1), 0 2px 4px -1px rgba(0,0,0,.06);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px;
  color: var(--gray-900);
  background: var(--gray-50);
  height: 100vh;
  overflow: hidden;
}

/* ── Layout ── */
#app { display: flex; flex-direction: column; height: 100vh; }

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  height: 56px;
  background: #fff;
  border-bottom: 1px solid var(--gray-200);
  flex-shrink: 0;
  box-shadow: var(--shadow);
}

header h1 { font-size: 16px; font-weight: 600; color: var(--gray-900); }

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

.content {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ── Sidebar ── */
.sidebar {
  width: 280px;
  flex-shrink: 0;
  background: #fff;
  border-right: 1px solid var(--gray-200);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--gray-200);
}

.sidebar-header select {
  width: 100%;
  padding: 6px 10px;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius);
  font-size: 13px;
  background: var(--gray-50);
  color: var(--gray-700);
  cursor: pointer;
}

#campaigns-list {
  flex: 1;
  overflow-y: auto;
  list-style: none;
  padding: 8px 0;
}

.campaign-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  cursor: pointer;
  border-left: 3px solid transparent;
  transition: background .15s, border-color .15s;
}

.campaign-item:hover { background: var(--gray-50); }
.campaign-item.active { background: var(--blue-light); border-left-color: var(--blue); }

.campaign-item .status-icon { font-size: 16px; flex-shrink: 0; }

.campaign-item .campaign-info { flex: 1; min-width: 0; }
.campaign-item .campaign-name {
  font-weight: 500;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.campaign-item .campaign-meta { font-size: 11px; color: var(--gray-500); margin-top: 2px; }

.empty-list {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  color: var(--gray-500);
  text-align: center;
  gap: 8px;
}
.empty-list .empty-icon { font-size: 32px; }

/* ── Main panel ── */
.panel {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  background: var(--gray-50);
}

.panel-title {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 20px;
  color: var(--gray-900);
}

/* ── Cards ── */
.card {
  background: #fff;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}

/* ── Form ── */
.form-group { margin-bottom: 16px; }
.form-label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--gray-700);
  margin-bottom: 6px;
}
.form-label small { font-weight: 400; color: var(--gray-500); }

.form-input,
.form-textarea,
.form-select {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius);
  font-size: 14px;
  font-family: inherit;
  color: var(--gray-900);
  background: #fff;
  transition: border-color .15s, box-shadow .15s;
}

.form-input:focus,
.form-textarea:focus,
.form-select:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(31,147,255,.15);
}

.form-textarea { resize: vertical; min-height: 100px; }

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

/* Tags selector */
.tags-container {
  border: 1px solid var(--gray-300);
  border-radius: var(--radius);
  padding: 8px;
  min-height: 42px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  cursor: text;
  background: #fff;
  transition: border-color .15s, box-shadow .15s;
}
.tags-container:focus-within {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(31,147,255,.15);
}

.tag-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  background: var(--blue-light);
  color: var(--blue);
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
}
.tag-badge .remove-tag {
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  opacity: .7;
}
.tag-badge .remove-tag:hover { opacity: 1; }

.tags-dropdown {
  position: relative;
}
.tags-options {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: #fff;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  z-index: 100;
  max-height: 200px;
  overflow-y: auto;
  margin-top: 4px;
}
.tags-options.open { display: block; }
.tag-option {
  padding: 8px 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}
.tag-option:hover { background: var(--gray-50); }
.tag-option.selected { color: var(--blue); }
.tag-option .dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}
.tags-loading { padding: 10px 12px; color: var(--gray-500); font-size: 13px; }

/* Checkbox group */
.checkbox-group { display: flex; flex-wrap: wrap; gap: 8px; }
.checkbox-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  cursor: pointer;
  padding: 6px 10px;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius);
  transition: all .15s;
  user-select: none;
}
.checkbox-label:hover { border-color: var(--blue); background: var(--blue-light); }
.checkbox-label input { display: none; }
.checkbox-label.checked {
  border-color: var(--blue);
  background: var(--blue-light);
  color: var(--blue);
  font-weight: 500;
}

/* Toggle */
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  border-top: 1px solid var(--gray-100);
}
.toggle-label { font-size: 13px; color: var(--gray-700); }
.toggle {
  position: relative;
  width: 40px;
  height: 22px;
  flex-shrink: 0;
}
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--gray-300);
  border-radius: 22px;
  cursor: pointer;
  transition: background .2s;
}
.toggle-slider::before {
  content: '';
  position: absolute;
  width: 16px; height: 16px;
  left: 3px; top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: transform .2s;
}
.toggle input:checked ~ .toggle-slider { background: var(--blue); }
.toggle input:checked ~ .toggle-slider::before { transform: translateX(18px); }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: none;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all .15s;
  white-space: nowrap;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }

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

.btn-secondary {
  background: var(--gray-100);
  color: var(--gray-700);
  border: 1px solid var(--gray-300);
}
.btn-secondary:hover:not(:disabled) { background: var(--gray-200); }

.btn-danger { background: #FEE2E2; color: var(--red); }
.btn-danger:hover:not(:disabled) { background: #FECACA; }

.btn-success { background: #DCFCE7; color: #16A34A; }
.btn-success:hover:not(:disabled) { background: #BBF7D0; }

.btn-icon {
  padding: 8px;
  background: transparent;
  color: var(--gray-500);
  border-radius: var(--radius);
}
.btn-icon:hover { background: var(--gray-100); color: var(--gray-700); }

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

.form-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 8px; }

/* ── Stats ── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}
.stat-card {
  background: #fff;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
  box-shadow: var(--shadow);
}
.stat-value { font-size: 28px; font-weight: 700; color: var(--gray-900); }
.stat-label { font-size: 12px; color: var(--gray-500); margin-top: 2px; }
.stat-card.success .stat-value { color: var(--green); }
.stat-card.danger .stat-value { color: var(--red); }
.stat-card.info .stat-value { color: var(--blue); }

/* ── Table ── */
.table-wrap { overflow-x: auto; }
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
thead th {
  background: var(--gray-50);
  padding: 10px 12px;
  text-align: left;
  font-weight: 600;
  color: var(--gray-500);
  border-bottom: 1px solid var(--gray-200);
  white-space: nowrap;
}
tbody td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--gray-100);
  color: var(--gray-700);
}
tbody tr:hover td { background: var(--gray-50); }
tbody tr:last-child td { border-bottom: none; }

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
}
.status-pill.sent { background: #DCFCE7; color: #16A34A; }
.status-pill.failed { background: #FEE2E2; color: var(--red); }
.status-pill.pending { background: #FEF3C7; color: #92400E; }
.status-pill.running { background: var(--blue-light); color: var(--blue); }
.status-pill.completed { background: #DCFCE7; color: #16A34A; }

/* ── Settings overlay ── */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.4);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.overlay.hidden { display: none; }

.settings-panel {
  background: #fff;
  border-radius: 12px;
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,.2);
}
.settings-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--gray-200);
  position: sticky;
  top: 0;
  background: #fff;
  z-index: 1;
}
.settings-panel-header h2 { font-size: 16px; font-weight: 600; }
.settings-panel-body { padding: 20px 24px 24px; }

.section-title {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--gray-500);
  margin-bottom: 12px;
  margin-top: 20px;
}
.section-title:first-child { margin-top: 0; }

/* ── Alert / Toast ── */
.toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 999;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  font-size: 13px;
  font-weight: 500;
  animation: slideIn .2s ease;
  max-width: 320px;
}
.toast.success { background: #DCFCE7; color: #16A34A; border: 1px solid #86EFAC; }
.toast.error { background: #FEE2E2; color: var(--red); border: 1px solid #FCA5A5; }
.toast.info { background: var(--blue-light); color: var(--blue); border: 1px solid #93C5FD; }

@keyframes slideIn {
  from { transform: translateX(40px); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* ── Misc ── */
.divider { height: 1px; background: var(--gray-200); margin: 16px 0; }
.text-muted { color: var(--gray-500); font-size: 12px; }
.flex { display: flex; }
.gap-2 { gap: 8px; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.mb-4 { margin-bottom: 16px; }
.loading-dots::after {
  content: '...';
  animation: dots 1.2s infinite;
}
@keyframes dots {
  0%, 100% { content: '.'; }
  33% { content: '..'; }
  66% { content: '...'; }
}

/* ── Setup screen ── */
#setup-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  padding: 40px;
  text-align: center;
}
#setup-screen .setup-icon { font-size: 48px; margin-bottom: 16px; }
#setup-screen h2 { font-size: 20px; font-weight: 600; margin-bottom: 8px; }
#setup-screen p { color: var(--gray-500); margin-bottom: 24px; max-width: 360px; }

/* ── Responsive ── */
@media (max-width: 640px) {
  .sidebar { width: 100%; }
  .content { flex-direction: column; }
  .form-row { grid-template-columns: 1fr; }
}

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--gray-300); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--gray-500); }

/* ── Contact count badge ── */
.contacts-count-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  background: var(--blue-light);
  color: var(--blue);
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
  margin-top: 6px;
}
.contacts-count-badge.loading { background: var(--gray-100); color: var(--gray-500); }
.contacts-count-badge.zero { background: #FEF3C7; color: #92400E; }

/* ── Send mode selector ── */
.send-mode-group {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}
.send-mode-option {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  border: 2px solid var(--gray-200);
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: all .15s;
  user-select: none;
  flex: 1;
  min-width: 140px;
}
.send-mode-option:hover { border-color: var(--blue); background: var(--blue-light); }
.send-mode-option input { display: none; }
.send-mode-option.selected {
  border-color: var(--blue);
  background: var(--blue-light);
  color: var(--blue);
}
.send-mode-icon { font-size: 18px; }

/* ── Template modal ── */
.template-panel {
  background: #fff;
  border-radius: 12px;
  width: 100%;
  max-width: 600px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 60px rgba(0,0,0,.2);
}
.template-panel-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--gray-200);
  flex-shrink: 0;
}
.template-panel-header h3 { font-size: 15px; font-weight: 600; margin-right: auto; }
.template-panel-header input {
  flex: 1;
  max-width: 220px;
  padding: 6px 12px;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius);
  font-size: 13px;
}
.template-panel-header input:focus {
  outline: none;
  border-color: var(--blue);
}
.template-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}
.template-group-title {
  padding: 8px 16px 4px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--gray-500);
  background: var(--gray-50);
  border-bottom: 1px solid var(--gray-100);
}
.template-item {
  padding: 12px 16px;
  cursor: pointer;
  border-bottom: 1px solid var(--gray-100);
  transition: background .1s;
}
.template-item:hover { background: var(--blue-light); }
.template-item:last-child { border-bottom: none; }
.template-item-name {
  font-weight: 600;
  font-size: 13px;
  color: var(--gray-900);
  margin-bottom: 3px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.template-item-name .tpl-badge {
  font-size: 10px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 10px;
  text-transform: uppercase;
}
.tpl-badge.whatsapp { background: #DCF8C6; color: #128C7E; }
.tpl-badge.canned { background: var(--gray-100); color: var(--gray-500); }
.template-item-body {
  font-size: 12px;
  color: var(--gray-500);
  line-height: 1.4;
  max-height: 48px;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.template-item-inbox {
  font-size: 11px;
  color: var(--blue);
  margin-top: 2px;
}
.template-empty {
  padding: 40px;
  text-align: center;
  color: var(--gray-500);
}
.template-label-group {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 4px;
}

