/* ==========================================================================
   Bản đồ số xã Võ Nhai — stylesheet cho trang /map (home/map.blade.php)
   Tách riêng khỏi Blade để dễ quản lý; không chứa biến PHP.
   ========================================================================== */

:root {
    --shell-navy: #0c1f63;
    --shell-navy-2: #0a1a52;
    --shell-blue: #1a3fda;
    --shell-blue-2: #12207a;
    --shell-yellow: #ffd54a;
    --shell-green: #1a9e5c;
    --shell-red: #e53935;
    --text-main: #1a1f36;
    --text-sub: #6b7280;
    --header-h: 84px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    height: 100%;
    font-family: 'Be Vietnam Pro', sans-serif;
    color: var(--text-main);
    background: #f4f6fb;
}

a { text-decoration: none; color: inherit; }
button { font-family: inherit; }

/* ══════════ HEADER ══════════ */
.appshell-header {
    height: var(--header-h);
    background: linear-gradient(90deg, var(--shell-blue-2), var(--shell-blue));
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    padding: 0 22px;
    position: relative;
    z-index: 60;
    box-shadow: 0 2px 10px rgba(0,0,0,.15);
}

.header-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

.header-brand img {
    height: 46px;
    width: auto;
    flex-shrink: 0;
}

.header-brand-text { line-height: 1.25; }

.header-brand-sup {
    display: block;
    font-size: 10.5px;
    font-weight: 700;
    color: var(--shell-yellow);
    text-transform: uppercase;
    letter-spacing: .6px;
}

.header-brand-title {
    display: block;
    font-size: 19px;
    font-weight: 800;
    letter-spacing: -.2px;
}

.header-brand-tag {
    display: block;
    font-size: 10.5px;
    font-style: italic;
    color: #c9f2d6;
}

.header-search {
    flex: 1;
    display: flex;
    max-width: 620px;
    margin: 0 auto;
}

.header-search input[type="text"] {
    flex: 1;
    border: none;
    padding: 9px 14px;
    font-size: 13.5px;
    font-family: inherit;
    border-radius: 8px 0 0 8px;
    outline: none;
}

.header-search select {
    border: none;
    border-left: 1px solid #e5e7eb;
    background: #fff;
    font-size: 13px;
    font-family: inherit;
    padding: 9px 10px;
    outline: none;
    max-width: 130px;
}

.header-search button {
    border: none;
    background: var(--shell-navy);
    color: #fff;
    padding: 0 16px;
    border-radius: 0 8px 8px 0;
    cursor: pointer;
}

.header-actions {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}

.header-actions .btn-shell {
    display: flex;
    align-items: center;
    gap: 6px;
    border: 1.5px solid rgba(255,255,255,.55);
    color: #fff;
    padding: 7px 14px;
    border-radius: 20px;
    font-size: 12.5px;
    font-weight: 600;
    white-space: nowrap;
    transition: background .15s;
}

.header-actions .btn-shell:hover { background: rgba(255,255,255,.12); }
.header-actions .btn-shell.primary { background: rgba(255,255,255,.18); }

/* Dropdown tài khoản người dùng */
.header-user { position: relative; }

.header-user-btn {
    border: 1.5px solid rgba(255,255,255,.55);
    background: rgba(255,255,255,.18);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 7px 14px;
    border-radius: 20px;
    font-size: 12.5px;
    font-weight: 600;
    color: #fff;
}

.header-user-menu {
    display: none;
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    background: #fff;
    border-radius: 10px;
    box-shadow: 0 10px 30px rgba(10,20,60,.2);
    overflow: hidden;
    min-width: 160px;
    z-index: 100;
}

.header-user-menu.open { display: block; }

.header-user-menu form { margin: 0; }

.header-user-menu button {
    width: 100%;
    border: none;
    background: none;
    text-align: left;
    padding: 11px 16px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-main);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
}

