/*
 * Quick Print v2 — mobile-first, enterprise look.
 *
 * Written as a small token set plus flat component rules rather than piling
 * utility classes into the markup. The old page's styling lived in a <style>
 * block inside the template and grew per-tab overrides; keeping it here means
 * the HTML stays readable and the browser can cache it.
 *
 * Phone is the default; anything wider is a progressive enhancement, because
 * the customer scanning a counter QR is on a phone essentially every time.
 */

/* Design tokens live on :root, not on .qp.

   The crop editor, the confirm screen, the collage and the result screen
   are all rendered outside <main class="qp"> - they are full-screen
   overlays - so scoping the tokens to .qp left every var() inside them
   undefined. The most visible consequence: .qp-btn-primary got no
   background at all, so white text sat on a white card and the button was
   simply invisible. */
:root {
    --ink: #0f172a;
    --ink-2: #334155;
    --muted: #64748b;
    --line: #e2e8f0;
    --line-soft: #eef2f7;
    --surface: #ffffff;
    --bg: #f4f6fa;
    --brand: #1d3557;
    --brand-2: #457b9d;
    --ok: #15803d;
    --ok-bg: #dcfce7;
    --warn: #b45309;
    --warn-bg: #fef3c7;
    --danger: #b91c1c;
    --danger-bg: #fee2e2;
    --radius: 14px;
    --radius-sm: 10px;
    --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 8px 24px rgba(15, 23, 42, .06);

}

.qp {
    max-width: 780px;
    margin: 0 auto;
    padding: 16px 14px 96px;
    color: var(--ink-2);
    font-size: 15px;
    -webkit-tap-highlight-color: transparent;
}

/* ── Header ─────────────────────────────────────────────────── */

.qp-head {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    margin-bottom: 14px;
}

.qp-head h1 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--ink);
    margin: 0;
    letter-spacing: -.01em;
}

.qp-head p {
    margin: 2px 0 0;
    font-size: .85rem;
    color: var(--muted);
}

.qp-head-text { flex: 1 1 auto; min-width: 0; }

.qp-chip {
    flex: 0 0 auto;
    background: var(--ok-bg);
    color: var(--ok);
    font-size: .74rem;
    font-weight: 700;
    padding: 5px 11px;
    border-radius: 999px;
    white-space: nowrap;
}

/* ── Tabs ───────────────────────────────────────────────────── */

.qp-tabs {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 6px;
    margin-bottom: 16px;
}

.qp-tab {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    border: 0;
    background: transparent;
    border-radius: var(--radius-sm);
    padding: 9px 4px;
    color: var(--muted);
    font-size: .7rem;
    font-weight: 600;
    line-height: 1.15;
    cursor: pointer;
    transition: background .15s, color .15s;
}

.qp-tab i { font-size: 1.15rem; }
.qp-tab:hover { background: var(--line-soft); color: var(--ink-2); }

.qp-tab.is-active {
    background: var(--brand);
    color: #fff;
}

/* ── Cards ──────────────────────────────────────────────────── */

.qp-card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 16px;
    margin-bottom: 14px;
}

.qp-card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 4px;
}

.qp-card-head h2 {
    font-size: .95rem;
    font-weight: 700;
    color: var(--ink);
    margin: 0;
}

.qp-count {
    display: inline-block;
    min-width: 22px;
    text-align: center;
    background: var(--line-soft);
    color: var(--muted);
    border-radius: 999px;
    font-size: .74rem;
    padding: 1px 8px;
    margin-left: 4px;
}

.qp-optional {
    font-weight: 500;
    font-size: .72rem;
    color: var(--muted);
    background: var(--line-soft);
    border-radius: 999px;
    padding: 2px 8px;
    margin-left: 6px;
}

.qp-hint {
    font-size: .78rem;
    color: var(--muted);
    margin: 6px 0 0;
    line-height: 1.45;
}

/* ── Drop / empty state ─────────────────────────────────────── */

.qp-drop {
    background: var(--surface);
    border: 2px dashed var(--line);
    border-radius: var(--radius);
    padding: 34px 20px 26px;
    text-align: center;
    transition: border-color .15s, background .15s;
}

.qp-drop.is-over {
    border-color: var(--brand-2);
    background: #f8fbff;
}

.qp-drop > i {
    font-size: 2.4rem;
    color: var(--brand-2);
    display: block;
    margin-bottom: 8px;
}

.qp-drop h2 {
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--ink);
    margin: 0 0 4px;
}

.qp-drop p {
    font-size: .85rem;
    color: var(--muted);
    margin: 0 auto;
    max-width: 34ch;
}

.qp-drop-actions {
    display: flex;
    gap: 10px;
    justify-content: center;
    margin: 18px 0 4px;
    flex-wrap: wrap;
}

/* ── Buttons ────────────────────────────────────────────────── */

.qp-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    padding: 11px 18px;
    font-size: .88rem;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: background .15s, border-color .15s, opacity .15s;
    min-height: 44px;            /* comfortable touch target */
}

