/* ========== IMAGE UPLOAD ========== */

.image-upload-zone {
    position: relative;
    display: block;
    width: 100%;
    max-width: 360px;
    min-height: 238px;
    aspect-ratio: 4 / 3;
    background: linear-gradient(165deg, var(--bg-elevated) 0%, #192132 100%);
    border: 2px dashed rgba(148, 163, 184, 0.35);
    border-radius: 16px;
    overflow: hidden;
    isolation: isolate;
    transition: all var(--transition-smooth);
}

.image-upload-zone.is-square {
    aspect-ratio: 1 / 1;
}

.image-upload-zone.is-free-ratio {
    max-width: 420px;
    aspect-ratio: 16 / 9;
}

.image-upload-zone:hover {
    border-color: rgba(96, 165, 250, 0.7);
    box-shadow: 0 0 32px rgba(59, 130, 246, 0.2);
}

.image-upload-zone.drag-over {
    border-color: var(--atlantic-light);
    background: rgba(59, 130, 246, 0.08);
}

.image-upload-zone.has-image .upload-prompt {
    display: none;
}

.image-upload-zone .upload-prompt {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 0.85rem;
    gap: 0.45rem;
    z-index: 2;
}

.upload-icon-wrap {
    width: 58px;
    height: 58px;
    border-radius: 16px;
    border: 1px solid rgba(148, 163, 184, 0.25);
    background: rgba(15, 23, 42, 0.55);
    display: flex;
    align-items: center;
    justify-content: center;
}

.upload-icon-wrap i {
    font-size: 1.8rem;
    color: rgba(148, 163, 184, 0.88);
}

.upload-copy {
    display: grid;
    gap: 0.2rem;
    justify-items: center;
}

.upload-prompt-text {
    font-size: 0.92rem;
    color: var(--text-soft);
    font-weight: 600;
    max-width: 260px;
}

.upload-prompt-sub {
    font-size: 0.78rem;
    color: var(--text-muted);
    max-width: 260px;
}

.image-upload-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.55rem;
    width: min(320px, 100%);
    margin-top: 0.45rem;
}

