/* Tampilan "aplikasi native" (iOS/Android) untuk shell admin /web — HANYA HP (<768px).
   Semua aturan di bawah html.web-native, kelas yang dipasang web-native.js hanya bila
   halaman punya sidebar+header shell (halaman login/publik tidak terpengaruh). */

/* Transisi antarhalaman ala native (Chrome/Safari 18.2+; peramban lain mengabaikan). */
@view-transition { navigation: auto; }
::view-transition-old(root) { animation: 120ms ease-out both wn-fade-out; }
::view-transition-new(root) { animation: 200ms ease-out both wn-fade-in; }
@keyframes wn-fade-out { to { opacity: 0; } }
@keyframes wn-fade-in { from { opacity: 0; transform: translateY(6px); } }

.wn-tabbar, .wn-ptr { display: none; }

@media (max-width: 767px) {
  html.web-native {
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    overscroll-behavior-y: none;
    touch-action: manipulation;
  }
  html.web-native body { -webkit-font-smoothing: antialiased; }
  /* Kontrol & kerangka tidak bisa diseleksi/di-long-press seperti halaman web; isi tetap bisa. */
  html.web-native :is(button, nav, header, th, label, .bi, [role="button"], [data-select-toggle]) { -webkit-user-select: none; user-select: none; }
  html.web-native :is(a, img) { -webkit-touch-callout: none; }
  html.web-native :is(input, textarea, [contenteditable]) { -webkit-user-select: text; user-select: text; }

  /* Umpan balik sentuh: menekan = sedikit mengecil, tanpa hover "menempel". */
  html.web-native :is(button, a[class*="rounded"], [role="button"], summary) {
    transition: transform .12s ease, background-color .15s ease, opacity .15s ease;
  }
  html.web-native :is(button, a[class*="rounded"], [role="button"]):not(:disabled):active { transform: scale(.96); }

  /* Ruang untuk tab bar bawah (+ area aman iPhone). */
  /* CANGKANG TERKUNCI (pola SMKP/Portal LSW): jendela tak pernah bergulir; body = area gulir sendiri, setinggi layar
     (inset:0). Bar position:fixed bottom:0 lalu selalu menempel di dasar layar, tak bergantung pada tinggi viewport
     "dinamis" iOS/Android yang membuatnya melayang. min-height:0 menimpa .min-h-screen (100vh > area terlihat di iOS). */
  html.web-native.has-tabbar { height: 100%; overflow: hidden; }
  html.web-native.has-tabbar body {
    position: fixed; top: 0; right: 0; bottom: 0; left: 0; width: 100%; height: auto; min-height: 0 !important;
    overflow-x: hidden; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior-y: contain;
    padding-bottom: calc(64px + env(safe-area-inset-bottom));
  }
  html.web-native.web-typing body { padding-bottom: 0; }

  /* App bar: judul tebal, blur kaca, garis halus. */
  html.web-native header.fixed { background: rgba(255,255,255,.88); -webkit-backdrop-filter: saturate(180%) blur(14px); backdrop-filter: saturate(180%) blur(14px); border-bottom-color: rgba(15,23,42,.06); view-transition-name: wn-head; }
  html.web-native header.fixed h1 { font-size: 1.05rem; letter-spacing: -.01em; }

  /* Kartu & panel: sudut lebih bulat, bayangan lembut ala iOS grouped list. */
  html.web-native main :is(.rounded-2xl) { border-radius: 18px; }

  /* Sidebar = laci gaya native (sudut kanan bulat, area aman). */
  html.web-native #sidebar { border-radius: 0 22px 22px 0; padding-top: env(safe-area-inset-top); padding-bottom: env(safe-area-inset-bottom); width: min(84vw, 320px); }

  /* Modal = bottom sheet: menempel di bawah, sudut atas bulat, gagang, naik dari bawah. */
  html.web-native [data-modal-panel].fixed.inset-0 { align-items: flex-end; padding: 0; }
  html.web-native [data-modal-panel].fixed.inset-0 > div {
    width: 100%; max-width: 100%; max-height: 88vh; max-height: 88dvh; overflow-y: auto; overscroll-behavior: contain;
    border-radius: 22px 22px 0 0; padding-bottom: calc(1.5rem + env(safe-area-inset-bottom));
    animation: wn-sheet .28s cubic-bezier(.2,.8,.2,1);
  }
  html.web-native [data-modal-panel].fixed.inset-0 > div::before { content: ""; display: block; width: 38px; height: 4px; border-radius: 4px; background: #cbd5e1; margin: -8px auto 14px; }
  @keyframes wn-sheet { from { transform: translateY(100%); } }

  /* Toast naik di atas tab bar. */
  html.web-native.has-tabbar #amiraToastHost, html.web-native.has-tabbar .amira-toast-host { bottom: calc(76px + env(safe-area-inset-bottom)) !important; }

  /* Tab bar bawah. */
  html.web-native .wn-tabbar {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 35;
    padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
    background: rgba(255,255,255,.92); -webkit-backdrop-filter: saturate(180%) blur(18px); backdrop-filter: saturate(180%) blur(18px);
    border-top: 1px solid rgba(15,23,42,.08); view-transition-name: wn-tabs;
  }
  html.web-native.web-typing .wn-tabbar { display: none; }
  .wn-tab { flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-height: 48px; border-radius: 14px; color: #64748b; font-size: 10.5px; font-weight: 600; text-decoration: none; background: none; border: 0; cursor: pointer; }
  .wn-tab i { font-size: 22px; line-height: 1; transition: transform .2s cubic-bezier(.3,1.6,.5,1); }
  .wn-tab span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .wn-tab.is-active { color: #006A63; }
  .wn-tab.is-active i { transform: translateY(-1px) scale(1.12); }
  .wn-tab:focus-visible { outline: 2px solid #006A63; outline-offset: -2px; }

  /* Tarik-untuk-muat-ulang (hanya mode terpasang/standalone). */
  html.web-native .wn-ptr { display: flex; position: fixed; top: 64px; left: 50%; z-index: 36; width: 38px; height: 38px; margin-left: -19px; align-items: center; justify-content: center; border-radius: 50%; background: #fff; color: #006A63; box-shadow: 0 4px 14px rgba(15,23,42,.18); opacity: 0; transform: translateY(-60px); pointer-events: none; }
  html.web-native .wn-ptr.is-loading i { animation: wn-spin .7s linear infinite; }
  @keyframes wn-spin { to { transform: rotate(360deg); } }
}

@media (prefers-reduced-motion: reduce) {
  ::view-transition-old(root), ::view-transition-new(root) { animation: none; }
  html.web-native [data-modal-panel].fixed.inset-0 > div { animation: none; }
}

/* ── Tombol aksi melayang (FAB) + menu lingkaran ─────────────────────────────
   Elemen dengan data-fab-label (tombol "Tambah ..." di halaman) disembunyikan di HP dan
   digantikan SATU tombol + di kanan bawah; ketuk -> menu lingkaran. Sumber: web-native.js. */
.wn-fab, .wn-fab-scrim, .wn-fab-items { display: none; }
@media (max-width: 767px) {
  html.web-native.has-fab [data-fab-label] { display: none !important; }
  html.web-native.has-fab .wn-fab-scrim { display: block; position: fixed; inset: 0; z-index: 36; background: rgba(15,23,42,.45); -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px); opacity: 0; pointer-events: none; transition: opacity .2s; }
  html.web-native.has-fab.fab-open .wn-fab-scrim { opacity: 1; pointer-events: auto; }
  html.web-native.has-fab .wn-fab {
    display: flex; position: fixed; right: 16px; z-index: 38; width: 56px; height: 56px; align-items: center; justify-content: center;
    bottom: calc(76px + env(safe-area-inset-bottom)); border: 0; border-radius: 50%; background: #006A63; color: #fff; font-size: 26px;
    box-shadow: 0 6px 18px rgba(0,106,99,.45), 0 2px 6px rgba(15,23,42,.25); transition: transform .25s cubic-bezier(.3,1.4,.5,1), background-color .2s;
  }
  html.web-native.has-fab .wn-fab i { transition: transform .25s; line-height: 1; }
  html.web-native.has-fab.fab-open .wn-fab { background: #0f172a; }
  html.web-native.has-fab.fab-open .wn-fab i { transform: rotate(135deg); }
  html.web-native.has-fab.web-typing .wn-fab { display: none; }
  html.web-native.has-fab .wn-fab-items { display: block; position: fixed; right: 16px; z-index: 37; width: 56px; height: 56px; bottom: calc(76px + env(safe-area-inset-bottom)); pointer-events: none; }
  .wn-fab-item {
    position: absolute; left: 50%; top: 50%; width: 62px; height: 62px; margin: -31px 0 0 -31px; border: 0; border-radius: 50%;
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; background: #fff; color: #006A63;
    font-size: 10px; font-weight: 700; line-height: 1; box-shadow: 0 6px 16px rgba(15,23,42,.28);
    opacity: 0; transform: translate(0,0) scale(.3); transition: transform .28s cubic-bezier(.3,1.4,.5,1), opacity .18s; pointer-events: none;
  }
  .wn-fab-item i { font-size: 20px; line-height: 1; }
  html.fab-open .wn-fab-item { opacity: 1; pointer-events: auto; transform: translate(var(--fx), var(--fy)) scale(1); transition-delay: calc(var(--fi) * 30ms); }
  html.web-native.has-fab :is(.wn-fab, .wn-fab-item):focus-visible { outline: 2px solid #fff; outline-offset: 2px; box-shadow: 0 0 0 4px #006A63; }
}
@media (prefers-reduced-motion: reduce) { .wn-fab, .wn-fab i, .wn-fab-item, .wn-fab-scrim { transition: none !important; } }

/* ── Kolom pertama tabel dibekukan (sticky) saat tabel digeser ke samping ───────
   Berlaku untuk tabel di dalam pembungkus .overflow-x-auto (semua ukuran layar).
   Bila kolom pertama berisi checkbox (mode Pilih), kolom ke-2 (nama) ikut dibekukan; lebar
   kolom checkbox diukur web-native.js ke --wn-c1w. Tabel yang tak boleh: data-no-freeze. */
html.web-native .overflow-x-auto table:not([data-no-freeze]):not(.mobile-card-table) > :is(thead, tbody, tfoot) > tr > :is(th, td):first-child {
  position: sticky; left: 0; z-index: 2; background-color: #fff; box-shadow: 1px 0 0 #e2e8f0, 4px 0 6px -4px rgba(15,23,42,.18);
}
html.web-native .overflow-x-auto table:not([data-no-freeze]):not(.mobile-card-table) > thead > tr > th:first-child { background-color: #f8fafc; z-index: 3; }
html.web-native .overflow-x-auto table:not([data-no-freeze]):not(.mobile-card-table) > tbody > tr:hover > td:first-child { background-color: #f8fafc; }
/* Kolom pertama teks (bukan checkbox): batasi lebar supaya tidak memakan layar. */
html.web-native .overflow-x-auto table:not([data-no-freeze]):not(.mobile-card-table) > :is(tbody, tfoot) > tr > td:first-child:not(:has(> input[type="checkbox"])) { min-width: 6.5rem; max-width: 10rem; overflow-wrap: anywhere; }
/* Tabel dengan checkbox di kolom pertama: bekukan juga kolom ke-2. */
html.web-native .overflow-x-auto table.wn-frz2:not([data-no-freeze]) > :is(thead, tbody, tfoot) > tr > :is(th, td):nth-child(2) {
  position: sticky; left: var(--wn-c1w, 44px); z-index: 2; background-color: #fff; box-shadow: 1px 0 0 #e2e8f0, 4px 0 6px -4px rgba(15,23,42,.18);
}
html.web-native .overflow-x-auto table.wn-frz2 > thead > tr > th:nth-child(2) { background-color: #f8fafc; z-index: 3; }
html.web-native .overflow-x-auto table.wn-frz2 > tbody > tr:hover > td:nth-child(2) { background-color: #f8fafc; }
html.web-native .overflow-x-auto table.wn-frz2 > :is(thead, tbody, tfoot) > tr > :is(th, td):first-child { box-shadow: none; }

@media (max-width: 767px) { html.web-native.has-fab.fab-empty :is(.wn-fab, .wn-fab-items, .wn-fab-scrim) { display: none !important; } }

@media (max-width: 767px) { .wn-fab-item { text-decoration: none; -webkit-tap-highlight-color: transparent; } .wn-fab-item:hover { color: #006A63; } }

/* ── Tab bar tidak "melayang" di PWA iOS/Android ───────────────────────────────────────────
   Di mode terpasang, viewport layout bisa LEBIH PENDEK dari layar (bug WebKit 301108 di iOS: setinggi
   status bar; sebagian Android: bilah gestur) sehingga bar position:fixed bottom:0 berhenti di atas
   tepi layar dan menyisakan celah berlatar halaman. Dua lapis perbaikan, keduanya aman bila bug tak terjadi:
   1) html diperpanjang sampai tinggi layar penuh (resep frappe-ui #1289, sama dgn SMKP);
   2) "rok" di bawah bar: ::after berlatar sama (kaca putih) yang menutup celah apa pun di bawahnya. */
@media (max-width: 767px) {
  html.web-native .wn-tabbar::after {
    content: ""; position: absolute; left: 0; right: 0; top: 100%; height: 160px;
    background: rgba(255,255,255,.92); pointer-events: none;
  }
  /* tanpa backdrop-filter pada rok: filter bar tak menjalar; warna sama menjaga kesinambungan */
}

/* Item menu FAB: bulatan KECIL (54px) bertulisan kecil, disusun melengkung (lihat JS) supaya semuanya muat di layar. */
@media (max-width: 767px) {
  html.web-native .wn-fab-item {
    width: 54px; height: 54px; margin: -27px 0 0 -27px; padding: 2px; gap: 2px; font-size: 9px; font-weight: 700; line-height: 1.05;
    text-align: center; flex-direction: column; justify-content: center; overflow: hidden; white-space: normal; transform-origin: center;
  }
  html.web-native .wn-fab-item i { font-size: 18px; }
  html.web-native .wn-fab-item span { display: block; max-width: 100%; overflow-wrap: anywhere; }
}
