/* ═══════════════════════════════════════════════════════════════
   CampusFlow — Premium Mobile Experience
   Transforms mobile from "responsive" to "native-feel SaaS"
   Loaded after site.css in all 3 layouts.

   Design references: Linear, Notion, Stripe Dashboard, GitHub Mobile
   ═══════════════════════════════════════════════════════════════ */

/* ═══════════════════════════════════════════
   §0  MOBILE DESIGN TOKENS
   Fluid spacing & typography scale
   ═══════════════════════════════════════════ */
:root {
  /* ── Safe Area ── */
  --safe-top:    env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left:   env(safe-area-inset-left, 0px);
  --safe-right:  env(safe-area-inset-right, 0px);

  /* ── Fluid Spacing Scale (mobile → desktop) ── */
  --sp-xs:  clamp(.25rem, .5vw, .375rem);    /*  4 →  6  */
  --sp-sm:  clamp(.5rem, 1vw, .75rem);       /*  8 → 12  */
  --sp-md:  clamp(.75rem, 1.5vw, 1rem);      /* 12 → 16  */
  --sp-lg:  clamp(1rem, 2vw, 1.5rem);        /* 16 → 24  */
  --sp-xl:  clamp(1.25rem, 2.5vw, 2rem);     /* 20 → 32  */
  --sp-2xl: clamp(1.5rem, 3vw, 2.5rem);      /* 24 → 40  */

  /* ── Fluid Typography ── */
  --fs-hero:    clamp(1.15rem, 3.5vw, 1.9rem);
  --fs-h2:      clamp(1rem, 2.5vw, 1.5rem);
  --fs-h3:      clamp(.92rem, 2vw, 1.15rem);
  --fs-body:    clamp(.82rem, 1.5vw, .88rem);
  --fs-small:   clamp(.72rem, 1.2vw, .78rem);
  --fs-micro:   clamp(.65rem, 1vw, .72rem);

  /* ── Mobile Card System ── */
  --card-pad-mobile: clamp(.85rem, 2.5vw, 1.25rem);
  --card-radius-mobile: clamp(12px, 2vw, 16px);
  --section-gap: clamp(1rem, 2.5vw, 1.5rem);
}


/* ═══════════════════════════════════════════
   §1  SAFE AREA — NOTCH DEVICES
   ═══════════════════════════════════════════ */
.sidebar {
  padding-bottom: calc(var(--safe-bottom) + 1.5rem);
}
.adm-sidebar {
  padding-bottom: calc(var(--safe-bottom) + 1rem);
}


/* ═══════════════════════════════════════════
   §2  SIDEBAR — TABLET BREAKPOINT OVERRIDE
   Bump student/instructor sidebar to 992px
   ═══════════════════════════════════════════ */
@media (max-width: 991.98px) {
  .sidebar {
    position: fixed;
    top: var(--topnav-h);
    left: 0;
    height: calc(100vh - var(--topnav-h));
    z-index: 1045;
    transform: translateX(-100%);
    box-shadow: 8px 0 32px rgba(0, 0, 0, .15);
  }
  .sidebar.sidebar-open {
    transform: translateX(0);
  }
  .sidebar-overlay {
    display: block;
  }
  .sidebar-overlay.sidebar-open {
    opacity: 1;
    pointer-events: auto;
  }
  .sidebar-content {
    padding: var(--sp-lg) var(--sp-md);
  }
  .btn-sidebar-toggle {
    display: inline-flex !important;
  }
}
@media (min-width: 992px) {
  .btn-sidebar-toggle {
    display: none !important;
  }
}


/* ═══════════════════════════════════════════
   §3  TOPBAR — PREMIUM MOBILE REBALANCE
   Feels native, compact, balanced
   ═══════════════════════════════════════════ */

/* ── Tablet topbar ── */
@media (max-width: 767.98px) {
  .top-nav {
    height: 52px;
  }
  .navbar-brand {
    font-size: .95rem;
    letter-spacing: -.2px;
  }
  .pub-nav-pill {
    font-size: .76rem;
    padding: .3rem .65rem;
  }
}

