/* ══ RESET ══════════════════════════════════════ */
:root {
    --accent:       #2563eb;
    --green:        #10b981;
    --text-main:    #1f2937;
    --text-muted:   #6b7280;
    --border:       #e5e7eb;
    --glass:        rgba(255,255,255,.50);
    --glass-border: rgba(255,255,255,.70);
    --panel-glass:  rgba(255,255,255,.25);
    --panel-blur:   blur(25px) saturate(200%);
    --panel-border: 1px solid rgba(255,255,255,.4);
    --m-accent:     #111827;
    --m-bg:         linear-gradient(135deg,#f3f4f6 0%,#e5e7eb 50%,#d1d5db 100%);
}
*, *::before, *::after { box-sizing: border-box; }
body {
    margin: 0;
    -webkit-touch-callout: none;
}
input, select, textarea { font-family: inherit; }

/* Заборона виділення тексту на десктопі */
#desktop {
    -webkit-user-select: none;
    user-select: none;
}
#desktop input,
#desktop select,
#desktop textarea {
    -webkit-user-select: text;
    user-select: text;
}

/* ══ SHARED A4 PAGE ══════════════════════════════ */
.a4-page {
    width: 210mm;
    height: 297mm;
    background: white;
    padding: 15mm 15mm 15mm 20mm;
    font-family: "Times New Roman", serif;
    color: #000;
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
    overflow: hidden;
}

.a4-header {
    text-align: center;
    margin-bottom: 8mm;
    flex-shrink: 0;
}
.a4-header-title {
    font-size: 16pt;
    font-weight: bold;
    font-family: "Times New Roman", serif;
    display: block;
    margin-bottom: 2mm;
}
.a4-header-sub {
    font-size: 12pt;
    font-family: "Times New Roman", serif;
    margin: 0 0 2mm 0;
}
.a4-header-addr {
    font-size: 11pt;
    font-family: "Times New Roman", serif;
    margin: 0;
    white-space: pre-wrap;
}

.a4-photos-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: space-evenly;
    min-height: 0;
    overflow: hidden;
    gap: 2mm;
}
.a4-photo-block {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    min-height: 0;
    flex: 1 1 0;
    overflow: hidden;
}
.a4-photo-block + .a4-photo-block { margin-top: 0; }

.a4-photo-wrap {
    width: 100%;
    flex: 1 1 0;
    min-height: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    position: relative;
}

.a4-photos-area.single {
    justify-content: flex-start;
    align-items: center;
    flex: 1;
    gap: 0;
}
.a4-photos-area.single .a4-photo-block {
    flex: 0 0 auto;
    width: 100%;
    max-height: 60%;
    height: auto;
    margin: 0;
    display: flex;
    flex-direction: column;
}
.a4-photos-area.single .a4-photo-wrap {
    flex: 1;
    min-height: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}
.a4-photos-area.single .a4-photo-img {
    max-height: 100%;
    max-width: 100%;
    width: auto;
    height: auto;
    object-fit: contain;
    display: block;
}

.a4-photo-img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    display: block;
    flex-shrink: 0;
}
.a4-photo-img.rotated-90 {
    max-width: none;
    max-height: none;
}

.a4-photo-caption {
    font-size: 12pt;
    font-family: "Times New Roman", serif;
    text-align: center;
    margin: 2mm 0 0 0;
    white-space: pre-wrap;
    line-height: 1.3;
    flex-shrink: 0;
}

.a4-photos-area.no-header { flex: 1; }

/* ══ TOGGLE SWITCH ══════════════════════════════ */
.tog-wrap {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    border-radius: 14px;
    background: rgba(255,255,255,.45);
    border: 1px solid rgba(255,255,255,.65);
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
}
.tog-label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-main);
}
.tog-switch {
    width: 40px;
    height: 24px;
    border-radius: 12px;
    background: #d1d5db;
    position: relative;
    transition: background .25s;
    flex-shrink: 0;
}
.tog-switch::after {
    content: '';
    position: absolute;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #fff;
    top: 3px;
    left: 3px;
    transition: transform .25s, box-shadow .25s;
    box-shadow: 0 1px 3px rgba(0,0,0,.25);
}
.tog-wrap.active .tog-switch { background: var(--accent); }
.tog-wrap.active .tog-switch::after { transform: translateX(16px); }

/* ══ SEGMENTED CONTROL ══════════════════════════ */
.seg-ctrl {
    display: flex;
    background: rgba(0,0,0,.07);
    border-radius: 11px;
    padding: 3px;
    gap: 2px;
}
.seg-btn {
    flex: 1;
    text-align: center;
    padding: 6px 8px;
    border-radius: 8px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    cursor: pointer;
    transition: background .2s, color .2s, box-shadow .2s;
    white-space: nowrap;
}
.seg-btn.active {
    background: #fff;
    color: var(--text-main);
    box-shadow: 0 1px 4px rgba(0,0,0,.15);
}

/* ══ SIGN EXTRA PANEL ═══════════════════════════ */
.sign-extra {
    margin-top: 8px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    animation: fadeSlide .2s ease;
}
@keyframes fadeSlide {
    from { opacity: 0; transform: translateY(-6px); }
    to   { opacity: 1; transform: translateY(0); }
}

.a4-page-num {
    text-align: right;
    font-size: 10pt;
    font-family: "Times New Roman", serif;
    margin-top: 4mm;
    flex-shrink: 0;
}

.a4-signature-row {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    font-size: 11pt;
    font-family: "Times New Roman", serif;
    margin-top: 0.5mm;
    flex-shrink: 0;
}
.a4-page.signature-spacing-normal .a4-signature-row { margin-top: 6mm; }
.a4-page.signature-spacing-large  .a4-signature-row { margin-top: 12mm; }
.a4-sign-left  { text-align: left; white-space: pre-wrap; flex: 1; }
.a4-sign-center {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
}
.a4-sign-line { width: 35mm; border-bottom: 1px solid #000; }
.a4-sign-right {
    text-align: right;
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 1mm;
    white-space: nowrap;
}

/* ══ DESKTOP (>= 768px) ══════════════════════════ */
#desktop {
    display: none;
    height: 100vh;
    overflow: hidden;
    background: var(--m-bg);
    background-attachment: fixed;
    color: var(--text-main);
    font-family: -apple-system, system-ui, sans-serif;
}
.d-wrap  { display: flex; height: 100vh; overflow: hidden; }

