:root {
  --bg: #fbf7f3;
  --panel: #ffffff;
  --side: #efe9fb;
  --lilac: #cbbcf6;
  --lilac-soft: #f1ecfd;
  --lilac-deep: #6f58c9;
  --mint: #cdeee0;
  --mint-deep: #2f8a67;
  --peach: #ffe0cf;
  --peach-deep: #b8592a;
  --sky: #d8e9fb;
  --sky-deep: #3c6fa8;
  --pink: #fbdde9;
  --pink-deep: #b03f6e;
  --butter: #fff2c6;
  --butter-deep: #8a6a10;
  --text: #4a4363;
  --muted: #8a84a3;
  --line: #ebe5f5;
  --radius: 16px;
  --shadow: 0 6px 24px rgba(111, 88, 201, 0.08);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: 'Nunito', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
}
a { color: var(--lilac-deep); }
h1, h2, h3 { font-family: 'Quicksand', 'Nunito', sans-serif; margin: 0 0 .5em; color: #3f3858; }
h1 { font-size: 26px; }
h2 { font-size: 19px; }
h3 { font-size: 16px; }

.app { display: grid; grid-template-columns: 230px 1fr; min-height: 100vh; }
.side {
  background: var(--side);
  padding: 24px 16px;
  display: flex; flex-direction: column; gap: 6px;
  position: sticky; top: 0; height: 100vh;
}
.brand { font-family: 'Quicksand', sans-serif; font-weight: 700; font-size: 20px; margin: 0 8px 22px; color: var(--lilac-deep); }
.brand small { display: block; font-size: 12px; font-weight: 600; color: var(--muted); }
.nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; border-radius: 12px; text-decoration: none; color: var(--text); font-weight: 600;
}
.nav a:hover { background: rgba(255, 255, 255, .6); }
.nav a.active { background: #fff; box-shadow: var(--shadow); color: var(--lilac-deep); }
.side .foot { margin-top: auto; font-size: 12px; color: var(--muted); padding: 0 8px; }

main { padding: 28px 36px 60px; max-width: 1280px; width: 100%; }
.head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.head p { margin: 0; color: var(--muted); }

.card { background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px 22px; margin-bottom: 18px; border: 1px solid var(--line); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 18px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px 18px; }
.full { grid-column: 1 / -1; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

label { display: block; font-weight: 700; font-size: 13px; margin-bottom: 5px; color: #5b5379; }
label .hint { font-weight: 500; color: var(--muted); }
input[type=text], input[type=number], input[type=password], input[type=email], select, textarea {
  width: 100%; font: inherit; color: var(--text);
  background: #fdfcff; border: 1.5px solid var(--line); border-radius: 12px; padding: 10px 12px;
  outline: none; transition: border-color .15s, box-shadow .15s;
}
textarea { min-height: 90px; resize: vertical; }
textarea.big { min-height: 190px; }
input:focus, select:focus, textarea:focus { border-color: var(--lilac); box-shadow: 0 0 0 4px var(--lilac-soft); }
.check { display: flex; gap: 8px; align-items: center; font-weight: 600; font-size: 14px; }

.btn {
  font: inherit; font-weight: 700; border: none; cursor: pointer;
  padding: 10px 18px; border-radius: 999px; background: var(--lilac-soft); color: var(--lilac-deep);
  transition: transform .1s, filter .15s; text-decoration: none; display: inline-flex; gap: 8px; align-items: center;
}
.btn:hover { filter: brightness(.97); transform: translateY(-1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.btn.primary { background: var(--lilac); color: #3b2c86; }
.btn.mint { background: var(--mint); color: #1f6b4f; }
.btn.peach { background: var(--peach); color: #8f4119; }
.btn.sky { background: var(--sky); color: #2c5a8c; }
.btn.pink { background: var(--pink); color: #8e2f57; }
.btn.small { padding: 6px 12px; font-size: 13px; }
.btn.ghost { background: transparent; border: 1.5px solid var(--line); color: var(--text); }

.tabs { display: flex; gap: 6px; background: var(--lilac-soft); padding: 5px; border-radius: 999px; width: fit-content; margin-bottom: 18px; }
.tabs button { font: inherit; font-weight: 700; border: none; background: transparent; color: var(--muted); padding: 8px 18px; border-radius: 999px; cursor: pointer; }
.tabs button.active { background: #fff; color: var(--lilac-deep); box-shadow: var(--shadow); }

.chip { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 700; background: var(--lilac-soft); color: var(--lilac-deep); }
.chip.ok { background: var(--mint); color: var(--mint-deep); }
.chip.warn { background: var(--butter); color: var(--butter-deep); }
.chip.err { background: var(--pink); color: var(--pink-deep); }
.chip.busy { background: var(--sky); color: var(--sky-deep); }
.chip.peach { background: var(--peach); color: var(--peach-deep); }

.jobbar {
  display: flex; align-items: center; gap: 12px; background: var(--sky); color: #2c5a8c;
  border-radius: 14px; padding: 12px 16px; margin-bottom: 16px; font-weight: 600;
}
.errbar { background: var(--pink); color: #8e2f57; border-radius: 14px; padding: 12px 16px; margin-bottom: 16px; font-weight: 600; }
.spin { width: 16px; height: 16px; border: 3px solid rgba(60, 111, 168, .25); border-top-color: #3c6fa8; border-radius: 50%; animation: spin .9s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }

/* listas de proyectos */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 16px; }
.pcard { background: #fff; border-radius: var(--radius); border: 1px solid var(--line); box-shadow: var(--shadow); overflow: hidden; cursor: pointer; transition: transform .15s; text-decoration: none; color: inherit; }
.pcard:hover { transform: translateY(-3px); }
.pcard .thumb { aspect-ratio: 3 / 4; background: linear-gradient(135deg, var(--lilac-soft), var(--peach)); display: grid; place-items: center; font-size: 40px; }
.pcard .thumb img { width: 100%; height: 100%; object-fit: cover; }
.pcard .info { padding: 12px 14px; }
.pcard .info b { display: block; margin-bottom: 4px; }
.empty { text-align: center; padding: 50px 20px; color: var(--muted); }
.empty .big { font-size: 46px; }

/* estilos */
.styles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.style-opt { border: 2px solid var(--line); border-radius: 14px; padding: 10px; cursor: pointer; background: #fff; }
.style-opt.sel { border-color: var(--lilac); background: var(--lilac-soft); }
.style-opt .imgs { display: flex; gap: 4px; margin-bottom: 8px; }
.style-opt .imgs img { width: 33%; aspect-ratio: 3 / 4; object-fit: cover; border-radius: 6px; }
.style-opt .imgs .ph { width: 100%; aspect-ratio: 3.2 / 1.4; border-radius: 8px; display: grid; place-items: center; background: repeating-linear-gradient(45deg, var(--lilac-soft), var(--lilac-soft) 8px, #fff 8px, #fff 16px); font-size: 28px; }
.style-opt b { font-size: 13px; }

/* subida de imágenes */
.drop { border: 2px dashed var(--lilac); border-radius: 14px; padding: 14px; text-align: center; color: var(--muted); cursor: pointer; background: #fdfcff; }
.drop.over { background: var(--lilac-soft); }
.thumbs { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.thumbs .t { position: relative; width: 78px; height: 78px; border-radius: 10px; overflow: hidden; border: 1px solid var(--line); }
.thumbs .t img { width: 100%; height: 100%; object-fit: cover; }
.thumbs .t button { position: absolute; top: 3px; right: 3px; border: none; background: rgba(255, 255, 255, .9); color: var(--pink-deep); border-radius: 50%; width: 22px; height: 22px; cursor: pointer; font-weight: 800; line-height: 1; }

/* plan */
.page-plan { border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; margin-bottom: 12px; background: #fff; }
.page-plan .ph { display: flex; gap: 10px; align-items: center; margin-bottom: 6px; }
.page-plan .num { width: 34px; height: 34px; border-radius: 50%; background: var(--peach); color: var(--peach-deep); display: grid; place-items: center; font-weight: 800; flex: none; }
.page-plan .hl { font-family: 'Quicksand', sans-serif; font-weight: 700; font-size: 17px; }
.page-plan .hl mark { background: var(--butter); color: inherit; border-radius: 4px; padding: 0 3px; }
.page-plan ul { margin: 6px 0; padding-left: 20px; }
.page-plan .blk { margin-top: 6px; }
.page-plan .visual { font-size: 13px; color: var(--muted); font-style: italic; margin-top: 6px; }
.audit-issue { padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 14px; }

/* páginas diseñadas */
.pages { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 14px; }
.pg { background: #fff; border-radius: 12px; border: 1px solid var(--line); overflow: hidden; cursor: pointer; box-shadow: var(--shadow); }
.pg .im { aspect-ratio: 1200 / 1696; background: var(--lilac-soft); display: grid; place-items: center; color: var(--muted); font-weight: 700; position: relative; }
.pg .im img { width: 100%; height: 100%; object-fit: cover; }
.pg .im .spin { position: absolute; }
.pg .meta { padding: 8px 10px; display: flex; justify-content: space-between; align-items: center; font-size: 13px; font-weight: 700; }

/* galería de imágenes */
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 16px; }
.gitem { background: #fff; border: 1px solid var(--line); border-radius: 14px; overflow: hidden; box-shadow: var(--shadow); }
.gitem .im { background: var(--lilac-soft); min-height: 200px; display: grid; place-items: center; cursor: zoom-in; }
.gitem .im img { width: 100%; display: block; }
.gitem .body { padding: 10px 12px; font-size: 13px; }
.gitem .hook { font-weight: 800; font-size: 14px; margin-bottom: 3px; }

.log { font-family: ui-monospace, Consolas, monospace; font-size: 12.5px; max-height: 420px; overflow: auto; background: #fdfcff; border-radius: 12px; padding: 12px; border: 1px solid var(--line); }
.log div { padding: 2px 0; }
.log time { color: var(--muted); margin-right: 8px; }

/* diálogos */
dialog { border: none; border-radius: 20px; padding: 0; box-shadow: 0 20px 60px rgba(74, 67, 99, .25); max-width: min(1100px, 94vw); width: 560px; color: var(--text); background: #fff; }
dialog.wide { width: 1100px; }
dialog::backdrop { background: rgba(203, 188, 246, .35); backdrop-filter: blur(3px); }
dialog .dh { padding: 18px 22px 0; }
dialog .db { padding: 14px 22px; max-height: 75vh; overflow: auto; }
dialog .df { padding: 12px 22px 18px; display: flex; justify-content: flex-end; gap: 10px; }
.viewer { display: grid; grid-template-columns: 1.1fr 1fr; gap: 20px; }
.viewer img.main { width: 100%; border-radius: 12px; border: 1px solid var(--line); }
.versions { display: flex; gap: 8px; flex-wrap: wrap; }
.versions .v { width: 70px; cursor: pointer; text-align: center; font-size: 11px; font-weight: 700; }
.versions .v img { width: 70px; border-radius: 6px; border: 2px solid transparent; }
.versions .v.cur img { border-color: var(--lilac-deep); }
.lightbox img { max-width: 90vw; max-height: 85vh; display: block; }

.toast { position: fixed; bottom: 22px; right: 22px; background: #fff; border-left: 6px solid var(--lilac); padding: 12px 18px; border-radius: 12px; box-shadow: var(--shadow); font-weight: 600; z-index: 99; max-width: 420px; }
.toast.err { border-color: var(--pink-deep); }

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .side { position: static; height: auto; flex-direction: row; flex-wrap: wrap; }
  .grid2, .grid3, .styles, .viewer { grid-template-columns: 1fr; }
  main { padding: 18px 16px; }
}

/* ---- Versión 2: estilos de ebook, editor con IA ---- */
.styles { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); }
.style-opt .imgs img { flex: 1; min-width: 0; width: auto; height: 120px; aspect-ratio: auto; object-fit: cover; object-position: top; }
.style-opt .imgs .ph { height: 120px; aspect-ratio: auto; }
.style-opt .muted.small { font-size: 12px; line-height: 1.35; margin-top: 4px; }
.regionbox { position: relative; user-select: none; touch-action: none; cursor: crosshair; }
.regionbox img { width: 100%; display: block; border-radius: 12px; border: 1px solid var(--line); pointer-events: none; }
.regionbox .zone { position: absolute; border: 2px dashed var(--lilac-deep); background: rgba(203, 188, 246, 0.28); border-radius: 6px; pointer-events: none; }
.nav a { font-size: 14px; }
.regionbox { display: inline-block; max-width: 100%; }
.regionbox img { width: auto; max-width: 100%; max-height: 72vh; }
