/* ==========================================================================
   Carlotta Mail — hoja de estilos única.
   Sin framework ni build step: se sirve tal cual desde /assets/css/app.css.
   ========================================================================== */

:root {
  --brand-900: #0f2b46;
  --brand-800: #143a5c;
  --brand-700: #1b4a72;
  --brand-600: #21618f;
  --brand-500: #2a7bb0;
  --brand-100: #e3f0f9;
  --brand-50: #f2f8fc;

  --ink-900: #101a24;
  --ink-700: #33475c;
  --ink-500: #5d7186;
  --ink-400: #8496a8;
  --ink-300: #b9c5d1;
  --ink-200: #dde4ec;
  --ink-100: #eef2f7;
  --ink-50: #f6f8fb;
  --white: #ffffff;

  --ok-600: #1c7a4d;
  --ok-100: #dcf3e6;
  --warn-600: #9a6206;
  --warn-100: #fdf0d5;
  --err-600: #b3261e;
  --err-100: #fbe3e1;
  --info-600: #1c5fb0;
  --info-100: #dfeafb;
  --purple-600: #6b3fa0;
  --purple-100: #ece2f8;

  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 2px rgba(16, 26, 36, 0.06);
  --shadow: 0 4px 14px rgba(16, 26, 36, 0.08);
  --shadow-lg: 0 18px 40px rgba(16, 26, 36, 0.18);
  --sidebar-w: 264px;
  --header-h: 64px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
  color: var(--ink-900);
  background: var(--ink-50);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--brand-600); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3, h4 { margin: 0 0 0.5rem; line-height: 1.25; font-weight: 650; }
h1 { font-size: 1.6rem; letter-spacing: -0.02em; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.02rem; }
p { margin: 0 0 0.75rem; }

/* ---------- Estructura ---------- */

.app-shell { min-height: 100vh; }

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--sidebar-w);
  background: var(--brand-900);
  color: #d7e5f0;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  z-index: 40;
}

.sidebar__brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 1.1rem 1.15rem;
  color: var(--white);
  font-weight: 700;
  font-size: 1.08rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.09);
}
.sidebar__brand:hover { text-decoration: none; }
.sidebar__logo {
  width: 32px; height: 32px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--brand-500), var(--brand-700));
  display: grid; place-items: center;
  font-size: 0.95rem; font-weight: 800;
  flex-shrink: 0;
}

.sidebar__section {
  padding: 0.9rem 1.15rem 0.3rem;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: #7fa3c0;
  font-weight: 700;
}

.sidebar__nav { list-style: none; margin: 0; padding: 0 0.55rem 0.75rem; }
.sidebar__link {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.5rem 0.6rem;
  border-radius: var(--radius-sm);
  color: #c7dbea;
  font-size: 0.9rem;
  margin-bottom: 2px;
}
.sidebar__link:hover { background: rgba(255, 255, 255, 0.07); color: var(--white); text-decoration: none; }
.sidebar__link.is-active { background: var(--brand-600); color: var(--white); font-weight: 600; }
.sidebar__icon { width: 18px; text-align: center; opacity: 0.9; flex-shrink: 0; }
.sidebar__badge {
  margin-left: auto;
  background: rgba(255, 255, 255, 0.16);
  border-radius: 999px;
  padding: 0 0.45rem;
  font-size: 0.72rem;
  font-weight: 700;
}
.sidebar__footer { margin-top: auto; padding: 0.85rem 1.15rem; border-top: 1px solid rgba(255,255,255,0.09); font-size: 0.78rem; color: #8fb0c9; }

.main { margin-left: var(--sidebar-w); min-height: 100vh; display: flex; flex-direction: column; }

.topbar {
  position: sticky; top: 0; z-index: 30;
  height: var(--header-h);
  display: flex; align-items: center; gap: 1rem;
  padding: 0 1.5rem;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--ink-200);
}
.topbar__title { font-size: 1.05rem; font-weight: 650; margin: 0; }
.topbar__spacer { flex: 1; }
.topbar__user { display: flex; align-items: center; gap: 0.6rem; font-size: 0.88rem; color: var(--ink-700); }
.avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--brand-100); color: var(--brand-700);
  display: grid; place-items: center; font-weight: 700; font-size: 0.82rem;
  flex-shrink: 0;
}