.header-user-menu button:hover { background: #f5f6fb; color: var(--shell-red); }

.sidebar-toggle {
    display: none;
    background: none;
    border: none;
    color: #fff;
    font-size: 22px;
    cursor: pointer;
}

/* ══════════ BODY LAYOUT ══════════ */
/* .appshell-body chỉ trừ chiều cao header — sidebar chiếm toàn bộ chiều
   cao còn lại. Cột bản đồ (.appshell-mapcol) tự chia bên trong nó thành
   phần bản đồ (flex:1) + thanh thống kê (chiều cao tự nhiên), nên thanh
   thống kê chỉ nằm bên dưới bản đồ, không tràn ngang qua sidebar. */
.appshell-body {
    display: flex;
    height: calc(100vh - var(--header-h));
    min-height: 420px;
}

/* Cột bên phải sidebar: bản đồ (phía trên) + thanh thống kê (phía dưới).
   position:relative để làm mốc cho .detail-panel — panel định vị theo
   TOÀN BỘ cột này (cao hết cỡ, đè lên góc phải thanh thống kê khi mở),
   không phải chỉ riêng phần bản đồ. */
.appshell-mapcol {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    position: relative;
}

/* ── SIDEBAR ── */
.appshell-sidebar {
    width: 232px;
    flex-shrink: 0;
    background: var(--shell-navy);
    color: #c6cff2;
    overflow-y: auto;
    z-index: 40;
}

.sidebar-nav { padding: 10px 0; }

.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 9px 18px;
    font-size: 13px;
    font-weight: 500;
    color: #c6cff2;
    border-left: 3px solid transparent;
    transition: background .15s, color .15s;
}

