/* PDF Studio — unified workspace (distinct from Smallpdf: indigo accent, sidebar layout) */
.pdf-studio-page {
    margin-left: auto;
    margin-right: auto;
}

.pdf-studio {
    --ps-accent: #4f46e5;
    --ps-accent-soft: rgba(79, 70, 229, 0.12);
    --ps-sidebar: #0f172a;
    --ps-sidebar-hover: #1e293b;
    --ps-toolbar: #1e293b;
    --ps-canvas-bg: #94a3b8;
    background: #f1f5f9;
    border-radius: 16px;
    overflow: visible;
    box-shadow: 0 4px 24px rgba(15, 23, 42, 0.08);
    min-height: 72vh;
    display: flex;
    flex-direction: column;
}

.pdf-studio .ps-workspace,
.pdf-studio .ps-upload-screen {
    overflow: hidden;
    border-radius: 0 0 16px 16px;
}

body.pdf-studio-expanded-lock {
    overflow: hidden;
}

.pdf-studio-page.is-expanded {
    position: fixed;
    inset: 0;
    z-index: 1060;
    width: 100vw !important;
    height: 100vh !important;
    max-width: none !important;
    padding: 0 !important;
    margin: 0 !important;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    display: flex;
    flex-direction: column;
    background: #f1f5f9;
}

.pdf-studio-page:fullscreen {
    width: 100%;
    height: 100%;
    max-width: none;
    padding: 0 !important;
    margin: 0 !important;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    display: flex;
    flex-direction: column;
    background: #f1f5f9;
}

.pdf-studio-page.is-expanded .pdf-studio,
.pdf-studio-page:fullscreen .pdf-studio {
    flex: 1 0 auto;
    min-height: 100%;
    height: auto;
    width: 100%;
    border-radius: 0;
    box-shadow: none;
    overflow: visible;
}

.pdf-studio-page.is-expanded .pdf-studio .ps-workspace,
.pdf-studio-page.is-expanded .pdf-studio .ps-upload-screen,
.pdf-studio-page:fullscreen .pdf-studio .ps-workspace,
.pdf-studio-page:fullscreen .pdf-studio .ps-upload-screen {
    border-radius: 0;
    overflow: visible;
}

.pdf-studio-page.is-expanded .ps-workspace,
.pdf-studio-page:fullscreen .ps-workspace,
.pdf-studio-page.is-expanded .ps-layout,
.pdf-studio-page:fullscreen .ps-layout,
.pdf-studio-page.is-expanded .ps-main,
.pdf-studio-page:fullscreen .ps-main,
.pdf-studio-page.is-expanded .ps-panel-editor,
.pdf-studio-page:fullscreen .ps-panel-editor,
.pdf-studio-page.is-expanded .ps-editor-shell,
.pdf-studio-page:fullscreen .ps-editor-shell,
.pdf-studio-page.is-expanded .ps-editor-workspace,
.pdf-studio-page:fullscreen .ps-editor-workspace,
.pdf-studio-page.is-expanded .ps-editor-main,
.pdf-studio-page:fullscreen .ps-editor-main,
.pdf-studio-page.is-expanded .ps-editor-center,
.pdf-studio-page:fullscreen .ps-editor-center {
    flex: 1 0 auto;
    min-height: auto;
    overflow: visible;
}

.pdf-studio-page.is-expanded .ps-sidebar,
.pdf-studio-page:fullscreen .ps-sidebar {
    max-height: none;
}

.pdf-studio-page.is-expanded .ps-sidebar .ps-nav,
.pdf-studio-page:fullscreen .ps-sidebar .ps-nav {
    max-height: 32vh;
}

.pdf-studio-page.is-expanded .ps-panel-editor.has-props-open .ps-editor-body,
.pdf-studio-page:fullscreen .ps-panel-editor.has-props-open .ps-editor-body {
    max-height: none;
}

.pdf-studio-page.is-expanded .ps-upload-screen,
.pdf-studio-page:fullscreen .ps-upload-screen {
    flex: 1 0 auto;
    min-height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.pdf-studio-page.is-expanded .ps-editor-body,
.pdf-studio-page:fullscreen .ps-editor-body {
    flex: 1 0 auto;
    max-height: none;
    min-height: auto;
    overflow: visible;
}

.pdf-studio-page.is-expanded .ps-canvas-col,
.pdf-studio-page:fullscreen .ps-canvas-col {
    max-height: min(70vh, 720px);
    overflow: auto;
    -webkit-overflow-scrolling: touch;
}

#psExpandToggle[aria-pressed="true"] {
    border-color: var(--ps-accent);
    color: var(--ps-accent);
    background: var(--ps-accent-soft);
}

.ps-header {
    position: relative;
    z-index: 200;
    flex-shrink: 0;
    overflow: visible;
    background: #fff;
    border-bottom: 1px solid #e2e8f0;
}

