* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background-color: #f5f5f5;
    color: #333;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

#login-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
}

.login-box {
    background: white;
    padding: 40px;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    width: 100%;
    max-width: 400px;
}

.login-box h1 {
    color: #2c3e50;
    margin-bottom: 10px;
    text-align: center;
}

.subtitle {
    text-align: center;
    color: #7f8c8d;
    margin-bottom: 20px;
    font-size: 14px;
}

.login-tabs {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
}

.tab-btn {
    flex: 1;
    padding: 10px;
    background-color: #ecf0f1;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: background-color 0.3s;
}

.tab-btn:hover {
    background-color: #d5dbdb;
}

.tab-btn.active {
    background-color: #3498db;
    color: white;
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

.help-text {
    font-size: 12px;
    color: #7f8c8d;
    margin-top: 5px;
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 5px;
    color: #555;
    font-weight: 500;
}

.form-group input {
    width: 100%;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
}

.form-group input:focus {
    outline: none;
    border-color: #3498db;
}

.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: background-color 0.3s;
}

.btn-primary {
    background-color: #3498db;
    color: white;
    width: 100%;
}

.btn-primary:hover {
    background-color: #2980b9;
}

.btn-secondary {
    background-color: #95a5a6;
    color: white;
}

.btn-secondary:hover {
    background-color: #7f8c8d;
}

.btn-success {
    background-color: #27ae60;
    color: white;
}

.btn-success:hover {
    background-color: #219a52;
}

.btn-warning {
    background-color: #f39c12;
    color: white;
}

.btn-warning:hover {
    background-color: #d68910;
}

.btn-danger {
    background-color: #e74c3c;
    color: white;
}

.btn-danger:hover {
    background-color: #c0392b;
}

.error-message {
    color: #e74c3c;
    font-size: 14px;
    margin-top: 10px;
    text-align: center;
}

