:root {
  --bg: #f4f6fb;
  --bg-elev: #ffffff;
  --bg-elev-2: #eef2f9;
  --surface: #ffffff;
  --border: #dde3ee;
  --border-soft: #eaeef6;
  --text: #0f172a;
  --text-dim: #475569;
  --text-mute: #94a3b8;
  --brand: #6366f1;
  --brand-2: #8b5cf6;
  --accent: #0891b2;
  --green: #15a34a;
  --green-bg: #16a34a1f;
  --blue: #2563eb;
  --blue-bg: #2563eb17;
  --amber: #d97706;
  --amber-bg: #f59e0b24;
  --red: #dc2626;
  --red-bg: #ef44441c;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 18px 40px -22px rgba(15, 23, 42, 0.3);
  --card-shadow: 0 1px 2px rgba(15, 23, 42, 0.04), 0 8px 24px -18px rgba(15, 23, 42, 0.25);
  --ring: 0 0 0 3px rgba(99, 102, 241, 0.28);
  --sb-thumb: #c6cfdd;
  --sb-thumb-hover: #97a3b8;
}

* { box-sizing: border-box; }

/* ── Premium scrollbars ────────────────────────────────── */
* { scrollbar-width: thin; scrollbar-color: var(--sb-thumb) transparent; }
::-webkit-scrollbar { width: 11px; height: 11px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--sb-thumb);
  border-radius: 999px;
  border: 3px solid transparent;
  background-clip: padding-box;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--sb-thumb-hover);
  background-clip: padding-box;
}
::-webkit-scrollbar-corner { background: transparent; }

html, body {
  margin: 0;
  height: 100%;
}

