/* ==========================================================================
   Orbium — screen-fit layer
   Loaded LAST on every app page. Layout only: no colours, fonts or
   component looks change here.

   Rule of the house: the page frame never scrolls. Header and footer stay
   put; the region between them fills the rest of the screen. Whenever a
   screen is too small for a section to show everything, that region (or the
   card inside it) scrolls on its own instead of being cut off or running
   under the footer.

   Tiers
     > 1180px   desktop / laptop: one-row header, multi-column sections
     769–1180   small laptop / tablet landscape: one-row compact header,
                sections stack where the columns would get too thin
     <= 768     phone / tablet portrait: two-row header, stacked content,
                compact footer
   ========================================================================== */

/* ---------- 0. Global guards ---------- */
html, body { max-width: 100%; overflow-x: hidden; }
body { min-width: 0; }
img, video, canvas { max-width: 100%; }

/* ---------- 1. Teacher console header ---------- */
/* Small laptops: keep the header on one row by tightening it instead of
   wrapping (wrapping pushed the logo out of the top of the bar). */
@media (min-width: 769px) and (max-width: 1180px) {
  nav.ob-topbar .topbar-in { flex-wrap: nowrap; padding-top: 0; padding-bottom: 0; gap: 12px; }
  nav.ob-topbar .pillnav { order: 0; flex: 0 1 auto; min-width: 0; margin: 0 auto; }
  nav.ob-topbar .snav-link { padding: 7px 12px; font-size: 13px; }
  nav.ob-topbar .nav-right { margin-left: 0; }
  nav.ob-topbar .account-id { display: none; }
  nav.ob-topbar .account-btn { padding: 3px; }
  .ob-brand-sub #orgName { max-width: 110px; }
}
@media (min-width: 769px) and (max-width: 960px) {
  .ob-brand-sub { display: none; }
  nav.ob-topbar .snav-link { padding: 7px 10px; font-size: 12.5px; }
}

/* Phones and portrait tablets: brand + account on row one, the section tabs
   on row two as a swipeable strip (every tab stays reachable). */
@media (max-width: 768px) {
  nav.ob-topbar { min-height: 0; }
  nav.ob-topbar .topbar-in {
    flex-wrap: wrap; row-gap: 8px; column-gap: 10px;
    padding: 8px 14px;
  }
  nav.ob-topbar .ob-brand { order: 0; flex: 1 1 auto; min-width: 0; }
  nav.ob-topbar .nav-right { order: 1; margin-left: auto; width: auto; flex: none; }
  nav.ob-topbar .topbar-in { align-items: center; }
  nav.ob-topbar .pillnav {
    order: 2; flex: 1 1 100%; max-width: 100%; margin: 0;
    justify-content: flex-start; overflow-x: auto; -webkit-overflow-scrolling: touch;
  }
  nav.ob-topbar .snav-link { padding: 7px 12px; font-size: 13px; flex: none; }
  nav.ob-topbar .account-id, nav.ob-topbar .term-pill, .ob-brand-sub { display: none; }
  nav.ob-topbar .account-btn { padding: 3px; }
  .ob-mark { width: 34px; height: 34px; font-size: 19px; border-radius: 10px; }
  nav.ob-topbar .brand-word, .ob-brand .brand-word { font-size: 21px; }
}

/* ---------- 2. Shared footer ---------- */
@media (max-height: 640px) {
  .db-footer.ob-footer, .db-footer { padding: 6px 0; }
}
@media (max-width: 768px) {
  .db-footer.ob-footer, .db-footer { padding: 6px 0; }
  .db-footer .db-footer-in { flex-wrap: nowrap; gap: 8px; }
  .db-footer .foot-brand { min-width: 0; font-size: 11px; }
  .db-footer .foot-brand > span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  /* links become icon buttons; their text stays for screen readers */
  .db-footer .foot-links { flex: none; gap: 2px; }
  .db-footer .foot-links button { font-size: 0; gap: 0; padding: 8px; min-width: 36px; min-height: 36px; justify-content: center; }
  .db-footer .foot-links button svg { width: 17px; height: 17px; }
}

/* ---------- 3. Teacher console sections ---------- */
/* Safety net: a section that cannot fit scrolls inside itself rather than
   being clipped under the footer. With the normal desktop layout nothing
   overflows, so no scrollbar appears there. */
main.section-page[data-page] { overflow-y: auto; overflow-x: hidden; scrollbar-width: thin; }

/* Dashboard, desktop layout on short screens: the goals card keeps its own
   height (so the export button is never cut off) and the milestones card
   takes whatever is left, scrolling its list. */
