/*
 * School Platform mobile application layer
 * Loaded after all feature styles. Every layout override is media-bound so
 * the existing desktop interface remains unchanged.
 */

@media (max-width: 900px) {
  :root {
    --mobile-gutter: clamp(12px, 3.75vw, 18px);
    --mobile-radius: 18px;
    --mobile-appbar-height: 74px;
    --mobile-shadow: 0 8px 28px rgba(15, 23, 42, 0.08);
    --mobile-shadow-raised: 0 18px 48px rgba(15, 23, 42, 0.18);
  }

  html {
    min-width: 0;
    background: #f3f6fb;
    overscroll-behavior-y: none;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
  }

  body {
    min-width: 0;
    min-height: 100dvh;
    overflow-x: hidden;
    color: #0f172a;
    background:
      radial-gradient(circle at 100% 0, color-mix(in srgb, var(--primary) 7%, transparent), transparent 35%),
      #f3f6fb;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    -webkit-tap-highlight-color: transparent;
  }

  button,
  input,
  select,
  textarea {
    font: inherit;
  }

  button,
  a,
  select,
  input[type="checkbox"],
  input[type="radio"],
  input[type="file"],
  input[type="date"],
  input[type="time"] {
    touch-action: manipulation;
  }

  button:focus-visible,
  a:focus-visible,
  input:focus-visible,
  select:focus-visible,
  textarea:focus-visible {
    outline: 3px solid color-mix(in srgb, var(--primary) 24%, transparent);
    outline-offset: 2px;
  }

  /* Portal frame and Android-style app bar */
  .app-shell {
    display: block;
    min-height: 100dvh;
    width: 100%;
  }

  .app-shell .main {
    width: 100%;
    min-width: 0;
    margin: 0;
    padding: 0 !important;
  }

  .topbar {
    position: sticky;
    top: 0;
    z-index: 85;
    display: grid !important;
    grid-template-columns: 46px minmax(0, 1fr) auto;
    align-items: center;
    gap: 10px;
    width: 100%;
    min-height: calc(var(--mobile-appbar-height) + env(safe-area-inset-top));
    margin: 0;
    padding: calc(10px + env(safe-area-inset-top)) var(--mobile-gutter) 10px;
    border: 0;
    border-radius: 0;
    color: #fff;
    background:
      linear-gradient(115deg, color-mix(in srgb, var(--header-bg, #0f172a) 88%, #000 12%), var(--header-bg, #0f172a)) !important;
    box-shadow: 0 5px 18px rgba(15, 23, 42, 0.16);
  }

  .mobile-menu-toggle {
    display: inline-grid !important;
    place-items: center;
    width: 44px;
    height: 44px;
    min-width: 44px;
    margin: 0;
    padding: 0;
    border: 1px solid rgba(255, 255, 255, 0.28);
    border-radius: 14px;
    color: #fff;
    background: rgba(255, 255, 255, 0.12);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.14);
    backdrop-filter: blur(10px);
  }

  .mobile-menu-toggle:hover,
  .mobile-menu-toggle:active {
    color: #fff;
    background: rgba(255, 255, 255, 0.2);
    transform: none;
  }

  .mobile-menu-toggle .menu-lines,
  .mobile-menu-toggle .menu-lines::before,
  .mobile-menu-toggle .menu-lines::after {
    width: 21px;
    height: 2px;
    border-radius: 999px;
    background: currentColor;
  }

  .topbar-title,
  .topbar > div:first-of-type {
    min-width: 0;
  }

  .topbar-title h1,
  .topbar > div:first-of-type h1 {
    overflow: hidden;
    margin: 0;
    color: #fff;
    font-size: clamp(19px, 5.4vw, 24px);
    font-weight: 800;
    line-height: 1.12;
    letter-spacing: -0.025em;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .topbar-title p,
  .topbar > div:first-of-type p {
    overflow: hidden;
    max-width: 100%;
    margin: 4px 0 0;
    color: rgba(255, 255, 255, 0.78);
    font-size: 12px;
    line-height: 1.25;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .topbar-date,
  .top-actions {
    display: none;
  }

  .header-profile-box {
    display: grid;
    place-items: center;
    min-width: 44px;
    min-height: 44px;
    margin: 0;
    padding: 3px;
    border: 1px solid rgba(255, 255, 255, 0.25);
    border-radius: 15px;
    background: rgba(255, 255, 255, 0.1);
    box-shadow: none;
  }

  .header-profile-box .header-avatar,
  .header-profile-box img {
    width: 36px;
    height: 36px;
    border-radius: 12px;
  }

  .header-profile-text {
    display: none !important;
  }

  /* Slide-out navigation drawer */
  .sidebar {
    position: fixed !important;
    inset: 0 auto 0 0;
    z-index: 110;
    display: flex !important;
    flex-direction: column;
    width: min(88vw, 340px) !important;
    height: 100dvh;
    min-height: 0;
    padding: calc(18px + env(safe-area-inset-top)) 16px calc(14px + env(safe-area-inset-bottom));
    border: 0;
    border-radius: 0 26px 26px 0;
    overflow: hidden;
    color: #fff;
    background:
      radial-gradient(circle at 0 0, rgba(255, 255, 255, 0.13), transparent 30%),
      linear-gradient(165deg, color-mix(in srgb, var(--sidebar-bg, #101828) 86%, #fff 14%), var(--sidebar-bg, #101828) 42%, color-mix(in srgb, var(--sidebar-bg, #101828) 84%, #000 16%));
    box-shadow: 22px 0 52px rgba(15, 23, 42, 0.26);
    transform: translate3d(-105%, 0, 0);
    transition: transform 220ms cubic-bezier(0.2, 0, 0, 1);
  }

  body.portal-nav-open .sidebar {
    transform: translate3d(0, 0, 0);
  }

  .sidebar .brand-box {
    display: grid;
    grid-template-columns: 52px minmax(0, 1fr);
    align-items: center;
    gap: 12px;
    flex: 0 0 auto;
    min-height: 74px;
    margin: 0 0 12px;
    padding: 10px 10px 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.16);
  }

  .sidebar .brand-box img,
  .sidebar .brand-box .brand-logo {
    width: 52px;
    height: 52px;
    padding: 3px;
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.96);
    object-fit: contain;
  }

  .sidebar .logo-wrap {
    width: 52px;
    height: 52px;
    border-radius: 16px;
  }

  .sidebar .brand-name,
  .sidebar .brand-box h2 {
    overflow: hidden;
    color: #fff;
    font-size: 16px;
    font-weight: 800;
    line-height: 1.18;
    text-overflow: ellipsis;
  }

  .sidebar .brand-slug,
  .sidebar .brand-box small {
    overflow: hidden;
    margin-top: 4px;
    color: rgba(255, 255, 255, 0.68);
    font-size: 12px;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .sidebar-profile-card {
    flex: 0 0 auto;
    min-height: 66px;
    margin: 0 2px 12px;
    padding: 10px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 17px;
    background: rgba(255, 255, 255, 0.1);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
  }

  .sidebar-profile-card img,
  .sidebar-profile-card .sidebar-profile-avatar {
    width: 44px;
    height: 44px;
    border-radius: 13px;
  }

  .sidebar nav {
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    gap: 5px;
    min-height: 0;
    padding: 2px 3px 12px;
    overflow-x: hidden;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.34) transparent;
    overscroll-behavior: contain;
  }

  .sidebar nav::-webkit-scrollbar {
    width: 4px;
  }

  .sidebar nav::-webkit-scrollbar-thumb {
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.34);
  }

  .sidebar nav button,
  .sidebar nav a {
    position: relative;
    display: flex;
    align-items: center;
    flex: 0 0 auto;
    min-height: 48px;
    margin: 0;
    padding: 0 16px;
    border: 0;
    border-radius: 14px;
    color: rgba(255, 255, 255, 0.8);
    background: transparent;
    box-shadow: none;
    font-size: 14px;
    font-weight: 650;
    text-align: left;
  }

  .sidebar nav button:hover,
  .sidebar nav a:hover,
  .sidebar nav button.active,
  .sidebar nav a.active {
    color: #fff;
    background: rgba(255, 255, 255, 0.14);
    transform: none;
  }

  .sidebar nav button.active::before,
  .sidebar nav a.active::before {
    position: absolute;
    left: 5px;
    width: 4px;
    height: 20px;
    border-radius: 999px;
    background: #fff;
    content: "";
  }

  .sidebar .switch-btn {
    flex: 0 0 auto;
    min-height: 48px;
    margin: 8px 3px 0;
    padding: 0 16px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 15px;
    color: #fff;
    background: rgba(255, 255, 255, 0.11);
    box-shadow: none;
    font-weight: 750;
  }

  .sidebar-backdrop {
    position: fixed;
    inset: 0;
    z-index: 105;
    display: block !important;
    visibility: hidden;
    border: 0;
    background: rgba(15, 23, 42, 0.56);
    opacity: 0;
    backdrop-filter: blur(3px);
    transition: opacity 200ms ease, visibility 200ms ease;
  }

  body.portal-nav-open {
    overflow: hidden;
  }

  body.portal-nav-open .sidebar-backdrop {
    visibility: visible;
    opacity: 1;
  }

  /* Main page rhythm, cards and dashboards */
  .page,
  .page.active {
    min-width: 0;
    padding: var(--mobile-gutter);
  }

  .page > .panel:first-child,
  .page > .stats-grid:first-child {
    margin-top: 0;
  }

  .panel,
  .profile-panel,
  .academic-settings-card,
  .brand-settings-card,
  .settings-card,
  .attendance-v2-panel {
    min-width: 0;
    margin-bottom: 14px;
    padding: clamp(16px, 4.5vw, 22px);
    border: 1px solid #e1e7f0;
    border-radius: var(--mobile-radius);
    background: rgba(255, 255, 255, 0.97);
    box-shadow: var(--mobile-shadow);
  }

  .panel h2,
  .panel h3,
  .profile-panel h2,
  .academic-settings-card h2,
  .brand-settings-card h2 {
    margin-top: 0;
    color: #111827;
    font-size: clamp(18px, 5vw, 22px);
    line-height: 1.25;
    letter-spacing: -0.025em;
  }

  .panel > p,
  .helper-text,
  .muted {
    font-size: 13px;
    line-height: 1.55;
  }

  .stats-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 12px;
    margin-bottom: 14px;
  }

  .stat-card {
    position: relative;
    display: flex;
    min-width: 0;
    min-height: 108px;
    flex-direction: column;
    justify-content: space-between;
    margin: 0;
    padding: 16px;
    overflow: hidden;
    border: 1px solid #e1e7f0;
    border-radius: 17px;
    background: #fff;
    box-shadow: 0 5px 18px rgba(15, 23, 42, 0.06);
  }

  .stat-card::before {
    position: absolute;
    inset: 0 0 auto;
    height: 3px;
    background: linear-gradient(90deg, var(--primary), color-mix(in srgb, var(--primary) 35%, #fff));
    content: "";
  }

  .stat-card .label,
  .stat-card > span,
  .stat-label {
    color: #64748b;
    font-size: 11px;
    font-weight: 800;
    line-height: 1.25;
    letter-spacing: 0.07em;
    text-transform: uppercase;
  }

  .stat-card .value,
  .stat-card > strong,
  .stat-value {
    overflow-wrap: anywhere;
    color: #0f172a;
    font-size: clamp(22px, 7.5vw, 32px);
    font-weight: 850;
    line-height: 1;
    letter-spacing: -0.04em;
  }

  .grid,
  .grid.two,
  .grid.three,
  .two-column,
  .three-column,
  .profile-settings-grid,
  .settings-layout,
  .details-layout,
  .detail-grid,
  .form-grid,
  .form-grid.two,
  .form-grid.three,
  .student-form-grid,
  .teacher-form-grid,
  .branding-grid,
  .academic-settings-grid {
    grid-template-columns: minmax(0, 1fr) !important;
    gap: 14px;
  }

  .record-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  .record-card,
  .detail-card,
  .info-card {
    min-width: 0;
    padding: 14px;
    border-radius: 15px;
  }

  /* Touch-friendly fields and actions */
  input:not([type="checkbox"]):not([type="radio"]):not([type="color"]),
  select,
  textarea {
    width: 100%;
    min-height: 50px;
    padding: 12px 14px;
    border: 1px solid #d8e0eb;
    border-radius: 13px;
    background-color: #fff;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.03);
    font-size: 16px;
    line-height: 1.35;
  }

  textarea {
    min-height: 104px;
    resize: vertical;
  }

  input:focus,
  select:focus,
  textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 4px color-mix(in srgb, var(--primary) 12%, transparent);
  }

  label {
    color: #334155;
    font-size: 13px;
    font-weight: 700;
  }

  .btn,
  button.primary,
  button.secondary,
  button.danger,
  .primary-btn,
  .secondary-btn,
  .danger-btn,
  .save-btn,
  .action-btn {
    min-height: 48px;
    padding: 0 18px;
    border-radius: 13px;
    font-size: 14px;
    font-weight: 750;
    line-height: 1.2;
  }

  .btn:hover,
  button.primary:hover,
  button.secondary:hover,
  button.danger:hover,
  .primary-btn:hover,
  .secondary-btn:hover,
  .danger-btn:hover,
  .save-btn:hover,
  .action-btn:hover {
    transform: none;
  }

  .button-row,
  .form-actions,
  .panel-actions,
  .modal-actions,
  .settings-actions,
  .toolbar-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
  }

  .button-row > *,
  .form-actions > *,
  .modal-actions > *,
  .settings-actions > * {
    flex: 1 1 150px;
  }

  input[type="file"] {
    padding: 7px;
  }

  input[type="file"]::file-selector-button {
    min-height: 36px;
    margin-right: 10px;
    padding: 0 13px;
    border: 0;
    border-radius: 10px;
    color: #fff;
    background: var(--primary);
    font-weight: 750;
  }

  input[type="color"] {
    width: 52px;
    height: 44px;
    padding: 5px;
    border: 1px solid #d8e0eb;
    border-radius: 12px;
    background: #fff;
  }

  /* Data tables remain complete and swipe naturally */
  .table-wrap,
  .table-responsive,
  .responsive-table,
  .cashbook-table-wrap {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    border: 1px solid #e1e7f0;
    border-radius: 15px;
    background: #fff;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
    scrollbar-width: thin;
  }

  .table-wrap table,
  .table-responsive table,
  .responsive-table table,
  .cashbook-table-wrap table {
    min-width: 680px;
    border: 0;
  }

  .attendance-v2-panel .table-wrap table,
  .timetable-wrap table,
  .cashbook-table-wrap table {
    min-width: 920px;
  }

  table th {
    position: sticky;
    top: 0;
    z-index: 2;
    padding: 12px 13px;
    color: #526079;
    background: #f6f8fb;
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0.055em;
    text-transform: uppercase;
    white-space: nowrap;
  }

  table td {
    padding: 13px;
    font-size: 13px;
    line-height: 1.4;
  }

  .pagination,
  .table-pagination {
    flex-wrap: wrap;
    gap: 8px;
    padding-top: 12px;
  }

  /* Attendance and timetable controls */
  .attendance-toolbar,
  .attendance-actions,
  .attendance-filter-v3,
  .attendance-filter-grid,
  .attendance-modal .modal-form,
  .attendance-modal .form-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 10px;
  }

  .attendance-filter-v3,
  .attendance-filter-shell {
    margin: 12px 0;
    padding: 12px;
    border-radius: 15px;
    background: #f7f9fc;
  }

  .record-switch,
  .attendance-record-switch {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 4px;
    width: 100%;
    padding: 4px;
    border: 1px solid #e1e7f0;
    border-radius: 14px;
    background: #edf1f7;
  }

  .record-switch button,
  .attendance-record-switch button {
    min-height: 42px;
    padding: 7px 9px;
    border: 0;
    border-radius: 11px;
    box-shadow: none;
    font-size: 12px;
  }

  .attendance-submit-actions,
  .attendance-top-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  .attendance-submit-actions button,
  .attendance-top-actions button {
    width: 100%;
    min-height: 48px;
    white-space: normal;
  }

  /* Profile, documents, photos and cash book */
  .profile-layout,
  .profile-details-layout,
  .teacher-profile-layout,
  .student-profile-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) !important;
    gap: 14px;
  }

  .profile-photo-card,
  .photo-card,
  .profile-summary {
    width: 100%;
    max-width: none;
    padding: 18px;
    border-radius: 17px;
  }

  .profile-photo-card img,
  .photo-card img,
  .profile-avatar-large {
    width: 112px;
    height: 112px;
    border-radius: 24px;
  }

  .document-upload-grid,
  .teacher-document-grid,
  .document-grid {
    grid-template-columns: minmax(0, 1fr) !important;
    gap: 10px;
  }

  .cashbook-summary-grid,
  .cashbook-dashboard-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 10px;
  }

  .cashbook-summary-card {
    min-width: 0;
    padding: 14px;
    border-radius: 15px;
  }
}

