/* =====================================================================
   mobile-app.css — Manadhone phone shell (v2)

   Below 992px the site behaves like a native app: compact top chrome, a
   fixed bottom tab bar (Home · News · FM · Jobs · Menu), an account block
   pinned to the top of the drawer, and dashboards that stack instead of
   scrolling sideways. Desktop (>=992px) is deliberately untouched.
   ===================================================================== */

/* Phone-only pieces stay out of the desktop layout entirely. */
.app-nav { display: none; }
.sb-me   { display: none; }

@media (max-width: 991.98px) {

  :root { --topbar-h: 56px; --appnav-h: 58px; --sb-w: min(87vw, 306px); }

  html { -webkit-text-size-adjust: 100%; }
  /* `clip` (not `hidden`) kills stray sideways scroll without turning the page
     into a scroll container, which would break the sticky top bar. A page that
     can pan sideways is what used to drag the fixed tab bar off screen. */
  html, body { overflow-x: clip; max-width: 100%; }
  body { overscroll-behavior-y: contain; }

  /* Room for the fixed bar, including the iOS home indicator. */
  body.has-appnav { padding-bottom: calc(var(--appnav-h) + env(safe-area-inset-bottom, 0px) + 4px); }

  /* ---------------- bottom tab bar ---------------- */
  .app-nav {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 1046;
    width: 100%; max-width: 100%;
    height: calc(var(--appnav-h) + env(safe-area-inset-bottom, 0px));
    padding-bottom: env(safe-area-inset-bottom, 0px);
    background: color-mix(in srgb, var(--bs-body-bg) 88%, transparent);
    -webkit-backdrop-filter: blur(18px) saturate(150%);
    backdrop-filter: blur(18px) saturate(150%);
    border-top: 1px solid var(--glass-border);
    box-shadow: 0 -12px 32px -20px rgba(0, 0, 0, .8);
  }
  .app-nav-item {
    position: relative; appearance: none; border: 0; background: none; cursor: pointer;
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .16rem;
    color: var(--ink-soft); text-decoration: none;
    font-family: inherit; font-size: .655rem; font-weight: 600; line-height: 1;
    transition: color .2s cubic-bezier(.22, 1, .36, 1), transform .18s cubic-bezier(.22, 1, .36, 1);
  }
  .app-nav-item i { font-size: 1.26rem; line-height: 1; }
  .app-nav-item:active { transform: scale(.9); }
  .app-nav-item.is-on { color: var(--page-accent, var(--md-accent)); }
  .app-nav-item.is-on::before {
    content: ""; position: absolute; top: 0; left: 50%; transform: translateX(-50%);
    width: 24px; height: 2px; border-radius: 0 0 3px 3px;
    background: var(--page-accent, var(--md-accent));
  }

  /* ---------------- top chrome ---------------- */
  .app-topbar .container-fluid { padding-top: .3rem; padding-bottom: .3rem; }
  .app-topbar .navbar-brand { font-size: 1.06rem; }
  .app-topbar .btn-icon { width: 38px; height: 38px; display: grid; place-items: center; padding: 0; }
  .sidebar-toggle { font-size: 1.35rem; }
  /* Signed in, the account menu lives at the top of the drawer instead. */
  .topbar-account { display: none; }

  /* ---------------- drawer: every module reachable ---------------- */
  /* The drawer is a full-height sheet and the list inside it scrolls, with room
     at the foot so the tab bar never sits on top of the last few modules. */
  .app-sidebar {
    top: var(--topbar-h); bottom: 0;
    border-radius: 0 20px 20px 0;
    background: color-mix(in srgb, var(--bs-body-bg) 92%, transparent);
  }
  .sb-scroll {
    flex: 1 1 auto; min-height: 0;
    overflow-y: auto; -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    padding: .5rem .55rem calc(var(--appnav-h) + env(safe-area-inset-bottom, 0px) + 1.5rem);
    scrollbar-width: thin;
  }
  .sb-link { padding: .58rem .7rem; font-size: .92rem; }
  .sb-sub { max-height: none; }
  .sb-sublink { padding-top: .46rem; padding-bottom: .46rem; }
  /* dvh where it exists: a collapsing browser toolbar then can't hide the last
     few links. Older browsers keep the bottom:0 box above. */
  @supports (height: 100dvh) {
    .app-sidebar { bottom: auto; height: calc(100dvh - var(--topbar-h)); }
  }
  /* Soft fade at the foot of the list: a visible hint that it keeps going. */
  .app-sidebar::after {
    content: ""; position: absolute; left: 0; right: 0; pointer-events: none;
    bottom: calc(var(--appnav-h) + env(safe-area-inset-bottom, 0px));
    height: 44px; background: linear-gradient(to top, var(--bs-body-bg), transparent);
    opacity: .9;
  }

  /* ---------------- drawer: account block ---------------- */
  /* First thing in the drawer. It lives inside the scroller on purpose: when the
     account menu expands it pushes the module list down instead of squashing it. */
  .sb-me {
    display: block;
    margin: -.5rem -.55rem .45rem; padding: .55rem .6rem .5rem;
    border-bottom: 1px solid var(--glass-border);
  }
  .sb-me-btn {
    display: flex; align-items: center; gap: .65rem; width: 100%;
    padding: .5rem .55rem; border-radius: 14px; cursor: pointer; text-align: left;
    border: 1px solid var(--glass-border); background: var(--glass-hi);
    color: var(--bs-emphasis-color); text-decoration: none;
    transition: border-color .18s var(--ease), background .18s var(--ease);
  }
  .sb-me-btn:active { transform: scale(.985); }
  .sb-me-btn[aria-expanded="true"] { border-color: color-mix(in srgb, var(--page-accent, var(--md-accent)) 45%, transparent); }
  .sb-me-btn[aria-expanded="true"] .sb-caret { transform: rotate(180deg); }
  .sb-me-av {
    flex: 0 0 auto; width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center;
    font-family: "Bricolage Grotesque", sans-serif; font-weight: 700; font-size: 1.08rem;
    color: var(--page-accent-ink, #06121a);
    background: linear-gradient(135deg, var(--page-accent, var(--md-accent)), var(--page-accent-2, var(--md-accent-2)));
  }
  .sb-me-id { min-width: 0; flex: 1; display: flex; flex-direction: column; gap: .1rem; }
  .sb-me-name { font-weight: 700; font-size: .95rem; line-height: 1.2; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .sb-me-sub { font-size: .7rem; color: var(--ink-soft); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .sb-me .sb-caret { flex: 0 0 auto; color: var(--ink-soft); font-size: .8rem; transition: transform .2s var(--ease); }
  .sb-me-menu { padding: .35rem .1rem .1rem; }
  .sb-me-link {
    display: flex; align-items: center; gap: .65rem; padding: .5rem .6rem; border-radius: 10px;
    color: var(--bs-body-color); text-decoration: none; font-size: .87rem; font-weight: 500;
  }
  .sb-me-link > i { width: 1.2rem; text-align: center; font-size: 1rem; color: var(--ink-soft); }
  .sb-me-link:active { background: var(--glass-hi); }
  .sb-me-link.danger, .sb-me-link.danger > i { color: #ff6b7a; }

  /* ---------------- content rhythm ---------------- */
  .app-main { padding-top: .9rem; padding-bottom: 1.1rem; }
  .app-content .container { padding-left: 14px; padding-right: 14px; }
  /* Button rows next to a heading used to run off the edge and make the whole
     page pannable. They wrap now. */
  .section-head { flex-wrap: wrap; align-items: flex-start; gap: .7rem; }
  .section-head > .d-flex { flex-wrap: wrap; }
  .glass-panel.p-4 { padding: 1rem !important; }
  /* 16px inputs: anything smaller makes iOS zoom in on focus and knocks the
     layout sideways. */
  .form-control, .form-select, .search-input { font-size: 16px; }
  .table-responsive { -webkit-overflow-scrolling: touch; }

  /* Floating buttons sit above the tab bar, never behind it. */
  body.has-appnav .fm-fab { bottom: calc(var(--appnav-h) + env(safe-area-inset-bottom, 0px) + 72px); }
  body.has-appnav .wa-fab { bottom: calc(var(--appnav-h) + env(safe-area-inset-bottom, 0px) + 14px); }
  body.has-appnav .soc-fabs { bottom: calc(var(--appnav-h) + env(safe-area-inset-bottom, 0px) + 18px); }

  /* ---------------- footer becomes a closing sheet ---------------- */
  .app-content .site-footer {
    margin-top: 2.2rem;
    border-radius: 22px 22px 0 0;
    padding-top: 1.4rem;
    border-top: 1px solid var(--glass-border);
  }
  .site-footer .footer-links { font-size: .84rem; }
  .site-footer .footer-links li { margin-bottom: .18rem; }
  .site-footer .footer-h { font-size: .78rem; letter-spacing: .1em; text-transform: uppercase; }
}

/* =====================================================================
   Dashboard tables -> stacked rows (.tbl-stack)
   A six-column admin table can't shrink to 360px, and forcing it made the
   page pan sideways. Each row becomes a small record instead, labelled from
   the table head via data-label.
   ===================================================================== */
@media (max-width: 767.98px) {
  .table-responsive.tbl-stack-wrap { overflow: visible; }
  .tbl-stack, .tbl-stack tbody, .tbl-stack tr, .tbl-stack td { display: block; width: 100%; }
  .tbl-stack thead { display: none; }
  .tbl-stack tbody tr {
    padding: .8rem .85rem; border-bottom: 1px solid var(--glass-border); background: none !important;
  }
  .tbl-stack tbody tr:last-child { border-bottom: 0; }
  .tbl-stack td {
    display: flex; align-items: flex-start; justify-content: space-between; gap: .8rem;
    padding: .22rem 0; border: 0; text-align: left !important; white-space: normal;
  }
  .tbl-stack td::before {
    content: attr(data-label); flex: 0 0 8.5rem;
    font-size: .66rem; font-weight: 600; letter-spacing: .09em; text-transform: uppercase;
    color: var(--ink-soft); padding-top: .16rem;
  }
  .tbl-stack td.tbl-main { display: block; padding: 0 0 .5rem; }
  .tbl-stack td.tbl-main::before { display: none; }
  .tbl-stack td.tbl-main .fw-semibold { font-size: 1rem; }
  .tbl-stack td.tbl-actions { padding-top: .6rem; }
  .tbl-stack td.tbl-actions::before { display: none; }
  .tbl-stack td.tbl-actions > div { display: flex !important; gap: .4rem; flex-wrap: wrap; }
  .tbl-stack td.tbl-actions .btn-icon { width: 40px; height: 40px; display: grid; place-items: center; }
  .tbl-stack .text-truncate { white-space: normal; overflow: visible; }
}

/* Installed to the home screen: pad for the status bar. */
@media (display-mode: standalone) {
  .app-topbar { padding-top: env(safe-area-inset-top, 0px); }
  .app-sidebar { top: calc(var(--topbar-h) + env(safe-area-inset-top, 0px)); }
  a, button { -webkit-touch-callout: none; }
}

@media (prefers-reduced-motion: reduce) {
  .app-nav-item, .sb-me-btn { transition: none; }
  .app-nav-item:active, .sb-me-btn:active { transform: none; }
}
