:root {
    --bg: #f3f6fb;
    --panel: #ffffff;
    --panel-soft: #f8fafc;
    --border: #dbe4f0;
    --text: #0f172a;
    --muted: #64748b;
    --blue: #2563eb;
    --blue-soft: #dbeafe;
    --green: #16a34a;
    --green-soft: #dcfce7;
    --red: #dc2626;
    --red-soft: #fee2e2;
    --amber: #d97706;
    --amber-soft: #fef3c7;
    --shadow: 0 14px 40px rgba(15, 23, 42, 0.08);
}

* { box-sizing: border-box; }
html, body {
    margin: 0;
    padding: 0;
    height: 100%;
}
body {
    font-family: 'Inter', sans-serif;
    color: var(--text);
    background: var(--bg);
    overflow: hidden;
}

button, input { font: inherit; }
button { cursor: pointer; }

.app-shell {
    display: grid;
    grid-template-columns: 340px minmax(0, 1fr);
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
}

.sidebar {
    position: relative;
    z-index: 700;
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding: 16px;
    background: #eef3f9;
    border-right: 1px solid var(--border);
    min-height: 0;
    height: 100%;
    overflow: hidden;
}

.sheet-grab,
.sheet-toggle-btn,
.mobile-tabs,
.mobile-menu-btn {
    display: none;
}

.sidebar-header,
.popular-section,
.list-section {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 20px;
    box-shadow: var(--shadow);
}

.sidebar-header { padding: 18px; }
.sidebar-content {
    display: flex;
    flex-direction: column;
    gap: 16px;
    min-height: 0;
    flex: 1;
    overflow: auto;
    padding-right: 4px;
    scrollbar-gutter: stable;
}
.popular-section, .list-section { padding: 14px; }
.list-section {
    display: flex;
    flex-direction: column;
    min-height: 0;
    flex: 1;
}

.sidebar-topline {
    display: block;
}

.eyebrow {
    margin: 0 0 6px;
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--blue);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

h1, h2 { margin: 0; }
h1 { font-size: 1.7rem; }
h2 { font-size: 1rem; }
.subtitle {
    margin: 8px 0 0;
    color: var(--muted);
    line-height: 1.5;
}

.summary-card {
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 16px;
    background: var(--panel-soft);
}
.summary-card strong {
    display: block;
    margin-top: 6px;
    font-size: 1.35rem;
}
.summary-card.subtle {
    padding: 10px 12px;
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(10px);
    box-shadow: 0 12px 30px rgba(15, 23, 42, 0.12);
}
.summary-card.subtle strong { font-size: 1.05rem; }
.summary-card.online { background: var(--green-soft); }
.summary-card.image-only { background: var(--amber-soft); }
.summary-card.offline { background: var(--red-soft); }
.summary-label { font-size: 0.78rem; color: var(--muted); }

.search-box {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: 16px;
    background: var(--panel-soft);
    margin-top: 16px;
}
.search-box svg { width: 18px; height: 18px; color: var(--muted); }
.search-box input {
    border: 0;
    outline: 0;
    background: transparent;
    width: 100%;
    min-width: 0;
}

.helper-text {
    margin: 12px 0 0;
    color: var(--muted);
    font-size: 0.9rem;
    line-height: 1.45;
}

.section-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
}

.sticky-head {
    position: sticky;
    top: 0;
    background: var(--panel);
    z-index: 2;
}

.ghost-btn {
    border: 1px solid var(--border);
    background: var(--panel-soft);
    color: var(--text);
    border-radius: 999px;
    padding: 8px 12px;
}

.count-pill {
    min-width: 34px;
    padding: 6px 10px;
    text-align: center;
    border-radius: 999px;
    background: var(--blue-soft);
    color: var(--blue);
    font-weight: 700;
}

.popular-list,
.camera-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.camera-list {
    overflow: auto;
    padding-right: 2px;
}

.popular-card,
.camera-card {
    width: 100%;
    border: 1px solid var(--border);
    background: var(--panel-soft);
    border-radius: 18px;
    text-align: left;
}

.popular-card {
    display: grid;
    grid-template-columns: 36px 64px minmax(0, 1fr);
    align-items: center;
    gap: 12px;
    padding: 10px;
}

.popular-rank {
    width: 36px;
    height: 36px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    background: var(--blue);
    color: #fff;
    font-weight: 700;
}

.popular-thumb {
    width: 64px;
    height: 48px;
    border-radius: 12px;
    object-fit: cover;
    background: #cbd5e1;
}