.content { padding: 1.5rem; flex: 1; max-width: 1400px; width: 100%; }
.page-header { display: flex; align-items: flex-start; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.25rem; }
.page-header__text { flex: 1; min-width: 240px; }
.page-header__actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.page-header p { color: var(--ink-500); margin: 0.15rem 0 0; }

.hamburger {
  display: none;
  background: none; border: 1px solid var(--ink-200); border-radius: var(--radius-sm);
  width: 38px; height: 38px; font-size: 1.1rem; cursor: pointer;
}

.scrim { display: none; position: fixed; inset: 0; background: rgba(16,26,36,0.5); z-index: 35; }
.scrim.is-open { display: block; }

/* ---------- Tarjetas ---------- */

.card {
  background: var(--white);
  border: 1px solid var(--ink-200);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.card__header {
  padding: 0.9rem 1.15rem;
  border-bottom: 1px solid var(--ink-100);
  display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap;
}
.card__header h2, .card__header h3 { margin: 0; }
.card__body { padding: 1.15rem; }
.card__footer { padding: 0.85rem 1.15rem; border-top: 1px solid var(--ink-100); background: var(--ink-50); border-radius: 0 0 var(--radius) var(--radius); }

.grid { display: grid; gap: 1rem; }
.grid--stats { grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }
.grid--2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid--3 { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.grid--form { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); align-items: start; }
.stack > * + * { margin-top: 1rem; }
.stack-sm > * + * { margin-top: 0.5rem; }

.stat { padding: 1.05rem 1.15rem; display: flex; flex-direction: column; gap: 0.2rem; }
.stat__label { font-size: 0.76rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-500); font-weight: 700; }
.stat__value { font-size: 1.85rem; font-weight: 700; letter-spacing: -0.02em; line-height: 1.1; }
.stat__hint { font-size: 0.8rem; color: var(--ink-400); }
.stat--brand .stat__value { color: var(--brand-600); }
.stat--ok .stat__value { color: var(--ok-600); }
.stat--warn .stat__value { color: var(--warn-600); }
.stat--err .stat__value { color: var(--err-600); }
.stat--info .stat__value { color: var(--info-600); }
.stat--purple .stat__value { color: var(--purple-600); }

/* ---------- Tablas ---------- */

.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.table th, .table td { padding: 0.62rem 0.85rem; text-align: left; border-bottom: 1px solid var(--ink-100); vertical-align: middle; }
.table th { font-size: 0.74rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--ink-500); font-weight: 700; background: var(--ink-50); white-space: nowrap; }
.table tbody tr:hover { background: var(--brand-50); }
.table td.actions { text-align: right; white-space: nowrap; }
.table td.actions form { display: inline; }
.table__empty { padding: 2.5rem 1rem; text-align: center; color: var(--ink-500); }
.table__email { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.84rem; }
.table__name { font-weight: 600; }
.table--compact td, .table--compact th { padding: 0.4rem 0.6rem; }
.var-token { width: 14rem; }

.detail-list { display: grid; grid-template-columns: minmax(7.5rem, auto) 1fr; gap: 0.45rem 0.9rem; margin: 0; }
.detail-list dt { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--ink-500); font-weight: 700; }
.detail-list dd { margin: 0; }

.plain-list { list-style: none; margin: 0.5rem 0 0; padding: 0; display: grid; gap: 0.5rem; }
.plain-list li { font-size: 0.88rem; }

/* Vista previa del cuerpo de una plantilla de email. */
iframe.preview {
  display: block;
  width: 100%;
  height: 520px;
  border: 1px solid var(--ink-200);
  border-radius: var(--radius-sm);
  background: var(--white);
}

