/* Google Fonts */
@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@300;400;500;600;700;800&display=swap');

/* Color Variables */
:root {
    --font-primary: 'Plus Jakarta Sans', sans-serif;
    
    /* Light Mode Palette */
    --bg-app: #f8fafc;
    --bg-card: #ffffff;
    --bg-sidebar: #0f172a;
    --sidebar-text: #94a3b8;
    --sidebar-text-active: #ffffff;
    --sidebar-hover-bg: #1e293b;
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #94a3b8;
    
    --primary: #10b981;
    --primary-rgb: 16, 185, 129;
    --primary-hover: #059669;
    --secondary: #6366f1;
    --secondary-rgb: 99, 102, 241;
    --accent: #f59e0b;
    --danger: #ef4444;
    --success: #10b981;
    --info: #06b6d4;
    
    --border-color: #e2e8f0;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    --border-radius: 16px;
    --glass-bg: rgba(255, 255, 255, 0.7);
    --glass-border: rgba(255, 255, 255, 0.3);

    --bottomnav-height: 64px;
}

[data-theme="dark"] {
    --bg-app: #090d16;
    --bg-card: #111827;
    --bg-sidebar: #0b0f19;
    --sidebar-text: #94a3b8;
    --sidebar-text-active: #ffffff;
    --sidebar-hover-bg: #1f2937;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    
    --primary: #34d399;
    --primary-rgb: 52, 211, 153;
    --primary-hover: #10b981;
    --secondary: #818cf8;
    --secondary-rgb: 129, 140, 248;
    --accent: #fbbf24;
    
    --border-color: #1f2937;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.5);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.5);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.5);
    --glass-bg: rgba(17, 24, 39, 0.7);
    --glass-border: rgba(255, 255, 255, 0.05);
}

/* Global Styles */
body {
    font-family: var(--font-primary);
    background-color: var(--bg-app);
    color: var(--text-primary);
    transition: background-color 0.3s ease, color 0.3s ease;
    overflow-x: hidden;
    -webkit-tap-highlight-color: transparent;
}

/* Glassmorphism */
.glass-panel {
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
}

/* Cards */
.card-custom {
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-sm);
    transition: transform 0.2s ease, box-shadow 0.2s ease, background-color 0.3s ease, border-color 0.3s ease;
}
.card-custom:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
}

.hover-scale { transition: transform 0.2s ease; }
.hover-scale:hover { transform: scale(1.02); }

/* ==========================
   SIDEBAR (Desktop Only)
   ========================== */
#sidebar {
    width: 260px;
    height: 100vh;
    position: fixed;
    top: 0;
    left: 0;
    background-color: var(--bg-sidebar);
    z-index: 1000;
    transition: transform 0.3s ease;
}
#sidebar .nav-link {
    color: var(--sidebar-text);
    padding: 12px 20px;
    border-radius: 12px;
    margin: 4px 12px;
    font-weight: 500;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 12px;
}
#sidebar .nav-link i { font-size: 1.25rem; }
#sidebar .nav-link:hover {
    background-color: var(--sidebar-hover-bg);
    color: var(--sidebar-text-active);
    transform: translateX(4px);
}
#sidebar .nav-link.active {
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    color: var(--sidebar-text-active);
    box-shadow: 0 4px 12px rgba(var(--primary-rgb), 0.3);
}

/* Top Navbar */
#top-bar {
    height: 70px;
    margin-left: 260px;
    padding: 0 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background-color: var(--bg-card);
    border-bottom: 1px solid var(--border-color);
    transition: background-color 0.3s ease, border-color 0.3s ease, margin-left 0.3s ease;
}

/* Main Content */
#main-content {
    margin-left: 260px;
    padding: 24px;
    min-height: calc(100vh - 70px);
    transition: margin-left 0.3s ease;
}

/* Theme Toggle */
.theme-toggle-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.4rem;
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    transition: background-color 0.2s;
}
.theme-toggle-btn:hover { background-color: var(--border-color); }

/* ==========================
   BOTTOM NAVIGATION (Mobile)
   ========================== */
