* { box-sizing: border-box; }
body {
    font-family: 'Segoe UI', Arial, sans-serif;
    margin: 0;
    background: #eef2fb;
    color: #0f172a;
}
.icon { width: 18px; height: 18px; flex-shrink: 0; }

/* ==================== TOP NAV ==================== */
.topnav {
    background: linear-gradient(135deg, #1e3a8a, #2563eb);
    color: #fff;
    padding: 16px 32px;
    display: flex;
    align-items: center;
    gap: 20px;
    flex-wrap: wrap;

    /* Dibuat menempel di atas layar saat halaman discroll */
    position: sticky;
    top: 0;
    z-index: 1000;
    box-shadow: 0 4px 14px rgba(30, 58, 138, 0.18);
}
.brand { display: flex; align-items: center; gap: 14px; }
.brand .logo {
    width: 48px; height: 48px; border-radius: 12px; background: #fff;
    display: flex; align-items: center; justify-content: center; flex-shrink: 0;
    overflow: hidden; padding: 4px;
}
.brand .logo svg { width: 24px; height: 24px; color: #2563eb; }
.brand .logo img { width: 100%; height: 100%; object-fit: contain; display: block; }
.brand h1 { margin: 0; font-size: 19px; letter-spacing: .3px; }
.brand .badge {
    display: inline-flex; align-items: center; gap: 6px;
    background: rgba(255,255,255,.16); border: 1px solid rgba(255,255,255,.3);
    padding: 3px 10px; border-radius: 20px; font-size: 11px; font-weight: 600; margin-left: 10px;
}
.brand .badge .dot { width: 6px; height: 6px; border-radius: 50%; background: #4ade80; }
.brand .subtitle { font-size: 12px; opacity: .85; margin-top: 2px; }

.nav-right { margin-left: auto; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.tab-group {
    display: flex; background: rgba(255,255,255,.12); border-radius: 12px; padding: 4px; gap: 2px;
}
.tab-btn {
    border: none; background: transparent; color: #fff; padding: 9px 16px; border-radius: 9px;
    font-size: 13px; font-weight: 600; cursor: pointer; opacity: .8; white-space: nowrap;
}
.tab-btn.active { background: #fff; color: #1e3a8a; opacity: 1; }
.tab-btn .n { opacity: .7; font-weight: 500; }
.tab-btn.active .n { opacity: .55; }

.nav-link {
    display: inline-flex; align-items: center; gap: 7px;
    color: #fff; background: rgba(255,255,255,.14); padding: 9px 16px;
    border-radius: 10px; text-decoration: none; font-size: 13px; font-weight: 600;
}
.nav-link:hover { background: rgba(255,255,255,.24); }

@media (max-width: 900px) {
    .topnav { padding: 14px 18px; }
    .nav-right { width: 100%; justify-content: flex-start; }
}

/* ==================== PAGE HEADER ==================== */
.page-head {
    padding: 28px 32px 0;
    display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; flex-wrap: wrap;
}
.page-head h2 { margin: 0 0 4px; font-size: 24px; color: #0f172a; }
.page-head .sub { margin: 0; font-size: 13px; color: #64748b; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.unit-pill {
    display: inline-block; background: #fff; border: 1px solid #dbe3f0; color: #334155;
    font-size: 11px; font-weight: 600; padding: 4px 10px; border-radius: 8px;
}

.head-tools { display: flex; gap: 10px; flex-wrap: wrap; }
.search-box {
    display: flex; align-items: center; gap: 8px; background: #fff; border: 1px solid #dbe3f0;
    border-radius: 10px; padding: 10px 14px; min-width: 240px;
}
.search-box svg { width: 16px; height: 16px; color: #94a3b8; flex-shrink: 0; }
.search-box input { border: none; outline: none; font-size: 13px; width: 100%; }
.filter-btn {
    display: inline-flex; align-items: center; gap: 8px; background: #fff; border: 1px solid #dbe3f0;
    border-radius: 10px; padding: 10px 16px; font-size: 13px; font-weight: 600; color: #334155; cursor: pointer;
}
.filter-btn:hover { background: #f8fafc; }
.filter-btn svg { width: 16px; height: 16px; }

/* ==================== SUMMARY CARDS ==================== */
.stat-grid {
    padding: 20px 32px 0;
    display: grid; grid-template-columns: repeat(4, 1fr); gap: 18px;
}
.stat-card {
    background: #fff; border-radius: 14px; padding: 18px 20px;
    box-shadow: 0 6px 18px rgba(30, 58, 138, 0.08);
    display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
}
.stat-card .stat-label { font-size: 11px; font-weight: 700; letter-spacing: .3px; color: #94a3b8; margin-bottom: 8px; }
.stat-card .stat-value { font-size: 26px; font-weight: 700; color: #0f172a; }
.stat-card .stat-value .unit { font-size: 13px; font-weight: 600; color: #64748b; }
.stat-card .stat-note { font-size: 11.5px; margin-top: 6px; color: #64748b; }
.stat-card .stat-note.good { color: #16a34a; }
.stat-card .stat-note.bad { color: #dc2626; }
.stat-card .stat-icon {
    width: 44px; height: 44px; border-radius: 12px; display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.stat-icon.blue { background: #e8effe; color: #2563eb; }
.stat-icon.green { background: #e8fbef; color: #16a34a; }
.stat-icon.red { background: #fdeceb; color: #dc2626; }
.stat-icon.amber { background: #fef7e8; color: #d97706; }
.stat-icon svg { width: 22px; height: 22px; }
.stat-note a { color: inherit; text-decoration: none; font-weight: 700; }
.stat-note a:hover { text-decoration: underline; }

@media (max-width: 900px) { .stat-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 520px) { .stat-grid { grid-template-columns: 1fr; } }

/* ==================== INSIGHT ROW: STATUS ARMADA (DONUT) + TOP 10 ==================== */
.insight-grid {
    padding: 20px 32px 0;
    display: grid; grid-template-columns: 360px 1fr; gap: 18px; align-items: stretch;
}
@media (max-width: 1100px) { .insight-grid { grid-template-columns: 1fr; } }

.insight-card {
    background: #fff; border-radius: 16px; padding: 22px 24px;
    box-shadow: 0 6px 18px rgba(30, 58, 138, 0.07);
    border: 1px solid #eef1f8;
}
.insight-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.insight-head h3 { margin: 0; font-size: 16px; color: #0f172a; display: flex; align-items: center; gap: 8px; }
.insight-head p { margin: 4px 0 0; font-size: 12px; color: #64748b; max-width: 280px; }
.insight-tag {
    font-size: 10px; font-weight: 800; letter-spacing: .4px; color: #1d4ed8;
    background: #e8effe; padding: 3px 8px; border-radius: 6px; text-transform: uppercase;
}
.badge-pill-red {
    display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 700;
    color: #b91c1c; background: #fdeceb; padding: 5px 12px; border-radius: 20px; white-space: nowrap;
}

/* ---- Donut chart (murni CSS conic-gradient, tanpa library) ---- */
.donut-outer {
    position: relative; width: 190px; height: 190px; margin: 18px auto 20px;
}
.donut-ring {
    width: 100%; height: 100%; border-radius: 50%;
    background: conic-gradient(#94a3b8 0% 100%); /* fallback, ditimpa lewat JS */
    transition: background .4s ease;
}
.donut-center {
    position: absolute; inset: 22px; background: #fff; border-radius: 50%;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    box-shadow: inset 0 0 0 1px #f1f5f9;
}
.donut-pct { font-size: 28px; font-weight: 800; color: #0f172a; line-height: 1.1; }
.donut-label { font-size: 11px; font-weight: 800; letter-spacing: .3px; color: #dc2626; margin-top: 2px; }
.donut-sub { font-size: 11px; color: #94a3b8; margin-top: 2px; }

.legend-row {
    display: flex; align-items: center; justify-content: space-between; gap: 10px;
    padding: 10px 0; border-bottom: 1px solid #f1f5f9; font-size: 13px; color: #334155; font-weight: 600;
}
.legend-row:last-of-type { border-bottom: none; }
.legend-row .legend-dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; margin-right: 8px; flex-shrink: 0; }
.legend-row .legend-name { display: flex; align-items: center; }
.legend-row .legend-count { color: #0f172a; }
.legend-row .legend-pct { font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 8px; margin-left: 8px; }
.legend-pct.green { background: #e8fbef; color: #16a34a; }
.legend-pct.red { background: #fdeceb; color: #dc2626; }

/* ---- Top 5 leaderboard table ---- */
.lb-total-badge {
    font-size: 12px; font-weight: 700; color: #1d4ed8; background: #eef4ff;
    border: 1px solid #dbe7fd; padding: 8px 14px; border-radius: 10px; white-space: nowrap;
}
.lb-table-wrap { overflow-x: auto; margin-top: 12px; }
table.lb-table { width: 100%; border-collapse: collapse; min-width: 520px; }
table.lb-table thead th {
    text-align: left; font-size: 10.5px; font-weight: 800; letter-spacing: .3px; color: #94a3b8;
    padding: 8px 10px; border-bottom: 1px solid #eef1f8; white-space: nowrap;
}
table.lb-table thead th.num, table.lb-table tbody td.num { text-align: right; }
table.lb-table tbody td { padding: 12px 10px; border-bottom: 1px solid #f6f8fc; font-size: 13px; vertical-align: middle; }
table.lb-table tbody tr:last-child td { border-bottom: none; }
.lb-rank {
    width: 26px; height: 26px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center;
    font-size: 12px; font-weight: 800; background: #f1f5f9; color: #64748b;
}
.lb-rank.gold { background: #fef3c7; color: #b45309; }
.lb-rank.silver { background: #e2e8f0; color: #475569; }
.lb-rank.bronze { background: #fee2c9; color: #b45309; }
.lb-device-code { font-weight: 700; color: #0f172a; }
.lb-device-loc { font-size: 11.5px; color: #94a3b8; margin-top: 1px; }
.lb-volume { font-weight: 700; color: #0f172a; }
.lb-status {
    display: inline-flex; align-items: center; gap: 6px; font-size: 10.5px; font-weight: 700;
    padding: 4px 9px; border-radius: 20px; background: #eafcf1; color: #15803d; white-space: nowrap;
}
.lb-status.offline { background: #fdeceb; color: #b91c1c; }
.lb-status .dot { width: 6px; height: 6px; border-radius: 50%; background: #22c55e; }
.lb-status.offline .dot { background: #ef4444; }
.lb-empty { text-align: center; padding: 24px; color: #94a3b8; font-size: 13px; }

.device-grid {
    padding: 24px 32px 0;
    display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px;
}
@media (max-width: 1100px) { .device-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 700px) { .device-grid { grid-template-columns: 1fr; padding-left: 18px; padding-right: 18px; } }

.device-card {
    background: #fff; border-radius: 16px; padding: 20px;
    box-shadow: 0 6px 18px rgba(30, 58, 138, 0.07);
    border: 1px solid #eef1f8;
}
.device-card.offline { border-color: #fbdada; background: #fffbfb; }

.device-top { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 6px; }
.device-code { font-size: 17px; font-weight: 700; color: #0f172a; }
.zone-badge {
    font-size: 10.5px; font-weight: 700; letter-spacing: .2px; color: #1d4ed8;
    background: #e8effe; padding: 3px 8px; border-radius: 6px;
}
.status-pill {
    margin-left: auto; display: inline-flex; align-items: center; gap: 6px;
    font-size: 11px; font-weight: 700; padding: 4px 10px; border-radius: 20px;
    background: #eafcf1; color: #15803d;
}
.status-pill .dot { width: 7px; height: 7px; border-radius: 50%; background: #22c55e; }
.status-pill.offline { background: #fdeceb; color: #b91c1c; }
.status-pill.offline .dot { background: #ef4444; }

.device-desc { font-size: 12.5px; color: #64748b; margin-bottom: 16px; min-height: 32px; }

.indicator-panel {
    display: flex; align-items: center; gap: 4px;
    background: #f8fafc; border-radius: 12px; padding: 16px 10px; margin-bottom: 16px;
}
.indicator { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center; }
.indicator-divider { width: 1px; align-self: stretch; background: #e6ebf5; }

/* Jarum berputar - dibuat senada dengan gauge "Live Data" di halaman detail alat */
.dial {
    width: 64px; height: 64px; border-radius: 50%; border: 5px solid #2563eb;
    display: flex; align-items: center; justify-content: center; position: relative;
    background: #fff;
}
.dial::after {
    content: ''; position: absolute; top: 50%; left: 50%; width: 9px; height: 9px;
    background: #2563eb; border-radius: 50%; transform: translate(-50%, -50%); z-index: 2;
}
.dial .needle {
    position: absolute; top: 50%; left: 50%; width: 4px; height: 20px; background: #2563eb;
    border-radius: 4px; transform-origin: top center; transform: translate(-50%, 0) rotate(0deg);
    animation: dial-spin 1.6s linear infinite;
}
.dial.stopped { border-color: #e2e8f0; background: #f8fafc; }
.dial.stopped::after { background: #94a3b8; }
.dial.stopped .needle { display: none; }
.dial.stopped .dial-dash { color: #94a3b8; font-size: 17px; font-weight: 700; }

/* Online tapi debit 0 (tidak ada aliran) -- pakai warna merah, sama seperti status offline. */
.dial.idle { border-color: #dc2626; }
.dial.idle::after { background: #dc2626; }
.dial.idle .needle {
    animation: none;
    transform: translate(-50%, 0) rotate(0deg);
    background: #dc2626;
}
@keyframes dial-spin {
    from { transform: translate(-50%, 0) rotate(0deg); }
    to   { transform: translate(-50%, 0) rotate(360deg); }
}

/* Broker/koneksi - lingkaran status online/offline (sama seperti gauge status di halaman detail) */
.sync-icon {
    width: 64px; height: 64px; border-radius: 50%; border: 5px solid #16a34a;
    display: flex; align-items: center; justify-content: center; background: #fff;
}
.sync-icon .sync-word { font-size: 11px; font-weight: 800; letter-spacing: .3px; color: #16a34a; }
.sync-icon.off { border-color: #dc2626; }
.sync-icon.off .sync-word { color: #dc2626; }

.indicator .ind-label { font-size: 12px; font-weight: 700; color: #334155; display: flex; align-items: center; gap: 6px; }
.indicator .ind-label .bullet { width: 6px; height: 6px; border-radius: 50%; background: #2563eb; flex-shrink: 0; }
.indicator .ind-label.bad .bullet { background: #dc2626; }
.indicator .ind-sub { font-size: 11px; color: #94a3b8; }
.indicator .ind-sub.bad { color: #dc2626; }

.device-bottom {
    display: flex; align-items: flex-end; justify-content: space-between; gap: 10px;
    border-top: 1px solid #f1f5f9; padding-top: 14px;
}
.device-bottom .vol-label { font-size: 10.5px; font-weight: 700; letter-spacing: .3px; color: #94a3b8; }
.device-bottom .vol-value { font-size: 21px; font-weight: 700; color: #0f172a; }
.device-bottom .vol-value .unit { font-size: 12px; font-weight: 600; color: #64748b; }

.card-action {
    display: inline-flex; align-items: center; gap: 5px; text-decoration: none;
    font-size: 13px; font-weight: 700; padding: 8px 14px; border-radius: 9px;
    background: #eaf1fe; color: #1d4ed8; white-space: nowrap;
}
.card-action:hover { background: #dbe7fd; }
.card-action.warn { background: #fdeceb; color: #b91c1c; }
.card-action.warn:hover { background: #fbdcdb; }
.card-action svg { width: 14px; height: 14px; }

/* ==================== KARTU KAMERA OCR (AI VISION) ==================== */
/* Border biru pembeda dari kartu MQTT biasa -- alat ini kerjanya beda
   (snapshot foto + angka OCR), bukan sensor debit kontinu. */
.device-card.ocr-card { border-color: #bfdbfe; }
.device-card.ocr-card.offline { border-color: #fbdada; background: #fffbfb; }

.ocr-unit-badge {
    display: inline-flex; align-items: center; gap: 6px;
    font-size: 10.5px; font-weight: 800; letter-spacing: .3px; color: #fff;
    background: #2563eb; padding: 4px 10px; border-radius: 999px;
    margin-bottom: 10px;
}
.ocr-unit-badge svg { width: 13px; height: 13px; }

.ocr-panel {
    display: flex; gap: 14px; align-items: stretch;
    background: #f8fafc; border-radius: 12px; padding: 14px; margin-bottom: 16px;
}

.raw-capture {
    position: relative; width: 96px; flex-shrink: 0;
    border-radius: 10px; overflow: hidden; background: #0f172a;
}
.raw-capture img { width: 100%; height: 96px; object-fit: cover; display: block; }
.raw-capture-empty {
    width: 100%; height: 96px; display: flex; align-items: center; justify-content: center;
    color: #64748b; font-size: 10.5px; text-align: center; padding: 8px;
}
.raw-capture-label {
    position: absolute; left: 0; right: 0; bottom: 0;
    font-size: 9px; font-weight: 800; letter-spacing: .3px; color: #fff;
    background: rgba(15, 23, 42, 0.72); text-align: center; padding: 3px 0;
}
.score-badge {
    position: absolute; top: 6px; right: 6px;
    font-size: 10px; font-weight: 800; color: #15803d; background: #eafcf1;
    padding: 2px 7px; border-radius: 999px;
}
.score-badge.low { color: #b45309; background: #fef3c7; }

.ocr-readout { flex: 1; min-width: 0; display: flex; flex-direction: column; justify-content: center; gap: 6px; }
.ocr-readout-label { font-size: 10.5px; font-weight: 700; letter-spacing: .3px; color: #94a3b8; }

/* Digit roll gaya odometer fisik: dasar gelap, angka putih monospace,
   bagian desimal (di belakang koma) disorot beda warna -- meniru tampilan
   "roll angka" di mockup, bukan literal roda digit animasi. */
.digit-roll {
    font-family: 'Courier New', monospace; font-weight: 800; font-size: 20px; letter-spacing: 1px;
    color: #f8fafc; background: #0f172a; border-radius: 8px; padding: 7px 10px;
    display: inline-flex; align-items: baseline; gap: 6px; width: fit-content; max-width: 100%;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.digit-roll-decimal { color: #fca5a5; }
.digit-roll-unit { font-size: 11px; font-weight: 700; color: #94a3b8; }

.ocr-meta-row {
    display: flex; align-items: center; justify-content: space-between; gap: 10px;
    font-size: 11px; color: #64748b;
}
.ocr-meta-item { display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ocr-meta-item .bullet { width: 6px; height: 6px; border-radius: 50%; background: #16a34a; flex-shrink: 0; }
.ocr-meta-item.bad { color: #dc2626; }
.ocr-meta-item.bad .bullet { background: #dc2626; }

.card-action.ghost { background: #f1f5f9; color: #334155; }
.card-action.ghost:hover { background: #e2e8f0; }

@media (max-width: 480px) {
    .ocr-panel { flex-direction: column; }
    .raw-capture { width: 100%; }
    .raw-capture img, .raw-capture-empty { height: 120px; }
}

/* ==================== PAGINATION ==================== */
.pagination-bar {
    margin: 24px 32px 0; background: #fff; border-radius: 14px; padding: 14px 20px;
    display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px;
    box-shadow: 0 4px 12px rgba(30, 58, 138, 0.05);
}
.pagination-bar .info { font-size: 12.5px; color: #64748b; }
.pagination-bar .pages { display: flex; gap: 6px; }
.page-btn {
    border: 1px solid #dbe3f0; background: #fff; color: #334155; font-size: 12.5px; font-weight: 600;
    padding: 8px 14px; border-radius: 8px; cursor: pointer;
}
.page-btn.active { background: #1d4ed8; border-color: #1d4ed8; color: #fff; }
.page-btn:disabled { opacity: .45; cursor: not-allowed; }

.empty-state {
    margin: 24px 32px 0; background: #fff; border-radius: 14px; padding: 48px 24px;
    text-align: center; color: #64748b; font-size: 14px;
}

/* ==================== FOOTER ==================== */
.page-footer {
    margin-top: 32px; padding: 18px 32px; border-top: 1px solid #dde5f3;
    display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 8px;
    font-size: 12px; color: #64748b;
}

/* ==================== MOBILE / ANDROID ==================== */
@media (max-width: 640px) {
    .topnav { padding: 14px 16px; gap: 14px; }
    .brand { width: 100%; }
    .brand .logo { width: 40px; height: 40px; }
    .brand h1 { font-size: 16px; }
    .brand .badge { display: none; }
    .brand .subtitle { font-size: 11px; }
    .nav-right { gap: 8px; }
    .tab-group { width: 100%; }
    .tab-btn { flex: 1; padding: 9px 6px; font-size: 12px; text-align: center; }
    .nav-link { flex: 1; justify-content: center; padding: 9px 10px; font-size: 12px; }

    .page-head { padding: 20px 16px 0; }
    .page-head h2 { font-size: 19px; }
    .page-head .sub { font-size: 12px; }
    .head-tools { width: 100%; }
    .search-box { min-width: 0; width: 100%; }
    .filter-btn { width: 100%; justify-content: center; }

    .stat-grid { padding: 16px 16px 0; grid-template-columns: 1fr; gap: 12px; }
    .stat-card { padding: 16px; }
    .stat-card .stat-value { font-size: 22px; }

    .insight-grid { padding: 16px 16px 0; gap: 12px; }
    .insight-card { padding: 18px; }
    /* Top 5 Pemakaian Air Terbanyak disembunyikan di tampilan Android/mobile */
    .insight-card.leaderboard-card { display: none; }

    .donut-outer { width: 160px; height: 160px; margin: 14px auto 16px; }
    .donut-pct { font-size: 24px; }

    .device-grid { padding: 18px 16px 0; grid-template-columns: 1fr; gap: 14px; }
    .device-card { padding: 16px; }
    .device-code { font-size: 15px; }
    .indicator-panel { padding: 12px 6px; }
    .dial, .sync-icon { width: 52px; height: 52px; border-width: 4px; }
    .device-bottom .vol-value { font-size: 18px; }
    .card-action { padding: 8px 12px; font-size: 12.5px; }

    .pagination-bar { margin: 18px 16px 0; padding: 12px 14px; flex-direction: column; align-items: stretch; }
    .pagination-bar .pages { justify-content: center; flex-wrap: wrap; }
    .pagination-bar .info { text-align: center; }

    .empty-state { margin: 18px 16px 0; }
    .page-footer { padding: 16px; flex-direction: column; align-items: flex-start; gap: 4px; }
}