:root {
    --bg: #0f172a;
    --panel: #1e293b;
    --panel-2: #273449;
    --line: #334155;
    --text: #e2e8f0;
    --muted: #94a3b8;
    --accent: #38bdf8;
    --accent-d: #0ea5e9;
    --red: #ef4444;
    --green: #22c55e;
    --sidebar-w: 340px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    height: 100%;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    color: var(--text);
    background: var(--bg);
}

#app {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* --- Sānu panelis --- */
#sidebar {
    width: var(--sidebar-w);
    min-width: var(--sidebar-w);
    background: var(--panel);
    border-right: 1px solid var(--line);
    padding: 18px 16px 28px;
    overflow-y: auto;
}

.side-head h1 {
    font-size: 19px;
    margin: 0 0 2px;
    letter-spacing: .2px;
}
.side-head .sub {
    margin: 0 0 14px;
    color: var(--muted);
    font-size: 12px;
}

.field { margin-bottom: 14px; }

.lbl {
    display: block;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .5px;
    color: var(--muted);
    margin-bottom: 6px;
}

.hint {
    font-size: 11.5px;
    color: var(--muted);
    margin: 6px 0 0;
    line-height: 1.4;
}

hr { border: none; border-top: 1px solid var(--line); margin: 16px 0; }

/* --- Segmentētās pogas --- */
.segmented {
    display: flex;
    background: var(--panel-2);
    border-radius: 8px;
    padding: 3px;
    gap: 3px;
}
.segmented.wrap { flex-wrap: wrap; }
.seg {
    flex: 1;
    border: none;
    background: transparent;
    color: var(--muted);
    padding: 7px 8px;
    font-size: 12.5px;
    border-radius: 6px;
    cursor: pointer;
    white-space: nowrap;
    transition: background .15s, color .15s;
}
.segmented.wrap .seg { flex: 1 0 40%; }
.seg:hover { color: var(--text); }
.seg.active {
    background: var(--accent-d);
    color: #04283a;
    font-weight: 600;
}

/* --- Izvēršamais logs --- */
.collapse-head {
    width: 100%;
    text-align: left;
    background: var(--panel-2);
    border: 1px solid var(--line);
    color: var(--text);
    padding: 9px 11px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 13px;
    display: flex;
    align-items: center;
    gap: 8px;
}
.collapse-head .chev { transition: transform .2s; }
.collapse-head[aria-expanded="false"] .chev { transform: rotate(-90deg); }
.count-badge {
    margin-left: auto;
    background: var(--accent-d);
    color: #04283a;
    font-size: 11px;
    font-weight: 700;
    padding: 1px 8px;
    border-radius: 20px;
}
.collapse-body {
    max-height: 320px;
    overflow: hidden;
    transition: max-height .25s ease;
}
.collapse-body.closed { max-height: 0; }

textarea#codes {
    width: 100%;
    height: 180px;
    margin-top: 8px;
    resize: vertical;
    background: #0b1220;
    color: var(--text);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 10px;
    font-family: ui-monospace, "SF Mono", Menlo, monospace;
    font-size: 12.5px;
    line-height: 1.5;
}

