/**
 * School Grade Portal - Responsive Styles
 * 
 * @author Siam Thanat Hack Co., Ltd. (STH)
 * @description Responsive CSS for mobile and tablet devices
 */

/* Mobile First Approach */

/* Extra Small Devices (phones, less than 576px) */
@media (max-width: 575.98px) {
    body {
        padding: 5px;
        font-size: 14px;
    }
    
    .container,
    .login-container {
        margin: 0;
        border-radius: 0;
        min-height: 100vh;
    }
    
    .header {
        padding: 15px;
    }
    
    .header h1 {
        font-size: 1.5em;
        line-height: 1.2;
    }
    
    .header p {
        font-size: 1em;
    }
    
    .login-header h1 {
        font-size: 1.4em;
    }
    
    .dashboard-header {
        padding: 15px;
        flex-direction: column;
        text-align: center;
        gap: 10px;
    }
    
    .dashboard-header h1 {
        font-size: 1.4em;
    }
    
    .teachers-grid {
        grid-template-columns: 1fr;
        padding: 15px;
        gap: 15px;
    }
    
    .teacher-card {
        padding: 15px;
    }
    
    .teacher-photo {
        width: 60px;
        height: 60px;
        font-size: 18px;
        margin-bottom: 10px;
    }
    
    .teacher-name {
        font-size: 1.1em;
    }
    
    .teacher-motto {
        font-size: 0.85em;
    }
    
    .login-section {
        padding: 20px 15px;
    }
    
    .login-form {
        padding: 20px 15px;
    }
    
    .dashboard-content {
        padding: 15px;
    }
    
    .teacher-profile {
        padding: 15px;
    }
    
    .profile-header {
        flex-direction: column;
        text-align: center;
        gap: 15px;
    }
    
    .profile-info h2 {
        font-size: 1.3em;
    }
    
    .admin-section {
        padding: 15px;
    }
    
    .file-form {
        flex-direction: column;
        gap: 10px;
    }
    
    .file-form input {
        min-width: auto;
        width: 100%;
    }
    
    .file-form button {
        width: 100%;
        padding: 12px;
    }
    
    .btn {
        padding: 12px 20px;
        font-size: 0.9em;
    }
    
    .form-control {
        padding: 12px;
        font-size: 16px; /* Prevents zoom on iOS */
    }
    
    .footer {
        padding: 15px;
        font-size: 0.8em;
    }
    
    /* Touch-friendly interactions */
    .card,
    .teacher-card {
        min-height: 44px; /* Minimum touch target size */
    }
    
    .btn,
    button {
        min-height: 44px;
        min-width: 44px;
    }
    
    /* Notification adjustments */
    .notification {
        top: 10px;
        right: 10px;
        left: 10px;
        max-width: none;
        transform: translateY(-100%);
    }
    
    .notification.show {
        transform: translateY(0);
    }
}

/* Small Devices (landscape phones, 576px and up) */
@media (min-width: 576px) and (max-width: 767.98px) {
    body {
        padding: 10px;
    }
    
    .container,
    .login-container {
        border-radius: 10px;
    }
    
    .header h1 {
        font-size: 2em;
    }
    
    .teachers-grid {
        grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
        padding: 20px;
    }
    
    .dashboard-header {
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: space-between;
    }
    
    .profile-header {
        flex-direction: row;
        text-align: left;
    }
    
    .file-form {
        flex-direction: row;
    }
    
    .file-form input {
        flex: 1;
        min-width: 200px;
    }
}

/* Medium Devices (tablets, 768px and up) */
@media (min-width: 768px) and (max-width: 991.98px) {
    body {
        padding: 15px;
    }
    
    .header h1 {
        font-size: 2.2em;
    }
    
    .teachers-grid {
        grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
        padding: 25px;
    }
    
    .dashboard-content {
        padding: 25px;
    }
    
    .teacher-profile {
        padding: 20px;
    }
}

/* Large Devices (desktops, 992px and up) */
@media (min-width: 992px) and (max-width: 1199.98px) {
    .container {
        max-width: 960px;
    }
    
    .teachers-grid {
        grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    }
}

/* Extra Large Devices (large desktops, 1200px and up) */
@media (min-width: 1200px) {
    .container {
        max-width: 1140px;
    }
    
    .teachers-grid {
        grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    }
}

/* Landscape Orientation */
@media (orientation: landscape) and (max-height: 500px) {
    .header {
        padding: 15px 30px;
    }
    
    .header h1 {
        font-size: 1.8em;
        margin-bottom: 5px;
    }
    
    .header p {
        font-size: 1em;
    }
    
    .login-container {
        max-height: 90vh;
        overflow-y: auto;
    }
    
    .login-header {
        padding: 20px;
    }
    
    .login-form {
        padding: 20px;
    }
}