@media (min-width: 1101px) {
  .dash .db-side > .db-card:last-child { flex: 0 1 auto; }
  .dash .db-side > .db-card:last-child .goal-list { flex: 0 1 auto; max-height: clamp(48px, 20vh, 240px); min-height: 0; }
  .dash .db-side > .db-card:first-child { flex: 1 1 0; min-height: 96px; }
  .dash .db-side .ms-list { min-height: 0; }
}
/* Dashboard, stacked layout: cards take their natural height and the
   section scrolls between header and footer. */
@media (max-width: 1100px) {
  main.dash.wrap[data-page="dashboard"] { height: 100%; overflow-y: auto; }
  .dash .db-main { flex: none; }
  .dash .db-left, .dash .db-side { height: auto; }
  .dash .db-left > .db-progress { flex: none; min-height: 300px; }
  .dash .db-left > .db-progress .pg-chart { flex: 1 1 auto; min-height: 200px; }
}
@media (max-width: 768px) {
  main.dash.wrap[data-page="dashboard"] { padding-left: 14px; padding-right: 14px; }
  .dash .db-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dash .db-topline { justify-content: flex-start; }
}

/* Timetable: on small screens let the whole section scroll; the week grid
   keeps a usable height instead of collapsing to three days. */
@media (max-width: 1180px), (max-height: 600px) {
  main.ob-page[data-page="timetable"] > .tt-layout { flex: none; overflow: visible; }
  main.ob-page[data-page="timetable"] .tt-week { min-height: min(560px, 80vh); }
  main.ob-page[data-page="timetable"] .rs-card { max-height: none; overflow: visible; }
  main.ob-page[data-page="timetable"] > :last-child { margin-bottom: 12px; }
}
@media (max-width: 768px) {
  main.ob-page[data-page="timetable"] .ht-grid-wrap { overflow-x: auto; }
  main.ob-page[data-page="timetable"] .ht-grid-wrap > * { min-width: 520px; }
}

/* Classes & Batches */
.gc-code { flex-wrap: wrap; row-gap: 6px; min-width: 0; }
.gcc-value { flex: 1 0 auto; }
.gcc-copy, .gcc-new { flex: none; }
@media (max-width: 980px) {
  /* stacked: sidebar then class list, each at natural height, section scrolls */
  main.layout[data-page="classes"] { display: flex; flex-direction: column; overflow-y: auto; }
  main.layout[data-page="classes"] > * { flex: none; min-height: auto; overflow: visible; }
  main.layout[data-page="classes"] .sidebar .card:last-child { flex: none; }
  main.layout[data-page="classes"] .sidebar .card:last-child .student-pick { flex: none; max-height: 220px; }
}

/* Payments */
@media (max-width: 900px), (max-height: 600px) {
  main.ob-page[data-page="payment"] > .pm-ledger-wrap { flex: none; min-height: min(520px, 85vh); }
}
main.ob-page[data-page="payment"] .pm-table-wrap { overflow-x: auto; }

/* Modals and pop-ups never exceed the screen */
.overlay .modal-box, .modal-box.card { max-height: calc(100dvh - 24px); overflow-y: auto; }
@media (max-width: 768px) {
  .modal-box, .modal-box.card { padding: 20px 18px; border-radius: 22px; width: min(520px, calc(100vw - 20px)); }
}

/* Timetable: below 900px the reschedule card drops under the week grid */
@media (max-width: 900px) {
  main.ob-page[data-page="timetable"] > .tt-layout { grid-template-columns: minmax(0, 1fr); }
}

/* Payments: ledger toolbar and legend wrap on narrow screens */
.pm-ledger-head, .pm-subtools, .pm-legend { flex-wrap: wrap; row-gap: 10px; }
.pm-ledger-title { min-width: 0; }
@media (max-width: 900px) {
  main.ob-page[data-page="payment"] .pm-ledger-head > .pm-kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 640px) {
  main.ob-page[data-page="payment"] .pm-ledger-head > .pm-kpis { grid-template-columns: minmax(0, 1fr); }
  .pm-filter { flex-wrap: wrap; }
  .pm-search-box { flex: 1 1 100%; }
}
main.ob-page[data-page="payment"] > *, .pm-ledger, .pm-ledger-wrap, .pm-table-wrap { min-width: 0; max-width: 100%; }

/* ---------- 4. Messages ---------- */
/* Narrow screens keep the fixed frame too: list OR conversation fills the
   space under the header, and only the list / message stream scroll. */
