:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f9fafb;
  --ink: #111827;
  --ink-2: #374151;
  --muted: #6b7280;
  --line: #e5e7eb;
  --line-strong: #d1d5db;
  --brand: #111827;
  --accent: #2563eb;
  --accent-soft: #eff6ff;
  --ok: #059669;
  --ok-soft: #ecfdf5;
  --warn: #d97706;
  --warn-soft: #fffbeb;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --z-product: #2563eb;
  --z-media: #db2777;
  --z-jump: #7c3aed;
  --z-link: #059669;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(17, 24, 39, .06), 0 4px 16px rgba(17, 24, 39, .06);
  --shadow-lg: 0 10px 40px rgba(17, 24, 39, .18);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.5 Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 20px; font-weight: 650; }
h2 { font-size: 16px; font-weight: 650; }
h3 { font-size: 14px; font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
.hidden { display: none !important; }

/* ---------- botones y formularios ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 34px; padding: 0 14px; border-radius: 8px;
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink);
  font-weight: 550; white-space: nowrap; text-decoration: none;
  transition: background .15s, border-color .15s, box-shadow .15s;
}
.btn:hover { background: var(--surface-2); border-color: #9ca3af; }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: #1f2937; }
.btn.accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: var(--danger); border-color: #fecaca; }
.btn.danger:hover { background: var(--danger-soft); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: #f3f4f6; }
.btn.sm { height: 28px; padding: 0 10px; font-size: 13px; }
.btn.icon { width: 34px; padding: 0; }
.btn.sm.icon { width: 28px; }
.btn.is-on { background: var(--accent-soft); border-color: #bfdbfe; color: var(--accent); }

label.field { display: grid; gap: 5px; font-size: 13px; font-weight: 550; color: var(--ink-2); }
label.field small { font-weight: 400; color: var(--muted); }
.input, select.input, textarea.input {
  width: 100%; height: 36px; padding: 0 10px; border-radius: 8px;
  border: 1px solid var(--line-strong); background: var(--surface); font-weight: 400;
}
textarea.input { height: auto; min-height: 80px; padding: 8px 10px; resize: vertical; }
.input:focus { outline: 2px solid #bfdbfe; border-color: var(--accent); }
.check { display: flex; align-items: flex-start; gap: 8px; font-size: 13px; }
.check input { margin-top: 3px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.form-grid .span-2 { grid-column: span 2; }
.row { display: flex; align-items: center; gap: 8px; }
.row.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }
.stack { display: grid; gap: 14px; }

/* ---------- estructura ---------- */
.shell { display: grid; grid-template-columns: 232px minmax(0, 1fr); height: 100vh; }
.side {
  background: var(--surface); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; min-height: 0;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 18px 18px 14px; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 8px; background: var(--brand); color: #fff;
  display: grid; place-items: center; font-weight: 700; font-size: 13px; letter-spacing: -.02em;
}
.brand strong { display: block; font-size: 14px; }
.brand span { display: block; font-size: 12px; color: var(--muted); }
.tenant-switch { padding: 0 14px 12px; }
.nav { display: grid; gap: 2px; padding: 6px 10px; }
.nav-label { padding: 14px 10px 4px; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; }
.nav button {
  display: flex; align-items: center; gap: 10px; width: 100%; height: 36px; padding: 0 10px;
  border: 0; border-radius: 8px; background: transparent; color: var(--ink-2); font-weight: 520; text-align: left;
}
.nav button:hover { background: #f3f4f6; }
.nav button.is-active { background: #f3f4f6; color: var(--ink); font-weight: 600; }
.nav svg { width: 17px; height: 17px; flex: none; color: var(--muted); }
.side-foot { margin-top: auto; padding: 12px 14px; border-top: 1px solid var(--line); display: grid; gap: 6px; }
.side-foot .who { font-size: 13px; font-weight: 600; }
.side-foot .who span { display: block; font-weight: 400; color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; }

.main { min-width: 0; min-height: 0; overflow: auto; }
.page { padding: 26px 32px 60px; max-width: 1280px; }
.page-head { display: flex; align-items: flex-end; gap: 12px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head p { margin: 4px 0 0; color: var(--muted); }
.crumbs { font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.crumbs button { border: 0; background: none; padding: 0; color: var(--muted); }
.crumbs button:hover { color: var(--ink); text-decoration: underline; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 18px 20px; }
.card-head { display: flex; align-items: center; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.card + .card { margin-top: 16px; }
.kpis > .card, .media-grid > .card, .catalog-grid > .card, .two-col > .card { margin-top: 0; }

.pill {
  display: inline-flex; align-items: center; gap: 5px; height: 22px; padding: 0 8px; border-radius: 99px;
  font-size: 12px; font-weight: 600; background: #f3f4f6; color: var(--ink-2);
}
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .7; }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.danger { background: var(--danger-soft); color: var(--danger); }
.pill.info { background: var(--accent-soft); color: var(--accent); }

.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 20px; }
.tabs button {
  border: 0; background: none; padding: 10px 14px; color: var(--muted); font-weight: 550;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tabs button.is-active { color: var(--ink); border-bottom-color: var(--ink); }

.empty { padding: 48px 20px; text-align: center; color: var(--muted); }
.empty h2 { color: var(--ink); margin-bottom: 6px; }

table.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); padding: 10px 14px; border-bottom: 1px solid var(--line); background: var(--surface-2); }
.table td { padding: 10px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table .thumb { width: 44px; height: 44px; border-radius: 6px; object-fit: cover; background: #f3f4f6; display: block; }

/* ---------- login ---------- */
.login {
  min-height: 100vh; display: grid; place-items: center; padding: 20px;
  background: radial-gradient(1200px 600px at 20% -10%, #e0e7ff 0, transparent 60%), var(--bg);
}
.login .card { width: min(380px, 100%); padding: 30px 28px; }
.login h1 { margin: 18px 0 4px; }
.login form { display: grid; gap: 14px; margin-top: 22px; }
.form-error { color: var(--danger); font-size: 13px; min-height: 18px; }

/* ---------- catálogos ---------- */
.catalog-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 18px; }
.catalog-card { overflow: hidden; display: flex; flex-direction: column; cursor: pointer; transition: transform .15s, box-shadow .15s; }
.catalog-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.catalog-cover { aspect-ratio: 3 / 4; background: #eef0f3 center / cover no-repeat; position: relative; border-bottom: 1px solid var(--line); }
.catalog-cover .pill { position: absolute; top: 10px; left: 10px; box-shadow: var(--shadow); }
.catalog-cover.is-empty { display: grid; place-items: center; color: var(--muted); }
.catalog-meta { padding: 12px 14px 14px; display: grid; gap: 4px; }
.catalog-meta h3 { font-size: 14px; }
.catalog-meta .small { display: flex; gap: 10px; }
.new-card { border: 1.5px dashed var(--line-strong); background: transparent; box-shadow: none; display: grid; place-items: center; min-height: 300px; color: var(--muted); font-weight: 600; }
.new-card:hover { border-color: var(--ink); color: var(--ink); }

/* ---------- modal ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(17, 24, 39, .45); display: grid; place-items: center; z-index: 50; padding: 20px; animation: fade .15s; }
.modal { width: min(560px, 100%); max-height: calc(100vh - 40px); overflow: auto; background: var(--surface); border-radius: 14px; box-shadow: var(--shadow-lg); }
.modal header { display: flex; align-items: center; padding: 18px 22px 0; }
.modal .body { padding: 18px 22px; display: grid; gap: 14px; }
.modal footer { display: flex; justify-content: flex-end; gap: 8px; padding: 0 22px 20px; }
@keyframes fade { from { opacity: 0; } }

.dropzone {
  border: 1.5px dashed var(--line-strong); border-radius: 12px; padding: 28px; text-align: center;
  background: var(--surface-2); color: var(--muted); cursor: pointer; transition: border-color .15s, background .15s;
}
.dropzone.is-over, .dropzone:hover { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.dropzone strong { display: block; color: var(--ink); margin-bottom: 4px; }

.progress { height: 6px; border-radius: 99px; background: #e5e7eb; overflow: hidden; }
.progress span { display: block; height: 100%; background: var(--accent); width: 0; transition: width .2s; }
.steps { display: grid; gap: 8px; }
.steps div { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--muted); }
.steps div::before { content: ""; width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--line-strong); flex: none; }
.steps div.is-active { color: var(--ink); font-weight: 600; }
.steps div.is-active::before { border-color: var(--accent); border-top-color: transparent; animation: spin .8s linear infinite; }
.steps div.is-done { color: var(--ink-2); }
.steps div.is-done::before { background: var(--ok); border-color: var(--ok); }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- editor ---------- */
.editor { display: grid; grid-template-columns: 150px minmax(0, 1fr) 320px; height: calc(100vh - 0px); min-height: 0; }
.editor-head {
  grid-column: 1 / -1; display: flex; align-items: center; gap: 10px; padding: 10px 16px;
  background: var(--surface); border-bottom: 1px solid var(--line); min-width: 0;
}
.editor-head h1 { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.editor-shell { display: grid; grid-template-rows: auto minmax(0, 1fr); height: 100vh; }
.save-state { font-size: 12px; color: var(--muted); white-space: nowrap; }
.save-state.is-dirty { color: var(--warn); }
.save-state.is-error { color: var(--danger); }

.page-rail { overflow: auto; padding: 12px; border-right: 1px solid var(--line); background: var(--surface); display: grid; gap: 10px; align-content: start; }
.page-rail button { border: 2px solid transparent; border-radius: 6px; padding: 0; background: none; position: relative; }
.page-rail button img { display: block; width: 100%; border-radius: 4px; box-shadow: 0 1px 3px rgba(0,0,0,.15); }
.page-rail button.is-active { border-color: var(--accent); }
.page-rail button span { position: absolute; bottom: 4px; left: 4px; font-size: 11px; font-weight: 600; background: rgba(17,24,39,.75); color: #fff; padding: 0 6px; border-radius: 4px; }
.page-rail button em { position: absolute; top: 4px; right: 4px; font-style: normal; font-size: 11px; font-weight: 700; background: var(--accent); color: #fff; padding: 0 6px; border-radius: 4px; }

.stage { position: relative; overflow: auto; background: #e9ebef; display: grid; grid-template-rows: auto minmax(0, 1fr); }
.toolbar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
  padding: 8px 12px; background: rgba(255,255,255,.92); backdrop-filter: blur(6px); border-bottom: 1px solid var(--line);
}
.toolbar .sep { width: 1px; height: 22px; background: var(--line); margin: 0 4px; }
.canvas-wrap { padding: 24px; display: grid; place-items: start center; }
.canvas { position: relative; box-shadow: 0 4px 30px rgba(0,0,0,.18); background: #fff; user-select: none; touch-action: none; }
.canvas img.page-img { display: block; width: 100%; height: 100%; pointer-events: none; }
.canvas.is-drawing { cursor: crosshair; }

.zone {
  position: absolute; border: 2px solid var(--zc); background: color-mix(in srgb, var(--zc) 14%, transparent);
  border-radius: 4px; cursor: move;
}
.zone.t-product { --zc: var(--z-product); }
.zone.t-media { --zc: var(--z-media); }
.zone.t-jump { --zc: var(--z-jump); }
.zone.t-link { --zc: var(--z-link); }
.zone.is-missing { border-style: dashed; --zc: var(--danger); }
.zone.is-selected { box-shadow: 0 0 0 2px #fff, 0 0 0 4px var(--zc); background: color-mix(in srgb, var(--zc) 22%, transparent); z-index: 3; }
.zone.is-locked { cursor: default; border-style: dotted; }
.zone .tag {
  position: absolute; left: -2px; top: -22px; max-width: 220px; height: 20px; padding: 0 6px; border-radius: 4px 4px 0 0;
  background: var(--zc); color: #fff; font-size: 11px; font-weight: 600; line-height: 20px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; pointer-events: none;
}
.zone .h { position: absolute; width: 10px; height: 10px; background: #fff; border: 2px solid var(--zc); border-radius: 2px; }
.zone .h-nw { left: -6px; top: -6px; cursor: nwse-resize; }
.zone .h-ne { right: -6px; top: -6px; cursor: nesw-resize; }
.zone .h-sw { left: -6px; bottom: -6px; cursor: nesw-resize; }
.zone .h-se { right: -6px; bottom: -6px; cursor: nwse-resize; }
.zone .h-n { left: calc(50% - 5px); top: -6px; cursor: ns-resize; }
.zone .h-s { left: calc(50% - 5px); bottom: -6px; cursor: ns-resize; }
.zone .h-w { top: calc(50% - 5px); left: -6px; cursor: ew-resize; }
.zone .h-e { top: calc(50% - 5px); right: -6px; cursor: ew-resize; }
.draft-box { position: absolute; border: 2px dashed var(--accent); background: rgba(37,99,235,.08); pointer-events: none; }

.inspector { overflow: auto; background: var(--surface); border-left: 1px solid var(--line); padding: 16px; display: grid; gap: 14px; align-content: start; }
.inspector h2 { font-size: 14px; }
.inspector .section { display: grid; gap: 10px; padding-top: 14px; border-top: 1px solid var(--line); }
.type-pick { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; }
.type-pick button { height: 54px; border: 1px solid var(--line-strong); border-radius: 8px; background: var(--surface); font-size: 11px; font-weight: 600; display: grid; place-items: center; gap: 0; padding: 4px; }
.type-pick button svg { width: 18px; height: 18px; }
.type-pick button.is-active { border-color: var(--ink); background: #f3f4f6; }
.product-card { display: grid; grid-template-columns: 56px 1fr; gap: 10px; align-items: center; padding: 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-2); }
.product-card img { width: 56px; height: 56px; border-radius: 6px; object-fit: cover; background: #fff; }
.product-card strong { display: block; font-size: 13px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 6px; height: 26px; padding: 0 4px 0 10px; border-radius: 99px; background: #f3f4f6; font-size: 12px; }
.chip button { border: 0; background: none; width: 20px; height: 20px; border-radius: 50%; color: var(--muted); }
.chip button:hover { background: #e5e7eb; color: var(--ink); }
.kbd { font: 11px ui-monospace, monospace; padding: 1px 5px; border: 1px solid var(--line-strong); border-bottom-width: 2px; border-radius: 4px; background: #fff; }
.help-list { display: grid; gap: 6px; font-size: 12px; color: var(--muted); }

/* ---------- multimedia ---------- */
.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 14px; }
.media-card { overflow: hidden; display: flex; flex-direction: column; }
.media-thumb { aspect-ratio: 4 / 3; background: #111 center / cover no-repeat; display: grid; place-items: center; color: #fff; position: relative; overflow: hidden; }
.media-thumb video, .media-thumb img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; display: block; }
.media-thumb .pill { z-index: 1; }
.media-thumb .pill { position: absolute; top: 8px; left: 8px; }
.media-meta { padding: 10px 12px; display: grid; gap: 6px; }
.media-meta input { border: 1px solid transparent; border-radius: 6px; padding: 2px 4px; margin: -2px -4px; font-weight: 600; width: 100%; background: none; }
.media-meta input:hover, .media-meta input:focus { border-color: var(--line-strong); background: #fff; }
.media-pick { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; max-height: 50vh; overflow: auto; }
.media-pick button { padding: 0; border: 2px solid transparent; border-radius: 8px; overflow: hidden; background: #111; aspect-ratio: 1; position: relative; }
.media-pick button.is-active { border-color: var(--accent); }
.media-pick img, .media-pick video { width: 100%; height: 100%; object-fit: cover; display: block; }
.media-pick span { position: absolute; left: 0; right: 0; bottom: 0; font-size: 11px; color: #fff; background: linear-gradient(transparent, rgba(0,0,0,.75)); padding: 14px 6px 4px; text-align: left; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- estadísticas ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; margin-bottom: 18px; }
.kpi { padding: 16px 18px; }
.kpi span { display: block; color: var(--muted); font-size: 12px; font-weight: 550; }
.kpi strong { display: block; font-size: 26px; font-weight: 650; letter-spacing: -.02em; margin-top: 4px; font-variant-numeric: tabular-nums; }
.chart { padding: 10px 18px 16px; }
.chart svg { width: 100%; height: 200px; display: block; }
.bars { display: grid; gap: 8px; padding: 14px 18px; }
.bar { display: grid; grid-template-columns: 90px 1fr 50px; align-items: center; gap: 10px; font-size: 13px; }
.bar i { height: 8px; border-radius: 99px; background: #f3f4f6; overflow: hidden; }
.bar b { display: block; height: 100%; background: var(--accent); border-radius: 99px; }
.bar strong { text-align: right; font-variant-numeric: tabular-nums; }
.two-col { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }

/* ---------- publicación ---------- */
.share-box { display: grid; grid-template-columns: minmax(0, 1fr) 150px; gap: 20px; align-items: start; }
.qr { width: 150px; height: 150px; padding: 8px; background: #fff; border: 1px solid var(--line); border-radius: 8px; }
.qr img, .qr canvas { width: 100% !important; height: 100% !important; }
.copy-field { display: flex; gap: 6px; }
.copy-field .input { font-family: ui-monospace, monospace; font-size: 12px; }
.version-list { display: grid; }
.version-list div { display: flex; align-items: center; gap: 10px; padding: 10px 18px; border-top: 1px solid var(--line); font-size: 13px; }

/* ---------- avisos ---------- */
.toasts { position: fixed; right: 18px; bottom: 18px; display: grid; gap: 8px; z-index: 100; }
.toast { min-width: 240px; max-width: 380px; padding: 11px 14px; border-radius: 10px; background: var(--ink); color: #fff; box-shadow: var(--shadow-lg); font-size: 13px; animation: toastIn .2s ease-out; }
.toast.error { background: var(--danger); }
.toast.ok { background: #065f46; }
@keyframes toastIn { from { transform: translateY(8px); opacity: 0; } }

@media (max-width: 1100px) {
  .editor { grid-template-columns: 110px minmax(0, 1fr) 280px; }
  .two-col { grid-template-columns: 1fr; }
}
@media (max-width: 820px) {
  .shell { grid-template-columns: 1fr; }
  .side { display: none; }
  .page { padding: 18px 16px 40px; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .span-2 { grid-column: auto; }
  .share-box { grid-template-columns: 1fr; }
}
