/*
 * PL Interactive Pipeline Map — Stylesheet
 * All selectors are scoped under .pl-pipe-map-widget to avoid polluting
 * the host WordPress theme. CSS custom properties are also namespaced with
 * --pl- to prevent collisions with theme variables.
 *
 * Version: 1.0.0
 */

/* ── Google Fonts ──────────────────────────────────────────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=Questrial&display=swap');

/* ── Design Tokens ─────────────────────────────────────────────────────────── */
.pl-pipe-map-widget {
    --pl-color-plant-off-load: #00c400;
    --pl-color-compression:    #ded39c;
    --pl-color-inactive:       #cd8966;
    --pl-color-gas:            #ffffff;
    --pl-color-amine:          #a952e6;

    --pl-color-pipe-harrah:    #ff5500;
    --pl-color-pipe-twin:      #38a800;
    --pl-color-pipe-cyclone:   #267300;
    --pl-color-pipe-woodford:  #00c5ff;
    --pl-color-pipe-pine:      #a83800;
    --pl-color-pipe-kinta:     #7a8ef5;
    --pl-color-pipe-blue:      #894465;
    --pl-color-pipe-matli:     #4ce600;
    --pl-color-pipe-milfay:    #0070ff;
    --pl-color-pipe-osage:     #004da8;

    --pl-color-toggle-off:     #5a5957;
    --pl-bg-sidebar:           rgba(43, 42, 40, 0.95);
}

/* ── Widget Shell ──────────────────────────────────────────────────────────── */
.pl-pipe-map-widget {
    position: relative;
    width: 100%;
    height: var(--pl-map-height, 600px);
    background-color: #1A1C19;
    color: #cdccca;
    font-family: "Helvetica LT Std", "Helvetica Neue", Helvetica, Arial, sans-serif;
    overflow: hidden;
    border-radius: 12px;
    box-sizing: border-box;
    /* Isolate the widget from the surrounding page stacking context */
    isolation: isolate;
}

/* Reset box-sizing for all children */
.pl-pipe-map-widget *,
.pl-pipe-map-widget *::before,
.pl-pipe-map-widget *::after {
    box-sizing: border-box;
}

/* ── Map Wrapper & Container ────────────────────────────────────────────────── */
.pl-map-wrapper {
    position: absolute;
    inset: 0;
    overflow: hidden;
    z-index: 1;
}

.pl-map-container {
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* Map SVG fills its container — width/height attributes are stripped via JS.
   Scoped to .pl-map-container so icon SVGs inside buttons are not affected. */
.pl-map-container svg {
    width: 100%;
    max-width: 100%;
    height: 100%;
    display: block; /* removes inline baseline gap */
}

/* Lock icon SVGs (mobile button, close button) to their intrinsic pixel size */
.pl-mobile-menu-btn svg,
.pl-close-sidebar svg {
    width: 22px;
    min-width: 22px;
    height: 22px;
    flex-shrink: 0;
    display: block;
}

.pl-pipe-map-widget svg g {
    transition: filter 0.3s ease;
}

.pl-map-layer-glow {
    filter: drop-shadow(0 0 6px rgba(255, 255, 255, 0.8))
            drop-shadow(0 0 14px rgba(255, 255, 255, 0.5));
}

/* ── Loading / Error States ─────────────────────────────────────────────────── */
.pl-map-status {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    color: #9a9896;
    font-family: 'Questrial', sans-serif;
    font-size: 0.9rem;
    letter-spacing: 1px;
    text-transform: uppercase;
}

.pl-spinner {
    width: 32px;
    height: 32px;
    border: 3px solid rgba(255, 255, 255, 0.1);
    border-top-color: #9a9896;
    border-radius: 50%;
    animation: pl-spin 0.8s linear infinite;
}

.pl-map-status.pl-error .pl-spinner { display: none; }
.pl-map-status.pl-error             { color: #cd8966; }

@keyframes pl-spin {
    to { transform: rotate(360deg); }
}

/* ── Mobile Map Key Button — Hidden on Desktop ──────────────────────────────── */
.pl-mobile-menu-btn {
    display: none;
    position: absolute;
    top: 20px;
    left: 20px;
    z-index: 11;
    background: rgba(43, 42, 40, 0.8);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: #fff;
    width: 44px;
    min-width: 44px; /* Prevents flex parents from collapsing the button and hiding the icon */
    height: 44px;
    border-radius: 8px;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    transition: background 0.2s ease;
    align-items: center;
    justify-content: center;
    padding: 0;
}

.pl-mobile-menu-btn:hover {
    background: rgba(60, 59, 57, 0.9);
}

/* ── Mobile Backdrop Overlay ─────────────────────────────────────────────────── */
.pl-sidebar-backdrop {
    display: none;
    position: absolute;
    inset: 0;
    z-index: 9;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    transition: opacity 0.3s ease;
}

/* ── Sidebar ─────────────────────────────────────────────────────────────────── */
.pl-controls {
    position: absolute;
    top: 20px;
    left: 20px;
    bottom: 20px;
    width: 320px;
    background-color: var(--pl-bg-sidebar);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    padding: 30px;
    border-radius: 12px;
    overflow-y: auto;
    z-index: 10;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.4);
    border: 1px solid rgba(255, 255, 255, 0.05);
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.pl-controls::-webkit-scrollbar       { width: 6px; }
.pl-controls::-webkit-scrollbar-track { background: transparent; }
.pl-controls::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
}

/* ── Sidebar Header ──────────────────────────────────────────────────────────── */
.pl-sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 30px;
}

