:root {
  --bg: #f4f2ee;
  --surface: #ffffff;
  --surface-2: #faf9f6;
  --ink: #1d1d1b;
  --ink-2: #5d5b55;
  --ink-3: #8f8c84;
  --line: #e3e0d8;
  --accent: #c2512f;
  --accent-ink: #ffffff;
  --accent-soft: #f6e4dc;
  --ok: #2f7d4f;
  --ok-soft: #e1f1e6;
  --err: #b3261e;
  --err-soft: #fbe4e2;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 16px rgba(0,0,0,.05);
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161614; --surface: #1f1f1c; --surface-2: #262623; --ink: #ecebe6; --ink-2: #b2afa6; --ink-3: #7d7a72;
    --line: #34332f; --accent: #e0714d; --accent-soft: #3a2620; --ok: #6cc28d; --ok-soft: #1f3327; --err: #f08b82; --err-soft: #3b2120;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.25);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.5 var(--font); -webkit-font-smoothing: antialiased; }
a { color: inherit; }
button, input, select { font: inherit; color: inherit; }
.wrap { max-width: 1180px; margin: 0 auto; padding: 0 20px; }

/* Cabeçalho */
.top { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 22px 0 8px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; }
.brand svg { width: 30px; height: 30px; color: var(--accent); }
.brand b { font-size: 19px; letter-spacing: -.01em; }
.brand span { color: var(--ink-3); font-size: 13px; }
.pill { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; padding: 4px 10px; border-radius: 99px; background: var(--surface); border: 1px solid var(--line); color: var(--ink-2); }
.pill .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ink-3); }
.pill.on .dot { background: var(--ok); }

/* Envio */
.hero { margin: 18px 0 28px; display: grid; grid-template-columns: 1.4fr 1fr; gap: 18px; }
@media (max-width: 860px) { .hero { grid-template-columns: 1fr; } }
.drop { position: relative; border: 1.5px dashed var(--line); background: var(--surface); border-radius: 14px; padding: 34px 26px; text-align: center; transition: border-color .15s, background .15s; cursor: pointer; box-shadow: var(--shadow); }
.drop:hover, .drop.over { border-color: var(--accent); background: var(--accent-soft); }
.drop h1 { font-size: 22px; margin: 10px 0 4px; letter-spacing: -.01em; }
.drop p { margin: 0; color: var(--ink-2); }
.drop .ico { width: 46px; height: 46px; color: var(--accent); }
.drop input { display: none; }
.drop .hint { margin-top: 14px; font-size: 13px; color: var(--ink-3); }
.upbar { margin-top: 16px; display: none; }
.upbar.show { display: block; }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 18px 20px; box-shadow: var(--shadow); }
.panel h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-3); margin: 0 0 12px; font-weight: 600; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; color: var(--ink-2); margin-bottom: 5px; }
.field select, .field input[type=text] { width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-2); }
.seg { display: flex; background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; padding: 3px; gap: 3px; }
.seg button { flex: 1; border: 0; background: none; padding: 6px 4px; border-radius: 6px; cursor: pointer; font-size: 13px; color: var(--ink-2); }
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.12); font-weight: 600; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.formats { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.chip { font: 600 11.5px var(--mono); padding: 3px 7px; border-radius: 5px; background: var(--surface-2); border: 1px solid var(--line); color: var(--ink-2); text-transform: uppercase; }
.chip.cloud { border-style: dashed; }
.chip.off { opacity: .45; text-decoration: line-through; }
.fgroup { margin-bottom: 10px; }
.fgroup small { display: block; color: var(--ink-3); font-size: 12px; margin-bottom: 4px; }

/* Galeria */
.section-head { display: flex; align-items: baseline; justify-content: space-between; margin: 8px 0 14px; }
.section-head h2 { margin: 0; font-size: 18px; }
.section-head span { color: var(--ink-3); font-size: 13px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; padding-bottom: 60px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; box-shadow: var(--shadow); display: flex; flex-direction: column; }
.thumb { aspect-ratio: 16/10; background: linear-gradient(160deg, var(--surface-2), var(--bg)); display: grid; place-items: center; position: relative; text-decoration: none; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb svg { width: 54px; color: var(--ink-3); opacity: .6; }
.badge { position: absolute; top: 10px; left: 10px; font: 600 11px var(--mono); padding: 3px 7px; border-radius: 5px; background: var(--surface); border: 1px solid var(--line); text-transform: uppercase; }
.card .body { padding: 12px 14px 14px; display: flex; flex-direction: column; gap: 8px; flex: 1; }
.card .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.meta { font-size: 12.5px; color: var(--ink-2); display: flex; flex-wrap: wrap; gap: 4px 12px; }
.meta b { color: var(--ink); font-weight: 600; }
.status { font-size: 12.5px; color: var(--ink-2); }
.status.err { color: var(--err); background: var(--err-soft); padding: 8px 10px; border-radius: 8px; line-height: 1.4; }
.warn { font-size: 12px; color: var(--ink-2); background: var(--accent-soft); padding: 6px 9px; border-radius: 7px; }
.bar { height: 6px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 99px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--accent); width: 0; transition: width .4s; }
.actions { display: flex; gap: 6px; margin-top: auto; padding-top: 4px; flex-wrap: wrap; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 7px 12px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; font-size: 13px; text-decoration: none; white-space: nowrap; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.06); }
.btn.ghost { border-color: transparent; }
.btn.icon { padding: 7px 9px; }
.btn svg { width: 15px; height: 15px; }
.empty { grid-column: 1/-1; text-align: center; color: var(--ink-3); padding: 50px 0; border: 1px dashed var(--line); border-radius: 12px; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 9px; font-size: 14px; opacity: 0; transition: .2s; pointer-events: none; z-index: 50; max-width: calc(100% - 32px); }
.toast.show { opacity: 1; transform: translateX(-50%); }