@media (max-width: 600px) {
  .topbar-title p {
    max-width: 52vw;
  }

  .page,
  .page.active {
    padding-bottom: calc(24px + env(safe-area-inset-bottom));
  }

  .panel,
  .profile-panel,
  .academic-settings-card,
  .brand-settings-card,
  .settings-card,
  .attendance-v2-panel {
    padding: 16px;
  }

  .page-header,
  .panel-header,
  .section-header,
  .details-header {
    align-items: flex-start;
    flex-direction: column;
    gap: 10px;
  }

  .page-header button,
  .panel-header button,
  .details-header button {
    width: 100%;
  }

  .attendance-toolbar,
  .attendance-actions,
  .attendance-filter-v3,
  .attendance-filter-grid,
  .attendance-modal .modal-form,
  .attendance-modal .form-grid {
    grid-template-columns: minmax(0, 1fr) !important;
  }
}

@media (max-width: 420px) {
  :root {
    --mobile-gutter: 12px;
  }

  .topbar {
    grid-template-columns: 44px minmax(0, 1fr) 42px;
    gap: 8px;
  }

  .topbar-title h1 {
    font-size: 18px;
  }

  .topbar-title p {
    max-width: 49vw;
    font-size: 11px;
  }

  .header-profile-box {
    min-width: 42px;
    min-height: 42px;
  }

  .stats-grid,
  .cashbook-summary-grid,
  .cashbook-dashboard-grid {
    gap: 9px;
  }

  .stat-card {
    min-height: 100px;
    padding: 14px;
  }

  .record-grid {
    grid-template-columns: minmax(0, 1fr);
  }
}

