/* CyberGate Responsive — tablet & mobile adaptations */

/* ── Tablet (768px – 1199px) ── */
@media (max-width: 1199px) {
  .app-page {
    padding: 12px;
    height: 100vh;
    height: 100dvh;
  }

  .app-shell {
    width: min(1440px, calc(100vw - 24px));
    height: calc(100vh - 24px);
    min-height: calc(100vh - 24px);
    max-height: calc(100vh - 24px);
  }

  .icon-rail {
    max-height: calc(100vh - 24px);
  }

  .topbar-tabs .topbar-tab:last-child {
    display: none;
  }

  .updated-pill {
    font-size: 10px;
    padding: 5px 10px;
  }

  .main-content {
    padding: 12px 14px 16px;
  }

  .kpi-value {
    font-size: 26px;
  }

  .page-header-text h1 {
    font-size: 17px;
  }

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

/* ── Compact shell: tablet portrait & mobile (drawer nav) ── */
@media (max-width: 1023px) {
  .app-shell {
    grid-template-columns: 1fr;
    width: 100%;
    min-height: calc(100vh - 16px);
    border-radius: 14px;
  }

  .mobile-menu-btn {
    display: flex !important;
  }

  .icon-rail {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(280px, 88vw);
    z-index: 300;
    transform: translateX(-105%);
    transition: transform 260ms cubic-bezier(0.22, 1, 0.36, 1);
    align-items: stretch;
    padding: 16px;
    min-height: 100vh;
    min-height: 100dvh;
    box-shadow: 8px 0 32px rgba(16, 42, 86, 0.15);
  }

  .icon-rail.open {
    transform: translateX(0);
  }

  .rail-nav {
    align-items: stretch;
    width: 100%;
    overflow-y: auto;
    flex: 1;
    gap: 4px;
  }

  .rail-link {
    width: 100%;
    height: auto;
    min-height: 44px;
    padding: 10px 12px;
    justify-content: flex-start;
    gap: 12px;
  }

  .rail-link[data-tooltip]:hover::after {
    display: none;
  }

  .rail-label {
    display: inline;
    font-size: 13px;
    font-weight: 500;
    color: inherit;
    max-width: none;
    opacity: 1;
    transform: none;
  }

  .rail-bottom {
    align-items: stretch;
    width: 100%;
  }

  .rail-bottom .rail-link {
    width: 100%;
  }

  .rail-bottom .avatar {
    align-self: flex-start;
    margin-top: 8px;
  }


  .nav-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(7, 26, 58, 0.45);
    z-index: 250;
    opacity: 0;
    pointer-events: none;
    transition: opacity 220ms ease;
  }

  .nav-backdrop.is-visible {
    opacity: 1;
    pointer-events: auto;
  }

  body.nav-open {
    overflow: hidden;
  }

  .shell-main {
    min-width: 0;
    width: 100%;
  }
}

/* Hide rail labels on desktop collapsed; expanded handled in rail.css */
@media (min-width: 1024px) {
  .nav-backdrop {
    display: none !important;
  }

  .mobile-menu-btn {
    display: none !important;
  }
}