.d-side  {
    width: 420px;
    background: rgba(255,255,255,.35);
    backdrop-filter: blur(25px) saturate(200%);
    -webkit-backdrop-filter: blur(25px) saturate(200%);
    border-right: 1px solid rgba(255,255,255,.5);
    display: flex;
    flex-direction: column;
    z-index: 10;
}
.d-header {
    padding: 16px 20px;
    border-bottom: 1px solid rgba(255,255,255,.4);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
}
.d-content { flex: 1; overflow-y: auto; padding: 20px; }

.d-preview {
    flex: 1;
    background: rgba(55,65,81,.6);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    padding: 16px 16px 0 16px;
}
#d-a4-wrap {
    display: grid;
    grid-template-columns: 794px 794px;
    gap: 20px;
    transform-origin: top left;
}
.d-preview .a4-page { box-shadow: 0 15px 50px rgba(0,0,0,.4); flex-shrink: 0; }

.d-group { margin-bottom: 15px; }
.d-lbl   {
    font-size: 9px;
    font-weight: 800;
    color: var(--text-muted);
    text-transform: uppercase;
    margin-bottom: 5px;
    display: block;
    padding-left: 4px;
}
.d-group input, .d-group select, .d-group textarea {
    width: 100%;
    padding: 11px 14px;
    border: 1px solid rgba(255,255,255,.6);
    border-radius: 14px;
    font-size: 14px;
    background: rgba(255,255,255,.5);
    color: var(--text-main);
    outline: none;
}
.d-group textarea { resize: vertical; min-height: 50px; }

.d-card {
    background: rgba(255,255,255,.4);
    border: 1px solid rgba(255,255,255,.6);
    border-radius: 18px;
    padding: 15px;
    margin-bottom: 15px;
}
.d-card-hdr {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}
.d-card-title {
    background: transparent;
    border: none;
    font-weight: 700;
    width: 80%;
    font-size: 14px;
    border-bottom: 1px solid rgba(0,0,0,.1);
    outline: none;
    color: var(--text-main);
    resize: none;
    overflow: hidden;
    line-height: 1.4;
    padding: 0;
    font-family: inherit;
}
.d-photo-grid {
    display: grid;
    grid-template-columns: repeat(4,1fr);
    gap: 6px;
    margin-top: 10px;
}
.d-photo-item {
    aspect-ratio: 1;
    border-radius: 10px;
    position: relative;
    overflow: hidden;
    background: rgba(0,0,0,.07);
    border: 1px solid rgba(255,255,255,.5);
    cursor: pointer;
    transition: transform .25s ease, filter .25s ease, opacity .25s ease;
}
.d-photo-item img { width: 100%; height: 100%; object-fit: cover; pointer-events: none; }
.d-photo-grid.has-active .d-photo-item:not(.active) {
    transform: scale(0.88);
    filter: blur(2px) brightness(0.7);
    opacity: 0.6;
}
.d-photo-grid.has-active .d-photo-item.active {
    transform: scale(1.08);
    z-index: 5;
    filter: none !important;
    opacity: 1 !important;
}
.d-add-photo {
    border: 1px dashed rgba(107,114,128,.5);
    border-radius: 12px;
    padding: 12px;
    text-align: center;
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    transition: background .2s, border-color .2s, color .2s;
}
.d-add-photo.drag-over {
    background: rgba(37,99,235,.10);
    border-color: var(--accent);
    color: var(--accent);
}

.btn-blue {
    background: var(--m-accent);
    color: #fff;
    border: none;
    padding: 9px 18px;
    border-radius: 12px;
    font-weight: 700;
    font-size: 13px;
    cursor: pointer;
}
.btn-green {
    background: rgba(255,255,255,.3);
    color: var(--text-main);
    border: 1px solid rgba(255,255,255,.5);
    padding: 9px 18px;
    border-radius: 12px;
    font-weight: 700;
    font-size: 13px;
    cursor: pointer;
}

.d-modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.35);
    backdrop-filter: blur(6px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 200;
}
.d-modal-box {
    background: rgba(255,255,255,.6);
    backdrop-filter: blur(25px) saturate(200%);
    -webkit-backdrop-filter: blur(25px) saturate(200%);
    border: 1px solid rgba(255,255,255,.7);
    padding: 25px;
    border-radius: 20px;
    width: 350px;
}
.d-modal-box input {
    width: 100%;
    padding: 11px 14px;
    border: 1px solid rgba(255,255,255,.6);
    border-radius: 14px;
    font-size: 14px;
    background: rgba(255,255,255,.5);
    margin-bottom: 15px;
    outline: none;
}

/* Desktop прогрес */
.d-load-bar-wrap {
    width: 100%;
    height: 3px;
    background: rgba(37,99,235,.15);
    border-radius: 2px;
    margin-top: 6px;
    overflow: hidden;
    display: none;
}
.d-load-bar {
    height: 100%;
    background: var(--accent);
    border-radius: 2px;
    transition: width .2s ease;
    width: 0%;
}
.d-load-count {
    font-size: 11px;
    color: var(--accent);
    font-weight: 700;
    margin-top: 3px;
    display: none;
}

/* ══ MOBILE (< 768px) ═══════════════════════════ */
#mobile {
    display: none;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    background: var(--m-bg);
    background-attachment: fixed;
    color: var(--text-main);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    flex-direction: column;
    box-sizing: border-box;
}
#mobile * {
    -webkit-tap-highlight-color: transparent;
    -webkit-user-select: none;
    user-select: none;
}
#mobile input,
#mobile select,
#mobile textarea {
    -webkit-user-select: text;
    user-select: text;
}

.m-spacer { height: env(safe-area-inset-top, 16px); min-height: 16px; flex-shrink: 0; }

.m-slider {
    flex: 1;
    display: flex;
    width: 200%;
    will-change: transform;
    transform: translateX(0);
}
.m-slide {
    width: 50%;
    height: 100vh;
    height: 100dvh;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    display: flex;
    flex-direction: column;
    padding: 0 16px 110px 16px;
}
.m-inner { max-width: 500px; margin: 0 auto; width: 100%; }

.m-group { margin-bottom: 14px; }
.m-lbl   {
    font-size: 9px;
    font-weight: 800;
    color: var(--text-muted);
    text-transform: uppercase;
    margin-bottom: 5px;
    display: block;
    padding-left: 8px;
}
.m-group input, .m-group select, .m-group textarea {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    font-size: 16px;
    background: var(--glass);
    color: var(--text-main);
    outline: none;
    resize: none;
}

