:root {
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --bg-body: #f3f4f6;
    --bg-surface: #ffffff;
    --text-main: #1f2937;
    --text-muted: #6b7280;
    --border-color: #e5e7eb;
    --sidebar-width: 260px;
    --radius: 8px;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-body);
    color: var(--text-main);
}

/* --- Layout --- */
.app-layout {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* --- Sidebar --- */
.sidebar {
    width: var(--sidebar-width);
    background-color: var(--bg-surface);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    transition: transform 0.3s ease;
}

.sidebar-header {
    height: 70px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    border-bottom: 1px solid var(--border-color);
}

.text-primary { color: var(--primary); }
.close-sidebar-btn { display: none; background: none; border: none; font-size: 1.2rem; cursor: pointer;}

.sidebar-nav {
    padding: 20px 0;
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.sidebar {
    height: 100vh; /* 1. Force the sidebar to be exactly the height of the screen */
    height: 100dvh; /* Modern fallback for mobile browsers with hiding address bars */
    display: flex;
    flex-direction: column;
}

.sidebar-nav {
    flex: 1; /* 2. Tell the nav to fill all the space under the header */
    overflow-y: auto; /* 3. Enable vertical scrolling! */
    padding-bottom: 80px; /* 4. Add a buffer so the last item isn't hugging the bottom edge */
    -webkit-overflow-scrolling: touch; /* 5. Make scrolling buttery smooth on iPhones */
}

/* Optional: Make the scrollbar thin and elegant so it doesn't look clunky */
.sidebar-nav::-webkit-scrollbar {
    width: 4px;
}

.sidebar-nav::-webkit-scrollbar-thumb {
    background: #cbd5e1; 
    border-radius: 4px;
}

.nav-link {
    text-decoration: none;
    color: var(--text-muted);
    padding: 12px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    font-weight: 500;
    transition: all 0.2s;
}

.nav-link:hover, .nav-link.active {
    background-color: #eff6ff;
    color: var(--primary);
    border-right: 3px solid var(--primary);
}

/* --- Main Wrapper & Header --- */
.main-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

.top-header {
    height: 70px;
    background-color: var(--bg-surface);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 30px;
    position: sticky;
    top: 0;
    z-index: 10;
}

.menu-toggle-btn { display: none; background: none; border: none; font-size: 1.2rem; cursor: pointer; color: var(--text-main); }
.header-title { font-size: 1.25rem; font-weight: 600; }
.user-profile { display: flex; align-items: center; gap: 10px; font-weight: 500; }
.avatar { width: 35px; height: 35px; background-color: var(--primary); color: white; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-weight: bold; }

/* --- Content Area & General Components --- */
.content-area { padding: 30px; }

.card {
    background: var(--bg-surface);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
    margin-bottom: 20px;
}

/* --- Tables --- */
.table-responsive { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; text-align: left; }
th, td { padding: 12px 15px; border-bottom: 1px solid var(--border-color); }
th { background-color: #f9fafb; font-weight: 600; color: var(--text-muted); }
tbody tr:hover { background-color: #f9fafb; }

/* --- Forms & Buttons --- */
.form-group { margin-bottom: 15px; }
.form-group label { display: block; margin-bottom: 5px; font-weight: 500; font-size: 0.9rem; }
.form-control {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-family: inherit;
    font-size: 1rem;
    transition: border-color 0.2s;
}
.form-control:focus { outline: none; border-color: var(--primary); }

.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-weight: 500;
    font-size: 0.95rem;
    transition: background 0.2s;
}
.btn-primary { background-color: var(--primary); color: white; }
.btn-primary:hover { background-color: var(--primary-hover); }
.btn-header-action { float: right; margin-top: -5px; }

/* --- Grid for Dashboards --- */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
    margin-bottom: 20px;
}

/* --- Mobile Responsiveness --- */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        height: 100%;
        z-index: 1000;
        transform: translateX(-100%);
    }
    .sidebar.open { transform: translateX(0); }
    .close-sidebar-btn, .menu-toggle-btn { display: block; }
    .top-header { padding: 0 15px; }
    .content-area { padding: 15px; }
}

/* ==========================================
   MOBILE TYPOGRAPHY FIXES
   ========================================== */
@media (max-width: 768px) {
    #pageTitle { font-size: 1.25rem !important; }
    h1 { font-size: 1.5rem !important; }
    h2 { font-size: 1.25rem !important; }
    h3 { font-size: 1.1rem !important; }
    h4 { font-size: 1rem !important; }
    .card { padding: 15px !important; }
    
    /* Ensure tables don't break boundaries */
    .table-responsive { 
        width: 100%; 
        overflow-x: auto; 
        -webkit-overflow-scrolling: touch;
    }
}

/* ==========================================
   REUSABLE TAB SYSTEM
   ========================================== */
.app-tab-nav {
    display: flex; gap: 10px; border-bottom: 2px solid #e2e8f0; margin-bottom: 20px; overflow-x: auto;
}
.app-tab-btn {
    padding: 10px 20px; background: transparent; border: none; border-bottom: 3px solid transparent; 
    color: #64748b; font-weight: 500; cursor: pointer; font-size: 0.95rem; white-space: nowrap; 
    transition: all 0.2s ease-in-out;
}
.app-tab-btn:hover {
    color: #3b82f6;
}
.app-tab-btn.active {
    border-bottom: 3px solid #2563eb; color: #1e293b; font-weight: 600;
}
.app-tab-pane {
    display: none; animation: fadeIn 0.3s ease;
}
.app-tab-pane.active {
    display: block;
}
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(5px); }
    to { opacity: 1; transform: translateY(0); }
}