:root {
  --ink: #1d1b24;
  --ink-2: #4a4655;
  --muted: #6c6876;
  --line: #e4e2ea;
  --line-2: #d6d2de;
  --bg: #f3f2f6;
  --card: #ffffff;
  --brand: #4b2a7b;
  --brand-hover: #3b2063;
  --brand-soft: #efe9f7;
  --sel: #7c4dbd;
  --ok: #1c6b55;
  --ok-soft: #e3f4ef;
  --warn: #8a5200;
  --warn-soft: #fdf1dc;
  --danger: #b42318;
  --danger-soft: #fdecea;
  --radius: 10px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: 'DM Sans', system-ui, -apple-system, 'Segoe UI', sans-serif; background: var(--bg); color: var(--ink); font-size: 15px; line-height: 1.45; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--brand); }
a:hover { color: var(--brand-hover); }
h1, h2, h3 { margin: 0; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--sel); outline-offset: 2px; }

/* ── Barra superior ───────────────────────────── */
.top { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 24px; background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.top-izq { display: flex; align-items: center; gap: 24px; flex-wrap: wrap; }
.marca { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; text-decoration: none; color: var(--ink); }
.marca-icono { width: 30px; height: 30px; border-radius: 8px; background: var(--brand); display: grid; place-items: center; flex: none; }
.marca-icono img { width: 20px; height: 20px; display: block; }
.nav { display: flex; gap: 4px; flex-wrap: wrap; }
.nav a { padding: 8px 12px; border-radius: 8px; color: #55525e; font-weight: 500; font-size: 14px; text-decoration: none; }
.nav a[aria-current="page"] { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.nav a:hover { background: var(--bg); }
.top-der { display: flex; align-items: center; gap: 10px; font-size: 14px; color: #55525e; flex-wrap: wrap; }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--line); display: grid; place-items: center; font-weight: 600; font-size: 13px; color: var(--ink); }

/* ── Botones y campos ─────────────────────────── */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 40px; padding: 0 16px; border-radius: 8px; border: 1px solid var(--line-2); background: var(--card); font-size: 14px; font-weight: 600; color: var(--ink); cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { background: #faf9fc; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primario { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primario:hover { background: var(--brand-hover); }
.btn-peligro { color: var(--danger); }
.btn-peligro:hover { background: var(--danger-soft); }
.btn-chico { min-height: 34px; padding: 0 10px; font-size: 13px; }
.btn-icono { width: 36px; min-height: 36px; padding: 0; }
.btn-linea { border-style: dashed; color: var(--brand); width: 100%; }
.campo { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 500; color: var(--ink-2); }
.campo input, .campo select, .campo textarea, .entrada { min-height: 40px; border: 1px solid var(--line-2); border-radius: 8px; padding: 8px 10px; font-size: 14px; background: #fff; width: 100%; color: var(--ink); }
.campo textarea { resize: vertical; min-height: 64px; }
.campo input:focus, .campo select:focus, .campo textarea:focus, .entrada:focus { outline: none; border-color: var(--sel); box-shadow: 0 0 0 3px rgba(124, 77, 189, .15); }
.campo .ayuda { font-weight: 400; color: var(--muted); font-size: 12px; }
.check { display: flex; align-items: center; gap: 10px; font-size: 14px; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--brand); }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.segmento { display: flex; gap: 4px; padding: 4px; border-radius: 10px; background: var(--bg); }
.segmento button { flex: 1; min-height: 32px; border: 0; border-radius: 7px; background: transparent; font-size: 13px; font-weight: 600; color: var(--muted); cursor: pointer; padding: 0 10px; }
.segmento button[aria-pressed="true"] { background: #fff; color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.12); }
.etiqueta { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.et-ok { background: var(--ok-soft); color: var(--ok); }
.et-warn { background: var(--warn-soft); color: var(--warn); }
.et-brand { background: var(--brand-soft); color: var(--brand); }
.et-gris { background: var(--bg); color: var(--muted); }
.titulo-seccion { font-size: 12px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin-bottom: 8px; }

/* ── Páginas ──────────────────────────────────── */
.pagina { width: 100%; max-width: 1240px; margin: 0 auto; padding: 28px 24px 48px; display: flex; flex-direction: column; gap: 18px; }
.cabecera { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px; }
.cabecera p { margin: 4px 0 0; color: #55525e; font-size: 14px; }
.acciones { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.tarjeta { background: var(--card); border: 1px solid var(--line); border-radius: 12px; }
.vacio { padding: 48px 24px; text-align: center; color: var(--muted); }
.vacio h2 { color: var(--ink); font-size: 18px; margin-bottom: 6px; }
.vacio .btn { margin-top: 16px; }

/* Plantillas */
.plantillas { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 16px; }
.plantilla { display: flex; flex-direction: column; overflow: hidden; }
.plantilla-img { aspect-ratio: 1841 / 700; background: #fff; border-bottom: 1px solid var(--line); display: grid; place-items: center; color: var(--muted); font-size: 13px; overflow: hidden; }
.plantilla-img img { width: 100%; height: 100%; object-fit: contain; display: block; }
.plantilla-pie { padding: 14px 16px; display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.plantilla-pie h3 { font-size: 16px; }
.plantilla-pie small { color: var(--muted); }

/* Tabla */
.tabla-caja { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; background: #faf9fc; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .05em; font-weight: 600; padding: 12px 14px; white-space: nowrap; }
td { padding: 12px 14px; border-top: 1px solid #efedf3; vertical-align: top; }
td .sub { font-size: 13px; color: var(--muted); }
.pre { white-space: pre-line; }
.filtros { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.filtros .entrada { max-width: 320px; }
.resumen { display: flex; flex-wrap: wrap; gap: 12px; }
.dato { flex: 1 1 180px; padding: 14px 16px; }
.dato span { font-size: 13px; color: var(--muted); }
.dato b { display: block; font-size: 24px; margin-top: 2px; }

/* ── Editor ───────────────────────────────────── */
/* Tres columnas en pantallas anchas; en medianas, los datos pasan arriba
   y las propiedades quedan SIEMPRE al lado de la vista previa. */
.editor { display: grid; grid-template-columns: 280px minmax(0, 1fr) 300px; grid-template-areas: "izq centro der"; align-items: start; min-height: calc(100vh - 57px); }
.ed-izq { grid-area: izq; align-self: stretch; background: var(--card); border-right: 1px solid var(--line); padding: 20px 16px; display: flex; flex-direction: column; gap: 18px; }
.ed-centro { grid-area: centro; min-width: 0; padding: 20px 24px; display: flex; flex-direction: column; gap: 16px; }
.ed-der { grid-area: der; background: var(--card); border-left: 1px solid var(--line); padding: 20px; display: flex; flex-direction: column; gap: 14px; position: sticky; top: 57px; max-height: calc(100vh - 57px); overflow-y: auto; }
.editor > .ed-centro:only-child { grid-column: 1 / -1; }
.lista-campos { display: flex; flex-direction: column; gap: 4px; }
.fila-item { display: flex; align-items: center; gap: 2px; }
.fila-item .campo-fila { min-width: 0; }
.fila-item .campo-fila .nom { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nota-izq { margin: 0 0 8px; font-size: 13px; line-height: 1.45; color: var(--muted); }
.lista-redes { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px; }
.red-opcion { display: flex; align-items: center; gap: 6px; min-width: 0; min-height: 34px; padding: 4px 6px; border-radius: 8px; border: 1px solid transparent; font-size: 13px; cursor: pointer; color: var(--ink-2); }
.red-opcion:hover { background: #faf9fc; }
.red-opcion.on { border-color: #cbb8e6; background: #f3edfb; color: var(--ink); }
.red-opcion input { width: 16px; height: 16px; accent-color: var(--brand); flex: none; }
.red-opcion svg { flex: none; color: var(--brand); }
.red-opcion span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.agregar-elementos { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
@media (max-width: 1180px) {
  .editor { grid-template-columns: minmax(0, 1fr) 290px; grid-template-areas: "izq izq" "centro der"; }
  .ed-izq { border-right: 0; border-bottom: 1px solid var(--line); padding: 12px 16px; gap: 6px; }
  .ed-izq .titulo-seccion { margin-bottom: 4px; }
  .ed-izq { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px; align-items: start; }
  .ed-izq .consejo { display: none; }
  .lista-redes { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
  .lista-campos .campo-fila { min-height: 40px; }
}
@media (max-width: 760px) {
  .editor { grid-template-columns: minmax(0, 1fr); grid-template-areas: "izq" "centro" "der"; }
  .ed-der { position: static; max-height: none; border-left: 0; border-top: 1px solid var(--line); }
}
.ed-cab { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; }
.ed-nombre { font-size: 20px; font-weight: 700; border: 1px solid transparent; border-radius: 8px; padding: 4px 8px; margin-left: -8px; background: transparent; min-width: 0; width: min(420px, 100%); }
.ed-nombre:hover { border-color: var(--line-2); }
.ed-nombre:focus { outline: none; border-color: var(--sel); background: #fff; }
.estado-guardado { font-size: 13px; color: var(--muted); }
.estado-guardado.sucio { color: var(--warn); font-weight: 600; }
.campo-fila { display: flex; align-items: center; gap: 10px; width: 100%; min-height: 44px; padding: 6px 8px; border-radius: 8px; cursor: pointer; border: 1px solid transparent; background: transparent; text-align: left; }
.campo-fila:hover { background: #faf9fc; }
.campo-fila[aria-pressed="true"] { border-color: #cbb8e6; background: #f3edfb; }
.campo-fila .ic { width: 28px; height: 28px; border-radius: 6px; background: var(--bg); display: grid; place-items: center; font-size: 12px; font-weight: 700; color: var(--brand); flex: none; }
.campo-fila .nom { flex: 1; font-size: 14px; font-weight: 500; }
.campo-fila .tam { font-size: 12px; color: var(--muted); }
.campo-fila.oculto .nom { color: var(--muted); text-decoration: line-through; }
.consejo { padding: 12px; border-radius: 10px; background: #f6f3fb; font-size: 13px; line-height: 1.5; color: var(--ink-2); }
.lienzo-caja { position: relative; width: 100%; background: #fff; outline: 1px solid #ece9f1; border-radius: 6px; user-select: none; touch-action: none; }
.lienzo-caja canvas { display: block; width: 100%; height: auto; border-radius: 6px; }
.caja-campo { position: absolute; cursor: move; border: 1px dashed transparent; border-radius: 3px; }
.caja-campo:hover { border-color: rgba(124, 77, 189, .55); }
.caja-campo.sel { border: 2px solid var(--sel); }
.caja-campo .asa { position: absolute; right: -7px; top: 50%; width: 12px; height: 24px; margin-top: -12px; border-radius: 4px; background: #fff; border: 2px solid var(--sel); cursor: ew-resize; display: none; }
.caja-campo.sel .asa { display: block; }
.caja-campo .chip { position: absolute; left: -2px; top: -22px; background: var(--sel); color: #fff; font-size: 11px; font-weight: 600; padding: 2px 6px; border-radius: 4px 4px 0 0; white-space: nowrap; display: none; }
.caja-campo.sel .chip { display: block; }
.caja-campo .aviso-achicado { position: absolute; right: -2px; bottom: -20px; font-size: 11px; color: var(--warn); background: var(--warn-soft); padding: 1px 6px; border-radius: 4px; white-space: nowrap; display: none; }
.caja-campo.sel .aviso-achicado.on { display: block; }
.datos-lienzo { display: flex; flex-wrap: wrap; gap: 16px; font-size: 13px; color: var(--muted); }
.subir-fondo { border: 2px dashed var(--line-2); border-radius: 12px; padding: 48px 24px; text-align: center; background: #fff; }
.subir-fondo.arrastrando { border-color: var(--sel); background: #f6f3fb; }
.subir-fondo h2 { font-size: 18px; margin-bottom: 6px; }
.subir-fondo p { color: var(--muted); margin: 0 auto 16px; max-width: 520px; }
.color-fila { display: flex; gap: 8px; align-items: center; }
.color-fila input[type=color] { width: 44px; height: 40px; padding: 2px; border: 1px solid var(--line-2); border-radius: 8px; background: #fff; cursor: pointer; flex: none; }

/* ── Login ────────────────────────────────────── */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login form { width: 100%; max-width: 380px; padding: 28px; display: flex; flex-direction: column; gap: 14px; }
.login h1 { font-size: 22px; }
.login p { margin: 0; color: var(--muted); font-size: 14px; }
.error { color: var(--danger); font-size: 14px; min-height: 1.2em; }

/* ── Modal ────────────────────────────────────── */
.fondo-modal { position: fixed; inset: 0; background: rgba(20, 14, 34, .45); display: grid; place-items: center; padding: 16px; z-index: 50; }
.modal { width: 100%; max-width: 520px; max-height: calc(100vh - 32px); overflow: auto; background: #fff; border-radius: 14px; box-shadow: 0 20px 50px rgba(20, 10, 40, .3); }
.modal.ancho { max-width: 1000px; }
.modal-cab { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 18px 20px 0; }
.modal-cab h2 { font-size: 18px; }
.modal-cuerpo { padding: 18px 20px; display: flex; flex-direction: column; gap: 14px; }
.modal-pie { padding: 0 20px 18px; display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }

/* ── Avisos ───────────────────────────────────── */
#toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 60; max-width: calc(100vw - 32px); }
.toast { background: var(--ink); color: #fff; padding: 12px 16px; border-radius: 10px; font-size: 14px; box-shadow: 0 8px 24px rgba(0,0,0,.2); max-width: 420px; }
.toast.err { background: var(--danger); }

@media (max-width: 640px) {
  .top { padding: 10px 16px; }
  .pagina { padding: 20px 16px 40px; }
  .ed-centro { padding: 16px; }
}
