/* IoT GPS Tracker - Light Theme CSS (Flat Design) */

:root {
    --bg-primary: #f8fafc;
    --bg-secondary: #ffffff;
    --bg-tertiary: #f1f5f9;
    --text-primary: #0f172a;
    --text-secondary: #64748b;
    --accent: #3b82f6;
    --accent-light: #eff6ff;
    --success: #22c55e;
    --success-light: #f0fdf4;
    --warning: #f59e0b;
    --warning-light: #fffbeb;
    --danger: #ef4444;
    --danger-light: #fef2f2;
    --purple: #8b5cf6;
    --purple-light: #f5f3ff;
    --border-color: #e2e8f0;
    --radius: 8px;
    --sidebar-width: 260px;
    --header-height: 60px;
    --footer-height: 48px;
}

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

body {
    font-family: 'Outfit', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
}

/* Sidebar */
.sidebar {
    position: fixed;
    left: 0;
    top: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    z-index: 1000;
    display: flex;
    flex-direction: column;
}

.sidebar-header {
    height: var(--header-height);
    padding: 0 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
}

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 12px;
    text-decoration: none;
    color: var(--text-primary);
}

.sidebar-logo-icon {
    width: 36px;
    height: 36px;
    background: var(--accent);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.sidebar-logo-icon svg {
    width: 20px;
    height: 20px;
    color: white;
}

.sidebar-logo-text {
    font-size: 18px;
    font-weight: 700;
    letter-spacing: -0.5px;
}

.sidebar-logo-text span {
    color: var(--accent);
}

.sidebar-nav {
    flex: 1;
    padding: 16px 12px;
    overflow-y: auto;
}

.nav-section {
    margin-bottom: 20px;
}

.nav-section-title {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
    padding: 0 12px;
    margin-bottom: 8px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 6px;
    text-decoration: none;
    color: var(--text-secondary);
    transition: all 0.15s ease;
    margin-bottom: 2px;
    font-weight: 500;
}

.nav-item:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.nav-item.active {
    background: var(--accent-light);
    color: var(--accent);
}

.nav-item.active svg {
    color: var(--accent);
}

.nav-item-icon {
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.nav-item-icon svg {
    width: 18px;
    height: 18px;
}

.nav-item-text {
    font-size: 14px;
}

.nav-item-badge {
    margin-left: auto;
    background: var(--danger);
    color: white;
    font-size: 11px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 10px;
    min-width: 20px;
    text-align: center;
}

/* Header */
.header {
    position: fixed;
    top: 0;
    left: var(--sidebar-width);
    right: 0;
    height: var(--header-height);
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    z-index: 999;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
}

.header-title {
    font-size: 18px;
    font-weight: 600;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 16px;
}

.header-status {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    background: var(--success-light);
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    color: var(--success);
}

.status-dot {
    width: 8px;
    height: 8px;
    background: var(--success);
    border-radius: 50%;
    animation: pulse 2s infinite;
}

@keyframes pulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.5;
    }
}

.header-time {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    background: var(--bg-tertiary);
    padding: 6px 12px;
    border-radius: 6px;
}

/* Footer */
.footer {
    position: fixed;
    bottom: 0;
    left: var(--sidebar-width);
    right: 0;
    height: var(--footer-height);
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
    z-index: 998;
    display: flex;
    align-items: center;
    padding: 0 24px;
}

.footer-content {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.footer-left {
    display: flex;
    align-items: center;
    gap: 8px;
}

.footer-brand {
    font-weight: 600;
    color: var(--text-primary);
}

.footer-separator {
    color: var(--border-color);
}

.footer-text {
    font-size: 13px;
    color: var(--text-secondary);
}

.footer-right {
    font-size: 13px;
    color: var(--text-secondary);
}

/* Main Content */
.main-content {
    margin-left: var(--sidebar-width);
    margin-top: var(--header-height);
    min-height: calc(100vh - var(--header-height) - var(--footer-height));
    padding: 24px;
    padding-bottom: calc(var(--footer-height) + 24px);
    background: var(--bg-primary);
}

/* Cards - Flat Design */
.card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 20px;
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border-color);
}

.card-title {
    font-size: 16px;
    font-weight: 600;
}

/* Stats Grid - Flat Design like the image */
.stats-grid {
    display: flex;
    gap: 16px;
    margin-bottom: 24px;
    flex-wrap: wrap;
}

.stat-card {
    flex: 1;
    min-width: 180px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 16px 20px;
    display: flex;
    align-items: center;
    gap: 14px;
}

.stat-icon {
    width: 40px;
    height: 40px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.stat-icon svg {
    width: 20px;
    height: 20px;
}

.stat-icon.blue {
    background: var(--accent-light);
    color: var(--accent);
}

.stat-icon.green {
    background: var(--success-light);
    color: var(--success);
}

.stat-icon.orange {
    background: var(--warning-light);
    color: var(--warning);
}

.stat-icon.purple {
    background: var(--purple-light);
    color: var(--purple);
}

.stat-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.stat-info p {
    font-size: 12px;
    color: var(--text-secondary);
    font-weight: 500;
    order: -1;
}

.stat-info h3 {
    font-size: 22px;
    font-weight: 700;
}

/* Map Container */
.map-container {
    height: calc(100vh - var(--header-height) - var(--footer-height) - 180px);
    border-radius: var(--radius);
    overflow: hidden;
    border: 1px solid var(--border-color);
    position: relative;
}

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

/* Ensure Leaflet controls stay inside map */
.leaflet-left {
    left: 10px !important;
}

.leaflet-control {
    z-index: 400 !important;
}

/* Device List */
.device-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.device-item {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 16px;
    background: var(--bg-tertiary);
    border-radius: var(--radius);
    transition: all 0.15s ease;
    cursor: pointer;
    text-decoration: none;
    color: inherit;
    border: 1px solid transparent;
}

.device-item:hover {
    background: var(--bg-secondary);
    border-color: var(--border-color);
}

.device-icon {
    width: 40px;
    height: 40px;
    background: var(--accent-light);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--accent);
}

