/* ==========================================================================
   LolosASN — Mobile Native iOS PWA Layer
   Desktop (> 768px) tidak tersentuh sama sekali.
   ========================================================================== */

.mobile-tabbar,
.ios-sheet-backdrop,
.ios-sheet,
.pwa-install-banner,
.mobile-only-inline {
  display: none !important;
}

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

@media (max-width: 768px) {
  html,
  body {
    -webkit-tap-highlight-color: transparent;
    overscroll-behavior-y: contain;
  }

  /* Cegah Safari iOS auto-zoom saat mengetik di input */
  input,
  textarea,
  select {
    font-size: 16px !important;
  }

  button,
  .btn,
  .nav-item,
  .option-btn,
  .ios-tab-btn {
    touch-action: manipulation;
  }

  .mobile-only-inline {
    display: inline-flex !important;
  }

  /* Sembunyikan hamburger menu & teks judul panjang di mobile — ganti header logo ala Native App */
  #btnOpenSidebar,
  #btnOpenAdminSidebar,
  .topbar-title-wrap {
    display: none !important;
  }

  .mobile-topbar-logo {
    display: block !important;
    width: auto;
    height: 20px;
  }

  /* Compact Native iOS Navigation Bar — tanpa tabrakan */
  .topbar {
    padding: calc(10px + env(safe-area-inset-top, 0px)) 16px 10px;
    background: rgba(11, 11, 12, 0.86);
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    flex-wrap: nowrap;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
  }

  .topbar-left {
    min-width: 0;
    flex: 1;
    gap: 10px;
  }

  .topbar-left > div {
    min-width: 0;
    flex: 1;
  }

  .breadcrumb {
    display: none;
  }

  .page-title {
    font-size: 15.5px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  /* Sidebar Drawer (Hamburger Menu) nyaman untuk jempol & safe area */
  .sidebar {
    width: min(82vw, 300px) !important;
    padding: calc(14px + env(safe-area-inset-top, 0px)) 14px calc(22px + env(safe-area-inset-bottom, 0px)) !important;
    background: rgba(14, 14, 16, 0.98) !important;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
  }

  .acct-popover {
    position: fixed !important;
    left: 12px !important;
    right: 12px !important;
    top: calc(58px + env(safe-area-inset-top, 0px)) !important;
    width: auto !important;
    max-width: none !important;
    max-height: 76dvh;
    overflow-y: auto;
  }

  .topbar-right {
    width: auto;
    flex-shrink: 0;
    flex-wrap: nowrap;
    gap: 6px;
  }

  /* Sembunyikan tombol aksi cepat yang duplikat di topbar mobile (sudah ada di tab bawah & hero) */
  #btnQuickWeak,
  #btnQuickResume {
    display: none !important;
  }

  .acct-pill {
    max-width: 156px;
    padding: 5px 9px;
  }

  .acct-name {
    max-width: 72px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .topbar-right .btn {
    flex: 0 0 auto;
    min-height: 36px;
    padding: 6px 10px;
    font-size: 12px;
  }

  /* Beri ruang aman di bawah agar konten tidak tertutup Bottom Tab Bar */
  .content,
  .admin-content {
    padding: 14px 14px calc(92px + env(safe-area-inset-bottom, 0px)) !important;
  }

  /* Saat sesi Drill / Simulasi CAT aktif: sembunyikan tab bar bawah agar fokus penuh & cegah salah sentuh */
  body.is-focus-session #mobileTabBar,
  body.is-focus-session .pwa-install-banner {
    display: none !important;
  }

  body.is-focus-session .content {
    padding-bottom: calc(24px + env(safe-area-inset-bottom, 0px)) !important;
  }

  /* Beranda Mobile Ringkas & Fokus Belajar */
  .hero-banner {
    padding: 16px !important;
    gap: 14px !important;
    border-radius: 18px !important;
    margin-bottom: 18px !important;
  }

  .hero-copy .eyebrow {
    font-size: 10.5px;
    margin-bottom: 6px;
  }

  .hero-copy h2 {
    font-size: 18px !important;
    line-height: 1.3 !important;
    margin-bottom: 6px !important;
  }

  .hero-actions {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    margin-top: 12px !important;
  }

  .hero-actions .btn {
    width: 100%;
    min-height: 46px;
    justify-content: center;
  }

  .readiness-box {
    display: flex !important;
    flex-direction: row !important;
    align-items: center !important;
    justify-content: space-between !important;
    gap: 10px !important;
    padding: 12px 14px !important;
    text-align: left !important;
  }

  .readiness-box .readiness-score {
    font-size: 24px !important;
    order: 2;
  }

  .readiness-box .stat-label {
    font-size: 12px;
  }

  .readiness-box .stat-sub {
    display: none;
  }

  /* Stats Grid 2x2 rapi di mobile */
  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 10px !important;
  }

  .stat-card {
    padding: 12px 14px !important;
  }

  .stat-card .stat-value {
    font-size: 22px !important;
  }

  .stat-card .stat-sub {
    display: none;
  }

  /* Sembunyikan promo marquee di mobile agar tidak mendistraksi belajar */
  .promo-marquee {
    display: none !important;
  }

  /* Filter & Grid Kurikulum di Mobile */
  .filter-bar {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  .pill-tabs {
    flex-wrap: nowrap !important;
    overflow-x: auto;
    scrollbar-width: none;
    padding-bottom: 2px;
  }

  .pill-tabs::-webkit-scrollbar {
    display: none;
  }

  .pill-filter {
    flex-shrink: 0;
    min-height: 38px;
  }

  .search-box {
    width: 100%;
  }

  .search-kbd {
    display: none !important;
  }

  .topics-grid {
    grid-template-columns: 1fr !important;
    gap: 12px !important;
  }

  .topic-card {
    padding: 16px !important;
  }

  .topic-foot {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  .topic-foot-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .topic-foot-actions .btn {
    min-height: 42px;
    justify-content: center;
  }

  /* Antrean Ulang: susun vertikal di mobile agar tombol Latih lega & mudah ditekan */
  .weak-item {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
    padding: 16px;
  }

  .weak-item > .btn {
    width: 100%;
    min-height: 44px;
    justify-content: center;
  }

  /* Kenyamanan kartu & opsi jawaban untuk jempol */
  .option-btn {
    min-height: 50px;
    padding: 12px 14px;
    border-radius: 14px;
    transition: transform 120ms ease, background-color 150ms ease, border-color 150ms ease;
  }

  .option-btn:active {
    transform: scale(0.985);
  }

  /* Modal tampil sebagai iOS Bottom Sheet */
  dialog.modal {
    margin: auto 0 0 0;
    width: 100%;
    max-width: 100%;
    max-height: 88dvh;
    border-radius: 22px 22px 0 0;
    border-bottom: none;
    padding: 20px 18px calc(22px + env(safe-area-inset-bottom, 0px));
    animation: iosSheetUp 220ms cubic-bezier(0.22, 1, 0.36, 1);
  }

  /* === FLOATING / FROSTED GLASS BOTTOM TAB BAR === */
  .mobile-tabbar {
    display: grid !important;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    align-items: stretch;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 45;
    background: rgba(15, 15, 17, 0.88);
    backdrop-filter: blur(24px) saturate(180%);
    -webkit-backdrop-filter: blur(24px) saturate(180%);
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    padding: 6px 6px calc(6px + env(safe-area-inset-bottom, 0px));
  }

  .ios-tab-btn {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    min-height: 48px;
    padding: 4px 2px;
    border: none;
    background: transparent;
    color: rgba(255, 255, 255, 0.58);
    font-family: inherit;
    font-size: 10.5px;
    font-weight: 500;
    cursor: pointer;
    transition: color 150ms ease, transform 120ms ease;
  }

  .ios-tab-btn:active {
    transform: scale(0.92);
  }

  .ios-tab-btn.active {
    color: var(--primary, #f16001);
    font-weight: 600;
  }

  .ios-tab-btn svg {
    width: 21px;
    height: 21px;
    flex-shrink: 0;
  }

  .ios-tab-badge {
    position: absolute;
    top: 2px;
    right: calc(50% - 19px);
    min-width: 17px;
    height: 17px;
    padding: 0 5px;
    border-radius: 99px;
    background: var(--primary, #f16001);
    color: #ffffff;
    font-size: 10px;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
  }

  .ios-tab-badge.is-zero {
    display: none;
  }

  /* === iOS SLIDE-UP ACTION SHEET ("Lainnya" / "Menu") === */
  .ios-sheet-backdrop {
    display: block !important;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.58);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 60;
  }

  .ios-sheet-backdrop.hidden {
    display: none !important;
  }

  .ios-sheet {
    display: flex !important;
    flex-direction: column;
    gap: 10px;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 65;
    max-height: 85dvh;
    overflow-y: auto;
    background: #141416;
    border-top: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 22px 22px 0 0;
    padding: 10px 16px calc(22px + env(safe-area-inset-bottom, 0px));
    box-shadow: 0 -16px 48px rgba(0, 0, 0, 0.65);
    animation: iosSheetUp 220ms cubic-bezier(0.22, 1, 0.36, 1);
  }

  .ios-sheet.hidden {
    display: none !important;
  }

  .ios-sheet-handle {
    width: 38px;
    height: 4px;
    border-radius: 99px;
    background: rgba(255, 255, 255, 0.24);
    margin: 2px auto 6px;
    flex-shrink: 0;
  }

  .ios-sheet-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 2px 4px 6px;
  }

  .ios-sheet-head strong {
    font-size: 15px;
  }

  .ios-sheet-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
  }

  .ios-sheet-item {
    width: 100%;
    min-height: 48px;
    padding: 12px 14px;
    border-radius: 14px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    background: rgba(255, 255, 255, 0.04);
    color: var(--text, #f5f5f7);
    font-family: inherit;
    font-size: 14px;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 12px;
    text-align: left;
    text-decoration: none;
    cursor: pointer;
  }

  .ios-sheet-item:active {
    transform: scale(0.985);
    background: rgba(255, 255, 255, 0.08);
  }

  .ios-sheet-daily {
    margin-top: 4px;
    padding: 12px 14px;
    border-radius: 14px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    background: rgba(255, 255, 255, 0.03);
  }

  /* === ADMIN AI COPILOT MOBILE CHAT-FIRST === */
  .copilot-split {
    display: block;
  }

  .copilot-chat-card {
    height: calc(100dvh - 144px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
    min-height: 400px;
    border-radius: 18px;
  }

  .copilot-chat-head {
    padding: 12px 14px;
    gap: 8px;
  }

  .copilot-chat-head .muted {
    display: none !important;
  }

  .copilot-messages {
    padding: 14px;
  }

  .chat-msg {
    max-width: 90%;
  }

  .copilot-presets {
    padding: 8px 12px;
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
  }

  .copilot-presets::-webkit-scrollbar {
    display: none;
  }

  .copilot-presets .admin-chip {
    flex-shrink: 0;
  }

  .copilot-composer {
    padding: 10px 12px;
  }

  .copilot-settings-card {
    display: none;
  }

  .copilot-settings-card.is-sheet-open {
    display: flex !important;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 65;
    max-height: 86dvh;
    overflow-y: auto;
    border-radius: 22px 22px 0 0;
    border-bottom: none;
    padding: 16px 16px calc(24px + env(safe-area-inset-bottom, 0px));
    box-shadow: 0 -16px 48px rgba(0, 0, 0, 0.7);
    animation: iosSheetUp 220ms cubic-bezier(0.22, 1, 0.36, 1);
  }

  /* === SMART PWA INSTALL BANNER === */
  .pwa-install-banner {
    display: flex !important;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    position: fixed;
    left: 12px;
    right: 12px;
    bottom: calc(70px + env(safe-area-inset-bottom, 0px));
    z-index: 44;
    padding: 10px 12px;
    border-radius: 14px;
    background: rgba(24, 24, 27, 0.94);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
    border: 1px solid rgba(255, 255, 255, 0.14);
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.45);
    font-size: 12px;
  }

  .pwa-install-banner.hidden {
    display: none !important;
  }

  .pwa-install-copy {
    min-width: 0;
    flex: 1;
    line-height: 1.35;
  }

  .pwa-install-copy strong {
    display: block;
    font-size: 12.5px;
  }

  .pwa-install-copy span {
    color: rgba(255, 255, 255, 0.7);
  }

  .pwa-install-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
  }
}
