/* =====================================================================
   Photo Picker modal (Phase 6.10) — "Choose a photo"
   Pixel-faithful port of the Cloud Design export (Photo Picker.html):
   three tabs (My photos / Upload / Stock gallery), desktop modal +
   mobile bottom-sheet. Tokens mirror the project design system.
   ===================================================================== */

.dg-pp-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 10, 30, 0.5);
    opacity: 0;
    /* Above EVERY host surface the picker can be opened from: the account
       drawer (1500) AND the fullscreen generator modal stack (modal 9990 /
       mobile preview 9995 / spinner 9996 / sheets 9997). Was 1600 — the
       picker opened UNDERNEATH the generator modal. */
    z-index: 10600;
    pointer-events: none;
    transition: opacity 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}
.dg-pp-backdrop[data-state="open"] {
    opacity: 1;
    pointer-events: auto;
}

.dg-pp {
    position: fixed;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -48%) scale(0.96);
    /* R3 — 20% wider than the original 720px export. Grid stays 4-col. */
    width: min(864px, calc(100vw - 2rem));
    max-height: 86vh;
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 24px 60px rgba(15, 10, 30, 0.2);
    z-index: 10601; /* one above .dg-pp-backdrop (10600) */
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s cubic-bezier(0.4, 0, 0.2, 1),
                transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}
.dg-pp[data-state="open"] {
    opacity: 1;
    pointer-events: auto;
    transform: translate(-50%, -50%) scale(1);
}

/* Drag handle — hidden on desktop, shown on the mobile sheet. */
.dg-pp__handle { display: none; }

/* Header ─────────────────────────────────────────────────────────── */
.dg-pp__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 1.15rem 1.4rem 0.85rem;
}
.dg-pp__title {
    margin: 0;
    font-size: 1.15rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: #313330;
}
.dg-pp__close {
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    border: none;
    background: #f5f3f0;
    color: #7a7a82;
    border-radius: 50%;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.15s, color 0.15s;
}
.dg-pp__close:hover,
.dg-pp__close:focus-visible {
    background: #ece9e2;
    color: #313330;
    outline: none;
}

/* Tab switcher — segmented pill ───────────────────────────────────── */
.dg-pp__tabs {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 2px;
    margin: 0 1.4rem;
    padding: 4px;
    background: #f5f3f0;
    border-radius: 100px;
}
.dg-pp__tab {
    border: none;
    background: transparent;
    color: #7a7a82;
    font-family: inherit;
    font-size: 0.875rem;
    font-weight: 600;
    padding: 0.6rem 0.75rem;
    border-radius: 100px;
    cursor: pointer;
    transition: background 0.18s cubic-bezier(0.4, 0, 0.2, 1), color 0.18s;
}
.dg-pp__tab:hover { color: #313330; }
.dg-pp__tab.is-active {
    background: linear-gradient(135deg, #6050b0 0%, #8a72d1 100%);
    color: #fff;
    box-shadow: 0 4px 12px -4px rgba(96, 80, 176, 0.5);
}

/* Body ────────────────────────────────────────────────────────────── */
.dg-pp__body {
    flex: 1 1 auto;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 1.25rem 1.4rem;
    min-height: 220px;
}
.dg-pp__panel { display: none; }
.dg-pp__panel.is-active { display: block; }

/* Thumbnail grid (My photos + Stock) ──────────────────────────────── */
.dg-pp__grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.6rem;
}
.dg-pp__tile {
    position: relative;
    aspect-ratio: 1 / 1;
    border-radius: 12px;
    overflow: hidden;
    border: 0;
    padding: 0;
    cursor: pointer;
    background: #f5f3f0;
    outline: 2px solid transparent;
    outline-offset: 2px;
    transition: transform 0.15s, outline-color 0.15s, box-shadow 0.2s;
}
.dg-pp__tile img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}
.dg-pp__tile:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px -6px rgba(15, 10, 30, 0.25);
}
.dg-pp__tile.is-selected {
    outline-color: #6050b0;
}
.dg-pp__tile.is-selected::after {
    content: "";
    position: absolute;
    inset: 0;
    background: rgba(96, 80, 176, 0.12);
}
.dg-pp__check {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: #6050b0;
    color: #fff;
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 2;
    box-shadow: 0 2px 6px rgba(96, 80, 176, 0.5);
}
.dg-pp__tile.is-selected .dg-pp__check { display: inline-flex; }
.dg-pp__badge {
    position: absolute;
    top: 6px;
    left: 6px;
    z-index: 2;
    font-size: 0.6rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 0.15rem 0.45rem;
    border-radius: 100px;
    background: #6050b0;
    color: #fff;
    box-shadow: 0 2px 6px rgba(96, 80, 176, 0.35);
}
.dg-pp__tile--add {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.25rem;
    background: #f5f3f0;
    border: 1px dashed #ece9e2;
    color: #7a7a82;
    font-size: 0.78rem;
    font-weight: 500;
}
.dg-pp__tile--add:hover {
    border-color: rgba(96, 80, 176, 0.45);
    color: #6050b0;
    box-shadow: none;
    transform: translateY(-2px);
}
.dg-pp__tile--add svg { width: 22px; height: 22px; }

