:root {
    --pv-red: #e31e24;
    --pv-bg-main: #0a0a0a;
    --pv-panel: #141414;
    --pv-border: #2a2a2a;
    --pv-text: #e0e0e0;
    --pv-text-muted: #888;
    --pv-highlight: #ffffff;
}

* { box-sizing: border-box; margin: 0; padding: 0; font-family: 'Segoe UI', Roboto, Helvetica, Arial, sans-serif; }
body { background-color: var(--pv-bg-main); color: var(--pv-text); display: flex; flex-direction: column; height: 100vh; overflow: hidden; }

/* --- NAVBAR --- */
.navbar {
    height: 64px; background: var(--pv-panel); display: flex; align-items: center; justify-content: space-between;
    padding: 0 24px; border-bottom: 2px solid var(--pv-red); z-index: 100; box-shadow: 0 4px 12px rgba(0,0,0,0.5); flex: 0 0 auto;
}
.nav-brand { display: flex; align-items: center; gap: 16px; }
.nav-brand img { height: 32px; }
.nav-title { font-size: 1.1rem; font-weight: 700; color: var(--pv-highlight); letter-spacing: 1px; border-left: 1px solid #333; padding-left: 16px; text-transform: uppercase; }
.nav-actions { display: flex; gap: 12px; }
.btn-outline { background: transparent; border: 1px solid #555; color: #fff; padding: 8px 16px; border-radius: 4px; cursor: pointer; font-size: 0.85rem; font-weight: 600; transition: 0.2s; }
.btn-outline:hover { background: var(--pv-red); border-color: var(--pv-red); }
.btn-outline.toggle-btn.active { background: var(--pv-red); border-color: var(--pv-red); }

.nav-unit-toggle { display: flex; background: #000; border: 1px solid #555; border-radius: 4px; overflow: hidden; }
.nav-unit-btn { padding: 8px 16px; background: transparent; border: none; color: #888; font-weight: 700; font-size: 0.85rem; cursor: pointer; transition: 0.2s; border-right: 1px solid #333; }
.nav-unit-btn:last-child { border-right: none; }
.nav-unit-btn.active { background: var(--pv-red); color: #fff; }
.nav-unit-btn:hover:not(.active) { color: #fff; background: #222; }

/* --- LAYOUT --- */
.app-layout { display: flex; flex: 1; overflow: hidden; }

.panel-left {
    width: 380px; background: var(--pv-panel); border-right: 1px solid var(--pv-border); padding: 24px;
    display: flex; flex-direction: column; gap: 24px; overflow: hidden; flex: 0 0 auto;
}
.panel-right {
    width: 360px; background: var(--pv-panel); border-left: 1px solid var(--pv-border); padding: 24px;
    display: flex; flex-direction: column; gap: 16px; overflow-y: auto; flex: 0 0 auto;
}

.section-title { font-size: 0.8rem; font-weight: 800; color: var(--pv-text-muted); text-transform: uppercase; letter-spacing: 1px; border-bottom: 1px solid var(--pv-border); padding-bottom: 8px; margin-bottom: 8px; }
.section-title span { color: var(--pv-red); }

.control-group { display: flex; flex-direction: column; gap: 8px; }
.control-group.list-group { flex: 1; min-height: 0; }

.inline-control { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.inline-control .inline-label { font-size: 0.8rem; font-weight: 600; color: #bbb; flex: 0 0 62px; white-space: nowrap; }
.inline-control select { flex: 1 1 auto; min-width: 0; }

.segmented-control { display: flex; background: #000; border-radius: 6px; padding: 4px; border: 1px solid var(--pv-border); }
.seg-btn { flex: 1; text-align: center; padding: 8px; cursor: pointer; font-size: 0.85rem; font-weight: 600; border-radius: 4px; color: #777; transition: 0.2s; }
.seg-btn.active { background: #222; color: #fff; box-shadow: 0 2px 4px rgba(0,0,0,0.5); border: 1px solid var(--pv-red); }

select, input[type="search"], input[type="text"] { width: 100%; background: #000; color: #fff; border: 1px solid var(--pv-border); padding: 10px 12px; border-radius: 6px; outline: none; font-size: 0.95rem; font-family: inherit; }
select:focus, input:focus { border-color: var(--pv-red); }

/* --- PROJECT LIST --- */
.site-list { list-style: none; overflow-y: auto; flex: 1; min-height: 0; margin-right: -8px; padding-right: 8px; }
.site-item {
    width: 100%; text-align: left; background: #000; border: 1px solid var(--pv-border); border-left: 3px solid transparent;
    border-radius: 6px; padding: 10px 12px; margin-bottom: 8px; cursor: pointer; transition: 0.2s;
    display: flex; align-items: center; gap: 12px;
}
.site-item:hover { border-color: var(--pv-red); border-left-color: var(--pv-red); background: #111; }
.site-item.active { border-left-color: var(--pv-red); background: #1a1a1a; }
.site-item-thumb { width: 44px; height: 34px; object-fit: cover; border-radius: 3px; flex: 0 0 auto; background: #1a1a1a; }
.site-item-body { flex: 1; min-width: 0; }
.site-item-name { font-size: 0.88rem; font-weight: 700; color: var(--pv-highlight); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.site-item-meta { font-size: 0.74rem; color: var(--pv-text-muted); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.site-item-sqm { font-size: 0.85rem; font-weight: 700; color: var(--pv-red); white-space: nowrap; flex: 0 0 auto; }
.empty-msg { font-size: 0.82rem; color: var(--pv-text-muted); padding: 8px 2px; }

/* --- SHEET GRIP (mobile only) --- */
.sheet-grip { display: none; }

/* --- STAGE / MAP --- */
.stage { flex: 1; position: relative; background-color: #050505; overflow: hidden; }
#map { position: absolute; inset: 0; }

.top-info-bar {
    position: absolute; top: 24px; left: 50%; transform: translateX(-50%); z-index: 30;
    display: flex; background: var(--pv-red); border-radius: 30px; box-shadow: 0 8px 24px rgba(227,30,36,0.3); overflow: hidden;
}
.info-seg { padding: 8px 22px; text-align: center; border-right: 1px solid rgba(255,255,255,0.3); }
.info-seg:last-child { border-right: none; }
.info-seg small { display: block; font-size: 0.58rem; font-weight: 700; color: rgba(255,255,255,0.8); letter-spacing: 1px; }
.info-seg span { display: block; font-weight: 800; font-size: 1.1rem; color: #fff; white-space: nowrap; }

.maplibregl-ctrl-attrib { background: rgba(0,0,0,0.7) !important; font-size: 10px; }
.maplibregl-ctrl-attrib a { color: var(--pv-text-muted) !important; }
.maplibregl-ctrl-group { background: var(--pv-panel) !important; border: 1px solid var(--pv-border) !important; box-shadow: none !important; }
.maplibregl-ctrl-group button + button { border-top: 1px solid var(--pv-border) !important; }
.maplibregl-ctrl-group button:hover { background: #222 !important; }
.maplibregl-ctrl-icon { filter: invert(1) brightness(0.85); }

/* --- HOVER CARD (map popup) --- */
.maplibregl-popup.pv-card .maplibregl-popup-content {
    padding: 0; background: var(--pv-panel); border: 1px solid var(--pv-border);
    border-top: 3px solid var(--pv-red); border-radius: 8px; width: 252px; overflow: hidden;
    box-shadow: 0 20px 60px rgba(0,0,0,0.9);
}
.maplibregl-popup.pv-card .maplibregl-popup-tip { display: none; }
.pv-card-img { display: block; width: 100%; height: 128px; object-fit: cover; background: #000; }
.pv-card-body { padding: 12px 14px 13px; }
.pv-card-name { font-size: 0.95rem; font-weight: 700; color: var(--pv-highlight); }
.pv-card-loc { font-size: 0.76rem; color: var(--pv-text-muted); margin-top: 3px; }
.pv-card-rows { margin-top: 10px; border-top: 1px solid #222; padding-top: 8px; }
.pv-card-row { display: flex; justify-content: space-between; padding: 3px 0; }
.pv-card-row span { font-size: 0.76rem; color: #aaa; font-weight: 600; }
.pv-card-row b { font-size: 0.82rem; color: var(--pv-highlight); font-weight: 700; }
.pv-card-row b.red { color: var(--pv-red); }
.pv-card-cta { margin-top: 9px; font-size: 0.66rem; font-weight: 800; letter-spacing: 1px; text-transform: uppercase; color: var(--pv-red); }
.pv-card-btn {
    margin-top: 10px; background: var(--pv-red); color: #fff; text-align: center;
    padding: 8px; border-radius: 6px; font-size: 0.78rem; font-weight: 700; transition: 0.2s;
}
.pv-card-btn:hover { background: #c11216; }
.maplibregl-popup.pv-card { cursor: pointer; }
/* wider invisible catch area so the pointer can travel from pin to card */
.maplibregl-popup.pv-card .maplibregl-popup-content { position: relative; }
.maplibregl-popup.pv-card .maplibregl-popup-content::before {
    content: ''; position: absolute; left: -20px; right: -20px; top: -24px; bottom: -20px; z-index: -1;
}

/* --- CLUSTER MARKERS --- */
.cluster-marker {
    width: 40px; height: 40px; border-radius: 50%; cursor: pointer;
    background: var(--pv-red); border: 2px solid rgba(255,255,255,0.9);
    display: flex; align-items: center; justify-content: center;
    box-shadow: 0 0 0 6px rgba(227,30,36,0.25), 0 6px 18px rgba(0,0,0,0.7);
    transition: transform 0.15s, box-shadow 0.15s;
}
.cluster-marker.is-big { width: 50px; height: 50px; }
.cluster-marker:hover { transform: scale(1.12); box-shadow: 0 0 0 9px rgba(227,30,36,0.32), 0 8px 22px rgba(0,0,0,0.8); }
.cluster-count { font-size: 0.95rem; font-weight: 800; color: #fff; line-height: 1; }
.cluster-marker.is-big .cluster-count { font-size: 1.05rem; }

/* --- RIGHT PANEL DATA --- */
.data-card { background: #000; padding: 16px; border-radius: 8px; border: 1px solid var(--pv-border); }
.data-card.highlight { border-left: 4px solid var(--pv-red); }
.data-row { display: flex; justify-content: space-between; align-items: center; padding: 6px 0; border-bottom: 1px solid #222; gap: 12px; }
.data-row:last-child { border-bottom: none; padding-bottom: 0; }
.data-lbl { font-size: 0.8rem; color: #aaa; font-weight: 600; }
.data-val { font-weight: 700; font-size: 0.95rem; color: var(--pv-highlight); text-align: right; }
.val-red { color: var(--pv-red); font-size: 1.1rem; }

.hint-card p { font-size: 0.78rem; line-height: 1.55; color: #999; }
.only-mobile { display: none; }

/* year bars */
.year-bar { display: flex; align-items: center; gap: 10px; padding: 4px 0; }
.year-bar-lbl { font-size: 0.75rem; color: #aaa; font-weight: 700; flex: 0 0 34px; }
.year-bar-track { flex: 1; height: 8px; background: #1c1c1c; border-radius: 4px; overflow: hidden; }
.year-bar-fill { display: block; height: 100%; background: var(--pv-red); }
.year-bar-val { font-size: 0.72rem; color: var(--pv-text-muted); flex: 0 0 auto; font-weight: 700; }

/* --- DETAIL PANE --- */
.detail-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 4px; }
.detail-year { font-size: 0.62rem; font-weight: 800; letter-spacing: 1px; text-transform: uppercase; color: var(--pv-red); }
.detail-name { font-size: 1.25rem; font-weight: 800; color: var(--pv-highlight); line-height: 1.2; margin-top: 6px; }
.detail-loc { font-size: 0.82rem; color: var(--pv-text-muted); margin-top: 4px; }
.detail-desc { font-size: 0.82rem; line-height: 1.55; color: #ccc; }
.btn-back { background: transparent; border: 1px solid #555; color: #fff; padding: 6px 10px; border-radius: 4px; cursor: pointer; font-size: 0.85rem; font-weight: 700; flex: 0 0 auto; transition: 0.2s; }
.btn-back:hover { background: var(--pv-red); border-color: var(--pv-red); }

.shot-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.shot-grid button { padding: 0; border: 1px solid var(--pv-border); border-radius: 6px; overflow: hidden; cursor: pointer; background: #000; line-height: 0; transition: 0.2s; }
.shot-grid button:first-child { grid-column: 1 / 3; }
.shot-grid button:hover { border-color: var(--pv-red); }
.shot-grid img { width: 100%; aspect-ratio: 4/3; object-fit: cover; display: block; }
.shot-grid button:first-child img { aspect-ratio: 16/9; }

.btn-action {
    background: #111; border: 1px solid var(--pv-border); color: #fff; padding: 16px; border-radius: 8px;
    cursor: pointer; text-align: left; display: flex; align-items: center; gap: 16px; transition: 0.2s; width: 100%;
}
.btn-action:hover { background: #1a1a1a; border-color: var(--pv-red); }
.btn-icon { color: var(--pv-red); font-size: 1.5rem; font-weight: bold; }
.btn-text h4 { font-size: 0.9rem; margin-bottom: 4px; color: var(--pv-highlight); }
.btn-text p { font-size: 0.75rem; color: var(--pv-text-muted); }
.btn-action-primary { background: var(--pv-red); border-color: var(--pv-red); }
.btn-action-primary:hover { background: #c11216; }
.btn-action-primary .btn-icon, .btn-action-primary .btn-text h4 { color: #fff; }
.btn-action-primary .btn-text p { color: rgba(255,255,255,0.8); }

/* --- MODAL / LIGHTBOX --- */
.modal-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,0.8); z-index: 2000;
    display: none; align-items: center; justify-content: center; backdrop-filter: blur(5px);
}
.modal-overlay.active { display: flex; }
.modal-card {
    background: var(--pv-panel); padding: 24px; border-radius: 12px; border: 2px solid var(--pv-red);
    box-shadow: 0 20px 60px rgba(0,0,0,0.9); display: flex; flex-direction: column; gap: 16px;
}
.modal-title { font-size: 1.1rem; font-weight: 800; color: var(--pv-highlight); }
.modal-btn { padding: 8px 14px; border: none; border-radius: 6px; cursor: pointer; font-weight: 700; font-size: 0.9rem; transition: 0.2s; }
.btn-scale { background: #222; color: #fff; border: 1px solid #444; }
.btn-scale:hover { background: #333; border-color: #666; }

.lightbox-card { width: min(1100px, 92vw); }
.lightbox-head { display: flex; justify-content: space-between; align-items: center; }
.lightbox-stage { display: flex; align-items: center; gap: 12px; }
.lightbox-stage img { flex: 1; min-width: 0; max-height: 72vh; object-fit: contain; border: 1px solid var(--pv-border); border-radius: 6px; background: #000; }
.lightbox-nav { background: #222; border: 1px solid #444; color: #fff; font-size: 1.6rem; line-height: 1; padding: 10px 14px; border-radius: 6px; cursor: pointer; transition: 0.2s; }
.lightbox-nav:hover { background: var(--pv-red); border-color: var(--pv-red); }
.lightbox-cap { font-size: 0.78rem; color: var(--pv-text-muted); text-align: center; }

::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: var(--pv-bg-main); }
::-webkit-scrollbar-thumb { background: #333; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--pv-red); }

@media (max-width: 1100px) and (min-width: 821px) {
    .panel-right { display: none; }
    .panel-right.is-open { display: flex; position: absolute; right: 0; top: 64px; bottom: 0; z-index: 60; }
}

/* ==========================================================
   MOBILE — map fills the screen, panels become bottom sheets
   ========================================================== */
@media (max-width: 820px) {
    body { overflow: hidden; }
    .hide-mobile { display: none !important; }
    .only-mobile { display: inline; }

    .navbar { height: 54px; padding: 0 12px; gap: 10px; }
    .nav-brand img { height: 24px; }
    .nav-title { display: none; }
    .nav-actions { gap: 8px; }
    .nav-unit-btn { padding: 7px 12px; font-size: 0.78rem; }
    .btn-icon-only { padding: 7px 12px; font-size: 1rem; line-height: 1; }

    .app-layout { display: block; position: relative; height: calc(100vh - 54px); height: calc(100dvh - 54px); }
    .stage { position: absolute; inset: 0; }

    /* stats strip, scrollable, tucked under the navbar */
    .top-info-bar {
        top: 10px; left: 10px; right: 10px; transform: none; width: auto;
        border-radius: 22px; overflow-x: auto; scrollbar-width: none; justify-content: flex-start;
    }
    .top-info-bar::-webkit-scrollbar { display: none; }
    .info-seg { padding: 6px 16px; flex: 0 0 auto; }
    .info-seg small { font-size: 0.52rem; }
    .info-seg span { font-size: 0.92rem; }

    /* keep zoom buttons clear of the sheet */
    .maplibregl-ctrl-bottom-right { bottom: 118px; }
    .maplibregl-ctrl-bottom-left { bottom: 96px; }
    .maplibregl-ctrl-group button { width: 40px !important; height: 40px !important; }

    /* ---------- bottom sheets ---------- */
    .sheet-grip {
        display: block; padding: 8px 4px 10px; cursor: grab; touch-action: none;
        flex: 0 0 auto; user-select: none;
    }
    .sheet-grip-bar { display: block; width: 40px; height: 4px; border-radius: 2px; background: #555; margin: 0 auto 10px; }
    .sheet-peek-row { display: flex; align-items: baseline; gap: 10px; padding: 0 4px 2px; }
    .sheet-peek-main { font-size: 0.95rem; font-weight: 700; color: var(--pv-highlight); }
    .sheet-peek-main b { color: var(--pv-red); }
    .sheet-peek-sub { font-size: 0.8rem; color: var(--pv-text-muted); flex: 1; }
    .sheet-peek-sub b { color: #ccc; font-weight: 700; }
    .sheet-peek-cta { font-size: 0.66rem; font-weight: 800; letter-spacing: 1px; text-transform: uppercase; color: var(--pv-red); }

    .panel-left {
        position: fixed; left: 0; right: 0; bottom: 0; top: auto; width: auto;
        height: 86vh; height: 86dvh; z-index: 60;
        border: 1px solid var(--pv-border); border-bottom: none; border-radius: 16px 16px 0 0;
        box-shadow: 0 -8px 30px rgba(0,0,0,0.7);
        padding: 0 16px 16px; gap: 16px;
        transform: translateY(calc(86vh - 96px)); transform: translateY(calc(86dvh - 96px));
        transition: transform 0.32s cubic-bezier(.22,.72,.24,1);
    }
    .panel-left.sheet-half { transform: translateY(46vh); transform: translateY(46dvh); }
    .panel-left.sheet-full { transform: translateY(0); }
    .panel-left.is-dragging { transition: none; }
    .panel-left .control-group:not(.list-group) { display: none; }
    .panel-left.sheet-half .control-group,
    .panel-left.sheet-full .control-group { display: flex; }

    .panel-right {
        position: fixed; left: 0; right: 0; bottom: 0; top: auto; width: auto;
        height: 92vh; height: 92dvh; z-index: 70; display: flex;
        border: 1px solid var(--pv-border); border-bottom: none; border-radius: 16px 16px 0 0;
        box-shadow: 0 -8px 30px rgba(0,0,0,0.8);
        padding: 0 16px 24px; gap: 14px;
        transform: translateY(100%);
        transition: transform 0.32s cubic-bezier(.22,.72,.24,1);
    }
    .panel-right.is-open { transform: translateY(0); }
    .panel-right.is-dragging { transition: none; }
    .sheet-grip--right { position: sticky; top: 0; background: var(--pv-panel); z-index: 2; }

    /* touch targets */
    .site-item { padding: 12px; margin-bottom: 10px; }
    .site-item-thumb { width: 54px; height: 42px; }
    .site-item-name { font-size: 0.92rem; }
    select, input[type="search"], input[type="text"] { padding: 12px; font-size: 16px; }
    .seg-btn { padding: 11px 8px; }
    .btn-action { padding: 14px; }
    .btn-back { padding: 10px 14px; font-size: 1rem; }

    .detail-name { font-size: 1.15rem; }
    .shot-grid { grid-template-columns: 1fr 1fr; }

    /* hover cards make no sense on touch — the sheet does the job */
    .maplibregl-popup.pv-card { display: none; }

    /* full-bleed photo viewer */
    .modal-overlay { padding: 0; }
    .lightbox-card { width: 100vw; height: 100vh; height: 100dvh; max-width: none; border: none; border-radius: 0; padding: 14px; justify-content: center; }
    .lightbox-stage { gap: 6px; }
    .lightbox-stage img { max-height: 66vh; }
    .lightbox-nav { padding: 14px 10px; font-size: 1.4rem; }
    .lightbox-head { position: absolute; top: 10px; left: 14px; right: 14px; }
}

@media (max-width: 820px) and (orientation: landscape) {
    .panel-left { height: 92vh; transform: translateY(calc(92vh - 88px)); }
    .panel-left.sheet-half { transform: translateY(40vh); }
    .lightbox-stage img { max-height: 74vh; }
}
