:root {
    --bg: #0f172a;
    --panel: #1e293b;
    --text: #e2e8f0;
    --muted: #94a3b8;
    --accent: #38bdf8;
    --line: #334155;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; font-family: "IBM Plex Sans", "Segoe UI", sans-serif; background: var(--bg); color: var(--text); }

.map-app {
    display: grid;
    grid-template-columns: 320px 1fr;
    height: 100vh;
    height: 100dvh;
}

.map-sidebar {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    padding: 1rem;
    background: var(--panel);
    border-right: 1px solid var(--line);
    overflow: auto;
}

.map-card { flex: 1 1 auto; min-height: 0; }

.map-brand {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}
.map-brand-site { font-size: 1.25rem; letter-spacing: 0.02em; }
.map-area-title { color: var(--muted); font-size: 0.85rem; }
.map-brand .map-area-title { display: block; }

/* Desktop: top brand / tap zone skryté */
.top-tap-zone,
.map-brand-top {
    display: none;
}

.map-section-title {
    margin: 0 0 0.35rem;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--muted);
}

.map-layers {
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--line);
}
.layers-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    width: 100%;
    margin: 0;
    padding: 0.15rem 0;
    border: 0;
    background: transparent;
    color: inherit;
    font: inherit;
    cursor: pointer;
    text-align: left;
}
.layers-toggle .map-section-title { margin: 0; }
.layers-toggle:hover .map-section-title { color: var(--accent); }
.layers-chevron {
    color: var(--muted);
    font-size: 0.85rem;
    transition: transform 0.15s ease;
}
.layers-toggle[aria-expanded="false"] .layers-chevron { transform: rotate(-90deg); }
.layers-body {
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
    margin-top: 0.45rem;
}
.layers-body[hidden] { display: none !important; }
.map-layers label { display: flex; align-items: center; gap: 0.5rem; font-size: 0.9rem; cursor: pointer; }
.map-layers label.opacity { flex-direction: column; align-items: stretch; gap: 0.25rem; color: var(--muted); font-size: 0.8rem; }

.btn-show-all {
    margin-top: 0.5rem;
    padding: 0.55rem 0.75rem;
    border: 1px solid var(--accent);
    border-radius: 6px;
    background: transparent;
    color: var(--accent);
    font: inherit;
    font-size: 0.85rem;
    cursor: pointer;
}
.btn-show-all:hover { background: rgba(56, 189, 248, 0.12); }
.btn-show-all[hidden] { display: none !important; }

.legend-note {
    margin: 0.45rem 0 0;
    font-size: 0.72rem;
    color: var(--muted);
    line-height: 1.35;
}
.swatch {
    display: inline-block;
    width: 14px;
    height: 14px;
    border-radius: 3px;
    border: 1px solid rgba(255,255,255,0.25);
    flex-shrink: 0;
}
.swatch.dashed {
    background: repeating-linear-gradient(90deg, #78909c 0 4px, transparent 4px 7px) !important;
    border-color: #78909c;
}
.map-card .swatch {
    width: 10px;
    height: 10px;
    margin-right: 0.15rem;
    vertical-align: -1px;
}

.map-card h2 { margin: 0; font-size: 1.05rem; text-align: left; }
.map-card h3 { margin: 0.9rem 0 0.35rem; font-size: 0.9rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.map-card ul { margin: 0; padding-left: 1.1rem; }
.map-card li { margin: 0.25rem 0; font-size: 0.95rem; }
.map-card code { color: var(--accent); }
.map-card .muted, .muted { color: var(--muted); font-size: 0.95rem; }
.map-card .err { color: #f87171; }

.addr-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    width: 100%;
    margin: 0;
    padding: 0;
    border: 0;
    background: transparent;
    color: inherit;
    font: inherit;
    cursor: pointer;
    text-align: left;
}
.addr-toggle:hover h2 { color: var(--accent); }
.addr-chevron {
    color: var(--muted);
    font-size: 0.85rem;
    transition: transform 0.15s ease;
}
.addr-toggle[aria-expanded="true"] .addr-chevron { transform: rotate(180deg); }
.ruian-panel {
    margin: 0.35rem 0 0;
    padding: 0.4rem 0.5rem;
    font-size: 0.95rem;
    border-left: 2px solid var(--line);
}
.ruian-panel[hidden] { display: none !important; }

.odbo-list { list-style: none; padding-left: 0; }
.odbo-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.35rem 0.55rem;
    font-size: 0.98rem;
}
.odbo-diam {
    font-size: 1rem;
    color: var(--muted);
    font-variant-numeric: tabular-nums;
}
.odbo-hub { font-size: 1.05rem; }
.odbo-pater-label {
    font-size: 0.95rem;
    color: var(--accent);
}
.odbo-row.odbo-pater .odbo-hub {
    flex-basis: 100%;
    padding-left: 1.35rem;
    margin-top: -0.1rem;
}
.odbo-dist {
    flex-basis: 100%;
    padding-left: 1.35rem;
    font-size: 1.05rem;
    line-height: 1.4;
}
.odbo-type {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text);
}

