/* ABSENKI phone layout — loaded only for screens <= 767.98px.
   Desktop/laptop rules remain in the existing stylesheets. */
@media (max-width: 767.98px) {
  :root {
    --absenki-mobile-gutter: 12px;
    --absenki-mobile-header: 58px;
    --absenki-mobile-bottom: 64px;
  }

  html {
    width: 100%;
    overflow-x: hidden;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
  }

  body {
    width: 100%;
    min-height: calc(var(--absenki-vh, 1vh) * 100);
    overflow-x: hidden;
    overscroll-behavior-y: contain;
    padding-bottom: env(safe-area-inset-bottom);
    background: #f6f8fc;
  }

  img, video, canvas, svg { max-width: 100%; }
  button, .btn, a.item, .nav-link, input, select, textarea { touch-action: manipulation; }
  input, select, textarea { font-size: 16px !important; }

  /* Student header */
  .appHeader {
    min-height: var(--absenki-mobile-header) !important;
    height: var(--absenki-mobile-header) !important;
    padding: 0 !important;
  }
  .appHeader .container-fluid { padding-left: 12px !important; padding-right: 12px !important; }
  .appHeader .header-toggle {
    display: inline-flex !important;
    width: 42px;
    height: 42px;
    align-items: center;
    justify-content: center;
    border-radius: 13px;
    background: rgba(255,255,255,.14);
    color: #fff;
  }
  .appHeader .header-toggle ion-icon { font-size: 25px; }
  .appHeader .navbar-brand { min-width: 0; margin-right: 0; }
  .appHeader .header-logo.d-none {
    display: block !important;
    width: auto;
    height: 32px;
    max-width: 116px;
    object-fit: contain;
  }
  .appHeader .header-avatar-btn img { width: 36px; height: 36px; }
  .appHeader .dropdown-menu {
    position: fixed !important;
    left: 12px !important;
    right: 12px !important;
    top: calc(var(--absenki-mobile-header) + 8px) !important;
    width: auto !important;
    max-width: none !important;
    transform: none !important;
  }

  #sidebarPanel .modal-dialog { width: min(88vw, 350px); max-width: min(88vw, 350px); }
  #sidebarPanel .modal-content { border-radius: 0 22px 22px 0 !important; }
  #sidebarPanel .modal-body { max-height: calc(var(--absenki-vh, 1vh) * 100); overflow-y: auto; }
  .sidebar-nav .nav-link { min-height: 50px; }

  /* Main student content */
  #appCapsule {
    width: 100%;
    padding-top: calc(var(--absenki-mobile-header) + 8px) !important;
    padding-bottom: calc(var(--absenki-mobile-bottom) + env(safe-area-inset-bottom) + 14px) !important;
  }
  #appCapsule.extra-header-active { padding-top: calc(var(--absenki-mobile-header) + 56px) !important; }
  .section { padding-left: var(--absenki-mobile-gutter) !important; padding-right: var(--absenki-mobile-gutter) !important; }
  .section.full { padding-left: 0 !important; padding-right: 0 !important; }
  .section-title.large { font-size: 1.15rem; }
  .card, .wallet-card, .wide-block { border-radius: 18px; }
  .card-body { padding: 16px; overflow-wrap: anywhere; }

  .wallet-card-section { padding-top: 4px !important; }
  .wallet-card { margin: 0; padding: 16px 12px; }
  .wallet-card .balance {
    display: grid !important;
    grid-template-columns: 1fr;
    gap: 8px;
    align-items: start;
  }
  .wallet-card .balance .left { width: 100%; min-width: 0; }
  .wallet-card .balance .left:last-child { text-align: left !important; }
  .wallet-card .wallet-footer {
    display: grid !important;
    grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
    gap: 14px 8px !important;
    overflow: visible !important;
  }
  .wallet-card .wallet-footer .item { min-width: 0 !important; width: auto !important; }
  .wallet-card .wallet-footer .icon-wrapper { width: 52px !important; height: 52px !important; border-radius: 16px !important; }
  .wallet-card .wallet-footer .item strong {
    max-width: 92px !important;
    min-height: 2.35em;
    font-size: 11px !important;
    line-height: 1.15 !important;
    overflow-wrap: anywhere;
  }

  /* Bottom phone navigation */
  .appBottomMenu {
    min-height: calc(var(--absenki-mobile-bottom) + env(safe-area-inset-bottom));
    height: auto !important;
    padding: 3px 4px env(safe-area-inset-bottom) !important;
    justify-content: flex-start !important;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
    box-shadow: 0 -8px 28px rgba(15,23,42,.09);
  }
  .appBottomMenu::-webkit-scrollbar { display: none; }
  .appBottomMenu .item {
    flex: 1 0 64px;
    min-width: 64px;
    max-width: 92px;
    height: 58px !important;
    padding: 2px 1px;
  }
  .appBottomMenu .item .col { padding: 0 2px; }
  .appBottomMenu .item ion-icon, .appBottomMenu .item .icon { font-size: 22px; margin-bottom: 2px; }
  .appBottomMenu .item strong {
    margin-top: 1px;
    min-height: 2.1em;
    font-size: 9px;
    line-height: 1.05;
    white-space: normal;
    overflow-wrap: anywhere;
  }

  /* Forms */
  .form-group.basic .form-control,
  .form-control,
  .custom-select,
  select.form-control { min-height: 48px; border-radius: 13px; }
  textarea.form-control { min-height: 110px; }
  .form-button-group {
    left: 0 !important;
    right: 0 !important;
    padding: 10px 12px calc(10px + env(safe-area-inset-bottom)) !important;
  }
  .form-button-group .btn { min-height: 48px; border-radius: 14px; }
  .btn-block, .form-button-group .btn { width: 100%; }
  .input-group { flex-wrap: nowrap; }

  /* Tables and reports */
  .table-responsive,
  .dataTables_wrapper,
  .absenki-mobile-scroll {
    width: 100%;
    max-width: 100%;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
  }
  .table-responsive > table,
  .dataTables_wrapper table { min-width: 650px; }
  .dataTables_wrapper .row { margin-left: 0; margin-right: 0; }
  .dataTables_wrapper .dataTables_filter,
  .dataTables_wrapper .dataTables_length { width: 100%; text-align: left !important; }
  .dataTables_wrapper .dataTables_filter input { width: 100% !important; margin: 6px 0 10px !important; }
  .dataTables_wrapper .pagination { flex-wrap: wrap; justify-content: center; }

  /* Camera/scanner */
  #reader, .reader, .scanner-card, .scan-shell { width: 100% !important; max-width: 100% !important; }
  #reader { min-height: 260px !important; border-radius: 18px !important; }
  #reader video, #faceVideo, .camera-preview video { width: 100% !important; height: auto !important; max-height: 58vh; object-fit: cover; }
  .absen-location-status { font-size: 13px !important; border-radius: 14px !important; }

  /* Dialogs become phone-friendly sheets */
  .modal-dialog:not(#sidebarPanel .modal-dialog) {
    width: calc(100% - 16px);
    max-width: none;
    margin: 8px auto;
    min-height: calc(100% - 16px);
    display: flex;
    align-items: flex-end;
  }
  .modal-content { max-height: calc(var(--absenki-vh, 1vh) * 100 - 16px); overflow: hidden; border-radius: 22px 22px 0 0 !important; }
  .modal-body { overflow-y: auto; -webkit-overflow-scrolling: touch; }
  .modal-footer { display: grid; grid-template-columns: 1fr; gap: 8px; }
  .modal-footer .btn { width: 100%; margin: 0 !important; min-height: 46px; }

  /* Offline status stays above bottom navigation */
  .absenki-network-bar {
    left: 8px !important;
    right: 8px !important;
    bottom: calc(var(--absenki-mobile-bottom) + env(safe-area-inset-bottom) + 7px) !important;
    max-width: none !important;
    font-size: 12px;
  }
  .absenki-sync-sheet { width: 100% !important; border-radius: 22px 22px 0 0 !important; }
  .absenki-sync-grid { grid-template-columns: repeat(2, 1fr) !important; }

  /* Public login */
  body:not(.admin-shell) #appCapsule .form-login .card { box-shadow: 0 14px 35px rgba(15,23,42,.08); }
}

