/* =========================================
   RESPONSIVE BREAKPOINTS
   Mobile First: base styles are mobile,
   then we expand for PC with min-width queries
   ========================================= */

/* ---- MOBILE (< 768px) ---- */

@media (max-width: 767px) {
  /* Show bottom nav, hide sidebar */
  .sidebar { display: none !important; }
  .bottom-nav { display: flex !important; }
  /* Main content: no left margin */
  .main-content {
    margin-left: 0;
    overflow-x: clip;
    width: 100%;
  }

  /* Prevent horizontal overflow in page content */
  #app-content,
  .page-body {
    overflow-x: clip;
    max-width: 100%;
    width: 100%;
  }

  /* Mobile header title: truncate if long */
  .mobile-header-title {
    flex: 1;
    text-align: center;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    padding: 0 var(--space-2);
    min-width: 0;
  }

  /* Ensure list items don't overflow */
  .list-item {
    overflow: hidden;
  }

  /* Flex children need min-width:0 to shrink properly */
  .group-card,
  .student-card,
  .card {
    min-width: 0;
    max-width: 100%;
  }

  /* Push page content below fixed tab bar + status bar */
  #app-content {
    padding-top: calc(56px + env(safe-area-inset-top));
  }

  /* Sticky page-header should sit below the fixed tab bar */
  .page-header {
    padding: var(--space-3) var(--space-4);
    top: calc(56px + env(safe-area-inset-top));
  }

  .page-body {
    padding: var(--space-4);
  }

  #toast-container {
    bottom: var(--space-6);
  }

  /* Grids collapse to 1 or 2 columns */
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .grid-3 { grid-template-columns: repeat(2, 1fr); }
  .grid-2 { grid-template-columns: 1fr; }

  /* Attendance buttons: larger touch targets and readable text */
  .att-btn {
    min-width: 42px;
    min-height: 38px;
    padding: var(--space-1) var(--space-2);
    font-size: 12px;
  }

  /* Modal takes more vertical space */
  .modal {
    max-height: calc(95vh - var(--ad-bottom-offset, 0px));
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    margin-top: auto;
  }

  .modal-backdrop {
    align-items: flex-end;
  }

  /* Student card: comfortable touch-friendly padding */
  .student-card {
    padding: var(--space-3) var(--space-3);
  }

  /* Student number circle: bigger on mobile */
  .student-number {
    width: 32px;
    height: 32px;
    font-size: var(--font-size-sm);
  }

  /* Date nav buttons: larger touch target */
  .date-nav-btn {
    width: 40px;
    height: 40px;
  }

  /* Stat cards: 2 columns */
  .stat-cards-grid {
    grid-template-columns: repeat(2, 1fr) !important;
  }

  /* Page title smaller */
  .page-title {
    font-size: var(--font-size-lg);
  }

  /* Quick mark bar wraps */
  .quick-mark-bar {
    flex-wrap: wrap;
    gap: var(--space-2);
  }

  /* Student table: allow horizontal scroll to see all columns (no hiding) */
  .student-table th,
  .student-table td {
    white-space: nowrap;
  }

  /* Student search input: full width on mobile */
  #student-search {
    width: 100% !important;
  }
}

/* ---- SMALL MOBILE (< 400px) ---- */

@media (max-width: 400px) {
  .grid-4 { grid-template-columns: 1fr 1fr; }
  .grid-3 { grid-template-columns: 1fr 1fr; }

  .att-btn {
    min-width: 34px;
    min-height: 36px;
    font-size: 11px;
    padding: var(--space-1);
  }

  .attendance-buttons {
    gap: 3px;
  }

  /* 그룹 행에서 버튼을 아이콘 크기로 압축 */
  .list-item .btn-sm {
    padding: var(--space-1) var(--space-2);
    font-size: 11px;
  }
}

/* ---- TABLET (768px - 1024px) ---- */

@media (min-width: 768px) and (max-width: 1024px) {
  /* Sidebar slightly narrower */
  :root { --sidebar-width: 200px; }

  .page-body {
    padding: var(--space-5) var(--space-6);
  }

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

/* ---- DESKTOP (>= 1024px) ---- */

@media (min-width: 1024px) {
  .page-body {
    padding: var(--space-6) var(--space-8);
  }

  .bottom-nav { display: none !important; }
}

/* ---- WIDE DESKTOP (>= 1280px) ---- */

@media (min-width: 1280px) {
  :root { --sidebar-width: 260px; }

  .page-body {
    padding: var(--space-8) var(--space-10);
  }
}

/* ---- TOUCH DEVICE OPTIMIZATIONS ---- */

@media (hover: none) {
  /* Disable hover effects on touch, rely on :active instead */
  .btn:hover,
  .group-card:hover,
  .sidebar-nav-item:hover,
  .list-item:hover {
    transform: none;
    box-shadow: none;
  }

  .att-btn:hover {
    background: transparent;
    border-color: var(--color-border);
    color: var(--color-text-muted);
  }

  .att-btn.active {
    /* Keep active styles even on touch */
  }
}

/* ---- PRINT ---- */

@media print {
  .sidebar,
  .bottom-nav,
  .btn,
  .quick-mark-bar,
  #toast-container {
    display: none !important;
  }

  .main-content {
    margin-left: 0;
  }

  .page-body {
    padding: 0;
  }

  .student-card {
    break-inside: avoid;
  }
}

/* ---- REDUCED MOTION ---- */

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

/* ---- STAT CARDS GRID (used in dashboard, stats pages) ---- */

.stat-cards-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--space-4);
}

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

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

/* ---- LANDSCAPE PHONE ---- */
/* Phones in landscape have widths 768–932px, escaping the max-width:767px mobile block.
   This block forces mobile layout and applies notch safe areas for landscape orientation. */

@media (orientation: landscape) and (max-height: 600px) {
  /* Force mobile nav layout */
  .sidebar { display: none !important; }
  .bottom-nav { display: flex !important; }

  /* Reset sidebar offset */
  .main-content {
    margin-left: 0;
    overflow-x: clip;
    width: 100%;
  }

  /* Push content below fixed tab bar + status bar */
  #app-content {
    padding-top: calc(56px + env(safe-area-inset-top));
    overflow-x: clip;
    max-width: 100%;
    width: 100%;
  }

  .page-header {
    top: calc(56px + env(safe-area-inset-top));
  }

  .page-body {
    padding: var(--space-3) var(--space-4);
  }

  #toast-container {
    bottom: var(--space-4);
  }

  /* Keep cards from overflowing in landscape */
  .group-card,
  .student-card,
  .card {
    min-width: 0;
    max-width: 100%;
  }

  /* Compact attendance buttons in landscape */
  .att-btn {
    min-width: 42px;
    min-height: 36px;
    padding: var(--space-1) var(--space-2);
    font-size: 12px;
  }

  /* Stat cards: 4 columns in landscape (more horizontal space) */
  .stat-cards-grid {
    grid-template-columns: repeat(4, 1fr) !important;
  }
}