.popular-text {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
}
.popular-text strong,
.camera-card strong {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.popular-text span,
.camera-meta { color: var(--muted); font-size: 0.88rem; }

.camera-card {
    display: grid;
    grid-template-columns: 88px minmax(0, 1fr);
    gap: 12px;
    align-items: center;
    padding: 10px;
}

.camera-thumb {
    width: 88px;
    height: 66px;
    border-radius: 14px;
    object-fit: cover;
    background: #cbd5e1;
}

.camera-card-body {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0;
}

.status-badge {
    align-self: flex-start;
    padding: 6px 10px;
    border-radius: 999px;
    font-size: 0.8rem;
    font-weight: 700;
}
.status-badge.online, .online { color: var(--green); }
.status-badge.online { background: var(--green-soft); }
.status-badge.image-only, .image-only { color: var(--amber); }
.status-badge.image-only { background: var(--amber-soft); }
.status-badge.offline, .offline { color: var(--red); }
.status-badge.offline { background: var(--red-soft); }
.status-badge.checking, .checking { color: var(--amber); }
.status-badge.checking { background: var(--amber-soft); }

.empty-card {
    padding: 16px;
    border: 1px dashed var(--border);
    border-radius: 16px;
    color: var(--muted);
    background: var(--panel-soft);
}
.more-note { text-align: center; }

.map-panel {
    position: relative;
    min-width: 0;
    background: #dbe4f0;
    height: 100%;
    overflow: hidden;
}
#map {
    width: 100%;
    height: 100%;
}

.map-summary {
    position: absolute;
    top: 16px;
    right: 16px;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 8px;
    width: min(440px, calc(100% - 32px));
    z-index: 450;
    pointer-events: none;
}

.map-theme-control {
    margin-top: 8px;
    border: 0;
    border-radius: 12px;
    padding: 10px 12px;
    background: rgba(15, 23, 42, 0.86);
    color: #fff;
    font-weight: 700;
    box-shadow: 0 12px 28px rgba(15, 23, 42, 0.18);
    cursor: pointer;
}

.map-theme-control:hover {
    background: rgba(15, 23, 42, 0.94);
}

.map-theme-control:focus-visible {
    outline: 2px solid #bfdbfe;
    outline-offset: 2px;
}

.camera-pin {
    width: 18px !important;
    height: 18px !important;
    margin-left: -9px !important;
    margin-top: -9px !important;
    background: transparent !important;
    border: 0 !important;
}

.camera-pin-dot {
    display: block;
    width: 18px;
    height: 18px;
    border-radius: 999px;
    border: 3px solid #ffffff;
    box-shadow: 0 0 0 2px rgba(15, 23, 42, 0.18), 0 4px 10px rgba(15, 23, 42, 0.25);
}

.leaflet-marker-icon.camera-pin,
.leaflet-div-icon.camera-pin {
    background: transparent;
    border: 0;
}

.leaflet-popup-content-wrapper {
    border-radius: 16px;
}
.popup-card { min-width: 220px; }
.popup-card strong { display: block; margin-bottom: 8px; }
.popup-card p { margin: 8px 0 0; color: var(--muted); }
.popup-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 10px;
}
.popup-img {
    display: block;
    width: 100%;
    height: 130px;
    object-fit: cover;
    border-radius: 12px;
    background: #cbd5e1;
}
.popup-btn {
    margin-top: 10px;
    width: 100%;
    border: 0;
    border-radius: 12px;
    padding: 10px 12px;
    background: var(--blue);
    color: #fff;
    font-weight: 700;
}
.preview-shell {
    position: relative;
    display: block;
}
.preview-age {
    position: absolute;
    top: 8px;
    right: 8px;
    z-index: 1;
    padding: 4px 7px;
    border-radius: 999px;
    background: rgba(15, 23, 42, 0.82);
    color: #fff;
    font-size: 0.72rem;
    font-weight: 700;
    backdrop-filter: blur(8px);
}
.preview-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 12px;
    border-radius: 14px;
    background:
        radial-gradient(circle at top left, rgba(37, 99, 235, 0.22), transparent 48%),
        linear-gradient(135deg, #dfe7f2, #c8d4e5);
    color: #334155;
    font-weight: 700;
    text-align: center;
}
.preview-placeholder span {
    max-width: 9ch;
    line-height: 1.3;
}

