/* ==========================================================================
   responsive.css — Afaq Platform Cross-Device Layout & Touch Optimization
   Breakpoints: Mobile (<= 640px), Tablet (641px - 1023px), Desktop (>= 1024px)
   ========================================================================== */

/* 1. Global Box Sizing & Fluid Overflow Protection */
*, *::before, *::after {
  box-sizing: border-box;
}

#main-content {
  min-width: 0;
  width: 100%;
}

#main-content :where(h1, h2, h3, h4, h5, h6, p, label, dd, dt, a, span) {
  overflow-wrap: anywhere;
  word-break: break-word;
}

#main-content :where(input, select, textarea, fieldset, button) {
  min-width: 0;
  max-width: 100%;
}

#main-content :where(.grid, .flex) > * {
  min-width: 0;
}

img, video, svg, canvas, iframe {
  max-width: 100%;
  height: auto;
}

/* 2. Responsive Tables & Overflow Handling */
#main-content .overflow-x-auto,
.table-responsive-wrapper {
  max-width: 100%;
  overscroll-behavior-x: contain;
  -webkit-overflow-scrolling: touch;
}

#main-content .overflow-x-auto:focus-visible,
.table-responsive-wrapper:focus-visible {
  outline: 3px solid #0D9A9B;
  outline-offset: 2px;
}

header form {
  min-width: 0;
}

.activity-layout > *,
.activity-stack,
.activity-panel,
.game-card {
  min-width: 0;
}

.game-options {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.game-option {
  overflow-wrap: anywhere;
  min-width: 0;
}

/* 3. Desktop Ergonomics (>= 1024px) */
@media (min-width: 1024px) {
  #sidebar {
    position: sticky;
    top: 0;
    align-self: flex-start;
    height: 100vh;
    height: 100dvh;
    flex-shrink: 0;
  }
}

/* 4. Tablet Landscape & Portrait (641px - 1023px) */
@media (min-width: 641px) and (max-width: 1023px) {
  .grid-cols-4,
  .grid-cols-5,
  .grid-cols-6 {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }

  .grid-cols-3 {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }

  #main-content {
    padding: 1.25rem;
  }

  /* Activity layout stacks on tablets if space is tight */
  .activity-layout {
    grid-template-columns: 1fr;
    gap: 1.25rem;
  }
}

/* 5. Mobile Ergonomics (<= 640px) */
@media (max-width: 640px) {
  /* Prevent iOS Safari auto-zoom on input focus */
  input:not([type="checkbox"]):not([type="radio"]),
  select,
  textarea,
  input.nu-field,
  .field {
    font-size: 16px !important;
  }

  /* Touch Target Standard: 44px minimum touch height */
  .btn,
  button:not(.act):not(.toast-close-btn),
  a.btn {
    white-space: normal;
    min-height: 44px;
    max-width: 100%;
  }

  .act {
    width: 44px;
    height: 44px;
  }

  #menu-btn,
  #sidebar-close,
  header a[title] {
    min-width: 44px;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  /* Responsive Grid Adjustments for Mobile */
  .grid-cols-2,
  .grid-cols-3,
  .grid-cols-4,
  .grid-cols-5,
  .grid-cols-6 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.75rem;
  }

  /* Narrow mobile: single column when needed */
  @media (max-width: 380px) {
    .grid-cols-2 {
      grid-template-columns: minmax(0, 1fr);
    }
  }

  /* Page title and actions header wrapping */
  #main-content > div.flex.flex-wrap.items-start.justify-between {
    flex-direction: column;
    gap: 1rem;
  }

  #main-content > div.flex.flex-wrap.items-start.justify-between > div.flex {
    width: 100%;
    justify-content: flex-start;
  }

  #main-content > div.flex.flex-wrap.items-start.justify-between > div.flex > * {
    flex: 1 1 auto;
  }

  /* Activity & Game elements */
  .activity-panel,
  .game-card {
    padding: 16px;
    border-radius: 14px;
  }

  .activity-hero {
    padding: 18px;
    border-radius: 18px;
  }

  .game-options {
    grid-template-columns: minmax(0, 1fr) !important;
    gap: 8px;
  }

  .activity-title {
    overflow-wrap: anywhere;
    font-size: 1.35rem;
  }

  /* Login Card Responsiveness */
  .auth-card {
    border-radius: 16px;
    margin: 1rem 0;
  }

  .auth-card .grid {
    grid-template-columns: 1fr;
  }

  .auth-art {
    display: none; /* Hide visual art banner on mobile to keep login fast and centered */
  }

  /* Mobile sidebar drawer */
  #sidebar {
    max-width: min(84vw, 300px);
    height: 100vh;
    height: 100dvh;
    box-shadow: -8px 0 24px rgba(7, 52, 90, 0.25);
    padding-top: env(safe-area-inset-top, 0);
    padding-bottom: env(safe-area-inset-bottom, 0);
  }

  /* Smooth backdrop blur when drawer is open */
  #overlay:not(.hidden) {
    display: block;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
  }

  /* Mobile header padding */
  header.h-\[68px\] {
    padding-inline: 0.75rem;
  }

  /* Mobile Stepper in Lessons */
  .lesson-steps {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .lesson-steps a {
    padding: 10px 14px;
  }
}

