:root {
    color-scheme: dark light;
}

html,
body {
    margin: 0;
    padding: 0;
    height: 100%;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI',
        sans-serif;
    background: #050712;
    color: #f4f4f4;
    overscroll-behavior-y: contain;
}

#app {
    display: flex;
    flex-direction: row;
    height: 100%;
    width: 100%;
    position: relative;
}

#map {
    flex: 1 1 auto;
    height: 100%;
    position: relative;
}

#fnewz-map-logo {
    position: absolute;
    left: 10px;
    bottom: 10px;
    width: 100px;
    height: 100px;
    opacity: 0.6;
    pointer-events: none;
    z-index: 500;
}

#fnewz-map-logo img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

#sidebar {
    width: 380px;
    max-width: 100%;
    background: rgba(7, 10, 24, 0.96);
    border-left: 1px solid rgba(255, 255, 255, 0.08);
    box-shadow: -4px 0 30px rgba(0, 0, 0, 0.4);
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: hidden;
}

#sidebar-header {
    padding: 14px 18px 10px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    background: radial-gradient(circle at top left,
            rgba(42, 176, 160, 0.25),
            rgba(7, 10, 24, 0.95));
    cursor: default;
}

#sidebar-header h1,
#sidebar-header small {
    font-family: 'Space Mono', ui-monospace, SFMono-Regular, Menlo, Monaco,
        Consolas, 'Liberation Mono', 'Courier New', monospace;
}

#sidebar-header h1 {
    margin: 0;
    font-size: 20px;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    display: flex;
    gap: 6px;
    align-items: center;
}

.brand-fnewz {
    color: #2ab0a0;
    font-weight: 700;
}

.brand-map-label {
    padding: 2px 8px;
    border-radius: 999px;
    background: rgba(15, 23, 42, 0.9);
    color: #e5e7eb;
    opacity: 0.95;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.18em;
}

.brand-tagline {
    display: block;
    margin-top: 6px;
    font-size: 11px;
    opacity: 0.75;
    color: #e5e7eb;
}

#sidebar-header::after {
    content: '';
    display: block;
    margin-top: 8px;
    width: 40%;
    height: 1px;
    background: linear-gradient(90deg,
            rgba(42, 176, 160, 0.9),
            rgba(148, 163, 184, 0.0));
}

#status-bar {
    margin-top: 4px;
    font-size: 11px;
    opacity: 0.7;
    min-height: 14px;
    align-self: center;
}

#gdelt-credit {
    margin-top: 4px;
    font-size: 10px;
    opacity: 0.65;
}

#gdelt-credit a {
    color: #2ab0a0;
    text-decoration: none;
}

#gdelt-credit a:hover {
    text-decoration: underline;
}

#controls {
    margin-top: 8px;
    padding: 0 16px 6px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: 12px;
}

.controls-row {
    display: flex;
    gap: 6px;
    flex-wrap: nowrap;
    align-items: center;
}

#controls input,
#controls select,
#controls button,
#controls label {
    font-size: 12px;
}

#controls input,
#controls select {
    padding: 4px 6px;
    border-radius: 4px;
    border: 1px solid rgba(255, 255, 255, 0.15);
    background: rgba(10, 14, 32, 0.95);
    color: #f4f4f4;
}

#q-input {
    flex: 1 1 auto;
}

#topic-select {
    flex: 0 0 120px;
}

#controls button {
    border-radius: 4px;
    border: none;
    background: #2ab0a0;
    color: #020308;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

#controls button:hover {
    filter: brightness(1.05);
}

#search-btn {
    flex: 0 0 34px;
    height: 28px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
}

#search-btn .icon-search::before {
    content: "🔍";
    display: inline-block;
    line-height: 1;
}

#sidebar-mobile-fab {
    position: fixed;
    left: 50%;
    bottom: 12px;
    transform: translateX(-50%);
    padding: 6px 12px;
    border-radius: 999px;
    border: 1px solid rgba(148, 163, 184, 0.6);
    background: rgba(7, 10, 24, 0.96);
    color: #e5e7eb;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    display: none;
    z-index: 950;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.45);
}

@media (prefers-color-scheme: light) {
    #sidebar-mobile-fab {
        background: rgba(255, 255, 255, 0.98);
        color: #111827;
        border-color: rgba(15, 23, 42, 0.2);
    }
}

#sidebar-list {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 8px 12px 12px;
}

.news-item {
    padding: 8px 8px 10px;
    border-radius: 8px;
    margin-bottom: 6px;
    background: rgba(14, 19, 42, 0.92);
    border: 1px solid transparent;
    cursor: pointer;
    transition: border-color 0.15s ease, background 0.15s ease,
        transform 0.12s ease;
}

