:root {
  --bg: #0b0f14;
  --bg-elev: #121821;
  --bg-elev-2: #172230;
  --surface: #131a24;
  --line: #23303f;
  --line-soft: #1a2532;
  --text: #e7eef5;
  --text-dim: #8ba0b3;
  --text-faint: #5c7186;
  --accent: #25d366;
  --accent-dim: #1faa52;
  --accent-glow: rgba(37, 211, 102, 0.18);
  --danger: #ff5c6c;
  --warn: #ffb020;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 18px 50px -20px rgba(0, 0, 0, 0.75);
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
}

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

body {
  font-family: var(--font);
  background:
    radial-gradient(1200px 600px at 80% -10%, rgba(37, 211, 102, 0.08), transparent 60%),
    radial-gradient(900px 500px at -10% 10%, rgba(45, 120, 255, 0.06), transparent 55%),
    var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
}

a { color: var(--accent); text-decoration: none; }
button { font-family: inherit; cursor: pointer; }
input, textarea, select {
  font-family: inherit;
  background: var(--bg);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 11px 13px;
  font-size: 14px;
  width: 100%;
  transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease);
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--accent-dim);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
textarea { resize: vertical; min-height: 96px; }
label { display: block; font-size: 12px; color: var(--text-dim); margin-bottom: 6px; font-weight: 500; letter-spacing: 0.01em; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid var(--line);
  background: var(--bg-elev);
  color: var(--text);
  border-radius: 999px;
  padding: 10px 18px;
  font-size: 13.5px; font-weight: 600; white-space: nowrap;
  transition: transform 0.12s var(--ease), background 0.15s, border-color 0.15s, box-shadow 0.15s;
}
.btn:hover { border-color: var(--line); background: var(--bg-elev-2); transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn-primary {
  background: linear-gradient(180deg, var(--accent), var(--accent-dim));
  border-color: transparent; color: #05130a;
  box-shadow: 0 8px 24px -10px var(--accent-glow);
}
.btn-primary:hover {
  /* Keep the green on hover — .btn:hover would otherwise override the background. */
  background: linear-gradient(180deg, #2ee06f, var(--accent));
  border-color: transparent;
  color: #05130a;
  box-shadow: 0 12px 30px -8px var(--accent-glow);
}
.btn-ghost { background: transparent; }
.btn-danger { color: var(--danger); border-color: transparent; background: rgba(255, 92, 108, 0.08); }
.btn-danger:hover { background: rgba(255, 92, 108, 0.16); }
.btn-sm { padding: 7px 13px; font-size: 12.5px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

/* ---------- Auth screen ---------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.auth-card {
  width: 100%; max-width: 400px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 34px 30px; box-shadow: var(--shadow);
}
.auth-card h1 { font-size: 22px; letter-spacing: -0.02em; }
.auth-card .sub { color: var(--text-dim); font-size: 13.5px; margin: 6px 0 26px; }
.field { margin-bottom: 16px; }
.auth-switch { text-align: center; font-size: 13px; color: var(--text-dim); margin-top: 18px; }
.err { color: var(--danger); font-size: 13px; margin-top: 12px; min-height: 18px; }
.ok { color: var(--accent); font-size: 13px; margin-top: 12px; }

/* ---------- App shell ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 26px; border-bottom: 1px solid var(--line-soft);
  position: sticky; top: 0; z-index: 20;
  background: rgba(11, 15, 20, 0.72); backdrop-filter: blur(14px);
}
.brand { display: flex; align-items: center; gap: 11px; font-weight: 700; letter-spacing: -0.01em; }
.brand .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 14px var(--accent); }
.topbar .who { color: var(--text-dim); font-size: 13px; }
.wrap { max-width: 1080px; margin: 0 auto; padding: 30px 26px 80px; }

.tabs { display: flex; gap: 4px; margin-bottom: 26px; border-bottom: 1px solid var(--line-soft); }
.tab {
  background: none; border: none; color: var(--text-dim);
  padding: 12px 16px; font-size: 14px; font-weight: 600;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--text); border-bottom-color: var(--accent); }

.section-head { display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap; margin-bottom: 18px; }
.section-head h2 { font-size: 18px; letter-spacing: -0.01em; }
.section-head p { color: var(--text-dim); font-size: 13px; margin-top: 3px; }

/* ---------- Cards / grid ---------- */
.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 18px 18px 16px;
  transition: border-color 0.15s, transform 0.15s var(--ease);
}
.card:hover { border-color: var(--line); transform: translateY(-2px); }
.card h3 { font-size: 15.5px; margin-bottom: 4px; letter-spacing: -0.01em; }
.card .meta { color: var(--text-faint); font-size: 12px; }
.card-actions { display: flex; gap: 8px; margin-top: 16px; flex-wrap: wrap; }

.badge {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 11.5px; font-weight: 600; padding: 4px 10px; border-radius: 999px;
  border: 1px solid var(--line); color: var(--text-dim);
}
.badge .pip { width: 7px; height: 7px; border-radius: 50%; background: var(--text-faint); }
.badge.connected { color: var(--accent); border-color: rgba(37,211,102,0.3); background: rgba(37,211,102,0.08); }
.badge.connected .pip { background: var(--accent); box-shadow: 0 0 8px var(--accent); }
.badge.qr, .badge.connecting, .badge.running, .badge.queued { color: var(--warn); border-color: rgba(255,176,32,0.3); background: rgba(255,176,32,0.07); }
.badge.qr .pip, .badge.connecting .pip, .badge.running .pip { background: var(--warn); animation: pulse 1.4s infinite; }
.badge.done { color: var(--accent); }
.badge.failed { color: var(--danger); }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.35; } }