/* handle bottom-sheetu — na desktopu skrytý */
.sheet-handle {
    display: none;
}
.node-card-title {
    display: flex;
    align-items: baseline;
    gap: 0.45rem 0.65rem;
    flex-wrap: wrap;
    margin: 0 0 0.35rem;
    font-size: 1.15rem;
    line-height: 1.25;
}
.node-card-name { font-weight: 700; }
.node-address {
    font-size: 1rem;
    font-weight: 400;
}
.node-summary {
    margin: 1rem 0 0;
    padding-top: 0.65rem;
    border-top: 1px solid var(--line);
    font-size: 0.95rem;
}
.mtd-list {
    gap: 0.15rem;
}
.mtd-item {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}
.mtd-pick {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.35rem 0.5rem;
    width: 100%;
    margin: 0;
    padding: 0.35rem 0.2rem;
    border: 0;
    border-radius: 4px;
    background: transparent;
    color: inherit;
    font: inherit;
    text-align: left;
    cursor: pointer;
}
.mtd-pick:hover,
.mtd-item.is-open > .mtd-pick {
    background: rgba(56, 189, 248, 0.1);
}
.mtd-chevron {
    margin-left: auto;
    color: var(--muted);
    font-size: 0.75rem;
}
.mtd-len {
    flex-basis: 100%;
    padding-left: 1.35rem;
    font-size: 0.95rem;
    line-height: 1.35;
}
.mtd-odbo {
    margin: 0 0 0.35rem;
    padding: 0.25rem 0 0.35rem 0.55rem;
    border-left: 2px solid rgba(56, 189, 248, 0.35);
}
.mtd-odbo-sep {
    list-style: none;
    height: 0;
    margin: 0.45rem 0.15rem;
    padding: 0;
    border: 0;
    border-top: 1px dashed rgba(148, 163, 184, 0.55);
}
.mtd-odbo-wrap {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}
.mtd-tube-notes {
    margin: 0.15rem 0 0.25rem;
    padding: 0.35rem 0.55rem 0.15rem;
    border-top: 1px solid rgba(148, 163, 184, 0.25);
    font-size: 0.95rem;
    line-height: 1.4;
}
.mtd-tube-notes p {
    margin: 0 0 0.3rem;
}
.odbo-end-house {
    font-size: 1rem;
    color: var(--text);
}
.odbo-end-dead {
    font-size: 1rem;
    color: var(--muted);
    font-style: italic;
}

.map-canvas {
    width: 100%;
    height: 100%;
    min-width: 0;
    min-height: 0;
    /* Leaflet: sever nahoře; pan bez gesture-rotate prohlížeče */
    touch-action: pan-x pan-y;
}

.leaflet-container { background: #0b1220; font: inherit; }
.cm-mtd-hit {
    cursor: pointer;
}

/* Uzly: červené poloprůhledné obdélníky; velikost = --cm-node-scale (zoom) */
.cm-node-wrap {
    background: transparent !important;
    border: none !important;
}
.cm-node {
    --s: var(--cm-node-scale, 1);
    transform: translate(-50%, -50%) scale(var(--s));
    transform-origin: center center;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 2.2rem;
    padding: 0.18rem 0.4rem;
    background: rgba(220, 38, 38, 0.55);
    border: 1.5px solid rgba(185, 28, 28, 0.85);
    border-radius: 2px;
    color: #fff;
    font: 700 11px/1.15 "IBM Plex Sans", "Segoe UI", sans-serif;
    letter-spacing: 0.02em;
    white-space: nowrap;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
    pointer-events: auto;
    user-select: none;
    will-change: transform;
}
.cm-node.is-focus {
    background: rgba(220, 38, 38, 0.82);
    border-color: #fff;
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.85), 0 2px 6px rgba(0, 0, 0, 0.4);
}
.cm-node.is-hidden {
    display: none;
}
.cm-node-label {
    text-shadow: 0 1px 1px rgba(0, 0, 0, 0.35);
}

/* Podpisy MTD / odboček (KLAD-like) */
.cm-line-label-wrap {
    background: transparent !important;
    border: none !important;
}
.cm-line-label {
    --s: var(--cm-label-scale, 1);
    --rot: 0deg;
    transform: translate(-50%, -50%) scale(var(--s)) rotate(var(--rot));
    transform-origin: center center;
    display: inline-block;
    font: 700 11px/1.1 "IBM Plex Sans", "Segoe UI", sans-serif;
    letter-spacing: 0.01em;
    color: #111;
    white-space: nowrap;
    pointer-events: none;
    user-select: none;
    text-shadow:
        0 0 3px #fff,
        0 0 3px #fff,
        1px 0 0 #fff,
        -1px 0 0 #fff,
        0 1px 0 #fff,
        0 -1px 0 #fff;
}
.cm-odbo-label {
    font-size: 10px;
    font-weight: 600;
    --rot: 0deg;
}
.cm-line-label.is-hidden,
.cm-line-label.is-length-hidden {
    display: none;
}
.map-canvas.labels-hidden .cm-line-label {
    display: none;
}

