/* ==========================================================================
   SPENDMINDAI - MOBILE & PWA APP STYLES (APPLE IOS TAB BAR STANDARD)
   Mobile Bottom Navigation, Touch Ergonomics & Responsive Enhancements
   ========================================================================== */

/* 1. Mobile Bottom Navigation Bar (Apple iOS Tab Bar) */
.mobile-bottom-nav,
.mobile-nav-bar,
#mobile-bottom-nav,
#mobile-nav-bar {
    display: none !important;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: calc(60px + env(safe-area-inset-bottom, 0px));
    padding-bottom: env(safe-area-inset-bottom, 0px);
    background: rgba(22, 22, 24, 0.82);
    backdrop-filter: blur(24px) saturate(180%);
    -webkit-backdrop-filter: blur(24px) saturate(180%);
    border-top: none !important;
    z-index: 1000;
    justify-content: space-around;
    align-items: center;
    box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.4);
}

[data-theme="light"] .mobile-bottom-nav,
[data-theme="light"] .mobile-nav-bar,
[data-theme="light"] #mobile-bottom-nav,
[data-theme="light"] #mobile-nav-bar {
    background: rgba(255, 255, 255, 0.85);
    border-top: none !important;
    box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.05);
}

.mobile-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: none;
    border: none !important;
    color: var(--text-secondary, #86868b);
    font-size: 0.65rem;
    font-weight: 500;
    letter-spacing: -0.01em;
    gap: 3px;
    padding: 6px 12px;
    min-width: 56px;
    min-height: 44px;
    cursor: pointer;
    transition: transform 0.18s cubic-bezier(0.16, 1, 0.3, 1), color 0.18s ease;
    border-radius: var(--radius-sm);
    text-decoration: none;
    -webkit-tap-highlight-color: transparent;
}

.mobile-nav-item i {
    width: 20px;
    height: 20px;
    stroke-width: 1.8;
    transition: transform 0.2s cubic-bezier(0.32, 0.72, 0, 1);
}

.mobile-nav-item:active {
    transform: scale(0.92);
}

.mobile-nav-item.active {
    color: var(--accent-color);
    font-weight: 600;
}

.mobile-nav-item.active i {
    transform: scale(1.08);
    stroke-width: 2.2;
}

/* Center Floating Add Button (+) - Apple Monochromatic */
.mobile-nav-item.nav-add-btn,
.mobile-nav-item.mobile-add-btn {
    position: relative;
    top: -12px;
    background: var(--accent-color);
    color: var(--accent-text) !important;
    width: 50px;
    height: 50px;
    min-width: 50px;
    min-height: 50px;
    border-radius: 50%;
    padding: 0;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
    border: none !important;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s cubic-bezier(0.32, 0.72, 0, 1), box-shadow 0.2s ease;
}

[data-theme="light"] .mobile-nav-item.nav-add-btn,
[data-theme="light"] .mobile-nav-item.mobile-add-btn {
    border: none !important;
}

