/* ═══════════════════════════════════════════
   NMN CHART PANEL – dùng class dma-chart-panel
   chỉ override z-index để stack đúng thứ tự
   ═══════════════════════════════════════════ */
#nmnChartPanel {
    z-index: 1101;
}

/* 4 stat cards cho NMN – grid 4 cột trên desktop, 2 cột mobile */
#nmnChartStats {
    grid-template-columns: repeat(4, 1fr) !important;
}
@media (max-width: 600px) {
    #nmnChartStats {
        grid-template-columns: repeat(2, 1fr) !important;
    }
}

/* ═══════════════════════════════════════════
   TILE SWITCHER
   Vị trí: góc dưới phải bản đồ, trên FAB
   ═══════════════════════════════════════════ */
.tile-switcher {
    position: absolute;
    bottom: 24px;
    left: 12px;
    z-index: 1000;
    display: flex;
    flex-direction: row;   /* nằm ngang trên desktop */
    gap: 4px;
    background: rgba(6, 18, 35, .88);
    border: 1px solid rgba(96, 165, 250, .22);
    border-radius: 14px;
    padding: 6px;
    backdrop-filter: blur(8px);
    box-shadow: 0 4px 20px rgba(0,0,0,.45);
}
.tile-btn {
    width: 36px;
    height: 36px;
    border: 1px solid transparent;
    border-radius: 9px;
    background: transparent;
    font-size: 17px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all .18s;
    line-height: 1;
    position: relative;   /* cần cho ::after tooltip */
}
.tile-btn:hover {
    background: rgba(96, 165, 250, .15);
    border-color: rgba(96, 165, 250, .3);
}
.tile-btn.active {
    background: rgba(56, 189, 248, .22);
    border-color: rgba(56, 189, 248, .6);
    box-shadow: 0 0 8px rgba(56,189,248,.3);
}

