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

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html,
body {
    font-family: 'Sarabun', sans-serif;
    height: 100%;
    margin: 0;
    padding: 0;
    overflow: hidden; /* ป้องกัน scroll bar ของตัว body เอง */
}

body {
    font-weight: 400;
}

.header,
th {
    font-weight: 600;
}

/* =========================
   ROOT GRID
========================= */

.app {
    height: 100vh;
    display: grid;
    grid-template-rows:
        minmax(90px, 10vh) 1fr;
    min-height: 0;
}

.header {
    display: flex;
    align-items: center;
    padding: 0 30px;
    background: linear-gradient(135deg, #83c5be 0%, #006d77 50%, #004d4d 100%);
    border-bottom: 1px solid rgba(255, 255, 255, 0.25);
    box-shadow: 0 8px 24px rgba(0, 77, 77, 0.2);
    position: relative;
    gap: 40px;
    z-index: 1000;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 20px;
    margin-left: auto;
    padding-right: 10px;
}

#user_display {
    font-weight: 800;
    color: #ffffff;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
    font-size: 14px;
}

.btn-header-contact {
    background: white;
    border: none;
    border-radius: 999px;
    padding: 8px 18px;
    font-weight: 600;
    font-size: 13px;
    color: #2d6a4f;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 6px;
}

.btn-header-contact:hover {
    background: #e0f2f1;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.logo {
    height: 60px;
    cursor: pointer;
    transition: all 0.3s ease;
}

/* =========================
   MENUS
========================= */

.hazard-menu {
    display: flex;
    gap: 15px;
    padding: 0;
    background: transparent;
    flex: 1;
    max-width: 900px;
}

.hazard-item {
    position: relative;
    display: flex;
    align-items: center;
    gap: 8px;
    flex: none; 
    min-width: auto; 
}

.hazard-item.disabled {
    cursor: pointer;
    opacity: 0.7;
}

.hazard-item.disabled::after {
    content: "อยู่ระหว่างพัฒนา";
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) rotate(-10deg);
    font-size: 10px;
    font-weight: 800;
    color: rgba(239, 68, 68, 0.4);
    white-space: nowrap;
    pointer-events: none;
    z-index: 10;
    text-transform: uppercase;
    border: 1px solid rgba(239, 68, 68, 0.3);
    padding: 1px 4px;
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.6);
}

.hazard {
    flex: 1;
    text-align: center;
    padding: 8px 15px;
    border-radius: 12px;
    cursor: pointer;
    background: rgba(255, 255, 255, 0.7);
    backdrop-filter: blur(4px);
    transition: .2s;
    font-size: 12px;
    white-space: nowrap;
}

.hazard:hover {
    background: #ddd;
}

.hazard.active {
    background: #e0f2f1;
    box-shadow: 0 2px 6px rgba(0, 0, 0, .15);
    font-weight: 800;
    color: #006666;
}

/* Tooltip & Compact style */
.hazard-item:not(.active-container) .hazard-text {
    display: none;
}

.hazard-item .hazard {
    min-width: 45px;
    padding: 8px 15px;
    flex: 0 0 auto;
}

.hazard-icon {
    font-size: 18px;
    vertical-align: middle;
}

.hazard-text {
    vertical-align: middle;
    margin-left: 5px;
}

.btn-manual {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: none;
    background: #ffffff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    transition: all 0.3s ease;
    flex-shrink: 0;
}

.btn-manual:hover {
    background: #f8f9fa;
    transform: scale(1.1) rotate(5deg);
    color: #006d77;
}




/* =========================
   DASHBOARD MAIN
========================= */

.dashboard-main {
    display: flex;
    flex: 1;
    min-height: 0;
    padding: 12px 12px 5px 12px;
    gap: 12px;
}

.map-container {
    flex: 1;
    position: relative;
    background: white;
    border-radius: 20px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    padding: 10px 0 0 0;
    box-shadow: 0 4px 15px rgba(0, 77, 77, 0.05);
    border: 1px solid rgba(131, 197, 190, 0.2);
}

