/* Interface do editor (nunca impressa) + regras de impressão A4. */
html { scroll-padding-top: 60px; }
html, body { margin: 0; }
body { background: var(--mist-200); font-family: var(--font-sans); color: var(--ink-900); }

/* ---------- Barra superior ---------- */
:root { --topbar-h: 48px; --panel-w: 300px; }
.topbar { position: sticky; top: 0; z-index: 50; height: var(--topbar-h); box-sizing: border-box; display: flex; align-items: center; gap: 10px; padding: 0 12px; background: var(--mist-0); border-bottom: 1px solid var(--border-default); font-size: 13px; }
.ab-title { font-family: var(--font-serif); font-weight: 400; font-size: 18px; color: var(--viva-purple); white-space: nowrap; }
.ab-state { font-size: 12px; color: var(--ink-400); display: inline-flex; gap: 8px; white-space: nowrap; }
.vstate::before { content: "·"; margin-right: 8px; }
.vstate:empty { display: none; }
.vstate.ok { color: var(--success); }
.vstate.dirty { color: var(--warning); font-weight: 700; }
.ab-spacer { flex: 1; }
.gl { font-family: var(--font-mono); font-size: 9px; letter-spacing: var(--tracking-overline); text-transform: uppercase; color: var(--purple-600); margin-right: 2px; }
button, .btn, dialog button {
  font: inherit; font-size: 13px; cursor: pointer; padding: 5px 9px; border-radius: 8px; text-decoration: none;
  border: 1px solid var(--border-default); background: var(--mist-0); color: var(--ink-900); display: inline-flex; align-items: center; gap: 6px;
}
button:hover, .btn:hover { background: var(--mist-100); }
button.primary, .btn.primary { background: var(--viva-purple); border-color: var(--viva-purple); color: #fff; }
button.primary:hover, .btn.primary:hover { background: var(--purple-600); }
.btn.danger { color: var(--danger); }
button:disabled { opacity: .5; cursor: wait; }
button.icon { width: 34px; height: 34px; justify-content: center; padding: 0; font-size: 18px; }
.count { background: var(--purple-50); color: var(--purple-700); border-radius: 20px; padding: 0 7px; font-size: 11px; font-weight: 700; }
.badge-warn { background: var(--danger-soft); color: var(--danger); border-radius: 20px; padding: 4px 10px; font-size: 12px; font-weight: 700; white-space: nowrap; }
button:focus-visible, input:focus-visible, select:focus-visible, a:focus-visible { outline: none; box-shadow: var(--shadow-focus); }

/* ---------- Painel lateral ---------- */
.layout { display: flex; align-items: flex-start; }
.panel { display: none; flex: 0 0 var(--panel-w); width: var(--panel-w); box-sizing: border-box; position: sticky; top: var(--topbar-h); height: calc(100vh - var(--topbar-h)); overflow: auto; background: var(--mist-0); border-right: 1px solid var(--border-default); font-size: 13px; }
body.panel-open .panel { display: block; }
.panel-top { display: flex; gap: 6px; padding: 10px 12px; border-bottom: 1px solid var(--border-subtle); position: sticky; top: 0; background: var(--mist-0); z-index: 1; }
.panel-top button { flex: 1; justify-content: center; font-size: 12px; }
.sec { border-bottom: 1px solid var(--border-subtle); }
.sec-h { width: 100%; justify-content: space-between; border: 0; border-radius: 0; background: var(--surface-app); padding: 10px 12px; font-family: var(--font-mono); font-size: 10px; letter-spacing: var(--tracking-overline); text-transform: uppercase; color: var(--purple-700); }
.sec-h::after { content: "−"; font-family: var(--font-sans); font-size: 14px; color: var(--ink-400); }
.sec-h[aria-expanded="false"]::after { content: "+"; }
.sec-h[aria-expanded="false"] + .sec-b { display: none; }
.sec-b { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 8px; }
.sec-b .row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.sec-b label { display: flex; align-items: center; gap: 4px; }
.sec-b .fld { flex-direction: column; align-items: stretch; gap: 4px; }
.sec-b select, .sec-b input[type=number] { font: inherit; padding: 5px 6px; border: 1px solid var(--border-default); border-radius: 6px; background: var(--mist-0); }
.sec-b input[type=number] { width: 52px; }
.sec-b > button { align-self: flex-start; }
.sec-b .muted { margin: 0; }
@media (max-width: 1099px) {
  .panel { position: fixed; left: 0; top: var(--topbar-h); z-index: 70; box-shadow: var(--shadow-lg); width: min(var(--panel-w), 88vw); }
  .ab-state { display: none; }
}

/* ---------- Área do documento ---------- */
#stage { flex: 1; min-width: 0; padding: 24px 24px 48px; display: flex; justify-content: center; }
#wrap { position: relative; }
#sheet { position: absolute; top: 0; left: 0; transform-origin: 0 0; box-shadow: var(--shadow-lg); }

/* Guias da área segura (somente na tela) */
.sheet.guides::after {
  content: ""; position: absolute; inset: var(--margin); border: 1px dashed var(--purple-300);
  pointer-events: none; z-index: 5;
}

/* Campos editáveis */
[contenteditable="true"] { outline: none; cursor: text; border-radius: 3px; }
[contenteditable="true"]:hover { box-shadow: 0 0 0 1px var(--purple-200); }
[contenteditable="true"]:focus { box-shadow: 0 0 0 2px var(--ring-brand); background: rgba(133,102,242,.06); }
img[data-img] { cursor: pointer; border-radius: 3px; }
img[data-img]:hover { outline: 2px dashed var(--purple-400); outline-offset: 2px; }
img[data-img].drag { outline: 2px solid var(--viva-purple); }

/* Controles flutuantes */
.fctl { position: fixed; z-index: 60; display: flex; gap: 2px; padding: 2px; background: var(--burgundy-800); border-radius: 8px; box-shadow: var(--shadow-md); }
.fctl[hidden] { display: none; }
.fctl button { font: 12px var(--font-sans); border: 0; background: transparent; color: #fff; padding: 4px 8px; border-radius: 6px; cursor: pointer; }
.fctl button:hover { background: var(--burgundy-500); }
.fctl button:disabled { opacity: .35; cursor: not-allowed; }
#statusctl { padding: 4px; gap: 6px; }
#statusctl button { width: 18px; height: 18px; padding: 0; border-radius: 50%; border: 2px solid #fff; }
#statusctl [data-s="success"] { background: var(--success); }
#statusctl [data-s="warning"] { background: var(--warning); }
#statusctl [data-s="danger"] { background: var(--danger); }
#statusctl [data-s="info"] { background: var(--blue-500); }
#statusctl [data-s="neutral"] { background: var(--mist-500); }

/* Diálogos e aviso */
dialog { border: 1px solid var(--border-default); border-radius: 14px; padding: 24px; max-width: 420px; width: calc(100vw - 48px); box-shadow: var(--shadow-lg); font-family: var(--font-sans); color: var(--ink-900); }
dialog::backdrop { background: rgba(20,8,15,.45); }
dialog h2 { font-family: var(--font-serif); font-weight: 400; color: var(--viva-purple); margin: 0 0 8px; }
dialog li { margin-bottom: 4px; }
.fld { display: flex; flex-direction: column; gap: 6px; font-size: 13px; }
.fld input { font: inherit; padding: 8px 10px; border: 1px solid var(--border-default); border-radius: 8px; }
.muted { color: var(--ink-400); font-size: 12px; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 80; background: var(--burgundy-800); color: #fff; padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow-lg); font-size: 13px; }
.toast[hidden] { display: none; }
.toast a { color: var(--blue-300); margin-left: 8px; }

/* ---------- Página de versões ---------- */
.page-versions { max-width: 880px; margin: 0 auto; padding: 24px 16px 64px; }
.page-versions h1 { font-family: var(--font-serif); font-weight: 400; color: var(--viva-purple); margin: 0 0 4px; }
.vlist { list-style: none; margin: 20px 0 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.vitem { background: var(--mist-0); border: 1px solid var(--border-default); border-radius: 12px; padding: 14px 16px; display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; }
.vinfo { flex: 1 1 260px; min-width: 0; }
.vname { font-weight: 700; overflow-wrap: anywhere; }
.vname.empty { font-weight: 400; color: var(--ink-500); font-style: italic; }
.vmeta { font-size: 12px; color: var(--ink-500); margin-top: 2px; overflow-wrap: anywhere; }
.vtime { font-family: var(--font-mono); font-size: 12px; color: var(--purple-700); white-space: nowrap; }
.vact { display: flex; gap: 6px; flex-wrap: wrap; }
.vempty { background: var(--mist-0); border: 1px dashed var(--border-strong); border-radius: 12px; padding: 32px 16px; text-align: center; color: var(--ink-500); margin-top: 20px; }


/* ---------- Bloco de imagem: seleção, painel, alças ---------- */
.imgblock { cursor: pointer; }
.imgblock.sel { outline: 2px solid var(--viva-purple); outline-offset: 2px; }
.blockctl { align-items: center; flex-wrap: wrap; max-width: 520px; padding: 6px; gap: 6px; }
.blockhint { flex-basis: 100%; font: 11px var(--font-sans); color: var(--mist-300); padding: 0 4px 2px; }
.blockctl select { font: 12px var(--font-sans); padding: 4px 6px; border-radius: 6px; border: 0; background: var(--burgundy-600); color: #fff; }
.blockctl button.danger { color: #ffb3c1; }
.rzh { position: fixed; z-index: 61; background: var(--viva-purple); border: 2px solid #fff; border-radius: 6px; box-shadow: 0 0 0 1px var(--purple-700), var(--shadow-md); touch-action: none; }
.rzh:hover { background: var(--purple-700); }
.rzh[hidden] { display: none; }
.rz-x { width: 12px; height: 44px; cursor: ew-resize; }
.rz-y { width: 44px; height: 12px; cursor: ns-resize; }
.rz-c { width: 18px; height: 18px; cursor: nwse-resize; border-radius: 50%; }
.pos-set { border: 1px solid var(--border-default); border-radius: 8px; padding: 8px 10px; margin: 10px 0; }
.pos-set label { display: flex; gap: 6px; align-items: center; }
dialog select { font: inherit; padding: 8px 10px; border: 1px solid var(--border-default); border-radius: 8px; }

/* ---------- Painel de cores de fundo ---------- */
.bgpanel { flex-direction: column; align-items: stretch; gap: 10px; padding: 12px; width: min(560px, calc(100vw - 16px)); background: var(--mist-0); color: var(--ink-900); border: 1px solid var(--border-default); max-height: calc(100vh - 140px); overflow: auto; }
.bgrow { display: flex; flex-direction: column; gap: 6px; padding-bottom: 8px; border-bottom: 1px solid var(--border-subtle); }
.bgrow:last-child { border-bottom: 0; padding-bottom: 0; }
.bgrow-h { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 12px; font-weight: 700; color: var(--ink-900); }
.bgsw { display: flex; flex-wrap: wrap; gap: 6px; }
.bgsw button { width: 24px; height: 24px; padding: 0; border-radius: 50%; border: 1px solid var(--border-strong); }
.bgsw button[aria-pressed="true"] { box-shadow: 0 0 0 2px #fff, 0 0 0 4px var(--viva-purple); }
.bgpanel .fctl-btn, .bgrow-h button { font: 11px var(--font-sans); padding: 3px 8px; border-radius: 6px; border: 1px solid var(--border-default); background: var(--mist-0); color: var(--ink-900); cursor: pointer; }
.bg-hl { outline: 3px solid var(--viva-purple); outline-offset: 2px; }

/* Impressão: A4 retrato, margem já embutida no layout (--margin). */
@page { size: A4 portrait; margin: 0; } /* substituído em tempo de execução por #pagestyle */
@media print {
  html, body { width: var(--pw, 210mm); height: var(--ph, 297mm); overflow: hidden; background: #fff; }
  .layout { display: block; }
  .ui, .fctl, .rzh, dialog, .toast { display: none !important; }
  .imgblock.empty .ph { display: none; }
  .imgblock.empty { background: transparent; }
  .imgblock { background: transparent; }
  .imgblock.sel, .bg-hl { outline: none; }
  #stage { padding: 0; display: block; }
  #wrap { width: var(--pw, 210mm) !important; height: var(--ph, 297mm) !important; }
  #sheet { position: static; transform: none !important; box-shadow: none; }
  .sheet.guides::after { display: none; }
  [contenteditable] { box-shadow: none !important; background: none !important; }
}
