﻿/* ============================================================================
   COMPREHENSIVE MOBILE OPTIMIZATION STYLES
   Responsive design for all device sizes from 320px (phone) to 1440px
   ============================================================================ */

/* Base Mobile Optimizations (320px - 480px) */
@media (max-width: 480px) {
    /* === GLOBAL OVERFLOW-X PREVENTION - FONTOS! === */
    html, body {
        overflow-x: hidden;
        width: 100%;
        max-width: 100%;
    }

    * {
        max-width: 100%;
    }

    /* === GLOBAL MOBILE OPTIMIZATIONS === */
    body {
        font-size: 14px;
    }

    * {
        touch-action: manipulation;
    }

    /* === HEADER PADDING === */
    header {
        padding: 8px 10px;
    }

    header nav {
        width: 100%;
    }

    #main-nav {
        gap: 4px;
    }

    #main-nav a {
        padding: 12px 10px;
        font-size: 12px;
        min-height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
        position: relative;
    }

    #main-nav a i {
        font-size: 16px;
        margin: 0;
    }

    #main-nav li {
        position: relative;
        min-width: 44px;
        min-height: 44px;
    }

    /* === MODALS === */
    .modal-backdrop {
        padding: 10px;
    }

    .modal-content {
        padding: 12px;
        max-height: 95vh;
        overflow-y: auto;
    }

    .modal-header {
        margin-bottom: 12px;
    }

    .modal-header h2 {
        font-size: 16px;
        margin: 0;
    }

    .modal-footer {
        padding: 10px 0;
        gap: 6px;
    }

    .modal-footer button {
        flex: 1;
        font-size: 12px;
        padding: 8px !important;
        min-height: 44px;
    }

    /* === FORM ELEMENTS === */
    input,
    select,
    textarea {
        font-size: 16px !important; /* Prevents zoom on iOS */
        padding: 10px !important;
        height: 44px;
        min-height: 44px;
        border-radius: 4px;
    }

    textarea {
        height: 80px !important;
        resize: vertical;
    }

    label {
        font-size: 12px;
        font-weight: 600;
    }

    /* === BUTTONS === */
    button:not(.close-button),
    .btn:not(.close-button) {
        font-size: 12px;
        padding: 10px 12px !important;
        min-height: 44px;
        border-radius: 4px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    button i,
    .btn i {
        font-size: 13px;
        margin-right: 4px;
    }

    /* Fix for Close Button on Mobile */
    .modal-content .close-button {
        width: 32px !important;
        height: 32px !important;
        min-width: 32px !important;
        min-height: 32px !important;
        padding: 0 !important;
        border-radius: 50% !important;
        background: rgba(0, 0, 0, 0.1) !important; /* Ensure visibility against white */
        color: var(--text-color) !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        z-index: 1050 !important;
    }

    /* Hide text in icon-only buttons on mobile */
    button.icon-only span,
    .btn.icon-only span {
        display: none;
    }

    /* === CARDS AND CONTAINERS === */
    .student-log-card,
    .event-card,
    .progress-card {
        padding: 12px;
        margin: 8px 0;
        border-radius: 6px;
    }

    .student-log-card-header {
        flex-direction: column;
        gap: 6px;
    }

    .student-name {
        font-size: 14px;
        font-weight: 600;
    }

    /* === TABLES === */
    table {
        font-size: 12px;
    }

    th,
    td {
        padding: 8px 4px !important;
    }

    th {
        font-size: 11px;
    }

    /* === CLASS LOG SPECIFIC === */
    .common-grading-section {
        padding: 12px;
        margin-bottom: 12px;
        gap: 10px;
    }

    .grading-control-group {
        gap: 6px;
    }

    .grading-control-group label {
        font-size: 11px;
    }

    .grade-buttons-common {
        gap: 4px;
    }

    .btn-grade-common {
        flex: 0 0 calc(20% - 3.2px);
        min-width: 38px;
        padding: 6px 2px;
        font-size: 12px;
    }

    .btn-grade-common .grade-number {
        display: block;
        line-height: 1;
    }

    #common-comment {
        font-size: 12px;
        padding: 8px;
        height: 60px;
    }

    #apply-grades-btn {
        padding: 8px;
        font-size: 12px;
    }

    .student-log-container {
        max-height: 50vh;
        overflow-y: auto;
    }

    /* === ATTENDANCE BUTTONS === */
    .attendance-btn-group,
    .grade-btn-group {
        gap: 4px;
        flex-wrap: wrap;
    }

    .btn-attendance,
    .btn-grade {
        flex: 0 0 calc(50% - 2px);
        padding: 6px 4px !important;
        font-size: 11px;
        min-height: 36px;
    }

    /* === HEADER === */
    header {
        padding: 8px 10px;
    }

    header h1 {
        font-size: 18px;
    }

    .logo {
        font-size: 14px;
    }

    .user-actions {
        z-index: 1001;
    }

    /* === THEME TOGGLE === */
    .theme-toggle-button {
        padding: 6px 8px;
    }

    /* === BADGES === */
    .pending-badge,
    .badge,
    .event-pending-badge {
        font-size: 10px;
        padding: 3px 6px;
    }

    /* === VISIBILITY --- */
    .hide-mobile {
        display: none !important;
    }

    .show-mobile {
        display: block !important;
    }

    .show-mobile-inline {
        display: inline !important;
    }
}