.map-title-overlay {
    width: 100%;
    text-align: center;
    padding: 10px 0;
    font-weight: 800;
    font-size: 24px; /* ขยายเพิ่ม 30% */
    color: #1a1a1a;
    background: transparent;
    z-index: 800;
}

#map {
    flex: 1;
    width: 100%;
    height: 100%;
    border-top: 1px solid #f0f0f0;
}

/* =========================
   SIDE PANEL (ข้อมูลสัญลักษณ์)
========================= */

.info-sidebar {
    width: 460px; /* เพิ่มความกว้างขึ้น 100px */
    display: flex;
    flex-direction: column;
    gap: 10px; /* ลดจาก 15px */
    overflow-y: auto;
    padding-right: 5px;
}



.logo-side-header {
    display: flex;
    align-items: center;
    justify-content: center; /* จัดกึ่งกลางหลักจากนำข้อความออก */
}

.side-logo {
    width: 80%;
    height: auto;
    max-height: 120px; /* ลดลงรวม 20% จาก 150px */
    object-fit: contain;
    margin: 0 auto;
    display: block;
}



.legend-card {
    padding: 10px 12px;
}

.legend-card {
    position: absolute;
    bottom: 15px;
    right: 15px;
    z-index: 1000;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 12px;
    padding: 12px 15px;
    border: 1px solid rgba(131, 197, 190, 0.5);
    box-shadow: 0 8px 32px rgba(0, 77, 77, 0.15);
    backdrop-filter: blur(8px);
    pointer-events: auto;
}

/* มือถือแนวตั้ง (Portrait) */
@media (max-width: 768px) {
    .legend-card {
        transform: scale(0.4);
        transform-origin: bottom right;
        bottom: 5px;
        right: 5px;
        margin: 0;
    }
}

/* มือถือแนวนอน (Landscape) */
@media (orientation: landscape) and (max-height: 600px) {
    .legend-card {
        transform: scale(0.4);
        transform-origin: bottom right;
        bottom: 5px;
        right: 5px;
        margin: 0;
    }
}

.legend-group {
    margin-bottom: 8px;
}

.group-title {
    font-weight: 800;
    color: #006d77;
    font-size: 13px;
    margin-bottom: 6px;
    padding-bottom: 3px;
    border-bottom: 1px solid #eef;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12.5px;
    color: #334e4e;
    margin-bottom: 5px;
}

.legend-item .box {
    width: 16px;
    height: 16px;
    border-radius: 5px;
    flex-shrink: 0;
    margin-top: 2px;
    box-shadow: inset 0 0 0 1px rgba(0,0,0,0.05);
}

.legend-item .dot {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    flex-shrink: 0;
    margin-top: 3px;
    border: 2px solid white;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}