/* 6. Public Footer Grid */
.footer-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 24px 16px;
  padding: 28px 20px;
}

.footer-grid > * {
  min-width: 0;
}

.footer-brand {
  grid-column: 1 / -1;
  padding-bottom: 24px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.14);
}

.site-footer p,
.site-footer a {
  overflow-wrap: anywhere;
}

.footer-brand > p {
  max-width: 38rem;
  line-height: 1.9;
}

.footer-links a {
  display: flex;
  align-items: center;
  min-height: 44px;
  padding: 8px 0;
  font-size: 14px;
  line-height: 1.6;
}

.footer-links a:focus-visible {
  outline: 2px solid #FDB833;
  outline-offset: 3px;
  border-radius: 4px;
}

.footer-grid h3 {
  margin-bottom: 8px;
}

@media (min-width: 768px) {
  .footer-grid {
    grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr) minmax(0, 1fr);
    gap: 40px;
    padding: 48px 24px;
  }

  .footer-brand {
    grid-column: auto;
    padding-bottom: 0;
    border-bottom: 0;
  }

  .footer-grid h3 {
    margin-bottom: 16px;
  }
}

/* 7. Print Responsiveness */
@media print {
  #sidebar,
  #overlay,
  #sidebar-close {
    display: none !important;
  }

  .overflow-x-auto {
    overflow: visible !important;
  }
}

/* 8. Grid Spans Utilities Fallback */
@media (min-width: 768px) {
  .md\:col-span-5 { grid-column: span 5 / span 5; }
  .md\:col-span-6 { grid-column: span 6 / span 6; }
  .md\:col-span-7 { grid-column: span 7 / span 7; }
  .md\:col-span-8 { grid-column: span 8 / span 8; }
  .md\:col-span-9 { grid-column: span 9 / span 9; }
  .md\:col-span-10 { grid-column: span 10 / span 10; }
  .md\:col-span-11 { grid-column: span 11 / span 11; }
  .md\:col-span-12 { grid-column: span 12 / span 12; }
}

/* Shared device ergonomics; keep table scrolling inside its own region. */
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
#sidebar nav { min-height: 0; }
#sidebar .nav-item { min-height: 44px; }
input[type="checkbox"], input[type="radio"] { flex-shrink: 0; }
details > summary { min-height: 44px; padding-block: 10px; }

