/* ========================================================= */
/* ==================== LOADER STYLES ==================== */
/* ========================================================= */
.loader-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(255, 255, 255, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    transition: opacity 0.3s ease;
    opacity: 1; /* 默认可见 */
}

.loader-overlay.hidden {
    opacity: 0;
    pointer-events: none; /* 隐藏时不可点击 */
}

.spinner {
    width: 50px;
    height: 50px;
    border: 5px solid #f3f3f3; /* 浅灰色背景 */
    border-top: 5px solid #3b71ca; /* 主题色 */
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}


:root {
    --status-normal: #28a745;
    --status-warning: #ffc107;
    --status-error: #dc3545;
    --primary-color: #3b71ca;
    --secondary-color: #6c757d;
    --tunnel-bg: #e9ecef;
    --south-bound: #4e73df;
    --north-bound: #1cc88a;
}
body {
    background-color: #f8f9fa;
    padding-bottom: 70px;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}
.status-normal { color: var(--status-normal); }
.status-warning { color: var(--status-warning); }
.status-error { color: var(--status-error); }
.stats-error { background-color: rgba(220, 53, 69, 0.1); }

.device-card {
    transition: all 0.3s ease;
    border-left: 4px solid var(--status-normal);
    position: relative;
    z-index: 1;
}
.device-card.warning { border-left-color: var(--status-warning); }
.device-card.error { border-left-color: var(--status-error); }

.device-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 5px 15px rgba(0,0,0,0.1);
    z-index: 2;
}

.device-card .dropdown-menu {
    z-index: 3;
}
.status-normal-item {
    color: var(--status-normal) !important;
}
.status-normal-item:hover {
    background-color: var(--status-normal) !important;
    color: white !important;
}

.status-warning-item {
    color: #664d03 !important;
}
.status-warning-item:hover {
    background-color: var(--status-warning) !important;
    color: black !important;
}

.status-error-item {
    color: var(--status-error) !important;
}
.status-error-item:hover {
    background-color: var(--status-error) !important;
    color: white !important;
}


.navbar-brand { font-weight: bold; }
/* ========================================================= */
/* ============== FIX FOR NAVBAR DROPDOWN MENU ============== */
/* This rule ensures the user dropdown menu floats correctly */
/* and is not contained within the navbar's layout flow. */
/* ========================================================= */
.navbar .dropdown .dropdown-menu {
    position: absolute !important; 
}


.section-title {
    border-left: 4px solid var(--primary-color);
    padding-left: 10px;
    margin: 20px 0;
}
.stats-card {
    text-align: center;
    padding: 15px;
    border-radius: 8px;
    margin-bottom: 20px;
}
.stats-normal { background-color: rgba(40, 167, 69, 0.1); }
.stats-warning { background-color: rgba(255, 193, 7, 0.1); }
.stats-error { background-color: rgba(220, 53, 69, 0.1); }
.badge { font-weight: 500; }
.mobile-bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 1000;
    background: white;
    box-shadow: 0 -2px 10px rgba(0,0,0,0.1);
    display: flex;
    justify-content: space-around;
    padding: 10px 0;
}
.mobile-bottom-nav .nav-item {
    text-align: center;
    font-size: 12px;
    color: var(--secondary-color);
    cursor: pointer;
    flex: 1;
}
.mobile-bottom-nav .nav-item.active { color: var(--primary-color); }
.mobile-bottom-nav .nav-item i {
    display: block;
    font-size: 20px;
    margin-bottom: 5px;
}
.camera-preview {
    width: 100%;
    height: 300px;
    background-color: #f0f0f0;
    margin-bottom: 15px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
}
.camera-preview video, .camera-preview canvas {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 8px;
}
.photo-preview {
    width: 100%;
    max-height: 200px;
    object-fit: contain;
    border-radius: 8px;
    margin-top: 10px;
    border: 1px solid #ddd;
}
.tunnel-map-container {
    overflow-x: auto;
    margin-bottom: 20px;
    background: white;
    border-radius: 8px;
    padding: 15px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.05);
}
.tunnel-map {
    min-width: 800px;
    height: 300px;
    background-color: var(--tunnel-bg);
    border-radius: 8px;
    position: relative;
    margin: 20px 0;
    display: flex;
}
.tunnel-section {
    flex: 1;
    position: relative;
    border-right: 2px dashed #ccc;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}
.tunnel-section:last-child { border-right: none; }
.tunnel-section-label {
    position: absolute;
    top: 10px;
    left: 0;
    right: 0;
    text-align: center;
    font-weight: bold;
    color: var(--secondary-color);
}
.device-marker {
    position: absolute;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 16px;
    cursor: pointer;
    transform: translate(-50%, -50%);
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
    transition: all 0.3s ease;
}
.device-marker:hover {
    transform: translate(-50%, -50%) scale(1.1);
    z-index: 10;
}
.device-marker.normal { background-color: var(--status-normal); }
.device-marker.warning { background-color: var(--status-warning); }
.device-marker.error { background-color: var(--status-error); }
.map-controls {
    display: flex;
    gap: 10px;
    margin-bottom: 15px;
    flex-wrap: wrap;
}
.map-controls .btn-group { flex: 1; }
.device-type-filter {
    display: flex;
    gap: 5px;
    flex-wrap: wrap;
    position: relative;
}
.device-icon {
    font-size: 20px;
    margin-right: 8px;
}
.pile-number {
    position: absolute;
    bottom: 5px;
    left: 0;
    right: 0;
    text-align: center;
    font-size: 12px;
    color: var(--secondary-color);
}
.direction-badge {
    position: absolute;
    top: 5px;
    right: 5px;
    font-size: 12px;
}
.south-bound {
    background-color: rgba(78, 115, 223, 0.1);
    border-left: 3px solid var(--south-bound);
}
.north-bound {
    background-color: rgba(28, 200, 138, 0.1);
    border-left: 3px solid var(--north-bound);
}
.form-label { font-weight: 500; }

#deviceTypeFilter .dropdown { position: relative; display: inline-block; }
#deviceTypeFilter .dropdown-content {
    display: none;
    position: absolute;
    background-color: #f9f9f9;
    min-width: 200px;
    box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
    padding: 12px 16px;
    z-index: 1000;
    border-radius: 5px;
    max-height: 300px;
    overflow-y: auto;
}
#deviceTypeFilter .dropdown:hover .dropdown-content { display: block; }
#deviceTypeFilter .dropdown-item {
    display: flex;
    align-items: center;
    padding: 5px 0;
    cursor: pointer;
}
#deviceTypeFilter .dropdown-item input { margin-right: 8px; }
#deviceTypeFilter .dropdown-header {
    font-weight: bold;
    margin-bottom: 10px;
    padding-bottom: 5px;
    border-bottom: 1px solid #ddd;
}
#deviceTypeFilter .dropdown-actions {
    display: flex;
    justify-content: space-between;
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid #ddd;
}

