/* =========================================
   1. GLOBAL VARIABLES & BASE STYLES 
   ========================================= */
:root {
    --top-space: 90px; /* ระยะห่างจากขอบบน (Navbar height + gap) */
    --nav-transition-time: 0.4s;
    --primary-color: #191D88;
    --primary-hover: #101256;
    --font-main: 'Prompt', sans-serif;
}

body {
    font-family: var(--font-main);
}

path.leaflet-interactive:focus {
    outline: none !important;
}

.leaflet-popup-content,
.leaflet-tooltip {
    font-family: var(--font-main);
}

.leaflet-top {
    top: var(--top-space) !important;
    transition: top var(--nav-transition-time) ease-in-out !important;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-5px); }
    to { opacity: 1; transform: translateY(0); }
}

/* =========================================
   2. NAVBAR & NAVIGATION
   ========================================= */
#navbar-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    z-index: 2000;
    transition: transform var(--nav-transition-time) ease-in-out;
}

#navbar-container.nav-collapsed {
    transform: translateY(-100%);
}

#navbar-toggler {
    position: absolute;
    bottom: -30px;
    left: 50%;
    transform: translateX(-50%);
    width: 50px;
    height: 30px;
    background-color: white;
    border-radius: 0 0 15px 15px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    color: var(--primary-color);
    font-size: 14px;
    z-index: -1;
    border: 1px solid #eee;
    border-top: none;
}

#navbar-toggler:hover {
    background-color: #f8f9fa;
    color: var(--primary-hover);
}

#navbar-container nav a,
#navbar-container nav button {
    color: #333333 !important;
    text-decoration: none !important;
    font-weight: 500;
}

#navbar-container nav a:hover,
#navbar-container nav button:hover {
    color: #1e40af !important;
}

ul.dropdown-menu.show-dropdown {
    display: block !important;
    opacity: 1 !important;
    visibility: visible !important;
    top: 100% !important;
}

ul.dropdown-menu {
    z-index: 9999 !important;
}

/* =========================================
   3. SIDEBAR & LEGEND
   ========================================= */
.sidebar {
    transition: transform 1s;
    z-index: 9999;
    width: 300px;
    top: 25%;
    bottom: 20%;
    display: flex;
    flex-direction: column;
    transform: translateX(0);
}

.sidebar.collapsed {
    transform: translateX(-100%);
}

.rounded-rect {
    background: white;
    border-radius: 10px;
    box-shadow: 0 0 50px -25px black;
}

.flex-center {
    position: absolute;
    display: flex;
    justify-content: center;
    align-items: center;
}

.flex-center.left { left: 0px; }
.flex-center.right { right: 0px; }

.sidebar-content {
    position: absolute;
    margin: 0 auto;
    width: 95%;
    height: 95%;
    font-family: var(--font-main);
    font-size: 32px;
    color: gray;
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
}

.sidebar-toggle {
    position: absolute;
    top: 50%;
    right: -1.5em;
    transform: translateY(-50%);
    width: 1.3em;
    height: 1.3em;
    overflow: visible;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2;
}

.sidebar-toggle.left { right: -1.8em; }
.sidebar-toggle.right { left: -1.5em; }

.sidebar-toggle:hover {
    background-color: #c4c4c4;
    cursor: pointer;
}

.sidebar-toggle i {
    font-size: 0.8em;
}

/* Container รูป Legend */
#layer-images-container {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 5px;
    overflow-y: auto;
    max-height: 80vh;
}

/* =========================================
   4. MAP CONTROLS (ซ้ายบน)
   ========================================= */
#map-controls {
    position: absolute;
    top: calc(var(--top-space) + 10px) !important;
    left: 60px;
    z-index: 1000;
    margin: 0 !important;
    transition: top var(--nav-transition-time) ease-in-out !important;
}

#map-controls .btn-primary {
    background-color: var(--primary-color);
    border-color: var(--primary-color);
    color: white;
    border-radius: 50px;
}

#map-controls .dropdown-menu {
    border-radius: 15px;
    margin-top: 5px !important;
    overflow: hidden;
}

#map-controls .btn-primary:hover,
#map-controls .btn-primary:focus,
#map-controls .btn-primary:active,
#map-controls .btn-primary.show {
    background-color: var(--primary-hover) !important;
    border-color: var(--primary-hover) !important;
    color: white !important;
    box-shadow: 0 0 0 0.25rem rgba(25, 29, 136, 0.5);
}

.btn-check:checked+.btn,
.btn.active,
.btn.show,
.btn:first-child:active,
:not(.btn-check)+.btn:active {
    background-color: var(--primary-hover) !important;
    border-color: var(--primary-hover) !important;
}

