:root {
  --ui-bg: #262628;
  --ui-panel: #2e2e31;
  --ui-panel-2: #353539;
  --ui-line: #414146;
  --ui-text: #e6e6e9;
  --ui-muted: #9a9aa2;
  --pasteboard: #3b3b3f;
  --accent: #3d8bff;
  --accent-2: #2f6fd6;
  --danger: #ff5a52;
  --overset: #e5302f;
  --snap: #ff2fc8;
  --margin: #c77dff;
  --font-ui: 'Inter', system-ui, -apple-system, sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 13px/1.4 var(--font-ui); background: var(--ui-bg); color: var(--ui-text); -webkit-font-smoothing: antialiased; }
button { font: inherit; color: inherit; }
input, select { font: inherit; color: inherit; }
.muted { color: var(--ui-muted); }

/* ------------------------------------------------------------ buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 30px; padding: 0 12px; border-radius: 7px; border: 1px solid var(--ui-line);
  background: var(--ui-panel-2); cursor: pointer; white-space: nowrap; font-weight: 500;
}
.btn:hover { border-color: #5a5a62; background: #3d3d42; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-2); }
.btn.sm { height: 26px; padding: 0 10px; font-size: 12px; }
.btn.danger { color: var(--danger); }
.icon-btn {
  display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 7px;
  border: 0; background: transparent; cursor: pointer; color: var(--ui-text); text-decoration: none; font-size: 16px;
}
.icon-btn:hover { background: rgba(255,255,255,.08); }
.icon-btn.sm { width: 24px; height: 24px; font-size: 14px; }
.icon-btn.xs { width: 20px; height: 20px; font-size: 13px; border-radius: 5px; }
.icon-btn.danger:hover { color: var(--danger); }
.icon-btn[aria-pressed="true"] { background: var(--accent); color: #fff; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 15px; }
.brand-mark {
  display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 6px;
  background: #49021f; color: #ff3366; border: 1.5px solid #ff3366; font-weight: 700; font-size: 14px; letter-spacing: -.02em;
}
.brand-mark.sm { width: 24px; height: 24px; font-size: 11px; border-radius: 5px; }

/* ------------------------------------------------------------ home */
.home { background: #1e1e20; }
.home-top { height: 56px; display: flex; align-items: center; padding: 0 28px; border-bottom: 1px solid var(--ui-line); }
.home-main { max-width: 1100px; margin: 0 auto; padding: 32px 28px 80px; display: grid; gap: 40px; }
.home h1 { font-size: 22px; margin: 0 0 16px; font-weight: 600; }
.home h2 { font-size: 15px; margin: 0 0 14px; color: var(--ui-muted); font-weight: 500; }
.new-doc-form { display: grid; gap: 16px; }
.new-doc-form > input {
  height: 40px; padding: 0 12px; border-radius: 8px; border: 1px solid var(--ui-line); background: var(--ui-panel); max-width: 480px; font-size: 14px;
}
.presets { display: flex; flex-wrap: wrap; gap: 10px; }
.preset {
  position: relative; display: grid; justify-items: center; gap: 4px; width: 112px; padding: 14px 8px 10px;
  border: 1px solid var(--ui-line); border-radius: 10px; background: var(--ui-panel); cursor: pointer;
}
.preset input { position: absolute; opacity: 0; }
.preset:has(input:checked) { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.preset-shape { display: block; height: 52px; max-width: 80px; background: #f4f1ea; border-radius: 2px; }
.preset-name { font-weight: 600; font-size: 12px; }
.preset-size { font-size: 11px; color: var(--ui-muted); }
.new-doc-form .btn { justify-self: start; height: 38px; padding: 0 18px; }
.doc-grid { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 18px; }
.doc-card { position: relative; background: var(--ui-panel); border: 1px solid var(--ui-line); border-radius: 10px; overflow: hidden; }
.doc-thumb { display: grid; place-items: center; height: 170px; background: var(--pasteboard); }
.doc-sheet { display: block; height: 130px; max-width: 150px; background: #fff; box-shadow: 0 2px 10px rgba(0,0,0,.4); }
.doc-info { display: grid; gap: 2px; padding: 10px 12px; font-size: 12px; }
.doc-title { color: var(--ui-text); font-weight: 600; font-size: 13px; text-decoration: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-del { position: absolute; top: 6px; right: 6px; opacity: 0; }
.doc-card:hover .doc-del { opacity: 1; }
.doc-del .icon-btn { background: rgba(0,0,0,.5); }

/* ------------------------------------------------------------ editor layout */
.editor-body { overflow: hidden; }
.editor {
  height: 100vh; display: grid;
  grid-template-columns: 44px 168px minmax(0, 1fr) 280px;
  grid-template-rows: 46px minmax(0, 1fr) 24px;
  grid-template-areas: "top top top top" "tools pages canvas inspector" "status status status status";
}
.topbar {
  grid-area: top; display: flex; align-items: center; gap: 10px; padding: 0 10px;
  background: var(--ui-bg); border-bottom: 1px solid var(--ui-line);
}
.doc-name { display: grid; line-height: 1.15; min-width: 0; }
.doc-name input {
  border: 1px solid transparent; background: transparent; font-weight: 600; font-size: 13px; padding: 1px 4px; border-radius: 4px; width: 260px; max-width: 30vw;
}
.doc-name input:hover, .doc-name input:focus { border-color: var(--ui-line); background: var(--ui-panel); outline: none; }
.save-state { font-size: 11px; color: var(--ui-muted); padding-left: 5px; }
.save-state[data-state="offline"] { color: #ffb020; }
.save-state[data-state="saved"]::before { content: "✓ "; color: #4cc38a; }
.topbar-center { flex: 1; display: flex; align-items: center; justify-content: center; gap: 2px; }
.topbar .sep { width: 1px; height: 20px; background: var(--ui-line); margin: 0 8px; }
.zoom-label { min-width: 54px; height: 26px; border: 0; background: transparent; cursor: pointer; border-radius: 6px; font-variant-numeric: tabular-nums; }
.zoom-label:hover { background: rgba(255,255,255,.08); }
.toggle { height: 26px; padding: 0 10px; border-radius: 6px; border: 1px solid var(--ui-line); background: transparent; cursor: pointer; font-size: 12px; }
.toggle[aria-pressed="true"] { background: rgba(61,139,255,.18); border-color: var(--accent); color: #cfe0ff; }
.presence { display: flex; align-items: center; }
.avatar {
  width: 28px; height: 28px; border-radius: 50%; border: 2px solid var(--ui-bg); background: var(--c); color: #fff;
  font-size: 11px; font-weight: 700; margin-left: -6px; cursor: pointer; display: grid; place-items: center;
}
.avatar:first-child { margin-left: 0; }

.toolbar {
  grid-area: tools; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 0;
  background: var(--ui-panel); border-right: 1px solid var(--ui-line);
}
.tool { width: 34px; height: 34px; border: 0; border-radius: 7px; background: transparent; cursor: pointer; display: grid; place-items: center; color: #cfcfd4; }
.tool:hover { background: rgba(255,255,255,.08); }
.tool.active { background: var(--accent); color: #fff; }
.tool-sep { width: 22px; height: 1px; background: var(--ui-line); margin: 6px 0; }
.swatch-pair { position: relative; width: 30px; height: 30px; }
.sw-fill, .sw-stroke { position: absolute; width: 18px; height: 18px; border-radius: 3px; }
.sw-fill { left: 0; top: 0; background: #d9d4c7; border: 1px solid #000; z-index: 1; }
.sw-stroke { right: 0; bottom: 0; border: 4px solid #1d1d1b; outline: 1px solid #777; }

.pages-panel { grid-area: pages; background: var(--ui-panel); border-right: 1px solid var(--ui-line); display: flex; flex-direction: column; min-height: 0; }
.panel-head { display: flex; align-items: center; justify-content: space-between; padding: 8px 8px 8px 12px; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--ui-muted); }
.panel-head b { color: var(--ui-text); font-weight: 600; margin-left: 4px; }
.page-thumbs { list-style: none; margin: 0; padding: 4px 10px 20px; overflow: auto; display: grid; gap: 10px; align-content: start; }
.page-item { display: grid; justify-items: center; gap: 4px; border-radius: 8px; padding: 6px; position: relative; }
.page-item[aria-current="page"] .thumb { outline: 2px solid var(--accent); outline-offset: 2px; }
.page-item.dragging { opacity: .4; }
.page-item.drop-before { box-shadow: 0 -2px 0 var(--accent); }
.page-item.drop-after { box-shadow: 0 2px 0 var(--accent); }
.thumb-btn { padding: 0; border: 0; background: none; cursor: pointer; }
.thumb { position: relative; overflow: hidden; background: #fff; box-shadow: 0 1px 4px rgba(0,0,0,.5); pointer-events: none; }
.page-meta { display: flex; align-items: center; justify-content: space-between; width: 100%; font-size: 11px; color: var(--ui-muted); padding: 0 2px; }
.page-actions { display: flex; opacity: 0; }
.page-item:hover .page-actions, .page-item:focus-within .page-actions { opacity: 1; }

.inspector { grid-area: inspector; background: var(--ui-panel); border-left: 1px solid var(--ui-line); overflow-y: auto; padding-bottom: 40px; }
.statusbar { grid-area: status; display: flex; align-items: center; justify-content: space-between; padding: 0 12px; font-size: 11px; background: var(--ui-bg); border-top: 1px solid var(--ui-line); color: #c6c6cc; }

/* ------------------------------------------------------------ inspector widgets */
.ins-title { padding: 12px 14px 4px; font-weight: 600; font-size: 13px; }
.ins-section { padding: 10px 14px 12px; border-bottom: 1px solid var(--ui-line); display: grid; gap: 8px; }
.ins-section h3 { margin: 0; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--ui-muted); font-weight: 600; }
.ins-row { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.ins-row > .num-field { flex: 1 1 0; min-width: 0; }
.ins-hint { font-size: 11px; color: var(--ui-muted); margin: 0; padding: 0 14px; line-height: 1.45; }
.ins-section .ins-hint { padding: 0; }
.ins-note { margin: 0; font-size: 12px; color: #c6c6cc; }
.ins-warn { margin: 0; font-size: 12px; color: #ff7a73; }
.num-field {
  display: flex; align-items: center; height: 28px; border-radius: 6px; background: var(--ui-panel-2); border: 1px solid transparent; padding-right: 6px;
}
.num-field:focus-within { border-color: var(--accent); }
.num-label { padding: 0 6px 0 8px; font-size: 11px; color: var(--ui-muted); cursor: ew-resize; user-select: none; white-space: nowrap; }
.num { width: 100%; min-width: 0; border: 0; background: transparent; height: 26px; font-variant-numeric: tabular-nums; font-size: 12px; outline: none; }
.unit { font-size: 10px; color: var(--ui-muted); }
.sel-field { display: grid; gap: 4px; flex: 1; }
.sel-field label, .color-field > label { font-size: 11px; color: var(--ui-muted); }
.sel-field select { height: 28px; border-radius: 6px; border: 1px solid transparent; background: var(--ui-panel-2); padding: 0 6px; font-size: 12px; }
.color-field { display: grid; gap: 6px; }
.swatches { display: flex; flex-wrap: wrap; gap: 5px; }
.swatch { width: 20px; height: 20px; border-radius: 4px; border: 1px solid rgba(255,255,255,.25); cursor: pointer; padding: 0; }
.swatch[aria-pressed="true"] { outline: 2px solid var(--accent); outline-offset: 1px; }
.swatch.none { background: linear-gradient(135deg, transparent 45%, var(--danger) 45% 55%, transparent 55%), #fff; }
.color-row { display: flex; gap: 6px; align-items: center; }
.color-row input[type="color"] { width: 28px; height: 26px; padding: 0; border: 0; background: none; cursor: pointer; }
.hex { flex: 1; min-width: 0; height: 26px; border-radius: 6px; border: 1px solid transparent; background: var(--ui-panel-2); padding: 0 8px; font-size: 12px; font-family: 'IBM Plex Mono', monospace; }
.icon-btn.seg { width: 30px; height: 28px; background: var(--ui-panel-2); border-radius: 6px; font-size: 13px; }
.icon-btn.seg[aria-pressed="true"] { background: var(--accent); }
.txt-bold { font-weight: 800; }
.txt-italic { font-style: italic; font-family: Georgia, serif; }
.txt-underline { text-decoration: underline; }
.cols-picker { display: flex; gap: 6px; }
.col-btn { flex: 1; height: 34px; display: flex; gap: 3px; padding: 6px; border-radius: 6px; border: 1px solid transparent; background: var(--ui-panel-2); cursor: pointer; }
.col-btn span { flex: 1; background: repeating-linear-gradient(#8f8f98 0 2px, transparent 2px 5px); border-radius: 1px; }
.col-btn[aria-pressed="true"] { border-color: var(--accent); background: rgba(61,139,255,.15); }

/* ------------------------------------------------------------ canvas */
.canvas { grid-area: canvas; position: relative; overflow: hidden; background: var(--pasteboard); outline: none; cursor: default; touch-action: none; user-select: none; -webkit-user-select: none; }
.canvas[data-tool="text"] { cursor: text; }
.canvas[data-tool="rect"], .canvas[data-tool="ellipse"], .canvas[data-tool="line"], .canvas[data-tool="image"] { cursor: crosshair; }
.canvas[data-tool="hand"] { cursor: grab; }
.canvas.panning, .canvas.panning * { cursor: grabbing !important; }
.canvas.loaded, .canvas.loaded * { cursor: copy !important; }
.world { position: absolute; left: 0; top: 0; transform-origin: 0 0; --z: 1; }
.pages, .overlay { position: absolute; left: 0; top: 0; }
.overlay { pointer-events: none; z-index: 10; }
.page { position: absolute; box-shadow: 0 1px 2px rgba(0,0,0,.4), 0 6px 24px rgba(0,0,0,.35); }
.page-bg { position: absolute; inset: 0; }
.page-label { position: absolute; top: 100%; left: 0; right: 0; text-align: center; color: #b4b4ba; font-size: calc(11px / var(--z)); margin-top: calc(6px / var(--z)); pointer-events: none; }
.canvas.preview .page-label { display: none; }
.guides { position: absolute; inset: 0; pointer-events: none; z-index: 100000; }
.canvas.no-guides .guides { display: none; }
.margin-box { position: absolute; border: calc(1px / var(--z)) solid var(--margin); opacity: .8; }
.col-guide { position: absolute; border-left: calc(1px / var(--z)) solid #8c6bff; border-right: calc(1px / var(--z)) solid #8c6bff; opacity: .7; }

.frame { position: absolute; box-sizing: border-box; }
.canvas:not(.no-guides) .frame[data-type="text"] { outline: calc(1px / var(--z)) solid rgba(140, 150, 170, .55); }
.canvas:not(.no-guides) .frame[data-type="image"].empty-img {
  background-image: linear-gradient(to top right, transparent calc(50% - .5px), #9aa 50%, transparent calc(50% + .5px)),
    linear-gradient(to bottom right, transparent calc(50% - .5px), #9aa 50%, transparent calc(50% + .5px)) !important;
  outline: calc(1px / var(--z)) solid #9aa;
}
.frame[data-type="image"] { overflow: hidden; }
.frame img { display: block; width: 100%; height: 100%; user-select: none; }
.frame[data-type="line"] { overflow: visible; }
.line-svg { position: absolute; left: 0; top: 0; width: 100%; height: 100%; overflow: visible; }
.txt { position: absolute; inset: 0; pointer-events: none; }
.txt span { position: absolute; white-space: pre; font-kerning: normal; user-select: none; }

/* overlay */
.sel-box, .sel-group, .hover-box, .peer-sel, .marquee, .draft { position: absolute; }
.sel-box { outline: calc(1px / var(--z)) solid var(--accent); }
.sel-box.editing { outline-style: dashed; }
.sel-group.multi { outline: calc(1px / var(--z)) dashed rgba(61,139,255,.7); }
.hover-box { outline: calc(1.5px / var(--z)) solid var(--accent); opacity: .7; }
.handle {
  position: absolute; width: calc(8px / var(--z)); height: calc(8px / var(--z)); background: #fff;
  border: calc(1px / var(--z)) solid var(--accent); transform: translate(-50%, -50%); pointer-events: auto;
}
.h-nw { left: 0; top: 0; cursor: nwse-resize; } .h-n { left: 50%; top: 0; cursor: ns-resize; }
.h-ne { left: 100%; top: 0; cursor: nesw-resize; } .h-e { left: 100%; top: 50%; cursor: ew-resize; }
.h-se { left: 100%; top: 100%; cursor: nwse-resize; } .h-s { left: 50%; top: 100%; cursor: ns-resize; }
.h-sw { left: 0; top: 100%; cursor: nesw-resize; } .h-w { left: 0; top: 50%; cursor: ew-resize; }
.port {
  position: absolute; width: calc(11px / var(--z)); height: calc(11px / var(--z)); background: #fff;
  border: calc(1px / var(--z)) solid var(--accent); transform: translate(-50%, -50%); pointer-events: auto; cursor: pointer;
  display: grid; place-items: center; font-size: calc(10px / var(--z)); line-height: 1; color: var(--accent); font-weight: 700;
}
.port.in { left: 0; top: calc(18px / var(--z)); }
.port.out { left: 100%; top: calc(100% - 18px / var(--z)); }
.port.linked::after { content: "▸"; }
.port.overset { background: #fff; border-color: var(--overset); color: var(--overset); }
.port.overset::after { content: "+"; font-size: calc(12px / var(--z)); }
.threads { position: absolute; left: 0; top: 0; width: 1px; height: 1px; overflow: visible; }
.threads path { fill: none; stroke: var(--accent); stroke-width: calc(1.25px / var(--z)); stroke-dasharray: calc(5px / var(--z)) calc(3px / var(--z)); }
.marquee { background: rgba(61,139,255,.08); outline: calc(1px / var(--z)) solid var(--accent); }
.draft { outline: calc(1px / var(--z)) solid var(--accent); background: rgba(61,139,255,.06); }
.draft-ellipse { border-radius: 50%; }
.draft-line { background: none; outline: none; border-top: calc(1px / var(--z)) solid var(--accent); }
.draft-size {
  position: absolute; left: 100%; top: 100%; margin: calc(6px / var(--z)); white-space: nowrap; background: var(--accent); color: #fff;
  font-size: calc(10px / var(--z)); padding: calc(1px / var(--z)) calc(5px / var(--z)); border-radius: calc(3px / var(--z));
}
.snap-line { position: absolute; }
.snap-line.v { border-left: calc(1px / var(--z)) solid var(--snap); width: 0 !important; }
.snap-line.h { border-top: calc(1px / var(--z)) solid var(--snap); height: 0 !important; }
.caret { position: absolute; width: calc(1.5px / var(--z)); background: #111; animation: blink 1.05s steps(1) infinite; }
.caret.hidden { display: none; }
@keyframes blink { 50% { opacity: 0; } }
.text-sel { position: absolute; background: rgba(61,139,255,.32); }
.peer-sel { outline: calc(2px / var(--z)) solid var(--c); }
.peer-badge {
  position: absolute; left: calc(-1px / var(--z)); bottom: 100%; white-space: nowrap; background: var(--c); color: #fff; font-weight: 600;
  font-size: calc(11px / var(--z)); line-height: 1.3; padding: calc(2px / var(--z)) calc(6px / var(--z)); border-radius: calc(4px / var(--z)) calc(4px / var(--z)) calc(4px / var(--z)) 0;
  margin-bottom: calc(2px / var(--z)); font-family: var(--font-ui);
}
.peer-cursor { position: absolute; transform: scale(calc(1 / var(--z))); transform-origin: 0 0; transition: left .08s linear, top .08s linear; }
.peer-cursor svg { display: block; }
.peer-cursor-name {
  position: absolute; left: 14px; top: 16px; white-space: nowrap; background: var(--c); color: #fff; font: 600 11px/1.3 var(--font-ui);
  padding: 2px 6px; border-radius: 4px;
}

.ime { position: fixed; left: -100px; top: 0; width: 2px; height: 1.2em; opacity: 0; border: 0; padding: 0; resize: none; pointer-events: none; font-size: 16px; }

/* ------------------------------------------------------------ toast / modal */
.toast {
  position: fixed; left: 50%; bottom: 40px; transform: translate(-50%, 20px); opacity: 0; transition: .2s; pointer-events: none;
  background: #111; color: #fff; padding: 8px 14px; border-radius: 8px; font-size: 12px; box-shadow: 0 6px 24px rgba(0,0,0,.5); z-index: 1000; max-width: 80vw;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: grid; place-items: center; z-index: 999; }
.name-card { width: min(380px, calc(100vw - 32px)); background: var(--ui-panel); border: 1px solid var(--ui-line); border-radius: 12px; padding: 22px; display: grid; gap: 12px; }
.name-card h2 { margin: 0; font-size: 17px; }
.name-card p { margin: 0; font-size: 12px; }
.name-card input { height: 38px; border-radius: 8px; border: 1px solid var(--ui-line); background: var(--ui-panel-2); padding: 0 12px; font-size: 14px; }

/* ------------------------------------------------------------ print / PDF */
.print-root { display: none; }
@media print {
  body > *:not(.print-root) { display: none !important; }
  html, body { background: #fff !important; height: auto; overflow: visible; }
  .print-root { display: block; }
  .print-page { position: relative; overflow: hidden; break-after: page; page-break-after: always; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .print-page:last-child { break-after: auto; page-break-after: auto; }
  .print-page .page { box-shadow: none; }
  .print-page .frame { outline: none !important; }
}

/* ------------------------------------------------------------ v2: steppers, rotation, masters, spreads */
.num-field { padding-right: 2px; }
.steps { display: grid; grid-template-rows: 1fr 1fr; height: 24px; margin-left: 4px; }
.step {
  width: 14px; display: grid; place-items: center; padding: 0; border: 0; background: transparent; color: var(--ui-muted);
  cursor: pointer; border-radius: 3px;
}
.step:hover { background: rgba(255,255,255,.1); color: var(--ui-text); }
.step:active { background: var(--accent); color: #fff; }

.rot-zone { position: absolute; width: calc(18px / var(--z)); height: calc(18px / var(--z)); pointer-events: auto; cursor: grab;
  cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 20 20'%3E%3Cpath d='M4 10a6 6 0 1 0 1.8-4.3' fill='none' stroke='white' stroke-width='3'/%3E%3Cpath d='M4 10a6 6 0 1 0 1.8-4.3' fill='none' stroke='black' stroke-width='1.4'/%3E%3Cpath d='M2 3v4.5h4.5' fill='none' stroke='black' stroke-width='1.4'/%3E%3C/svg%3E") 10 10, crosshair; }
.r-nw { left: 0; top: 0; transform: translate(-100%, -100%); }
.r-ne { left: 100%; top: 0; transform: translate(0, -100%); }
.r-se { left: 100%; top: 100%; }
.r-sw { left: 0; top: 100%; transform: translate(-100%, 0); }
.rot-label {
  position: absolute; white-space: nowrap; background: var(--accent); color: #fff; font: 600 calc(11px / var(--z)) / 1.3 var(--font-ui);
  padding: calc(2px / var(--z)) calc(6px / var(--z)); border-radius: calc(4px / var(--z));
}
.text-ov { position: absolute; }

.master-layer { position: absolute; inset: 0; z-index: 0; pointer-events: none; }
.canvas.master-view { background: #3a3550; }
.master-banner {
  position: absolute; left: 50%; top: 12px; transform: translateX(-50%); z-index: 20; display: flex; align-items: center; gap: 10px;
  background: #5b3fd6; color: #fff; padding: 6px 6px 6px 14px; border-radius: 999px; font-weight: 600; font-size: 12px; box-shadow: 0 4px 16px rgba(0,0,0,.4);
}
.master-banner .btn { background: rgba(255,255,255,.16); border-color: transparent; color: #fff; border-radius: 999px; }
.master-list { list-style: none; margin: 0; padding: 0 8px 8px; display: grid; gap: 2px; border-bottom: 1px solid var(--ui-line); }
.master-item { display: flex; align-items: center; gap: 8px; padding: 4px 6px; border-radius: 6px; cursor: pointer; font-size: 12px; }
.master-item:hover { background: rgba(255,255,255,.06); }
.master-item[aria-current="true"] { background: rgba(91,63,214,.35); }
.master-item .icon-btn { margin-left: auto; opacity: 0; }
.master-item:hover .icon-btn { opacity: 1; }
.master-item.none { color: var(--ui-muted); }
.master-prefix { display: inline-grid; place-items: center; min-width: 20px; height: 20px; border-radius: 4px; background: #5b3fd6; color: #fff; font-weight: 700; font-size: 11px; }
.master-item.none .master-prefix { background: var(--ui-panel-2); color: var(--ui-muted); }
.master-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.master-rename { flex: 1; min-width: 0; height: 22px; border-radius: 4px; border: 1px solid var(--accent); background: var(--ui-panel-2); padding: 0 6px; font-size: 12px; }
.page-thumbs > li { list-style: none; }
.page-thumbs.facing { padding: 4px 6px 20px; }
.spread { display: flex; justify-content: center; }
.spread .page-item { padding: 6px 0; }
.spread .page-item:first-child .thumb { box-shadow: -1px 1px 4px rgba(0,0,0,.5); }
.page-spacer { flex: 0 0 auto; width: 62px; }
.spread .page-meta { padding: 0 4px; }
.thumb-btn { position: relative; }
.thumb-master {
  position: absolute; top: 3px; right: 3px; min-width: 14px; height: 14px; display: grid; place-items: center; border-radius: 3px;
  background: #5b3fd6; color: #fff; font-size: 9px; font-weight: 700; padding: 0 3px;
}
.page-item.drop-master .thumb { outline: 2px solid #8f73ff; outline-offset: 2px; }
.check { display: flex; align-items: center; gap: 8px; font-size: 12px; cursor: pointer; }
.check input { accent-color: var(--accent); width: 15px; height: 15px; }
.page[data-side="L"] { box-shadow: -1px 1px 2px rgba(0,0,0,.4), -6px 6px 24px rgba(0,0,0,.3); }

/* ------------------------------------------------------------ v3: color pair, spreads, pdf menu */
.swatch-pair { width: 34px; height: 34px; }
.sw-fill, .sw-stroke { width: 20px; height: 20px; border-radius: 2px; }
.sw-fill { left: 2px; top: 2px; background: var(--c, #d9d4c7); border: 1px solid #111; box-shadow: 0 0 0 1px #777; }
.sw-stroke { right: 2px; bottom: 2px; border: 5px solid var(--c, #1d1d1b); outline: 1px solid #777; background: transparent; }
.sw-stroke i { position: absolute; inset: 0; outline: 1px solid #777; }
.sw-fill.none { background: linear-gradient(to top right, #fff calc(50% - 1px), #e5302f calc(50% - 1px) calc(50% + 1px), #fff calc(50% + 1px)); }
.sw-stroke.none { border-color: #fff; background: linear-gradient(to top right, transparent calc(50% - 1px), #e5302f calc(50% - 1px) calc(50% + 1px), transparent calc(50% + 1px)); }
.sw-fill.mixed, .sw-stroke.mixed { border-color: #888; background: repeating-conic-gradient(#999 0 25%, #555 0 50%) 0 0 / 6px 6px; }
.sw-stroke.mixed { background: transparent; border-image: repeating-conic-gradient(#999 0 25%, #555 0 50%) 5; }
.sw-swap {
  position: absolute; right: -3px; top: -3px; width: 14px; height: 14px; padding: 0; border: 0; background: transparent;
  color: #cfcfd4; cursor: pointer; display: grid; place-items: center; z-index: 2; border-radius: 3px;
}
.sw-swap:hover { color: #fff; background: rgba(255,255,255,.12); }

.spread-shadows { position: absolute; left: 0; top: 0; }
.spread-shadow { position: absolute; box-shadow: 0 1px 2px rgba(0,0,0,.4), 0 6px 24px rgba(0,0,0,.35); }
.canvas.facing .page, .canvas.facing .page[data-side="L"] { box-shadow: none; }
.sub-head { display: flex; justify-content: space-between; font-size: 11px; color: #c6c6cc; margin-top: 4px; }

.pop-menu {
  position: fixed; z-index: 1000; min-width: 240px; display: grid; padding: 6px; gap: 2px;
  background: var(--ui-panel); border: 1px solid var(--ui-line); border-radius: 10px; box-shadow: 0 10px 30px rgba(0,0,0,.5);
}
.pop-menu button { display: grid; gap: 2px; text-align: left; padding: 8px 10px; border: 0; border-radius: 7px; background: transparent; cursor: pointer; }
.pop-menu button:hover { background: rgba(255,255,255,.07); }
.pop-menu b { font-size: 13px; font-weight: 600; }
.pop-menu span { font-size: 11px; color: var(--ui-muted); }

/* ------------------------------------------------------------ v4: rulers & guides */
.pages { z-index: 0; }
.ruler { position: absolute; z-index: 15; background: #2b2b2e; }
.ruler canvas { display: block; }
.ruler-h { left: 0; top: 0; right: 0; height: 20px; cursor: row-resize; }
.ruler-v { left: 0; top: 0; bottom: 0; width: 20px; cursor: col-resize; }
.ruler-corner { position: absolute; left: 0; top: 0; width: 20px; height: 20px; z-index: 16; background: #2b2b2e; border-right: 1px solid #414146; border-bottom: 1px solid #414146; cursor: context-menu; }
.canvas.preview .ruler, .canvas.preview .ruler-corner { display: none; }
.canvas.dragging-hguide, .canvas.dragging-hguide * { cursor: row-resize !important; }
.canvas.dragging-vguide, .canvas.dragging-vguide * { cursor: col-resize !important; }
.unit-menu { min-width: 190px; }
.unit-menu button[aria-checked="true"] b { color: #9cc2ff; }

.rguides { position: absolute; inset: 0; }
.ruler-guide { position: absolute; pointer-events: auto; }
.ruler-guide::after { content: ""; position: absolute; background: #2fc6f6; }
.ruler-guide.x { top: 0; bottom: 0; width: calc(7px / var(--z)); transform: translateX(-50%); cursor: col-resize; }
.ruler-guide.y { left: 0; right: 0; height: calc(7px / var(--z)); transform: translateY(-50%); cursor: row-resize; }
.ruler-guide.x::after { left: 50%; top: 0; bottom: 0; width: calc(1px / var(--z)); }
.ruler-guide.y::after { top: 50%; left: 0; right: 0; height: calc(1px / var(--z)); }
.ruler-guide.selected::after { background: #0070ff; box-shadow: 0 0 0 calc(1px / var(--z)) rgba(0,112,255,.35); }
.ruler-guide.from-master { pointer-events: none; }
.ruler-guide.from-master::after { background: #8fdcf5; opacity: .8; }
.guide-draft { position: absolute; }
.guide-draft.x { border-left: calc(1px / var(--z)) solid #2fc6f6; }
.guide-draft.y { border-top: calc(1px / var(--z)) solid #2fc6f6; }

/* ------------------------------------------------------------ v5: collapsible panels (icon docks + flyouts) */
.panel-bar, .ins-bar {
  display: flex; align-items: center; justify-content: space-between; height: 30px; padding: 0 6px 0 12px;
  font-size: 11px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: #c6c6cc;
  background: #29292c; border-bottom: 1px solid var(--ui-line); flex: none;
}
.panel-bar .collapse, .ins-bar .collapse { font-size: 14px; color: var(--ui-muted); }
.panel-bar .collapse:hover, .ins-bar .collapse:hover { color: var(--ui-text); }
.left-dock { grid-area: pages; display: none; flex-direction: column; align-items: center; gap: 4px; padding: 8px 0; background: var(--ui-panel); border-right: 1px solid var(--ui-line); }
.dock-btn {
  width: 32px; height: 32px; display: grid; place-items: center; border: 0; border-radius: 6px; background: transparent;
  color: #cfcfd4; cursor: pointer; font-size: 14px; flex: none;
}
.dock-btn:hover { background: rgba(255,255,255,.08); color: #fff; }
.dock-btn[aria-pressed="true"] { background: #4a4a50; color: #fff; box-shadow: inset 2px 0 0 var(--accent); }
.dock-btn.expand { color: var(--ui-muted); height: 22px; margin-bottom: 4px; }

.editor.left-collapsed { grid-template-columns: 44px 40px minmax(0, 1fr) 280px; }
.editor.left-collapsed .left-dock { display: flex; }
.editor.left-collapsed .pages-panel {
  display: none; position: fixed; left: 92px; top: 52px; bottom: 32px; width: 210px; z-index: 50;
  border: 1px solid var(--ui-line); border-radius: 10px; box-shadow: 0 12px 40px rgba(0,0,0,.55); overflow: hidden;
}
.editor.left-collapsed.left-open .pages-panel { display: flex; }
.editor.left-collapsed.left-open .left-dock .dock-btn:first-child { background: #4a4a50; color: #fff; box-shadow: inset 2px 0 0 var(--accent); }
.editor.left-collapsed .pages-panel .panel-bar .collapse { display: none; }

.editor.right-collapsed { grid-template-columns: 44px 168px minmax(0, 1fr) 40px; }
.editor.left-collapsed.right-collapsed { grid-template-columns: 44px 40px minmax(0, 1fr) 40px; }
.editor.right-collapsed .inspector { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 8px 0; overflow: hidden; }

.float-panel {
  position: fixed; z-index: 50; width: 284px; max-height: calc(100vh - 90px); overflow: auto;
  background: var(--ui-panel); border: 1px solid var(--ui-line); border-radius: 10px; box-shadow: 0 12px 40px rgba(0,0,0,.55);
}
.float-head {
  position: sticky; top: 0; z-index: 1; display: flex; align-items: center; justify-content: space-between; height: 30px; padding: 0 6px 0 12px;
  background: #29292c; border-bottom: 1px solid var(--ui-line); font-size: 12px; font-weight: 600;
}
.float-panel .ins-section { border-bottom: 0; }
.float-panel .ins-section > h3 { display: none; }

/* ------------------------------------------------------------ v6: review comments */
.review-btn { gap: 6px; }
.review-btn[aria-pressed="true"] { background: #ffc53d; border-color: #ffc53d; color: #1d1d1b; }
.review-count {
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: #e5484d; color: #fff;
  font-size: 10px; font-weight: 700; display: inline-grid; place-items: center;
}
.review-btn[aria-pressed="true"] .review-count { background: #1d1d1b; }
.canvas.review, .canvas.review .frame { cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='22' height='22' viewBox='0 0 22 22'%3E%3Cpath d='M2 2h18v12H8l-6 5z' fill='%23ffc53d' stroke='%231d1d1b' stroke-width='1.4' stroke-linejoin='round'/%3E%3C/svg%3E") 2 19, crosshair; }
.canvas.review .frame[data-type="text"] { cursor: text; }
.canvas.review::after {
  content: "Modo revisão · clique para comentar · arraste sobre um texto · Esc sai"; position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%);
  background: #ffc53d; color: #1d1d1b; font-size: 12px; font-weight: 600; padding: 6px 12px; border-radius: 999px; z-index: 20; pointer-events: none;
  box-shadow: 0 4px 16px rgba(0,0,0,.4);
}

.comment-hl { position: absolute; background: rgba(255, 197, 61, .35); mix-blend-mode: multiply; }
.comment-hl.open { background: rgba(255, 197, 61, .6); }
.comment-hl.selecting { background: rgba(61, 139, 255, .3); mix-blend-mode: normal; }
.comment-pin {
  position: absolute; width: 0; height: 0; pointer-events: auto; cursor: pointer; z-index: 2;
}
.comment-pin span {
  position: absolute; left: 0; bottom: 0; transform: scale(calc(1 / var(--z))); transform-origin: 0 100%;
  min-width: 26px; height: 26px; padding: 0 6px; display: grid; place-items: center;
  border-radius: 13px 13px 13px 2px; background: var(--c); color: #fff; font: 700 11px/1 var(--font-ui);
  border: 2px solid #fff; box-shadow: 0 2px 8px rgba(0,0,0,.35); transition: box-shadow .12s;
}
.comment-pin:hover span, .comment-pin.open span { box-shadow: 0 0 0 3px rgba(255,197,61,.9), 0 2px 8px rgba(0,0,0,.35); }
.comment-pin.resolved span { opacity: .55; }

.comment-pop {
  position: absolute; z-index: 30; width: 300px; max-height: 70vh; overflow: auto; display: grid; gap: 10px; padding: 10px 12px 12px;
  background: #fff; color: #1d1d1b; border-radius: 12px; box-shadow: 0 12px 40px rgba(0,0,0,.45); cursor: default;
}
.comment-pop .icon-btn { color: #555; }
.comment-pop .icon-btn:hover { background: #f0f0f0; }
.c-head { display: flex; align-items: center; justify-content: space-between; font-size: 12px; font-weight: 600; color: #555; }
.c-tools { display: flex; gap: 2px; }
.c-quote { margin: 0; padding: 6px 10px; border-left: 3px solid #ffc53d; background: #fff8e6; font: italic 12px/1.4 'Source Serif 4', serif; color: #444; }
.c-entry { display: flex; gap: 8px; }
.c-avatar { flex: none; width: 24px; height: 24px; border-radius: 50%; background: var(--c); color: #fff; font-size: 10px; font-weight: 700; display: grid; place-items: center; }
.c-body { min-width: 0; }
.c-meta { display: flex; gap: 6px; align-items: baseline; font-size: 12px; }
.c-meta span { color: #888; font-size: 11px; }
.c-body p { margin: 2px 0 0; font-size: 13px; line-height: 1.4; white-space: pre-wrap; overflow-wrap: anywhere; }
.c-compose textarea {
  width: 100%; resize: vertical; border: 1px solid #d8d8dc; border-radius: 8px; padding: 8px 10px; font: 13px/1.4 var(--font-ui); color: #1d1d1b; background: #fafafa;
}
.c-compose textarea:focus { outline: 2px solid var(--accent); border-color: transparent; background: #fff; }
.c-actions { display: flex; align-items: center; justify-content: flex-end; gap: 6px; margin-top: 6px; }
.c-actions .muted { margin-right: auto; font-size: 11px; color: #999; }
.comment-pop .btn:not(.primary) { background: #f2f2f4; border-color: #e2e2e6; color: #1d1d1b; }

/* ------------------------------------------------------------ v7: comments list */
.c-tabs { display: flex; gap: 4px; padding: 2px; background: var(--ui-panel-2); border-radius: 8px; }
.c-tab { flex: 1; display: inline-flex; align-items: center; justify-content: center; gap: 5px; height: 26px; border: 0; border-radius: 6px; background: transparent; cursor: pointer; font-size: 12px; color: #c6c6cc; }
.c-tab span { font-size: 10px; color: var(--ui-muted); }
.c-tab[aria-pressed="true"] { background: #4a4a50; color: #fff; }
.c-tab[aria-pressed="true"] span { color: #ffc53d; }
.c-list { display: grid; gap: 4px; margin: 0 -6px; }
.c-item {
  display: flex; gap: 8px; text-align: left; padding: 8px; border: 1px solid transparent; border-radius: 8px; background: transparent; cursor: pointer;
}
.c-item:hover { background: rgba(255,255,255,.05); }
.c-item.active { background: rgba(255,197,61,.12); border-color: rgba(255,197,61,.5); }
.c-item.resolved { opacity: .6; }
.c-item .c-avatar { margin-top: 1px; }
.c-item-body { display: grid; gap: 3px; min-width: 0; }
.c-item-meta { display: flex; gap: 6px; align-items: baseline; font-size: 12px; }
.c-item-meta span { font-size: 10.5px; color: var(--ui-muted); white-space: nowrap; }
.c-item-quote { font: italic 11.5px/1.35 'Source Serif 4', serif; color: #d9c48a; border-left: 2px solid #ffc53d; padding-left: 6px; }
.c-item-text { font-size: 12.5px; line-height: 1.4; color: var(--ui-text); display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; }
.c-item-foot { display: flex; gap: 8px; font-size: 10.5px; color: var(--ui-muted); }
.c-item-foot:empty { display: none; }
.c-done { color: #4cc38a; }
.doc-sheet.img { object-fit: cover; height: 140px; width: auto; max-width: 150px; background: #fff; }
.doc-card:hover .doc-sheet { transform: translateY(-2px); box-shadow: 0 6px 18px rgba(0,0,0,.5); }
.doc-sheet { transition: transform .15s, box-shadow .15s; }

/* ------------------------------------------------------------ v8: roles, auth, workspace pages */
.role-view .toolbar .tool:not([data-tool="select"]):not([data-tool="hand"]),
.role-view .swatch-pair, .role-view .tool-sep,
.role-view [data-cmd="add-page"], .role-view [data-cmd="add-master"], .role-view .page-actions,
.role-view .master-item .icon-btn, .role-view [data-cmd="undo"], .role-view [data-cmd="redo"],
.role-user [data-cmd="add-master"], .role-user .master-item .icon-btn { display: none !important; }
.role-view .review-btn { pointer-events: none; }
.role-view .doc-name input { pointer-events: none; }

.home-top { gap: 14px; }
.home-top .brand { color: var(--ui-text); text-decoration: none; }
.crumb { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.crumb .sep { color: var(--ui-muted); }
.small { font-size: 12px; }
.top-nav { margin-left: auto; display: flex; align-items: center; gap: 16px; font-size: 13px; }
.top-nav a { color: #c6c6cc; text-decoration: none; }
.top-nav a:hover { color: #fff; }
.me { display: flex; align-items: center; gap: 8px; }
.role-tag { font-size: 10px; text-transform: uppercase; letter-spacing: .05em; padding: 2px 6px; border-radius: 4px; background: var(--ui-panel-2); color: var(--ui-muted); }
.u-avatar { width: 26px; height: 26px; border-radius: 50%; background: var(--c); color: #fff; display: inline-grid; place-items: center; font-size: 10px; font-weight: 700; flex: none; }
.home-main.narrow { max-width: 860px; }
.home-main a { color: #9cc2ff; }
.auth .auth-card { width: min(400px, calc(100vw - 32px)); margin: 12vh auto 0; display: grid; gap: 14px; padding: 28px; background: var(--ui-panel); border: 1px solid var(--ui-line); border-radius: 14px; }
.auth-card h1 { margin: 6px 0 0; font-size: 22px; }
.auth-card p { margin: 0; line-height: 1.5; }
.auth-card a { color: #9cc2ff; }
.auth-form { display: grid; gap: 12px; }
.auth-form label, .grid-form label { display: grid; gap: 6px; font-size: 12px; color: var(--ui-muted); }
.auth-form input, .grid-form input, .invite-form input, .invite-form select, .inline select, .grid-form select {
  height: 38px; border-radius: 8px; border: 1px solid var(--ui-line); background: var(--ui-panel-2); padding: 0 12px; font-size: 14px; color: var(--ui-text);
}
.auth-form .btn, .grid-form .btn { height: 38px; }
.form-error { color: #ff8a84; background: rgba(229,72,77,.12); border: 1px solid rgba(229,72,77,.4); padding: 8px 12px; border-radius: 8px; font-size: 13px; }
.form-ok { color: #7ee2b0; background: rgba(48,164,108,.12); border: 1px solid rgba(48,164,108,.4); padding: 8px 12px; border-radius: 8px; font-size: 13px; }
.dev-box { font-size: 13px; padding: 10px 12px; border-radius: 8px; background: rgba(255,197,61,.12); border: 1px dashed #ffc53d; }
.tenant-list { list-style: none; padding: 0; display: grid; gap: 10px; }
.tenant-card { display: grid; gap: 4px; padding: 16px; border-radius: 10px; background: var(--ui-panel); border: 1px solid var(--ui-line); color: var(--ui-text) !important; text-decoration: none; }
.tenant-card:hover { border-color: var(--accent); }
.panel-card { background: var(--ui-panel); border: 1px solid var(--ui-line); border-radius: 12px; padding: 18px 20px; display: grid; gap: 12px; }
.panel-card h2 { margin: 0; color: var(--ui-text); font-size: 15px; }
.grid-form { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; align-items: end; }
.slug-field { display: flex; align-items: center; gap: 0; border: 1px solid var(--ui-line); border-radius: 8px; background: var(--ui-panel-2); padding-left: 10px; }
.slug-field span { color: var(--ui-muted); font-size: 13px; white-space: nowrap; }
.slug-field input { border: 0 !important; background: transparent !important; padding-left: 2px !important; width: 100%; }
.invite-form { display: flex; gap: 8px; flex-wrap: wrap; }
.invite-form input[type="email"] { flex: 1 1 220px; }
.inline { display: flex; gap: 6px; align-items: center; }
.inline select { height: 30px; font-size: 13px; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th { text-align: left; font-weight: 500; color: var(--ui-muted); font-size: 11px; text-transform: uppercase; letter-spacing: .05em; padding: 8px; border-bottom: 1px solid var(--ui-line); }
.table td { padding: 10px 8px; border-bottom: 1px solid var(--ui-line); vertical-align: middle; }
.who { display: flex; align-items: center; gap: 10px; }
.danger-text { color: #ff8a84; }
@media (max-width: 640px) { .grid-form { grid-template-columns: 1fr; } .top-nav .me span:not(.u-avatar) { display: none; } }
