/* =========================================================================
   OMNIGUARD - MẠNG LƯỚI CẢM BIẾN (mang-luoi.html)
   Dùng token & thành phần của style.css; bổ sung bảng màu TRẠNG THÁI THIẾT BỊ.
   Màu trạng thái luôn đi kèm biểu tượng + nhãn, không bao giờ chỉ dùng màu.
   ========================================================================= */
:root {
    --st-online: #0ca30c;
    --st-degraded: #fab219;
    --st-faulty: #ec835a;
    --st-offline: #d03b3b;
    --st-nodata: #8b8f98;
    --sim: #b9a6ff;            /* nhận diện cảm biến mô phỏng (không phải màu trạng thái) */
    --sim-soft: rgba(185, 166, 255, 0.12);
    --chart-line: #22c3ee;
    --grid: rgba(148, 163, 184, 0.14);
}

/* ---------------- Thanh trên */
#sn-updated { margin-left: 4px; }

/* ---------------- Tab & bộ lọc */
.sn-tabs { flex-wrap: nowrap; }
.sn-tab-count { margin-left: 4px; font-weight: 700; color: var(--text); }
.sn-filters { padding: var(--sp-3) var(--sp-4); border-bottom: 1px solid var(--border); display: flex; flex-direction: column; gap: var(--sp-2); }
.sn-filter-row { display: flex; gap: var(--sp-2); flex-wrap: wrap; }
.sn-type-btn {
    display: inline-flex; align-items: center; gap: 6px;
    height: 28px; padding: 0 10px; border-radius: 999px;
    border: 1px solid var(--border); color: var(--text-2); font-size: var(--fs-xs); font-weight: 600;
}
.sn-type-btn:hover { color: var(--text); border-color: var(--border-strong); }
.sn-type-btn.active { color: var(--text); background: var(--accent-soft); border-color: var(--accent); }
.sn-type-btn small { color: var(--text-3); font-weight: 500; }
.sn-province-chip {
    display: flex; align-items: center; justify-content: space-between; gap: var(--sp-2);
    padding: 6px 10px; border-radius: var(--r-md); background: var(--surface-2); border: 1px solid var(--border);
}
.sn-province-chip button { color: var(--text-3); }
.sn-province-chip button:hover { color: var(--text); }

/* ---------------- Khối nội dung */
.sn-section-title { font-size: var(--fs-xs); font-weight: 700; color: var(--text-3); text-transform: uppercase; letter-spacing: 0.6px; margin-top: var(--sp-2); }
.sn-card { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-md); padding: var(--sp-3); }
.sn-muted { color: var(--text-3); }
.sn-small { font-size: var(--fs-xs); }
.sn-num { font-variant-numeric: tabular-nums; }

.sn-tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--sp-2); }
.sn-tile { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-md); padding: var(--sp-3); }
.sn-tile-label { font-size: var(--fs-xs); color: var(--text-3); }
.sn-tile-value { font-size: var(--fs-xl); font-weight: 800; line-height: 1.2; font-variant-numeric: tabular-nums; }
.sn-tile-sub { font-size: var(--fs-xs); color: var(--text-2); }

/* Trạng thái: biểu tượng + nhãn + màu */
.sn-status { display: inline-flex; align-items: center; gap: 5px; font-size: var(--fs-xs); font-weight: 600; white-space: nowrap; color: var(--text); }
.sn-status i { font-size: 11px; }
.sn-status--ONLINE i { color: var(--st-online); }
.sn-status--DEGRADED i { color: var(--st-degraded); }
.sn-status--FAULTY i { color: var(--st-faulty); }
.sn-status--OFFLINE i { color: var(--st-offline); }
.sn-status--NO_DATA i { color: var(--st-nodata); }
.sn-sev { display: inline-flex; align-items: center; gap: 5px; font-size: var(--fs-xs); font-weight: 600; white-space: nowrap; }
.sn-sev--critical i { color: var(--st-offline); }
.sn-sev--warning i { color: var(--st-degraded); }
.sn-sev--info i { color: var(--st-nodata); }

