/* Small-screen layout for the installed app and mobile browsers. */
@media (max-width: 760px) {
  html, body, #root, .app, .main { width: 100%; min-width: 0; }
  .app:has(.sidebar.open)::before {
    content: "";
    position: fixed;
    inset: 0;
    z-index: 40;
    background: rgba(9, 32, 21, .58);
  }
  body:has(.sidebar.open) { overflow: hidden; }
  .sidebar {
    width: min(340px, calc(100vw - 52px)) !important;
    height: 100dvh;
    max-height: 100dvh;
    z-index: 50 !important;
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .sidebar.open { overflow: hidden; }
  .sidebar .brand { flex: none; min-height: 72px; height: auto; }
  .sidebar .period { flex: none; margin: 10px 14px; }
  .sidebar nav {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding-bottom: 12px;
    -webkit-overflow-scrolling: touch;
  }
  .sidebar nav button { min-height: 44px; }
  .sidebar nav button span { min-width: 0; white-space: normal; line-height: 1.3; }
  .sidebar .subnav { max-height: none; overflow: visible; }
  .sidebar .subnav button { min-height: 40px; }
  .sideFooter { flex: none; padding-bottom: 12px; }

  .main { margin-left: 0 !important; width: 100% !important; }
  .main > header {
    display: grid;
    grid-template-columns: 42px minmax(0, 1fr);
    grid-template-rows: minmax(43px, auto) 40px;
    gap: 2px 8px;
    height: auto;
    min-height: 94px;
    padding: max(5px, env(safe-area-inset-top)) 12px 6px !important;
    z-index: 35;
  }
  .main > header > div:nth-child(2) { min-width: 0; }
  .main > header h1 {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 16px;
    line-height: 1.3;
  }
  .main > header .crumb { display: none; }
  .main > header .hamb {
    display: grid;
    place-items: center;
    width: 40px;
    height: 40px;
    margin: 0;
    border: 1px solid #d6e7dc;
    border-radius: 10px;
    background: #f3faf5;
    color: #175239;
    font-size: 20px;
  }
  .app:has(.sidebar.open) .main > header {
    position: fixed;
    z-index: 60;
    width: 0;
    height: 0;
    min-height: 0;
    padding: 0 !important;
    border: 0;
    background: transparent;
    backdrop-filter: none;
  }
  .app:has(.sidebar.open) .main > header > div { visibility: hidden; }
  .app:has(.sidebar.open) .main > header .hamb {
    position: fixed;
    top: calc(env(safe-area-inset-top) + 12px);
    right: 7px;
    z-index: 60;
    width: 40px;
    height: 40px;
    font-size: 0;
    background: #fff;
    box-shadow: 0 4px 16px rgba(0,0,0,.14);
  }
  .app:has(.sidebar.open) .main > header .hamb::after {
    content: "×";
    font-size: 27px;
    line-height: 1;
  }
  .main > header .topActions {
    grid-column: 1 / -1;
    min-width: 0;
    display: flex;
    gap: 6px;
    justify-content: flex-end;
  }
  .topActions .textSizeControl { min-width: 0; flex: 1 1 auto; padding: 2px; gap: 0; }
  .topActions .textSizeControl > span { display: none; }
  .topActions .textSizeControl button {
    flex: 1 1 0;
    min-width: 0 !important;
    padding: 0 3px !important;
    font-size: 11px !important;
    white-space: nowrap;
  }
  .topActions > button { flex: none; width: 38px; height: 38px; }
  .content { width: 100%; min-width: 0; padding: 14px 12px 28px !important; }
  .content > *, .panel, .moduleHead, .welcome, .moduleIntro,
  .grid2 > *, .grid3 > *, .stats > *, .formGrid > * { min-width: 0; }
  .welcome, .moduleIntro, .moduleHead { flex-wrap: wrap; gap: 10px; }
  .welcome h2, .moduleIntro h2, .moduleHead h2 { overflow-wrap: anywhere; }
  .stats, .dashboardKpis, .quickActionGrid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat { min-width: 0; align-items: flex-start; }
  .stat span, .stat b, .stat small { overflow-wrap: anywhere; }
  .grid2, .grid3, .grid4, .definitionGrid, .formGrid,
  .v22Two, .v22Split, .familyColumns { grid-template-columns: minmax(0, 1fr) !important; }
  .collectionsV17 .collectionsLayout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) !important;
    width: 100%;
    gap: 12px;
  }
  .collectionsV17 .collectionsLayout > aside,
  .collectionsV17 .collectionsLayout > main {
    width: 100%;
    min-width: 0;
  }
  .collectionsV17 .collectionStudents {
    position: static;
    max-height: 230px;
    overflow-y: auto;
    overscroll-behavior: contain;
  }
  .collectionsV17 .collectionStudents .search {
    position: sticky;
    top: 0;
    z-index: 1;
    width: 100%;
    min-width: 0;
    background: #fff;
  }
  .collectionsV17 .v17FinanceHero {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    width: 100%;
    min-width: 0;
    gap: 10px;
  }
  .collectionsV17 .v17FinanceHero > div,
  .collectionsV17 .v17FinanceHero > button,
  .collectionsV17 .v17FinanceHero > small { min-width: 0; overflow-wrap: anywhere; }
  .collectionsV17 .v17FinanceHero > div:first-child,
  .collectionsV17 .v17FinanceHero > button,
  .collectionsV17 .v17FinanceHero > small { grid-column: 1 / -1; }
  .collectionsV17 .v17FinanceHero > button { width: 100%; min-height: 44px; }
  .collectionsV17 .grid2 { grid-template-columns: minmax(0, 1fr) !important; }
  .panelHead, .toolbar, .financeQuick { flex-wrap: wrap; }
  .tableWrap { max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .tabbar, .tabBar, .tabs, .v22InlineTabs, .reportCategoryTabs {
    max-width: 100%;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    -webkit-overflow-scrolling: touch;
  }
  .modalBackdrop { align-items: flex-end; padding: 0 !important; }
  .modal, .modalCard, .wizardModal {
    width: 100% !important;
    max-width: 100% !important;
    max-height: calc(100dvh - env(safe-area-inset-top) - 8px) !important;
    border-radius: 18px 18px 0 0;
    padding-bottom: max(16px, env(safe-area-inset-bottom));
  }
}
@media (max-width: 380px) {
  .main > header { padding-left: 9px !important; padding-right: 9px !important; }
  .main > header .topActions { gap: 4px; }
  .topActions .textSizeControl button { font-size: 10px !important; padding: 0 1px !important; }
  .topActions > button { width: 34px; }
  .stats, .dashboardKpis, .quickActionGrid { grid-template-columns: minmax(0, 1fr); }
}