.sidebar-nav a i { font-size: 15px; width: 18px; text-align: center; color: #8b96c7; }

.sidebar-nav a img {
    width: 18px; height: 18px; object-fit: cover;
    border-radius: 4px; flex-shrink: 0;
}

.sidebar-nav a:hover { background: rgba(255,255,255,.06); color: #fff; }

.sidebar-nav a.active {
    background: var(--shell-blue);
    color: #fff;
    border-left-color: var(--shell-yellow);
}

.sidebar-nav a.active i { color: #fff; }

.sidebar-divider {
    border-top: 1px solid rgba(255,255,255,.1);
    margin: 6px 0;
}

.sidebar-sublist-head {
    font-size: 11px;
    font-weight: 700;
    color: #7f8bc2;
    text-transform: uppercase;
    letter-spacing: .6px;
    padding: 12px 18px 6px;
}

.sidebar-sublist { padding: 0 10px 12px; }

.sidebar-sublist-item {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 8px 10px;
    border-radius: 8px;
    font-size: 12.5px;
    font-weight: 500;
    color: #c6cff2;
    cursor: pointer;
    margin-bottom: 2px;
    transition: background .15s, color .15s;
}

.sidebar-sublist-item i { font-size: 13px; color: #8b96c7; }

.sidebar-sublist-item:hover { background: rgba(255,255,255,.07); color: #fff; }

.sidebar-sublist-item.active {
    background: var(--shell-blue);
    color: #fff;
}

.sidebar-sublist-item.active i { color: #fff; }

.sidebar-viewall {
    display: block;
    text-align: center;
    font-size: 12px;
    font-weight: 600;
    color: var(--shell-yellow);
    padding: 8px 10px;
}

.sidebar-empty {
    padding: 10px 18px;
    font-size: 12px;
    color: #7f8bc2;
}

/* ── MAP AREA ── */
.appshell-map { flex: 1; position: relative; overflow: hidden; background: #dfe6f0; }

/* Leaflet tự gắn z-index nội bộ rất cao cho các pane của nó (tile/marker/
   popup pane: 200-700). Nếu #map không có z-index riêng, nó không tạo
   "stacking context" mới nên các pane đó "thoát ra ngoài" và so trực tiếp
   với z-index của .detail-panel (45) ở ngoài — khiến bản đồ luôn đè lên
   panel dù panel có z-index cao hơn trên giấy. Gán z-index cho #map để
   cô lập toàn bộ nội dung Leaflet vào 1 stacking context riêng. */
#map { position: absolute; inset: 0; z-index: 1; }

.map-zoom-ctrl, .map-locate-ctrl, .map-layers-ctrl, .map-list-ctrl {
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,.2);
    overflow: hidden;
    margin-left: 10px;
}

.map-locate-ctrl, .map-layers-ctrl, .map-list-ctrl { margin-top: 8px; }

.map-zoom-ctrl button, .map-locate-ctrl button, .map-layers-ctrl button, .map-list-ctrl button {
    display: block;
    width: 34px;
    height: 34px;
    border: none;
    background: #fff;
    font-size: 16px;
    color: #1a1f36;
    cursor: pointer;
    line-height: 34px;
    text-align: center;
    position: relative;
}

.map-zoom-ctrl button:first-child { border-bottom: 1px solid #eee; }
.map-zoom-ctrl button:hover,
.map-locate-ctrl button:hover,
.map-layers-ctrl button:hover,
.map-list-ctrl button:hover { background: #f0f2f8; }

.map-list-ctrl button.active,
.map-layers-ctrl button.active { background: var(--shell-blue); color: #fff; }

.map-layers-ctrl .layer-tag {
    position: absolute;
    bottom: 1px;
    right: 1px;
    font-size: 7px;
    font-weight: 800;
    color: var(--shell-blue);
    background: #fff;
    border-radius: 3px;
    padding: 0 2px;
    line-height: 1.3;
}

/* ── PANEL NỔI DÙNG CHUNG (chi tiết + danh sách) ── */
/* Cả 2 panel chiếm CÙNG 1 vị trí/kích thước ở góc phải bản đồ, chỉ hiện
   1 trong 2 tại 1 thời điểm (JS toggle class .open). Cao theo NỘI DUNG
   (không kéo full cột) để tránh khoảng trắng rỗng khi nội dung ngắn — chỉ
   giới hạn max-height, phần .panel-content tự cuộn nếu nội dung dài hơn. */
.side-panel {
    position: absolute;
    top: 16px;
    right: 16px;
    max-height: calc(100% - 32px);
    height: fit-content;
    width: 410px;
    max-width: calc(100% - 24px);
    background: #fff;
    border-radius: 18px;
    box-shadow: 0 20px 50px rgba(10,20,60,.28);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform: translateX(120%);
    opacity: 0;
    pointer-events: none;
    transition: transform .3s ease, opacity .3s ease;
    z-index: 45;
}

.side-panel.open { transform: translateX(0); opacity: 1; pointer-events: auto; }

.list-panel { max-height: calc(100% - 32px); }

.panel-cover {
    width: 100%;
    height: 120px;
    object-fit: cover;
    display: block;
    background: linear-gradient(135deg, #dce8ff, #c8d8ff);
    flex-shrink: 0;
}

.panel-titlebar {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 10px;
    padding: 10px 14px 6px;
    flex-shrink: 0;
}

.panel-titlebar h3 {
    margin: 0;
    font-size: 14.5px;
    font-weight: 800;
    color: var(--text-main);
    letter-spacing: -.2px;
    text-transform: uppercase;
    line-height: 1.25;
}

.panel-close {
    border: none;
    background: #f1f3f9;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    font-size: 13px;
    color: #6b7280;
    cursor: pointer;
    flex-shrink: 0;
    transition: background .15s, color .15s;
}

.panel-close:hover { background: #fde3e3; color: var(--shell-red); }

.panel-tabs {
    display: flex;
    background: #f5f6fb;
    border-radius: 9px;
    margin: 0 14px 4px;
    padding: 3px;
    flex-shrink: 0;
}

.panel-tabs button {
    flex: 1;
    border: none;
    background: none;
    border-radius: 7px;
    padding: 6px 4px;
    font-size: 11px;
    font-weight: 700;
    color: #8990a3;
    cursor: pointer;
    transition: background .15s, color .15s;
}

.panel-tabs button.active {
    color: var(--shell-blue);
    background: #fff;
    box-shadow: 0 1px 4px rgba(10,20,60,.12);
}

.panel-content {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    padding: 4px 14px 10px;
}

.panel-tabpane { display: none; }
.panel-tabpane.active { display: block; }

.panel-section-title {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 10.5px;
    font-weight: 800;
    color: var(--shell-blue);
    text-transform: uppercase;
    letter-spacing: .5px;
    margin: 10px 0 6px;
}

.panel-section-title::before {
    content: '';
    width: 3px;
    height: 11px;
    border-radius: 2px;
    background: var(--shell-blue);
}

.panel-section-title:first-child { margin-top: 2px; }

.panel-intro {
    font-size: 12px;
    line-height: 1.55;
    color: #4a5063;
}

.panel-more-link {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    margin-top: 2px;
    font-size: 11px;
    font-weight: 700;
    color: var(--shell-blue);
    cursor: pointer;
}

.panel-more-link:hover { text-decoration: underline; }

.info-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
}

.info-cell {
    display: flex;
    align-items: center;
    gap: 8px;
    background: #f7f8fc;
    border: 1px solid #eef0f6;
    border-radius: 9px;
    padding: 6px 8px;
}

.info-icon {
    width: 26px;
    height: 26px;
    border-radius: 7px;
    background: rgba(26,63,218,.1);
    color: var(--shell-blue);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    flex-shrink: 0;
}

.info-text { display: flex; flex-direction: column; gap: 0; min-width: 0; }

.info-text .label {
    font-size: 9.5px;
    color: var(--text-sub);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.info-text .value {
    font-size: 12px;
    font-weight: 700;
    color: var(--text-main);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.leader-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 4px;
    border-bottom: 1px solid #f0f1f6;
}

.leader-row:last-child { border-bottom: none; }

.leader-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: #eef2ff;
    color: var(--shell-blue);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    flex-shrink: 0;
}

.leader-text { display: flex; flex-direction: column; flex: 1; min-width: 0; gap: 0; }
.leader-role { font-size: 9.5px; color: var(--text-sub); }
.leader-name {
    font-size: 12px;
    font-weight: 700;
    color: var(--text-main);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.leader-phone {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 11px;
    font-weight: 700;
    color: var(--shell-blue);
    background: #eef2ff;
    padding: 4px 9px;
    border-radius: 20px;
    white-space: nowrap;
    flex-shrink: 0;
    transition: background .15s;
}

.leader-phone:hover { background: #dde5ff; }

.panel-empty {
    text-align: center;
    padding: 20px 10px;
    color: #9aa1b5;
    font-size: 12px;
}

.media-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
}

.media-grid img {
    width: 100%;
    height: 74px;
    object-fit: cover;
    border-radius: 8px;
}

.panel-footer {
    display: flex;
    gap: 8px;
    padding: 10px 14px;
    border-top: 1px solid #eef0f6;
    box-shadow: 0 -4px 12px rgba(10,20,60,.04);
    flex-shrink: 0;
}

.panel-footer button {
    flex: 1;
    border: none;
    border-radius: 10px;
    padding: 9px 8px;
    font-size: 12.5px;
    font-weight: 700;
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    transition: background .15s, transform .1s;
}

.panel-footer button:active { transform: scale(.97); }

.btn-directions { background: var(--shell-blue); box-shadow: 0 4px 12px rgba(26,63,218,.3); }
.btn-directions:hover { background: var(--shell-blue-2); }
.btn-share { background: var(--shell-green); box-shadow: 0 4px 12px rgba(26,158,92,.3); }
.btn-share:hover { background: #158049; }

/* ── MARKER (Google Maps, không dùng InfoWindow mặc định, dùng panel riêng) ── */
.vn-marker { filter: drop-shadow(0 2px 4px rgba(0,0,0,.35)); }

/* ── LIST PANEL (danh sách địa điểm, nổi cùng chỗ với panel chi tiết) ── */
.list-panel-search {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0 14px 8px;
    padding: 8px 12px;
    background: #f5f6fb;
    border-radius: 10px;
    flex-shrink: 0;
    color: #8990a3;
}

.list-panel-search input {
    flex: 1;
    border: none;
    background: none;
    outline: none;
    font-size: 12.5px;
    font-family: inherit;
    color: var(--text-main);
}

.list-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 8px;
    border-radius: 10px;
    cursor: pointer;
    transition: background .15s;
    margin-bottom: 2px;
}

.list-item:hover { background: #f5f6fb; }

.list-item.active { background: #eef2ff; }

.list-item-dot {
    width: 11px;
    height: 11px;
    border-radius: 50%;
    flex-shrink: 0;
    box-shadow: 0 0 0 3px rgba(0,0,0,.05);
}

.list-item-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }

.list-item-name {
    font-size: 12.5px;
    font-weight: 700;
    color: var(--text-main);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.list-item-cat { font-size: 10.5px; color: var(--text-sub); }

.list-item > .bi-chevron-right { color: #c2c8dd; font-size: 12px; flex-shrink: 0; }

.list-panel-empty {
    text-align: center;
    padding: 30px 10px;
    color: #9aa1b5;
    font-size: 12.5px;
}

/* ── LEGEND (chú giải màu marker) ── */
.map-legend {
    position: absolute;
    left: 16px;
    bottom: 16px;
    z-index: 20;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(10,20,60,.16);
    overflow: hidden;
    max-width: 220px;
}

.map-legend-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    width: 100%;
    border: none;
    background: #fff;
    padding: 9px 12px;
    font-size: 12px;
    font-weight: 700;
    color: var(--text-main);
    cursor: pointer;
}

.map-legend-toggle #legendChevron { margin-left: auto; font-size: 10px; transition: transform .2s; }

.map-legend.collapsed .map-legend-toggle #legendChevron { transform: rotate(180deg); }

.map-legend-body {
    padding: 2px 12px 10px;
    max-height: 200px;
    overflow-y: auto;
}

.map-legend.collapsed .map-legend-body { display: none; }

.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 11.5px;
    color: #4a5063;
    padding: 4px 0;
}

.legend-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
    box-shadow: 0 0 0 2px rgba(0,0,0,.05);
}

/* ══════════ STATS BAR ══════════ */
/* Nổi (floating) trên bản đồ như một khối pill riêng, background chỉ ôm
   sát nội dung — không còn là thanh trắng kéo dài hết chiều ngang. Mặc
   định căn giữa cột bản đồ; khi panel chi tiết đang mở thì dạt sang trái
   (qua class .shifted, JS gắn/gỡ theo trạng thái panel) để không bị panel
   che mất. */
.appshell-stats {
    position: absolute;
    left: 50%;
    bottom: 16px;
    transform: translateX(-50%);
    width: fit-content;
    max-width: calc(100% - 32px);
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 10px 30px rgba(10,20,60,.16);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: nowrap;
    overflow-x: auto;
    padding: 8px 10px;
    gap: 2px;
    z-index: 20;
    transition: left .25s ease, transform .25s ease;
    scrollbar-width: thin;
}

.appshell-stats::-webkit-scrollbar { height: 4px; }
.appshell-stats::-webkit-scrollbar-thumb { background: #dfe3f0; border-radius: 4px; }

/* Panel rộng 410px + margin phải 16px + khoảng cách 16px ≈ 442px, dạt
   trái đúng bằng nửa khoảng đó để phần còn lại vẫn nằm giữa vùng trống */
.appshell-stats.shifted {
    left: calc(50% - 221px);
}

.stat-item {
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 4px 10px;
    border-right: 1px solid #eef0f6;
    flex-shrink: 0;
    white-space: nowrap;
}

.stat-item:last-child { border-right: none; }

.stat-icon {
    width: 30px;
    height: 30px;
    border-radius: 9px;
    background: #eef2ff;
    color: var(--shell-blue);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    flex-shrink: 0;
    overflow: hidden;
}

.stat-icon img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.stat-value {
    font-size: 15px;
    font-weight: 800;
    color: var(--text-main);
    line-height: 1.1;
}

.stat-label {
    font-size: 9.5px;
    color: var(--text-sub);
    font-weight: 600;
}

/* ══════════ RESPONSIVE ══════════ */
@media (max-width: 992px) {
    .sidebar-toggle { display: block; }

    .appshell-sidebar {
        position: fixed;
        top: var(--header-h);
        bottom: 0;
        left: 0;
        width: 260px;
        transform: translateX(-100%);
        transition: transform .25s ease;
        box-shadow: 4px 0 20px rgba(0,0,0,.25);
    }

    .appshell-sidebar.open { transform: translateX(0); }

    .header-search { display: none; }
    .header-actions .btn-shell span { display: none; }
    .header-actions .btn-shell { padding: 8px; }

    .side-panel { width: calc(100% - 24px); }
}

@media (max-width: 576px) {
    .header-brand-tag { display: none; }
    .appshell-stats {
        left: 12px;
        right: 12px;
        bottom: 12px;
        transform: none;
        width: auto;
        max-width: none;
        justify-content: flex-start;
        overflow-x: auto;
        flex-wrap: nowrap;
    }
    .appshell-stats.shifted { left: 12px; }

    .map-legend { left: 10px; bottom: auto; top: 10px; max-width: 160px; }
}
