/* ============================================================================
 * NUEVARIFA.COM — ESTUDIO DE DIFUSIÓN (/carteles, RF-037 §9)
 * Hoja dedicada sobre los tokens de /css/home.css, /css/panel.css y /css/org-shell.css.
 * Mobile-first, WCAG AA, sin cajas negras pesadas ni desbordamiento horizontal.
 * ========================================================================== */

/* ---------- Contenedor principal y barra contextual ---------- */
.cp-wrap {
  width: 100%;
  max-width: none;
  padding-inline: 0;
  display: grid;
  gap: 18px;
  min-width: 0;
}
.cp-wrap > .org-breadcrumb {
  margin-bottom: -6px;
}

.cp-context-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--ui-border, var(--line));
}

.cp-context-left {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 14px;
  min-width: 0;
  flex: 1 1 280px;
}

.cp-picker {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  max-width: 100%;
}

.cp-picker label {
  margin: 0;
  font-size: 0.84rem;
  font-weight: 700;
  color: var(--text-muted);
  white-space: nowrap;
}

.cp-picker .input {
  min-height: 44px;
  min-width: 0;
  width: auto;
  max-width: min(320px, 60vw);
  padding: 6px 12px;
  border-radius: var(--ui-radius, 10px);
  border: 1.5px solid var(--line-control);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.88rem;
  font-weight: 700;
  box-shadow: var(--shadow-sm);
}

.cp-zip-btn {
  width: auto;
  min-height: 44px;
  border-radius: var(--ui-radius, 10px);
  padding: 0 16px;
  font-size: 0.86rem;
  font-weight: 700;
  white-space: nowrap;
  flex: 0 0 auto;
}

@media (max-width: 540px) {
  .cp-picker {
    flex: 1 1 100%;
  }

  .cp-picker .input {
    flex: 1 1 auto;
    width: 100%;
    max-width: 100%;
  }

  .cp-zip-btn {
    width: 100%;
  }
}

/* ---------- Cabecera de la rifa activa ---------- */
.cp-header-meta {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.cp-header-meta .pn-title {
  text-wrap: balance;
}

.cp-header-sub {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  min-width: 0;
}

.cp-raffle-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-muted);
  overflow-wrap: break-word;
  text-wrap: pretty;
}

.cp-meta-pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 3px 11px;
  border-radius: 999px;
  background: var(--accent-soft);
  border: 1px solid rgba(11, 110, 79, 0.22);
  color: var(--accent-ink);
  font-size: 0.8rem;
  font-weight: 700;
  white-space: nowrap;
}

.cp-meta-pill.is-muted {
  background: var(--n-100);
  border-color: var(--line);
  color: var(--text-muted);
}

.cp-auto {
  display: grid;
  gap: 10px;
  padding: 16px 18px;
  border-radius: var(--radius-md);
  background: var(--accent-soft);
  border: 1px solid rgba(11, 110, 79, 0.24);
}

.cp-auto p {
  margin: 0;
  font-weight: 600;
  color: var(--accent-ink);
}

/* ---------- Pestañas de canal (una sola fila, sin salto de tamaño) ---------- */
.cp-sections {
  display: grid;
  gap: 0;
  min-width: 0;
}

.cp-tabs {
  display: flex;
  overflow-x: auto;
  gap: 4px;
  scroll-snap-type: inline proximity;
  border-bottom: 1px solid var(--line);
  scrollbar-width: thin;
  min-width: 0;
}

.cp-tabs button[role="tab"] {
  flex: none;
  min-height: 50px;
  padding: 10px 16px;
  display: grid;
  gap: 2px;
  text-align: left;
  border: 0;
  background: transparent;
  cursor: pointer;
  position: relative;
  color: var(--text-muted);
  scroll-snap-align: start;
  font-family: inherit;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  transition: color 140ms ease, background-color 140ms ease;
}

@media (hover: hover) and (pointer: fine) {
  .cp-tabs button[role="tab"]:hover {
    color: var(--text);
    background: rgba(22, 19, 15, 0.04);
  }
}

.cp-tab-name {
  font-weight: 800;
  font-size: 0.92rem;
  line-height: 1.2;
  white-space: nowrap;
}

.cp-tab-sub {
  font-weight: 500;
  font-size: 0.74rem;
  line-height: 1.2;
  white-space: nowrap;
  color: var(--text-muted);
}

.cp-tabs button[role="tab"][aria-selected="true"] {
  color: var(--accent-ink);
}

.cp-tabs button[role="tab"][aria-selected="true"] .cp-tab-sub {
  color: var(--accent-ink);
}

.cp-tabs button[role="tab"][aria-selected="true"]::after {
  content: "";
  position: absolute;
  inset: auto 10px 0;
  border-block-end: 3px solid var(--accent);
}

@media (max-width: 640px) {
  .cp-tabs {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
    overflow-x: visible;
    border-bottom: 0;
  }

  .cp-tabs button[role="tab"] {
    min-width: 0;
    min-height: 48px;
    padding: 8px 12px;
    border: 1px solid var(--ui-border, var(--line));
    border-radius: var(--ui-radius, 10px);
    background: var(--surface);
  }

  .cp-tabs button[role="tab"][aria-selected="true"] {
    border-color: var(--accent);
    background: var(--accent-soft);
  }

  .cp-tabs button[role="tab"][aria-selected="true"]::after {
    display: none;
  }
}

