/* =====================================================================
   EduWave — iOS / Safari mobile compatibility layer   (assets/css/ios.css)
   ---------------------------------------------------------------------
   Load order: this file must be the LAST stylesheet on every page
   (after style.css, page CSS and compact-ui.css).

   Targets: iPhone + iPad, Safari / Chrome / Edge on iOS (all use WebKit),
            iOS 12 and newer, notch / Dynamic Island / home-indicator devices.

   Rules of the road
   - Everything is inside @media screen, so print / PDF output is untouched.
   - No new components: the phone menu button + overlay reuse the existing
     .mobile-menu-toggle / .sidebar-overlay pattern from the student portal.
   - !important is used only where a page's own inline <style> (which is
     parsed after this file) would otherwise win.
   - Sections: 1 Base · 2 Forms · 3 Touch targets · 4 Safe areas ·
               5 Phone/tablet navigation · 6 Modals & toasts · 7 Tables &
               overflow · 8 Phone spacing · 9 Sticky-hover reset ·
               10 Glass / blur · 11 iOS-only quirks · 12 Landscape ·
               13 Motion · 14 Old-iOS fallbacks
   ===================================================================== */

@media screen {

/* ---------------------------------------------------------------------
   1. BASE
   --------------------------------------------------------------------- */
html {
  -webkit-text-size-adjust: 100%;          /* stop iOS inflating text in landscape */
  text-size-adjust: 100%;
  -webkit-tap-highlight-color: rgba(67, 97, 238, 0.14);
}

body {
  -webkit-font-smoothing: antialiased;
}

/* Removes the 300 ms tap delay and double-tap-to-zoom on controls */
a, button, input, select, textarea, label, summary,
[role="button"], .btn, .nav-link, .dropdown-item, .page-link,
.form-check-label, .list-group-item-action {
  touch-action: manipulation;
}

/* No accidental text selection / callout when long-pressing buttons & nav */
.btn, .nav-link, .nav-link-custom, .dropdown-item, .page-link,
.mobile-menu-toggle, .sidebar-overlay {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

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

pre { overflow-x: auto; -webkit-overflow-scrolling: touch; }

.overflow-auto, .overflow-scroll, .overflow-y-auto, .overflow-x-auto {
  -webkit-overflow-scrolling: touch;
}

/* ---------------------------------------------------------------------
   2. FORMS
   --------------------------------------------------------------------- */

/* iOS zooms the whole page when a focused field has font-size < 16px
   (compact-ui.css sets the root to 14.5px, which triggers it everywhere). */
@media (hover: none) and (pointer: coarse) {
  input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="file"]):not([type="color"]):not([type="image"]):not([type="submit"]):not([type="button"]):not([type="reset"]),
  select, textarea,
  .form-control, .form-control-sm, .form-control-lg,
  .form-select, .form-select-sm, .form-select-lg {
    font-size: 16px !important;
  }

  .form-control, .form-select { min-height: 44px; }
  .form-control-sm, .form-select-sm { min-height: 40px; }

  .form-check:not(.form-switch) .form-check-input { width: 1.25em; height: 1.25em; margin-top: 0.1em; }
  .form-check-label { padding-top: 2px; }
}

/* Date / time pickers: iOS ignores height, centres the text and lets the
   control burst out of flex / grid parents. */
html.is-ios input[type="date"], html.is-ios input[type="time"],
html.is-ios input[type="datetime-local"], html.is-ios input[type="month"],
html.is-ios input[type="week"] {
  -webkit-appearance: none;
  appearance: none;
  display: block;
  min-width: 0;
  max-width: 100%;
  min-height: 2.5rem;
  line-height: 1.5;
}
html.is-ios input[type="date"]::-webkit-date-and-time-value,
html.is-ios input[type="time"]::-webkit-date-and-time-value,
html.is-ios input[type="datetime-local"]::-webkit-date-and-time-value,
html.is-ios input[type="month"]::-webkit-date-and-time-value,
html.is-ios input[type="week"]::-webkit-date-and-time-value {
  text-align: left;
  min-height: 1.5em;
}

