/* =======================================================
   🌟 Learning T-Map — Global Design System v3.0
   Premium UI/UX Upgrade — สกร.จังหวัดสิงห์บุรี
   ======================================================= */

/* --- 0. Google Fonts & CSS Variables --- */
@import url('https://fonts.googleapis.com/css2?family=Sarabun:wght@300;400;500;600;700;800&family=Prompt:wght@400;500;600;700&display=swap');

:root {
    /* Brand Colors */
    --primary:       #2563eb;
    --primary-dark:  #1d4ed8;
    --primary-light: #eff6ff;
    --primary-ghost: rgba(37,99,235,0.06);
    --success:       #16a34a;
    --success-light: #dcfce7;
    --danger:        #dc2626;
    --danger-light:  #fee2e2;
    --warning:       #d97706;
    --warning-light: #fef3c7;
    --purple:        #7c3aed;
    --purple-light:  #f5f3ff;
    --info:          #0891b2;
    --info-light:    #e0f2fe;

    /* Neutrals */
    --text-main:    #1e293b;
    --text-sub:     #64748b;
    --text-muted:   #94a3b8;
    --bg-page:      #f8fafc;
    --bg-card:      #ffffff;
    --border:       #e2e8f0;
    --border-light: #f1f5f9;

    /* Shadows — softer & more layered */
    --shadow-xs:  0 1px 2px rgba(0,0,0,0.04);
    --shadow-sm:  0 1px 3px rgba(0,0,0,0.05), 0 1px 2px rgba(0,0,0,0.03);
    --shadow-md:  0 4px 12px rgba(0,0,0,0.06), 0 2px 4px rgba(0,0,0,0.04);
    --shadow-lg:  0 10px 28px rgba(0,0,0,0.08), 0 4px 10px rgba(0,0,0,0.05);
    --shadow-xl:  0 16px 40px rgba(0,0,0,0.10), 0 6px 16px rgba(0,0,0,0.06);
    --shadow-blue:  0 8px 24px rgba(37,99,235,0.20);
    --shadow-green: 0 8px 24px rgba(22,163,74,0.20);

    /* Border Radius */
    --radius-xs:  6px;
    --radius-sm:  10px;
    --radius-md:  14px;
    --radius-lg:  20px;
    --radius-xl:  28px;
    --radius-full: 9999px;

    /* Transitions */
    --transition:      all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-fast: all 0.15s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-slow: all 0.45s cubic-bezier(0.4, 0, 0.2, 1);
    --bounce:          all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);

    /* Z-index layers */
    --z-dropdown: 200;
    --z-sticky:   100;
    --z-overlay:  300;
    --z-modal:    400;
    --z-toast:    500;
}

/* --- 1. Reset & Base --- */
*, *::before, *::after { box-sizing: border-box; }

html {
    scroll-behavior: smooth;
    -webkit-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
    overflow-x: hidden;
}

body {
    font-family: 'Sarabun', Tahoma, sans-serif;
    background: var(--bg-page);
    background-image:
        radial-gradient(ellipse at 10% 0%,   rgba(37,99,235,0.04) 0%, transparent 50%),
        radial-gradient(ellipse at 90% 100%, rgba(124,58,237,0.03) 0%, transparent 50%);
    margin: 0;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    color: var(--text-main);
    line-height: 1.65;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.main-content {
    flex-grow: 1;
    padding: 28px 16px 56px;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; }

/* --- 2. Premium Navbar --- */
.main-navbar {
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(24px) saturate(1.4);
    -webkit-backdrop-filter: blur(24px) saturate(1.4);
    box-shadow: 0 1px 0 var(--border), 0 4px 20px rgba(0,0,0,0.04);
    position: sticky;
    top: 0;
    z-index: var(--z-sticky);
    width: 100%;
    border-bottom: 1px solid rgba(226,232,240,0.6);
}

.nav-container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    max-width: 1600px;
    margin: 0 auto;
    padding: 12px 28px;
    gap: 16px;
}

.nav-brand {
    display: flex;
    align-items: center;
    gap: 14px;
    text-decoration: none;
    flex-shrink: 0;
}

.nav-brand img {
    width: 50px;
    height: 50px;
    border-radius: 14px;
    object-fit: cover;
    box-shadow: 0 2px 8px rgba(37,99,235,0.12);
    border: 2px solid var(--primary-light);
    transition: var(--bounce);
}
.nav-brand img:hover { transform: scale(1.08) rotate(2deg); }

.brand-text-group { display: flex; flex-direction: column; justify-content: center; }

.brand-title {
    font-family: 'Prompt', 'Sarabun', sans-serif;
    font-size: 21px;
    font-weight: 700;
    background: linear-gradient(135deg, #1e293b 0%, #2563eb 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    line-height: 1.2;
    letter-spacing: 0.3px;
}

.brand-subtitle {
    font-size: 12.5px;
    font-weight: 500;
    color: var(--text-sub);
    margin-top: 1px;
}

/* Nav Search */
.nav-search-wrapper {
    flex: 1;
    max-width: 360px;
    position: relative;
}

.nav-search-input {
    width: 100%;
    padding: 9px 16px 9px 42px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-full);
    font-family: 'Sarabun', sans-serif;
    font-size: 14px;
    color: var(--text-main);
    background: var(--bg-page);
    outline: none;
    transition: var(--transition);
}
.nav-search-input:focus {
    border-color: var(--primary);
    background: white;
    box-shadow: 0 0 0 3px var(--primary-ghost);
}
.nav-search-input::placeholder { color: var(--text-muted); }