/* Mobile dialogs use a native-feeling bottom sheet pattern. */
@media (max-width: 900px) {
  .small-modal,
  .user-form-modal,
  .attendance-modal,
  .cashbook-modal,
  .manager-modal-backdrop,
  .school-download-denied-backdrop,
  .modal-backdrop {
    position: fixed !important;
    inset: 0 !important;
    z-index: 300 !important;
    display: flex;
    align-items: flex-end !important;
    justify-content: center !important;
    width: 100%;
    height: 100dvh;
    padding: 56px 0 0 !important;
    overflow: hidden !important;
    background: rgba(15, 23, 42, 0.62) !important;
    opacity: 1;
    backdrop-filter: blur(5px);
  }

  .small-modal.hidden,
  .user-form-modal.hidden,
  .attendance-modal.hidden,
  .cashbook-modal.hidden,
  .manager-modal-backdrop.hidden,
  .school-download-denied-backdrop.hidden,
  .modal-backdrop.hidden,
  [hidden] {
    display: none !important;
  }

  .small-modal-card,
  .user-form-card,
  .user-form-modal-card,
  .attendance-modal-card,
  .cashbook-modal-card,
  .manager-modal-card,
  .manager-modal-dialog,
  .school-download-denied-card,
  .school-download-denied-dialog,
  .modal-card {
    position: relative;
    display: flex;
    width: 100% !important;
    max-width: none !important;
    max-height: calc(100dvh - 56px - env(safe-area-inset-top));
    margin: 0 !important;
    padding: 24px var(--mobile-gutter) calc(18px + env(safe-area-inset-bottom)) !important;
    overflow-x: hidden;
    overflow-y: auto;
    flex-direction: column;
    border: 0 !important;
    border-radius: 24px 24px 0 0 !important;
    background: #fff !important;
    box-shadow: 0 -18px 60px rgba(15, 23, 42, 0.22) !important;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    animation: mobileSheetIn 220ms cubic-bezier(0.2, 0, 0, 1);
  }

  .small-modal-card::before,
  .user-form-card::before,
  .user-form-modal-card::before,
  .attendance-modal-card::before,
  .cashbook-modal-card::before,
  .manager-modal-card::before,
  .manager-modal-dialog::before,
  .school-download-denied-card::before,
  .school-download-denied-dialog::before,
  .modal-card::before {
    position: absolute;
    top: 8px;
    left: 50%;
    width: 38px;
    height: 4px;
    border-radius: 99px;
    background: #d5dce6;
    content: "";
    transform: translateX(-50%);
  }

  .modal-header,
  .small-modal-head,
  .attendance-modal-header,
  .manager-modal-header,
  .cashbook-modal-header,
  .cashbook-modal-head,
  .user-form-header,
  .user-form-modal-head {
    position: sticky;
    top: -24px;
    z-index: 5;
    flex: 0 0 auto;
    margin: -8px calc(-1 * var(--mobile-gutter)) 14px;
    padding: 18px var(--mobile-gutter) 14px;
    border-bottom: 1px solid #e5eaf1;
    background: rgba(255, 255, 255, 0.96);
    backdrop-filter: blur(14px);
  }

  .modal-header h2,
  .small-modal-head strong,
  .attendance-modal-header h2,
  .manager-modal-header h2,
  .cashbook-modal-header h2,
  .cashbook-modal-head h2,
  .user-form-header h2,
  .user-form-modal-head h2 {
    margin: 0;
    padding-right: 52px;
    font-size: 21px;
    line-height: 1.2;
    letter-spacing: -0.025em;
  }

  .modal-close,
  .attendance-modal-close,
  .manager-modal-close,
  .cashbook-modal-close,
  .user-form-close,
  .modal-close-btn,
  .small-modal-head button,
  .close-modal {
    width: 42px !important;
    height: 42px !important;
    min-width: 42px !important;
    min-height: 42px !important;
    padding: 0 !important;
    border: 1px solid #dfe5ed !important;
    border-radius: 50% !important;
    color: #334155 !important;
    background: #fff !important;
    box-shadow: 0 3px 10px rgba(15, 23, 42, 0.06) !important;
  }

  .modal-actions,
  .attendance-modal-actions,
  .manager-modal-actions,
  .cashbook-modal-actions,
  .user-form-actions {
    position: sticky;
    bottom: calc(-18px - env(safe-area-inset-bottom));
    z-index: 5;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    flex: 0 0 auto;
    gap: 10px;
    margin: 18px calc(-1 * var(--mobile-gutter)) calc(-18px - env(safe-area-inset-bottom));
    padding: 12px var(--mobile-gutter) calc(12px + env(safe-area-inset-bottom));
    border-top: 1px solid #e5eaf1;
    background: rgba(255, 255, 255, 0.96);
    backdrop-filter: blur(14px);
  }

  .modal-actions > *,
  .attendance-modal-actions > *,
  .manager-modal-actions > *,
  .cashbook-modal-actions > *,
  .user-form-actions > * {
    width: 100%;
    min-height: 48px;
    margin: 0;
  }

  .school-download-denied-dialog {
    display: grid;
    grid-template-columns: 48px minmax(0, 1fr);
    gap: 14px;
  }

  .school-download-denied-button {
    grid-column: 1 / -1;
    width: 100%;
    min-height: 48px;
  }

  @keyframes mobileSheetIn {
    from {
      opacity: 0;
      transform: translateY(32px);
    }
    to {
      opacity: 1;
      transform: translateY(0);
    }
  }
}

