/* ==========================================================
   Catalyx · interfaz del administrador
   ========================================================== */
:root {
  --bg: #f3f4f8;
  --panel: #ffffff;
  --panel-2: #f7f7fb;
  --line: #e5e7ef;
  --text: #14161c;
  --muted: #6b7080;
  --brand: #7c3aed;
  --brand-2: #10b981;
  --brand-ink: #ffffff;
  --brand-soft: #efe8ff;
  --danger: #e5484d;
  --danger-soft: #fdecec;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 18, 27, .06), 0 8px 24px rgba(16, 18, 27, .06);
  --tabbar-h: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d0e12; --panel: #16181f; --panel-2: #1c1f28; --line: #272b37;
    --text: #eef0f6; --muted: #9aa0b2; --brand-soft: #2a2140; --danger-soft: #3a1c1f;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.3);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0d0e12; --panel: #16181f; --panel-2: #1c1f28; --line: #272b37;
  --text: #eef0f6; --muted: #9aa0b2; --brand-soft: #2a2140; --danger-soft: #3a1c1f;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.3);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
button, input, select, textarea { font: inherit; color: inherit; }
img { display: block; max-width: 100%; }
[hidden] { display: none !important; }

/* ---------- Botones ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid transparent; border-radius: 11px; padding: 9px 14px;
  font-weight: 600; font-size: 14px; cursor: pointer; white-space: nowrap;
  background: var(--panel-2); transition: transform .12s, background .15s, opacity .15s;
  text-decoration: none;
}
.btn:active { transform: scale(.97); }
.btn.primary { background: linear-gradient(135deg, var(--brand), #9b5cff); color: var(--brand-ink); box-shadow: 0 6px 18px -6px rgba(124, 58, 237, .6); }
.btn.ghost { background: transparent; border-color: var(--line); }
.btn.soft { background: var(--brand-soft); color: var(--brand); }
.btn.wa { background: #25d366; color: #fff; }
.btn.danger-soft { background: var(--danger-soft); color: var(--danger); }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; pointer-events: none; }
.icon-btn {
  width: 38px; height: 38px; border-radius: 10px; border: 0; background: var(--panel-2);
  cursor: pointer; display: grid; place-items: center; font-size: 16px; flex: none;
}
.icon-btn:hover { background: var(--line); }
.link { background: none; border: 0; color: var(--brand); cursor: pointer; padding: 0; font-size: 13px; font-weight: 600; }

/* ---------- Layout principal ---------- */
.app { display: grid; grid-template-rows: auto 1fr; height: 100dvh; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line);
  padding-top: max(10px, env(safe-area-inset-top));
}
.brand { display: flex; align-items: center; gap: 8px; min-width: 0; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; color: #fff;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  box-shadow: 0 6px 16px -6px rgba(124, 58, 237, .7);
}
.brand-mark svg { width: 20px; height: 20px; }
.brand-name { font-weight: 800; font-size: 19px; letter-spacing: -.02em; }
.beta { font-size: 10px; font-weight: 800; letter-spacing: .08em; padding: 2px 6px; border-radius: 6px; background: var(--brand-soft); color: var(--brand); }
.top-actions { display: flex; gap: 8px; }

.workspace {
  display: grid; grid-template-columns: 260px minmax(0, 1fr) 440px;
  min-height: 0;
}
.panel { min-height: 0; overflow-y: auto; overscroll-behavior: contain; }
.panel.designs { background: var(--panel); border-right: 1px solid var(--line); padding: 16px 14px 24px; }
.panel.editor { background: var(--panel); border-left: 1px solid var(--line); padding: 14px 18px 32px; }
.panel.preview { display: flex; flex-direction: column; overflow: hidden; }

.panel-head h2, .h { margin: 0; font-size: 18px; letter-spacing: -.01em; }
.panel-head p { margin: 2px 0 14px; color: var(--muted); font-size: 13px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 14px 0 10px; }
.tip { font-size: 12.5px; color: var(--muted); margin: 14px 2px 0; }

