/* ============================================================
   GYMBEEM LAYOUT - App Structure with Safe Area
   ============================================================ */

/* ============================================================
   ROOT VARIABLES - SAFE AREA
   ============================================================ */
:root {
    /* Safe area untuk iPhone (notch, home indicator) */
    --safe-area-inset-top: env(safe-area-inset-top, 0px);
    --safe-area-inset-bottom: env(safe-area-inset-bottom, 0px);
    --safe-area-inset-left: env(safe-area-inset-left, 0px);
    --safe-area-inset-right: env(safe-area-inset-right, 0px);
    
    /* Fallback untuk browser yang tidak support */
    --safe-top: max(0px, var(--safe-area-inset-top));
    --safe-bottom: max(0px, var(--safe-area-inset-bottom));
    --safe-left: max(0px, var(--safe-area-inset-left));
    --safe-right: max(0px, var(--safe-area-inset-right));
    
    /* Height dengan safe area - HEADER DIKECILKAN */
    --header-height: 44px;
    --nav-height: 64px;
    --header-total: calc(var(--header-height) + var(--safe-top));
    --nav-total: calc(var(--nav-height) + var(--safe-bottom));
}

/* ============================================================
   BODY - PADDING MINIMAL
   ============================================================ */
body {
    padding-top: var(--header-total);
    padding-bottom: var(--nav-total);
    padding-left: var(--safe-left);
    padding-right: var(--safe-right);
    min-height: 100vh;
    min-height: 100dvh;
}

/* ============================================================
   APP CONTAINER
   ============================================================ */
.app-container {
    max-width: 100%;
    margin: 0 auto;
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
}

/* ============================================================
   HEADER - KOMPAK, TIDAK MEMAKAN BANYAK RUANG
   ============================================================ */
.app-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 100;
    height: var(--header-total);
    padding-top: var(--safe-top);
    padding-left: max(12px, var(--safe-left));
    padding-right: max(12px, var(--safe-right));
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    display: flex;
    align-items: center;
    transition: background 0.3s ease, border-color 0.3s ease;
}

.header-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    height: var(--header-height);
    max-width: 480px;
    margin: 0 auto;
}

.header-left {
    display: flex;
    align-items: center;
    min-width: 36px;
}

.header-brand {
    display: flex;
    align-items: center;
    gap: var(--space-1);
    color: var(--primary);
    text-decoration: none;
}

.brand-text {
    font-weight: 700;
    font-size: 15px;
    letter-spacing: -0.5px;
    color: var(--text);
}

.header-center {
    flex: 1;
    text-align: center;
    padding: 0 var(--space-1);
}

.header-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
    letter-spacing: -0.3px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.header-right {
    display: flex;
    align-items: center;
    gap: var(--space-1);
    min-width: 36px;
    justify-content: flex-end;
}

.header-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.header-btn:hover {
    background: var(--bg-hover);
}

.header-btn:active {
    transform: scale(0.92);
}

.header-btn svg {
    width: 18px;
    height: 18px;
    stroke: currentColor;
}

/* ============================================================
   MAIN CONTENT - FULL, MANFAATKAN SEMUA RUANG
   ============================================================ */
.app-main {
    flex: 1;
    padding: 4px max(12px, var(--safe-left)) 4px max(12px, var(--safe-right));
    max-width: 480px;
    width: 100%;
    margin: 0 auto;
}

.app-content {
    animation: fadeIn 0.3s ease;
}

/* ============================================================
   BOTTOM NAV - KOMPAK
   ============================================================ */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 100;
    height: var(--nav-total);
    padding-bottom: var(--safe-bottom);
    padding-left: var(--safe-left);
    padding-right: var(--safe-right);
    background: var(--bg-card);
    border-top: 1px solid var(--border);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    display: flex;
    align-items: stretch;
    transition: background 0.3s ease, border-color 0.3s ease;
}

.nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0px;
    text-decoration: none;
    color: var(--text-muted);
    font-size: 9px;
    font-weight: 500;
    padding: 2px 0;
    cursor: pointer;
    transition: color 0.2s ease;
    user-select: none;
}

.nav-item svg {
    width: 20px;
    height: 20px;
    stroke: currentColor;
    transition: transform 0.2s ease;
}

.nav-item .nav-label {
    font-size: 8px;
    letter-spacing: 0.2px;
}

.nav-item.active {
    color: var(--primary);
}

.nav-item.active svg {
    transform: scale(1.05);
}

.nav-item:active {
    transform: scale(0.92);
}

/* ============================================================
   TOAST - DENGAN SAFE AREA (DI layout.css)
   ============================================================ */
#toast-container {
    position: fixed;
    bottom: calc(var(--nav-total) + 16px);
    left: max(10px, var(--safe-left));
    right: max(10px, var(--safe-right));
    z-index: 99999;
    max-width: 480px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 6px;
    pointer-events: none;
}

/* Di mobile, ubah agar full width */
@media (max-width: 576px) {
    #toast-container {
        left: 0;
        right: 0;
        bottom: calc(var(--nav-total) + 12px);
        padding: 0 12px;
        max-width: 100%;
    }
}