/* High DPI Displays */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .teacher-photo {
        background-size: cover;
    }
    
    /* Ensure crisp borders and shadows */
    .card,
    .teacher-card {
        box-shadow: 0 2.5px 7.5px rgba(0,0,0,0.1);
    }
    
    .container,
    .login-container {
        box-shadow: 0 10px 20px rgba(0,0,0,0.1);
    }
}

/* Dark Mode Support */
@media (prefers-color-scheme: dark) {
    :root {
        --text-primary: #e9ecef;
        --text-secondary: #adb5bd;
        --text-muted: #6c757d;
        --light-bg: #343a40;
        --border-color: #495057;
    }
    
    body {
        background: linear-gradient(135deg, #2c3e50 0%, #34495e 100%);
    }
    
    .container,
    .login-container {
        background: #212529;
        color: var(--text-primary);
    }
    
    .card,
    .teacher-card {
        background: #343a40;
        color: var(--text-primary);
    }
    
    .teacher-profile {
        background: #495057;
    }
    
    .form-control {
        background: #495057;
        border-color: #6c757d;
        color: var(--text-primary);
    }
    
    .form-control:focus {
        border-color: #667eea;
        background: #5a6268;
    }
    
    .file-content {
        background: #495057;
        border-color: #6c757d;
        color: var(--text-primary);
    }
}

/* Print Styles */
@media print {
    body {
        background: white !important;
        color: black !important;
        padding: 0;
    }
    
    .container,
    .login-container {
        box-shadow: none;
        border-radius: 0;
        max-width: none;
    }
    
    .header {
        background: none !important;
        color: black !important;
    }
    
    .btn,
    button,
    .logout-btn {
        display: none;
    }
    
    .admin-section {
        background: none !important;
        border: 1px solid #ccc;
    }
    
    .teacher-photo {
        background: #f8f9fa !important;
        color: black !important;
    }
    
    .footer {
        background: none !important;
        color: black !important;
        border-top: 1px solid #ccc;
    }
    
    .teachers-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 15px;
    }
    
    .card,
    .teacher-card {
        box-shadow: none;
        border: 1px solid #ccc;
        break-inside: avoid;
    }
    
    .page-break {
        page-break-before: always;
    }
}

/* Accessibility Improvements */
@media (prefers-reduced-motion: reduce) {
    .card:hover {
        transform: none;
    }
    
    .btn:hover {
        transform: none;
    }
    
    .teacher-photo::after {
        animation: none;
    }
    
    .header::before {
        animation: none;
    }
}

/* Focus Styles for Keyboard Navigation */
@media (any-hover: none) {
    .card:hover,
    .teacher-card:hover {
        transform: none;
        box-shadow: var(--shadow-light);
    }
    
    .btn:hover {
        transform: none;
    }
}

/* High Contrast Mode */
@media (prefers-contrast: high) {
    .btn {
        border: 2px solid currentColor;
    }
    
    .form-control {
        border: 2px solid currentColor;
    }
    
    .card,
    .teacher-card {
        border: 1px solid currentColor;
    }
    
    .teacher-photo {
        border: 2px solid currentColor;
    }
}

/* Custom Scrollbar for Mobile */
@media (max-width: 768px) {
    .file-content {
        scrollbar-width: thin;
        scrollbar-color: #667eea transparent;
    }
    
    .file-content::-webkit-scrollbar {
        width: 6px;
    }
    
    .file-content::-webkit-scrollbar-track {
        background: transparent;
    }
    
    .file-content::-webkit-scrollbar-thumb {
        background: #667eea;
        border-radius: 3px;
    }
}

/* Safe Area Insets for iPhone X and newer */
@supports (padding: max(0px)) {
    body {
        padding-left: max(10px, env(safe-area-inset-left));
        padding-right: max(10px, env(safe-area-inset-right));
        padding-bottom: max(10px, env(safe-area-inset-bottom));
    }
    
    .header {
        padding-top: max(30px, env(safe-area-inset-top));
    }
}

/* Hover States for Touch Devices */
@media (hover: none) and (pointer: coarse) {
    .hover-lift:hover,
    .hover-scale:hover,
    .hover-rotate:hover,
    .hover-glow:hover {
        transform: none;
        box-shadow: var(--shadow-light);
    }
    
    .card:hover,
    .teacher-card:hover {
        transform: none;
    }
    
    .btn:hover {
        transform: none;
    }
}

/* Landscape Phone Specific */
@media (max-width: 896px) and (orientation: landscape) and (max-height: 414px) {
    .container,
    .login-container {
        margin: 5px auto;
        max-height: calc(100vh - 10px);
        overflow-y: auto;
    }
    
    .header {
        padding: 10px 20px;
    }
    
    .teachers-grid {
        padding: 15px;
        grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    }
    
    .dashboard-content {
        padding: 15px;
    }
}