.m-card {
    border-radius: 20px;
    padding: 16px;
    margin-bottom: 16px;
    background: rgba(255,255,255,.4);
    border: 1px solid var(--glass-border);
}
.m-card-hdr {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 12px;
    gap: 10px;
}
.m-card-title {
    background: transparent;
    border: none;
    font-weight: 700;
    width: 70%;
    color: var(--text-main);
    outline: none;
    font-size: 15px;
    padding: 4px 0;
    border-radius: 0;
    min-height: 24px;
    border-bottom: 1px solid rgba(0,0,0,.05);
    resize: none;
}

.m-photo-grid {
    display: grid;
    grid-template-columns: repeat(3,1fr);
    gap: 8px;
    margin-top: 12px;
    min-height: 10px;
}
.m-photo-item {
    aspect-ratio: 1;
    border-radius: 18px;
    position: relative;
    overflow: hidden;
    background: rgba(0,0,0,.05);
    display: flex;
    align-items: center;
    justify-content: center;
    touch-action: pan-y;
    cursor: pointer;
    transition: transform .25s ease, filter .25s ease, opacity .25s ease;
}
.m-photo-item.sortable-ghost { opacity: .35; transform: scale(.93); }
.m-photo-item img { width: 100%; height: 100%; object-fit: contain; pointer-events: none; }
.m-del {
    position: absolute;
    top: 4px;
    right: 4px;
    background: #fff;
    border: none;
    color: #ef4444;
    border-radius: 50%;
    width: 22px;
    height: 22px;
    font-size: 14px;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}
.m-photo-grid.has-active .m-photo-item:not(.active) {
    transform: scale(0.85);
    filter: blur(2px) brightness(0.65);
    opacity: 0.55;
}
.m-photo-grid.has-active .m-photo-item.active {
    transform: scale(1.1);
    z-index: 5;
    filter: none !important;
    opacity: 1 !important;
}
.m-add-btn {
    border: 1px dashed var(--text-muted);
    border-radius: 15px;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-weight: 600;
    font-size: 12px;
    transition: background .2s, border-color .2s, color .2s;
}
.m-add-btn.loading {
    pointer-events: none;
    border-color: var(--accent);
    color: var(--accent);
    gap: 8px;
}

/* ── Прогрес-бар завантаження ── */
.m-load-bar-wrap {
    width: 100%;
    height: 4px;
    background: rgba(37,99,235,.15);
    border-radius: 2px;
    margin-top: 10px;
    overflow: hidden;
    display: none;
}
.m-load-bar {
    height: 100%;
    background: var(--accent);
    border-radius: 2px;
    transition: width .2s ease;
    width: 0%;
}
.m-load-count {
    font-size: 11px;
    font-weight: 700;
    color: var(--accent);
    text-align: center;
    margin-top: 4px;
    display: none;
}

@keyframes spin { to { transform: rotate(360deg); } }
.m-spinner {
    width: 14px; height: 14px;
    border: 2px solid rgba(37,99,235,.25);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin .7s linear infinite;
    flex-shrink: 0;
}

#m-preview-slide {
    background: #374151;
    padding: 16px 16px 0 16px !important;
    align-items: flex-start;
    height: 100vh !important;
    height: 100dvh !important;
    padding-bottom: 20px !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
}
.m-a4-wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    transform-origin: top center;
}
#m-preview-slide .a4-page {
    box-shadow: none;
    margin: 0 auto 0;
    flex-shrink: 0;
    border-bottom: 2px solid #000;
}
#m-preview-slide .a4-page:last-child { border-bottom: none; }

.m-nav {
    position: fixed;
    bottom: 16px;
    left: 20px;
    right: 20px;
    height: 50px;
    border-radius: 25px;
    display: flex;
    justify-content: space-around;
    align-items: center;
    z-index: 100;
    background: var(--panel-glass);
    backdrop-filter: var(--panel-blur);
    box-shadow: 0 4px 24px rgba(0,0,0,.18);
}
.m-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: #94a3b8;
    font-size: 9px;
    gap: 2px;
    font-weight: 700;
    cursor: pointer;
}
.m-nav-item.active { color: var(--m-accent); }
.m-nav-item svg { width: 18px; height: 18px; }

.m-pdf-btn {
    position: fixed;
    bottom: 82px;
    right: 24px;
    width: 46px;
    height: 46px;
    border-radius: 23px;
    font-weight: 800;
    font-size: 10px;
    color: var(--m-accent);
    background: var(--panel-glass);
    backdrop-filter: var(--panel-blur);
    border: var(--panel-border);
    z-index: 101;
    opacity: 0;
    transform: scale(.5);
    pointer-events: none;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity .3s, transform .3s, bottom .3s ease;
    box-shadow: 0 4px 20px rgba(0,0,0,.18);
    cursor: pointer;
}
.m-sheet {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    background: rgba(0,0,0,.35);
    backdrop-filter: blur(6px);
    opacity: 0;
    pointer-events: none;
    transition: opacity .3s;
}
.m-sheet.open { opacity: 1; pointer-events: auto; }
.m-sheet-inner {
    background: var(--panel-glass);
    backdrop-filter: var(--panel-blur);
    border: var(--panel-border);
    border-radius: 28px 28px 0 0;
    width: 100%;
    max-width: 500px;
    padding: 24px 20px 40px;
}
.m-sheet-inner input {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    font-size: 16px;
    background: var(--glass);
    color: var(--text-main);
    outline: none;
    margin-top: 6px;
}

/* ══ CROP MODAL ═════════════════════════════════ */
#crop-overlay {
    position: fixed; inset: 0; z-index: 500;
    background: #0d0d0f;
    display: flex; flex-direction: column;
    align-items: center; justify-content: flex-start;
    opacity: 0;
    pointer-events: none;
    transition: opacity .3s cubic-bezier(.4,0,.2,1);
}
#crop-overlay.open {
    opacity: 1;
    pointer-events: auto;
}

/* ── Toolbar (desktop top / mobile hidden at top) ── */
#crop-toolbar {
    width: 100%;
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 16px;
    height: 56px;
    flex-shrink: 0;
    color: #fff;
    font-family: -apple-system, system-ui, sans-serif;
    font-size: 14px; font-weight: 600;
    background: rgba(255,255,255,.04);
    border-bottom: 1px solid rgba(255,255,255,.08);
    gap: 12px;
    position: relative;
}
#crop-toolbar > span {
    position: absolute;
    left: 50%; transform: translateX(-50%);
    font-size: 13px;
    font-weight: 700;
    letter-spacing: .2px;
    color: rgba(255,255,255,.7);
    white-space: nowrap;
    pointer-events: none;
}

