/* ==========================================
   1. CẤU HÌNH CHUNG & RESET CSS
   ========================================== */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

body {
    background-color: #f0f2f5;
    color: #1a202c;
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ==========================================
   2. HEADER & THANH CẢNH BÁO TOÀN CỤC
   ========================================== */
.header {
    background: #1a365d;
    color: #ffffff;
    padding: 12px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: bold;
    font-size: 16px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    z-index: 100;
}

.demo-btn {
    background: #ed8936;
    color: white;
    border: none;
    padding: 8px 14px;
    font-weight: bold;
    border-radius: 6px;
    cursor: pointer;
    font-size: 12px;
    transition: background 0.2s, transform 0.1s;
}

.demo-btn:hover {
    background: #dd6b20;
    transform: translateY(-1px);
}

/* Ẩn hoàn toàn thanh cảnh báo đỏ, ghi đè mọi lệnh từ JavaScript */
#global-alert {
    display: none !important;
    height: 0 !important;
    padding: 0 !important;
    margin: 0 !important;
    border: none !important;
    opacity: 0 !important;
    position: absolute !important;
    top: 54px !important;
    left: 0;
    width: 100%;
    z-index: 2000;
}

.btn-mute {
    background: #ffffff;
    color: #e53e3e;
    border: none;
    padding: 4px 10px;
    font-weight: bold;
    font-size: 11px;
    border-radius: 4px;
    cursor: pointer;
    transition: 0.2s;
}

.btn-mute:hover {
    background: #ffe3e3;
}

.btn-mute.muted-active {
    background: #4a5568;
    color: #ffffff;
}

/* ==========================================
   3. BỐ CỤC CHÍNH (MAIN CONTAINER)
   ========================================== */
.main-container {
    display: flex;
    flex: 1;
    height: calc(100vh - 50px);
    position: relative;
}

/* ==========================================
   4. BẢN ĐỒ & CỤM CÔNG CỤ TRÊN BẢN ĐỒ
   ========================================== */
.map-wrapper {
    flex: 1;
    position: relative;
    height: 100%;
}

#map {
    width: 100%;
    height: 100%;
    z-index: 1;
}

/* Cụm công cụ chọn Lớp bản đồ & Bán kính */
.map-control-bar {
    position: absolute;
    top: 12px;
    left: 12px;
    z-index: 1000;
    display: flex;
    gap: 8px;
    align-items: center;
}

.map-layer-select {
    background: white;
    padding: 6px 12px;
    border-radius: 6px;
    border: 1px solid #cbd5e0;
    font-size: 12px;
    font-weight: bold;
    color: #2d3748;
    box-shadow: 0 2px 6px rgba(0,0,0,0.15);
    cursor: pointer;
    outline: none;
}

.map-toggle-btn {
    background: white;
    padding: 6px 12px;
    border-radius: 6px;
    border: 1px solid #cbd5e0;
    font-size: 12px;
    font-weight: bold;
    color: #2d3748;
    box-shadow: 0 2px 6px rgba(0,0,0,0.15);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    user-select: none;
}

.map-toggle-btn input {
    cursor: pointer;
}

/* Widget Thống kê phủ góc dưới Bản đồ */
.summary-overlay {
    position: absolute;
    bottom: 40px !important;
    left: 20px;
    z-index: 1001;
    background: rgba(255, 255, 255, 0.95);
    padding: 10px 16px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    display: flex;
    gap: 16px;
    backdrop-filter: blur(4px);
}

