:root{
  --toolbar-h: 52px;
  --sidebar-w: 76px;
  --props-w: 280px;
  --mobile-bar-h: 60px;
}

.editor-body{
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  display: grid;
  grid-template-rows: var(--toolbar-h) 1fr;
  background: var(--c-bg-alt);
}

/* Header */
.editor-header{
  display:flex; align-items:center; gap: var(--sp-3);
  padding: 0 var(--sp-4);
  height: var(--toolbar-h);
  background: var(--c-surface);
  border-bottom: 1px solid var(--c-border);
  position: relative;
  z-index: 20;
}
.eh-left{ display:flex; align-items:center; gap: var(--sp-3); min-width:0; flex:1; }
.eh-center{ display:flex; align-items:center; gap: var(--sp-1); }
.eh-right{ display:flex; align-items:center; gap: var(--sp-2); flex:1; justify-content:flex-end; }
.eh-home{ display:inline-flex; color: var(--c-primary); }
.eh-file{ display:flex; flex-direction:column; min-width:0; }
.eh-filename{
  font-size: var(--fs-300); font-weight: var(--fw-semi); color: var(--c-text);
  max-width: 260px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap;
}
.eh-status{ font-size: var(--fs-100); color: var(--c-text-subtle); }
.eh-divider{ width:1px; height:22px; background: var(--c-border); margin: 0 var(--sp-2); }

.tbtn{
  display:inline-flex; align-items:center; justify-content:center;
  width:36px; height:36px; border:0; background:transparent;
  color: var(--c-text-muted); border-radius: var(--r-2); cursor:pointer;
  transition: background var(--dur-1) var(--ease), color var(--dur-1) var(--ease);
}
.tbtn:hover:not(:disabled){ background: var(--c-surface-2); color: var(--c-text); }
.tbtn:disabled{ opacity:.35; cursor:not-allowed; }
.tbtn--ghost{ color: var(--c-text); }

.zoom-group{ display:flex; align-items:center; gap:2px; background: var(--c-surface-2); border-radius: var(--r-3); padding:2px; }
.zoom-value{
  font-size: var(--fs-200); font-weight: var(--fw-semi); color: var(--c-text);
  background:transparent; border:0; cursor:pointer; min-width: 52px;
  padding: 4px 8px; border-radius: var(--r-2);
}
.zoom-value:hover{ background: var(--c-surface); }

/* Shell grid */
.editor-shell{
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr var(--props-w);
  height: 100%;
  min-height: 0;
  position: relative;
}

/* Sidebar */
.editor-sidebar{
  background: var(--c-surface);
  border-right: 1px solid var(--c-border);
  display:flex; flex-direction:column;
  padding: var(--sp-2);
  gap: 2px;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
}
.sidebar-divider{ height:1px; background: var(--c-border); margin: var(--sp-2) var(--sp-3); }

.tool{
  display:flex; flex-direction:column; align-items:center; justify-content:center;
  gap: 3px; padding: 8px 4px;
  background: transparent; border:0; border-radius: var(--r-2);
  color: var(--c-text-muted); cursor:pointer;
  font-size: var(--fs-100); font-weight: var(--fw-medium);
  transition: background var(--dur-1) var(--ease), color var(--dur-1) var(--ease);
  min-height: 52px;
}
.tool:hover{ background: var(--c-surface-2); color: var(--c-text); }
.tool[aria-pressed="true"]{ background: var(--c-primary-soft); color: var(--c-primary); }
.tool span{ line-height:1; }

/* Canvas */
.editor-canvas{
  position: relative;
  min-width: 0; min-height: 0;
  background: #e9ecf0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
@media (prefers-color-scheme: dark){
  .editor-canvas{ background: #0a0d12; }
}

.canvas-scroll{
  position: absolute;
  inset: 0;
  overflow: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: var(--sp-6) var(--sp-4);
  display: flex;
  justify-content: center;
}
.pages-stack{
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-5);
  padding-bottom: var(--sp-8);
  height: max-content;
}

/* Page */
.pdf-page{
  position: relative;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,.15), 0 0 0 1px rgba(0,0,0,.04);
  border-radius: 2px;
  overflow: hidden;
  user-select: none;
  flex: none;
}
.pdf-page canvas{ display:block; }
.pdf-page.is-active{ outline: 2px solid var(--c-primary); outline-offset: 2px; }

/* Loading */
.canvas-loading{
  position:absolute; inset:0; display:flex; align-items:center; justify-content:center;
  flex-direction:column; gap: var(--sp-4);
  background: rgba(255,255,255,.85); backdrop-filter: blur(4px);
  z-index: 5;
}
@media (prefers-color-scheme: dark){ .canvas-loading{ background: rgba(10,13,18,.85); } }
.canvas-loading p{ color: var(--c-text); font-size: var(--fs-300); }

.spinner{
  width: 32px; height: 32px;
  border: 3px solid var(--c-border-strong);
  border-top-color: var(--c-primary);
  border-radius: 50%;
  animation: spin 800ms linear infinite;
}
@keyframes spin{ to { transform: rotate(360deg); } }

