:root {
  color-scheme: dark;
  --bg: #0b1220;
  --surface: #121b2e;
  --surface-2: #17233b;
  --border: #263252;
  --text: #e7ecf7;
  --text-dim: #93a1c2;
  --text-faint: #647096;

  --accent: #4c8dff;
  --accent-soft: rgba(76, 141, 255, 0.14);
  --ok: #22d3aa;
  --ok-soft: rgba(34, 211, 170, 0.14);
  --warn: #ffb454;
  --warn-soft: rgba(255, 180, 84, 0.14);
  --danger: #ff6b6b;
  --danger-soft: rgba(255, 107, 107, 0.14);
  --muted: #9d8cff;
  --muted-soft: rgba(157, 140, 255, 0.14);

  --radius: 12px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 12px 28px -14px rgba(0, 0, 0, 0.55);
  --font-body: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, monospace;
}

* {
  box-sizing: border-box;
}

/* Blindaje del atributo nativo `hidden`: sin esto, cualquier regla de
   `display` sobre el mismo elemento (ej. .state-panel { display: flex })
   le gana en cascada al [hidden]{display:none} del navegador, porque las
   reglas de esta hoja de estilos (origen "author") tienen prioridad sobre
   la hoja de estilos nativa (origen "user-agent") aunque la especificidad
   sea igual. El !important es necesario a propósito: [hidden] tiene que
   ganar siempre, sin excepciones caso por caso. */
[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.app {
  max-width: 1240px;
  margin: 0 auto;
  padding: 28px 24px 64px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

/* ── Layout con sidebar ─────────────────────────────── */
.layout {
  display: grid;
  grid-template-columns: 232px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 22px 14px 18px;
  gap: 26px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar__brand {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 0 8px;
}

.sidebar__brand-mark {
  color: var(--accent);
  font-size: 19px;
}

.sidebar__brand strong {
  display: block;
  font-size: 15px;
  letter-spacing: -0.01em;
}

.sidebar__brand-sub {
  font-size: 12px;
  color: var(--text-faint);
}

.sidebar__nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 12px;
  border: none;
  border-radius: 8px;
  background: none;
  color: var(--text-dim);
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.nav-item:hover {
  background: var(--surface-2);
  color: var(--text);
}

.nav-item:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.nav-item.is-active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

.nav-item__icon {
  font-size: 13px;
  width: 16px;
  text-align: center;
  opacity: 0.85;
}

.nav-item__badge {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-faint);
}

.nav-item.is-active .nav-item__badge {
  color: var(--accent);
}

.sidebar__footer {
  padding: 0 10px;
  border-top: 1px solid var(--border);
  padding-top: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.sidebar__logout {
  width: 100%;
  justify-content: center;
}

.main {
  min-width: 0;
  padding: 24px 28px 64px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.view {
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.panel__note {
  margin: -6px 0 16px;
  font-size: 13px;
  color: var(--text-dim);
  line-height: 1.55;
}

.panel__note--warn {
  padding: 11px 13px;
  background: var(--warn-soft);
  border-left: 3px solid var(--warn);
  border-radius: 6px;
  color: var(--text-dim);
}

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

.cell-mono {
  font-family: var(--font-mono);
  font-size: 13px;
  white-space: nowrap;
}

.text-faint {
  color: var(--text-faint);
}

/* ── Header ─────────────────────────────────────────── */
.app-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border);
}

.app-header__title h1 {
  margin: 0 0 4px;
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.app-header__subtitle {
  margin: 0;
  color: var(--text-dim);
  font-size: 14px;
}

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

.last-updated {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-faint);
  white-space: nowrap;
}

/* ── Buttons ────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 9px 16px;
  border-radius: 8px;
  border: 1px solid transparent;
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, opacity 0.15s ease;
}

.btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

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

.btn__icon {
  font-size: 14px;
  line-height: 1;
}

.btn--primary {
  background: var(--accent);
  color: #061024;
}
.btn--primary:hover:not(:disabled) {
  background: #6ba1ff;
}

.btn--ghost {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--border);
}
.btn--ghost:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
}

.btn--sm {
  padding: 5px 12px;
  font-size: 12.5px;
  text-decoration: none;
}

/* ── Login ──────────────────────────────────────────── */
.login-view {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--bg);
}

.login-card {
  width: 100%;
  max-width: 340px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px 26px 26px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.login-card__brand {
  display: flex;
  align-items: center;
  gap: 11px;
  margin-bottom: 6px;
}

.login-card h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.login-card__subtitle {
  margin: 0 0 6px;
  font-size: 13px;
  color: var(--text-dim);
}

.login-card label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-dim);
}

.login-card input {
  width: 100%;
  padding: 9px 11px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
}

.login-card input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.login-card__error {
  margin: 0;
  padding: 8px 10px;
  border-radius: 6px;
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 13px;
}

.login-card__submit {
  margin-top: 6px;
  justify-content: center;
}

/* ── Loading / error state ─────────────────────────────── */
.state-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 90px 20px;
  color: var(--text-dim);
  text-align: center;
}

.state-panel--error {
  color: var(--danger);
}

.state-panel__icon {
  font-size: 34px;
  margin: 0;
}

.spinner {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}

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

/* ── KPI grid ───────────────────────────────────────── */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 14px;
}

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  box-shadow: var(--shadow);
  border-top: 3px solid var(--border);
}

