/* Bottom Navigation PWA UI - Option 1 */
/* Mobile-first bottom navigation bar with 5 primary tabs */

:root {
    --bottom-nav-height: 56px;
    --bottom-nav-bg: rgba(255, 255, 255, 0.98);
    --bottom-nav-shadow: 0 -2px 8px rgba(0, 0, 0, 0.1);
    --tab-active-color: #667eea;
    --tab-inactive-color: #718096;
    --safe-area-bottom: env(safe-area-inset-bottom, 0px);
}

/* Main layout adjustments for bottom nav */
body.pwa-mode {
    padding-bottom: calc(var(--bottom-nav-height) + var(--safe-area-bottom));
}

/* Bottom Navigation Container */
.bottom-navigation {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: calc(var(--bottom-nav-height) + var(--safe-area-bottom));
    background: var(--bottom-nav-bg);
    box-shadow: var(--bottom-nav-shadow);
    z-index: 9999;
    display: none; /* Hidden by default, shown when pwa-mode is active */
    justify-content: space-around;
    align-items: flex-start;
    padding-top: 8px;
    padding-bottom: var(--safe-area-bottom);
    backdrop-filter: blur(10px);
    /* CRITICAL: Prevent scroll-induced movement - make it truly sticky */
    transform: translate3d(0, 0, 0);
    -webkit-transform: translate3d(0, 0, 0);
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
    will-change: transform;
    /* Force hardware acceleration and prevent repaints */
    contain: layout style paint;
    /* Prevent any layout shifts */
    min-height: calc(var(--bottom-nav-height) + var(--safe-area-bottom));
    max-height: calc(var(--bottom-nav-height) + var(--safe-area-bottom));
}

/* CRITICAL: Always show bottom nav when pwa-mode class is present */
body.pwa-mode .bottom-navigation {
    display: flex !important;
}

/* Also ensure it shows in standalone mode via media query as fallback */
@media (display-mode: standalone) {
    body.pwa-mode .bottom-navigation {
        display: flex !important;
    }
}

/* Navigation Tabs */
.nav-tab {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    padding: 4px 0;
    text-decoration: none;
    color: var(--tab-inactive-color);
    cursor: pointer;
    transition: all 0.2s ease;
    -webkit-tap-highlight-color: transparent;
    position: relative;
}

.nav-tab:active {
    transform: scale(0.95);
}

.nav-tab.active {
    color: var(--tab-active-color);
}

.nav-tab.active::before {
    content: '';
    position: absolute;
    top: -8px;
    left: 50%;
    transform: translateX(-50%);
    width: 32px;
    height: 3px;
    background: var(--tab-active-color);
    border-radius: 3px;
}

/* Tab Icons */
.nav-tab-icon {
    font-size: 24px;
    line-height: 1;
    margin-bottom: 4px;
    transition: transform 0.2s ease;
}

.nav-tab.active .nav-tab-icon {
    transform: scale(1.1);
}

/* Tab Labels */
.nav-tab-label {
    font-size: 11px;
    font-weight: 500;
    text-align: center;
    white-space: nowrap;
    font-family: 'Comfortaa', sans-serif;
}

.nav-tab.active .nav-tab-label {
    font-weight: 600;
}

/* Badge indicator for notifications */
.nav-tab-badge {
    position: absolute;
    top: 0;
    right: calc(50% - 20px);
    background: #ef4444;
    color: white;
    font-size: 10px;
    font-weight: 700;
    padding: 2px 5px;
    border-radius: 10px;
    min-width: 18px;
    text-align: center;
}

/* Content area adjustments */
.pwa-content {
    min-height: calc(100vh - var(--bottom-nav-height) - var(--safe-area-bottom) - 120px);
    padding: 16px 16px 16px 16px;
    /* Disable native pull-to-refresh to use custom implementation */
    overscroll-behavior-y: contain;
    /* Allow all touch interactions while preventing double-tap zoom delay */
    touch-action: manipulation;
}

