/**
 * LokusAnalytics PWA & Mobile Styles
 * ===================================
 * Estilos globales para Progressive Web App y dispositivos móviles
 */

/* ========================================
   CSS VARIABLES
   ======================================== */
:root {
    --touch-target-min: 48px;
    --safe-area-top: env(safe-area-inset-top, 0px);
    --safe-area-bottom: env(safe-area-inset-bottom, 0px);
    --safe-area-left: env(safe-area-inset-left, 0px);
    --safe-area-right: env(safe-area-inset-right, 0px);
}

/* ========================================
   PREVENT HORIZONTAL OVERFLOW
   ======================================== */
*, *::before, *::after {
    box-sizing: border-box;
}

html, body {
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
}

/* ========================================
   PREVENT ZOOM ON INPUT FOCUS (iOS)
   ======================================== */
input, select, textarea {
    font-size: 16px !important;
}

/* ========================================
   TOUCH TARGETS (Minimum 48px)
   ======================================== */
.btn,
.nav-link,
.dropdown-item,
.form-control,
.form-select,
.form-check-input,
a.clickable,
[role="button"] {
    min-height: var(--touch-target-min);
}

.btn {
    padding: 0.625rem 1.25rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.form-check-input {
    width: 1.25rem;
    height: 1.25rem;
}

/* ========================================
   SAFE AREA INSETS (Notched Devices)
   ======================================== */
.navbar {
    padding-top: max(0.5rem, var(--safe-area-top));
    padding-left: max(1rem, var(--safe-area-left));
    padding-right: max(1rem, var(--safe-area-right));
}

footer {
    padding-bottom: max(1rem, var(--safe-area-bottom));
}

/* ========================================
   MOBILE BREAKPOINT (< 768px)
   ======================================== */
@media (max-width: 767.98px) {
    /* Larger touch targets */
    .btn {
        min-height: 48px;
        padding: 0.75rem 1.25rem;
    }

    .nav-link {
        padding: 0.75rem 1rem !important;
    }

    .dropdown-item {
        padding: 0.75rem 1.5rem;
    }

    /* Stack columns */
    .row > [class*="col-md-"],
    .row > [class*="col-lg-"] {
        margin-bottom: 1rem;
    }

    /* Container padding */
    .container-fluid {
        padding-left: 1rem;
        padding-right: 1rem;
    }

    /* Full width cards */
    .card {
        border-radius: 1rem;
    }

    /* Footer center on mobile */
    footer .col-md-4 {
        text-align: center;
        margin-bottom: 1.5rem;
    }

    footer .col-md-4:last-child {
        margin-bottom: 0;
    }

    /* Modal adjustments */
    .modal-dialog {
        margin: 0.5rem;
    }
}

/* ========================================
   SMALL MOBILE (< 576px)
   ======================================== */
@media (max-width: 575.98px) {
    h1 { font-size: 1.75rem; }
    h2 { font-size: 1.5rem; }
    h3 { font-size: 1.25rem; }

    .container {
        padding-left: 1rem;
        padding-right: 1rem;
    }
}

/* ========================================
   TABLET (768px - 991px)
   ======================================== */
@media (min-width: 768px) and (max-width: 991.98px) {
    .container {
        max-width: 100%;
        padding-left: 2rem;
        padding-right: 2rem;
    }
}

/* ========================================
   PWA STANDALONE MODE
   ======================================== */
@media (display-mode: standalone) {
    body {
        padding-top: var(--safe-area-top);
    }

    /* Hide browser-specific elements in standalone */
    .browser-only {
        display: none !important;
    }
}

/* ========================================
   SMOOTH SCROLLING
   ======================================== */
html {
    scroll-behavior: smooth;
}

/* ========================================
   ACCESSIBILITY - FOCUS STYLES
   ======================================== */
:focus-visible {
    outline: 2px solid var(--primary-color, #2563eb);
    outline-offset: 2px;
}

/* ========================================
   LOADING STATES
   ======================================== */
.btn.loading {
    position: relative;
    color: transparent !important;
    pointer-events: none;
}

.btn.loading::after {
    content: '';
    position: absolute;
    width: 1rem;
    height: 1rem;
    top: 50%;
    left: 50%;
    margin-left: -0.5rem;
    margin-top: -0.5rem;
    border: 2px solid currentColor;
    border-radius: 50%;
    border-top-color: transparent;
    animation: btn-spinner 0.8s linear infinite;
}

@keyframes btn-spinner {
    to { transform: rotate(360deg); }
}

/* ========================================
   PULL TO REFRESH INDICATOR
   ======================================== */
.pull-to-refresh {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--primary-color, #2563eb);
    color: white;
    transform: translateY(-100%);
    transition: transform 0.3s;
    z-index: 9999;
}

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

/* ========================================
   INSTALL PWA BANNER
   ======================================== */
.pwa-install-banner {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: white;
    padding: 1rem;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.15);
    z-index: 1050;
    display: none;
    padding-bottom: max(1rem, var(--safe-area-bottom));
}

.pwa-install-banner.show {
    display: block;
    animation: slideUp 0.3s ease-out;
}

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

/* ========================================
   OFFLINE INDICATOR
   ======================================== */
.offline-indicator {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background: #ef4444;
    color: white;
    text-align: center;
    padding: 0.5rem;
    font-size: 0.875rem;
    z-index: 9999;
    display: none;
}

.offline-indicator.show {
    display: block;
}

/* ========================================
   SKELETON LOADING
   ======================================== */
.skeleton {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s infinite;
    border-radius: 4px;
}

@keyframes skeleton-loading {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}
