/* =========================================
   MODERN SAAS DASHBOARD - BASE STYLES
   ========================================= */

:root {
    /* Brand Colors */
    --primary: #3498db;
    --primary-hover: #2980b9;
    --primary-light: #e1f0fa;
    --secondary: #2c3e50;
    
    /* UI Colors */
    --bg-body: #f3f4f6;
    --bg-surface: #ffffff;
    --bg-sidebar: #1e293b; /* Dark slate sidebar for pro look */
    
    /* Text Colors */
    --text-main: #1f2937;
    --text-muted: #6b7280;
    --text-sidebar: #94a3b8;
    --text-sidebar-hover: #ffffff;
    
    /* Borders & Lines */
    --border-color: #e5e7eb;
    --border-focus: #3498db;
    
    /* Spacing & Sizing */
    --sidebar-width: 260px;
    --header-height: 60px;
    --radius-sm: 4px;
    --radius-md: 6px;
    --radius-lg: 8px;
    
    /* Transitions */
    --transition: all 0.2s ease-in-out;
}

/* RESET & BASE */
* { box-sizing: border-box; outline: none; }
html { font-size: 14px; } /* Reduced base size from 16px to 14px for density */
body {
    margin: 0;
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background-color: var(--bg-body);
    color: var(--text-main);
    line-height: 1.5;
    overflow-x: hidden;
}

a { text-decoration: none; color: inherit; transition: var(--transition); }
ul { list-style: none; padding: 0; margin: 0; }

/* =========================================
   LAYOUT GRID
   ========================================= */
.app-layout {
    display: flex;
    min-height: 100vh;
    height: 100%; /* Ensure full height */
}

/* SIDEBAR */
.app-sidebar {
    width: var(--sidebar-width);
    background-color: var(--bg-sidebar);
    color: var(--text-sidebar);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 50;
    transition: transform 0.3s ease;
}

.sidebar-header {
    height: var(--header-height);
    display: flex;
    align-items: center;
    padding: 0 1.5rem;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

.brand-link {
    display: flex;
    align-items: center;
    color: white;
    font-weight: 600;
    font-size: 1.1rem;
}
.brand-icon { color: var(--primary); margin-right: 0.75rem; }

.sidebar-content { flex: 1; overflow-y: auto; padding: 1.5rem 1rem; }

/* Sidebar Nav */
.nav-label {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #64748b;
    margin: 1.5rem 0 0.5rem 0.75rem;
    font-weight: 600;
}
.nav-label:first-child { margin-top: 0; }

.nav-item {
    display: flex;
    align-items: center;
    padding: 0.6rem 0.75rem;
    margin-bottom: 0.25rem;
    border-radius: var(--radius-md);
    color: var(--text-sidebar);
    font-size: 0.95rem;
}

.nav-item:hover {
    background-color: rgba(255,255,255,0.05);
    color: var(--text-sidebar-hover);
}

.nav-item.active {
    background-color: var(--primary);
    color: white;
}

.nav-icon { width: 20px; margin-right: 0.75rem; text-align: center; }

.sidebar-footer {
    padding: 1rem;
    border-top: 1px solid rgba(255,255,255,0.1);
}

/* MAIN WRAPPER */
.main-wrapper {
    flex: 1;
    margin-left: var(--sidebar-width); /* Push content */
    display: flex;
    flex-direction: column;
    min-height: 100vh; /* Full viewport height */
    width: calc(100% - var(--sidebar-width));
    transition: margin-left 0.3s ease;
}

/* TOP HEADER */
.app-header {
    height: var(--header-height);
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 1.5rem;
    position: sticky;
    top: 0;
    z-index: 40;
}

.header-left, .header-right { display: flex; align-items: center; gap: 1rem; }

.btn-icon {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.1rem;
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 50%;
    transition: var(--transition);
}
.btn-icon:hover { background-color: var(--bg-body); color: var(--primary); }

/* Search Bar */
.search-bar-wrapper {
    position: relative;
    margin-left: 1rem;
}
.search-icon {
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    font-size: 0.9rem;
}
.search-input {
    border: 1px solid var(--border-color);
    background-color: var(--bg-body);
    border-radius: 20px;
    padding: 0.5rem 1rem 0.5rem 2.2rem;
    font-size: 0.9rem;
    width: 250px;
    transition: var(--transition);
}
.search-input:focus {
    background-color: white;
    border-color: var(--border-focus);
    width: 320px;
    box-shadow: 0 0 0 2px var(--primary-light);
}

/* User Profile */
.user-profile-btn {
    background: none;
    border: none;
    display: flex;
    align-items: center;
    cursor: pointer;
    padding: 0.25rem;
}
.avatar-circle {
    width: 32px;
    height: 32px;
    background-color: var(--primary);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.9rem;
    margin-right: 0.5rem;
}

/* CONTENT AREA */
.app-content {
    flex: 1 0 auto; /* Flex grow, don't shrink, auto basis - pushes footer down */
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    min-height: calc(100vh - var(--header-height)); /* Ensure minimum height to push footer */
}

/* Content Container inside app-content */
.content-container {
    flex: 1 0 auto;
    max-width: 1600px; /* Prevent ultra-wide stretching */
    width: 100%;
    margin: 0 auto;
    padding-bottom: 1rem; /* Add space before footer */
}

/* Cards & Containers (For Dashboard Look) */
.card {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--border-color);
}
.card-title { font-size: 1.1rem; font-weight: 600; color: var(--text-main); margin: 0; }

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem 1rem;
    border-radius: var(--radius-md);
    font-weight: 500;
    font-size: 0.9rem;
    cursor: pointer;
    border: 1px solid transparent;
    transition: var(--transition);
}
.btn-primary { background-color: var(--primary); color: white; }
.btn-primary:hover { background-color: var(--primary-hover); }
.btn-sm { padding: 0.25rem 0.75rem; font-size: 0.8rem; }