/* ── Phone topbar ── */
@media (max-width: 575.98px) {
  .top-nav {
    padding-left: .625rem;
    padding-right: .625rem;
    gap: .25rem;
    height: 48px;
  }
  .navbar-brand {
    font-size: .88rem;
    gap: .3rem;
  }
  .navbar-brand .bi-mortarboard-fill {
    font-size: .95rem;
  }
  .theme-toggle {
    min-width: 2.1rem;
    height: 2.1rem;
    font-size: .82rem;
    border-radius: 10px;
  }
  .lang-switcher-btn {
    padding: .25rem .55rem;
    font-size: .72rem;
  }
  .lang-flag {
    font-size: .88rem;
  }
  .pub-logout-btn {
    font-size: .72rem;
    padding: .22rem .5rem;
    border-radius: 8px;
  }
  .pub-login-btn {
    font-size: .76rem;
    padding: .3rem .7rem;
  }
  .pub-username {
    display: none !important;
  }

  /* Admin topbar */
  .adm-topnav {
    padding-left: .625rem;
    padding-right: .625rem;
    gap: .3rem;
    height: 48px;
  }
  .adm-page-title {
    font-size: .76rem;
    max-width: 110px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .adm-icon-btn {
    width: 32px;
    height: 32px;
    font-size: .85rem;
  }
  .adm-avatar {
    width: 30px;
    height: 30px;
    font-size: .7rem;
  }
}


/* ═══════════════════════════════════════════
   §4  HERO / BANNER — MOBILE PREMIUM POLISH
   Elegant, compact, touch-friendly
   ═══════════════════════════════════════════ */

/* ── Student Hero — tablet ── */
@media (max-width: 767.98px) {
  body .sd-hero {
    padding: 1.5rem 1.25rem;
    border-radius: var(--radius-xl);
    margin-bottom: var(--section-gap);
    box-shadow: 0 4px 20px rgba(var(--brand-primary-rgb), .15);
  }
  body .sd-hero-content {
    gap: 1.25rem;
  }
  body .sd-hero-headline {
    font-size: var(--fs-h2);
    margin-bottom: .85rem;
    line-height: 1.25;
  }
  body .sd-hero-greeting {
    font-size: var(--fs-small);
    margin-bottom: .25rem;
  }
  body .sd-hero-ring {
    width: 92px;
    height: 92px;
  }
  body .sd-ring-svg {
    width: 92px;
    height: 92px;
  }
  body .sd-ring-pct {
    font-size: 1.25rem;
  }
  body .sd-ring-sub {
    font-size: .52rem;
    max-width: 56px;
  }
  body .sd-hero-btn {
    padding: .5rem 1rem;
    font-size: .78rem;
    border-radius: 10px;
  }
}

@media (max-width: 575.98px) {
  body .sd-hero {
    padding: 1.25rem 1rem;
    border-radius: 14px;
  }
  body .sd-hero-content {
    flex-direction: column;
    text-align: center;
    gap: 1rem;
  }
  body .sd-hero-actions {
    justify-content: center;
    width: 100%;
  }
  body .sd-hero-btn {
    flex: 1;
    justify-content: center;
    max-width: 180px;
  }
  body .sd-hero-ring {
    margin: 0 auto;
    width: 84px;
    height: 84px;
  }
  body .sd-ring-svg {
    width: 84px;
    height: 84px;
  }
  body .sd-ring-pct {
    font-size: 1.15rem;
  }
  body .sd-hero-headline {
    font-size: 1.1rem;
    letter-spacing: -.2px;
  }
  body .sd-hero-greeting {
    font-size: .78rem;
  }
}

/* ── Admin Welcome Banner — tablet ── */
@media (max-width: 767.98px) {
  body .adm-welcome {
    padding: 1.35rem 1.15rem;
    border-radius: var(--radius-lg);
    margin-bottom: var(--section-gap);
  }
  body .adm-welcome-text h1 {
    font-size: 1.2rem;
    letter-spacing: -.2px;
  }
  body .adm-welcome-text p {
    font-size: .8rem;
    opacity: .85;
  }
  body .adm-health-badge {
    margin-top: .5rem;
    font-size: .68rem;
  }
}
@media (max-width: 575.98px) {
  body .adm-welcome {
    padding: 1.1rem .9rem;
    border-radius: 14px;
  }
  body .adm-welcome-text h1 {
    font-size: 1.05rem;
  }
  body .adm-welcome-text p {
    font-size: .76rem;
  }
  body .adm-welcome-actions {
    display: none !important;
  }
}

/* ── Instructor Banner — tablet ── */
@media (max-width: 767.98px) {
  body .id-banner {
    padding: 1.5rem 1.25rem;
    border-radius: var(--radius-xl);
    margin-bottom: var(--section-gap);
  }
  body .id-banner-content {
    flex-direction: column;
    align-items: flex-start;
    gap: .85rem;
  }
  body .id-greeting-name {
    font-size: var(--fs-hero);
    letter-spacing: -.3px;
  }
  body .id-greeting-sub,
  body .id-greeting-hint {
    font-size: var(--fs-small);
  }
  body .id-banner-btn {
    padding: .45rem .95rem;
    font-size: .78rem;
    border-radius: 10px;
  }
}
@media (max-width: 575.98px) {
  body .id-banner {
    padding: 1.15rem .9rem;
    border-radius: 14px;
  }
  body .id-greeting-name {
    font-size: 1.1rem;
  }
  body .id-greeting-sub,
  body .id-greeting-hint {
    font-size: .72rem;
  }
  body .id-banner-actions {
    width: 100%;
  }
  body .id-banner-btn {
    flex: 1;
    justify-content: center;
  }
}


/* ═══════════════════════════════════════════
   §5  KPI / STAT CARDS — MOBILE REDESIGN
   Better breathing, hierarchy, touch feel
   ═══════════════════════════════════════════ */

/* ── Student Stat Cards ── */
@media (max-width: 960px) {
  body .sd-stats {
    grid-template-columns: repeat(3, 1fr);
    gap: .6rem;
    margin-bottom: var(--section-gap);
  }
}
@media (max-width: 575.98px) {
  body .sd-stats {
    grid-template-columns: repeat(2, 1fr);
    gap: .5rem;
  }
  body .sd-stat {
    padding: .85rem .75rem;
    gap: .55rem;
    border-radius: 12px;
  }
  body .sd-stat-icon {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    font-size: 1rem;
  }
  body .sd-stat-num {
    font-size: 1.2rem;
    letter-spacing: -.3px;
  }
  body .sd-stat-label {
    font-size: .64rem;
    margin-top: .15rem;
    letter-spacing: .01em;
  }
}

/* ── Admin Stat Cards ── */
@media (min-width: 576px) and (max-width: 991.98px) {
  .col-xl-2.col-md-4 {
    flex: 0 0 33.333%;
    max-width: 33.333%;
  }
}
@media (max-width: 575.98px) {
  body .adm-stat {
    padding: .85rem .75rem;
    gap: .55rem;
    border-radius: 12px;
  }
  body .adm-stat-icon {
    width: 38px;
    height: 38px;
    font-size: .95rem;
    border-radius: 10px;
  }
  body .adm-stat-value {
    font-size: 1.25rem;
    letter-spacing: -.3px;
  }
  body .adm-stat-label {
    font-size: .65rem;
    margin-top: .1rem;
    letter-spacing: .01em;
  }
  /* Better 2-col spacing for admin stats */
  .row.g-3.mb-4.stagger-children {
    --bs-gutter-x: .5rem;
    --bs-gutter-y: .5rem;
    margin-bottom: var(--section-gap) !important;
  }
}

/* ── Instructor KPI Cards ── */
@media (max-width: 767.98px) {
  body .id-kpi-grid {
    grid-template-columns: repeat(auto-fill, minmax(145px, 1fr));
    gap: .6rem;
    margin-bottom: var(--section-gap);
  }
}
@media (max-width: 575.98px) {
  body .id-kpi-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: .5rem;
  }
  body .id-kpi {
    padding: .85rem .8rem .7rem;
    border-radius: 12px;
    gap: .4rem;
  }
  body .id-kpi-icon {
    width: 34px;
    height: 34px;
    border-radius: 9px;
    font-size: .9rem;
  }
  body .id-kpi-num {
    font-size: 1.35rem;
    letter-spacing: -.3px;
  }
  body .id-kpi-lbl {
    font-size: .65rem;
  }
  body .id-kpi-link {
    font-size: .68rem;
  }
}