.qp-btn-primary { background: var(--brand); color: #fff; }
.qp-btn-primary:hover { background: #24446e; }
.qp-btn-primary:active { background: #16283f; }

.qp-btn-outline { background: #fff; border-color: var(--line); color: var(--ink-2); }
.qp-btn-outline:hover { background: #f8fafc; border-color: #94a3b8; }

.qp-btn-ghost { background: transparent; color: var(--brand-2); padding: 8px 12px; min-height: 38px; }
.qp-btn-ghost:hover { background: var(--line-soft); }

.qp-btn-sm { padding: 8px 14px; min-height: 38px; font-size: .82rem; }

.qp-btn[disabled] { opacity: .5; cursor: not-allowed; }

.qp-icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: 0;
    border-radius: 10px;
    background: transparent;
    color: inherit;
    font-size: 1.05rem;
    cursor: pointer;
}
.qp-icon-btn:hover { background: rgba(148, 163, 184, .18); }

/* ── Upload progress ────────────────────────────────────────── */

.qp-upload-top {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    font-size: .84rem;
    margin-bottom: 8px;
}

.qp-upload-detail { color: var(--muted); font-size: .78rem; }

.qp-bar {
    height: 8px;
    background: var(--line-soft);
    border-radius: 999px;
    overflow: hidden;
}

.qp-bar-fill {
    height: 100%;
    width: 0;
    background: linear-gradient(90deg, var(--brand-2), var(--brand));
    border-radius: 999px;
    transition: width .18s ease-out;
}

/* ── Page list ──────────────────────────────────────────────── */

.qp-pages {
    list-style: none;
    margin: 12px 0 0;
    padding: 0;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
    gap: 10px;
}

.qp-page {
    position: relative;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: #fff;
    overflow: hidden;
    aspect-ratio: 3 / 4;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: grab;
    touch-action: manipulation;
}

.qp-page.is-dragging { opacity: .45; }
.qp-page.is-target { outline: 2px solid var(--brand-2); outline-offset: 1px; }

.qp-page img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    background: var(--line-soft);
}

.qp-page-num {
    position: absolute;
    top: 5px;
    left: 5px;
    background: rgba(15, 23, 42, .78);
    color: #fff;
    font-size: .68rem;
    font-weight: 700;
    border-radius: 6px;
    padding: 1px 6px;
}

.qp-page-kind {
    position: absolute;
    top: 5px;
    right: 5px;
    background: rgba(255, 255, 255, .92);
    color: var(--muted);
    font-size: .62rem;
    font-weight: 700;
    border-radius: 6px;
    padding: 1px 5px;
    text-transform: uppercase;
    letter-spacing: .03em;
}

.qp-page-tools {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    background: linear-gradient(transparent, rgba(15, 23, 42, .72));
    padding: 14px 4px 4px;
    gap: 2px;
}

.qp-page-tools button {
    flex: 1 1 0;
    border: 0;
    background: transparent;
    color: #fff;
    font-size: .82rem;
    padding: 5px 0;
    border-radius: 6px;
    cursor: pointer;
}
.qp-page-tools button:hover { background: rgba(255, 255, 255, .2); }

.qp-page-skel {
    width: 100%;
    height: 100%;
    background: linear-gradient(100deg, #eef2f7 30%, #f8fafc 50%, #eef2f7 70%);
    background-size: 200% 100%;
    animation: qp-shimmer 1.1s linear infinite;
}

@keyframes qp-shimmer {
    from { background-position: 150% 0; }
    to { background-position: -50% 0; }
}

/* ── Fields ─────────────────────────────────────────────────── */

.qp-fields {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 12px;
    margin-top: 12px;
}

.qp-field { display: flex; flex-direction: column; gap: 5px; }

.qp-field > span {
    font-size: .76rem;
    font-weight: 600;
    color: var(--muted);
}

.qp-field select,
.qp-field input {
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    padding: 11px 12px;
    font-size: .92rem;
    color: var(--ink-2);
    background: #fff;
    min-height: 44px;
    font-family: inherit;
}

.qp-field select:focus,
.qp-field input:focus {
    outline: none;
    border-color: var(--brand-2);
    box-shadow: 0 0 0 3px rgba(69, 123, 157, .14);
}

/* ── Summary ────────────────────────────────────────────────── */

.qp-quote {
    background: var(--line-soft);
    border-radius: var(--radius-sm);
    padding: 12px 14px;
    font-size: .88rem;
    color: var(--ink-2);
    line-height: 1.5;
}

.qp-quote b { color: var(--ink); }

.qp-quote-total {
    display: block;
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--ink);
    margin-top: 2px;
}

.qp-quote-note { display: block; font-size: .78rem; color: var(--muted); margin-top: 3px; }

.qp-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-top: 12px;
}

.qp-btn-send { grid-column: 1 / -1; }

.qp-wysiwyg { display: flex; align-items: flex-start; gap: 6px; }
.qp-wysiwyg i { color: var(--ok); margin-top: 1px; }

/* ── Toast ──────────────────────────────────────────────────── */

.qp-toast {
    position: fixed;
    left: 50%;
    bottom: 84px;
    transform: translateX(-50%);
    /* Above every overlay (the editor at 1080 is the highest), because a toast
       is almost always reporting on something done INSIDE one. Below them, it
       explained failures to an empty screen behind the crop editor - which read
       as the button simply doing nothing. */
    z-index: 1200;
    max-width: min(92vw, 520px);
    background: var(--ink);
    color: #fff;
    border-radius: 12px;
    padding: 12px 16px;
    font-size: .86rem;
    box-shadow: 0 10px 30px rgba(15, 23, 42, .28);
    display: flex;
    align-items: center;
    gap: 10px;
}

.qp-toast.is-ok { background: var(--ok); }
.qp-toast.is-warn { background: var(--warn); }
.qp-toast.is-error { background: var(--danger); }

.qp-toast button {
    border: 1px solid rgba(255, 255, 255, .5);
    background: transparent;
    color: #fff;
    border-radius: 8px;
    padding: 5px 11px;
    font-size: .8rem;
    font-weight: 600;
    cursor: pointer;
    margin-left: auto;
    white-space: nowrap;
}

/* ── Coming-soon panels ─────────────────────────────────────── */

.qp-soon {
    text-align: center;
    padding: 56px 20px;
    color: var(--muted);
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
}

.qp-soon i { font-size: 2.2rem; color: var(--line); display: block; margin-bottom: 10px; }
.qp-soon h2 { font-size: 1rem; color: var(--ink); margin: 0 0 4px; }
.qp-soon p { margin: 0; font-size: .85rem; }

/* ── Crop editor ────────────────────────────────────────────── */

.qp-editor {
    position: fixed;
    inset: 0;
    z-index: 1080;
    background: #0b1220;
    display: flex;
    flex-direction: column;
    color: #e2e8f0;
}

.qp-editor-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px calc(10px);
    padding-top: calc(10px + env(safe-area-inset-top, 0px));
    background: #0f172a;
    border-bottom: 1px solid rgba(255, 255, 255, .08);
    flex: 0 0 auto;
}

.qp-editor-bar > span {
    flex: 1 1 auto;
    text-align: center;
    font-size: .9rem;
    font-weight: 600;
    color: #fff;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.qp-editor-stage {
    flex: 1 1 auto;
    position: relative;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 10px;
    min-height: 0;
    touch-action: none;          /* corner dragging owns the gesture */
}

.qp-editor-stage canvas {
    max-width: 100%;
    max-height: 100%;
    display: block;
}

.qp-editor-tools {
    flex: 0 0 auto;
    background: #0f172a;
    border-top: 1px solid rgba(255, 255, 255, .08);
    padding: 10px 12px calc(12px + env(safe-area-inset-bottom, 0px));
    display: flex;
    flex-direction: column;
    gap: 9px;
}

.qp-tool-row {
    display: flex;
    gap: 7px;
    overflow-x: auto;
    scrollbar-width: none;
    padding-bottom: 1px;
}
.qp-tool-row::-webkit-scrollbar { display: none; }

.qp-pill {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    border: 1px solid rgba(255, 255, 255, .18);
    background: rgba(255, 255, 255, .06);
    color: #cbd5e1;
    border-radius: 999px;
    padding: 8px 14px;
    font-size: .8rem;
    font-weight: 600;
    cursor: pointer;
    min-height: 38px;
}

.qp-pill:hover { background: rgba(255, 255, 255, .12); color: #fff; }
.qp-pill.is-active { background: var(--brand-2, #457b9d); border-color: transparent; color: #fff; }

.qp-slider {
    display: grid;
    grid-template-columns: 82px 1fr;
    align-items: center;
    gap: 10px;
}

.qp-slider > span { font-size: .76rem; color: #94a3b8; }
.qp-slider input { width: 100%; accent-color: #457b9d; }

/* ── Result screen ──────────────────────────────────────────── */

.qp-result {
    position: fixed;
    inset: 0;
    z-index: 1070;
    background: var(--bg, #f4f6fa);
    overflow-y: auto;
    padding: 20px 14px calc(28px + env(safe-area-inset-bottom, 0px));
}

/* ── Wider screens ──────────────────────────────────────────── */

@media (min-width: 768px) {
    .qp { padding: 26px 20px 40px; }
    .qp-head h1 { font-size: 1.75rem; }
    .qp-tab { flex-direction: row; gap: 7px; font-size: .82rem; padding: 10px 8px; }
    .qp-tab i { font-size: 1rem; }
    .qp-actions { grid-template-columns: auto auto 1fr; }
    .qp-btn-send { grid-column: auto; }
    .qp-pages { grid-template-columns: repeat(auto-fill, minmax(126px, 1fr)); }
    .qp-toast { bottom: 24px; }
}

/* Phones: tabs become a fixed bottom bar, matching how native apps behave. */
@media (max-width: 767.98px) {
    .qp-tabs {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 1030;
        border-radius: 0;
        border-left: 0;
        border-right: 0;
        border-bottom: 0;
        margin: 0;
        padding: 5px 6px calc(5px + env(safe-area-inset-bottom, 0px));
        box-shadow: 0 -2px 14px rgba(15, 23, 42, .1);
    }
}

@media (prefers-reduced-motion: reduce) {
    .qp-page-skel { animation: none; }
    .qp-bar-fill { transition: none; }
}

/* ═══════════════════════════════════════════════════════════════
   Collage editor — Document and PVC Card tabs

   Full-height dark workspace, sheet in the middle, templates and
   tools pinned to the bottom the way a phone editor should be.
   ═══════════════════════════════════════════════════════════════ */

.cl {
    position: fixed;
    inset: 0;
    z-index: 1060;
    display: flex;
    flex-direction: column;
    background: #0b1220;
    color: #e2e8f0;
}

/* ---- top strip: sheet paging ---- */

.cl-top {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 10px 12px;
    padding-top: calc(10px + env(safe-area-inset-top, 0px));
    background: #0f172a;
    border-bottom: 1px solid rgba(255, 255, 255, .08);
}

.cl-nav {
    width: 38px;
    height: 38px;
    border: 1px solid rgba(255, 255, 255, .16);
    background: rgba(255, 255, 255, .06);
    color: #cbd5e1;
    border-radius: 10px;
    font-size: 1.1rem;
    line-height: 1;
    cursor: pointer;
}
.cl-nav:hover { background: rgba(255, 255, 255, .13); color: #fff; }
.cl-danger { border-color: rgba(252, 165, 165, .4); color: #fecaca; }
.cl-danger:hover { background: rgba(220, 38, 38, .22); color: #fff; }

.cl-count {
    font-size: .85rem;
    font-weight: 700;
    min-width: 56px;
    text-align: center;
    color: #fff;
}

.cl-spacer { flex: 1 1 auto; }

/* ---- the sheet ---- */

.cl-stage {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 14px;
    overflow: hidden;
}

.cl-sheet {
    position: relative;
    background: #fff;
    max-width: 100%;
    max-height: 100%;
    /* aspect-ratio is set from the real paper size in JS, so the on-screen
       sheet is the same shape as the paper it will print on. */
    height: 100%;
    box-shadow: 0 10px 40px rgba(0, 0, 0, .5);
    touch-action: none;          /* dragging owns the gesture, not the scroller */
    overflow: hidden;
}

.cl-empty {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 20px;
    color: #94a3b8;
    font-size: .85rem;
}

/* ---- items on the sheet ---- */

.cl-item {
    position: absolute;
    box-sizing: border-box;
    cursor: grab;
    touch-action: none;
}

.cl-item img {
    width: 100%;
    height: 100%;
    object-fit: fill;    /* the server already fitted the aspect; do not re-fit */
    display: block;
    pointer-events: none;
    user-select: none;
}

.cl-item.is-selected {
    outline: 2px solid #2dd4bf;
    outline-offset: 0;
    z-index: 5;
}

.cl-handle {
    position: absolute;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    border: 2px solid #0f172a;
    background: #fff;
    color: #0f172a;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: .8rem;
    cursor: pointer;
    padding: 0;
    box-shadow: 0 2px 6px rgba(0, 0, 0, .3);
}

.cl-handle-del  { top: -15px; left: -15px; background: #fff; color: #0f766e; }
.cl-handle-size { bottom: -15px; right: -15px; background: #2dd4bf; color: #062f2b; cursor: nwse-resize; }

/* ---- item tray ---- */

.cl-tray {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 8px 12px;
    overflow-x: auto;
    background: #0f172a;
    border-top: 1px solid rgba(255, 255, 255, .08);
    scrollbar-width: none;
}
.cl-tray::-webkit-scrollbar { display: none; }
.cl-tray:empty { display: none; }

.cl-tray-label {
    flex: 0 0 auto;
    font-size: .7rem;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: .04em;
    margin-right: 2px;
}

.cl-tray-item {
    flex: 0 0 auto;
    width: 46px;
    height: 46px;
    border: 1px solid rgba(255, 255, 255, .18);
    border-radius: 8px;
    overflow: hidden;
    background: #1e293b;
    padding: 0;
    cursor: pointer;
}
.cl-tray-item:hover { border-color: #2dd4bf; }
.cl-tray-item img { width: 100%; height: 100%; object-fit: cover; display: block; }

/* ---- template strip ---- */

.cl-templates {
    flex: 0 0 auto;
    display: flex;
    gap: 8px;
    padding: 10px 12px;
    overflow-x: auto;
    background: #0f172a;
    border-top: 1px solid rgba(255, 255, 255, .08);
    scrollbar-width: none;
}
.cl-templates::-webkit-scrollbar { display: none; }

.cl-tpl {
    flex: 0 0 auto;
    width: 72px;
    border: 0;
    background: transparent;
    color: #94a3b8;
    font-size: .64rem;
    line-height: 1.2;
    cursor: pointer;
    padding: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.cl-tpl span { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.cl-tpl small { font-size: .58rem; color: #64748b; }
.cl-tpl.is-active { color: #2dd4bf; }
.cl-tpl.is-active small { color: #2dd4bf; }

.cl-tpl-thumb {
    width: 54px;
    height: 68px;
    background: #1e293b;
    border: 1px solid rgba(255, 255, 255, .16);
    border-radius: 5px;
    display: grid;
    gap: 3px;
    padding: 4px;
    box-sizing: border-box;
}

.cl-tpl-thumb i {
    background: #475569;
    border-radius: 2px;
    display: block;
}

/* Named templates show two real-size cards stacked, not a grid. */
.cl-tpl-thumb.is-named {
    grid-template-columns: 1fr;
    grid-template-rows: repeat(2, auto);
    align-content: center;
    gap: 6px;
    padding: 8px 6px;
}
.cl-tpl-thumb.is-named i { height: 16px; }

.cl-tpl.is-active .cl-tpl-thumb { border-color: #2dd4bf; }
.cl-tpl.is-active .cl-tpl-thumb i { background: #2dd4bf; }

/* ---- bottom tool bar ---- */

.cl-bar {
    flex: 0 0 auto;
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: 1fr;
    gap: 4px;
    background: #0f172a;
    border-top: 1px solid rgba(255, 255, 255, .1);
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom, 0px));
}

.cl-tool {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    border: 0;
    background: transparent;
    color: #94a3b8;
    font-size: .66rem;
    font-weight: 600;
    padding: 8px 2px;
    border-radius: 9px;
    cursor: pointer;
}
.cl-tool i { font-size: 1.15rem; }
.cl-tool:hover { background: rgba(255, 255, 255, .07); color: #e2e8f0; }
.cl-tool.is-on { color: #2dd4bf; }

.cl-exit { color: #062f2b; background: #2dd4bf; }
.cl-exit:hover { background: #14b8a6; color: #062f2b; }

@media (min-width: 768px) {
    .cl-tpl { width: 82px; font-size: .7rem; }
    .cl-tpl-thumb { width: 62px; height: 78px; }
    .cl-tool { flex-direction: row; gap: 7px; font-size: .78rem; }
    .cl-bar { grid-auto-columns: auto; justify-content: center; gap: 10px; padding: 8px; }
    .cl-tool { padding: 9px 18px; }
}

/* ═══════════════════════════════════════════════════════════════
   Final preview — the last thing a customer sees before paper
   comes out, so it shows the real composed sheets, full width.
   ═══════════════════════════════════════════════════════════════ */

.qp-confirm {
    position: fixed;
    inset: 0;
    z-index: 1075;
    background: #f4f6fa;
    display: flex;
    flex-direction: column;
}

.qp-confirm-bar {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    padding-top: calc(12px + env(safe-area-inset-top, 0px));
    background: #fff;
    border-bottom: 1px solid #e2e8f0;
}

.qp-confirm-bar > span:first-of-type {
    flex: 1 1 auto;
    font-size: .95rem;
    font-weight: 700;
    color: #0f172a;
}

.qp-confirm-scroll {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    padding: 16px 14px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
}

/* Each sheet on a white card with a shadow, so it reads as paper. */
.qp-confirm-page {
    position: relative;
    width: 100%;
    max-width: 460px;
    background: #fff;
    box-shadow: 0 4px 20px rgba(15, 23, 42, .14);
    border-radius: 4px;
    overflow: hidden;
}

.qp-confirm-page img { width: 100%; display: block; }

.qp-confirm-page-num {
    position: absolute;
    top: 8px;
    left: 8px;
    background: rgba(15, 23, 42, .78);
    color: #fff;
    font-size: .68rem;
    font-weight: 700;
    border-radius: 6px;
    padding: 2px 8px;
}

.qp-confirm-foot {
    flex: 0 0 auto;
    background: #fff;
    border-top: 1px solid #e2e8f0;
    padding: 12px 14px calc(12px + env(safe-area-inset-bottom, 0px));
}

.qp-confirm-info {
    font-size: .84rem;
    color: #334155;
    margin-bottom: 10px;
    line-height: 1.5;
}

.qp-confirm-info b { color: #0f172a; }

.qp-confirm-actions {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 8px;
}

/* The countdown reads as a filling bar rather than a bare number, so it is
   obvious at a glance how long is left to press Cancel. */
.qp-countdown {
    height: 4px;
    background: #e2e8f0;
    border-radius: 999px;
    margin-top: 10px;
    overflow: hidden;
}

.qp-countdown-fill {
    height: 100%;
    width: 100%;
    background: linear-gradient(90deg, #457b9d, #1d3557);
    border-radius: 999px;
    transition: width 1s linear;
}

.qp-countdown.is-done .qp-countdown-fill { background: #15803d; }

/* Cancel sits beside Done: leaving the arrange screen without keeping it. */
.cl-cancel { color: #fca5a5; }
.cl-cancel:hover { background: rgba(220, 38, 38, .18); color: #fff; }

/* ═══════════════════════════════════════════════════════════════
   Photo tab — passport / ID photos
   ═══════════════════════════════════════════════════════════════ */

.ph-modes {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-top: 12px;
}

.ph-mode {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 3px;
    text-align: left;
    border: 1px solid var(--line);
    background: #fff;
    border-radius: var(--radius-sm);
    padding: 13px 14px;
    cursor: pointer;
    transition: border-color .15s, background .15s;
}

.ph-mode i { font-size: 1.2rem; color: var(--brand-2); margin-bottom: 2px; }
.ph-mode strong { font-size: .87rem; color: var(--ink); font-weight: 700; }
.ph-mode small { font-size: .72rem; color: var(--muted); line-height: 1.35; }

.ph-mode:hover { border-color: #94a3b8; background: #f8fafc; }

.ph-mode.is-active {
    border-color: var(--brand);
    background: #f2f6fb;
    box-shadow: inset 0 0 0 1px var(--brand);
}
.ph-mode.is-active i { color: var(--brand); }

.ph-mode[disabled] { opacity: .45; cursor: not-allowed; }

/* ---- photo + tools ---- */

.ph-photo-row {
    display: flex;
    gap: 14px;
    margin-top: 12px;
    align-items: flex-start;
}

.ph-photo {
    flex: 0 0 auto;
    width: 116px;
    aspect-ratio: 35 / 45;          /* the passport proportion, so the crop reads true */
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    overflow: hidden;
    background: var(--line-soft);
    display: flex;
    align-items: center;
    justify-content: center;
}

.ph-photo img { width: 100%; height: 100%; object-fit: cover; display: block; }

.ph-photo-tools {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-width: 0;
}
.ph-photo-tools .qp-btn { width: 100%; justify-content: flex-start; }

/* ---- background swatches ---- */

.ph-bg {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 14px;
    padding-top: 12px;
    border-top: 1px solid var(--line-soft);
    flex-wrap: wrap;
}

.ph-bg-label {
    font-size: .76rem;
    font-weight: 600;
    color: var(--muted);
}

.ph-swatches { display: flex; gap: 8px; flex-wrap: wrap; }

.ph-swatch {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    border: 2px solid var(--line);
    cursor: pointer;
    padding: 0;
    position: relative;
}
.ph-swatch:hover { border-color: #94a3b8; }
.ph-swatch.is-active { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(29, 53, 87, .15); }

.ph-swatch.is-active::after {
    content: "";
    position: absolute;
    inset: 0;
    margin: auto;
    width: 9px; height: 5px;
    border-left: 2px solid #0f172a;
    border-bottom: 2px solid #0f172a;
    transform: rotate(-45deg) translate(1px, -2px);
}
.ph-swatch[data-bg="white"].is-active::after,
.ph-swatch[data-bg="grey"].is-active::after { border-color: #0f172a; }
.ph-swatch[data-bg="blue"].is-active::after,
.ph-swatch[data-bg="red"].is-active::after { border-color: #fff; }

/* ---- sheet preview ---- */

.ph-sheet {
    margin-top: 12px;
    background: var(--line-soft);
    border-radius: var(--radius-sm);
    padding: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 200px;
}

.ph-sheet img {
    max-width: 100%;
    max-height: 420px;
    display: block;
    background: #fff;
    box-shadow: 0 4px 18px rgba(15, 23, 42, .16);
}

@media (max-width: 480px) {
    .ph-modes { grid-template-columns: 1fr; }
    .ph-photo { width: 96px; }
}

/* ── Crop editor: the rendered result, shown in Adjust mode ───────── */

.qp-crop-result {
    max-width: 100%;
    max-height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 120px;
}

.qp-crop-result img {
    max-width: 100%;
    max-height: 100%;
    display: block;
    background: #fff;
    box-shadow: 0 6px 26px rgba(0, 0, 0, .45);
}

/* A settling render should read as "working", not as a blank stage. */
.qp-crop-result.is-loading { opacity: .45; transition: opacity .12s; }

.qp-modes { justify-content: center; }
.qp-modes .qp-pill { min-width: 106px; justify-content: center; }

.qp-editor-hint {
    margin: 8px 0 0;
    font-size: .74rem;
    color: #94a3b8;
    text-align: center;
}

/* The [hidden] attribute must beat our own display rules.

   .qp-editor, .qp-confirm and .cl all set display:flex, and an author
   declaration outranks the UA stylesheet's [hidden]{display:none} however
   specific that is. Without this the crop editor would simply never close —
   Apply and Cancel would run, set hidden, and nothing would appear to happen.
   Bootstrap's reboot happens to carry the same rule, but relying on a
   third-party reset to keep our own overlays closable is not a dependency
   worth having. */
[hidden] { display: none !important; }

.qp-icon-btn[disabled] { opacity: .35; cursor: default; }
.qp-icon-btn[disabled]:hover { background: transparent; }

/* ── Photo tab: busy strip and background controls ─────────────── */

/* One strip for every AI operation. They cannot overlap — the server works on
   a single photo — so a shared indicator is both simpler and more honest than
   a spinner on whichever button was pressed. */
.ph-busy {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 12px;
    padding: 10px 14px;
    background: #fff7ed;
    border: 1px solid #fed7aa;
    border-radius: var(--radius-sm);
    font-size: .84rem;
    color: #9a3412;
}

.ph-busy-dot {
    width: 9px; height: 9px;
    border-radius: 50%;
    background: #f97316;
    animation: ph-pulse 1s ease-in-out infinite;
    flex: 0 0 auto;
}

.ph-busy-time { margin-left: auto; font-variant-numeric: tabular-nums; font-weight: 700; }

@keyframes ph-pulse { 0%,100% { opacity: 1; } 50% { opacity: .25; } }

/* While an operation runs every other control is disabled, so a second
   request cannot be queued behind one that already takes most of a minute. */
.ph-op[disabled] { opacity: .45; cursor: not-allowed; }

.ph-bg-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    width: 100%;
}

.ph-bg-custom {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    width: 100%;
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--line-soft);
}

.ph-bg-custom-label { font-size: .76rem; color: var(--muted); font-weight: 600; }

#phBgColor {
    width: 44px; height: 34px;
    padding: 2px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    cursor: pointer;
}

#phBgHex {
    width: 96px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 7px 10px;
    font-family: "Consolas", monospace;
    font-size: .82rem;
    text-transform: lowercase;
}
#phBgHex:focus { outline: none; border-color: var(--brand-2); }
#phBgHex.is-invalid { border-color: var(--danger); background: #fef2f2; }

.ph-bg-file {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    margin-top: 10px;
    font-size: .8rem;
    color: var(--ink-2);
}

.ph-bg-file img {
    width: 44px; height: 44px;
    object-fit: cover;
    border-radius: 8px;
    border: 1px solid var(--line);
}

.ph-bg-file span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }


/* PVC Card tab */

.pv-sides {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 12px;
    margin-top: 12px;
}

.pv-side {
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    overflow: hidden;
    background: #fff;
}

/* Card proportion, so a badly-detected crop is obvious at a glance rather
   than only once the sheet has been printed and cut. */
.pv-side-img {
    aspect-ratio: 85.6 / 54;
    background: var(--line-soft);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.pv-side-img img { width: 100%; height: 100%; object-fit: cover; display: block; }

.pv-side-bar {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 7px 8px;
    border-top: 1px solid var(--line-soft);
}

.pv-side-name {
    font-size: .74rem;
    font-weight: 700;
    color: var(--ink-2);
    margin-right: auto;
}

.pv-side-bar button {
    border: 0;
    background: transparent;
    color: var(--muted);
    font-size: .9rem;
    padding: 4px 6px;
    border-radius: 6px;
    cursor: pointer;
}
.pv-side-bar button:hover { background: var(--line-soft); color: var(--ink); }
.pv-side-bar button[disabled] { opacity: .4; cursor: not-allowed; }

.pv-badge {
    font-size: .6rem;
    font-weight: 700;
    padding: 1px 6px;
    border-radius: 999px;
    text-transform: uppercase;
    letter-spacing: .03em;
}
.pv-badge-auto { background: var(--ok-bg); color: var(--ok); }
.pv-badge-manual { background: var(--warn-bg); color: var(--warn); }

.pv-sheet {
    margin-top: 14px;
    background: var(--line-soft);
    border-radius: var(--radius-sm);
    padding: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 220px;
}

.pv-sheet img {
    max-width: 100%;
    max-height: 460px;
    background: #fff;
    box-shadow: 0 4px 18px rgba(15, 23, 42, .16);
    display: block;
}

.pv-op[disabled] { opacity: .45; cursor: not-allowed; }

/* Crop editor: page-shape selector sits in the slider grid so the whole
   control column lines up. */
.qp-slider-select select {
    grid-column: 2 / -1;
    background: rgba(255, 255, 255, .08);
    border: 1px solid rgba(255, 255, 255, .18);
    color: #e2e8f0;
    border-radius: 8px;
    padding: 7px 10px;
    font-size: .8rem;
    width: 100%;
}
.qp-slider-select select option { background: #0f172a; color: #e2e8f0; }

.qp-slider output {
    font-size: .74rem;
    color: #94a3b8;
    min-width: 34px;
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.qp-slider { grid-template-columns: 82px 1fr auto; }

.qp-tool-sep {
    width: 1px;
    align-self: stretch;
    background: rgba(255, 255, 255, .16);
    margin: 2px 4px;
    flex: 0 0 auto;
}


/* ═══════════════════════════════════════════════════════════════
   Result screen — the last thing a customer sees
   ═══════════════════════════════════════════════════════════════ */

.qp-done {
    max-width: 460px;
    margin: 32px auto;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 32px 26px 26px;
    text-align: center;
}

.qp-done-mark {
    width: 62px;
    height: 62px;
    margin: 0 auto 16px;
    border-radius: 50%;
    background: var(--ok-bg);
    color: var(--ok);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
}

.qp-done h2 {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--ink);
    margin: 0 0 4px;
}

.qp-done-sub {
    font-size: .85rem;
    color: var(--muted);
    margin: 0 auto 20px;
    max-width: 32ch;
    line-height: 1.5;
}

/* The token is the biggest thing here on purpose: it is the one piece a
   person has to read out or show at a counter, often across it, often on a
   cracked screen. */
.qp-done-token {
    background: var(--line-soft);
    border: 1px dashed var(--line);
    border-radius: var(--radius-sm);
    padding: 14px 16px;
    margin-bottom: 14px;
}

.qp-done-token-label {
    display: block;
    font-size: .68rem;
    font-weight: 700;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--muted);
    margin-bottom: 4px;
}

.qp-done-token strong {
    display: block;
    font-size: 1.7rem;
    font-weight: 700;
    color: var(--brand);
    letter-spacing: .02em;
    font-variant-numeric: tabular-nums;
    word-break: break-all;
}

.qp-done-pay {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    font-size: .85rem;
    font-weight: 600;
    padding: 8px 14px;
    border-radius: 999px;
    margin-bottom: 18px;
}
.qp-done-pay.is-paid { background: var(--ok-bg); color: var(--ok); }
.qp-done-pay.is-due { background: var(--warn-bg); color: var(--warn); }

.qp-done-actions {
    display: grid;
    grid-template-columns: 1fr;
    gap: 9px;
}

.qp-done-actions .qp-btn { width: 100%; }

.qp-done-note {
    font-size: .76rem;
    color: var(--muted);
    margin: 16px 0 0;
}

@media (min-width: 520px) {
    .qp-done-actions { grid-template-columns: 1fr 1fr; }
}

/* ── Full Page tab ───────────────────────────────────────────────── */

.fp-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 12px;
}

.fp-edge {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-top: 14px;
}

.fp-edge-opt {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 3px;
    text-align: left;
    border: 1px solid var(--line);
    background: #fff;
    border-radius: var(--radius-sm);
    padding: 13px 14px;
    cursor: pointer;
    transition: border-color .15s, background .15s;
}

.fp-edge-opt i { font-size: 1.2rem; color: var(--brand-2); margin-bottom: 2px; }
.fp-edge-opt strong { font-size: .87rem; color: var(--ink); font-weight: 700; }
.fp-edge-opt small { font-size: .72rem; color: var(--muted); line-height: 1.35; }

.fp-edge-opt:hover { border-color: #94a3b8; background: #f8fafc; }

.fp-edge-opt.is-active {
    border-color: var(--brand);
    background: #f2f6fb;
    box-shadow: inset 0 0 0 1px var(--brand);
}
.fp-edge-opt.is-active i { color: var(--brand); }

.fp-margin {
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 12px;
    margin-top: 16px;
}

.fp-margin label { font-size: .8rem; color: var(--muted); }
.fp-margin input[type="range"] { width: 100%; }
.fp-margin-out { font-size: .82rem; color: var(--ink); font-weight: 600; min-width: 52px; text-align: right; }

/* Borderless leaves the control in place but inert, so the customer's own
   number is still there when they switch back. */
.fp-margin.is-off { opacity: .45; }
.fp-margin.is-off input[type="range"] { cursor: not-allowed; }

.fp-sheet {
    margin-top: 12px;
    background: var(--line-soft);
    border-radius: var(--radius-sm);
    padding: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 220px;
}

.fp-sheet img {
    max-width: 100%;
    max-height: 460px;
    display: block;
    background: #fff;
    box-shadow: 0 4px 18px rgba(15, 23, 42, .16);
}

@media (max-width: 480px) {
    .fp-edge { grid-template-columns: 1fr; }
    .fp-margin { grid-template-columns: 1fr; gap: 6px; }
    .fp-margin-out { text-align: left; }
}

/* ── Opened without a shop's QR code ─────────────────────────────── */

.qp-noshop {
    display: flex;
    gap: 12px;
    align-items: flex-start;
    margin: 0 0 14px;
    padding: 14px 16px;
    border-radius: var(--radius-sm);
    background: #fff8e6;
    border: 1px solid #f2d492;
    color: #6b4c07;
}

.qp-noshop i { font-size: 1.25rem; color: #d99000; line-height: 1.2; }
.qp-noshop strong { display: block; font-size: .9rem; font-weight: 700; margin-bottom: 2px; }
.qp-noshop p { margin: 0; font-size: .8rem; line-height: 1.45; }

/* With Send disabled, Download is the only action that finishes the job, so it
   stops sitting in a half-width slot next to a button nobody can press. */
.qp-actions.is-download-only { grid-template-columns: 1fr; }

/* ── Photo tab: print queue + custom size + sheet sliders ────────── */

.ph-custom { display: flex; align-items: center; gap: 6px; }
.ph-custom input { width: 68px; }
.ph-custom span { color: var(--muted); font-size: .82rem; }

.ph-queue { display: flex; flex-direction: column; gap: 9px; margin-top: 12px; }

.ph-queue-item {
    display: grid;
    grid-template-columns: 44px 1fr auto auto;
    align-items: center;
    gap: 12px;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    padding: 9px 11px;
}

.ph-queue-thumb {
    width: 44px; height: 54px;
    object-fit: cover;
    border-radius: 6px;
    background: var(--line-soft);
    border: 1px solid var(--line);
}

.ph-queue-info { min-width: 0; }
.ph-queue-info strong { display: block; font-size: .86rem; }
.ph-queue-info small { color: var(--muted); font-size: .74rem; }

.ph-queue-copies { display: flex; align-items: center; gap: 8px; }
.ph-queue-copies b { min-width: 18px; text-align: center; font-size: .9rem; }
.ph-queue-del { color: var(--danger); }

/* The queue steppers are icon-sized buttons even on the shared .qp-btn-sm */
.ph-queue-copies .qp-btn-sm { padding: 5px 10px; }

@media (max-width: 480px) {
    .ph-queue-item { grid-template-columns: 40px 1fr auto; row-gap: 6px; }
    .ph-queue-del { grid-column: 3; grid-row: 1; }
    .ph-queue-copies { grid-column: 2 / 4; justify-content: flex-start; }
}

