/* ══════════════════════════════════════════════════════════════
   InfiNEET — Mobile-First Production CSS
   ══════════════════════════════════════════════════════════════ */

/* ── CSS Variables ─────────────────────────────────────────── */
:root {
    --primary-color: #2c3e50;
    --secondary-color: #3498db;
    --success-color: #27ae60;
    --warning-color: #f39c12;
    --danger-color: #e74c3c;
    --light-bg: #f8f9fa;
    --text-dark: #1a202c;
    --text-muted: #6c757d;
    --border-color: #e2e8f0;
    --card-shadow: 0 2px 12px rgba(0,0,0,.07);
    --card-hover-shadow: 0 8px 28px rgba(0,0,0,.13);
    --radius: 12px;
    --radius-lg: 16px;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* ── Base Reset & Typography ───────────────────────────────── */
*, *::before, *::after {
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;
    scroll-behavior: smooth;
}

body {
    font-family: 'Poppins', 'Segoe UI', system-ui, -apple-system, sans-serif;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    background-color: var(--light-bg);
    color: var(--text-dark);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow-x: hidden;
}

main {
    flex: 1;
}

/* Prevent horizontal overflow globally */
.container, .container-fluid {
    max-width: 100%;
    overflow-x: hidden;
}

/* ── Navigation ────────────────────────────────────────────── */
.navbar {
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.navbar-brand {
    font-weight: 700;
    font-size: 1.5rem;
}

.navbar-brand i {
    margin-right: 0.5rem;
}

/* ── Cards ─────────────────────────────────────────────────── */
.dashboard-card {
    background: white;
    border-radius: var(--radius);
    padding: 1.5rem;
    text-align: center;
    box-shadow: var(--card-shadow);
    transition: transform 0.22s, box-shadow 0.22s;
    margin-bottom: 1rem;
}

.dashboard-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--card-hover-shadow);
}

.card-icon {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 0.8rem;
    color: white;
    font-size: 1.4rem;
}

.card-value {
    font-size: 1.9rem;
    font-weight: 800;
    color: var(--primary-color);
    line-height: 1.15;
}

.card-label {
    color: var(--text-muted);
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-top: 0.25rem;
}

/* ── Feature Grid ──────────────────────────────────────────── */
.feature-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
    padding: 1.5rem;
}

.feature-card {
    background: white;
    border-radius: var(--radius);
    padding: 1.25rem;
    text-align: center;
    box-shadow: var(--card-shadow);
}

.feature-icon {
    font-size: 2rem;
    color: var(--secondary-color);
    margin-bottom: 0.75rem;
}

/* ── Steps ─────────────────────────────────────────────────── */
.step-card {
    text-align: center;
    padding: 1.25rem;
    position: relative;
}

.step-number {
    width: 36px;
    height: 36px;
    background: var(--secondary-color);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    margin: 0 auto 0.75rem;
    font-size: 0.9rem;
}

/* ── Statistics Cards ──────────────────────────────────────── */
.stat-card {
    background: #fff;
    border-radius: 14px;
    padding: 1.2rem;
    text-align: center;
    box-shadow: var(--card-shadow);
    transition: transform .22s, box-shadow .22s;
    height: 100%;
    border: 1px solid #eef0f4;
}

.stat-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--card-hover-shadow);
}

.stat-value {
    font-size: 1.9rem;
    font-weight: 800;
    color: var(--text-dark);
    line-height: 1.15;
}

.stat-label {
    color: var(--text-muted);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-top: 0.25rem;
}

.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 0.6rem;
    color: #fff;
    font-size: 1.2rem;
}

/* ── Question Display ──────────────────────────────────────── */
.question-container {
    background: white;
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    box-shadow: var(--card-shadow);
    margin-bottom: 1.5rem;
}

.question-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.25rem;
    padding-bottom: 0.75rem;
    border-bottom: 2px solid #eee;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.question-type {
    padding: 0.25rem 0.75rem;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 600;
    white-space: nowrap;
}