/* Workspace finder and workspace manager */
@media (max-width: 900px) {
  .workspace-directory-screen,
  .platform-manager-screen {
    min-height: 100dvh;
    padding: 0 !important;
    background:
      radial-gradient(circle at 100% 0, #dce8ff 0, transparent 38%),
      linear-gradient(180deg, #f8faff, #eff4fb);
  }

  .workspace-directory-shell,
  .platform-manager-shell {
    width: 100%;
    max-width: none;
    min-height: 100dvh;
    margin: 0;
    padding: 0 0 calc(24px + env(safe-area-inset-bottom));
    border: 0;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
  }

  .directory-hero,
  .platform-manager-header {
    position: relative;
    margin: 0 0 14px;
    padding: calc(24px + env(safe-area-inset-top)) var(--mobile-gutter) 24px;
    overflow: hidden;
    border: 0;
    border-radius: 0 0 26px 26px;
    color: #fff;
    background: linear-gradient(135deg, #143fc0, #2563eb 62%, #0ea5e9);
    box-shadow: 0 14px 38px rgba(37, 99, 235, 0.22);
  }

  .directory-hero::after,
  .platform-manager-header::after {
    position: absolute;
    right: -55px;
    bottom: -75px;
    width: 190px;
    height: 190px;
    border: 30px solid rgba(255, 255, 255, 0.08);
    border-radius: 50%;
    content: "";
  }

  .directory-hero h1,
  .platform-manager-header h1 {
    position: relative;
    z-index: 1;
    max-width: 18ch;
    margin: 6px 0 10px;
    color: #fff;
    font-size: clamp(27px, 8vw, 38px);
    line-height: 1.05;
    letter-spacing: -0.04em;
  }

  .directory-hero p,
  .platform-manager-header p,
  .directory-eyebrow,
  .platform-manager-header .eyebrow {
    position: relative;
    z-index: 1;
    max-width: 48ch;
    color: rgba(255, 255, 255, 0.82);
  }

  .workspace-search-panel,
  .saved-workspace-panel,
  .workspace-results-panel,
  .manager-panel,
  .manager-create-panel,
  .manager-workspaces-panel {
    margin: 0 var(--mobile-gutter) 14px;
    padding: 17px;
    border: 1px solid #e0e7f1;
    border-radius: 19px;
    background: rgba(255, 255, 255, 0.96);
    box-shadow: var(--mobile-shadow);
  }

  .workspace-results-section {
    padding: 0 var(--mobile-gutter) 18px;
  }

  .directory-footer {
    padding: 16px var(--mobile-gutter);
  }

  .workspace-search-form,
  .workspace-search-row,
  .workspace-directory-grid,
  .manager-content-grid,
  .manager-form-grid,
  .manager-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) !important;
    gap: 12px;
  }

  .workspace-search-form button,
  .workspace-search-row button {
    width: 100%;
    min-height: 50px;
  }

  .workspace-results-grid,
  .saved-workspaces-grid,
  .manager-workspace-list,
  .manager-users-list {
    display: grid;
    grid-template-columns: minmax(0, 1fr) !important;
    gap: 11px;
  }

  .workspace-result-card,
  .saved-workspace-card,
  .manager-workspace-item,
  .manager-user-item {
    min-width: 0;
    padding: 15px;
    border: 1px solid #e1e7f0;
    border-radius: 17px;
    background: #fff;
    box-shadow: 0 4px 16px rgba(15, 23, 42, 0.05);
  }

  .workspace-result-card-head,
  .saved-workspace-card-head,
  .manager-workspace-main {
    align-items: center;
    gap: 11px;
  }

  .workspace-result-logo,
  .saved-workspace-logo,
  .manager-workspace-logo {
    width: 52px;
    height: 52px;
    min-width: 52px;
    border-radius: 15px;
  }

  .workspace-role-actions,
  .workspace-card-actions,
  .manager-workspace-actions,
  .manager-user-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    width: 100%;
    margin-top: 12px;
  }

  .workspace-role-actions a,
  .workspace-role-actions button,
  .workspace-card-actions a,
  .workspace-card-actions button,
  .manager-workspace-actions button,
  .manager-user-actions button {
    display: grid;
    place-items: center;
    min-height: 44px;
    margin: 0;
    padding: 8px 10px;
    border-radius: 12px;
    font-size: 12px;
    line-height: 1.25;
    text-align: center;
    white-space: normal;
  }

  .saved-role-actions,
  .workspace-card-role-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    width: 100%;
    margin-top: 12px;
  }

  .saved-role-actions button,
  .workspace-card-role-actions button {
    min-height: 44px;
    margin: 0;
    padding: 8px 10px;
    border-radius: 12px;
    font-size: 12px;
    white-space: normal;
  }

  .manager-summary-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
    margin: 0 var(--mobile-gutter) 14px;
    padding: 0;
  }

  .manager-content-grid {
    padding: 0 var(--mobile-gutter) 18px;
  }

  .manager-summary-card {
    min-width: 0;
    min-height: 96px;
    padding: 13px 10px;
    border-radius: 16px;
    text-align: center;
  }

  .manager-summary-card .label {
    font-size: 9px;
    line-height: 1.2;
  }

  .manager-summary-card .value {
    margin-top: 8px;
    font-size: 24px;
  }

  .platform-manager-header .button-row,
  .platform-manager-header .header-actions {
    position: relative;
    z-index: 1;
    width: 100%;
    margin-top: 16px;
  }
}

