/**
 * Crop & edit panel. Shares the tokens defined by photo-print-crop-editor.css
 * (the MagicPath palette, Task 9): the design's selected-photo panel, with
 * gold-edged option cards, small uppercase group labels and ink buttons.
 * Desktop: preview left, controls right. Phone: stacked, controls scroll,
 * actions pinned so Save is always reachable.
 */

.ppce-editor {
    position: fixed;
    inset: 0;
    /* Above the site's phone bottom nav (999990), category drawer (9999999)
       and the chat buttons, which otherwise cover Save. */
    z-index: 10000000;
    display: flex;
    align-items: stretch;
    justify-content: center;
    background: rgba(12, 10, 9, .65);
    --ppe-ink: var(--ppce-stone-900, #1c1917);
    --ppe-muted: var(--ppce-stone-600, #57534e);
    --ppe-line: var(--ppce-stone-200, #e7e5e4);
    --ppe-quiet: var(--ppce-stone-100, #f5f5f4);
    --ppe-accent: var(--ppce-gold-line, #a2814b);
    --ppe-on: var(--ppce-paper, #f6f1e7);
}

@supports ((-webkit-backdrop-filter: blur(4px)) or (backdrop-filter: blur(4px))) {
    .ppce-editor { -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px); }
}

.ppce-editor[x-cloak] { display: none !important; }

.ppce-editor__sheet {
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 1180px;
    margin: auto;
    max-height: 100%;
    background: var(--ppce-shell, #faf9f6);
    border-radius: 28px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, .25);
    overflow: hidden;
}

@media (min-width: 640px) {
    .ppce-editor { padding: 20px; }
}

/* ---------- header ---------- */

.ppce-editor__head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    padding: 16px 20px;
    border-bottom: 1px solid var(--ppe-line);
    background: #fff;
}

.ppce-editor__title { margin: 2px 0 0; font-size: 18px; font-weight: 600; letter-spacing: -.01em; color: var(--ppe-ink); }

.ppce-editor__sub {
    margin: 3px 0 0;
    font-size: 13px;
    color: var(--ppe-muted);
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: baseline;
}

.ppce-editor__count { font-weight: 600; color: var(--ppe-ink); }

.ppce-editor__close {
    width: 44px; height: 44px; flex: 0 0 44px;
    border: 1px solid var(--ppe-line); border-radius: 9999px; background: #fff;
    font-size: 22px; line-height: 1; color: var(--ppe-muted); cursor: pointer;
}
.ppce-editor__close:hover { background: var(--ppe-quiet); color: var(--ppe-ink); }

/* ---------- body ---------- */

.ppce-editor__body {
    display: grid;
    grid-template-columns: 1fr;
    min-height: 0;
    overflow: hidden;
}

@media (min-width: 960px) {
    .ppce-editor__body { grid-template-columns: minmax(0, 1fr) 340px; }
}

/* ---------- preview ---------- */

.ppce-editor__stage {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    gap: 12px;
    padding: 20px;
    background: var(--ppe-quiet);
    min-height: 0;
    overflow-y: auto;
}

@media (min-width: 960px) {
    /* `safe` keeps the top reachable if the column ever overflows. */
    .ppce-editor__stage { justify-content: center; }
    @supports (justify-content: safe center) {
        .ppce-editor__stage { justify-content: safe center; }
    }
}

.ppce-stage__frame {
    position: relative;
    display: inline-block;
    max-width: 100%;
    border: 5px solid #fff;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, .1), 0 4px 6px -4px rgba(0, 0, 0, .1);
    background: #fff;
}

.ppce-stage__canvas {
    display: block;
    max-width: 100%;
    max-height: 52vh;
    height: auto;
}

/* Drag to move. touch-action stops the page scrolling under the finger. */
.ppce-stage__frame.is-pannable { cursor: grab; touch-action: none; user-select: none; }
.ppce-stage__frame.is-panning { cursor: grabbing; }
.ppce-stage__drag-hint { margin: 10px 0 0; font-size: 13px; font-weight: 600; color: #6b5a3a; }

/* rule-of-thirds guides */
.ppce-stage__thirds { position: absolute; inset: 0; pointer-events: none; }
.ppce-stage__thirds span { position: absolute; background: rgba(255, 255, 255, .55); }
.ppce-stage__thirds span:nth-child(1) { left: 33.333%; top: 0; bottom: 0; width: 1px; }
.ppce-stage__thirds span:nth-child(2) { left: 66.666%; top: 0; bottom: 0; width: 1px; }
.ppce-stage__thirds span:nth-child(3) { top: 33.333%; left: 0; right: 0; height: 1px; }
.ppce-stage__thirds span:nth-child(4) { top: 66.666%; left: 0; right: 0; height: 1px; }

/* anything outside this line can be trimmed in finishing */
.ppce-stage__trim {
    position: absolute;
    border: 1px dashed rgba(255, 255, 255, .95);
    box-shadow: 0 0 0 1px rgba(0, 0, 0, .4), inset 0 0 0 1px rgba(0, 0, 0, .4);
    pointer-events: none;
}

.ppce-stage__quality {
    margin: 0;
    max-width: 560px;
    text-align: center;
    font-size: 13px;
    line-height: 1.5;
    color: var(--ppe-muted);
}
.ppce-stage__quality .ppce-pill { margin-bottom: 6px; }
.ppce-stage__quality strong { display: block; font-size: 14px; font-weight: 600; color: var(--ppe-ink); }

.ppce-stage__guide { font-size: 13px; color: var(--ppe-muted); }

.ppce-stage__info { display: flex; flex-direction: column; align-items: center; gap: 12px; }

/* Phone-only resolution warning (the full quality block is hidden there). */
.ppce-stage__warn {
    display: none;
    align-items: center;
    gap: 8px;
    margin: 0;
    font-size: 12px;
    font-weight: 600;
    color: var(--ppe-muted);
}

.ppce-stage__trimnote {
    margin: -4px 0 0;
    max-width: 440px;
    text-align: center;
    font-size: 12px;
    line-height: 1.45;
    color: var(--ppe-muted);
}

/* ---------- control panel ---------- */

.ppce-editor__panel {
    padding: 18px 20px 24px;
    background: #fff;
    border-top: 1px solid var(--ppe-line);
    overflow-y: auto;
    min-height: 0;
}

@media (min-width: 960px) {
    .ppce-editor__panel { border-top: 0; border-left: 1px solid var(--ppe-line); }
}

.ppce-group { margin-bottom: 20px; }
.ppce-group__title {
    margin: 0 0 8px;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: .05em;
    text-transform: uppercase;
    color: var(--ppe-muted);
}
.ppce-group__hint { margin: 8px 0 0; font-size: 12px; line-height: 1.45; color: var(--ppe-muted); }

/* segmented control: option cards with a short line under the name */
.ppce-seg { display: flex; gap: 8px; }
.ppce-seg button {
    display: flex;
    flex: 1 1 0;
    flex-direction: column;
    align-items: flex-start;
    justify-content: center;
    gap: 2px;
    min-height: 56px;
    padding: 8px 14px;
    border: 1px solid var(--ppe-line);
    border-radius: 14px;
    background: #fff;
    font-size: 13px;
    font-weight: 600;
    font-family: inherit;
    line-height: 1.3;
    text-align: left;
    color: var(--ppe-ink);
    cursor: pointer;
}
.ppce-seg button small { font-size: 11px; font-weight: 500; color: var(--ppe-muted); }

/* boxed groups, like the design's cards */
.ppce-group--box {
    padding: 14px;
    border: 1px solid var(--ppe-line);
    border-radius: 16px;
    background: #fff;
}
.ppce-group--row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.ppce-group__label { margin: 0; font-size: 13px; font-weight: 600; color: var(--ppe-ink); }
.ppce-group--row .ppce-group__hint { margin-top: 2px; }

.ppce-sr {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.ppce-pillbtn {
    flex: 0 0 auto;
    min-height: 44px;
    padding: 0 18px;
    border: 1px solid var(--ppce-stone-300, #d6d3d1);
    border-radius: 9999px;
    background: #fff;
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    color: var(--ppe-ink);
    cursor: pointer;
}
.ppce-pillbtn:hover { background: var(--ppe-quiet); }
.ppce-pillbtn.is-on { border-color: var(--ppce-ink, #292c24); background: var(--ppce-ink, #292c24); color: #fff; }
.ppce-pillbtn:focus-visible { outline: 3px solid var(--ppce-focus, #292c24); outline-offset: 2px; }

.ppce-rotate { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-top: 4px; }
.ppce-rotate .ppce-tool { flex-direction: row; gap: 8px; min-height: 44px; }

/* "More adjustments": flip and colour, folded away */
.ppce-more {
    margin-bottom: 16px;
    border: 1px solid var(--ppe-line);
    border-radius: 16px;
    background: #fff;
}
.ppce-more summary {
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-height: 52px;
    padding: 8px 40px 8px 14px;
    position: relative;
    font-size: 13px;
    font-weight: 600;
    color: var(--ppe-ink);
    list-style: none;
    cursor: pointer;
}
.ppce-more summary::-webkit-details-marker { display: none; }
.ppce-more summary::after {
    content: "+";
    position: absolute;
    right: 16px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 18px;
    font-weight: 400;
    color: var(--ppe-muted);
}
.ppce-more[open] summary::after { content: "\2212"; }
.ppce-more summary small { font-size: 11px; font-weight: 500; color: var(--ppe-muted); }
.ppce-more summary:focus-visible { outline: 3px solid var(--ppce-focus, #292c24); outline-offset: 2px; border-radius: 16px; }
.ppce-more > :not(summary) { margin-left: 14px; margin-right: 14px; }
.ppce-more .ppce-tools { grid-template-columns: repeat(2, minmax(0, 1fr)); margin-bottom: 14px; }

.ppce-editor__extras { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.ppce-editor__extras .ppce-reset { width: auto; padding: 0 18px; border-radius: 9999px; }
.ppce-editor__state { font-size: 12px; color: var(--ppe-muted); }
.ppce-editor__remove { display: block; margin: 16px 0 0; padding-left: 0; color: var(--ppce-error, #c70036); }

.ppce-editor__name { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ppce-seg button:hover { border-color: var(--ppce-stone-300, #d6d3d1); }
.ppce-seg button.is-on {
    border-color: var(--ppe-accent);
    background: var(--ppe-on);
    color: var(--ppe-ink);
}
.ppce-seg button:focus-visible,
.ppce-tool:focus-visible,
.ppce-reset:focus-visible,
.ppce-editor__close:focus-visible { outline: 3px solid var(--ppce-focus, #292c24); outline-offset: 2px; }

/* rotate / flip */
.ppce-tools { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
.ppce-tool {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
    min-height: 56px;
    border: 1px solid var(--ppe-line);
    border-radius: 14px;
    background: #fff;
    font-size: 17px;
    font-family: inherit;
    color: var(--ppe-ink);
    cursor: pointer;
}
.ppce-tool span { font-size: 10px; font-weight: 600; }
.ppce-tool:hover { border-color: var(--ppce-stone-300, #d6d3d1); }
.ppce-tool.is-on { border-color: var(--ppe-accent); background: var(--ppe-on); color: var(--ppe-ink); }

/* sliders */
.ppce-slider {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 2px 8px;
    margin-bottom: 12px;
}
.ppce-slider label { font-size: 12px; font-weight: 600; color: var(--ppe-muted); }
.ppce-slider__value { font-size: 12px; font-weight: 700; color: var(--ppe-muted); font-variant-numeric: tabular-nums; }
.ppce-slider input[type="range"] { grid-column: 1 / -1; width: 100%; height: 28px; accent-color: var(--ppce-gold, #9a7944); }
.ppce-slider input[type="range"]:disabled { opacity: .4; cursor: not-allowed; }

.ppce-reset {
    width: 100%;
    min-height: 44px;
    border: 1px solid var(--ppe-line);
    border-radius: 14px;
    background: #fff;
    font-size: 12px;
    font-weight: 600;
    font-family: inherit;
    color: var(--ppe-ink);
    cursor: pointer;
}
.ppce-reset:hover:not(:disabled) { background: var(--ppe-quiet); }
.ppce-reset:disabled { opacity: .45; cursor: not-allowed; }

/* ---------- footer ---------- */

.ppce-editor__foot {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    justify-content: space-between;
    padding: 14px 20px;
    border-top: 1px solid var(--ppe-line);
    background: #fff;
}
.ppce-editor__nav,
.ppce-editor__actions { display: flex; gap: 10px; }

@media (max-width: 959.98px) {
    .ppce-editor__body { overflow-y: auto; }
    /* min-height:0 lets a grid row shrink below its content; on one
       scrolling column the rows must grow instead so nothing overlaps. */
    .ppce-editor__stage,
    .ppce-editor__panel { overflow: visible; min-height: auto; }

    /* Keep the print in view while the controls scroll under it, otherwise
       dragging Zoom moves something the customer cannot see. */
    .ppce-editor__stage {
        position: sticky;
        top: 0;
        z-index: 2;
        padding: 14px 20px 12px;
        border-bottom: 1px solid var(--ppe-line);
    }
    .ppce-stage__canvas { max-height: 38vh; }

    /* Phones and small tablets: only the preview and a resolution warning
       stay under it; the explanations and guides toggle go. */
    .ppce-stage__info { display: none; }
    .ppce-stage__warn { display: flex; }
}

@media (max-width: 575.98px) {
    .ppce-editor__sheet { border-radius: 0; height: 100%; height: 100dvh; max-height: none; }
    .ppce-editor__head { padding: 12px 16px; }
    .ppce-editor__head .ppce-eyebrow { display: none; }
    .ppce-editor__title { font-size: 17px; }
    .ppce-editor__sub { font-size: 12px; }
    .ppce-editor__stage { padding: 12px 16px 10px; }
    .ppce-stage__canvas { max-height: 36vh; }
    .ppce-editor__panel { padding: 14px 16px 20px; }

    /* One row: arrows either side of a wide Save; the header × cancels. */
    .ppce-editor__foot {
        position: sticky;
        bottom: 0;
        flex-wrap: nowrap;
        gap: 8px;
        padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0px));
    }
    .ppce-editor__nav { flex: 0 0 auto; gap: 6px; }
    .ppce-editor__nav .ppce-btn { width: 48px; padding: 0; font-size: 18px; }
    .ppce-editor__navtext,
    .ppce-editor__cancel { display: none; }
    .ppce-editor__actions { flex: 1 1 auto; }
    .ppce-editor__save { flex: 1 1 auto; min-height: 48px; font-size: 14px; }
}

@media (prefers-reduced-motion: reduce) {
    .ppce-editor, .ppce-editor * { transition: none !important; animation: none !important; }
}