.modal {
    position: fixed;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: rgba(15, 23, 42, 0.58);
    z-index: 5000;
}
.modal.show { display: flex; }
.modal-content {
    width: min(920px, 100%);
    max-height: calc(100vh - 40px);
    overflow: auto;
    background: var(--panel);
    border-radius: 24px;
    box-shadow: 0 28px 70px rgba(15, 23, 42, 0.24);
    transition: transform 0.18s ease;
}
.modal-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    padding: 20px 20px 0;
}
.modal-kicker {
    margin: 0 0 4px;
    color: var(--blue);
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.modal-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}
.modal-ghost-btn {
    padding-inline: 14px;
    white-space: nowrap;
}
.close-btn {
    border: 0;
    background: var(--panel-soft);
    width: 42px;
    height: 42px;
    border-radius: 999px;
    font-size: 1.7rem;
    line-height: 1;
}
.modal-body { padding: 20px; }
.player-wrapper {
    position: relative;
    width: 100%;
    aspect-ratio: 16 / 9;
    border-radius: 20px;
    overflow: hidden;
    background: #000;
}
.player-wrapper video,
.player-wrapper img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.player-wrapper.image-only {
    background: #0f172a;
}
.player-empty {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    padding: 24px;
    text-align: center;
    color: rgba(255, 255, 255, 0.9);
    font-weight: 600;
    line-height: 1.5;
}
.player-empty[hidden] {
    display: none;
}
.player-status {
    position: absolute;
    left: 12px;
    bottom: 12px;
    z-index: 2;
    padding: 7px 10px;
    border-radius: 999px;
    background: rgba(15, 23, 42, 0.72);
    color: #fff;
    font-size: 0.8rem;
    font-weight: 600;
    backdrop-filter: blur(8px);
}
.camera-details {
    margin-top: 16px;
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
}
.detail-item {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 14px;
    border-radius: 16px;
    border: 1px solid var(--border);
    background: var(--panel-soft);
}
.detail-item span { color: var(--muted); font-size: 0.85rem; }
.detail-item.full-width { grid-column: 1 / -1; }

