/* =========================================
   1. GLOBAL VARIABLES & THEME CONFIG
   ========================================= */
:root {
  /* --- Brand Colors --- */
  --primary-color: #4f46e5;
  --primary-hover: #4338ca;
  --accent-pink: #e2136e;

  /* --- Light Mode Defaults --- */
  --body-bg: #f1f5f9;
  --card-bg: #ffffff;
  --text-main: #1e293b;
  --text-muted: #64748b;
  --sidebar-bg: #0f172a; /* Sidebar stays dark in light mode */
  --navbar-bg: rgba(255, 255, 255, 0.85); /* Glass effect */
  --border-color: rgba(0, 0, 0, 0.05);

  --sidebar-width: 17rem;
  --header-height: 70px;
}

/* --- Dark Mode Overrides --- */
[data-bs-theme="dark"] {
  --body-bg: #0f172a;        /* Deep Slate */
  --card-bg: #1e293b;        /* Lighter Slate */
  --text-main: #f1f5f9;      /* White-ish */
  --text-muted: #94a3b8;     /* Light Gray */
  --sidebar-bg: #020617;     /* Darker Sidebar */
  --navbar-bg: rgba(15, 23, 42, 0.85); /* Dark Glass */
  --border-color: rgba(255, 255, 255, 0.05);
}

body {
  font-family: "Poppins", sans-serif;
  background-color: var(--body-bg);
  color: var(--text-main);
  transition: background-color 0.3s ease, color 0.3s ease;
}

/* =========================================
   2. BOOTSTRAP OVERRIDES
   ========================================= */
.btn-primary {
  background-color: var(--primary-color);
  border-color: var(--primary-color);
  padding: 0.6rem 1.2rem;
  font-weight: 500;
  border-radius: 8px;
  transition: all 0.2s;
}

.btn-primary:hover {
  background-color: var(--primary-hover);
  border-color: var(--primary-hover);
  transform: translateY(-1px);
  box-shadow: 0 4px 6px rgba(79, 70, 229, 0.2);
}

.form-control:focus,
.form-select:focus {
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.15);
}

.card {
  border: none;
  border-radius: 12px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
  background-color: var(--card-bg);
}

/* =========================================
   3. LAYOUT STRUCTURE
   ========================================= */
#wrapper {
  /* Removed display: flex; - It causes conflicts with fixed sidebars */
  position: relative;
  width: 100%;
  overflow-x: hidden;
}

#page-content-wrapper {
  width: 100%;
  min-height: 100vh;
  /* Smooth transition for the margin change */
  transition: margin-left 0.3s ease, width 0.3s ease; 
}

main {
  width: 100%;
}

/* =========================================
   4. MODERN SIDEBAR (REDESIGNED)
   ========================================= */
/* =========================================
   SIDEBAR: FULL SCREEN HEIGHT (FIXED)
   ========================================= */

#sidebar-wrapper {
  position: fixed; /* Lock sidebar to screen */
  top: 0;
  bottom: 0;
  left: 0;
  width: var(--sidebar-width);
  height: 100vh;
  background: var(--sidebar-bg);
  color: #94a3b8;
  transition: margin 0.3s ease; /* Smooth slide effect */
  display: flex;
  flex-direction: column;
  border-right: 1px solid rgba(255, 255, 255, 0.05);
  z-index: 1000; /* Ensure it stays on top */
}
/* --- Brand Section --- */
.sidebar-brand {
    height: var(--header-height);
    display: flex;
    align-items: center;
    padding: 0 1.5rem;
    background: rgba(255, 255, 255, 0.02);
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.brand-icon {
    width: 40px;
    height: 40px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 12px;
    box-shadow: 0 0 15px rgba(79, 70, 229, 0.15); /* Subtle glow */
}

.brand-text span {
    display: block;
    color: #fff;
    font-weight: 700;
    font-size: 1.1rem;
    line-height: 1.1;
    letter-spacing: -0.5px;
}

.brand-text small {
    color: var(--accent-pink);
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 1.5px;
    text-transform: uppercase;
}

/* --- Navigation Links --- */
.sidebar-nav {
    padding: 1.5rem 1rem;
}

.nav-label {
    color: #64748b;
    font-size: 0.7rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin: 1.5rem 0 0.5rem 1rem;
}

.sidebar-nav .nav-link {
    color: #94a3b8;
    padding: 0.8rem 1rem;
    margin-bottom: 5px;
    border-radius: 12px;
    font-weight: 500;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
}

.sidebar-nav .nav-link i {
    font-size: 1.2rem;
    margin-right: 12px;
    width: 24px;
    text-align: center;
    transition: transform 0.2s ease;
}

/* Hover State */
.sidebar-nav .nav-link:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.05);
    transform: translateX(5px);
}

.sidebar-nav .nav-link:hover i {
    transform: scale(1.1);
    color: var(--primary-color);
}