.cp-panel {
  display: grid;
  gap: 18px;
  padding-top: 18px;
  min-width: 0;
}

/* ---------- Estudio de dos columnas ---------- */
.cp-studio {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 18px;
  align-items: start;
  min-width: 0;
}

@media (min-width: 960px) {
  .cp-studio {
    grid-template-columns: minmax(340px, 460px) minmax(0, 1fr);
    gap: 24px;
    align-items: start;
  }
}

/* ---------- Columna izquierda: escenario del lienzo ---------- */
.cp-stage {
  min-width: 0;
  display: grid;
  gap: 12px;
}

@media (min-width: 960px) and (min-height: 760px) {
  .cp-stage {
    position: sticky;
    top: 80px;
  }
}

.cp-stage-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 18px;
  display: grid;
  gap: 14px;
  min-width: 0;
  box-shadow: var(--shadow-sm);
}

.cp-stage-top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-width: 0;
}

.cp-formats {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.cp-format-btn {
  min-height: 40px;
  padding: 6px 14px;
  border-radius: 999px;
  border: 1.5px solid var(--line);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 0.84rem;
  font-weight: 700;
  cursor: pointer;
  transition: background-color 140ms ease, border-color 140ms ease, color 140ms ease;
}

@media (hover: hover) and (pointer: fine) {
  .cp-format-btn:hover {
    border-color: var(--n-400);
    background: var(--n-100);
  }
}

.cp-format-btn[aria-pressed="true"] {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent-ink);
}

.cp-stage-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  margin-left: auto;
}

.cp-dimensions {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--n-100);
  padding: 5px 10px;
  border-radius: 999px;
  white-space: nowrap;
}

.cp-safe-toggle {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 4px 6px;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  accent-color: var(--accent);
  white-space: nowrap;
}

.cp-safe-toggle input {
  width: 17px;
  height: 17px;
  margin: 0;
  cursor: pointer;
}

.cp-safe {
  margin: 0;
  font-size: 0.82rem;
  line-height: 1.45;
  color: var(--text-muted);
  background: var(--bg);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  border-left: 3px solid var(--accent);
}

.cp-canvas-mat {
  background: #ebe6dc;
  border-radius: var(--radius-md);
  padding: 16px;
  display: grid;
  place-items: center;
  min-height: 280px;
  border: 1px solid rgba(22, 19, 15, 0.06);
  min-width: 0;
}

.cp-canvas-frame {
  position: relative;
  display: inline-grid;
  max-width: 100%;
}

#cpCanvas {
  display: block;
  max-width: 100%;
  max-height: min(58dvh, 520px);
  width: auto;
  height: auto;
  border-radius: 10px;
  box-shadow: 0 12px 28px rgba(22, 19, 15, 0.16);
}

#cpSafeOverlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  border-radius: 10px;
  overflow: hidden;
}

.cp-safe-band {
  position: absolute;
  background: rgba(220, 38, 38, 0.22);
  border: 1px dashed rgba(220, 38, 38, 0.72);
  color: #ffffff;
  display: grid;
  place-items: center;
  padding: 4px;
  text-align: center;
  font-size: 0.72rem;
  font-weight: 800;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.65);
}

.cp-primary-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.cp-primary-actions .btn {
  flex: 1 1 160px;
  min-height: 44px;
}

/* ---------- Columna derecha: controles y mensaje ---------- */
.cp-controls {
  display: grid;
  gap: 16px;
  min-width: 0;
}

.cp-guide-banner {
  padding: 12px 14px;
  border-radius: var(--radius-md);
  background: var(--accent-soft);
  border: 1px solid rgba(11, 110, 79, 0.2);
  color: var(--accent-ink);
  font-size: 0.88rem;
  font-weight: 600;
  line-height: 1.45;
  text-wrap: pretty;
}

.cp-guide-banner:empty {
  display: none;
}

.cp-action-box {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 18px;
  display: grid;
  gap: 12px;
  min-width: 0;
  box-shadow: var(--shadow-sm);
}

.cp-action-box h3 {
  margin: 0;
  font-size: 1.02rem;
  font-weight: 800;
  letter-spacing: -0.01em;
  color: var(--text);
}

.cp-action-box p {
  margin: 0;
  font-size: 0.88rem;
  color: var(--text-muted);
  line-height: 1.45;
}

.cp-control-group {
  display: grid;
  gap: 8px;
  min-width: 0;
}

.cp-control-label {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--text-muted);
}

.cp-style-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 8px;
}

.cp-style-btn {
  min-height: 54px;
  text-align: left;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--line);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  cursor: pointer;
  display: grid;
  gap: 2px;
  align-content: center;
  transition: border-color 140ms ease, background-color 140ms ease, color 140ms ease;
}

@media (hover: hover) and (pointer: fine) {
  .cp-style-btn:hover {
    border-color: var(--n-400);
    background: var(--n-100);
  }
}

