:root {
    --primary-blue: #4EBCD6;
    --sidebar-bg: #ffffff; /* Persistent sidebar light background */
    --sidebar-text: #191c1d;
    --main-bg: #f8faf9; /* M3 background light */
    --card-bg: #ffffff;
    --text-main: #191c1d; /* M3 on-surface light */
    --text-muted: #5c5f60; /* M3 outline light */
    --border-color: #e0e3e3; /* M3 divider */

    /* Google Material 3 Design System Variables */
    --md-sys-color-primary: #006876;
    --md-sys-color-on-primary: #ffffff;
    --md-sys-color-primary-container: #a1efff;
    --md-sys-color-on-primary-container: #001f25;
    --md-sys-color-secondary: #4a6266;
    --md-sys-color-on-secondary: #ffffff;
    --md-sys-color-secondary-container: #cde7ec;
    --md-sys-color-on-secondary-container: #051f22;
    --md-sys-color-surface: #f8faf9;
    --md-sys-color-on-surface: #191c1d;
    --md-sys-color-surface-container: #ecf0f1;
    --md-sys-color-surface-container-high: #e2e5e5;
    --md-sys-color-outline: #70787a;
    --md-sys-color-outline-variant: #bfc8ca;
    --md-sys-color-error: #ba1a1a;
    
    --md-ref-typeface-brand: 'Inter', sans-serif;
    --md-ref-typeface-plain: 'Roboto', sans-serif;
}

body {
    background-color: var(--main-bg);
    color: var(--text-main);
    font-family: 'Inter', 'Roboto', sans-serif;
    margin: 0;
    overflow-x: hidden;
}

#app-container {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* Horizontal Top App Bar */
.top-app-bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 64px;
    background-color: #ffffff;
    border-bottom: 1px solid var(--border-color);
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    z-index: 1010;
}

.top-bar-left {
    display: flex;
    align-items: center;
    gap: 32px;
}

.app-logo-link {
    display: flex;
    align-items: center;
    gap: 12px;
    text-decoration: none;
    color: var(--text-main);
}

.app-logo {
    height: 32px;
    width: 32px;
    object-fit: contain;
}

.app-title {
    font-weight: 700;
    font-size: 1.15rem;
    letter-spacing: -0.02em;
    font-family: 'Inter', sans-serif;
}

.top-nav {
    display: flex;
    align-items: center;
    gap: 8px;
}

.top-nav-item {
    display: flex;
    align-items: center;
    gap: 8px;
    text-decoration: none;
    color: var(--text-muted);
    font-weight: 500;
    font-size: 0.9rem;
    padding: 8px 16px;
    border-radius: 20px;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.top-nav-item span {
    font-size: 20px;
}

.top-nav-item:hover {
    color: var(--text-main);
    background-color: var(--md-sys-color-surface-container);
}

.top-nav-item.active {
    color: var(--md-sys-color-primary);
    background-color: var(--md-sys-color-primary-container);
    font-weight: 600;
}

.user-controls {
    display: flex;
    align-items: center;
    gap: 16px;
    position: relative;
}

/* Master Grid Layout with Filters Left Sidebar */
.main-layout {
    display: flex;
    margin-top: 64px;
    min-height: calc(100vh - 64px);
    width: 100vw;
}

/* Filters Left Sidebar */
.filters-sidebar {
    width: 300px;
    flex-shrink: 0;
    background-color: var(--sidebar-bg);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 64px;
    bottom: 0;
    left: 0;
    z-index: 1000;
    box-sizing: border-box;
}

.filters-sidebar .sidebar-header {
    padding: 16px 24px;
    display: flex;
    align-items: center;
    gap: 12px;
    font-weight: 600;
    font-size: 1rem;
    color: var(--text-main);
    border-bottom: 1px solid var(--border-color);
}

.filters-sidebar .sidebar-header span {
    font-size: 20px;
    color: var(--text-muted);
}

.sidebar-filters {
    padding: 24px;
    flex-grow: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.filter-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
    transition: opacity 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.filter-label {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
}

/* Dimmed and Locked state for inactive page filters */
.filter-group.disabled-group {
    opacity: 0.35;
    pointer-events: none;
}

.sidebar-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--border-color);
    background-color: #ffffff;
}

/* Main Content Wrapper */
#main-content {
    flex-grow: 1;
    margin-left: 300px;
    padding: 32px;
    box-sizing: border-box;
    overflow-y: auto;
    min-width: 0; /* Prevents flex children from stretching */
}