/* Tablet Optimizations (481px - 768px) */
@media (min-width: 481px) and (max-width: 768px) {
    /* === NAVIGATION === */
    main nav ul li a {
        padding: 14px 12px;
        font-size: 14px;
    }

    /* === MODALS === */
    .modal-content {
        padding: 16px;
        max-height: 90vh;
    }

    .modal-header h2 {
        font-size: 18px;
    }

    .modal-footer button {
        font-size: 13px;
        padding: 10px !important;
        min-height: 40px;
    }

    /* === FORM ELEMENTS === */
    input,
    select,
    textarea {
        font-size: 14px;
        padding: 10px;
        min-height: 40px;
    }

    textarea {
        height: 100px;
    }

    label {
        font-size: 13px;
    }

    /* === BUTTONS === */
    button,
    .btn {
        font-size: 13px;
        padding: 10px 14px !important;
        min-height: 40px;
    }

    /* === CARDS === */
    .student-log-card,
    .event-card,
    .progress-card {
        padding: 14px;
        margin: 10px 0;
    }

    /* === CLASS LOG === */
    .common-grading-section {
        padding: 14px;
        gap: 12px;
    }

    .grade-buttons-common {
        gap: 6px;
    }

    .btn-grade-common {
        flex: 0 0 calc(20% - 4.8px);
        min-width: 44px;
        padding: 8px;
        font-size: 13px;
    }

    #common-comment {
        font-size: 13px;
        height: 80px;
    }

    .btn-attendance,
    .btn-grade {
        flex: 0 0 calc(50% - 3px);
        font-size: 12px;
        min-height: 38px;
    }

    .hide-mobile {
        display: none !important;
    }

    .show-mobile {
        display: block !important;
    }
}

/* Large Tablets / Small Laptops (769px - 1024px) */
@media (min-width: 769px) and (max-width: 1024px) {
    .modal-content {
        max-height: 85vh;
    }

    .student-log-container {
        max-height: 60vh;
    }

    .hide-mobile {
        display: block !important;
    }

    .show-mobile {
        display: none !important;
    }
}

/* Desktop (1025px+) */
@media (min-width: 1025px) {
    .hide-mobile {
        display: block !important;
    }

    .show-mobile {
        display: none !important;
    }

    .modal-content {
        max-height: 80vh;
    }

    /* Desktop nagyobb padding */
    main {
        padding: 30px 40px;
    }

    header {
        padding: 15px 30px;
    }

    #main-nav {
        gap: 5px;
        margin-left: 20px;
    }

    #main-nav a {
        padding: 8px 12px;
        font-size: 0.95em;
        gap: 8px;
    }

    footer {
        padding: 30px 20px;
        font-size: 1rem;
    }

    footer .slogan {
        font-size: 1.1em;
        margin-bottom: 15px;
    }
}

/* ============================================================================
   ORIENTATION-SPECIFIC OPTIMIZATIONS
   ============================================================================ */

/* Landscape mode (phones and tablets) */
@media (max-height: 500px) and (orientation: landscape) {
    /* === REDUCE VERTICAL PADDING FOR LANDSCAPE === */
    .modal-header {
        margin-bottom: 8px;
    }

    .modal-content {
        padding: 10px;
        max-height: 90vh;
    }

    .modal-header h2 {
        font-size: 16px;
        margin: 0;
    }

    .student-log-container {
        max-height: 40vh;
    }

    main nav ul {
        flex-wrap: wrap;
    }

    main nav ul li {
        flex: 0 0 auto;
    }
}

/* ============================================================================
   ACCESSIBILITY & UX IMPROVEMENTS FOR MOBILE
   ============================================================================ */

/* Ensure touch targets are at least 44px x 44px (Mobile UX best practice) */
@media (pointer: coarse) and (max-width: 768px) {
    button,
    .btn,
    a[role="button"],
    input[type="checkbox"],
    input[type="radio"] {
        min-width: 44px;
        min-height: 44px;
        padding: 10px !important;
    }

    /* Increase spacing around interactive elements */
    button + button,
    .btn + .btn {
        margin-left: 8px;
    }

    /* Reduce motion for users who prefer it */
    @media (prefers-reduced-motion: reduce) {
        * {
            animation: none !important;
            transition: none !important;
        }
    }
}