@media (max-width: 400px) {
    #toast-container {
        padding: 0 8px;
        bottom: calc(var(--nav-total) + 8px);
    }
}

/* ============================================================
   MODAL - DENGAN SAFE AREA
   ============================================================ */
.modal-dialog {
    margin: max(10px, var(--safe-top)) auto;
}

.modal-content {
    border-radius: 24px !important;
    border: none !important;
    background: var(--bg-card) !important;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3) !important;
    color: var(--text) !important;
}

/* ============================================================
   PWA INSTALL BANNER - DENGAN SAFE AREA
   ============================================================ */
.pwa-install-banner {
    position: fixed;
    bottom: calc(var(--nav-total) + 8px);
    left: max(10px, var(--safe-left));
    right: max(10px, var(--safe-right));
    z-index: 99998;
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    box-shadow: 0 8px 30px rgba(0,0,0,0.15);
    border: 1px solid var(--border-light);
    padding: 10px 14px;
    animation: slideUpBanner 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    max-width: 480px;
    margin: 0 auto;
}

/* ============================================================
   RESPONSIVE - UMUM
   ============================================================ */
@media (max-width: 360px) {
    .nav-item svg { width: 18px; height: 18px; }
    .nav-item .nav-label { font-size: 7px; }
    .header-title { font-size: 13px; }
    .app-main {
        padding: 2px max(8px, var(--safe-left)) 2px max(8px, var(--safe-right));
    }
    .header-btn { width: 28px; height: 28px; }
    .header-btn svg { width: 16px; height: 16px; }
    .header-left { min-width: 30px; }
    .header-right { min-width: 30px; }
}

@media (min-width: 768px) {
    .app-main { max-width: 560px; }
    .header-inner { max-width: 560px; }
}

@media (min-width: 1024px) {
    .app-main { max-width: 600px; }
    .header-inner { max-width: 600px; }
}

/* ============================================================
   RESPONSIVE - IPHONE SPECIFIC
   ============================================================ */

/* iPhone 12/13/14 (notch) */
@supports (padding: max(0px)) {
    .app-header {
        padding-top: max(8px, var(--safe-top));
        height: calc(var(--header-height) + var(--safe-top));
    }
    .bottom-nav {
        padding-bottom: max(0px, var(--safe-bottom));
        height: calc(var(--nav-height) + var(--safe-bottom));
    }
    body {
        padding-top: calc(var(--header-height) + var(--safe-top));
        padding-bottom: calc(var(--nav-height) + var(--safe-bottom) + 4px);
    }
}

/* iPhone 14 Pro / 15 Pro (Dynamic Island) */
@supports (padding: max(0px)) and (height: 852px) {
    .app-header {
        padding-top: max(12px, var(--safe-top));
    }
}

/* iPhone SE (home button) - tanpa notch */
@media only screen and (max-width: 375px) and (max-height: 667px) {
    .app-header {
        padding-top: max(4px, var(--safe-top));
    }
    .bottom-nav {
        padding-bottom: max(0px, var(--safe-bottom));
    }
    body {
        padding-top: calc(var(--header-height) + var(--safe-top));
        padding-bottom: calc(var(--nav-height) + var(--safe-bottom) + 2px);
    }
}

/* iPhone X, XS, 11 Pro, 12, 13, 14 (notch) */
@media only screen and (min-width: 375px) and (max-width: 430px) and (min-height: 780px) {
    .app-header {
        padding-top: max(8px, var(--safe-top));
    }
    .bottom-nav {
        padding-bottom: max(4px, var(--safe-bottom));
    }
}

/* ============================================================
   LANDSCAPE MODE - IPHONE
   ============================================================ */
@media only screen and (orientation: landscape) and (max-height: 500px) {
    .app-header {
        height: calc(36px + var(--safe-top));
        padding-top: var(--safe-top);
    }
    .header-inner {
        height: 36px;
    }
    .bottom-nav {
        height: calc(44px + var(--safe-bottom));
        padding-bottom: var(--safe-bottom);
    }
    .nav-item svg {
        width: 16px;
        height: 16px;
    }
    .nav-item .nav-label {
        font-size: 7px;
    }
    .header-title {
        font-size: 12px;
    }
    .app-main {
        padding: 2px max(8px, var(--safe-left)) 2px max(8px, var(--safe-right));
    }
    body {
        padding-top: calc(36px + var(--safe-top));
        padding-bottom: calc(44px + var(--safe-bottom) + 2px);
    }
    #toast-container {
        bottom: calc(44px + var(--safe-bottom) + 4px);
    }
}

/* ============================================================
   GLOBAL RESET UNTUK MOBILE
   ============================================================ */
* {
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
}

html {
    -webkit-text-size-adjust: 100%;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Prevent zoom on input focus (iOS) */
input, select, textarea, button {
    font-size: 16px !important;
}

/* Fix 100vh issue on iOS Safari */
@supports (-webkit-touch-callout: none) {
    .app-container,
    body {
        min-height: -webkit-fill-available;
    }
}