/* ---------- Progress ---------- */
.progress { height: 8px; border-radius: 999px; background: var(--bg); overflow: hidden; margin-top: 14px; border: 1px solid var(--line-soft); }
.progress .bar { height: 100%; background: linear-gradient(90deg, var(--accent-dim), var(--accent)); width: 0%; transition: width 0.4s var(--ease); }
.stat-row { display: flex; gap: 18px; margin-top: 12px; font-size: 12.5px; }
.stat-row .n { font-weight: 700; font-size: 16px; letter-spacing: -0.02em; }
.stat-row .sent .n { color: var(--accent); }
.stat-row .failed .n { color: var(--danger); }
.stat-row .k { color: var(--text-faint); }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(4, 7, 11, 0.7);
  backdrop-filter: blur(6px); display: grid; place-items: center; z-index: 50; padding: 24px;
}
.modal {
  width: 100%; max-width: 480px; background: var(--bg-elev);
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 26px; box-shadow: var(--shadow); max-height: 90vh; overflow-y: auto;
}
.modal.wide { max-width: 620px; }
.modal h3 { font-size: 18px; margin-bottom: 4px; }
.modal .sub { color: var(--text-dim); font-size: 13px; margin-bottom: 20px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; }

.qr-box { display: grid; place-items: center; padding: 18px; background: #fff; border-radius: var(--radius-sm); margin: 8px 0 4px; min-height: 240px; }
.qr-box img { width: 240px; height: 240px; }
.qr-hint { color: var(--text-dim); font-size: 12.5px; text-align: center; margin-top: 10px; }

.dropzone {
  border: 1.5px dashed var(--line); border-radius: var(--radius-sm);
  padding: 22px; text-align: center; color: var(--text-dim); font-size: 13px;
  transition: border-color 0.15s, background 0.15s; cursor: pointer;
}
.dropzone:hover { border-color: var(--accent-dim); background: rgba(37,211,102,0.04); }
.dropzone strong { color: var(--text); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.chip { font-size: 11.5px; background: var(--bg-elev-2); border: 1px solid var(--line); padding: 4px 9px; border-radius: 6px; color: var(--text-dim); }
.chip code { color: var(--accent); font-family: ui-monospace, monospace; }

.empty { text-align: center; padding: 60px 20px; color: var(--text-faint); }
.empty .big { font-size: 40px; margin-bottom: 12px; opacity: 0.6; }

.toast-wrap { position: fixed; bottom: 22px; right: 22px; display: flex; flex-direction: column; gap: 10px; z-index: 80; }
.toast {
  background: var(--bg-elev-2); border: 1px solid var(--line);
  border-left: 3px solid var(--accent); padding: 12px 16px; border-radius: var(--radius-sm);
  font-size: 13px; box-shadow: var(--shadow); animation: slidein 0.3s var(--ease);
  max-width: 320px;
}
.toast.err { border-left-color: var(--danger); }
@keyframes slidein { from { opacity: 0; transform: translateX(20px); } }

.hint { color: var(--text-faint); font-size: 12px; margin-top: 6px; }
.spinner { width: 18px; height: 18px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.center-load { display: grid; place-items: center; padding: 60px; }

/* ---------- Campaign detail / stats ---------- */
.detail-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.detail-head h2 { font-size: 20px; letter-spacing: -0.02em; }
.detail-head .meta { color: var(--text-faint); font-size: 12.5px; margin-top: 3px; }
.stat-tiles { display: grid; grid-template-columns: repeat(6, 1fr); gap: 12px; margin-bottom: 20px; }
.stat-tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 14px 16px; }
.stat-tile .n { font-size: 24px; font-weight: 700; letter-spacing: -0.02em; }
.stat-tile .k { color: var(--text-faint); font-size: 11.5px; margin-top: 2px; font-weight: 500; }
.stat-tile.sent .n { color: var(--text); }
.stat-tile.delivered .n { color: #34d399; }
.stat-tile.read .n { color: #3b82f6; }
.stat-tile.failed .n { color: var(--danger); }
.stat-tile.pending .n { color: var(--text-dim); }

.chart-grid { display: grid; grid-template-columns: minmax(240px, 340px) 1fr; gap: 16px; margin-bottom: 20px; }
.chart-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; }
.chart-card h4 { font-size: 13px; color: var(--text-dim); font-weight: 600; margin-bottom: 16px; letter-spacing: 0.01em; }
.donut-wrap { display: flex; align-items: center; gap: 20px; flex-wrap: wrap; }
.donut-center { font-weight: 700; }
.legend { display: flex; flex-direction: column; gap: 9px; font-size: 13px; }
.legend .row { display: flex; align-items: center; gap: 9px; color: var(--text-dim); }
.legend .row .sw { width: 10px; height: 10px; border-radius: 3px; }
.legend .row b { color: var(--text); margin-left: auto; font-variant-numeric: tabular-nums; }

.funnel { display: flex; flex-direction: column; gap: 16px; }
.funnel .stage .top { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 6px; }
.funnel .stage .top .lbl { color: var(--text-dim); font-weight: 500; }
.funnel .stage .top .val { font-weight: 700; font-variant-numeric: tabular-nums; }
.funnel .stage .track { height: 12px; background: var(--bg); border: 1px solid var(--line-soft); border-radius: 999px; overflow: hidden; }
.funnel .stage .track i { display: block; height: 100%; border-radius: 999px; transition: width 0.5s var(--ease); }
.funnel .pct { color: var(--text-faint); font-size: 11.5px; margin-left: 8px; }

.rcpt-table { width: 100%; border-collapse: collapse; }
.rcpt-table th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-faint); font-weight: 600; padding: 0 12px 10px; }
.rcpt-table td { padding: 11px 12px; border-top: 1px solid var(--line-soft); font-size: 13.5px; }
.rcpt-table .ph { font-variant-numeric: tabular-nums; }
.rstat { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; }
.rstat .dot2 { width: 7px; height: 7px; border-radius: 50%; }
.rstat.read { color: #3b82f6; } .rstat.read .dot2 { background: #3b82f6; }
.rstat.delivered { color: #34d399; } .rstat.delivered .dot2 { background: #34d399; }
.rstat.sent { color: var(--text-dim); } .rstat.sent .dot2 { background: var(--text-dim); }
.rstat.failed { color: var(--danger); } .rstat.failed .dot2 { background: var(--danger); }
.rstat.pending { color: var(--text-faint); } .rstat.pending .dot2 { background: var(--text-faint); }

@media (max-width: 760px) {
  .stat-tiles { grid-template-columns: repeat(3, 1fr); }
  .chart-grid { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
  .wrap { padding: 22px 16px 64px; }
  .topbar { padding: 14px 16px; }
  .who { display: none; }
  .stat-tiles { grid-template-columns: repeat(2, 1fr); }
  .tabs { overflow-x: auto; }
  .tab { white-space: nowrap; }
  .detail-head { align-items: flex-start; }
}