body {
  font-family: "Inter", system-ui, -apple-system, sans-serif;
  height: 100%;
  overflow: hidden;
  background: radial-gradient(1200px 600px at 12% -10%, #e7ecfb 0%, transparent 55%),
    radial-gradient(1000px 520px at 100% 0%, #f0e9fb 0%, transparent 50%), var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

.app-root { min-height: 100%; }

.boot {
  display: grid;
  place-items: center;
  min-height: 100vh;
  color: var(--text-mute);
  font-size: 14px;
}

/* ── Login ─────────────────────────────────────────────── */
.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 34px 30px;
}

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

.brand-logo {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  display: grid;
  place-items: center;
  font-weight: 700;
  color: white;
  box-shadow: 0 8px 20px -8px var(--brand);
}

.brand h1 {
  font-size: 18px;
  margin: 0;
  letter-spacing: -0.01em;
}

.login-sub {
  color: var(--text-dim);
  font-size: 13px;
  margin: 4px 0 26px;
}

.field { margin-bottom: 14px; }

.field label {
  display: block;
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 6px;
  font-weight: 500;
}

input,
select,
button {
  font-family: inherit;
  font-size: 14px;
}

.input {
  width: 100%;
  padding: 11px 13px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--text);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.input:focus {
  border-color: var(--brand);
  box-shadow: var(--ring);
}

.btn {
  cursor: pointer;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 11px 16px;
  font-weight: 600;
  color: white;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  transition: transform 0.08s, filter 0.15s, opacity 0.15s;
}

.btn:hover { filter: brightness(1.08); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }

.btn-block { width: 100%; margin-top: 6px; }

.btn-ghost {
  background: var(--bg-elev-2);
  border-color: var(--border);
  color: var(--text-dim);
}
.btn-ghost:hover { color: var(--text); filter: none; background: var(--border-soft); }

.form-error {
  color: var(--red);
  font-size: 13px;
  min-height: 18px;
  margin: 10px 0 0;
}

/* ── App shell ─────────────────────────────────────────── */
.shell {
  width: 75%;
  max-width: 1600px;
  min-width: 0;
  height: 100vh;
  margin: 0 auto;
  padding: 20px 22px 22px;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 4px 2px 20px;
  flex-wrap: wrap;
  flex-shrink: 0;
}

.topbar .brand h1 { font-size: 17px; }

.phone-pill {
  font-size: 12px;
  color: var(--text-dim);
  background: var(--bg-elev-2);
  border: 1px solid var(--border-soft);
  padding: 3px 10px;
  border-radius: 999px;
  margin-top: 2px;
  display: inline-block;
}

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

/* Connection status pill */
.conn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  font-weight: 600;
  padding: 5px 11px;
  border-radius: 999px;
  border: 1px solid var(--border-soft);
  background: var(--bg-elev-2);
  white-space: nowrap;
  user-select: none;
}
.conn-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-dim);
  flex-shrink: 0;
}
.conn.online { color: var(--green); border-color: color-mix(in srgb, var(--green) 30%, transparent); background: color-mix(in srgb, var(--green) 10%, var(--bg-elev-2)); }
.conn.online .conn-dot { background: var(--green); box-shadow: 0 0 0 3px color-mix(in srgb, var(--green) 22%, transparent); }
.conn.offline { color: var(--red); border-color: color-mix(in srgb, var(--red) 32%, transparent); background: color-mix(in srgb, var(--red) 10%, var(--bg-elev-2)); }
.conn.offline .conn-dot { background: var(--red); animation: conn-blink 1.1s ease-in-out infinite; }
.conn.pending { color: var(--text-dim); }
.conn.pending .conn-dot { background: #f59e0b; animation: conn-blink 1.1s ease-in-out infinite; }

@keyframes conn-blink {
  0%, 100% { opacity: 1; }
  50% { opacity: .3; }
}

/* WhatsApp usage progress */
.wa-progress {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 13px;
  color: var(--text-dim);
  flex: 0 1 auto;
  min-width: 0;
}
.wa-progress:empty { display: none; }
.wa-ico {
  display: inline-flex;
  color: var(--green);
}
.wa-ico svg { width: 16px; height: 16px; }
.wa-text { white-space: nowrap; }
.wa-text strong { color: var(--text); font-weight: 700; }
.wa-total { color: var(--text-dim); }
.wa-bar {
  position: relative;
  width: 120px;
  height: 7px;
  border-radius: 999px;
  background: var(--bg-elev-2);
  border: 1px solid var(--border-soft);
  overflow: hidden;
}
.wa-fill {
  position: absolute;
  inset: 0 auto 0 0;
  height: 100%;
  border-radius: 999px;
  background: var(--green);
  transition: width .4s ease;
}
.wa-fill.warn { background: #f59e0b; }
.wa-fill.danger { background: var(--red); }

@media (max-width: 900px) {
  .wa-bar { width: 80px; }
}

/* Language toggle (ES | EN) */
.lang {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 9px;
  overflow: hidden;
  background: var(--bg-elev);
}
.lang-btn {
  border: 0;
  background: transparent;
  color: var(--text-dim);
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .02em;
  padding: 7px 12px;
  cursor: pointer;
  transition: background .12s ease, color .12s ease;
}
.lang-btn + .lang-btn { border-left: 1px solid var(--border); }
.lang-btn:hover { color: var(--text); background: var(--bg-elev-2); }
.lang-btn.active { background: var(--brand); color: #fff; }

.login-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.switch {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-dim);
  user-select: none;
  cursor: pointer;
}

.switch input { accent-color: var(--brand); width: 15px; height: 15px; }

/* ── Stats ─────────────────────────────────────────────── */
.stats {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 12px;
  margin-bottom: 18px;
  flex-shrink: 0;
}

.stat {
  background: var(--bg-elev);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--card-shadow);
}

.stat .label {
  font-size: 12px;
  color: var(--text-mute);
  display: flex;
  align-items: center;
  gap: 6px;
}

.stat .value {
  font-size: 26px;
  font-weight: 700;
  margin-top: 6px;
  letter-spacing: -0.02em;
}

.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.dot.sms { background: var(--blue); }
.dot.whatsapp { background: var(--green); }
.dot.delivered { background: var(--green); }
.dot.failed { background: var(--red); }

/* ── Toolbar ───────────────────────────────────────────── */
.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 14px;
  flex-shrink: 0;
}

.search {
  position: relative;
  flex: 1;
  min-width: 220px;
}

.search .input { padding-left: 36px; }

.search svg {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-mute);
}

