:root {
    --primary-color: #3aaeb5;
    --secondary-color: #6bbe4c;
    --success-color: #10b981;
    --warning-color: #f59e0b;
    --danger-color: #ef4444;
    --dark-bg: #051011;
    --card-bg: #0b1a1c;
    --text-light: #f8fafc;
    --text-muted: #94a3b8;
    --sidebar-width: 260px;
    --header-height: 70px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', sans-serif;
    background: var(--dark-bg);
    color: var(--text-light);
    min-height: 100vh;
    display: flex;
    overflow-x: hidden;
}

/* Sidebar Navigation */
.sidebar {
    width: var(--sidebar-width);
    background: var(--card-bg);
    height: 100vh;
    position: fixed;
    left: 0;
    top: 0;
    z-index: 1000;
    border-right: 1px solid rgba(255, 255, 255, 0.05);
    display: flex;
    flex-direction: column;
    padding: 0 0 20px 0;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.sidebar.collapsed {
    left: calc(var(--sidebar-width) * -1);
}

.sidebar-toggle {
    position: fixed;
    left: calc(var(--sidebar-width) - 20px);
    top: 25px;
    width: 40px;
    height: 40px;
    background: var(--primary-color);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: rgb(255, 255, 255);
    cursor: pointer;
    z-index: 1001;
    box-shadow: 0 4px 15px rgba(37, 99, 235, 0.4);
    transition: all 0.3s ease;
    border: none;
}

.sidebar.collapsed+.main-content .sidebar-toggle {
    left: 20px;
}

.sidebar-toggle i {
    transition: transform 0.3s ease;
}

.sidebar.collapsed+.main-content .sidebar-toggle i {
    transform: rotate(180deg);
}

.sidebar-brand {
    padding: 0 25px 30px;
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 20px;
    font-weight: 700;
    color: var(--text-light);
}

.sidebar-brand i {
    color: var(--primary-color);
}

.sidebar-menu {
    list-style: none;
    flex: 1;
    padding-top: 60px;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 14px 25px;
    color: var(--text-muted);
    text-decoration: none;
    font-weight: 500;
    font-size: 17px;
    transition: all 0.2s ease;
    cursor: pointer;
    border-left: 3px solid transparent;
}

.sidebar-link:hover {
    background: rgba(255, 255, 255, 0.03);
    color: var(--text-light);
}

.sidebar-link.active {
    color: var(--primary-color);
    background: rgba(37, 99, 235, 0.1);
    border-left-color: var(--primary-color);
}

.sidebar-link i {
    width: 20px;
    font-size: 18px;
}

/* Main Content Area */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    padding: 30px;
    width: calc(100% - var(--sidebar-width));
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.sidebar.collapsed+.main-content {
    margin-left: 0;
    width: 100%;
}

.sidebar.collapsed+.main-content .header {
    padding-left: 60px;
    /* Clear toggle button */
}

.container {
    max-width: 1400px;
    margin: 0 auto;
}

/* Header & Stat-Bar */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 25px;
    margin-bottom: 30px;
    background: linear-gradient(135deg, rgba(5, 16, 17, 0.9) 0%, rgba(11, 26, 28, 0.9) 100%);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(58, 174, 181, 0.3);
    border-radius: 16px;
    color: var(--text-light);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3), 0 0 15px rgba(58, 174, 181, 0.05);
}

.header #lastUpdate {
    color: #64748b !important;
}

.header .status-indicator span {
    color: inherit;
}

