/* ==========================================================================
   Export PDF dialog (partials/pdf-export-dialog.blade.php, hp-pdf-export.js).
   Left: the pages, drawn on the server, on the dark library desk (both
   themes, so ivory and white paper read as paper). Right: the options,
   following the page theme through the --hx-* tokens. Logical properties
   throughout, so Arabic pages mirror.
   ========================================================================== */

html.hp-pdf-on { overflow: hidden; }
html.hp-pdf-on :is(.hp-help, .hp-install, .hp-tour, .hp-tour-pop, .site-announcements) { visibility: hidden; }

body.hp-ui .hp-pdf {
    position: fixed; inset: 0; z-index: 2147481000;
    display: grid; place-items: center; padding: 24px;
    color: var(--hx-ink); font-family: var(--hx-f-body);
}
body.hp-ui .hp-pdf[hidden] { display: none; }

body.hp-ui .hp-pdf-scrim {
    position: absolute; inset: 0;
    background: rgba(3, 12, 8, .72);
    opacity: 0; transition: opacity .24s ease;
}

body.hp-ui .hp-pdf-panel {
    position: relative; display: grid; grid-template-columns: minmax(0, 1fr) minmax(330px, 404px);
    width: min(1220px, 100%); height: min(880px, calc(100dvh - 48px));
    background: var(--hx-surface); border: 1px solid var(--hx-line); border-radius: 28px;
    box-shadow: var(--hx-shadow-lg); overflow: hidden;
    opacity: 0; transform: translateY(14px) scale(.988);
    transition: opacity .26s var(--hx-ease), transform .32s var(--hx-ease);
}
body.hp-ui .hp-pdf.is-open .hp-pdf-scrim { opacity: 1; }
body.hp-ui .hp-pdf.is-open .hp-pdf-panel { opacity: 1; transform: none; }

/* ---------- The desk and its pages ---------- */
body.hp-ui .hp-pdf-stage {
    position: relative; display: grid; grid-template-rows: auto minmax(0, 1fr) auto; min-width: 0; min-height: 0;
    background:
        radial-gradient(110% 60% at 0% 0%, rgba(35, 107, 82, .38), transparent 62%),
        radial-gradient(80% 50% at 100% 100%, rgba(184, 137, 74, .12), transparent 70%),
        var(--hx-stage);
    color: var(--hx-on-stage);
}
body.hp-ui .hp-pdf-stage-bar {
    display: flex; align-items: baseline; justify-content: space-between; gap: 16px;
    padding: 20px 28px 14px; border-bottom: 1px solid var(--hx-stage-line);
}
body.hp-ui .hp-pdf-stage-title {
    display: inline-flex; align-items: center; gap: 10px; margin: 0;
    font-size: .72rem; font-weight: 700; letter-spacing: .18em; text-transform: uppercase; color: #e6c995;
}
body.hp-ui .hp-pdf-stage-title::before {
    content: ""; width: 7px; height: 7px; border-radius: 50%; background: #e6c995;
    box-shadow: 0 0 0 3px rgba(230, 201, 149, .18);
}
body.hp-ui .hp-pdf-count { margin: 0; font-size: .82rem; font-variant-numeric: tabular-nums; color: var(--hx-on-stage-2); }

body.hp-ui .hp-pdf-desk {
    position: relative; min-height: 0; overflow-y: auto; overscroll-behavior: contain;
    padding: 30px 34px 40px; scrollbar-color: rgba(230, 201, 149, .35) transparent;
}
body.hp-ui .hp-pdf-desk:focus-visible { outline: 2px solid var(--hx-focus-on-stage); outline-offset: -4px; }

