/* ==========================================================================
   1. RESET & BASE VARIABLES
   ========================================================================== */
:root {
    --bg-main: #f4f6f9;
    --bg-surface: #ffffff;
    --border-color: #e2e8f0;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --header-height: 60px;
    --sidebar-width: 240px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, sans-serif;
}

body {
    background-color: var(--bg-main);
    color: var(--text-primary);
    line-height: 1.5;
}

/* ==========================================================================
   2. MAIN LAYOUT STRUCTURE
   ========================================================================== */
.app-layout {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.app-body {
    display: flex;
    flex: 1;
}

/* ==========================================================================
   3. HEADER STYLES
   ========================================================================== */
.app-header {
    height: var(--header-height);
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.brand-logo {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--primary);
    text-decoration: none;
}

.mobile-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 1.25rem;
    cursor: pointer;
    color: var(--text-primary);
}

.header-nav {
    display: flex;
    align-items: center;
    gap: 1.25rem;
}

.header-link {
    text-decoration: none;
    color: var(--text-secondary);
    font-size: 0.9rem;
    transition: color 0.2s;
}

.header-link:hover {
    color: var(--text-primary);
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background-color: var(--primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: bold;
}

/* ==========================================================================
   4. SIDEBAR STYLES
   ========================================================================== */
.app-sidebar {
    width: var(--sidebar-width);
    background: var(--bg-surface);
    border-right: 1px solid var(--border-color);
    padding: 1.5rem 1rem;
    flex-shrink: 0;
}

.sidebar-menu {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.menu-group ul {
    list-style: none;
    margin-top: 0.5rem;
}

.menu-heading {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    font-weight: 700;
    padding-left: 0.75rem;
}

.menu-item {
    display: block;
    padding: 0.5rem 0.5rem;
    color: var(--text-secondary);
    text-decoration: none;
    border-radius: 6px;
    font-size: 0.9rem;
    font-weight: 500;
    transition: all 0.2s;
}

.menu-item:hover,
.menu-item.active {
    background-color: #eff6ff;
    color: var(--primary);
}

.menu-item.logout {
    color: #ef4444;
}

.menu-item.logout:hover {
    background-color: #fee2e2;
}

/* ==========================================================================
   5. DASHBOARD & MAIN CONTENT
   ========================================================================== */
.app-content {
    flex: 1;
    padding: 2rem;
    overflow-x: hidden;
}

.content-header {
    margin-bottom: 1.5rem;
}

.content-header h1 {
    font-size: 1.5rem;
    font-weight: 600;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 0.875rem;
}

/* Stats Cards */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 1.25rem;
}

.stat-card h3 {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
}

.stat-value {
    font-size: 1.5rem;
    font-weight: 700;
}

.stat-change {
    font-size: 0.8rem;
    font-weight: 500;
}

.stat-change.positive { color: #16a34a; }
.stat-change.negative { color: #dc2626; }
.stat-change.neutral { color: var(--text-secondary); }

/* Content Card & Table */
.content-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 1.5rem;
}

.content-card h2 {
    font-size: 1.15rem;
    margin-bottom: 1rem;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
    font-size: 0.9rem;
}

.data-table th,
.data-table td {
    padding: 0.75rem;
    border-bottom: 1px solid var(--border-color);
}

.data-table th {
    color: var(--text-secondary);
    font-weight: 600;
}

.badge {
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
}

.badge.success { background: #dcfce7; color: #16a34a; }
.badge.warning { background: #fef9c3; color: #ca8a04; }
.badge.danger { background: #fee2e2; color: #dc2626; }

/* ==========================================================================
   6. FOOTER STYLES
   ========================================================================== */
.app-footer {
    background: var(--bg-surface);
    border-top: 1px solid var(--border-color);
    padding: 1rem 1.5rem;
    text-align: center;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

/* ==========================================================================
   7. RESPONSIVE MEDIA QUERIES
   ========================================================================== */
@media (max-width: 768px) {
    .mobile-toggle {
        display: block;
    }

    .brand-logo {
      font-size: 1rem;
    }

    .app-body {
        position: relative;
    }

    .app-sidebar {
        position: absolute;
        top: 0;
        left: -100%;
        bottom: 0;
        height: 100%;
        z-index: 50;
        transition: left 0.3s ease;
        box-shadow: 2px 0 8px rgba(0,0,0,0.05);
    }

    .app-sidebar.open {
        left: 0;
    }

    .app-content {
        padding: 1rem;
    }

    .stats-grid {
        grid-template-columns: 1fr;
    }

    .user-name {
        display: none;
    }
}