@media (max-width: 1000px) {
  html:has(body.ms-body), body.ob-doodle.ms-body { height: 100%; }
  body.ob-doodle.ms-body { height: 100vh; height: 100dvh; min-height: 0; overflow: hidden; }
  .ms-body .ms-page { flex: 1 1 0%; min-height: 0; overflow: hidden; padding: 10px 16px; }
  .ms-body .ms-grid { display: block; height: 100%; }
  .ms-body .ms-side, .ms-body .ms-main { height: 100%; min-height: 0; }
  .ms-body .ms-list, .ms-body .wa-list { flex: 1 1 0%; min-height: 0; max-height: none; overflow-y: auto; }
  .ms-body .ms-msgs { flex: 1 1 0%; min-height: 0; max-height: none; }
}
@media (max-width: 768px) {
  .ms-herobar { padding: 8px 14px; gap: 6px; }
  .ms-body .ms-hero-k { flex-wrap: wrap; row-gap: 4px; }
  .ms-body .ms-h1 { font-size: 20px; line-height: 1.2; }
  /* status chips: one swipeable row instead of three stacked rows */
  .ms-body .ms-metrics { flex-wrap: nowrap; overflow-x: auto; max-width: 100%; scrollbar-width: none; }
  .ms-body .ms-metrics::-webkit-scrollbar { display: none; }
  .ms-body .ms-metrics > * { flex: none; }
  .ms-body .ms-page { padding: 8px 10px; }
}
@media (max-width: 768px) and (max-height: 700px) {
  .ms-body .ms-eyebrow, .ms-body .ms-hero-k { display: none; }
}

/* ---------- 5. Classroom, class payments, students list ---------- */
/* Main always spans the full content width (as a centred flex item it was
   shrinking to its content and leaving wide empty margins on big screens). */
body.ob-doodle > main.layout.wrap:not(.section-page),
body.ob-doodle > main.pay-main,
body.ob-doodle > main.students-page { width: 100%; }
/* Content that does not fit scrolls inside the page area instead of being
   cut off (the Save button and graph card were unreachable on short laptops). */
body.ob-doodle > main.pay-main,
body.ob-doodle > main.students-page { overflow-y: auto; overflow-x: hidden; }
@media (max-width: 980px) {
  body.ob-doodle:has(> main.layout.wrap:not(.section-page)),
  body.ob-doodle:has(> main.pay-main),
  body.ob-doodle:has(> main.students-page) { height: 100vh; height: 100dvh; overflow: hidden; }
  body.ob-doodle > main.layout.wrap:not(.section-page) { height: auto; overflow-y: auto; overflow-x: hidden; align-items: start; }
}
/* class top bar on phones: wrap the action pills instead of overflowing */
@media (max-width: 768px) {
  body.ob-doodle > nav:not(.ob-topbar) .wrap { flex-wrap: wrap; row-gap: 8px; padding-top: 8px; padding-bottom: 8px; }
  body.ob-doodle > nav:not(.ob-topbar) { height: auto; }
  body.ob-doodle > main.pay-main, body.ob-doodle > main.students-page,
  body.ob-doodle > main.layout.wrap:not(.section-page) { padding-left: 14px; padding-right: 14px; }
}
/* the wide month table scrolls sideways inside its card, never past the screen */
.pay-grid { grid-template-columns: minmax(0, 380px) minmax(0, 1fr); }
.pay-grid > * { min-width: 0; }
@media (max-width: 980px) { .pay-grid { grid-template-columns: minmax(0, 1fr); } }
.layout > *, .main-col > * { min-width: 0; }

/* ---------- 6. Student home ---------- */
/* The card was centred in a box as tall as the screen PLUS the page padding,
   so every screen got 48px of stray scroll; on phones the overflow was cut
   off entirely. Now the body is the frame and scrolls only when needed. */
body:has(> .onb) { height: 100vh; height: 100dvh; min-height: 0; overflow-y: auto; }
body > .onb { min-height: 100%; }
@media (max-width: 480px) { body:has(> .onb) { padding: 12px; } }

/* ---------- 7. Big monitors ---------- */
/* Above 1800px the 1600px content cap left wide empty bands; let the
   content grow with the screen (90% of its width). */
@media (min-width: 1800px) {
  .wrap, nav.ob-topbar .topbar-in, nav.ob-topbar .wrap,
  body.ob-doodle > main.ob-page > *, .ob-page .ob-hero.ob-hero-row,
  main.dash.wrap, .db-footer.ob-footer .wrap { max-width: 90vw; }
}
