/* Copyright (c) 2026 Dung1412. All Rights Reserved. */
/* ============================================================================
   GLOBAL UI / UX POLISH LAYER — PHÚ TÀI BIOENERGY WEBGIS
   Smooth Spring Motion • Frosted Glassmorphism • Custom Sliders & Scrollbars
   Dark & Light Theme Parity • Zero Breaking Changes to Core Layout
   ============================================================================ */

/* --- 1. Typography & Smooth Rendering --- */
html, body {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

/* --- 2. Ultra-Thin Translucent Scrollbars Everywhere --- */
* {
    scrollbar-width: thin;
    scrollbar-color: rgba(56, 189, 248, 0.32) transparent;
}

*::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

*::-webkit-scrollbar-track {
    background: transparent;
}

*::-webkit-scrollbar-thumb {
    background: rgba(148, 163, 184, 0.28);
    border-radius: 999px;
    border: 1px solid transparent;
    background-clip: padding-box;
    transition: background 0.2s ease;
}

*::-webkit-scrollbar-thumb:hover {
    background: rgba(56, 189, 248, 0.58);
}

/* --- 3. Refined Top Header & Tactile Pill Buttons --- */
html:not([data-theme="light"]) .app-header {
    background: linear-gradient(180deg, rgba(8, 17, 29, 0.94) 0%, rgba(6, 13, 22, 0.92) 100%) !important;
    backdrop-filter: blur(22px) saturate(140%) !important;
    -webkit-backdrop-filter: blur(22px) saturate(140%) !important;
    border-bottom: 1px solid rgba(56, 189, 248, 0.2) !important;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.45), inset 0 -1px 0 rgba(16, 185, 129, 0.14) !important;
}

.app-header .btn-header,
.app-header .btn-header-dropdown {
    border-radius: 9px !important;
    transition: transform 0.16s cubic-bezier(0.22, 1, 0.36, 1),
                box-shadow 0.2s ease,
                background-color 0.2s ease,
                border-color 0.2s ease !important;
}

.app-header .btn-header:hover,
.app-header .btn-header-dropdown:hover {
    transform: translateY(-1px);
    box-shadow: 0 5px 14px rgba(0, 0, 0, 0.32);
}

.app-header .btn-header:active,
.app-header .btn-header-dropdown:active {
    transform: translateY(0) scale(0.97) !important;
}

/* --- 4. Smooth Dropdown & Modal Spring Entrances --- */
@keyframes ptSpringDrop {
    from { opacity: 0; transform: translateY(-6px) scale(0.97); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

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

@keyframes ptPopupBloom {
    from { opacity: 0; transform: translateY(6px) scale(0.94); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.header-dropdown-menu.open,
.header-dropdown-menu.show,
#theme-switcher-menu:not([hidden]) {
    animation: ptSpringDrop 0.19s cubic-bezier(0.22, 1, 0.36, 1);
    backdrop-filter: blur(20px) saturate(135%) !important;
    -webkit-backdrop-filter: blur(20px) saturate(135%) !important;
    border-radius: 12px !important;
    box-shadow: 0 18px 44px rgba(0, 0, 0, 0.58), 0 0 0 1px rgba(56, 189, 248, 0.16) inset !important;
}

.header-dropdown-menu .dropdown-item {
    border-radius: 8px !important;
    transition: background-color 0.15s ease, transform 0.15s ease, color 0.15s ease !important;
}

.header-dropdown-menu .dropdown-item:hover {
    transform: translateX(3px);
}

.modal-overlay.open {
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
}

.modal-overlay.open > div,
.modal-overlay.open .modal-content,
.modal-overlay.open .modal-card {
    animation: ptSpringModal 0.22s cubic-bezier(0.22, 1, 0.36, 1);
}

/* --- 5. Sidebar KPI Stat Cards (Fix Number Clipping + Glass Depth) --- */
.stats-grid .stat-card,
.kpi-card {
    border-radius: 12px !important;
    transition: transform 0.18s cubic-bezier(0.22, 1, 0.36, 1),
                border-color 0.2s ease,
                box-shadow 0.2s ease !important;
    overflow: hidden;
}

.stats-grid .stat-card:hover {
    transform: translateY(-2px);
    border-color: rgba(56, 189, 248, 0.42) !important;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.32);
}

.stats-grid .stat-value {
    font-size: clamp(13px, 1.15vw, 17px) !important;
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.3px;
    word-break: break-word;
    line-height: 1.25 !important;
}

.sidebar,
aside.sidebar {
    transition: width 0.28s cubic-bezier(0.22, 1, 0.36, 1),
                transform 0.28s cubic-bezier(0.22, 1, 0.36, 1) !important;
}

.nav-tab {
    transition: all 0.18s cubic-bezier(0.22, 1, 0.36, 1) !important;
}

.plot-card,
.layer-item-card {
    transition: transform 0.16s cubic-bezier(0.22, 1, 0.36, 1),
                background-color 0.18s ease,
                border-color 0.18s ease,
                box-shadow 0.18s ease !important;
}

.plot-card:hover {
    transform: translateY(-1px);
}

/* --- 6. Sleek Custom Range Sliders Across Whole App --- */
input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    height: 6px;
    border-radius: 999px;
    background: linear-gradient(90deg, rgba(14, 165, 233, 0.35), rgba(16, 185, 129, 0.45));
    outline: none;
    transition: background 0.2s ease;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 15px;
    height: 15px;
    border-radius: 50%;
    background: linear-gradient(135deg, #f8fafc, #38bdf8);
    border: 2px solid #0f172a;
    box-shadow: 0 0 0 2px rgba(56, 189, 248, 0.42), 0 2px 8px rgba(0, 0, 0, 0.55);
    cursor: pointer;
    transition: transform 0.14s cubic-bezier(0.22, 1, 0.36, 1), box-shadow 0.16s ease;
}

input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.18);
    box-shadow: 0 0 0 4px rgba(56, 189, 248, 0.35), 0 3px 12px rgba(14, 165, 233, 0.6);
}

