/* Shared mobile shell for Super Admin pages.
 * Pages keep their desktop layout; below 768px the sidebar becomes an
 * accessible off-canvas drawer and dense workspaces adapt to touch screens. */
.sa-mobile-nav-toggle,
.sa-mobile-drawer-backdrop { display: none; }

@media (max-width: 768px) {
  html, body { width: 100%; overflow-x: hidden; }
  html { overflow-y: auto !important; }
  body:not(.sa-scroll-lock):not(.sa-drawer-open) { overflow-y: auto !important; }
  body.sa-drawer-open { overflow: hidden; }

  .app-shell,
  body.sidebar-collapsed .app-shell,
  .shell,
  body.sidebar-collapsed .shell {
    display: block;
    width: 100%;
    min-height: 100dvh;
    height: auto;
  }

  .app-shell > .sidebar,
  body.sidebar-collapsed .app-shell > .sidebar,
  .shell > .sidebar,
  body.sidebar-collapsed .shell > .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 1100;
    width: min(88vw, 304px);
    height: 100dvh;
    padding-top: max(18px, env(safe-area-inset-top));
    padding-bottom: max(18px, env(safe-area-inset-bottom));
    border-radius: 0 22px 22px 0;
    transform: translate3d(-105%, 0, 0);
    transition: transform .24s cubic-bezier(.4, 0, .2, 1);
    box-shadow: 18px 0 48px rgba(7, 3, 24, .38);
    overflow: hidden;
    overscroll-behavior: contain;
  }
  body.sa-drawer-open .app-shell > .sidebar,
  body.sa-drawer-open .shell > .sidebar { transform: translate3d(0, 0, 0); }

  body.sidebar-collapsed .brand-copy,
  body.sidebar-collapsed .brand-text,
  body.sidebar-collapsed .brand-subtitle,
  body.sidebar-collapsed .portal-chip { display: flex !important; }
  body.sidebar-collapsed .brand-copy { flex-direction: column; }
  body.sidebar-collapsed .nav-label { display: inline !important; }
  body.sidebar-collapsed .brand-wrap,
  body.sidebar-collapsed .nav a { justify-content: flex-start; }
  body.sidebar-collapsed .sidebar-footer-row { flex-direction: row; justify-content: space-between; }
  .app-shell > .sidebar > .brand-wrap,
  .app-shell > .sidebar > .portal-chip,
  .app-shell > .sidebar > .sidebar-footer-row,
  .shell > .sidebar > .brand-wrap,
  .shell > .sidebar > .portal-chip,
  .shell > .sidebar > .sidebar-footer-row { flex: 0 0 auto; }
  .app-shell > .sidebar > .nav,
  .shell > .sidebar > .nav {
    flex: 1 1 auto;
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
    padding-right: 4px;
    overscroll-behavior: contain;
    scrollbar-width: thin;
  }
  .app-shell > .sidebar > .nav a,
  .shell > .sidebar > .nav a { min-height: 44px; margin-bottom: 3px; }
  .app-shell > .sidebar > .nav .nav-label,
  .shell > .sidebar > .nav .nav-label {
    min-width: 0;
    white-space: normal;
    overflow-wrap: anywhere;
    line-height: 1.25;
  }
  .app-shell > .sidebar > .sidebar-footer-row,
  .shell > .sidebar > .sidebar-footer-row {
    margin-top: 8px;
    padding-top: 10px;
    background: inherit;
  }

  .sa-mobile-drawer-backdrop {
    position: fixed;
    inset: 0;
    z-index: 1090;
    border: 0;
    width: 100%;
    height: 100%;
    background: rgba(7, 3, 24, .58);
    opacity: 0;
    visibility: hidden;
    transition: opacity .2s ease, visibility .2s ease;
  }
  body.sa-drawer-open .sa-mobile-drawer-backdrop {
    display: block;
    opacity: 1;
    visibility: visible;
  }

  .right-column { display: block; width: 100%; height: auto; min-height: 100dvh; }
  .topbar {
    position: sticky;
    top: 0;
    z-index: 60;
    width: 100%;
    min-height: calc(64px + env(safe-area-inset-top));
    height: auto;
    padding: calc(10px + env(safe-area-inset-top)) 12px 10px;
    flex-wrap: nowrap;
  }
  .topbar-left, .topbar-right { min-width: 0; gap: 8px; }
  .sa-mobile-nav-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 44px;
    width: 44px;
    height: 44px;
    padding: 0;
    border: 1px solid var(--line, #e7e9f2);
    border-radius: 13px;
    background: rgba(255, 255, 255, .08);
    color: var(--primary, #4b2aad);
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }
  .sa-mobile-nav-toggle svg { width: 22px; height: 22px; }
  .sa-mobile-nav-toggle:focus-visible { outline: 3px solid rgba(123, 108, 246, .45); outline-offset: 2px; }
  .sa-mobile-nav-standalone {
    position: sticky;
    top: max(10px, env(safe-area-inset-top));
    z-index: 60;
    margin: 0 0 12px;
    background: var(--panel, #fff);
    box-shadow: 0 8px 24px rgba(7, 3, 24, .15);
  }

  .school-name, .school-sub,
  .kairos-user-box .user-name, .kairos-user-box .user-role,
  .user-box .user-name, .user-box .user-role,
  .user-box > div:last-child { display: none; }
  .school-logo, .user-avatar { width: 38px; height: 38px; }
  .user-box { padding: 4px; border-radius: 12px; }

  .page-content {
    width: 100%;
    min-width: 0;
    padding: 14px 12px calc(24px + env(safe-area-inset-bottom));
    overflow: visible;
  }
  .hero, .uwk-head { border-radius: 20px; padding: 20px 16px; }
  .hero h1, .uwk-head h1 { font-size: clamp(24px, 7vw, 30px); }
  .hero-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .hero-stat, .quick-card, .panel { min-width: 0; }
  .kpi-card, .swk-kpi, .uwk-kpi, .cw-kpi, .hero-stat {
    min-width: 0;
    padding: 11px 12px;
    border-radius: 14px;
  }
  .kpi-val, .swk-kpi-v, .uwk-kpi-v, .cw-kpi__value, .hero-stat .value {
    font-size: clamp(20px, 6vw, 24px);
    line-height: 1.05;
  }
  .kpi-label, .swk-kpi-k, .uwk-kpi-k, .cw-kpi__label, .hero-stat .label {
    font-size: 10px;
    line-height: 1.25;
  }
  .grid, .quick-grid { grid-template-columns: minmax(0, 1fr); }
  .tabs, .ob-tabs {
    flex-wrap: nowrap;
    margin-inline: -12px;
    padding-inline: 12px;
    overflow-x: auto;
    overscroll-behavior-inline: contain;
    scrollbar-width: none;
  }
  .tabs::-webkit-scrollbar, .ob-tabs::-webkit-scrollbar { display: none; }
  .tabs > *, .ob-tabs > * { flex: 0 0 auto; min-height: 44px; }
  .hero-tabs, .subtabs {
    display: flex;
    flex-wrap: nowrap;
    max-width: none;
    margin-inline: -12px;
    padding: 0 12px 5px;
    overflow-x: auto;
    overscroll-behavior-inline: contain;
    scrollbar-width: none;
  }
  .hero-tabs::-webkit-scrollbar, .subtabs::-webkit-scrollbar { display: none; }
  .hero-tabs > *, .subtabs > * { flex: 0 0 auto; min-height: 44px; }
  .hero-actions { width: 100%; }
  .hero-actions .btn, .hero-actions a, .hero-actions button { min-height: 44px; justify-content: center; }
  .toolbar { align-items: stretch; }
  .toolbar .btn, .btn { min-height: 44px; justify-content: center; }
  button, .btn, .sa-btn, .swk-btn, .swk-row-action, .swk-head-cta {
    max-width: 100%;
    min-width: 0;
    white-space: normal;
    overflow-wrap: anywhere;
  }
  .form-row input, .form-row select { min-height: 44px; font-size: 16px; }
  .main-grid, .content-grid, .context-grid, .field-grid,
  .an-grid, .an-status-grid { grid-template-columns: minmax(0, 1fr); }
  .top-actions, .an-actions {
    display: flex;
    width: 100%;
    min-width: 0;
    flex-wrap: wrap;
    align-items: stretch;
    gap: 8px;
  }
  .top-actions > *, .an-actions > * { flex: 1 1 140px; max-width: 100%; justify-content: center; }
  .field-grid input, .field-grid select, .field-grid textarea,
  .an-field input, .an-field select, .an-field textarea { width: 100%; min-width: 0; font-size: 16px; }
  .table-wrap { max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .table, .sa-table, .content-tbl, .upd-table { min-width: 680px; }
  .sa-table-scroll, .content-tbl-scroll, .upd-table-wrap { max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .uwk-head .uwk-head-actions { width: 100%; align-items: stretch; }
  .uwk-head .uwk-head-cta { justify-content: center; min-height: 44px; }
  .uwk-head .uwk-warn { max-width: none; }

  .uwk-tabbar {
    flex-wrap: nowrap;
    margin-inline: -12px;
    padding: 0 12px 5px;
    overflow-x: auto;
    scroll-snap-type: x proximity;
    scrollbar-width: none;
  }
  .uwk-tabbar::-webkit-scrollbar { display: none; }
  .uwk-tabbar button { flex: 0 0 auto; min-height: 44px; scroll-snap-align: start; }
  .uwk-panel, .uwk-create-card { padding: 15px; border-radius: 18px; }
  .uwk-toolbar { align-items: stretch; }
  .uwk-toolbar input[type="search"] { flex-basis: 100%; min-width: 0; min-height: 44px; }
  .uwk-filter-chips { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 3px; scrollbar-width: none; }
  .uwk-filter-chips::-webkit-scrollbar { display: none; }
  .uwk-filter-chips button { flex: 0 0 auto; min-height: 40px; }
  .uwk-btn, .uwk-row-action { min-height: 44px; }
  .uwk-form-grid, .uwk-roles-grid, .uwk-preview-grid { grid-template-columns: minmax(0, 1fr); }
  .uwk-form-row input, .uwk-form-row select { min-height: 44px; font-size: 16px; }
  .uwk-form-actions { align-items: stretch; }
  .uwk-form-actions .uwk-btn { width: 100%; }
  .uwk-recent-row { align-items: flex-start; flex-wrap: wrap; }
  .uwk-table-wrap { max-width: 100%; -webkit-overflow-scrolling: touch; }
  .uwk-table { min-width: 720px; }

  /* Schools command center: keep every action inside the mobile viewport. */
  .swk-head { min-width: 0; }
  .swk-head-actions,
  .swk-toolbar,
  .swk-schools-ops,
  .swk-bulkbar,
  .swk-bulk-actions,
  .swk-pager,
  .swk-pager-actions,
  .swk-form-actions { width: 100%; min-width: 0; }
  .swk-head-actions > *,
  .swk-schools-ops > *,
  .swk-bulk-actions > *,
  .swk-pager-actions > *,
  .swk-form-actions > button { flex: 1 1 140px; justify-content: center; text-align: center; }
  .swk-toolbar input[type="search"],
  .swk-toolbar input[type="text"],
  .swk-toolbar select,
  .swk-dir-search { width: 100%; min-width: 0; flex: 1 1 100%; font-size: 16px; }
  .swk-dir-head { flex-direction: column; align-items: stretch; }
  .swk-dir-seg { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); width: 100%; }
  .swk-dir-seg button { min-width: 0; white-space: normal; }
  .swk-hero-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .swk-panel { min-width: 0; padding: 14px; border-radius: 18px; }
}

@media (max-width: 420px) {
  .topbar .notif { width: 38px; height: 38px; }
  .hero-stats { grid-template-columns: 1fr; }
  .uwk-hero-grid { grid-template-columns: 1fr; }
  .swk-head-actions > *,
  .swk-schools-ops > *,
  .swk-bulk-actions > *,
  .swk-pager-actions > *,
  .swk-form-actions > button { flex-basis: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  .app-shell > .sidebar, .shell > .sidebar, .sa-mobile-drawer-backdrop { transition: none !important; }
}
