/* OER Frontend - Responsive Styles
 * Mobile-first responsive design
 */

/* ============================================
   Tablet and smaller (max-width: 1024px)
   ============================================ */
@media (max-width: 1024px) {
  :root {
    --sidebar-width: 240px;
  }

  .container {
    padding: 0 var(--spacing-md);
  }

  .grid-4 {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* ============================================
   Mobile landscape and tablet portrait (max-width: 768px)
   ============================================ */
@media (max-width: 768px) {
  :root {
    --navbar-height: 56px;
  }

  /* Typography adjustments */
  h1 { font-size: var(--font-size-2xl); }
  h2 { font-size: var(--font-size-xl); }

  /* Grid adjustments */
  .grid-2,
  .grid-3,
  .grid-4 {
    grid-template-columns: 1fr;
  }

  /* Navbar mobile */
  .navbar-nav {
    display: none;
  }

  .navbar-container {
    padding: 0 var(--spacing-md);
  }

  .navbar-mobile-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 42px;
    background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    cursor: pointer;
    color: #475569;
    transition: all 0.2s ease;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
  }

  .navbar-mobile-toggle:hover {
    background: linear-gradient(135deg, #eff6ff 0%, #dbeafe 100%);
    border-color: #bfdbfe;
    color: #2563eb;
  }

  .navbar-mobile-toggle .material-icons {
    font-size: 22px;
  }

  /* Mobile menu backdrop */
  .mobile-menu-backdrop {
    display: block;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 998;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
  }

  .mobile-menu-backdrop.active {
    opacity: 1;
    visibility: visible;
  }

  /* Mobile menu */
  .mobile-menu {
    display: block;
    position: fixed;
    top: 0;
    left: 0;
    width: 300px;
    max-width: 85vw;
    height: 100vh;
    background-color: #fff;
    padding: 0;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    z-index: 999;
    overflow-y: auto;
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.15);
  }

  .mobile-menu.active {
    transform: translateX(0);
  }

  /* Mobile menu header */
  .mobile-menu-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid #e5e7eb;
    background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
  }

  .mobile-menu-title {
    font-size: 18px;
    font-weight: 700;
    color: #fff;
  }

  .mobile-menu-close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background: rgba(255, 255, 255, 0.2);
    border: none;
    border-radius: 8px;
    cursor: pointer;
    color: #fff;
    transition: background 0.2s ease;
  }

  .mobile-menu-close:hover {
    background: rgba(255, 255, 255, 0.3);
  }

  .mobile-menu-close .material-icons {
    font-size: 24px;
  }

  .mobile-menu-nav {
    list-style: none;
    margin: 0;
    padding: 12px 0;
  }

  .mobile-menu-nav li {
    border-bottom: 1px solid #f1f5f9;
  }

  .mobile-menu-nav li:last-child {
    border-bottom: none;
  }

  .mobile-menu-nav a {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 16px 20px;
    margin: 4px 12px;
    color: #475569;
    text-decoration: none;
    font-size: 15px;
    font-weight: 500;
    border-radius: 12px;
    transition: all 0.2s ease;
  }

  .mobile-menu-nav a .material-icons {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f1f5f9;
    border-radius: 10px;
    color: #64748b;
    font-size: 20px;
    transition: all 0.2s ease;
  }

  .mobile-menu-nav a:hover {
    background-color: #f8fafc;
    color: #1e293b;
  }

  .mobile-menu-nav a:hover .material-icons {
    background: #eff6ff;
    color: #2563eb;
  }

  .mobile-menu-nav a.active {
    background-color: #eff6ff;
    color: #2563eb;
  }

  .mobile-menu-nav a.active .material-icons {
    background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
    color: #fff;
  }

  /* Hero adjustments */
  .hero {
    padding: 40px 0 32px;
  }

  .hero h1 {
    font-size: 1.75rem;
  }

  .hero p {
    font-size: 15px;
  }

  /* Page Header */
  .page-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 16px;
  }

  .page-header-content {
    width: 100%;
  }

  .page-header-actions {
    width: 100%;
    display: flex;
    gap: 8px;
  }

  .page-header-actions .btn {
    flex: 1;
    justify-content: center;
  }

  .page-title-row {
    flex-wrap: wrap;
    gap: 8px;
  }

  .page-title-row h1 {
    font-size: 1.5rem;
    flex: 1;
    min-width: 200px;
  }

  .school-code-subtitle {
    font-size: 13px;
    margin-left: 44px;
  }

  /* User menu in navbar */
  .user-menu {
    display: none;
  }

  .navbar-actions .btn-login {
    padding: 8px 14px;
    font-size: 13px;
  }

  .navbar-actions .btn-login span:not(.material-icons) {
    display: none;
  }

  .navbar-actions .btn-login .material-icons {
    margin: 0;
  }

  /* Search form */
  .search-input-group {
    flex-direction: column;
  }

  .search-input-group .btn {
    width: 100%;
  }

  /* School cards */
  .school-cards-grid {
    grid-template-columns: 1fr;
  }

  /* Result cards */
  .result-card {
    flex-direction: column;
  }

  .result-icon {
    align-self: flex-start;
  }

  .result-actions {
    flex-direction: row;
    width: 100%;
  }

  .result-actions .btn {
    flex: 1;
  }

  /* Repo layout */
  .repo-layout {
    flex-direction: column;
    gap: 16px;
  }

  .repo-sidebar {
    width: 100% !important;
    min-width: 100% !important;
    max-height: 350px;
    overflow: hidden;
  }

  .repo-sidebar.collapsed {
    max-height: 56px;
  }

  .repo-sidebar.collapsed #folder-tree {
    display: none;
  }

  #folder-tree {
    max-height: 280px;
  }

  .sidebar-header {
    cursor: pointer;
  }

  .sidebar-header::after {
    content: 'expand_more';
    font-family: 'Material Icons';
    font-size: 20px;
    color: #9ca3af;
    transition: transform 0.2s ease;
  }

  .repo-sidebar.collapsed .sidebar-header::after {
    transform: rotate(-90deg);
  }

  .repo-content {
    width: 100%;
  }

  /* File detail panel - full screen on mobile */
  .repo-detail {
    width: 100% !important;
    max-width: 100vw;
  }

  .repo-detail-backdrop {
    display: block;
  }

  #file-detail-content {
    padding: 24px 16px;
  }

  .detail-file-icon {
    width: 72px;
    height: 72px;
  }

  .detail-file-icon .material-icons {
    font-size: 36px;
  }

  .detail-file-name {
    font-size: 18px;
  }

  .detail-actions {
    flex-direction: row;
    flex-wrap: wrap;
  }

  .detail-actions .btn {
    flex: 1;
    min-width: calc(50% - 6px);
  }

  /* File table responsive */
  .file-table-container {
    overflow-x: auto;
    margin: 0 -16px;
    padding: 0 16px;
  }

  .file-table {
    min-width: 500px;
  }

  /* Cards */
  .card {
    border-radius: 12px;
  }

  .card-body {
    padding: 16px;
  }

  /* Folder header */
  .folder-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }

  .folder-header h2 {
    font-size: 1.25rem;
  }

  .folder-tags {
    flex-wrap: wrap;
  }

  /* Resource search form */
  .resource-search-form .search-row {
    flex-direction: column;
  }

  .resource-search-form .search-row .form-group {
    min-width: 100%;
  }

  /* Form rows */
  .form-row {
    flex-direction: column;
  }

  .form-row .form-group {
    min-width: 100% !important;
    flex: 1 1 100% !important;
  }

  .form-row .form-group[style*="flex: 0 0"] {
    flex: 1 1 100% !important;
  }

  /* Search section */
  .search-section {
    padding: 0 8px;
  }

  .search-section h2 {
    font-size: 1.25rem;
  }

  .search-form {
    padding: 16px;
  }

  .search-form .btn {
    width: 100%;
    justify-content: center;
  }

  /* Modal */
  .modal {
    width: 95%;
    max-height: 95vh;
  }

  .modal-body {
    max-height: calc(95vh - 140px);
  }

  /* Toast */
  .toast-container {
    left: var(--spacing-md);
    right: var(--spacing-md);
    top: calc(var(--navbar-height) + var(--spacing-md));
  }

  .toast {
    min-width: auto;
    max-width: none;
  }

  /* Dashboard grid */
  .dashboard-grid {
    grid-template-columns: 1fr;
  }

  /* Profile header */
  .profile-header {
    flex-direction: column;
    text-align: center;
  }

  /* Pagination */
  .pagination {
    flex-wrap: wrap;
  }

  .pagination-info {
    width: 100%;
    text-align: center;
    margin-left: 0;
    margin-top: var(--spacing-sm);
  }

  /* Favourites */
  .favourite-card {
    flex-direction: column;
  }

  .favourite-actions {
    width: 100%;
    justify-content: flex-end;
  }
}