.table-hover tbody tr:hover {
    background-color: #f5f5f5;
    cursor: pointer;
}

.status-badge {
    padding: 0.35em 0.65em;
    font-size: .75em;
    font-weight: 700;
    line-height: 1;
    color: #fff;
    text-align: center;
    white-space: nowrap;
    vertical-align: baseline;
    border-radius: 0.25rem;
}
.status-badge.resolved {
    background-color: var(--status-normal);
}
.status-badge.active {
    background-color: var(--status-error);
}

#statsView .card-header {
    background-color: rgba(0,0,0,.03);
    border-bottom: 1px solid rgba(0,0,0,.125);
}

#statsView .card-title {
    font-size: 1.1rem;
    font-weight: 500;
}

.qr-placeholder-small {
    width: 40px;
    height: 40px;
    background-color: #f0f0f0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #ccc;
    border-radius: .25rem;
    border: 1px solid #dee2e6;
}

#itemListContainer .list-group-item .btn {
    margin-left: 4px; 
}

.qr-browser-container {
    display: flex;
    flex-direction: column;
    min-height: 500px;
    justify-content: center;
    padding: 1rem;
}
.qr-browser-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    color: #6c757d;
    flex-grow: 1;
}
#qrBrowserBody {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100%;
    flex-grow: 1;
}
.qr-browser-header {
    text-align: center;
    padding: 1rem;
    border-bottom: 1px solid #eee;
}
.qr-browser-header h5 {
    margin-bottom: 0.25rem;
}
.qr-browser-header p {
    margin-bottom: 0;
}
.qr-browser-main {
    flex-grow: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
    min-height: 300px;
}
.qr-browser-main img {
    max-width: 100%;
    max-height: 300px;
    height: auto;
    object-fit: contain;
    border: 1px solid #ddd;
    border-radius: 8px;
    padding: 5px;
    background: white;
}
.qr-browser-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    border-top: 1px solid #eee;
}
.qr-browser-footer .btn {
    min-width: 100px;
}

.firebox-nav-list {
    list-style: none;
    padding-left: 0;
    max-height: 300px;
    overflow-y: auto;
    border: 1px solid #eee;
    border-radius: .25rem;
}
.firebox-nav-list .direction-header {
    font-weight: bold;
    padding: 8px 12px;
    background-color: #f8f9fa;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #eee;
}
.firebox-nav-list .direction-header .toggle-icon {
    transition: transform 0.2s ease-in-out;
}
.firebox-nav-list .direction-header.collapsed .toggle-icon {
    transform: rotate(-90deg);
}

.firebox-nav-list .firebox-items {
    list-style: none;
    padding-left: 0;
    margin: 0;
}

.firebox-nav-list .firebox-items.collapsed {
    display: none;
}