@media (max-width: 960px) {
    body {
        overflow: hidden;
    }

    .app-shell {
        display: block;
        min-height: 100vh;
        min-height: 100dvh;
        height: auto;
    }

    #map {
        height: 100vh;
        height: 100dvh;
        touch-action: pan-x pan-y;
    }

    .mobile-menu-btn {
        position: absolute;
        left: 12px;
        bottom: calc(12px + env(safe-area-inset-bottom));
        z-index: 480;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        border: 0;
        border-radius: 999px;
        padding: 12px 16px;
        background: rgba(15, 23, 42, 0.86);
        color: #fff;
        font-weight: 700;
        box-shadow: 0 16px 30px rgba(15, 23, 42, 0.24);
    }

    .sidebar {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        min-height: 0;
        height: min(88vh, 760px);
        height: min(88dvh, 760px);
        padding: 8px 12px calc(12px + env(safe-area-inset-bottom));
        gap: 10px;
        border-right: 0;
        border-top: 1px solid var(--border);
        border-radius: 24px 24px 0 0;
        box-shadow: 0 -20px 50px rgba(15, 23, 42, 0.18);
        transform: translateY(calc(100% - 96px));
        transition: transform 0.28s ease;
        overscroll-behavior: contain;
        background: rgba(238, 243, 249, 0.96);
        backdrop-filter: blur(12px);
        pointer-events: auto;
    }

    .sidebar[data-sheet-state="collapsed"] {
        transform: translateY(calc(100% - 96px));
    }

    .sidebar[data-sheet-state="half"] {
        transform: translateY(calc(100% - 52dvh));
    }

    .sidebar[data-sheet-state="full"] {
        transform: translateY(0);
    }

    .sheet-grab {
        display: block;
        width: 52px;
        height: 6px;
        border-radius: 999px;
        background: #cbd5e1;
        margin: 0 auto 2px;
    }

    .sidebar-header,
    .popular-section,
    .list-section {
        border-radius: 18px;
    }

    .sidebar-header {
        padding: 14px;
        flex-shrink: 0;
        touch-action: pan-y;
    }

    .sidebar-topline {
        display: flex;
        align-items: flex-start;
        justify-content: space-between;
        gap: 12px;
    }

    h1 {
        font-size: 1.35rem;
    }

    .subtitle {
        font-size: 0.9rem;
    }

    .search-box {
        margin-top: 12px;
        padding: 11px 13px;
    }

    .helper-text {
        margin-top: 8px;
        font-size: 0.82rem;
    }

    .sheet-toggle-btn {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        border: 1px solid var(--border);
        background: var(--panel-soft);
        border-radius: 999px;
        padding: 10px 14px;
        font-weight: 600;
        white-space: nowrap;
    }

    .mobile-tabs {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 8px;
        margin-top: 10px;
    }

    .tab-btn {
        border: 1px solid var(--border);
        background: var(--panel-soft);
        color: var(--muted);
        border-radius: 14px;
        padding: 11px 12px;
        font-weight: 700;
    }

    .tab-btn.active {
        background: var(--blue-soft);
        color: var(--blue);
        border-color: #bfdbfe;
    }

    .sidebar-content {
        min-height: 0;
        display: block;
        overflow: auto;
        padding-bottom: 4px;
        padding-right: 0;
    }

    .popular-section,
    .list-section {
        display: none;
        min-height: 0;
    }

    .popular-section.active,
    .list-section.active {
        display: block;
    }

    .list-section.active {
        display: flex;
    }

    .sticky-head {
        top: 0;
    }

    .map-summary {
        top: 10px;
        right: 10px;
        left: 10px;
        width: auto;
        grid-template-columns: repeat(4, minmax(0, 1fr));
        gap: 6px;
    }

    .leaflet-top.leaflet-left {
        top: 84px;
    }

    .leaflet-bottom.leaflet-right {
        bottom: 84px;
    }

    .modal {
        padding: 0;
        align-items: flex-end;
    }

    .modal-content {
        width: 100%;
        max-height: 100vh;
        max-height: 100dvh;
        border-radius: 24px 24px 0 0;
    }

    .modal-header {
        position: sticky;
        top: 0;
        z-index: 4;
        flex-wrap: wrap;
        padding: 16px 16px 12px;
        background: rgba(255, 255, 255, 0.96);
        border-bottom: 1px solid var(--border);
        backdrop-filter: blur(12px);
        touch-action: pan-y;
    }

    .modal-title-block {
        min-width: 0;
        flex: 1 1 100%;
    }

    .modal-actions {
        width: 100%;
        justify-content: space-between;
        gap: 8px;
    }

    .modal-ghost-btn {
        flex: 1 1 auto;
    }

    .modal-body {
        padding: 14px 16px calc(18px + env(safe-area-inset-bottom));
    }

    .player-wrapper {
        margin-bottom: 48px;
    }

    .player-status {
        top: calc(100% + 10px);
        bottom: auto;
        left: 0;
        background: var(--panel-soft);
        color: var(--text);
        border: 1px solid var(--border);
    }
}

@media (max-width: 640px) {
    .map-summary {
        display: flex;
        align-items: center;
        gap: 4px;
        padding: 4px;
        border-radius: 999px;
        background: rgba(255, 255, 255, 0.92);
        border: 1px solid rgba(219, 228, 240, 0.92);
        box-shadow: 0 12px 28px rgba(15, 23, 42, 0.12);
        backdrop-filter: blur(12px);
    }

    .summary-card.subtle {
        flex: 1 1 0;
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 4px;
        padding: 8px 7px;
        box-shadow: none;
    }

    .summary-card.subtle strong {
        margin-top: 0;
        font-size: 0.9rem;
    }

    .summary-label {
        font-size: 0;
    }

    .summary-label::after {
        content: attr(data-short-label);
        font-size: 0.66rem;
        color: var(--muted);
    }

    .camera-card {
        grid-template-columns: 72px minmax(0, 1fr);
        align-items: flex-start;
    }

    .camera-thumb {
        width: 72px;
        height: 56px;
    }

    .popular-card {
        grid-template-columns: 32px 56px minmax(0, 1fr);
        gap: 10px;
    }

    .popular-thumb {
        width: 56px;
        height: 42px;
    }

    .popular-text strong,
    .camera-card strong {
        display: -webkit-box;
        white-space: normal;
        overflow: hidden;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
    }

    .camera-meta,
    .popular-text span {
        font-size: 0.8rem;
    }

    .status-badge {
        padding: 5px 9px;
        font-size: 0.74rem;
    }
    .modal-ghost-btn {
        padding-inline: 12px;
        font-size: 0.9rem;
    }
}

@media (max-width: 960px) and (orientation: landscape) {
    .sidebar {
        height: min(94dvh, 560px);
    }

    .modal-content {
        max-height: 100dvh;
    }

    .player-wrapper {
        aspect-ratio: 16 / 8.8;
    }
}