/* ============================================================================
   FLEXIBLE LAYOUT HELPERS
   ============================================================================ */

.flex-mobile-col {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

@media (max-width: 768px) {
    .flex-desktop-row {
        flex-direction: column !important;
    }

    .flex-desktop-row > * {
        width: 100% !important;
    }
}

/* ============================================================================
   MODAL-SPECIFIC MOBILE FIXES
   ============================================================================ */

@media (max-width: 768px) {
    /* JAVĂŤTĂS: A modĂˇlis ablakok garantĂˇltan kĂ¶zĂ©pre igazĂ­tĂˇsa mobilon */
    .modal-backdrop {
        position: fixed; /* Fix pozĂ­ciĂł a viewport-hoz kĂ©pest */
        inset: 0; /* Shorthand for top: 0; right: 0; bottom: 0; left: 0; */
        width: 100%;
        height: 100%;
        display: flex !important; /* JAVĂŤTĂS: Biztosan flex legyen */
        align-items: center !important; /* JAVĂŤTĂS: Biztosan kĂ¶zĂ©pre igazĂ­tson fĂĽggĹ‘legesen */
        justify-content: center !important; /* JAVĂŤTĂS: Biztosan kĂ¶zĂ©pre igazĂ­tson vĂ­zszintesen */
        padding: 15px; /* TĂ©rkĂ¶z a kĂ©pernyĹ‘ szĂ©lĂ©tĹ‘l */
        box-sizing: border-box;
        overflow-y: auto; /* EngedĂ©lyezi a gĂ¶rgetĂ©st, ha a tartalom magasabb */
    }

    .modal-content {
        width: 100% !important; /* A padding miatt 100% szĂ©les lehet a kontĂ©neren belĂĽl */
        max-width: 450px !important; /* MaximĂˇlis szĂ©lessĂ©g a jobb olvashatĂłsĂˇgĂ©rt */
        margin: auto; /* Automatikus margĂł a flexboxos kĂ¶zĂ©pre igazĂ­tĂˇs megerĹ‘sĂ­tĂ©sĂ©re */
        border-radius: 12px !important;
        display: flex; /* Flexbox a belsĹ‘ elrendezĂ©shez */
        flex-direction: column; /* A tartalom fĂĽggĹ‘legesen rendezĹ‘dik */
        max-height: 90vh; /* MaximĂˇlis magassĂˇg, hogy ne lĂłgjon ki */
    }

    .modal-body {
        overflow-y: auto; /* Csak a modal body-n belĂĽl legyen gĂ¶rgetĂ©s, ha szĂĽksĂ©ges */
    }
    
    /* Better form field visibility */
    .form-control,
    input,
    select,
    textarea {
        width: 100%;
        box-sizing: border-box;
    }

    /* Better table scrolling on mobile */
    table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    thead {
        display: none;
    }

    tbody,
    tr,
    td {
        display: block;
        width: 100%;
    }

    tr {
        margin-bottom: 12px;
        border: 1px solid var(--border-color);
        border-radius: 4px;
        padding: 10px;
    }

    td {
        padding: 8px 0;
        text-align: right;
    }

    td::before {
        content: attr(data-label);
        float: left;
        font-weight: 600;
        margin-right: 10px;
    }

    /* === KOMPAKT Ă‰S RESZPONZĂŤV OSZTĂLYZĂ“ KĂRTYA MOBILRA === */
    .student-log-card {
        display: grid !important;
        grid-template-columns: auto 1fr auto auto !important;
        grid-template-rows: auto auto !important;
        align-items: center !important;
        gap: 8px !important;
        padding: 10px !important;
        background: var(--card-bg) !important;
        border-radius: 8px !important;
        box-shadow: 0 2px 6px rgba(0,0,0,0.08) !important;
        margin-bottom: 10px !important;
        border: 1px solid var(--border-color) !important;
        width: 100% !important;
        box-sizing: border-box !important;
    }

    body.dark-theme .student-log-card {
        background: #263C3F !important;
    }

    /* NĂ©v - balra, kisebb, kompakt */
    .student-log-card .student-name {
        grid-column: 1 / 2 !important;
        grid-row: 1 / 3 !important;
        font-size: 0.9rem !important;
        font-weight: 700 !important;
        margin: 0 !important;
        padding: 0 5px !important;
        text-align: left !important;
        white-space: nowrap !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
        max-width: 100px !important;
    }

    /* JelenlĂ©t gombok - fent jobbra */
    .student-log-card .attendance-btn-group {
        grid-column: 2 / 5 !important;
        grid-row: 1 !important;
        display: flex !important;
        gap: 4px !important;
        justify-content: flex-end !important;
    }

    .student-log-card .attendance-btn-group .btn-attendance {
        padding: 6px 8px !important;
        font-size: 11px !important;
        min-width: 36px !important;
        height: 32px !important;
        flex: 0 0 auto !important;
    }

    /* Ă‰rtĂ©kelĂ©s - lent, teljes szĂ©lessĂ©g */
    .student-log-card .log-actions {
        grid-column: 2 / 5 !important;
        grid-row: 2 !important;
        display: flex !important;
        justify-content: flex-end !important;
        align-items: center !important;
        gap: 6px !important;
        width: auto !important;
    }

    .student-log-card .log-actions .grade-btn-group {
        display: flex !important;
        gap: 3px !important;
        flex: 0 0 auto !important;
    }

    .student-log-card .btn-grade {
        padding: 5px 6px !important;
        min-width: 28px !important;
        height: 28px !important;
        font-size: 10px !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
    }

    /* === ĂšJ: NaplĂłzĂˇs UI mobil optimalizĂˇciĂł === */
    .log-class-form-grid {
        display: flex;
        flex-direction: column !important;
        gap: 15px;
    }

    .log-details-column,
    .student-list-column {
        width: 100%;
    }

    .student-log-container {
        max-height: 60vh;
        overflow-y: auto;
        border: 1px solid #ddd;
        border-radius: 8px;
        padding: 10px;
    }

    .student-log-card {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 8px;
        padding: 10px;
        background: #f9f9f9;
        border-radius: 6px;
        margin-bottom: 8px;
    }

    .attendance-btn-group button {
        padding: 6px 8px;
        font-size: 12px;
    }

    .grade-btn-group {
        display: flex;
        gap: 4px;
    }

    .btn-grade {
        padding: 6px;
        min-width: 32px;
        font-size: 12px;
    }

    .common-grading-section {
        margin-top: 15px;
        padding: 12px;
        background: #f0f8ff;
        border-radius: 8px;
        border-left: 4px solid var(--primary-color);
    }

    .grading-control-group {
        margin-bottom: 12px;
    }

    .grading-control-group label {
        display: block;
        font-weight: 600;
        margin-bottom: 6px;
        font-size: 13px;
    }

    .grade-buttons-common {
        display: flex;
        gap: 6px;
        justify-content: space-between;
    }

    .btn-grade-common {
        flex: 1;
        padding: 8px 4px;
        font-size: 12px;
        min-width: 40px;
    }

    .modal-fullscreen {
        max-height: 95vh;
        width: 95vw;
    }

    .modal-footer {
        display: flex;
        gap: 8px;
        margin-top: 15px;
        flex-wrap: wrap;
    }

    .modal-footer button {
        flex: 1;
        min-width: 100px;
        padding: 10px 8px;
    }
}

/* Fix for mobile navigation centering */
@media (max-width: 768px) {
    #mobile-menu-overlay {
        justify-content: center !important;
        padding-top: 0 !important;
    }
    
    /* Ensure grading buttons are visible and usable on mobile */
    .grade-btn-group {
        display: flex !important;
        flex-wrap: wrap !important;
        justify-content: center !important;
        gap: 5px !important;
        width: 100% !important;
        margin-top: 5px;
    }
    
    .btn-grade {
        flex: 1 0 auto !important;
        min-width: 35px !important;
        height: 35px !important;
        padding: 0 !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
    }
    
    .btn-give-badge {
        width: 100% !important;
        margin-top: 8px !important;
        padding: 8px !important;
    }
    
    /* Fix modal positioning on mobile */
    .modal-backdrop {
        align-items: center !important;
        padding: 10px !important;
    }
    
    .modal-content {
        max-height: 90vh !important;
        margin: 0 auto !important;
    }

    /* === LOGIN PAGE MOBILE OPTIMIZATION === */
    .login-actions {
        display: flex;
        flex-direction: column;
        gap: 10px;
    }
    
    .login-actions button {
        width: 100%;
        display: block;
    }
    
    .btn-link {
        width: 100%;
        display: block;
    }
    
    .btn-secondary {
        width: 100%;
        display: block;
    }

    /* QR Reader mobile optimization */
    #qr-reader-container {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        width: 100% !important;
        height: 100% !important;
        z-index: 9999 !important;
    }

    #qr-reader {
        width: 95% !important;
        max-width: 100% !important;
        border-radius: 8px !important;
    }

    /* === ÚJ ELEMEK MOBIL OPTIMALIZÁLÁSA === */
    .user-details-grid {
        grid-template-columns: 1fr !important; /* Egy oszlop mobilon */
        gap: 10px !important;
    }

    .flex-desktop-row {
        flex-direction: column !important; /* Egymás alá kerüljenek */
        gap: 10px !important;
    }

    .recipient-label {
        padding: 10px 10px 10px 0 !important;
    }
}