.nav-search-icon {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 16px;
    pointer-events: none;
    color: var(--text-muted);
}

.nav-search-results {
    position: absolute;
    top: calc(100% + 8px);
    left: 0; right: 0;
    background: white;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-xl);
    display: none;
    z-index: var(--z-dropdown);
    overflow: hidden;
    animation: fadeDown 0.2s ease;
}
.nav-search-results.show { display: block; }

.nav-search-item {
    padding: 12px 16px;
    cursor: pointer;
    border-bottom: 1px solid var(--border-light);
    transition: var(--transition-fast);
    display: flex;
    align-items: flex-start;
    gap: 10px;
}
.nav-search-item:last-child { border-bottom: none; }
.nav-search-item:hover { background: var(--primary-ghost); }
.nav-search-item-title { font-weight: 600; font-size: 14px; color: var(--text-main); }
.nav-search-item-sub   { font-size: 12px; color: var(--text-sub); margin-top: 1px; }
.nav-search-item-icon  { font-size: 18px; flex-shrink: 0; margin-top: 1px; }

/* Nav Links */
.nav-links { display: flex; align-items: center; gap: 4px; flex-shrink: 0; }

.nav-links a {
    text-decoration: none;
    color: var(--text-main);
    font-weight: 600;
    font-size: 14.5px;
    transition: var(--transition);
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border-radius: var(--radius-full);
    letter-spacing: 0.2px;
    position: relative;
}
.nav-links a:hover {
    color: var(--primary);
    background: var(--primary-ghost);
    text-decoration: none;
}

.nav-links a.nav-active {
    color: var(--primary);
    background: var(--primary-light);
}

.nav-links a.nav-active::after {
    content: '';
    position: absolute;
    bottom: -10px;
    left: 50%;
    transform: translateX(-50%);
    width: 20px;
    height: 3px;
    background: var(--primary);
    border-radius: 3px 3px 0 0;
}

.btn-login-nav {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark)) !important;
    color: white !important;
    padding: 9px 20px !important;
    border-radius: var(--radius-full) !important;
    border: none !important;
    box-shadow: var(--shadow-blue) !important;
    font-weight: 700 !important;
    transition: var(--transition) !important;
}
.btn-login-nav:hover {
    transform: translateY(-2px) !important;
    box-shadow: 0 10px 28px rgba(37,99,235,0.35) !important;
    background: linear-gradient(135deg, var(--primary-dark), #1e40af) !important;
}

/* Mobile Hamburger */
.nav-hamburger {
    display: none;
    flex-direction: column;
    gap: 5px;
    cursor: pointer;
    padding: 8px;
    border-radius: var(--radius-sm);
    border: 1.5px solid var(--border);
    background: white;
    transition: var(--transition);
}
.nav-hamburger span {
    display: block;
    width: 20px;
    height: 2px;
    background: var(--text-main);
    border-radius: 2px;
    transition: var(--transition);
}
.nav-hamburger:hover { border-color: var(--primary); }
.nav-hamburger:hover span { background: var(--primary); }

/* Mobile Drawer */
.nav-mobile-drawer {
    display: none;
    position: fixed;
    inset: 0;
    z-index: var(--z-overlay);
}
.nav-mobile-drawer.open { display: block; }
.mobile-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.5);
    backdrop-filter: blur(4px);
}
.mobile-menu {
    position: absolute;
    top: 0;
    right: 0;
    width: min(320px, 85vw);
    height: 100%;
    background: white;
    box-shadow: var(--shadow-xl);
    padding: 24px 20px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    animation: slideLeft 0.3s cubic-bezier(0.16,1,0.3,1);
    overflow-y: auto;
}
.mobile-menu .mobile-close {
    align-self: flex-end;
    background: var(--bg-page);
    border: 1.5px solid var(--border);
    width: 36px; height: 36px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 8px;
    transition: var(--transition-fast);
}
.mobile-menu .mobile-close:hover { background: var(--danger); color: white; border-color: var(--danger); }
.mobile-menu a {
    text-decoration: none;
    color: var(--text-main);
    font-weight: 600;
    font-size: 15px;
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    gap: 10px;
    transition: var(--transition-fast);
}
.mobile-menu a:hover,
.mobile-menu a.nav-active { background: var(--primary-ghost); color: var(--primary); }
.mobile-menu .mobile-login {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white !important;
    border-radius: var(--radius-full);
    justify-content: center;
    box-shadow: var(--shadow-blue);
    margin-top: 8px;
}