/* Compact Home tab - fit content in one screen */
#home-content {
    padding: 12px;
}

#home-content .dashboard-card {
    padding: 1rem;
    margin-bottom: 0.75rem;
}

#home-content .dashboard-card h3 {
    font-size: 1rem;
    margin-bottom: 0.5rem;
}

#home-content .dashboard-stat {
    padding: 0.35rem 0;
}

#home-content .dashboard-stat-label {
    font-size: 0.85rem;
}

#home-content .dashboard-stat-value {
    font-size: 0.95rem;
}

#home-content .quick-actions {
    margin-top: 0.75rem;
    gap: 0.5rem;
}

#home-content .quick-action-btn {
    padding: 0.6rem 0.75rem;
    font-size: 0.85rem;
}

#home-content .pwa-footer {
    margin-top: 0.5rem;
    padding: 0.5rem;
    font-size: 0.75rem;
}

#home-content .pwa-footer p {
    margin: 0.25rem 0;
}

/* Hide default features grid on mobile when bottom nav is active */
/* Apply for: small viewports, standalone PWA mode, OR touch devices up to tablet size */
@media (max-width: 768px), (display-mode: standalone), ((max-width: 1024px) and (pointer: coarse)) {
    body.pwa-mode .features-grid {
        display: none;
    }
    
    body.pwa-mode .header {
        padding: 1rem;
        margin-bottom: 1rem;
    }
    
    body.pwa-mode .header h1 {
        font-size: 1.5rem;
    }
    
    body.pwa-mode .header p {
        font-size: 0.9rem;
    }
}

/* Ensure bottom navigation is visible in standalone mode regardless of viewport */
@media (display-mode: standalone) {
    body.pwa-mode .bottom-navigation {
        display: flex !important;
    }
}

/* Tab content sections */
.tab-content {
    display: none;
    /* Fix positioning to prevent jumping during load */
    position: relative;
    width: 100%;
}

.tab-content.active {
    display: block;
}

/* Home Dashboard Cards */
.dashboard-card {
    background: white;
    border-radius: 12px;
    padding: 1.5rem;
    margin-bottom: 1rem;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    /* Fix positioning to prevent jumping */
    position: relative;
    width: 100%;
}

.dashboard-card:active {
    transform: scale(0.98);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15);
}

