/**
 * Normalized Mobile UI Components for iLearnZed
 * 
 * Ensures consistent course cards, buttons, badges, and instructor rows
 * across all pages with proper mobile scaling and alignment.
 * 
 * Usage: Include this file after base styles but before page-specific styles.
 */

/* ============================================
   COURSE CARDS - Normalized
   ============================================ */

.course-card {
    background: #ffffff;
    border-radius: 16px;
    overflow: hidden; /* Keep hidden for rounded corners */
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    transition: all 0.3s ease;
    display: flex;
    flex-direction: column;
    position: relative;
    border: 1px solid #f0f0f0;
    width: 100%;
    max-width: 100%;
    height: auto; /* Auto height to accommodate all content */
    min-height: 500px; /* Minimum height for consistency */
}

/* Mobile: Full width cards, consistent height */
@media (max-width: 768px) {
    .course-card {
        border-radius: 12px;
        min-height: auto;
        height: auto;
    }
}

.course-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 24px rgba(0, 166, 81, 0.15);
}

.course-card .card-image {
    position: relative;
    width: 100%;
    height: 200px;
    min-height: 200px;
    overflow: hidden;
    background: #E5E7EB;
    flex-shrink: 0;
    border-radius: 16px 16px 0 0; /* Round top corners only */
}

.course-card .card-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

/* ============================================
   BADGES - Normalized
   ============================================ */

.badge,
.card-badges .badge {
    padding: 0.4rem 0.85rem;
    border-radius: 8px;
    font-size: 0.75rem;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    white-space: nowrap;
    line-height: 1.2;
}

/* Mobile: Smaller badges */
@media (max-width: 768px) {
    .badge,
    .card-badges .badge {
        padding: 0.35rem 0.7rem;
        font-size: 0.7rem;
    }
}

.badge-enrolled {
    background: rgba(16, 185, 129, 0.95);
    color: white;
}

.badge-recommended {
    background: linear-gradient(135deg, #fbbf24, #f59e0b);
    color: #1f2937;
}

.badge-price {
    background: rgba(255, 255, 255, 0.98);
    color: #1f2937;
    font-weight: 800;
}

.badge-price.free {
    background: linear-gradient(135deg, #10b981, #059669);
    color: white;
}

/* ============================================
   BUTTONS - Normalized CTAs
   ============================================ */

.btn-view,
.btn-enroll,
.btn-primary-action {
    padding: 0.875rem 1.25rem;
    border-radius: 12px;
    font-size: 0.9rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.3s ease;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    border: none;
    white-space: nowrap;
    min-height: 44px; /* Touch target size */
    box-sizing: border-box;
}

/* Mobile: Full width buttons, larger touch targets */
@media (max-width: 768px) {
    .btn-view,
    .btn-enroll,
    .btn-primary-action {
        width: 100%;
        padding: 1rem 1.5rem;
        font-size: 0.95rem;
        min-height: 48px;
    }
    
    .card-footer {
        flex-direction: column;
    }
    
    .card-footer .btn-view,
    .card-footer .btn-enroll {
        width: 100%;
    }
}

.btn-view {
    background: linear-gradient(135deg, #00A651 0%, #0288D1 100%);
    color: white;
    box-shadow: 0 2px 8px rgba(0, 166, 81, 0.25);
}

.btn-view:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(0, 166, 81, 0.35);
    color: white;
}

.btn-enroll {
    border: 2px solid #00A651;
    background: transparent;
    color: #00A651;
}

.btn-enroll:hover {
    background: #00A651;
    color: white;
}

/* ============================================
   INSTRUCTOR ROWS - Normalized
   ============================================ */

.instructor-row,
.instructor-info {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 0;
    flex-wrap: wrap;
}

.instructor-label {
    font-size: 0.7rem;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
    margin-bottom: 0.25rem;
    width: 100%;
}

.instructor-name {
    font-size: 0.95rem;
    font-weight: 700;
    color: #1f2937;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
    min-width: 0;
}

/* Mobile: Stack instructor info */
@media (max-width: 768px) {
    .instructor-row,
    .instructor-info {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }
    
    .instructor-name {
        width: 100%;
        font-size: 0.9rem;
    }
}

.verified-badge {
    color: #00A651;
    font-size: 1rem;
    flex-shrink: 0;
}

/* ============================================
   CARD FOOTER - Normalized Alignment
   ============================================ */

.card-footer {
    padding: 1rem 1.5rem;
    background: #ffffff;
    display: flex;
    gap: 0.75rem;
    margin-top: auto;
    flex-shrink: 0;
    border-top: 1px solid #f0f0f0;
    align-items: center;
    width: 100%;
    box-sizing: border-box;
}

/* Mobile: Stack buttons vertically */
@media (max-width: 768px) {
    .card-footer {
        flex-direction: column;
        padding: 1rem;
        gap: 0.5rem;
    }
}

/* ============================================
   CARD BODY - Normalized Spacing
   ============================================ */

.card-body {
    padding: 1.5rem;
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    background: #ffffff;
    min-height: 0;
}

/* Mobile: Reduced padding */
@media (max-width: 768px) {
    .card-body {
        padding: 1rem;
        gap: 0.75rem;
    }
}

/* ============================================
   CARD TITLE - Normalized Typography
   ============================================ */

.card-title {
    font-size: 1.2rem;
    font-weight: 800;
    color: #111827;
    margin: 0;
    line-height: 1.35;
    word-wrap: break-word;
    overflow-wrap: break-word;
    /* Removed line clamping to show full title */
}

/* Mobile: Slightly smaller title */
@media (max-width: 768px) {
    .card-title {
        font-size: 1.1rem;
        line-height: 1.3;
    }
}

/* ============================================
   UTILITY: Ensure consistent spacing
   ============================================ */

.courses-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1.5rem;
}

/* Mobile: Single column */
@media (max-width: 768px) {
    .courses-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
}

/* Ensure all CTAs align properly */
.course-card .card-footer,
.course-card .btn-view,
.course-card .btn-enroll {
    align-self: stretch;
}

@media (max-width: 768px) {
    .course-card .card-footer {
        align-items: stretch;
    }
}

/* ============================================
   AI HELPERS - Mobile & Desktop
   Ensures AI assist buttons work everywhere: phones, tablets, desktops
   ============================================ */

.ai-assist-btn,
.ai-suggest-btn,
.btn-ai-assist,
.ai-assistance-buttons button,
.ai-action-btn,
button[id^="ai"],
button[id*="Ai"],
#aiSuggestContentBtn,
#aiGenerateTitleBtn,
#aiGenerateTextBtn,
#aiParaphraseBtn,
#aiEnhanceBtn,
#generate-ai-questions,
#ai-generate-title,
#ai-generate-description,
#ai-generate-full-plan {
    /* Minimum touch target (44px) for mobile accessibility */
    min-height: 44px !important;
    min-width: 44px !important;
    padding: 0.5rem 1rem !important;
    cursor: pointer !important;
    pointer-events: auto !important;
    touch-action: manipulation !important;
    -webkit-tap-highlight-color: rgba(0, 166, 81, 0.2);
}