/* iOS greys out disabled fields so hard they become unreadable */
.form-control:disabled, .form-control[readonly], .form-select:disabled,
input:disabled, textarea:disabled, select:disabled {
  -webkit-text-fill-color: currentColor;
  opacity: 1;
}

input[type="search"]::-webkit-search-decoration { -webkit-appearance: none; }
html.is-ios textarea { -webkit-appearance: none; appearance: none; }   /* removes iOS inner shadow */

/* ---------------------------------------------------------------------
   3. TOUCH TARGETS  (Apple HIG: ≈44 pt)
   --------------------------------------------------------------------- */
@media (hover: none) and (pointer: coarse) {
  /* Only Bootstrap's own contextual buttons are resized; custom-styled
     buttons (.btn-hero, .btn-glass, …) and .btn-lg keep their padding. */
  .btn-primary:not(.btn-lg):not(.btn-sm), .btn-secondary:not(.btn-lg):not(.btn-sm),
  .btn-success:not(.btn-lg):not(.btn-sm), .btn-danger:not(.btn-lg):not(.btn-sm),
  .btn-warning:not(.btn-lg):not(.btn-sm), .btn-info:not(.btn-lg):not(.btn-sm),
  .btn-light:not(.btn-lg):not(.btn-sm),   .btn-dark:not(.btn-lg):not(.btn-sm),
  .btn[class*="btn-outline-"]:not(.btn-lg):not(.btn-sm) {
    padding-top: 0.65rem;
    padding-bottom: 0.65rem;
  }
  .btn.btn-sm         { padding-top: 0.45rem; padding-bottom: 0.45rem; }
  .btn-close          { min-width: 32px; min-height: 32px; }
  .dropdown-item      { padding-top: 0.6rem;  padding-bottom: 0.6rem; }
  .page-link          { padding: 0.55rem 0.85rem; }
  .sidebar .nav-link  { padding-top: 0.7rem;  padding-bottom: 0.7rem; }
  .sidebar .collapse .nav-link { padding-top: 0.6rem; padding-bottom: 0.6rem; }
}

/* ---------------------------------------------------------------------
   4. SAFE AREAS  (notch, Dynamic Island, rounded corners, home bar)
   --------------------------------------------------------------------- */
@supports (padding: max(0px)) {
  body {
    padding-left:   env(safe-area-inset-left);
    padding-right:  env(safe-area-inset-right);
    padding-bottom: env(safe-area-inset-bottom);   /* keeps the last row clear of the home bar */
  }
  .sidebar { padding-left: env(safe-area-inset-left); }
  .student-sidebar {
    padding-left:   calc(1.5rem + env(safe-area-inset-left));
    padding-bottom: calc(2rem + env(safe-area-inset-bottom));
  }
  /* student portal's floating menu button sits below the notch */
  .mobile-menu-toggle:not(.is-portal) {
    top:  calc(1rem + env(safe-area-inset-top));
    left: calc(1rem + env(safe-area-inset-left));
  }
  .toastify { margin-top: env(safe-area-inset-top); }
}
@media (max-width: 992px) {
  @supports (padding: max(0px)) {
    .student-main-content { padding-top: calc(5rem + env(safe-area-inset-top)); }
  }
}

/* ---------------------------------------------------------------------
   5. NAVIGATION ON PHONES & TABLETS  (≤ 992px)
   The 14 staff portals had no way to open the sidebar below 768px, and
   showed an icon-only rail on iPad. Below 992px they now use an
   off-canvas drawer opened by the (student-portal style) menu button,
   which assets/js/ios.js adds to pages that have a .sidebar.
   --------------------------------------------------------------------- */
.mobile-menu-toggle.is-portal,
.sidebar-overlay.is-portal { display: none; }

