:root {
    --primary: #2563eb;
    --primary-dark: #1e40af;
    --primary-light: #3b82f6;
    --secondary: #64748b;
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    --info: #06b6d4;
    --dark: #1e293b;
    --light: #f8fafc;
    --border: #e2e8f0;
    --shadow: rgba(0, 0, 0, 0.1);
    --shadow-lg: rgba(0, 0, 0, 0.15);
    
    --radius: 12px;
    --radius-sm: 8px;
    --radius-lg: 16px;
    
    --transition: all 0.3s ease;
}

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

html, body {
    overflow-x: hidden;
    max-width: 100%;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: var(--light);
    color: var(--dark);
    line-height: 1.6;
    min-height: 100vh;
}

/* Login Page */
.login-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.login-box {
    background: white;
    padding: 3rem;
    border-radius: var(--radius-lg);
    box-shadow: 0 20px 50px var(--shadow-lg);
    width: 100%;
    max-width: 450px;
    animation: slideUp 0.5s ease;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.login-header {
    text-align: center;
    margin-bottom: 2.5rem;
}

.login-header h1 {
    color: var(--dark);
    font-size: 2rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
}

.login-header p {
    color: var(--secondary);
    font-size: 0.95rem;
}

.form-group {
    margin-bottom: 1.5rem;
}

.form-label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: var(--dark);
    font-size: 0.9rem;
}

