:root {
    --primary-color: #4f46e5;
    --primary-dark: #4338ca;
    --secondary-color: #06b6d4;
    --accent-color: #8b5cf6;
    --bg-color: #f3f4f6;
    --card-bg: #ffffff;
    --text-color: #1f2937;
    --text-light: #6b7280;
    --success: #10b981;
    --danger: #ef4444;
    --gradient-main: linear-gradient(135deg, #4f46e5 0%, #06b6d4 100%);
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --radius-md: 0.5rem;
    --radius-lg: 1rem;

    /* Admin Specific */
    --admin-dark: #0f172a;
    --admin-card: rgba(255, 255, 255, 0.8);
    --admin-bg: #f1f5f9;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    line-height: 1.6;
    min-height: 100vh;
}

h1, h2, h3, h4, h5, h6 {
    line-height: 1.2;
    margin-bottom: 1rem;
    color: #111827;
}

a {
    text-decoration: none;
    color: var(--primary-color);
    transition: color 0.3s ease;
}

a:hover {
    color: var(--primary-dark);
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
}

/* Auth Pages (Login/Register) */
.auth-wrapper {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    background: var(--gradient-main);
    padding: 20px;
}

.auth-card {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    padding: 2.5rem;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 450px;
}

.auth-header {
    text-align: center;
    margin-bottom: 2rem;
}

.auth-header h2 {
    font-size: 2rem;
    color: var(--primary-dark);
}

.auth-header p {
    color: var(--text-light);
}

.form-group {
    margin-bottom: 1.5rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: var(--text-color);
}

.form-control {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 1px solid #d1d5db;
    border-radius: var(--radius-md);
    font-size: 1rem;
    transition: all 0.3s ease;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.btn {
    display: inline-block;
    padding: 0.75rem 1.5rem;
    border-radius: var(--radius-md);
    font-weight: 600;
    text-align: center;
    cursor: pointer;
    border: none;
    transition: all 0.3s ease;
}

.btn-primary {
    background: var(--gradient-main);
    color: white;
    width: 100%;
}

.btn-primary:hover {
    opacity: 0.9;
    transform: translateY(-1px);
}

.auth-footer {
    text-align: center;
    margin-top: 1.5rem;
    font-size: 0.9rem;
    color: var(--text-light);
}

/* Dashboard Layout */
.dashboard-layout {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 260px;
    background: white;
    box-shadow: var(--shadow-md);
    position: fixed;
    height: 100vh;
    left: 0;
    top: 0;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    max-height: 100vh;
}

/* Keep the sidebar scrollable on mobile while hidden backdrop does not block pointer events */
.sidebar-header {
    padding: 1.5rem;
    border-bottom: 1px solid #f3f4f6;
}

.logo {
    font-size: 1.5rem;
    font-weight: 800;
    background: var(--gradient-main);
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.nav-links {
    flex: 1 1 auto;
    padding: 1.5rem 1rem;
    list-style: none;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

.nav-item {
    margin-bottom: 0.5rem;
}

.nav-link {
    display: flex;
    align-items: center;
    padding: 0.75rem 1rem;
    color: var(--text-light);
    border-radius: var(--radius-md);
    font-weight: 500;
}

.nav-link:hover, .nav-link.active {
    background-color: #eef2ff;
    color: var(--primary-color);
}

.nav-icon {
    margin-right: 0.75rem;
}

.user-profile {
    padding: 1rem;
    border-top: 1px solid #f3f4f6;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
    flex-shrink: 0;
    text-align: center;
    min-height: 120px;
    margin-top: auto;
}

.avatar-circle {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--primary-color), #667eea);
    color: white;
}

.user-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
}

.user-name {
    font-size: 0.85rem;
    font-weight: 700;
    color: #1e293b;
    margin-bottom: 0.25rem;
    word-break: break-word;
}

.text-sm {
    font-size: 0.75rem;
}

.text-danger {
    color: #dc2626;
    text-decoration: none;
    font-weight: 600;
    transition: color 0.3s ease;
    display: inline-block;
    margin-top: 0.5rem;
}

.text-danger:hover {
    color: #991b1b;
}

.main-content {
    margin-left: 260px;
    flex: 1;
    padding: 2rem;
}

.page-header {
    margin-bottom: 2rem;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: white;
    padding: 1.5rem;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    border: 1px solid #f3f4f6;
}

.stat-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--primary-color);
    margin: 0.5rem 0;
}

.stat-label {
    color: var(--text-light);
    font-size: 0.9rem;
}