.image-action-btn {
    border: 1px solid rgba(96, 165, 250, 0.45);
    background: rgba(15, 23, 42, 0.78);
    color: var(--text-soft);
    min-height: 42px;
    border-radius: 11px;
    font-size: 0.78rem;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
    width: 100%;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.image-action-btn span {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.image-action-btn:hover {
    border-color: rgba(147, 197, 253, 0.95);
    background: rgba(30, 41, 59, 0.92);
    color: #fff;
    box-shadow: 0 8px 18px rgba(30, 64, 175, 0.28);
}

.image-action-btn i {
    font-size: 1rem;
}

.image-remove-btn {
    border-color: rgba(248, 113, 113, 0.45);
    background: rgba(127, 29, 29, 0.28);
}

.image-remove-btn:hover {
    border-color: rgba(252, 165, 165, 0.9);
    background: rgba(127, 29, 29, 0.46);
}

.image-upload-zone .image-upload-input,
.image-upload-zone .image-upload-input-camera,
.image-upload-zone .image-upload-input-gallery {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    opacity: 0 !important;
    pointer-events: none !important;
    left: -9999px !important;
    top: -9999px !important;
}

.image-preview {
    position: absolute;
    inset: 0;
    display: none;
    z-index: 1;
    background: #0a0f1a;
}

.image-upload-zone.has-image .image-preview {
    display: block;
}

.image-preview img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    pointer-events: none;
}

.image-preview-overlay {
    position: absolute;
    inset: auto 0 0 0;
    z-index: 3;
    background: linear-gradient(180deg, rgba(0, 0, 0, 0) 0%, rgba(3, 7, 18, 0.8) 45%, rgba(3, 7, 18, 0.92) 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    gap: 0.45rem;
    padding: 1rem;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition-fast);
}

.image-upload-zone.has-image:hover .image-preview-overlay,
.image-upload-zone.has-image .image-preview-overlay:focus-within {
    opacity: 1;
    pointer-events: auto;
}

/* ========== CROPPER MODAL ========== */

.image-cropper-modal {
    position: fixed;
    inset: 0;
    z-index: 2100;
    background: rgba(8, 10, 16, 0.82);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.image-cropper-modal.hidden {
    display: none;
}

.image-cropper-dialog {
    width: min(680px, calc(100vw - 2rem));
    max-height: min(88vh, 760px);
    background: var(--bg-primary);
    border: 1px solid var(--glass-border-hover);
    border-radius: 14px;
    overflow: hidden;
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
}

.image-cropper-header {
    padding: 0.9rem 1rem;
    border-bottom: 1px solid var(--glass-border);
}

.image-cropper-header h3 {
    margin: 0;
    font-size: 0.95rem;
    color: var(--text-pure);
}

.image-cropper-subtitle {
    margin: 0.3rem 0 0;
    font-size: 0.78rem;
    color: var(--text-subtle);
}

.image-cropper-body {
    flex: 1;
    min-height: min(42vh, 360px);
    max-height: min(56vh, 460px);
    background: #0a0d16;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.image-cropper-target {
    display: block;
    max-width: 100%;
    max-height: 100%;
    width: 100%;
    object-fit: contain;
}

.image-cropper-footer {
    padding: 0.9rem 1rem;
    border-top: 1px solid var(--glass-border);
    display: flex;
    align-items: center;
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: 0.6rem;
}

.image-cropper-skip-btn {
    margin-right: auto;
}

body.image-cropper-open {
    overflow: hidden;
}

html.theme-light .image-upload-zone {
    background: linear-gradient(165deg, #ffffff 0%, #eef4ff 100%);
    border-color: rgba(37, 99, 235, 0.28);
}

html.theme-light .image-upload-zone:hover {
    border-color: rgba(37, 99, 235, 0.5);
    box-shadow: 0 0 28px rgba(37, 99, 235, 0.16);
}

html.theme-light .image-upload-zone.drag-over {
    background: rgba(37, 99, 235, 0.12);
}

html.theme-light .upload-icon-wrap {
    border-color: rgba(37, 99, 235, 0.22);
    background: rgba(37, 99, 235, 0.08);
}

html.theme-light .upload-icon-wrap i {
    color: #1d4ed8;
}

html.theme-light .upload-prompt-text {
    color: var(--text-soft);
}

html.theme-light .upload-prompt-sub {
    color: var(--text-subtle);
}

html.theme-light .image-action-btn {
    border-color: rgba(37, 99, 235, 0.3);
    background: rgba(255, 255, 255, 0.92);
    color: #1e293b;
}

html.theme-light .image-action-btn:hover {
    border-color: rgba(37, 99, 235, 0.48);
    background: rgba(37, 99, 235, 0.14);
    color: #0f172a;
    box-shadow: 0 8px 18px rgba(37, 99, 235, 0.16);
}

html.theme-light .image-remove-btn {
    border-color: rgba(220, 38, 38, 0.34);
    background: #fef2f2; /* opaque: it sits on the dark hover overlay */
    color: #991b1b;
}

html.theme-light .image-remove-btn:hover {
    border-color: rgba(220, 38, 38, 0.5);
    background: #fee2e2;
    color: #7f1d1d;
}

html.theme-light .image-preview {
    background: #e2e8f0;
}

html.theme-light .image-cropper-modal {
    background: rgba(15, 23, 42, 0.38);
}

html.theme-light .image-cropper-dialog {
    background: #ffffff;
    border-color: rgba(37, 99, 235, 0.24);
    box-shadow: 0 22px 54px rgba(30, 80, 160, 0.24);
}

html.theme-light .image-cropper-header,
html.theme-light .image-cropper-footer {
    border-color: rgba(37, 99, 235, 0.2);
}

html.theme-light .image-cropper-header h3 {
    color: var(--text-pure);
}

html.theme-light .image-cropper-subtitle {
    color: var(--text-muted);
}

html.theme-light .image-cropper-body {
    background: #edf3fb;
}

@media (max-width: 576px) {
    .image-upload-zone {
        width: 100%;
        max-width: none;
        min-height: 220px;
        aspect-ratio: 4 / 3;
    }

    .image-upload-zone.is-free-ratio {
        aspect-ratio: 16 / 10;
    }

    .image-upload-actions {
        grid-template-columns: 1fr;
        width: min(260px, 100%);
    }

    .image-action-btn {
        width: 100%;
        min-height: 40px;
    }

    .image-preview-overlay {
        opacity: 1;
        pointer-events: auto;
    }

    .image-cropper-modal {
        padding: 0.5rem;
    }

    .image-cropper-dialog {
        width: 100%;
        max-height: 90vh;
    }

    .image-cropper-body {
        min-height: min(38vh, 280px);
        max-height: 44vh;
    }

    .image-cropper-footer {
        justify-content: stretch;
    }

    .image-cropper-footer .znd-btn {
        flex: 1 1 100%;
    }
}

/* ========== CAMERA + ACCESSIBLE REVIEW ========== */

:root {
    --image-dialog-z: 2400;
}

.image-upload-status {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}

.image-upload-zone.has-error .image-upload-status {
    z-index: 5;
    width: auto;
    height: auto;
    clip: auto;
    margin: 0;
    inset: auto 0.65rem 0.65rem;
    padding: 0.55rem 0.7rem;
    border: 1px solid rgba(248, 113, 113, 0.55);
    border-radius: 10px;
    background: rgba(69, 10, 10, 0.94);
    color: #fecaca;
    font-size: 0.75rem;
    white-space: normal;
}

.upload-drag-hint {
    color: var(--text-subtle);
    font-size: 0.7rem;
}

.image-preview-badge {
    position: absolute;
    top: 0.7rem;
    left: 0.7rem;
    z-index: 2;
    padding: 0.35rem 0.55rem;
    border: 1px solid rgba(147, 197, 253, 0.38);
    border-radius: 999px;
    background: rgba(2, 6, 23, 0.78);
    color: #dbeafe;
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    backdrop-filter: blur(8px);
}

.image-upload-zone.has-new-image .image-preview-badge {
    border-color: rgba(52, 211, 153, 0.55);
    color: #a7f3d0;
}

.image-upload-zone.is-wide {
    max-width: 520px;
    aspect-ratio: 3 / 1;
    min-height: 170px;
}

.image-action-btn,
.image-dialog-close,
.image-tool-btn,
.image-camera-footer .znd-btn,
.image-cropper-footer .znd-btn {
    min-height: 44px;
    min-width: 44px;
}

.image-action-btn:focus-visible,
.image-dialog-close:focus-visible,
.image-tool-btn:focus-visible,
.image-camera-footer .znd-btn:focus-visible,
.image-cropper-footer .znd-btn:focus-visible {
    outline: 3px solid #60a5fa;
    outline-offset: 2px;
}

.image-camera-modal,
.image-cropper-modal {
    z-index: var(--image-dialog-z);
}

.image-camera-modal {
    position: fixed;
    inset: 0;
    display: grid;
    place-items: center;
    padding: 1rem;
    background: rgba(2, 6, 23, 0.88);
    backdrop-filter: blur(10px);
}

.image-camera-modal.hidden {
    display: none;
}

.image-camera-dialog {
    display: flex;
    flex-direction: column;
    width: min(760px, calc(100vw - 2rem));
    max-height: min(94dvh, 860px);
    overflow: hidden;
    border: 1px solid var(--glass-border-hover);
    border-radius: 18px;
    background: var(--bg-primary);
    color: var(--text-primary);
    box-shadow: 0 30px 90px rgba(0, 0, 0, 0.48);
}

.image-camera-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    padding: 1rem 1.1rem;
    border-bottom: 1px solid var(--glass-border);
}

.image-camera-header h3 {
    margin: 0;
    color: var(--text-pure);
    font-size: 1rem;
}

.image-camera-header p {
    max-width: 620px;
    margin: 0.35rem 0 0;
    color: var(--text-muted);
    font-size: 0.76rem;
    line-height: 1.55;
}

.image-dialog-close,
.image-tool-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--glass-border-hover);
    border-radius: 11px;
    background: var(--bg-elevated);
    color: var(--text-soft);
    cursor: pointer;
}