.firebox-nav-list .firebox-item {
    padding: 6px 12px 6px 24px;
    font-size: 0.9em;
    cursor: pointer;
    border-bottom: 1px solid #f0f0f0;
}
.firebox-nav-list .firebox-item:last-child {
    border-bottom: none;
}
.firebox-nav-list .firebox-item:hover {
    background-color: #e9ecef;
}
.firebox-nav-list .firebox-item.active {
    background-color: var(--primary-color);
    color: white;
    font-weight: 500;
}

/* ============================================= */
/* ============= MOBILE OPTIMIZATIONS ============ */
/* ============================================= */
@media (max-width: 768px) {
    /* --- General Layout --- */
    html {
        font-size: 14px;
    }
    body {
        padding-bottom: 80px; /* More space for the bottom nav */
    }
    .container, .container-fluid {
        padding-left: 10px;
        padding-right: 10px;
    }
    #main-container {
        margin-top: 1rem !important;
    }

    /* --- Titles and Actions --- */
    .section-title {
        font-size: 1.4rem;
        margin-bottom: 1rem;
    }
    .device-list-actions {
        width: 100%;
        gap: 0.5rem;
    }
    .device-list-actions .btn {
        flex-grow: 1; /* Make buttons fill the space */
        font-size: 0.9rem;
    }

    /* --- Stats Cards --- */
    #listView .row:first-of-type .stats-card {
        padding: 0.5rem;
        margin-bottom: 10px;
        border-radius: 4px;
    }
    #listView .row:first-of-type .stats-card h4 {
        font-size: 0.65rem;
        margin-bottom: 2px;
    }
    #listView .row:first-of-type .stats-card h4 i {
        display: none; /* Hide icon to save space */
    }
    #listView .row:first-of-type .stats-card h2 {
        font-size: 1.3rem;
    }

    /* --- Filter Panel --- */
    #filterPanel .card-body {
        padding: 1rem;
    }
    #filterPanel .row > [class*="col-"] {
        width: 100%; /* Force all columns to stack */
        margin-bottom: 0.75rem;
    }
    #filterPanel .row .btn {
        width: 100%; /* Make clear button full-width */
    }

    /* --- Device Cards --- */
    .device-card {
        font-size: 0.85rem;
    }
    .device-card .card-body {
        padding: 0.75rem;
    }
    .device-card .card-title {
        font-size: 1rem;
    }
    .device-card .card-text {
        font-size: 0.8rem;
        margin-bottom: 0.25rem;
    }
    .device-card .card-body p {
        margin-bottom: 0.3rem;
    }
    .device-card .card-footer {
        padding: 0.5rem 0.75rem;
        display: flex;
        gap: 0.5rem;
    }
    .device-card .card-footer .btn {
        flex-grow: 1; /* Make footer buttons take equal width */
    }

    /* --- Map View --- */
    .tunnel-map {
        height: 250px;
    }
    .map-controls {
        flex-direction: column;
    }
    #deviceTypeFilter .dropdown-content {
        position: fixed;
        left: 50%;
        top: 50%;
        transform: translate(-50%, -50%);
        width: 80%;
        max-width: 300px;
    }

    /* --- QR View --- */
    #qrView .row {
        flex-direction: column;
    }
    #qrView .row > [class*="col-"] {
        width: 100%;
        margin-bottom: 1rem;
    }

    /* --- Modals --- */
    .modal-dialog {
        margin: 0.5rem; /* Give more screen real estate */
    }
    .modal-content {
        font-size: 0.95rem;
    }
    .modal-footer {
        flex-direction: column-reverse; /* Put primary action on bottom (easier to reach) */
        gap: 0.5rem;
        padding: 0.75rem;
    }
    .modal-footer .btn {
        width: 100%;
        margin: 0;
    }

    /* --- Fault Log Table --- */
    #faultLogView .table thead { display: none; }
    #faultLogView .table, #faultLogView .table tbody, #faultLogView .table tr, #faultLogView .table td {
        display: block;
        width: 100%;
    }
    #faultLogView .table tr {
        margin-bottom: 0.75rem;
        border: 1px solid #dee2e6;
        border-radius: .375rem;
        background-color: #fff;
    }
    #faultLogView .table td {
        text-align: right;
        position: relative;
        padding: .5rem .75rem;
        padding-left: 50%;
        border: none;
        border-bottom: 1px solid #f0f0f0;
    }
    #faultLogView .table tr td:last-child { border-bottom: none; }
    #faultLogView .table td::before {
        content: attr(data-label);
        position: absolute;
        left: .75rem;
        width: calc(50% - 1.5rem);
        padding-right: 10px;
        text-align: left;
        font-weight: 500;
        white-space: nowrap;
        color: #6c757d;
    }

    /* --- Hide Desktop Navbar Items --- */
    .navbar-collapse .navbar-nav .nav-item:not(.dropdown) {
        display: none;
    }
}