/* Colors from Mock Image */
.rice { background: #2ecc71; }
.fruit { background: #f1c40f; }
.flower { background: #ff00e6; }

.normal { background: #009d41; }
.warning-1 { background: #f1c40f; }
.warning-2 { background: #e67e22; }
.danger { background: #e74c3c; }

.boundary-watch {
    width: 22px;
    height: 16px;
    border: 2px solid #e91e63;
    background: rgba(233, 30, 99, 0.08);
    border-radius: 4px;
    flex-shrink: 0;
}

/* Table Card Styling */
.table-card {
    position: relative;
    padding-bottom: 12px !important;
    display: flex;
    flex-direction: column;
    min-height: 150px;
}

.resizer-v {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 12px;
    cursor: ns-resize;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
}

.resizer-v::after {
    content: '';
    width: 30px;
    height: 4px;
    background: #cbd5e0;
    border-radius: 2px;
    transition: background 0.2s;
}

.resizer-v:hover::after {
    background: #a0aec0;
}

.table-card {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0; /* Important for flex children scrolling */
}

.table-card .card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.table-card h4 {
    font-size: 13.5px;
    color: #004d4d;
    font-weight: 800;
    white-space: nowrap;
}

.table-card h4 i {
    margin-right: 5px;
    color: #e67e22;
}

.ch-left {
    display: flex;
    align-items: center;
}



.table-wrapper {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    border-radius: 12px;
    border: 1px solid #eef3f3;
}

.mini-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}

.mini-table thead th {
    background: #f8fbfa;
    padding: 6px 8px;
    text-align: center;
    color: #006d77;
    position: sticky;
    top: 0;
    border-bottom: 2px solid #83c5be;
    font-weight: 700;
    z-index: 10;
}

.mini-table td {
    padding: 6px 8px;
    border-bottom: 1px solid #f4f8f8;
    color: #445555;
    line-height: 1.3;
    text-align: center;
}

.mini-table tr:hover {
    background: #fdfdfd;
}

/* Advice & Credits */
.advice {
    font-size: 11px;
    color: #856404;                /* สีน้ำตาลเข้มเฝ้าระวัง */
    background: #fff3cd;           /* แถบสีเหลือง Warning */
    padding: 8px;
    border-radius: 10px;
    border-left: 5px solid #ffc107; /* เส้นขอบข้างสีเหลืองเข้ม */
    margin-bottom: 8px;
    line-height: 1.4;
}

.source-box {
    background: #e5e5e5; /* สีเทาตามรูปตัวอย่าง */
    border: 1px solid #777;
    padding: 6px;
    margin: 8px 0;
    color: #000;
    font-size: 10px;
}

.source-title {
    font-weight: 800;
    margin-bottom: 5px;
    text-decoration: underline;
}

.source-list {
    list-style: none;
    padding: 0;
}

.source-list li {
    margin-bottom: 4px;
    line-height: 1.4;
}

.organizer {
    font-size: 11px;
    font-weight: 800;
    color: #333;
    text-align: left;
    margin-top: 5px;
}

#map {
    width: 100%;
    flex: 1;
    min-height: 0;
}

/* overlay ดำโปร่ง */
#on_progres {
    position: fixed;
    z-index: 9999;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    display: none;

    /* จัดกรอบขาวให้อยู่กลางจอ */
    display: flex;
    justify-content: center;
    align-items: center;
}



/* =========================
   CONTACT MODAL
========================= */

.contact-card {
    background: white;
    width: 800px;
    border-radius: 24px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    animation: swal-show 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.contact-header {
    background: linear-gradient(135deg, #83c5be 0%, #008080 100%);
    padding: 20px 25px;
    color: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.contact-title {
    font-size: 20px;
    font-weight: 700;
}

.contact-close {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.contact-close:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: rotate(90deg);
}

.contact-body {
    padding: 30px;
    display: grid;
    grid-template-columns: 1fr 1.2fr;
    gap: 30px;
    background: #f0f7f7;
}

.dept-name {
    color: #2d6a4f;
    font-size: 18px;
    font-weight: 800;
    margin-bottom: 25px;
    line-height: 1.4;
}

.info-item {
    display: flex;
    gap: 15px;
    margin-bottom: 20px;
    font-size: 15px;
    color: #444;
    line-height: 1.5;
}

.info-icon {
    font-size: 20px;
    flex-shrink: 0;
}

.contact-map {
    border-radius: 16px;
    overflow: hidden;
    border: 1px solid #e0e0e0;
    box-shadow: 0 4px 15px rgba(0,0,0,0.05);
    height: 350px;
}

.contact-map iframe {
    border: 0;
}


/* =========================
   SOFT UI SHADOW SYSTEM
========================= */

.label {
    display: flex;
    align-items: center;
    justify-content: center;
    color: black;
    text-shadow:
        -1px -1px 0 white,
        1px -1px 0 white,
        -1px 1px 0 white,
        1px 1px 0 white;
    transition: transform 0.2s ease;
}

@media (max-width: 768px), (orientation: landscape) and (max-height: 600px) {
    .label, .label-admin, .custom-station-label {
        /* บังคับกรอบให้กึ่งกลางพิกัดเป๊ะๆ */
        width: 100px !important;
        height: 40px !important;
        margin-left: -50px !important;
        margin-top: -20px !important;
        
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        background: transparent !important;
        border: none !important;
        box-shadow: none !important;
        overflow: visible !important;
    }

    /* ย่อเนื้อหาด้านในโดยไม่กระทบพิกัดกรอบนอก */
    .label, .label-admin div, .custom-station-label div {
        zoom: 0.4 !important;
        white-space: nowrap !important;
        text-align: center !important;
        transform: none !important; 
        margin: 0 !important;
    }
}



/* =========================
   RESPONSIVE (Scaling Mode)
========================= */
/* เราจะใช้ JS ในการสเกลสัดส่วนแทนการจัด Layout ใหม่ตามความต้องการของ USER */
body {
    overflow-x: hidden;
}

.app {
    min-width: 1440px; /* ยืนพื้นขนาด Desktop เป็นมาตรฐาน */
    transition: transform 0.3s ease;
}

/* =========================
   LOGIN MODAL
========================= */

#login_overlay {
    position: fixed;
    inset: 0;
    z-index: 2000;
    background: rgba(0, 0, 0, 0.55);

    display: none;
    /* เริ่มต้นซ่อน */
    justify-content: center;
    align-items: center;
}

.login-box {
    width: 360px;
    background: white;
    border-radius: 22px;
    padding: 24px 26px;

    box-shadow:
        0 18px 40px rgba(0, 0, 0, .35),
        inset 0 1px 0 rgba(255, 255, 255, .8);
}

.login-title {
    font-size: 18px;
    font-weight: 700;
    text-align: center;
    margin-bottom: 18px;
    color: #006d77;
}

.login-actions {
    display: flex;
    gap: 10px;
    margin-top: 18px;
}

.login-actions button {
    flex: 1;
    border: none;
    border-radius: 999px;
    padding: 10px;
    cursor: pointer;
    font-weight: 600;
}

.btn-cancel {
    background: #ccc;
}

/* =========================
   PROCESSING MODAL (NEW)
========================= */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(4px);
    z-index: 10000;
    align-items: center;
    justify-content: center;
}

.processing-card {
    background: white;
    padding: 40px;
    border-radius: 24px;
    text-align: center;
    width: 320px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    animation: swal-show 0.3s ease-out;
}

.spinner-box {
    margin-bottom: 10px;
}

.modern-spinner {
    width: 50px;
    height: 50px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid #008080; /* สีธีมหลัก */
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

.processing-info .proc-title {
    font-size: 20px;
    font-weight: 700;
    color: #333;
    margin-bottom: 8px;
}

.processing-info .proc-status {
    font-size: 14px;
    color: #666;
    line-height: 1.5;
}

.btn-cancel-modal {
    margin-top: 10px;
    background: #f8f8f8;
    color: #888;
    border: 1px solid #eee;
    padding: 10px 20px;
    border-radius: 12px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    width: 100%;
}

.btn-cancel-modal:hover {
    background: #fff0f0;
    color: #e53935;
    border-color: #ffcdd2;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

@keyframes slideUp {
    from { transform: translateY(10px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

/* ====================================================
   SWEETALERT (SWAL) CUSTOMIZATION
   ==================================================== */
.swal-modal {
    border-radius: 20px !important;
    padding: 24px !important;
    box-shadow: 0 15px 40px rgba(0, 0, 0, 0.2) !important;
}

.swal-title {
    font-size: 22px !important;
    color: #006d77 !important;
    font-weight: 700 !important;
    margin-bottom: 15px !important;
    padding: 0 !important;
}

.swal-text {
    font-size: 16px !important;
    color: #555 !important;
    text-align: center !important;
    line-height: 1.6 !important;
}

.swal-title {
    color: #006666 !important;
    font-family: 'Prompt', sans-serif !important;
    font-size: 20px !important;
    font-weight: 700 !important;
    margin-bottom: 0 !important;
}

.swal-text {
    color: #444 !important;
    font-family: 'Sarabun', sans-serif !important;
    font-size: 15px !important;
    text-align: center !important;
    line-height: 1.6 !important;
    margin-top: 15px !important;
}

.swal-button {
    font-family: 'Sarabun', sans-serif !important;
    font-size: 14px !important;
    font-weight: 600 !important;
    padding: 10px 28px !important;
    border-radius: 10px !important;
    transition: all 0.2s ease !important;
    box-shadow: none !important;
    outline: none !important;
}

/* Success / Confirm Button */
.swal-button--confirm {
    background-color: #008080 !important; /* Teal Tone */
    color: #fff !important;
}

.swal-button--confirm:hover {
    background-color: #006666 !important;
    transform: translateY(-1px) !important;
}

/* Cancel Button */
.swal-button--cancel {
    background-color: #f5f5f5 !important;
    color: #666 !important;
}

.swal-button--cancel:hover {
    background-color: #eeeeee !important;
}

/* Error/Danger Style (if used by swal) */
.swal-button--danger {
    background-color: #d32f2f !important;
}

.swal-icon--success::before,
.swal-icon--success::after,
.swal-icon--success__hide-corners {
    background: transparent !important;
}

.swal-icon--success__line {
    background-color: #008080 !important;
}

.swal-icon--success__ring {
    border: 4px solid rgba(0, 128, 128, 0.2) !important;
}

.swal-footer {
    text-align: center !important;
    margin-top: 25px !important;
}

/* =========================
   DIAGNOSTIC BUTTON (DEBUG)
========================= */
.btn_log_coords {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 9999;
    padding: 10px 18px;
    background: #006d77;
    color: white;
    border: none;
    border-radius: 50px;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(0,0,0,0.25);
    font-family: 'Sarabun', sans-serif;
    font-size: 12px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all 0.2s ease;
}

.btn_log_coords:hover {
    background: #004d4d;
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0,0,0,0.3);
}
/* =========================
   FLOATING PRINT BUTTON
========================= */
#floating_print_btn {
    position: fixed;
    bottom: 30px;
    right: 480px;
    z-index: 5000;
    width: 55px;
    height: 55px;
    border-radius: 50%;
    background: #006d77;
    color: white;
    border: 3px solid white;
    box-shadow: 0 4px 15px rgba(0,0,0,0.3);
    cursor: grab;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.5;
    transition: opacity 0.3s, transform 0.2s, background 0.3s;
}

#floating_print_btn:hover {
    opacity: 1;
    transform: scale(1.1);
    background: #83c5be;
}

#floating_print_btn:active {
    cursor: grabbing;
}

#floating_print_btn i {
    font-size: 22px;
}

/* --- Print Styles for High Quality PDF --- */
@media print {
  @page {
    size: A4 landscape;
    margin: 10mm;
  }

  /* ซ่อนองค์ประกอบที่ไม่จำเป็น */
  .header, 
  #floating_print_btn, 
  .hazard-menu, 
  .header-right, 
  #login_overlay, 
  #on_progres, 
  .resizer-v {
    display: none !important;
  }

  .map-title-overlay {
    display: block !important;
    position: static !important;
    text-align: center !important;
    background: white !important;
    color: #006d77 !important;
    font-size: 20px !important;
    font-weight: bold !important;
    margin-bottom: 15px !important;
    width: 100% !important;
    border: none !important;
    box-shadow: none !important;
  }

  /* ปรับโครงสร้างหลักให้พิมพ์สวย */
  body, .app {
    height: auto !important;
    overflow: visible !important;
    background: white !important;
  }

  .dashboard-main {
    display: flex !important;
    flex-direction: row !important;
    gap: 20px !important;
    padding: 0 !important;
    margin: 0 !important;
    width: 100% !important;
    height: auto !important;
  }

  /* แผนที่: ล็อกความกว้างให้นิ่ง */
  .map-container {
    flex: 2 !important;
    height: 650px !important;
    border: 2px solid #006d77 !important;
    box-shadow: none !important;
    page-break-inside: avoid;
  }

  /* แถบข้าง: ปรับให้พอดี */
  .info-sidebar {
    flex: 1 !important;
    width: 350px !important;
    height: auto !important;
    overflow: visible !important;
    padding: 0 !important;
    gap: 10px !important;
  }

  .info-card {
    box-shadow: none !important;
    border: 1px solid #ccc !important;
    page-break-inside: avoid;
  }

  /* บังคับให้แผนที่แสดงผล (บางเบราว์เซอร์อาจซ่อน Background) */
  * {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }
  
  #map {
    height: 100% !important;
    width: 100% !important;
  }
}

/* =========================
   MOBILE PORTRAIT (Responsive)
========================= */
@media (max-width: 768px) {
    html, body {
        height: auto !important;
        overflow: auto !important;
    }

    .app {
        min-width: 0 !important;
        width: 100% !important;
        height: auto !important;
        display: block !important;
        overflow-x: hidden;
    }

    .header {
        padding: 15px !important;
        height: auto !important;
        min-height: 80px;
        flex-direction: column;
        gap: 15px;
    }

    .logo {
        height: 45px;
        margin-bottom: 5px;
    }

    .hazard-menu {
        max-width: 100%;
        overflow-x: auto;
        padding-bottom: 10px;
        width: 100%;
        justify-content: flex-start;
        display: flex;
        -webkit-overflow-scrolling: touch;
    }

    .hazard-item {
        flex: 0 0 auto;
    }

    .header-right {
        width: 100%;
        justify-content: center;
        margin-left: 0;
        gap: 15px;
        padding-top: 10px;
        border-top: 1px solid rgba(255,255,255,0.2);
    }

    .dashboard-main {
        flex-direction: column !important;
        height: auto !important;
        padding: 10px !important;
        gap: 15px !important;
        display: flex !important;
    }

    .map-container {
        width: 100% !important;
        height: 450px !important;
        flex: none !important;
        order: -1; /* แผนที่อยู่บนสุด */
    }

    .map-title-overlay {
        font-size: 16px !important;
        padding: 10px 15px;
    }

    .info-sidebar {
        width: 100% !important;
        padding: 0 !important;
        overflow: visible !important;
    }

    .info-card {
        width: 100% !important;
        margin-bottom: 15px;
    }

    .side-logo {
        width: 60%;
        max-height: 80px;
    }

    .legend-group {
        width: 100%;
    }

    .table-card {
        min-height: 300px !important;
    }

    .mini-table {
        font-size: 13px;
    }

    /* Modals */
    .contact-card, .login-box, .processing-card {
        width: 95% !important;
        max-width: 100% !important;
        margin: 10px;
    }

    .contact-body {
        grid-template-columns: 1fr;
        padding: 20px;
    }

    .contact-map {
        height: 200px;
    }

    #floating_print_btn {
        width: 50px;
        height: 50px;
        font-size: 20px;
        bottom: 20px;
        right: 20px;
    }
}

/* =========================
   MOBILE LANDSCAPE (Responsive)
========================= */
/* =========================
   MOBILE LANDSCAPE (Responsive)
========================= */
@media (orientation: landscape) and (max-height: 600px) {
    .app {
        height: 100vh !important;
        width: 100vw !important;
        display: flex !important;
        flex-direction: column !important;
        background: #f4f6f9 !important;
        overflow: hidden !important;
        position: fixed !important;
        top: 0;
        left: 0;
    }

    .header {
        flex: none !important;
        height: 70px !important;
        min-height: 70px !important;
        padding: 0 12px !important;         /* ลด padding ขอบลงเหลือ 12px */
        display: flex !important;
        flex-direction: row !important;
        align-items: center !important;
        gap: 12px !important;               /* ลด gap ระหว่าง Logo/Menu/Right เหลือ 12px */
        background: linear-gradient(135deg, #83c5be 0%, #006d77 50%, #004d4d 100%) !important;
        border-bottom: 1px solid rgba(255, 255, 255, 0.25) !important;
        box-shadow: 0 8px 24px rgba(0, 77, 77, 0.2) !important;
        z-index: 1000 !important;
        position: relative !important;
        width: 100% !important;
        overflow: hidden !important;
        box-sizing: border-box !important;
    }

    .logo {
        height: 32px !important;            /* ลดความสูงโลโก้ลงอีก */
        width: auto !important;
        max-width: 150px !important;        /* จำกัดความกว้างไม่ให้เบียด */
        flex-shrink: 0 !important;
        margin: 0 !important;
        cursor: pointer !important;
    }

    .hazard-menu {
        display: flex !important;
        gap: 6px !important;                /* ลด gap ระหว่างปุ่มเมนูเหลือ 6px */
        padding: 0 5px !important;
        margin: 0 !important;
        background: transparent !important;
        flex: 1 1 0 !important;             /* กินพื้นที่ที่เหลือ */
        align-items: center !important;
        overflow-x: auto !important;        /* ให้เลื่อนแนวนอนได้ถ้าเมนูเยอะเกิน */
        overflow-y: hidden !important;
        min-width: 0 !important;            /* สำคัญ: ให้ flex item หดได้ */
        -webkit-overflow-scrolling: touch !important;
    }

    /* ซ่อน scrollbar สำหรับ hazard-menu */
    .hazard-menu::-webkit-scrollbar {
        display: none !important;
    }

    .hazard {
        flex: 0 0 auto !important;
        text-align: center !important;
        padding: 4px 10px !important;       /* ลด padding ลงเหลือ 4px 10px */
        border-radius: 8px !important;
        cursor: pointer !important;
        background: rgba(255, 255, 255, 0.7) !important;
        backdrop-filter: blur(4px) !important;
        transition: .2s !important;
        font-size: 10px !important;         /* ลดฟอนต์เหลือ 10px */
        white-space: nowrap !important;
        color: #333 !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        border: none !important;
        min-width: 32px !important;         /* ขนาดขั้นต่ำเล็กลง */
    }

    .hazard.active {
        background: #ffffff !important;
        box-shadow: 0 2px 6px rgba(0, 0, 0, .15) !important;
        font-weight: 800 !important;
        color: #006d77 !important;
    }

    .hazard-icon {
        font-size: 16px !important;         /* ลดขนาดไอคอนเหลือ 16px */
    }

    .hazard-text {
        margin-left: 5px !important; 
        font-weight: inherit !important;
    }

    /* ตรรกะแสดงเฉพาะ Active Text */
    .hazard:not(.active) .hazard-text {
        display: none !important;
    }

    .hazard.active .hazard-text {
        display: inline-block !important;
    }

    .header-right {
        display: flex !important;
        align-items: center !important;
        gap: 6px !important;
        flex-shrink: 0 !important;          /* ห้ามหด */
        margin-left: auto !important;
        min-width: fit-content !important;
    }

    #user_display {
        display: none !important;           /* ซ่อนชื่อผู้ใช้ใน landscape เพื่อเพิ่มพื้นที่ */
    }

    .btn-header-contact {
        padding: 5px 10px !important;       /* ลด padding ปุ่มให้เล็กลง */
        font-size: 11px !important;         /* ลดขนาดฟอนต์ปุ่ม */
        white-space: nowrap !important;
        height: 32px !important;            /* กำหนดความสูงให้พอดีกับโลโก้ */
        display: flex !important;
        align-items: center !important;
    }

    .dashboard-main {
        flex: 1 !important; /* Fill remaining space */
        display: flex !important;
        flex-direction: row !important;
        height: auto !important;
        overflow: hidden !important;
    }

    .info-sidebar {
        width: 48% !important;
        height: 100% !important;
        padding: 8px !important;
        overflow-y: auto !important;
        display: flex !important;
        flex-direction: column !important;
        gap: 10px !important;
        -webkit-overflow-scrolling: touch;
    }

    .map-container {
        width: 52% !important;
        height: 100% !important;
        flex: none !important;
        order: 1 !important;
        border-radius: 0 !important;
        position: relative !important;
        display: flex !important; /* ใช้ Flex เพื่อจัดเรียงแนวตั้ง */
        flex-direction: column !important;
        background: #fff !important;
        padding-top: 5px !important; /* เว้นระยะด้านบนเล็กน้อย */
    }

    .map-title-overlay {
        position: static !important; /* เปลี่ยนเป็น Static ไม่ให้ทับซ้อน */
        font-size: 10px !important;
        padding: 4px 12px !important;
        margin: 0 auto 5px auto !important; /* กึ่งกลางและห่างจากแผนที่ด้านล่าง */
        width: fit-content !important;
        max-width: 95% !important;
        transform: none !important;
        border-radius: 6px !important;
        text-align: center !important;
        white-space: normal !important; /* อนุญาตให้ตัดบรรทัดถ้าแคบมาก */
        background: rgba(255, 255, 255, 0.9) !important;
        border: 1px solid rgba(0,0,0,0.1) !important;
        color: #333 !important;
        z-index: 10 !important;
    }

    #map {
        flex: 1 !important; /* ให้แผนที่กินพื้นที่ที่เหลือทั้งหมด */
        height: auto !important;
        width: 100% !important;
    }


    .info-card {
        padding: 6px 8px !important;
        margin-bottom: 0 !important;
        border-radius: 8px !important;
        flex: 0 0 auto !important;
    }

    .legend-card {
        min-height: unset !important;       /* ยกเลิกความสูงขั้นต่ำที่บังคับไว้ */
        height: fit-content !important;     /* ความสูงพอดีกับวัตถุข้างใน */
        flex: 0 0 auto !important;          /* ไม่ยืดไม่หด */
    }

    .table-card {
        min-height: auto !important; /* ปรับความสูงตามข้อมูล */
        margin-bottom: 15px !important;
        display: flex !important;
        flex-direction: column !important;
    }


    .credit-card {
        min-height: auto !important; /* ปรับความสูงตามข้อมูล */
        margin-top: 0 !important;
        margin-bottom: 20px !important;
    }


    .resizer-v {
        display: none !important;
    }

    #floating_print_btn {
        width: 36px !important;
        height: 36px !important;
        font-size: 14px !important;
        bottom: 15px !important;
        right: 15px !important;
    }

    /* ปรับ Modal ติดต่อเราให้พอดีกับจอแนวตั้งในโหมดแนวนอน */
    .contact-card {
        max-height: 95vh !important;
        width: 90% !important;
        display: flex !important;
        flex-direction: column !important;
        overflow: hidden !important;
        margin: auto !important;
    }
    .contact-header {
        padding: 10px 20px !important;
    }
    .contact-body {
        overflow-y: auto !important;
        padding: 15px !important;
        display: grid !important;
        grid-template-columns: 1fr 1fr !important;
        gap: 15px !important;
        flex: 1 !important;
    }
    .contact-map {
        height: 180px !important;
    }
    .dept-name {
        font-size: 14px !important;
        margin-bottom: 10px !important;
    }
    .info-item {
        font-size: 12px !important;
        margin-bottom: 8px !important;
        gap: 8px !important;
    }
}