.kpi-card__label {
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.kpi-card__value {
  font-family: var(--font-mono);
  font-size: 30px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

.kpi-card__detail {
  font-size: 12px;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}

.kpi-card--neutral {
  border-top-color: var(--text-faint);
}
.kpi-card--accent {
  border-top-color: var(--accent);
}
.kpi-card--accent .kpi-card__value {
  color: var(--accent);
}
.kpi-card--warn {
  border-top-color: var(--warn);
}
.kpi-card--warn .kpi-card__value {
  color: var(--warn);
}
.kpi-card--danger {
  border-top-color: var(--danger);
}
.kpi-card--danger .kpi-card__value {
  color: var(--danger);
}
.kpi-card--muted {
  border-top-color: var(--muted);
}
.kpi-card--muted .kpi-card__value {
  color: var(--muted);
}

/* ── Panels ─────────────────────────────────────────── */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 22px 22px;
  box-shadow: var(--shadow);
}

.panel__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.panel__header h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
}

.panel__header-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 14px;
}

.panel--chart .chart-wrap {
  position: relative;
  height: 320px;
}

.empty-note {
  color: var(--text-faint);
  font-size: 13.5px;
  text-align: center;
  padding: 24px 0 4px;
  margin: 0;
}

/* ── Tabs ───────────────────────────────────────────── */
.tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 18px;
  border-bottom: 1px solid var(--border);
}

.tab-btn {
  appearance: none;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 9px 4px 11px;
  margin-right: 22px;
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-dim);
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease;
}

.tab-btn:hover {
  color: var(--text);
}

.tab-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.tab-btn.is-active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.tab-panel .panel__header {
  margin-bottom: 14px;
}

/* ── Filter bar (Historial de envíos) ──────────────────── */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 14px;
  padding: 14px 16px;
  margin-bottom: 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
}

.filter-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 0;
}

.filter-field label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-faint);
}

.filter-field input,
.filter-field select {
  font-family: inherit;
  font-size: 13.5px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 8px 10px;
  min-width: 0;
}

.filter-field input:focus-visible,
.filter-field select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-color: var(--accent);
}

.filter-field--search {
  flex: 1 1 200px;
}

.filter-field--search input {
  width: 100%;
}

.filter-field select,
.filter-field input[type="date"] {
  width: 100%;
}

.filter-field--clear {
  align-self: flex-end;
}

.filter-count {
  margin: 0 0 14px;
  font-size: 12.5px;
  color: var(--text-faint);
  font-family: var(--font-mono);
}

/* ── Table ──────────────────────────────────────────── */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 640px;
  font-size: 13.8px;
}

.data-table thead th {
  position: sticky;
  top: 0;
  background: var(--surface-2);
  text-align: left;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-dim);
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.data-table tbody td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  vertical-align: middle;
}

.data-table tbody tr:last-child td {
  border-bottom: none;
}

.data-table tbody tr:hover {
  background: rgba(255, 255, 255, 0.02);
}

.data-table tbody tr.empty-row:hover {
  background: none;
}

.data-table tbody tr.empty-row td {
  text-align: center;
  color: var(--text-faint);
  padding: 26px 14px;
}

.cell-phone {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--text-dim);
  white-space: nowrap;
}

.cell-date {
  font-family: var(--font-mono);
  font-size: 12.5px;
  color: var(--text-dim);
  white-space: nowrap;
}

/* ── Status badges ──────────────────────────────────── */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  white-space: nowrap;
}
.status-badge::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.status-badge--sent,
.status-badge--delivered,
.status-badge--read,
.status-badge--accepted {
  background: var(--ok-soft);
  color: var(--ok);
}
.status-badge--pending,
.status-badge--queued,
.status-badge--leased {
  background: var(--warn-soft);
  color: var(--warn);
}
.status-badge--failed,
.status-badge--error {
  background: var(--danger-soft);
  color: var(--danger);
}
.status-badge--default {
  background: var(--muted-soft);
  color: var(--muted);
}

/* ── Progress bar (progreso por campaña) ───────────────── */
.cell-progress {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 140px;
}

.progress-bar {
  flex: 1 1 auto;
  height: 8px;
  border-radius: 4px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  overflow: hidden;
}

.progress-bar__fill {
  height: 100%;
  background: var(--accent);
  border-radius: 4px 0 0 4px;
  transition: width 0.2s ease;
}

.progress-bar__label {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-dim);
  white-space: nowrap;
}

/* ── Toast ──────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 1000;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 12px 18px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 9px;
  color: var(--text);
  font-size: 13.5px;
  font-weight: 500;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.18s ease, transform 0.18s ease;
  pointer-events: none;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

/* ── Responsive ─────────────────────────────────────── */
@media (max-width: 900px) {
  .layout {
    grid-template-columns: 1fr;
  }
  .sidebar {
    position: static;
    height: auto;
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding: 16px 14px;
    gap: 16px;
  }
  .sidebar__nav {
    flex-direction: row;
    flex-wrap: wrap;
  }
  .nav-item {
    width: auto;
  }
  .sidebar__footer {
    display: none;
  }
  .main {
    padding: 20px 16px 48px;
  }
}

@media (max-width: 640px) {
  .app {
    padding: 20px 16px 48px;
  }
  .app-header {
    align-items: flex-start;
  }
  .kpi-card__value {
    font-size: 25px;
  }
  .panel__header {
    flex-direction: column;
    align-items: flex-start;
  }
  .filter-bar {
    flex-direction: column;
    align-items: stretch;
  }
  .filter-field--clear {
    align-self: stretch;
  }
}