/* ═══════════════════════════════════════════
   §6  CHART — MOBILE EXPERIENCE
   Less vertical dominance, better proportions
   ═══════════════════════════════════════════ */

/* Chart container overflow prevention */
.adm-chart-wrap,
.id-card-body {
  overflow: hidden;
}

@media (max-width: 767.98px) {
  /* Reduce chart card heights */
  body .adm-chart-wrap {
    min-height: 180px;
  }
  body .adm-card-body[style*="height:280px"],
  body .adm-card-body[style*="height:260px"] {
    height: 200px !important;
  }
  canvas {
    min-height: 160px;
    max-height: 220px;
  }
  /* Chart card header */
  body .adm-card-header {
    padding: .7rem .85rem;
    flex-wrap: wrap;
    gap: .4rem;
  }
  body .adm-card-body {
    padding: .75rem .85rem;
  }
  body .adm-card-title {
    font-size: .82rem;
  }
  body .adm-pill-group {
    order: 2;
  }
  body .adm-pill {
    padding: .2rem .5rem;
    font-size: .66rem;
  }
}

@media (max-width: 575.98px) {
  body .adm-card-body[style*="height:280px"],
  body .adm-card-body[style*="height:260px"] {
    height: 175px !important;
  }
  canvas {
    min-height: 140px;
    max-height: 185px;
  }
  body .adm-chart-wrap {
    min-height: 150px;
  }
  body .adm-card-header {
    padding: .65rem .75rem;
  }
  body .adm-card-body {
    padding: .6rem .75rem;
  }
  body .adm-card-title {
    font-size: .78rem;
  }
  /* Chart.js legend — smaller */
  .adm-chart-wrap canvas + div {
    font-size: .7rem !important;
  }
}

/* Canvas max-width for all sizes */
canvas {
  max-width: 100%;
}


/* ═══════════════════════════════════════════
   §7  CARD CONSISTENCY — UNIFIED SYSTEM
   All cards share consistent properties
   ═══════════════════════════════════════════ */
@media (max-width: 575.98px) {
  /* Unified card radii */
  body .adm-card,
  body .adm-stat,
  body .sd-widget,
  body .sd-course,
  body .id-card,
  body .id-kpi,
  body .sd-stat,
  .surface-card,
  .card {
    border-radius: 12px;
  }

  /* Unified card shadows — lighter on mobile for performance */
  body .adm-card,
  body .sd-widget,
  body .id-card {
    box-shadow: 0 1px 3px rgba(0, 0, 0, .04), 0 2px 8px rgba(var(--brand-primary-rgb), .03);
  }

  /* Card borders — softer on mobile */
  body .adm-card,
  body .sd-widget,
  body .id-card,
  body .adm-stat,
  body .sd-stat,
  body .id-kpi {
    border-width: 1px;
    border-color: var(--border-soft);
  }
}

/* Tablet card system */
@media (min-width: 576px) and (max-width: 991.98px) {
  .sidebar-content {
    padding: var(--sp-lg) var(--sp-lg);
  }
}


/* ═══════════════════════════════════════════
   §8  TYPOGRAPHY — MOBILE FLUID SYSTEM
   Consistent hierarchy, readable sizes
   ═══════════════════════════════════════════ */