.card {
    background: white;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th, td {
    padding: 1rem;
    text-align: left;
    border-bottom: 1px solid #f3f4f6;
}

th {
    font-weight: 600;
    color: var(--text-light);
    background-color: #f9fafb;
}

.badge {
    padding: 0.25rem 0.75rem;
    border-radius: 1rem;
    font-size: 0.75rem;
    font-weight: 600;
}

.badge-success { background: #d1fae5; color: #065f46; }
.badge-warning { background: #fef3c7; color: #92400e; }

/* Admin Portal Refinement */
.admin-body {
    background-color: var(--admin-bg);
}

.admin-sidebar {
    background-color: var(--admin-dark);
    color: white;
}

.admin-sidebar .logo {
    background: white;
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.admin-sidebar .nav-link {
    color: #94a3b8;
}

.admin-sidebar .nav-link:hover, .admin-sidebar .nav-active {
    background: rgba(255, 255, 255, 0.1);
    color: white;
}

.admin-stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 2rem;
}

.admin-stat-card {
    background: white;
    padding: 2rem;
    border-radius: 1.5rem;
    box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    border: 1px solid rgba(226, 232, 240, 0.8);
    position: relative;
    overflow: hidden;
    transition: transform 0.3s ease;
}

.admin-stat-card:hover {
    transform: translateY(-5px);
}

.admin-stat-card::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 4px;
    height: 100%;
    background: var(--admin-primary);
}

/* Mobile Header - Hidden by default, visible only on mobile */
.mobile-header {
    display: none;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    background: white;
    box-shadow: var(--shadow-sm);
    position: relative;
    z-index: 999;
}

.mobile-header .logo {
    font-size: 1.25rem;
    font-weight: 800;
    color: var(--primary-color);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.menu-toggle {
    font-size: 1.5rem;
    color: var(--text-color);
    cursor: pointer;
    background: none;
    border: none;
    padding: 0.5rem;
    transition: color 0.2s ease;
}

.menu-toggle:active, .menu-toggle:focus {
    color: var(--primary-color);
    outline: none;
}

/* Hidden backdrop should not capture clicks until the sidebar is open */
.sidebar-backdrop {
    display: none !important;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
    transition: opacity 0.25s ease, visibility 0.25s ease;
}

body.sidebar-open .sidebar-backdrop {
    display: block !important;
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

/* Mobile responsiveness for screens below 750px */
@media (max-width: 750px) {
    .mobile-header { 
        display: flex !important;
    }
    
    .sidebar { 
        position: fixed !important;
        left: 0;
        top: 0;
        width: 280px;
        height: 100vh;
        z-index: 1001 !important;
        transform: translateX(-100%);
        transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
    }
    
    .sidebar.active { 
        transform: translateX(0) !important;
    }
    
    .main-content { 
        margin-left: 0 !important; 
        padding: 1rem; 
        width: 100%;
    }
    
    .dashboard-layout { 
        flex-direction: column; 
    }
    
    .nav-links { 
        padding: 1rem 0.75rem; 
    }
    
    .user-profile { 
        flex-direction: column; 
        gap: 0.75rem; 
        align-items: center; 
        text-align: center;
        padding: 1rem;
    }
    
    .avatar-circle { 
        width: 40px; 
        height: 40px; 
    }

    /* Grid stacking */
    .stats-grid { grid-template-columns: 1fr !important; }
    .admin-stat-grid { grid-template-columns: 1fr !important; }
    .micro-card-grid { grid-template-columns: 1fr !important; }
    .glass-card-grid { grid-template-columns: 1fr !important; }
    .stat-card { padding: 1rem; }
    .admin-stat-card { padding: 1rem; }
    .card { padding: 1rem; }

    /* Tables and lists scroll horizontally */
    table { display: block; width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
    th, td { padding: 0.6rem; font-size: 0.85rem; }

    /* Reduce oversized stat values */
    .stat-value { font-size: 1.6rem !important; }

    /* Buttons full width on narrow screens */
    .btn { width: 100%; display: block; margin: 0.5rem 0; }
    .btn-primary { width: 100%; display: block; }
    .btn-ghost { width: 100%; display: block; }

    /* Hero / Index adjustments */
    .hero { grid-template-columns: 1fr !important; gap: 20px !important; padding: 28px 0 36px !important; }
    .hero-left h1 { font-size: 2rem !important; }
    .lead { font-size: 1rem !important; max-width: 100% !important; }

    /* Admin wrapper fluid */
    .admin-wrapper { max-width: 100% !important; padding: 0 12px !important; }

    /* Icon stacks */
    .admin-tool-grid { grid-template-columns: 1fr !important; }
}

/* Desktop-only overrides (screens 751px and above) */
@media (min-width: 751px) {
    .mobile-header { 
        display: none !important;
    }
    
    .sidebar {
        position: fixed !important;
        left: 0;
        top: 0;
        width: 260px;
        height: 100vh;
        z-index: 1000;
        transform: translateX(0) !important;
    }
    
    .sidebar-backdrop {
        display: none !important;
    }
    
    .main-content {
        margin-left: 260px !important;
        padding: 2rem !important;
    }
    
    .dashboard-layout {
        flex-direction: row;
    }
}

/* Utility two-column grid used in admin pages */
.two-column-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2.5rem;
}
@media (max-width: 750px) {
    .two-column-grid { grid-template-columns: 1fr !important; display: block !important; }
}

.admin-stat-icon {
    position: absolute;
    right: 1.5rem;
    top: 1.5rem;
    font-size: 2.5rem;
    opacity: 0.1;
    color: var(--admin-dark);
}

.admin-tool-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 1.5rem;
}

.admin-tool-card {
    background: white;
    padding: 1.5rem;
    border-radius: 1.25rem;
    border: 1px solid #e2e8f0;
    display: flex;
    align-items: center;
    gap: 1.25rem;
    transition: all 0.2s ease;
}

.admin-tool-card:hover {
    border-color: var(--primary-color);
    box-shadow: var(--shadow-md);
    background: #f8fafc;
}

.admin-tool-icon {
    width: 56px;
    height: 56px;
    background: #f1f5f9;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--admin-dark);
    font-size: 1.25rem;
}

.admin-tool-card:hover .admin-tool-icon {
    background: var(--primary-color);
    color: white;
}

/* --- Mobile Responsiveness --- */
.mobile-header {
    display: none;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    background: white;
    box-shadow: var(--shadow-sm);
    position: sticky;
    top: 0;
    z-index: 1001;
}

.menu-toggle {
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-color);
    padding: 0.5rem;
    border-radius: 0.5rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    touch-action: manipulation;
}

@media screen and (max-width: 768px) {
    .dashboard-layout {
        flex-direction: column;
    }
    
    .mobile-header {
        display: flex;
    }

    .sidebar {
        transform: translateX(-100%);
        transition: transform 0.3s ease-in-out;
        width: 280px;
        box-shadow: 2px 0 10px rgba(0,0,0,0.1);
    }

    .container {
        padding: 0 1rem;
    }

    .main-content {
        padding: 1rem;
    }

    .card, .admin-stat-card, .admin-tool-card {
        margin-bottom: 1rem;
    }

    .btn-block, .btn-full {
        width: 100%;
    }

    .form-control,
    .form-group input,
    .form-group select,
    .form-group textarea,
    .card-header,
    .card-footer {
        width: 100%;
    }

    .page-header {
        margin-bottom: 1.5rem;
    }

    .table-responsive {
        overflow-x: auto;
    }

    .sidebar {
        position: fixed;
        height: 100vh;
        top: 0;
        left: 0;
        width: min(280px, 100%);
        max-width: 280px;
    }

    .nav-links {
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    .main-content {
        margin-left: 0;
        padding: 1rem;
        width: 100%;
        overflow-x: hidden;
    }

    .stats-grid, .admin-stat-grid, .admin-tool-grid {
        grid-template-columns: 1fr;
    }

    .card, .admin-stat-card, .admin-tool-card {
        padding: 1rem;
    }
    
    table {
        display: block;
        overflow-x: auto;
        white-space: nowrap;
    }
    
    .row {
        flex-direction: column;
    }
    
    .form-group input, .form-group select, .form-group textarea {
        width: 100%;
    }
    
    /* Wizard Overrides for all generator files */
    .break-row, .topic-row, .lesson-row {
        grid-template-columns: 1fr !important;
        gap: 0.5rem !important;
    }
    
    .wizard-footer {
        flex-direction: column !important;
        gap: 1rem !important;
        padding: 1rem !important;
    }
    
    .btn-wizard {
        width: 100% !important;
        justify-content: center !important;
    }
    
    .progress-bar {
        padding: 1rem !important;
        overflow-x: auto !important;
        gap: 0.5rem !important;
    }
    
    .step-label, .step-name {
        display: none !important;
    }
    
    .progress-step {
        flex: 0 0 auto !important;
        width: 50px !important;
    }
    
    .preview-grid {
        grid-template-columns: 1fr !important;
        margin-bottom: 1rem !important;
    }
    
    /* Fix inline grids that force multi-column on mobile */
    div[style*="grid-template-columns: 1fr 1fr"],
    div[style*="grid-template-columns: 1fr 1fr 1fr"],
    div[style*="grid-template-columns: 280px 1fr"],
    div[style*="grid-template-columns: repeat(3, 1fr)"],
    .options-grid {
        grid-template-columns: 1fr !important;
    }
}

