/* ==========================================================================
   Base CSS - Core Foundation
   ========================================================================== */

/* 1. CSS Variables & Root Settings
   ========================================================================== */
:root {
    /* Z-index Layers - Organized hierarchy */
    --z-base: 1;
    --z-content: 10;
    --z-sidebar: 800;
    --z-navbar: 1000;
    --z-sidebar-overlay: 1050;  /* Mobile sidebar overlay - lower than modals */
    --z-modal: 1100;  /* Bootstrap modal default */
    --z-dropdown: 1200;  /* Dropdowns above modals */
    --z-toast: 1300;  /* Toast notifications */
    --z-tooltip: 1400;  /* Tooltips highest */
    
    /* Layout Measurements */
    --navbar-height: 144px;
    --sidebar-width: 280px;
    --sidebar-collapsed-width: 80px;

    /* Primary Theme Colors */
    --primary-color: #000000;
    --primary-text: #ffffff;  /* Text color for primary backgrounds */
    
    /* Light Theme Colors */
    --light-bg: #ffffff;
    --light-text: #333333;
    --light-content-bg: #f5f5f5;  /* Light gray for light mode */
    --light-border: #e0e0e0;
    
    /* Dark Theme Colors */
    --dark-bg: #1e1e1e;
    --dark-text: #ffffff;
    --dark-content-bg: #121212;   /* Darker shade for dark mode */
    --dark-border: #404040;
    
    /* Auto-contrast text colors */
    --text-on-light: #000000;  /* Black text for light backgrounds */
    --text-on-dark: #ffffff;   /* White text for dark backgrounds */
    
    /* Surface Colors */
    --surface-color: #ffffff;
    --surface-text: var(--text-on-light);  /* Auto black text on light surface */
    --text-color: #333333;
    --border-color: #e0e0e0;
    --hover-color: #f5f5f5;
    --input-bg: #ffffff;
    
    /* Shadows */
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 4px 6px rgba(0, 0, 0, 0.1);
    
    /* Status Colors */
    --success-color: #28a745;
    --danger-color: #dc3545;
    --warning-color: #ffc107;
    --info-color: #17a2b8;
    --text-muted: #6c757d;
    
    /* Input Colors */
    --light-input-bg: #ffffff;
    --dark-input-bg: #1e1e1e;
    --dark-card-bg: #2d2d2d;

    /* Dropdown Colors */
    --dropdown-bg: var(--primary-color);
    --dropdown-text: var(--primary-text);
    --dropdown-hover-bg: rgba(255, 255, 255, 0.2);
    --dropdown-hover-text: var(--primary-text);
    --dropdown-active-bg: rgba(255, 255, 255, 0.3);
    --dropdown-active-text: var(--primary-text);

    /* Button Colors */
    --btn-primary-bg: var(--primary-color);
    --btn-primary-border: var(--primary-color);
    --btn-primary-color: var(--primary-text);
}

/* 2. Font Imports & Base Typography
   ========================================================================== */
@import url('https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,100;0,300;0,400;0,500;0,700;0,900;1,400&display=swap');

/* Base Typography */
body {
    font-family: 'Roboto', sans-serif;
    font-weight: 400;
    line-height: 1.6;
    margin: 0;
    padding: 0;
    min-height: 100vh;
    background-color: var(--light-bg);
    color: var(--light-text);
}

/* Typography Scale */
h1, h2, h3, h4, h5, h6 {
    font-family: 'Roboto', sans-serif;
    margin-bottom: 1rem;
    line-height: 1.2;
}

h1 {
    font-size: 2.5rem;
    font-weight: 700;
    letter-spacing: -0.5px;
}

h2 {
    font-size: 2rem;
    font-weight: 500;
    letter-spacing: -0.3px;
}

h3 {
    font-size: 1.75rem;
    font-weight: 500;
}

h4 {
    font-size: 1.5rem;
    font-weight: 500;
}

h5 {
    font-size: 1.25rem;
    font-weight: 500;
}

h6 {
    font-size: 1rem;
    font-weight: 500;
}

/* Text Elements */
p {
    margin-bottom: 1rem;
    line-height: 1.6;
}

.text-small {
    font-size: 0.875rem;
}

.text-large {
    font-size: 1.125rem;
}

/* 3. Core Layout Structure
   ========================================================================== */

