/* ==========================================
   NetVision Tracker - Custom Styles
   PWA-Optimized | Mobile-First
   ========================================== */

/* === PWA: Prevent pull-to-refresh & overscroll bounce === */
html, body {
    overscroll-behavior-y: none;
    -webkit-overflow-scrolling: touch;
}

/* === PWA: Standalone mode adjustments === */
@media all and (display-mode: standalone) {
    body {
        /* Slightly taller safe area on iOS standalone */
        padding-top: env(safe-area-inset-top);
    }
}

:root {
    --nv-bg: #f8fafc;
    --nv-card: #ffffff;
    --nv-primary: #6C3BFF;
    --nv-secondary: #00D4FF;
    --nv-text: #475569;
    --nv-success: #10B981;
    --nv-warning: #F59E0B;
    --nv-danger: #EF4444;
    --nv-border: rgba(0, 0, 0, 0.08);
    --nv-main: #020617;
    
    --glass-bg: rgba(255, 255, 255, 0.7);
    --glass-border: rgba(108, 59, 255, 0.12);
    --glass-hover-border: rgba(108, 59, 255, 0.35);
    
    --scrollbar-track: #f1f5f9;
    --sidebar-bg: rgba(255, 255, 255, 0.97);
}

.dark {
    --nv-bg: #0B1020;
    --nv-card: #141B2D;
    --nv-primary: #6C3BFF;
    --nv-secondary: #00D4FF;
    --nv-text: #94A3B8;
    --nv-success: #10B981;
    --nv-warning: #F59E0B;
    --nv-danger: #EF4444;
    --nv-border: rgba(108, 59, 255, 0.08);
    --nv-main: #ffffff;
    
    --glass-bg: rgba(20, 27, 45, 0.7);
    --glass-border: rgba(108, 59, 255, 0.12);
    --glass-hover-border: rgba(108, 59, 255, 0.35);
    
    --scrollbar-track: #0B1020;
    --sidebar-bg: rgba(14, 18, 35, 0.97);
}