/* Active State (Floating Pill) */
.sidebar-nav .nav-link.active {
    background: var(--primary-color);
    color: #fff;
    box-shadow: 0 4px 15px rgba(79, 70, 229, 0.4);
    font-weight: 600;
}

.sidebar-nav .nav-link.active i {
    color: #fff;
}

/* --- Sidebar Footer (Profile) --- */
.sidebar-footer {
    margin-top: auto; /* Push to bottom */
    padding: 1.2rem;
    background: rgba(0, 0, 0, 0.2);
    backdrop-filter: blur(5px);
    border-top: 1px solid rgba(255, 255, 255, 0.05);
}

.user-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.user-avatar {
    width: 42px;
    height: 42px;
    background: linear-gradient(135deg, var(--accent-pink), #ec4899);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-weight: bold;
    border: 2px solid rgba(255, 255, 255, 0.1);
}

.user-details {
    overflow: hidden;
}

.user-name {
    display: block;
    color: #fff;
    font-weight: 600;
    font-size: 0.95rem;
    white-space: nowrap;
}

.user-status {
    display: block;
    color: #10b981; /* Green */
    font-size: 0.75rem;
    font-weight: 500;
}

/* =========================================
   5. MODERN HEADER (GLASSMORPHISM)
   ========================================= */
.navbar {
  height: var(--header-height);
  background: var(--navbar-bg);
  backdrop-filter: blur(12px); /* The "Glass" Effect */
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-color) !important;
  box-shadow: 0 4px 30px rgba(0, 0, 0, 0.03);
  padding: 0 1.5rem;
  position: sticky; /* Keeps header at top */
  top: 0;
  z-index: 900;
  transition: background 0.3s ease;
}

/* Sidebar Toggle */
#sidebarToggle {
  border: none;
  background: transparent;
  color: var(--text-main);
  font-size: 1.4rem;
  padding: 8px;
  border-radius: 50%;
  width: 45px;
  height: 45px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

#sidebarToggle:hover {
  background-color: var(--card-bg);
  color: var(--primary-color);
  box-shadow: 0 2px 5px rgba(0,0,0,0.05);
}

/* Theme Toggle Button */
.theme-toggle-btn {
  background: transparent;
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-right: 15px;
  transition: all 0.2s ease;
}

.theme-toggle-btn:hover {
  background-color: var(--card-bg);
  color: var(--primary-color);
  transform: translateY(-1px);
}

/* Profile Dropdown */
.navbar-nav .nav-link {
  color: var(--text-main);
  font-weight: 500;
  padding: 0.5rem 1rem;
  border-radius: 30px;
  transition: all 0.2s;
}

.navbar-nav .nav-link:hover,
.navbar-nav .nav-link.show {
  background-color: var(--card-bg);
  color: var(--primary-color);
}

.dropdown-menu {
  background-color: var(--card-bg);
  border: 1px solid var(--border-color);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
}

.dropdown-item {
  color: var(--text-main);
}

.dropdown-item:hover {
  background-color: rgba(79, 70, 229, 0.1); /* Light primary bg */
  color: var(--primary-color);
}

.dropdown-divider {
  border-top-color: var(--border-color);
}

/* =========================================
   6. RESPONSIVE BEHAVIOR (FIXED MOBILE TOGGLE)
   ========================================= */

/* --- SHARED TRANSITIONS --- */
/* Add transform to the transition list for smooth sliding */
#sidebar-wrapper, #page-content-wrapper {
    transition: margin-left 0.3s ease-in-out, transform 0.3s ease-in-out;
}

/* ---------------------------------------------------
   DESKTOP LOGIC (Screen > 768px)
   --------------------------------------------------- */
@media (min-width: 768px) {
    
    /* 1. Default: Sidebar OPEN */
    #sidebar-wrapper {
        margin-left: 0;
    }
    #page-content-wrapper {
        margin-left: var(--sidebar-width);
        width: calc(100% - var(--sidebar-width));
    }

    /* 2. Toggled: Sidebar CLOSED */
    /* When wrapper has .toggled, hide sidebar to the left */
    #wrapper.toggled #sidebar-wrapper {
        margin-left: calc(var(--sidebar-width) * -1);
    }
    #wrapper.toggled #page-content-wrapper {
        margin-left: 0;
        width: 100%;
    }
}

/* ---------------------------------------------------
   MOBILE LOGIC (Screen < 768px)
   --------------------------------------------------- */