/* ============================================
   Mobile portrait (max-width: 480px)
   ============================================ */
@media (max-width: 480px) {
  :root {
    --spacing-lg: 1rem;
    --spacing-xl: 1.5rem;
  }

  .container {
    padding: 0 12px;
  }

  /* Page title */
  .page-title-row h1 {
    font-size: 1.25rem;
  }

  .school-code-subtitle {
    font-size: 12px;
    margin-left: 40px;
  }

  .back-link-minimal {
    width: 32px;
    height: 32px;
  }

  .back-link-minimal .material-icons {
    font-size: 24px;
  }

  /* Buttons full width */
  .btn-block-mobile {
    width: 100%;
  }

  /* Form actions stack */
  .form-actions {
    flex-direction: column;
  }

  .form-actions .btn {
    width: 100%;
  }

  /* Table adjustments */
  .file-table {
    font-size: 12px;
    min-width: 400px;
  }

  .file-table th,
  .file-table td {
    padding: 8px;
  }

  /* Hide less important table columns */
  .file-table .hide-mobile {
    display: none;
  }

  /* Breadcrumb */
  .breadcrumb {
    font-size: 12px;
    flex-wrap: wrap;
  }

  .breadcrumb-container {
    padding: 8px 0;
  }

  /* Search type toggle */
  .search-type-toggle {
    flex-direction: column;
    gap: 8px;
  }

  /* Panel header */
  .panel-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }

  .folder-actions {
    width: 100%;
    flex-wrap: wrap;
  }

  .folder-actions .btn {
    flex: 1;
    min-width: calc(50% - 4px);
    font-size: 12px;
    padding: 8px 12px;
  }

  /* Stats */
  .stat-row {
    flex-direction: column;
    gap: 12px;
  }

  /* Lang switcher */
  .lang-switcher {
    display: none;
  }

  /* Repo sidebar */
  .repo-sidebar {
    max-height: 300px;
    border-radius: 8px;
  }

  #folder-tree {
    max-height: 230px;
  }

  .sidebar-header {
    padding: 12px;
  }

  .sidebar-header h2 {
    font-size: 13px;
  }

  /* Tree items */
  .tree-item {
    padding: 6px 10px;
    font-size: 13px;
  }

  .tree-icon {
    width: 24px;
    height: 24px;
  }

  .tree-icon .material-icons {
    font-size: 14px;
  }

  .tree-tags {
    display: none;
  }

  /* File detail panel */
  #file-detail-content {
    padding: 16px 12px;
  }

  .detail-file-icon {
    width: 56px;
    height: 56px;
  }

  .detail-file-icon .material-icons {
    font-size: 28px;
  }

  .detail-file-name {
    font-size: 16px;
  }

  .detail-meta {
    gap: 8px;
  }

  .detail-meta-item {
    font-size: 12px;
  }

  .detail-section h4 {
    font-size: 13px;
  }

  .detail-tags .tag {
    font-size: 11px;
    padding: 4px 8px;
  }

  .detail-actions .btn {
    min-width: 100%;
    padding: 10px 16px;
  }

  /* Modal */
  .modal {
    width: 100%;
    max-width: 100%;
    height: 100%;
    max-height: 100%;
    border-radius: 0;
  }

  .modal-body {
    max-height: calc(100vh - 140px);
  }

  .modal-header {
    padding: 16px;
  }

  .modal-body {
    padding: 16px;
  }

  .modal-footer {
    padding: 16px;
    flex-direction: column;
  }

  .modal-footer .btn {
    width: 100%;
  }

  /* Footer */
  footer {
    padding: 24px 0;
  }

  footer p::before {
    display: none;
  }

  /* Cards */
  .card-body {
    padding: 12px;
  }

  .card-header {
    padding: 12px;
  }

  /* Form controls */
  .form-control {
    font-size: 16px; /* Prevents zoom on iOS */
    padding: 10px 12px;
  }

  /* Hero */
  .hero {
    padding: 24px 0;
  }

  .hero h1 {
    font-size: 1.5rem;
  }
}

/* ============================================
   Print styles
   ============================================ */
@media print {
  .navbar,
  .sidebar-toggle-mobile,
  .repo-sidebar,
  .folder-actions,
  .pagination,
  .toast-container,
  .modal-backdrop,
  .btn,
  footer {
    display: none !important;
  }

  body {
    background: white;
    color: black;
  }

  .container {
    max-width: 100%;
    padding: 0;
  }

  .card,
  .school-card,
  .result-card,
  .favourite-card {
    box-shadow: none;
    border: 1px solid #ccc;
  }

  a {
    color: black;
    text-decoration: underline;
  }

  .repo-content {
    grid-template-columns: 1fr;
  }
}

/* ============================================
   High contrast mode
   ============================================ */
@media (prefers-contrast: high) {
  :root {
    --color-border: #666;
    --color-text-muted: #444;
  }

  .btn-secondary {
    border-width: 2px;
  }

  .form-control {
    border-width: 2px;
  }
}

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

/* ============================================
   Dark mode (future enhancement)
   ============================================ */
@media (prefers-color-scheme: dark) {
  /* Placeholder for future dark mode support */
  /* Users can enable via system preferences */
}