@media (max-width: 767.98px) {
  /* Page headers */
  .page-header-title h2 {
    font-size: var(--fs-h2);
    letter-spacing: -.3px;
  }
  .page-header-title p {
    font-size: var(--fs-small);
  }
  .page-header {
    margin-bottom: var(--sp-lg);
    gap: .5rem;
  }

  /* Section titles */
  body .sd-section-title,
  body .id-card-title {
    font-size: var(--fs-body);
  }
  body .sd-link,
  body .id-card-action,
  body .adm-link-btn {
    font-size: var(--fs-micro);
  }

  /* Breadcrumb */
  .adm-breadcrumb {
    font-size: .68rem;
    margin-bottom: .65rem;
  }
}

@media (max-width: 575.98px) {
  /* Ensure body text stays readable */
  .page-header-title h2 {
    font-size: 1.1rem;
  }
  .page-header-title p {
    font-size: .75rem;
  }

  /* Sidebar section labels */
  .sidebar-section-label {
    font-size: .6rem;
    padding: .7rem .75rem .3rem;
  }

  /* Empty states */
  .empty-state h5,
  .adm-empty-state h6 {
    font-size: .92rem;
  }
  .empty-state p,
  .adm-empty-state p {
    font-size: .78rem;
  }
  .empty-state {
    padding: 2.5rem 1.25rem;
  }

  /* Badge sizing */
  .badge {
    font-size: .66rem;
    padding: .22em .55em;
  }
}


/* ═══════════════════════════════════════════
   §9  TABLES — RESPONSIVE EXPERIENCE
   ═══════════════════════════════════════════ */

/* Horizontal scroll with momentum */
.table-responsive {
  -webkit-overflow-scrolling: touch;
}

/* Scroll hint gradient */
@media (max-width: 991.98px) {
  .table-responsive {
    position: relative;
  }
  .table-responsive::after {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    width: 20px;
    height: 100%;
    background: linear-gradient(to left, var(--surface-bg) 0%, transparent 100%);
    pointer-events: none;
    opacity: .5;
    border-radius: 0 var(--radius-md) var(--radius-md) 0;
    z-index: 1;
  }
}

/* Card-style table opt-in */
@media (max-width: 767.98px) {
  .table-responsive {
    border-radius: 12px;
  }

  .resp-cards thead {
    display: none;
  }
  .resp-cards tbody tr {
    display: block;
    padding: .65rem .8rem;
    border-bottom: 1px solid var(--border-soft);
    border-left: 3px solid transparent;
    border-radius: 10px;
    margin-bottom: .3rem;
    background: var(--surface-card);
    transition: border-left-color .15s;
  }
  .resp-cards tbody tr:hover {
    border-left-color: var(--brand-primary);
  }
  .resp-cards tbody td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: .25rem 0;
    border: none;
    font-size: .8rem;
  }
  .resp-cards tbody td::before {
    content: attr(data-label);
    font-weight: 700;
    font-size: .65rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--text-muted);
    margin-right: .65rem;
    flex-shrink: 0;
    max-width: 40%;
  }
  .resp-cards tbody td:last-child {
    justify-content: flex-end;
    padding-top: .4rem;
    gap: .3rem;
  }
}

/* Action button tap targets */
@media (max-width: 575.98px) {
  .btn-adm-action {
    width: 36px;
    height: 36px;
    font-size: .8rem;
    border-radius: 8px;
  }
  .adm-pagination .page-link,
  .pagination .page-link {
    min-width: 36px;
    min-height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: .76rem;
  }

  /* Instructor table */
  body .id-table-wrap {
    margin: 0 -1rem;
    padding: 0 1rem;
  }
  body .id-table td {
    padding: .6rem .6rem;
    font-size: .78rem;
  }
  body .id-table th {
    font-size: .64rem;
    padding: .4rem .6rem;
  }
  body .id-row-btn {
    width: 32px;
    height: 32px;
  }
}


/* ═══════════════════════════════════════════
   §10  FORMS — MOBILE POLISH
   ═══════════════════════════════════════════ */
@media (max-width: 575.98px) {
  .row.g-3 > .col-md-6,
  .row.g-3 > .col-md-4,
  .row.g-3 > .col-md-3 {
    padding-left: calc(var(--bs-gutter-x) * .5);
    padding-right: calc(var(--bs-gutter-x) * .5);
  }

  /* Search/filter bars */
  body .adm-card-header {
    flex-direction: column;
    align-items: stretch;
    gap: .4rem;
  }

  /* Inputs */
  .form-control,
  .form-select {
    min-height: 2.5rem;
    font-size: .85rem;
    border-radius: 10px;
  }
  .form-label {
    font-size: .8rem;
    margin-bottom: .3rem;
  }
  .input-group {
    flex-wrap: nowrap;
  }

  /* Button groups responsive */
  .d-flex.gap-2 > .btn,
  .d-flex.gap-1 > .btn {
    flex-shrink: 1;
    min-width: 0;
  }
}


/* ═══════════════════════════════════════════
   §11  MODALS / DROPDOWNS / NOTIFICATIONS
   ═══════════════════════════════════════════ */