/* Empty */
.canvas-empty{
  position: absolute; inset: 0;
  display:flex; align-items:center; justify-content:center;
  padding: var(--sp-5);
}
.empty-card{
  max-width: 420px; text-align:center; padding: var(--sp-8) var(--sp-6);
  background: var(--c-surface);
  border: 1.5px dashed var(--c-border-strong);
  border-radius: var(--r-5);
  box-shadow: var(--sh-2);
}
.empty-card h1{ font-size: var(--fs-700); margin-bottom: var(--sp-3); }
.empty-card p{ color: var(--c-text-muted); margin-bottom: var(--sp-5); font-size: var(--fs-300); }
.empty-note{ font-size: var(--fs-200); color: var(--c-text-subtle); margin-top: var(--sp-5) !important; }

/* Toast */
.canvas-toast{
  position: absolute; left: 50%; bottom: var(--sp-6); transform: translateX(-50%);
  background: var(--c-text); color: var(--c-text-invert);
  padding: 10px 16px; border-radius: var(--r-3);
  font-size: var(--fs-300); box-shadow: var(--sh-3);
  z-index: 30; max-width: min(90vw, 420px); text-align:center;
}

/* Properties panel */
.editor-properties{
  background: var(--c-surface);
  border-left: 1px solid var(--c-border);
  overflow-y: auto;
  padding: var(--sp-4);
}
.props-empty{ color: var(--c-text-subtle); font-size: var(--fs-300); text-align:center; padding: var(--sp-6) var(--sp-3); }

/* Context menu */
.ctx-menu{
  position: fixed;
  background: var(--c-surface);
  border:1px solid var(--c-border);
  border-radius: var(--r-3);
  box-shadow: var(--sh-4);
  padding: var(--sp-1);
  min-width: 180px;
  z-index: 60;
  display:flex; flex-direction:column;
}
.ctx-menu button{
  display:flex; align-items:center; gap: var(--sp-2);
  padding: 8px 10px; background:transparent; border:0; cursor:pointer;
  color: var(--c-text); font-size: var(--fs-300); border-radius: var(--r-2);
  text-align: left; width:100%;
}
.ctx-menu button:hover{ background: var(--c-surface-2); }
.ctx-menu button[data-danger]{ color: var(--c-danger); }
.ctx-menu hr{ margin: var(--sp-1) 0; border-top:1px solid var(--c-border); }

/* Modal */
.modal{
  position: fixed; inset: 0;
  background: rgba(10,13,18,.5);
  display:flex; align-items:center; justify-content:center;
  padding: var(--sp-4); z-index: 100;
}
.modal-panel{
  background: var(--c-surface);
  border-radius: var(--r-5);
  box-shadow: var(--sh-4);
  width: 100%; max-width: 480px;
  max-height: 90vh;
  display:flex; flex-direction:column;
}
.modal-head{
  display:flex; align-items:center; justify-content:space-between;
  padding: var(--sp-4) var(--sp-5);
  border-bottom:1px solid var(--c-border);
}
.modal-head h2{ margin:0; font-size: var(--fs-500); }
.modal-body{ padding: var(--sp-5); overflow-y:auto; flex:1; }
.modal-foot{
  display:flex; justify-content:flex-end; gap: var(--sp-2);
  padding: var(--sp-4) var(--sp-5);
  border-top:1px solid var(--c-border);
}

/* Busy */
.busy{
  position: fixed; inset:0; z-index: 200;
  background: rgba(10,13,18,.55);
  display:flex; align-items:center; justify-content:center;
}
.busy-panel{
  background: var(--c-surface);
  padding: var(--sp-6) var(--sp-7);
  border-radius: var(--r-4);
  display:flex; flex-direction:column; align-items:center; gap: var(--sp-4);
  box-shadow: var(--sh-4);
  min-width: 260px; text-align:center;
}
.busy-panel p{ margin:0; color: var(--c-text); font-weight: var(--fw-medium); }

/* Thumbs panel */
.thumbs-panel{
  position:absolute; left: var(--sidebar-w); top:0; bottom:0;
  width: 220px;
  background: var(--c-surface);
  border-right:1px solid var(--c-border);
  z-index: 30;
  display:flex; flex-direction:column;
  box-shadow: var(--sh-3);
}
.thumbs-head{
  display:flex; align-items:center; justify-content:space-between;
  padding: var(--sp-3) var(--sp-4);
  border-bottom:1px solid var(--c-border);
}
.thumbs-head h2{ margin:0; font-size: var(--fs-400); }
.thumbs-list{ flex:1; overflow-y:auto; padding: var(--sp-3); display:flex; flex-direction:column; gap: var(--sp-3); }

.thumb{
  position:relative;
  border:2px solid transparent;
  border-radius: var(--r-2);
  background: var(--c-surface-2);
  cursor:pointer;
  overflow:hidden;
  padding:0;
  display:flex; flex-direction:column; align-items:center;
  transition: border-color var(--dur-1) var(--ease);
}
.thumb:hover{ border-color: var(--c-border-strong); }
.thumb.is-active{ border-color: var(--c-primary); }
.thumb canvas{ width:100%; display:block; background:#fff; }
.thumb-num{
  position:absolute; bottom:4px; right:6px;
  background: rgba(0,0,0,.7); color:#fff;
  font-size: 10px; padding: 2px 6px; border-radius: var(--r-full);
}