.pl-close-sidebar {
    display: none; /* Hidden on desktop */
    background: none;
    border: none;
    color: #797876;
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    transition: color 0.2s ease;
}

.pl-close-sidebar:hover { color: #fff; }

/* Override any theme h2 styling inside the widget */
.pl-pipe-map-widget .pl-map-title {
    font-family: 'Questrial', sans-serif !important;
    text-transform: uppercase;
    margin-top: 0 !important;
    margin-bottom: 5px !important;
    font-size: 1.75rem !important;
    font-weight: normal !important;
    color: #fff !important;
    letter-spacing: 2px;
    line-height: 1.2;
}

.pl-subtitle {
    font-family: 'Questrial', sans-serif;
    text-transform: uppercase;
    font-size: 0.75rem;
    color: #9a9896;
    letter-spacing: 1px;
}

/* Override any theme h3 styling inside the widget */
.pl-pipe-map-widget .pl-section-heading {
    font-family: 'Questrial', sans-serif !important;
    text-transform: uppercase;
    font-size: 0.8rem !important;
    color: #9a9896 !important;
    letter-spacing: 1px;
    margin-top: 30px !important;
    margin-bottom: 15px !important;
    padding-bottom: 10px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    font-weight: normal !important;
}

/* ── Layer Toggles ───────────────────────────────────────────────────────────── */
.pl-layer-toggle {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 12px;
    margin-bottom: 12px;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: normal;
    transition: color 0.2s ease;
}

.pl-layer-toggle:hover { color: #fff; }

.pl-toggle-all-row {
    font-weight: bold;
    color: #fff;
    margin-bottom: 15px;
    padding-bottom: 12px;
    border-bottom: 1px dashed rgba(255, 255, 255, 0.1);
}

/* Hide the native checkbox — the .pl-switch provides the visual */
.pl-layer-toggle input[type="checkbox"] { display: none; }

/* ── Toggle Switch ───────────────────────────────────────────────────────────── */
.pl-switch {
    position: relative;
    width: 32px;
    height: 18px;
    background-color: var(--pl-color-toggle-off);
    border-radius: 10px;
    transition: background-color 0.3s ease;
    flex-shrink: 0;
}

.pl-switch::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 14px;
    height: 14px;
    background-color: #fff;
    border-radius: 50%;
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1), background-color 0.3s ease;
}

.pl-layer-toggle input[type="checkbox"]:checked + .pl-switch {
    background-color: rgba(255, 255, 255, 0.2);
}

.pl-layer-toggle input[type="checkbox"]:checked + .pl-switch::after {
    transform: translateX(14px);
    background-color: var(--toggle-color, #4f98a3);
}

/* ── Zoom Controls ───────────────────────────────────────────────────────────── */
.pl-zoom-controls {
    position: absolute;
    bottom: 30px;
    right: 30px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 10;
}

.pl-zoom-controls button {
    background: rgba(43, 42, 40, 0.8);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: #fff;
    width: 44px;
    height: 44px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1.2rem;
    transition: all 0.2s ease;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    padding: 0;
    line-height: 1;
}

.pl-zoom-controls button:hover {
    background: rgba(60, 59, 57, 0.9);
    transform: translateY(-1px);
}

/* ── Responsive Heights ──────────────────────────────────────────────────────── */

/* Desktop (769px and above) */
@media (min-width: 769px) {
    .pl-pipe-map-widget {
        height: 814px;
    }
}

/* Tablet (481px – 768px) */
@media (min-width: 481px) and (max-width: 768px) {
    .pl-pipe-map-widget {
        height: 697px;
    }
}

/* Phone (480px and below) */
@media (max-width: 480px) {
    .pl-pipe-map-widget {
        height: 575px;
    }
}

/* ── Mobile Sidebar Behaviour (tablet + phone) ───────────────────────────────── */
@media (max-width: 768px) {
    .pl-mobile-menu-btn {
        display: flex;
    }

    .pl-controls {
        transform: translateX(-120%);
        width: calc(100% - 40px);
        max-width: 340px;
    }

    .pl-controls.pl-open {
        transform: translateX(0);
    }

    .pl-sidebar-backdrop.pl-open {
        display: block;
    }

    .pl-close-sidebar {
        display: block;
    }
}