@media (max-width: 768px) {

    /* 1. Default: Sidebar OPEN (Overlay Mode) */
    /* Note: JS adds .toggled by default on mobile, so this state 
       only happens after you click the button to OPEN it. */
    #sidebar-wrapper {
        margin-left: 0;
        box-shadow: 5px 0 15px rgba(0,0,0,0.1);
        z-index: 1000;
    }

    /* KEY FIX: SLIDE CONTENT RIGHT */
    /* We slide the content (and the button) to the right so the button is not covered */
    #page-content-wrapper {
        margin-left: 0;
        width: 100%;
        transform: translateX(17rem); /* Push content aside */
    }

    /* 2. Toggled: Sidebar CLOSED (Default Mobile State) */
    #wrapper.toggled #sidebar-wrapper {
        margin-left: -17rem; /* Move sidebar off-screen */
    }

    #wrapper.toggled #page-content-wrapper {
        transform: translateX(0); /* Reset content position */
    }
}



/* =========================================
   7. FORM INPUTS & DROPDOWNS (THEME AWARE)
   ========================================= */
.form-control, 
.form-select,
.input-group-text {
  /* Default (Light Mode) - Light Gray Background */
  background-color: #f8fafc; 
  border: 1px solid transparent; /* cleaner look than border-0 */
  color: var(--text-main);
  transition: all 0.2s ease-in-out;
}

/* Dark Mode Override */
[data-bs-theme="dark"] .form-control, 
[data-bs-theme="dark"] .form-select,
[data-bs-theme="dark"] .input-group-text {
  /* Dark Mode - Darker than card, lighter than body */
  background-color: #0f172a; 
  color: #e2e8f0;
  border-color: rgba(255, 255, 255, 0.05);
}

/* Focus States (Glow Effect) */
.form-control:focus, 
.form-select:focus {
  background-color: var(--card-bg); /* Becomes slightly brighter on focus */
  border-color: var(--primary-color);
  box-shadow: 0 0 0 4px rgba(79, 70, 229, 0.1);
}

/* Fix for Dropdown Options in Dark Mode */
option {
  background-color: var(--card-bg);
  color: var(--text-main);
}


/* =========================================
   STICKY FOOTER LOGIC
   ========================================= */
#page-content-wrapper {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

main {
    flex: 1 0 auto; /* This forces main to grow and push footer down */
}

footer {
    flex-shrink: 0; /* Prevents footer from shrinking */
}


/* =========================================
   FORCE STICKY HEADER
   ========================================= */

/* 1. Reset overflow on parents so sticky works */
#wrapper, 
#page-content-wrapper {
    overflow: visible !important; 
}

/* 2. Force the navbar to stick */
.navbar {
    position: -webkit-sticky !important; /* Safari */
    position: sticky !important;
    top: 0;
    z-index: 1020; /* Ensure it stays above content */
    
    /* Optional: Add a shadow when scrolling for better visibility */
    box-shadow: 0 2px 10px rgba(0,0,0,0.05);
}


/* ============================================================
   ROBUST FIXES: STICKY HEADER, ICON COLORS, MOBILE LAYOUT
   ============================================================ */

/* --- 1. FORCE STICKY HEADER --- */
/* We remove overflow constraints on all parent containers. 
   This allows 'position: sticky' to work relative to the viewport. */
html, body, #wrapper, #page-content-wrapper {
    overflow: visible !important;
    height: auto !important; /* Prevents height locking */
}

.navbar {
    position: -webkit-sticky !important;
    position: sticky !important;
    top: 0;
    z-index: 1030; /* Higher index to stay on top of everything */
    width: 100%;
    /* Ensure background is solid so content doesn't show through when scrolling */
    background-color: var(--navbar-bg); 
}

/* --- 2. FIX INVISIBLE PROFILE ICON (Light Mode) --- */
/* When the dropdown is open (.show), Bootstrap might set color to white.
   We force it to dark/primary color in Light Mode so it stays visible. */

/* Target both the link text AND the icon inside it */
.navbar-nav .nav-link.show,
.navbar-nav .nav-link.show i {
    color: var(--primary-color) !important;
    background-color: transparent !important; /* Remove conflicting backgrounds */
}

/* In Dark Mode, keep it light/white */
[data-bs-theme="dark"] .navbar-nav .nav-link.show,
[data-bs-theme="dark"] .navbar-nav .nav-link.show i {
    color: #ffffff !important;
}

/* --- 3. FIX MOBILE HEIGHT EXPANSION --- */
/* Prevent the navbar from growing when a menu is clicked */
.navbar {
    height: var(--header-height) !important; /* Force fixed height */
    min-height: var(--header-height) !important;
    max-height: var(--header-height) !important;
}

/* Force contents to stay in one line (no wrapping) */
.navbar .container-fluid {
    flex-wrap: nowrap !important;
}

/* Ensure the dropdown menu floats properly and doesn't push the navbar open */
.navbar-nav .dropdown-menu {
    position: absolute !important;
    top: 100% !important; /* Push it right below the header */
    right: 0 !important;
    margin-top: 5px !important;
}

/* Prevent User Name text from wrapping on small screens */
.navbar-nav .nav-link {
    white-space: nowrap;
}