@media (max-width: 992px) {

  /* --- menu button (same pattern as .mobile-menu-toggle in student.css) --- */
  .mobile-menu-toggle.is-portal {
    display: flex;
    align-items: center;
    justify-content: center;
    position: fixed;
    top: 10px;
    top: calc(env(safe-area-inset-top, 0px) + 10px);
    left: 12px;
    left: calc(env(safe-area-inset-left, 0px) + 12px);
    z-index: 1030;
    width: 44px;
    height: 44px;
    padding: 0;
    border: 0;
    border-radius: 12px;
    background: linear-gradient(135deg, var(--primary, #4361ee), var(--secondary, #3f37c9));
    color: #fff;
    font-size: 1.4rem;
    line-height: 1;
    box-shadow: 0 4px 14px rgba(67, 97, 238, 0.38);
    -webkit-appearance: none;
    appearance: none;
    cursor: pointer;
  }
  .mobile-menu-toggle.is-portal:active { transform: scale(0.95); }
  body.sidebar-open .mobile-menu-toggle.is-portal { z-index: 1046; }

  .sidebar-overlay.is-portal {
    display: block;
    position: fixed;
    top: 0; right: 0; bottom: 0; left: 0;
    z-index: 1040;
    background: rgba(15, 23, 42, 0.5);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.25s ease, visibility 0s linear 0.25s;
    -webkit-tap-highlight-color: transparent;
    touch-action: none;
  }
  .sidebar-overlay.is-portal.active {
    opacity: 1;
    visibility: visible;
    transition: opacity 0.25s ease;
  }
  body.sidebar-open { overflow: hidden; }

  /* --- the drawer itself --- */
  .sidebar {
    position: fixed !important;
    top: 0 !important;
    bottom: 0 !important;
    left: 0 !important;
    height: auto !important;            /* 100vh is taller than the visible area on iOS */
    width: 260px !important;
    width: min(86vw, 300px) !important;
    min-width: 0 !important;
    max-width: none !important;
    z-index: 1045 !important;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    text-align: left;
    padding-bottom: 24px;
    padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 24px);
    transition: transform 0.28s ease, visibility 0s linear 0.28s;
  }
  /* closed: keep it rendered (so it can slide) but off-screen and inert */
  .sidebar.collapse:not(.show),
  .sidebar.d-none {
    display: block !important;
    visibility: hidden;
    transform: translateX(-105%);
  }
  /* open */
  .sidebar.mobile-open,
  .sidebar.mobile-open.collapse:not(.show),
  .sidebar.mobile-open.d-none {
    display: block !important;
    visibility: visible;
    transform: none !important;
    transition: transform 0.28s ease, visibility 0s;
    box-shadow: 8px 0 40px rgba(0, 0, 0, 0.35);
  }

  /* style.css collapses the sidebar to an icon rail at ≤992px and hides
     the labels; inside the drawer we want the full labelled menu back. */
  .sidebar .nav-link span:not(.d-none):not(.badge),
  .sidebar-brand h3 span { display: inline !important; }
  .sidebar .nav-link i { margin-right: 12px; font-size: 1.05rem; }
  .sidebar .nav-link i.float-end { margin-right: 0; margin-left: auto; }

  /* --- content takes the full width (fixes the 80px rail offset) --- */
  .main-content, .student-main-content {
    margin-left: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0;
    flex: none !important;
  }
  /* clear the floating menu button */
  body.has-portal-toggle .main-content {
    padding-top: 64px !important;
    padding-top: calc(env(safe-area-inset-top, 0px) + 64px) !important;
  }
}

/* ---------------------------------------------------------------------
   6. MODALS & TOASTS
   --------------------------------------------------------------------- */
.modal { -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
.modal-body { -webkit-overflow-scrolling: touch; }
.dropdown-menu { -webkit-overflow-scrolling: touch; }

@media (max-width: 575.98px) {
  .modal-dialog { margin: 0.5rem; }
  @supports (padding: max(0px)) {
    .modal-dialog {
      margin-top:    max(0.5rem, env(safe-area-inset-top));
      margin-right:  max(0.5rem, env(safe-area-inset-right));
      margin-bottom: max(0.5rem, env(safe-area-inset-bottom));
      margin-left:   max(0.5rem, env(safe-area-inset-left));
    }
  }
  .modal-dialog-scrollable .modal-content { max-height: calc(100vh - 1rem); max-height: calc(100dvh - 1rem); }
  .modal-footer { flex-wrap: wrap; }
  .modal-footer > .btn { flex: 1 1 auto; }
}
.toastify { max-width: calc(100vw - 24px); }

/* ---------------------------------------------------------------------
   7. TABLES & OVERFLOW
   --------------------------------------------------------------------- */
.table-responsive { -webkit-overflow-scrolling: touch; }

.main-content, .student-main-content { overflow-wrap: break-word; }
.card, .card-body, .modal-body, .dashboard-card { min-width: 0; }

@media (max-width: 767.98px) {
  /* Wide data tables scroll sideways instead of crushing their columns.
     (ios.js wraps bare tables in Bootstrap's own .table-responsive.) */
  .table-responsive > .table { min-width: 560px; }
  .table-responsive > .table > thead > tr > th { white-space: nowrap; }
}

/* ---------------------------------------------------------------------
   8. PHONE SPACING  (≤ 575px)
   --------------------------------------------------------------------- */
@media (max-width: 575.98px) {
  .main-content, .student-main-content {
    padding-left: 12px;
    padding-right: 12px;
  }
  .card-body   { padding: 0.9rem; }
  .card-header, .card-footer { padding: 0.7rem 0.9rem; }

  .page-header, .dashboard-header, .card-header.d-flex {
    flex-wrap: wrap;
    gap: 0.5rem;
  }
  .page-header h1, .dashboard-header h1 { font-size: 1.2rem; }
  .welcome-banner { padding: 16px 18px; }
  .welcome-content h2 { font-size: 1.2rem; }

  .btn-toolbar, .btn-group-vertical { max-width: 100%; }
  .breadcrumb { flex-wrap: wrap; }
  .nav-tabs, .nav-pills { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; white-space: nowrap; }
  .nav-tabs .nav-link, .nav-pills .nav-link { flex: 0 0 auto; }
}
@media (max-width: 360px) {
  .stats-grid, .quick-actions-grid, .stat-cards { grid-template-columns: 1fr !important; }
  .login-container, .erp-login-box { margin: 6px; }
}

/* ---------------------------------------------------------------------
   9. STICKY-HOVER RESET
   iOS keeps :hover applied after a tap, so "lift on hover" cards stay
   raised / scaled until you tap somewhere else. Touch screens don't
   need the lift, so it is switched off. Colours & shadows still change.
   --------------------------------------------------------------------- */
@media (hover: none) {
.acc-action-card:hover,
.acc-stat-card:hover,
.action-btn.delete:hover,
.action-btn.edit:hover,
.action-btn.primary:hover,
.action-btn.view:hover,
.action-btn.warning:hover,
.action-btn:hover,
.action-card-body:hover,
.action-card:hover,
.add-grade-btn:hover,
.additional-metric:hover,
.adm-action-card:hover,
.adm-action-card:hover .action-icon,
.adm-stat-card:hover,
.alert-modern .alert-close:hover,
.amount-badge:hover,
.attendance-item:hover,
.attendance-options .btn:hover,
.attendance-stats-card:hover,
.badge:hover,
.bed-btn.occupied:hover,
.bed-btn.vacant:hover,
.btn-action-sm:hover,
.btn-action:hover,
.btn-add-fine:hover,
.btn-add-first:hover,
.btn-add-new:hover,
.btn-assign:hover,
.btn-back:hover,
.btn-checkout:hover,
.btn-collect:hover,
.btn-configure:hover,
.btn-create-notice:hover,
.btn-create:hover,
.btn-delete-fee:hover,
.btn-delete:hover,
.btn-download:hover,
.btn-edit:hover,
.btn-export-enhanced:hover,
.btn-filter-apply:hover,
.btn-filter-search:hover,
.btn-filter:hover,
.btn-financial-report:hover,
.btn-financial-report:hover .btn-icon,
.btn-fines-action:hover,
.btn-generate:hover,
.btn-glass:hover,
.btn-header-back:hover,
.btn-header-export:hover,
.btn-header-primary:hover,
.btn-header-secondary:hover,
.btn-header:hover,
.btn-hero:hover,
.btn-hostel-action.primary:hover,
.btn-info:hover,
.btn-load:hover,
.btn-login:hover,
.btn-manage:hover,
.btn-modal-confirm:hover,
.btn-modal-danger:hover,
.btn-modal-save:hover,
.btn-modal-submit:hover,
.btn-outline-primary:hover,
.btn-premium-primary:hover,
.btn-preview:hover,
.btn-primary:hover,
.btn-print:hover,
.btn-regenerate-enhanced:hover,
.btn-revoke:hover,
.btn-rose:hover,
.btn-save:hover,
.btn-search-modern:hover,
.btn-search-primary:hover,
.btn-search:hover,
.btn-status-pill:hover,
.btn-submit-payment:hover,
.btn-submit-primary:hover,
.btn-submit-success:hover,
.btn-submit:hover,
.btn-success:hover,
.btn-view-all:hover,
.btn-view:hover,
.btn-warning:hover,
.btn-white:hover,
.btn:hover,
.calendar-day:not(.empty):hover,
.card-hover:hover,
.card:hover,
.change-btn:hover,
.chart-badge:hover,
.chart-card:hover,
.class-card-hover:hover,
.class-card-hover:hover .class-icon-modern,
.class-card-premium:hover,
.class-card:hover,
.class-dashboard-card:hover,
.contact-item:hover,
.defaulter-item:hover .defaulter-avatar,
.detail-item:hover,
.device-card:hover,
.dir-card:hover,
.doc-btn:hover,
.doc-link:hover,
.document-card:hover,
.document-item:hover,
.erp-login-box form button:hover,
.event-badge:hover,
.event-card:hover,
.fb-card:hover,
.fee-card:hover:not(.disabled),
.fee-type-card:hover,
.finance-card:hover,
.finance-item:hover,
.financial-metric-card:hover,
.financial-metric-card:hover .metric-icon,
.fine-detail-row:hover,
.form-card:hover,
.form-select-enhanced:hover,
.ft-row:hover,
.ft-select-card:hover,
.glass-card:hover,
.hero-stat-item:hover,
.hostel-card:hover,
.hover-elevate:hover,
.hover-scale:hover,
.info-item:hover,
.lab-card:hover,
.lib-action-card:hover,
.lib-action-card:hover .action-icon,
.lib-btn-primary:hover,
.lib-btn-success:hover,
.lib-stat-card:hover,
.list-group-item:hover,
.login-header:hover .logo i,
.logout-btn:hover,
.logout-link:hover,
.nav-link-custom:hover,
.nav-link-custom:hover i,
.notice-card:hover,
.notify-btn:hover,
.option-item:hover,
.option-item:hover .option-arrow,
.payments-table tbody tr:hover,
.payments-table tbody tr:hover .student-avatar,
.posco-stat-card:hover,
.pri-card:hover,
.quick-action-btn:hover,
.quick-action-btn:hover .action-icon,
.quick-action-card:hover,
.quick-action-item:hover,
.quick-action-item:hover .action-icon-box,
.quick-action-item:hover .chevron-icon,
.quick-action:hover,
.quick-btn:hover,
.rating-card:hover,
.remove-btn:hover,
.report-link:hover,
.report-link:hover .report-link-icon,
.room-card:hover,
.settings-card:hover,
.sf-card:hover,
.star-input-group label:hover,
.star-input-group label:hover ~ label,
.stat-card-modern:hover,
.stat-card-premium:hover,
.stat-card:hover,
.stat-card:hover .stat-icon,
.stat-mini-card:hover,
.stat-trend:hover,
.student-card-premium:hover,
.student-card:hover,
.student-profile-card:hover,
.student-rank-card:hover,
.subject-card:hover,
.summary-card:hover,
.teacher-assignment-card:hover,
.teacher-assignment-card:hover .teacher-avatar,
.teacher-pick-card:hover,
.theme-btn:hover,
.type-card:hover,
.upload-btn:hover,
.use-case-card:hover,
.user-card:hover,
.warden-action-card:hover,
.warden-stat-card:hover
  {
    -webkit-transform: none !important;
    transform: none !important;
  }
}

/* ---------------------------------------------------------------------
   10. GLASS / BLUR
   --------------------------------------------------------------------- */
/* Safari < 18 only understands the -webkit- prefixed property (added
   site-wide in the source CSS). Where blur isn't available at all, use
   an opaque surface so text stays readable. */
@supports not ((-webkit-backdrop-filter: blur(1px)) or (backdrop-filter: blur(1px))) {
  .student-sidebar, .glass-panel { background: rgba(255, 255, 255, 0.98) !important; }
  .glass-card { background: rgba(255, 255, 255, 0.96) !important; }
}
/* Large blurs are expensive on older iPhones while scrolling */
@media (max-width: 767.98px) {
  .student-sidebar, .glass-panel, .glass-card {
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
  }
}

/* ---------------------------------------------------------------------
   11. iOS-ONLY QUIRKS  (html.is-ios is added by ios.js)
   --------------------------------------------------------------------- */
/* iOS ignores background-attachment: fixed and stretches the image */
html.is-ios body { background-attachment: scroll; }
/* html{overflow-y:scroll} in style.css makes iOS treat <html> as a nested scroller */
html.is-ios { overflow-y: auto; }
/* Avoid flicker on fixed + transformed panels */
html.is-ios .sidebar, html.is-ios .student-sidebar {
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
}

/* ---------------------------------------------------------------------
   12. LANDSCAPE PHONES  (short viewports)
   --------------------------------------------------------------------- */
@media (max-height: 480px) and (orientation: landscape) {
  .sidebar .nav-link { padding-top: 0.45rem !important; padding-bottom: 0.45rem !important; }
  .mobile-menu-toggle.is-portal { width: 40px; height: 40px; top: 6px; top: calc(env(safe-area-inset-top, 0px) + 6px); }
  body.has-portal-toggle .main-content { padding-top: 52px !important; padding-top: calc(env(safe-area-inset-top, 0px) + 52px) !important; }
  .modal-dialog { margin-top: 0.25rem; margin-bottom: 0.25rem; }
  .welcome-banner { padding: 12px 16px; }
}

/* ---------------------------------------------------------------------
   13. MOTION  (also saves battery on older iPhones)
   --------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ---------------------------------------------------------------------
   14. OLD-iOS FALLBACKS  (iOS < 15.4 has no dvh; iOS < 14.5 no flex gap)
   --------------------------------------------------------------------- */
/* --app-vh is set by ios.js from window.innerHeight */
@supports not (height: 100dvh) {
  html.is-ios .login-wrapper,
  html.is-ios .erp-login-container,
  html.is-ios .student-main-content,
  html.is-ios .main-content { min-height: calc(var(--app-vh, 1vh) * 100); }
}
/* Bootstrap gap utilities on flex rows, for iOS 12–14.4 (html.no-flex-gap set by ios.js) */
html.no-flex-gap .d-flex.gap-1 > * + * { margin-left: 0.25rem; }
html.no-flex-gap .d-flex.gap-2 > * + * { margin-left: 0.5rem; }
html.no-flex-gap .d-flex.gap-3 > * + * { margin-left: 1rem; }
html.no-flex-gap .d-flex.gap-4 > * + * { margin-left: 1.5rem; }
html.no-flex-gap .d-flex.gap-5 > * + * { margin-left: 3rem; }
html.no-flex-gap .d-flex.flex-column.gap-1 > * + * { margin-left: 0; margin-top: 0.25rem; }
html.no-flex-gap .d-flex.flex-column.gap-2 > * + * { margin-left: 0; margin-top: 0.5rem; }
html.no-flex-gap .d-flex.flex-column.gap-3 > * + * { margin-left: 0; margin-top: 1rem; }
html.no-flex-gap .d-flex.flex-column.gap-4 > * + * { margin-left: 0; margin-top: 1.5rem; }
html.no-flex-gap .d-flex.flex-column.gap-5 > * + * { margin-left: 0; margin-top: 3rem; }

} /* end @media screen */
