/* ============================================================================
   OpenLayers Professional Map Styles — LGU Portal Pro
   Comprehensive GIS styling for Philippine LGU & Barangay mapping
   ============================================================================ */

/* ── Base Map Container ─────────────────────────────────────────────────── */
.ol-map-container {
    position: relative;
    width: 100%;
    border-radius: 0.5rem;
    overflow: hidden;
    background: #e8ecf1;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
}
.ol-map-container .ol-viewport {
    border-radius: 0.5rem;
}

/* Full-height map pages */
.ol-map-fullpage {
    height: calc(100vh - 60px);
    border-radius: 0;
}
.ol-map-fullpage .ol-viewport {
    border-radius: 0;
}

/* Standard map heights */
.ol-map-lg  { height: 600px; }
.ol-map-md  { height: 450px; }
.ol-map-sm  { height: 300px; }
.ol-map-xs  { height: 200px; }
.ol-map-auto { height: calc(100vh - 250px); min-height: 500px; }

/* ── OL Native Controls Override ────────────────────────────────────────── */
.ol-zoom {
    top: auto;
    bottom: 2.5rem;
    left: 0.625rem;
}
.ol-zoom .ol-zoom-in,
.ol-zoom .ol-zoom-out {
    width: 2.25rem;
    height: 2.25rem;
    font-size: 1.125rem;
    font-weight: 600;
    background: #fff;
    color: #334155;
    border: none;
    border-radius: 0.5rem;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    margin-bottom: 0.25rem;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}