/* =========================================
   5. CUSTOM LAYER CONTROL (ขวาบน)
   ========================================= */
.custom-control-wrapper {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
}

.layer-toggle-btn {
    width: 40px;
    height: 40px;
    background-color: var(--primary-color);
    color: white;
    border: none;
    border-radius: 10px;
    box-shadow: 0 1px 5px rgba(0, 0, 0, 0.4);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 25px;
    margin-bottom: 5px;
    transition: background-color 0.2s;
}

.layer-toggle-btn:hover {
    background-color: var(--primary-hover);
}

.custom-layer-control {
    background: white;
    padding: 10px;
    border-radius: 15px;
    box-shadow: 0 1px 5px rgba(0, 0, 0, 0.4);
    width: 350px;
    max-height: 80vh;
    overflow-y: auto;
    font-family: var(--font-main);
    font-size: 16px;
    display: none;
}

.custom-layer-control.active {
    display: block;
}

.group-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
    border-bottom: 1px solid #eee;
    font-weight: 600;
    transition: all 0.2s ease;
    border-left: 0px solid transparent;
}

.group-header.active-group {
    color: var(--primary-color);
    background-color: #eef2ff;
    border-left: 5px solid var(--primary-color);
    padding-left: 10px;
}

.group-content {
    display: none;
    padding-left: 15px;
    margin-top: 5px;
    margin-bottom: 10px;
}

.group-content.show {
    display: block;
}

.layer-item {
    margin: 5px 0;
    display: flex;
    align-items: center;
}

.layer-item input {
    margin-right: 8px;
    cursor: pointer;
}

.layer-item label {
    cursor: pointer;
    margin-bottom: 0;
}

.switch {
    position: relative;
    display: inline-block;
    width: 34px;
    height: 20px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: #ccc;
    transition: .4s;
    border-radius: 34px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 14px;
    width: 14px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
}

input:checked+.slider {
    background-color: #2196F3;
}

input:checked+.slider:before {
    transform: translateX(14px);
}

.custom-layer-control, .sidebar-content {
    background: rgba(255, 255, 255, 0.85) !important;
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.3);
}

/* =========================================
   6. UTILITIES / MISC
   ========================================= */
.leaflet-control-basemap {
    background: transparent;
    border: none;
    padding: 4px;
}

.leaflet-control-basemap img {
    cursor: pointer;
    transition: transform 0.15s;
    border-radius: 5px;
}

.leaflet-control-basemap img:hover {
    transform: scale(1.05);
}

tbody.query {
    overflow: auto;
    display: block;
}

.cross {
    width: 300px;
    height: 300px;
}

.custom-title {
    position: absolute;
    top: -15px;
    left: 768px;
    transform: translateX(-50%);
    background-color: white;
    padding: 5px 30px;
    border: 1px solid #ccc;
    border-radius: 5px;
    z-index: 1000;
    width: 650px;
    height: auto;
    font-size: large;
    font-family: var(--font-main);
}

/* Select All / Clear All */
.group-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 12px;
}

.action-btn {
    border: none;
    background: none;
    cursor: pointer;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 4px;
    transition: all 0.2s;
    font-family: var(--font-main);
}

.select-all-btn {
    color: #191D88;
}

.select-all-btn:hover {
    background-color: #eef2ff;
    /* text-decoration: underline; */
}

.clear-all-btn {
    color: #dc3545;
    display: none;
}

.clear-all-btn:hover {
    background-color: #fff0f1;
    /* text-decoration: underline; */
}

/* =========================================
   7. LOADING ANIMATION
   ========================================= */

#page-loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(255, 255, 255, 0.85);
    z-index: 99999;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    transition: opacity 0.5s ease-out;
}

/* ข้อความแจ้งเตือน */
.loading-text {
    margin-top: 20px;
    text-align: center;
    font-family: 'Prompt', sans-serif;
    color: #191D88;
    font-size: 1.2rem;
    animation: blink 1.5s infinite;
}

@keyframes blink {
    0% { opacity: 0.5; }
    50% { opacity: 1; }
    100% { opacity: 0.5; }
}

/* --- ส่วน CSS ของ Loader --- */
.loader {
  width: 120px;
  height: 22px;
  border-radius: 20px;
  color: #191D88;
  border: 2px solid;
  position: relative;
}
.loader::before {
  content: "";
  position: absolute;
  margin: 2px;
  inset: 0 100% 0 0;
  border-radius: inherit;
  background: currentColor;
  animation: l6 2s infinite;
}
@keyframes l6 {
    100% {inset:0}
}