.image-camera-body {
    min-height: 0;
    overflow: auto;
    padding: 1rem;
}

.image-camera-stage {
    position: relative;
    display: grid;
    place-items: center;
    width: 100%;
    min-height: 280px;
    max-height: 58dvh;
    overflow: hidden;
    border-radius: 14px;
    background: #020617;
    aspect-ratio: 4 / 3;
}

.image-camera-modal[data-profile="brand_horizontal"] .image-camera-stage,
.image-camera-modal[data-profile="mail_logo"] .image-camera-stage {
    aspect-ratio: 3 / 1;
    min-height: 190px;
}

.image-camera-video,
.image-camera-review {
    width: 100%;
    height: 100%;
    max-height: 58dvh;
    object-fit: contain;
    background: #020617;
}

.image-camera-video.is-mirrored {
    transform: scaleX(-1);
}

.image-camera-loading {
    position: absolute;
    inset: 0;
    z-index: 3;
    display: grid;
    place-content: center;
    justify-items: center;
    gap: 0.65rem;
    background: linear-gradient(145deg, #07111f, #0f172a);
    color: #dbeafe;
}

.image-camera-guide {
    position: absolute;
    inset: 9%;
    z-index: 2;
    pointer-events: none;
    border: 2px solid rgba(255, 255, 255, 0.72);
    border-radius: 18px;
    box-shadow: 0 0 0 999px rgba(2, 6, 23, 0.18);
}

.image-camera-modal[data-profile^="person_"] .image-camera-guide {
    inset: 9% 24%;
    border-radius: 48% 48% 38% 38%;
}

.image-camera-modal[data-profile="brand_horizontal"] .image-camera-guide,
.image-camera-modal[data-profile="mail_logo"] .image-camera-guide {
    inset: 12% 6%;
    border-radius: 10px;
}

.image-camera-error {
    margin-top: 0.75rem;
    padding: 0.75rem 0.85rem;
    border: 1px solid rgba(248, 113, 113, 0.5);
    border-radius: 10px;
    background: rgba(127, 29, 29, 0.24);
    color: #fecaca;
    font-size: 0.8rem;
}

.image-camera-meta {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    margin-top: 0.65rem;
    color: var(--text-subtle);
    font-size: 0.72rem;
}

.image-camera-footer,
.image-cropper-tools {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: 0.55rem;
    padding: 0.85rem 1rem max(0.85rem, env(safe-area-inset-bottom));
    border-top: 1px solid var(--glass-border);
    background: var(--bg-primary);
}

.image-cropper-tools {
    justify-content: center;
    padding: 0.65rem 1rem;
}

.image-tool-btn {
    gap: 0.4rem;
    padding: 0.55rem 0.75rem;
}

body.image-camera-open,
body.image-cropper-open {
    overflow: hidden;
}

html.theme-light .image-camera-modal {
    background: rgba(15, 23, 42, 0.42);
}

html.theme-light .image-camera-dialog {
    border-color: rgba(37, 99, 235, 0.24);
    background: #fff;
    color: #0f172a;
}

html.theme-light .image-camera-header,
html.theme-light .image-camera-footer,
html.theme-light .image-cropper-tools {
    border-color: rgba(37, 99, 235, 0.18);
    background: #fff;
}

html.theme-light .image-dialog-close,
html.theme-light .image-tool-btn {
    border-color: rgba(37, 99, 235, 0.25);
    background: #eff6ff;
    color: #1e3a8a;
}

@media (max-width: 576px) {
    .upload-drag-hint {
        display: none;
    }

    .image-upload-zone.is-wide {
        aspect-ratio: 3 / 1;
        min-height: 150px;
    }

    .image-camera-modal {
        align-items: end;
        padding: 0;
    }

    .image-camera-dialog {
        width: 100%;
        max-height: 100dvh;
        border-radius: 18px 18px 0 0;
    }

    .image-camera-body {
        padding: 0.65rem;
    }

    .image-camera-stage {
        min-height: min(52dvh, 420px);
        max-height: 56dvh;
    }

    .image-camera-modal[data-profile="brand_horizontal"] .image-camera-stage,
    .image-camera-modal[data-profile="mail_logo"] .image-camera-stage {
        min-height: 170px;
    }

    .image-camera-footer {
        position: sticky;
        bottom: 0;
        align-items: stretch;
    }

    .image-camera-footer .znd-btn {
        flex: 1 1 100%;
    }
}

@media (max-height: 520px) and (orientation: landscape) {
    .image-camera-dialog {
        max-height: 100dvh;
    }

    .image-camera-header p,
    .image-camera-meta {
        display: none;
    }

    .image-camera-body {
        padding: 0.45rem 0.75rem;
    }

    .image-camera-stage,
    .image-camera-video,
    .image-camera-review {
        min-height: 0;
        max-height: 52dvh;
    }
}

@media (prefers-reduced-motion: reduce) {
    .image-upload-zone,
    .image-action-btn,
    .image-camera-dialog,
    .image-cropper-dialog {
        transition: none !important;
        animation: none !important;
    }
}
