/* ==================== IMAGE POSITIONER MODAL v2.0 - SCROLL FIX ==================== */

/* Tekrarlanan selector grubu için kısaltma:
   .ipm = #imagePositionerModal .modal-content,
          .image-positioner-modal .modal-content,
          .image-positioner-modal .modal-content.large
   Bunları her breakpoint'te tek blokta yazıyoruz. */

/* ==================== MODAL OVERLAY ==================== */
#imagePositionerModal.modal {
    overflow: hidden;
}

/* ==================== MODAL CONTENT ==================== */
#imagePositionerModal .modal-content,
.image-positioner-modal .modal-content {
    width: min(720px, calc(100vw - 16px));
    max-width: min(720px, calc(100vw - 16px));
    max-height: calc(100vh - 16px);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding: 0;
    border-radius: 16px;
}

/* ==================== HEADER ==================== */
#imagePositionerModal .modal-header {
    flex: 0 0 auto;
    padding: 14px 20px;
    border-bottom: 1px solid #e2e8f0;
    background: #f8fafc;
    border-radius: 16px 16px 0 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

#imagePositionerModal .modal-header h3 {
    font-size: 15px;
    font-weight: 600;
    color: #0f172a;
    margin: 0;
    display: flex;
    align-items: center;
    gap: 8px;
}

#imagePositionerModal .modal-close {
    position: static;
    width: 32px;
    height: 32px;
    min-height: 32px;
    background: rgba(239, 68, 68, 0.1);
    border: 2px solid transparent;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}

#imagePositionerModal .modal-close:hover {
    background: #ef4444;
    border-color: #ef4444;
    transform: rotate(90deg);
}

/* ==================== MODAL BODY ==================== */
#imagePositionerModal .modal-body {
    flex: 1 1 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 12px 16px;
    overflow: hidden;
}

/* ==================== TALİMATLAR ==================== */
.positioner-instructions {
    flex: 0 0 auto;
    background: linear-gradient(135deg, #eff6ff, #eef2ff);
    border: 1px solid #bfdbfe;
    border-radius: 10px;
    padding: 8px 14px;
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
    justify-content: center;
}

.positioner-instructions p {
    margin: 0;
    font-size: 12px;
    color: #1e40af;
    display: flex;
    align-items: center;
    gap: 6px;
}

/* ==================== CANVAS CONTAINER ==================== */
.positioner-container {
    flex: 1 1 0;
    min-height: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    background: #f1f5f9;
    border-radius: 10px;
    border: 1px solid #e2e8f0;
}

.canvas-container {
    position: relative;
    width: 100%;
    height: 100%;
    border-radius: 10px;
    overflow: hidden;
    cursor: grab;
    background: #f0f0f0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.canvas-container:active { cursor: grabbing; }

#positionerCanvas {
    display: block;
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    border-radius: 8px;
    cursor: grab;
    touch-action: none;
}

#positionerCanvas:active { cursor: grabbing; }

.crop-overlay {
    position: absolute;
    inset: 0;
    pointer-events: none;
    border: 3px solid #2563eb;
    border-radius: 10px;
    box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.5);
}

.crop-overlay::before,
.crop-overlay::after {
    content: '';
    position: absolute;
    width: 20px;
    height: 20px;
    border: 3px solid #2563eb;
}

.crop-overlay::before {
    top: -3px; left: -3px;
    border-right: none;
    border-bottom: none;
    border-radius: 10px 0 0 0;
}

.crop-overlay::after {
    bottom: -3px; right: -3px;
    border-left: none;
    border-top: none;
    border-radius: 0 0 10px 0;
}

/* ==================== KONTROLLER ==================== */
.positioner-controls {
    flex: 0 0 auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.zoom-control {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 14px;
    background: #f8fafc;
    border-radius: 10px;
    border: 1px solid #e2e8f0;
}

.zoom-control label {
    font-size: 13px;
    font-weight: 600;
    color: #334155;
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 5px;
    flex-shrink: 0;
}

.zoom-control input[type="range"] {
    flex: 1;
    min-width: 0;
    height: 6px;
    border-radius: 3px;
    background: linear-gradient(to right, #3b82f6, #8b5cf6);
    outline: none;
    border: none;
    padding: 0;
    min-height: auto;
    cursor: pointer;
}

.zoom-control input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: white;
    border: 3px solid #2563eb;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
    transition: transform 0.15s;
}

.zoom-control input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.15);
}

.zoom-control input[type="range"]::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: white;
    border: 3px solid #2563eb;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}

#zoomValue {
    font-size: 13px;
    font-weight: 700;
    color: #2563eb;
    min-width: 42px;
    text-align: center;
    background: white;
    padding: 3px 8px;
    border-radius: 6px;
    border: 1px solid #e2e8f0;
    flex-shrink: 0;
}

.position-buttons {
    display: flex;
    gap: 8px;
    flex-wrap: nowrap;
}

.btn-position {
    flex: 1;
    min-width: 0;
    padding: 7px 6px;
    font-size: 11px;
    font-weight: 500;
    border: 2px solid #e2e8f0;
    border-radius: 8px;
    background: white;
    color: #334155;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    white-space: nowrap;
    overflow: hidden;
    font-family: inherit;
    min-height: 34px;
}

.btn-position:hover {
    border-color: #2563eb;
    background: #eff6ff;
    color: #2563eb;
}

.btn-position:active { transform: scale(0.97); }

.btn-position img {
    width: 13px;
    height: 13px;
    flex-shrink: 0;
}

