@import url('https://fonts.googleapis.com/css2?family=Sarabun:wght@300;400;500;700&display=swap');

body {
    font-family: 'Sarabun', sans-serif;
    background-color: #374151; /* Dark gray background outside A4 */
    margin: 0;
    padding: 0;
}

.page-wrapper {
    display: flex;
    justify-content: center;
    align-items: flex-start;
    min-height: 100vh;
    padding: 40px 20px;
    overflow-x: auto;
    background-color: #D3D3D3;
}

.a4-scaler {
    transform-origin: top center;
    transition: transform 0.1s ease-out;
    width: 794px; /* Fixed base width */
    flex-shrink: 0;
}

.a4-page {
    width: 794px;
    height: 1123px;
    position: relative;
    background-color: white;
    box-shadow: 0 25px 50px -12px rgb(0 0 0 / 0.5);
    border: 1px solid #e5e7eb;
    margin: 0 !important;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.a4-background {
    position: absolute;
    inset: 0;
    background-image: url('../template.png');
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    opacity: 0.5;
    z-index: 0;
}

.a4-overlay {
    position: absolute;
    inset: 0;
    background-color: rgba(255, 255, 255, 0.55);
    z-index: 1;
}

.a4-content {
    position: relative;
    z-index: 10;
    padding: 3rem; /* p-12 equivalent for real document padding */
    height: 100%;
    display: flex;
    flex-direction: column;
}

.section-title {
    font-size: 1.1rem;
    font-weight: 700;
    color: #1e3a8a;
    border-bottom: 2px solid #E5E7EB;
    padding-bottom: 0.25rem;
    margin-bottom: 1.25rem;
}

.leaflet-tooltip-custom {
    background: rgba(15, 23, 42, 0.88);
    color: #fff;
    border: none;
    border-radius: 6px;
    padding: 4px 10px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.25);
    pointer-events: none;
}
.leaflet-tooltip-custom::before {
    border-top-color: rgba(15, 23, 42, 0.88);
}

.input-standard {
    width: 100%;
    border-radius: 0.375rem;
    border: 1px solid #d1d5db;
    padding: 0.5rem;
    font-size: 0.875rem;
    background-color: rgba(255, 255, 255, 0.7);
}

.input-standard:focus {
    border-color: #3b82f6;
    outline: 2px solid transparent;
    outline-offset: 2px;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}

/* Float mask styling */
.leaflet-container.transparent-map {
    background: transparent !important;
}

/* Hide any unintended black bounding boxes or extra paths in simple preview */
#mapInline path[stroke="#000000"], 
#mapInline path[stroke="black"],
#mapInline .leaflet-interactive[stroke="#000000"] {
    display: none !important;
}

@media print {
    body {
        background: white !important;
    }
    .page-wrapper {
        padding: 0 !important;
        display: block !important;
        background: none !important;
        overflow: visible !important;
    }
    .a4-scaler {
        transform: scale(1) !important;
        width: 794px !important;
        height: 1123px !important;
        margin: 0 auto !important;
    }
    .a4-page {
        box-shadow: none !important;
        border: none !important;
        height: auto !important;
        min-height: 1123px !important;
    }
    .selected-info-box {
        background: rgba(255, 255, 255, 0.9);
        padding: 6px 10px;
        border-radius: 6px;
        font-size: 11px;
        line-height: 1.4;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
        max-width: 220px;
        border: 1px solid #e2e8f0;
    }
    .no-print {
        display: none !important;
    }
}

/* ===== Mobile Responsive Layout (< 768px) ===== */
@media (max-width: 767px) {
    body {
        background-color: #f3f4f6;
    }

    .page-wrapper {
        padding: 0;
        display: block;
        background-color: #f3f4f6;
        overflow-x: hidden;
    }

    .a4-scaler {
        width: 100% !important;
        transform: none !important;
        height: auto !important;
    }

    .a4-page {
        width: 100% !important;
        height: auto !important;
        min-height: unset !important;
        overflow: visible !important;
        box-shadow: 0 2px 12px rgba(0,0,0,0.08) !important;
        border: none !important;
        border-radius: 0 !important;
    }

    /* แสดง background บนมือถือ */
    .a4-background, .a4-overlay {
        display: block !important;
    }
    .a4-background {
        opacity: 0.5 !important;
    }

    .a4-content {
        padding: 1.25rem !important;
        height: auto !important;
    }

    .section-title {
        font-size: 0.95rem;
    }

    /* ปรับ 3 คอลัมน์ → 1 คอลัมน์บนมือถือ */
    .grid-cols-3 {
        grid-template-columns: repeat(1, minmax(0, 1fr)) !important;
    }

    /* Section 2 map preview */
    #mapInline {
        min-height: 180px !important;
    }

    /* Footer ปุ่ม submit */
    .a4-content footer .flex {
        flex-direction: column;
        gap: 0.75rem;
        align-items: stretch;
    }

    .a4-content footer .flex > div:first-child {
        order: 2;
    }

    .a4-content footer .flex-none,
    .a4-content footer .flex > div:last-child {
        order: 1;
    }

    .a4-content footer button[type="submit"] {
        width: 100%;
        padding-top: 0.625rem;
        padding-bottom: 0.625rem;
    }
}

/* Global Unified Scrollbar Style */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: #f1f1f1; border-radius: 4px; }
::-webkit-scrollbar-thumb { background: #D3D3D3; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #C0C0C0; }