/* Mobile: Ensure AI buttons are visible and tappable */
@media (max-width: 768px) {
    .ai-assist-btn,
    .ai-suggest-btn,
    .btn-ai-assist,
    .ai-assistance-buttons button,
    .ai-action-btn,
    button[id^="ai"],
    button[id*="Ai"],
    #aiSuggestContentBtn,
    #aiGenerateTitleBtn,
    #aiGenerateTextBtn,
    #aiParaphraseBtn,
    #aiEnhanceBtn,
    #generate-ai-questions,
    #ai-generate-title,
    #ai-generate-description,
    #ai-generate-full-plan {
        min-height: 48px !important;
        padding: 0.75rem 1.25rem !important;
        font-size: 0.95rem !important;
        flex-shrink: 0 !important;
    }
    
    /* Form label with AI button: stack on mobile so button stays visible */
    .form-label {
        flex-wrap: wrap !important;
    }
    
    .form-label .ai-assist-btn,
    .form-label .btn-ai-assist,
    .form-label button[id^="ai"],
    .form-label #aiGenerateTitleBtn {
        margin-left: 0 !important;
        margin-top: 0.5rem !important;
        width: 100% !important;
        justify-content: center !important;
    }
    
    /* AI button groups (e.g. content form: Generate, Paraphrase, Enhance) - wrap on mobile */
    .form-label .btn-group,
    .form-field-wrapper .btn-group {
        flex-wrap: wrap !important;
        width: 100% !important;
    }
    
    .form-label .btn-group .btn,
    .form-field-wrapper .btn-group .btn {
        min-width: 44px !important;
    }
    
    /* AI assistant section - ensure visible on mobile */
    #ai-assistant-section,
    .module-suggestions,
    .ai-suggestions-box {
        max-width: 100% !important;
    }
    
    /* AI buttons inside input groups (e.g. study plan title/description) - move below on mobile */
    .input-group {
        flex-wrap: wrap !important;
    }
    
    .input-group .btn-ai-assist {
        position: static !important;
        margin-top: 0.5rem !important;
        width: 100% !important;
        transform: none !important;
        order: 99 !important;
    }
}