#bottom-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--bottomnav-height);
    background-color: var(--bg-card);
    border-top: 1px solid var(--border-color);
    z-index: 1100;
    box-shadow: 0 -4px 16px rgba(0,0,0,0.06);
    transition: background-color 0.3s ease, border-color 0.3s ease;
}
.bottom-nav-inner {
    display: flex;
    justify-content: space-around;
    align-items: stretch;
    height: 100%;
    max-width: 500px;
    margin: 0 auto;
}
.bnav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    flex: 1;
    text-decoration: none !important;
    color: var(--text-muted);
    font-size: 0.62rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    transition: color 0.15s ease;
    position: relative;
    padding: 4px 0;
}
.bnav-item i { font-size: 1.15rem; transition: transform 0.15s ease; }
.bnav-item.active {
    color: var(--primary);
}
.bnav-item.active i { transform: scale(1.15); }
.bnav-item.active::before {
    content: '';
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 28px;
    height: 3px;
    border-radius: 0 0 4px 4px;
    background: linear-gradient(90deg, var(--primary), var(--secondary));
}

/* Drawer for "More" on mobile */
#moreDrawer {
    display: none;
    position: fixed;
    bottom: var(--bottomnav-height);
    left: 0;
    right: 0;
    background: var(--bg-card);
    border-top: 1px solid var(--border-color);
    border-radius: 20px 20px 0 0;
    padding: 16px;
    z-index: 1099;
    box-shadow: 0 -8px 24px rgba(0,0,0,0.12);
    transform: translateY(100%);
    transition: transform 0.3s ease;
}
#moreDrawer.show { transform: translateY(0); }
#moreDrawer .drawer-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
}
#moreDrawer .drawer-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 12px 4px;
    border-radius: 12px;
    text-decoration: none !important;
    color: var(--text-secondary);
    font-size: 0.7rem;
    font-weight: 600;
    transition: background 0.15s;
}
#moreDrawer .drawer-item:active { background: rgba(var(--primary-rgb), 0.08); }
#moreDrawer .drawer-item i { font-size: 1.2rem; color: var(--primary); }
.drawer-backdrop { display: none; position: fixed; inset: 0; z-index: 1098; background: rgba(0,0,0,0.3); }
.drawer-backdrop.show { display: block; }

/* ==========================
   MOBILE TABLE → CARD
   ========================== */
@media (max-width: 767.98px) {
    .table-responsive table.table thead { display: none; }
    .table-responsive table.table tbody { display: flex; flex-direction: column; gap: 10px; }
    .table-responsive table.table tbody tr {
        display: flex;
        flex-wrap: wrap;
        background: var(--bg-card);
        border: 1px solid var(--border-color);
        border-radius: 14px;
        padding: 12px 14px 8px;
        box-shadow: var(--shadow-sm);
        gap: 0;
    }
    .table-responsive table.table tbody tr td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        width: 100%;
        padding: 4px 0;
        border: none !important;
        font-size: 0.82rem;
        line-height: 1.4;
    }
    .table-responsive table.table tbody tr td::before {
        content: attr(data-label);
        font-weight: 700;
        color: var(--text-muted);
        font-size: 0.72rem;
        text-transform: uppercase;
        letter-spacing: 0.04em;
        flex-shrink: 0;
        margin-right: 10px;
    }
    .table-responsive table.table tbody tr td:first-child {
        display: none; /* hide No column on mobile */
    }
    .table-responsive table.table tbody tr td:last-child {
        border-top: 1px solid var(--border-color) !important;
        margin-top: 6px;
        padding-top: 8px;
        justify-content: flex-end;
    }
}

/* ==========================
   MOBILE RESPONSIVE OVERRIDES
   ========================== */