.navbar {
    background-color: #2c3e50;
    color: white;
    padding: 15px 30px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.navbar-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.navbar-brand {
    font-size: 20px;
    font-weight: bold;
}

.navbar-user {
    display: flex;
    align-items: center;
    gap: 15px;
}

.badge {
    background-color: #3498db;
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 500;
}

.main-content {
    display: flex;
    min-height: calc(100vh - 60px);
}

.sidebar {
    width: 250px;
    background-color: white;
    border-right: 1px solid #ddd;
    padding: 10px 0;
    overflow-y: auto;
}

.sidebar ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.sidebar > ul > li {
    padding: 12px 20px;
    cursor: pointer;
    transition: background-color 0.3s;
}

.sidebar > ul > li:hover {
    background-color: #ecf0f1;
}

.sidebar > ul > li.active {
    background-color: #3498db;
    color: white;
}

/* Category headers */
.sidebar .menu-category-header {
    padding: 10px 16px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #7f8c8d;
    background-color: #f8f9fa;
    border-top: 1px solid #ecf0f1;
    border-bottom: 1px solid #ecf0f1;
    cursor: pointer;
    display: flex;
    align-items: center;
    user-select: none;
    transition: background-color 0.2s;
    margin-top: 4px;
}

.sidebar .menu-category-header:first-child {
    margin-top: 0;
    border-top: none;
}

.sidebar .menu-category-header:hover {
    background-color: #ecf0f1;
    color: #2c3e50;
}

.sidebar .menu-category-header.collapsed {
    border-bottom-color: transparent;
}

.sidebar .menu-category-icon {
    margin-right: 6px;
    font-size: 13px;
}

.sidebar .menu-category-arrow {
    margin-left: auto;
    font-size: 9px;
    transition: transform 0.2s;
    color: #bdc3c7;
}

/* Category sub-items */
.sidebar .menu-category-items {
    list-style: none;
    overflow: hidden;
    max-height: 600px;
    transition: max-height 0.3s ease, opacity 0.2s ease;
    opacity: 1;
}

.sidebar .menu-category-items.collapsed {
    max-height: 0;
    opacity: 0;
}

.sidebar .menu-category-items li {
    padding: 10px 20px 10px 36px;
    cursor: pointer;
    font-size: 13px;
    color: #34495e;
    transition: background-color 0.2s, color 0.2s;
    border-left: 3px solid transparent;
}

.sidebar .menu-category-items li:hover {
    background-color: #ecf0f1;
    border-left-color: #3498db;
}

.sidebar .menu-category-items li.active {
    background-color: #3498db;
    color: white;
    border-left-color: #2980b9;
}

.content {
    flex: 1;
    padding: 30px;
    overflow-y: auto;
}

.dashboard-header {
    margin-bottom: 30px;
}

.dashboard-header h2 {
    color: #2c3e50;
    margin-bottom: 10px;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.stat-card {
    background: white;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.stat-card h3 {
    color: #7f8c8d;
    font-size: 14px;
    font-weight: normal;
    margin-bottom: 10px;
}

.stat-card .value {
    font-size: 32px;
    font-weight: bold;
    color: #2c3e50;
}

.card {
    background: white;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    margin-bottom: 20px;
}

.card h3 {
    color: #2c3e50;
    margin-bottom: 15px;
}

.table {
    width: 100%;
    border-collapse: collapse;
}

.table th,
.table td {
    padding: 12px;
    text-align: left;
    border-bottom: 1px solid #ddd;
}

.table th {
    background-color: #f8f9fa;
    font-weight: 600;
    color: #555;
}

.status-badge {
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 500;
}

.status-active {
    background-color: #d4edda;
    color: #155724;
}

.status-inactive {
    background-color: #f8d7da;
    color: #721c24;
}

.status-warning {
    background-color: #fff3cd;
    color: #856404;
}

.severity-critical {
    background-color: #f8d7da;
    color: #721c24;
}

.severity-high {
    background-color: #fff3cd;
    color: #856404;
}

.severity-medium {
    background-color: #d1ecf1;
    color: #0c5460;
}

.severity-low {
    background-color: #d4edda;
    color: #155724;
}

.loading {
    text-align: center;
    padding: 40px;
    color: #7f8c8d;
}

.empty-state {
    text-align: center;
    padding: 40px;
    color: #7f8c8d;
}

.map-container {
    height: 600px;
    background-color: #ecf0f1;
    border-radius: 8px;
    position: relative;
    z-index: 1;
}

#worksite-map {
    width: 100%;
    height: 100%;
    border-radius: 8px;
}

.map-legend {
    margin-top: 20px;
    padding: 15px;
    background-color: #f8f9fa;
    border-radius: 4px;
}

.map-legend h4 {
    color: #2c3e50;
    font-size: 14px;
    margin-bottom: 10px;
}

.legend-item {
    display: flex;
    align-items: center;
    margin-bottom: 8px;
    font-size: 13px;
    color: #555;
}

.legend-marker {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    margin-right: 8px;
    display: inline-block;
}

.legend-marker.worksite {
    background-color: #e74c3c;
    border: 2px solid #c0392b;
}

.legend-marker.personnel {
    background-color: #2196F3;
    border: 2px solid #1976D2;
}

.legend-marker.device {
    background-color: #4CAF50;
    border: 2px solid #388E3C;
}

.legend-marker.asset {
    background-color: #FF9800;
    border: 2px solid #F57C00;
}

.legend-marker.worker {
    background-color: #2196F3;
    border: 2px solid #1976D2;
}

.legend-marker.perimeter {
    background-color: transparent;
    border: 2px solid #ff7800;
}

.legend-marker.weather {
    background-color: #3498db;
    border: 2px solid #2980b9;
}

/* Weather markers on map */
.weather-marker,
.weather-marker-mini {
    background: transparent !important;
    border: none !important;
}

/* Weather alert banner */
#weather-alert-banner {
    margin-bottom: 10px;
}

#weather-alert-banner > div {
    animation: weatherAlertFadeIn 0.3s ease-in;
}

@keyframes weatherAlertFadeIn {
    from { opacity: 0; transform: translateY(-5px); }
    to { opacity: 1; transform: translateY(0); }
}

.custom-marker {
    background-color: transparent;
    border: none;
}

.custom-marker .marker-pin {
    width: 0;
    height: 0;
    border-left: 8px solid transparent;
    border-right: 8px solid transparent;
    position: relative;
}

