/* Difusiones Libertat — paleta del Manual de marca 2025 */
:root {
  --tinta: #120E49;        /* azul institucional */
  --tinta-hover: #1c1766;
  --lima: #C0EB46;         /* verde lima del isotipo */
  --lima-suave: #EAF7C8;
  --papel: #F7F8FC;
  --card: #FFFFFF;
  --niebla: #E3E6F2;
  --texto: #221E52;
  --texto-suave: #6A6F8E;
  --azul: #0027A5;
  --violeta: #7B45E1;
  --magenta: #C2258F;      /* derivado del rosado de marca, para errores */
  --ambar: #E8A13D;        /* semáforo YELLOW de Meta */
  --radio: 14px;
  --sombra: 0 1px 3px rgba(18, 14, 73, .06), 0 8px 24px rgba(18, 14, 73, .07);
}
* { margin: 0; padding: 0; box-sizing: border-box; }
html { font-size: 15px; }
body {
  font-family: "Manrope", system-ui, -apple-system, sans-serif;
  background: var(--papel);
  color: var(--texto);
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; cursor: pointer; }
input, select { font: inherit; color: var(--texto); }

.shell { display: flex; min-height: 100vh; }

/* ---------- sidebar ---------- */
.sidebar {
  width: 236px; flex-shrink: 0;
  background: var(--tinta);
  display: flex; flex-direction: column;
  padding: 28px 18px 18px;
  /* position: fixed (no sticky): sticky en un flex-item se rompe en Safari y el menú
     se iba con el scroll en páginas largas. Fixed la ancla siempre; overflow-y por si
     el menú no cabe en pantallas bajas. .main compensa con margin-left. */
  position: fixed; top: 0; left: 0; height: 100vh; overflow-y: auto; z-index: 20;
  box-sizing: border-box;
}
.brand-logo { width: 150px; margin: 0 6px 4px; }
.brand-sub {
  font-family: "Baloo 2", var(--tinta);
  color: var(--lima); font-size: .82rem; font-weight: 600;
  letter-spacing: .12em; text-transform: uppercase;
  margin: 0 6px 30px;
}
.sidebar nav { display: flex; flex-direction: column; gap: 4px; }
.nav-item {
  background: none; border: 0; text-align: left;
  color: #B9BCD8; padding: 10px 12px; border-radius: 9px;
  font-weight: 600; border-left: 3px solid transparent;
  transition: background .15s, color .15s;
}
.nav-item:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav-item.active { color: #fff; background: rgba(255,255,255,.08); border-left-color: var(--lima); }
.nav-item:focus-visible, .btn:focus-visible, input:focus-visible, select:focus-visible {
  outline: 2px solid var(--lima); outline-offset: 2px;
}
.phone-chip {
  margin-top: auto; display: flex; gap: 10px; align-items: center;
  background: rgba(255,255,255,.07); border-radius: 12px; padding: 10px 12px;
}
.phone-num { color: #fff; font-weight: 700; font-size: .85rem; }
.phone-q { color: #B9BCD8; font-size: .74rem; }
/* Selector de remitente dentro del chip: va sobre fondo oscuro, así que no
   hereda los estilos de los <select> del formulario. Oculto si solo hay uno. */
.sender-pick {
  width: 100%; margin-bottom: 4px; padding: 4px 6px; font: inherit; font-size: .74rem;
  color: #fff; background: rgba(255,255,255,.1); border: 1px solid rgba(255,255,255,.18);
  border-radius: 8px; cursor: pointer;
}
.sender-pick option { color: var(--texto); background: #fff; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.dot-green { background: var(--lima); box-shadow: 0 0 0 4px rgba(192,235,70,.18); }
.dot-yellow { background: var(--ambar); }
.dot-red { background: var(--magenta); }
.dot-off { background: #555a80; }

/* ---------- main ---------- */
.main { flex: 1; padding: 34px 42px 60px; max-width: 1150px; margin-left: 236px; }
.view-head {
  display: flex; justify-content: space-between; align-items: center; margin-bottom: 24px; gap: 12px;
}
h1 { font-family: "Baloo 2", sans-serif; font-size: 1.7rem; color: var(--tinta); font-weight: 700; }
h2 { font-family: "Baloo 2", sans-serif; color: var(--tinta); font-size: 1.25rem; }
h3 { font-size: .8rem; letter-spacing: .1em; text-transform: uppercase; color: var(--texto-suave); margin: 22px 0 10px; }
.hidden { display: none !important; }
.hint { color: var(--texto-suave); font-size: .84rem; line-height: 1.45; margin: 6px 0; }
.empty-state { color: var(--texto-suave); padding: 40px; text-align: center; }

/* ---------- botones ---------- */
.btn {
  border: 0; border-radius: 10px; padding: 10px 18px; font-weight: 700;
  transition: transform .1s, filter .15s;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--lima); color: var(--tinta); }
.btn-primary:hover { filter: brightness(1.05); }
.btn-primary:disabled { background: var(--niebla); color: var(--texto-suave); cursor: not-allowed; }
.btn-secondary { background: var(--card); color: var(--tinta); border: 1.5px solid var(--niebla); }
.btn-secondary:hover { border-color: var(--tinta); }
.btn-ghost { background: none; color: var(--texto-suave); }
.btn-ghost:hover { color: var(--tinta); }
.btn-danger { background: none; color: var(--magenta); border: 1.5px solid currentColor; }
.btn-xs { padding: 4px 9px; font-size: .76rem; border-radius: 8px; }
.row-actions { display: flex; gap: 4px; flex-wrap: wrap; justify-content: flex-end; }
.pill {
  display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: .68rem;
  font-weight: 700; background: var(--lima-suave); color: var(--tinta); vertical-align: middle;
}

/* ---------- cards y campaña ---------- */
.card {
  background: var(--card); border-radius: var(--radio); box-shadow: var(--sombra);
  padding: 22px; margin-bottom: 16px;
}
.card.narrow { max-width: 520px; }
.camp-card { cursor: pointer; transition: box-shadow .15s; }
.camp-card:hover { box-shadow: 0 2px 6px rgba(18,14,73,.1), 0 12px 32px rgba(18,14,73,.12); }
.camp-top { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.camp-name { font-weight: 800; font-size: 1.05rem; color: var(--tinta); }
.camp-meta { color: var(--texto-suave); font-size: .8rem; }

.status-pill {
  font-size: .72rem; font-weight: 800; letter-spacing: .06em; text-transform: uppercase;
  padding: 4px 10px; border-radius: 99px;
}
.st-running { background: var(--lima-suave); color: #3d5310; }
.st-paused { background: #F0E9FB; color: var(--violeta); }
.st-draft { background: var(--niebla); color: var(--texto-suave); }
.st-done { background: #DFF7EE; color: #0E7A57; }
.st-canceled { background: #FBE9F5; color: var(--magenta); }

/* barra de progreso rematada por el isotipo (figura de brazos abiertos) */
.progress-wrap { margin: 14px 0 6px; }
.progress-track {
  height: 10px; background: var(--niebla); border-radius: 99px; position: relative; overflow: visible;
}
.progress-fill {
  height: 100%; background: linear-gradient(90deg, #A5D62E, var(--lima));
  border-radius: 99px; min-width: 10px; position: relative;
  transition: width .6s ease;
}
.progress-head {
  position: absolute; right: -13px; top: 50%; transform: translateY(-50%);
  width: 26px; height: 26px; border-radius: 50%;
  background: #fff url("/static/assets/isotipo_verde.png") center/70% no-repeat;
  box-shadow: var(--sombra); border: 2px solid var(--lima);
}
.progress-nums { display: flex; justify-content: space-between; font-size: .78rem; color: var(--texto-suave); margin-top: 8px; }

.big-num { font-family: "Baloo 2", sans-serif; font-size: 1.9rem; font-weight: 700; color: var(--tinta); line-height: 1; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 14px; margin: 16px 0; }
.stat-cell { background: var(--papel); border-radius: 10px; padding: 12px 14px; }
.stat-label { font-size: .72rem; color: var(--texto-suave); text-transform: uppercase; letter-spacing: .07em; margin-top: 4px; }
.stat-bad .big-num { color: var(--magenta); }

/* ---------- tacómetro de ritmo (elemento firma) ---------- */
.tacho-box { display: flex; gap: 22px; align-items: center; flex-wrap: wrap; }
.tacho { width: 170px; }
.tacho-caption { font-size: .78rem; color: var(--texto-suave); max-width: 220px; line-height: 1.4; }
.tacho-value { font-family: "Baloo 2", sans-serif; font-weight: 700; fill: var(--tinta); font-size: 26px; }
.tacho-unit { fill: var(--texto-suave); font-size: 9.5px; letter-spacing: .08em; }

/* ---------- log ---------- */
.log-table { width: 100%; border-collapse: collapse; font-size: .82rem; }
.log-table th {
  text-align: left; font-size: .7rem; text-transform: uppercase; letter-spacing: .08em;
  color: var(--texto-suave); padding: 8px 10px; border-bottom: 1.5px solid var(--niebla);
}
.log-table td { padding: 8px 10px; border-bottom: 1px solid var(--papel); }
.log-table .mono, .mono { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: .78rem; }
.ev-line { display: flex; gap: 10px; padding: 7px 0; font-size: .82rem; border-bottom: 1px solid var(--papel); }
.ev-ts { color: var(--texto-suave); white-space: nowrap; font-size: .74rem; padding-top: 2px; }
.ev-warn { color: #8a5a00; }
.ev-error { color: var(--magenta); }
.ev-ok { color: #3d6b12; }

/* ---------- wizard ---------- */
.steps { display: flex; gap: 8px; list-style: none; margin-bottom: 26px; flex-wrap: wrap; }
.step {
  display: flex; align-items: center; gap: 8px; padding: 8px 16px 8px 8px;
  border-radius: 99px; background: var(--card); color: var(--texto-suave);
  font-weight: 600; font-size: .85rem; box-shadow: var(--sombra);
}
.step span {
  width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center;
  background: var(--niebla); font-weight: 800; font-size: .8rem;
}
.step.active { color: var(--tinta); }
.step.active span { background: var(--lima); color: var(--tinta); }
.step.done span { background: var(--tinta); color: var(--lima); }
.pane-grid { display: grid; grid-template-columns: 1.15fr .85fr; gap: 34px; }
.pane-foot { display: flex; justify-content: space-between; margin-top: 30px; }
.row { display: flex; gap: 10px; align-items: center; margin: 10px 0; flex-wrap: wrap; }
.grow { flex: 1; min-width: 160px; }
.block { display: block; margin: 12px 0; font-weight: 600; font-size: .88rem; }
.block input, .block select { margin-top: 6px; }
input[type="text"], input[type="password"], input[type="number"], input[type="time"], select {
  width: 100%; padding: 9px 12px; border: 1.5px solid var(--niebla); border-radius: 9px;
  background: var(--card);
}
input[type="range"] { width: 100%; accent-color: var(--tinta); margin-top: 8px; }
.field-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin: 12px 0; }
.field-grid label { font-size: .8rem; font-weight: 600; color: var(--texto-suave); }
.field-grid input, .field-grid select { margin-top: 5px; }

.tpl-list { display: flex; flex-direction: column; gap: 10px; max-height: 420px; overflow-y: auto; padding-right: 4px; }
.tpl-item {
  text-align: left; background: var(--card); border: 2px solid var(--niebla); border-radius: 12px;
  padding: 12px 14px; transition: border-color .12s;
}
.tpl-item:hover { border-color: var(--texto-suave); }
.tpl-item.selected { border-color: var(--tinta); background: #F3F5FF; }
.tpl-name { font-weight: 800; color: var(--tinta); }
.tpl-meta { font-size: .74rem; color: var(--texto-suave); margin-top: 3px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }
.chip {
  border: 1.5px solid var(--niebla); background: var(--card); border-radius: 99px;
  padding: 6px 14px; font-size: .82rem; font-weight: 600;
}
.chip.on { background: var(--tinta); color: #fff; border-color: var(--tinta); }

/* ---------- preview WhatsApp ---------- */
.wa-preview {
  background: #EFE7DC;
  background-image: radial-gradient(rgba(18,14,73,.05) 1px, transparent 1px);
  background-size: 16px 16px;
  border-radius: var(--radio); padding: 18px; min-height: 220px; box-shadow: var(--sombra);
}
.wa-bubble {
  background: #fff; border-radius: 10px; border-top-left-radius: 2px;
  max-width: 330px; padding: 6px; box-shadow: 0 1px 1px rgba(0,0,0,.08);
  font-family: system-ui, -apple-system, sans-serif; font-size: .84rem;
}
.wa-img { width: 100%; border-radius: 7px; display: block; }
.wa-img-ph {
  width: 100%; height: 120px; border-radius: 7px; background: var(--niebla);
  display: grid; place-items: center; color: var(--texto-suave); font-size: .78rem;
}
.wa-body { padding: 8px 6px 4px; white-space: pre-wrap; line-height: 1.35; color: #111; }
.wa-time { text-align: right; color: #999; font-size: .68rem; padding: 0 6px 4px; }
.wa-btn {
  border-top: 1px solid #eee; color: #00A5F4; text-align: center; padding: 9px 0 5px;
  font-weight: 600;
}

/* ---------- funnel enviado → entregado → leído ---------- */
.funnel { display: flex; flex-direction: column; gap: 11px; margin: 14px 0 4px; }
.fn-bar-track { height: 14px; background: var(--niebla); border-radius: 99px; overflow: hidden; }
.fn-bar { height: 100%; border-radius: 99px; transition: width .6s ease; }
.fn-sent { background: var(--tinta); }
.fn-deliv { background: var(--violeta); }
.fn-read { background: linear-gradient(90deg, #A5D62E, var(--lima)); }
.fn-reply { background: var(--aguamarina); }
.fn-meta { display: flex; justify-content: space-between; font-size: .78rem; margin-top: 4px; color: var(--texto-suave); }
.fn-label { font-weight: 600; }
.fn-num em { color: var(--tinta); font-style: normal; font-weight: 800; }
:root { --aguamarina: #4BDEB1; }

textarea {
  width: 100%; padding: 10px 12px; border: 1.5px solid var(--niebla); border-radius: 9px;
  background: var(--card); font-family: inherit; font-size: .92rem; resize: vertical; color: var(--texto);
}
textarea:focus-visible { outline: 2px solid var(--lima); outline-offset: 2px; }

/* ---------- stats de audiencia ---------- */
.aud-report { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; margin-top: 16px; }
.aud-cell { background: var(--card); border-radius: 10px; padding: 12px; box-shadow: var(--sombra); }
.aud-cell b { display: block; font-size: 1.3rem; font-family: "Baloo 2", sans-serif; color: var(--tinta); }
.aud-cell.aud-main { background: var(--tinta); }
.aud-cell.aud-main b, .aud-cell.aud-main span { color: #fff; }
.aud-cell.aud-main b { color: var(--lima); font-size: 1.6rem; }
.aud-cell span { font-size: .72rem; color: var(--texto-suave); }

/* ---------- modal y toast ---------- */
.modal-back {
  position: fixed; inset: 0; background: rgba(18,14,73,.45); display: grid; place-items: center; z-index: 40;
}
.modal { background: var(--card); border-radius: 16px; padding: 28px; width: min(480px, 92vw); }
.modal-actions { justify-content: flex-end; margin-top: 18px; }
.check-line { font-size: .86rem; align-items: flex-start; line-height: 1.4; }
.check-line input { margin-top: 3px; }
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--tinta); color: #fff; padding: 12px 22px; border-radius: 12px;
  font-weight: 600; box-shadow: var(--sombra); z-index: 50; max-width: 90vw;
}
.toast.err { background: var(--magenta); }

/* ---------- login ---------- */
.login-wrap {
  min-height: 100vh; display: grid; place-items: center; padding: 20px;
  background: radial-gradient(120% 120% at 50% 0%, #1c1766 0%, var(--tinta) 55%, #0d0a38 100%);
}
.login-card {
  background: var(--card); border-radius: 20px; box-shadow: 0 20px 60px rgba(0,0,0,.35);
  padding: 40px 36px; width: min(400px, 94vw); text-align: center;
}
.login-logo { width: 150px; margin: 0 auto 6px; display: block; }
.login-sub {
  font-family: "Baloo 2", sans-serif; color: var(--violeta); font-weight: 600;
  letter-spacing: .12em; text-transform: uppercase; font-size: .74rem; margin-bottom: 26px;
}
.login-title { font-family: "Baloo 2", sans-serif; color: var(--tinta); font-size: 1.6rem; }
.login-hint { color: var(--texto-suave); font-size: .86rem; margin: 4px 0 22px; }
.login-label { display: block; text-align: left; font-weight: 600; font-size: .85rem; color: var(--texto); margin-bottom: 14px; }
.login-label input { margin-top: 6px; }
.login-btn { width: 100%; margin-top: 6px; padding: 12px; font-size: 1rem; }
.login-error { color: var(--magenta); font-size: .84rem; margin-top: 12px; min-height: 1.2em; font-weight: 600; }
.login-foot { color: var(--texto-suave); font-size: .7rem; margin-top: 26px; line-height: 1.4; }

/* usuario + salir en la barra lateral */
.user-chip {
  margin-top: 12px; display: flex; align-items: center; justify-content: space-between; gap: 8px;
  background: rgba(255,255,255,.06); border-radius: 10px; padding: 8px 12px;
}
.user-name { color: #fff; font-size: .8rem; font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.user-logout { background: none; border: 0; color: var(--lima); font-weight: 700; font-size: .8rem; cursor: pointer; }
.user-logout:hover { text-decoration: underline; }

/* ---------- responsive ---------- */
/* Blindaje: el cuerpo nunca scrollea en horizontal; el contenido ancho scrollea
   dentro de su propia tarjeta, y los textos largos sin espacios (nombres de
   plantilla con guiones bajos, correos, wamids) cortan en vez de empujar el ancho. */
html, body { max-width: 100%; overflow-x: hidden; }
/* min-width:0 rompe el default flex/grid "min-width:auto" que estira el contenedor
   hasta el contenido más ancho (tabla de 831px) en vez de dejarlo scrollear. */
.main { min-width: 0; }
.pane-grid > *, .pane-grid { min-width: 0; }
/* Solo las tarjetas CON tabla scrollean (evita la franja/gutter blanca en tarjetas
   de funnel y KPIs, que no desbordan). El resto queda visible y limpio. */
.card:has(.log-table) { overflow-x: auto; }
.log-table { width: 100%; }
.tpl-name, .camp-name, .wa-body, .ev-line span, .aud-cell span, .fn-label { overflow-wrap: anywhere; }
.tpl-list { max-width: 100%; }

@media (max-width: 900px) {
  .shell { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; padding: 16px; overflow-y: visible; }
  .sidebar nav { flex-direction: row; flex-wrap: wrap; }
  .brand-logo { width: 110px; }
  .phone-chip { margin-top: 10px; }
  .main { padding: 20px; margin-left: 0; }   /* la barra ya no es fija en móvil */
  .pane-grid { grid-template-columns: 1fr; }
  .steps { flex-wrap: wrap; }
  .view-head { flex-wrap: wrap; }
  .head-actions { flex-wrap: wrap; gap: 8px; }
}
@media (max-width: 560px) {
  .main { padding: 14px; }
  h1 { font-size: 1.4rem; }
  .stat-grid { grid-template-columns: repeat(auto-fit, minmax(90px, 1fr)); }
  .tacho-box { flex-direction: column; align-items: flex-start; }
  .btn { padding: 9px 14px; }
  .modal { padding: 20px; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