/* ── Modals ── */
@media (max-width: 575.98px) {
  .modal-dialog {
    margin: .5rem;
    max-width: calc(100vw - 1rem);
  }
  .modal-dialog-centered {
    min-height: calc(100vh - 1rem);
  }
  .modal-content {
    border-radius: 16px;
  }
  .modal-body {
    padding: 1rem;
  }
  .modal-header,
  .modal-footer {
    padding: .65rem 1rem;
  }
  .modal-title {
    font-size: .92rem;
  }
}

/* ── Notification dropdown ── */
@media (max-width: 575.98px) {
  .nd-menu {
    width: calc(100vw - 1.25rem) !important;
    max-width: 340px;
    right: -.5rem;
  }
  .adm-topnav .dropdown-menu {
    max-width: calc(100vw - 1rem);
  }
}

/* ── Dropdowns ── */
@media (max-width: 575.98px) {
  .dropdown-menu {
    max-width: calc(100vw - 1rem);
    border-radius: 12px;
  }
  .lang-dropdown {
    min-width: 140px !important;
    max-width: calc(100vw - 2rem);
  }
  .adm-topnav .dropdown-menu-end {
    right: 0 !important;
    left: auto !important;
  }
  .dropdown-item {
    font-size: .82rem;
    padding: .5rem .75rem;
    border-radius: 8px;
  }
}

/* ── Toast notifications ── */
@media (max-width: 575.98px) {
  #notifToastContainer {
    top: calc(var(--safe-top) + .5rem);
    right: .5rem;
    left: .5rem;
    max-width: none;
    width: auto;
  }
  .nt-toast {
    border-radius: 12px;
  }
}

/* ── Command palette ── */
@media (max-width: 575.98px) {
  .cp-inner {
    width: calc(100vw - 1rem);
    border-radius: 14px;
  }
  .cp-panel {
    padding-top: calc(var(--safe-top) + .75rem);
  }
  .cp-search-row {
    padding: .65rem .75rem;
  }
  .cp-item {
    padding: .5rem .75rem;
    font-size: .82rem;
  }
  .cp-footer {
    padding: .4rem .75rem;
    flex-wrap: wrap;
    gap: .4rem;
  }
  .cp-footer-tip {
    display: none;
  }
}


/* ═══════════════════════════════════════════
   §12  VISUAL DENSITY — PREMIUM TUNING
   Reduce clutter, add breathing room
   ═══════════════════════════════════════════ */

/* ── Content area spacing ── */
@media (max-width: 575.98px) {
  .adm-content {
    padding: .85rem .65rem 2rem;
  }
  .app-shell {
    padding: .85rem .65rem 2rem;
  }

  /* Consistent section spacing */
  .row.g-3.mb-4 {
    margin-bottom: var(--section-gap) !important;
  }

  /* Admin user rows — cleaner */
  body .adm-user-row {
    padding: .5rem .75rem;
    gap: .55rem;
  }
  body .adm-user-avatar {
    width: 32px;
    height: 32px;
    font-size: .65rem;
    border-radius: 8px;
  }
  body .adm-user-name {
    font-size: .78rem;
  }
  body .adm-user-email {
    font-size: .66rem;
  }
  body .adm-role-badge {
    font-size: .6rem;
    padding: .15rem .4rem;
  }

  /* Skeleton rows */
  body .adm-skeleton-row {
    gap: .5rem;
  }
}

@media (min-width: 576px) and (max-width: 991.98px) {
  .adm-content {
    padding: 1rem 1rem 2rem;
  }
  .app-shell {
    padding: 1.15rem 1rem 2rem;
  }
}

/* ── Reduce border visual weight on mobile ── */
@media (max-width: 575.98px) {
  body .adm-card,
  body .sd-widget,
  body .id-card {
    border-color: rgba(var(--brand-primary-rgb), .05);
  }
  [data-theme="dark"] body .adm-card,
  [data-theme="dark"] body .sd-widget,
  [data-theme="dark"] body .id-card {
    border-color: rgba(255, 255, 255, .04);
  }
}


/* ═══════════════════════════════════════════
   §13  DASHBOARD MOBILE SECTIONS
   Consistent vertical rhythm, breathing
   ═══════════════════════════════════════════ */

/* ── Student Dashboard Sections ── */
@media (max-width: 767.98px) {
  body .sd-section {
    margin-bottom: var(--section-gap);
  }
  body .sd-section-head {
    margin-bottom: .65rem;
  }
  body .sd-widgets {
    grid-template-columns: 1fr;
    gap: .75rem;
    margin-bottom: 1.5rem;
  }
}