.worksite-marker .marker-pin {
    border-bottom: 24px solid #e74c3c;
}

.worksite-marker .marker-pin::before {
    content: '';
    position: absolute;
    width: 12px;
    height: 12px;
    background-color: #e74c3c;
    border-radius: 50%;
    top: 24px;
    left: -6px;
    border: 2px solid white;
}

.worksite-marker .marker-label {
    position: absolute;
    top: -20px;
    left: 50%;
    transform: translateX(-50%);
    background-color: white;
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 11px;
    font-weight: bold;
    color: #e74c3c;
    white-space: nowrap;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.personnel-marker .marker-pin,
.worker-marker .marker-pin {
    border-bottom: 20px solid #2196F3;
}

.personnel-marker .marker-pin::before,
.worker-marker .marker-pin::before {
    content: '';
    position: absolute;
    width: 8px;
    height: 8px;
    background-color: #2196F3;
    border-radius: 50%;
    top: 20px;
    left: -4px;
    border: 2px solid white;
}

.worker-marker.outside .marker-pin {
    border-bottom: 20px solid #dc3545;
}

.worker-marker.outside .marker-pin::before {
    background-color: #dc3545;
}

.device-marker .marker-pin {
    border-bottom: 16px solid #4CAF50;
}

.device-marker .marker-pin::before {
    content: '';
    position: absolute;
    width: 6px;
    height: 6px;
    background-color: #4CAF50;
    border-radius: 50%;
    top: 16px;
    left: -3px;
    border: 2px solid white;
}

.asset-marker .marker-pin {
    border-bottom: 20px solid #FF9800;
}

.asset-marker .marker-pin::before {
    content: '';
    position: absolute;
    width: 8px;
    height: 8px;
    background-color: #FF9800;
    border-radius: 50%;
    top: -4px;
    left: -4px;
    border: 2px solid white;
}

.leaflet-tile-pane {
    filter: grayscale(100%);
    -webkit-filter: grayscale(100%);
}

.leaflet-popup-content {
    margin: 8px 12px;
    font-size: 13px;
    line-height: 1.4;
}

.leaflet-popup-content b {
    color: #2c3e50;
}

.data-form {
    max-width: 800px;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 20px;
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 5px;
    color: #555;
    font-weight: 500;
    font-size: 14px;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
    font-family: inherit;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: #3498db;
    box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.1);
}

.form-group textarea {
    resize: vertical;
    min-height: 80px;
}

.form-actions {
    margin-top: 30px;
    padding-top: 20px;
    border-top: 1px solid #eee;
}

.success-message {
    background-color: #d4edda;
    color: #155724;
    padding: 12px;
    border-radius: 4px;
    margin-top: 15px;
    border: 1px solid #c3e6cb;
}

#form-message,
#start-message {
    margin-top: 15px;
}

/* ==========================================
   NAVBAR LEFT GROUP
   ========================================== */
.navbar-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

/* Hamburger toggle button - hidden on desktop */
.sidebar-toggle {
    display: none;
    flex-direction: column;
    justify-content: center;
    gap: 5px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    z-index: 1001;
}

.sidebar-toggle span {
    display: block;
    width: 24px;
    height: 2px;
    background-color: white;
    border-radius: 2px;
    transition: transform 0.3s, opacity 0.3s;
}

/* Sidebar overlay - hidden on desktop */
.sidebar-overlay {
    display: none;
}

/* Tables horizontal scroll wrapper */
.table-responsive {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* ==========================================
   RESPONSIVE: TABLET (max-width: 1024px)
   ========================================== */
@media (max-width: 1024px) {
    .content {
        padding: 20px;
    }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }

    .form-row {
        gap: 15px;
    }

    .map-container,
    #worksite-map {
        height: 450px;
    }
}

/* ==========================================
   RESPONSIVE: MOBILE (max-width: 768px)
   ========================================== */