/* Mobile: hide top toolbar buttons, show bottom action bar */
@media (max-width: 767px) {
    /* Hide top toolbar completely on mobile */
    #crop-toolbar {
        display: none;
    }

    /* Canvas wrap: limit height so image doesn't take full screen */
    #crop-main-area {
        flex-direction: column;
        flex: 0 0 auto;
    }
    #crop-canvas-wrap {
        flex: 0 0 auto;
        height: 55svh;
        width: 100%;
    }

    /* Rotate panel */
    #crop-rotate-panel {
        background: transparent;
        border-top: none;
        padding: 20px 16px 0 16px;
        width: 100%;
        flex-shrink: 0;
    }

    /* Ruler row: [capsule+number] [reset] */
    #crop-rotate-row {
        margin: 0;
        padding: 0;
        gap: 10px;
        background: transparent;
        border-radius: 0;
        overflow: visible;
        height: auto;
        align-items: center;
        display: flex;
    }

    /* Capsule: великий світло-сірий pill — число всередині зліва */
    #crop-ruler-wrap {
        flex: 1;
        height: 64px;
        border-radius: 32px;
        background: rgba(255,255,255,.14);
        overflow: hidden;
        min-width: 0;
        position: relative;
    }

    /* Число — абсолютно всередині капсули, зліва */
    #crop-angle-display {
        position: absolute;
        left: 20px;
        top: 50%;
        transform: translateY(-50%);
        display: flex;
        align-items: center;
        justify-content: center;
        z-index: 2;
        pointer-events: none;
    }
    #crop-angle-val {
        font-size: 22px;
        font-weight: 700;
        min-width: 32px;
        text-align: left;
        color: rgba(255,255,255,.95);
        background: transparent;
        border-radius: 0;
        padding: 0;
        letter-spacing: -0.5px;
        box-shadow: none;
        font-family: -apple-system, system-ui, sans-serif;
    }

    /* Bottom action bar */
    #crop-mobile-actions {
        position: relative;
        display: flex;
        width: 100%;
        align-items: center;
        justify-content: space-between;
        padding: 20px 20px calc(env(safe-area-inset-bottom, 16px) + 16px);
        background: transparent;
        border-top: none;
        flex-shrink: 0;
        margin-top: auto;
    }
    /* Кнопки — широкі pill, як на референсі */
    #crop-mobile-actions .crop-mob-cancel {
        width: 80px;
        height: 56px;
        border-radius: 28px;
        border: none;
        background: rgba(255,255,255,.14);
        color: #fff;
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
        flex-shrink: 0;
        flex: unset;
        outline: none;
        -webkit-tap-highlight-color: transparent;
        -webkit-appearance: none;
        appearance: none;
    }
    #crop-mobile-actions .crop-mob-cancel:active { background: rgba(255,255,255,.22); }
    #crop-mobile-actions .crop-mob-apply {
        width: 80px;
        height: 56px;
        border-radius: 28px;
        border: none;
        background: rgba(255,255,255,.14);
        color: #fff;
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
        flex-shrink: 0;
        flex: unset;
        outline: none;
        -webkit-tap-highlight-color: transparent;
        -webkit-appearance: none;
        appearance: none;
    }
    #crop-mobile-actions .crop-mob-apply:active { background: rgba(255,255,255,.22); }
    #crop-mobile-actions .crop-mob-apply {
        opacity: 0.28;
        pointer-events: none;
    }
    #crop-mobile-actions .crop-mob-apply.dirty {
        background: rgba(235,235,235,.85);
        color: #1a1a1a;
        opacity: 1;
        pointer-events: auto;
    }
}

/* Desktop: show top toolbar buttons, hide bottom bar */
@media (min-width: 768px) {
    #crop-mobile-actions { display: none !important; }
    #crop-cancel-btn { display: flex; align-items: center; }
    #crop-apply-btn  { display: flex; align-items: center; }
}

#crop-cancel-btn {
    padding: 0 16px; height: 36px;
    border: 1px solid rgba(255,255,255,.18);
    border-radius: 10px;
    font-size: 13px; font-weight: 600;
    cursor: pointer;
    background: rgba(255,255,255,.07);
    color: rgba(255,255,255,.85);
    transition: background .18s, border-color .18s;
    flex-shrink: 0;
    outline: none;
    -webkit-tap-highlight-color: transparent;
}
#crop-cancel-btn:hover { background: rgba(255,255,255,.14); border-color: rgba(255,255,255,.3); }
#crop-cancel-btn:active { background: rgba(255,255,255,.08); }

#crop-apply-btn {
    padding: 0 20px; height: 36px;
    border: none; border-radius: 10px;
    font-size: 13px; font-weight: 700;
    cursor: pointer;
    background: rgba(255,255,255,.14);
    color: rgba(255,255,255,.45);
    transition: background .18s, color .18s, box-shadow .18s, transform .12s;
    flex-shrink: 0;
    outline: none;
    -webkit-tap-highlight-color: transparent;
}
#crop-apply-btn.dirty {
    background: rgba(200,200,200,.30);
    color: rgba(255,255,255,1);
    box-shadow: none;
}
#crop-apply-btn.dirty:hover  { background: rgba(200,200,200,.40); }
#crop-apply-btn:active { transform: scale(.96); }

/* ── Canvas area ── */
#crop-main-area {
    flex: 1;
    display: flex;
    flex-direction: row;
    align-items: stretch;
    width: 100%;
    min-height: 0;
    overflow: hidden;
}

#crop-canvas-wrap {
    position: relative;
    flex: 1; width: 100%;
    display: flex; align-items: center; justify-content: center;
    overflow: hidden; user-select: none; touch-action: none;
}
#crop-canvas { display: block; }

/* ── Crop box ── */
/* ── Crop box — без суцільної рамки, тільки кутові дужки ── */
#crop-box {
    position: absolute;
    border: none;
    box-shadow: 0 0 0 9999px rgba(0,0,0,.55);
    cursor: move;
    box-sizing: border-box;
}

/* Сітка 3×3 — тонка, ледь помітна */
#crop-box::before {
    content: ''; position: absolute; inset: 0;
    pointer-events: none;
    background:
        linear-gradient(rgba(255,255,255,.12) 1px, transparent 1px) 0 33.33% / 100% 33.33%,
        linear-gradient(90deg, rgba(255,255,255,.12) 1px, transparent 1px) 33.33% 0 / 33.33% 100%;
}