.pagination { display: flex; gap: 0.3rem; flex-wrap: wrap; align-items: center; justify-content: flex-end; }
.pagination__info { margin-right: auto; font-size: 0.85rem; color: var(--ink-500); }

/* ---------- Formularios ---------- */

.field { margin-bottom: 1rem; }
.field__label { display: block; font-size: 0.85rem; font-weight: 650; margin-bottom: 0.3rem; color: var(--ink-700); }
.field__hint { font-size: 0.8rem; color: var(--ink-400); margin-top: 0.25rem; }
.field__error { font-size: 0.82rem; color: var(--err-600); margin-top: 0.25rem; font-weight: 600; }

.input, .select, .textarea {
  width: 100%;
  padding: 0.5rem 0.65rem;
  border: 1px solid var(--ink-300);
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 0.92rem;
  color: var(--ink-900);
  background: var(--white);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--brand-500);
  box-shadow: 0 0 0 3px rgba(42, 123, 176, 0.16);
}
.input[aria-invalid='true'], .select[aria-invalid='true'] { border-color: var(--err-600); }
.textarea { min-height: 110px; resize: vertical; }
.textarea--code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.85rem; line-height: 1.55; tab-size: 2; }
.input--search { padding-left: 2.1rem; }
.search { position: relative; }
.search::before {
  content: '⌕';
  position: absolute; left: 0.6rem; top: 50%; transform: translateY(-52%);
  color: var(--ink-400); font-size: 1.05rem; pointer-events: none;
}

.field-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 0 0.9rem; }

.checkbox { display: flex; align-items: flex-start; gap: 0.5rem; font-size: 0.9rem; margin-bottom: 0.5rem; }
.checkbox input { margin-top: 0.22rem; width: 16px; height: 16px; accent-color: var(--brand-600); flex-shrink: 0; }

/* Selector multiple de listas de destino en el formulario de campaña. */
.checklist { display: grid; gap: 0.35rem; max-height: 15rem; overflow-y: auto; padding: 0.55rem 0.7rem; border: 1px solid var(--ink-200); border-radius: var(--radius-sm); background: var(--ink-50); }
.checklist .checkbox { margin-bottom: 0; font-size: 0.86rem; }

/* Filtros por estado en el listado de campañas. */
.tabs { display: flex; gap: 0.25rem; flex-wrap: wrap; margin-bottom: 1rem; border-bottom: 1px solid var(--ink-200); }
.tab { display: inline-flex; align-items: center; gap: 0.35rem; padding: 0.45rem 0.7rem; font-size: 0.86rem; font-weight: 600; color: var(--ink-500); border-bottom: 2px solid transparent; text-decoration: none; }
.tab:hover { color: var(--ink-900); }
.tab.is-active { color: var(--brand-700); border-bottom-color: var(--brand-600); }
.tab__count { font-size: 0.74rem; font-weight: 700; color: var(--ink-500); background: var(--ink-100); border-radius: 999px; padding: 0.05rem 0.4rem; }
.tab.is-active .tab__count { background: var(--brand-100); color: var(--brand-700); }

fieldset { border: 1px solid var(--ink-200); border-radius: var(--radius); padding: 0.9rem 1rem; margin: 0 0 1rem; }
legend { font-size: 0.8rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: var(--ink-500); padding: 0 0.35rem; }

.filters { display: flex; gap: 0.6rem; flex-wrap: wrap; align-items: flex-end; }
.filters .field { margin-bottom: 0; min-width: 150px; }

/* ---------- Botones ---------- */

