/**
 * ATLAS - Responsive Design Enhancements
 * Ensures all UI elements work perfectly on all screen sizes
 */

/* ============================================
   Mobile-First Base Adjustments
   ============================================ */

* {
    box-sizing: border-box;
}

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
}

body {
    overflow-x: hidden;
}

/* ============================================
   Header Responsive
   ============================================ */

@media (max-width: 1024px) {
    .app-header {
        padding: 0.75rem 1rem;
    }

    .header-left {
        flex-wrap: wrap;
    }

    .logo {
        margin-right: 1rem;
    }

    .logo-text {
        font-size: 1.25rem;
    }

    .main-nav {
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .nav-btn {
        padding: 0.5rem 0.75rem;
        font-size: 0.875rem;
    }
}

@media (max-width: 768px) {
    .app-header {
        flex-direction: column;
        align-items: stretch;
        gap: 0.75rem;
    }

    .header-left,
    .header-right {
        width: 100%;
        justify-content: space-between;
    }

    .main-nav {
        order: 3;
        width: 100%;
        justify-content: center;
    }

    .class-indicator {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.25rem;
    }

    .class-name {
        font-size: 0.875rem;
    }

    .class-code {
        font-size: 0.75rem;
    }

    .user-btn {
        padding: 0.5rem;
    }

    .user-name {
        display: none;
    }
}

/* ============================================
   Sidebar Responsive
   ============================================ */

@media (max-width: 1024px) {
    .sidebar {
        width: 200px;
    }

    .topic-item {
        padding: 0.75rem;
    }

    .topic-desc {
        font-size: 0.75rem;
    }

    .topic-progress {
        font-size: 0.75rem;
    }
}

@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: -280px;
        top: 0;
        height: 100vh;
        width: 280px;
        z-index: 999;
        transition: left 0.3s ease;
        box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
        background: var(--bg-primary);
    }

    .sidebar.mobile-open {
        left: 0;
    }

    .sidebar-section {
        padding: 1rem;
    }
}

/* ============================================
   Workspace Responsive
   ============================================ */

@media (max-width: 1200px) {
    .workspace {
        padding: 1.5rem;
    }

    .editor-section {
        min-height: 400px;
    }
}

@media (max-width: 768px) {
    .workspace {
        padding: 1rem;
    }

    .workspace-header {
        flex-direction: column;
        align-items: stretch;
        gap: 1rem;
    }

    .workspace-actions {
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .editor-container {
        flex-direction: column;
    }

    .editor-section {
        width: 100% !important;
        min-height: 300px;
    }

    .test-panel {
        width: 100% !important;
        max-width: none;
        margin-top: 1rem;
    }

    .toolbar {
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .toolbar-group {
        flex-wrap: wrap;
    }

    .tool-btn {
        min-width: 40px;
        padding: 0.5rem;
    }
}

/* ============================================
   Modal Responsive
   ============================================ */

@media (max-width: 768px) {
    .modal-content {
        width: 95%;
        max-width: 95vw;
        max-height: 90vh;
        margin: 1rem;
        padding: 1rem;
    }

    .auth-modal {
        padding: 1.5rem;
    }

    .modal-header h2 {
        font-size: 1.5rem;
    }

    .form-group label {
        font-size: 0.875rem;
    }

    .btn-full {
        padding: 0.875rem 1rem;
    }
}

/* ============================================
   Tables Responsive
   ============================================ */

@media (max-width: 768px) {
    .roster-table,
    .problems-table {
        display: block;
        overflow-x: auto;
        white-space: nowrap;
    }

    .roster-table table,
    .problems-table table {
        min-width: 600px;
    }

    .table-responsive {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
}

/* ============================================
   Dashboard Cards Responsive
   ============================================ */

@media (max-width: 1024px) {
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .chart-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }

    .stat-card {
        padding: 1.5rem;
    }

    .stat-value {
        font-size: 2rem;
    }

    .stat-label {
        font-size: 0.875rem;
    }
}

/* ============================================
   Problems View Responsive
   ============================================ */

@media (max-width: 768px) {
    .problems-grid {
        grid-template-columns: 1fr;
    }

    .problem-card {
        padding: 1rem;
    }

    .problem-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }

    .difficulty-badge {
        font-size: 0.75rem;
        padding: 0.25rem 0.5rem;
    }
}

/* ============================================
   Progress View Responsive
   ============================================ */

@media (max-width: 768px) {
    .progress-overview {
        flex-direction: column;
    }

    .progress-circle {
        width: 150px;
        height: 150px;
    }

    .topic-progress-list {
        grid-template-columns: 1fr;
    }
}

/* ============================================
   Study View Responsive
   ============================================ */

@media (max-width: 1024px) {
    .modules-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 768px) {
    .modules-grid {
        grid-template-columns: 1fr;
    }

    .module-card {
        padding: 1rem;
    }

    .flashcard-container {
        padding: 1rem;
    }

    .flashcard {
        height: 300px;
    }
}

/* ============================================
   Canvas Responsive
   ============================================ */

@media (max-width: 768px) {
    #automatonCanvas {
        touch-action: none;
        min-height: 250px;
    }

    .canvas-container {
        position: relative;
        overflow: hidden;
    }

    /* Enable touch gestures for canvas */
    .canvas-container canvas {
        touch-action: pan-x pan-y pinch-zoom;
    }
}