.header-left h1 {
    font-size: 24px;
    font-weight: 700;
    background: linear-gradient(90deg, var(--primary-color), var(--secondary-color));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.header-logo {
    height: 60px;
    border-radius: 10px;
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    cursor: pointer;
    filter: brightness(2.5);
}

.header-logo:hover {
    transform: scale(1.08);
    filter: brightness(3.0);
}



.header-right {
    display: flex;
    align-items: center;
    gap: 15px;
}

.status-indicator {
    display: inline-flex;
    align-items: center;
    padding: 6px 14px;
    border-radius: 30px;
    font-size: 13px;
    font-weight: 600;
    gap: 8px;
}

/* Management Page Styling */
.sub-nav {
    display: flex;
    background: rgba(255, 255, 255, 0.03);
    padding: 10px;
    border-radius: 12px;
    margin-bottom: 25px;
    gap: 5px;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.sub-nav-item {
    padding: 10px 20px;
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    border-radius: 8px;
    transition: all 0.2s ease;
}

.sub-nav-item:hover {
    color: var(--text-light);
    background: rgba(255, 255, 255, 0.05);
}

.sub-nav-item.active {
    background: var(--primary-color);
    color: white;
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
}

.sub-tab-content {
    display: none;
    animation: fadeIn 0.3s ease;
}

.sub-tab-content.active {
    display: block;
}

.mgmt-card {
    background: var(--card-bg) !important;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.mgmt-title {
    font-size: 18px;
    font-weight: 700;
    margin-bottom: 20px;
    color: var(--text-light);
}

.mgmt-form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 20px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.form-group label {
    font-size: 11px;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.form-group input,
.form-group select,
.form-group textarea {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: white;
    padding: 12px 15px;
    border-radius: 10px;
    font-size: 14px;
    outline: none;
    transition: all 0.2s ease;
}

.form-group select {
    appearance: none;
    cursor: pointer;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='white'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M19 9l-7 7-7-7'%3E%3C/path%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 15px center;
    background-size: 16px;
    padding-right: 40px !important;
}

.form-group select option {
    background: var(--card-bg);
    color: white;
    padding: 10px;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    border-color: var(--primary-color);
    background: rgba(37, 99, 235, 0.05);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.form-hint {
    font-size: 11px;
    color: var(--text-muted);
    opacity: 0.7;
}

.mgmt-btn {
    padding: 12px 24px;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    border: none;
    display: flex;
    align-items: center;
    gap: 8px;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-light);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.btn-refresh {
    background: transparent;
    border: 1px solid var(--primary-color);
    color: var(--primary-color);
    padding: 8px 16px;
    font-size: 12px;
}

.btn-refresh:hover {
    background: var(--primary-color);
    color: white;
}

.mgmt-badge {
    background: var(--primary-color);
    color: white;
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 20px;
    font-weight: 700;
}

.mgmt-table-wrapper {
    overflow-x: auto;
}

.mgmt-table {
    width: 100%;
    border-collapse: collapse;
}

.mgmt-table th {
    text-align: left;
    padding: 15px 20px;
    font-size: 12px;
    text-transform: uppercase;
    color: var(--text-muted);
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    font-weight: 700;
}

.mgmt-table td {
    padding: 15px 20px;
    font-size: 13px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.03);
}

.mgmt-table tr:hover {
    background: rgba(255, 255, 255, 0.01);
}

.mgmt-action-btn {
    padding: 6px;
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    transition: color 0.2s;
}

.mgmt-action-btn:hover {
    color: var(--primary-color);
}

.status-online {
    background: rgba(16, 185, 129, 0.15);
    color: var(--success-color);
}

.status-offline {
    background: rgba(239, 68, 68, 0.15);
    color: var(--danger-color);
}

.status-warning {
    background: rgba(245, 158, 11, 0.15);
    color: var(--warning-color);
}

/* Premium Management Select */
.mgmt-select {
    appearance: none;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: var(--text-light);
    padding: 8px 32px 8px 12px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    outline: none;
    transition: all 0.2s ease;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%2394a3b8'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M19 9l-7 7-7-7'%3E%3C/path%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    background-size: 14px;
    min-width: 160px;
    backdrop-filter: blur(4px);
}

.mgmt-select:hover {
    background-color: rgba(255, 255, 255, 0.05);
    border-color: rgba(255, 255, 255, 0.2);
}

.mgmt-select:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.mgmt-select option {
    background-color: var(--dark-bg);
    color: white;
    padding: 10px;
}

/* Pages */
.page {
    display: none;
    animation: fadeIn 0.4s ease;
}

.page.active {
    display: block;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: translateY(30px) scale(0.96);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* Overview Layout: Map Left, Alerts Right */
.overview-grid {
    display: grid;
    grid-template-columns: 1fr 380px;
    gap: 25px;
    height: calc(100vh - 180px);
}

#map {
    height: 100%;
    min-height: 500px;
    border-radius: 16px;
    border: 1px solid rgba(255, 255, 255, 0.05);
    z-index: 10;
}

.alerts-panel {
    background: var(--card-bg);
    border-radius: 16px;
    border: 1px solid rgba(255, 255, 255, 0.05);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.alerts-header {
    padding: 18px 20px;
    background: rgba(255, 255, 255, 0.02);
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.alerts-title {
    font-size: 14px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted);
}

.alerts-list {
    flex: 1;
    overflow-y: auto;
    padding: 15px;
}

.alert-card {
    background: rgba(239, 68, 68, 0.08);
    border: 1px solid rgba(239, 68, 68, 0.2);
    border-radius: 12px;
    padding: 15px;
    margin-bottom: 12px;
    cursor: pointer;
    transition: transform 0.2s;
}

.alert-card:hover {
    transform: scale(1.02);
    background: rgba(239, 68, 68, 0.12);
}

.alert-card.warning {
    background: rgba(245, 158, 11, 0.08);
    border-color: rgba(245, 158, 11, 0.2);
}

.card-label {
    font-size: 11px;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.card-value {
    font-size: 32px;
    font-weight: 700;
}

/* Search Bar Styling - Premium Glassmorphism */
.search-container {
    position: relative;
    width: 320px;
}

.search-container i {
    position: absolute;
    left: 16px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--primary-color);
    font-size: 14px;
    pointer-events: none;
    opacity: 0.7;
    transition: all 0.3s ease;
}

.search-container input {
    width: 100%;
    padding: 12px 16px 12px 44px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 14px;
    color: white;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    backdrop-filter: blur(8px);
}

.search-container input::placeholder {
    color: rgba(148, 163, 184, 0.5);
}

.search-container:hover input {
    background: rgba(255, 255, 255, 0.05);
    border-color: rgba(255, 255, 255, 0.15);
}

.search-container input:focus {
    outline: none;
    background: rgba(37, 99, 235, 0.05);
    border-color: var(--primary-color);
    box-shadow: 0 0 20px rgba(37, 99, 235, 0.15), inset 0 0 10px rgba(37, 99, 235, 0.05);
}

.search-container input:focus+i {
    opacity: 1;
    transform: translateY(-50%) scale(1.1);
}

/* Edit Icon Styling */
.edit-name-btn {
    opacity: 0.4;
    font-size: 12px;
    margin-left: 8px;
    color: var(--text-muted);
    transition: all 0.2s ease;
    padding: 4px;
    border-radius: 4px;
}

.device-card:hover .edit-name-btn {
    opacity: 0.8;
}

.edit-name-btn:hover {
    color: var(--primary-color);
    background: rgba(37, 99, 235, 0.1);
    opacity: 1 !important;
}

/* Metric Card Clickable Styles */
.metric-card {
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    cursor: pointer;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.metric-card:hover {
    transform: translateY(-5px);
    background: rgba(255, 255, 255, 0.08) !important;
    border-color: var(--primary-color);
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.2);
}

.metric-card.active-metric {
    border-color: var(--primary-color);
    background: rgba(37, 99, 235, 0.1) !important;
}

/* Dashboard Generic Grid */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 24px;
    margin-bottom: 30px;
}

.card {
    background: var(--card-bg);
    border-radius: 16px;
    padding: 24px;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

/* Device List / Cards */
.device-selector {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 20px;
}

.device-card {
    background: var(--card-bg);
    border-radius: 12px;
    padding: 20px;
    cursor: pointer;
    border: 2px solid transparent;
    position: relative;
    transition: 0.3s;
}

.device-card.active {
    border-color: var(--primary-color);
    background: rgba(37, 99, 235, 0.05);
}

.device-card.alert {
    border-color: var(--danger-color);
    animation: alertPulse 2s infinite;
}

@keyframes alertPulse {
    0% {
        box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4);
    }

    70% {
        box-shadow: 0 0 0 10px rgba(239, 68, 68, 0);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(239, 68, 68, 0);
    }
}

/* Buttons */
.relay-btn {
    padding: 10px 18px;
    border: none;
    border-radius: 10px;
    font-weight: 600;
    cursor: pointer;
    transition: 0.2s;
    background: #334155;
    color: white;
}

.relay-btn:hover {
    filter: brightness(1.1);
}

.relay-btn.on {
    background: var(--success-color);
}

.relay-btn.off {
    background: var(--danger-color);
}

/* Helpers */
.text-muted {
    color: var(--text-muted);
}

.device-count,
.alert-counter {
    background: var(--primary-color);
    padding: 2px 10px;
    border-radius: 20px;
    font-size: 11px;
    margin-left: 8px;
}

.alert-counter {
    background: var(--danger-color);
}

.loading {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 50px;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid rgba(255, 255, 255, 0.1);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Notification */
.notification-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 9999;
    max-width: 350px;
}

.notification {
    padding: 15px 20px;
    border-radius: 12px;
    background: #1e293b;
    color: white;
    margin-bottom: 10px;
    border-left: 4px solid var(--primary-color);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    animation: slideIn 0.3s ease;
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
    }

    to {
        transform: translateX(0);
    }
}

/* Map overlays */
.fleet-badge {
    position: absolute;
    bottom: 25px;
    right: 25px;
    background: white;
    padding: 12px 20px;
    border-radius: 12px;
    color: #1e293b;
    font-size: 13px;
    font-weight: 600;
    z-index: 1000;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    border: 1px solid rgba(0, 0, 0, 0.05);
}

.coord-box {
    position: absolute;
    bottom: 25px;
    left: 25px;
    background: #1e293b;
    color: white;
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 500;
    z-index: 1000;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Analytics View Components */
.analytics-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 25px;
}

.analytics-container {
    display: flex;
    flex-direction: column;
    gap: 25px;
}

.analytics-card {
    background: rgba(30, 41, 59, 0.7);
    backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 20px;
    padding: 30px;
    box-shadow: 0 15px 35px rgba(0, 0, 0, 0.2);
}

.chart-wrapper {
    height: 400px;
    width: 100%;
    margin: 20px 0;
}

.analytics-actions {
    display: flex;
    gap: 12px;
}

.action-btn {
    padding: 10px 20px;
    border-radius: 12px;
    font-size: 13px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all 0.3s ease;
    border: 1px solid transparent;
    cursor: pointer;
}

.btn-glass {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-light);
    border-color: rgba(255, 255, 255, 0.1);
}

.btn-glass:hover {
    background: rgba(255, 255, 255, 0.1);
    transform: translateY(-2px);
}

.btn-outline-primary {
    background: transparent;
    border-color: var(--primary-color);
    color: var(--primary-color);
}

.btn-outline-primary:hover {
    background: var(--primary-color);
    color: white;
    box-shadow: 0 8px 20px rgba(37, 99, 235, 0.3);
}

.btn-outline-danger {
    background: transparent;
    border-color: var(--danger-color);
    color: var(--danger-color);
}

.btn-outline-danger:hover {
    background: var(--danger-color);
    color: white;
    box-shadow: 0 8px 20px rgba(239, 68, 68, 0.3);
}

/* Premium Table Styling */
.premium-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0 8px;
}

.premium-table th {
    padding: 15px 20px;
    text-align: left;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted);
    font-weight: 700;
}

.premium-table tbody tr {
    background: rgba(255, 255, 255, 0.02);
    transition: all 0.2s ease;
}

.premium-table tbody tr:hover {
    background: rgba(37, 99, 235, 0.08);
    transform: scale(1.005);
}

.premium-table td {
    padding: 15px 20px;
    font-size: 14px;
    border: none;
}

.premium-table tbody tr td:first-child {
    border-top-left-radius: 12px;
    border-bottom-left-radius: 12px;
}

.premium-table tbody tr td:last-child {
    border-top-right-radius: 12px;
    border-bottom-right-radius: 12px;
}

.record-pill {
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
    background: rgba(255, 255, 255, 0.05);
}

.record-pill i {
    margin-right: 5px;
}

.metric-value-high {
    color: var(--primary-color);
    font-weight: 700;
}

.metric-value-success {
    color: var(--success-color);
    font-weight: 700;
}

.metric-value-warning {
    color: var(--warning-color);
    font-weight: 700;
}

.metric-value-danger {
    color: var(--danger-color);
    font-weight: 700;
}