/* --- Pogas --- */
button.primary, button.secondary {
    width: 100%;
    border: none;
    border-radius: 8px;
    padding: 11px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
}
button.primary { background: var(--accent); color: #04283a; }
button.primary:hover { background: #7dd3fc; }
button.primary:disabled { opacity: .55; cursor: default; }
button.secondary {
    background: var(--panel-2);
    color: var(--text);
    border: 1px solid var(--line);
    font-weight: 500;
}
button.secondary:hover { background: #33445c; }

.status {
    font-size: 12.5px;
    color: var(--muted);
    margin-top: 10px;
    line-height: 1.5;
}
.status b { color: var(--text); }
.status .warn { color: #fbbf24; }
.status .tip { color: var(--accent); font-size: 12px; }

/* --- Sadalījums pa numuriem --- */
.breakdown {
    margin-top: 10px;
    background: #0b1220;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 6px 10px;
    font-size: 12.5px;
}
.breakdown summary {
    cursor: pointer;
    color: var(--muted);
    padding: 2px 0;
    user-select: none;
}
.bd-row {
    padding: 5px 0;
    border-top: 1px solid var(--line);
}
.bd-row:first-of-type { border-top: none; }
.bd-row.nf .bd-nr { color: #fbbf24; }
.bd-nr {
    font-family: ui-monospace, Menlo, monospace;
    font-weight: 600;
    color: var(--text);
    margin-right: 8px;
}
.bd-detail { color: var(--muted); }
.bd-codes {
    margin-top: 2px;
    font-family: ui-monospace, Menlo, monospace;
    font-size: 11px;
    color: var(--accent);
    word-break: break-all;
}

/* --- Filtri --- */
.check {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    cursor: pointer;
}
.type-list {
    max-height: 150px;
    overflow-y: auto;
    background: #0b1220;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 6px 8px;
}
.type-list label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12.5px;
    padding: 3px 0;
    cursor: pointer;
}
.type-list .cnt { margin-left: auto; color: var(--muted); font-size: 11px; }

.range-row {
    display: flex;
    align-items: center;
    gap: 8px;
}
.range-row input {
    flex: 1;
    background: #0b1220;
    border: 1px solid var(--line);
    color: var(--text);
    border-radius: 6px;
    padding: 8px;
    font-size: 13px;
}

/* --- Datubāze / progress --- */
.progress {
    height: 8px;
    background: #0b1220;
    border-radius: 20px;
    overflow: hidden;
    margin-top: 10px;
}
.progress-bar {
    height: 100%;
    width: 0;
    background: linear-gradient(90deg, var(--accent-d), var(--accent));
    transition: width .3s;
}

/* --- Ēku saraksts (pēc platības) --- */
.bld-sort { font-size: 12px; padding: 6px 8px; }
.bld-list {
    max-height: 260px;
    overflow-y: auto;
    background: #0b1220;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 4px;
}
.bld-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 8px;
    border-radius: 6px;
    cursor: pointer;
    border-bottom: 1px solid var(--line);
}
.bld-item:last-child { border-bottom: none; }
.bld-item:hover { background: var(--panel-2); }
.bld-item .rank {
    flex: 0 0 auto;
    min-width: 20px;
    text-align: right;
    color: var(--muted);
    font-size: 11px;
}
.bld-item .meta { flex: 1; min-width: 0; }
.bld-item .bt { font-size: 12.5px; color: var(--text); }
.bld-item .bc {
    font-family: ui-monospace, Menlo, monospace;
    font-size: 10.5px;
    color: var(--muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.bld-item .ba {
    flex: 0 0 auto;
    font-weight: 600;
    font-size: 12.5px;
    color: var(--accent);
    white-space: nowrap;
}
.bld-empty { padding: 8px; color: var(--muted); font-size: 12.5px; text-align: center; }

.hidden { display: none !important; }

/* --- Karte --- */
#map { flex: 1; height: 100%; position: relative; }
.leaflet-container { background: #0b1220; }

/* --- Ēku multileader etiķetes --- */
.label-overlay {
    position: absolute;
    inset: 0;
    z-index: 650;
    pointer-events: none;
    transition: opacity .12s;
}
.label-svg {
    position: absolute;
    inset: 0;
    z-index: 649;
    pointer-events: none;
    overflow: visible;
    transition: opacity .12s;
}
.leader { stroke: #38bdf8; stroke-width: 1; opacity: .85; }
.leader-dot { fill: #38bdf8; }
.blabel {
    position: absolute;
    background: rgba(15, 23, 42, .92);
    color: #e2e8f0;
    border: 1px solid #38bdf8;
    border-radius: 5px;
    padding: 2px 6px;
    font-size: 11px;
    line-height: 1.25;
    white-space: nowrap;
    pointer-events: none;
    box-shadow: 0 1px 5px rgba(0, 0, 0, .45);
}
.blabel b { display: block; font-weight: 600; }
.blabel span { color: #7dd3fc; font-size: 10px; }

/* Zemes gabalu nosaukumu etiķetes — oranžas (kā zemes robežas) */
.blabel.plabel { border-color: #f97316; }
.blabel.plabel b { color: #fed7aa; }
.blabel.plabel span { color: #fdba74; }

.popup-title { font-weight: 700; margin-bottom: 4px; }
.popup-row { font-size: 12px; }
.popup-row .k { color: #64748b; }

/* --- Responsīvs --- */
@media (max-width: 720px) {
    #app { flex-direction: column; }
    #sidebar {
        width: 100%;
        min-width: 0;
        max-height: 52vh;
        border-right: none;
        border-bottom: 1px solid var(--line);
    }
    #map { height: 48vh; }
}