/* ============================================
   Utility Classes for Responsive
   ============================================ */

.hide-mobile {
    display: block;
}

.show-mobile {
    display: none;
}

@media (max-width: 768px) {
    .hide-mobile {
        display: none !important;
    }

    .show-mobile {
        display: block !important;
    }
}

/* ============================================
   Touch-Friendly Interactions
   ============================================ */

@media (hover: none) and (pointer: coarse) {
    /* Touch devices */
    button,
    .nav-btn,
    .topic-item,
    .tool-btn {
        min-height: 44px;
        min-width: 44px;
    }

    .dropdown-item {
        padding: 0.875rem 1rem;
    }

    /* Increase tap targets */
    a,
    button,
    input[type="checkbox"],
    input[type="radio"] {
        min-height: 44px;
        display: inline-flex;
        align-items: center;
    }
}

/* ============================================
   Scrollbar Styling
   ============================================ */

@media (min-width: 768px) {
    /* Custom scrollbar for desktop */
    ::-webkit-scrollbar {
        width: 8px;
        height: 8px;
    }

    ::-webkit-scrollbar-track {
        background: var(--bg-secondary);
    }

    ::-webkit-scrollbar-thumb {
        background: var(--border);
        border-radius: 4px;
    }

    ::-webkit-scrollbar-thumb:hover {
        background: var(--text-tertiary);
    }
}

/* ============================================
   Print Styles
   ============================================ */

@media print {
    .app-header,
    .sidebar,
    .toolbar,
    .modal,
    .toast,
    .mobile-menu-toggle {
        display: none !important;
    }

    .workspace,
    .problems-view,
    .progress-view,
    .study-view {
        max-width: 100%;
        padding: 0;
    }

    body {
        background: white;
        color: black;
    }

    .editor-section,
    .test-panel {
        border: 1px solid #ccc;
    }
}

/* ============================================
   High Contrast Mode
   ============================================ */

@media (prefers-contrast: high) {
    :root {
        --border: #000;
        --text-primary: #000;
        --text-secondary: #000;
    }

    button,
    .nav-btn,
    .topic-item {
        border: 2px solid currentColor;
    }
}

/* ============================================
   Reduced Motion
   ============================================ */

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }

    .sidebar,
    .main-nav,
    .modal {
        transition: none !important;
    }
}

/* ============================================
   Focus Visible (Keyboard Navigation)
   ============================================ */

@supports selector(:focus-visible) {
    *:focus {
        outline: none;
    }

    *:focus-visible {
        outline: 2px solid var(--primary);
        outline-offset: 2px;
    }
}

/* ============================================
   Landscape Orientation (Mobile)
   ============================================ */

@media (max-width: 768px) and (orientation: landscape) {
    .workspace {
        padding: 0.5rem;
    }

    .editor-section {
        min-height: 200px;
    }

    .sidebar {
        width: 200px;
    }

    .modal-content {
        max-height: 85vh;
        overflow-y: auto;
    }
}
