:root {
    --bg-body: #f1f5f9;
    /* Light Gray Background */
    --bg-panel: #ffffff;
    /* White Panels */
    --text-primary: #0f172a;
    /* Dark Text */
    --text-secondary: #64748b;
    /* Muted Text */
    --accent-red: #ef4444;
    --accent-green: #10b981;
    --accent-blue: #3b82f6;
    --border-color: #cbd5e1;
    /* Light Border */
    --hover-bg: #f8fafc;
}

body {
    margin: 0;
    padding: 0;
    font-family: 'Kanit', sans-serif;
    background-color: var(--bg-body);
    color: var(--text-primary);
    overflow: hidden;
}

/* Layout: Top Bar + Flex Body */
.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
}

/* 1. Top Bar - Navy Theme */
.top-bar {
    height: 60px;
    background: #1e3a8a;
    /* Navy Blue */
    border-bottom: 1px solid #1e40af;
    display: flex;
    align-items: center;
    padding: 0 20px;
    justify-content: space-between;
    z-index: 100;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    color: white;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    color: white;
}

.brand h2 {
    margin: 0;
    font-size: 20px;
    font-weight: 700;
    letter-spacing: 0.5px;
}

.top-menu {
    display: flex;
    gap: 20px;
    margin-left: 40px;
    margin-right: auto;
}

.menu-item {
    color: rgba(255, 255, 255, 0.7);
    text-decoration: none;
    font-weight: 500;
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border-radius: 6px;
    transition: all 0.2s;
}

.menu-item:hover,
.menu-item.active {
    color: white;
    background: rgba(255, 255, 255, 0.15);
}

.top-stats {
    display: flex;
    gap: 15px;
    margin-right: 20px;
}

.stat-pill {
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(0, 0, 0, 0.2);
    padding: 5px 12px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 500;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.stat-value {
    font-weight: 700;
    color: white;
}

.stat-label {
    color: rgba(255, 255, 255, 0.8);
}

.stat-value.danger {
    color: #fca5a5;
}

/* Light Red for Dark bg */
.stat-value.success {
    color: #86efac;
}

/* Light Green for Dark bg */

.user-controls {
    display: flex;
    align-items: center;
    gap: 15px;
    border-left: 1px solid rgba(255, 255, 255, 0.2);
    padding-left: 20px;
}

.icon-btn {
    background: none;
    border: none;
    font-size: 18px;
    color: rgba(255, 255, 255, 0.8);
    cursor: pointer;
}

.icon-btn:hover,
.icon-btn.active {
    color: white;
}

.user-profile {
    font-size: 14px;
    color: white;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}

.logout-btn {
    color: #fca5a5;
    font-size: 16px;
    cursor: pointer;
    opacity: 0.8;
}

.logout-btn:hover {
    opacity: 1;
}

/* 2. Main Body */
.main-body {
    display: flex;
    flex: 1;
    overflow: hidden;
    background-color: #f1f5f9;
}

/* Sidebar (Restyled) */
.sidebar {
    width: 320px;
    background: white;
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    z-index: 90;
}

.sidebar-search-area {
    padding: 15px;
    border-bottom: 1px solid var(--border-color);
    background: #fafafa;
}

.search-box {
    position: relative;
    margin-bottom: 10px;
}

.search-box input {
    width: 100%;
    padding: 10px 10px 10px 35px;
    border-radius: 6px;
    border: 1px solid var(--border-color);
    font-size: 14px;
}

.search-box i {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-secondary);
}

.filter-chips {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 2px;
}

.chip {
    border: 1px solid var(--border-color);
    background: white;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 12px;
    cursor: pointer;
    color: var(--text-secondary);
    white-space: nowrap;
}

.chip.active {
    background: var(--accent-blue);
    color: white;
    border-color: var(--accent-blue);
}

.device-list {
    flex: 1;
    overflow-y: auto;
    padding: 10px;
}

/* Map Wrapper */
.map-wrapper {
    flex: 1;
    position: relative;
    height: 100%;
}

#map {
    width: 100%;
    height: 100%;
}

/* Sidebar Components */
.sidebar-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 20px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border-color);
}

.logo-icon {
    font-size: 24px;
    color: var(--accent-red);
    animation: pulse 2s infinite;
}

.stats-panel {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    /* Specific gap */
    margin-bottom: 10px;
    /* Reduced margin */
}