/* ── Handles ── */
.crop-handle {
    position: absolute;
    box-sizing: border-box;
}

/* Кутові handles — L-подібні дужки через border */
.crop-handle.tl,
.crop-handle.tr,
.crop-handle.bl,
.crop-handle.br {
    width: 22px; height: 22px;
    background: transparent;
}

/* tl — ліво+верх */
.crop-handle.tl {
    top: -1.5px; left: -1.5px;
    border-top: 3px solid #fff;
    border-left: 3px solid #fff;
    border-radius: 2px 0 0 0;
    cursor: nwse-resize;
}
/* tr — право+верх */
.crop-handle.tr {
    top: -1.5px; right: -1.5px;
    border-top: 3px solid #fff;
    border-right: 3px solid #fff;
    border-radius: 0 2px 0 0;
    cursor: nesw-resize;
}
/* bl — ліво+низ */
.crop-handle.bl {
    bottom: -1.5px; left: -1.5px;
    border-bottom: 3px solid #fff;
    border-left: 3px solid #fff;
    border-radius: 0 0 0 2px;
    cursor: nesw-resize;
}
/* br — право+низ */
.crop-handle.br {
    bottom: -1.5px; right: -1.5px;
    border-bottom: 3px solid #fff;
    border-right: 3px solid #fff;
    border-radius: 0 0 2px 0;
    cursor: nwse-resize;
}

/* Бічні handles — невидимі, але залишаємо для drag-функціональності */
.crop-handle.tm,
.crop-handle.bm {
    width: 40px; height: 10px;
    background: transparent;
    left: calc(50% - 20px);
}
.crop-handle.tm { top: -5px; cursor: ns-resize; }
.crop-handle.bm { bottom: -5px; cursor: ns-resize; }

.crop-handle.ml,
.crop-handle.mr {
    width: 10px; height: 40px;
    background: transparent;
    top: calc(50% - 20px);
}
.crop-handle.ml { left: -5px; cursor: ew-resize; }
.crop-handle.mr { right: -5px; cursor: ew-resize; }

/* ── Rotate panel ── */
#crop-rotate-panel {
    width: 100%;
    padding: 8px 16px 14px;
    flex-shrink: 0;
    font-family: -apple-system, system-ui, sans-serif;
    color: #fff;
    background: rgba(255,255,255,.04);
    border-top: 1px solid rgba(255,255,255,.08);
}

/* Angle display — inline left of ruler */
#crop-angle-display {
    display: flex;
    justify-content: center;
    align-items: center;
    flex-shrink: 0;
}
#crop-angle-val {
    font-size: 13px;
    font-weight: 700;
    min-width: 52px;
    text-align: center;
    color: rgba(255,255,255,.9);
    background: rgba(255,255,255,.10);
    border-radius: 8px;
    padding: 4px 8px;
    letter-spacing: .3px;
}

#crop-rotate-row {
    display: flex;
    align-items: center;
    gap: 8px;
    max-width: 800px;
    margin: 0 auto;
}

/* ±90 rotate buttons */
.crop-rot90-btn {
    display: flex; align-items: center; justify-content: center;
    width: 34px; height: 34px;
    background: rgba(255,255,255,.08);
    border: none; border-radius: 9px;
    color: rgba(255,255,255,.7);
    cursor: pointer;
    flex-shrink: 0;
    transition: background .18s, color .18s;
}
.crop-rot90-btn:hover  { background: rgba(255,255,255,.16); color: #fff; }
.crop-rot90-btn:active { background: rgba(255,255,255,.06); transform: scale(.92); }

/* Ruler canvas container */
#crop-ruler-wrap {
    flex: 1;
    height: 44px;
    position: relative;
    cursor: ew-resize;
    overflow: hidden;
    touch-action: none;
}
#crop-ruler {
    display: block;
    width: 100%;
    height: 100%;
}

/* Center indicator line — replaced by thumb, removed */


/* ── Desktop: wider toolbar & panel ── */
@media (min-width: 768px) {
    #crop-toolbar {
        padding: 0 28px;
        height: 60px;
    }
    #crop-toolbar > span { font-size: 14px; }
    #crop-cancel-btn { padding: 0 20px; height: 38px; font-size: 14px; }
    #crop-apply-btn  { padding: 0 26px; height: 38px; font-size: 14px; }

    #crop-rotate-panel { padding: 8px 28px 16px; }
    #crop-ruler-wrap { height: 52px; overflow: hidden; }

    /* Corner handles: трохи менші на ПК — точніший контроль мишею */
    /* Мобайл: кутові дужки трохи більші для пальця */
    .crop-handle.tl,
    .crop-handle.tr,
    .crop-handle.bl,
    .crop-handle.br { width: 26px; height: 26px; }
    .crop-handle.tl { top: -2px; left: -2px; border-width: 3.5px; }
    .crop-handle.tr { top: -2px; right: -2px; border-width: 3.5px; }
    .crop-handle.bl { bottom: -2px; left: -2px; border-width: 3.5px; }
    .crop-handle.br { bottom: -2px; right: -2px; border-width: 3.5px; }

    .crop-handle.tm, .crop-handle.bm { width: 44px; height: 12px; left: calc(50% - 22px); }
    .crop-handle.tm { top: -6px; }
    .crop-handle.bm { bottom: -6px; }
    .crop-handle.ml, .crop-handle.mr { width: 12px; height: 44px; top: calc(50% - 22px); }
    .crop-handle.ml { left: -6px; }
    .crop-handle.mr { right: -6px; }
}