.mobile-nav-item.nav-add-btn:active,
.mobile-nav-item.mobile-add-btn:active {
    transform: scale(0.92) translateY(2px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.mobile-nav-item.nav-add-btn i,
.mobile-nav-item.mobile-add-btn i {
    width: 24px;
    height: 24px;
    stroke-width: 2.4;
}

/* 2. Responsive Mobile Layout Adaptations */
@media (max-width: 768px) {
    .mobile-bottom-nav,
    .mobile-nav-bar,
    #mobile-bottom-nav,
    #mobile-nav-bar {
        display: flex !important;
    }

    /* Add bottom padding to dashboard so content is not obscured by bottom bar */
    .app-container {
        padding-bottom: calc(84px + env(safe-area-inset-bottom, 0px)) !important;
    }

    /* Single column layout optimized for touch */
    .app-main-grid {
        grid-template-columns: 1fr !important;
        gap: 20px !important;
    }

    /* Mobile Bottom Sheet Modal */
    .modal-overlay {
        align-items: flex-end !important;
        padding: 0 !important;
        z-index: 10000 !important;
    }

    .modal-content.form-card {
        max-width: 100% !important;
        width: 100% !important;
        border-radius: 24px 24px 0 0 !important;
        max-height: 85vh !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch;
        margin: 0 !important;
        animation: slideUpMobile 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards !important;
        padding: 24px 20px calc(36px + env(safe-area-inset-bottom, 16px)) 20px !important;
        box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.8) !important;
    }

    .modal-content.form-card .form-actions {
        margin-top: 24px !important;
        margin-bottom: 8px !important;
    }

    .modal-content.form-card #btn-submit {
        min-height: 50px !important;
        width: 100% !important;
        font-size: 1rem !important;
        font-weight: 600 !important;
    }

    @keyframes slideUpMobile {
        from {
            transform: translateY(100%);
            opacity: 0.5;
        }
        to {
            transform: translateY(0);
            opacity: 1;
        }
    }

    /* Hide bottom nav and chatbot when transaction modal is open */
    body.modal-open .mobile-bottom-nav,
    body.modal-open .mobile-nav-bar,
    body.modal-open #mobile-bottom-nav,
    body.modal-open #mobile-nav-bar,
    body.modal-open .chatbot-widget,
    body:has(.modal-overlay:not(.hidden)) .mobile-bottom-nav,
    body:has(.modal-overlay:not(.hidden)) .chatbot-widget {
        opacity: 0 !important;
        pointer-events: none !important;
        visibility: hidden !important;
        transform: translateY(24px) !important;
        transition: opacity 0.2s ease, transform 0.2s ease;
    }

    /* Prevent background body scroll when modal or settings is open */
    body.modal-open,
    body.settings-open {
        overflow: hidden !important;
    }

    /* Chatbot repositioning above bottom nav */
    .chatbot-widget {
        bottom: calc(76px + env(safe-area-inset-bottom, 0px)) !important;
        right: 16px !important;
    }

    .chatbot-container {
        width: calc(100vw - 32px) !important;
        max-width: 420px !important;
        right: 0 !important;
        bottom: 60px !important;
        height: 70vh !important;
        max-height: 520px !important;
    }

    /* Mobile Header Layout - Apple iOS Top Bar Standard */
    .app-header {
        display: flex !important;
        flex-direction: row !important;
        align-items: center !important;
        justify-content: space-between !important;
        flex-wrap: nowrap !important;
        gap: 8px !important;
        padding: 10px 14px !important;
        margin-bottom: 12px !important;
        border-radius: var(--radius-lg, 18px) !important;
        background: var(--surface-card, #1c1c1e) !important;
        backdrop-filter: blur(20px) saturate(180%) !important;
        -webkit-backdrop-filter: blur(20px) saturate(180%) !important;
        box-shadow: 0 4px 20px rgba(0, 0, 0, 0.25) !important;
        border: none !important;
        transform: none !important;
        filter: none !important;
    }

    [data-theme="light"] .app-header {
        background: #ffffff !important;
        box-shadow: 0 4px 20px rgba(0, 0, 0, 0.05) !important;
    }

    .logo-area {
        display: flex !important;
        flex-direction: row !important;
        align-items: center !important;
        text-align: left !important;
        gap: 10px !important;
        min-width: 0 !important;
        flex: 1 1 auto !important;
    }

    .logo-icon {
        width: 36px !important;
        height: 36px !important;
        min-width: 36px !important;
        min-height: 36px !important;
        border-radius: 11px !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        flex-shrink: 0 !important;
    }

    .logo-icon img {
        width: 36px !important;
        height: 36px !important;
        border-radius: 11px !important;
        object-fit: cover !important;
        display: block !important;
    }

    .logo-area > div {
        min-width: 0 !important;
        display: flex !important;
        flex-direction: column !important;
        justify-content: center !important;
    }

    .logo-area h1 {
        font-size: 0.92rem !important;
        font-weight: 700 !important;
        color: var(--text-primary) !important;
        margin: 0 !important;
        padding: 0 !important;
        line-height: 1.25 !important;
        white-space: nowrap !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
        letter-spacing: -0.015em !important;
    }

    .logo-area .tagline {
        font-size: 0.70rem !important;
        color: var(--text-secondary) !important;
        margin: 2px 0 0 0 !important;
        padding: 0 !important;
        line-height: 1.2 !important;
        white-space: nowrap !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
    }

    .header-actions {
        display: flex !important;
        flex-direction: row !important;
        align-items: center !important;
        justify-content: flex-end !important;
        width: auto !important;
        gap: 6px !important;
        flex-shrink: 0 !important;
        border-top: none !important;
        padding-top: 0 !important;
    }

    .backup-actions {
        display: flex !important;
        flex-direction: row !important;
        align-items: center !important;
        gap: 6px !important;
    }

    .btn-icon-label {
        width: 36px !important;
        height: 36px !important;
        min-width: 36px !important;
        min-height: 36px !important;
        padding: 0 !important;
        border-radius: 50% !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        background: var(--surface-secondary, rgba(255, 255, 255, 0.06)) !important;
        color: var(--text-secondary) !important;
        border: none !important;
        transition: transform 0.15s cubic-bezier(0.32, 0.72, 0, 1), background 0.15s ease !important;
    }

    [data-theme="light"] .btn-icon-label {
        background: rgba(0, 0, 0, 0.05) !important;
        color: var(--text-secondary) !important;
    }

    .btn-icon-label:active {
        transform: scale(0.90) !important;
        background: rgba(255, 255, 255, 0.12) !important;
    }

    .btn-icon-label span {
        display: none !important;
    }

    .btn-icon-label i,
    .btn-icon-label svg {
        width: 17px !important;
        height: 17px !important;
        stroke-width: 1.8 !important;
    }

    .settings-menu-container {
        position: relative !important;
    }

    .theme-toggle-btn#btn-settings {
        width: 36px !important;
        height: 36px !important;
        min-width: 36px !important;
        min-height: 36px !important;
        padding: 0 !important;
        border-radius: 50% !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        background: var(--surface-secondary, rgba(255, 255, 255, 0.06)) !important;
        border: none !important;
        overflow: hidden !important;
        cursor: pointer !important;
        transition: transform 0.15s cubic-bezier(0.32, 0.72, 0, 1) !important;
    }

    [data-theme="light"] .theme-toggle-btn#btn-settings {
        background: rgba(0, 0, 0, 0.05) !important;
    }

    .theme-toggle-btn#btn-settings:active {
        transform: scale(0.90) !important;
    }

    .theme-toggle-btn#btn-settings .user-avatar-img {
        width: 100% !important;
        height: 100% !important;
        border-radius: 50% !important;
        object-fit: cover !important;
        display: block !important;
        border: none !important;
    }

    /* Touch target sizes (minimum 44px) */
    .btn, 
    .btn-icon-label, 
    .theme-toggle-btn, 
    .btn-month-nav,
    .toggle-label {
        min-height: 44px;
        touch-action: manipulation;
    }

    /* Calendar Grid cells touch optimization */
    .calendar-grid {
        gap: 2px !important;
    }

    .calendar-cell {
        min-height: 48px !important;
        padding: 4px 2px !important;
    }

    .calendar-cell .cell-date {
        font-size: 0.8rem !important;
    }

    /* Mobile inertial touch scrolling & vertical pan navigation */
    html, body {
        overscroll-behavior-y: auto;
        touch-action: pan-y;
        -webkit-overflow-scrolling: touch;
    }
}
