/**
 * CLAUDIA Dashboard - Mobile Views System
 * Transforms dashboard into independent views with bottom navigation
 * Only active on mobile (max-width: 768px)
 */

/* =============================================
   CSS VARIABLES
   ============================================= */
:root {
    --mobile-nav-height: 64px;
    --mobile-nav-bg: #0D1F3C;
    --mobile-nav-border: rgba(255, 255, 255, 0.1);
    --mobile-accent: #00D4AA;
    --mobile-accent-bg: rgba(0, 212, 170, 0.15);
    --mobile-inactive: rgba(255, 255, 255, 0.5);
    --mobile-transition: 200ms ease-out;
}

/* =============================================
   MOBILE VIEW CONTAINER
   ============================================= */
@media (max-width: 768px) {
    /* Main dashboard adjustments */
    .dashboard {
        padding-bottom: calc(var(--mobile-nav-height) + 16px);
    }

    /* Views container */
    .mobile-views-container {
        position: relative;
        min-height: calc(100vh - 60px - var(--mobile-nav-height));
    }

    /* Individual views */
    .mobile-view {
        display: none;
        opacity: 0;
        transition: opacity var(--mobile-transition);
        padding: 0;
    }

    .mobile-view.active {
        display: block;
        opacity: 1;
    }

    .mobile-view.transitioning-out {
        opacity: 0;
    }

    .mobile-view.transitioning-in {
        opacity: 1;
    }

    /* Hide content-grid default layout on mobile */
    .content-grid {
        display: block;
        padding: 0 1rem;
    }

    /* Sections inside views */
    .mobile-view .section {
        margin-bottom: 1rem;
    }

    /* Summary cards adjustments */
    .mobile-view[data-view="summary"] .summary {
        padding: 1rem;
    }

    /* Hide non-primary views' secondary content on combined views */
    .view-section-separator {
        height: 1px;
        background: var(--mobile-nav-border);
        margin: 1.5rem 0;
    }
}

/* =============================================
   BOTTOM NAVIGATION BAR
   ============================================= */
.mobile-bottom-nav {
    display: none;
}

@media (max-width: 768px) {
    .mobile-bottom-nav {
        display: flex;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        height: var(--mobile-nav-height);
        background: var(--mobile-nav-bg);
        border-top: 1px solid var(--mobile-nav-border);
        box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.3);
        z-index: 1000;
        justify-content: space-around;
        align-items: center;
        padding: 0 8px;
        padding-bottom: env(safe-area-inset-bottom, 0);
    }

    /* Nav items */
    .mobile-nav-item {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 4px;
        padding: 8px 12px;
        border: none;
        background: transparent;
        cursor: pointer;
        border-radius: 12px;
        transition: all var(--mobile-transition);
        min-width: 56px;
        min-height: 48px;
        -webkit-tap-highlight-color: transparent;
    }

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

    /* Icon */
    .mobile-nav-item .nav-icon {
        width: 24px;
        height: 24px;
        color: var(--mobile-inactive);
        transition: color var(--mobile-transition), transform var(--mobile-transition);
    }

    .mobile-nav-item .nav-icon svg {
        width: 100%;
        height: 100%;
    }

    /* Label */
    .mobile-nav-item .nav-label {
        font-size: 10px;
        font-weight: 500;
        color: var(--mobile-inactive);
        transition: color var(--mobile-transition);
        white-space: nowrap;
    }

    /* Hover state */
    .mobile-nav-item:hover .nav-icon,
    .mobile-nav-item:hover .nav-label {
        color: rgba(255, 255, 255, 0.7);
    }

    /* Active state */
    .mobile-nav-item.active {
        background: var(--mobile-accent-bg);
    }

    .mobile-nav-item.active .nav-icon {
        color: var(--mobile-accent);
        transform: scale(1.1);
    }

    .mobile-nav-item.active .nav-label {
        color: var(--mobile-accent);
    }

    /* Badge for notifications */
    .mobile-nav-item .nav-badge {
        position: absolute;
        top: 4px;
        right: 4px;
        min-width: 16px;
        height: 16px;
        background: #ef4444;
        border-radius: 8px;
        font-size: 10px;
        font-weight: 600;
        color: white;
        display: flex;
        align-items: center;
        justify-content: center;
        padding: 0 4px;
    }

    .mobile-nav-item .nav-badge:empty {
        display: none;
    }
}

/* =============================================
   VIEW-SPECIFIC ADJUSTMENTS
   ============================================= */
@media (max-width: 768px) {
    /* Summary view */
    .mobile-view[data-view="summary"] {
        padding-top: 0;
    }

    /* Infrastructure view */
    .mobile-view[data-view="infrastructure"] .infrastructure-section {
        grid-column: 1 / -1;
    }

    /* Services view - combined services + alerts */
    .mobile-view[data-view="services"] .services-section,
    .mobile-view[data-view="services"] .alerts-section {
        margin-bottom: 1rem;
    }

    /* Credits view */
    .mobile-view[data-view="credits"] .api-credits-section {
        grid-column: 1 / -1;
    }

    /* Metrics view - combined health + saas */
    .mobile-view[data-view="metrics"] .health-score-section,
    .mobile-view[data-view="metrics"] .saas-metering-section {
        margin-bottom: 1rem;
    }

    /* DNS view */
    .mobile-view[data-view="dns"] .dns-section {
        grid-column: 1 / -1;
    }

    /* Actions view */
    .mobile-view[data-view="actions"] .actions-section {
        grid-column: 1 / -1;
    }
}