@media (max-width: 575.98px) {
  /* Course grid */
  body .sd-course-grid {
    grid-template-columns: repeat(auto-fill, minmax(155px, 1fr));
    gap: .5rem;
  }
  body .sd-course {
    border-radius: 12px;
  }
  body .sd-course-banner {
    height: 68px;
  }
  body .sd-course-body {
    padding: .6rem .7rem;
  }
  body .sd-course-name {
    font-size: .78rem;
    -webkit-line-clamp: 2;
    line-height: 1.3;
  }
  body .sd-course-instructor {
    font-size: .66rem;
    margin-bottom: .35rem;
  }
  body .sd-prog-text {
    font-size: .58rem;
  }
  body .sd-course-action {
    padding: .4rem;
    font-size: .72rem;
  }
  body .sd-course-pct {
    font-size: .6rem;
    padding: 2px 7px;
    top: 6px;
    right: 6px;
  }

  /* Widget cards */
  body .sd-widget {
    padding: .8rem .75rem;
    border-radius: 12px;
  }
  body .sd-widget-stack {
    gap: .65rem;
  }

  /* Grade rows — compact */
  body .sd-grade-list {
    gap: .2rem;
  }
  body .sd-grade-row {
    gap: .4rem;
    padding: .4rem .35rem;
    border-radius: 8px;
  }
  body .sd-grade-icon {
    width: 30px;
    height: 30px;
    font-size: .78rem;
    border-radius: 7px;
  }
  body .sd-grade-course {
    font-size: .74rem;
  }
  body .sd-grade-lesson {
    font-size: .64rem;
  }
  body .sd-grade-pct {
    font-size: .82rem;
  }
  body .sd-grade-pts {
    font-size: .58rem;
  }
  body .sd-grade-score {
    margin-right: 0;
  }
  body .sd-grade-badge {
    display: none;
  }

  /* Completed items */
  body .sd-completed-item {
    padding: .4rem .45rem;
  }
  body .sd-completed-name {
    font-size: .76rem;
  }
  body .sd-completed-meta {
    font-size: .62rem;
  }
  body .sd-cert-badge {
    font-size: .58rem;
    padding: 2px 6px;
  }

  /* Activity items */
  body .sd-activity-item {
    padding: .35rem .45rem;
    gap: .45rem;
  }
  body .sd-activity-text {
    font-size: .74rem;
  }
  body .sd-activity-ago {
    font-size: .62rem;
  }

  /* Empty states */
  body .sd-empty-state {
    padding: 2rem 1.25rem;
    border-radius: 14px;
  }
  body .sd-widget-empty {
    padding: 1.25rem .75rem;
  }
}

/* ── Instructor Dashboard Sections ── */
@media (max-width: 900px) {
  body .id-main-grid {
    grid-template-columns: 1fr;
    gap: .75rem;
  }
}
@media (max-width: 575.98px) {
  body .id-card {
    padding: .85rem .75rem;
    border-radius: 12px;
  }
  body .id-card-head {
    margin-bottom: .65rem;
    gap: .4rem;
    flex-wrap: wrap;
  }
  body .id-card-title {
    font-size: .88rem;
  }
  body .id-card-sub {
    font-size: .68rem;
  }

  /* Quick action cards */
  body .id-quick-grid {
    gap: .5rem;
  }
  body .id-quick-btn {
    padding: .65rem .5rem;
    font-size: .72rem;
    border-radius: 10px;
  }
  body .id-quick-btn i {
    font-size: 1.05rem;
  }

  /* Feed rows */
  body .id-feed-row {
    padding: .5rem .3rem;
    gap: .55rem;
  }
  body .id-feed-avatar {
    width: 32px;
    height: 32px;
    font-size: .72rem;
    border-radius: 8px;
  }
  body .id-feed-name {
    font-size: .78rem;
  }
  body .id-feed-course {
    font-size: .66rem;
  }
  body .id-right-col {
    gap: .75rem;
  }
}


/* ═══════════════════════════════════════════
   §14  TOUCH EXPERIENCE — PREMIUM FEEL
   Native-like tap, scroll, gesture
   ═══════════════════════════════════════════ */

/* ── Touch device overrides ── */
@media (hover: none) and (pointer: coarse) {
  /* Remove hover transforms that cause jank on touch */
  .adm-stat:hover,
  .sd-stat:hover,
  .id-kpi:hover,
  .course-card:hover,
  .sd-course:hover,
  .kpi-card:hover,
  .adm-card:hover,
  .id-card:hover,
  .sd-widget:hover,
  .float-card:hover {
    transform: none;
  }

  /* Active state feedback instead of hover */
  .adm-stat:active,
  .sd-stat:active,
  .id-kpi:active {
    transform: scale(.98);
    transition-duration: .1s;
  }

  .sd-course:active {
    transform: scale(.985);
    transition-duration: .1s;
  }

  .id-quick-btn:active {
    transform: scale(.96);
    transition-duration: .08s;
  }

  /* Larger tap targets */
  .sidebar .nav-link {
    padding: .6rem .8rem;
    min-height: 44px;
  }
  .adm-nav-link {
    padding: .55rem .7rem;
    min-height: 44px;
  }

  /* Prevent iOS 300ms delay */
  a, button, [role="button"], input, select, textarea {
    touch-action: manipulation;
  }

  /* Better scroll containers */
  .table-responsive,
  .sidebar,
  .adm-sidebar,
  .id-table-wrap {
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
  }

  /* Button active states */
  .btn:active,
  .sd-hero-btn:active,
  .id-banner-btn:active,
  .adm-qaction:active {
    transform: scale(.97);
    transition-duration: .08s;
  }

  .sd-link:active,
  .id-card-action:active,
  .adm-link-btn:active {
    opacity: .7;
  }

  /* Grade/feed row active */
  .sd-grade-row:active,
  .id-feed-row:active,
  .sd-completed-item:active,
  .sd-activity-item:active {
    background: rgba(var(--brand-primary-rgb), .06);
    transition-duration: .05s;
  }
}

