/* Font Import */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

*,
*::before,
*::after {
    box-sizing: border-box;
}

:root {
    --bg-dark: #0f172a;
    --bg-glass: rgba(15, 23, 42, 0.85);
    --border-glass: rgba(255, 255, 255, 0.1);
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --accent-risk-high: #ef4444;
    --accent-risk-med: #f59e0b;
    --accent-risk-low: #10b981;
    --primary-action: #38bdf8;
    --accent-hero: #c084fc;

    --shadow-soft: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-glow: 0 0 15px rgba(56, 189, 248, 0.15);
    --shadow-hero: 0 0 30px rgba(192, 132, 252, 0.3);
}

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-dark);
    color: var(--text-primary);
    margin: 0;
    padding: 0;
    overflow: hidden;
    height: 100vh;
    width: 100vw;
}

/* Map Container */
#map {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
}

/* Scanner Overlay */
#map::after {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 2px;
    background: linear-gradient(to right, transparent, var(--primary-action), transparent);
    z-index: 10;
    opacity: 0.3;
    pointer-events: none;
    animation: scanner-move 8s linear infinite;
    box-shadow: 0 0 15px var(--primary-action);
}

@keyframes scanner-move {
    0% {
        top: 0;
    }

    50% {
        top: 100%;
    }

    100% {
        top: 0;
    }
}

/* UI Overlay Container */
.ui-overlay {
    position: relative;
    z-index: 1000;
    pointer-events: none;
    /* Let clicks pass through empty spaces */
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 1.5rem;
}

/* Common Glassmorphism */
.glass-panel {
    background: var(--bg-glass);
    -webkit-backdrop-filter: blur(12px);
    backdrop-filter: blur(12px);
    border: 1px solid var(--border-glass);
    border-radius: 12px;
    box-shadow: var(--shadow-soft);
    pointer-events: auto;
    /* Re-enable clicks */
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

/* Header */
header.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    margin-bottom: 1rem;
}

.app-title h1 {
    font-size: 1.25rem;
    font-weight: 700;
    margin: 0;
    letter-spacing: -0.025em;
    background: linear-gradient(135deg, #fff 0%, #cbd5e1 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.app-subtitle {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin: 0;
    margin-top: 0.25rem;
    font-weight: 400;
}

/* Sidebar / Controls */
.sidebar {
    width: 320px;
    max-height: calc(100vh - 120px);
    display: flex;
    flex-direction: column;
    padding: 0;
    overflow: hidden;
    /* Header will be sticky-ish, body scrolls */
    z-index: 10;
}

.sidebar-header,
.status-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border-glass);
    background: rgba(255, 255, 255, 0.02);
    min-height: 50px;
    box-sizing: border-box;
}