.ol-zoom .ol-zoom-in:hover,
.ol-zoom .ol-zoom-out:hover {
    background: #f1f5f9;
    color: #0f172a;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}
.ol-zoom .ol-zoom-in:focus,
.ol-zoom .ol-zoom-out:focus {
    outline: 2px solid #3b82f6;
    outline-offset: 2px;
}

.ol-rotate {
    display: none;
}

.ol-attribution {
    font-size: 0.65rem;
    background: rgba(255, 255, 255, 0.85) !important;
    border-radius: 0.375rem;
    padding: 0.125rem 0.5rem;
    backdrop-filter: blur(4px);
}
.ol-attribution:not(.ol-collapsed) {
    max-width: 360px;
}
.ol-attribution button {
    font-size: 0.7rem;
}

.ol-scale-line {
    bottom: 0.5rem;
    left: 3.5rem;
    background: rgba(255, 255, 255, 0.85);
    border-radius: 0.375rem;
    padding: 0.125rem 0.5rem;
    backdrop-filter: blur(4px);
}
.ol-scale-line-inner {
    border-color: #475569;
    color: #334155;
    font-size: 0.7rem;
    font-weight: 500;
}

/* ── Professional Popup / Overlay ───────────────────────────────────────── */
.ol-popup {
    position: absolute;
    background-color: #fff;
    padding: 0;
    border-radius: 0.75rem;
    border: none;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.18), 0 2px 8px rgba(0, 0, 0, 0.06);
    min-width: 220px;
    max-width: 360px;
    font-size: 0.875rem;
    transform: translate(-50%, calc(-100% - 16px));
    z-index: 100;
    animation: olPopupFadeIn 0.2s ease-out;
}
@keyframes olPopupFadeIn {
    from { opacity: 0; transform: translate(-50%, calc(-100% - 8px)) scale(0.95); }
    to   { opacity: 1; transform: translate(-50%, calc(-100% - 16px)) scale(1); }
}
.ol-popup::after {
    content: '';
    position: absolute;
    bottom: -8px;
    left: 50%;
    transform: translateX(-50%);
    width: 0;
    height: 0;
    border-style: solid;
    border-width: 8px 8px 0 8px;
    border-color: #fff transparent transparent transparent;
    filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.06));
}
.ol-popup-header {
    padding: 0.75rem 1rem 0.5rem;
    border-bottom: 1px solid #e2e8f0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}
.ol-popup-header h6 {
    margin: 0;
    font-size: 0.9rem;
    font-weight: 700;
    color: #0f172a;
    line-height: 1.3;
}
.ol-popup-close {
    background: none;
    border: none;
    color: #94a3b8;
    font-size: 1rem;
    cursor: pointer;
    padding: 0.125rem;
    line-height: 1;
    border-radius: 0.375rem;
    transition: all 0.15s;
    flex-shrink: 0;
}
.ol-popup-close:hover {
    color: #ef4444;
    background: #fef2f2;
}
.ol-popup-body {
    padding: 0.625rem 1rem 0.875rem;
}
.ol-popup-body table {
    width: 100%;
    font-size: 0.8rem;
}
.ol-popup-body table td {
    padding: 0.2rem 0;
    vertical-align: top;
}
.ol-popup-body table td:first-child {
    color: #64748b;
    padding-right: 0.75rem;
    white-space: nowrap;
    font-weight: 500;
}
.ol-popup-body table td:last-child {
    color: #1e293b;
    font-weight: 600;
}
.ol-popup-footer {
    padding: 0 1rem 0.75rem;
}
.ol-popup-footer .btn {
    font-size: 0.78rem;
    border-radius: 0.5rem;
}
/* Badge utilities inside popups */
.ol-popup .badge-risk {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 1rem;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}
.ol-popup .badge-risk-very_high { background: #fde8e8; color: #991b1b; }
.ol-popup .badge-risk-high      { background: #fff7ed; color: #9a3412; }
.ol-popup .badge-risk-medium    { background: #fefce8; color: #854d0e; }
.ol-popup .badge-risk-low       { background: #f0fdf4; color: #166534; }
.ol-popup .badge-risk-very_low  { background: #f1f5f9; color: #475569; }

/* ── Professional Legend Control ─────────────────────────────────────────── */
.ol-legend {
    position: absolute;
    bottom: 2rem;
    right: 0.75rem;
    z-index: 50;
    background: #fff;
    padding: 0.875rem 1rem;
    border-radius: 0.75rem;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
    min-width: 160px;
    max-width: 260px;
    font-size: 0.78rem;
    backdrop-filter: blur(4px);
    border: 1px solid rgba(0, 0, 0, 0.05);
}
.ol-legend h6 {
    margin: 0 0 0.625rem 0;
    font-size: 0.82rem;
    font-weight: 700;
    color: #0f172a;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.ol-legend-item {
    display: flex;
    align-items: center;
    margin-bottom: 0.375rem;
    gap: 0.5rem;
}
.ol-legend-item:last-child { margin-bottom: 0; }
.ol-legend-color {
    width: 1rem;
    height: 0.875rem;
    border-radius: 0.25rem;
    flex-shrink: 0;
    border: 1px solid rgba(0, 0, 0, 0.06);
}
.ol-legend-circle {
    width: 0.875rem;
    height: 0.875rem;
    border-radius: 50%;
    flex-shrink: 0;
    border: 2px solid #fff;
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.1);
}
.ol-legend-label {
    color: #475569;
    font-weight: 500;
    line-height: 1.3;
}

/* ── Floating Map Toolbar ───────────────────────────────────────────────── */
.ol-toolbar {
    position: absolute;
    top: 0.75rem;
    right: 0.75rem;
    z-index: 50;
    display: flex;
    flex-direction: column;
    gap: 0.375rem;
}
.ol-toolbar .ol-tool-btn {
    width: 2.25rem;
    height: 2.25rem;
    background: #fff;
    color: #475569;
    border: none;
    border-radius: 0.5rem;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.875rem;
    transition: all 0.2s ease;
}
.ol-toolbar .ol-tool-btn:hover {
    background: #f1f5f9;
    color: #0f172a;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.18);
}
.ol-toolbar .ol-tool-btn.active {
    background: #3b82f6;
    color: #fff;
    box-shadow: 0 2px 8px rgba(59, 130, 246, 0.4);
}
.ol-toolbar .ol-tool-btn.active:hover {
    background: #2563eb;
}

/* ── Status Bar ─────────────────────────────────────────────────────────── */
.ol-status-bar {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 50;
    background: rgba(15, 23, 42, 0.8);
    color: #e2e8f0;
    padding: 0.25rem 0.75rem;
    font-size: 0.7rem;
    font-family: 'SF Mono', 'Fira Code', Consolas, monospace;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    backdrop-filter: blur(6px);
}
.ol-status-bar .status-sep {
    color: #475569;
}
.ol-status-bar .status-label {
    color: #94a3b8;
}
.ol-status-bar .status-value {
    color: #f1f5f9;
    font-weight: 500;
}

/* ── Layer Switcher Panel ───────────────────────────────────────────────── */
.ol-layer-switcher {
    position: absolute;
    top: 0.75rem;
    left: 0.75rem;
    z-index: 50;
    background: #fff;
    border-radius: 0.75rem;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
    overflow: hidden;
    min-width: 200px;
    max-height: calc(100% - 6rem);
    overflow-y: auto;
}
.ol-layer-switcher-header {
    padding: 0.75rem 1rem;
    background: linear-gradient(135deg, #1e40af 0%, #3b82f6 100%);
    color: #fff;
    font-weight: 700;
    font-size: 0.82rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.ol-layer-group-title {
    padding: 0.5rem 1rem 0.25rem;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: #94a3b8;
    border-top: 1px solid #f1f5f9;
}
.ol-layer-group-title:first-of-type { border-top: none; }
.ol-layer-item {
    padding: 0.375rem 1rem;
}
.ol-layer-item .form-check-label {
    font-size: 0.82rem;
    font-weight: 500;
    color: #334155;
}

/* ── Measure Tooltip ────────────────────────────────────────────────────── */
.ol-measure-tooltip {
    position: relative;
    background: rgba(15, 23, 42, 0.85);
    color: #f1f5f9;
    padding: 0.25rem 0.625rem;
    border-radius: 0.375rem;
    font-size: 0.75rem;
    font-weight: 600;
    font-family: 'SF Mono', Consolas, monospace;
    white-space: nowrap;
    backdrop-filter: blur(4px);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}
.ol-measure-tooltip::after {
    content: '';
    position: absolute;
    bottom: -5px;
    left: 50%;
    transform: translateX(-50%);
    border: 5px solid transparent;
    border-top-color: rgba(15, 23, 42, 0.85);
}
.ol-measure-tooltip-static {
    background: rgba(59, 130, 246, 0.9);
    color: #fff;
}
.ol-measure-tooltip-static::after {
    border-top-color: rgba(59, 130, 246, 0.9);
}

/* ── Loading Spinner ────────────────────────────────────────────────────── */
.ol-map-loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 60;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    background: rgba(255, 255, 255, 0.95);
    padding: 0.75rem 1.25rem;
    border-radius: 2rem;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
    font-size: 0.82rem;
    font-weight: 600;
    color: #475569;
    backdrop-filter: blur(4px);
}
.ol-map-loading .spinner-border {
    width: 1.25rem;
    height: 1.25rem;
    border-width: 2px;
}

/* ── Risk/Hazard Color Palette ──────────────────────────────────────────── */
:root {
    --risk-very-high: #dc2626;
    --risk-high: #f97316;
    --risk-medium: #eab308;
    --risk-low: #22c55e;
    --risk-very-low: #6b7280;
    --hazard-flood: #0d6efd;
    --hazard-landslide: #6f4e37;
    --hazard-storm-surge: #6610f2;
    --hazard-earthquake: #dc3545;
    --hazard-tsunami: #0891b2;
    --hazard-liquefaction: #d97706;
    --brgy-boundary: #3b82f6;
    --evac-center: #16a34a;
    --tourism: #06b6d4;
    --government: #eab308;
    --infrastructure: #8b5cf6;
}

/* ── Map Picker (CMS Forms) ─────────────────────────────────────────────── */
.ol-map-picker-wrapper {
    position: relative;
    border-radius: 0.625rem;
    overflow: hidden;
    border: 1px solid #d1d5db;
    background: #f8fafc;
    transition: border-color 0.2s;
}
.ol-map-picker-wrapper:focus-within {
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}
.ol-map-picker-wrapper .ol-map-picker-map {
    width: 100%;
    height: 300px;
    z-index: 0;
    cursor: crosshair;
}
/* Search bar overlay */
.ol-map-picker-search {
    position: absolute;
    top: 0.625rem;
    left: 3.125rem;
    right: 3.125rem;
    z-index: 100;
}
.ol-map-picker-search .input-group {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    border-radius: 0.5rem;
    overflow: hidden;
}
.ol-map-picker-search input {
    border: none;
    font-size: 0.82rem;
    padding: 0.5rem 0.75rem;
    background: #fff;
}
.ol-map-picker-search input:focus {
    box-shadow: none;
    background: #fff;
}
.ol-map-picker-search .btn {
    border: none;
    background: #fff;
    color: #64748b;
    padding: 0.5rem 0.625rem;
}
.ol-map-picker-search .btn:hover {
    background: #f1f5f9;
    color: #0f172a;
}
.ol-map-picker-search .search-results {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: #fff;
    border-radius: 0 0 0.5rem 0.5rem;
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.12);
    max-height: 200px;
    overflow-y: auto;
    display: none;
    z-index: 101;
}
.ol-map-picker-search .search-results.active {
    display: block;
}
.ol-map-picker-search .search-result-item {
    padding: 0.5rem 0.75rem;
    cursor: pointer;
    font-size: 0.8rem;
    border-bottom: 1px solid #f1f5f9;
    transition: background 0.15s;
}
.ol-map-picker-search .search-result-item:last-child { border-bottom: none; }
.ol-map-picker-search .search-result-item:hover { background: #f8fafc; }
/* Picker toolbar */
.ol-map-picker-toolbar {
    position: absolute;
    bottom: 0.625rem;
    left: 0.625rem;
    z-index: 100;
    display: flex;
    gap: 0.375rem;
}
.ol-map-picker-toolbar .btn {
    background: #fff;
    color: #475569;
    border: none;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
    border-radius: 0.5rem;
    padding: 0.375rem 0.625rem;
    font-size: 0.78rem;
    cursor: pointer;
    transition: all 0.2s;
}
.ol-map-picker-toolbar .btn:hover  {
    background: #f1f5f9;
    color: #0f172a;
}
.ol-map-picker-toolbar .btn.locating { color: #3b82f6; }
/* Tile switcher */
.ol-map-picker-tiles {
    position: absolute;
    bottom: 0.625rem;
    right: 0.625rem;
    z-index: 100;
}
.ol-map-picker-tiles .btn {
    background: #fff;
    color: #475569;
    border: none;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
    border-radius: 0.5rem;
    padding: 0.375rem 0.625rem;
    font-size: 0.75rem;
    cursor: pointer;
    transition: all 0.2s;
}
.ol-map-picker-tiles .btn:hover { background: #f1f5f9; }
/* Coordinate readout */
.ol-map-picker-coords {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.375rem 0.75rem;
    background: #f8fafc;
    border-top: 1px solid #e2e8f0;
    font-size: 0.78rem;
    color: #64748b;
}
.ol-map-picker-coords .coord-value {
    font-family: 'SF Mono', Consolas, monospace;
    color: #1e293b;
    font-weight: 600;
}
.ol-map-picker-hint {
    text-align: center;
    font-size: 0.72rem;
    color: #94a3b8;
    padding: 0.25rem 0;
    background: #f8fafc;
}

/* ── Detail Page Mini-Maps ──────────────────────────────────────────────── */
.ol-detail-map {
    height: 280px;
    border-radius: 0.625rem;
    overflow: hidden;
    border: 1px solid #e2e8f0;
}
.ol-detail-map-sm { height: 180px; }

/* ── Dark Mode Support ──────────────────────────────────────────────────── */
[data-bs-theme="dark"] .ol-popup {
    background: #1e293b;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
}
[data-bs-theme="dark"] .ol-popup::after {
    border-color: #1e293b transparent transparent transparent;
}
[data-bs-theme="dark"] .ol-popup-header {
    border-color: #334155;
}
[data-bs-theme="dark"] .ol-popup-header h6 { color: #f1f5f9; }
[data-bs-theme="dark"] .ol-popup-body table td:first-child { color: #94a3b8; }
[data-bs-theme="dark"] .ol-popup-body table td:last-child  { color: #e2e8f0; }

[data-bs-theme="dark"] .ol-legend {
    background: #1e293b;
    border-color: #334155;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
}
[data-bs-theme="dark"] .ol-legend h6 { color: #e2e8f0; }
[data-bs-theme="dark"] .ol-legend-label { color: #94a3b8; }

[data-bs-theme="dark"] .ol-toolbar .ol-tool-btn {
    background: #1e293b;
    color: #94a3b8;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}
[data-bs-theme="dark"] .ol-toolbar .ol-tool-btn:hover {
    background: #334155;
    color: #f1f5f9;
}

[data-bs-theme="dark"] .ol-status-bar {
    background: rgba(0, 0, 0, 0.7);
}

[data-bs-theme="dark"] .ol-zoom .ol-zoom-in,
[data-bs-theme="dark"] .ol-zoom .ol-zoom-out {
    background: #1e293b;
    color: #94a3b8;
}
[data-bs-theme="dark"] .ol-zoom .ol-zoom-in:hover,
[data-bs-theme="dark"] .ol-zoom .ol-zoom-out:hover {
    background: #334155;
    color: #f1f5f9;
}
[data-bs-theme="dark"] .ol-layer-switcher {
    background: #1e293b;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
}
[data-bs-theme="dark"] .ol-layer-group-title {
    color: #64748b;
    border-color: #334155;
}
[data-bs-theme="dark"] .ol-layer-item .form-check-label { color: #e2e8f0; }

[data-bs-theme="dark"] .ol-map-picker-wrapper {
    border-color: #334155;
    background: #0f172a;
}
[data-bs-theme="dark"] .ol-map-picker-coords {
    background: #0f172a;
    border-color: #334155;
    color: #64748b;
}
[data-bs-theme="dark"] .ol-map-picker-coords .coord-value { color: #e2e8f0; }
[data-bs-theme="dark"] .ol-map-picker-hint { background: #0f172a; color: #475569; }
[data-bs-theme="dark"] .ol-map-picker-search input { background: #1e293b; color: #e2e8f0; }
[data-bs-theme="dark"] .ol-map-picker-search .btn { background: #1e293b; color: #94a3b8; }
[data-bs-theme="dark"] .ol-map-picker-search .search-results { background: #1e293b; }
[data-bs-theme="dark"] .ol-map-picker-search .search-result-item { border-color: #334155; }
[data-bs-theme="dark"] .ol-map-picker-search .search-result-item:hover { background: #0f172a; }
[data-bs-theme="dark"] .ol-map-picker-toolbar .btn,
[data-bs-theme="dark"] .ol-map-picker-tiles .btn {
    background: #1e293b;
    color: #94a3b8;
}

/* ── Map Control Buttons (blocks-style) ─────────────────────────────────── */
.ol-base-layer-switcher {
    position: absolute;
    bottom: 0.75rem;
    right: 0.75rem;
    z-index: 50;
    display: flex;
    gap: 0.25rem;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 0.5rem;
    padding: 0.25rem;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
    backdrop-filter: blur(6px);
}
.ol-base-layer-btn {
    border: none;
    background: transparent;
    color: #64748b;
    padding: 0.375rem 0.625rem;
    font-size: 0.72rem;
    font-weight: 600;
    border-radius: 0.375rem;
    cursor: pointer;
    transition: all 0.2s;
}
.ol-base-layer-btn.active {
    background: #3b82f6;
    color: #fff;
}
.ol-base-layer-btn:hover:not(.active) {
    background: #f1f5f9;
    color: #0f172a;
}

[data-bs-theme="dark"] .ol-base-layer-switcher {
    background: rgba(30, 41, 59, 0.95);
}
[data-bs-theme="dark"] .ol-base-layer-btn { color: #94a3b8; }
[data-bs-theme="dark"] .ol-base-layer-btn:hover:not(.active) { background: #334155; color: #f1f5f9; }

/* ── Responsive ─────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
    .ol-popup { min-width: 180px; max-width: 280px; }
    .ol-legend { bottom: 1rem; right: 0.5rem; font-size: 0.72rem; min-width: 140px; }
    .ol-toolbar .ol-tool-btn { width: 2rem; height: 2rem; font-size: 0.8rem; }
    .ol-map-lg { height: 400px; }
    .ol-map-auto { height: calc(100vh - 200px); min-height: 350px; }
}