/* Empty state (My photos, no photos) ──────────────────────────────── */
.dg-pp__empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 0.5rem;
    padding: 2.25rem 1rem;
}
.dg-pp__empty-icon {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: rgba(96, 80, 176, 0.1);
    color: #6050b0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 0.25rem;
}
.dg-pp__empty-title {
    font-size: 1.05rem;
    font-weight: 700;
    color: #313330;
}
.dg-pp__empty-hint {
    font-size: 0.85rem;
    color: #7a7a82;
    margin-bottom: 0.5rem;
}
.dg-pp__empty-actions {
    display: inline-flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    justify-content: center;
}

/* Upload tab ──────────────────────────────────────────────────────── */
.dg-pp__dropzone {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    text-align: center;
    min-height: 200px;
    padding: 1.5rem;
    border: 2px dashed #ece9e2;
    border-radius: 16px;
    background: #faf9f7;
    color: #7a7a82;
    cursor: pointer;
    transition: border-color 0.18s, background 0.18s;
}
.dg-pp__dropzone:hover,
.dg-pp__dropzone.is-drag {
    border-color: rgba(96, 80, 176, 0.5);
    background: rgba(96, 80, 176, 0.04);
}
.dg-pp__dropzone-icon { color: #6050b0; }
.dg-pp__dropzone-title { font-size: 0.95rem; font-weight: 600; color: #313330; }
.dg-pp__dropzone-hint { font-size: 0.78rem; color: #7a7a82; }
.dg-pp__uploads { margin-top: 1rem; }
.dg-pp__uploads-label {
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: #7a7a82;
    margin-bottom: 0.5rem;
}
.dg-pp__upload-row {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.5rem 0;
}
.dg-pp__upload-thumb {
    width: 72px;
    height: 72px;
    border-radius: 10px;
    object-fit: cover;
    flex-shrink: 0;
    background: #f5f3f0;
}
.dg-pp__upload-meta { flex: 1 1 auto; min-width: 0; }
.dg-pp__upload-name {
    font-size: 0.82rem;
    color: #313330;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.dg-pp__upload-bar {
    height: 4px;
    border-radius: 100px;
    background: #ece9e2;
    overflow: hidden;
    margin-top: 0.35rem;
}
.dg-pp__upload-bar-fill {
    display: block;
    height: 100%;
    width: 0;
    background: linear-gradient(135deg, #6050b0 0%, #c4b8ff 100%);
    border-radius: inherit;
    transition: width 0.25s ease;
}
/* R4/R7 — live percentage label next to the bar. */
.dg-pp__upload-pct {
    flex-shrink: 0;
    font-size: 0.72rem;
    font-weight: 600;
    color: #6050b0;
    min-width: 34px;
    text-align: right;
    font-variant-numeric: tabular-nums;
}
/* R5 — × to remove the uploaded photo from the slot (deselect-only). */
.dg-pp__upload-x {
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    border: none;
    background: transparent;
    color: #7a7a82;
    border-radius: 50%;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.15s, color 0.15s;
}
.dg-pp__upload-x:hover {
    background: rgba(197, 67, 67, 0.1);
    color: #c54343;
}

/* Stock tab — chips + search ──────────────────────────────────────── */
.dg-pp__stock-head {
    display: flex;
    flex-direction: column;
    gap: 0.7rem;
    /* Keep the occasion filter pinned while the grid scrolls (.dg-pp__body is
       the scroll container). Negative side margins + matching padding bleed the
       white background across the body's 1.4rem padding so tiles never peek at
       the edges; padding-bottom covers the gap above the grid. */
    position: sticky;
    top: 0;
    z-index: 3;
    background: #fff;
    margin: 0 -1.4rem 0.85rem;
    padding: 0 1.4rem 0.7rem;
}
/* R2 — search bar removed; occasion chips are the only stock filter. */
.dg-pp__chips {
    display: flex;
    gap: 0.4rem;
    overflow-x: auto;
    padding-bottom: 0.15rem;
    scrollbar-width: thin;
}
.dg-pp__chip {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.4rem 0.8rem;
    border: 1px solid #ece9e2;
    border-radius: 100px;
    background: #fff;
    color: #7a7a82;
    font-family: inherit;
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.dg-pp__chip:hover { border-color: rgba(96, 80, 176, 0.4); color: #6050b0; }
.dg-pp__chip.is-active {
    background: #6050b0;
    border-color: #6050b0;
    color: #fff;
}

/* Loading skeleton + status text ──────────────────────────────────── */
.dg-pp__skeleton {
    aspect-ratio: 1 / 1;
    border-radius: 12px;
    background: linear-gradient(100deg, #f0eee9 30%, #f7f5f1 50%, #f0eee9 70%);
    background-size: 200% 100%;
    animation: dg-pp-shimmer 1.2s linear infinite;
}
@keyframes dg-pp-shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
.dg-pp__status {
    padding: 1.5rem 1rem;
    text-align: center;
    font-size: 0.85rem;
    color: #7a7a82;
}

/* Login prompt (guest, My photos) ─────────────────────────────────── */
.dg-pp__login {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 0.6rem;
    padding: 2.25rem 1rem;
}

/* R6 — selected-photo preview strip above the footer ──────────────── */
.dg-pp__selected {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 0.7rem;
    padding: 0.7rem 1.4rem;
    border-top: 1px solid #ece9e2;
    background: #faf9f7;
}
.dg-pp__selected[hidden] { display: none; }
.dg-pp__selected-thumb {
    width: 44px;
    height: 44px;
    border-radius: 10px;
    object-fit: cover;
    flex-shrink: 0;
    background: #f5f3f0;
    border: 2px solid #6050b0;
}
.dg-pp__selected-label {
    flex: 1 1 auto;
    min-width: 0;
    font-size: 0.82rem;
    color: #313330;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.dg-pp__selected-x {
    flex-shrink: 0;
    width: 30px;
    height: 30px;
    border: none;
    background: #fff;
    color: #7a7a82;
    border-radius: 50%;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid #ece9e2;
    transition: background-color 0.15s, color 0.15s, border-color 0.15s;
}
.dg-pp__selected-x:hover {
    background: rgba(197, 67, 67, 0.1);
    color: #c54343;
    border-color: rgba(197, 67, 67, 0.2);
}

/* Footer ──────────────────────────────────────────────────────────── */
.dg-pp__foot {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.9rem;
    padding: 0.875rem 1.4rem;
    border-top: 1px solid #ece9e2;
    background: #fff;
}
.dg-pp__counter {
    font-size: 0.82rem;
    color: #7a7a82;
}
.dg-pp__actions {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
}
.dg-pp__btn {
    font-family: inherit;
    font-size: 0.875rem;
    font-weight: 600;
    border-radius: 100px;
    cursor: pointer;
    border: 1px solid transparent;
    transition: transform 0.15s, box-shadow 0.2s, background 0.15s, border-color 0.15s, opacity 0.15s;
}
.dg-pp__btn--ghost {
    background: transparent;
    border-color: transparent;
    color: #7a7a82;
    font-weight: 500;
    padding: 0.625rem 1.1rem;
}
.dg-pp__btn--ghost:hover { color: #313330; }
.dg-pp__btn--primary {
    background: linear-gradient(135deg, #6050b0 0%, #c4b8ff 100%);
    color: #fff;
    padding: 0.625rem 1.25rem;
    box-shadow: 0 6px 16px -6px rgba(96, 80, 176, 0.5);
}
.dg-pp__btn--primary:hover { transform: translateY(-1px); }
.dg-pp__btn--primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}
.dg-pp__btn--secondary {
    background: #fff;
    border-color: #ece9e2;
    color: #313330;
    padding: 0.55rem 1rem;
}
.dg-pp__btn--secondary:hover { border-color: rgba(96, 80, 176, 0.45); }

/* RTL — mirror search icon side */

/* Mobile bottom-sheet (≤640px) ────────────────────────────────────── */
@media (max-width: 640px) {
    .dg-pp {
        left: 0;
        right: 0;
        top: auto;
        bottom: 0;
        width: 100%;
        max-width: none;
        max-height: 90vh;
        border-radius: 20px 20px 0 0;
        transform: translateY(100%);
    }
    .dg-pp[data-state="open"] { transform: translateY(0); }
    .dg-pp__handle {
        display: block;
        width: 40px;
        height: 4px;
        border-radius: 2px;
        background: #e2e0db;
        margin: 0.55rem auto 0;
        flex-shrink: 0;
    }
    .dg-pp__head { padding-top: 0.6rem; }
    .dg-pp__grid { grid-template-columns: repeat(3, 1fr); }
    .dg-pp__foot { flex-direction: column-reverse; align-items: stretch; }
    .dg-pp__actions { width: 100%; }
    .dg-pp__btn--ghost, .dg-pp__btn--primary { flex: 1 1 auto; text-align: center; }
    .dg-pp__counter { text-align: center; }
}
