/**
 * Student Mobile Responsive CSS
 * Optimized for Capacitor APK conversion
 * KalviYogi Nagarajan - Edunivra Pvt Ltd - 369 Tesla
 */

/* Safe area for notch devices */
:root {
    --safe-area-top: env(safe-area-inset-top, 0px);
    --safe-area-bottom: env(safe-area-inset-bottom, 0px);
    --safe-area-left: env(safe-area-inset-left, 0px);
    --safe-area-right: env(safe-area-inset-right, 0px);
}

/* Base touch optimizations */
* {
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
}

html {
    scroll-behavior: smooth;
    -webkit-text-size-adjust: 100%;
}

body {
    padding-top: var(--safe-area-top);
    padding-bottom: var(--safe-area-bottom);
    overscroll-behavior-y: contain;
}

/* Touch-friendly buttons */
.btn, button, a.btn {
    min-height: 44px;
    min-width: 44px;
    touch-action: manipulation;
}

/* Mobile Navigation - Bottom Tab Bar */
@media (max-width: 768px) {
    .header {
        padding: 12px 16px !important;
        padding-top: calc(12px + var(--safe-area-top)) !important;
        flex-direction: column !important;
        gap: 8px !important;
    }
    
    .header .logo {
        font-size: 1.2rem !important;
    }
    
    .nav-links {
        position: fixed !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        background: linear-gradient(180deg, rgba(26, 26, 36, 0.95) 0%, #1a1a24 100%) !important;
        backdrop-filter: blur(20px) !important;
        -webkit-backdrop-filter: blur(20px) !important;
        padding: 8px 8px calc(8px + var(--safe-area-bottom)) !important;
        margin: 0 !important;
        gap: 0 !important;
        justify-content: space-around !important;
        border-top: 1px solid rgba(255, 215, 0, 0.2) !important;
        z-index: 1000 !important;
        flex-wrap: nowrap !important;
        overflow-x: auto !important;
    }
    
    .nav-links a {
        flex-direction: column !important;
        gap: 2px !important;
        padding: 8px 10px !important;
        font-size: 0.7rem !important;
        text-align: center !important;
        min-width: 60px !important;
        border-radius: 8px !important;
        white-space: nowrap !important;
    }
    
    .nav-links a.active {
        background: rgba(255, 215, 0, 0.15) !important;
        color: var(--gold-primary) !important;
    }
    
    /* Hide text, show emoji icons only on very small screens */
    @media (max-width: 400px) {
        .nav-links a {
            font-size: 1.2rem !important;
            padding: 8px 6px !important;
            min-width: 50px !important;
        }
    }
    
    /* Add bottom padding for fixed nav */
    main, .main {
        padding-bottom: 80px !important;
    }
    
    body {
        padding-bottom: calc(70px + var(--safe-area-bottom)) !important;
    }
    
    /* User menu in header */
    .user-menu {
        width: 100% !important;
        justify-content: space-between !important;
        padding: 0 8px !important;
    }
}

/* Tablet Layout */
@media (min-width: 769px) and (max-width: 1024px) {
    .main {
        padding: 20px !important;
    }
    
    .stats-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }
    
    .test-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }
}

/* Mobile Cards */
@media (max-width: 768px) {
    .main {
        padding: 12px !important;
    }
    
    /* Stats Grid */
    .stats-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 10px !important;
    }
    
    .stat-card {
        padding: 14px !important;
        border-radius: 12px !important;
    }
    
    .stat-icon {
        font-size: 1.5rem !important;
        margin-bottom: 6px !important;
    }
    
    .stat-value {
        font-size: 1.6rem !important;
    }
    
    .stat-label {
        font-size: 0.75rem !important;
    }
    
    /* Test Cards */
    .test-grid {
        grid-template-columns: 1fr !important;
        gap: 12px !important;
    }
    
    .test-card {
        padding: 16px !important;
        border-radius: 12px !important;
    }
    
    .test-title {
        font-size: 1rem !important;
    }
    
    .test-meta {
        flex-wrap: wrap !important;
        gap: 8px !important;
        font-size: 0.8rem !important;
    }
    
    .test-actions {
        flex-direction: column !important;
        gap: 8px !important;
    }
    
    .test-actions .btn {
        width: 100% !important;
        text-align: center !important;
        padding: 12px !important;
    }
    
    /* Section Headers */
    .section-header {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 10px !important;
    }
    
    .section-title {
        font-size: 1.1rem !important;
    }
    
    /* Welcome Section */
    .welcome h1 {
        font-size: 1.3rem !important;
    }
    
    .welcome p {
        font-size: 0.9rem !important;
    }
    
    /* Cards */
    .card {
        border-radius: 12px !important;
        padding: 14px !important;
    }
    
    .card-header {
        padding: 12px !important;
    }
    
    .card-body {
        padding: 12px !important;
    }
}

/* Very Small Phones */
@media (max-width: 360px) {
    .stats-grid {
        grid-template-columns: 1fr 1fr !important;
        gap: 8px !important;
    }
    
    .stat-card {
        padding: 10px !important;
    }
    
    .stat-value {
        font-size: 1.3rem !important;
    }
    
    .stat-label {
        font-size: 0.65rem !important;
    }
    
    .main {
        padding: 8px !important;
    }
    
    .header .logo {
        font-size: 1rem !important;
    }
}

