/* ── Designer shell ───────────────────────────────────────── */
.pf-designer {
    display: flex;
    height: 100vh;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    font-size: 13px;
    background: #1e1e2e;
    color: #cdd6f4;
    user-select: none;
}

/* ── Toolbox (left) ──────────────────────────────────────── */
.pf-toolbox {
    width: 200px;
    min-width: 200px;
    background: #181825;
    border-right: 1px solid #313244;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}
.pf-toolbox-header {
    height: 42px;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    border-bottom: 1px solid #313244;
    color: #89b4fa;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: .7px;
    text-transform: uppercase;
    box-sizing: border-box;
}
.pf-toolbox-collapse-btn {
    width: 32px;
    height: 30px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 32px;
    border: 1px solid #45475a;
    border-radius: 5px;
    background: #313244;
    color: #cdd6f4;
    cursor: pointer;
    padding: 0;
}
.pf-toolbox-collapse-btn:hover {
    background: #45475a;
    border-color: #89b4fa;
}
.pf-toolbox-collapse-btn .material-icons {
    font-size: 18px;
}
.pf-toolbox-section { padding: 8px 12px 4px; font-size: 10px; text-transform: uppercase; letter-spacing: 1px; color: #6c7086; }
.pf-toolbox-section-toggle {
    width: 100%;
    border: none;
    background: transparent;
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    text-align: left;
}
.pf-toolbox-section-toggle:hover {
    color: #cdd6f4;
}
.pf-toolbox-section-toggle span {
    width: 10px;
    color: #89b4fa;
}
.pf-toolbox-btn {
    display: flex; align-items: center; gap: 8px;
    padding: 7px 14px; cursor: pointer; border: none;
    background: transparent; color: #cdd6f4; width: 100%; text-align: left;
    border-radius: 4px; margin: 1px 6px; width: calc(100% - 12px);
    transition: background 0.15s;
}
.pf-toolbox-btn:hover { background: #313244; }
.pf-toolbox-btn .icon { font-size: 16px; width: 20px; text-align: center; }
.pf-toolbox-divider { border-top: 1px solid #313244; margin: 6px 0; }

/* Page size presets */
.pf-preset-btn {
    display: block; width: calc(100% - 12px); margin: 1px 6px;
    padding: 5px 14px; cursor: pointer; border: 1px solid #45475a;
    background: transparent; color: #bac2de; border-radius: 4px;
    font-size: 11px; text-align: left;
}
.pf-preset-btn:hover { background: #313244; border-color: #89b4fa; }
.pf-preset-btn.selected {
    background: #1e293b;
    border-color: #ffffff;
    color: #ffffff;
    box-shadow: inset 0 0 0 1px #89b4fa;
}

/* Toolbox input settings styling */
.pf-toolbox input, .pf-toolbox select {
    background: #313244; border: 1px solid #45475a; color: #cdd6f4;
    border-radius: 4px; padding: 4px 7px; font-size: 12px; width: 100%; box-sizing: border-box;
}
.pf-toolbox input:focus, .pf-toolbox select:focus {
    outline: none; border-color: #89b4fa;
}


/* ── Canvas area (center) ────────────────────────────────── */
.pf-canvas-area {
    flex: 1;
    overflow: auto;
    background: #313244;
    display: flex;
    flex-direction: column;
}
.pf-canvas-toolbar {
    display: flex; align-items: center; gap: 8px;
    padding: 6px 12px; background: #181825; border-bottom: 1px solid #313244;
    flex-wrap: wrap;
}
.pf-canvas-toolbar button {
    padding: 4px 12px; border: 1px solid #45475a; border-radius: 4px;
    background: #313244; color: #cdd6f4; cursor: pointer; font-size: 12px;
}
.pf-canvas-toolbar button:hover { background: #45475a; }
.pf-canvas-toolbar button.primary { background: #89b4fa; color: #1e1e2e; border-color: #89b4fa; font-weight: 600; }
.pf-canvas-toolbar button.primary:hover { background: #74c7ec; }
.pf-canvas-toolbar button.danger { background: #f38ba8; color: #1e1e2e; border-color: #f38ba8; }
.pf-canvas-toolbar select, .pf-canvas-toolbar input[type=range], .pf-canvas-toolbar input[type=text] {
    background: #313244; border: 1px solid #45475a; color: #cdd6f4;
    border-radius: 4px; padding: 3px 6px; font-size: 12px;
}
.pf-canvas-toolbar input[type=text]:focus {
    outline: none; border-color: #89b4fa;
}

.pf-canvas-scroll { flex:1; overflow:auto; display:flex; justify-content:flex-start; align-items:flex-start; padding: 32px; gap: 0; }
.pf-canvas-scroll-inner { display:flex; justify-content:flex-start; min-width:100%; min-height:100%; padding: 12px; }

/* ── Page / canvas ───────────────────────────────────────── */
.pf-page {
    position: relative;
    background: #ffffff;
    border: 1px solid #d7dce8;
    box-sizing: border-box;
    box-shadow: 0 4px 24px rgba(0,0,0,0.4);
    flex-shrink: 0;
    overflow: hidden;
}
/* Handles on selected elements need to escape the page clip,
   so we lift them out via a sibling overlay trick — but for
   elements not at the very edge this is invisible. */
.pf-page > .pf-element.selected {
    overflow: visible;
}

/* ── Elements on canvas ──────────────────────────────────── */
.pf-element {
    position: absolute;
    box-sizing: border-box;
    cursor: move;
    border: 1px dashed transparent;
}
.pf-element:hover { border-color: #89b4fa80; }
.pf-element.selected { border-color: #89b4fa; border-style: solid; }

/* Resize handles */
.pf-handle {
    position: absolute; width: 8px; height: 8px;
    background: #89b4fa; border: 1px solid #1e1e2e;
    border-radius: 2px; z-index: 100;
}
.pf-handle.nw { top:-4px;  left:-4px;  cursor:nw-resize; }
.pf-handle.n  { top:-4px;  left:calc(50% - 4px); cursor:n-resize; }
.pf-handle.ne { top:-4px;  right:-4px; cursor:ne-resize; }
.pf-handle.w  { top:calc(50% - 4px); left:-4px; cursor:w-resize; }
.pf-handle.e  { top:calc(50% - 4px); right:-4px; cursor:e-resize; }
.pf-handle.sw { bottom:-4px; left:-4px;  cursor:sw-resize; }
.pf-handle.s  { bottom:-4px; left:calc(50% - 4px); cursor:s-resize; }
.pf-handle.se { bottom:-4px; right:-4px; cursor:se-resize; }

/* Element content rendering */
.pf-text-content { width:100%; min-height:100%; overflow:visible; box-sizing:border-box; padding:1px; pointer-events:none; }
.pf-barcode-content, .pf-qrcode-content, .pf-image-content {
    width:100%; height:100%; display:flex; align-items:center; justify-content:center;
    pointer-events:none; overflow:hidden;
}
.pf-image-content img { user-select:none; -webkit-user-drag:none; }
.pf-barcode-content { background: repeating-linear-gradient(90deg,#000 0,#000 2px,transparent 2px,transparent 4px); opacity:0.7; }
.pf-qrcode-content  { background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='40' height='40'%3E%3Crect width='40' height='40' fill='white'/%3E%3Crect x='2' y='2' width='14' height='14' fill='none' stroke='black' stroke-width='2'/%3E%3Crect x='5' y='5' width='8' height='8' fill='black'/%3E%3Crect x='24' y='2' width='14' height='14' fill='none' stroke='black' stroke-width='2'/%3E%3Crect x='27' y='5' width='8' height='8' fill='black'/%3E%3Crect x='2' y='24' width='14' height='14' fill='none' stroke='black' stroke-width='2'/%3E%3Crect x='5' y='27' width='8' height='8' fill='black'/%3E%3C/svg%3E") center/contain no-repeat; }
.pf-table-content   { width:100%; height:100%; overflow:hidden; pointer-events:none; }
.pf-line-h { width:100%; height:0; border:none; border-top:1px solid #000; position:absolute; top:50%; }
.pf-line-v { height:100%; width:0; border:none; border-left:1px solid #000; position:absolute; left:50%; }
.pf-rect-content { width:100%; height:100%; box-sizing:border-box; }

/* ── Properties panel (right) ───────────────────────────── */
.pf-properties {
    width: 260px; min-width: 260px;
    background: #181825;
    border-left: 1px solid #313244;
    display: flex; flex-direction: column;
    overflow-y: auto;
}
.pf-prop-header {
    padding: 10px 14px; font-weight: 600; font-size: 12px;
    border-bottom: 1px solid #313244; background: #11111b;
    text-transform: uppercase; letter-spacing: 0.5px; color: #89b4fa;
}
.pf-prop-section { padding: 8px 14px 4px; font-size: 10px; text-transform: uppercase; color: #6c7086; letter-spacing: 1px; }
.pf-prop-row { padding: 4px 14px; display:flex; flex-direction:column; gap:2px; }
.pf-prop-row label { font-size: 11px; color: #a6adc8; }
.pf-prop-row input:not([type=checkbox]):not([type=range]), 
.pf-prop-row select, 
.pf-prop-row textarea,
.pf-prop-row-inline input:not([type=checkbox]):not([type=range]), 
.pf-prop-row-inline select, 
.pf-prop-row-inline textarea {
    background: #313244; border: 1px solid #45475a; color: #cdd6f4;
    border-radius: 4px; padding: 4px 7px; font-size: 12px; width: 100%; box-sizing: border-box;
}
.pf-prop-row input:not([type=checkbox]):not([type=range]):focus, 
.pf-prop-row select:focus, 
.pf-prop-row textarea:focus,
.pf-prop-row-inline input:not([type=checkbox]):not([type=range]):focus, 
.pf-prop-row-inline select:focus, 
.pf-prop-row-inline textarea:focus {
    outline: none; border-color: #89b4fa;
}
.pf-designer select option {
    background-color: #1e1e2e;
    color: #cdd6f4;
}
.pf-prop-row input[type=color], .pf-prop-row-inline input[type=color] {
    padding: 2px;
    height: 26px;
    cursor: pointer;
}

.pf-prop-row-inline { display:flex; gap:6px; padding: 4px 14px; }
.pf-prop-row-inline > * { flex:1; }
.pf-prop-row-inline label { font-size: 11px; color: #a6adc8; display:block; margin-bottom:2px; }
.pf-prop-checkbox { display:flex; align-items:center; gap:8px; padding:4px 14px; }
.pf-prop-checkbox input[type=checkbox] { accent-color: #89b4fa; width:14px; height:14px; }
.pf-prop-checkbox label { font-size:12px; }
.pf-prop-btn {
    margin: 6px 14px; padding: 6px; border: 1px solid #45475a;
    background: #313244; color: #cdd6f4; border-radius: 4px; cursor: pointer; font-size: 12px;
}
.pf-prop-btn:hover { background: #45475a; }
.pf-prop-btn.danger { border-color:#f38ba8; color:#f38ba8; }
.pf-prop-btn.danger:hover { background:#f38ba8; color:#1e1e2e; }

/* Table column cards */
.pf-col-card { margin:4px 10px; background:#11111b; border:1px solid #313244; border-radius:5px; padding:6px 8px; display:flex; flex-direction:column; gap:4px; }
.pf-col-r1 { display:flex; gap:4px; align-items:center; }
.pf-col-input { flex:1; background:#313244; border:1px solid #45475a; color:#cdd6f4; border-radius:3px; padding:3px 6px; font-size:11px; min-width:0; }
.pf-col-input:focus { outline:none; border-color:#89b4fa; }
.pf-col-w { max-width:44px; flex:none; text-align:center; }
.pf-col-pad { max-width:34px; flex:none; text-align:center; }
.pf-col-del { background:transparent; border:1px solid #45475a; color:#f38ba8; border-radius:3px; padding:2px 6px; cursor:pointer; font-size:11px; flex-shrink:0; }
.pf-col-del:hover { background:#f38ba8; color:#1e1e2e; }
.pf-col-style-row { display:flex; align-items:center; gap:3px; flex-wrap:wrap; }
.pf-col-label { font-size:9px; text-transform:uppercase; color:#6c7086; letter-spacing:.5px; width:22px; flex-shrink:0; }
.pf-align-btn { width:20px; height:20px; display:flex; align-items:center; justify-content:center; background:#313244; border:1px solid #45475a; color:#a6adc8; border-radius:3px; cursor:pointer; font-size:10px; padding:0; }
.pf-align-btn:hover, .pf-align-btn.active { background:#89b4fa; border-color:#89b4fa; color:#1e1e2e; }
.pf-style-btn { width:20px; height:20px; display:flex; align-items:center; justify-content:center; background:#313244; border:1px solid #45475a; color:#a6adc8; border-radius:3px; cursor:pointer; font-size:11px; font-weight:bold; padding:0; }
.pf-style-btn.italic { font-style:italic; font-weight:normal; }
.pf-style-btn:hover, .pf-style-btn.active { background:#89b4fa; border-color:#89b4fa; color:#1e1e2e; }
.pf-col-add { margin:4px 10px; padding:5px 8px; background:transparent; border:1px dashed #45475a; color:#a6adc8; border-radius:4px; cursor:pointer; font-size:11px; width:calc(100% - 20px); }
.pf-col-add:hover { border-color:#89b4fa; color:#89b4fa; }

/* No-selection placeholder */
.pf-no-selection { padding:20px 14px; color:#6c7086; font-size:12px; text-align:center; }

/* ── Preview modal ───────────────────────────────────────── */
.pf-preview-overlay {
    position:fixed; inset:0; background:rgba(0,0,0,0.7); z-index:1000;
    display:flex; align-items:stretch; justify-content:stretch;
    padding:0; box-sizing:border-box;
}
.pf-preview-modal {
    background:#1e1e2e; border:0; border-radius:0;
    padding:0; width:100%; height:100%; max-width:none; max-height:none;
    display:flex; flex-direction:column; gap:0; box-sizing:border-box;
}
.pf-preview-header {
    display:flex; justify-content:space-between; align-items:center; gap:12px; flex-shrink:0;
    padding:10px 12px; border-bottom:1px solid #313244;
}
.pf-preview-actions {
    display:flex; gap:8px; align-items:center; flex-wrap:wrap; justify-content:flex-end;
}
.pf-preview-stage {
    flex:1; min-height:0; overflow:auto; display:flex; flex-direction:column;
    align-items:center; padding:8px; background:#313244; border-radius:0; gap:10px;
}
.pf-preview-page-group {
    display:flex; flex-direction:column; align-items:center; flex-shrink:0;
}
.pf-preview-page-label {
    color:#cdd6f4; font-size:11px; margin-bottom:6px;
}
.pf-preview-modal iframe { flex:1; border:none; background:#fff; border-radius:4px; }
.pf-preview-modal button { padding:6px 16px; background:#89b4fa; color:#1e1e2e; border:none; border-radius:4px; cursor:pointer; font-weight:600; }
.pf-preview-zoom {
    display:flex; align-items:center; gap:6px;
    padding:4px 6px; background:#181825; border:1px solid #45475a; border-radius:4px;
}
.pf-preview-zoom input[type="range"] {
    width:120px; accent-color:#89b4fa;
}
.pf-preview-zoom span {
    min-width:42px; color:#cdd6f4; font-size:11px; text-align:center;
}
.pf-preview-zoom button {
    padding:4px 8px; background:#313244; color:#cdd6f4; border:1px solid #45475a; border-radius:4px;
}

/* ── Sticky Rulers & Multi-page canvas ─────────────────────────── */
.pf-canvas-container {
    position: relative;
    background: #1e1e2e;
    box-shadow: 0 4px 24px rgba(0,0,0,0.25);
    border-radius: 4px;
    border: 1px solid #313244;
}
.pf-ruler-corner {
    border-top-left-radius: 4px;
}
.pf-ruler-horizontal {
    border-top-right-radius: 4px;
}
.pf-ruler-vertical {
    border-bottom-left-radius: 4px;
}
.pf-canvas-workspace {
    background: #313244;
}
.pf-page-break {
    position: absolute;
    left: 0;
    width: 100%;
    height: 0;
    border-top: 1.5px dashed #f38ba8;
    z-index: 50;
    pointer-events: none;
}
.pf-page-break-label {
    position: absolute;
    right: 12px;
    top: -9px;
    background: #f38ba8;
    color: #1e1e2e;
    font-size: 9px;
    padding: 1px 6px;
    border-radius: 3px;
    font-weight: 600;
    letter-spacing: 0.5px;
    box-shadow: 0 2px 6px rgba(0,0,0,0.2);
}
.pf-margin-guide {
    position: absolute;
    border: 1px dashed rgba(137, 180, 250, 0.35);
    pointer-events: none;
    z-index: 5;
}
.pf-margin-label {
    position: absolute;
    left: 6px;
    top: 4px;
    color: rgba(137, 180, 250, 0.4);
    font-size: 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.pf-add-page-btn {
    transition: background 0.2s, border-color 0.2s, transform 0.15s;
}
.pf-add-page-btn:hover {
    background: #313244 !important;
    border-color: #a6e3a1 !important;
    color: #a6e3a1 !important;
    transform: scale(1.02);
}
.pf-add-page-btn:active {
    transform: scale(0.98);
}
.pf-layer-btn {
    flex: 1;
    height: 26px;
    background: #313244;
    border: 1px solid #45475a;
    color: #cdd6f4;
    border-radius: 4px;
    cursor: pointer;
    font-size: 11px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    transition: background 0.15s, border-color 0.15s;
}
.pf-layer-btn:hover {
    background: #45475a;
    border-color: #89b4fa;
}

.pf-marquee {
    border: 1px dashed #89b4fa;
    background: rgba(137, 180, 250, 0.15);
}

.pf-back-btn:hover {
    background: #45475a !important;
    border-color: #89b4fa !important;
    color: #ffffff !important;
}

/* Specificity overrides to defeat ERP app.css global input styles */
.pf-designer input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]),
.pf-designer select,
.pf-designer textarea {
    background-color: #313244 !important;
    border: 1px solid #45475a !important;
    color: #cdd6f4 !important;
    border-radius: 4px !important;
    box-shadow: none !important;
    height: auto !important;
    line-height: normal !important;
}

.pf-designer input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]):focus,
.pf-designer select:focus,
.pf-designer textarea:focus {
    border-color: #89b4fa !important;
    outline: none !important;
    box-shadow: 0 0 0 2px rgba(137, 180, 250, 0.2) !important;
}

/* Padding and width overrides to ensure compact fields in designer panels */
.pf-designer .pf-toolbox input,
.pf-designer .pf-toolbox select,
.pf-designer .pf-prop-row input,
.pf-designer .pf-prop-row select,
.pf-designer .pf-prop-row textarea,
.pf-designer .pf-prop-row-inline input,
.pf-designer .pf-prop-row-inline select,
.pf-designer .pf-prop-row-inline textarea {
    padding: 4px 7px !important;
    font-size: 12px !important;
}

.pf-designer .pf-canvas-toolbar input[type=text],
.pf-designer .pf-canvas-toolbar select {
    padding: 3px 6px !important;
    font-size: 12px !important;
    width: auto !important;
}

.pf-designer .pf-col-input {
    padding: 3px 6px !important;
    font-size: 11px !important;
}

/* Canva-like editor chrome: manually collapsible rail, centered canvas, bottom zoom bar */
@media (min-width: 861px) {
    .pf-toolbox {
        transition: width .18s ease, min-width .18s ease, box-shadow .18s ease;
        z-index: 5;
    }

    .pf-toolbox.expanded {
        width: 224px;
        min-width: 224px;
    }

    .pf-toolbox.collapsed {
        width: 76px;
        min-width: 76px;
        overflow-x: hidden;
    }

    .pf-toolbox.collapsed .pf-toolbox-header {
        justify-content: center;
        padding: 6px 0;
    }

    .pf-toolbox.collapsed .pf-toolbox-header > span:not(.material-icons) {
        display: none;
    }

    .pf-toolbox.collapsed .pf-toolbox-section {
        font-size: 0;
        padding: 8px 0 4px;
        text-align: center;
    }

    .pf-toolbox.collapsed .pf-toolbox-btn {
        justify-content: center;
        gap: 0;
        font-size: 0;
        min-height: 46px;
        padding: 7px 0;
        margin: 3px 10px;
        width: calc(100% - 20px);
    }

    .pf-toolbox.collapsed .pf-toolbox-btn .icon {
        width: 100%;
        font-size: 22px;
    }

    .pf-toolbox.collapsed .pf-toolbox-section-toggle,
    .pf-toolbox.collapsed .pf-preset-btn,
    .pf-toolbox.collapsed .pf-toolbox-divider,
    .pf-toolbox.collapsed .pf-toolbox-section-toggle + div {
        display: none !important;
    }
}

.pf-canvas-toolbar {
    min-height: 44px;
}

.pf-canvas-toolbar input[type="text"] {
    min-width: 190px !important;
    font-weight: 600;
}

.pf-canvas-scroll {
    justify-content: center;
    align-items: flex-start;
    background:
        linear-gradient(90deg, rgba(255,255,255,.025) 1px, transparent 1px),
        linear-gradient(180deg, rgba(255,255,255,.025) 1px, transparent 1px),
        #313244;
    background-size: 24px 24px;
}

.pf-canvas-scroll-inner {
    justify-content: center;
}

.pf-canvas-statusbar {
    flex-shrink: 0;
    min-height: 40px;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 12px;
    background: #181825;
    border-top: 1px solid #313244;
}

.pf-status-group {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.pf-status-label {
    color: #6c7086;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .6px;
}

.pf-status-spacer {
    flex: 1;
}

.pf-canvas-statusbar select {
    background: #313244;
    border: 1px solid #45475a;
    color: #cdd6f4;
    border-radius: 4px;
    min-height: 28px;
    padding: 3px 8px;
    font-size: 12px;
}

.pf-zoom-control {
    min-width: 260px;
}

.pf-zoom-control .material-icons {
    font-size: 16px;
    color: #a6adc8;
}

.pf-zoom-control input[type="range"] {
    width: 150px;
    accent-color: #89b4fa;
}

.pf-zoom-value {
    min-width: 44px;
    color: #cdd6f4;
    font-size: 12px;
    text-align: center;
}

@media (max-width: 860px) {
    .pf-canvas-scroll {
        justify-content: flex-start;
    }

    .pf-canvas-scroll-inner {
        justify-content: flex-start;
    }

    .pf-canvas-statusbar {
        min-height: 42px;
        padding: 6px 8px;
        gap: 8px;
        overflow-x: auto;
    }

    .pf-status-spacer {
        flex: 0;
    }

    .pf-zoom-control {
        min-width: 210px;
    }

    .pf-zoom-control input[type="range"] {
        width: 120px;
    }
}

@media (max-width: 520px) {
    .pf-canvas-toolbar input[type="text"] {
        min-width: 140px !important;
    }

    .pf-canvas-statusbar {
        justify-content: space-between;
    }

    .pf-status-label {
        display: none;
    }

    .pf-zoom-control {
        min-width: 180px;
    }

    .pf-zoom-control input[type="range"] {
        width: 96px;
    }
}

/* Usability pass: clearer controls, touch targets, responsive editor shell */
.pf-designer {
    min-width: 0;
    min-height: 0;
    height: 100dvh;
    overflow: hidden;
}

.pf-canvas-area,
.pf-toolbox,
.pf-properties {
    min-width: 0;
    min-height: 0;
}

.pf-toolbox,
.pf-properties,
.pf-canvas-scroll {
    scrollbar-width: thin;
    scrollbar-color: #6c7086 #181825;
}

.pf-canvas-toolbar {
    flex-shrink: 0;
}

.pf-canvas-toolbar > * {
    flex-shrink: 0;
}

.pf-canvas-scroll {
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    touch-action: pan-x pan-y;
}

.pf-element,
.pf-handle {
    touch-action: none;
}

.pf-toolbox-btn,
.pf-preset-btn,
.pf-prop-btn,
.pf-canvas-toolbar button,
.pf-canvas-toolbar select,
.pf-canvas-toolbar input[type="text"],
.pf-prop-row input:not([type=checkbox]):not([type=range]),
.pf-prop-row select,
.pf-prop-row textarea,
.pf-prop-row-inline input:not([type=checkbox]):not([type=range]),
.pf-prop-row-inline select,
.pf-prop-row-inline textarea {
    min-height: 32px;
}

.pf-toolbox-btn .material-icons.icon {
    font-size: 18px;
    line-height: 1;
    color: #89b4fa;
}

.pf-prop-row input[type="color"],
.pf-prop-row-inline input[type="color"],
.pf-toolbox input[type="color"] {
    appearance: none;
    -webkit-appearance: none;
    min-height: 28px !important;
    width: 42px !important;
    min-width: 42px !important;
    flex: 0 0 42px !important;
    padding: 2px !important;
    border: 1px solid #45475a !important;
    border-radius: 5px !important;
    background: #11111b !important;
    cursor: pointer;
}

.pf-prop-row input[type="color"]::-webkit-color-swatch-wrapper,
.pf-prop-row-inline input[type="color"]::-webkit-color-swatch-wrapper,
.pf-toolbox input[type="color"]::-webkit-color-swatch-wrapper {
    padding: 0;
}

.pf-prop-row input[type="color"]::-webkit-color-swatch,
.pf-prop-row-inline input[type="color"]::-webkit-color-swatch,
.pf-toolbox input[type="color"]::-webkit-color-swatch {
    border: 1px solid #6c7086;
    border-radius: 4px;
}

.pf-prop-row input[type="color"]::-moz-color-swatch,
.pf-prop-row-inline input[type="color"]::-moz-color-swatch,
.pf-toolbox input[type="color"]::-moz-color-swatch {
    border: 1px solid #6c7086;
    border-radius: 4px;
}

.pf-prop-row input[type="color"]:disabled,
.pf-prop-row-inline input[type="color"]:disabled,
.pf-toolbox input[type="color"]:disabled {
    opacity: .55;
    cursor: not-allowed;
}

.pf-prop-checkbox {
    min-height: 28px;
}

.pf-prop-checkbox input[type=checkbox] {
    min-width: 16px;
    min-height: 16px;
}

.pf-align-btn,
.pf-style-btn,
.pf-layer-btn {
    min-height: 28px;
}

.pf-properties {
    width: 252px;
    min-width: 252px;
}

.pf-properties .pf-prop-header {
    padding: 8px 12px;
}

.pf-properties .pf-prop-section {
    padding: 7px 12px 2px;
    font-size: 9px;
}

.pf-properties .pf-prop-row {
    padding: 3px 12px;
    gap: 1px;
}

.pf-properties .pf-prop-row-inline {
    gap: 6px;
    padding: 3px 12px;
}

.pf-properties .pf-prop-row-inline > * {
    min-width: 0;
}

.pf-properties .pf-prop-row label,
.pf-properties .pf-prop-row-inline label {
    font-size: 10px;
}

.pf-properties .pf-prop-row input:not([type=checkbox]):not([type=range]):not([type=color]),
.pf-properties .pf-prop-row select,
.pf-properties .pf-prop-row-inline input:not([type=checkbox]):not([type=range]):not([type=color]),
.pf-properties .pf-prop-row-inline select {
    min-height: 28px;
    padding: 3px 6px !important;
}

.pf-properties .pf-prop-row textarea,
.pf-properties .pf-prop-row-inline textarea {
    min-height: 40px;
    padding: 4px 6px !important;
}

.pf-properties .pf-prop-checkbox {
    min-height: 24px;
    gap: 5px;
}

.pf-properties .pf-prop-checkbox label {
    font-size: 10px;
}

.pf-properties .pf-align-btn,
.pf-properties .pf-style-btn,
.pf-properties .pf-layer-btn {
    min-height: 26px;
}

.pf-properties .pf-prop-btn {
    margin: 4px 12px;
    padding: 5px 8px;
}

.pf-properties input[type="range"] {
    height: 22px;
}

.pf-color-control {
    display: flex;
    align-items: center;
    gap: 5px;
    min-height: 28px;
}

.pf-color-control .pf-prop-checkbox {
    padding: 0;
    margin: 0;
    min-height: 22px;
    gap: 4px;
}

.pf-color-control .pf-prop-checkbox label {
    font-size: 9px;
    line-height: 1;
    white-space: nowrap;
    cursor: pointer;
}

.pf-compact-color-row {
    align-items: flex-end;
}

@media (max-width: 1180px) {
    .pf-toolbox {
        width: 176px;
        min-width: 176px;
    }

    .pf-properties {
        width: 248px;
        min-width: 248px;
    }

    .pf-canvas-scroll {
        padding: 20px;
    }
}

@media (max-width: 860px) {
    .pf-designer {
        flex-direction: column;
        height: 100dvh;
    }

    .pf-toolbox {
        order: 1;
        width: 100%;
        min-width: 0;
        max-height: 24dvh;
        border-right: 0;
        border-bottom: 1px solid #313244;
        display: block;
        overflow: auto;
    }

    .pf-canvas-area {
        order: 2;
        flex: 1 1 auto;
        min-height: 34dvh;
        overflow: hidden;
    }

    .pf-properties {
        order: 3;
        width: 100%;
        min-width: 0;
        max-height: 36dvh;
        border-left: 0;
        border-top: 1px solid #313244;
        box-shadow: 0 -8px 24px rgba(0,0,0,.22);
    }

    .pf-canvas-toolbar {
        gap: 6px;
        padding: 6px 8px;
        overflow-x: auto;
        overflow-y: hidden;
        flex-wrap: nowrap;
    }

    .pf-canvas-toolbar input[type="text"] {
        width: 150px !important;
    }

    .pf-canvas-toolbar select {
        max-width: 170px;
    }

    .pf-canvas-toolbar span {
        white-space: nowrap;
    }

    .pf-toolbox-section {
        padding: 7px 10px 3px;
    }

    .pf-toolbox-btn {
        width: auto;
        min-width: 112px;
        display: inline-flex;
        margin: 4px 2px;
        padding: 8px 10px;
        vertical-align: top;
    }

    .pf-toolbox-divider {
        margin: 4px 0;
    }

    .pf-preset-btn {
        display: inline-flex;
        align-items: center;
        width: auto;
        min-width: 118px;
        min-height: 32px;
        margin: 3px 2px;
        padding: 6px 10px;
    }

    .pf-canvas-scroll {
        padding: 12px;
    }

    .pf-canvas-scroll-inner {
        min-width: max-content;
        min-height: max-content;
        padding: 8px;
    }

    .pf-ruler-corner,
    .pf-ruler-horizontal,
    .pf-ruler-vertical {
        position: relative !important;
    }

    .pf-prop-header {
        position: sticky;
        top: 0;
        z-index: 2;
    }

    .pf-prop-row,
    .pf-prop-row-inline {
        padding-left: 10px;
        padding-right: 10px;
    }

    .pf-prop-row-inline {
        gap: 8px;
    }

    .pf-preview-header {
        align-items: flex-start;
        flex-direction: column;
    }

    .pf-preview-actions {
        width: 100%;
        justify-content: flex-start;
    }
}

@media (max-width: 520px) {
    .pf-toolbox {
        max-height: 22dvh;
    }

    .pf-properties {
        max-height: 40dvh;
    }

    .pf-canvas-toolbar {
        font-size: 12px;
    }

    .pf-canvas-toolbar button {
        padding: 5px 9px;
    }

    .pf-prop-row-inline {
        flex-direction: column;
    }

    .pf-prop-row input:not([type=checkbox]):not([type=range]):not([type=color]),
    .pf-prop-row select,
    .pf-prop-row textarea,
    .pf-prop-row-inline input:not([type=checkbox]):not([type=range]):not([type=color]),
    .pf-prop-row-inline select,
    .pf-prop-row-inline textarea {
        font-size: 14px !important;
        min-height: 36px;
    }

    .pf-handle {
        width: 14px;
        height: 14px;
    }

    .pf-handle.nw { top:-7px; left:-7px; }
    .pf-handle.n  { top:-7px; left:calc(50% - 7px); }
    .pf-handle.ne { top:-7px; right:-7px; }
    .pf-handle.w  { top:calc(50% - 7px); left:-7px; }
    .pf-handle.e  { top:calc(50% - 7px); right:-7px; }
    .pf-handle.sw { bottom:-7px; left:-7px; }
    .pf-handle.s  { bottom:-7px; left:calc(50% - 7px); }
    .pf-handle.se { bottom:-7px; right:-7px; }

    .pf-preview-zoom {
        width: 100%;
        box-sizing: border-box;
    }

    .pf-preview-zoom input[type="range"] {
        flex: 1;
        width: auto;
    }
}

/* Manual toolbox collapse wins over width-specific responsive rules. */
@media (min-width: 861px) {
    .pf-toolbox.expanded {
        width: 224px;
        min-width: 224px;
    }

    .pf-toolbox.collapsed {
        width: 76px;
        min-width: 76px;
    }
}

@media (max-width: 860px) {
    .pf-toolbox.collapsed {
        max-height: 48px;
        overflow: hidden;
    }

    .pf-toolbox.collapsed .pf-toolbox-header {
        border-bottom: 0;
    }
}