.ps-header .dropdown-menu {
    z-index: 1090;
}

.ps-brand-icon {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    background: linear-gradient(135deg, #ef4444, #dc2626);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
}

.ps-title {
    font-weight: 700;
    color: #0f172a;
}

.ps-subtitle {
    color: #64748b;
    max-width: 42rem;
}

.ps-upload-screen {
    background: linear-gradient(160deg, #eef2ff 0%, #f8fafc 45%, #f1f5f9 100%);
    min-height: 60vh;
}

.ps-upload-card {
    max-width: 560px;
}

.ps-dropzone {
    position: relative;
    border: 2px dashed #c7d2fe;
    border-radius: 20px;
    padding: 3rem 2rem;
    background: #fff;
    cursor: pointer;
    transition: border-color 0.2s, box-shadow 0.2s, transform 0.15s;
}

.ps-dropzone.is-loading {
    pointer-events: none;
    border-color: var(--ps-accent);
}

.ps-drop-loading {
    position: absolute;
    inset: 0;
    z-index: 5;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.92);
    border-radius: 18px;
}

.ps-dropzone.is-loading .ps-drop-content {
    opacity: 0.35;
}

#psSelectBtn.is-loading {
    pointer-events: none;
}

.ps-btn-loading {
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

#psExportBtn.is-loading .ps-export-idle {
    display: none !important;
}

#psExportBtn.is-loading .ps-export-loading {
    display: inline-flex !important;
    align-items: center;
}

#psExportBtn .ps-export-loading {
    display: none;
}

.btn.is-loading {
    pointer-events: none;
    opacity: 0.85;
}

.ps-dropzone:hover,
.ps-dropzone:focus,
.ps-dropzone.dragover {
    border-color: var(--ps-accent);
    box-shadow: 0 12px 40px rgba(79, 70, 229, 0.15);
    transform: translateY(-2px);
}

.ps-drop-icon {
    font-size: 3rem;
    color: var(--ps-accent);
    margin-bottom: 1rem;
}

.ps-layout {
    display: flex;
    min-height: calc(72vh - 64px);
}

.ps-sidebar {
    width: 220px;
    flex-shrink: 0;
    background: var(--ps-sidebar);
    color: #e2e8f0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transition: width 0.22s ease, opacity 0.18s ease, margin 0.22s ease;
}

.ps-sidebar .ps-nav {
    flex-shrink: 0;
    overflow-y: auto;
    max-height: 42vh;
}

.ps-sidebar.has-action-panel .ps-nav {
    max-height: 38vh;
}

.ps-sidebar-panels {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.ps-sidebar .ps-panel-action {
    margin: 0;
    border-radius: 0;
    box-shadow: none;
    max-width: none;
    background: transparent;
    color: #e2e8f0;
}

.ps-sidebar .ps-panel-action .p-4 {
    padding: 1rem !important;
}

.ps-sidebar .ps-panel-action .text-secondary,
.ps-sidebar .ps-panel-action .text-muted,
.ps-sidebar .ps-panel-action .form-label {
    color: #94a3b8 !important;
}

.ps-sidebar .ps-panel-action .form-control,
.ps-sidebar .ps-panel-action .form-select {
    background: #1e293b;
    border-color: #334155;
    color: #f1f5f9;
}

.ps-sidebar .ps-panel-action .btn-outline-primary {
    border-color: #64748b;
    color: #e2e8f0;
}

.ps-sidebar .ps-panel-action h2,
.ps-sidebar .ps-panel-action h5 {
    color: #f8fafc;
}

.ps-sidebar-head {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.65rem 0.75rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    flex-shrink: 0;
}

.ps-sidebar-head-label {
    font-size: 0.8rem;
    font-weight: 600;
    color: #e2e8f0;
    letter-spacing: 0.02em;
}

.ps-sidebar-menu-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    padding: 0;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: #e2e8f0;
    font-size: 1.15rem;
    line-height: 1;
    cursor: pointer;
    flex-shrink: 0;
}

.ps-sidebar-menu-btn:hover {
    background: var(--ps-sidebar-hover);
    color: #fff;
}

.ps-sidebar-menu-btn[aria-expanded="false"] {
    color: var(--ps-accent);
    background: var(--ps-accent-soft);
}

.ps-layout.is-sidebar-collapsed .ps-sidebar {
    width: 0;
    min-width: 0;
    flex: 0 0 0;
    margin: 0;
    padding: 0;
    border: none;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    overflow: hidden;
}

#psSidebarToggle[aria-expanded="false"],
#psSidebarMenuBtn[aria-expanded="false"] {
    border-color: var(--ps-accent);
    color: var(--ps-accent);
}

.ps-nav {
    padding: 0.75rem 0;
}

.ps-nav-label {
    display: block;
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #64748b;
    padding: 0.5rem 1rem 0.35rem;
    font-weight: 600;
}

