/* ===================================
   GoTrip — Tourism Map CSS
   Redesigned UI · same color palette
   ----------------------------------
   Colors from tamplate.css:
   --primary:  #2D5A87
   --blue:     #4a90e2
   --gold:     #F1E5AC
   --dark:     #2A2A3E
   =================================== */

/* ===================================
   1. CSS VARIABLES & RESET
   =================================== */
:root {
    --primary:      #2D5A87;
    --primary-dark: #1e3f61;
    --primary-light:#4a7bb5;
    --blue:         #4a90e2;
    --blue-light:   #6aaff5;
    --gold:         #F1E5AC;
    --gold-dark:    #d4c474;
    --dark:         #2A2A3E;
    --text:         #1e293b;
    --text-muted:   #64748b;
    --text-light:   #94a3b8;
    --bg:           #f0f4f8;
    --white:        #ffffff;
    --border:       #e2e8f0;
    --border-focus: #4a90e2;
    --success:      #10b981;
    --danger:       #ef4444;

    --grad-main:    linear-gradient(135deg, #2D5A87 0%, #4a90e2 60%, #F1E5AC 100%);
    --grad-btn:     linear-gradient(135deg, #4a90e2 0%, #2D5A87 100%);
    --grad-gold:    linear-gradient(135deg, #F1E5AC 0%, #4a90e2 100%);

    --radius-sm:    8px;
    --radius:       12px;
    --radius-lg:    16px;
    --shadow-sm:    0 1px 4px rgba(0,0,0,0.08);
    --shadow:       0 4px 16px rgba(45,90,135,0.12);
    --shadow-lg:    0 8px 32px rgba(45,90,135,0.18);
    --transition:   all 0.22s cubic-bezier(.4,0,.2,1);
}

* { margin:0; padding:0; box-sizing:border-box; }

html {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: 'Sarabun', 'Kanit', 'Segoe UI', sans-serif;
    line-height: 1.6;
    color: var(--text);
    background: #ffffff;
    overflow: hidden;
    height: 100%;
    /* header tamplate.css เป็น fixed 64px */
    padding-top: 64px;
}

/* ===================================
   2. HEADER — ใช้ tamplate.css
   =================================== */

/* ===================================
   3. MAIN LAYOUT (desktop)
   =================================== */
.container {
    display: flex;
    flex-direction: row;
    width: 100%;
    height: calc(100vh - 64px);
    position: relative;
    overflow: hidden;
    background: #ffffff;
}

/* ===================================
   4. SIDEBAR (desktop)
   =================================== */
.sidebar {
    width: 300px;
    min-width: 300px;
    max-width: 300px;
    flex-shrink: 0;
    overflow-y: auto;
    background: var(--white);
    border-right: 1px solid var(--border);
    z-index: 900;
    position: relative;
    transition: width 0.3s cubic-bezier(.4,0,.2,1),
                min-width 0.3s cubic-bezier(.4,0,.2,1),
                transform 0.3s cubic-bezier(.4,0,.2,1);
    box-shadow: 2px 0 12px rgba(45,90,135,0.08);
}

/* collapsed: ซ่อน sidebar ออกซ้าย + แผนที่ขยายเต็ม */
.sidebar.collapsed {
    width: 0;
    min-width: 0;
    overflow: hidden;
    border-right: none;
    box-shadow: none;
}

/* scrollbar */
.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }
.sidebar::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
.sidebar::-webkit-scrollbar-thumb:hover { background: var(--text-light); }

.sidebar-toggle {
    position: absolute;
    right: -36px;
    top: 18px;
    background: var(--white);
    border: 1px solid var(--border);
    border-left: none;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    box-shadow: 3px 0 8px rgba(0,0,0,0.08);
    transition: var(--transition);
    z-index: 1000;
    font-size: 13px;
    color: var(--text-muted);
}

.sidebar-toggle:hover {
    background: var(--bg);
    color: var(--primary);
}

/* เมื่อ collapsed → ปุ่มยังอยู่ให้กดเปิดได้ */
.sidebar.collapsed .sidebar-toggle {
    right: -36px;
    border-left: 1px solid var(--border);
    border-radius: var(--radius-sm);
}

/* sidebar top accent bar */
.sidebar::before {
    content: '';
    display: block;
    height: 3px;
    background: var(--grad-btn);
    flex-shrink: 0;
}

.sidebar-content {
    padding: 18px 16px 24px;
}

.sidebar-title {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 18px;
    display: flex;
    align-items: center;
    gap: 6px;
}

/* ===================================
   5. FILTER CONTROLS
   =================================== */
.filter-group {
    margin-bottom: 14px;
}

.filter-label {
    display: block;
    margin-bottom: 5px;
    font-weight: 600;
    color: var(--text-muted);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.filter-select,
.filter-input {
    width: 100%;
    padding: 9px 12px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.88rem;
    font-family: inherit;
    color: var(--text);
    background: var(--white);
    transition: var(--transition);
    outline: none;
}

.filter-select:hover,
.filter-input:hover {
    border-color: var(--blue-light);
}

.filter-select:focus,
.filter-input:focus {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px rgba(74,144,226,0.12);
    background: #fafcff;
}

/* ── divider ── */
.filter-divider {
    height: 1px;
    background: var(--border);
    margin: 16px 0;
}

.filter-actions {
    display: flex;
    gap: 8px;
    margin-top: 16px;
}

/* ===================================
   6. BUTTONS
   =================================== */
.btn {
    flex: 1;
    padding: 9px 14px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.88rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: var(--transition);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    position: relative;
    overflow: hidden;
}

/* ripple */
.btn::after {
    content: '';
    position: absolute;
    inset: 0;
    background: rgba(255,255,255,0.18);
    opacity: 0;
    transition: opacity 0.15s;
}
.btn:active::after { opacity: 1; }

.btn-primary {
    background: var(--grad-btn);
    color: var(--white);
    box-shadow: 0 2px 8px rgba(74,144,226,0.3);
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 14px rgba(74,144,226,0.4);
}

.btn-secondary {
    background: var(--bg);
    color: var(--text-muted);
    border: 1.5px solid var(--border);
}

.btn-secondary:hover {
    background: #e8edf2;
    color: var(--text);
    border-color: #c8d4e0;
}

/* sidebar action buttons (planning / nav) */
.sidebar-content .btn[id="planningBtn"],
.sidebar-content .btn[id="openNavBtn"] {
    width: 100%;
    padding: 11px 14px;
    margin-top: 10px;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-weight: 700;
    letter-spacing: 0.2px;
}

/* ===================================
   7. STATISTICS
   =================================== */
.stats-container {
    margin-top: 20px;
    padding: 14px;
    background: linear-gradient(135deg, #f0f6ff 0%, #fdf8ea 100%);
    border-radius: var(--radius);
    border: 1px solid rgba(74,144,226,0.15);
}

.stats-title {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.stat-item {
    text-align: center;
    padding: 12px 8px;
    background: var(--white);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
    transition: var(--transition);
}

.stat-item:hover {
    border-color: var(--blue);
    box-shadow: var(--shadow);
    transform: translateY(-1px);
}

.stat-value {
    font-size: 1.8rem;
    font-weight: 800;
    background: var(--grad-btn);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    line-height: 1;
}

.stat-label {
    font-size: 0.75rem;
    color: var(--text-light);
    margin-top: 4px;
    font-weight: 500;
}

/* ===================================
   8. INFO BOX
   =================================== */
.info-box {
    margin-top: 16px;
    padding: 12px 14px;
    background: linear-gradient(135deg, #eff6ff 0%, #fdf8ea 100%);
    border-left: 3px solid var(--blue);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.info-text {
    font-size: 0.8rem;
    color: var(--primary);
    line-height: 1.9;
}

/* ===================================
   9. MAP WRAPPER
   =================================== */
.map-wrapper {
    flex: 1;
    position: relative;
    z-index: 1;
    min-width: 0;
    overflow: hidden;
}

#map {
    width: 100%;
    height: 100%;
    position: relative;
    z-index: 1;
}

/* ===================================
   10. LEAFLET OVERRIDES
   =================================== */
.leaflet-container { width:100%; height:100%; z-index:1; }
.leaflet-control-container {
    position: absolute !important;
    width: 100% !important;
    height: 100% !important;
    pointer-events: none !important;
}
.leaflet-control             { pointer-events: auto !important; }
.leaflet-control-zoom        { z-index:10000 !important; margin:10px !important; }
.leaflet-top, .leaflet-bottom { z-index:10000 !important; }
.leaflet-left                { left:10px !important; }
.leaflet-right               { right:10px !important; }
.leaflet-control-layers      { z-index:10000 !important; }
.leaflet-pane                { z-index:400 !important; }
.leaflet-tile-pane           { z-index:200 !important; }
.leaflet-overlay-pane        { z-index:400 !important; }
.leaflet-shadow-pane         { z-index:500 !important; }
.leaflet-marker-pane         { z-index:600 !important; }
.leaflet-tooltip-pane        { z-index:650 !important; }
.leaflet-popup-pane          { z-index:700 !important; }

/* zoom buttons redesign */
.leaflet-control-zoom a {
    background: var(--white) !important;
    color: var(--primary) !important;
    border-color: var(--border) !important;
    font-weight: 700 !important;
    transition: var(--transition) !important;
}
.leaflet-control-zoom a:hover {
    background: var(--bg) !important;
    color: var(--blue) !important;
}

/* ===================================
   11. LEGEND
   =================================== */
.legend {
    position: fixed !important;
    bottom: 24px !important;
    left: 316px !important;
    width: 220px !important;
    z-index: 99999 !important;
    background: var(--white) !important;
    border-radius: var(--radius) !important;
    box-shadow: var(--shadow-lg) !important;
    border: 1px solid var(--border) !important;
    overflow: hidden !important;
    transform: none !important;
    transition: none !important;
}

.legend-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 14px;
    background: linear-gradient(90deg, #f0f6ff, #fdf8ea);
    border-bottom: 1px solid var(--border);
    cursor: pointer;
}

.legend-title {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--primary);
}

.legend-toggle {
    background: none;
    border: none;
    font-size: 1.1rem;
    cursor: pointer;
    color: var(--text-muted);
    line-height: 1;
    width: 22px;
    height: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: var(--transition);
}
.legend-toggle:hover { background: var(--border); color: var(--text); }

.legend-content {
    padding: 10px 12px;
    max-height: 360px;
    overflow-y: auto;
}
.legend-content.collapsed { display: none !important; }

.legend-content::-webkit-scrollbar { width: 3px; }
.legend-content::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 0;
    font-size: 0.8rem;
    color: var(--text);
    transition: var(--transition);
    border-radius: 4px;
}
.legend-item:hover { background: var(--bg); padding-left: 4px; }

.legend-icon {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid rgba(255,255,255,0.8);
    box-shadow: 0 1px 4px rgba(0,0,0,0.15);
    font-size: 13px;
    flex-shrink: 0;
}

/* ===================================
   12. LOADING OVERLAY
   =================================== */
.loading-overlay {
    position: absolute;
    inset: 0;
    background: rgba(255,255,255,0.94);
    backdrop-filter: blur(3px);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    gap: 16px;
}
.loading-overlay.hidden { display: none; }

.loading-spinner {
    width: 44px;
    height: 44px;
    border: 3px solid var(--border);
    border-top-color: var(--blue);
    border-right-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.9s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.loading-text {
    color: var(--primary);
    font-size: 0.9rem;
    font-weight: 600;
    letter-spacing: 0.3px;
}

/* ===================================
   13. POPUP STYLES
   =================================== */
.leaflet-popup-content-wrapper {
    padding: 0 !important;
    border-radius: var(--radius) !important;
    overflow: hidden;
    box-shadow: var(--shadow-lg) !important;
    border: 1px solid var(--border) !important;
    min-width: 260px;
}

.leaflet-popup-content {
    margin: 0 !important;
    width: 270px !important;
}

.leaflet-popup-tip {
    background: var(--white) !important;
}

/* popup image */
.popup-img-wrap {
    width: 100%;
    height: 150px;
    overflow: hidden;
    background: linear-gradient(135deg, #dbeafe, #fef9c3);
    position: relative;
    flex-shrink: 0;
}
.popup-img {
    width: 100%; height: 100%;
    object-fit: cover;
    display: block;
    transition: transform 0.35s ease;
}
.popup-img:hover { transform: scale(1.05); }
.popup-img-wrap::after {
    content: '';
    position: absolute;
    bottom: 0; left: 0; right: 0;
    height: 40px;
    background: linear-gradient(transparent, rgba(0,0,0,0.2));
    pointer-events: none;
}

.popup-content { font-family: 'Sarabun', sans-serif; }

.popup-header {
    background: var(--grad-gold);
    color: var(--primary-dark);
    padding: 12px 14px 8px;
}

.popup-title {
    font-size: 1rem;
    font-weight: 800;
    line-height: 1.3;
    color: var(--primary-dark);
}

.popup-type {
    display: inline-block;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--primary);
    background: rgba(255,255,255,0.5);
    padding: 1px 8px;
    border-radius: 20px;
    margin-top: 4px;
}

.popup-body { padding: 10px 14px 12px; }

.popup-info {
    display: flex;
    align-items: flex-start;
    gap: 4px;
    margin-bottom: 6px;
    font-size: 0.85rem;
    color: var(--text-muted);
    line-height: 1.5;
}
.popup-info:last-child { margin-bottom: 0; }
.popup-info strong { color: var(--text); font-weight: 600; }

.popup-rating {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: #fef3c7;
    color: #92400e;
    padding: 2px 8px;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 700;
}

/* ===================================
   14. MARKER HOVER EFFECT
   =================================== */
.custom-marker-icon > div {
    transition: transform 0.18s ease, box-shadow 0.18s ease;
}
.custom-marker-icon:hover > div {
    transform: rotate(-45deg) scale(1.15) !important;
    box-shadow: 0 6px 16px rgba(45,90,135,0.4) !important;
}

/* ===================================
   15. SCROLLBAR
   =================================== */
.sidebar::-webkit-scrollbar,
.legend-content::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-track,
.legend-content::-webkit-scrollbar-track { background: transparent; }
.sidebar::-webkit-scrollbar-thumb,
.legend-content::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 4px; }
.sidebar::-webkit-scrollbar-thumb:hover,
.legend-content::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* ===================================
   16. Z-INDEX OVERRIDES
   =================================== */
.planning-modal-overlay.active { z-index: 100000 !important; }
.legend { z-index: 99999 !important; }

/* ===================================
   17. RESPONSIVE — MOBILE & TABLET
   =================================== */

/* ── Tablet (768px – 1024px) ── */
@media (max-width: 1024px) {

    body { padding-top: 64px !important; }

    .container { height: calc(100vh - 64px); }

    .sidebar {
        width: 260px;
        min-width: 260px;
        max-width: 260px;
    }

    .sidebar.collapsed {
        width: 0;
        min-width: 0;
    }

    #navPanel { width: 290px; }

    .legend {
        left: 276px !important;
        max-width: 200px !important;
    }
}

/* ── Mobile (≤ 768px) ── */
@media (max-width: 768px) {

    /* body/html เต็มจอ ไม่มีสีพื้นหลังรั่ว */
    html, body {
        background: #ffffff !important;
        overflow: hidden !important;
        padding-top: 64px !important;
        margin: 0 !important;
    }

    /* ── Container: row เหมือนเดิม แผนที่เต็มพื้นที่ทั้งหมด ── */
    .container {
        flex-direction: row;
        width: 100vw;
        height: calc(100vh - 64px);
        overflow: hidden;
        position: relative;
        background: #ffffff;
    }

    /* ── Map wrapper: เต็มพื้นที่ container ทั้งหมด ── */
    .map-wrapper {
        position: absolute !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        width: 100% !important;
        height: 100% !important;
        z-index: 1;
    }

    #map {
        width: 100% !important;
        height: 100% !important;
    }

    /* ── Sidebar: ซ่อนพ้นจอซ้าย เปิดเป็น drawer ทับแผนที่ ── */
    .sidebar {
        position: fixed !important;
        top: 64px !important;
        left: 0 !important;
        width: min(85vw, 300px) !important;
        max-width: 300px !important;
        min-width: unset !important;
        height: calc(100vh - 64px) !important;
        z-index: 9000 !important;
        transform: translateX(-110%) !important;
        box-shadow: none;
        transition: transform 0.28s cubic-bezier(.4,0,.2,1),
                    box-shadow 0.28s ease !important;
        overflow-y: auto;
    }

    .sidebar.mobile-open {
        transform: translateX(0) !important;
        box-shadow: 4px 0 24px rgba(0,0,0,0.22) !important;
    }

    .sidebar.collapsed {
        transform: translateX(-110%) !important;
    }

    /* ซ่อนปุ่ม toggle เดิมที่อยู่ใน sidebar */
    .sidebar > .sidebar-toggle {
        display: none !important;
    }

    /* Backdrop */
    .sidebar-backdrop {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,0.38);
        z-index: 8999;
        backdrop-filter: blur(2px);
        -webkit-backdrop-filter: blur(2px);
    }
    .sidebar-backdrop.show { display: block; }

    /* ── FAB ☰ เปิด sidebar — ลอยมุมซ้ายล่าง ── */
    #mobileSidebarFab {
        display: flex !important;
        position: fixed;
        left: 14px;
        bottom: 86px;
        width: 46px;
        height: 46px;
        border-radius: 50%;
        border: none;
        background: linear-gradient(135deg, #4a90e2, #2D5A87);
        color: #fff;
        font-size: 20px;
        box-shadow: 0 4px 16px rgba(45,90,135,0.45);
        z-index: 9001;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        transition: transform 0.2s, box-shadow 0.2s;
    }
    #mobileSidebarFab:hover {
        transform: scale(1.08);
        box-shadow: 0 6px 20px rgba(45,90,135,0.55);
    }

    /* Legend มุมขวาล่าง */
    .legend {
        left: unset !important;
        right: 10px !important;
        bottom: 10px !important;
        max-width: 180px !important;
        font-size: 0.78rem !important;
    }

    /* Navigation panel เต็มความกว้าง */
    #navPanel {
        top: 64px !important;
        right: 0 !important;
        left: 0 !important;
        width: 100% !important;
        max-height: calc(100vh - 64px) !important;
        border-radius: 0 !important;
        box-shadow: 0 4px 20px rgba(0,0,0,0.2) !important;
    }

    #navPickBar { top: 72px; }

    /* FAB นำทาง — มุมขวาล่าง */
    #navToggleFab {
        bottom: 16px !important;
        top: unset !important;
        right: 16px !important;
        width: 46px !important;
        height: 46px !important;
    }

    /* Popup */
    .custom-popup .leaflet-popup-content {
        margin: 0 !important;
    padding: 0 !important;
}

    /* จัดส่วน body */
    .popup-body {
    padding: 12px;
}

    /* เว้นขอบรูป */
    .popup-body img {
    margin-top: 10px;
    border-radius: 12px;
}

    /* Zoom controls ใหญ่ขึ้น สำหรับนิ้วกด */
    .leaflet-control-zoom { margin: 8px !important; }
    .leaflet-control-zoom a {
        width: 34px !important;
        height: 34px !important;
        line-height: 34px !important;
        font-size: 18px !important;
    }
}