.content-header {
    margin-bottom: 24px;
}

.page-title {
    margin: 0;
    font-size: 1.75rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--text-main);
}

.content-body {
    width: 100%;
}

/* Cards & Layout */
.card {
    background: var(--card-bg);
    border-radius: 16px;
    border: 1px solid var(--border-color);
    box-shadow: 0 1px 3px rgba(0,0,0,0.04), 0 2px 8px rgba(0,0,0,0.04);
    padding: 24px;
    margin-bottom: 24px;
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1), box-shadow 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 16px rgba(0,0,0,0.06), 0 2px 4px rgba(0,0,0,0.04);
}

.card-title {
    font-size: 0.875rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    font-weight: 600;
    margin-bottom: 8px;
}

.card-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-main);
}

/* Grid Layouts */
.grid {
    display: grid;
    gap: 24px;
}

.grid-cols-2 { grid-template-columns: repeat(2, 1fr); }
.grid-cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid-cols-4 { grid-template-columns: repeat(4, 1fr); }

@media (max-width: 1024px) {
    .grid-cols-4 { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 640px) {
    .grid-cols-2, .grid-cols-3, .grid-cols-4 { grid-template-columns: 1fr; }
}

.flex { display: flex; }
.flex-col { flex-direction: column; }
.gap-4 { gap: 1rem; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.w-full { width: 100%; }
.mt-8 { margin-top: 2rem; }

/* Tab content styling */
.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* Dynamic Loading Spinner styling overrides */
.d-none { display: none !important; }

/* Unified Outlined Fields Height Mapping for Material 3 */
md-outlined-text-field {
    --md-outlined-text-field-container-height: 48px;
    --md-outlined-text-field-container-shape: 8px;
    width: 100%;
}


/* Scrollbar customization using M3 properties */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--main-bg);
}

::-webkit-scrollbar-thumb {
    background: var(--md-sys-color-outline-variant);
    border-radius: 8px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--md-sys-color-outline);
}

/* Leaflet map M3 integrations */
.leaflet-container {
    font-family: inherit !important;
    border: 1px solid var(--border-color) !important;
}

.leaflet-popup-content-wrapper {
    border-radius: 12px !important;
    background-color: var(--card-bg) !important;
    color: var(--text-main) !important;
    box-shadow: 0 4px 16px rgba(0,0,0,0.1) !important;
    border: 1px solid var(--border-color);
}

.leaflet-popup-tip {
    background-color: var(--card-bg) !important;
}

/* md-dialog custom properties to match exact M3 rounded styling */
md-dialog {
    --md-dialog-container-color: var(--card-bg);
    --md-dialog-headline-color: var(--text-main);
    --md-dialog-supporting-text-color: var(--text-muted);
    --md-dialog-container-shape: 28px; /* M3 rounded-container shape spec */
    --md-dialog-headline-font: 'Inter', sans-serif;
    --md-dialog-headline-size: 24px;
    --md-dialog-headline-weight: 500;
}

/* Native Material 3 Multi-Select Styles */
.m3-multi-select {
    position: relative;
    width: 100%;
}

.menu-search-container {
    background-color: var(--card-bg);
    position: sticky;
    top: 0;
    z-index: 10;
    margin-bottom: 8px;
    border-bottom: 1px solid var(--border-color);
}

.menu-options-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.menu-option-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 12px;
    border-radius: 8px;
    cursor: pointer;
    user-select: none;
    transition: background-color 0.15s ease;
}

.menu-option-row:hover {
    background-color: rgba(0, 104, 118, 0.08); /* 8% primary M3 container state */
}

.menu-option-row md-checkbox {
    --md-checkbox-container-size: 18px;
    pointer-events: none; /* Let clicking the entire row row toggle the checkbox state */
}

.menu-option-row span {
    font-size: 0.9rem;
    color: var(--text-main);
    font-weight: 500;
}

.sidebar-filters {
    padding-top: 8px;
}

.filter-group.disabled-group {
    opacity: 0.35;
    pointer-events: none;
}

/* Custom M3 Combo-Box Dropdown */
.m3-dropdown-menu {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    width: 100%;
    min-width: 260px;
    box-sizing: border-box;
    background-color: var(--card-bg);
    border-radius: 12px;
    box-shadow: 0px 8px 24px rgba(0, 0, 0, 0.15);
    border: 1px solid var(--border-color);
    z-index: 1005;
    display: none;
    flex-direction: column;
    overflow: hidden;
    padding: 8px;
}

.m3-dropdown-menu.open {
    display: flex;
}