.ps-nav-link {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 0.55rem 1rem;
    color: #94a3b8;
    text-decoration: none;
    font-size: 0.9rem;
    border-left: 3px solid transparent;
    transition: background 0.15s, color 0.15s;
}

.ps-nav-link:hover {
    background: var(--ps-sidebar-hover);
    color: #f8fafc;
}

.ps-nav-link.active {
    color: #fff;
    background: var(--ps-accent-soft);
    border-left-color: var(--ps-accent);
}

.ps-nav-link i {
    width: 1.1rem;
    text-align: center;
}

.ps-main {
    flex: 1;
    min-width: 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
    background: #e2e8f0;
}

.ps-workspace {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.ps-panel-editor {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.ps-props-dock {
    flex-shrink: 0;
    background: #fff;
    border-top: 1px solid #e2e8f0;
    max-height: 0;
    overflow: hidden;
    opacity: 0;
    transition: max-height 0.28s ease, opacity 0.2s ease;
}

.ps-props-dock.is-open {
    max-height: min(42vh, 380px);
    overflow-y: auto;
    opacity: 1;
}

.ps-panel-editor.has-props-open .ps-editor-body {
    max-height: min(62vh, 680px);
}

.ps-editor-toolbar {
    background: linear-gradient(90deg, var(--ps-toolbar), #334155);
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.ps-editor-toolbar .btn-outline-light {
    border-color: rgba(255, 255, 255, 0.35);
    color: #e2e8f0;
}

.ps-tool-btn {
    background: transparent;
    border: 1px solid transparent;
    color: #94a3b8;
}

.ps-tool-btn:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.08);
}

.ps-tool-btn.active {
    color: #fff;
    background: rgba(79, 70, 229, 0.45);
    border-color: rgba(129, 140, 248, 0.6);
}

.ps-editor-shell {
    display: flex;
    flex: 1;
    min-height: 0;
    flex-direction: column;
    align-items: stretch;
}

.ps-editor-main {
    flex: 1;
    min-width: 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.ps-editor-workspace {
    display: flex;
    flex: 1;
    min-width: 0;
    min-height: 0;
    align-items: stretch;
}

.ps-editor-body {
    display: flex;
    flex: 1;
    min-height: 520px;
    max-height: min(78vh, 820px);
}

.ps-right-sidebar {
    width: 300px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    align-self: stretch;
    min-height: 0;
    background: #fff;
    border-left: 1px solid #e2e8f0;
    overflow: hidden;
}

.ps-right-sidebar-head {
    flex-shrink: 0;
    padding: 0.85rem 1rem;
    border-bottom: 1px solid #e2e8f0;
    background: #f8fafc;
    position: sticky;
    top: 0;
    z-index: 2;
}

.ps-right-sidebar-body {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
}

.ps-right-props {
    flex-shrink: 0;
    border-bottom: 1px solid #e2e8f0;
}

.ps-right-props-body {
    max-height: min(40vh, 340px);
    overflow-y: auto;
}

.ps-right-panels {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

.ps-right-sidebar .ps-panel-right {
    margin: 0;
    border-radius: 0;
    box-shadow: none;
    max-width: none;
    height: auto;
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}

.ps-right-panels .ps-panel-action:not(.d-none) {
    flex: 1;
    min-height: 0;
}

.ps-right-panels .ps-panel-action .p-4,
.ps-right-panels .ps-panel-action .ps-right-sidebar-body {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
}

.ps-right-panels .ps-panel-action .h5,
.ps-right-panels .ps-panel-action .ps-right-sidebar-head .h6 {
    font-size: 0.95rem;
    font-weight: 600;
}

.ps-right-panels .col-md-4 {
    flex: 0 0 100%;
    max-width: 100%;
}

.ps-right-panels .form-select.w-auto,
.ps-right-panels select.form-select {
    width: 100% !important;
}

.ps-right-panels .btn-primary,
.ps-right-panels .btn-outline-primary {
    width: 100%;
}

.ps-right-panels .form-range {
    width: 100%;
}

.ps-right-panels .ps-page-thumbs {
    max-height: 200px;
    overflow-y: auto;
}

.ps-right-panels .ps-page-thumb {
    min-width: 2.5rem;
}

.ps-panel-editor.has-right-panel .ps-editor-center,
.ps-panel-editor.has-right-panel .ps-editor-workspace {
    min-width: 0;
}

.ps-panel-editor.has-right-panel .ps-editor-body {
    max-height: min(78vh, 820px);
}

.ps-panel-editor.has-right-panel .ps-editor-shell,
.ps-panel-editor.has-right-panel .ps-editor-workspace {
    min-height: 520px;
}

.ps-pages-rail {
    width: 150px;
    flex-shrink: 0;
    background: #fff;
    border-right: 1px solid #e2e8f0;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.ps-page-actions {
    display: flex;
    flex-wrap: nowrap;
    justify-content: center;
    align-items: center;
    gap: 0.4rem;
    flex-shrink: 0;
    align-self: center;
    width: fit-content;
    max-width: calc(100% - 1rem);
    margin: 0 auto;
    padding: 0.45rem 0.7rem;
    position: sticky;
    bottom: 0;
    z-index: 15;
    border: 1px solid #e2e8f0;
    border-bottom: none;
    border-radius: 14px 14px 0 0;
    background: rgba(248, 250, 252, 0.96);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    box-shadow: 0 -8px 28px rgba(15, 23, 42, 0.14);
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
}

.ps-page-act-btn {
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    padding: 0;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    background: #fff;
    color: #475569;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.ps-page-act-btn:hover:not(:disabled) {
    background: #eef2ff;
    border-color: #a5b4fc;
    color: var(--ps-accent);
}

.ps-page-act-btn:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

.ps-page-act-danger:hover:not(:disabled) {
    background: #fef2f2;
    border-color: #fca5a5;
    color: #dc2626;
}

.ps-pages-rail-head {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: #64748b;
    padding: 0.65rem 0.5rem 0.4rem;
    border-bottom: 1px solid #e2e8f0;
    flex-shrink: 0;
}

.ps-pages-rail-list {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 0.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.ps-page-rail-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
    padding: 0.35rem;
    border: 2px solid #e2e8f0;
    border-radius: 8px;
    background: #f8fafc;
    cursor: grab;
    transition: border-color 0.15s, box-shadow 0.15s, transform 0.15s;
    width: 100%;
    touch-action: none;
    user-select: none;
}

.ps-page-rail-item:active {
    cursor: grabbing;
}

.ps-page-rail-ghost {
    opacity: 0.45;
    background: #eef2ff;
    border-style: dashed;
}

.ps-page-rail-chosen {
    box-shadow: 0 8px 20px rgba(79, 70, 229, 0.25);
    transform: scale(1.03);
    z-index: 2;
}

.ps-page-rail-drag {
    opacity: 0.9;
}

.ps-page-rail-item:hover {
    border-color: #a5b4fc;
}

.ps-page-rail-item.active {
    border-color: var(--ps-accent);
    box-shadow: 0 0 0 2px var(--ps-accent-soft);
    background: #eef2ff;
}

.ps-page-rail-item canvas {
    display: block;
    width: 72px;
    height: auto;
    border-radius: 2px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12);
}

.ps-page-rail-item span {
    font-size: 0.7rem;
    font-weight: 600;
    color: #475569;
}

.ps-page-thumb:not(.active) {
    opacity: 0.45;
    text-decoration: line-through;
    background: #fee2e2;
    border-color: #fca5a5;
}

.ps-editor-center {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    min-height: 0;
    position: relative;
    overflow: hidden;
    background: #e2e8f0;
}

.ps-canvas-col {
    position: relative;
    background: #c5ced9;
    overflow: auto;
    padding: 1rem;
    display: flex;
    justify-content: safe center;
    align-items: flex-start;
    flex: 1;
    min-height: 280px;
    touch-action: manipulation;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
}

.ps-canvas-busy {
    position: absolute;
    inset: 0;
    z-index: 8;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(241, 245, 249, 0.72);
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.18s ease;
}

.ps-canvas-busy-inner {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.65rem;
    padding: 1rem 1.25rem;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.12);
    font-size: 0.9rem;
    font-weight: 600;
    color: #334155;
}

.ps-canvas-col.is-busy .ps-canvas-busy {
    opacity: 1;
}

.ps-canvas-col.is-busy .ps-stage {
    opacity: 0.72;
    transition: opacity 0.18s ease;
}

.ps-props {
    width: 260px;
    flex-shrink: 0;
    overflow-y: auto;
}

.ps-sign-canvas {
    display: block;
    width: 100%;
    max-width: 280px;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    background: #fff;
    cursor: crosshair;
    touch-action: none;
}

.ps-stage {
    position: relative;
    display: inline-block;
    max-width: none;
    box-shadow: 0 12px 40px rgba(15, 23, 42, 0.22);
    border-radius: 2px;
    line-height: 0;
    background: #fff;
    transition: opacity 0.2s ease;
}

.ps-stage.is-turning {
    opacity: 0.4;
    pointer-events: none;
}

#psPdfCanvas {
    display: block;
    max-width: none;
    height: auto;
    background: #fff;
    vertical-align: top;
}

#psOverlay {
    position: absolute;
    left: 0;
    top: 0;
    /* width/height set in JS to match PDF canvas client size — do not force 100% */
    max-width: none;
    cursor: crosshair;
    /* 1-finger pan/scroll + allow 2-finger pinch events */
    touch-action: manipulation;
    background: transparent;
    pointer-events: auto;
}