@media (max-width: 420px) {
  .workspace-role-actions,
  .workspace-card-actions,
  .manager-workspace-actions,
  .manager-user-actions,
  .saved-role-actions,
  .workspace-card-role-actions {
    grid-template-columns: minmax(0, 1fr);
  }
}

/* Login pages become clean, installable-app-like screens on phones. */
@media (max-width: 600px) {
  body.login-page,
  .login-page {
    display: block;
    min-height: 100dvh;
    padding: 0;
    background:
      radial-gradient(circle at 100% 0, #dce8ff 0, transparent 35%),
      linear-gradient(180deg, #f8faff, #eef3fa);
  }

  .login-card {
    display: flex;
    width: 100%;
    max-width: none;
    min-height: 100dvh;
    margin: 0;
    padding: calc(28px + env(safe-area-inset-top)) 22px calc(20px + env(safe-area-inset-bottom));
    flex-direction: column;
    border: 0;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
  }

  .login-header {
    align-items: center;
    min-height: 66px;
    margin: 0 0 clamp(34px, 8vh, 70px);
    padding: 0;
  }

  .login-mark {
    display: grid;
    place-items: center;
    width: 56px;
    height: 56px;
    min-width: 56px;
    border-radius: 18px;
    color: #fff;
    background: linear-gradient(145deg, var(--primary, #2563eb), color-mix(in srgb, var(--primary, #2563eb) 70%, #0ea5e9));
    box-shadow: 0 10px 26px color-mix(in srgb, var(--primary, #2563eb) 28%, transparent);
  }

  .login-mark img {
    width: 100%;
    height: 100%;
    padding: 4px;
    border-radius: inherit;
    background: #fff;
    object-fit: contain;
  }

  .login-header strong {
    color: #111827;
    font-size: 17px;
    line-height: 1.2;
  }

  .login-header span,
  .login-header small {
    color: #64748b;
    font-size: 12px;
  }

  .login-card h1 {
    margin: 0 0 8px;
    color: #0f172a;
    font-size: clamp(29px, 9vw, 38px);
    line-height: 1.05;
    letter-spacing: -0.045em;
  }

  .login-card > p,
  .login-subtitle {
    margin-bottom: 26px;
    color: #64748b;
    font-size: 14px;
    line-height: 1.55;
  }

  .login-form {
    display: grid;
    gap: 15px;
    width: 100%;
  }

  .login-form label {
    color: #334155;
    font-size: 13px;
    font-weight: 750;
  }

  .login-form input,
  .login-form select {
    min-height: 54px;
    padding: 13px 15px;
    border: 1px solid #d8e0eb;
    border-radius: 15px;
    background: rgba(255, 255, 255, 0.92);
    box-shadow: 0 3px 12px rgba(15, 23, 42, 0.04);
    font-size: 16px;
  }

  .login-form button,
  .login-submit {
    width: 100%;
    min-height: 54px;
    margin-top: 2px;
    border: 0;
    border-radius: 15px;
    color: #fff;
    background: linear-gradient(135deg, var(--primary, #2563eb), color-mix(in srgb, var(--primary, #2563eb) 72%, #0ea5e9));
    box-shadow: 0 12px 26px color-mix(in srgb, var(--primary, #2563eb) 24%, transparent);
    font-size: 15px;
    font-weight: 800;
  }

  .login-footer {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    margin-top: auto;
    padding-top: 28px;
    color: #64748b;
    font-size: 12px;
  }

  .login-message,
  .form-message {
    border-radius: 13px;
    font-size: 13px;
  }
}

@media (max-width: 900px) and (prefers-reduced-motion: reduce) {
  .sidebar,
  .sidebar-backdrop,
  .small-modal-card,
  .user-form-card,
  .attendance-modal-card,
  .cashbook-modal-card,
  .manager-modal-card,
  .modal-card {
    scroll-behavior: auto !important;
    animation: none !important;
    transition: none !important;
  }
}

/* MOBILE_TIMETABLE_HORIZONTAL_SCROLL_FIX_V2_20260905 */
@media (max-width: 900px) {
  .tt-v2,
  #ttMasterView,
  #ttTeacherView,
  #ttClassView {
    min-width: 0;
    max-width: 100%;
  }

  .tt-v2 {
    overflow: visible !important;
  }

  .tt-scroll {
    position: relative;
    display: block !important;
    width: 100% !important;
    max-width: 100% !important;
    overflow-x: scroll !important;
    overflow-y: auto !important;
    border-radius: 14px;
    touch-action: pan-x pan-y;
    overscroll-behavior-x: contain;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: auto;
    scrollbar-color:
      color-mix(in srgb, var(--primary) 65%, #64748b)
      #e8edf5;
  }

  .tt-scroll::-webkit-scrollbar {
    height: 10px;
  }

  .tt-scroll::-webkit-scrollbar-track {
    border-radius: 999px;
    background: #e8edf5;
  }

  .tt-scroll::-webkit-scrollbar-thumb {
    border: 2px solid #e8edf5;
    border-radius: 999px;
    background:
      color-mix(in srgb, var(--primary) 70%, #64748b);
  }

  .tt-table {
    width: max-content !important;
    min-width: max-content !important;
    max-width: none !important;
    table-layout: fixed !important;
  }

  .tt-table thead th,
  .tt-table tbody td {
    box-sizing: border-box;
    width: 184px !important;
    min-width: 184px !important;
    max-width: 184px !important;
  }

  .tt-table .tt-class-col {
    width: 126px !important;
    min-width: 126px !important;
    max-width: 126px !important;
  }

  .tt-table .tt-day-col {
    width: 148px !important;
    min-width: 148px !important;
    max-width: 148px !important;
  }

  /*
   * Do not freeze these columns horizontally on phones.
   * They previously covered the lesson columns during swiping.
   */
  .tt-table tbody .tt-class-col,
  .tt-table tbody .tt-day-col {
    position: static !important;
    left: auto !important;
    z-index: auto !important;
  }

  .tt-table thead .tt-class-col,
  .tt-table thead .tt-day-col {
    left: auto !important;
  }

  .tt-table .tt-period-times label {
    grid-template-columns: 32px minmax(116px, 1fr);
  }

  .tt-table .tt-period-times input[type="time"] {
    min-width: 116px;
  }

  .tt-table .tt-day-tools {
    align-items: flex-start;
    flex-direction: column;
  }

  .tt-table .tt-day-tools > div {
    width: 100%;
    justify-content: flex-start;
  }
}

/* SACASTA_LIVE_LAYOUT_20260906 */
@media (max-width:900px) {
  #appShell {
    min-width:0!important;
    width:100%!important;
    max-width:100%!important;
  }
  #appShell > main.main {
    min-width:0!important;
    width:100%!important;
    max-width:100%!important;
    margin-inline:0!important;
  }
  #appShell .topbar {
    box-sizing:border-box;
    min-width:0;
    max-width:100%;
    grid-template-columns:44px minmax(0,1fr) auto!important;
  }
  #appShell .topbar #todayText {
    display:none!important;
  }
  #appShell .topbar > div:first-of-type {
    min-width:0;
  }
  #appShell .topbar h1,
  #appShell .topbar p {
    max-width:100%;
    overflow:hidden;
    text-overflow:ellipsis;
    white-space:nowrap;
  }
  #appShell .page,
  #appShell .panel,
  #appShell .grid {
    box-sizing:border-box;
    min-width:0;
    max-width:100%;
  }
  #appShell .table-wrap {
    display:block;
    width:100%;
    max-width:100%;
    overflow-x:auto;
  }
  #appShell .attendance-v2-panel,
  #appShell .attendance-filter-v3 {
    min-width:0;
    max-width:100%;
  }
  #appShell .attendance-filter-v3 > * {
    min-width:0;
  }
}