/* ══ CUSTOM INLINE SELECT ═══════════════════════ */
.c-select { position: relative; width: 100%; }
.c-select-trigger {
    width: 100%;
    padding: 11px 40px 11px 14px;
    border: 1px solid rgba(255,255,255,.6);
    border-radius: 14px;
    font-size: 14px;
    background: rgba(255,255,255,.5);
    color: var(--text-main);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-family: inherit;
    box-sizing: border-box;
    -webkit-user-select: none;
    user-select: none;
    transition: border-radius .22s ease, border-color .18s ease;
}
.c-select-trigger:hover { background: rgba(255,255,255,.65); }
.c-select.open .c-select-trigger {
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
    border-bottom-color: rgba(200,200,200,.3);
}
.c-select-arrow {
    width: 18px; height: 18px;
    flex-shrink: 0;
    color: var(--text-muted);
    transition: transform .24s ease;
    pointer-events: none;
}
.c-select.open .c-select-arrow { transform: rotate(180deg); }
.c-select-panel {
    overflow: hidden;
    max-height: 0;
    opacity: 0;
    border: 1px solid rgba(255,255,255,.6);
    border-top: none;
    border-radius: 0 0 14px 14px;
    background: rgba(230,232,235,.9);
    transition: max-height .28s ease, opacity .22s ease;
    margin-top: 0;
}
.c-select.open .c-select-panel { max-height: 320px; opacity: 1; }
.c-select-option {
    padding: 13px 16px;
    font-size: 14px;
    font-family: inherit;
    color: var(--text-main);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}
.c-select-option + .c-select-option { border-top: 1px solid rgba(0,0,0,.06); }
.c-select-option:active { background: rgba(255,255,255,.5); }
.c-select-option.selected { font-weight: 700; }
.c-radio {
    width: 22px; height: 22px;
    border-radius: 50%;
    border: 2px solid rgba(0,0,0,.2);
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background .15s, border-color .15s;
}
.c-select-option.selected .c-radio { background: var(--m-accent); border-color: var(--m-accent); }
.c-radio-dot {
    width: 8px; height: 8px;
    border-radius: 50%;
    background: #fff;
    opacity: 0;
    transform: scale(0);
    transition: opacity .15s, transform .18s ease;
}
.c-select-option.selected .c-radio-dot { opacity: 1; transform: scale(1); }

/* Mobile overrides */
#mobile .c-select-trigger {
    padding: 13px 40px 13px 14px;
    border-radius: 16px;
    font-size: 16px;
    background: var(--glass);
    border-color: var(--glass-border);
}
#mobile .c-select.open .c-select-trigger {
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
}
#mobile .c-select-panel {
    border-radius: 0 0 16px 16px;
    background: rgba(224,226,230,.92);
    border-color: var(--glass-border);
}
#mobile .c-select-option { padding: 15px 18px; font-size: 16px; }