.ps-canvas-col.is-drawing #psOverlay,
.ps-canvas-col.is-touch-capture #psOverlay {
    touch-action: none;
}

.ps-sel-chrome {
    position: absolute;
    box-sizing: border-box;
    border: 2px solid #3b82f6;
    border-radius: 1px;
    z-index: 6;
    pointer-events: none; /* only handles / move pad receive events */
    cursor: default;
    transition: none;
    touch-action: none;
    margin: 0;
    padding: 0;
}

.ps-sel-chrome.is-dragging,
.ps-sel-chrome.is-resizing {
    transition: none !important;
    z-index: 8;
}

.ps-sel-move {
    position: absolute;
    inset: 10px;
    pointer-events: auto;
    touch-action: none;
    cursor: move;
    z-index: 1;
}

.ps-sel-handle {
    --ps-handle-size: 12px;
    position: absolute;
    width: var(--ps-handle-size);
    height: var(--ps-handle-size);
    background: #2563eb;
    border: 2px solid #fff;
    border-radius: 50%;
    box-sizing: border-box;
    pointer-events: auto;
    touch-action: none;
    transform: translate(-50%, -50%);
    z-index: 5;
    box-shadow: 0 0 0 1px rgba(37, 99, 235, 0.35), 0 1px 4px rgba(15, 23, 42, 0.22);
}