.stat-item {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.stat-title {
    font-size: 10px;
    font-weight: 800;
    color: #718096;
    text-transform: uppercase;
}

.stat-value {
    font-size: 18px;
    font-weight: 800;
    color: #2b6cb0;
}

.stat-warning { color: #d69e2e; }
.stat-danger { color: #e53e3e; }

/* Nâng logo Leaflet tránh khuất thanh thời tiết */
.leaflet-bottom {
    bottom: 35px !important;
}

/* ==========================================
   5. CUSTOM MAP MARKERS (LEAFLET)
   ========================================== */
.safe-marker {
    background-color: #38a169;
    border: 2px solid #ffffff;
    border-radius: 50%;
    box-shadow: 0 0 4px rgba(0,0,0,0.4);
}

.warning-marker {
    background-color: #d69e2e;
    border: 2px solid #ffffff;
    border-radius: 50%;
    box-shadow: 0 0 6px rgba(214, 158, 46, 0.8);
}

.pulse-marker {
    background-color: #e53e3e;
    border: 2px solid #ffffff;
    border-radius: 50%;
    box-shadow: 0 0 0 0 rgba(229, 62, 62, 0.7);
    animation: pulse-animation 1.2s infinite;
}

@keyframes pulse-animation {
    0% { box-shadow: 0 0 0 0 rgba(229, 62, 62, 0.8); }
    70% { box-shadow: 0 0 0 16px rgba(229, 62, 62, 0); }
    100% { box-shadow: 0 0 0 0 rgba(229, 62, 62, 0); }
}

/* ==========================================
   6. SIDEBAR & CÁC WIDGETS
   ========================================== */
.sidebar {
    width: 380px;
    background: #ffffff;
    border-left: 1px solid #e2e8f0;
    display: flex;
    flex-direction: column;
    padding: 14px;
    gap: 12px;
    overflow-y: auto;
}

.weather-widget {
    background: linear-gradient(135deg, #ebf8ff 0%, #bee3f8 100%);
    border: 1px solid #90cdf4;
    border-radius: 8px;
    padding: 10px 14px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.weather-info h4 { font-size: 13px; color: #2b6cb0; margin-bottom: 2px; }
.weather-info p { font-size: 11px; color: #4a5568; }
.weather-icon img { width: 42px; height: 42px; }

.chart-container {
    background: #f7fafc;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 10px;
}

.sidebar-header-tools {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.sidebar-header-tools h3 {
    font-size: 14px;
    color: #2d3748;
}

.btn-tool {
    background: #3182ce;
    color: white;
    border: none;
    padding: 5px 10px;
    font-size: 11px;
    font-weight: bold;
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-tool:hover { background: #2b6cb0; }

.filter-bar {
    display: flex;
    gap: 4px;
    background: #edf2f7;
    padding: 3px;
    border-radius: 6px;
}

.filter-btn {
    flex: 1;
    border: none;
    background: transparent;
    padding: 5px 0;
    font-size: 11px;
    font-weight: bold;
    color: #718096;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
}

.filter-btn.active {
    background: #ffffff;
    color: #2b6cb0;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

/* ==========================================
   7. STATION CARDS (THẺ QUAN TRẮC)
   ========================================== */
#station-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.station-card {
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-left: 5px solid #cbd5e0;
    border-radius: 6px;
    padding: 10px 12px;
    font-size: 12px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
    transition: transform 0.15s, box-shadow 0.15s;
}

.station-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.1);
}

.station-card.safe { border-left-color: #38a169; }
.station-card.warning { border-left-color: #dd6b20; background: #fffaf0; }
.station-card.danger { border-left-color: #e53e3e; background: #fff5f5; }

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
}

.card-header h4 { font-size: 13px; color: #2d3748; }

.pump-badge {
    border: none;
    font-size: 10px;
    font-weight: bold;
    padding: 4px 8px;
    border-radius: 12px;
    cursor: pointer;
    transition: transform 0.1s, opacity 0.2s;
}

.pump-badge:hover { opacity: 0.85; transform: scale(1.05); }
.pump-on { background: #fed7d7; color: #9b2c2c; }
.pump-off { background: #c6f6d5; color: #22543d; }

.ai-box { margin-top: 6px; padding: 6px 8px; border-radius: 4px; font-size: 11px; font-weight: 500; }
.ai-box.up { background: #feebc8; color: #7b341e; }
.ai-box.down { background: #e6fffa; color: #234e52; }
.ai-box.stable { background: #edf2f7; color: #4a5568; }

/* ==========================================
   8. TOAST NOTIFICATIONS & REPORT WIDGET
   ========================================== */
#toast-container {
    position: fixed;
    top: 65px;
    right: 20px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
}

.toast-item {
    pointer-events: auto;
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 280px;
    max-width: 380px;
    padding: 10px 14px;
    background: #ffffff;
    border-left: 5px solid #3182ce;
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    font-size: 12px;
    font-weight: bold;
    color: #2d3748;
    transform: translateX(120%);
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.toast-item.show { transform: translateX(0); }
.toast-item.toast-danger { border-left-color: #e53e3e; background: #fff5f5; }
.toast-item.toast-success { border-left-color: #38a169; background: #f0fff4; }
.toast-item.toast-info { border-left-color: #3182ce; background: #ebf8ff; }

.report-widget {
    background: #f7fafc;
    border: 1px solid #cbd5e0;
    border-radius: 8px;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.report-widget h4 { font-size: 13px; color: #1a365d; margin-bottom: 2px; }
.date-filter-group { display: flex; flex-direction: column; gap: 6px; }
.input-item { display: flex; justify-content: space-between; align-items: center; font-size: 11px; color: #4a5568; font-weight: 600; }
.input-item input[type="datetime-local"] { padding: 4px 6px; border: 1px solid #cbd5e0; border-radius: 4px; font-size: 11px; color: #2d3748; outline: none; }
.report-btn-group { display: flex; gap: 6px; margin-top: 4px; }
.report-btn-group .btn-tool { flex: 1; text-align: center; padding: 6px 0; }
.btn-csv { background: #2b6cb0; }
.btn-csv:hover { background: #2c5282; }
.btn-pdf { background: #dd6b20; }
.btn-pdf:hover { background: #c05621; }

/* ==========================================
   9. WIDGET CÔNG CỤ CHỈ ĐƯỜNG NÉ NGẬP
   ========================================== */
.routing-widget {
    background: #ffffff;
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 15px;
    box-shadow: 0 2px 6px rgba(0,0,0,0.06);
    border: 1px solid #e2e8f0;
}

.routing-widget h4 { margin: 0 0 10px 0; font-size: 13px; color: #1a365d; text-transform: uppercase; }
.route-input-group { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }
.input-with-btn { display: flex; gap: 6px; }
.input-with-btn input { flex: 1; padding: 6px 8px; font-size: 12px; border: 1px solid #cbd5e0; border-radius: 4px; background: #f7fafc; }

.btn-pick { background: #3182ce; color: white; border: none; padding: 6px 10px; border-radius: 4px; font-size: 11px; cursor: pointer; white-space: nowrap; transition: 0.2s; }
.btn-pick.picking-active { background: #dd6b20; font-weight: bold; animation: pulse 1s infinite alternate; }

.route-status-idle { background: #edf2f7; border-left: 4px solid #a0aec0; padding: 8px; font-size: 11px; color: #4a5568; border-radius: 0 4px 4px 0; }
.route-status-safe { background: #f0fff4; border-left: 4px solid #38a169; padding: 8px; font-size: 11px; color: #22543d; border-radius: 0 4px 4px 0; }
.route-status-danger { background: #fff5f5; border-left: 4px solid #e53e3e; padding: 8px; font-size: 11px; color: #742a2a; border-radius: 0 4px 4px 0; }

.btn-clear-route { width: 100%; margin-top: 8px; background: #e2e8f0; color: #4a5568; border: none; padding: 6px; border-radius: 4px; font-size: 11px; cursor: pointer; font-weight: 500; }
.btn-clear-route:hover { background: #cbd5e0; }

.leaflet-routing-container { display: none !important; }

/* ==========================================
   10. WEATHER TICKER (THỜI TIẾT CHẠY)
   ========================================== */
.weather-ticker-container {
    display: flex;
    align-items: center;
    background: #1a365d;
    color: #fff;
    padding: 6px 12px;
    font-size: 13px;
    font-weight: 500;
    overflow: hidden;
    border-top: 1px solid #2b6cb0;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.2);
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    z-index: 9999;
    box-sizing: border-box;
}

.ticker-label {
    background: #e53e3e;
    color: white;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: bold;
    margin-right: 10px;
    white-space: nowrap;
    animation: pulse-badge 2s infinite;
}

.ticker-wrapper { overflow: hidden; white-space: nowrap; width: 100%; }
.ticker-text { display: inline-block; padding-left: 100%; animation: ticker-scroll 35s linear infinite; }
.ticker-text:hover { animation-play-state: paused; }

@keyframes ticker-scroll {
    0% { transform: translate3d(0, 0, 0); }
    100% { transform: translate3d(-100%, 0, 0); }
}

@keyframes pulse-badge {
    0% { opacity: 1; }
    50% { opacity: 0.6; }
    100% { opacity: 1; }
}

/* ==========================================
   11. RESPONSIVE MOBILE
   ========================================== */
@media (max-width: 768px) {
    body { overflow-y: auto; height: auto; }
    .header { flex-direction: column; gap: 10px; text-align: center; }
    .main-container { flex-direction: column; height: auto; overflow: visible; }
    .map-wrapper { height: 380px; min-height: 320px; width: 100%; }
    
    #map, .map, #map-container, div[id*="map"] {
        width: 100% !important;
        height: 380px !important; 
        min-height: 380px !important;
        display: block !important;
        clear: both;
    }
    
    .sidebar { width: 100%; height: auto; border-left: none; border-top: 1px solid #e2e8f0; overflow-y: visible; }
    .map-control-bar { flex-wrap: wrap; top: 8px; left: 8px; right: 8px; }
    
    .summary-overlay {
        bottom: 50px !important; 
        left: 10px;
        right: 10px;
        padding: 6px 10px;
        justify-content: space-around;
        gap: 8px;
    }
    
    .stat-value { font-size: 15px; }
    .status-bar, .stat-container { clear: both; margin-top: 10px; }
}
/* =========================================================
 * HARDWARE HEALTH & ADMIN WATCHDOG STYLES
 * ========================================================= */

/* Huy hiệu Trạng thái Trạm (Status Badges) */
.health-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px 8px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
}

.health-badge.online {
    background-color: rgba(40, 167, 69, 0.15);
    color: #28a745;
    border: 1px solid #28a745;
}

.health-badge.warning {
    background-color: rgba(255, 193, 7, 0.15);
    color: #d39e00;
    border: 1px solid #ffc107;
}

.health-badge.faulty, .health-badge.offline {
    background-color: rgba(220, 53, 69, 0.15);
    color: #dc3545;
    border: 1px solid #dc3545;
    animation: pulse-danger-badge 1.5s infinite;
}

@keyframes pulse-danger-badge {
    0% { box-shadow: 0 0 0 0 rgba(220, 53, 69, 0.4); }
    70% { box-shadow: 0 0 0 6px rgba(220, 53, 69, 0); }
    100% { box-shadow: 0 0 0 0 rgba(220, 53, 69, 0); }
}

/* Widget Thống kê Sức khỏe Phần cứng (Admin Panel) */
.hardware-health-widget {
    background: #ffffff;
    border-radius: 10px;
    padding: 12px 16px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.08);
    margin-bottom: 15px;
}

.health-stat-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    margin-top: 8px;
    text-align: center;
}

.health-stat-item {
    padding: 8px 4px;
    border-radius: 6px;
    background: #f8f9fa;
}

.health-stat-item .val {
    font-size: 1.1rem;
    font-weight: 700;
}

.health-stat-item.online .val { color: #28a745; }
.health-stat-item.warning .val { color: #ffc107; }
.health-stat-item.faulty .val { color: #dc3545; }
.health-stat-item.offline .val { color: #6c757d; }

.health-stat-item .lbl {
    font-size: 0.7rem;
    color: #6c757d;
}

/* Marker trên bản đồ khi trạm hỏng */
.leaflet-marker-icon.station-offline {
    filter: grayscale(100%) opacity(0.7);
}

.leaflet-marker-icon.station-faulty {
    filter: drop-shadow(0 0 8px #dc3545);
}

/* =========================================================
   V4.0 - BẢN SAO SỐ LƯU VỰC & BẢNG ĐIỀU KHIỂN IOC
========================================================= */
.radar-blur-effect { filter: blur(5px); transition: fill-opacity 0.5s ease; pointer-events: none !important; }
.radar-dash-border { pointer-events: none !important; }
.ioc-widget { position: absolute; z-index: 1000; background: rgba(255, 255, 255, 0.95); backdrop-filter: blur(10px); border-radius: 8px; box-shadow: 0 4px 15px rgba(0,0,0,0.15); padding: 15px; font-family: 'Segoe UI', Arial, sans-serif; border: 1px solid #e2e8f0; pointer-events: auto; }
#ioc-eco-panel { bottom: 30px; left: 20px; min-width: 280px; border-left: 5px solid #3182ce; transition: all 0.3s ease; }
#ioc-slider-panel { top: 90px; right: 20px; width: 300px; border-top: 4px solid #805ad5; }
.ioc-title { margin: 0 0 10px 0; font-size: 14px; color: #2d3748; text-transform: uppercase; font-weight: 800; display:flex; justify-content:space-between;}
.ioc-stat-row { display: flex; justify-content: space-between; margin-bottom: 5px; font-size: 13px; color: #4a5568;}
.ioc-value { font-weight: bold; font-size: 15px; }
.eco-danger { color: #e53e3e; } .eco-warning { color: #dd6b20; } .eco-safe { color: #38a169; }
input[type=range].ioc-slider { width: 100%; cursor: pointer; margin: 10px 0; }