/* =================================================================
   GAYA BERSAMA ALA APLIKASI MOBILE
   Dipakai semua halaman lewat partials/app.php
   ================================================================= */

:root {
    --app-primary: #4F46E5;
    --app-tabbar-h: 60px;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* Transisi halus antar halaman (Chrome/Edge terbaru), mirip perpindahan layar di aplikasi */
@view-transition { navigation: auto; }

html { -webkit-tap-highlight-color: transparent; }
a, button, select, label, input[type="checkbox"] { touch-action: manipulation; }

/* ---------- App bar atas (khusus HP) ---------- */
.app-topbar {
    position: sticky;
    top: 0;
    z-index: 40;
    padding-top: var(--safe-top);
    background-color: var(--app-primary);
    color: #fff;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
    view-transition-name: app-topbar;
    -webkit-user-select: none;
    user-select: none;
}

/* ---------- Tab bar bawah (khusus HP) ---------- */
.app-tabbar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 40;
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    padding-bottom: var(--safe-bottom);
    background-color: rgba(255, 255, 255, 0.97);
    border-top: 1px solid #e5e7eb;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.05);
    view-transition-name: app-tabbar;
    -webkit-user-select: none;
    user-select: none;
}
@supports (backdrop-filter: blur(8px)) {
    .app-tabbar { background-color: rgba(255, 255, 255, 0.88); backdrop-filter: blur(8px); }
}
.app-tabbar a {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    height: var(--app-tabbar-h);
    padding: 0 2px;
    color: #6b7280;
    font-size: 11px;
    line-height: 1.1;
    -webkit-touch-callout: none;
}
.app-tabbar a span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.app-tabbar a svg { width: 24px; height: 24px; transition: transform 0.15s ease; }
.app-tabbar a:active svg { transform: scale(0.88); }
.app-tabbar a.active { color: var(--app-primary); font-weight: 600; }
.app-tabbar a.active svg { stroke-width: 2.2; }

/* ---------- Tombol tambah melayang (FAB) ---------- */
.app-fab {
    position: fixed;
    right: 16px;
    bottom: calc(var(--app-tabbar-h) + var(--safe-bottom) + 16px);
    z-index: 30;
    width: 56px;
    height: 56px;
    border-radius: 9999px;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: var(--app-primary);
    color: #fff;
    box-shadow: 0 6px 16px rgba(79, 70, 229, 0.45);
    transition: transform 0.15s ease, opacity 0.15s ease;
}
.app-fab svg { width: 28px; height: 28px; }
.app-fab:active { transform: scale(0.92); }
.app-fab.is-hidden { opacity: 0; transform: scale(0.6); pointer-events: none; }

/* Form tambah tidak tertutup app bar saat digulir ke sana */
#tambah { scroll-margin-top: calc(56px + var(--safe-top) + 12px); }

/* ---------- Modal edit ---------- */
.app-modal > div { max-height: calc(100vh - 2rem); overflow-y: auto; overscroll-behavior: contain; }

/* ---------- Banner offline & petunjuk install iOS ---------- */
.app-offline-banner {
    position: fixed;
    left: 0;
    right: 0;
    top: 0;
    z-index: 1100;
    padding: calc(var(--safe-top) + 6px) 12px 6px;
    background-color: #f59e0b;
    color: #1f2937;
    font-size: 13px;
    font-weight: 600;
    text-align: center;
}
.app-sheet-backdrop {
    position: fixed;
    inset: 0;
    z-index: 1100;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    background-color: rgba(0, 0, 0, 0.4);
}
.app-sheet {
    width: 100%;
    max-width: 28rem;
    background-color: #fff;
    border-radius: 1rem 1rem 0 0;
    padding: 1.5rem 1.25rem calc(1.25rem + var(--safe-bottom));
    animation: app-sheet-up 0.25s ease-out;
}

@keyframes app-sheet-up {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}

/* ---------- Penyesuaian layar HP ---------- */
@media (max-width: 767px) {
    /* Ruang kosong di bawah agar konten tidak tertutup tab bar */
    body { padding-bottom: calc(var(--app-tabbar-h) + var(--safe-bottom)); }

    /* Font input minimal 16px supaya iPhone tidak otomatis zoom saat mengetik */
    input, select, textarea { font-size: 16px !important; }

    .app-footer { display: none; }

    /* Modal edit tampil sebagai "bottom sheet" dari bawah layar */
    .app-modal { align-items: flex-end !important; padding: 0 !important; }
    .app-modal > div {
        max-width: none !important;
        max-height: 92vh;
        border-radius: 1rem 1rem 0 0 !important;
        padding-bottom: calc(1.5rem + var(--safe-bottom)) !important;
        animation: app-sheet-up 0.25s ease-out;
    }
}

@media (min-width: 768px) {
    .app-topbar, .app-tabbar, .app-fab { display: none; }
}

@media (prefers-reduced-motion: reduce) {
    @view-transition { navigation: none; }
    .app-sheet, .app-modal > div { animation: none !important; }
}