@media (max-width: 768px) {
    /* Navbar */
    .navbar {
        padding: 10px 15px;
        flex-wrap: wrap;
        gap: 8px;
    }

    .navbar-brand-text {
        display: none;
    }

    .navbar-user {
        gap: 8px;
        font-size: 13px;
    }

    .navbar-user #user-name {
        display: none;
    }

    /* Show hamburger */
    .sidebar-toggle {
        display: flex;
    }

    /* Sidebar as slide-over drawer */
    .sidebar {
        position: fixed;
        top: 0;
        left: -280px;
        width: 280px;
        height: 100vh;
        z-index: 1000;
        transition: left 0.3s ease;
        box-shadow: none;
        padding-top: 60px;
        overflow-y: auto;
    }

    .sidebar.open {
        left: 0;
        box-shadow: 4px 0 20px rgba(0, 0, 0, 0.15);
    }

    /* Overlay when sidebar is open */
    .sidebar-overlay {
        display: block;
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0, 0, 0, 0.4);
        z-index: 999;
        opacity: 0;
        visibility: hidden;
        transition: opacity 0.3s, visibility 0.3s;
    }

    .sidebar-overlay.active {
        opacity: 1;
        visibility: visible;
    }

    /* Main content takes full width */
    .main-content {
        flex-direction: column;
    }

    .content {
        padding: 15px;
        min-height: calc(100vh - 60px);
    }

    /* Form rows stack vertically */
    .form-row {
        grid-template-columns: 1fr !important;
        gap: 10px;
    }

    /* Stats grid single column */
    .stats-grid {
        grid-template-columns: 1fr !important;
        gap: 15px;
    }

    /* Cards */
    .card {
        padding: 15px;
        margin-bottom: 15px;
    }

    /* Tables */
    .table th,
    .table td {
        padding: 8px 6px;
        font-size: 12px;
    }

    .table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        white-space: nowrap;
    }

    /* Dashboard header */
    .dashboard-header {
        margin-bottom: 15px;
    }

    .dashboard-header h2 {
        font-size: 20px;
    }

    /* Maps smaller on mobile */
    .map-container,
    #worksite-map,
    #worksites-map,
    #areas-overview-map,
    #area-draw-map,
    #edit-area-draw-map,
    #perimeterEditorMap,
    #perimeterMap {
        height: 300px !important;
    }

    /* Stat cards compact */
    .stat-card .value {
        font-size: 24px;
    }

    .stat-card h3 {
        font-size: 12px;
    }

    /* Login box */
    .login-box {
        padding: 25px 20px;
        margin: 10px;
    }

    /* Buttons */
    .btn {
        font-size: 13px;
        padding: 8px 16px;
    }

    /* Form group inputs */
    .form-group input,
    .form-group select,
    .form-group textarea {
        font-size: 16px; /* Prevents iOS zoom on focus */
    }

    /* Leaflet popups */
    .leaflet-popup-content {
        max-width: 220px;
        font-size: 12px;
    }

    /* Data form max width */
    .data-form {
        max-width: 100%;
    }

    /* Legend */
    .map-legend {
        padding: 10px;
    }

    .legend-item {
        font-size: 12px;
        margin-bottom: 5px;
    }
}

/* ==========================================
   RESPONSIVE: SMALL MOBILE (max-width: 480px)
   ========================================== */
@media (max-width: 480px) {
    .navbar {
        padding: 8px 10px;
    }

    .content {
        padding: 10px;
    }

    .card {
        padding: 12px;
        border-radius: 6px;
    }

    .stat-card {
        padding: 12px;
    }

    .stat-card .value {
        font-size: 20px;
    }

    .map-container,
    #worksite-map,
    #worksites-map,
    #areas-overview-map,
    #area-draw-map,
    #edit-area-draw-map,
    #perimeterEditorMap,
    #perimeterMap {
        height: 250px !important;
    }

    .table th,
    .table td {
        padding: 6px 4px;
        font-size: 11px;
    }

    .login-box {
        padding: 20px 15px;
    }

    .login-box h1 {
        font-size: 22px;
    }

    .login-tabs {
        gap: 5px;
    }

    .tab-btn {
        padding: 8px;
        font-size: 12px;
    }

    .badge {
        font-size: 10px;
        padding: 3px 8px;
    }
}