.sn-sim-badge {
    display: inline-flex; align-items: center; gap: 4px; padding: 1px 7px; border-radius: 999px;
    font-size: 11px; font-weight: 700; letter-spacing: 0.3px; color: var(--sim); background: var(--sim-soft); border: 1px dashed var(--sim);
}
.sn-real-badge {
    display: inline-flex; align-items: center; gap: 4px; padding: 1px 7px; border-radius: 999px;
    font-size: 11px; font-weight: 600; color: var(--text-2); border: 1px solid var(--border-strong);
}
.sn-sim-banner {
    border: 1px dashed var(--sim); background: var(--sim-soft); color: #ddd3ff;
    border-radius: var(--r-md); padding: var(--sp-3); font-size: var(--fs-xs); display: flex; gap: var(--sp-2);
}

/* Bảng theo loại cảm biến + thanh trạng thái xếp chồng */
.sn-table { width: 100%; border-collapse: collapse; font-size: var(--fs-xs); }
.sn-table th { text-align: left; font-weight: 600; color: var(--text-3); padding: 4px 4px 6px; border-bottom: 1px solid var(--border); }
.sn-table td { padding: 7px 4px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.sn-table tr:last-child td { border-bottom: none; }
.sn-table .r { text-align: right; font-variant-numeric: tabular-nums; }
.sn-stack { display: flex; height: 8px; gap: 2px; border-radius: 4px; overflow: hidden; min-width: 90px; background: var(--surface-3); }
.sn-stack span { display: block; height: 100%; }
.sn-stack .ONLINE { background: var(--st-online); }
.sn-stack .DEGRADED { background: var(--st-degraded); }
.sn-stack .FAULTY { background: var(--st-faulty); }
.sn-stack .OFFLINE { background: var(--st-offline); }
.sn-stack .NO_DATA { background: var(--st-nodata); }
.sn-legend-inline { display: flex; flex-wrap: wrap; gap: var(--sp-3); font-size: var(--fs-xs); color: var(--text-2); }

/* Nguồn dữ liệu */
.sn-source { display: flex; justify-content: space-between; gap: var(--sp-2); padding: 6px 0; border-bottom: 1px solid var(--border); }
.sn-source:last-child { border-bottom: none; }

/* Danh sách tỉnh / sự cố */
.sn-list { display: flex; flex-direction: column; gap: var(--sp-2); }
.sn-row {
    display: flex; flex-direction: column; gap: 4px; text-align: left; width: 100%;
    background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-md); padding: 10px var(--sp-3);
    transition: border-color 0.15s, background 0.15s;
}
.sn-row:hover { border-color: var(--border-strong); background: var(--surface-3); }
.sn-row-top { display: flex; justify-content: space-between; align-items: center; gap: var(--sp-2); }
.sn-row-title { font-weight: 600; font-size: var(--fs-sm); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sn-row-meta { display: flex; flex-wrap: wrap; gap: 4px 10px; font-size: var(--fs-xs); color: var(--text-2); }
.sn-gap { display: inline-flex; gap: 3px; padding: 0 6px; border-radius: 4px; background: var(--surface-3); color: var(--text-2); font-size: 11px; }

/* Thanh tỷ lệ (kiểm định QC) */
.sn-bar { height: 8px; border-radius: 4px; background: var(--surface-3); overflow: hidden; min-width: 60px; }
.sn-bar > span { display: block; height: 100%; background: var(--chart-line); border-radius: 4px; }

/* Hồ sơ thiết bị */
.sn-dev-head { display: flex; flex-direction: column; gap: 6px; }
.sn-dev-title { font-size: var(--fs-lg); font-weight: 700; line-height: 1.25; }
.sn-badges { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.sn-facts { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--sp-2); }
.sn-fact { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-md); padding: 8px 10px; }
.sn-fact .k { font-size: 11px; color: var(--text-3); }
.sn-fact .v { font-size: var(--fs-md); font-weight: 700; font-variant-numeric: tabular-nums; }
.sn-issue { display: flex; gap: var(--sp-2); align-items: flex-start; padding: 8px 0; border-bottom: 1px solid var(--border); }
.sn-issue:last-child { border-bottom: none; }
.sn-issue > div { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.sn-timeline-item { display: grid; grid-template-columns: 14px 1fr; gap: var(--sp-2); padding: 6px 0; }
.sn-timeline-item .dot { width: 10px; height: 10px; border-radius: 50%; margin-top: 4px; border: 2px solid var(--text-3); }
.sn-timeline-item.open .dot { border-color: var(--st-degraded); background: var(--st-degraded); }
.sn-timeline-item.critical.open .dot { border-color: var(--st-offline); background: var(--st-offline); }

/* Biểu đồ chuỗi thời gian */
.sn-chart { position: relative; }
.sn-chart > svg { display: block; width: 100%; height: 190px; overflow: visible; }
.sn-chart .axis text { fill: var(--text-3); font-size: 11px; }
.sn-chart .grid line { stroke: var(--grid); stroke-width: 1; }
.sn-chart .series { fill: none; stroke: var(--chart-line); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.sn-chart .crosshair { stroke: var(--text-3); stroke-width: 1; stroke-dasharray: 3 3; }
.sn-chart .hover-dot { fill: var(--chart-line); stroke: var(--surface-1); stroke-width: 2; }
.sn-chart .m-suspect { fill: var(--surface-1); stroke: var(--st-degraded); stroke-width: 2; }
.sn-chart .m-bad { stroke: var(--st-offline); stroke-width: 2.5; stroke-linecap: round; }
.sn-chart .band { fill: rgba(250, 178, 25, 0.10); }
.sn-tooltip {
    position: absolute; pointer-events: none; z-index: 5; min-width: 140px;
    background: var(--surface-1); border: 1px solid var(--border-strong); border-radius: var(--r-sm);
    padding: 6px 8px; font-size: var(--fs-xs); box-shadow: var(--shadow); white-space: nowrap;
}
.sn-chart-legend { display: flex; gap: var(--sp-3); flex-wrap: wrap; font-size: 11px; color: var(--text-2); margin-top: 4px; }
.sn-chart-legend svg { width: 12px; height: 12px; vertical-align: -2px; margin-right: 3px; }

/* Bản đồ */
.sn-dot { display: inline-block; width: 12px; height: 12px; border-radius: 50%; vertical-align: -2px; }
.sn-dot--real { background: var(--text-2); }
.sn-dot--sim { border: 2.5px solid var(--sim); background: transparent; }
.sn-legend .legend-item i.fa-solid { width: 12px; text-align: center; }
.maplibregl-popup.sn-popup .maplibregl-popup-content {
    background: var(--surface-1); color: var(--text); border: 1px solid var(--border-strong); border-radius: var(--r-md);
    padding: 8px 10px; font-size: var(--fs-xs); box-shadow: var(--shadow);
}
.maplibregl-popup.sn-popup .maplibregl-popup-tip { display: none; }

.sn-link { color: var(--accent); text-decoration: none; }
.sn-link:hover { text-decoration: underline; }
.sn-cell { display: inline-block; width: 10px; height: 10px; border-radius: 2px; vertical-align: -1px; margin-right: 4px; }

.sn-empty { padding: var(--sp-5) var(--sp-3); text-align: center; color: var(--text-3); }
.sn-note { font-size: var(--fs-xs); color: var(--text-3); line-height: 1.5; }
.sn-more { align-self: center; }

@media (max-width: 768px) {
    .sn-facts { grid-template-columns: repeat(2, 1fr); }
    .sn-legend { display: none; }
}