@media (max-width: 991.98px) {
    #sidebar { transform: translateX(-100%); }
    #sidebar.show { transform: translateX(0); }
    .sidebar-overlay { display: none; position: fixed; top: 0; left: 0; width: 100vw; height: 100vh; background: rgba(0,0,0,0.4); z-index: 999; }
    .sidebar-overlay.show { display: block; }

    #top-bar {
        margin-left: 0;
        height: 52px;
        padding: 0 14px;
    }
    #top-bar h4, #top-bar h5 { font-size: 1rem; }

    #main-content {
        margin-left: 0;
        padding: 12px 10px;
        padding-bottom: calc(var(--bottomnav-height) + 14px);
    }

    #bottom-nav { display: block; }

    /* Slimmer cards */
    .card-custom {
        border-radius: 14px;
        box-shadow: var(--shadow-sm);
    }
    .card-custom:hover { transform: none; box-shadow: var(--shadow-sm); }

    .card-custom.p-4 { padding: 14px !important; }
    .card-custom.p-3 { padding: 10px !important; }

    /* Slim stat cards */
    .stat-icon { width: 38px; height: 38px; border-radius: 10px; font-size: 1.1rem; }

    /* Compact page headers */
    #main-content h3 { font-size: 1.15rem; }
    #main-content .mb-4 { margin-bottom: 0.75rem !important; }

    /* Premium buttons slim */
    .btn-premium-primary { padding: 8px 16px; font-size: 0.82rem; border-radius: 10px; }
    .btn-premium-secondary { padding: 8px 16px; font-size: 0.82rem; border-radius: 10px; }

    /* Form controls compact */
    .form-control, .form-select { padding: 9px 12px; font-size: 0.88rem; border-radius: 10px; }

    /* Modal compact */
    .modal-content { border-radius: 18px !important; }
    .modal-body { padding: 14px !important; }
    .modal-header { padding: 14px !important; }
    .modal-footer { padding: 10px 14px !important; }

    /* Badges slim */
    .badge { font-size: 0.68rem; padding: 3px 8px; }

    /* table font slim */
    .table { font-size: 0.82rem; }
}

/* Small phone extra slim */
@media (max-width: 400px) {
    #main-content { padding: 8px 6px; padding-bottom: calc(var(--bottomnav-height) + 10px); }
    .stat-icon { width: 32px; height: 32px; font-size: 0.9rem; border-radius: 8px; }
    #main-content h3 { font-size: 1.05rem; }
    .bnav-item { font-size: 0.58rem; }
    .bnav-item i { font-size: 1rem; }
}

/* ==========================
   PREMIUM BUTTONS
   ========================== */
.btn-premium-primary {
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    border: none;
    color: white !important;
    border-radius: 12px;
    padding: 10px 24px;
    font-weight: 600;
    box-shadow: 0 4px 10px rgba(var(--primary-rgb), 0.2);
    transition: all 0.2s ease;
}
.btn-premium-primary:hover { transform: translateY(-2px); box-shadow: 0 6px 14px rgba(var(--primary-rgb), 0.3); opacity: 0.95; }
.btn-premium-secondary {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    color: var(--text-primary) !important;
    border-radius: 12px;
    padding: 10px 24px;
    font-weight: 600;
    transition: all 0.2s ease;
}
.btn-premium-secondary:hover { background-color: var(--border-color); transform: translateY(-2px); }

/* Forms */
.form-control, .form-select {
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    border-radius: 12px;
    padding: 12px;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.form-control:focus, .form-select:focus {
    background-color: var(--bg-card);
    border-color: var(--primary);
    color: var(--text-primary);
    box-shadow: 0 0 0 4px rgba(var(--primary-rgb), 0.15);
}

/* Leaflet Map */
.premium-map {
    border-radius: var(--border-radius);
    overflow: hidden;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-md);
}

/* Badges */
.badge-custom { padding: 6px 12px; border-radius: 30px; font-weight: 600; font-size: 0.8rem; }

/* Tables */
.table { color: var(--text-primary) !important; }
.table td, .table th { border-color: var(--border-color); }
.thead-dark-custom th {
    background-color: var(--bg-app) !important;
    color: var(--text-secondary);
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.05em;
}

/* Dashboard Stat Cards */
.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    color: white;
}

/* iOS-like safe area on modern phones */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
    #bottom-nav { padding-bottom: env(safe-area-inset-bottom); height: calc(var(--bottomnav-height) + env(safe-area-inset-bottom)); }
    #main-content { padding-bottom: calc(var(--bottomnav-height) + env(safe-area-inset-bottom) + 14px); }
}
