/* ================================
   PHOTO RESIZER - PI7 STYLE
   ================================ */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, sans-serif;
    background: #f5f5f5;
    min-height: 100vh;
    color: #333;
    line-height: 1.6;
}

.container {
    max-width: 900px;
    margin: 0 auto;
    padding: 20px;
}

/* HEADER */
.header {
    background: linear-gradient(135deg, #4c51bf 0%, #553c9a 100%);
    padding: 30px 0;
    text-align: center;
    color: white;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
}

.logo {
    font-size: 28px;
    margin-bottom: 8px;
    font-weight: 700;
}

.tagline {
    font-size: 14px;
    opacity: 0.9;
}

.nav {
    margin-top: 18px;
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 8px;
}

.nav a {
    color: white;
    text-decoration: none;
    padding: 7px 14px;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    background: rgba(255, 255, 255, 0.1);
}

.nav a:hover {
    background: rgba(255, 255, 255, 0.25);
}

/* INTRO */
.intro-section {
    background: white;
    border-radius: 14px;
    padding: 25px 30px;
    margin: 25px 0;
    text-align: center;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

.intro-section h2 {
    color: #4c51bf;
    font-size: 24px;
    margin-bottom: 10px;
}

.intro-section p {
    color: #718096;
    font-size: 15px;
}

/* COUNTRY CARDS */
.country-section { margin: 35px 0; }

.section-title {
    color: #333;
    font-size: 22px;
    text-align: center;
    margin-bottom: 20px;
    font-weight: 700;
}

.country-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 18px;
}

.country-card {
    background: white;
    border-radius: 14px;
    padding: 22px 18px;
    text-align: center;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

.country-flag { font-size: 48px; margin-bottom: 10px; }
.country-card h4 { font-size: 18px; color: #4c51bf; margin-bottom: 12px; }
.doc-size { font-size: 12px; color: #718096; font-weight: 500; }

/* ========== TOOL BOXES ========== */
.tool-container {
    background: white;
    border-radius: 14px;
    padding: 30px;
    margin: 25px 0;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
}

.tool-title {
    text-align: center;
    font-size: 24px;
    color: #333;
    margin-bottom: 20px;
    font-weight: 700;
}

.tool-title span {
    color: #4c51bf;
}

/* IMAGE BOX */
.tool-box {
    border: 2px solid #4c51bf;
    border-radius: 8px;
    padding: 20px;
    min-height: 200px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #fafbff;
    margin-bottom: 15px;
    cursor: pointer;
    transition: 0.2s;
}

.tool-box:hover {
    background: #f0f4ff;
}

.image-area {
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    min-height: 160px;
}

.empty-state {
    text-align: center;
    color: #667eea;
    font-size: 16px;
    font-weight: 500;
}

.image-area img {
    max-width: 280px;
    max-height: 180px;
    border-radius: 6px;
    display: block;
}

/* CROP & REMOVE ICONS */
.crop-btn-icon, .remove-btn-icon {
    position: absolute;
    top: 5px;
    z-index: 10;
    border: none;
    cursor: pointer;
    font-weight: 600;
    transition: 0.2s;
}

.crop-btn-icon {
    left: 5px;
    background: #4c51bf;
    color: white;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 12px;
}

.crop-btn-icon:hover {
    background: #3c40a0;
}

.remove-btn-icon {
    right: 5px;
    background: #dc2626;
    color: white;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.remove-btn-icon:hover {
    background: #b91c1c;
}

/* FILE NAME */
.file-name {
    text-align: center;
    font-size: 13px;
    color: #555;
    margin-bottom: 15px;
    min-height: 20px;
    word-break: break-all;
}

/* BADGES */
.badges {
    display: flex;
    justify-content: center;
    gap: 15px;
    margin-bottom: 15px;
}

.badge {
    background: #f0f0f0;
    color: #555;
    padding: 4px 14px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 600;
}

/* INPUT ROW */
.input-row {
    display: flex;
    justify-content: center;
    align-items: flex-end;
    gap: 15px;
    margin-bottom: 15px;
    flex-wrap: wrap;
}

.input-group {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.input-group label {
    font-size: 12px;
    color: #555;
    font-weight: 600;
    margin-bottom: 5px;
}

.input-group input {
    width: 100px;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 16px;
    text-align: center;
    font-weight: 600;
}

.input-group input:focus {
    outline: none;
    border-color: #4c51bf;
}

.x-sign {
    font-size: 20px;
    font-weight: 700;
    color: #555;
    padding-bottom: 8px;
}

/* SIZE ROW */
.size-row {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
    margin-bottom: 20px;
}

.size-row label {
    font-size: 15px;
    font-weight: 600;
    color: #333;
}

.size-row input {
    width: 100px;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 16px;
    text-align: center;
    font-weight: 600;
}

.size-row input:focus {
    outline: none;
    border-color: #4c51bf;
}

.kb-label {
    background: #555;
    color: white;
    padding: 10px 14px;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 600;
}

/* RESIZE BUTTON */
.resize-btn {
    display: block;
    width: 100%;
    max-width: 280px;
    margin: 0 auto 15px;
    padding: 14px;
    background: #4c51bf;
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
    transition: 0.2s;
}

.resize-btn:hover:not(:disabled) {
    background: #3c40a0;
    transform: translateY(-2px);
}

.resize-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* DOWNLOAD BUTTON */
.download-btn {
    display: block;
    width: 100%;
    max-width: 280px;
    margin: 0 auto;
    padding: 14px;
    background: #16a34a;
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
    transition: 0.2s;
}

.download-btn:hover {
    background: #15803d;
    transform: translateY(-2px);
}

/* CARD */
.card {
    background: white;
    border-radius: 12px;
    padding: 25px;
    margin: 20px 0;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

.card h2 {
    font-size: 18px;
    color: #4a5568;
    margin-bottom: 15px;
    font-weight: 600;
}

/* FOOTER */
.footer {
    text-align: center;
    color: #555;
    padding: 20px 0;
    font-size: 13px;
}

/* CROP MODAL */
.crop-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    z-index: 1000;
    justify-content: center;
    align-items: center;
    padding: 20px;
}

.crop-modal.active {
    display: flex;
}

.crop-modal-content {
    background: white;
    border-radius: 14px;
    padding: 20px;
    max-width: 90vw;
    max-height: 95vh;
    display: flex;
    flex-direction: column;
    gap: 15px;
    overflow: auto;
}

.crop-modal-content h3 {
    color: #4c51bf;
    font-size: 20px;
}

.crop-canvas-wrapper {
    position: relative;
    background: #2d3748;
    border-radius: 10px;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 400px;
}

.crop-canvas-wrapper canvas {
    max-width: 100%;
    max-height: 70vh;
    display: block;
    cursor: crosshair;
    touch-action: none;
    border-radius: 8px;
}

.crop-controls {
    display: flex;
    gap: 10px;
    justify-content: center;
}

.crop-controls button {
    padding: 10px 20px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    border: none;
}

.crop-controls .btn-save {
    background: #4c51bf;
    color: white;
}

.crop-controls .btn-cancel {
    background: #edf2f7;
    color: #4a5568;
}

/* MOBILE */
@media (max-width: 600px) {
    .logo { font-size: 22px; }
    .tool-container { padding: 20px 15px; }
    .tool-title { font-size: 20px; }
    .country-grid { grid-template-columns: 1fr 1fr; gap: 12px; }
    .country-flag { font-size: 36px; }
    .crop-canvas-wrapper { min-height: 300px; }
    .input-row { gap: 10px; }
    .input-group input { width: 80px; }
}


/* ========== IMAGE AREA (Photo/Signature Box) ========== */
.image-area img {
    max-width: 280px;
    max-height: 180px;
    width: auto;
    height: auto;
    object-fit: contain;
    border-radius: 6px;
    display: block;
}

.image-area {
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    min-height: 160px;
    max-height: 200px;
    overflow: hidden;
}

.tool-box {
    max-height: 240px;
    overflow: hidden;
}

/* MOBILE */
@media (max-width: 600px) {
    .image-area img {
        max-width: 220px;
        max-height: 140px;
    }
    .tool-box {
        max-height: 200px;
    }
}


/* ========== MERGE GRID (PI7 STYLE) ========== */
.merge-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    justify-content: center;
    padding: 15px;
    background: #f8f9ff;
    border: 2px dashed #667eea;
    border-radius: 12px;
    margin-bottom: 20px;
    min-height: 160px;
    max-height: 500px;
    overflow-y: auto;
}

.merge-item {
    position: relative;
    background: white;
    border: 2px solid #4c51bf;
    border-radius: 8px;
    padding: 6px;
    width: 200px;
    height: 160px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    transition: 0.2s;
    flex-shrink: 0;
}

.merge-item:hover {
    box-shadow: 0 4px 12px rgba(76, 81, 191, 0.2);
}

.merge-item img {
    max-width: 100%;
    max-height: 100px;
    width: auto;
    height: auto;
    object-fit: contain;
    border-radius: 4px;
    display: block;
}

.merge-item .crop-btn {
    position: absolute;
    top: 5px;
    left: 5px;
    background: #4c51bf;
    color: white;
    border: none;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 10px;
    font-weight: 600;
    cursor: pointer;
    z-index: 10;
}

.merge-item .crop-btn:hover {
    background: #3c40a0;
}

.merge-item .remove-btn {
    position: absolute;
    top: 5px;
    right: 5px;
    background: #dc2626;
    color: white;
    border: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
}

.merge-item .remove-btn:hover {
    background: #b91c1c;
}

.merge-item .file-name {
    font-size: 9px;
    color: #718096;
    margin-top: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    width: 100%;
    text-align: center;
}

/* ADD PHOTO BOX */
.add-photo-inner {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    cursor: pointer;
    color: #667eea;
    border-radius: 6px;
}

.add-photo-inner:hover {
    background: #f0f4ff;
}

/* MERGE CANVAS (PREVIEW) */
#mergeCanvas {
    max-width: 100%;
    max-height: 400px;
    border-radius: 6px;
    display: block;
    margin: 0 auto;
}

#mergePreviewBox {
    background: #f7fafc;
    border: 2px dashed #cbd5e0;
    border-radius: 8px;
    padding: 15px;
    text-align: center;
    overflow: hidden;
}

/* MOBILE */
@media (max-width: 600px) {
    .merge-item {
        width: 140px;
        height: 130px;
    }
    .merge-item img {
        max-height: 80px;
    }
    #mergeCanvas {
        max-height: 250px;
    }
}


/* ========== PHOTO COMPRESSOR ========== */
#compressBtn, #compressDownloadBtn {
    display: block;
    width: 100%;
    max-width: 280px;
    margin: 12px auto 0;
    padding: 14px;
    border-radius: 8px;
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
    border: none;
    transition: 0.2s;
}

#compressBtn {
    background: #4c51bf;
    color: white;
}

#compressBtn:hover:not(:disabled) {
    background: #3c40a0;
    transform: translateY(-2px);
}

#compressBtn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    background: #a0aec0;
}

#compressDownloadBtn {
    background: #16a34a;
    color: white;
}

#compressDownloadBtn:hover:not(:disabled) {
    background: #15803d;
    transform: translateY(-2px);
}

#compressDownloadBtn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    background: #a0aec0;
}

#compressPreview {
    max-width: 100%;
    max-height: 300px;
    border-radius: 6px;
    display: block;
    margin: 0 auto;
}

#compressStatus {
    color: #718096;
    font-size: 14px;
    margin-top: 10px;
    text-align: center;
    font-weight: 500;
}

/* COMPRESS BOX */
.compress-preview-box {
    background: #f7fafc;
    border: 2px dashed #cbd5e0;
    border-radius: 8px;
    padding: 20px;
    text-align: center;
    min-height: 200px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    margin-bottom: 15px;
}

/* MOBILE */
@media (max-width: 600px) {
    #compressBtn, #compressDownloadBtn {
        max-width: 100%;
    }
    #compressPreview {
        max-height: 200px;
    }
}