/* Quiz Page Mobile */
@media (max-width: 768px) {
    .quiz-container {
        padding: 12px !important;
    }
    
    .question-card {
        padding: 16px !important;
        border-radius: 12px !important;
    }
    
    .question-text {
        font-size: 1rem !important;
        line-height: 1.5 !important;
    }
    
    .options-list {
        gap: 10px !important;
    }
    
    .option-item {
        padding: 14px !important;
        border-radius: 10px !important;
        font-size: 0.95rem !important;
    }
    
    .quiz-nav {
        flex-wrap: wrap !important;
        gap: 8px !important;
    }
    
    .quiz-nav .btn {
        flex: 1 !important;
        min-width: 100px !important;
    }
    
    .question-palette {
        position: fixed !important;
        bottom: 60px !important;
        left: 0 !important;
        right: 0 !important;
        background: var(--bg-card) !important;
        padding: 10px !important;
        border-top: 1px solid rgba(255, 215, 0, 0.2) !important;
        max-height: 120px !important;
        overflow-y: auto !important;
    }
    
    .palette-grid {
        display: flex !important;
        flex-wrap: wrap !important;
        gap: 6px !important;
        justify-content: center !important;
    }
    
    .palette-btn {
        width: 36px !important;
        height: 36px !important;
        font-size: 0.8rem !important;
    }
    
    .timer-display {
        font-size: 1.2rem !important;
        padding: 8px 16px !important;
    }
}

/* Result Page Mobile */
@media (max-width: 768px) {
    .result-card {
        padding: 20px !important;
        border-radius: 16px !important;
    }
    
    .result-score {
        font-size: 3rem !important;
    }
    
    .result-stats {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 12px !important;
    }
    
    .result-stat {
        padding: 12px !important;
    }
    
    .result-actions {
        flex-direction: column !important;
        gap: 10px !important;
    }
    
    .result-actions .btn {
        width: 100% !important;
    }
}

/* Analytics Page Mobile */
@media (max-width: 768px) {
    .chart-container {
        height: 200px !important;
    }
    
    .analytics-grid {
        grid-template-columns: 1fr !important;
    }
    
    .performance-bar {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 6px !important;
    }
    
    .performance-bar .name {
        width: 100% !important;
    }
    
    .performance-bar .bar {
        width: 100% !important;
    }
}

/* Profile Page Mobile */
@media (max-width: 768px) {
    .profile-header {
        flex-direction: column !important;
        text-align: center !important;
    }
    
    .profile-avatar-large {
        width: 80px !important;
        height: 80px !important;
    }
    
    .grid-2 {
        grid-template-columns: 1fr !important;
    }
    
    .form-group {
        margin-bottom: 16px !important;
    }
}

/* Tables to Cards on Mobile */
@media (max-width: 768px) {
    table.responsive-table {
        display: block !important;
    }
    
    table.responsive-table thead {
        display: none !important;
    }
    
    table.responsive-table tbody {
        display: flex !important;
        flex-direction: column !important;
        gap: 12px !important;
    }
    
    table.responsive-table tr {
        display: flex !important;
        flex-direction: column !important;
        background: var(--bg-card) !important;
        border-radius: 12px !important;
        padding: 14px !important;
        border: 1px solid rgba(255, 215, 0, 0.1) !important;
    }
    
    table.responsive-table td {
        display: flex !important;
        justify-content: space-between !important;
        align-items: center !important;
        padding: 8px 0 !important;
        border-bottom: 1px solid var(--bg-secondary) !important;
    }
    
    table.responsive-table td:last-child {
        border-bottom: none !important;
    }
    
    table.responsive-table td::before {
        content: attr(data-label) !important;
        font-weight: 600 !important;
        color: var(--gold-primary) !important;
        font-size: 0.8rem !important;
    }
}

/* Modal Mobile */
@media (max-width: 768px) {
    .modal-content {
        width: 95% !important;
        max-height: 85vh !important;
        border-radius: 16px 16px 0 0 !important;
        margin-top: auto !important;
    }
    
    .modal-overlay {
        align-items: flex-end !important;
    }
}

/* Pull to Refresh Style */
.pull-indicator {
    text-align: center;
    padding: 20px;
    color: var(--gold-primary);
    display: none;
}

/* Loading Spinner */
.loading-spinner {
    display: inline-block;
    width: 24px;
    height: 24px;
    border: 3px solid rgba(255, 215, 0, 0.3);
    border-radius: 50%;
    border-top-color: var(--gold-primary);
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Swipe Actions */
.swipeable {
    touch-action: pan-y;
    user-select: none;
}

/* Floating Action Button */
.fab {
    position: fixed;
    bottom: calc(80px + var(--safe-area-bottom));
    right: 16px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--gold-primary), var(--gold-dark));
    color: var(--bg-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    box-shadow: 0 4px 20px rgba(255, 215, 0, 0.4);
    z-index: 999;
    border: none;
    cursor: pointer;
}

/* Hide scrollbar but keep functionality */
.hide-scrollbar {
    -ms-overflow-style: none;
    scrollbar-width: none;
}

.hide-scrollbar::-webkit-scrollbar {
    display: none;
}

/* Smooth transitions */
.smooth-transition {
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Image optimization */
img {
    max-width: 100%;
    height: auto;
}

/* Prevent text selection on UI elements */
.no-select {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

/* Active states for touch */
.btn:active, button:active {
    transform: scale(0.98);
    opacity: 0.9;
}

/* Landscape mode adjustments */
@media (max-height: 500px) and (orientation: landscape) {
    .nav-links {
        padding: 6px 8px !important;
    }
    
    .nav-links a {
        padding: 6px 8px !important;
        font-size: 0.8rem !important;
    }
    
    .main {
        padding-bottom: 60px !important;
    }
}

