html.editor-html, body.editor-body { width: 100%; height: 100%; overflow: hidden; }
.editor-body { background: var(--surface-2); }
.editor-shell {
  width: 100%;
  height: 100dvh;
  display: grid;
  grid-template-rows: 52px minmax(0, 1fr) 38px;
  grid-template-columns: 54px minmax(0, 1fr) 282px;
  grid-template-areas:
    "top top top"
    "tools canvas inspector"
    "tools pages inspector";
  background: var(--surface-2);
}
.topbar {
  grid-area: top;
  display: grid;
  grid-template-columns: auto minmax(160px, 360px) minmax(0, 1fr) auto;
  align-items: center;
  gap: 9px;
  padding: 0 10px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  z-index: 30;
}
.topbar-left, .topbar-actions, .topbar-center { display: flex; align-items: center; gap: 5px; }
.topbar-left .brand-mini { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 9px; }
.topbar-left .brand-mini:hover { background: var(--surface-2); }
.topbar-left img { width: 27px; height: 27px; }
.doc-title {
  min-width: 0;
  width: 100%;
  border: 1px solid transparent;
  background: transparent;
  border-radius: 8px;
  height: 34px;
  padding: 0 9px;
  font-weight: 740;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.doc-title:hover { background: var(--surface-2); }
.doc-title:focus { background: var(--surface); border-color: var(--border); }
.topbar-center { justify-content: center; overflow: hidden; }
.save-status { min-width: 130px; color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .tool-button { width: 34px; height: 34px; }
.topbar .btn { min-height: 34px; }
.tool-rail {
  grid-area: tools;
  min-height: 0;
  padding: 8px 7px;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  border-right: 1px solid var(--border);
  background: var(--surface);
  z-index: 20;
  scrollbar-width: thin;
}
.tool-button {
  width: 40px;
  height: 40px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border-radius: 9px;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
  position: relative;
}
.tool-button:hover { background: var(--surface-2); color: var(--text); }
.tool-button.active { background: var(--primary-soft); color: var(--primary); }
.tool-button .shortcut-hint { display: none; }
.tool-divider { width: 30px; height: 1px; background: var(--border); margin: 3px 0; flex: 0 0 auto; }
.tool-spacer { margin-top: auto; }
.canvas-area { grid-area: canvas; position: relative; min-width: 0; min-height: 0; overflow: hidden; background: var(--surface-2); }
.canvas-viewport { position: absolute; inset: 0; overflow: hidden; touch-action: none; user-select: none; cursor: default; }
.canvas-viewport.tool-hand { cursor: grab; }
.canvas-viewport.tool-hand.is-panning { cursor: grabbing; }
.canvas-viewport.tool-pen { cursor: crosshair; }
.canvas-viewport.tool-shape, .canvas-viewport.tool-connector, .canvas-viewport.tool-text { cursor: crosshair; }
#canvas { width: 100%; height: 100%; display: block; outline: none; touch-action: none; }
.canvas-hud { position: absolute; left: 12px; bottom: 12px; z-index: 8; display: flex; align-items: center; gap: 5px; }
.zoom-control { height: 34px; display: flex; align-items: center; gap: 2px; padding: 2px; border: 1px solid var(--border); border-radius: 10px; background: color-mix(in srgb, var(--surface), transparent 4%); box-shadow: var(--shadow-sm); }
.zoom-control button { width: 29px; height: 28px; border-radius: 7px; background: transparent; cursor: pointer; color: var(--muted); }
.zoom-control button:hover { background: var(--surface-2); color: var(--text); }
.zoom-value { min-width: 49px; text-align: center; color: var(--muted); font-size: 12px; font-weight: 700; }
.mode-badge { height: 34px; padding: 0 11px; display: flex; align-items: center; gap: 7px; border: 1px solid var(--border); border-radius: 10px; background: color-mix(in srgb, var(--surface), transparent 4%); box-shadow: var(--shadow-sm); color: var(--muted); font-size: 12px; font-weight: 700; }
.inspector {
  grid-area: inspector;
  min-height: 0;
  overflow: hidden;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  border-left: 1px solid var(--border);
  background: var(--surface);
  z-index: 20;
}
.inspector-tabs { display: grid; grid-template-columns: repeat(3, 1fr); padding: 7px; gap: 4px; border-bottom: 1px solid var(--border); }
.inspector-tab { min-height: 34px; border-radius: 8px; background: transparent; color: var(--muted); cursor: pointer; font-size: 12px; font-weight: 750; }
.inspector-tab:hover { background: var(--surface-2); }
.inspector-tab.active { background: var(--primary-soft); color: var(--primary); }
.inspector-content { min-height: 0; overflow-y: auto; padding: 14px; }
.inspector-section { display: grid; gap: 11px; padding: 4px 0 16px; }
.inspector-section + .inspector-section { border-top: 1px solid var(--border); padding-top: 16px; }
.inspector-section h3 { margin: 0; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }
.field-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.inline-field { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.inline-field label { font-size: 12px; color: var(--muted); font-weight: 650; }
.number-input { width: 78px; min-height: 34px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); padding: 0 8px; }
.color-input-wrap { height: 36px; display: flex; align-items: center; gap: 7px; padding: 0 8px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); }
.color-input-wrap input[type="color"] { width: 23px; height: 23px; padding: 0; border: 0; border-radius: 6px; background: transparent; cursor: pointer; }
.color-input-wrap span { min-width: 0; overflow: hidden; text-overflow: ellipsis; font-size: 11px; color: var(--muted); }
.segmented { display: grid; grid-template-columns: repeat(var(--segments, 3), 1fr); gap: 3px; padding: 3px; background: var(--surface-2); border-radius: 9px; }
.segmented button { min-height: 29px; border-radius: 7px; background: transparent; color: var(--muted); cursor: pointer; font-size: 11px; font-weight: 700; }
.segmented button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }
.checkbox-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; min-height: 34px; }
.checkbox-row label { font-size: 12px; color: var(--muted); font-weight: 650; }
.switch { position: relative; width: 38px; height: 22px; flex: 0 0 auto; }
.switch input { position: absolute; opacity: 0; }
.switch span { position: absolute; inset: 0; border-radius: 999px; background: var(--surface-3); transition: .15s; cursor: pointer; }
.switch span::after { content: ""; position: absolute; width: 16px; height: 16px; left: 3px; top: 3px; border-radius: 50%; background: var(--surface); box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: .15s; }
.switch input:checked + span { background: var(--primary); }
.switch input:checked + span::after { transform: translateX(16px); }
.selection-empty { min-height: 260px; display: grid; place-items: center; text-align: center; padding: 28px 12px; color: var(--muted); }
.selection-empty .icon { width: 40px; height: 40px; margin: 0 auto 10px; opacity: .55; }
.selection-empty strong { display: block; color: var(--text); font-size: 14px; }
.selection-empty p { margin: 5px 0 0; font-size: 12px; line-height: 1.5; }
.layer-list { display: grid; gap: 6px; }
.layer-item { min-height: 40px; padding: 4px 5px 4px 8px; display: grid; grid-template-columns: auto minmax(0, 1fr) auto auto; align-items: center; gap: 6px; border: 1px solid transparent; border-radius: 9px; }
.layer-item:hover { background: var(--surface-2); }
.layer-item.active { border-color: color-mix(in srgb, var(--primary), transparent 55%); background: var(--primary-soft); }
.layer-item button { width: 29px; height: 29px; display: grid; place-items: center; border-radius: 7px; background: transparent; cursor: pointer; color: var(--muted); }
.layer-item button:hover { background: var(--surface); color: var(--text); }
.layer-name { min-width: 0; border: 0; background: transparent; font-size: 12px; font-weight: 700; }
.layer-count { font-size: 10px; color: var(--muted); }
.inspector-action-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
.inspector-action-grid .btn { min-height: 34px; padding: 0 8px; font-size: 11px; }
.pages-bar {
  grid-area: pages;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 4px 8px;
  border-top: 1px solid var(--border);
  background: var(--surface);
  overflow: hidden;
  z-index: 18;
}
.page-tabs { min-width: 0; flex: 1; display: flex; align-items: center; gap: 4px; overflow-x: auto; scrollbar-width: thin; }
.page-tab { height: 29px; max-width: 170px; flex: 0 0 auto; padding: 0 10px; display: flex; align-items: center; gap: 7px; border-radius: 7px; background: transparent; color: var(--muted); cursor: pointer; font-size: 11px; font-weight: 700; }
.page-tab:hover { background: var(--surface-2); color: var(--text); }
.page-tab.active { background: var(--primary-soft); color: var(--primary); }
.page-tab span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.page-add { width: 29px; height: 29px; flex: 0 0 auto; display: grid; place-items: center; border-radius: 7px; background: transparent; color: var(--muted); cursor: pointer; }
.page-add:hover { background: var(--surface-2); color: var(--text); }
.context-menu { position: fixed; z-index: 850; min-width: 210px; padding: 6px; border: 1px solid var(--border); border-radius: 11px; background: var(--surface); box-shadow: var(--shadow-md); }
.context-menu button { width: 100%; min-height: 34px; padding: 0 9px; display: flex; align-items: center; justify-content: space-between; gap: 14px; border-radius: 7px; background: transparent; cursor: pointer; color: var(--text); text-align: left; font-size: 12px; }
.context-menu button:hover { background: var(--surface-2); }
.context-menu kbd { color: var(--muted); font: 10px var(--font); }
.context-menu .danger { color: var(--danger); }
.context-menu .menu-divider { height: 1px; background: var(--border); margin: 5px 2px; }