/* Portrait phone: mapa fullscreen, panel = vytahovací bottom-sheet */
@media (max-width: 800px) and (orientation: portrait) {
    .map-app {
        grid-template-columns: 1fr;
        grid-template-rows: 1fr;
        position: relative;
    }
    .map-canvas {
        order: 1;
        min-height: 0;
        width: 100%;
        height: 100%;
    }

    /* Neviditelný pruh nahoře — tap ukáže Cable_Map */
    .top-tap-zone {
        display: block;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        z-index: 1200;
        height: max(28px, env(safe-area-inset-top, 0px) + 18px);
        margin: 0;
        padding: 0;
        border: 0;
        background: transparent;
        cursor: pointer;
    }
    .map-brand-top {
        display: flex;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        z-index: 1201;
        align-items: center;
        justify-content: center;
        padding: calc(env(safe-area-inset-top, 0px) + 0.45rem) 1rem 0.55rem;
        background: linear-gradient(180deg, rgba(15, 23, 42, 0.92), rgba(15, 23, 42, 0.72));
        backdrop-filter: blur(6px);
        transform: translateY(-110%);
        opacity: 0;
        transition: transform 0.2s ease, opacity 0.2s ease;
        pointer-events: none;
    }
    .map-brand-top.is-visible {
        transform: translateY(0);
        opacity: 1;
        pointer-events: auto;
    }
    .map-brand-top strong {
        font-size: 1.15rem;
        letter-spacing: 0.04em;
        font-weight: 700;
    }

    .map-sidebar {
        order: 2;
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 1100;
        height: var(--sheet-h, 36vh);
        max-height: 92vh;
        min-height: 12vh;
        border-right: none;
        border-top: 1px solid var(--line);
        border-radius: 14px 14px 0 0;
        padding: 0 0.85rem 0.75rem;
        gap: 0.45rem;
        box-shadow: 0 -8px 28px rgba(0, 0, 0, 0.35);
        transition: height 0.22s ease;
        overflow: auto;
        overscroll-behavior: contain;
        -webkit-overflow-scrolling: touch;
    }
    .map-sidebar.is-sheet-dragging {
        transition: none;
        user-select: none;
    }

    /* V sheetu jen název KLAD / oblasti — ne Cable_Map */
    .map-sidebar .map-brand-site { display: none; }
    .map-sidebar .map-brand {
        flex-direction: row;
        align-items: baseline;
        gap: 0.35rem;
        margin: 0 0 0.15rem;
    }
    .map-sidebar .map-area-title {
        color: var(--text);
        font-size: 1.05rem;
        font-weight: 600;
        letter-spacing: 0.01em;
    }

    .sheet-handle {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 0.15rem;
        width: 100%;
        margin: 0;
        padding: 0.45rem 0 0.15rem;
        border: 0;
        background: transparent;
        color: var(--muted);
        cursor: grab;
        touch-action: none;
        flex: 0 0 auto;
    }
    .sheet-handle:active { cursor: grabbing; }
    .sheet-handle-bar {
        display: block;
        width: 2.5rem;
        height: 4px;
        border-radius: 999px;
        background: #64748b;
    }
    .sheet-handle-arrow {
        font-size: 0.7rem;
        line-height: 1;
        opacity: 0.85;
    }

    .map-card li { font-size: 1.08rem; }
    .map-card .muted,
    .map-sidebar .muted { font-size: 1.08rem; }
    .map-card h3 { font-size: 0.98rem; }
    .odbo-row { font-size: 1.12rem; }
    .odbo-type { font-size: 1.14rem; }
    .odbo-hub { font-size: 1.14rem; }
    .odbo-diam { font-size: 1.1rem; }
    .odbo-dist { font-size: 1.12rem; }
    .odbo-pater-label { font-size: 1.05rem; }
    .odbo-end-house,
    .odbo-end-dead { font-size: 1.1rem; }
    .node-address { font-size: 1.08rem; }
    .node-summary { font-size: 1.05rem; }
    .mtd-len,
    .mtd-tube-notes,
    .ruian-panel { font-size: 1.08rem; }
}

/* Landscape phone/tablet: mapa vpravo na celou výšku, panel vlevo */
@media (max-width: 1100px) and (orientation: landscape) {
    .map-app {
        grid-template-columns: minmax(200px, 30vw) 1fr;
        grid-template-rows: 1fr;
        height: 100vh;
        height: 100dvh;
    }
    .map-sidebar {
        position: relative;
        order: 1;
        height: auto;
        max-height: none;
        min-height: 0;
        border-radius: 0;
        border-right: 1px solid var(--line);
        border-top: none;
        box-shadow: none;
        padding: 0.75rem;
    }
    .sheet-handle { display: none; }
    .top-tap-zone,
    .map-brand-top { display: none !important; }
    .map-sidebar .map-brand-site { display: block; }
    .map-canvas { order: 2; min-height: 0; }
}