/* =============================================
   HIDE ELEMENTS ON MOBILE VIEWS
   ============================================= */
@media (max-width: 768px) {
    /* Hide the old mobile menu sections we added before */
    .mobile-nav-divider,
    .mobile-nav-section-label,
    .mobile-nav-sections {
        display: none !important;
    }

    /* Hide FAB - replaced by bottom nav */
    .fab-container {
        display: none !important;
    }

    /* Hide scroll to top - views don't need it */
    .scroll-to-top {
        display: none !important;
    }
}

/* =============================================
   TRANSITION ANIMATIONS
   ============================================= */
@keyframes viewFadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes viewFadeOut {
    from {
        opacity: 1;
        transform: translateY(0);
    }
    to {
        opacity: 0;
        transform: translateY(-10px);
    }
}

@media (max-width: 768px) {
    .mobile-view.active {
        animation: viewFadeIn var(--mobile-transition) ease-out;
    }
}

/* =============================================
   DESKTOP - DISABLE MOBILE VIEWS
   ============================================= */
@media (min-width: 769px) {
    .mobile-view {
        display: block !important;
        opacity: 1 !important;
    }

    .mobile-bottom-nav {
        display: none !important;
    }

    .mobile-views-container {
        display: contents;
    }
}

/* =============================================
   LOADING STATE
   ============================================= */
.mobile-view-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 200px;
    color: var(--mobile-inactive);
}

.mobile-view-loading::after {
    content: '';
    width: 32px;
    height: 32px;
    border: 3px solid var(--mobile-nav-border);
    border-top-color: var(--mobile-accent);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* =============================================
   SWIPE INDICATOR (optional)
   ============================================= */
.swipe-indicator {
    position: fixed;
    bottom: calc(var(--mobile-nav-height) + 20px);
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 12px;
    opacity: 0;
    transition: opacity 0.3s;
    pointer-events: none;
    z-index: 999;
}

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

/* =============================================
   INTERNAL TABS SYSTEM
   ============================================= */
@media (max-width: 768px) {
    /* Tabs container */
    .view-tabs {
        display: flex;
        background: rgba(255, 255, 255, 0.05);
        border-radius: 12px;
        padding: 4px;
        margin: 0 0 16px 0;
        gap: 4px;
    }

    /* Individual tab button */
    .view-tab {
        flex: 1;
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 6px;
        padding: 10px 12px;
        border: none;
        background: transparent;
        color: var(--mobile-inactive);
        font-size: 13px;
        font-weight: 500;
        border-radius: 8px;
        cursor: pointer;
        transition: all var(--mobile-transition);
        -webkit-tap-highlight-color: transparent;
        min-height: 44px;
    }

    .view-tab:active {
        transform: scale(0.98);
    }

    /* Tab icon */
    .view-tab .tab-icon {
        width: 18px;
        height: 18px;
        flex-shrink: 0;
    }

    .view-tab .tab-icon svg {
        width: 100%;
        height: 100%;
    }

    /* Tab label */
    .view-tab .tab-label {
        white-space: nowrap;
    }

    /* Hover state */
    .view-tab:hover {
        color: rgba(255, 255, 255, 0.7);
    }

    /* Active tab */
    .view-tab.active {
        background: var(--mobile-accent);
        color: #0D1F3C;
        font-weight: 600;
    }

    .view-tab.active .tab-icon {
        color: #0D1F3C;
    }

    /* Tab content panels */
    .tab-content {
        display: none;
        opacity: 0;
        transition: opacity var(--mobile-transition);
    }

    .tab-content.active {
        display: block;
        opacity: 1;
        animation: tabFadeIn var(--mobile-transition) ease-out;
    }

    @keyframes tabFadeIn {
        from {
            opacity: 0;
            transform: translateX(10px);
        }
        to {
            opacity: 1;
            transform: translateX(0);
        }
    }

    /* Infrastructure view tabs */
    .mobile-view[data-view="infrastructure"] .view-tabs {
        margin-top: 8px;
    }

    /* Metrics view tabs */
    .mobile-view[data-view="metrics"] .view-tabs {
        margin-top: 8px;
    }

    /* Alerts view adjustments (now separate view) */
    .mobile-view[data-view="alerts"] .alerts-section {
        margin-bottom: 1rem;
    }

    .mobile-view[data-view="alerts"] .services-section {
        margin-bottom: 1rem;
    }
}

/* =============================================
   DESKTOP - TABS HIDDEN
   ============================================= */
@media (min-width: 769px) {
    .view-tabs {
        display: none !important;
    }

    .tab-content {
        display: block !important;
        opacity: 1 !important;
    }
}