.dashboard-card h3 {
    color: #4a5568;
    font-size: 1.1rem;
    margin-bottom: 0.75rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.dashboard-card-content {
    color: #718096;
    font-size: 0.95rem;
}

.dashboard-stat {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 0;
    border-bottom: 1px solid #e2e8f0;
}

.dashboard-stat:last-child {
    border-bottom: none;
}

.dashboard-stat-label {
    color: #718096;
    font-size: 0.9rem;
}

.dashboard-stat-value {
    color: #2d3748;
    font-weight: 600;
    font-size: 1rem;
}

/* Quick action buttons */
.quick-actions {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
    margin-top: 1rem;
}

.quick-action-btn {
    background: linear-gradient(45deg, #667eea, #764ba2);
    color: white;
    border: none;
    padding: 0.75rem 1rem;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    font-family: 'Comfortaa', sans-serif;
}

.quick-action-btn:active {
    transform: scale(0.95);
}

/* Pull to refresh indicator */
.pull-to-refresh {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(180deg, rgba(102, 126, 234, 0.15) 0%, transparent 100%);
    transform: translateY(-100%);
    transition: transform 0.3s ease;
    z-index: 999;
    pointer-events: none;
}

.pull-to-refresh.visible {
    transform: translateY(0);
}

.pull-to-refresh-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.pull-to-refresh-spinner {
    width: 32px;
    height: 32px;
    border: 3px solid #e2e8f0;
    border-top-color: #667eea;
    border-radius: 50%;
    transition: transform 0.2s ease;
}

.pull-to-refresh.refreshing .pull-to-refresh-spinner {
    animation: spin 1s linear infinite;
}

.pull-to-refresh-text {
    color: #667eea;
    font-size: 14px;
    font-weight: 600;
    font-family: 'Comfortaa', sans-serif;
    opacity: 0.9;
}

.pull-to-refresh.ready {
    background: linear-gradient(180deg, rgba(102, 126, 234, 0.25) 0%, transparent 100%);
}

.pull-to-refresh.ready .pull-to-refresh-text {
    opacity: 1;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

@keyframes fadeOut {
    from {
        opacity: 1;
    }
    to {
        opacity: 0;
    }
}

/* Swipe indicator */
.swipe-indicator {
    position: fixed;
    top: 50%;
    transform: translateY(-50%);
    color: #667eea;
    font-size: 2rem;
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
    z-index: 998;
}

.swipe-indicator.left {
    left: 20px;
}

.swipe-indicator.right {
    right: 20px;
}

.swipe-indicator.visible {
    opacity: 0.5;
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    :root {
        --bottom-nav-bg: rgba(45, 55, 72, 0.98);
        --tab-inactive-color: #a0aec0;
    }
    
    .dashboard-card {
        background: #2d3748;
        color: #e2e8f0;
    }
    
    .dashboard-card h3 {
        color: #f7fafc;
    }
    
    .dashboard-stat {
        border-bottom-color: #4a5568;
    }
    
    .dashboard-stat-label {
        color: #cbd5e0;
    }
    
    .dashboard-stat-value {
        color: #f7fafc;
    }
}

/* Desktop view - hide bottom nav UNLESS in standalone mode or pwa-mode class is present */
@media (min-width: 769px) and (display-mode: browser) {
    body:not(.pwa-mode) .bottom-navigation {
        display: none;
    }
    
    body:not(.pwa-mode) {
        padding-bottom: 0;
    }
}

/* Standalone mode always shows bottom nav even on larger screens */
/* This is critical for iOS/iPad PWA apps */
@media (display-mode: standalone) {
    body .bottom-navigation {
        display: flex !important;
    }
    
    body {
        padding-bottom: calc(var(--bottom-nav-height) + var(--safe-area-bottom)) !important;
    }
    
    body.pwa-mode .features-grid {
        display: none !important;
    }
}

/* iOS standalone mode (older detection method) */
@supports (-webkit-touch-callout: none) {
    body.pwa-mode .bottom-navigation {
        display: flex !important;
    }
}

/* Tablet landscape - adjust layout */
@media (min-width: 769px) and (max-width: 1024px) {
    .dashboard-card {
        display: inline-block;
        width: calc(50% - 0.5rem);
        margin-right: 0.5rem;
        vertical-align: top;
    }
}

/* Accessibility improvements */
.nav-tab:focus {
    outline: 2px solid var(--tab-active-color);
    outline-offset: 2px;
}

.nav-tab:focus:not(:focus-visible) {
    outline: none;
}

/* Reduce motion for accessibility */
@media (prefers-reduced-motion: reduce) {
    .nav-tab,
    .nav-tab-icon,
    .dashboard-card,
    .tab-content {
        animation: none;
        transition: none;
    }
}

/* Clickable dashboard cards */
.dashboard-card.clickable {
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.dashboard-card.clickable:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.dashboard-card.clickable:active {
    transform: scale(0.98);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
}

/* Logout button styling - make it wider (two columns) */
.quick-action-btn.logout-btn {
    grid-column: span 2;
    background: linear-gradient(45deg, #e53e3e, #c53030);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

/* User Preferences button styling - make it wider (two columns) */
.quick-action-btn[data-action="openUserPreferences"] {
    grid-column: span 2;
}

/* Logout icon styling */
.logout-icon {
    width: 20px;
    height: 20px;
    fill: white;
}

/* Safe area adjustments for iPhone notch/island */
/* Use CSS custom property to centralize safe area calculation */
:root {
    --safe-area-top: env(safe-area-inset-top, 0px);
}

body.pwa-mode {
    /* Add safe area for top (notch/island) - applied to body to affect all children */
    padding-top: var(--safe-area-top);
}

/* Additional safe area for container in PWA mode */
body.pwa-mode .container {
    padding-left: max(20px, env(safe-area-inset-left, 0px));
    padding-right: max(20px, env(safe-area-inset-right, 0px));
    /* Top padding already handled by body, just ensure minimum */
    padding-top: 20px;
}

/* Ensure PWA tab content has adequate top spacing */
body.pwa-mode .pwa-content {
    /* Inherit safe area from body, just add minimum padding */
    padding-top: 20px;
}

/* Header in PWA mode - safe area already applied via body padding */
body.pwa-mode .header {
    /* No additional margin needed since body handles safe area */
    margin-top: 0;
}

/* PWA Footer - Copyright and Privacy Policy */
.pwa-footer {
    text-align: center;
    padding: 1rem 1rem;
    margin-top: 1rem;
    margin-bottom: 0.5rem;
    font-size: 0.85rem;
    border-top: 1px solid var(--border-color);
    color: var(--text-muted);
}

.pwa-footer p {
    margin: 0 0 0.5rem 0;
    color: var(--text-muted);
}

.pwa-footer p:last-child {
    margin-bottom: 0;
}

.pwa-footer a {
    color: var(--accent-primary);
    text-decoration: underline;
    transition: color 0.2s ease;
}

.pwa-footer a:hover {
    color: var(--accent-hover);
}

.pwa-footer a:active {
    color: var(--accent-secondary);
}

/* Hide Manage Life Zones button in PWA mode (entity management is in Life Zones tab) */
body.pwa-mode #manageEntitiesBtn {
    display: none !important;
}

/* PWA Entity Cards - Life Zones Tab */
.pwa-entities-list {
    max-height: calc(100vh - 350px);
    overflow-y: auto;
    padding: 0 4px;
}

.pwa-entity-card {
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    cursor: pointer;
    margin-bottom: 0.75rem;
}

.pwa-entity-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.pwa-entity-card:active {
    transform: scale(0.98);
}

/* Life Zones tab specific styles */
.pwa-description {
    color: #718096;
    margin-bottom: 1rem;
}

.pwa-single-column {
    grid-template-columns: 1fr;
}

.entity-management-btn {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.pwa-loading-state {
    text-align: center;
    padding: 1rem;
    color: #718096;
}

.pwa-loading-icon {
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
}

.pwa-empty-state {
    text-align: center;
    padding: 1.5rem;
    color: #718096;
}

.pwa-empty-icon {
    font-size: 2rem;
    margin-bottom: 0.75rem;
}

.pwa-empty-title {
    color: #4a5568;
    margin-bottom: 0.5rem;
}

.pwa-empty-description {
    margin-bottom: 1rem;
}

.pwa-error-state {
    text-align: center;
    padding: 1rem;
    color: #e53e3e;
}

.pwa-error-icon {
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
}

.pwa-inline-btn {
    display: inline-block;
    width: auto;
}

.pwa-retry-btn {
    margin-top: 0.5rem;
}

/* Entity card content styles */
.pwa-entity-content {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
}

.pwa-entity-info {
    flex: 1;
}

.pwa-entity-name {
    color: #4a5568;
    margin: 0;
    font-size: 1rem;
}

.pwa-entity-meta {
    color: #718096;
    font-size: 0.8rem;
    margin: 0.25rem 0 0 0;
}

.pwa-entity-description {
    color: #718096;
    font-size: 0.85rem;
    margin: 0.5rem 0 0 0;
}

.pwa-entity-arrow {
    color: #667eea;
    font-size: 1.2rem;
}

.pwa-primary-badge {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    background: #48bb78;
    color: white;
    border-radius: 12px;
    font-size: 0.7rem;
    margin-left: 0.5rem;
}