/* --- 3. Quick Stats Bar (หน้าแผนที่) --- */
.quick-stats-bar {
    background: linear-gradient(135deg, #1e3a8a 0%, #2563eb 60%, #7c3aed 100%);
    padding: 10px 28px;
    display: flex;
    justify-content: center;
    gap: 32px;
    flex-wrap: wrap;
}
.quick-stat {
    display: flex;
    align-items: center;
    gap: 8px;
    color: rgba(255,255,255,0.9);
    font-size: 13.5px;
    font-weight: 600;
}
.quick-stat-num {
    font-family: 'Prompt', sans-serif;
    font-size: 18px;
    font-weight: 700;
    color: white;
}
.quick-stat-label { opacity: 0.8; }

/* --- 4. Map Container --- */
.map-container {
    position: relative;
    width: 96%;
    max-width: 1800px;
    margin: 0 auto;
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    background-color: #fff;
    box-shadow: var(--shadow-lg);
    transition: var(--transition-slow);
    touch-action: pan-x pan-y;
    overflow: hidden;
}
.map-container:hover {
    box-shadow: 0 20px 50px rgba(0,0,0,0.10);
}
.map-image {
    width: 100%;
    height: auto;
    display: block;
    -webkit-user-drag: none;
    user-select: none;
    -webkit-user-select: none;
    pointer-events: none;
}

.back-btn-wrapper {
    width: 96%;
    max-width: 1800px;
    margin: 0 auto;
    display: flex;
    justify-content: flex-start;
}

.btn-back-map {
    padding: 10px 22px;
    background: rgba(255, 255, 255, 0.96);
    color: var(--text-main);
    border: 1.5px solid var(--border);
    border-radius: var(--radius-full);
    cursor: pointer;
    font-family: 'Sarabun', sans-serif;
    font-size: 14px;
    font-weight: 700;
    box-shadow: var(--shadow-md);
    backdrop-filter: blur(12px);
    transition: var(--transition);
    display: inline-flex;
    align-items: center;
    gap: 7px;
    margin-bottom: 12px;
}
.btn-back-map:hover {
    background: var(--text-main);
    color: white;
    border-color: var(--text-main);
    transform: translateY(-2px);
    box-shadow: 0 10px 28px rgba(0,0,0,0.2);
}

/* --- 5. Map Legend (แสดงใต้แผนที่) --- */
.map-legend {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px 20px;
    margin-top: 10px;
    padding: 10px 16px;
    background: white;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-sm);
    font-size: 13px;
    font-weight: 600;
    color: var(--text-main);
    width: 100%;
    box-sizing: border-box;
}
.map-legend-title {
    font-size: 12px;
    font-weight: 700;
    color: var(--text-muted);
    letter-spacing: 0.3px;
    white-space: nowrap;
    margin-right: 4px;
}
.legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12.5px;
    white-space: nowrap;
}
.legend-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 2px solid white;
    box-shadow: 0 1px 4px rgba(0,0,0,0.2);
    flex-shrink: 0;
}
.legend-dot.district    { background: linear-gradient(135deg, #2563eb, #3b82f6); }
.legend-dot.subdistrict { background: linear-gradient(135deg, #16a34a, #22c55e); }
.legend-dot.learning    { background: linear-gradient(135deg, #dc2626, #ef4444); }

/* --- 6. Map Pins --- */
.district-pin, .subdistrict-pin, .village-pin, .learning-pin, .sage-pin {
    position: absolute;
    transform: translate(-50%, -50%);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 3px solid #ffffff;
    box-shadow: 0 4px 14px rgba(0,0,0,0.28);
    border-radius: 50%;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    z-index: 10;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    -webkit-user-select: none;
    pointer-events: auto;
}

@keyframes pinPop {
    0%   { transform: translate(-50%, -50%) scale(0); opacity: 0; }
    60%  { transform: translate(-50%, -50%) scale(1.2); opacity: 1; }
    100% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}
.pin-anim {
    animation: pinPop 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275) backwards;
}

.district-pin    { width: 64px; height: 64px; background: linear-gradient(135deg, #2563eb, #3b82f6); font-size: 30px; }
.subdistrict-pin { width: 54px; height: 54px; background: linear-gradient(135deg, #16a34a, #22c55e); font-size: 24px; }
.village-pin     { width: 40px; height: 40px; background: linear-gradient(135deg, #f97316, #ea580c); font-size: 18px; z-index: 5; }
.learning-pin    { width: 50px; height: 50px; background: linear-gradient(135deg, #dc2626, #ef4444); font-size: 24px; }
.sage-pin        { width: 54px; height: 54px; background: linear-gradient(135deg, #7c3aed, #6d28d9); font-size: 26px; z-index: 11; }

/* Touch feedback */
.district-pin:active    { transform: translate(-50%, -50%) scale(0.92); opacity: 0.85; }
.subdistrict-pin:active { transform: translate(-50%, -50%) scale(0.92); opacity: 0.85; }
.village-pin:active     { transform: translate(-50%, -50%) scale(0.92); opacity: 0.85; }
.learning-pin:active    { transform: translate(-50%, -50%) scale(0.92); opacity: 0.85; }
.sage-pin:active        { transform: translate(-50%, -50%) scale(0.92); opacity: 0.85; }

.district-pin::after,
.subdistrict-pin::after,
.village-pin::after,
.learning-pin::after,
.sage-pin::after {
    content: '';
    position: absolute;
    inset: -6px;
    border-radius: 50%;
    animation: pinPulse 2.5s ease-out infinite;
    pointer-events: none;
}
.district-pin::after    { background: rgba(37,99,235,0.15); }
.subdistrict-pin::after { background: rgba(22,163,74,0.15); }
.village-pin::after     { background: rgba(249,115,22,0.15); }
.learning-pin::after    { background: rgba(220,38,38,0.15); }
.sage-pin::after        { background: rgba(124,58,237,0.25); animation: pinPulse 2s ease-out infinite; }

.district-pin:hover, .subdistrict-pin:hover, .village-pin:hover, .learning-pin:hover, .sage-pin:hover {
    transform: translate(-50%, -50%) scale(1.22);
    z-index: 20;
    box-shadow: 0 10px 30px rgba(0,0,0,0.35);
}

.pin-label {
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    margin-top: 6px;
    color: var(--text-main);
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 12.5px;
    font-weight: 700;
    white-space: nowrap;
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    box-shadow: var(--shadow-sm);
    background-color: rgba(255, 255, 255, 0.97);
    border: 1px solid var(--border);
    transition: var(--transition);
}
.district-pin .pin-label    { color: #1d4ed8; border-color: #bfdbfe; background: #eff6ff; }
.subdistrict-pin .pin-label { color: #15803d; border-color: #bbf7d0; background: #f0fdf4; }
.village-pin .pin-label     { color: #ffffff; border-color: #ea580c; background: linear-gradient(135deg, #f97316, #ea580c); box-shadow: 0 4px 12px rgba(249,115,22,0.3); font-size: 11px; padding: 3px 8px; }
.learning-pin .pin-label    { color: #b91c1c; border-color: #fecaca; background: #fef2f2; }
.sage-pin .pin-label        { color: #ffffff; border-color: #7c3aed; background: linear-gradient(135deg, #7c3aed, #6d28d9); box-shadow: 0 4px 12px rgba(124,58,237,0.3); }

/* --- 7. Info Box (Popup) --- */
.info-box {
    position: absolute;
    background: rgba(255, 255, 255, 0.99);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-xl);
    display: none;
    z-index: 40;
    width: 340px;
    max-width: calc(100vw - 24px);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(255,255,255,0.8);
    opacity: 0;
    transform: translateY(14px) scale(0.96);
    animation: fadeUp 0.35s forwards cubic-bezier(0.16, 1, 0.3, 1);
    overflow: hidden;
    -webkit-overflow-scrolling: touch;
}

.info-cover-area {
    position: relative;
    width: 100%;
    height: 170px;
    background: linear-gradient(135deg, #e2e8f0, #cbd5e1);
    overflow: hidden;
}
.info-cover-area img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: var(--transition-slow);
}
.info-box:hover .info-cover-area img { transform: scale(1.04); }

.info-gradient-overlay {
    position: absolute;
    bottom: 0; left: 0; right: 0;
    height: 50%;
    background: linear-gradient(to top, rgba(0,0,0,0.25), transparent);
    pointer-events: none;
}

.close-btn {
    position: absolute;
    top: 10px;
    right: 10px;
    background: rgba(255,255,255,0.92);
    border: 1px solid rgba(255,255,255,0.6);
    border-radius: 50%;
    width: 32px;
    height: 32px;
    cursor: pointer;
    font-size: 13px;
    color: var(--text-sub);
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
    backdrop-filter: blur(8px);
    z-index: 5;
}
.close-btn:hover {
    background: var(--danger);
    color: white;
    transform: rotate(90deg);
    border-color: var(--danger);
}

.info-body { padding: 18px 20px 20px; }

.badge {
    display: inline-block;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
    padding: 5px 14px;
    border-radius: 20px;
    font-size: 12px;
    margin-bottom: 10px;
    font-weight: 700;
    letter-spacing: 0.3px;
}

h3#infoName {
    margin: 0 0 10px;
    font-size: 18px;
    color: var(--text-main);
    line-height: 1.4;
    font-weight: 700;
}

#infoDesc {
    font-size: 13.5px;
    color: var(--text-sub);
    line-height: 1.65;
    max-height: 80px;
    overflow-y: auto;
    margin-bottom: 14px;
}

.district-text {
    font-size: 13px;
    color: var(--text-sub);
    margin-bottom: 14px;
    display: flex;
    align-items: center;
    gap: 5px;
    font-weight: 500;
}
.district-text::before { content: '📍'; font-size: 14px; }

.action-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    text-align: center;
    background: linear-gradient(135deg, var(--success), #22c55e);
    color: white;
    text-decoration: none;
    padding: 12px;
    border-radius: var(--radius-full);
    font-size: 14.5px;
    font-weight: 700;
    transition: var(--transition);
    box-shadow: var(--shadow-green);
    letter-spacing: 0.3px;
}
.action-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 28px rgba(22,163,74,0.4);
    filter: brightness(1.06);
    text-decoration: none;
    color: white;
}

/* QR Container */
.qr-container {
    text-align: center;
    margin-bottom: 14px;
    background: var(--bg-page);
    padding: 10px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
}
.qr-container small {
    color: var(--text-sub);
    display: block;
    margin-bottom: 6px;
    font-size: 12px;
}
.qr-container img {
    max-width: 120px;
    border: 1px solid var(--border);
    padding: 4px;
    background: white;
    border-radius: var(--radius-xs);
}

/* --- 8. Search Wrapper (Navbar Dropdown) --- */
.search-wrapper {
    position: relative;
    max-width: 340px;
}
.search-results {
    position: absolute;
    top: calc(100% + 8px);
    left: 0; right: 0;
    background: white;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-xl);
    display: none;
    z-index: var(--z-dropdown);
    overflow: hidden;
    max-height: 380px;
    overflow-y: auto;
}
.search-item {
    padding: 11px 16px;
    cursor: pointer;
    border-bottom: 1px solid var(--border-light);
    transition: var(--transition-fast);
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.search-item:last-child { border-bottom: none; }
.search-item:hover { background: var(--primary-ghost); }
.search-title { font-weight: 600; font-size: 14px; color: var(--text-main); }
.search-desc  { font-size: 12.5px; color: var(--text-sub); }

/* --- 9. Floating Action Button --- */
.fab {
    position: fixed;
    bottom: 28px;
    right: 28px;
    z-index: 50;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    box-shadow: var(--shadow-blue);
    transition: var(--transition);
    text-decoration: none;
}
.fab:hover {
    transform: scale(1.12) translateY(-2px);
    box-shadow: 0 14px 36px rgba(37,99,235,0.4);
    color: white;
    text-decoration: none;
}

/* --- 10. Skeleton Loading --- */
.skeleton {
    background: linear-gradient(90deg, #f1f5f9 25%, #e2e8f0 50%, #f1f5f9 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: var(--radius-sm);
}
.skeleton-card {
    background: white;
    border-radius: var(--radius-md);
    overflow: hidden;
    border: 1px solid var(--border);
}
.skeleton-img  { height: 185px; }
.skeleton-line { height: 14px; margin: 10px 16px; }
.skeleton-line.wide   { margin: 16px 16px 8px; height: 16px; }
.skeleton-line.short  { width: 60%; height: 12px; }

/* --- 11. Filter Bar (Search Page) --- */
.page-filter-bar {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    align-items: center;
    max-width: 1200px;
    margin: 0 auto 28px;
    padding: 0 16px;
}
.filter-select {
    padding: 10px 16px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-full);
    font-family: 'Sarabun', sans-serif;
    font-size: 14px;
    color: var(--text-main);
    background: white;
    cursor: pointer;
    outline: none;
    transition: var(--transition);
}
.filter-select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-ghost); }

.filter-badge {
    background: var(--primary-light);
    color: var(--primary-dark);
    padding: 6px 16px;
    border-radius: var(--radius-full);
    font-size: 13px;
    font-weight: 700;
}

/* --- 12. Dashboard Charts Area --- */
.charts-area {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
    gap: 20px;
    margin-top: 20px;
}
.chart-card {
    background: white;
    border-radius: var(--radius-lg);
    padding: 28px;
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border-light);
    position: relative;
    overflow: hidden;
}
.chart-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 4px;
    background: linear-gradient(90deg, var(--primary), var(--purple));
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}
.chart-card-title {
    font-family: 'Prompt', sans-serif;
    font-size: 16px;
    font-weight: 700;
    color: var(--text-main);
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 8px;
}

/* --- 13. Stat Cards (Dashboard) --- */
.stats-grid-5 {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(185px, 1fr));
    gap: 16px;
    margin-bottom: 28px;
}
.stat-card {
    color: white;
    padding: 28px 18px 22px;
    border-radius: var(--radius-lg);
    box-shadow: 0 6px 20px rgba(0,0,0,0.1);
    text-align: center;
    position: relative;
    overflow: hidden;
    transition: all 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}
.stat-card:hover {
    transform: translateY(-6px);
    box-shadow: 0 16px 40px rgba(0,0,0,0.16);
}
.stat-card::before {
    content: '';
    position: absolute;
    top: -30px; right: -30px;
    width: 110px; height: 110px;
    border-radius: 50%;
    background: rgba(255,255,255,0.1);
    pointer-events: none;
}
.stat-card::after {
    content: '';
    position: absolute;
    bottom: -20px; left: -20px;
    width: 70px; height: 70px;
    border-radius: 50%;
    background: rgba(255,255,255,0.07);
    pointer-events: none;
}
.stat-card h3  { margin: 0 0 10px; font-size: 14.5px; font-weight: 500; opacity: 0.9; position: relative; }
.stat-card .number { font-family: 'Prompt', sans-serif; font-size: 52px; font-weight: 700; margin: 0; line-height: 1; position: relative; }
.stat-card .unit   { font-size: 13px; opacity: 0.8; margin-top: 6px; display: block; position: relative; }

.bg-district    { background: linear-gradient(135deg, #1d4ed8, #3b82f6); }
.bg-subdistrict { background: linear-gradient(135deg, #065f46, #10b981); }
.bg-village     { background: linear-gradient(135deg, #15803d, #4ade80); }
.bg-source      { background: linear-gradient(135deg, #b45309, #f59e0b); }
.bg-sage        { background: linear-gradient(135deg, #6d28d9, #a78bfa); }

/* --- 14. List/Progress Cards --- */
.list-card {
    background: white;
    padding: 28px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border-light);
}
.list-card-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding-bottom: 16px;
    margin-bottom: 8px;
    border-bottom: 2px solid var(--border-light);
}
.list-card-header h3 { color: var(--text-main); margin: 0; font-size: 17px; font-weight: 700; }

.list-item {
    padding: 13px 4px;
    border-bottom: 1px solid var(--border-light);
    font-size: 14.5px;
    transition: var(--transition-fast);
}
.list-item:last-child { border-bottom: none; }
.list-item:hover { padding-left: 8px; }

.list-item-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 7px;
}
.list-item-label { color: #334155; font-weight: 500; }
.list-item-value { font-weight: 700; font-size: 14px; white-space: nowrap; margin-left: 8px; }

.progress-bar-track {
    width: 100%;
    height: 8px;
    background: var(--bg-page);
    border-radius: 20px;
    overflow: hidden;
}
.progress-bar-fill {
    height: 100%;
    border-radius: 20px;
    transition: width 1.2s cubic-bezier(0.16, 1, 0.3, 1);
}
.fill-source   { background: linear-gradient(90deg, #b45309, #f59e0b); }
.fill-sage     { background: linear-gradient(90deg, #6d28d9, #a78bfa); }
.fill-district { background: linear-gradient(90deg, #1d4ed8, #60a5fa); }

.empty-data { text-align: center; color: #94a3b8; padding: 28px 0; font-size: 15px; }

/* --- 15. Latest Items Cards --- */
.latest-card {
    background: white;
    border-radius: var(--radius-lg);
    padding: 28px;
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border-light);
}
.latest-item {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 12px 0;
    border-bottom: 1px solid var(--border-light);
    transition: var(--transition-fast);
}
.latest-item:last-child { border-bottom: none; }
.latest-item:hover { padding-left: 6px; }
.latest-item-icon {
    width: 42px; height: 42px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    flex-shrink: 0;
    background: var(--primary-light);
}
.latest-item-info { flex: 1; min-width: 0; }
.latest-item-name { font-weight: 600; font-size: 14px; color: var(--text-main); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.latest-item-sub  { font-size: 12px; color: var(--text-sub); margin-top: 2px; }

/* --- 16. Footer --- */
.admin-footer {
    text-align: center;
    padding: 28px 20px;
    background: linear-gradient(135deg, #1e293b 0%, #1e3a8a 100%);
    width: 100%;
    box-sizing: border-box;
    margin-top: auto;
    position: relative;
    overflow: hidden;
}
.admin-footer::before {
    content: '';
    position: absolute;
    width: 200px; height: 200px;
    border-radius: 50%;
    background: rgba(255,255,255,0.03);
    top: -60px; left: -60px;
    pointer-events: none;
}
.admin-footer::after {
    content: '';
    position: absolute;
    width: 160px; height: 160px;
    border-radius: 50%;
    background: rgba(255,255,255,0.03);
    bottom: -50px; right: -50px;
    pointer-events: none;
}
.footer-content { position: relative; z-index: 1; max-width: 900px; margin: 0 auto; }
.footer-logo-text {
    font-family: 'Prompt', 'Sarabun', sans-serif;
    font-size: 15px;
    font-weight: 600;
    color: #ffffff;
    margin-bottom: 6px;
}
.admin-footer p { margin: 4px 0; font-size: 13px; color: rgba(255, 255, 255, 0.5); line-height: 1.6; }
.credit-link { color: #93c5fd; text-decoration: none; font-weight: 600; transition: var(--transition-fast); }
.credit-link:hover { color: #dbeafe; text-decoration: underline; }
.footer-divider {
    width: 40px; height: 2px;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.3), transparent);
    margin: 10px auto;
    border-radius: 2px;
}
.footer-links {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin-bottom: 10px;
    flex-wrap: wrap;
}
.footer-links a {
    color: rgba(255,255,255,0.6);
    text-decoration: none;
    font-size: 13px;
    transition: var(--transition-fast);
}
.footer-links a:hover { color: white; }

/* --- 17. Animations --- */
@keyframes fadeUp {
    from { opacity: 0; transform: translateY(14px) scale(0.96); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes fadeDown {
    from { opacity: 0; transform: translateY(-8px); }
    to   { opacity: 1; transform: translateY(0); }
}
@keyframes fadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}
@keyframes slideUp {
    from { opacity: 0; transform: translateY(24px); }
    to   { opacity: 1; transform: translateY(0); }
}
@keyframes slideLeft {
    from { opacity: 0; transform: translateX(100%); }
    to   { opacity: 1; transform: translateX(0); }
}
@keyframes pinPulse {
    0%   { opacity: 0.7; transform: scale(1); }
    70%  { opacity: 0; transform: scale(2.2); }
    100% { opacity: 0; transform: scale(2.2); }
}
@keyframes spin {
    to { transform: rotate(360deg); }
}
@keyframes shimmer {
    0%   { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}
@keyframes countUp {
    from { opacity: 0; transform: translateY(10px); }
    to   { opacity: 1; transform: translateY(0); }
}
@keyframes gradientShift {
    0%   { background-position: 0% 50%; }
    50%  { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

/* --- 18. Responsive Mobile — Full Coverage --- */

/* ── 1024px (Large Tablet) ── */
@media screen and (max-width: 1024px) {
    .nav-search-wrapper { max-width: 260px; }
    .stats-grid-5 { grid-template-columns: repeat(3, 1fr); }
    .charts-area  { grid-template-columns: 1fr; }
}

/* ── 768px (Tablet / Phablet) ── */
@media screen and (max-width: 768px) {
    /* Base */
    .main-content { padding: 16px 12px 40px; }

    /* Navbar */
    .nav-container      { flex-wrap: nowrap; gap: 8px; padding: 10px 14px; }
    .nav-search-wrapper { display: none; }
    .nav-links          { display: none; }
    .nav-hamburger      { display: flex; }
    .brand-title        { font-size: 18px; }
    .brand-subtitle     { font-size: 11.5px; }
    .nav-brand img      { width: 46px; height: 46px; }

    /* Quick Stats Bar */
    .quick-stats-bar { padding: 8px 12px; gap: 14px; flex-wrap: wrap; }
    .quick-stat      { font-size: 12px; }
    .quick-stat-num  { font-size: 15px; }

    /* Map Container — full width on mobile */
    .map-container {
        width: 100%;
        border-radius: var(--radius-md);
        border-width: 1.5px;
    }

    /* Back Button — bigger touch target */
    .btn-back-map {
        top: 10px;
        left: 10px;
        padding: 10px 16px;
        font-size: 12px;
        gap: 5px;
        min-height: 44px;
    }

    /* Map Legend — compact on mobile (flex bar) */
    .map-legend {
        gap: 5px 14px;
        padding: 8px 12px;
        margin-top: 8px;
    }
    .map-legend-title { font-size: 11px; }
    .legend-item { font-size: 11.5px; gap: 5px; }
    .legend-dot  { width: 10px; height: 10px; }

    /* Map Pins — แผนที่ mobile ลดขนาดลงให้พอดี */
    .district-pin    { width: 58px; height: 58px; font-size: 26px; border-width: 2.5px; }
    .subdistrict-pin { width: 50px; height: 50px; font-size: 22px; border-width: 2px; }
    .learning-pin    { width: 46px; height: 46px; font-size: 22px; border-width: 2px; }
    .sage-pin        { width: 50px; height: 50px; font-size: 24px; border-width: 2px; }
    .village-pin     { width: 38px; height: 38px; font-size: 16px; border-width: 2px; }
    .pin-label       { font-size: 12px; padding: 3px 9px; margin-top: 5px; max-width: 100px; }

    /* Info Box — bottom sheet on mobile */
    .info-box {
        position: fixed !important;
        top: auto !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        transform: translateY(0) !important;
        width: 100% !important;
        max-width: 100% !important;
        max-height: 82vh;
        overflow-y: auto;
        overflow-x: hidden;
        z-index: 9999 !important;
        border-radius: 20px 20px 0 0 !important;
        box-shadow: 0 -8px 40px rgba(0,0,0,0.3) !important;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
        animation: slideUpSheet 0.32s cubic-bezier(0.16,1,0.3,1) forwards !important;
    }
    /* Drag handle indicator */
    .info-box::before {
        content: '';
        display: block;
        width: 40px;
        height: 4px;
        background: #cbd5e1;
        border-radius: 4px;
        margin: 10px auto 0;
    }
    .info-cover-area { height: 150px; }
    .info-body { padding: 16px 18px 32px; }
    #infoDesc  { max-height: 80px; overflow-y: auto; -webkit-overflow-scrolling: touch; }
    .close-btn { width: 40px; height: 40px; font-size: 16px; }

    /* Stats Grid */
    .stats-grid-5 {
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
    }
    .stat-card       { padding: 22px 14px 18px; }
    .stat-card h3    { font-size: 13px; }
    .stat-card .number { font-size: 38px; }
    .stat-card .unit { font-size: 12px; }

    /* Charts */
    .charts-area { grid-template-columns: 1fr; gap: 16px; }
    .chart-card  { padding: 20px; }

    /* List / Latest cards */
    .list-card   { padding: 18px; }
    .latest-card { padding: 18px; }

    /* Filter Bar */
    .page-filter-bar { gap: 8px; }
    .filter-select { font-size: 13px; padding: 9px 12px; }

    /* FAB */
    .fab { bottom: 20px; right: 16px; width: 50px; height: 50px; font-size: 20px; }

    /* Footer links */
    .footer-links { gap: 12px; }
}

/* ── 640px (Mobile Landscape) ── */
@media screen and (max-width: 640px) {
    .main-content { padding: 12px 10px 36px; }

    /* Map instruction */
    .map-instruction { font-size: 11.5px; gap: 4px; flex-wrap: wrap; justify-content: center; }
    .map-instruction span { font-size: 11px; padding: 3px 9px; }

    /* Info Box adjustments */
    .info-box { max-height: 78vh; }

    /* Stats */
    .stats-grid-5 { gap: 10px; }
    .stat-card .number { font-size: 34px; }
}

/* ── 480px (Mobile Portrait standard) ── */
@media screen and (max-width: 480px) {
    /* Navbar */
    .brand-title    { font-size: 15px; }
    .brand-subtitle { font-size: 10px; display: none; }
    .nav-brand img  { width: 40px; height: 40px; }
    .nav-container  { padding: 8px 12px; }

    /* Stats */
    .stats-grid-5  { grid-template-columns: 1fr 1fr; gap: 8px; }
    .stat-card     { padding: 18px 14px; }
    .stat-card .number { font-size: 36px; }

    /* Map pins — ต้องเล็กลงจาก 768px */
    .district-pin    { width: 52px; height: 52px; font-size: 24px; border-width: 2.5px; }
    .subdistrict-pin { width: 46px; height: 46px; font-size: 20px; border-width: 2px; }
    .learning-pin    { width: 44px; height: 44px; font-size: 20px; border-width: 2px; }
    .sage-pin        { width: 46px; height: 46px; font-size: 22px; border-width: 2px; }
    .village-pin     { width: 36px; height: 36px; font-size: 16px; border-width: 2px; }
    .pin-label       { font-size: 11px; padding: 3px 8px; max-width: 90px; margin-top: 4px; }

    /* Back button */
    .btn-back-map { padding: 8px 12px; font-size: 11px; gap: 4px; min-height: 40px; }

    /* Map Legend — compact flex at 480px */
    .map-legend {
        gap: 4px 12px;
        padding: 7px 10px;
        margin-top: 6px;
    }
    .map-legend-title { font-size: 10px; }
    .legend-item { font-size: 10.5px; gap: 4px; }
    .legend-dot  { width: 9px; height: 9px; border-width: 1.5px; }

    /* FAB */
    .fab { bottom: 16px; right: 12px; width: 46px; height: 46px; font-size: 18px; }

    /* Hero Stats Chips */
    .hero-stats { gap: 8px; }
    .hero-stat-chip { padding: 6px 12px; font-size: 12px; }
    .hero-stat-chip strong { font-size: 14px; }

    /* Quick Stats Bar */
    .quick-stats-bar { gap: 10px; padding: 8px; }
    .quick-stat { font-size: 11px; gap: 5px; }
    .quick-stat-num { font-size: 14px; }

    /* Info Box */
    .info-box { max-height: 85vh; }
    .info-cover-area { height: 130px; }
    .info-body { padding: 14px 16px 28px; }
}

/* ── 375px (iPhone standard) ── */
@media screen and (max-width: 375px) {
    .district-pin    { width: 50px; height: 50px; font-size: 22px; }
    .subdistrict-pin { width: 44px; height: 44px; font-size: 20px; }
    .learning-pin    { width: 42px; height: 42px; font-size: 20px; }
    .sage-pin        { width: 44px; height: 44px; font-size: 20px; }
    .village-pin     { width: 34px; height: 34px; font-size: 14px; }
    .pin-label { font-size: 11px; padding: 3px 7px; max-width: 80px; }
    .brand-title { font-size: 14px; }
    .nav-brand img { width: 38px; height: 38px; }
    /* Legend wrap tighter on tiny screens */
    .map-legend { gap: 4px 10px; padding: 6px 10px; font-size: 10px; }
    .legend-item { font-size: 10px; }
    .legend-dot  { width: 8px; height: 8px; }
}

/* ── 360px (Small Android) ── */
@media screen and (max-width: 360px) {
    .brand-title    { font-size: 13px; }
    .nav-brand img  { width: 36px; height: 36px; }
    .nav-container  { padding: 7px 10px; }

    .district-pin    { width: 46px; height: 46px; font-size: 20px; }
    .subdistrict-pin { width: 40px; height: 40px; font-size: 18px; }
    .learning-pin    { width: 38px; height: 38px; font-size: 16px; }
    .sage-pin        { width: 40px; height: 40px; font-size: 18px; }
    .village-pin     { width: 32px; height: 32px; font-size: 14px; }
    .pin-label       { font-size: 10px; padding: 2px 6px; max-width: 72px; }

    .btn-back-map { padding: 7px 10px; font-size: 10.5px; }
    .fab { width: 42px; height: 42px; font-size: 16px; }
    .stats-grid-5 { grid-template-columns: 1fr; }
}

/* ── Touch Devices — extend tap area WITHOUT forcing min-size ── */
@media (hover: none) and (pointer: coarse) {
    /* Invisible larger tap area using ::before pseudo element */
    .district-pin::before,
    .subdistrict-pin::before,
    .learning-pin::before,
    .sage-pin::before {
        content: '';
        position: absolute;
        inset: -24px;  /* extends tap zone by 24px on each side */
        border-radius: 50%;
    }
    /* Do NOT set min-width/min-height here — it overrides breakpoint sizes */
    .nav-hamburger { padding: 10px; min-width: 44px; min-height: 44px; }
    .mobile-menu a { padding: 14px 16px; min-height: 48px; }
    .filter-select { padding: 11px 14px; min-height: 44px; }
    .nav-search-item { padding: 14px 16px; min-height: 48px; }
    .close-btn { width: 44px; height: 44px; font-size: 18px; }
    .btn-back-map { min-height: 44px; }
    .action-btn { min-height: 48px; }
    /* Prevent double-tap zoom */
    .district-pin, .subdistrict-pin, .learning-pin, .sage-pin,
    .btn-back-map, .close-btn, .action-btn {
        touch-action: manipulation;
    }
}

/* ── Slide-up animation for info box sheet ── */
@keyframes slideUpSheet {
    from { transform: translateY(100%); }
    to   { transform: translateY(0); }
}