.template-picker-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.template-pick { min-height: 150px; overflow: hidden; text-align: left; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); cursor: pointer; }
.template-pick:hover { border-color: var(--primary); box-shadow: var(--shadow-sm); }
.template-pick .thumb { height: 94px; background: var(--surface-2); display: grid; place-items: center; border-bottom: 1px solid var(--border); }
.template-pick .thumb svg { width: 88%; height: 88%; }
.template-pick .copy { padding: 10px; }
.template-pick strong { display: block; font-size: 12px; }
.template-pick span { display: block; color: var(--muted); margin-top: 3px; font-size: 10px; line-height: 1.35; }
.export-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.export-option { min-height: 108px; padding: 14px; display: flex; align-items: flex-start; gap: 12px; text-align: left; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); cursor: pointer; }
.export-option:hover { border-color: var(--primary); background: var(--primary-soft); }
.export-option .icon { color: var(--primary); width: 26px; height: 26px; }
.export-option strong { display: block; font-size: 13px; }
.export-option span { display: block; margin-top: 4px; color: var(--muted); font-size: 11px; line-height: 1.45; }
.shortcuts-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px 26px; }
.shortcut-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 32px; border-bottom: 1px solid var(--border); font-size: 12px; }
.shortcut-row kbd { padding: 3px 7px; border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 6px; background: var(--surface-2); color: var(--muted); font: 10px var(--font); }
.file-drop-overlay { position: absolute; inset: 18px; z-index: 50; display: none; place-items: center; border: 3px dashed var(--primary); border-radius: 18px; background: color-mix(in srgb, var(--primary-soft), transparent 10%); color: var(--primary); font-size: 20px; font-weight: 800; pointer-events: none; }
.canvas-area.dragging-file .file-drop-overlay { display: grid; }
.text-editor-overlay { position: absolute; z-index: 70; min-width: 120px; min-height: 48px; padding: 8px; resize: both; border: 2px solid var(--primary); border-radius: 5px; background: var(--surface); color: var(--text); box-shadow: var(--shadow-md); outline: none; line-height: 1.25; }
.presentation-overlay { position: fixed; inset: 0; z-index: 1200; display: grid; grid-template-rows: minmax(0,1fr) auto; background: #111; color: #fff; }
.presentation-stage { min-height: 0; display: grid; place-items: center; overflow: hidden; }
.presentation-stage svg { max-width: 100%; max-height: 100%; background: white; box-shadow: 0 18px 60px rgba(0,0,0,.45); }
.presentation-controls { min-height: 52px; display: flex; align-items: center; justify-content: center; gap: 9px; padding: 7px; background: rgba(15,15,18,.92); }
.presentation-controls button { width: 38px; height: 38px; border-radius: 9px; background: rgba(255,255,255,.1); color: white; cursor: pointer; }
.presentation-controls button:hover { background: rgba(255,255,255,.18); }
.presentation-label { min-width: 100px; text-align: center; font-size: 12px; color: #ccc; }

/* SVG canvas */
.canvas-background { fill: var(--surface-2); }
.page-shadow { fill: rgba(20, 22, 31, .14); }
.page-surface { fill: #fff; stroke: #c9cbd3; stroke-width: 1; }
:root[data-theme="dark"] .page-surface { fill: #f8f8fa; stroke: #72747d; }
.canvas-object { cursor: move; }
.canvas-object.locked { cursor: not-allowed; }
.canvas-object .shape-hit { pointer-events: all; }
.canvas-object.selected .shape-primary { filter: drop-shadow(0 0 1px rgba(103,80,164,.55)); }
.connector-path { fill: none; pointer-events: stroke; cursor: pointer; }
.connector-label-bg { fill: var(--surface); stroke: var(--border); stroke-width: .7; }
.selection-box { fill: none; stroke: #6750a4; stroke-width: 1.4; stroke-dasharray: 5 3; vector-effect: non-scaling-stroke; pointer-events: none; }
.selection-handle { fill: #fff; stroke: #6750a4; stroke-width: 1.5; vector-effect: non-scaling-stroke; cursor: nwse-resize; }
.selection-handle.ne, .selection-handle.sw { cursor: nesw-resize; }
.rotation-handle { fill: #fff; stroke: #6750a4; stroke-width: 1.5; vector-effect: non-scaling-stroke; cursor: grab; }
.rotation-line { stroke: #6750a4; stroke-width: 1; vector-effect: non-scaling-stroke; }
.lasso-box { fill: rgba(103,80,164,.07); stroke: #6750a4; stroke-width: 1; stroke-dasharray: 5 4; vector-effect: non-scaling-stroke; }
.connection-port { fill: #fff; stroke: #6750a4; stroke-width: 1.5; vector-effect: non-scaling-stroke; cursor: crosshair; opacity: 0; }
.canvas-object:hover .connection-port, .canvas-object.selected .connection-port, .tool-connector .connection-port { opacity: 1; }
.rough-shape { filter: url(#roughen); }
.canvas-text { user-select: none; pointer-events: none; }
.canvas-text-wrap { overflow: hidden; display: flex; align-items: center; justify-content: center; text-align: center; padding: 6px; word-break: break-word; line-height: 1.2; }
.canvas-text-wrap.left { justify-content: flex-start; text-align: left; }
.canvas-text-wrap.right { justify-content: flex-end; text-align: right; }
.snap-guide { stroke: #d13d75; stroke-width: 1; stroke-dasharray: 4 3; vector-effect: non-scaling-stroke; pointer-events: none; }

body.presentation-print .topbar,
body.presentation-print .tool-rail,
body.presentation-print .inspector,
body.presentation-print .pages-bar,
body.presentation-print .canvas-hud { display: none !important; }
body.presentation-print .editor-shell { display: block; }
body.presentation-print .canvas-area { position: fixed; inset: 0; }

@media (max-width: 960px) {
  .editor-shell { grid-template-columns: 50px minmax(0,1fr); grid-template-areas: "top top" "tools canvas" "tools pages"; }
  .inspector { position: fixed; right: 0; top: 52px; bottom: 0; width: min(310px, 88vw); transform: translateX(100%); box-shadow: var(--shadow-md); transition: transform .18s ease; }
  .inspector.open { transform: translateX(0); }
  .topbar { grid-template-columns: auto minmax(100px, 1fr) auto; }
  .topbar-center { display: none; }
  .topbar-actions .desktop-only { display: none; }
}
@media (max-width: 600px) {
  .editor-shell { grid-template-rows: 48px minmax(0,1fr) 36px; grid-template-columns: 46px minmax(0,1fr); }
  .topbar { height: 48px; padding: 0 5px; grid-template-columns: auto minmax(80px,1fr) auto; }
  .topbar-left .brand-mini { width: 32px; }
  .doc-title { font-size: 13px; }
  .topbar-actions .mobile-hide { display: none; }
  .tool-rail { padding: 5px 3px; }
  .tool-button { width: 38px; height: 38px; }
  .canvas-hud { left: 7px; bottom: 7px; }
  .mode-badge { display: none; }
  .template-picker-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .export-grid, .shortcuts-grid { grid-template-columns: 1fr; }
}
@media print {
  body { background: white !important; }
  .topbar, .tool-rail, .inspector, .pages-bar, .canvas-hud, .toast-stack { display: none !important; }
  .editor-shell { display: block; height: auto; background: white; }
  .canvas-area { position: static; width: 100%; height: auto; overflow: visible; background: white; }
  .canvas-viewport { position: static; width: 100%; height: auto; overflow: visible; }
  #canvas { width: 100%; height: auto; }
}