.stat-card {
    background: white;
    padding: 10px;
    /* Reduced padding */
    border-radius: 10px;
    text-align: center;
    display: flex;
    flex-direction: column;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    border: 1px solid var(--border-color);
}

.stat-card.danger {
    border-top: 3px solid var(--accent-red);
    color: var(--accent-red);
}

.stat-card.success {
    border-top: 3px solid var(--accent-green);
    color: var(--accent-green);
}

.stat-value {
    font-size: 20px;
    font-weight: bold;
    color: var(--text-primary);
    line-height: 1.2;
}

.stat-label {
    font-size: 12px;
    color: var(--text-secondary);
}

.incident-list-container,
.device-list-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    margin-bottom: 10px;
}

h3 {
    font-size: 16px;
    margin-bottom: 10px;
    color: var(--text-primary);
    font-weight: 600;
}

.incident-list,
.device-list {
    flex: 1;
    overflow-y: auto;
    padding-right: 5px;
}

/* Item Cards */
.card-item {
    background: white;
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 10px;
    border: 1px solid var(--border-color);
    border-left: 4px solid transparent;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.card-item:hover {
    background: var(--hover-bg);
    transform: translateY(-1px);
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
}

.card-item.sos {
    border-left-color: var(--accent-red);
    background: #fef2f2;
    /* Light Red tint */
    border-color: #fee2e2;
}

.card-item.online {
    border-left-color: var(--accent-green);
}

.card-item.offline {
    border-left-color: var(--text-secondary);
    opacity: 0.7;
    bg: #f8fafc;
}

.card-header {
    display: flex;
    justify-content: space-between;
    font-weight: 600;
    margin-bottom: 5px;
    color: var(--text-primary);
}

.card-details {
    font-size: 12px;
    color: var(--text-secondary);
}

.blink-red {
    animation: blink 1s infinite alternate;
    color: var(--accent-red);
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    z-index: 2000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    /* Semi-transparent backdrop */
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(2px);
}

.modal-content {
    background-color: var(--bg-panel);
    padding: 24px;
    border-radius: 16px;
    width: 90%;
    max-width: 500px;
    position: relative;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
    border: 1px solid var(--border-color);
}

.close-modal {
    position: absolute;
    right: 20px;
    top: 15px;
    font-size: 24px;
    font-weight: bold;
    cursor: pointer;
    color: var(--text-secondary);
}

.close-modal:hover {
    color: var(--text-primary);
}

.btn-resolve {
    background: var(--accent-green);
    color: white;
    border: none;
    padding: 12px 20px;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    width: 100%;
    margin-top: 20px;
    box-shadow: 0 2px 4px rgba(16, 185, 129, 0.2);
    transition: background 0.2s;
}

.btn-resolve:hover {
    background: #059669;
}

/* Utilities */
.status-badge {
    padding: 3px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: bold;
}

.badge-sos {
    background: #fee2e2;
    color: #dc2626;
    border: 1px solid #fecaca;
}

.badge-online {
    background: #d1fae5;
    color: #059669;
    border: 1px solid #a7f3d0;
}

/* Animations */
@keyframes pulse {
    0% {
        transform: scale(1);
        opacity: 1;
    }

    50% {
        transform: scale(1.1);
        opacity: 0.8;
    }

    100% {
        transform: scale(1);
        opacity: 1;
    }
}

@keyframes blink {
    from {
        opacity: 1;
    }

    to {
        opacity: 0.5;
    }
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

/* Map Overlay */
.map-overlay-info {
    position: absolute;
    bottom: 20px;
    left: 20px;
    background: rgba(255, 255, 255, 0.9);
    padding: 6px 12px;
    border-radius: 6px;
    z-index: 1001;
    font-size: 12px;
    pointer-events: none;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    color: var(--text-secondary);
    font-weight: 500;
}

/* ... existing styles ... */

.chip {
    background: white;
    border: 1px solid var(--border-color);
    padding: 4px 10px;
    border-radius: 15px;
    font-size: 12px;
    cursor: pointer;
    color: var(--text-secondary);
    white-space: nowrap;
    transition: all 0.2s;
}

.chip:hover {
    background: var(--hover-bg);
    color: var(--text-primary);
}

.chip.active {
    background: var(--accent-blue);
    color: white;
    border-color: var(--accent-blue);
}

::-webkit-scrollbar {
    width: 4px;
}

/* Slimmer scrollbar for sidebar */