.btn {
  display: inline-flex; align-items: center; gap: 0.4rem;
  padding: 0.5rem 0.9rem;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font: inherit; font-size: 0.9rem; font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.btn:hover { text-decoration: none; }
.btn--primary { background: var(--brand-600); color: var(--white); }
.btn--primary:hover { background: var(--brand-700); }
.btn--secondary { background: var(--white); color: var(--ink-700); border-color: var(--ink-300); }
.btn--secondary:hover { background: var(--ink-50); border-color: var(--ink-400); }
.btn--ghost { background: transparent; color: var(--brand-600); padding: 0.4rem 0.5rem; }
.btn--ghost:hover { background: var(--brand-50); }
.btn--danger { background: var(--err-600); color: var(--white); }
.btn--danger:hover { background: #92150f; }
.btn--danger-ghost { background: transparent; color: var(--err-600); }
.btn--danger-ghost:hover { background: var(--err-100); }
.btn--sm { padding: 0.3rem 0.6rem; font-size: 0.82rem; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-row { display: flex; gap: 0.5rem; flex-wrap: wrap; }

/* ---------- Distintivos ---------- */

.badge {
  display: inline-flex; align-items: center; gap: 0.3rem;
  padding: 0.16rem 0.55rem;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 650;
  background: var(--ink-100);
  color: var(--ink-700);
  white-space: nowrap;
}
.badge--ok { background: var(--ok-100); color: var(--ok-600); }
.badge--warn { background: var(--warn-100); color: var(--warn-600); }
.badge--err { background: var(--err-100); color: var(--err-600); }
.badge--info { background: var(--info-100); color: var(--info-600); }
.badge--purple { background: var(--purple-100); color: var(--purple-600); }
.badge--muted { background: var(--ink-100); color: var(--ink-500); }

.tag-list { display: flex; gap: 0.3rem; flex-wrap: wrap; }

.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }

/* ---------- Avisos ---------- */

.alert { padding: 0.75rem 0.95rem; border-radius: var(--radius); border: 1px solid; margin-bottom: 1rem; font-size: 0.9rem; display: flex; gap: 0.55rem; align-items: flex-start; }
.alert--success { background: var(--ok-100); border-color: #a8ddc1; color: #14563a; }
.alert--error { background: var(--err-100); border-color: #f0b4b0; color: #8c1c16; }
.alert--info { background: var(--info-100); border-color: #b6cff0; color: #164a86; }
.alert--warning { background: var(--warn-100); border-color: #f0d59a; color: #7d4e05; }
.alert ul { margin: 0.4rem 0 0; padding-left: 1.1rem; }

/* ---------- Utilidades ---------- */

.muted { color: var(--ink-500); }
.small { font-size: 0.84rem; }
.tiny { font-size: 0.78rem; }
.strong { font-weight: 650; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.nowrap { white-space: nowrap; }
.mt-0 { margin-top: 0; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mb-0 { margin-bottom: 0; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.flex { display: flex; gap: 0.6rem; align-items: center; }
.flex-between { display: flex; gap: 0.6rem; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.w-full { width: 100%; }
.hidden { display: none !important; }
.divider { height: 1px; background: var(--ink-200); margin: 1.15rem 0; border: 0; }

.empty-state { text-align: center; padding: 3rem 1rem; color: var(--ink-500); }
.empty-state__icon { font-size: 2.4rem; opacity: 0.4; }
.empty-state h3 { color: var(--ink-700); margin-top: 0.5rem; }

/* ---------- Progreso ---------- */

progress.progress { width: 100%; height: 8px; border: 0; border-radius: 999px; background: var(--ink-100); accent-color: var(--brand-600); overflow: hidden; }
progress.progress::-webkit-progress-bar { background: var(--ink-100); border-radius: 999px; }
progress.progress::-webkit-progress-value { background: var(--brand-600); border-radius: 999px; }
progress.progress::-moz-progress-bar { background: var(--brand-600); border-radius: 999px; }
progress.progress--sm { width: 90px; }
progress.progress--ok { accent-color: var(--ok-600); }
progress.progress--ok::-webkit-progress-value { background: var(--ok-600); }
progress.progress--ok::-moz-progress-bar { background: var(--ok-600); }
progress.progress--err { accent-color: var(--err-600); }
progress.progress--err::-webkit-progress-value { background: var(--err-600); }
progress.progress--err::-moz-progress-bar { background: var(--err-600); }

.progress { height: 8px; background: var(--ink-100); border-radius: 999px; overflow: hidden; }
.progress__bar { height: 100%; background: var(--brand-600); border-radius: 999px; transition: width 0.3s; }
.progress__bar--ok { background: var(--ok-600); }
.progress__bar--err { background: var(--err-600); }

.meter { display: flex; flex-direction: column; gap: 0.3rem; }
.meter__head { display: flex; justify-content: space-between; font-size: 0.84rem; }
.meter__head strong { font-weight: 650; }

/* ---------- Páginas públicas ---------- */

.public-body { background: var(--brand-900); min-height: 100vh; display: grid; place-items: center; padding: 1.5rem; }
.public-card { width: 100%; max-width: 420px; background: var(--white); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); padding: 2rem; }
.public-card--wide { max-width: 560px; }
.public-card h1 { text-align: center; margin-bottom: 0.25rem; }
.public-card__subtitle { text-align: center; color: var(--ink-500); margin-bottom: 1.5rem; }
.public-logo { display: flex; align-items: center; justify-content: center; gap: 0.6rem; margin-bottom: 1.25rem; font-weight: 700; font-size: 1.1rem; color: var(--brand-800); }
.public-foot { text-align: center; color: #7fa3c0; font-size: 0.8rem; margin-top: 1.25rem; }

/* ---------- Responsive ---------- */

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

@media (max-width: 860px) {
  .sidebar { transform: translateX(-100%); transition: transform 0.2s ease; box-shadow: var(--shadow-lg); }
  .sidebar.is-open { transform: translateX(0); }
  .main { margin-left: 0; }
  .hamburger { display: grid; place-items: center; }
  .content { padding: 1rem; }
  .topbar { padding: 0 1rem; }
  .topbar__user span.user-name { display: none; }
  .page-header { flex-direction: column; align-items: stretch; }
  .page-header__actions .btn { flex: 1; justify-content: center; }
}

@media (max-width: 560px) {
  .grid--stats { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
  .stat__value { font-size: 1.5rem; }
  .card__body { padding: 0.9rem; }
  .btn { width: 100%; justify-content: center; }
  .btn-row .btn { width: auto; }
  .page-header__actions { flex-direction: column; }
  .field-row { grid-template-columns: 1fr; }
  .filters .field { width: 100%; }
}

@media print {
  .sidebar, .topbar, .page-header__actions, .btn { display: none !important; }
  .main { margin-left: 0; }
  .card { box-shadow: none; border: 1px solid #ccc; }
}

/* ---------- Utilidades (sustituyen a los estilos en línea, bloqueados por la CSP) ---------- */

.u-grow { flex: 1; min-width: 240px; }
.u-center { justify-content: center; }
.u-contents { display: contents; }
.u-w-auto { width: auto; }
.u-text-lg { font-size: 1.15rem; }
.u-mt-2 { margin-top: 0.5rem; }
.u-center-text { text-align: center; }
.u-mt-4 { margin-top: 1rem; }
.u-list-none { list-style: none; padding: 0; margin: 0; }
.u-list-indent { list-style: none; padding: 0 0 0 1.15rem; margin: 0; }
.org-option--active { background: var(--brand-600); }
.org-option--idle { background: var(--ink-300); }

/* ---------- Configuración ---------- */
.card__subtitle { font-size: 0.9rem; font-weight: 700; color: var(--ink-700); margin: 0 0 0.5rem; }
.text-muted { color: var(--ink-500); font-size: 0.92rem; }
.info-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.6rem; }
.info-list__item { display: grid; gap: 0.15rem; padding-left: 0.75rem; border-left: 2px solid var(--ink-200); }
.info-list__item strong { font-size: 0.88rem; color: var(--ink-800); }
.info-list__item span { font-size: 0.85rem; color: var(--ink-500); }

/* ---------- Paneles de proveedor (configuración) ---------- */
.provider-panel.is-hidden { display: none; }
.btn--link { background: none; border: 0; padding: 0; color: var(--brand-700); font-size: 0.85rem; font-weight: 600; text-decoration: underline; cursor: pointer; }

/* Columnas numéricas de las tablas de estadísticas. */
.table .num { text-align: right; white-space: nowrap; }