/* Alerts */
.messages-container { margin-bottom: 1.5rem; }
.alert {
    padding: 0.75rem 1rem;
    border-radius: var(--radius-md);
    margin-bottom: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 0.9rem;
}
.alert-success { background: #def7ec; color: #03543f; }
.alert-error { background: #fde8e8; color: #9b1c1c; }
.alert-info { background: #e1f0fa; color: #1e429f; }
.alert-content { display: flex; align-items: center; gap: 0.5rem; }
.alert-close { background: none; border: none; cursor: pointer; color: inherit; opacity: 0.6; }

/* =========================================
   STICKY FOOTER IMPLEMENTATION
   =========================================
   The footer stays at the bottom of the page
   even when content is minimal. This is achieved
   through a flexbox approach:

   1. .main-wrapper uses flexbox column layout
   2. .app-content has flex: 1 0 auto (grows to fill space)
   3. .app-footer has margin-top: auto (pushed to bottom)
   4. flex-shrink: 0 prevents footer from collapsing

   This ensures the footer is always at the bottom,
   whether the content is short or long.
   ========================================= */
.app-footer {
    margin-top: auto; /* Push to bottom */
    padding: 1.5rem 1.5rem;
    border-top: 1px solid var(--border-color);
    color: var(--text-muted);
    font-size: 0.85rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0; /* Prevent footer from shrinking */
    background: var(--bg-surface);
    width: 100%; /* Ensure footer takes full width */
    position: relative; /* Ensure proper positioning */
}

.footer-links {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.footer-links a {
    color: var(--text-muted);
    transition: color 0.2s;
}

.footer-links a:hover {
    color: var(--primary);
}

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

.footer-copyright {
    color: var(--text-muted);
}

/* UTILITIES */
.d-none { display: none; }
.d-md-block { display: block; } /* Adjust via media queries below */
.text-xs { font-size: 0.75rem; }
.ml-2 { margin-left: 0.5rem; }
.font-bold { font-weight: 600; }
.text-muted { color: var(--text-muted); }
.text-danger { color: #dc2626; }

/* =========================================
   RESPONSIVE DESIGN
   ========================================= */
@media (max-width: 992px) {
    /* Tablet/Mobile: Sidebar Hidden by Default */
    .app-sidebar { transform: translateX(-100%); }
    .app-sidebar.show { transform: translateX(0); box-shadow: 4px 0 10px rgba(0,0,0,0.1); }
    
    .main-wrapper { margin-left: 0; width: 100%; }
    
    .sidebar-close-btn {
        background: none; border: none; color: white; font-size: 1.2rem;
        margin-left: auto; cursor: pointer;
    }
    
    /* Adjust Header */
    .search-input { width: 160px; }
    .search-input:focus { width: 200px; }
}

@media (max-width: 576px) {
    /* Mobile specific */
    .search-bar-wrapper { display: none; } /* Hide search on small mobile or move to dropdown */
    .app-content { padding: 1rem; }
    .d-md-block { display: none; }

    /* Footer responsive */
    .app-footer {
        flex-direction: column;
        gap: 0.75rem;
        text-align: center;
        padding: 1rem;
    }

    .footer-links {
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: center;
    }
}


/* Additions for JS interactivity */
.dropdown-menu {
    position: absolute;
    top: 100%;
    right: 0;
    width: 220px;
    background: white;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    padding: 0.5rem 0;
    display: none; /* Hidden by default */
    z-index: 100;
}
.dropdown-menu.show { display: block; animation: fadeIn 0.2s; }
.dropdown-item {
    display: block;
    padding: 0.5rem 1rem;
    color: var(--text-main);
    font-size: 0.9rem;
}
.dropdown-item:hover { background-color: var(--bg-body); color: var(--primary); }
.dropdown-divider { border-top: 1px solid var(--border-color); margin: 0.5rem 0; }

/* Mobile Overlay */
.sidebar-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 45;
    opacity: 0;
    visibility: hidden;
    transition: var(--transition);
}
.sidebar-overlay.active { opacity: 1; visibility: visible; }

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

/* Hide sidebar close X on desktop */
@media (min-width: 992px) {
  .sidebar-close-btn {
    display: none;
  }
}

/* Desktop collapsed sidebar behavior */
.app-sidebar.collapsed {
  width: 72px;
}

.app-sidebar.collapsed .brand-text,
.app-sidebar.collapsed .nav-text,
.app-sidebar.collapsed .nav-label,
.app-sidebar.collapsed .sidebar-footer {
  display: none;
}

.main-wrapper.expanded {
  margin-left: 72px;
  width: calc(100% - 72px);
}

/* User menu dropdown */
.user-menu {
  padding: 0.4rem 0;
  border-radius: 10px;
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.15);
  border: 1px solid var(--border-color);
}

/* Header: “Signed in as …” */
.user-menu .dropdown-header {
  padding: 0.6rem 1rem 0.5rem;
  background: linear-gradient(135deg, var(--primary-light), #ffffff);
  border-bottom: 1px solid var(--border-color);
}

.user-menu .dropdown-header .text-xs {
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.user-menu .dropdown-header .font-bold {
  font-size: 0.9rem;
  color: var(--secondary);
}

/* Items with icons */
.user-menu .dropdown-item {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.55rem 1rem;
  font-size: 0.9rem;
}

.user-menu .dropdown-item i {
  width: 16px;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.95rem;
}

.user-menu .dropdown-item:hover {
  background-color: var(--bg-body);
  color: var(--primary);
}

.user-menu .dropdown-item.text-danger {
  color: var(--text-danger);
}

.user-menu .dropdown-item.text-danger:hover {
  background-color: #fef2f2;
}

/* Divider spacing */
.user-menu .dropdown-divider {
  margin: 0.35rem 0;
}

/* Add these to your existing base.css if not present */

/* Utility Classes */
.mb-3 { margin-bottom: 1rem; }
.text-center { text-align: center; }

/* Alert base styles (if not in base.css) */
.alert {
    padding: 1rem;
    border-radius: var(--radius-md);
    margin-bottom: 1rem;
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
}

.alert-success {
    background: #def7ec;
    color: #03543f;
    border: 1px solid #bcf0da;
}

.alert-error {
    background: #fde8e8;
    color: #9b1c1c;
    border: 1px solid #fbd5d5;
}

.alert-info {
    background: #e1f0fa;
    color: #1e429f;
    border: 1px solid #c3ddfd;
}

.alert-content {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex: 1;
}

.alert-close {
    background: none;
    border: none;
    cursor: pointer;
    color: inherit;
    opacity: 0.7;
    padding: 0.25rem;
    border-radius: 4px;
}

.alert-close:hover {
    opacity: 1;
    background: rgba(0, 0, 0, 0.1);
}

/* Form base styles */
.form-control {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: 1rem;
    transition: var(--transition);
    background-color: var(--bg-surface);
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px var(--primary-light); 
}

.invalid-feedback {
    display: block;
    width: 100%;
    margin-top: 0.25rem;
    font-size: 0.875rem;
    color: #dc2626;
}

.form-text {
    display: block;
    margin-top: 0.25rem;
    font-size: 0.875rem;
    color: var(--text-muted);
}