/* ---------- Diseños ---------- */
.theme-list { display: grid; gap: 10px; }
.theme-card {
  display: grid; grid-template-columns: 54px 1fr; gap: 10px; align-items: center; text-align: left;
  padding: 8px; border-radius: 13px; border: 1.5px solid var(--line); background: var(--panel);
  cursor: pointer; transition: border-color .15s, transform .12s, box-shadow .15s;
}
.theme-card:hover { transform: translateY(-1px); box-shadow: var(--shadow); }
.theme-card.on { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.theme-thumb {
  width: 54px; height: 54px; border-radius: 10px; position: relative; overflow: hidden;
  display: grid; place-items: center; font-size: 22px;
}
.theme-thumb::after {
  content: ""; position: absolute; left: 6px; right: 6px; bottom: 6px; height: 8px; border-radius: 4px;
  background: var(--t-accent); opacity: .95;
}
.theme-card b { display: block; font-size: 14px; }
.theme-card small { display: block; color: var(--muted); font-size: 12px; line-height: 1.3; }
.accent-box { margin-top: 18px; }
.accent-box h3 { font-size: 13px; margin: 0 0 8px; color: var(--muted); font-weight: 600; }
.accent-list { display: flex; flex-wrap: wrap; gap: 8px; }
.accent-dot {
  width: 30px; height: 30px; border-radius: 50%; border: 2px solid var(--panel); cursor: pointer;
  box-shadow: 0 0 0 1.5px var(--line); position: relative; padding: 0;
}
.accent-dot.on { box-shadow: 0 0 0 2.5px var(--text); }
.accent-dot.auto { background: conic-gradient(#ff3d7f, #facc15, #22d3ee, #7c3aed, #ff3d7f); }
.accent-dot input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

/* ---------- Vista previa ---------- */
.preview-bar { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 16px 0; flex-wrap: wrap; }
.preview-hint { color: var(--muted); font-size: 12.5px; }
.seg { display: inline-flex; background: var(--panel-2); border: 1px solid var(--line); border-radius: 12px; padding: 3px; gap: 2px; }
.seg button { border: 0; background: transparent; padding: 7px 12px; border-radius: 9px; cursor: pointer; font-weight: 600; font-size: 13px; color: var(--muted); }
.seg button.on { background: var(--panel); color: var(--text); box-shadow: var(--shadow); }
.preview .seg { background: var(--panel); }
.preview .seg button.on { background: var(--brand-soft); color: var(--brand); box-shadow: none; }
.stage { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; padding: 14px 16px 18px; }
.device {
  position: relative; background: #000; overflow: hidden; box-shadow: 0 30px 60px -20px rgba(0,0,0,.35), 0 0 0 1px rgba(0,0,0,.08);
}
.device.phone { width: 380px; max-width: 100%; height: min(780px, 100%); border-radius: 38px; border: 10px solid #111; }
.device.desktop { width: 100%; height: 100%; border-radius: 14px; border: 6px solid #111; border-top-width: 24px; }
.device.desktop::before { content: "● ● ●"; position: absolute; top: -21px; left: 10px; color: #555; font-size: 10px; letter-spacing: 2px; }
.device > .cx-root { position: absolute; inset: 0; }

/* ---------- Editor ---------- */
.tabs { width: 100%; display: grid; grid-template-columns: repeat(3, 1fr); position: sticky; top: -14px; z-index: 2; }
.tab { animation: fadeIn .2s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin: 4px 0 10px; }
.chip {
  border: 1px solid var(--line); background: var(--panel); border-radius: 99px; padding: 5px 11px;
  font-size: 13px; cursor: pointer; font-weight: 500; display: inline-flex; align-items: center; gap: 6px;
}
.chip.on { background: var(--text); color: var(--panel); border-color: var(--text); }
.chip .x { font-size: 11px; opacity: .7; }

.p-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.p-item {
  display: grid; grid-template-columns: 34px 54px 1fr auto; align-items: center; gap: 10px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 13px; padding: 7px 8px 7px 2px;
  transition: box-shadow .15s;
}
.p-item:hover { box-shadow: var(--shadow); }
.p-item.is-off { opacity: .55; }
.p-item .handle {
  height: 54px; display: grid; place-items: center; cursor: grab; color: var(--muted); font-size: 18px;
  touch-action: none; user-select: none; letter-spacing: -3px;
}
.p-item img { width: 54px; height: 54px; border-radius: 10px; object-fit: cover; background: var(--panel-2); }
.p-info { min-width: 0; cursor: pointer; }
.p-info b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 14.5px; }
.p-info small { color: var(--muted); font-size: 12.5px; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.p-info .pill { display: inline-block; font-size: 10.5px; font-weight: 700; padding: 1px 6px; border-radius: 6px; background: var(--brand-soft); color: var(--brand); margin-left: 4px; vertical-align: 1px; }
.p-acts { display: flex; gap: 4px; }
.p-acts .icon-btn { width: 34px; height: 34px; font-size: 14px; }
.sortable-ghost { opacity: .35; }
.sortable-chosen { box-shadow: 0 14px 30px -10px rgba(0,0,0,.35); transform: scale(1.02); }
.sortable-drag { opacity: .95; }

.empty { text-align: center; padding: 30px 10px; border: 1.5px dashed var(--line); border-radius: 16px; }
.empty-ico { font-size: 40px; }

/* ---------- Formularios ---------- */
.form { display: grid; gap: 12px; margin-top: 12px; }
.field { display: grid; gap: 5px; font-size: 13px; font-weight: 600; }
.field > span { color: var(--text); }
.field small { font-weight: 400; color: var(--muted); font-size: 12px; }
.field input:not([type="checkbox"]):not([type="color"]), .field select, .field textarea, .inline-add input:not([type="color"]) {
  width: 100%; border: 1px solid var(--line); background: var(--panel-2); border-radius: 10px;
  padding: 10px 12px; font-weight: 400; font-size: 15px; outline: none; transition: border-color .15s, box-shadow .15s;
}
.field input:focus, .field select:focus, .field textarea:focus, .inline-add input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.field textarea { resize: vertical; min-height: 44px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stack { display: grid; gap: 10px; margin-top: 14px; }
code { background: var(--panel-2); padding: 1px 5px; border-radius: 5px; font-size: 12px; }

.switch { display: inline-flex; align-items: center; gap: 10px; font-size: 14px; font-weight: 500; cursor: pointer; user-select: none; }
.switch input { display: none; }
.switch span { width: 40px; height: 23px; border-radius: 99px; background: var(--line); position: relative; transition: background .2s; flex: none; }
.switch span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 17px; height: 17px; border-radius: 50%; background: #fff; transition: transform .2s; box-shadow: 0 1px 3px rgba(0,0,0,.25); }
.switch input:checked + span { background: var(--brand-2); }
.switch input:checked + span::after { transform: translateX(17px); }
.switch-row { display: flex; gap: 22px; flex-wrap: wrap; padding: 4px 0; }

.media-pick { display: grid; grid-template-columns: 92px 1fr; gap: 10px; }
.logo-pick, .cover-pick {
  position: relative; height: 92px; border-radius: 14px; border: 1.5px dashed var(--line); cursor: pointer;
  display: grid; place-items: center; overflow: hidden; background: var(--panel-2); font-size: 12.5px; color: var(--muted); font-weight: 600;
}
.logo-pick { border-radius: 50%; }
.logo-pick img, .cover-pick img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.logo-pick img:not([src]), .cover-pick img:not([src]), .logo-pick img[src=""], .cover-pick img[src=""] { display: none; }
.media-clear { display: flex; gap: 16px; margin-top: -4px; }

.img-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(78px, 1fr)); gap: 8px; }
.img-cell { position: relative; aspect-ratio: 1; border-radius: 12px; overflow: hidden; background: var(--panel-2); }
.img-cell img { width: 100%; height: 100%; object-fit: cover; }
.img-cell .main-tag { position: absolute; left: 4px; top: 4px; background: rgba(0,0,0,.65); color: #fff; font-size: 10px; padding: 1px 5px; border-radius: 5px; font-weight: 700; }
.img-cell .img-acts { position: absolute; right: 4px; top: 4px; display: flex; gap: 4px; }
.img-cell .img-acts button { width: 24px; height: 24px; border-radius: 50%; border: 0; background: rgba(0,0,0,.65); color: #fff; font-size: 11px; cursor: pointer; display: grid; place-items: center; padding: 0; }
.img-add {
  aspect-ratio: 1; border-radius: 12px; border: 1.5px dashed var(--brand); color: var(--brand); background: var(--brand-soft);
  display: grid; place-items: center; text-align: center; font-size: 12px; font-weight: 700; cursor: pointer; line-height: 1.2;
}
.img-add b { font-size: 22px; display: block; }

.color-presets { display: flex; flex-wrap: wrap; gap: 7px; }
.color-chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px 4px 4px; border-radius: 99px;
  border: 1px solid var(--line); background: var(--panel); cursor: pointer; font-size: 12.5px; font-weight: 500;
}
.color-chip i { width: 18px; height: 18px; border-radius: 50%; box-shadow: inset 0 0 0 1px rgba(0,0,0,.15); }
.color-chip.on { border-color: var(--brand); background: var(--brand-soft); color: var(--brand); font-weight: 700; }
.size-presets { display: flex; flex-wrap: wrap; gap: 6px; }
.size-presets .chip { font-size: 12px; padding: 4px 9px; }
.inline-add { display: flex; gap: 8px; margin-top: 8px; align-items: center; }
.inline-add input[type="color"] { width: 44px; height: 42px; border: 1px solid var(--line); border-radius: 10px; padding: 3px; background: var(--panel-2); flex: none; cursor: pointer; }
.chips.sel:empty { display: none; }
.chips.sel { margin: 8px 0 0; }

.coupon-form { padding: 14px; background: var(--panel-2); border-radius: 16px; border: 1px solid var(--line); }
.coupon-list { list-style: none; padding: 0; margin: 14px 0 0; display: grid; gap: 8px; }
.coupon {
  display: grid; grid-template-columns: 1fr auto auto; gap: 10px; align-items: center;
  padding: 12px; border-radius: 13px; border: 1.5px dashed var(--brand); background: var(--panel);
}
.coupon.off { border-color: var(--line); opacity: .6; }
.coupon b { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 15px; letter-spacing: .04em; }
.coupon small { display: block; color: var(--muted); font-size: 12.5px; }

/* ---------- Diálogos ---------- */
dialog.sheet {
  border: 0; padding: 0; background: transparent; color: var(--text);
  width: min(620px, calc(100vw - 24px)); max-height: calc(100dvh - 32px);
}
dialog.sheet.small { width: min(460px, calc(100vw - 24px)); }
dialog.sheet::backdrop { background: rgba(10, 10, 20, .55); backdrop-filter: blur(3px); }
dialog.sheet[open] { animation: pop .22s cubic-bezier(.2, .9, .3, 1.2); }
@keyframes pop { from { opacity: 0; transform: translateY(14px) scale(.98); } to { opacity: 1; transform: none; } }
.sheet-inner { background: var(--panel); border-radius: 20px; display: flex; flex-direction: column; max-height: calc(100dvh - 32px); overflow: hidden; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.sheet-head h2 { margin: 0; font-size: 17px; }
.sheet-body { padding: 16px; overflow-y: auto; display: grid; gap: 14px; }
.sheet-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--line); padding-bottom: max(12px, env(safe-area-inset-bottom)); }
.pub-link { display: flex; gap: 8px; }
.pub-link input { flex: 1; min-width: 0; border: 1px solid var(--line); background: var(--panel-2); border-radius: 10px; padding: 10px 12px; font-size: 14px; }
.steps { margin: 0; padding-left: 20px; display: grid; gap: 6px; font-size: 14px; }
.note { font-size: 13px; padding: 10px 12px; border-radius: 12px; background: var(--brand-soft); }

/* ---------- Vista cliente a pantalla completa / pública ---------- */
.fullview, .public { position: fixed; inset: 0; z-index: 50; background: #000; }
.fullview > .cx-root, .public > .cx-root { position: absolute; inset: 0; }

/* ---------- Toast ---------- */
.app-toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 30px); opacity: 0; pointer-events: none;
  background: #16181f; color: #fff; padding: 11px 14px; border-radius: 12px; font-size: 14px; z-index: 100;
  display: flex; gap: 14px; align-items: center; box-shadow: 0 12px 30px rgba(0,0,0,.3); transition: .25s; max-width: calc(100vw - 32px);
}
.app-toast.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
.app-toast button { background: none; border: 0; color: #a78bfa; font-weight: 700; cursor: pointer; padding: 0; }

/* ---------- Barra inferior móvil ---------- */
.tabbar { display: none; }

/* ---------- Responsive ---------- */
@media (max-width: 1180px) {
  .workspace { grid-template-columns: 220px minmax(0, 1fr) 390px; }
  .theme-card { grid-template-columns: 44px 1fr; }
  .theme-thumb { width: 44px; height: 44px; font-size: 18px; }
  .theme-card small { display: none; }
}
@media (max-width: 920px) {
  .app { grid-template-rows: auto 1fr auto; }
  .workspace { display: block; position: relative; }
  .panel { position: absolute; inset: 0; border: 0 !important; }
  .panel:not(.on) { display: none !important; }
  .panel.on { display: block; }
  .panel.preview.on { display: flex; }
  .panel.designs, .panel.editor { padding: 14px 16px calc(24px + var(--tabbar-h)); }
  .theme-list { grid-template-columns: 1fr 1fr; }
  .theme-card { grid-template-columns: 1fr; text-align: center; justify-items: center; }
  .theme-thumb { width: 100%; height: 64px; font-size: 24px; }
  .theme-card small { display: block; }
  .preview-bar { display: none; }
  .stage { padding: 0; }
  .device, .device.phone, .device.desktop { width: 100%; height: 100%; border: 0; border-radius: 0; box-shadow: none; }
  .device.desktop::before { display: none; }
  .tabs { top: -14px; }
  .tabbar {
    display: grid; grid-template-columns: repeat(3, 1fr); background: var(--panel); border-top: 1px solid var(--line);
    padding-bottom: env(safe-area-inset-bottom); z-index: 5;
  }
  .tabbar button { border: 0; background: none; display: grid; justify-items: center; gap: 1px; padding: 8px 0 9px; font-size: 20px; cursor: pointer; color: var(--muted); }
  .tabbar button span { font-size: 11.5px; font-weight: 600; }
  .tabbar button.on { color: var(--brand); }
  .tabbar button.on span { color: var(--brand); }
  .app-toast { bottom: calc(var(--tabbar-h) + 14px); }
  .hide-sm { display: none; }
  dialog.sheet, dialog.sheet.small { width: 100vw; max-width: 100vw; max-height: 100dvh; margin: auto 0 0; }
  .sheet-inner { border-radius: 20px 20px 0 0; max-height: 94dvh; }
}
@media (max-width: 480px) {
  .hide-xs { display: none; }
  .topbar { padding-left: 12px; padding-right: 12px; }
  .top-actions .btn { padding: 9px 11px; }
  .grid2 { grid-template-columns: 1fr 1fr; gap: 8px; }
}

/* ---------- Estado de guardado y cuenta ---------- */
.save-status { align-self: center; font-size: 12.5px; color: var(--muted); white-space: nowrap; }
.save-status[data-kind="ok"] { color: var(--brand-2); }
.save-status[data-kind="err"] { color: var(--danger); }
.account-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px; border-radius: 14px; background: var(--panel-2); }
.account-row b { display: block; word-break: break-all; }

/* ---------- Pantalla de ingreso ---------- */
body:has(.auth:not([hidden])) { overflow: auto; }
.auth {
  min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px;
  background: radial-gradient(900px 500px at 0% 0%, rgba(124, 58, 237, .18), transparent 60%), radial-gradient(800px 500px at 100% 100%, rgba(16, 185, 129, .16), transparent 60%), var(--bg);
}
.auth-card { width: min(420px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 24px; padding: 28px 24px; box-shadow: var(--shadow); }
.auth-card h1 { font-size: 24px; letter-spacing: -.02em; margin: 18px 0 6px; line-height: 1.2; }
.auth-card .form { margin-top: 16px; }
.brand.big .brand-mark { width: 42px; height: 42px; border-radius: 12px; }
.brand.big .brand-name { font-size: 24px; }
.code-input { font-size: 24px !important; letter-spacing: .4em; text-align: center; font-variant-numeric: tabular-nums; }
.auth-msg { color: var(--danger); font-size: 13.5px; min-height: 1em; margin: 10px 0 0; }
.auth-perks { list-style: none; padding: 14px 0 0; margin: 14px 0 0; border-top: 1px solid var(--line); display: grid; gap: 6px; font-size: 13.5px; color: var(--muted); }