.gradebook-filters {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 16px;
  align-items: end;
}
.gradebook-filters > * { min-width: 0; }
.gradebook-filters :is(input, select, button) { min-height: 44px; }
.gradebook-scroll {
  overflow: auto;
  max-height: 75vh;
  max-height: 75dvh;
  margin-bottom: 0;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  overscroll-behavior-inline: contain;
}
.gradebook-table .gradebook-student {
  position: sticky;
  inset-inline-start: 0;
  min-width: 120px;
  max-width: 220px;
  width: clamp(120px, 20vw, 220px);
  overflow-wrap: anywhere;
  background: #fff;
  z-index: 1;
  border-inline-end: 1px solid #e3e9ef;
}
.gradebook-table thead .gradebook-student { z-index: 3; background: #f8fafc; }
.gradebook-table .gradebook-result { min-width: 82px; text-align: center; }
.gradebook-scroll-hint { line-height: 1.8; }

/* Spreadsheet-style grade register: strong headers and a readable cell grid. */
.gradebook-sheet { border-block-start: 1px solid #c7d5e1; }
.gradebook-sheet :is(th, td) {
  border-inline-end: 1px solid #c7d5e1;
  border-block-end: 1px solid #c7d5e1;
  vertical-align: middle;
}
.gradebook-sheet thead th { text-align: center; font-weight: 700; }
.gradebook-sheet .gradebook-groups > th { background: #07345a; color: #fff; }
.gradebook-sheet .gradebook-groups .gradebook-student { background: #07345a; color: #fff; }
.gradebook-sheet thead .gradebook-task { background: #eaf0f6; color: #07345a; }
.gradebook-sheet .gradebook-category-homework { box-shadow: inset 0 -4px #66b8be; }
.gradebook-sheet .gradebook-category-activity { box-shadow: inset 0 -4px #e5b554; }
.gradebook-sheet .gradebook-category-quiz { box-shadow: inset 0 -4px #a8b7de; }
.gradebook-sheet tbody tr { background: #fff; }
.gradebook-sheet tbody tr:nth-child(even) { background: #f5f8fb; }
.gradebook-sheet tbody tr:hover { background: #edf5fa; }
.gradebook-sheet tbody :is(th, td) { background: inherit; min-height: 52px; }
.gradebook-sheet .gradebook-number {
  position: sticky;
  inset-inline-start: 0;
  min-width: 44px;
  width: 44px;
  padding: 12px 8px;
  text-align: center;
  z-index: 1;
}
.gradebook-sheet .gradebook-student { inset-inline-start: 44px; }
.gradebook-sheet thead :is(.gradebook-number, .gradebook-student) { z-index: 3; }
.gradebook-sheet tbody .gradebook-letter { background: #edf4fa; color: #07345a; }
.gradebook-sheet tbody .gradebook-final { background: #e5f3ee; color: #145a46; }
@media print {
  .gradebook-sheet .gradebook-number { position: static; }
}

@media (min-width: 640px) {
  .gradebook-filters { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (min-width: 1100px) {
  .gradebook-filters { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1.3fr) auto; }
}
@media (min-width: 1024px) {
  #sidebar-close { display: none; }
}
@media (max-width: 1023px), (hover: none) and (pointer: coarse) {
  input:not([type="checkbox"]):not([type="radio"]), select, textarea {
    font-size: 16px !important;
  }
  .btn, .act, #menu-btn, #sidebar-close { min-height: 44px; }
  .act, #menu-btn, #sidebar-close { min-width: 44px; }
  #sidebar { max-width: min(84vw, 300px); }
}
@media (max-width: 640px) {
  .js-card > .flex {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: start;
  }
  .js-card > .flex > div { width: 100%; }
  .js-card > .flex > :nth-child(3), .js-card > .flex > :last-child { grid-column: 1 / -1; }
  .js-card > .flex > :last-child { margin-inline-start: 0; }
  .js-optrow > input[type="text"] { width: 0; flex: 1 1 0%; }
  .gradebook-table :is(th, td) { padding: 12px 10px; }
}
@media (hover: none) {
  .card:hover, .nav-item:hover, .btn:hover { transform: none; }
}
@media print {
  .gradebook-filters, .gradebook-scroll-hint { display: none; }
  .gradebook-scroll { max-height: none; overflow: visible; }
  .gradebook-table .gradebook-student { position: static; }
}

/* Consistent gradebook icons and controls. */
.students-directory table { min-width:900px; }
.students-directory table :is(th,td) { vertical-align:middle; }
.students-directory table td > span { white-space:nowrap; flex-wrap:nowrap; }
.students-directory table td:nth-child(2) { min-width:110px; }
.students-directory table td:nth-child(4) { min-width:108px; }
.students-directory table td:first-child { min-width:225px; }
.students-directory bdi { unicode-bidi:isolate; white-space:nowrap; }
.students-directory .students-filter-summary { display:flex; align-items:center; gap:10px; }
.students-directory .students-filter-summary > :is(div,a) { margin-block:0; align-self:center; }
.students-directory .students-filter-summary > div { min-height:40px; display:inline-flex; align-items:center; box-sizing:border-box; }
.students-directory .students-filter-summary > div:last-child { padding-block:8px; }
.students-directory table .act { display:inline-flex; align-items:center; justify-content:center; min-width:40px; min-height:40px; }
.students-directory table .inline-flex { gap:6px; line-height:1.5; }
.students-directory .w-12.h-12 { background:#07345a; color:white; }
.students-directory > .grid > div:nth-child(2) .w-12.h-12 { background:#087e83; }
.students-directory > .grid > div:nth-child(3) .w-12.h-12 { background:#14734d; }
.students-directory > .grid > div:nth-child(4) .w-12.h-12 { background:#a64d0b; }
@media (max-width:1023px) { .students-directory table .act { min-width:44px; min-height:44px; } }
.teacher-dashboard-stats > a .w-12.h-12 { background:#07345a; color:#fff; opacity:1; }
.teacher-dashboard-stats > a:nth-child(2) .w-12.h-12 { background:#087e83; }
.teacher-dashboard-stats > a:nth-child(3) .w-12.h-12 { background:#14734d; }
.teacher-dashboard-stats > a:nth-child(4) .w-12.h-12 { background:#a64d0b; }
.teacher-dashboard-stats > a .w-12.h-12 i { color:#fff; opacity:1; font-size:20px; }
.gradebook-page .gradebook-sheet { border-block-start:1px solid #e2e9ed; }
.gradebook-page .gradebook-sheet :is(th,td) { border-inline-end:0; border-block-end:1px solid #e7edf1; padding:18px 16px; }
.gradebook-page .gradebook-sheet .gradebook-groups > th,
.gradebook-page .gradebook-sheet .gradebook-groups .gradebook-student { background:#fff; color:#567076; }
.gradebook-page .gradebook-sheet .gradebook-category { box-shadow:none; color:#0b9186; }
.gradebook-page .gradebook-sheet thead .gradebook-task { background:#fff; color:#0b9186; }
.gradebook-page .gradebook-sheet tbody tr { background:#fff; }
.gradebook-page .gradebook-sheet tbody tr:hover { background:#f4faf9; }
.gradebook-page .gradebook-sheet tbody .gradebook-letter,
.gradebook-page .gradebook-sheet tbody .gradebook-final { background:inherit; color:#0b9186; }
.gradebook-page .gradebook-sheet .gradebook-number { padding:12px 8px; color:#8c9da2; }
.gradebook-student-name { display:flex; align-items:center; gap:12px; text-align:start; }
.gradebook-avatar { display:inline-flex; align-items:center; justify-content:center; flex:0 0 38px; width:38px; height:38px; border-radius:12px; background:#12a396; color:white; font-size:18px; font-weight:700; }
.gradebook-score { display:inline-block; min-width:82px; padding:10px 12px; border:1px solid #dde6eb; border-radius:10px; background:#fff; color:#18343b; font-size:15px; }
.gradebook-score small { font-size:11px; color:#7c9197; font-weight:400; }
.gradebook-page .gradebook-sheet .gradebook-student { min-width:180px; }
.gradebook-page [data-gradebook-table] { box-shadow:none; border:1px solid #e2e9ed; }
.gradebook-thresholds { margin-top:24px; padding:16px; border:1px solid #e0e8ef; border-radius:16px; min-width:0; }
.gradebook-thresholds legend { padding:0 8px; font-size:15px; font-weight:700; }
.gradebook-threshold-grid { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:16px; margin-top:16px; }
.gradebook-threshold-grid > div { min-width:0; }
.gradebook-threshold-grid label { display:flex; align-items:center; gap:8px; margin-bottom:8px; font-size:14px; }
.gradebook-threshold-grid label b { display:inline-flex; align-items:center; justify-content:center; width:32px; height:32px; border-radius:10px; background:#e8f4f4; color:#0d777e; font-size:16px; }
.gradebook-threshold-grid input { width:100%; min-width:0; text-align:center; }
@media (min-width:768px) { .gradebook-threshold-grid { grid-template-columns:repeat(4,minmax(0,1fr)); } }
.gradebook-page .gradebook-icon { display:inline-flex; align-items:center; justify-content:center; width:32px; height:32px; flex:0 0 32px; border-radius:10px; color:#0d777e; background:#e8f4f4; }
.gradebook-page .gradebook-icon i { width:16px; font-size:16px; line-height:1; text-align:center; }
.gradebook-filter-label { display:flex; align-items:center; gap:8px; min-height:32px; margin-bottom:8px; font-size:14px; font-weight:600; }
.gradebook-page .btn { display:inline-flex; align-items:center; justify-content:center; gap:8px; min-height:44px; font-size:14px; line-height:1.5; }
.gradebook-page .btn > i { width:16px; flex:0 0 16px; font-size:16px; text-align:center; }
.gradebook-actions { display:grid; grid-template-columns:minmax(0,1fr); gap:12px; margin-bottom:20px; }
.gradebook-actions > details { margin:0; min-width:0; }
.gradebook-actions > details[open] { grid-column:1 / -1; }
.gradebook-actions > details > summary { display:flex; align-items:center; gap:12px; min-height:44px; padding:0; list-style:none; cursor:pointer; font-size:14px; font-weight:700; }
.gradebook-action-summary::-webkit-details-marker { display:none; }
.gradebook-action-summary > span:nth-child(2) { flex:1; min-width:0; line-height:1.7; }
.gradebook-chevron { font-size:12px; transition:transform .2s; }
.gradebook-actions > details[open] .gradebook-chevron { transform:rotate(180deg); }
.gradebook-register-heading { display:flex; align-items:center; gap:10px; font-size:18px; font-weight:700; }
@media (min-width:768px) { .gradebook-actions { grid-template-columns:repeat(2,minmax(0,1fr)); } }