.select {
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  padding: 10px 38px 10px 13px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background-color: var(--bg-elev);
  color: var(--text);
  outline: none;
  cursor: pointer;
  font-weight: 500;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 11px center;
  background-size: 16px;
  transition: border-color 0.15s, box-shadow 0.15s, background-color 0.15s;
}
.select:hover { border-color: #c4ccdb; }
.select:focus { border-color: var(--brand); box-shadow: var(--ring); }
.select option { color: var(--text); background: #ffffff; padding: 8px; }

/* ── Custom dropdown ──────────────────────────────── */
.dd { position: relative; }

.dd-trigger {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--text);
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.dd-trigger:hover { border-color: #c4ccdb; }
.dd.open .dd-trigger { border-color: var(--brand); box-shadow: var(--ring); }

.dd-label {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  white-space: nowrap;
}
.dd-label svg { width: 14px; height: 14px; }
.dd-label .ico-wa { color: var(--green); }
.dd-label .ico-sms { color: var(--blue); }

.dd-caret {
  margin-left: 2px;
  color: var(--text-mute);
  transition: transform 0.18s ease;
}
.dd.open .dd-caret { transform: rotate(180deg); }

.dd-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 50;
  min-width: 100%;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 6px;
  box-shadow: 0 14px 36px -12px rgba(15, 23, 42, 0.28), 0 2px 8px rgba(15, 23, 42, 0.06);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(-4px) scale(0.98);
  transform-origin: top;
  transition: opacity 0.14s ease, transform 0.14s ease, visibility 0.14s;
}
.dd.open .dd-menu {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: none;
}

.dd-opt {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  width: 100%;
  padding: 9px 11px;
  border: none;
  background: transparent;
  border-radius: 8px;
  font: inherit;
  color: var(--text-dim);
  text-align: left;
  white-space: nowrap;
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
}
.dd-opt-l { display: inline-flex; align-items: center; gap: 8px; }
.dd-opt-l svg { width: 15px; height: 15px; }
.dd-opt .ico-wa { color: var(--green); }
.dd-opt .ico-sms { color: var(--blue); }
.dd-opt:hover { background: #f1f4fb; color: var(--text); }
.dd-opt .dd-check { color: var(--brand); opacity: 0; flex-shrink: 0; }
.dd-opt.is-selected { background: #eef1fe; color: var(--text); font-weight: 600; }
.dd-opt.is-selected .dd-check { opacity: 1; }

/* ── Table ─────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--card-shadow);
  flex: 1 1 auto;
  min-height: 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.table-scroll { overflow: auto; flex: 1 1 auto; min-height: 0; }

table { width: 100%; border-collapse: collapse; }

thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f7f9fd;
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 600;
  text-align: left;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tbody td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-soft);
  font-size: 13.5px;
  vertical-align: middle;
}

tbody tr { transition: background 0.12s; }
tbody tr:hover { background: #f5f8ff; }
tbody tr:last-child td { border-bottom: none; }

.mono { font-variant-numeric: tabular-nums; color: var(--text-dim); white-space: nowrap; }
.num { font-weight: 500; }

.body-cell {
  color: var(--text);
  overflow-wrap: anywhere;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  white-space: nowrap;
}

.badge.whatsapp { background: var(--green-bg); color: var(--green); }
.badge.sms { background: var(--blue-bg); color: var(--blue); }
.badge svg { width: 13px; height: 13px; }

.stat-ico { display: inline-flex; align-items: center; }
.stat-ico svg { width: 14px; height: 14px; }
.stat-ico.sms { color: var(--blue); }
.stat-ico.whatsapp { color: var(--green); }

.dir {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: var(--text-dim);
  white-space: nowrap;
}
.dir.inbound { color: var(--green); }
.dir.outbound { color: var(--blue); }

.status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 500;
  text-transform: capitalize;
}
.status::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--text-mute); }
.status.ok { color: var(--green); }
.status.ok::before { background: var(--green); }
.status.pending { color: var(--amber); }
.status.pending::before { background: var(--amber); }
.status.bad { color: var(--red); }
.status.bad::before { background: var(--red); }

/* ── States ────────────────────────────────────────────── */
.state {
  padding: 60px 20px;
  text-align: center;
  color: var(--text-mute);
  font-size: 14px;
}

.state .title { color: var(--text-dim); font-weight: 600; margin-bottom: 6px; }

.banner {
  margin: 0 0 14px;
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  border: 1px solid var(--red-bg);
  background: var(--red-bg);
  color: var(--red);
}

.spinner {
  width: 22px;
  height: 22px;
  border: 2.5px solid var(--border);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 12px;
}

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

.footnote {
  color: var(--text-mute);
  font-size: 12px;
  text-align: right;
  margin-top: 10px;
  flex-shrink: 0;
}

@media (max-width: 1100px) {
  .shell { width: 92%; }
}
@media (max-width: 900px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 560px) {
  .stats { grid-template-columns: 1fr; }
  .col-price, .col-error { display: none; }
}