.cp-style-btn[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-ink);
}

.cp-style-name {
  font-weight: 800;
  font-size: 0.88rem;
  line-height: 1.25;
}

.cp-style-sub {
  font-weight: 500;
  font-size: 0.74rem;
  line-height: 1.3;
  color: var(--text-muted);
}

.cp-style-btn[aria-pressed="true"] .cp-style-sub {
  color: var(--accent-ink);
}

.cp-palettes {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.cp-palette-btn {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1.5px solid var(--line);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.84rem;
  font-weight: 700;
  cursor: pointer;
  transition: border-color 140ms ease, background-color 140ms ease, color 140ms ease;
}

@media (hover: hover) and (pointer: fine) {
  .cp-palette-btn:hover {
    border-color: var(--n-400);
    background: var(--n-100);
  }
}

.cp-swatch {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 1px solid rgba(0, 0, 0, 0.2);
  flex: none;
}

.cp-palette-btn[aria-pressed="true"] {
  border-color: var(--n-950);
  background: var(--n-950);
  color: var(--n-0);
}

.cp-palette-btn[aria-pressed="true"] .cp-swatch {
  border-color: rgba(255, 255, 255, 0.5);
}

.cp-checks {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
}

.cp-checks label {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  accent-color: var(--accent);
}

.cp-checks label input {
  width: 18px;
  height: 18px;
  margin: 0;
  cursor: pointer;
}

.cp-checks label.is-disabled,
.cp-checks label:has(input:disabled) {
  opacity: 0.6;
  cursor: not-allowed;
}

.cp-url-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-width: 0;
}

.cp-url-row .input {
  flex: 1 1 200px;
  min-width: 0;
  min-height: 44px;
  padding: 8px 12px;
  border: 1.5px solid var(--line-control);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: max(1rem, 0.84rem);
}

.cp-url-row .btn {
  min-height: 44px;
  flex: 0 0 auto;
}

.cp-tones {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.cp-tone-btn {
  min-height: 40px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1.5px solid var(--line);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
  transition: background-color 140ms ease, border-color 140ms ease, color 140ms ease;
}

.cp-tone-btn[aria-pressed="true"] {
  background: var(--n-950);
  color: var(--n-0);
  border-color: var(--n-950);
}

.cp-caption {
  width: 100%;
  min-height: 132px;
  font: inherit;
  font-size: max(1rem, 0.92rem);
  line-height: 1.5;
  padding: 12px 14px;
  border: 1.5px solid var(--line-control);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  resize: vertical;
}

.cp-btn-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.cp-btn-grid .btn {
  flex: 1 1 160px;
  min-height: 44px;
}

/* ---------- Panel A4 imprimible embebido ---------- */
.cp-a4-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 18px;
  align-items: start;
  min-width: 0;
}

@media (min-width: 960px) {
  .cp-a4-layout {
    grid-template-columns: minmax(0, 1fr) 330px;
    gap: 24px;
    align-items: start;
  }
}

.cp-a4-stage {
  background: #ebe6dc;
  border-radius: var(--radius-lg);
  padding: 14px;
  border: 1px solid rgba(22, 19, 15, 0.06);
  display: grid;
  place-items: center;
  min-width: 0;
}

#cpA4Frame {
  display: block;
  width: 100%;
  aspect-ratio: 210 / 297;
  max-height: 76dvh;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: #ebe6dc;
}

.cp-a4-controls .input {
  width: 100%;
  min-height: 44px;
  padding: 8px 12px;
  border: 1.5px solid var(--line-control);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: max(1rem, 0.9rem);
  font-weight: 600;
}

/* ---------- Vídeo promocional (cuando está activo) ---------- */
.cp-video {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 20px;
  display: grid;
  gap: 14px;
  max-width: 680px;
  box-shadow: var(--shadow-sm);
}

.cp-video p {
  margin: 0;
  line-height: 1.5;
}

.cp-video video {
  display: block;
  width: 100%;
  max-width: 340px;
  border-radius: var(--radius-md);
  background: #16130f;
}

.cp-status {
  font-weight: 700;
}

.cp-status.is-error {
  color: #b91c1c;
}

/* ---------- Accesibilidad, foco y notificaciones ---------- */
:where(
  .cp-tabs button[role="tab"],
  .cp-format-btn,
  .cp-style-btn,
  .cp-palette-btn,
  .cp-tone-btn,
  .cp-body select,
  .cp-body textarea,
  .cp-body input
):focus-visible {
  outline: 2.5px solid var(--accent);
  outline-offset: 2px;
}

.cp-body .pn-toast {
  white-space: normal;
  overflow-wrap: break-word;
  color: #f8fafc;
}

.cp-body .pn-toast.is-error {
  background: #7f1d1d;
  color: #ffffff;
  border-color: rgba(254, 202, 202, 0.38);
}

@media (prefers-reduced-motion: reduce) {
  .cp-tabs button[role="tab"],
  .cp-format-btn,
  .cp-style-btn,
  .cp-palette-btn,
  .cp-tone-btn,
  .cp-body .pn-toast {
    transition: none;
  }
}