/* ===== Visualizador ===== */
body.viewer { overflow: hidden; height: 100vh; }
#stage { position: fixed; inset: 0; }
#stage canvas { display: block; outline: none; }
.vbar { position: fixed; top: 12px; left: 12px; right: 12px; display: flex; align-items: center; gap: 10px; pointer-events: none; z-index: 5; }
.vbar > * { pointer-events: auto; }
.vtitle { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 6px 12px 6px 6px; display: flex; align-items: center; gap: 10px; box-shadow: var(--shadow); min-width: 0; }
.vtitle .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 40vw; }
.vtitle .dims { color: var(--ink-3); font-size: 12.5px; white-space: nowrap; }
.spacer { flex: 1; }
.tools { position: fixed; top: 64px; right: 12px; width: 250px; max-height: calc(100vh - 80px); overflow: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); padding: 12px 14px; z-index: 5; }
.tools h3 { font-size: 11.5px; text-transform: uppercase; letter-spacing: .07em; color: var(--ink-3); margin: 14px 0 7px; }
.tools h3:first-child { margin-top: 2px; }
.tools .grid4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; }
.tools .grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; }
.tools .btn { padding: 6px; font-size: 12.5px; }
.tools .btn.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 600; }
.tools input[type=range] { width: 100%; accent-color: var(--accent); }
.tools .lbl { display: flex; justify-content: space-between; font-size: 12.5px; color: var(--ink-2); }
.toggle { display: flex; align-items: center; gap: 8px; font-size: 13px; padding: 3px 0; cursor: pointer; }
.toggle input { accent-color: var(--accent); }
.layers .toggle span:last-child { margin-left: auto; color: var(--ink-3); font-size: 12px; }
.vstats { position: fixed; left: 12px; bottom: 12px; font: 11.5px var(--mono); color: var(--ink-2); background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; z-index: 5; }
.loader { position: fixed; inset: 0; display: grid; place-items: center; z-index: 10; background: var(--bg); transition: opacity .3s; }
.loader.hide { opacity: 0; pointer-events: none; }
.loader .box { width: min(320px, 80vw); text-align: center; color: var(--ink-2); font-size: 14px; }
.loader .bar { margin-top: 10px; }
.mlabel { background: var(--ink); color: var(--bg); font: 600 12px var(--mono); padding: 3px 7px; border-radius: 5px; white-space: nowrap; pointer-events: none; }
.help { position: fixed; bottom: 12px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--bg); font-size: 13px; padding: 7px 14px; border-radius: 8px; z-index: 6; display: none; }
.help.show { display: block; }
.tools-toggle { display: none; }