.device-icon svg {
    width: 20px;
    height: 20px;
}

.device-info {
    flex: 1;
}

.device-name {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 2px;
}

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

.device-status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    font-weight: 500;
    color: var(--success);
    background: var(--success-light);
    padding: 4px 10px;
    border-radius: 12px;
}

.device-status.offline {
    color: var(--text-secondary);
    background: var(--bg-tertiary);
}

/* History Table */
.history-table {
    width: 100%;
    border-collapse: collapse;
}

.history-table th,
.history-table td {
    padding: 12px 16px;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

.history-table th {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
    background: var(--bg-tertiary);
}

.history-table th:first-child {
    border-radius: 6px 0 0 6px;
}

.history-table th:last-child {
    border-radius: 0 6px 6px 0;
}

.history-table tr:hover td {
    background: var(--bg-tertiary);
}

.history-table td {
    font-size: 13px;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    text-decoration: none;
    border: none;
    cursor: pointer;
    transition: all 0.15s ease;
    font-family: 'Outfit', sans-serif;
}

.btn svg {
    width: 16px;
    height: 16px;
}

.btn-primary {
    background: var(--accent);
    color: white;
}

.btn-primary:hover {
    background: #2563eb;
}

.btn-secondary {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background: var(--bg-secondary);
}

/* Select */
select.btn {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    padding-right: 36px;
}

/* Custom Select Component (Alpine.js) */
.custom-select-wrapper {
    position: relative;
    min-width: 200px;
}

.custom-select-btn {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 12px 16px;
    background: var(--bg-secondary);
    border: 2px solid var(--border-color);
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 500;
    font-family: 'Outfit', sans-serif;
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.15s ease;
}

.custom-select-btn:hover {
    border-color: var(--accent);
}

.custom-select-btn.active {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-light);
}

.custom-select-btn .select-arrow {
    width: 18px;
    height: 18px;
    color: var(--text-secondary);
    transition: transform 0.2s ease;
    flex-shrink: 0;
}

.custom-select-btn .select-arrow.rotate {
    transform: rotate(180deg);
}

.custom-select-dropdown {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    z-index: 100;
    max-height: 240px;
    overflow-y: auto;
}

.custom-select-options {
    padding: 4px 0;
}

.custom-select-option {
    display: block;
    width: 100%;
    padding: 10px 16px;
    text-align: left;
    font-size: 14px;
    font-family: 'Outfit', sans-serif;
    color: var(--text-primary);
    background: transparent;
    border: none;
    border-left: 3px solid transparent;
    cursor: pointer;
    transition: all 0.1s ease;
}

.custom-select-option:hover {
    background: var(--bg-tertiary);
}

.custom-select-option.selected {
    color: var(--accent);
    border-left-color: var(--accent);
    background: var(--accent-light);
}

/* Responsive */
@media (max-width: 768px) {
    :root {
        --sidebar-width: 0px;
    }

    .sidebar {
        transform: translateX(-100%);
        width: 260px;
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .header {
        left: 0;
        padding: 0 16px;
    }

    .header-title {
        font-size: 16px;
    }

    .header-actions {
        gap: 8px;
    }

    .header-status span:last-child {
        display: none;
    }

    .header-time {
        display: none;
    }

    .main-content {
        margin-left: 0;
        padding: 16px;
    }

    .footer {
        left: 0;
        padding: 0 16px;
    }

    .footer-left .footer-text,
    .footer-separator {
        display: none;
    }

    .stats-grid {
        flex-direction: column;
    }

    .stat-card {
        min-width: 100%;
    }

    .map-container {
        height: calc(100vh - var(--header-height) - var(--footer-height) - 220px);
    }
}

/* Mobile Menu Button */
.mobile-menu-btn {
    display: none;
    width: 40px;
    height: 40px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    margin-right: 12px;
    flex-shrink: 0;
}

.mobile-menu-btn svg {
    width: 20px;
    height: 20px;
    color: var(--text-primary);
}

@media (max-width: 768px) {
    .mobile-menu-btn {
        display: flex !important;
    }
}

/* Overlay for mobile menu */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
}

.sidebar-overlay.active {
    display: block;
}

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

::-webkit-scrollbar-track {
    background: var(--bg-primary);
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

/* Leaflet Overrides */
.leaflet-container {
    background: var(--bg-primary);
    font-family: 'Outfit', sans-serif;
}

.leaflet-popup-content-wrapper {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
}

.leaflet-popup-tip {
    background: var(--bg-secondary);
}

.leaflet-control-zoom {
    z-index: 400 !important;
}

.leaflet-control-zoom a {
    background: var(--bg-secondary) !important;
    color: var(--text-primary) !important;
    border: 1px solid var(--border-color) !important;
}

.leaflet-control-attribution {
    background: var(--bg-secondary) !important;
    color: var(--text-secondary) !important;
}