/* ---------- พื้นที่ทำงานบนเอกสาร (เต็มจอ) ---------- */
.ws {
  position: fixed; inset: 0; display: flex; flex-direction: column; background-color: #e6edf8;
  background-image: linear-gradient(rgb(31 111 229 / .06) 1px, transparent 1px), linear-gradient(90deg, rgb(31 111 229 / .06) 1px, transparent 1px);
  background-size: 24px 24px;
}
.ws-body { flex: 1; min-height: 0; display: flex; }
.ws-top { display: flex; align-items: center; gap: 8px; padding: 6px 10px; background: var(--surface); border-bottom: 1px solid var(--border); min-height: 56px; }
.ws-title { min-width: 0; flex: 1; line-height: 1.3; }
.ws-title b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ws-docs { display: flex; gap: 6px; padding: 6px 10px; background: var(--surface); border-bottom: 1px solid var(--border); overflow-x: auto; scrollbar-width: thin; }
.ws-doc { display: inline-flex; align-items: center; gap: 6px; padding: 5px 12px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; white-space: nowrap; font-size: .88rem; max-width: 260px; }
.ws-doc span { overflow: hidden; text-overflow: ellipsis; }
.ws-doc.on { background: var(--primary-soft); border-color: var(--primary); color: var(--primary-ink); font-weight: 500; }
.ws-main { position: relative; flex: 1; min-height: 0; min-width: 0; display: flex; flex-direction: column; }
.ws-side { width: 340px; flex: none; min-height: 0; overflow-y: auto; background: var(--surface); border-left: 1px solid var(--border); padding: 16px; display: flex; flex-direction: column; gap: 14px; }
.ws-side.closed { display: none; }
@media (max-width: 900px) {
  .ws-side { position: fixed; z-index: 20; right: 0; bottom: 0; top: auto; width: 100%; max-height: 62vh; border-left: 0; border-top: 1px solid var(--border); border-radius: 18px 18px 0 0; box-shadow: var(--shadow-lg); }
}
.save-state { font-size: .82rem; color: var(--text-3); white-space: nowrap; }
.save-state.err { color: var(--danger); }

/* ---------- แถบเครื่องมือ ---------- */
.tb { position: absolute; z-index: 5; left: 50%; bottom: 14px; transform: translateX(-50%); display: flex; align-items: center; gap: 2px; padding: 5px; max-width: calc(100% - 16px); overflow-x: auto; scrollbar-width: none;
  background: var(--surface); border: 1px solid var(--border); border-radius: 20px; box-shadow: 0 12px 32px rgb(31 76 160 / .2); }
.tb-btn { display: inline-grid; place-items: center; width: 42px; height: 42px; flex: none; border: 0; border-radius: 13px; background: transparent; color: var(--text-2); cursor: pointer; position: relative; }
.tb-btn:hover { background: var(--surface-2); color: var(--text); }
.tb-btn.on { background: var(--primary); color: #fff; box-shadow: 0 4px 10px rgb(31 111 229 / .3); }
.tb-btn:disabled { opacity: .35; cursor: default; background: transparent; }
.tb-btn .tb-color { position: absolute; left: 11px; right: 11px; bottom: 6px; height: 3px; border-radius: 2px; }
.tb-sep { width: 1px; height: 26px; background: var(--border); margin: 0 4px; flex: none; }
.tb-zoom { min-width: 48px; text-align: center; font-size: .82rem; color: var(--text-2); flex: none; }
.tb-pop { position: absolute; z-index: 6; left: 50%; bottom: 76px; transform: translateX(-50%); display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: center; padding: 8px 12px;
  max-width: calc(100% - 16px); background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow-lg); }
.dot { width: 30px; height: 30px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 0 0 1px var(--border-strong); cursor: pointer; flex: none; }
.dot.on { box-shadow: 0 0 0 2px var(--text); }
.size { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; border: 1px solid var(--border); background: var(--surface); cursor: pointer; flex: none; }
.size.on { border-color: var(--text); }
.size i { display: block; border-radius: 50%; background: var(--text); }
.pager { position: absolute; z-index: 5; top: 10px; right: 14px; padding: 2px 10px; border-radius: 999px; background: rgb(16 33 63 / .72); color: #fff; font-size: .82rem; }
.ro-banner { position: absolute; z-index: 5; top: 10px; left: 50%; transform: translateX(-50%); padding: 4px 14px; border-radius: 999px; background: rgb(16 33 63 / .78); color: #fff; font-size: .85rem; white-space: nowrap; }
@media (max-width: 700px) {
  .ro-banner { white-space: normal; text-align: center; width: max-content; max-width: calc(100% - 24px); border-radius: 14px; }
  .pager { top: auto; bottom: 82px; right: 12px; }
}

/* ---------- ตัวแสดงเอกสาร ---------- */
.dv-root { flex: 1; min-height: 0; overflow: auto; position: relative; overscroll-behavior: contain; -webkit-user-select: none; user-select: none; }
.dv-pages { display: flex; flex-direction: column; align-items: center; gap: 16px; padding: 16px 16px 110px; width: max-content; min-width: 100%; }
.dv-page { position: relative; background: #fff; box-shadow: 0 1px 3px rgb(15 23 42 / .18), 0 4px 14px rgb(15 23 42 / .08); flex: none; }
.dv-page canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.dv-root[data-tool="pan"] .dv-page { cursor: grab; touch-action: pan-x pan-y pinch-zoom; }
.dv-root.dv-grabbing .dv-page, .dv-root.dv-grabbing { cursor: grabbing; }
.dv-root:not([data-tool="pan"]) .dv-page { touch-action: none; }
.dv-root[data-tool="pen"] .dv-page, .dv-root[data-tool="hl"] .dv-page { cursor: crosshair; }
.dv-root[data-tool="text"] .dv-page { cursor: text; }
.dv-root[data-tool="eraser"] .dv-page { cursor: cell; }
.dv-root[data-tool="select"] .dv-page { cursor: default; }
.dv-eraser { position: fixed; z-index: 4; border-radius: 50%; border: 2px solid #0f172a; background: rgb(255 255 255 / .35); pointer-events: none; }
.dv-text-editor {
  position: absolute; z-index: 3; margin: 0; padding: 0; border: 0; outline: 1.5px dashed #0ea5e9; outline-offset: 3px; background: rgb(255 255 255 / .75);
  font-family: "Noto Sans Thai Looped", "Leelawadee UI", Thonburi, sans-serif; white-space: pre; overflow: hidden; resize: none; min-width: 20px;
  -webkit-user-select: text; user-select: text;
}
.dv-loading { position: absolute; inset: 0; display: grid; place-items: center; color: var(--text-2); pointer-events: none; }