.sidebar-title-wrap {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.sidebar-body {
    flex: 1;
    overflow-y: auto;
    padding: 0;
    /* Remove padding to handle it in sections */
    display: flex;
    flex-direction: column;
    /* scrollbar-gutter: stable; */
    /* Causes Safari lint warning, removed */
    transition: opacity 0.3s ease;
}

.panel-section {
    border-bottom: 1px solid var(--border-glass);
}

.panel-section:last-child {
    border-bottom: none;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.25rem;
    cursor: pointer;
    transition: background 0.2s ease;
}

.section-header:hover {
    background: rgba(255, 255, 255, 0.03);
}

.section-title {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    margin-bottom: 0;
    font-weight: 600;
}

.section-chevron {
    transition: transform 0.3s ease;
    color: var(--text-secondary);
}

.panel-section.collapsed .section-chevron {
    transform: rotate(-90deg);
}

.section-content {
    padding: 0 1.25rem 1.25rem 1.25rem;
    max-height: 1000px;
    /* High enough for content */
    overflow: hidden;
    transition: max-height 0.4s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.3s ease, padding 0.3s ease;
}

.panel-section.collapsed .section-content {
    max-height: 0;
    opacity: 0;
    padding-top: 0;
    padding-bottom: 0;
    pointer-events: none;
}


/* Custom Checkboxes */
.layer-toggle-group {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.layer-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 6px;
    transition: background 0.2s;
}

.layer-item:hover {
    background: rgba(255, 255, 255, 0.05);
}

.layer-checkbox {
    appearance: none;
    width: 1.1em;
    height: 1.1em;
    border: 2px solid var(--text-secondary);
    border-radius: 4px;
    background-color: transparent;
    display: grid;
    place-content: center;
    transition: all 0.2s;
}

.layer-checkbox::before {
    content: "";
    width: 0.65em;
    height: 0.65em;
    transform: scale(0);
    transition: 120ms transform ease-in-out;
    box-shadow: inset 1em 1em var(--bg-dark);
    transform-origin: center;
    clip-path: polygon(14% 44%, 0 65%, 50% 100%, 100% 16%, 80% 0%, 43% 62%);
}

.layer-checkbox:checked {
    border-color: var(--primary-action);
    background-color: var(--primary-action);
}

.layer-checkbox:checked::before {
    transform: scale(1);
    background-color: white;
    /* Important, was using box-shadow trick which fails on solid */
    box-shadow: none;
    background-color: var(--bg-dark);
}

.layer-label {
    font-size: 0.9rem;
    font-weight: 500;
}

/* Sidebar Layer Groups */
.layer-group-header {
    font-size: 0.65rem;
    text-transform: uppercase;
    color: var(--text-secondary);
    font-weight: 700;
    letter-spacing: 0.05em;
    padding-bottom: 0.25rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    margin-bottom: 0.5rem;
    opacity: 0.8;
}

.sub-layer-group {
    padding-left: 0.5rem;
    border-left: 2px solid rgba(255, 255, 255, 0.1);
    margin-left: 0.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.layer-item.sm {
    padding: 0.25rem 0.5rem;
}

.layer-item.sm .layer-label {
    font-size: 0.8rem;
    font-weight: 400;
}

.layer-item.sm .layer-checkbox {
    width: 0.9em;
    height: 0.9em;
}

.mt-sm {
    margin-top: 0.5rem;
}

/* Insight Card */
.insight-card {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 8px;
    padding: 1rem;
    margin-top: 0.5rem;
}

.insight-metric {
    display: flex;
    justify-content: space-between;
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
}

.insight-value {
    font-weight: 600;
    color: var(--primary-action);
}

.insight-desc {
    font-size: 0.8rem;
    color: var(--text-secondary);
    line-height: 1.4;
    font-style: italic;
    border-left: 2px solid var(--primary-action);
    padding-left: 0.75rem;
    margin-top: 0.75rem;
}

/* Popups */
.leaflet-popup-content-wrapper {
    background: var(--bg-dark);
    color: var(--text-primary);
    border: 1px solid var(--border-glass);
    border-radius: 8px;
}

.leaflet-popup-tip {
    background: var(--bg-dark);
}

.popup-header {
    font-weight: 700;
    border-bottom: 1px solid var(--border-glass);
    padding-bottom: 0.5rem;
    margin-bottom: 0.5rem;
}

.popup-row {
    display: flex;
    justify-content: space-between;
    margin-bottom: 0.25rem;
    font-size: 0.85rem;
}

/* Legend/Disclaimer Bottom Right */
.bottom-panel {
    position: absolute;
    bottom: 1.5rem;
    right: 1.5rem;
    max-width: 350px;
    font-size: 0.85rem;
    color: var(--text-secondary);
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0;
    z-index: 10;
    overflow: hidden;
}

.status-board {
    border-right: 4px solid var(--accent-risk-low);
    min-width: 220px;
}

.status-row {
    display: flex;
    justify-content: space-between;
    padding: 0.25rem 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.03);
}

.status-row:last-of-type {
    border-bottom: none;
}

.status-row-wrap {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    white-space: nowrap;
    flex-shrink: 0;
}

.status-header {
    /* Styles unified with .sidebar-header above */
    width: 100%;
    /* Keep width 100% for status-header specifically */
}

.status-title-wrap {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.status-title-wrap .status-dot {
    width: 8px;
    height: 8px;
}

.status-body {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    padding: 1.25rem;
    box-sizing: border-box;
}

.status-light {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #4ade80;
    /* Green */
    box-shadow: 0 0 10px #4ade80;
    flex-shrink: 0;
}

.status-light.offline {
    background: #ef4444;
    /* Red */
    box-shadow: 0 0 10px #ef4444;
}

.status-title,
.sidebar-header .section-title {
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-size: 0.75rem;
    font-weight: 600;
    margin: 0 !important;
}

.status-details {
    font-size: 0.75rem;
    line-height: 1.5;
}

.status-active {
    color: var(--accent-risk-low);
}

.status-primary-text {
    color: var(--text-primary);
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.75rem;
    color: var(--accent-risk-low);
}

.status-dot {
    width: 8px;
    height: 8px;
    background: #4ade80;
    /* Default Green */
    border-radius: 50%;
    box-shadow: 0 0 8px #4ade80;
    transition: all 0.3s ease;
}

.status-dot.yellow {
    background: #facc15;
    box-shadow: 0 0 8px #facc15;
    animation: pulse-status-yellow 2s infinite;
}

.status-dot.red {
    background: #ef4444;
    box-shadow: 0 0 10px #ef4444;
}

@keyframes pulse-status-yellow {
    0% {
        opacity: 1;
    }

    50% {
        opacity: 0.5;
    }

    100% {
        opacity: 1;
    }
}

.status-row-dot {
    width: 0.5rem;
    height: 0.5rem;
    border-radius: 50%;
    background: #4ade80;
    flex-shrink: 0;
}

.status-row-dot.red {
    background: #ef4444;
    box-shadow: 0 0 4px #ef4444;
}

.status-row-dot.yellow {
    background: #facc15;
    box-shadow: 0 0 4px #facc15;
}

.status-details a {
    color: inherit;
    text-decoration: none;
    border-bottom: 1px dashed rgba(255, 255, 255, 0.2);
    transition: all 0.2s;
}

.status-details a:hover {
    color: var(--primary-action);
    border-bottom-style: solid;
    border-bottom-color: var(--primary-action);
}

.feed-container {
    font-size: 0.8rem;
    color: var(--text-secondary);
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.feed-item {
    padding: 0.75rem;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 6px;
    transition: all 0.3s ease;
}

.grid-link {
    cursor: pointer;
    color: var(--primary-action);
    text-decoration: underline;
    text-underline-offset: 2px;
    font-weight: 600;
    transition: all 0.2s ease;
}

.grid-link:hover {
    color: #fff;
    text-shadow: 0 0 8px var(--primary-action);
}

.feed-item:hover {
    background: rgba(255, 255, 255, 0.06);
    transform: translateX(4px);
}

.critical-alert {
    border-left: 3px solid var(--accent-risk-high);
    background: rgba(239, 68, 68, 0.05);
}

.feed-item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.25rem;
}

.feed-timestamp {
    font-size: 0.65rem;
    color: rgba(255, 255, 255, 0.3);
}

.feed-item-title {
    color: var(--text-primary);
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.critical-highlight {
    color: var(--accent-risk-high);
    font-weight: 600;
}

.signal-highlight {
    color: #facc15;
}

.vector-card {
    background: rgba(56, 189, 248, 0.05);
    border-color: rgba(56, 189, 248, 0.2);
}

.glfc-vector-card {
    border-left: 3px solid #38bdf8;
    background: rgba(56, 189, 248, 0.08);
}

.vector-header {
    font-size: 0.75rem;
    color: var(--primary-action);
    font-weight: 600;
    margin-bottom: 0.4rem;
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.vector-icon {
    font-size: 1rem;
}

.vector-text {
    font-size: 0.75rem;
    line-height: 1.4;
    color: var(--text-secondary);
}

.credits {
    margin-top: 0.5rem;
    font-size: 0.7rem;
    color: rgba(255, 255, 255, 0.3);
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    padding-top: 0.5rem;
    padding-bottom: 10px;
}

.credits a {
    color: rgba(255, 255, 255, 0.5);
    text-decoration: none;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    transition: all 0.2s ease;
}

.credits a:hover {
    color: #fff;
    border-bottom-color: #fff;
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.1);
}

::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* Collapsible & Toggle Button */
.toggle-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    transition: all 0.2s;
}

.toggle-btn:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
}

/* Common Collapse Animation */
.sidebar .sidebar-body,
.status-board .status-body {
    transition: max-height 0.4s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.3s ease, padding 0.3s ease, margin 0.3s ease;
    overflow: hidden;
}

.sidebar.collapsed .sidebar-body,
.status-board.collapsed .status-body {
    max-height: 0 !important;
    opacity: 0 !important;
    padding-top: 0 !important;
    padding-bottom: 0 !important;
    margin-top: 0 !important;
    margin-bottom: 0 !important;
    pointer-events: none;
}

.sidebar.collapsed,
.status-board.collapsed {
    max-height: fit-content !important;
}

/* Integrated Status Section */
.status-section {
    border-top: 1px solid var(--border-glass);
    padding-top: 1.25rem;
    margin-top: 0.5rem;
}

.status-section .credits {
    border-top: none;
    margin-top: 0.75rem;
    padding-top: 0;
}

/* Responsiveness - Side-by-Side Mobile Layout */
@media screen and (max-width: 768px) {
    .ui-overlay {
        padding: 0.75rem;
    }

    .sidebar,
    .status-board {
        position: fixed !important;
        bottom: 0.75rem !important;
        width: calc(50% - 1.15rem) !important;
        max-height: calc(100vh - 120px) !important;
        margin: 0 !important;
        right: auto !important;
        display: flex;
        flex-direction: column;
    }

    .sidebar-header,
    .status-header {
        padding: 0.6rem 0.75rem !important;
        min-height: 45px !important;
    }

    .sidebar-header .section-title,
    .status-title {
        font-size: 0.65rem !important;
    }

    .sidebar {
        left: 0.75rem !important;
    }

    .status-board {
        right: 0.75rem !important;
    }

    /* Adjust font sizes for tight space */
    .section-title {
        font-size: 0.65rem;
    }

    .insight-metric span,
    .layer-label {
        font-size: 0.8rem;
    }

    .status-primary-text {
        font-size: 0.7rem;
    }

    .status-row {
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: space-between;
        align-items: center;
        gap: 0.25rem 0.5rem;
    }

    .credits {
        font-size: 0.6rem;
    }
}

@media screen and (max-height: 700px) {
    .sidebar {
        max-height: calc(100vh - 80px);
    }

    .sidebar-body {
        gap: 0.75rem;
        padding: 1rem;
    }

    .panel-section {
        margin-bottom: 0.5rem;
    }
}

/* Pulse animation for the master status dot when active */
.status-dot.active {
    animation: status-pulse 2s infinite;
}

@keyframes status-pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(74, 222, 128, 0.4);
    }

    70% {
        box-shadow: 0 0 0 10px rgba(74, 222, 128, 0);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(74, 222, 128, 0);
    }
}