/* ── Mobile (≤767px) ── */
@media (max-width: 767px) {
  html {
    font-size: 13px;
  }

  .app-page {
    padding: 0;
    align-items: stretch;
    height: 100vh;
    height: 100dvh;
  }

  .app-shell {
    width: 100%;
    height: 100vh;
    height: 100dvh;
    min-height: 100vh;
    min-height: 100dvh;
    max-height: 100dvh;
    border-radius: 0;
    border-left: none;
    border-right: none;
    box-shadow: none;
  }

  .topbar {
    height: auto;
    min-height: 56px;
    padding: 10px 12px;
    gap: 8px;
    flex-wrap: wrap;
  }

  .topbar-left {
    gap: 10px;
    flex: 1;
    min-width: 0;
  }

  .topbar-right {
    gap: 6px;
    flex-shrink: 0;
  }

  .wordmark {
    font-size: 15px;
    white-space: nowrap;
  }

  .topbar-tabs {
    display: none;
  }

  .updated-pill {
    display: none;
  }

  .icon-btn {
    width: 40px;
    height: 40px;
    flex-shrink: 0;
  }

  .main-content {
    padding: 10px 12px 20px;
    padding-bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  }

  .card {
    padding: 16px;
  }

  .kpi-value {
    font-size: 22px;
  }

  .kpi-card {
    min-height: 120px;
    padding: 14px 16px;
  }

  .page-kpi {
    min-height: 80px;
    padding: 14px;
  }

  .page-header-actions {
    flex-wrap: wrap;
    gap: 8px;
  }

  /* Page header stacks */
  .page-header {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }

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

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

  /* Toolbar filters stack */
  .toolbar-card {
    flex-direction: column;
    align-items: stretch;
    padding: 12px;
  }

  .toolbar-filters {
    flex-direction: column;
    width: 100%;
  }

  .toolbar-filters .form-input,
  .toolbar-filters .form-select {
    max-width: none !important;
    width: 100%;
  }

  .toolbar-filters .btn {
    width: 100%;
    justify-content: center;
  }

  /* Tables scroll horizontally */
  .table-shell-body {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 0 -1px;
  }

  .table-shell-body::after {
    content: '';
    display: block;
    height: 1px;
  }

  .data-table {
    min-width: 560px;
  }

  .data-table th,
  .data-table td {
    padding: 10px 8px;
    font-size: 12px;
  }

  .table-scroll-hint {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    color: var(--muted);
    padding: 6px 12px;
    border-top: 1px solid var(--border);
    background: var(--shell);
  }

  .table-scroll-hint svg {
    width: 14px;
    height: 14px;
    opacity: 0.6;
  }

  /* Detail pages */
  .detail-hero {
    padding: 16px;
  }

  .detail-hero-inner {
    flex-direction: column;
    align-items: stretch;
  }

  .detail-hero-actions {
    flex-wrap: wrap;
  }

  .quick-actions {
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 4px;
    margin-bottom: 12px;
    scrollbar-width: none;
  }

  .quick-actions::-webkit-scrollbar {
    display: none;
  }

  .quick-action-btn {
    flex-shrink: 0;
    white-space: nowrap;
  }

  /* Messages: stack list above thread */
  .split-layout {
    grid-template-columns: 1fr;
  }

  .split-sidebar .messages-layout {
    min-height: auto;
  }

  .split-sidebar .conv-list {
    max-height: 220px;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .split-main .msg-thread {
    height: min(420px, 60vh);
  }

  .messages-layout {
    grid-template-columns: 1fr;
    min-height: auto;
  }

  .conv-list {
    max-height: 240px;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .msg-thread {
    height: min(400px, 55vh);
  }

  .msg-bubble {
    max-width: 88%;
  }

  /* Calendar horizontal scroll */
  .calendar-scroll-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 0 -4px;
    padding-bottom: 4px;
  }

  .calendar-grid {
    min-width: 560px;
  }

  .cal-day {
    min-height: 64px;
  }

  .data-table tbody tr:hover {
    transform: none;
  }

  .data-table tbody tr:hover td:first-child {
    box-shadow: none;
  }

  /* Modals full-width */
  .modal {
    width: calc(100vw - 24px) !important;
    max-height: calc(100dvh - 32px);
    padding: 20px 16px;
    margin: 16px 12px;
  }

  .modal-overlay {
    align-items: flex-end;
    padding: 0;
  }

  .modal-overlay .modal {
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
    margin: 0;
    width: 100% !important;
    max-height: 92dvh;
  }

  /* Search dialog */
  .search-dialog {
    padding-top: 8vh;
    align-items: flex-start;
  }

  .search-box {
    width: calc(100vw - 24px);
    margin: 0 12px;
  }

  .search-box input {
    font-size: 16px;
  }

  /* Forms — prevent iOS zoom */
  .form-input,
  .form-select,
  .form-textarea {
    font-size: 16px;
    min-height: 44px;
  }

  .btn {
    min-height: 44px;
    padding: 10px 16px;
  }

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

  /* Toast bottom on mobile */
  .toast-container {
    top: auto;
    bottom: calc(16px + env(safe-area-inset-bottom, 0px));
    left: 12px;
    right: 12px;
  }

  .toast {
    width: 100%;
  }

  /* Auth pages */
  .auth-page {
    padding: 16px;
    align-items: flex-start;
    padding-top: max(24px, env(safe-area-inset-top));
  }

  .auth-card {
    padding: 24px 20px;
  }

  /* Dashboard flow diagram */
  .student-flow-diagram {
    padding: 12px;
    min-height: 280px;
  }

  .flow-row {
    max-width: 100%;
  }

  .area-student-flow {
    min-height: 300px;
  }

  /* Export / course grids */
  .course-grid,
  .class-grid,
  .export-grid,
  .finance-kpi-grid,
  .finance-split-grid,
  .stat-trio-grid,
  .page-kpi-row {
    grid-template-columns: 1fr !important;
  }

  .today-slots {
    grid-template-columns: 1fr 1fr !important;
  }

  .dashboard-grid {
    grid-template-columns: 1fr !important;
    grid-template-areas: unset !important;
  }

  .dashboard-grid > * {
    grid-area: unset !important;
  }

  .kpi-strip {
    grid-template-columns: 1fr 1fr !important;
  }

  .student-dashboard-grid {
    grid-template-columns: 1fr !important;
  }

  .student-welcome {
    grid-column: span 1 !important;
  }

  /* Obligation rows stack */
  .obligation-row {
    flex-wrap: wrap;
  }

  .tabs-card .tabs {
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 0;
  }

  .tabs-card .tab {
    flex-shrink: 0;
    white-space: nowrap;
  }
}

/* ── Small phones (≤480px) ── */
@media (max-width: 480px) {
  .kpi-strip {
    grid-template-columns: 1fr !important;
  }

  .today-slots {
    grid-template-columns: 1fr !important;
  }

  .topbar-right .dropdown {
    display: none;
  }

  #quickAddBtn {
    display: none;
  }

  .page-header-actions {
    flex-direction: column;
  }

  .page-header-actions .btn {
    width: 100%;
  }
}

/* ── Tablet landscape tweaks (768–1023px) ── */
@media (min-width: 768px) and (max-width: 1023px) {
  .app-page {
    padding: 10px;
  }

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

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

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

  .data-table {
    min-width: 480px;
  }
}

/* Desktop-only: hide scroll hints */
@media (min-width: 768px) {
  .table-scroll-hint {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .icon-rail,
  .nav-backdrop {
    transition: none !important;
  }
}