/* ----- Espaço privado (galeria) ----- */
.space-note { display: flex; align-items: center; gap: 10px; margin: -4px 0 14px; padding: 9px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); font-size: 13px; color: var(--ink-2); }
.space-note svg { width: 16px; height: 16px; color: var(--accent); flex: none; }
.space-note span { flex: 1; }
.space-note .btn[hidden] { display: none; }

/* ----- Zonas ----- */
.tools.editor.zones { width: 280px; overflow-x: hidden; }
.vbar .btn.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 600; }
.tools .field-row { display: flex; align-items: center; gap: 8px; margin-top: 6px; font-size: 12.5px; color: var(--ink-2); }
.tools .field-row label { width: 46px; flex: none; }
.tools .field-row input[type=text], .tools .field-row input:not([type]), .tools .field-row input[type=number] { flex: 1; min-width: 0; padding: 5px 8px; border: 1px solid var(--line); border-radius: 7px; background: var(--surface-2); color: var(--ink); font: inherit; }
.tools .field-row input[type=color] { width: 34px; height: 26px; padding: 0; border: 1px solid var(--line); border-radius: 6px; background: none; cursor: pointer; }
.tools textarea { width: 100%; margin-top: 8px; padding: 6px 8px; border: 1px solid var(--line); border-radius: 7px; background: var(--surface-2); color: var(--ink); font: 12.5px/1.4 var(--font); resize: vertical; box-sizing: border-box; }
.tools .btn.danger { color: var(--err); }
.muted { color: var(--ink-3); } .small { font-size: 11.5px; }
.zlist { display: flex; flex-direction: column; gap: 3px; max-height: 210px; overflow: auto; }
.zitem { display: flex; align-items: center; gap: 8px; padding: 5px 7px; border-radius: 7px; border: 1px solid transparent; cursor: pointer; font-size: 12.5px; }
.zitem:hover { background: var(--surface-2); }
.zitem.on { border-color: var(--accent); background: var(--accent-soft); }
.zitem i, .zsum i { width: 11px; height: 11px; border-radius: 3px; flex: none; border: 1px solid rgba(0,0,0,.2); display: inline-block; }
.zitem .zn { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.zitem .zn small { display: block; color: var(--ink-3); font-size: 11px; }
.zitem .za { font: 11.5px var(--mono); color: var(--ink-2); white-space: nowrap; }
.zeye { border: 0; background: none; color: var(--ink-2); cursor: pointer; font-size: 13px; padding: 0 2px; }
.zeye.off { color: var(--ink-3); }
.zsum { margin-top: 8px; border-top: 1px solid var(--line); padding-top: 6px; font-size: 12px; color: var(--ink-2); }
.zsum div { display: flex; align-items: center; gap: 6px; padding: 1px 0; }
.zsum b { margin-left: auto; font: 600 11.5px var(--mono); color: var(--ink); }
.zsum .tot { border-top: 1px dashed var(--line); margin-top: 3px; padding-top: 3px; color: var(--ink); font-weight: 600; }
.zlabel { --zc: #c9b79c; background: color-mix(in srgb, var(--surface) 88%, transparent); border: 1.5px solid var(--zc); border-radius: 8px; padding: 3px 8px; text-align: center; font-size: 12px; line-height: 1.25; color: var(--ink); white-space: nowrap; pointer-events: none; box-shadow: 0 1px 4px rgba(0,0,0,.18); }
.zlabel b { display: block; font-size: 12.5px; }
.zlabel span { font: 11px var(--mono); color: var(--ink-2); }
.zlabel.sel { outline: 2px solid var(--accent); outline-offset: 1px; }
body.zoning .zlabel { pointer-events: auto; cursor: pointer; }
.zvtx { width: 12px; height: 12px; border-radius: 50%; background: #fff; border: 2px solid var(--accent); cursor: grab; pointer-events: auto; box-shadow: 0 1px 3px rgba(0,0,0,.35); }
.zvtx.drag, .zvtx.ghost { cursor: grabbing; }
.zmid { width: 8px; height: 8px; border-radius: 50%; background: color-mix(in srgb, var(--accent) 55%, #fff); opacity: .75; cursor: copy; pointer-events: auto; }
.zmid:hover { opacity: 1; transform: scale(1.3); }
body.zoning #stage canvas { cursor: crosshair; }

/* ----- Vista travada ----- */
.viewlock { position: fixed; top: 12px; left: 50%; transform: translateX(-50%); z-index: 6; display: flex; align-items: center; gap: 8px; background: var(--surface); border: 1px solid var(--accent); color: var(--ink-2); border-radius: 10px; padding: 4px 4px 4px 10px; font-size: 13px; box-shadow: var(--shadow); }
.viewlock[hidden] { display: none; }
.viewlock svg { width: 15px; height: 15px; color: var(--accent); }
.viewlock b { color: var(--ink); }
.viewlock .btn { padding: 4px 10px; font-size: 12.5px; }
@media (max-width: 700px) { .viewlock { top: 60px; } }
body.embed .viewlock .btn { display: none; }

/* ----- Editor ----- */
.tools.editor { right: auto; left: 12px; width: 262px; }
.tools .grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; }
.tools .btn:disabled { opacity: .45; cursor: default; }
.selinfo { margin-top: 8px; font-size: 12.5px; color: var(--ink-2); background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; line-height: 1.4; }
.selinfo b { color: var(--ink); }
.selinfo small { color: var(--ink-3); }
#edPaint.disabled { opacity: .4; pointer-events: none; }
.swatches { display: grid; grid-template-columns: repeat(6, 1fr); gap: 5px; }
.sw { aspect-ratio: 1; border-radius: 7px; border: 1px solid rgba(0,0,0,.18); cursor: pointer; padding: 0; position: relative; }
.sw.on { outline: 2px solid var(--accent); outline-offset: 2px; }
.sw.custom { background: conic-gradient(#e44, #ee4, #4e4, #4ee, #44e, #e4e, #e44); overflow: hidden; display: block; }
.sw.custom input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; border: 0; padding: 0; }
.savestate { margin-top: 10px; font-size: 11.5px; color: var(--ink-3); min-height: 1em; }
.croprect { position: fixed; display: none; border: 2px dashed var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent); pointer-events: none; z-index: 6; border-radius: 3px; }
body.editing #stage canvas { cursor: crosshair; }
body.embed .tools.editor, body.embed #btnEdit { display: none; }
/* Link compartilhado: só visualização */
body.readonly #btnEdit, body.readonly #btnZones { display: none; }
@media (max-width: 700px) {
  .tools { top: auto; bottom: 0; right: 0; left: 0; width: auto; max-height: 50vh; border-radius: 14px 14px 0 0; transform: translateY(100%); transition: transform .25s; }
  .tools.open { transform: none; }
  .tools-toggle { display: inline-flex; }
  .vtitle .dims { display: none; }
  .vstats { display: none; }
}
body.embed .vbar, body.embed .tools, body.embed .vstats { display: none; }
@media (max-width: 700px) {
  .tools.editor { left: 0; right: 0; width: auto; transform: none; max-height: 55vh; }
}