/* ── Smooth scrolling for all scroll containers ── */
@media (max-width: 991.98px) {
  .sidebar,
  .adm-sidebar {
    overscroll-behavior: contain;
    scroll-behavior: smooth;
  }
}


/* ═══════════════════════════════════════════
   §15  ALERT — MOBILE
   ═══════════════════════════════════════════ */
@media (max-width: 575.98px) {
  .alert {
    font-size: .8rem;
    padding: .6rem .75rem;
    border-radius: 10px;
  }
  .alert .btn-close {
    padding: .45rem;
  }
}


/* ═══════════════════════════════════════════
   §16  AUTH PAGES — SMALL SCREENS
   ═══════════════════════════════════════════ */
@media (max-width: 575.98px) {
  body.auth-page {
    min-height: 100dvh;
    height: auto;
    overflow-x: hidden;
    overflow-y: auto;
  }
  body.auth-page .auth-shell {
    padding: .75rem .75rem calc(32px + env(safe-area-inset-bottom, 0px));
  }
  body.auth-page .auth-shell > main {
    align-items: stretch;
  }
  .app-shell {
    padding: .85rem .85rem calc(2rem + var(--safe-bottom));
  }
  .auth-card {
    width: 100%;
    max-width: 100%;
    margin: .75rem auto 1.75rem;
  }
  .auth-card .card {
    border-radius: 16px;
    overflow: visible;
  }
  .auth-card .card-body {
    padding: 1.45rem 1rem 1.6rem !important;
  }
  .auth-card h2 {
    font-size: 1.2rem;
    letter-spacing: -.3px;
  }
  .auth-card .row.g-3 {
    --bs-gutter-y: .75rem;
  }
  .auth-card .mb-3 {
    margin-bottom: .75rem !important;
  }
  .auth-card .mb-4 {
    margin-bottom: 1rem !important;
  }
  .auth-card .form-control,
  .auth-card .form-select,
  .auth-card .pwd-toggle-btn {
    min-height: 44px;
  }
  .auth-card .btn-primary.btn-lg {
    border-radius: 12px;
    font-size: .88rem;
    min-height: 44px;
    padding: .65rem .85rem;
  }
  body.auth-page .auth-card {
    margin: .75rem auto 2.25rem;
  }
  body.auth-page .auth-card .card,
  body.auth-page .auth-card .card-body,
  body.auth-page .auth-card form {
    max-height: none;
    overflow: visible;
  }
  body.auth-page .auth-footer {
    position: static !important;
    bottom: auto !important;
    flex-shrink: 0;
  }
}
@media (max-width: 390px) {
  .auth-card {
    margin-top: .5rem;
  }
  .auth-card .card-body {
    padding: 1.25rem .9rem 1.45rem !important;
  }
  .auth-card h2 {
    font-size: 1.1rem;
  }
}


/* ═══════════════════════════════════════════
   §17  QUIZ — MOBILE UX
   ═══════════════════════════════════════════ */
@media (max-width: 575.98px) {
  .qt-shell {
    padding-top: .25rem;
  }
  .qt-header {
    flex-direction: column;
    align-items: stretch;
    gap: .4rem;
    padding: .6rem .75rem;
    border-radius: 12px;
  }
  .qt-header-left {
    gap: .45rem;
  }
  .qt-header-right {
    justify-content: space-between;
  }
  .qt-header-icon {
    width: 32px;
    height: 32px;
    font-size: .9rem;
  }
  .qt-header-title {
    font-size: .78rem;
  }
  .qt-timer {
    padding: .25rem .45rem .25rem .25rem;
  }
  .qt-timer-ring,
  .qt-ring-svg {
    width: 28px;
    height: 28px;
  }
  .qt-timer-value {
    font-size: .82rem;
  }
  .qt-question-card {
    padding: .85rem;
    border-radius: 12px;
  }
  .qt-question-text {
    font-size: .88rem;
    line-height: 1.5;
  }
  .qt-option {
    padding: .75rem .8rem;
    gap: .55rem;
    border-radius: 10px;
    min-height: 44px;
  }
  .qt-option-text {
    font-size: .82rem;
  }
  .qt-nav {
    gap: .4rem;
  }
  .qt-nav-prev,
  .qt-nav-next,
  .qt-submit-btn {
    flex: 1;
    justify-content: center;
    padding: .6rem .75rem;
    border-radius: 10px;
    font-size: .82rem;
  }
  .qt-dots {
    gap: .4rem;
    margin-top: .75rem;
  }
  .qt-dot {
    width: 11px;
    height: 11px;
  }
  .qt-attempt-bar {
    flex-direction: column;
    align-items: flex-start;
    gap: .3rem;
    padding: .45rem .65rem;
    font-size: .72rem;
    border-radius: 8px;
  }
  .qt-autosave-status {
    margin-left: 0;
  }
}


/* ═══════════════════════════════════════════
   §18  FOOTER — MOBILE POLISH
   ═══════════════════════════════════════════ */
@media (max-width: 575.98px) {
  .footer {
    padding: .65rem 0;
    padding-bottom: calc(.65rem + var(--safe-bottom));
    font-size: .74rem;
  }
  .footer-inner {
    gap: .5rem;
    flex-direction: column;
    text-align: center;
  }
  .footer-brand {
    font-size: .76rem;
  }
}