/* App Container */
.app-container {
    position: relative;
    min-height: 100vh;
    padding-top: var(--navbar-height);
    width: 100%;
    overflow-x: hidden;
}

/* Main Wrapper */
.wrapper {
    display: flex;
    width: 100%;
    position: relative;
}

/* Content Wrapper */
.content-wrapper {
    position: relative;
    width: 100%;
    min-height: calc(100vh - var(--navbar-height));
    overflow-x: hidden;
    z-index: var(--z-content);
    pointer-events: auto;
    margin-left: var(--sidebar-width);
    width: calc(100% - var(--sidebar-width));
    transition: margin-left 0.3s ease, width 0.3s ease;
}

.content-wrapper.full-width {
    margin-left: 0;
    width: 100%;
}

/* Content Main */
.content-main {
    position: relative;
    width: 100%;
    height: 100%;
    overflow-x: hidden;
}

/* Main Content Area */
#content {
    background-color: var(--light-content-bg);
    color: var(--light-text);
    position: relative;
    z-index: var(--z-content);
    margin-top: 0;
    margin-left: var(--sidebar-width);
    min-height: calc(100vh - var(--navbar-height));
    padding: 2rem;
    box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.05);
    width: calc(100% - var(--sidebar-width));
    transition: margin-left 0.3s ease, width 0.3s ease;
}

#content.full-width {
    margin-left: 0;
    width: 100%;
}

/* Container Utilities */
.container-fluid {
    display: flex;
    align-items: center;
    width: 100%;
    padding: 0 1rem;
}

/* 4. Dark Theme Base Adjustments
   ========================================================================== */
body.dark-theme {
    background-color: #000000 !important;
    color: var(--dark-text);
    
    /* Update dark theme variables */
    --surface-color: #2d2d2d;
    --surface-text: var(--text-on-dark);
    --text-color: #ffffff;
    --border-color: #404040;
    --hover-color: #3d3d3d;
    --input-bg: #1e1e1e;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 4px 6px rgba(0, 0, 0, 0.3);
    --text-muted: #a0a0a0;
    
    /* Add dark theme specific colors */
    --dark-sidebar-bg: #121212;  /* Darker black for sidebar */
    --dark-navbar-bg: #121212;   /* Darker black for navbar */

    /* Update link colors for dark theme */
    --bs-link-color: var(--primary-text);
    --bs-link-hover-color: var(--primary-text);
}

body.dark-theme #wrapper,
body.dark-theme #content {
    background-color: #000000 !important;
    color: var(--dark-text);
}

body.dark-theme main,
body.dark-theme .content-wrapper,
body.dark-theme .content-wrapper.unauthenticated {
    background-color: #000000 !important;
}



/* 5. Responsive Base Adjustments
   ========================================================================== */

/* Mobile Adjustments */
@media (max-width: 767px) {
    /* iOS Safari viewport height fix */
    .app-container {
        padding-top: 60px; /* Smaller navbar on mobile */
        min-height: 100vh;
        min-height: calc(var(--vh, 1vh) * 100);
    }
    
    .content-wrapper {
        margin-left: 0 !important;
        width: 100% !important;
        transition: none;
    }
    
    #content {
        margin-left: 0 !important;
        width: 100% !important;
        padding: 1rem;
        padding-bottom: 90px; /* Extra space for mobile bottom nav */
        transition: none;
    }
    
    /* Prevent content from being affected by sidebar */
    body.sidebar-open .content-wrapper,
    body.sidebar-open #content {
        margin-left: 0 !important;
        width: 100% !important;
    }
    
    /* Typography adjustments */
    h1 {
        font-size: 2rem;
    }
    
    h2 {
        font-size: 1.75rem;
    }
    
    h3 {
        font-size: 1.5rem;
    }
}

/* Tablet Adjustments */
@media (max-width: 991px) {
    .content-wrapper {
        margin-left: var(--sidebar-collapsed-width);
        width: calc(100% - var(--sidebar-collapsed-width));
    }
    
    #content {
        margin-left: var(--sidebar-collapsed-width);
        width: calc(100% - var(--sidebar-collapsed-width));
        padding: 1.5rem;
    }
}

/* Print Styles */
@media print {
    .app-container {
        padding-top: 0;
    }
    
    .content-wrapper,
    #content {
        margin-left: 0 !important;
        width: 100% !important;
        padding: 0 !important;
        box-shadow: none !important;
        background: white !important;
        color: black !important;
    }
}