/* ══ PHOTO ACTION POPUP ═════════════════════════ */
#photo-popup {
    position: fixed;
    z-index: 300;
    background: rgba(255,255,255,.28);
    backdrop-filter: blur(32px) saturate(200%);
    -webkit-backdrop-filter: blur(32px) saturate(200%);
    border: 1px solid rgba(255,255,255,.60);
    border-radius: 18px;
    padding: 6px 0;
    min-width: 210px;
    box-shadow: 0 8px 30px rgba(0,0,0,.08);
    opacity: 0;
    transform: scale(.85) translateY(-8px);
    pointer-events: none;
    transition: opacity .2s ease, transform .2s ease;
}
#photo-popup.open {
    opacity: 1;
    transform: scale(1) translateY(0);
    pointer-events: auto;
}
.pp-btn {
    display: flex;
    align-items: center;
    gap: 13px;
    width: 100%;
    padding: 12px 16px;
    background: none;
    border: none;
    color: var(--text-main);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    text-align: left;
    font-family: -apple-system, system-ui, sans-serif;
    transition: background .12s;
}
.pp-btn:hover  { background: rgba(0,0,0,.05); }
.pp-btn:active { background: rgba(0,0,0,.09); }
.pp-btn.danger { color: #dc2626; }
.pp-icon {
    width: 36px;
    height: 36px;
    border-radius: 9px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 15px;
    flex-shrink: 0;
}
.pp-icon.mono { background: rgba(0,0,0,.07); color: var(--text-main); }
.pp-icon.red  { background: rgba(220,38,38,.1); color: #dc2626; }
.pp-divider { height: 1px; background: rgba(0,0,0,.07); margin: 4px 0; }
.pp-rotate-row {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 4px 0 8px;
}
.pp-rot-btn {
    flex: 1;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    color: var(--text-main);
    cursor: pointer;
    transition: background .12s, transform .1s;
    padding: 0;
    border-radius: 8px;
}
.pp-rot-btn:hover  { background: rgba(0,0,0,.04); }
.pp-rot-btn:active { transform: scale(.9); }
.pp-rot-divider {
    width: 1px;
    height: 22px;
    background: rgba(0,0,0,.1);
    flex-shrink: 0;
}

/* ══ CUSTOM CALENDAR PICKER ════════════════════ */
.cal-trigger {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    font-size: 16px;
    background: var(--glass);
    color: var(--text-main);
    outline: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    user-select: none;
    -webkit-user-select: none;
    transition: background .2s, border-color .2s;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
.cal-trigger:active { background: rgba(255,255,255,.7); }
.cal-trigger .cal-trigger-text { flex: 1; text-align: left; }
.cal-trigger svg { flex-shrink: 0; color: var(--text-muted); }

.cal-overlay {
    position: fixed;
    inset: 0;
    z-index: 300;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0,0,0,.35);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    opacity: 0;
    pointer-events: none;
    transition: opacity .22s ease;
    padding: 40px 40px;
}
.cal-overlay.open { opacity: 1; pointer-events: auto; }

.cal-sheet {
    width: 100%;
    max-width: 290px;
    background: rgba(240,241,243,.98);
    backdrop-filter: blur(40px) saturate(180%);
    -webkit-backdrop-filter: blur(40px) saturate(180%);
    border: 1px solid rgba(255,255,255,.6);
    border-radius: 20px;
    padding: 0 0 6px 0;
    transform: scale(.88);
    transition: transform .25s cubic-bezier(.34,1.4,.64,1);
    overflow: hidden;
    box-shadow: 0 16px 48px rgba(0,0,0,.28);
}
.cal-overlay.open .cal-sheet { transform: scale(1); }

.cal-header-strip {
    background: rgba(228,230,233,.98);
    color: var(--text-main);
    padding: 10px 14px 8px;
    border-bottom: 1px solid rgba(0,0,0,.08);
}
.cal-header-year {
    font-size: 11px;
    font-weight: 600;
    opacity: .55;
    margin-bottom: 1px;
    letter-spacing: .4px;
}
.cal-header-date {
    font-size: 18px;
    font-weight: 800;
    letter-spacing: -.4px;
    line-height: 1;
}

/* Desktop: inline dropdown below trigger */
.d-cal-popup {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    right: 0;
    z-index: 400;
    background: rgba(240,241,243,1);
    backdrop-filter: none;
    border: 1px solid rgba(210,212,216,.9);
    border-radius: 14px;
    box-shadow: 0 8px 28px rgba(0,0,0,.2);
    overflow: hidden;
    transform-origin: top center;
    transform: scaleY(.85);
    opacity: 0;
    pointer-events: none;
    transition: transform .2s cubic-bezier(.34,1.4,.64,1), opacity .18s ease;
    width: 220px; /* fixed narrow width instead of stretching to parent */
    right: auto;  /* align left */
}
.d-cal-popup.open { transform: scaleY(1); opacity: 1; pointer-events: auto; }
.d-cal-popup .cal-header-strip { background: rgba(228,230,233,1); padding: 7px 12px 6px; }
.d-cal-popup .cal-header-year { font-size: 10px; }
.d-cal-popup .cal-header-date { font-size: 14px; }
.d-cal-popup .cal-nav { padding: 5px 10px 1px; }
.d-cal-popup .cal-nav-btn { width: 24px; height: 24px; }
.d-cal-popup .cal-weekdays { padding: 0 6px; }
.d-cal-popup .cal-days { padding: 0 6px; gap: 1px; }
.d-cal-popup .cal-day { font-size: 11px; }
.d-cal-popup .cal-nav-title { font-size: 12px; }
.d-cal-popup .cal-wd { font-size: 9px; }
.d-cal-popup .cal-actions { padding: 1px 12px 0; }
.d-cal-popup .cal-action-btn { padding: 6px 0; font-size: 12px; }

.cal-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 7px 12px 2px;
}
.cal-nav-btn {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: none;
    background: rgba(255,255,255,.5);
    backdrop-filter: blur(10px);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background .18s;
    flex-shrink: 0;
}
.cal-nav-btn:active { background: rgba(255,255,255,.85); }
.cal-nav-title {
    font-weight: 800;
    font-size: 13px;
    color: var(--text-main);
    letter-spacing: -.2px;
}
.cal-weekdays {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    padding: 0 8px;
    margin-bottom: 2px;
}
.cal-wd {
    text-align: center;
    font-size: 9px;
    font-weight: 700;
    color: var(--text-muted);
    padding: 3px 0;
    text-transform: uppercase;
    letter-spacing: .4px;
}
.cal-days {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    padding: 0 8px;
    gap: 1px;
}
.cal-day {
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 500;
    border-radius: 50%;
    cursor: pointer;
    transition: background .15s, color .15s;
    -webkit-user-select: none;
    user-select: none;
}
.cal-day:not(.empty):active { background: rgba(17,24,39,.12); }
.cal-day.empty { pointer-events: none; }
.cal-day.today { font-weight: 800; color: #2563eb; }
.cal-day.selected { background: #111827; color: #fff; font-weight: 700; }
.cal-day.today.selected { background: #111827; color: #fff; }
.cal-actions {
    display: flex;
    flex-direction: column;
    padding: 2px 14px 0;
    gap: 0;
}
.cal-action-btn {
    background: transparent;
    border: none;
    padding: 8px 0;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-main);
    cursor: pointer;
    text-align: right;
    border-top: 1px solid rgba(0,0,0,.07);
    transition: opacity .15s;
}
.cal-action-btn:first-child { border-top: none; }
.cal-action-btn.primary { font-weight: 700; }
.cal-action-btn.muted { color: var(--text-muted); }

.d-cal-wrap { position: relative; }
.d-cal-trigger {
    width: 100%;
    padding: 11px 14px;
    border: 1px solid rgba(255,255,255,.6);
    border-radius: 14px;
    font-size: 14px;
    background: rgba(255,255,255,.5);
    color: var(--text-main);
    outline: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    user-select: none;
    -webkit-user-select: none;
    font-family: -apple-system, system-ui, sans-serif;
}
.d-cal-trigger:hover { background: rgba(255,255,255,.7); }

/* ══ PRINT ══════════════════════════════════════ */
@media print {
    @page { size: A4; margin: 0; }
    html, body { width: 210mm !important; margin: 0 !important; padding: 0 !important; overflow: visible !important; background: white !important; }
    #mobile  { display: none !important; }
    #desktop { display: block !important; height: auto !important; overflow: visible !important; background: white !important; }
    .d-wrap  { display: block !important; height: auto !important; }
    .d-side, .d-header, .btn-blue, .btn-green, #d-modal { display: none !important; }
    .d-preview {
        display: block !important; width: 210mm !important;
        margin: 0 auto !important; padding: 0 !important;
        overflow: visible !important; background: white !important;
    }
    #d-a4-wrap {
        display: block !important;
        transform: none !important;
        width: 210mm !important;
        height: auto !important;
        margin: 0 !important;
    }
    .a4-page {
        width: 210mm !important; min-height: 297mm !important; height: 297mm !important;
        margin: 0 !important; padding: 15mm 15mm 15mm 20mm !important;
        background: white !important; box-shadow: none !important; border: none !important;
        overflow: visible !important; display: flex !important; position: relative !important;
        page-break-after: always !important; break-after: page !important;
    }
    .a4-page:last-child { page-break-after: auto !important; }
}

/* ══ CORRECTION PANEL ══════════════════════════ */
.hidden { display: none !important; }

#crop-correct-btn {
    padding: 0 16px; height: 36px;
    border: 1px solid rgba(255,255,255,.25);
    border-radius: 10px;
    font-size: 13px; font-weight: 600;
    cursor: pointer;
    background: rgba(255,255,255,.07);
    color: rgba(255,255,255,.75);
    transition: background .18s, border-color .18s, color .18s;
    flex-shrink: 0;
    outline: none;
    -webkit-tap-highlight-color: transparent;
    font-family: -apple-system, system-ui, sans-serif;
}
#crop-correct-btn:hover  { background: rgba(255,255,255,.14); color: #fff; }
#crop-correct-btn:active { background: rgba(255,255,255,.08); }
#crop-correct-btn.active {
    background: rgba(255,255,255,.22);
    border-color: rgba(255,255,255,.5);
    color: #fff;
}

/* Desktop correction panel — vertical side panel on the right */
#crop-correct-panel {
    width: 280px;
    min-width: 260px;
    flex-shrink: 0;
    padding: 20px 18px 20px 16px;
    background: rgba(255,255,255,.05);
    border-left: 1px solid rgba(255,255,255,.10);
    display: flex;
    flex-direction: column;
    gap: 20px;
    align-items: stretch;
    font-family: -apple-system, system-ui, sans-serif;
    overflow-y: auto;
}