.form-control {
    width: 100%;
    padding: 0.875rem 1rem;
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 1rem;
    transition: var(--transition);
    background: var(--light);
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
    background: white;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.btn {
    display: inline-block;
    padding: 0.875rem 1.5rem;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    text-decoration: none;
    text-align: center;
}

.btn-primary {
    background: var(--primary);
    color: white;
    width: 100%;
}

.btn-primary:hover {
    background: var(--primary-dark);
    transform: translateY(-2px);
    box-shadow: 0 10px 20px var(--shadow);
}

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

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

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

.alert {
    padding: 1rem;
    border-radius: var(--radius-sm);
    margin-bottom: 1.5rem;
    animation: slideDown 0.3s ease;
}

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

.alert-danger {
    background: #fee2e2;
    color: #991b1b;
    border-left: 4px solid var(--danger);
}

.alert-success {
    background: #d1fae5;
    color: #065f46;
    border-left: 4px solid var(--success);
}

.text-center {
    text-align: center;
}

.forgot-password {
    display: block;
    margin-top: 1rem;
    color: var(--primary);
    text-decoration: none;
    font-size: 0.9rem;
}

.forgot-password:hover {
    text-decoration: underline;
}

/* Dashboard Layout */
.dashboard-container {
    display: flex;
    min-height: 100vh;
    background: var(--light);
    overflow-x: hidden;
    padding-left: 0;
    width: 100%;
    max-width: 100%;
    position: relative;
}

.sidebar {
    width: 280px;
    background: linear-gradient(165deg, #0f172a 0%, #1e1b4b 40%, #172554 70%, #0f172a 100%);
    position: fixed;
    height: 100vh;
    overflow-y: auto;
    overflow-x: hidden;
    z-index: 1000;
    transition: var(--transition);
    box-shadow: 4px 0 40px rgba(0, 0, 0, 0.4);
}

.sidebar::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background:
        radial-gradient(ellipse 400px 300px at 0% 0%, rgba(139, 92, 246, 0.2), transparent 50%),
        radial-gradient(ellipse 300px 200px at 100% 100%, rgba(6, 182, 212, 0.15), transparent 50%),
        radial-gradient(ellipse 250px 250px at 50% 50%, rgba(236, 72, 153, 0.08), transparent 50%);
    pointer-events: none;
    z-index: 0;
}

.sidebar::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: linear-gradient(90deg, #8b5cf6, #ec4899, #06b6d4, #8b5cf6);
    background-size: 300% 100%;
    animation: gradientShift 8s ease infinite;
    z-index: 2;
}

@keyframes gradientShift {
    0%, 100% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
}

.sidebar > * {
    position: relative;
    z-index: 1;
}

.sidebar-header {
    padding: 1.75rem 1.5rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    background: linear-gradient(180deg, rgba(255,255,255,0.04) 0%, transparent 100%);
}

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.sidebar-logo img {
    width: 45px;
    height: 45px;
    border-radius: 50%;
    object-fit: cover;
}

.sidebar .user-avatar {
    width: 52px;
    height: 52px;
    border-radius: 14px;
    background: linear-gradient(135deg, #8b5cf6, #ec4899);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 700;
    font-size: 1.3rem;
    box-shadow: 0 8px 24px rgba(139, 92, 246, 0.4);
    position: relative;
}

.sidebar .user-avatar::after {
    content: '';
    position: absolute;
    inset: -2px;
    border-radius: 16px;
    background: linear-gradient(135deg, #8b5cf6, #ec4899, #06b6d4);
    z-index: -1;
    opacity: 0.5;
    filter: blur(8px);
}

.sidebar-logo-text h2 {
    font-size: 1.15rem;
    color: #f8fafc;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.sidebar-logo-text p {
    font-size: 0.75rem;
    color: rgba(139, 92, 246, 0.9);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.1em;
}

.sidebar-menu {
    padding: 1.25rem 0.75rem;
}

.menu-item {
    padding: 0.85rem 1rem;
    margin: 0.25rem 0;
    color: rgba(203, 213, 225, 0.75);
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 0.875rem;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    font-weight: 500;
    border-radius: 12px;
    border-left: none;
    position: relative;
    overflow: hidden;
}

.menu-item::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 0;
    background: linear-gradient(180deg, #8b5cf6, #ec4899);
    border-radius: 0 4px 4px 0;
    transition: height 0.3s ease;
}

.menu-item:hover {
    background: rgba(139, 92, 246, 0.1);
    color: #f8fafc;
    transform: translateX(4px);
}

.menu-item:hover::before {
    height: 60%;
}

.menu-item:hover i {
    color: #a78bfa;
    text-shadow: 0 0 20px rgba(139, 92, 246, 0.6);
}

.menu-item.active {
    background: linear-gradient(90deg, rgba(139, 92, 246, 0.2) 0%, rgba(236, 72, 153, 0.1) 50%, transparent 100%);
    color: #f8fafc;
}

.menu-item.active::before {
    height: 70%;
    box-shadow: 0 0 12px rgba(139, 92, 246, 0.6);
}

.menu-item.active i {
    color: #c4b5fd;
    text-shadow: 0 0 16px rgba(139, 92, 246, 0.8);
}

.menu-item i {
    font-size: 1.15rem;
    width: 24px;
    text-align: center;
    transition: all 0.3s ease;
}

/* Logout button special style */
.menu-item[style*="color: var(--danger)"],
.menu-item[style*="color:var(--danger)"] {
    margin-top: 1.5rem !important;
    color: rgba(248, 113, 113, 0.85) !important;
    border-top: 1px solid rgba(255, 255, 255, 0.06);
    padding-top: 1.25rem;
    border-radius: 12px;
}

.menu-item[style*="color: var(--danger)"]:hover,
.menu-item[style*="color:var(--danger)"]:hover {
    background: rgba(239, 68, 68, 0.15) !important;
    color: #fca5a5 !important;
}

.menu-item[style*="color: var(--danger)"]::before,
.menu-item[style*="color:var(--danger)"]::before {
    background: linear-gradient(180deg, #ef4444, #f87171) !important;
}

.menu-item[style*="color: var(--danger)"]:hover i,
.menu-item[style*="color:var(--danger)"]:hover i {
    color: #fca5a5 !important;
    text-shadow: 0 0 20px rgba(239, 68, 68, 0.6) !important;
}

/* Sidebar scrollbar */
.sidebar::-webkit-scrollbar {
    width: 4px;
}

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

.sidebar::-webkit-scrollbar-thumb {
    background: rgba(139, 92, 246, 0.3);
    border-radius: 4px;
}

.sidebar::-webkit-scrollbar-thumb:hover {
    background: rgba(139, 92, 246, 0.5);
}

.main-content {
    flex: 1;
    padding: 2rem;
    margin-left: 280px;
    width: calc(100% - 280px);
    max-width: calc(100% - 280px);
    min-width: 0;
    box-sizing: border-box;
    overflow-x: hidden;
    overflow-y: auto;
    background: var(--light);
}

.main-content > * {
    max-width: 100%;
    box-sizing: border-box;
}

.main-content * {
    box-sizing: border-box;
}

/* Force flex items to shrink */
.main-content [style*="display:flex"],
.main-content [style*="display: flex"] {
    max-width: 100%;
}

.main-content [style*="display:flex"] > *,
.main-content [style*="display: flex"] > * {
    min-width: 0;
}

.top-bar {
    background: white;
    padding: 1.5rem 2rem;
    border-radius: var(--radius);
    box-shadow: 0 2px 8px var(--shadow);
    margin-bottom: 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.top-bar-title h1 {
    font-size: 1.75rem;
    color: var(--dark);
    font-weight: 700;
}

.top-bar-user {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.user-avatar {
    width: 45px;
    height: 45px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 600;
    font-size: 1.1rem;
}

.user-info p {
    font-weight: 600;
    color: var(--dark);
}

.user-info small {
    color: var(--secondary);
    font-size: 0.85rem;
}

/* Cards */
.cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.cards-grid > .card {
    min-width: 0;
}

.card {
    background: white;
    padding: 1.5rem;
    border-radius: var(--radius);
    box-shadow: 0 2px 8px var(--shadow);
    transition: var(--transition);
    max-width: 100%;
    box-sizing: border-box;
}

.card > * {
    max-width: 100%;
}

.card canvas {
    max-width: 100%;
}

.card-contained {
    position: relative;
    overflow: hidden;
    contain: paint;
    max-width: 100%;
    box-sizing: border-box;
}

.card-contained .table-header {
    flex-wrap: wrap;
}

/* Ensure dashboard content doesn't overflow */
.dashboard-container {
    overflow-x: hidden !important;
    width: 100% !important;
    max-width: 100vw !important;
}

.main-content {
    overflow-x: hidden !important;
}

.main-content * {
    max-width: 100%;
}

.main-content .card {
    overflow: hidden !important;
    word-wrap: break-word;
    width: 100% !important;
    max-width: 100% !important;
}

.main-content .card > div {
    max-width: 100% !important;
}

.main-content .table-responsive {
    overflow-x: auto;
    max-width: 100%;
}

.main-content table {
    min-width: 600px;
}

/* MG Panel fix */
.mg-panel {
    overflow-x: auto;
}

.mg-panel .mg-table {
    min-width: 0;
}

/* Leaflet map containment */
.leaflet-container {
    max-width: 100% !important;
    overflow: hidden !important;
}

#mg-heatmap {
    max-width: 100% !important;
    overflow: hidden !important;
}

.card:hover {
    transform: translateY(-5px);
    box-shadow: 0 8px 20px var(--shadow-lg);
}

.stat-card {
    position: relative;
    overflow: hidden;
}

.stat-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 4px;
    height: 100%;
    background: var(--primary);
}

.stat-card.success::before {
    background: var(--success);
}

.stat-card.warning::before {
    background: var(--warning);
}

.stat-card.danger::before {
    background: var(--danger);
}

.stat-icon {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    margin-bottom: 1rem;
}

.stat-icon.primary {
    background: rgba(37, 99, 235, 0.1);
    color: var(--primary);
}

.stat-icon.success {
    background: rgba(16, 185, 129, 0.1);
    color: var(--success);
}

.stat-icon.warning {
    background: rgba(245, 158, 11, 0.1);
    color: var(--warning);
}

.stat-icon.danger {
    background: rgba(239, 68, 68, 0.1);
    color: var(--danger);
}

.stat-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--dark);
    margin-bottom: 0.5rem;
}

.stat-label {
    color: var(--secondary);
    font-size: 0.9rem;
    font-weight: 500;
}

/* Tables */
.table-container {
    background: white;
    border-radius: var(--radius);
    box-shadow: 0 2px 8px var(--shadow);
    overflow: hidden;
}

.table-header {
    padding: 1.5rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.table-header h2 {
    font-size: 1.25rem;
    color: var(--dark);
    font-weight: 600;
}

.table-responsive {
    overflow-x: auto;
    max-width: 100%;
}

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

thead {
    background: var(--light);
}

th {
    padding: 1rem 1.5rem;
    text-align: left;
    font-weight: 600;
    color: var(--dark);
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

td {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border);
}

tbody tr:hover {
    background: var(--light);
}

.badge {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    border-radius: 50px;
    font-size: 0.8rem;
    font-weight: 600;
}

.badge-success {
    background: #d1fae5;
    color: #065f46;
}

.badge-warning {
    background: #fef3c7;
    color: #92400e;
}

.badge-danger {
    background: #fee2e2;
    color: #991b1b;
}

.badge-info {
    background: #cffafe;
    color: #155e75;
}

/* Responsive */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-280px);
    }
    
    .sidebar.active {
        transform: translateX(0);
    }
    
    .main-content {
        margin-left: 0;
        width: 100%;
        max-width: 100%;
    }
    
    .cards-grid {
        grid-template-columns: 1fr;
    }
    
    .top-bar {
        flex-direction: column;
        gap: 1rem;
    }
}

/* Utilities */
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }

.btn-sm {
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
}

.btn-group {
    display: flex;
    gap: 0.5rem;
}
