:root {
    --bg: #e9eef3;
    --surface: #ffffff;
    --surface-soft: #f4f6f8;
    --text: #111827;
    --muted: #5f6b7a;
    --line: #cfd7df;
    --line-strong: #aeb8c3;
    --accent: #172033;
    --focus: #1d4ed8;
    --shadow: 0 12px 28px rgba(15, 23, 42, .10);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
    margin: 0;
    color: var(--text);
    background: var(--bg);
    font-family: Poppins, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button, input, textarea, select { font: inherit; }
.leaflet-container { font-family: Poppins, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }

.app-shell {
    min-height: 100%;
    padding: 18px;
}

.site-header {
    min-height: 76px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    max-width: 1680px;
    margin: 0 auto 14px;
    padding: 0 2px;
}
.site-header h1 {
    margin: 3px 0 0;
    font-size: clamp(1.55rem, 2.5vw, 2.35rem);
    line-height: 1.05;
    letter-spacing: -.035em;
}
.eyebrow {
    margin: 0;
    color: var(--muted);
    font-size: .7rem;
    font-weight: 800;
    letter-spacing: .14em;
    text-transform: uppercase;
}
.mobile-panel-toggle {
    display: none;
    border: 1px solid var(--accent);
    background: var(--accent);
    color: #fff;
    padding: 10px 14px;
}

.workspace {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(310px, 390px);
    gap: 14px;
    height: calc(100vh - 126px);
    min-height: 590px;
    max-width: 1680px;
    margin: 0 auto;
}
.map-column, .sidebar {
    position: relative;
    overflow: hidden;
    background: var(--surface);
    border: 1px solid var(--line-strong);
    box-shadow: var(--shadow);
}
.map-column { min-width: 0; }
.map { width: 100%; height: 100%; min-height: 560px; background: #dce5ec; }

.search-panel {
    position: absolute;
    z-index: 900;
    top: 14px;
    right: 14px;
    left: auto;
    width: min(480px, calc(100% - 28px));
}
.search-box {
    display: grid;
    grid-template-columns: 28px 1fr 34px;
    align-items: center;
    min-height: 50px;
    padding: 0 8px 0 13px;
    background: rgba(255,255,255,.98);
    border: 1px solid var(--line-strong);
    box-shadow: 0 8px 20px rgba(15, 23, 42, .14);
}
.search-icon { color: var(--muted); font-size: 1.3rem; transform: rotate(-15deg); }
.search-box input { width: 100%; border: 0; outline: 0; background: transparent; color: var(--text); }
.search-box input::placeholder { color: #8a96a5; }
.search-clear { height: 34px; border: 0; background: transparent; color: var(--muted); font-size: 1.45rem; line-height: 1; }
.search-results {
    max-height: 360px;
    overflow: auto;
    margin-top: 6px;
    padding: 5px;
    background: rgba(255,255,255,.99);
    border: 1px solid var(--line-strong);
    box-shadow: 0 12px 28px rgba(15,23,42,.16);
}
.search-result {
    display: block;
    width: 100%;
    padding: 11px 12px;
    text-align: left;
    border: 0;
    border-bottom: 1px solid #e5e9ee;
    background: transparent;
    color: var(--text);
}
.search-result:last-child { border-bottom: 0; }
.search-result:hover, .search-result:focus-visible { background: #edf2f7; outline: none; }
.search-result-title { display: block; font-weight: 750; line-height: 1.25; }
.search-result-meta { display: flex; gap: 8px; align-items: center; margin-top: 4px; color: var(--muted); font-size: .78rem; }
.search-result-dot { width: 9px; height: 9px; flex: none; }
.search-empty { padding: 14px; color: var(--muted); text-align: center; }

.map-status {
    position: absolute;
    z-index: 850;
    left: 14px;
    bottom: 14px;
    padding: 7px 10px;
    color: #334155;
    background: rgba(255,255,255,.94);
    border: 1px solid var(--line-strong);
    font-size: .77rem;
    box-shadow: 0 6px 16px rgba(15,23,42,.08);
}

.sidebar { display: flex; flex-direction: column; }
.sidebar-header { padding: 18px; border-bottom: 1px solid var(--line); background: #fff; }
.sidebar-header h2 { margin: 3px 0 13px; font-size: 1.3rem; }
.sidebar-actions { display: flex; flex-wrap: wrap; gap: 14px; }
.text-button {
    padding: 0 0 2px;
    border: 0;
    border-bottom: 1px solid currentColor;
    background: transparent;
    color: #1d4ed8;
    font-size: .8rem;
    font-weight: 700;
}
.groups-list { overflow: auto; padding: 10px; background: #f2f4f6; }
.group-card {
    border: 1px solid var(--line);
    border-left: 5px solid var(--group-color);
    background: #fff;
    overflow: hidden;
    margin-bottom: 8px;
}
.group-header {
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 10px;
    width: 100%;
    min-height: 54px;
    padding: 10px 11px;
    border: 0;
    background: #fff;
    text-align: left;
}
.group-header:hover { background: var(--surface-soft); }
.group-color { width: 12px; height: 12px; background: var(--group-color); }
.group-label { min-width: 0; }
.group-name { display: block; font-weight: 800; }
.group-count { display: block; margin-top: 2px; color: var(--muted); font-size: .72rem; }
.group-toggle-symbol {
    display: grid;
    place-items: center;
    width: 28px;
    height: 28px;
    border: 1px solid var(--line);
    background: #eef1f4;
    color: #334155;
    font-weight: 800;
    transition: transform .18s, background .18s;
}
.group-card.is-open .group-toggle-symbol { transform: rotate(45deg); background: #e3e8ed; }
.group-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 11px;
    border-top: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
    background: #f4f6f8;
}
.checkbox-control { display: flex; align-items: center; gap: 7px; color: #475569; font-size: .78rem; }
.checkbox-control input { accent-color: var(--group-color, #2563eb); }
.group-items { display: none; padding: 0; }
.group-card.is-open .group-items { display: block; }
.investment-row {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 8px;
    align-items: start;
    padding: 10px 11px;
    border-bottom: 1px solid #e8ecf0;
}
.investment-row:last-child { border-bottom: 0; }
.investment-row:hover { background: #f4f6f8; }
.investment-row input { margin-top: 3px; accent-color: var(--group-color); }
.investment-link { padding: 0; border: 0; background: transparent; color: var(--text); text-align: left; line-height: 1.3; }
.investment-link:hover { color: #1d4ed8; }
.investment-amount { display: block; margin-top: 3px; color: var(--muted); font-size: .72rem; }
.skeleton-card {
    height: 70px;
    margin-bottom: 8px;
    border: 1px solid #d9e0e7;
    background: linear-gradient(90deg, #e9edf1, #f7f8fa, #e9edf1);
    background-size: 200% 100%;
    animation: shimmer 1.2s infinite;
}
@keyframes shimmer { to { background-position: -200% 0; } }

.investment-marker { background: transparent; border: 0; }
.marker-pin {
    width: 28px;
    height: 28px;
    border-radius: 50% 50% 50% 7px;
    transform: rotate(-45deg);
    background: var(--marker-color);
    border: 3px solid #fff;
    box-shadow: 0 5px 13px rgba(15,23,42,.34);
}
.marker-pin::after {
    content: '';
    display: block;
    width: 7px;
    height: 7px;
    margin: 7px;
    border-radius: 50%;
    background: #fff;
}
.marker-pin.is-highlighted {
    width: 34px;
    height: 34px;
    margin: -3px;
    box-shadow: 0 0 0 6px rgba(15,23,42,.16), 0 8px 20px rgba(15,23,42,.4);
}
.marker-pin.is-highlighted::after { margin: 10px; }

.leaflet-control-zoom a,
.leaflet-bar,
.leaflet-control-layers,
.leaflet-popup-content-wrapper,
.leaflet-popup-tip { border-radius: 0 !important; }
.leaflet-popup-content-wrapper { box-shadow: 0 16px 36px rgba(15,23,42,.22); }
.leaflet-popup-content { width: min(340px, 72vw) !important; margin: 0; }
.popup-card { overflow: hidden; }
.popup-gallery { display: grid; grid-auto-flow: column; grid-auto-columns: 100%; overflow-x: auto; scroll-snap-type: x mandatory; background: #e2e8f0; }
.popup-gallery img { display: block; width: 100%; height: 190px; object-fit: cover; scroll-snap-align: start; }
.popup-body { padding: 16px; border-top: 4px solid var(--popup-color); }
.popup-group { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: .73rem; font-weight: 750; text-transform: uppercase; letter-spacing: .05em; }
.popup-group::before { content: ''; width: 9px; height: 9px; background: var(--popup-color); }
.popup-title { margin: 8px 0 0; font-size: 1.05rem; line-height: 1.25; }
.popup-description { margin: 9px 0 0; color: #475569; font-size: .86rem; line-height: 1.5; white-space: pre-line; }
.popup-amount { display: inline-block; margin-top: 12px; padding: 6px 9px; border: 1px solid var(--line); background: #f1f3f5; color: #0f172a; font-size: .8rem; font-weight: 800; }

@media (max-width: 960px) {
    .app-shell { padding: 10px; }
    .site-header { min-height: 66px; margin-bottom: 9px; }
    .mobile-panel-toggle { display: block; }
    .workspace { display: block; height: calc(100vh - 94px); min-height: 540px; }
    .map-column { height: 100%; }
    .sidebar {
        position: fixed;
        z-index: 1200;
        top: 0;
        right: 0;
        width: min(390px, 94vw);
        height: 100vh;
        border: 0;
        border-left: 1px solid var(--line-strong);
        transform: translateX(105%);
        transition: transform .25s ease;
    }
    .sidebar.is-mobile-open { transform: translateX(0); }
}

@media (max-width: 560px) {
    .site-header h1 { font-size: 1.32rem; }
    .site-header .eyebrow { display: none; }
    .mobile-panel-toggle { padding: 9px 10px; font-size: .8rem; }
    .search-panel { top: 9px; right: 9px; left: 9px; width: auto; }
    .search-box { min-height: 47px; }
    .map-status { left: 9px; bottom: 9px; }
}