.type-mcq   { background: #e3f2fd; color: #1976d2; }
.type-ar    { background: #fff3e0; color: #f57c00; }
.type-match { background: #e8f5e8; color: #388e3c; }

.question-text {
    font-size: 1.05rem;
    margin-bottom: 1.5rem;
    line-height: 1.7;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

/* ── Options ───────────────────────────────────────────────── */
.options-list {
    list-style: none;
    padding: 0;
}

.option-item {
    padding: 0.9rem 1rem;
    margin-bottom: 0.5rem;
    border: 2px solid #eee;
    border-radius: var(--radius);
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.option-item:hover {
    background: #f8f9fa;
    border-color: var(--secondary-color);
}

.option-item:active {
    transform: scale(0.98);
}

.option-item.selected {
    background: var(--secondary-color);
    color: white;
    border-color: var(--secondary-color);
}

.option-prefix {
    display: inline-flex;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: #eee;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    flex-shrink: 0;
    font-size: 0.85rem;
}

.selected .option-prefix {
    background: white;
    color: var(--secondary-color);
}

/* ── Progress Bar ──────────────────────────────────────────── */
.progress-custom {
    height: 8px;
    border-radius: 4px;
    background: #eee;
    overflow: hidden;
    margin: 0.75rem 0;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--secondary-color), var(--primary-color));
    transition: width 0.3s;
    border-radius: 4px;
}

/* ── Feedback ──────────────────────────────────────────────── */
.feedback-box {
    padding: 1.25rem;
    border-radius: var(--radius);
    margin: 1rem 0;
}

.feedback-correct {
    background: #d4edda;
    border: 1px solid #c3e6cb;
    color: #155724;
}

.feedback-incorrect {
    background: #f8d7da;
    border: 1px solid #f5c6cb;
    color: #721c24;
}

/* ── Language Selector ─────────────────────────────────────── */
.language-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 0.75rem;
    margin: 1rem 0;
}

.language-option {
    padding: 0.75rem;
    border: 2px solid #eee;
    border-radius: var(--radius);
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    touch-action: manipulation;
}

.language-option:hover {
    border-color: var(--secondary-color);
    background: #f8f9fa;
}

.language-option.selected {
    background: var(--secondary-color);
    color: white;
    border-color: var(--secondary-color);
}

.language-native {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 0.15rem;
}

.language-english {
    font-size: 0.8rem;
    opacity: 0.8;
}

/* ── Chapter Selection ─────────────────────────────────────── */
.chapter-item {
    padding: 0.85rem 1rem;
    border: 2px solid #eee;
    border-radius: var(--radius);
    margin-bottom: 0.4rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    transition: all 0.2s;
    touch-action: manipulation;
    gap: 0.5rem;
}

.chapter-item:hover {
    border-color: var(--secondary-color);
}

.chapter-item.selected {
    background: #e3f2fd;
    border-color: var(--secondary-color);
}

.chapter-name {
    font-weight: 500;
    font-size: 0.9rem;
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chapter-counts {
    display: flex;
    gap: 0.35rem;
    flex-shrink: 0;
}

.count-badge {
    padding: 0.2rem 0.45rem;
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: 600;
}

.badge-mcq   { background: #e3f2fd; color: #1976d2; }
.badge-ar    { background: #fff3e0; color: #f57c00; }
.badge-match { background: #e8f5e8; color: #388e3c; }

/* ── Loading Spinner ───────────────────────────────────────── */
.spinner {
    border: 3px solid #f3f3f3;
    border-top: 3px solid var(--secondary-color);
    border-radius: 50%;
    width: 36px;
    height: 36px;
    animation: spin 1s linear infinite;
    margin: 2rem auto;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* ── Animations ────────────────────────────────────────────── */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(15px); }
    to   { opacity: 1; transform: translateY(0); }
}

.fade-in {
    animation: fadeIn 0.4s ease-out;
}

/* ── Tooltips ──────────────────────────────────────────────── */
.tooltip-icon {
    color: var(--secondary-color);
    cursor: help;
    margin-left: 0.5rem;
}

/* ── Footer ────────────────────────────────────────────────── */
.footer {
    margin-top: auto;
    background: var(--light-bg);
    border-top: 1px solid var(--border-color);
}

/* ── Tables (Biology Match Questions) ──────────────────────── */
.table-responsive {
    -webkit-overflow-scrolling: touch;
}

.table {
    font-size: 0.9rem;
}

/* ── Images in Questions ───────────────────────────────────── */
.img-fluid {
    max-width: 100%;
    height: auto;
}

/* ── Custom Buttons — Touch Friendly ───────────────────────── */
.btn {
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.btn-lg {
    padding: 0.75rem 1.5rem;
    font-size: 1rem;
}

/* ── Form Controls — Mobile Friendly ───────────────────────── */
.form-control, .form-select {
    font-size: 16px !important; /* Prevents iOS zoom on focus */
    border-radius: var(--radius);
    padding: 0.6rem 0.85rem;
}

.form-control:focus, .form-select:focus {
    border-color: var(--secondary-color);
    box-shadow: 0 0 0 0.2rem rgba(52, 152, 219, 0.25);
}

/* ══════════════════════════════════════════════════════════════
   RESPONSIVE BREAKPOINTS
   ══════════════════════════════════════════════════════════════ */

/* ── Extra Small (phones, <576px) ──────────────────────────── */
@media (max-width: 575.98px) {
    body {
        padding-bottom: calc(80px + var(--safe-bottom));
        font-size: 14px;
    }

    h1 { font-size: 1.5rem; }
    h2 { font-size: 1.3rem; }
    h3 { font-size: 1.15rem; }
    h4 { font-size: 1.05rem; }
    h5 { font-size: 0.95rem; }
    h6 { font-size: 0.85rem; }

    .container { padding-left: 12px; padding-right: 12px; }

    .card-value, .stat-value { font-size: 1.4rem; }

    .feature-grid {
        grid-template-columns: 1fr;
        padding: 0.75rem;
        gap: 0.75rem;
    }

    .language-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.5rem;
    }

    .language-option { padding: 0.5rem; }
    .language-native { font-size: 0.95rem; }

    .question-text { font-size: 0.95rem; line-height: 1.6; }

    .option-item {
        padding: 0.75rem 0.85rem;
        margin-bottom: 0.4rem;
        font-size: 0.9rem;
    }
    .option-prefix { width: 28px; height: 28px; font-size: 0.8rem; }

    .chapter-item { padding: 0.65rem 0.75rem; }
    .chapter-name { font-size: 0.82rem; }
    .count-badge  { font-size: 0.65rem; padding: 0.15rem 0.35rem; }

    .stat-card { padding: 0.85rem 0.5rem; }
    .stat-icon { width: 40px; height: 40px; font-size: 1rem; }
    .stat-label { font-size: 0.65rem; }

    /* Dashboard nav hamburger */
    .app-navbar .nav-links {
        display: none;
    }

    /* Stack buttons vertically */
    .d-flex.gap-2.flex-wrap { flex-direction: column; }
    .d-flex.gap-2.flex-wrap .btn { width: 100%; }
    
    /* Fix tables on small screens */
    .table { font-size: 0.78rem; }
    .table th, .table td { padding: 0.35rem 0.5rem; }
}

/* ── Small (landscape phones, 576px – 767px) ───────────────── */
@media (min-width: 576px) and (max-width: 767.98px) {
    body {
        padding-bottom: calc(80px + var(--safe-bottom));
    }

    .card-value, .stat-value { font-size: 1.6rem; }

    .feature-grid {
        grid-template-columns: repeat(2, 1fr);
        padding: 1rem;
    }
    
    .language-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

/* ── Medium (tablets, 768px – 991px) ───────────────────────── */
@media (min-width: 768px) and (max-width: 991.98px) {
    .feature-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .language-grid {
        grid-template-columns: repeat(4, 1fr);
    }

    .stat-card {
        border-right: none;
        border-bottom: 1px solid #dee2e6;
    }

    .stat-card:last-child {
        border-bottom: none;
    }
}

/* ── Large+ (desktops, 992px+) ─────────────────────────────── */
@media (min-width: 992px) {
    .card-value, .stat-value { font-size: 1.9rem; }

    .language-grid {
        grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    }
}

/* ══════════════════════════════════════════════════════════════
   UTILITY HELPERS
   ══════════════════════════════════════════════════════════════ */

/* Safe scrollable containers */
.scroll-container {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
}

/* Hide scrollbar but keep scrollable */
.scroll-hide::-webkit-scrollbar { display: none; }
.scroll-hide { -ms-overflow-style: none; scrollbar-width: none; }

/* Touch-friendly tap targets (min 44px per WCAG) */
.tap-target {
    min-height: 44px;
    min-width: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* Text truncation */
.text-truncate-2 {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* No-select for interactive elements */
.no-select {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

/* Prevent pull-to-refresh on mobile when inside a scrollable area */
.overscroll-contain {
    overscroll-behavior: contain;
}

/* ══════════════════════════════════════════════════════════════
   PRINT STYLES
   ══════════════════════════════════════════════════════════════ */
@media print {
    .navbar, .mobile-bottom-nav, .footer, .btn { display: none !important; }
    body { padding: 0; background: white; }
    .card { box-shadow: none; border: 1px solid #ddd; }
}