.ps-sel-handle[data-handle="nw"] {
    left: 0;
    top: 0;
    cursor: nwse-resize;
}

.ps-sel-handle[data-handle="n"] {
    left: 50%;
    top: 0;
    cursor: ns-resize;
}

.ps-sel-handle[data-handle="ne"] {
    left: 100%;
    top: 0;
    cursor: nesw-resize;
}

.ps-sel-handle[data-handle="e"] {
    left: 100%;
    top: 50%;
    cursor: ew-resize;
}

.ps-sel-handle[data-handle="se"] {
    left: 100%;
    top: 100%;
    cursor: nwse-resize;
}

.ps-sel-handle[data-handle="s"] {
    left: 50%;
    top: 100%;
    cursor: ns-resize;
}

.ps-sel-handle[data-handle="sw"] {
    left: 0;
    top: 100%;
    cursor: nesw-resize;
}

.ps-sel-handle[data-handle="w"] {
    left: 0;
    top: 50%;
    cursor: ew-resize;
}

.ps-sel-chrome-bar {
    position: absolute;
    top: -34px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 2px;
    padding: 3px 5px;
    border-radius: 8px;
    background: #fff;
    border: 1px solid #cbd5e1;
    box-shadow: 0 4px 14px rgba(15, 23, 42, 0.16);
    pointer-events: auto;
    white-space: nowrap;
    z-index: 3;
    cursor: default;
}

.ps-sel-color-wrap {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    margin: 0 2px 0 0;
    cursor: pointer;
    flex-shrink: 0;
}

.ps-sel-color-dot {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    border: 2px solid #fff;
    box-shadow: 0 0 0 1px #94a3b8, 0 1px 3px rgba(15, 23, 42, 0.2);
    background: #1e3a5f;
    pointer-events: none;
}

.ps-sel-color-input {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
    border: 0;
    padding: 0;
}

.ps-inline-text {
    position: absolute;
    z-index: 7;
    margin: 0;
    padding: 2px 4px;
    border: 1.5px solid #3b82f6;
    border-radius: 2px;
    background: rgba(255, 255, 255, 0.96);
    color: #1e3a5f;
    font-family: Helvetica, Arial, sans-serif;
    font-weight: 400;
    line-height: 1.25;
    resize: none;
    overflow: hidden;
    outline: none;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
    box-sizing: border-box;
    white-space: pre-wrap;
    word-break: break-word;
    caret-color: #2563eb;
}

.ps-sel-chrome.is-editing-text {
    pointer-events: none;
}

.ps-sel-chrome.is-editing-text .ps-sel-chrome-bar,
.ps-sel-chrome.is-editing-text .ps-sel-handle,
.ps-sel-chrome.is-editing-text .ps-sel-move {
    pointer-events: auto;
}

.ps-sel-chrome-bar.is-bottom {
    top: auto;
    bottom: -34px;
}

.ps-sel-chrome-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    padding: 0;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: #475569;
    font-size: 0.7rem;
    line-height: 1;
    cursor: pointer;
    transition: background 0.12s ease, color 0.12s ease;
}

.ps-sel-chrome-btn:hover {
    background: #eff6ff;
    color: #2563eb;
}

.ps-sel-chrome-btn-danger:hover {
    background: #fef2f2;
    color: #dc2626;
}

.ps-stage.is-turning .ps-sel-chrome {
    opacity: 0;
    visibility: hidden;
}

