/* ==========================================================
   mobile.css  —  Mobile & Tablet overrides only
   Scope : max-width 991.98px  (Bootstrap lg breakpoint)
   Rule  : Desktop ≥992px is NEVER touched here
   ========================================================== */

/* ── Safe-area / iOS notch ─────────────────────────────── */
#bnav {
  padding-bottom: max(env(safe-area-inset-bottom, 0px), 6px);
}

/* ── Scrollable filter-tab rows ────────────────────────── */
.ftab-row {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  flex-wrap: nowrap;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.ftab-row::-webkit-scrollbar { display: none; }

/* ── Responsive stat-grid  (2 cols on phone, 4 on sm+) ── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}
@media (min-width: 576px) {
  .stat-grid { grid-template-columns: repeat(4, 1fr); }
}

/* ── Table scroll wrapper ──────────────────────────────── */
.lt-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* ── Touch-friendly action buttons in list tables ──────── */
.lt-action-btn {
  min-width: 44px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  font-size: 16px;
  flex-shrink: 0;
}

/* ================================================================
   MOBILE + TABLET  (≤ 991px)
   ================================================================ */
@media (max-width: 991.98px) {

  /* ── Content area bottom padding clears the fixed bottom nav ── */
  #content {
    padding-bottom: calc(72px + env(safe-area-inset-bottom, 0px)) !important;
  }

  /* ── Prevent iOS input zoom (inputs must be ≥16px) ─────────── */
  .fld input,
  .fld select,
  input[type="text"],
  input[type="password"],
  input[type="date"],
  input[type="month"],
  input[type="number"],
  select {
    font-size: 16px !important;
  }

  /* ── Filter tabs ─────────────────────────────────────────────── */
  .ftab {
    padding: 10px 16px;
    font-size: 13px;
    min-height: 44px;
    white-space: nowrap;
    flex-shrink: 0;
  }

  /* ── Timetable table ─────────────────────────────────────────── */
  .tt-wrap {
    -webkit-overflow-scrolling: touch;
    border-radius: 10px;
  }
  .tt-tbl { min-width: 480px; }
  .ttc     { min-height: 54px !important; }
  .tte     { min-height: 54px !important; font-size: 22px !important; }

  /* ── List tables ─────────────────────────────────────────────── */
  .lt { min-width: 460px; }

  /* ── Card spacing ────────────────────────────────────────────── */
  .card { padding: 12px; }

  /* ── Sheet (bottom drawer) content padding ───────────────────── */
  .scnt { padding: 14px 16px calc(28px + env(safe-area-inset-bottom, 0px)); }

  /* ── Form field button rows ──────────────────────────────────── */
  .actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
  }
  .actions button { flex: 1; min-height: 44px; }

  /* ── Generic buttons — minimum touch target ──────────────────── */
  .btn { min-height: 44px; }
  .bsm { min-height: 40px; }

  /* ── Leave-type grid on small screens ───────────────────────── */
  #s-tgrid {
    grid-template-columns: 1fr 1fr !important;
    gap: 8px;
  }
  .ltyp {
    min-height: 52px !important;
    font-size: 12px !important;
    padding: 8px 4px !important;
  }

  /* ── Dialog — slide up from bottom on phone ─────────────────── */
  .dov {
    padding: 0 !important;
    align-items: flex-end !important;
  }
  .dc {
    width: 100% !important;
    max-width: 100% !important;
    border-radius: 20px 20px 0 0 !important;
    max-height: 92vh !important;
  }

  /* ── Manage modal-box (legacy pages) ─────────────────────────── */
  .modal-box {
    width: min(340px, 92vw) !important;
  }

  /* ── Report stat grid — 2 cols on phone ──────────────────────── */
  #rc2 .kpi-inline {
    grid-template-columns: repeat(2, 1fr) !important;
  }

  /* ── Topbar — don't wrap, hide secondary badges on xs ───────── */
  #topbar { flex-wrap: nowrap; min-height: 54px; }
}

/* ================================================================
   PHONE ONLY  (≤ 575px)
   ================================================================ */
@media (max-width: 575.98px) {
  /* Hide workload column in teacher table to save space */
  .lt-hide-xs { display: none !important; }

  /* Topbar role badge — hide on very narrow phones */
  .role-badge { display: none !important; }

  /* Timetable cells a little taller for easier tap */
  .ttc { min-height: 60px !important; }
  .tte { min-height: 60px !important; }
}

/* ================================================================
   TABLET  (768px – 991px)
   ================================================================ */
@media (min-width: 768px) and (max-width: 991.98px) {
  #content { padding: 18px 20px calc(72px + env(safe-area-inset-bottom, 0px)) !important; }

  .tt-tbl  { min-width: 560px; }
  .ttc     { min-height: 68px !important; }
  .tte     { min-height: 68px !important; }

  .lt th, .lt td { padding: 12px 14px; }

  .ftab { font-size: 14px; padding: 10px 18px; }

  /* Wider dialog on tablet */
  .dov  { align-items: center !important; padding: 16px !important; }
  .dc   {
    width: auto !important;
    max-width: 480px !important;
    border-radius: 16px !important;
    max-height: 88vh !important;
  }
}