/* ==================== MODAL ACTIONS ==================== */
#imagePositionerModal .modal-actions,
.image-positioner-modal .modal-actions {
    flex: 0 0 auto;
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    padding: 10px 16px;
    border-top: 1px solid #e2e8f0;
    background: #f8fafc;
    border-radius: 0 0 16px 16px;
    margin-top: 0;
}

#imagePositionerModal .modal-actions .btn-secondary,
#imagePositionerModal .modal-actions .btn-primary,
.image-positioner-modal .modal-actions .btn-secondary,
.image-positioner-modal .modal-actions .btn-primary {
    width: auto;
    min-width: 90px;
    padding: 9px 20px;
    min-height: 40px;
    font-size: 13px;
}

/* ==================== ANİMASYON ==================== */
@keyframes fadeInScale {
    from { opacity: 0; transform: scale(0.96); }
    to   { opacity: 1; transform: scale(1); }
}

.image-positioner-modal.active .modal-content {
    animation: fadeInScale 0.25s ease-out;
}

/* ==================== SORU FORMUNDAKİ BUTON ==================== */
#positionImageBtn {
    margin-left: 8px;
    padding: 8px 14px;
    font-size: 13px;
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 38px;
}

#positionImageBtn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

#positionImageBtn img {
    filter: brightness(0) invert(1);
    width: 14px;
    height: 14px;
}

/* ==================== RESİM ÖNİZLEME ==================== */
#imagePreview {
    position: relative;
    margin-top: 12px;
    padding: 10px;
    background: #f8fafc;
    border-radius: 10px;
    border: 2px dashed #cbd5e1;
}

#imagePreview img {
    max-width: 100%;
    max-height: 180px;
    border-radius: 8px;
    display: block;
    margin: 0 auto;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

#imagePreview .btn-remove {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: #ef4444;
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

#imagePreview .btn-remove:hover {
    background: #dc2626;
    transform: scale(1.1);
}

/* ==================== RESİM YÜKLEME CONTAINER ==================== */
.image-upload-container {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    margin-top: 8px;
}

/* ==================== RESPONSIVE ==================== */

/* Tablet (≥ 600px) */
@media (min-width: 600px) {
    #imagePositionerModal .modal-content,
    .image-positioner-modal .modal-content {
        width: min(720px, calc(100vw - 24px));
        max-width: min(720px, calc(100vw - 24px));
        max-height: calc(100vh - 24px);
    }

    .btn-position {
        font-size: 12px;
        padding: 8px;
        gap: 5px;
        min-height: 36px;
    }

    .btn-position img { width: 14px; height: 14px; }
}

/* Desktop (≥ 1024px) */
@media (min-width: 1024px) {
    #imagePositionerModal .modal-content,
    .image-positioner-modal .modal-content {
        width: 720px;
        max-width: calc(100vw - 40px);
        height: min(700px, calc(100vh - 40px));
        max-height: min(700px, calc(100vh - 40px));
    }

    .btn-position {
        font-size: 13px;
        padding: 9px 10px;
        gap: 6px;
        min-height: 38px;
    }

    .btn-position img { width: 15px; height: 15px; }
    .positioner-instructions p { font-size: 13px; }
}

/* Küçük ekran — tam ekran (≤ 380px) */
@media (max-width: 380px) {
    #imagePositionerModal .modal-content,
    .image-positioner-modal .modal-content {
        width: 100vw;
        max-width: 100vw;
        max-height: 100vh;
        height: 100vh;
        border-radius: 0;
    }

    #imagePositionerModal .modal-header {
        border-radius: 0;
        padding: 10px 12px;
    }

    #imagePositionerModal .modal-actions,
    .image-positioner-modal .modal-actions {
        border-radius: 0;
        padding: 8px 12px;
    }

    #imagePositionerModal .modal-body {
        padding: 8px 10px;
        gap: 6px;
    }

    .positioner-instructions { padding: 6px 10px; gap: 6px; }
    .positioner-instructions p { font-size: 10px; }

    .position-buttons {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 5px;
    }

    .btn-position { font-size: 10px; padding: 6px 4px; min-height: 30px; }

    .zoom-control { padding: 6px 10px; gap: 8px; }
    .zoom-control label { font-size: 11px; }

    #zoomValue { font-size: 11px; min-width: 34px; padding: 2px 6px; }

    .image-upload-container { flex-direction: column; align-items: stretch; }
    .image-upload-container button { width: 100%; justify-content: center; }
    #positionImageBtn { margin-left: 0; }
}

/* Yatay mod — landscape telefon */
@media (max-height: 500px) and (orientation: landscape) {
    #imagePositionerModal .modal-content,
    .image-positioner-modal .modal-content {
        height: 100vh;
        max-height: 100vh;
        border-radius: 0;
    }

    .positioner-instructions { display: none; }

    #imagePositionerModal .modal-header {
        padding: 7px 14px;
        border-radius: 0;
    }

    #imagePositionerModal .modal-header h3 { font-size: 13px; }

    #imagePositionerModal .modal-body {
        padding: 5px 10px;
        gap: 5px;
    }

    .zoom-control { padding: 4px 10px; }
    .position-buttons { gap: 5px; }
    .btn-position { min-height: 28px; font-size: 10px; padding: 4px 5px; }

    #imagePositionerModal .modal-actions,
    .image-positioner-modal .modal-actions {
        padding: 6px 10px;
        border-radius: 0;
    }

    #imagePositionerModal .modal-actions .btn-secondary,
    #imagePositionerModal .modal-actions .btn-primary,
    .image-positioner-modal .modal-actions .btn-secondary,
    .image-positioner-modal .modal-actions .btn-primary {
        min-height: 32px;
        padding: 5px 14px;
        font-size: 12px;
    }
}