/* ========================================
   Mobile Experience Fixes
   Layout, Header & Visual Hierarchy
   ======================================== */

/* Header Móvil Premium */
.mobile-header {
    display: none;
    /* Desktop hidden */
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 60px;
    /* Ajuste de espaciado */
    padding: 0 20px;
    align-items: center;
    justify-content: space-between;

    /* Estilos Adaptativos (Claro/Oscuro) */
    background: var(--glass-bg, rgba(255, 255, 255, 0.9));
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--glass-border, rgba(0, 0, 0, 0.05));
    color: var(--text-primary, #1e293b);

    /* Sombra suave */
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.03);
}

/* Fix para modo oscuro explícito si las variables fallan */
body.dark-mode .mobile-header {
    background: rgba(15, 23, 42, 0.9);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.header-logo {
    display: flex;
    align-items: center;
    gap: 10px;
}

.header-logo-img {
    width: 32px;
    height: 32px;
    object-fit: contain;
}

.header-title {
    font-weight: 700;
    font-size: 1.1rem;
    background: linear-gradient(135deg, var(--primary-600), var(--primary-400));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    color: transparent;
    /* Fallback */
}

.header-btn {
    background: transparent;
    border: none;
    color: var(--primary-500);
    padding: 8px;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.2s;
}

.header-btn:active {
    background: rgba(147, 51, 234, 0.1);
    transform: scale(0.95);
}

.heart-icon {
    width: 24px;
    height: 24px;
    animation: heartbeat 2s infinite;
}

@keyframes heartbeat {
    0% {
        transform: scale(1);
    }

    15% {
        transform: scale(1.15);
    }

    30% {
        transform: scale(1);
    }

    45% {
        transform: scale(1.15);
    }

    60% {
        transform: scale(1);
    }
}

/* Reordenamiento del Layout Móvil */
@media (max-width: 900px) {

    /* Mostrar header */
    .mobile-header {
        display: flex;
    }

    /* Ajustar espaciado superior */
    .app-container {
        padding-top: 100px !important;
        /* Más espacio para evitar solapamiento */
        padding-bottom: 100px !important;
        /* Espacio para nav bar */
    }

    /* Ocultar sidebar tradicional */
    .sidebar {
        display: none !important;
        /* Si usamos el nav inferior nuevo */
    }

    /* Nuevo Mobile Grid Layout */
    /* Nuevo Mobile Grid Layout - Solo para CREAR */
    .view-create.active {
        display: flex !important;
        flex-direction: column;
    }

    /* Restaurar comportamiento normal para otras vistas */
    .view-scan.active,
    .view-history.active {
        display: block !important;
    }

    .create-container {
        display: flex !important;
        flex-direction: column;
        gap: 20px;
    }

    /* 1. Input Section (Ingresa tu contenido) */
    .input-section {
        order: 1;
        width: 100%;
        margin-bottom: 0;
    }

    .panel-input {
        order: 1 !important;
    }

    /* Contenedor de paneles (Preview + Custom) */
    .panels-grid {
        display: flex !important;
        flex-direction: column;
        order: 2;
        gap: 20px;
    }

    /* 2. Preview Panel */
    .panel-preview {
        order: 2 !important;
    }

    /* 3. Customization Panel (Incluye Marcos al final) */
    .panel-customization {
        order: 3 !important;
    }

    /* Ajustes visuales extra */
    .qr-preview-container {
        min-height: 250px;
    }

    .frame-options {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        gap: 10px;
    }

    /* === Scan View Responsive === */
    .view-scan .content-header {
        text-align: center;
        margin-bottom: 20px;
    }

    .scan-drop-zone {
        padding: 40px 20px;
        min-height: 250px;
        display: flex;
        flex-direction: column;
        justify-content: center;
        gap: 15px;
    }

    .scan-drop-zone svg {
        width: 64px;
        height: 64px;
        margin-bottom: 10px;
    }

    /* Input de resultado scan responsive */
    .result-content {
        display: flex;
        flex-direction: column;
        gap: 15px;
    }

    .result-text-input {
        width: 100%;
        padding: 15px;
        font-size: 1rem;
        border: 2px solid var(--gray-200);
        border-radius: 12px;
        background: var(--bg-input, #f8fafc);
    }

    .result-actions {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 10px;
    }

    /* === General Mobile UI === */
    /* Botones principales de acción (Guardar, Subir) full width */
    .save-section .btn-primary,
    .scan-drop-zone .btn-secondary,
    .result-actions .btn-primary,
    .result-actions .btn-secondary {
        width: 100%;
        justify-content: center;
        padding: 12px;
        font-size: 1rem;
    }

    /* NO tocar botones pequeños del historial ni otros iconos */

    .input-section h1,
    .content-header h1 {
        font-size: 1.5rem;
        /* Títulos más pequeños */
    }
}

/* Mobile Navigation Bar Fix (Donation Icon) */
@media (max-width: 768px) {
    .mobile-nav-bar {
        position: fixed;
        bottom: 0;
        left: 0;
        width: 100%;
        height: 70px;
        background: white;
        display: flex;
        justify-content: space-around;
        align-items: center;
        box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.1);
        z-index: 999;
        /* Blur glass */
        backdrop-filter: blur(12px);
        background: rgba(255, 255, 255, 0.95);
        padding-bottom: env(safe-area-inset-bottom);
    }

    /* Si ya existe .sidebar actuando como nav bar, la ajustamos */
    .sidebar {
        display: flex !important;
        position: fixed !important;
        bottom: 0 !important;
        top: auto !important;
        left: 0 !important;
        width: 100% !important;
        height: 70px !important;
        flex-direction: row !important;
        padding: 0 10px !important;
        border-radius: 20px 20px 0 0 !important;
    }

    .sidebar-header {
        display: none !important;
    }

    .main-nav {
        flex-direction: row !important;
        width: 100%;
        justify-content: space-evenly;
    }

    /* Ocultar elementos no deseados en móvil */
    .user-profile,
    .donation-btn {
        display: none !important;
    }

    /* Ajustar footer para mostrar botones de navegación y portfolio */
    .sidebar-footer {
        display: flex !important;
        align-items: center;
        gap: 10px;
        width: auto !important;
        margin-top: 0 !important;
        padding: 0 !important;
        border: none !important;
    }

    .credit-btn {
        display: flex !important;
        /* Asegurar que Portfolio/Info se vea */
    }

    .nav-label {
        font-size: 0.7rem;
        margin-top: 4px;
    }

    /* === Historial Responsive === */
    .history-item {
        flex-direction: row;
        /* Mantener fila pero ajustar contenido */
        align-items: center;
        padding: 12px;
        gap: 10px;
    }

    .history-qr img {
        width: max-content;
        /* QR más pequeño en lista */
        height: max-content;
    }

    .history-info {
        font-size: 0.9rem;
    }

    /* Botones de acción pequeños y elegantes */
    .history-actions {
        display: flex;
        gap: 8px;
    }

    .history-actions button {
        padding: 6px;
        /* Botón compacto */
        width: 32px;
        height: 32px;
        border-radius: 8px;
        display: flex;
        align-items: center;
        justify-content: center;
        background: transparent;
        border: 1px solid var(--gray-200);
        color: var(--gray-500);
    }

    .history-actions button:hover {
        background: var(--primary-50);
        color: var(--primary-600);
        border-color: var(--primary-200);
    }

    .history-actions button svg {
        width: 16px;
        height: 16px;
    }
}

/* ========================================
   GLOBAL FIXES (Desktop & Mobile)
   ======================================== */

/* Botones de Historial Professionales (Global) */
.history-actions button {
    padding: 8px;
    width: 36px;
    height: 36px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: 1px solid rgba(0, 0, 0, 0.1);
    color: #64748b;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.history-actions button svg {
    width: 18px;
    height: 18px;
    stroke-width: 1.5;
}

/* TOAST ALERTS ADAPTABLES */
.toast {
    background: var(--bg-card, white);
    color: var(--text-primary, #1e293b);
    border: 1px solid var(--glass-border, rgba(0, 0, 0, 0.1));
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
    backdrop-filter: blur(12px);
}

body.dark-mode .toast {
    background: rgba(30, 41, 59, 0.95);
    color: #f8fafc;
    border-color: rgba(255, 255, 255, 0.1);
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.3);
}

/* Fix para iconos de historial en global */
.history-actions button:hover {
    background: white;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    transform: translateY(-2px);
    color: var(--primary-600);
    border-color: var(--primary-200);
}

.history-actions .history-delete:hover {
    color: #ef4444;
    border-color: #fee2e2;
    background: #fef2f2;
}

/* Ajuste general de items de historial */
.history-item {
    transition: transform 0.2s, box-shadow 0.2s;
    border: 1px solid rgba(255, 255, 255, 0.5);
}

.history-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.06);
}

/* HISTORIAL GRID FIX (DESKTOP) */
@media (min-width: 901px) {
    .history-item {
        display: flex;
        flex-direction: column;
        padding: 0;
        /* Remover padding del contenedor para que la imagen toque bordes si se quiere, o dejarlo */
        overflow: hidden;
        background: white;
    }

    .history-qr {
        width: 100% !important;
        background: #f8fafc;
        display: flex;
        align-items: center;
        justify-content: center;
        padding: 0 !important;
        /* Sin padding para que toque bordes si es necesario */
        aspect-ratio: 1/1;
        /* Cuadrado perfecto */
        min-height: 250px;
    }

    .history-qr img {
        width: 100% !important;
        height: 100% !important;
        object-fit: contain !important;
        /* O cover si quiere recortar */
        max-width: none !important;
        max-height: none !important;
        padding: 10px;
        /* Padding interno en la imagen para que no toque los bordes exactos visualmente */
        filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.1));
    }

    .history-info {
        padding: 15px;
        width: 100%;
    }

    .history-actions {
        padding: 0 15px 15px 15px;
        width: 100%;
        justify-content: space-between;
        /* Botones separados */
    }
}