/* PHASE 4K-6V5U6H8R2.1C — Professional Mobile App Shell
   Presentation only. No data, navigation, or business authority lives here. */
:root {
  --ui-space-1: 4px;
  --ui-space-2: 8px;
  --ui-space-3: 12px;
  --ui-space-4: 16px;
  --ui-space-5: 20px;
  --ui-radius-sm: 10px;
  --ui-radius-md: 14px;
  --ui-radius-lg: 20px;
  --ui-touch-min: 44px;
  --ui-font-xs: 0.75rem;
  --ui-font-sm: 0.875rem;
  --ui-font-md: 1rem;
  --ui-font-lg: 1.125rem;
  --ui-font-xl: 1.35rem;
  --ui-shadow-sm: 0 2px 10px rgba(15, 23, 42, 0.08);
  --ui-shadow-md: 0 12px 30px rgba(15, 23, 42, 0.16);
  --ui-bottom-nav-height: 66px;
  --ui-appbar-height: 58px;
  --ui-z-sticky: 40;
  --ui-z-appbar: 60;
  --ui-z-bottom-nav: 80;
  --ui-z-sheet: 140;
  --ui-z-modal: 200;
  --ui-z-toast: 260;
}

.ui-visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.ui-bottom-nav { display: none; }
#tuitionPrimaryActions { display: none; }
#debtPrimaryActions { display: none; }
body:has(#tab_tx.active):not(:has(#superAdminView[style*="display: block"])):not(:has(#clubAccessBlockBanner)) #tuitionPrimaryActions { display: flex; }
body:has(#tab_debt.active):not(:has(#superAdminView[style*="display: block"])):not(:has(#clubAccessBlockBanner)) #debtPrimaryActions { display: block; }
.ui-filter-sheet-head { display: none; }
.ui-filter-toggle { display: none; }
.ui-more-title { font-size: 0.78rem; font-weight: 800; color: #94a3b8; text-transform: uppercase; letter-spacing: 0.07em; }
.ui-more-section { margin-bottom: var(--ui-space-3); }
.ui-more-section-label { font-size: var(--ui-font-xs); font-weight: 800; color: #64748b; text-transform: uppercase; letter-spacing: 0.06em; margin: 2px 2px 8px; }
.ui-more-utility-label { margin-top: 14px; }
.ui-more-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.ui-more-module { min-height: 52px; border: 1px solid #e2e8f0; border-radius: var(--ui-radius-md); background: #f8fafc; color: #334155; font-weight: 800; font-size: var(--ui-font-sm); display: flex; align-items: center; gap: 8px; padding: 10px 12px; cursor: pointer; }
.ui-more-module > span:first-child { font-size: 1.05rem; }
.ui-icon-button { min-width: var(--ui-touch-min); min-height: var(--ui-touch-min); display: inline-flex; align-items: center; justify-content: center; }
.ui-context-search { min-width: 0; }
.ui-search-icon { position: absolute; left: 12px; top: 0; bottom: 0; margin-block: auto; display: grid; place-items: center; width: 20px; height: 20px; line-height: 20px; font-size: 1rem; pointer-events: none; z-index: 1; }
.ui-search-input { box-sizing: border-box; line-height: 1.25; }
.ui-shell-overlay { align-items: center; justify-content: center; padding: 20px; }

/* C1E1: preserve the legacy transaction form lifecycle but remove its visual shell while every direct canonical control is hidden. */
#transactionForm[data-ui-empty-shell="collapse"]:not(:has(> :not([hidden]):not(.hidden):not([style*="display:none"]):not([style*="display: none"]))) {
  display: none;
}
.ui-more-close { background: #f1f5f9; border: 0; border-radius: 50%; color: #64748b; cursor: pointer; }

/* Desktop/tablet keeps the existing presentation and controls. */
@media (min-width: 768px) {
  .ui-context-bar { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; background: #f8fafc; padding: 16px; border-radius: 12px; border: 1px solid #f1f5f9; margin-bottom: 24px; }
  .ui-context-search { grid-column: 3; position: relative; display: flex; align-items: center; }
  .ui-search-icon { color: #64748b; }
  .ui-search-input { padding-left: 40px; }
  .ui-filter-controls { grid-column: 1 / 3; grid-row: 1; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
  .ui-filter-field label { display: block; font-size: 0.7rem; font-weight: 800; color: #64748b; margin-bottom: 4px; text-transform: uppercase; }
  .ui-filter-done { display: none; }
  .ui-filter-note { grid-column: 1 / -1; margin: 0; color: #94a3b8; font-size: 0.72rem; font-style: italic; }
}

@media (max-width: 767px) {
  body.ui-mobile-shell { font-size: 14px; padding-bottom: calc(var(--ui-bottom-nav-height) + env(safe-area-inset-bottom) + var(--ui-space-4)); }
  #mainApp.app-container { padding: 0 12px 12px; min-height: 100dvh; }

  /* SHELL — compact app bar; dashboard KPIs remain inside Dashboard instead of the chrome. */
  .mobile-header-bar { position: sticky; top: 0; z-index: var(--ui-z-appbar); min-height: var(--ui-appbar-height); margin: 0 -12px 10px; padding: calc(8px + env(safe-area-inset-top)) 12px 8px; border-radius: 0 0 16px 16px; }
  .mobile-header-bar .mhb-title-row { min-height: 44px; margin-bottom: 0; }
  .mobile-header-bar .mhb-title { font-size: 0.95rem; max-width: calc(100vw - 92px); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .mobile-header-bar .mhb-subtitle { display: none; }
  .mobile-header-bar .mhb-stats { display: none; }
  .mobile-header-bar .club-logo-img { width: 48px; height: 40px; border-radius: 9px; }
  /* C1E1: Bottom Nav `Khác` is the sole mobile trigger for the canonical More sheet. */
  .mobile-header-bar .mhb-title-row > .mhb-menu-btn { display: none; }

  /* Existing nine-tab strip remains in DOM for desktop/rollback, hidden only on mobile. */
  #mainTabsWrapper { display: none; }

  /* CONTEXT / SEARCH. Existing controls and IDs are physically reused; only presentation changes. */
  #filterArea.ui-context-bar { display: grid; grid-template-columns: minmax(0, 1fr) !important; align-items: start; gap: 8px; position: relative; margin: 0 0 12px; padding: 0; background: transparent; border: 0; }
  .ui-context-search { grid-column: 1 / -1; grid-row: 2; display: block; min-width: 0; position: relative; }
  .ui-search-icon { color: #64748b; }
  .ui-search-input { min-height: var(--ui-touch-min); padding: 10px 12px 10px 40px; border-radius: 14px; background: #fff; box-shadow: var(--ui-shadow-sm); border: 1px solid #dbe3ef; font-size: 16px; }
  .ui-filter-toggle { display: none; }
  /* D1: let available width and text size decide when the two controls fit.
     14rem preserves room for the native month editor and select arrow. */
  .ui-filter-controls, #filterArea.mobile-filter-open .ui-filter-controls { grid-column: 1 / -1; grid-row: 1; display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 14rem), 1fr)); align-items: start; gap: 8px; min-width: 0; max-width: 100%; }
  #filterArea.mobile-filter-open::before { content: none; }
  .ui-filter-controls .input-branch { grid-column: auto; grid-row: auto; min-width: 0; align-self: start; }
  .ui-filter-controls .input-branch label { display: block; }
  .ui-filter-controls .input-branch #filterBranch { min-width: 0; height: auto; min-height: var(--ui-touch-min); padding: 8px 30px 8px 10px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; box-shadow: var(--ui-shadow-sm); border-radius: 14px; }
  .ui-filter-controls > .ui-filter-field:not(.input-branch) { grid-column: auto; grid-row: auto; min-width: 0; }
  /* A9R14: presentation only; the existing inputs, IDs and events stay in place. */
  #filterArea .ui-filter-field > label { font-size: 0.75rem; font-weight: 700; line-height: 1.35; }
  #filterArea #filterMonth, #filterArea #filterBranch, #filterArea #searchInput { font-size: 16px !important; line-height: 1.25; min-height: var(--ui-touch-min); }
  #filterArea #searchInput::placeholder { font-size: 0.875rem; }
  .ui-filter-sheet-head, .ui-filter-done { display: none; }
  .ui-filter-field label { display: block; margin-bottom: 5px; color: #475569; font-size: 0.78rem; font-weight: 800; }
  .ui-filter-control { min-height: 46px; font-size: 16px; }
  .ui-filter-note { display: none; }

  /* TUITION PRIORITY ACTIONS — requested order: actions first, search/filter immediately below. */
  #tuitionPrimaryActions.ui-tuition-payment-panel { margin: 0 0 8px; padding: 8px 10px; gap: 6px; background: #fff; border: 1px solid #e2e8f0; border-radius: var(--ui-radius-md); box-shadow: var(--ui-shadow-sm); }
  #tuitionPrimaryActions.ui-tuition-payment-panel h4 { margin: 0; font-size: 0.94rem; line-height: 1.25; }
  #tuitionPrimaryActions.ui-tuition-payment-panel > div { width: 100%; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
  #tuitionPrimaryActions.ui-tuition-payment-panel button { width: auto; min-width: 0; min-height: var(--ui-touch-min); padding: 7px 6px; white-space: normal; line-height: 1.15; font-size: 0.72rem; }
  #debtPrimaryActions { margin: 0 0 10px; }
  #debtPrimaryActions .ui-debt-priority-header { margin-bottom: 8px; }
  #debtPrimaryActions .ui-debt-priority-header > div { width: 100%; display: flex; gap: 6px; flex-wrap: wrap; }
  #debtPrimaryActions .ui-debt-priority-header button { min-height: var(--ui-touch-min); flex: 1 1 145px; }
  #debtPrimaryActions .ui-debt-summary { padding: 8px 10px; gap: 8px; margin-bottom: 10px; }
  #debtPrimaryActions .ui-debt-summary .block { font-size: 0.95rem; }
  body:has(#clubAccessBlockBanner) #tuitionPrimaryActions,
  body:has(#superAdminView[style*="display: block"]) #tuitionPrimaryActions { display: none; }

  /* CONTENT — readable cards and touch targets without changing renderer actions. */
  .tab-content { padding-bottom: 8px; }
  .tab-content h4, .tab-content h3, .tab-content h2 { line-height: 1.3; }
  .name-link { font-size: 1rem; line-height: 1.35; }
  .btn-sm, .tab-content button, .action-btns button { min-height: var(--ui-touch-min); }
  .btn-sm { font-size: 0.78rem; padding: 9px 10px; border-radius: 10px; }
  #tbl_active tbody tr, #tbl_debt tbody tr, #tbl_quit tbody tr, #tbl_tx tbody tr, #tbl_exam tbody tr { border-radius: 14px; box-shadow: var(--ui-shadow-sm); }
  #tbl_active tbody td, #tbl_debt tbody td, #tbl_quit tbody td, #tbl_tx tbody td, #tbl_exam tbody td { line-height: 1.4; }
  #tab_active .text-\[0\.6rem\], #tab_debt .text-\[0\.6rem\], #tab_tx .text-\[0\.6rem\], #tab_quit .text-\[0\.6rem\] { font-size: var(--ui-font-xs); }
  #tab_attendance button { min-height: var(--ui-touch-min); }
  #tab_attendance select, #tab_attendance input { font-size: 16px; }

  /* MODALS — existing IDs/handlers are untouched; standard modal class remains the visual owner. */
  .modal { z-index: var(--ui-z-modal); }
  .modal-content { width: 100%; max-width: 620px; max-height: calc(92dvh - env(safe-area-inset-top)); padding-bottom: calc(18px + env(safe-area-inset-bottom)); }
  .modal-content input, .modal-content select, .modal-content textarea,
  .ui-shell-overlay input, .ui-shell-overlay select, .ui-shell-overlay textarea { font-size: 16px; }
  .modal-content button, .ui-shell-overlay button { min-height: var(--ui-touch-min); }

  /* Existing non-.modal overlays get safe mobile overlay behavior without changing their JS display contract. */
  .ui-shell-overlay { padding-bottom: env(safe-area-inset-bottom); }
  #quickPayModal.ui-shell-overlay, #changePasswordModal.ui-shell-overlay, #manageCatModal.ui-shell-overlay, #deleteTxModal.ui-shell-overlay { align-items: flex-end; padding-left: 0; padding-right: 0; padding-bottom: env(safe-area-inset-bottom); }

  /* MORE — same existing mobileMenuSheet/openMobileMenu owner. */
  #mobileMenuSheet { z-index: var(--ui-z-sheet); }
  #mobileMenuSheetContent { max-height: min(82dvh, 720px); overflow-y: auto; overscroll-behavior: contain; }
  .mms-btn { min-height: 52px; font-size: var(--ui-font-sm); }

  /* BOTTOM NAVIGATION — fixed presentation only; every action calls an existing authority. */
  .ui-bottom-nav { position: fixed; left: 0; right: 0; bottom: 0; z-index: var(--ui-z-bottom-nav); display: none; grid-template-columns: repeat(5, minmax(0, 1fr)); height: calc(var(--ui-bottom-nav-height) + env(safe-area-inset-bottom)); padding: 5px 6px env(safe-area-inset-bottom); background: rgba(255, 255, 255, 0.96); border-top: 1px solid #dbe3ef; box-shadow: 0 -8px 24px rgba(15, 23, 42, 0.08); backdrop-filter: blur(14px); }
  .ui-bottom-nav-item { min-width: 0; min-height: 54px; border: 0; border-radius: 12px; background: transparent; color: #64748b; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 0.75rem; font-weight: 800; cursor: pointer; }
  .ui-nav-icon { font-size: 1.15rem; line-height: 1; }
  /* C1 tenant-shell eligibility mirrors existing DOM authority: main tenant shell visible, not SuperAdmin root, not access-blocked. */
  body:has(#mainApp[style*="display: block"]):not(:has(#superAdminView[style*="display: block"])):not(:has(#clubAccessBlockBanner)) .ui-bottom-nav { display: grid; }
  body:has(#superAdminView[style*="display: block"]) .ui-bottom-nav,
  body:has(#clubAccessBlockBanner) .ui-bottom-nav,
  body:has(#clubAccessBlockBanner) #filterArea,
  body:has(#clubAccessBlockBanner) .mobile-header-bar,
  body:has(#clubAccessBlockBanner) .mobile-menu-btn,
  body:has(#clubAccessBlockBanner) #mobileMenuSheet { display: none; }
  body.ui-mobile-shell:has(#clubAccessBlockBanner),
  body.ui-mobile-shell:has(#superAdminView[style*="display: block"]) { padding-bottom: calc(env(safe-area-inset-bottom) + var(--ui-space-4)); }
  body:has(#tab_tx.active) #mobileNavTuition,
  body:has(#tab_debt.active) #mobileNavDebt,
  body:has(#tab_attendance.active) #mobileNavAttendance,
  body:has(#tab_active.active) #mobileNavStudents,
  body:has(#tab_dashboard.active) #mobileNavMore,
  body:has(#tab_inventory.active) #mobileNavMore,
  body:has(#tab_exam.active) #mobileNavMore,
  body:has(#tab_expense.active) #mobileNavMore,
  body:has(#tab_quit.active) #mobileNavMore { color: var(--primary); background: #eef4ff; }

  /* Role/access parity derives only from existing desktop DOM presentation; no mobile role state exists. */
  body:has(#btn_dashboard[style*="display: none"]):has(#btn_tx[style*="display: none"]):has(#btn_active[style*="display: none"]):has(#tab_attendance.active) .ui-bottom-nav { grid-template-columns: 1fr; }
  body:has(#btn_dashboard[style*="display: none"]):has(#btn_tx[style*="display: none"]):has(#btn_active[style*="display: none"]):has(#tab_attendance.active) #mobileNavTuition,
  body:has(#btn_dashboard[style*="display: none"]):has(#btn_tx[style*="display: none"]):has(#btn_active[style*="display: none"]):has(#tab_attendance.active) #mobileNavDebt,
  body:has(#btn_dashboard[style*="display: none"]):has(#btn_tx[style*="display: none"]):has(#btn_active[style*="display: none"]):has(#tab_attendance.active) #mobileNavStudents,
  body:has(#btn_dashboard[style*="display: none"]):has(#btn_tx[style*="display: none"]):has(#btn_active[style*="display: none"]):has(#tab_attendance.active) #mobileNavMore,
  body:has(#btn_dashboard[style*="display: none"]):has(#btn_tx[style*="display: none"]):has(#btn_active[style*="display: none"]):has(#tab_attendance.active) #mobileMoreModuleSection { display: none; }
  body:has(#superAdminView[style*="display: block"]) #mobileMoreModuleSection,
  body:has(#clubAccessBlockBanner) #mobileMoreModuleSection { display: none; }

  /* Mobile utilities mirror the existing desktop/current permission presentation. */
  body:has(#btnSettings[style*="display: none"]) #mmsSettingsAction,
  body:has(#btnSettings[hidden]) #mmsSettingsAction { display: none; }
  body:has(#exportTaxBtn[style*="display: none"]) #mmsTaxAction,
  body:has(#exportTaxBtn[hidden]) #mmsTaxAction { display: none; }
  body:has(#exportBtn[style*="display: none"]) #mmsExcelAction,
  body:has(#exportBtn[hidden]) #mmsExcelAction { display: none; }
  body:has(#btnChangePassword[style*="display: none"]) #mmsChangePasswordBtn,
  body:has(#btnChangePassword[hidden]) #mmsChangePasswordBtn { display: none; }

  body:has(#btn_exam[style*="display: none"]) #mobileMoreExam { display: none; }

  .toast { z-index: var(--ui-z-toast); bottom: calc(var(--ui-bottom-nav-height) + env(safe-area-inset-bottom) + 12px); }

  button[aria-label="Đóng"], button[aria-label="Thêm thành tích"] { min-width: var(--ui-touch-min); min-height: var(--ui-touch-min); }
  :focus-visible { outline: 3px solid rgba(0, 51, 160, 0.38); outline-offset: 2px; }
}

@media (prefers-reduced-motion: reduce) {
  .ui-mobile-shell *, .ui-mobile-shell *::before, .ui-mobile-shell *::after { scroll-behavior: auto; animation-duration: 0.01ms; animation-iteration-count: 1; transition-duration: 0.01ms; }
}
/* A9R15: existing registration controls, ordered branch -> shift -> weekdays. */
.training-registration { display:flex; flex-direction:column; gap:10px; min-width:0; padding:12px; border:1px solid #bfdbfe; border-radius:12px; background:#f8fafc; }
.training-registration > div { margin:0 !important; }
.training-registration select { font-size:16px !important; min-height:44px; max-width:100%; }
.training-registration label, .training-registration > div > span { font-size:13px !important; }
.training-registration [role="alert"] { color:#9f1239; font-size:13px; line-height:1.5; overflow-wrap:anywhere; }
.training-registration button { font-size:13px; min-height:44px; border:1px solid #cbd5e1; border-radius:8px; background:white; padding:8px; }
.training-registration pre { white-space:pre-wrap; overflow-wrap:anywhere; max-height:240px; overflow:auto; font-size:12px; }