.news-item:hover {
    border-color: rgba(42, 176, 160, 0.8);
    transform: translateY(-1px);
}

.news-item-inner {
    display: flex;
    gap: 8px;
}

.news-item-thumb {
    width: 56px;
    height: 56px;
    border-radius: 6px;
    overflow: hidden;
    flex-shrink: 0;
    background: rgba(255, 255, 255, 0.05);
}

.news-item-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.news-item-title {
    font-size: 13px;
    font-weight: 600;
    line-height: 1.3;
}

.news-item-meta {
    margin-top: 4px;
    font-size: 11px;
    opacity: 0.8;
}

.news-item-meta span+span::before {
    content: '•';
    margin: 0 4px;
    opacity: 0.6;
}

.news-marker {
    cursor: pointer;
}

.news-marker {
    cursor: pointer;
}

.leaflet-marker-icon.news-marker {
    width: auto !important;
    height: auto !important;
}

.news-marker-card {
    position: relative;
    background: rgba(7, 10, 24, 0.96);
    border-radius: 10px;
    border: 1px solid rgba(42, 176, 160, 0.7);
    box-shadow: 0 0 15px rgba(0, 0, 0, 0.6);
    display: inline-block;
    pointer-events: auto;
    max-width: 200px;
    overflow: hidden;
}

.news-marker-thumb {
    display: inline-block;
    max-width: 200px;
    max-height: 100px;
    background: rgba(255, 255, 255, 0.04);
}

.news-marker-thumb img {
    display: block;
    max-width: 100%;
    max-height: 100px;
    width: auto;
    height: 100px;
}

.news-marker-title {
    padding: 4px 6px 6px;
    font-size: 10px;
    line-height: 1.3;
}

.news-marker-close {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 16px;
    height: 16px;
    border-radius: 999px;
    border: none;
    background: rgba(0, 0, 0, 0.7);
    color: #f4f4f4;
    font-size: 11px;
    line-height: 1;
    cursor: pointer;
    padding: 0;
}

.news-marker-close:hover {
    background: rgba(0, 0, 0, 0.9);
}

.leaflet-popup-content-wrapper,
.leaflet-popup-tip {
    background: rgba(7, 10, 24, 0.97);
    color: #f4f4f4;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.leaflet-container a {
    color: #2ab0a0;
}

.popup-title {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 4px;
}

.popup-meta {
    font-size: 11px;
    opacity: 0.8;
    margin-bottom: 4px;
}

.popup-link {
    font-size: 11px;
}

details#more-filters {
    margin-top: 4px;
    border-radius: 6px;
    background: rgba(11, 16, 36, 0.95);
    border: 1px solid rgba(255, 255, 255, 0.08);
    padding: 4px 8px;
}

details#more-filters summary {
    list-style: none;
    cursor: pointer;
    font-size: 11px;
    opacity: 0.8;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 2px 0;
}

details#more-filters summary::-webkit-details-marker {
    display: none;
}

details#more-filters summary span.label {
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

details#more-filters summary span.chevron {
    font-size: 10px;
    opacity: 0.7;
}

#more-content {
    margin-top: 4px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.more-row {
    display: flex;
    gap: 6px;
    flex-wrap: nowrap;
}

#lang-select {
    flex: 1 1 auto;
}

#place-input {
    flex: 1 1 auto;
}

#place-btn {
    flex: 0 0 54px;
    height: 26px;
    padding: 0 6px;
    font-size: 11px;
}

#timespan-select {
    flex: 1 1 auto;
}

@media (prefers-color-scheme: light) {

    html,
    body {
        background: #f4f4f4;
        color: #111827;
    }

    #sidebar {
        background: rgba(255, 255, 255, 0.96);
        border-left: 1px solid rgba(15, 23, 42, 0.12);
    }

    #controls input,
    #controls select {
        background: rgba(255, 255, 255, 0.95);
        color: #111827;
        border-color: rgba(15, 23, 42, 0.15);
    }

    .news-item {
        background: rgba(255, 255, 255, 0.96);
    }

    .leaflet-popup-content-wrapper,
    .leaflet-popup-tip {
        background: rgba(255, 255, 255, 0.98);
        color: #111827;
        border-color: rgba(15, 23, 42, 0.15);
    }

    .news-marker-card {
        background: rgba(255, 255, 255, 0.98);
        border-color: rgba(37, 99, 235, 0.7);
    }

    details#more-filters {
        background: rgba(255, 255, 255, 0.98);
        border-color: rgba(15, 23, 42, 0.12);
    }

    #gdelt-credit a {
        color: #2563eb;
    }
}