body.hp-ui .hp-pdf-pages {
    display: grid; gap: 26px; justify-items: center;
    width: min(100%, 600px); margin-inline: auto;
    transition: opacity .2s ease;
}
body.hp-ui .hp-pdf.is-busy.is-ready .hp-pdf-pages { opacity: .55; }
body.hp-ui .hp-pdf-sheet {
    position: relative; width: 100%; line-height: 0;
    box-shadow:
        0 0 0 1px rgba(230, 201, 149, .14),
        0 2px 4px rgba(0, 0, 0, .25),
        0 30px 60px -28px rgba(0, 0, 0, .9);
}
body.hp-ui .hp-pdf-sheet > svg { display: block; width: 100%; height: auto; }
body.hp-ui .hp-pdf-sheet::after {
    content: attr(data-page); position: absolute; inset-block-end: -20px; inset-inline-end: 0;
    font: 600 .68rem/1 var(--hx-f-body); letter-spacing: .14em; color: rgba(230, 201, 149, .55);
}
body.hp-ui .hp-pdf-defs { position: absolute; width: 0; height: 0; overflow: hidden; }

body.hp-ui .hp-pdf-wait {
    position: absolute; inset: 0; display: none; place-content: center; justify-items: center; gap: 16px;
    font-size: .95rem; color: var(--hx-on-stage-2); pointer-events: none;
}
body.hp-ui .hp-pdf:not(.is-ready) .hp-pdf-wait { display: grid; }
body.hp-ui .hp-pdf-wait-sheet {
    display: grid; gap: 7px; width: 74px; padding: 14px 12px; border-radius: 3px;
    background: #faf6ee; box-shadow: 0 18px 40px -18px rgba(0, 0, 0, .9);
}
body.hp-ui .hp-pdf-wait-sheet i { display: block; height: 3px; border-radius: 2px; background: #d9cfbd; }
body.hp-ui .hp-pdf-wait-sheet i:first-child { width: 60%; height: 5px; background: #0f4536; }
body.hp-ui .hp-pdf-wait-sheet i:last-child { width: 70%; }

/* A thin brass line runs along the top of the desk while a new preview is set. */
body.hp-ui .hp-pdf-stage-bar { position: relative; }
body.hp-ui .hp-pdf-stage-bar::after {
    content: ""; position: absolute; inset-inline: 0; bottom: -1px; height: 2px;
    background: linear-gradient(90deg, transparent, #e6c995, transparent);
    transform: scaleX(0); opacity: 0; transition: opacity .2s ease;
}
body.hp-ui .hp-pdf.is-busy .hp-pdf-stage-bar::after { opacity: 1; animation: hp-pdf-setting 1.1s var(--hx-ease) infinite; }
@keyframes hp-pdf-setting {
    0% { transform: translateX(-40%) scaleX(.3); }
    100% { transform: translateX(40%) scaleX(.3); }
}

body.hp-ui .hp-pdf-more {
    margin: 0; padding: 12px 28px 16px; border-top: 1px solid var(--hx-stage-line);
    font-size: .82rem; color: var(--hx-on-stage-2);
}
body.hp-ui .hp-pdf-more[hidden] { display: none; }

/* ---------- The options ---------- */
body.hp-ui .hp-pdf-side {
    display: flex; flex-direction: column; gap: 22px; min-width: 0; min-height: 0;
    padding: 34px 28px 0; overflow-y: auto; overscroll-behavior: contain;
}
body.hp-ui .hp-pdf-head { display: grid; gap: 9px; padding-inline-end: 36px; }
body.hp-ui .hp-pdf-eyebrow {
    margin: 0; font-size: .72rem; font-weight: 700; letter-spacing: .16em; text-transform: uppercase;
    color: var(--hx-quill-ink);
}
body.hp-ui .hp-pdf-title {
    margin: 0; font-family: var(--hx-f-display); font-weight: 400;
    font-size: 2.1rem; line-height: 1.02; letter-spacing: -.01em; color: var(--hx-ink);
}
body.hp-ui .hp-pdf-note { margin: 2px 0 0; font-size: .88rem; line-height: 1.55; color: var(--hx-ink-3); }

body.hp-ui .hp-pdf-group { display: grid; gap: 12px; min-width: 0; margin: 0; padding: 0; border: 0; }
body.hp-ui .hp-pdf-group[hidden] { display: none; }
body.hp-ui .hp-pdf-legend {
    display: flex; align-items: center; gap: 10px; width: 100%; margin: 0 0 2px; padding: 0;
    font-size: .7rem; font-weight: 800; letter-spacing: .16em; text-transform: uppercase; color: var(--hx-ink-2);
}
body.hp-ui .hp-pdf-legend::after { content: ""; flex: 1; height: 1px; background: var(--hx-line); }
body.hp-ui .hp-pdf [data-hp-pdf-for][hidden] { display: none; }

/* Design cards */
body.hp-ui .hp-pdf-designs { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
body.hp-ui .hp-pdf-design {
    position: relative; display: grid; align-content: start; gap: 4px; padding: 10px 10px 12px;
    border: 1px solid var(--hx-line); border-radius: 16px; background: var(--hx-surface-2);
    cursor: pointer; transition: border-color .18s ease, background-color .18s ease, box-shadow .18s ease;
}
body.hp-ui .hp-pdf-design:hover { border-color: var(--hx-line-2); }
body.hp-ui .hp-pdf-design:has(input:checked) {
    border-color: var(--hx-quill); background: var(--hx-surface);
    box-shadow: 0 0 0 1px var(--hx-quill), 0 12px 24px -18px rgba(8, 26, 19, .5);
}
body.hp-ui .hp-pdf-design input,
body.hp-ui .hp-pdf-seg input,
body.hp-ui .hp-pdf-switch input {
    position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer;
}
body.hp-ui .hp-pdf-design:has(input:focus-visible),
body.hp-ui .hp-pdf-seg label:has(input:focus-visible),
body.hp-ui .hp-pdf-switch:has(input:focus-visible) .hp-pdf-switch-track { outline: 2px solid var(--hx-focus); outline-offset: 2px; }
body.hp-ui .hp-pdf-design-name { margin-top: 6px; font-size: .86rem; font-weight: 700; color: var(--hx-ink); }
body.hp-ui .hp-pdf-design-text { font-size: .72rem; line-height: 1.35; color: var(--hx-ink-3); }

/* The little pages on the cards: drawn with CSS, a hint of each design. */
body.hp-ui .hp-pdf-swatch {
    position: relative; display: block; width: min(100%, 128px); aspect-ratio: 210 / 250; border-radius: 4px; overflow: hidden;
    background: #fff; box-shadow: 0 0 0 1px rgba(20, 35, 28, .12), 0 6px 14px -10px rgba(8, 26, 19, .6);
}
body.hp-ui .hp-pdf-swatch i,
body.hp-ui .hp-pdf-swatch b,
body.hp-ui .hp-pdf-swatch s { position: absolute; display: block; text-decoration: none; }
body.hp-ui .hp-pdf-swatch s { height: 2px; border-radius: 1px; background: #c9c3b8; inset-inline: 16%; }
body.hp-ui .hp-pdf-swatch s:nth-of-type(1) { top: 52%; }
body.hp-ui .hp-pdf-swatch s:nth-of-type(2) { top: 62%; }
body.hp-ui .hp-pdf-swatch s:nth-of-type(3) { top: 72%; inset-inline-end: 38%; }

body.hp-ui .hp-pdf-swatch.is-forest { background: #faf6ee; }
body.hp-ui .hp-pdf-swatch.is-forest::before {
    content: ""; position: absolute; inset: 5px; border: 1px solid #b8894a; border-radius: 1px;
}
body.hp-ui .hp-pdf-swatch.is-forest i { top: 15%; inset-inline-start: 16%; width: 15%; aspect-ratio: 1; border: 1.5px solid #b8894a; border-radius: 50%; }
body.hp-ui .hp-pdf-swatch.is-forest b { top: 18%; inset-inline-start: 36%; width: 38%; height: 5px; border-radius: 2px; background: #0f4536; }
body.hp-ui .hp-pdf-swatch.is-forest::after {
    content: ""; position: absolute; top: 36%; inset-inline: 16%; height: 3px;
    border-top: 1.5px solid #b8894a; border-bottom: 1px solid #b8894a;
}

body.hp-ui .hp-pdf-swatch.is-classic i { top: 11%; left: calc(50% - 4px); width: 8px; aspect-ratio: 1; border: 1px solid #161616; transform: rotate(45deg); }
body.hp-ui .hp-pdf-swatch.is-classic b { top: 24%; left: 30%; width: 40%; height: 3px; background: #161616; }
body.hp-ui .hp-pdf-swatch.is-classic::after {
    content: ""; position: absolute; top: 36%; inset-inline: 14%; height: 3px;
    border-top: 2px solid #161616; border-bottom: 1px solid #161616;
}
body.hp-ui .hp-pdf-swatch.is-classic s { background: #9a9a9a; inset-inline: 14%; }
body.hp-ui .hp-pdf-swatch.is-classic s:nth-of-type(3) { inset-inline-end: 14%; }

body.hp-ui .hp-pdf-swatch.is-modern i { top: 13%; inset-inline-start: 12%; width: 13%; aspect-ratio: 1; background: #0f4536; }
body.hp-ui .hp-pdf-swatch.is-modern b { top: 15%; inset-inline-start: 34%; width: 44%; height: 6px; border-radius: 1px; background: #d0d6d2; }
body.hp-ui .hp-pdf-swatch.is-modern::after {
    content: ""; position: absolute; top: 37%; inset-inline: 12%; height: 1px; background: #d5dbd6;
    box-shadow: inset 14px 0 0 #0f4536;
}
body.hp-ui .hp-pdf-swatch.is-modern s { inset-inline-start: 34%; inset-inline-end: 12%; background: #c4cbc6; }
body.hp-ui .hp-pdf-swatch.is-modern s:nth-of-type(3) { inset-inline-end: 34%; }

/* Segmented choices */
body.hp-ui .hp-pdf-seg {
    display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 4px; padding: 4px;
    border: 1px solid var(--hx-line); border-radius: 999px; background: var(--hx-surface-2);
}
body.hp-ui .hp-pdf-seg label { position: relative; display: block; border-radius: 999px; }
body.hp-ui .hp-pdf-seg span {
    display: grid; place-items: center; min-height: 38px; padding: 0 8px; border-radius: 999px;
    font-size: .82rem; font-weight: 700; text-align: center; color: var(--hx-ink-2);
    transition: background-color .18s ease, color .18s ease;
}
body.hp-ui .hp-pdf-seg label:hover span { color: var(--hx-ink); }
body.hp-ui .hp-pdf-seg input:checked + span { background: var(--hx-btn); color: #fff; }

/* Fields */
body.hp-ui .hp-pdf-fields,
body.hp-ui .hp-pdf-fields-more { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
body.hp-ui .hp-pdf-fields-more { grid-column: 1 / -1; }
body.hp-ui .hp-pdf-fields-more[hidden] { display: none; }
body.hp-ui .hp-pdf-field { display: grid; gap: 5px; min-width: 0; }
body.hp-ui .hp-pdf-field[hidden] { display: none; }
body.hp-ui .hp-pdf-field.is-wide { grid-column: 1 / -1; }
body.hp-ui .hp-pdf-field > span { font-size: .76rem; font-weight: 700; color: var(--hx-ink-2); }
body.hp-ui .hp-pdf-field > span[hidden] { display: none; }
/* The fill is a background image and the outline an inset shadow: the
   document pages force a light background-color and border on every input. */
body.hp-ui .hp-pdf-field :is(input, textarea) {
    --hp-pdf-fill: var(--hx-surface-2);
    --hp-pdf-edge: var(--hx-line-2);
    width: 100%; min-height: 44px; padding: 10px 12px; border: 1px solid transparent; border-radius: 12px;
    background: linear-gradient(var(--hp-pdf-fill), var(--hp-pdf-fill)); box-shadow: inset 0 0 0 1px var(--hp-pdf-edge);
    color: var(--hx-ink); font: 500 .9rem/1.4 var(--hx-f-body);
    transition: box-shadow .18s ease;
}
body.hp-ui .hp-pdf-field textarea { min-height: 76px; resize: vertical; }
body.hp-ui .hp-pdf-field :is(input, textarea)::placeholder { color: var(--hx-ink-3); opacity: .8; }
body.hp-ui .hp-pdf-field :is(input, textarea):hover { --hp-pdf-edge: var(--hx-quill); }
body.hp-ui .hp-pdf-field :is(input, textarea):focus-visible { --hp-pdf-fill: var(--hx-surface); outline: 2px solid var(--hx-focus); outline-offset: 1px; }

/* Switches */
body.hp-ui .hp-pdf-switch {
    position: relative; display: flex; align-items: center; gap: 12px; min-height: 40px;
    font-size: .86rem; font-weight: 600; color: var(--hx-ink-2); cursor: pointer;
}
body.hp-ui .hp-pdf-switch[hidden] { display: none; }
body.hp-ui .hp-pdf-switch-track {
    position: relative; flex: none; width: 38px; height: 22px; border-radius: 999px;
    background: var(--hx-line-2); transition: background-color .18s ease;
}
body.hp-ui .hp-pdf-switch-track::after {
    content: ""; position: absolute; top: 3px; inset-inline-start: 3px; width: 16px; height: 16px; border-radius: 50%;
    background: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, .25); transition: transform .2s var(--hx-ease);
}
body.hp-ui .hp-pdf-switch input:checked + .hp-pdf-switch-track { background: var(--hx-btn); }
body.hp-ui .hp-pdf-switch input:checked + .hp-pdf-switch-track::after { transform: translateX(16px); }
html[dir="rtl"] body.hp-ui .hp-pdf-switch input:checked + .hp-pdf-switch-track::after { transform: translateX(-16px); }
body.hp-ui .hp-pdf-switch.is-footer { padding-top: 14px; border-top: 1px solid var(--hx-line); }

body.hp-ui .hp-pdf-hint { margin: -2px 0 0; font-size: .76rem; line-height: 1.5; color: var(--hx-ink-3); }

body.hp-ui .hp-pdf-alerts { display: grid; gap: 8px; }
body.hp-ui .hp-pdf-alerts:empty { display: none; }
body.hp-ui .hp-pdf-alert {
    margin: 0; padding: 10px 12px; border-radius: 12px; border-inline-start: 3px solid var(--hx-quill);
    background: var(--hx-quill-soft); font-size: .82rem; line-height: 1.5; color: var(--hx-ink);
}
body.hp-ui .hp-pdf-alert.is-error { border-inline-start-color: var(--hx-danger); background: var(--hx-danger-soft); }

/* The download button stays in view at the foot of the options. */
body.hp-ui .hp-pdf-actions {
    position: sticky; bottom: 0; z-index: 1; display: grid; gap: 8px;
    margin: auto -28px 0; padding: 16px 28px 22px;
    background: linear-gradient(to bottom, transparent, var(--hx-surface) 28%);
}
body.hp-ui .hp-pdf-btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 10px;
    min-height: 52px; padding: 0 22px; border-radius: 999px; border: 1px solid var(--hx-btn);
    background: var(--hx-btn); color: #fff; font: 700 1rem/1 var(--hx-f-body); cursor: pointer;
    box-shadow: 0 16px 30px -18px rgba(15, 69, 54, .9);
    transition: background-color .18s ease, transform .18s var(--hx-ease);
}
body.hp-ui .hp-pdf-btn:hover:not(:disabled) { background: var(--hx-royal-hover); }
body.hp-ui .hp-pdf-btn:active:not(:disabled) { transform: translateY(1px); }
body.hp-ui .hp-pdf-btn:disabled { opacity: .6; cursor: progress; }
body.hp-ui .hp-pdf-btn:focus-visible,
body.hp-ui .hp-pdf-close:focus-visible { outline: 2px solid var(--hx-focus); outline-offset: 3px; }
body.hp-ui .hp-pdf-i { width: 18px; height: 18px; flex: none; }
body.hp-ui .hp-pdf-status { min-height: 1.3em; margin: 0; font-size: .82rem; line-height: 1.45; text-align: center; color: var(--hx-ink-3); }

body.hp-ui .hp-pdf-close {
    position: absolute; top: 14px; inset-inline-end: 14px; z-index: 2;
    display: grid; place-items: center; width: 44px; height: 44px; padding: 0;
    border: 1px solid transparent; border-radius: 50%; background: transparent; color: var(--hx-ink-2);
    cursor: pointer; transition: background-color .18s ease, color .18s ease;
}
body.hp-ui .hp-pdf-close:hover { background: var(--hx-surface-2); color: var(--hx-ink); }

/* Dark theme: the brass ring and the primary button keep their contrast. */
html[data-hp-theme="dark"] body.hp-ui .hp-pdf-seg input:checked + span,
html[data-hp-theme="dark"] body.hp-ui .hp-pdf-btn { background: var(--hx-royal); border-color: var(--hx-royal); }
html[data-hp-theme="dark"] body.hp-ui .hp-pdf-btn:hover:not(:disabled) { background: var(--hx-royal-hover); }
html[data-hp-theme="dark"] body.hp-ui .hp-pdf-swatch { box-shadow: 0 0 0 1px rgba(230, 201, 149, .18); }

/* Arabic: no letter-spacing on Arabic capitals-style labels (it breaks the joins). */
html[lang="ar"] body.hp-ui :is(.hp-pdf-eyebrow, .hp-pdf-title, .hp-pdf-legend, .hp-pdf-stage-title) { letter-spacing: 0; }
html[lang="ar"] body.hp-ui .hp-pdf-title { line-height: 1.3; }

/* ---------- Narrower screens: pages above, options below ---------- */
@media (max-width: 900px) {
    body.hp-ui .hp-pdf { padding: 0; place-items: stretch; }
    body.hp-ui .hp-pdf-panel {
        display: block; width: 100%; height: 100dvh; border: 0; border-radius: 0; overflow-y: auto; overscroll-behavior: contain;
    }
    body.hp-ui .hp-pdf-stage { grid-template-rows: auto auto auto; }
    body.hp-ui .hp-pdf-stage-bar { padding: 18px 64px 12px 20px; }
    html[dir="rtl"] body.hp-ui .hp-pdf-stage-bar { padding: 18px 20px 12px 64px; }
    body.hp-ui .hp-pdf-desk { height: min(62dvh, 560px); padding: 20px 18px 30px; }
    body.hp-ui .hp-pdf-side { overflow: visible; max-width: 680px; margin-inline: auto; padding: 26px 18px 0; }
    body.hp-ui .hp-pdf-actions { margin-inline: -18px; padding: 14px 18px calc(16px + env(safe-area-inset-bottom)); }
    /* Fixed over the pages and the options alike, so it carries its own dark disc. */
    body.hp-ui .hp-pdf-close {
        position: fixed; top: 10px; inset-inline-end: 10px;
        background: rgba(4, 23, 15, .82); border-color: rgba(230, 201, 149, .3); color: var(--hx-on-stage);
    }
    body.hp-ui .hp-pdf-close:hover { background: var(--hx-stage); color: #fff; }
}

@media (max-width: 420px) {
    body.hp-ui .hp-pdf-designs { gap: 8px; }
    body.hp-ui .hp-pdf-design { padding: 8px 8px 10px; }
    body.hp-ui .hp-pdf-design-text { display: none; }
    body.hp-ui .hp-pdf-seg.is-four { grid-auto-flow: row; grid-template-columns: repeat(2, minmax(0, 1fr)); border-radius: 22px; }
    body.hp-ui .hp-pdf-fields,
    body.hp-ui .hp-pdf-fields-more { grid-template-columns: minmax(0, 1fr); }
}

@media (prefers-reduced-motion: reduce) {
    body.hp-ui .hp-pdf-scrim,
    body.hp-ui .hp-pdf-panel,
    body.hp-ui .hp-pdf-pages,
    body.hp-ui .hp-pdf-design,
    body.hp-ui .hp-pdf-switch-track,
    body.hp-ui .hp-pdf-switch-track::after,
    body.hp-ui .hp-pdf-btn { transition: none; }
    body.hp-ui .hp-pdf-panel { transform: none; }
    body.hp-ui .hp-pdf.is-busy .hp-pdf-stage-bar::after { animation: none; transform: none; opacity: .7; }
}