/* ═══════════════════════════════════════════
   §19  CHAT — MOBILE
   ═══════════════════════════════════════════ */
@media (max-width: 575.98px) {
  .ct-message {
    max-width: 92%;
  }
  .ct-input-wrap textarea {
    min-height: 38px;
    font-size: .85rem;
  }
}


/* ═══════════════════════════════════════════
   §20  COURSE CARDS — MOBILE POLISH
   ═══════════════════════════════════════════ */
@media (max-width: 575.98px) {
  .course-card {
    border-radius: 14px;
  }
  .course-card-img,
  .course-card-img-placeholder {
    height: 140px;
  }
  .course-card-body {
    padding: .85rem .9rem;
  }
  .course-card-title {
    font-size: .88rem;
    margin-bottom: .3rem;
  }
  .course-card-desc {
    font-size: .78rem;
    margin-bottom: .65rem;
  }
}


/* ═══════════════════════════════════════════
   §21  MOBILE BASE FONT SCALE
   Premium Inter at proper mobile size
   ═══════════════════════════════════════════ */
@media (max-width: 767.98px) {
  html {
    font-size: 14px;
  }
}
@media (max-width: 390px) {
  html {
    font-size: 13.5px;
  }
}


/* ═══════════════════════════════════════════
   §22  PUBLIC HOME — HERO MOBILE
   ═══════════════════════════════════════════ */
@media (max-width: 575.98px) {
  .hero {
    padding: 2.5rem 1rem 2rem;
  }
  .hero h1 {
    font-size: clamp(1.5rem, 6vw, 2rem);
    letter-spacing: -1px;
    line-height: 1.2;
  }
  .hero p {
    font-size: .88rem;
    line-height: 1.6;
    margin-bottom: 1.5rem;
  }
}


/* ═══════════════════════════════════════════
   §23  SMOOTH SCROLL BEHAVIOR
   ═══════════════════════════════════════════ */
@media (max-width: 991.98px) {
  /* Prevent bounce on iOS */
  body {
    overscroll-behavior-y: none;
  }

  /* Sidebar smooth scroll */
  .sidebar,
  .adm-sidebar {
    scroll-behavior: smooth;
  }
}


/* ═══════════════════════════════════════════
   §24  PRINT — HIDE CHROME
   ═══════════════════════════════════════════ */
@media print {
  .sidebar,
  .adm-sidebar,
  .top-nav,
  .adm-topnav,
  .sidebar-overlay,
  .adm-overlay,
  .btn-sidebar-toggle {
    display: none !important;
  }
  .sidebar-content,
  .adm-content,
  .adm-main {
    margin-left: 0 !important;
    padding: 0 !important;
  }
}


/* ═══════════════════════════════════════════
   §26  POINTER-EVENTS SAFETY NET
   Ensure decorative layers never intercept taps
   ═══════════════════════════════════════════ */

/*
 * Decorative overlays: invisible overlays that exist in DOM for mobile
 * sidebar/admin panel must never intercept touch when closed.
 * The base rules in site.css / _AdminLayout already set pointer-events:none,
 * but this defensive layer ensures mobile specificity cannot re-enable them.
 */
@media (max-width: 991.98px) {
  .sidebar-overlay:not(.sidebar-open) {
    pointer-events: none !important;
  }
  .adm-overlay:not(.open) {
    pointer-events: none !important;
  }
}

/*
 * Decorative pseudo-elements: absolutely positioned pseudo-elements
 * used for gradient accents, shimmer effects, etc. must pass through.
 */
.sd-hero-bg,
.sd-hero-ring .sd-ring-track,
.id-kpi::before,
.adm-welcome::before,
.adm-welcome::after {
  pointer-events: none;
}


/* ═══════════════════════════════════════════
   §27  iOS SAFARI COMPATIBILITY
   Fix touch issues specific to WebKit/Safari
   ═══════════════════════════════════════════ */

/*
 * backdrop-filter on interactive elements can cause iOS Safari
 * to drop touch events in certain compositing scenarios.
 * Force a new stacking context and ensure tappability.
 */
.sd-hero-btn--ghost {
  -webkit-transform: translateZ(0);
  transform: translateZ(0);
  position: relative;
  z-index: 1;
}

/*
 * iOS tap highlight: provide subtle visual feedback on tap
 * instead of the default blue/grey highlight box.
 */
@media (pointer: coarse) {
  a, button, [role="button"],
  .sd-hero-btn,
  .id-banner-btn,
  .id-kpi-link,
  .adm-qaction,
  .adm-nav-link,
  .sidebar .nav-link {
    -webkit-tap-highlight-color: rgba(var(--brand-primary-rgb), .12);
  }
}

/*
 * Ensure hero CTA buttons are explicitly interactive.
 * Defensive: even if a parent accidentally sets pointer-events:none,
 * interactive children override it.
 */
.sd-hero-actions a,
.sd-hero-actions button,
.id-banner-actions a,
.id-banner-actions button,
.adm-welcome a,
.adm-welcome button {
  pointer-events: auto;
  position: relative;
  z-index: 2;
}


/* ═══════════════════════════════════════════
   §28  REDUCED MOTION — ACCESSIBILITY
   ═══════════════════════════════════════════ */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }
}
