.studio-page-layout {
  display: grid;
  grid-template-areas: "pages editor tools";
  grid-template-columns: minmax(170px, 210px) minmax(0, 1fr) minmax(290px, 340px);
  gap: 18px;
  align-items: start;
}
.studio-page .studio-main { box-sizing:border-box;width:100%;height:calc(100vh - 76px);margin:0;padding:12px;overflow:hidden }
.studio-page .studio-workspace { height:100%;min-height:0;gap:0;overflow:hidden }
.studio-page .studio-page-layout { height:100%;min-height:0;grid-template-rows:minmax(0,1fr);align-items:stretch;overflow:hidden }
.studio-page .footer { display:none }
.studio-page .page-navigator,.studio-page .studio-tools-drawer { position:relative;top:auto;height:100%;max-height:none }
.studio-page .studio-tools-body { max-height:100% }
.studio-page .studio-editor { height:100%;min-height:0;overflow:auto;align-content:start;grid-auto-rows:max-content }
.studio-page .studio-paper { border-radius:16px }
.studio-page .studio-paper { position:relative }
.studio-page .studio-paper .book-page-editor { width:min(var(--paper-width,794px),100%);min-height:var(--paper-height,1123px);margin:0 auto }
.studio-save-strip { position:sticky;top:0;z-index:5;display:flex;align-items:center;justify-content:flex-end;gap:10px;padding:10px;border:1px solid #d8c5b9;border-radius:13px;background:rgba(255,253,248,.98);box-shadow:0 7px 20px rgba(61,43,35,.07) }
.studio-save-strip .books-status { flex:1;text-align:left }
.studio-save-strip .book-save { flex:0 0 auto }
.page-layout-fields { display:grid;grid-template-columns:1fr 1fr;gap:9px }
.page-layout-fields select { box-sizing:border-box;width:100%;height:42px;border:1px solid #d8c5b9;border-radius:11px;background:#fffefb;padding:0 9px;color:var(--ink);font:650 .78rem system-ui }
.footer-number-actions { display:grid;grid-template-columns:1fr 1fr;gap:7px }
.footer-number-actions>span { grid-column:1/-1;color:#816b61;font:750 .66rem system-ui }
.footer-number-actions button { height:34px;border:1px solid #d8c5b9;border-radius:9px;background:#fffaf4;color:#674d42;font:750 .7rem system-ui;cursor:pointer }
.footer-number-actions button:hover { border-color:#9b7463;background:#f4e7de }
.studio-paper .book-page-editor { position:relative }
.studio-page .studio-paper .book-page-editor::before { content:attr(data-page-header);position:absolute;right:46px;top:22px;left:46px;color:#98796a;text-align:center;font:700 .66rem/1.3 system-ui;letter-spacing:.04em;pointer-events:none }
.studio-page .studio-paper .book-page-editor[data-page-header=""]:empty::before { content:attr(data-placeholder);position:static;display:block;color:#a28f85;text-align:left;font:inherit;letter-spacing:normal;pointer-events:none }
.studio-paper .book-page-editor::after { content:attr(data-page-footer);position:absolute;right:46px;bottom:22px;left:46px;color:#98796a;text-align:center;font:700 .66rem/1.3 system-ui;letter-spacing:.04em;pointer-events:none }
.book-page-editor img.page-object-selected,.book-page-editor table.page-object-selected,.book-page-editor hr.page-object-selected { outline:3px solid #9b654f;outline-offset:4px }
.insert-object-tools { position:fixed;z-index:120;display:flex;gap:5px;padding:6px;border:1px solid #c9ad9d;border-radius:11px;background:#fffdf8;box-shadow:0 12px 34px rgba(55,37,30,.22) }
.insert-object-tools[hidden] { display:none }
.insert-object-tools button { min-height:34px;padding:0 11px;border:1px solid #dac7bb;border-radius:8px;background:#f8eee6;color:#65483d;font:750 .68rem system-ui;cursor:pointer }
.insert-object-tools button:hover:not(:disabled) { border-color:#986a57;background:#efe0d5 }
.insert-object-tools button[data-object-action="delete"] { border-color:#c99c92;color:#963d35 }
.insert-object-tools button:disabled { opacity:.4;cursor:not-allowed }
@media(max-width:620px){.insert-object-tools{right:8px;left:8px;justify-content:center}.insert-object-tools button{flex:1;padding:0 6px}}
.page-navigator {
  grid-area: pages;
  position: sticky;
  top: 82px;
  display: grid;
  grid-template-rows: auto auto minmax(160px, 1fr) auto;
  gap: 12px;
  max-height: calc(100vh - 100px);
  padding: 15px;
  border: 1px solid #d8c5b9;
  border-radius: 18px;
  background: rgba(255,253,248,.96);
  box-shadow: 0 12px 35px rgba(75,53,44,.07);
  box-sizing:border-box;
  min-height:0;
  overflow:hidden;
}
.page-navigator-head { display:flex;align-items:center;justify-content:space-between;gap:10px }
.page-navigator-head span { color:#9a7565;font:800 .6rem system-ui;text-transform:uppercase;letter-spacing:.11em }
.page-navigator-head h2 { margin:2px 0 0;color:#4e3d36;font:500 1.2rem Georgia,serif }
.page-navigator-head button { width:36px;height:36px;border:0;border-radius:11px;background:#8e6252;color:#fff;font-size:1.25rem;cursor:pointer }
.sidebar-page-controls { display:grid;gap:8px;padding:9px;border:1px solid #dfd0c6;border-radius:12px;background:#f8eee6 }
.sidebar-page-position { display:grid;grid-template-columns:30px minmax(0,1fr) 30px;gap:6px;align-items:center }
.sidebar-page-position strong { overflow:hidden;color:#5b463d;text-align:center;font:800 .68rem/1.2 system-ui;white-space:nowrap }
.sidebar-page-controls button { min-width:0;height:30px;padding:0 4px;border:1px solid #cfb9ab;border-radius:8px;background:#fffaf5;color:#694d41;font:800 .72rem system-ui;cursor:pointer }
.sidebar-page-controls button:hover { border-color:#997060;background:#fff }
.sidebar-page-actions { display:grid;grid-template-columns:repeat(4,minmax(0,1fr));gap:5px }
.sidebar-page-controls>small { color:#816b61;text-align:center;font:700 .6rem/1.35 system-ui }
.sidebar-page-controls>small.over-limit { color:#a32727 }
.page-list { display:grid;min-height:0;align-content:start;gap:8px;overflow:auto;padding-right:2px;scrollbar-width:thin }
.page-list-item { display:grid;grid-template-columns:34px minmax(0,1fr);gap:9px;align-items:center;width:100%;padding:9px;border:1px solid #dfd0c6;border-radius:11px;background:#fffaf4;color:#5f4c44;text-align:left;cursor:pointer }
.page-list-item:hover { border-color:#b99582;background:#f8ede4 }
.page-list-item.active { border-color:#8e6252;background:#efe0d6;box-shadow:0 0 0 2px rgba(142,98,82,.1) }
.page-list-item b { display:grid;place-items:center;width:30px;height:38px;border:1px solid #cfbcae;border-radius:3px 7px 7px 3px;background:#fffdf8;font:800 .68rem system-ui }
.page-list-item span { overflow:hidden;color:#604e46;font:700 .7rem/1.35 system-ui;text-overflow:ellipsis;white-space:nowrap }
.page-navigator>small { color:#8c776d;font:500 .63rem/1.45 system-ui }
.studio-editor { grid-area: editor;min-width:0 }
.studio-tools-drawer { grid-area:tools;position:sticky;top:82px;display:block;max-height:calc(100vh - 100px);overflow:visible;padding:0 }
.studio-tools-body { display:block;max-height:calc(100vh - 100px);padding-left:10px;overflow:auto;scroll-padding-top:70px;scrollbar-width:thin;transition:opacity .18s ease,transform .22s ease }
.studio-tools-body>.studio-save-strip,.studio-tools-body>.studio-panel,.studio-tools-body>.book-file-row { margin-bottom:14px }
.studio-tools-toggle { position:absolute;z-index:4;top:12px;left:-34px;display:flex;align-items:center;justify-content:center;width:36px;height:88px;padding:0;border:1px solid #cdb9ad;border-right:0;border-radius:12px 0 0 12px;background:#8e6252;color:#fff;box-shadow:-6px 8px 18px rgba(65,43,35,.12);cursor:pointer;writing-mode:vertical-rl }
.studio-tools-toggle span { font:800 .68rem system-ui;letter-spacing:.08em;text-transform:uppercase }
.studio-tools-toggle b { margin-top:5px;font-size:1rem;transition:transform .2s ease }
.studio-page-layout.tools-collapsed { grid-template-columns:minmax(170px,210px) minmax(0,1fr) 20px }
.tools-collapsed .studio-tools-body { pointer-events:none;opacity:0;transform:translateX(24px) }
.tools-collapsed .studio-tools-toggle b { transform:rotate(180deg) }
.studio-tools-body>.rich-toolbar { position:static;display:grid;grid-template-columns:1fr;gap:0;margin:0 0 14px;padding:0;border-radius:16px;overflow:hidden }
.studio-tools-body>.rich-toolbar .tool-group { display:grid;gap:7px;margin:0;padding:11px 12px;border:0;border-bottom:1px solid #e2d4ca;background:rgba(255,253,248,.96) }
.studio-tools-body>.rich-toolbar .tool-group:last-of-type { border-bottom:0 }
.studio-tools-body>.rich-toolbar .tool-group-title { color:#947163;font:800 .58rem/1.2 system-ui;letter-spacing:.1em;text-transform:uppercase }
.studio-tools-body>.rich-toolbar .tool-row { display:grid;gap:7px;align-items:end }
.studio-tools-body>.rich-toolbar .tool-history .tool-row { grid-template-columns:repeat(2,minmax(0,1fr)) }
.studio-tools-body>.rich-toolbar .tool-type .tool-row { grid-template-columns:repeat(2,minmax(0,1fr)) }
.studio-tools-body>.rich-toolbar .tool-format .tool-row { grid-template-columns:repeat(6,minmax(0,1fr)) }
.studio-tools-body>.rich-toolbar .tool-align .tool-row,.studio-tools-body>.rich-toolbar .tool-paragraph .tool-row { grid-template-columns:repeat(4,minmax(0,1fr)) }
.studio-tools-body>.rich-toolbar .tool-insert .tool-row { grid-template-columns:repeat(3,minmax(0,1fr)) }
.studio-tools-body>.rich-toolbar .tool-view .tool-row { grid-template-columns:1fr }
.studio-tools-body>.rich-toolbar .tool-row>button,.studio-tools-body>.rich-toolbar .tool-row>.toolbar-colour { box-sizing:border-box;width:100%;min-width:0 }
.studio-tools-body>.rich-toolbar .toolbar-select { display:grid;gap:4px;min-width:0 }
.studio-tools-body>.rich-toolbar .toolbar-select span { display:block }
.studio-tools-body>.rich-toolbar .toolbar-select select { width:100%;max-width:none }
.studio-tools-body>.rich-toolbar .font-stepper { display:grid;grid-template-columns:44px minmax(0,1fr) 44px;justify-content:stretch }
.studio-tools-body>.rich-toolbar .font-stepper button { width:100%;min-width:0 }
@media(max-width:1180px) {
  .studio-page-layout { grid-template-columns:170px minmax(0,1fr) 300px }
}
@media(max-width:940px) {
  .studio-page-layout { grid-template-areas:"pages editor";grid-template-columns:155px minmax(0,1fr) }
  .page-navigator { top:132px }
  .studio-page .studio-tools-drawer { position:fixed;z-index:70;top:76px;right:0;width:min(340px,calc(100vw - 54px));height:calc(100vh - 76px);max-height:none;padding:12px;background:#eadfd6;box-shadow:-18px 0 44px rgba(48,32,26,.24);transform:translateX(100%);transition:transform .24s ease }
  .studio-tools-body { max-height:100%;padding-left:0 }
  .studio-tools-toggle { top:22px;left:-36px }
  .studio-page-layout:not(.tools-collapsed) .studio-tools-drawer { transform:translateX(0) }
  .studio-page-layout.tools-collapsed { grid-template-columns:155px minmax(0,1fr) }
  .tools-collapsed .studio-tools-body { opacity:1;transform:none }
}
@media(max-width:620px) {
  .studio-page-layout { grid-template-areas:"pages" "editor";grid-template-columns:1fr;grid-template-rows:auto auto }
  .page-navigator { position:static;display:block;max-height:none;padding:12px }
  .sidebar-page-controls { margin-top:10px }
  .page-list { display:flex;gap:8px;margin-top:10px;padding-bottom:5px;overflow-x:auto }
  .page-list-item { flex:0 0 118px }
  .page-navigator>small { display:none }
  .studio-page .studio-main { height:calc(100dvh - 64px);padding:8px;overflow:auto }
  .studio-page .studio-workspace,.studio-page .studio-page-layout { overflow:visible }
  .studio-page .studio-page-layout { height:auto;min-height:100% }
  .studio-page .page-navigator { height:auto }
  .studio-page .studio-editor { height:auto;overflow:visible }
  .studio-page .studio-paper .book-page-editor { min-height:var(--paper-height,1123px) }
  .studio-page .studio-tools-drawer { top:64px;height:calc(100dvh - 64px) }
  .studio-tools-body>.rich-toolbar { grid-template-columns:1fr;max-height:none }
}