input[type="range"]::-moz-range-thumb {
    width: 15px;
    height: 15px;
    border-radius: 50%;
    background: linear-gradient(135deg, #f8fafc, #38bdf8);
    border: 2px solid #0f172a;
    box-shadow: 0 0 0 2px rgba(56, 189, 248, 0.42), 0 2px 8px rgba(0, 0, 0, 0.55);
    cursor: pointer;
    transition: transform 0.14s ease, box-shadow 0.16s ease;
}

/* --- 7. Frosted Glassmorphism MapLibre Popups (Dark & Light Parity!) --- */
.maplibregl-popup {
    z-index: 40 !important;
}

.maplibregl-popup-content {
    animation: ptPopupBloom 0.2s cubic-bezier(0.22, 1, 0.36, 1);
    border-radius: 14px !important;
    padding: 12px 14px !important;
    font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, sans-serif !important;
}

html:not([data-theme="light"]) .maplibregl-popup-content {
    background: linear-gradient(165deg, rgba(11, 22, 36, 0.96), rgba(7, 14, 24, 0.98)) !important;
    backdrop-filter: blur(20px) saturate(145%) !important;
    -webkit-backdrop-filter: blur(20px) saturate(145%) !important;
    border: 1px solid rgba(56, 189, 248, 0.42) !important;
    color: #f1f5f9 !important;
    box-shadow: 0 18px 46px rgba(0, 0, 0, 0.72), 0 0 24px rgba(14, 165, 233, 0.16), inset 0 1px 0 rgba(255, 255, 255, 0.1) !important;
}

/* Override legacy dark inline colors inside MapLibre hover/click popups when dark theme is active */
html:not([data-theme="light"]) .maplibregl-popup-content div[style*="color:#1e293b"],
html:not([data-theme="light"]) .maplibregl-popup-content div[style*="color: #1e293b"],
html:not([data-theme="light"]) .maplibregl-popup-content div[style*="color:#0f172a"],
html:not([data-theme="light"]) .maplibregl-popup-content div[style*="color: #0f172a"],
html:not([data-theme="light"]) .maplibregl-popup-content div[style*="color:#334155"],
html:not([data-theme="light"]) .maplibregl-popup-content div[style*="color: #334155"],
html:not([data-theme="light"]) .maplibregl-popup-content div[style*="color:#475569"],
html:not([data-theme="light"]) .maplibregl-popup-content div[style*="color: #475569"],
html:not([data-theme="light"]) .maplibregl-popup-content span[style*="color:#0f172a"],
html:not([data-theme="light"]) .maplibregl-popup-content span[style*="color:#1e293b"],
html:not([data-theme="light"]) .maplibregl-popup-content span[style*="color:#334155"] {
    color: #f1f5f9 !important;
}

html:not([data-theme="light"]) .maplibregl-popup-content [style*="color:#0284c7"],
html:not([data-theme="light"]) .maplibregl-popup-content [style*="color: #0284c7"],
html:not([data-theme="light"]) .maplibregl-popup-content [style*="color:#0369a1"],
html:not([data-theme="light"]) .maplibregl-popup-content [style*="color: #0369a1"],
html:not([data-theme="light"]) .maplibregl-popup-content [style*="color:#1d4ed8"],
html:not([data-theme="light"]) .maplibregl-popup-content [style*="color:#2563eb"] {
    color: #38bdf8 !important;
}

html:not([data-theme="light"]) .maplibregl-popup-content [style*="color:#64748b"],
html:not([data-theme="light"]) .maplibregl-popup-content [style*="color: #64748b"] {
    color: #94a3b8 !important;
}

html:not([data-theme="light"]) .maplibregl-popup-content [style*="border-bottom:1px solid #e2e8f0"],
html:not([data-theme="light"]) .maplibregl-popup-content [style*="border-bottom: 1px solid #e2e8f0"] {
    border-bottom-color: rgba(148, 163, 184, 0.28) !important;
    color: #ffffff !important;
}

html:not([data-theme="light"]) .maplibregl-popup-content b,
html:not([data-theme="light"]) .maplibregl-popup-content strong {
    color: #f8fafc;
}

html:not([data-theme="light"]) .maplibregl-popup-tip {
    border-top-color: rgba(11, 22, 36, 0.95) !important;
    border-bottom-color: rgba(11, 22, 36, 0.95) !important;
    border-left-color: rgba(11, 22, 36, 0.95) !important;
    border-right-color: rgba(11, 22, 36, 0.95) !important;
}

html[data-theme="light"] .maplibregl-popup-content {
    background: rgba(255, 255, 255, 0.95) !important;
    backdrop-filter: blur(18px) !important;
    -webkit-backdrop-filter: blur(18px) !important;
    border: 1px solid rgba(14, 165, 233, 0.28) !important;
    color: #0f172a !important;
    box-shadow: 0 16px 38px rgba(15, 23, 42, 0.18) !important;
}

.maplibregl-popup-close-button {
    top: 7px !important;
    right: 7px !important;
    width: 24px !important;
    height: 24px !important;
    border-radius: 50% !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    font-size: 15px !important;
    line-height: 1 !important;
    color: #94a3b8 !important;
    background: rgba(148, 163, 184, 0.14) !important;
    transition: background 0.15s ease, color 0.15s ease, transform 0.15s ease !important;
}

.maplibregl-popup-close-button:hover {
    background: rgba(239, 68, 68, 0.26) !important;
    color: #fecaca !important;
    transform: rotate(90deg);
}

/* --- 8. Frosted Glass MapLibre Controls & Scale & Bottom Coordinate HUD --- */
html:not([data-theme="light"]) .maplibregl-ctrl-group {
    background: rgba(9, 19, 32, 0.88) !important;
    backdrop-filter: blur(16px) !important;
    -webkit-backdrop-filter: blur(16px) !important;
    border: 1px solid rgba(56, 189, 248, 0.28) !important;
    border-radius: 11px !important;
    box-shadow: 0 8px 22px rgba(0, 0, 0, 0.5) !important;
    overflow: hidden;
}

html:not([data-theme="light"]) .maplibregl-ctrl-group button {
    border-color: rgba(148, 163, 184, 0.16) !important;
    transition: background-color 0.15s ease !important;
}

html:not([data-theme="light"]) .maplibregl-ctrl-group button:hover {
    background-color: rgba(56, 189, 248, 0.22) !important;
}

html:not([data-theme="light"]) .maplibregl-ctrl-group button .maplibregl-ctrl-icon {
    filter: invert(1) brightness(1.25);
}

html:not([data-theme="light"]) .maplibregl-ctrl-scale {
    background: rgba(9, 19, 32, 0.82) !important;
    backdrop-filter: blur(10px) !important;
    border-color: rgba(56, 189, 248, 0.65) !important;
    color: #e2e8f0 !important;
    border-radius: 4px;
    font-weight: 700 !important;
    font-size: 10.5px !important;
    padding: 1px 6px !important;
}

/* Smooth transitions on Basemap Picker & Timeline Dock */
#basemap-picker,
#satellite-timeline {
    transition: width 0.24s cubic-bezier(0.22, 1, 0.36, 1),
                border-radius 0.22s ease,
                padding 0.22s ease,
                box-shadow 0.22s ease !important;
}

/* --- 9. Subtle Toast Feedback Stack --- */
#pt-ux-toast-stack {
    position: fixed;
    right: 16px;
    bottom: 46px;
    z-index: 9800;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
    max-width: min(360px, calc(100vw - 32px));
}

.pt-ux-toast {
    pointer-events: auto;
    padding: 9px 13px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 700;
    color: #f8fafc;
    background: rgba(9, 19, 33, 0.94);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
    border: 1px solid rgba(56, 189, 248, 0.42);
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.55);
    display: flex;
    align-items: center;
    gap: 8px;
    animation: ptSpringDrop 0.22s cubic-bezier(0.22, 1, 0.36, 1);
    transition: opacity 0.22s ease, transform 0.22s ease;
}

.pt-ux-toast.success { border-color: rgba(52, 211, 153, 0.65); }
.pt-ux-toast.danger { border-color: rgba(248, 113, 113, 0.68); }
.pt-ux-toast.hiding { opacity: 0; transform: translateY(8px) scale(0.96); }