/* ================================================================
   TIMETABLE CARD LAYOUT  (mobile ≤ 991.98px only)
   ================================================================ */

/* Desktop: hide all card-view elements */
@media (min-width: 992px) {
  .m-day-grp,
  .m-view-toggle,
  .m-card-view,
  .m-view-toggle-wrap { display: none !important; }
}

/* Mobile: show toggle button + card layout */
@media (max-width: 991.98px) {
  .tt-wrap.m-hidden { display: none !important; }

  .m-view-toggle {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: 99px;
    border: 1.5px solid #1d4ed8;
    background: #fff;
    color: #1d4ed8;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    min-height: 40px;
    margin-bottom: 10px;
  }

  .m-day-grp { margin-bottom: 10px; }

  .m-day-hdr {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    background: #1e3a8a;
    color: #fff;
    border-radius: 10px 10px 0 0;
    font-weight: 800;
    font-size: 14px;
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
  }
  .m-day-hdr.today-hdr { background: #1d4ed8; }

  .m-today-badge {
    font-size: 10px;
    background: #fbbf24;
    color: #1a1a1a;
    border-radius: 99px;
    padding: 2px 8px;
    font-weight: 800;
  }

  .m-arrow {
    margin-left: auto;
    font-size: 11px;
    transition: transform .2s;
    opacity: .7;
  }
  .m-day-grp.m-closed .m-arrow { transform: rotate(-90deg); }
  .m-day-grp.m-closed .m-per-list { display: none; }

  .m-per-list {
    border: 1px solid #e5e7eb;
    border-top: none;
    border-radius: 0 0 10px 10px;
    overflow: hidden;
  }

  .m-per-card {
    display: flex;
    align-items: stretch;
    background: #fff;
    border-bottom: 1px solid #f3f4f6;
    min-height: 70px;
  }
  .m-per-card:last-child { border-bottom: none; }

  .m-per-strip {
    width: 5px;
    flex-shrink: 0;
    background: #e5e7eb;
  }

  .m-per-num {
    width: 42px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 6px 2px;
    background: #f8fafc;
    border-right: 1px solid #f3f4f6;
  }
  .m-per-num .m-pn {
    font-size: 17px;
    font-weight: 900;
    color: #1e3a8a;
    line-height: 1;
  }
  .m-per-num .m-pt {
    font-size: 7px;
    color: #9ca3af;
    text-align: center;
    margin-top: 3px;
    line-height: 1.3;
  }

  .m-per-body {
    flex: 1;
    padding: 8px 10px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 2px;
    min-width: 0;
  }
  .m-per-body .m-subj {
    font-weight: 800;
    font-size: 14px;
    color: #1e293b;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .m-per-body .m-tchr {
    font-size: 12px;
    color: #4b5563;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .m-per-body .m-room {
    font-size: 11px;
    color: #6b7280;
  }

  .m-per-act {
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 6px 8px;
    gap: 4px;
    flex-shrink: 0;
  }
  .m-per-act button {
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    font-size: 15px;
  }

  .m-empty { background: #fafafa; }
  .m-empty .m-per-body .m-subj {
    color: #d1d5db;
    font-weight: 400;
    font-size: 12px;
    font-style: italic;
  }

  .m-locked { opacity: .9; }
  .m-locked .m-per-num { background: rgba(0,0,0,.1); border-right-color: rgba(255,255,255,.2); }
  .m-locked .m-per-num .m-pn { color: rgba(255,255,255,.85); }
  .m-locked .m-per-body .m-subj { color: #fff; font-size: 12px; }

  .m-lunch {
    background: #fef9c3;
    border-bottom: 1px solid #fde68a;
    min-height: 50px;
  }
  .m-lunch .m-per-num { background: #fef3c7; border-right-color: #fde68a; }
  .m-lunch .m-per-num .m-pn { color: #92400e; font-size: 20px; }
  .m-lunch .m-per-body .m-subj { color: #92400e; font-size: 12px; font-style: normal; font-weight: 700; }
  .m-lunch .m-per-body .m-room { color: #a16207; }

  .m-add-btn {
    width: 100%;
    padding: 11px;
    background: #f0f9ff;
    border: 1.5px dashed #93c5fd;
    border-top: none;
    border-radius: 0 0 10px 10px;
    color: #1d4ed8;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    text-align: center;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
  }
}

/* ================================================================
   TIMETABLE PAGE — TABLE / CARD TOGGLE HELPERS
   ================================================================ */
@media (max-width: 991.98px) {
  /* hide table wrapper when card view is active */
  .tbl-wrap.m-hidden    { display: none !important; }
  /* hide card wrapper when table view is active  */
  .m-card-view.m-hidden { display: none !important; }

  /* special-room tag inside card body */
  .m-sroom {
    font-size: 10px;
    color: #0e7490;
    font-weight: 600;
    margin-top: 1px;
  }
}