@media (max-width: 359.98px) {
  .wallet-card .wallet-footer { grid-template-columns: repeat(2, minmax(0,1fr)) !important; }
  .appBottomMenu .item { min-width: 61px; }
}

/* ABSENKI student phone refinement v2. */
@media (max-width: 767.98px) {
  :root {
    --absenki-mobile-gutter: clamp(10px, 3.4vw, 14px);
    --absenki-mobile-header: 58px;
    --absenki-mobile-bottom: 66px;
  }

  body,
  #appCapsule,
  .section,
  .card,
  .wide-block,
  .wallet-card {
    max-width: 100%;
  }

  #sidebarPanel .modal-dialog {
    width: min(86vw, 330px) !important;
    max-width: min(86vw, 330px) !important;
    margin: 0 !important;
  }

  #sidebarPanel .modal-content {
    width: 100%;
    height: calc(var(--absenki-vh, 1vh) * 100);
    max-height: calc(var(--absenki-vh, 1vh) * 100);
    border-radius: 0 22px 22px 0 !important;
  }

  #sidebarPanel .modal-body {
    width: 100%;
    overflow-x: hidden !important;
    overscroll-behavior: contain;
  }

  .sidebar-nav,
  .sidebar-nav .nav,
  .sidebar-nav .nav-item { width: 100%; min-width: 0; }

  .sidebar-nav .nav-link {
    width: auto;
    min-width: 0;
    margin: 2px 7px !important;
    padding: 10px 12px !important;
    min-height: 48px;
    gap: 11px;
    font-size: .9rem;
    line-height: 1.25;
  }

  .sidebar-nav .nav-label {
    min-width: 0;
    white-space: normal;
    overflow-wrap: anywhere;
  }

  .sidebar-nav .nav-icon {
    width: 35px;
    height: 35px;
    flex: 0 0 35px;
  }

  #appCapsule h1,
  #appCapsule h2,
  #appCapsule h3,
  #appCapsule h4,
  #appCapsule h5,
  #appCapsule p,
  #appCapsule .section-title,
  #appCapsule .card-title {
    max-width: 100%;
    overflow-wrap: anywhere;
  }

  #appCapsule h1 { font-size: clamp(1.35rem, 6vw, 1.7rem); line-height: 1.25; }
  #appCapsule h2 { font-size: clamp(1.18rem, 5vw, 1.45rem); line-height: 1.3; }
  #appCapsule h3 { font-size: clamp(1.02rem, 4.6vw, 1.22rem); line-height: 1.35; }

  .appBottomMenu .item {
    min-width: 66px;
    max-width: none;
  }

  .appBottomMenu .item strong {
    font-size: clamp(8.5px, 2.5vw, 10px);
    line-height: 1.08;
  }
}

@media (max-width: 374.98px) {
  #sidebarPanel .modal-dialog {
    width: calc(100vw - 38px) !important;
    max-width: calc(100vw - 38px) !important;
  }
}