/* Tooltip hiện phía trên nút (vì nút ở dưới cùng) */
.tile-btn::after {
    content: attr(title);
    position: absolute;
    bottom: 44px;
    left: 50%;
    transform: translateX(-50%) translateY(4px);
    background: rgba(6,18,35,.95);
    color: #e2e8f0;
    font-size: 11px;
    font-weight: 700;
    font-family: 'Quicksand', sans-serif;
    white-space: nowrap;
    padding: 4px 9px;
    border-radius: 8px;
    border: 1px solid rgba(96,165,250,.2);
    pointer-events: none;
    opacity: 0;
    transition: opacity .15s, transform .15s;
}
.tile-btn:hover::after {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

@media (max-width: 900px) {
    .tile-switcher {
        bottom: calc(var(--dockH, 60px) + 10px);
        left: 10px;
        flex-direction: row;
    }
    .tile-btn { width: 34px; height: 34px; font-size: 16px; }
    .tile-btn::after { display: none; }

    /* Ẩn FAB van/DMA cũ — đã có nút trong tile-switcher thay thế */
    .fab-toggle-valves,
    .fab-toggle-dma-popups { display: none !important; }
}

/* Separator giữa nhóm tile và nhóm toggle */
.tile-sep {
    width: 1px;
    height: 22px;
    background: rgba(96,165,250,.25);
    border-radius: 1px;
    align-self: center;
    flex-shrink: 0;
    margin: 0 2px;
}

/* Nút text VAN / DMA */
.tile-btn--text {
    width: auto;
    min-width: 36px;
    padding: 0 8px;
    font-size: 11px;
    font-weight: 800;
    font-family: 'Quicksand', sans-serif;
    letter-spacing: .04em;
    color: #94a3b8;
}
.tile-btn--text.active { color: #e2e8f0; }

@media (max-width: 900px) {
    .tile-btn--text { font-size: 10px; padding: 0 6px; min-width: 34px; }
}

/* ── Mobile Nav Dock ── */
.mobile-nav.dock-solid { display: none; }

@media (max-width: 900px) {
    #nmnChartPanel {
        bottom: var(--dockH, 60px);
        max-height: 50vh;
    }

    .mobile-nav.dock-solid {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 9999;
        display: flex;
        gap: 8px;
        padding: 8px 10px calc(env(safe-area-inset-bottom) + 8px);
        background:
            radial-gradient(circle at left center, rgba(37,99,235,.18), transparent 28%),
            linear-gradient(180deg, #031225 0%, #04162d 100%);
        border-top: 1px solid rgba(80,140,255,.18);
        box-shadow: 0 -10px 30px rgba(0,0,0,.35);
    }
    .mobile-nav.dock-solid .mnav {
        flex: 1;
        min-width: 0;
        height: 58px;
        padding: 6px 4px 5px;
        border-radius: 14px;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 5px;
        text-decoration: none;
        background: linear-gradient(180deg, #0a1d39 0%, #08182f 100%);
        border: 1px solid rgba(59,130,246,.16);
        box-shadow: inset 0 1px 0 rgba(255,255,255,.03), 0 0 0 1px rgba(8,25,52,.25);
        transition: all .22s ease;
    }
    .mobile-nav.dock-solid .micon {
        width: 22px; height: 22px;
        display: flex; align-items: center; justify-content: center;
        border-radius: 8px;
        background: rgba(37,99,235,.08);
        color: #5ea2ff;
        font-size: 0;
        transition: all .22s ease;
    }
    .mobile-nav.dock-solid .micon svg {
        width: 16px; height: 16px;
        display: block;
        stroke: currentColor;
    }
    .mobile-nav.dock-solid .mlabel {
        max-width: 100%;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        font-size: 10px;
        line-height: 1;
        font-weight: 700;
        letter-spacing: 0;
        color: #86a7d8;
        transition: all .22s ease;
    }
    .mobile-nav.dock-solid .mnav:hover {
        border-color: rgba(96,165,250,.28);
        background: linear-gradient(180deg, #0d2344 0%, #0a1d39 100%);
    }
    .mobile-nav.dock-solid .mnav:hover .micon { color: #7db7ff; background: rgba(59,130,246,.12); }
    .mobile-nav.dock-solid .mnav:hover .mlabel { color: #b8d4ff; }
    .mobile-nav.dock-solid .mnav.active {
        background: linear-gradient(180deg, #3b82f6 0%, #2563eb 100%);
        border: 1px solid rgba(147,197,253,.7);
        box-shadow: 0 0 0 1px rgba(255,255,255,.10) inset, 0 0 18px rgba(59,130,246,.45), 0 8px 18px rgba(37,99,235,.32);
    }
    .mobile-nav.dock-solid .mnav.active .micon { background: rgba(255,255,255,.16); color: #fff; }
    .mobile-nav.dock-solid .mnav.active .mlabel { color: #fff; font-weight: 800; text-shadow: 0 1px 2px rgba(0,0,0,.18); }
    .mobile-nav.dock-solid .mnav:active { transform: scale(.97); }
}

@media (max-width: 380px) {
    .mobile-nav.dock-solid { gap: 6px; padding: 7px 8px calc(env(safe-area-inset-bottom) + 7px); }
    .mobile-nav.dock-solid .mnav { height: 54px; border-radius: 12px; gap: 4px; padding: 5px 2px 4px; }
    .mobile-nav.dock-solid .micon { width: 20px; height: 20px; }
    .mobile-nav.dock-solid .micon svg { width: 14px; height: 14px; }
    .mobile-nav.dock-solid .mlabel { font-size: 9px; }
}

/* ══════════════════════════════════════════════════════════════
   VALVE PHOTO
══════════════════════════════════════════════════════════════ */
.valve-photo-wrap {
    margin-top: 12px;
    border-top: 1px solid rgba(255,255,255,.08);
    padding-top: 10px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* Hàng 1: tiêu đề */
.valve-photo-title {
    font-size: 11px;
    font-weight: 800;
    color: #94a3b8;
    letter-spacing: .04em;
    text-transform: uppercase;
}

/* Hàng 2: nút Chụp + Chọn */
.valve-photo-btns {
    display: flex;
    gap: 8px;
}
.valve-photo-btn {
    flex: 1;
    border: none;
    border-radius: 9px;
    padding: 7px 10px;
    font-size: 12px;
    font-weight: 700;
    font-family: 'Quicksand', sans-serif;
    cursor: pointer;
    transition: all .18s;
    text-align: center;
}
.valve-photo-btn:active { transform: scale(.95); }
.valve-photo-btn.capture {
    background: linear-gradient(135deg, #2563eb, #1d4ed8);
    color: #fff;
}
.valve-photo-btn.pick {
    background: rgba(96,165,250,.12);
    border: 1px solid rgba(96,165,250,.3);
    color: #93c5fd;
}

.valve-photo-msg {
    font-size: 11px;
    font-weight: 700;
    min-height: 14px;
    color: #86efac;
}

/* Gallery: lưới ảnh 3 cột */
.valve-photo-gallery {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 5px;
    max-height: 200px;
    overflow-y: auto;
}
.valve-photo-gallery:empty::after {
    content: 'Chưa có ảnh';
    grid-column: 1/-1;
    text-align: center;
    font-size: 11px;
    color: #475569;
    padding: 10px 0;
}

/* Mỗi ô ảnh */
.vp-thumb {
    position: relative;
    aspect-ratio: 1;
    border-radius: 8px;
    overflow: hidden;
    background: rgba(255,255,255,.04);
    border: 1px solid rgba(255,255,255,.08);
    cursor: pointer;
    transition: transform .15s;
}
.vp-thumb:hover { transform: scale(1.03); }
.vp-thumb img {
    width: 100%; height: 100%;
    object-fit: cover;
    display: block;
}
.vp-label {
    position: absolute;
    bottom: 0; left: 0; right: 0;
    background: rgba(0,0,0,.55);
    color: #e2e8f0;
    font-size: 8px;
    font-weight: 700;
    padding: 2px 4px;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Nút xóa góc trên phải mỗi ảnh — luôn hiện */
.vp-del {
    position: absolute;
    top: 3px; right: 3px;
    width: 22px; height: 22px;
    border-radius: 50%;
    background: rgba(239,68,68,.9);
    border: 1.5px solid rgba(255,255,255,.6);
    color: #fff;
    font-size: 11px;
    font-weight: 900;
    line-height: 1;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    z-index: 2;
    box-shadow: 0 1px 4px rgba(0,0,0,.4);
    transition: transform .15s, background .15s;
}
.vp-del:hover { background: #dc2626; transform: scale(1.15); }

/* Lightbox */
#vpLightbox {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 99999;
    background: rgba(0,0,0,.92);
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 12px;
}
#vpLightbox.open { display: flex; }
#vpLightbox img {
    max-width: 94vw;
    max-height: 80vh;
    border-radius: 10px;
    object-fit: contain;
    box-shadow: 0 8px 40px rgba(0,0,0,.7);
}
#vpLightbox .vp-lb-label {
    color: #94a3b8;
    font-size: 12px;
    font-weight: 700;
}
#vpLightbox .vp-lb-close {
    position: absolute;
    top: 16px; right: 16px;
    background: rgba(255,255,255,.12);
    border: none;
    border-radius: 50%;
    width: 38px; height: 38px;
    font-size: 18px;
    color: #fff;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
}

/* ══════════════════════════════════════════════════════════════
   MŨI TÊN SO SÁNH HÔM QUA (popup DMA)
══════════════════════════════════════════════════════════════ */
.pop-delta {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    margin-left: 6px;
    padding: 1px 6px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 800;
    line-height: 1.5;
    vertical-align: middle;
    letter-spacing: .02em;
}
.pop-delta.up   { color: #16a34a; background: rgba(22,163,74,.16); }
.pop-delta.down { color: #dc2626; background: rgba(220,38,38,.16); }
.pop-delta.flat { color: #94a3b8; background: rgba(148,163,184,.16); }