/* Mobile correction panel */
#crop-correct-panel-mob {
    width: 100%;
    padding: 10px 8px 8px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-family: -apple-system, system-ui, sans-serif;
}

.cadj-row {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 10px;
    flex: unset;
    min-width: unset;
    padding: 6px 0;
}
.cadj-row-header { display: none; /* not used anymore */ }
#crop-correct-panel-mob .cadj-row {
    padding: 10px 0;
}
#crop-correct-panel-mob .cadj-lbl {
    width: 56px;
}
.cadj-lbl {
    font-size: 11px; font-weight: 600;
    color: rgba(255,255,255,.60);
    width: 58px;
    flex-shrink: 0;
    letter-spacing: .1px;
}
.cadj-val {
    font-size: 11px; font-weight: 700;
    color: rgba(255,255,255,.65);
    width: 26px; text-align: right;
    flex-shrink: 0;
    font-variant-numeric: tabular-nums;
}
.cadj-row input[type=range] {
    flex: 1;
    width: 100%;
    -webkit-appearance: none; appearance: none;
    height: 3px; border-radius: 2px;
    background: rgba(255,255,255,.25);
    outline: none; cursor: pointer; min-width: 0;
}
.cadj-row input[type=range]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 18px; height: 18px;
    border-radius: 50%; background: #fff;
    box-shadow: 0 1px 4px rgba(0,0,0,.4); cursor: pointer;
}
.cadj-row input[type=range]::-moz-range-thumb {
    width: 18px; height: 18px;
    border-radius: 50%; background: #fff;
    border: none; box-shadow: 0 1px 4px rgba(0,0,0,.4); cursor: pointer;
}
@media (max-width: 767px) {
    .cadj-row input[type=range]::-webkit-slider-thumb { width: 22px; height: 22px; }
}

.cadj-reset-btn {
    padding: 0 14px; height: 30px;
    border: 1px solid rgba(255,255,255,.2);
    border-radius: 8px;
    font-size: 12px; font-weight: 600;
    cursor: pointer;
    background: transparent;
    color: rgba(255,255,255,.55);
    transition: background .15s, color .15s;
    outline: none;
    font-family: -apple-system, system-ui, sans-serif;
    flex-shrink: 0; align-self: center;
}
.cadj-reset-btn:hover  { background: rgba(255,255,255,.10); color: #fff; }
.cadj-reset-btn:active { background: rgba(255,255,255,.05); }

/* Mobile кнопка Корекція */
.crop-mob-correct-btn {
    width: 56px; height: 56px;
    border-radius: 28px; border: none;
    background: rgba(255,255,255,.14);
    color: #fff; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0; outline: none;
    -webkit-tap-highlight-color: transparent;
    -webkit-appearance: none; appearance: none;
    transition: background .18s;
}
.crop-mob-correct-btn:active { background: rgba(255,255,255,.22); }
.crop-mob-correct-btn.active {
    background: rgba(255,255,255,.85);
    color: #1a1a1a;
}

/* Розділення desktop/mobile елементів */
@media (max-width: 767px) {
    #crop-correct-btn   { display: none; }
    #crop-correct-panel { display: none !important; }
}
@media (min-width: 768px) {
    .crop-mob-correct-btn   { display: none; }
    #crop-correct-panel-mob { display: none !important; }
    /* На ПК hidden перекриває flex */
    #crop-correct-panel.hidden { display: none !important; }
}

/* ════════════════════════════════════════════════════════════
   PIXELAPP INTEGRATION — Professional WebGL Editor Overlay
   Замінює старий #crop-overlay
════════════════════════════════════════════════════════════ */

/* Overlay container — fixed fullscreen, above everything */
#pixelapp-overlay {
    position: fixed;
    inset: 0;
    z-index: 10000;
    background: #141414;
    display: flex;
    flex-direction: column;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
}

#pixelapp-overlay.pixelapp-hidden {
    display: none !important;
}

/* Header bar */
.pxa-header {
    flex-shrink: 0;
    height: 56px;
    background: #1c1c1e;
    border-bottom: 1px solid #2c2c2e;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    gap: 12px;
}

.pxa-title {
    display: flex;
    align-items: center;
    gap: 8px;
    color: #8e8e93;
    font-size: 13px;
    font-weight: 600;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

/* Cancel button */
.pxa-btn-cancel {
    display: flex;
    align-items: center;
    gap: 6px;
    background: transparent;
    color: #ff453a;
    border: 1px solid rgba(255, 69, 58, 0.45);
    padding: 8px 14px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
    white-space: nowrap;
}
.pxa-btn-cancel:hover {
    background: rgba(255, 69, 58, 0.12);
    border-color: #ff453a;
}
.pxa-btn-cancel:active { opacity: 0.7; }

/* Apply / Save button */
.pxa-btn-apply {
    display: flex;
    align-items: center;
    gap: 6px;
    background: #0a84ff;
    color: #fff;
    border: none;
    padding: 9px 18px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    transition: background 0.15s, transform 0.1s;
    white-space: nowrap;
    box-shadow: 0 2px 8px rgba(10, 132, 255, 0.35);
}
.pxa-btn-apply:hover { background: #0071e3; }
.pxa-btn-apply:active { transform: scale(0.96); }

/* Main editor body — pis-app fills all remaining space */
.pxa-body {
    flex: 1;
    position: relative;
    overflow: hidden;
    min-height: 0;
}

#pixelapp-editor {
    display: block;
    width: 100%;
    height: 100%;
}

/* Loading spinner overlay (shown while image loads into WebGL) */
.pxa-loading {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
    background: rgba(20, 20, 20, 0.85);
    color: #aeaeb2;
    font-size: 14px;
    pointer-events: none;
    transition: opacity 0.3s;
    z-index: 10;
}

.pxa-loading.pxa-loaded {
    opacity: 0;
}

@keyframes pxa-spin {
    to { transform: rotate(360deg); }
}
.pxa-spinner {
    width: 36px;
    height: 36px;
    border: 3px solid rgba(255, 255, 255, 0.1);
    border-top-color: #0a84ff;
    border-radius: 50%;
    animation: pxa-spin 0.8s linear infinite;
}

/* Mobile: hide title text to save header space */
@media (max-width: 480px) {
    .pxa-title { display: none; }
    .pxa-header { padding: 0 12px; }
    .pxa-btn-cancel,
    .pxa-btn-apply { padding: 8px 12px; font-size: 12px; }
}
