/* Phone and small-tablet layout for the family and teacher portal.
   Loaded only by the portal base.html (never by the admin), after ui_system.css.
   Tables are marked .pt-stack by base.html's script and become cards on phones. */

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
img, video, iframe { max-width: 100%; }
.pt-tabbar { display: none; }
.menu-user { display: none; padding: 10px 12px 12px; font-weight: 700; color: var(--text-dark, #0f172a); border-bottom: 1px solid var(--border, #e2e8f0); margin-bottom: 4px; }
.menu-user small { font-weight: 500; color: var(--text-light, #64748b); }
.menu-user i { color: var(--primary, var(--p-700, #0f766e)); margin-right: 4px; }

/* ── Tablet and below ─────────────────────────────────────────────── */
@media (max-width: 900px) {
  .navbar { padding: 0 1rem; }
  .navbar-user { max-width: 220px; overflow: hidden; text-overflow: ellipsis; }
  main { padding: 1.25rem 1rem; }
}

/* ── Phones ───────────────────────────────────────────────────────── */
@media (max-width: 640px) {
  body { overflow-x: hidden; }
  main { padding: 1rem 12px calc(1.25rem + env(safe-area-inset-bottom)); }
  .container { padding: 1rem 12px; }

  /* Navbar: brand left, icons right, everything else moves into the menu. */
  .navbar { padding: 0 10px; height: 56px; padding-top: env(safe-area-inset-top); height: calc(56px + env(safe-area-inset-top)); }
  .navbar-content { gap: 6px !important; }
  .navbar-user { display: none; }
  .navbar-brand .brand-product small { display: none; }
  .navbar-brand .brand-logo-img { width: auto; max-width: 96px; }
  .menu-btn { padding: 0; width: 38px; height: 38px; justify-content: center; }
  .menu-btn .menu-btn-label, .menu-btn .fa-chevron-down { display: none; }
  .menu-user { display: block !important; }
  .navbar-menu .dropdown-menu {
    position: fixed; top: calc(60px + env(safe-area-inset-top)); left: 10px; right: 10px;
    min-width: 0; max-height: calc(100vh - 80px); overflow-y: auto;
  }
  .dropdown-menu a { padding: 12px 12px; font-size: 15px; }
  #portal-bell-dropdown {
    position: fixed !important; top: calc(60px + env(safe-area-inset-top)) !important;
    left: 10px !important; right: 10px !important; width: auto !important;
  }
  #portal-toast-container { left: 12px !important; right: 12px !important; max-width: none !important; }

  /* Page titles and heroes. */
  main h1 { font-size: 1.45rem; line-height: 1.25; }
  main h2 { font-size: 1.15rem; }
  .lms-hero, .page-hero { padding: 18px 16px !important; border-radius: 14px; }

  /* Cards: less padding; headers wrap instead of overflowing. */
  .card-header { padding: 12px 14px; flex-wrap: wrap; gap: 8px; }
  .card-body { padding: 14px; }

  /* iOS zooms into any field under 16px; keep fields at 16px and full width in rows. */
  input:not([type=checkbox]):not([type=radio]), select, textarea { font-size: 16px !important; max-width: 100%; }
  .pt-filter-row { flex-wrap: wrap; }
  .pt-filter-row > * { flex: 1 1 100% !important; width: 100%; }

  /* Comfortable tap targets. */
  .btn { min-height: 40px; }
  .btn-sm { min-height: 34px; }

  /* Stat tiles: two per row, compact. */
  .pt-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; gap: 10px !important; margin-bottom: 1.25rem !important; }
  .pt-kpis > .card { padding: 14px 8px !important; }
  .pt-kpis > .card > div:empty { display: none; }
  .pt-kpis > .card > div:nth-last-child(2) { font-size: 1.6rem !important; }
  .pt-kpis > .card > div:last-child { font-size: .8rem !important; }

  /* Side-by-side panels stack. */
  .pt-split { grid-template-columns: 1fr !important; min-height: 0 !important; }
  #course-lessons-modal .pt-split > :first-child { border-right: 0 !important; border-bottom: 1px solid var(--border); max-height: 40vh; }

  /* Tables become one card per row: "Label ........ value". */
  table.pt-stack { min-width: 0 !important; width: 100% !important; border: 0 !important; background: transparent !important; box-shadow: none !important; }
  table.pt-stack thead { display: none !important; }
  table.pt-stack, table.pt-stack tbody, table.pt-stack tr, table.pt-stack td { display: block !important; width: 100% !important; }
  table.pt-stack tr {
    margin: 0 0 10px; border: 1px solid var(--border) !important; border-radius: 12px; overflow: hidden;
    box-shadow: 0 1px 2px rgba(15, 23, 42, .05);
  }
  table.pt-stack td {
    display: block !important; position: relative; max-width: none !important; min-width: 0 !important;
    padding: 9px 12px !important; border: 0 !important; border-bottom: 1px solid rgba(148, 163, 184, .18) !important;
    text-align: right !important; white-space: normal !important; overflow-wrap: anywhere;
  }
  table.pt-stack td::after { content: ""; display: block; clear: both; }
  table.pt-stack td:last-child { border-bottom: 0 !important; }
  table.pt-stack td::before {
    content: attr(data-label); float: left; max-width: 40%; margin: 2px 12px 0 0;
    text-align: left; font-size: 11px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase;
    color: var(--text-light, #64748b);
  }
  table.pt-stack td[data-label=""]::before { display: none; }
  table.pt-stack td .badge, table.pt-stack td .status-badge, table.pt-stack td .status { white-space: nowrap; }
  table.pt-stack td > div, table.pt-stack td .action-buttons, table.pt-stack td form {
    display: flex; flex-wrap: wrap; justify-content: flex-end !important; gap: 6px;
  }
  table.pt-stack tr:hover { transform: none !important; }
  /* The wrapper no longer needs to scroll sideways. */
  .pt-stack-wrap { overflow-x: visible !important; }

  /* Month calendars fit the screen instead of scrolling. */
  table.calendar, table.family-calendar { min-width: 0 !important; width: 100% !important; table-layout: fixed; }
  table.calendar th, table.family-calendar th { padding: 6px 0 !important; font-size: 10px !important; letter-spacing: 0 !important; }
  table.calendar td, table.family-calendar td { padding: 3px 2px !important; height: 64px !important; min-height: 0 !important; vertical-align: top; font-size: 10px; }
  table.calendar .cal-session, table.family-calendar .calendar-session {
    display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    font-size: 9px !important; line-height: 1.3; padding: 1px 3px !important; margin: 2px 0 0 !important; border-radius: 4px;
  }
  table.calendar .cal-session br { display: none; }
  .calendar-wrap { overflow-x: visible !important; }
  #month-grid [style*="repeat(7"] { gap: 3px !important; }
  #month-grid [style*="repeat(7"] > div { padding: 4px 2px !important; font-size: 11px !important; }
  #month-grid .tc-day { min-height: 56px !important; overflow: hidden !important; padding: 3px !important; }
  #month-grid .tc-daynum { font-size: .85rem !important; margin-bottom: 2px !important; }
  #month-grid .tc-empty, #month-grid .tc-chip-name { display: none !important; }
  #month-grid .tc-chip { font-size: 9px !important; padding: 1px 2px !important; margin-bottom: 2px !important; }
  #month-grid h3 { min-width: 0 !important; font-size: 1rem !important; }

  /* Modals use the whole width. */
  [id$="-modal"] > div { max-height: 92vh !important; }
  [id$="-modal"] { padding: 8px !important; }
}

/* Phone bottom tab bar: Home, Classes, Islamic (when the brand enables it), Inbox, Menu. */
@media (max-width: 640px) {
  .pt-tabbar {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 1040; display: flex;
    background: var(--bg-white, #fff); border-top: 1px solid var(--border, #e2e8f0);
    box-shadow: 0 -4px 16px rgba(15, 23, 42, .08); padding-bottom: env(safe-area-inset-bottom);
  }
  .pt-tabbar a, .pt-tabbar button {
    position: relative; flex: 1 1 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
    min-height: 58px; padding: 6px 2px; border: 0; background: none; font: inherit; font-size: 11px; font-weight: 600;
    color: var(--text-light, #64748b); text-decoration: none; cursor: pointer; -webkit-tap-highlight-color: transparent;
  }
  .pt-tabbar i { font-size: 19px; }
  .pt-tabbar [aria-current="page"] { color: var(--primary-dark, var(--p-700, #0f766e)); }
  .pt-tabbar [aria-current="page"]::before {
    content: ""; position: absolute; top: 0; left: 25%; right: 25%; height: 3px; border-radius: 0 0 3px 3px;
    background: var(--primary-dark, var(--p-700, #0f766e));
  }
  .pt-tab-badge {
    position: absolute; top: 5px; left: calc(50% + 6px); min-width: 17px; padding: 0 4px; border-radius: 9px;
    background: #ef4444; color: #fff; font-size: 10px; line-height: 17px;
  }
  body:has(.pt-tabbar) { padding-bottom: calc(60px + env(safe-area-inset-bottom)); }
  .pt-tabbar ~ #pwa-install { bottom: calc(60px + env(safe-area-inset-bottom)); }
}

/* Very narrow phones (iPhone SE 1st gen, small Androids). */
@media (max-width: 360px) {
  .pt-kpis { grid-template-columns: 1fr 1fr !important; }
  table.pt-stack td::before { float: none; display: block; max-width: none; margin: 0 0 2px; }
  table.pt-stack td { text-align: left !important; }
  table.pt-stack td > div, table.pt-stack td .action-buttons, table.pt-stack td form { justify-content: flex-start !important; }
}