@media (max-width: 991px) {
    .ps-sel-handle {
        --ps-handle-size: 18px;
        border-width: 2.5px;
    }

    .ps-sel-move {
        inset: 14px;
    }

    .ps-sel-chrome-bar {
        top: -40px;
        padding: 4px 6px;
        gap: 4px;
    }

    .ps-sel-chrome-bar.is-bottom {
        bottom: -40px;
    }

    .ps-sel-chrome-btn {
        width: 32px;
        height: 32px;
        font-size: 0.8rem;
    }
}

@media (max-width: 480px) {
    .ps-sel-handle {
        --ps-handle-size: 20px;
    }
}

@media (min-width: 1200px) {
    .ps-sel-handle {
        --ps-handle-size: 11px;
    }
}

.ps-props {
    background: #fff;
}

.ps-panel-action {
    background: #fff;
    margin: 1rem;
    border-radius: 12px;
    box-shadow: 0 2px 12px rgba(15, 23, 42, 0.06);
    max-width: 720px;
}

.ps-file-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.ps-file-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.6rem 0.85rem;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    cursor: grab;
}

.ps-file-item.dragging {
    opacity: 0.6;
}

.ps-merge-upload-panel {
    max-width: 520px;
    margin-left: auto;
    margin-right: auto;
}

.ps-panel-editor.ps-merge-setup .ps-editor-toolbar,
.ps-panel-editor.ps-merge-setup .ps-pages-rail,
.ps-panel-editor.ps-merge-setup .ps-editor-center,
.ps-panel-editor.ps-merge-setup .ps-page-actions {
    display: none !important;
}

.ps-panel-editor.ps-merge-setup .ps-editor-workspace {
    min-height: 280px;
    justify-content: center;
    align-items: stretch;
}

.ps-panel-editor.ps-merge-setup .ps-editor-body {
    min-height: 280px;
    max-height: none;
}

.ps-panel-editor.ps-merge-setup .ps-right-sidebar {
    width: 100%;
    max-width: 400px;
    margin: 0 auto;
    border-left: none;
    border-top: none;
}