/* Custom scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--scrollbar-track); }
::-webkit-scrollbar-thumb { background: var(--nv-primary); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #5a2de0; }

* { scrollbar-width: thin; scrollbar-color: var(--nv-primary) var(--scrollbar-track); }

/* Gradient text */
.gradient-text {
    background: linear-gradient(135deg, #6C3BFF, #00D4FF);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* Glass card */
.glass-card {
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
.glass-card:hover {
    border-color: var(--glass-hover-border);
    box-shadow: 0 8px 32px rgba(108, 59, 255, 0.08);
    transform: translateY(-2px);
}

/* Gradient border */
.gradient-border { position: relative; }
.gradient-border::before {
    content: ''; position: absolute; inset: 0; border-radius: 16px; padding: 1px;
    background: linear-gradient(135deg, #6C3BFF, #00D4FF);
    -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
    -webkit-mask-composite: xor; mask-composite: exclude; pointer-events: none;
}

/* Buttons */
.btn-primary {
    background: linear-gradient(135deg, #6C3BFF, #5a2de0);
    color: white; padding: 0.625rem 1.5rem; border-radius: 12px;
    font-weight: 600; transition: all 0.3s ease; border: none; cursor: pointer;
    display: inline-flex; align-items: center; gap: 8px; font-family: 'Inter', sans-serif; font-size: 0.875rem;
}
.btn-primary:hover { transform: translateY(-2px); box-shadow: 0 8px 25px rgba(108, 59, 255, 0.4); }
.btn-primary:active { transform: translateY(0); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.btn-outline {
    background: transparent; color: #6C3BFF; padding: 0.625rem 1.5rem; border-radius: 12px;
    font-weight: 600; transition: all 0.3s ease; border: 1px solid rgba(108, 59, 255, 0.4);
    cursor: pointer; display: inline-flex; align-items: center; gap: 8px; font-family: 'Inter', sans-serif; font-size: 0.875rem;
}
.btn-outline:hover { background: rgba(108, 59, 255, 0.1); border-color: #6C3BFF; }

.btn-danger {
    background: linear-gradient(135deg, #EF4444, #dc2626);
    color: white; padding: 0.625rem 1.5rem; border-radius: 12px;
    font-weight: 600; transition: all 0.3s ease; border: none; cursor: pointer;
    display: inline-flex; align-items: center; gap: 8px; font-family: 'Inter', sans-serif; font-size: 0.875rem;
}
.btn-danger:hover { transform: translateY(-2px); box-shadow: 0 8px 25px rgba(239, 68, 68, 0.4); }

.btn-sm { padding: 0.375rem 0.875rem; font-size: 0.75rem; border-radius: 8px; }
.btn-icon { padding: 0.5rem; border-radius: 10px; }

.input-field {
    background: var(--nv-card); border: 1px solid var(--nv-border);
    border-radius: 12px; padding: 0.75rem 1rem; color: var(--nv-main); width: 100%;
    transition: all 0.3s ease; outline: none; font-family: 'Inter', sans-serif; font-size: 0.875rem;
}
.input-field:focus { border-color: #6C3BFF; box-shadow: 0 0 0 3px rgba(108, 59, 255, 0.15); }
.input-field::placeholder { color: #94A3B8; }

select.input-field { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2394A3B8' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 2.5rem; }
select.input-field option { background: var(--nv-card); color: var(--nv-main); }

/* Badges */
.badge { display: inline-flex; align-items: center; padding: 0.2rem 0.7rem; border-radius: 9999px; font-size: 0.7rem; font-weight: 600; letter-spacing: 0.025em; }
.badge-success { background: rgba(16, 185, 129, 0.15); color: #10B981; }
.badge-warning { background: rgba(245, 158, 11, 0.15); color: #F59E0B; }
.badge-danger { background: rgba(239, 68, 68, 0.15); color: #EF4444; }
.badge-info { background: rgba(0, 212, 255, 0.15); color: #00D4FF; }
.badge-primary { background: rgba(108, 59, 255, 0.15); color: #6C3BFF; }

/* Sidebar */
.sidebar {
    width: 272px; min-height: 100vh; background: var(--sidebar-bg);
    border-right: 1px solid var(--nv-border); transition: all 0.3s ease;
    position: fixed; left: 0; top: 0; z-index: 40; overflow-y: auto; overflow-x: hidden;
}
.sidebar-link {
    display: flex; align-items: center; gap: 12px; padding: 11px 18px; border-radius: 12px;
    color: #94A3B8; transition: all 0.25s ease; cursor: pointer; margin: 3px 12px;
    text-decoration: none; font-size: 0.875rem; font-weight: 500; position: relative;
}
.sidebar-link:hover { color: white; background: rgba(108, 59, 255, 0.08); }
.sidebar-link.active {
    color: white; background: linear-gradient(135deg, rgba(108, 59, 255, 0.18), rgba(0, 212, 255, 0.08));
    border-left: 3px solid #6C3BFF;
}
.sidebar-link .icon { width: 20px; height: 20px; flex-shrink: 0; }

/* Main content */
.main-content { margin-left: 272px; min-height: 100vh; transition: margin-left 0.3s ease; }

/* Data table */
.data-table { width: 100%; border-collapse: separate; border-spacing: 0; }
.data-table th { padding: 12px 16px; text-align: left; color: #94A3B8; font-weight: 600; font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.06em; border-bottom: 1px solid rgba(108, 59, 255, 0.08); }
.data-table td { padding: 12px 16px; border-bottom: 1px solid rgba(255,255,255,0.03); font-size: 0.85rem; }
.data-table tbody tr { transition: background 0.2s; }
.data-table tbody tr:hover td { background: rgba(108, 59, 255, 0.04); }

/* Battery bar */
.battery-bar { height: 6px; border-radius: 3px; background: rgba(255,255,255,0.08); overflow: hidden; width: 100%; }
.battery-fill { height: 100%; border-radius: 3px; transition: width 0.6s ease; }

/* Leaflet custom */
.leaflet-container { border-radius: 16px; }
.custom-marker {
    width: 42px; height: 42px; border-radius: 50%; display: flex; align-items: center;
    justify-content: center; font-size: 18px; border: 2px solid #6C3BFF;
    background: rgba(20, 27, 45, 0.92); backdrop-filter: blur(4px);
    box-shadow: 0 4px 16px rgba(108, 59, 255, 0.35); transition: all 0.3s;
}
.custom-marker:hover { transform: scale(1.15); box-shadow: 0 6px 24px rgba(108, 59, 255, 0.5); }
.leaflet-popup-content-wrapper { background: var(--nv-card) !important; color: var(--nv-main) !important; border: 1px solid var(--nv-border) !important; border-radius: 12px !important; box-shadow: 0 8px 32px rgba(0,0,0,0.15) !important; }
.leaflet-popup-tip { background: var(--nv-card) !important; }
.leaflet-popup-close-button { color: var(--nv-text) !important; }
.leaflet-control-zoom a { background: var(--nv-card) !important; color: var(--nv-main) !important; border-color: var(--nv-border) !important; }

/* Modal */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.65); backdrop-filter: blur(4px); z-index: 50; display: flex; align-items: center; justify-content: center; animation: fadeIn 0.2s ease-out; }
.modal-content { background: var(--nv-card); border: 1px solid var(--nv-border); border-radius: 20px; padding: 28px; max-width: 520px; width: 92%; max-height: 90vh; overflow-y: auto; animation: slideUp 0.3s ease-out; }

/* Toast */
.toast-container { position: fixed; top: 20px; right: 20px; z-index: 100; display: flex; flex-direction: column; gap: 8px; }
.toast { padding: 14px 20px; border-radius: 12px; font-size: 0.85rem; font-weight: 500; animation: slideInRight 0.3s ease-out; display: flex; align-items: center; gap: 10px; backdrop-filter: blur(12px); max-width: 380px; }
.toast-success { background: rgba(16, 185, 129, 0.15); border: 1px solid rgba(16, 185, 129, 0.3); color: #10B981; }
.toast-error { background: rgba(239, 68, 68, 0.15); border: 1px solid rgba(239, 68, 68, 0.3); color: #EF4444; }
.toast-info { background: rgba(0, 212, 255, 0.15); border: 1px solid rgba(0, 212, 255, 0.3); color: #00D4FF; }

/* Animations */
.fade-in { animation: fadeIn 0.4s ease-out; }
.slide-up { animation: slideUp 0.4s ease-out; }
.slide-in-left { animation: slideInLeft 0.3s ease-out; }

@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
@keyframes slideUp { from { opacity: 0; transform: translateY(24px); } to { opacity: 1; transform: translateY(0); } }
@keyframes slideInLeft { from { transform: translateX(-100%); } to { transform: translateX(0); } }
@keyframes slideInRight { from { opacity: 0; transform: translateX(100px); } to { opacity: 1; transform: translateX(0); } }
@keyframes slideOut { from { opacity: 1; transform: translateX(0); } to { opacity: 0; transform: translateX(100px); } }

.pulse-live { animation: pulseLive 2s infinite; }
@keyframes pulseLive { 0%, 100% { opacity: 1; } 50% { opacity: 0.4; } }

.shimmer { background: linear-gradient(90deg, #141B2D 25%, #1e2740 50%, #141B2D 75%); background-size: 200% 100%; animation: shimmer 1.5s infinite; border-radius: 8px; }
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

.shimmer-bar { animation: shimmerBar 2s infinite; }
@keyframes shimmerBar { 0% { width: 0%; } 50% { width: 70%; } 100% { width: 100%; } }

/* Toggle switch */
.toggle { position: relative; width: 44px; height: 24px; background: rgba(255,255,255,0.1); border-radius: 12px; cursor: pointer; transition: all 0.3s; border: none; padding: 0; }
.toggle::after { content: ''; position: absolute; width: 18px; height: 18px; border-radius: 50%; background: white; top: 3px; left: 3px; transition: all 0.3s; }
.toggle.active { background: #6C3BFF; }
.toggle.active::after { left: 23px; }

/* Tab buttons */
.tab-btn { padding: 8px 16px; border-radius: 10px; font-size: 0.8rem; font-weight: 500; color: #94A3B8; background: transparent; border: none; cursor: pointer; transition: all 0.25s; }
.tab-btn:hover { color: white; background: rgba(108,59,255,0.1); }
.tab-btn.active { color: white; background: rgba(108,59,255,0.2); border: 1px solid rgba(108,59,255,0.3); }

/* Notification dot */
.notification-dot { width: 8px; height: 8px; background: #EF4444; border-radius: 50%; position: absolute; top: -2px; right: -2px; animation: pulseLive 2s infinite; }
.notification-badge { position: absolute; top: -6px; right: -6px; background: #EF4444; color: white; font-size: 0.6rem; font-weight: 700; min-width: 18px; height: 18px; border-radius: 9px; display: flex; align-items: center; justify-content: center; padding: 0 4px; }

/* Responsive */
@media (max-width: 1024px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); box-shadow: 8px 0 32px rgba(0,0,0,0.5); }
    .main-content { margin-left: 0; }
}

/* Sidebar overlay on mobile */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    z-index: 39;
    opacity: 0;
    transition: opacity 0.3s ease;
}
.sidebar-overlay.active {
    display: block;
    opacity: 1;
}

@media (max-width: 640px) {
    .modal-content { width: 95%; padding: 20px; border-radius: 16px; }
    .toast-container { top: 12px; right: 12px; left: 12px; }
    .toast { max-width: 100%; font-size: 0.8rem; padding: 12px 16px; }
}

/* === PWA: Safe Area Inset Utilities === */
@supports (padding: env(safe-area-inset-top)) {
    .pt-safe { padding-top: env(safe-area-inset-top) !important; }
    .pb-safe { padding-bottom: env(safe-area-inset-bottom) !important; }
    .pl-safe { padding-left: env(safe-area-inset-left) !important; }
    .pr-safe { padding-right: env(safe-area-inset-right) !important; }
    .px-safe {
        padding-left: env(safe-area-inset-left) !important;
        padding-right: env(safe-area-inset-right) !important;
    }
    .py-safe {
        padding-top: env(safe-area-inset-top) !important;
        padding-bottom: env(safe-area-inset-bottom) !important;
    }
}

/* === Leaflet: Mobile Touch Optimizations === */
@media (max-width: 1024px) {
    .leaflet-container {
        touch-action: pan-x pan-y;
        border-radius: 12px;
    }
    .leaflet-control-zoom {
        border: none !important;
        box-shadow: 0 2px 12px rgba(0,0,0,0.3) !important;
        border-radius: 12px !important;
        overflow: hidden;
    }
    .leaflet-control-zoom a {
        width: 36px !important;
        height: 36px !important;
        line-height: 36px !important;
        font-size: 18px !important;
    }
    .custom-marker {
        width: 36px;
        height: 36px;
        font-size: 15px;
    }
}

/* Auth page background */
.auth-bg {
    background: radial-gradient(ellipse at 30% 20%, rgba(108, 59, 255, 0.08) 0%, transparent 60%),
                radial-gradient(ellipse at 70% 80%, rgba(0, 212, 255, 0.06) 0%, transparent 60%),
                var(--nv-bg);
    min-height: 100vh;
}

/* Stat card accent */
.stat-accent-primary { border-left: 3px solid #6C3BFF; }
.stat-accent-secondary { border-left: 3px solid #00D4FF; }
.stat-accent-success { border-left: 3px solid #10B981; }
.stat-accent-warning { border-left: 3px solid #F59E0B; }
.stat-accent-danger { border-left: 3px solid #EF4444; }