#sidebar-toggle-handle {
    position: fixed;
    top: 50%;
    right: 380px;
    transform: translateY(-50%);
    width: 22px;
    height: 72px;
    border: none;
    border-radius: 12px 0 0 12px;
    background: linear-gradient(180deg,
            rgba(42, 176, 160, 0.95),
            rgba(15, 23, 42, 0.95));
    color: #020308;
    font-weight: 700;
    font-size: 16px;
    cursor: pointer;
    box-shadow: 0 0 18px rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 900;
}

#sidebar-toggle-handle:hover {
    filter: brightness(1.06);
}

#sidebar-toggle-handle::before {
    content: '';
    width: 2px;
    height: 40px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.24);
}

#app.sidebar-collapsed #sidebar {
    width: 0;
    max-width: 0;
    border-left: none;
    overflow: hidden;
}

#app.sidebar-collapsed #sidebar>* {
    opacity: 0;
    pointer-events: none;
}

#app.sidebar-collapsed #map {
    flex: 1 1 auto;
}

#sidebar {
    transition: width 0.22s ease;
}

#sidebar>*,
#map {
    transition: all 0.22s ease;
}

#gdelt-credit {
    margin-top: 4px;
    font-size: 10px;
    opacity: 0.65;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

#gdelt-warning {
    font-size: 9px;
    line-height: 1.3;
    opacity: 0.7;
}

#sidebar-mobile-header {
    display: none;
}

#gdelt-warning-mobile {
    display: none;
    /* hidden by default, shown only on mobile below */
    width: 100%;
    margin-top: 4px;
    font-size: 10px;
    color: #e5e7eb;
}

#gdelt-warning-mobile summary {
    cursor: pointer;
    list-style: none;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-weight: 500;
    opacity: 0.9;
}

#gdelt-warning-mobile summary::-webkit-details-marker {
    display: none;
}

#gdelt-warning-mobile p {
    margin: 4px 0 0;
    line-height: 1.35;
    opacity: 0.8;
}


@media (max-width: 768px) {
    #app {
        flex-direction: column;
    }

    #sidebar {
        width: 100vw;
        max-width: 100vw;
        height: 50%;
        max-height: 55%;
        box-sizing: border-box;
    }


    #map {
        height: 50%;
    }

    .controls-row {
        gap: 4px;
    }

    #sidebar-header {
        display: none;
    }

    #sidebar-mobile-header {
        display: flex;
        flex-direction: column;
        align-items: center;
        padding: 6px 12px 4px;
        position: relative;
        z-index: 2;
    }

    .sidebar-mobile-grip {
        width: 40px;
        height: 4px;
        border-radius: 999px;
        background: rgba(148, 163, 184, 0.8);
        opacity: 0.9;
        margin-bottom: 6px;
    }

    .sidebar-mobile-title-row {
        width: 100%;
        display: flex;
        align-items: center;
        justify-content: space-between;
        font-size: 11px;
        text-transform: uppercase;
        letter-spacing: 0.12em;
        opacity: 0.85;
    }

    .sidebar-mobile-title {
        font-weight: 600;
    }

    #sidebar-mobile-toggle {
        border: none;
        background: rgba(15, 23, 42, 0.9);
        color: #e5e7eb;
        border-radius: 999px;
        width: 26px;
        height: 18px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        font-size: 11px;
        cursor: pointer;
    }

    #sidebar-mobile-toggle:active {
        transform: translateY(1px);
    }

    #controls {
        margin-top: 4px;
    }

    /* handles we use for drag should not start page scroll */
    #sidebar-mobile-header,
    #status-bar {
        touch-action: none;
    }

    /* allow list itself to scroll normally */
    #sidebar-list {
        -webkit-overflow-scrolling: touch;
    }

    /* desktop-style fixed handle is hidden on mobile */
    #sidebar-toggle-handle {
        display: none;
    }

    #app.sidebar-collapsed #sidebar {
        height: 44px;
        max-height: 44px;
        border-radius: 16px 16px 0 0;
    }

    #app.sidebar-collapsed #controls,
    #app.sidebar-collapsed #status-bar,
    #app.sidebar-collapsed #sidebar-list {
        opacity: 0;
        pointer-events: none;
        height: 0;
        padding: 0;
        margin: 0;
    }

    #app.sidebar-collapsed #map {
        height: calc(100% - 44px);
    }

    #gdelt-warning-mobile {
        display: block;
    }

    /* since #sidebar-header is hidden on mobile, this is just a safety,
       but in case you ever show it, hide the long warning to avoid duplication */
    #gdelt-credit #gdelt-warning {
        display: none;
    }

    #sidebar-mobile-fab {
        font-size: 11px;
    }

    #app.sidebar-collapsed #sidebar-mobile-fab {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        gap: 4px;
    }
}