/* Bravelyn Digital Academy - phone fit.
   Loaded LAST so it wins. Goal: on any screen width nothing overlaps, nothing is cut off at the edge and the page never scrolls sideways.
   Text wraps, boxes shrink, rows that do not fit drop to the next line. Wide tables scroll inside their own box only. */

/* ---------- 1. safety net for every portal (Facilitator, Admin, Student) ---------- */
.tp-root :where(h1, h2, h3, h4, h5, p, b, strong, span, small, label, td, th, li, a, button) { overflow-wrap: anywhere; }
.tp-root :where(img, svg, video, canvas, iframe) { max-width: 100%; }
.tp-root :where(input, select, textarea) { max-width: 100%; }
.tp-p-main { overflow-x: hidden; }                      /* nothing may push the page sideways; wide tables get their own scroll box below */
.tp-p-main > section, .tp-p-main > div { max-width: 100%; }
.tp-p-main :where(table) { max-width: none; }
.tp-p-main .tp-card, .tp-p-main .tp-stat { max-width: 100%; }
/* tables sit inside a box that scrolls by itself */
.tp-p-main :where(.tp-table-wrap, .tp-wrap, .anc-wrap, .asg-wrap-t, [class*="table-wrap"]) { max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* ---------- 2. Announcement Management centre (Admin + Facilitator) ---------- */
.anc { max-width: 100%; overflow-x: clip; }
.anc-tabs { grid-template-columns: repeat(auto-fit, minmax(min(210px, 100%), 1fr)); }
.anc-tab > span:last-child { min-width: 0; flex: 1 1 auto; }
.anc-tab b, .anc-tab small, .anc-hero h2, .anc-hero p, .anc-card-h h3, .anc-card-h p, .anc-sec h4, .anc-sch b, .anc-pick b, .anc-pick small { overflow-wrap: anywhere; }
.anc-stats { grid-template-columns: repeat(auto-fit, minmax(min(130px, 100%), 1fr)); }
.anc-stats span, .anc-meters span { overflow-wrap: anywhere; }
.anc-grid { grid-template-columns: repeat(auto-fit, minmax(min(240px, 100%), 1fr)); }
.anc-picklist { grid-template-columns: repeat(auto-fill, minmax(min(240px, 100%), 1fr)); }
.anc-cards { grid-template-columns: repeat(auto-fill, minmax(min(320px, 100%), 1fr)); }
.anc-meters { grid-template-columns: repeat(auto-fit, minmax(min(140px, 100%), 1fr)); }
.anc-switch > span { min-width: 0; }
.anc-picks-h input { max-width: 100%; flex: 1 1 160px; }
.anc-bar input, .anc-bar select { flex: 1 1 min(170px, 100%); min-width: 0; }
.anc-sch-h, .anc-sch-when { flex-wrap: wrap; }
.anc-card-h > * { min-width: 0; }

@media (max-width: 720px) {
  .anc-tabs { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .anc-tab { flex-direction: column; align-items: flex-start; gap: 8px; padding: 10px; }
  .anc-tab b { font-size: 13px; line-height: 1.25; }
  .anc-card { padding: 14px; border-radius: 14px; }
  .anc-hero h2 { font-size: 19px; }
  .anc-stats b { font-size: 22px; }
  .anc-actions { justify-content: stretch; }
  .anc-acts .anc-btn { flex: 1 1 auto; }
}
@media (max-width: 340px) { .anc-tabs { grid-template-columns: minmax(0, 1fr); } .anc-stats { grid-template-columns: minmax(0, 1fr); } }

/* ---------- 3. Facilitator Portal frame ---------- */
@media (max-width: 640px) {
  .tp-p-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; padding: 10px 12px; padding-top: max(10px, env(safe-area-inset-top)); }
  .tp-p-head > img { order: 1; flex: 0 0 auto; width: 38px; height: 38px; }
  .tp-p-head > div { order: 2; flex: 1 1 0; min-width: 0; }
  .tp-p-head > .tp-x { order: 3; margin-left: auto; }
  .tp-p-head > .tp-spacer { order: 4; flex: 0 0 100%; height: 0; }          /* starts a new line for the buttons */
  .tp-p-head > #tpMyStatus, .tp-p-head > .tp-btn { order: 5; }
  .tp-p-head h1 { font-size: 16px; }
  .tp-p-head p { overflow-wrap: anywhere; }
  .tp-p-head .tp-btn { padding: 8px 12px; }
  .tp-p-main { padding: 12px; padding-bottom: 88px; }
  .tp-page-h { font-size: 19px; }
  .tp-card { padding: 14px; border-radius: 14px; }
  .tp-card-h > * { min-width: 0; }
  .tp-stats { grid-template-columns: repeat(auto-fit, minmax(min(130px, 100%), 1fr)); }
  .tp-row { min-width: 0; }
  .tp-btn { white-space: normal; text-align: center; }
  .tp-sess { flex-wrap: wrap; }
  .tp-sess .tp-grow { flex: 1 1 140px; }
  .tp-drawer { padding: 14px; }
}
@media (max-width: 400px) { .tp-p-head .tp-btn { flex: 1 1 auto; } }

/* ---------- 4. other portal modules that use their own tab grids ---------- */
.asg-tabs { grid-template-columns: repeat(auto-fit, minmax(min(210px, 100%), 1fr)); }
@media (max-width: 720px) { .asg-tabs { grid-template-columns: repeat(2, minmax(0, 1fr)); } .asg-tab { min-width: 0; } .asg-tab b, .asg-tab small { overflow-wrap: anywhere; } }
@media (max-width: 340px) { .asg-tabs { grid-template-columns: minmax(0, 1fr); } }

/* ---------- 5. form controls that have a fixed natural width (file pickers, date/time boxes) ---------- */
.tp-root input[type="file"], .anc input[type="file"] { width: 100%; max-width: 100%; }
.tp-root :where(input[type="date"], input[type="time"], input[type="datetime-local"], input[type="month"]) { min-width: 0; max-width: 100%; }
.tp-row > div, .tp-field > div { min-width: 0; max-width: 100%; }

/* ---------- 6. announcement list on a phone: one card per announcement instead of a sideways-scrolling table ---------- */
@media (max-width: 720px) {
  .anc-wrap { overflow-x: visible; border: 0; border-radius: 0; }
  .anc-table.anc-fluid { min-width: 0; table-layout: auto; }
  .anc-wrap:has(.anc-fluid) { overflow-x: auto; border: 1px solid var(--line); border-radius: 14px; }
  .anc-table.anc-fluid th, .anc-table.anc-fluid td { padding: 9px 10px; }
  .anc-table.anc-stack { min-width: 0; display: block; }
  .anc-table.anc-stack thead { display: none; }
  .anc-table.anc-stack tbody { display: grid; gap: 12px; }
  .anc-table.anc-stack tr { display: grid; gap: 8px; background: var(--n2); border: 1px solid var(--line); border-left: 4px solid var(--gold); border-radius: 14px; padding: 12px; min-width: 0; }
  .anc-table.anc-stack td { display: block; border: 0; padding: 0; min-width: 0; }
  .anc-table.anc-stack td[data-l] { display: grid; grid-template-columns: 88px minmax(0, 1fr); gap: 8px; align-items: start; }
  .anc-table.anc-stack td[data-l]::before { content: attr(data-l); color: var(--mut); font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .05em; padding-top: 2px; }
  .anc-table.anc-stack td.anc-acts { display: flex; flex-wrap: wrap; gap: 6px; border-top: 1px solid var(--line); padding-top: 10px; margin-top: 2px; }
  .anc-table.anc-stack td.anc-acts .anc-btn { flex: 1 1 auto; text-align: center; }
  .anc-chip { margin: 2px 4px 2px 0; }
}
@media (max-width: 720px) { .anc-table.anc-stack td[data-l] > .anc-b { justify-self: start; } }

/* ---------- 7. public page: floating badge must stay inside the screen ---------- */
@media (max-width: 640px) { .absolute.-top-4.-right-4 { right: .75rem; max-width: calc(100% - 1.5rem); text-align: center; } }

/* ---------- 8. Programme Calendar toolbar (Admin / Facilitator): buttons wrap instead of running off the screen ---------- */
.ac-mgmt { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; max-width: 100%; }
.ac-mgmt > b { min-width: 0; overflow-wrap: anywhere; flex: 1 1 200px; }
.ac-mgmt > .ac-btn { flex: 0 1 auto; }
@media (max-width: 480px) { .ac-mgmt > .ac-btn { flex: 1 1 auto; } }
.ac-bar, .ac-nav, .ac-seg { max-width: 100%; }