.ps-page-thumbs {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.ps-page-thumb {
    width: 72px;
    padding: 0.35rem;
    border: 2px solid #e2e8f0;
    border-radius: 6px;
    text-align: center;
    font-size: 0.75rem;
    cursor: pointer;
    background: #fff;
}

.ps-page-thumb,
.ps-page-rail-item {
    font: inherit;
}

.ps-page-thumb.selected {
    border-color: var(--ps-accent);
    background: var(--ps-accent-soft);
}

body.dark-theme .pdf-studio,
[data-bs-theme="dark"] .pdf-studio {
    background: #0f172a;
}

body.dark-theme .ps-header,
[data-bs-theme="dark"] .ps-header {
    background: #1e293b;
    border-color: #334155;
}

body.dark-theme .ps-props,
body.dark-theme .ps-props-dock,
body.dark-theme .ps-right-sidebar,
body.dark-theme .ps-panel-action,
[data-bs-theme="dark"] .ps-props,
[data-bs-theme="dark"] .ps-props-dock,
[data-bs-theme="dark"] .ps-right-sidebar,
[data-bs-theme="dark"] .ps-panel-action {
    background: #1e293b;
    color: #e2e8f0;
}

body.dark-theme .ps-right-sidebar,
[data-bs-theme="dark"] .ps-right-sidebar {
    border-left-color: #334155;
}

body.dark-theme .ps-right-sidebar-head,
[data-bs-theme="dark"] .ps-right-sidebar-head {
    background: #0f172a;
    border-bottom-color: #334155;
}

body.dark-theme .ps-props-dock,
[data-bs-theme="dark"] .ps-props-dock {
    border-top-color: #334155;
}

@media (max-width: 991px) {
    .pdf-studio-page.container {
        max-width: 100%;
        width: 100%;
        padding-left: 0.5rem;
        padding-right: 0.5rem;
    }

    .pdf-studio {
        border-radius: 10px;
        min-height: auto;
    }

    .ps-header-inner {
        flex-direction: column;
        align-items: flex-start !important;
    }

    .ps-header-actions {
        width: 100%;
        margin-left: 0 !important;
    }

    .ps-editor-body {
        flex-direction: column;
        max-height: none;
        min-height: auto;
        padding-bottom: calc(72px + env(safe-area-inset-bottom, 0px));
    }

    /* Allow the whole page to scroll after preview scroll ends */
    .pdf-studio .ps-workspace,
    .pdf-studio .ps-upload-screen {
        overflow: visible;
    }

    .ps-editor-main,
    .ps-editor-workspace,
    .ps-editor-shell {
        min-height: auto;
        overflow: visible;
    }

    .ps-header {
        position: sticky;
        top: var(--ps-site-nav-h, 56px);
        z-index: 1030;
        background: #fff;
    }

    /* Hide title/subtitle while editing — sticky tool bar needs the space */
    .ps-header.is-compact .ps-brand {
        display: none !important;
    }

    .ps-header.is-compact .ps-header-inner {
        flex-direction: row !important;
        flex-wrap: nowrap;
        align-items: center !important;
        padding-top: 0.4rem;
        padding-bottom: 0.4rem;
        gap: 0.5rem !important;
    }

    .ps-header.is-compact .ps-header-actions {
        width: 100%;
        margin-left: 0 !important;
        justify-content: flex-end;
        flex-wrap: nowrap;
    }

    /* Tool toolbar sticks under site navbar + studio header */
    .ps-editor-toolbar {
        position: sticky;
        top: var(--ps-sticky-under-header, 112px);
        z-index: 1028;
        background: linear-gradient(90deg, var(--ps-toolbar), #334155);
        box-shadow: 0 6px 18px rgba(15, 23, 42, 0.18);
        padding: 0.5rem !important;
        gap: 0.35rem !important;
        overflow-x: auto;
        flex-wrap: nowrap !important;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }

    .ps-editor-toolbar::-webkit-scrollbar {
        display: none;
    }

    .ps-editor-toolbar .btn-sm {
        padding: 0.35rem 0.55rem;
        min-height: 40px;
        min-width: 40px;
        flex-shrink: 0;
    }

    /* Page strip — hidden by default on mobile; toggle from toolbar */
    .ps-pages-rail {
        display: none;
        order: 2;
        width: 100%;
        max-height: none;
        border-right: none;
        border-bottom: none;
        border-top: 1px solid #e2e8f0;
        background: #fff;
        position: sticky;
        bottom: calc(64px + env(safe-area-inset-bottom, 0px));
        z-index: 1078;
        box-shadow: 0 -6px 20px rgba(15, 23, 42, 0.08);
    }

    .ps-panel-editor.is-pages-open .ps-pages-rail {
        display: flex;
        flex-direction: column;
    }

    .ps-pages-toggle.is-active {
        background: rgba(79, 70, 229, 0.45);
        border-color: rgba(129, 140, 248, 0.7);
        color: #fff;
    }

    .ps-pages-rail-head {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 0.45rem 0.75rem 0.25rem;
        border-bottom: none;
    }

    .ps-pages-rail-head::after {
        content: 'Hold & slide to reorder';
        font-size: 0.65rem;
        font-weight: 600;
        text-transform: none;
        letter-spacing: 0;
        color: #64748b;
        opacity: 0.9;
    }

    .ps-pages-rail-list {
        flex-direction: row;
        overflow-x: auto;
        overflow-y: hidden;
        flex-wrap: nowrap;
        gap: 0.55rem;
        padding: 0.35rem 0.75rem 0.65rem;
        -webkit-overflow-scrolling: touch;
        scroll-snap-type: x proximity;
        overscroll-behavior-x: contain;
    }

    .ps-page-rail-item {
        width: auto;
        min-width: 80px;
        flex-shrink: 0;
        scroll-snap-align: start;
        padding: 0.4rem;
        border-radius: 10px;
        touch-action: none;
        -webkit-user-select: none;
        user-select: none;
        -webkit-touch-callout: none;
    }

    .ps-page-rail-item canvas {
        width: 64px;
        pointer-events: none;
    }

    .ps-page-rail-item .ps-page-rail-grip {
        display: flex;
        color: #94a3b8;
        font-size: 0.7rem;
        line-height: 1;
        margin-top: 0.1rem;
    }

    /* Fixed bottom page tool menu */
    .ps-page-actions {
        position: fixed !important;
        left: 0;
        right: 0;
        bottom: 0;
        top: auto !important;
        order: 0;
        width: 100% !important;
        max-width: 100% !important;
        margin: 0 !important;
        align-self: stretch;
        justify-content: space-evenly;
        flex-wrap: nowrap;
        gap: 0.25rem;
        padding: 0.55rem 0.5rem calc(0.55rem + env(safe-area-inset-bottom, 0px));
        border: none;
        border-top: 1px solid #e2e8f0;
        border-bottom: none;
        border-radius: 16px 16px 0 0;
        background: rgba(255, 255, 255, 0.98);
        box-shadow: 0 -10px 32px rgba(15, 23, 42, 0.16);
        z-index: 1080;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }

    .ps-page-actions::-webkit-scrollbar {
        display: none;
    }

    .ps-page-act-btn {
        width: 40px;
        height: 40px;
        font-size: 1.05rem;
        border-radius: 12px;
        flex-shrink: 0;
    }

    .ps-editor-center {
        order: 1;
        width: 100%;
        flex: 1 1 auto;
        min-height: 42vh;
        overflow: visible;
        padding-bottom: 0;
        display: flex;
        flex-direction: column;
    }

    .ps-editor-shell {
        flex-direction: column;
    }

    .ps-editor-workspace {
        flex-direction: column;
    }

    .ps-right-sidebar {
        width: 100%;
        max-height: none;
        border-left: none;
        border-top: 1px solid #e2e8f0;
        order: -1;
    }

    .ps-panel-editor.has-right-panel .ps-editor-body,
    .ps-panel-editor.has-right-panel .ps-editor-shell,
    .ps-panel-editor.has-right-panel .ps-editor-workspace {
        max-height: none;
        min-height: auto;
    }

    .ps-canvas-col {
        width: 100%;
        padding: 0.65rem;
        min-height: 42vh;
        max-height: 58vh;
        overflow: auto;
        -webkit-overflow-scrolling: touch;
        /* When preview scroll ends, continue scrolling the page */
        overscroll-behavior: auto;
    }

    .ps-stage {
        width: auto;
        max-width: none;
        display: inline-block;
        margin: 0 auto;
    }

    #psPdfCanvas {
        /* Keep JS pixel size so pinch-zoom can pan horizontally */
        width: auto !important;
        height: auto !important;
        max-width: none;
    }

    #psOverlay {
        max-width: none !important;
    }

    .ps-props-dock.is-open {
        position: fixed;
        left: 0;
        right: 0;
        bottom: calc(64px + env(safe-area-inset-bottom, 0px));
        z-index: 1075;
        max-height: min(50vh, 380px);
        border-top-left-radius: 16px;
        border-top-right-radius: 16px;
        box-shadow: 0 -12px 40px rgba(15, 23, 42, 0.2);
    }

    .ps-panel-editor.has-props-open .ps-editor-body {
        max-height: none;
    }

    .ps-sidebar.has-action-panel .ps-sidebar-panels {
        max-height: 45vh;
    }

    .ps-layout {
        flex-direction: column;
    }

    .ps-layout.is-sidebar-collapsed .ps-sidebar {
        display: none;
    }

    .ps-sidebar {
        width: 100%;
        max-height: none;
        position: relative;
        z-index: 20;
    }

    .ps-nav {
        display: flex;
        flex-wrap: nowrap;
        gap: 0.35rem;
        padding: 0.5rem;
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }

    .ps-nav::-webkit-scrollbar {
        display: none;
    }

    .ps-nav-group {
        display: flex;
        flex-wrap: nowrap;
        gap: 0.25rem;
        flex-shrink: 0;
    }

    .ps-nav-label {
        display: none;
    }

    .ps-nav-link {
        flex-shrink: 0;
        border-left: none;
        border-radius: 8px;
        padding: 0.45rem 0.75rem;
        font-size: 0.8rem;
        white-space: nowrap;
    }

    /* Organize thumbs: bigger tap targets + horizontal scroll */
    .ps-page-thumbs {
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 0.25rem;
        gap: 0.55rem;
    }

    .ps-page-thumb {
        min-width: 72px;
        min-height: 72px;
        flex-shrink: 0;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        font-size: 0.85rem;
        font-weight: 700;
        touch-action: none;
        -webkit-user-select: none;
        user-select: none;
    }

    .pdf-studio-page.is-expanded .ps-editor-center,
    .pdf-studio-page.is-expanded .ps-editor-main,
    .pdf-studio-page.is-expanded .ps-editor-shell,
    .pdf-studio-page.is-expanded .ps-editor-workspace,
    .pdf-studio-page.is-expanded .ps-workspace {
        overflow: visible !important;
        min-height: auto !important;
    }

    .pdf-studio-page.is-expanded .ps-canvas-col {
        max-height: min(58vh, 560px);
        overflow: auto;
        -webkit-overflow-scrolling: touch;
    }

    .pdf-studio-page.is-expanded .ps-page-actions,
    .pdf-studio-page.is-expanded .ps-pages-rail {
        z-index: 1090;
    }

    .pdf-studio-page.is-expanded .ps-header {
        top: 0;
    }

    .pdf-studio-page.is-expanded .ps-editor-toolbar {
        top: var(--ps-expanded-header-h, 72px);
    }
}

/* Hide grip icon on desktop (rail is vertical) */
.ps-page-rail-grip {
    display: none;
}

body.dark-theme .ps-page-actions,
[data-bs-theme="dark"] .ps-page-actions {
    background: rgba(30, 41, 59, 0.98);
    border-color: #334155;
    box-shadow: 0 -10px 32px rgba(0, 0, 0, 0.4);
}

@media (max-width: 991px) {
    body.dark-theme .ps-pages-rail,
    [data-bs-theme="dark"] .ps-pages-rail {
        background: #1e293b;
        border-top-color: #334155;
        box-shadow: 0 -6px 20px rgba(0, 0, 0, 0.35);
    }

    body.dark-theme .ps-page-actions,
    [data-bs-theme="dark"] .ps-page-actions {
        border-top-color: #334155;
        border-bottom-color: transparent;
        box-shadow: 0 -10px 32px rgba(0, 0, 0, 0.45);
    }

    body.dark-theme .ps-header,
    [data-bs-theme="dark"] .ps-header {
        background: #0f172a;
    }
}
