:root {
    --bg-app: #f0f2f5;
    --bg-card: #ffffff;
    --text-main: #0f1419;
    --text-sec: #536471;
    --border: #eff3f4;
    --primary: #ff385c;
    --primary-hover: #e03151;
    --radius-lg: 16px;
    --radius-md: 12px;
    --radius-sm: 8px;
    --shadow-card: 0 2px 8px rgba(0,0,0,0.06);
    --shadow-hover: 0 12px 24px rgba(0,0,0,0.12);
    --font-sans: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }

body {
    font-family: var(--font-sans);
    background-color: var(--bg-app);
    color: var(--text-main);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow-x: hidden;
    padding-bottom: calc(70px + var(--safe-bottom));
}

img, picture, video { display: block; max-width: 100%; height: auto; }
input, button { font: inherit; color: inherit; border: none; background: transparent; outline: none; }
button { cursor: pointer; }
a { text-decoration: none; color: inherit; }
ul, ol { list-style: none; }

.hidden-mobile { display: none !important; }
@media (min-width: 768px) { 
    .hidden-desktop { display: none !important; } 
    .hidden-mobile { display: flex !important; }
    body { padding-bottom: 0; }
}

/* HEADER */
.app-header {
    position: sticky; top: 0; background: rgba(255, 255, 255, 0.98);
    backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
    z-index: 1000; border-bottom: 1px solid var(--border); padding: 12px 16px; width: 100%;
}
.header-container { max-width: 1600px; margin: 0 auto; display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.brand { font-size: 1.5rem; font-weight: 900; letter-spacing: -1px; flex-shrink: 0; }
.brand span { color: var(--primary); }

.search-bar {
    flex: 1; max-width: 600px; min-width: 0; display: flex; align-items: center;
    background: var(--bg-app); border-radius: 50px; padding: 8px 16px; border: 2px solid transparent; transition: all 0.2s ease;
}
.search-bar:focus-within { background: #fff; border-color: var(--primary); }
.search-icon { font-size: 1.1rem; margin-right: 8px; opacity: 0.6; flex-shrink: 0; }
.search-bar input { width: 100%; min-width: 0; }

.header-actions { align-items: center; gap: 12px; flex-shrink: 0; }
.icon-btn { font-size: 1.4rem; padding: 8px; border-radius: 50%; transition: background-color 0.2s; display: flex; align-items: center; justify-content: center; }
.icon-btn:hover { background-color: var(--bg-app); }
.btn-surprise { background: linear-gradient(135deg, #7c3aed, #db2777); color: #fff; padding: 8px 16px; border-radius: 50px; font-weight: 700; font-size: 0.95rem; display: flex; align-items: center; gap: 6px; transition: transform 0.2s; white-space: nowrap; }
.btn-surprise:hover { transform: scale(1.05); }
.btn-post { background: var(--text-main); color: #fff; padding: 8px 20px; border-radius: 50px; font-weight: 600; display: flex; align-items: center; gap: 6px; white-space: nowrap; transition: background-color 0.2s; }
.btn-post:hover { background: #272c30; }
.avatar-btn img { width: 36px; height: 36px; border-radius: 50%; object-fit: cover; }

/* CATEGORÍAS */
.discovery-nav { background: #fff; padding: 16px 0; border-bottom: 1px solid var(--border); width: 100%; }
.discovery-scroll { display: flex; gap: 16px; overflow-x: auto; padding: 0 16px; scrollbar-width: none; -ms-overflow-style: none; max-width: 1600px; margin: 0 auto; scroll-behavior: smooth; }
.discovery-scroll::-webkit-scrollbar { display: none; }
.chip { display: flex; flex-direction: column; align-items: center; gap: 6px; min-width: max-content; cursor: pointer; opacity: 0.6; transition: opacity 0.2s ease, transform 0.2s ease; }
.chip:hover, .chip.active { opacity: 1; transform: translateY(-2px); }
.chip-icon { font-size: 1.8rem; background: var(--bg-app); width: 60px; height: 60px; display: flex; align-items: center; justify-content: center; border-radius: 50%; transition: background-color 0.2s; }
.chip:hover .chip-icon { background: #e2e8f0; }
.chip-name { font-size: 0.8rem; font-weight: 600; }

/* FEED Y MASONRY */
.main-feed { max-width: 1600px; margin: 0 auto; padding: 16px; width: 100%; }
.masonry-grid { column-count: 2; column-gap: 16px; width: 100%; }

@media (min-width: 640px)  { .masonry-grid { column-count: 3; } }
@media (min-width: 1024px) { .masonry-grid { column-count: 4; } }
@media (min-width: 1440px) { .masonry-grid { column-count: 5; } }


/* POST CARD (FIX ANTI-CORTES IOS DEFINITIVO) */
.post-card {
    /* Prevención estricta de cortes en WebKit */
    -webkit-column-break-inside: avoid;
    page-break-inside: avoid;
    break-inside: avoid-column;
    
    /* En iOS, block es más estable que inline-block para masonry */
    display: block; 
    width: 100%;
    margin-bottom: 16px;
    
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    overflow: hidden; /* Esto es suficiente para contener los bordes curvos */
    box-shadow: var(--shadow-card);
    position: relative;
    transition: box-shadow 0.3s ease;
    
    /* ⚠️ ELIMINAMOS 'transform' y 'contain' que causaban la invisibilidad en iPhone */
}

.post-card:hover { box-shadow: var(--shadow-hover); }

/* CARRUSEL Y MEDIA */
.card-media { position: relative; width: 100%; background-color: #e2e8f0; }
.card-carousel {
    display: flex; overflow-x: auto; scroll-snap-type: x mandatory; 
    scrollbar-width: none; -ms-overflow-style: none; height: 100%; width: 100%;
    cursor: grab;
}
.card-carousel:active { cursor: grabbing; }
.card-carousel::-webkit-scrollbar { display: none; }
.card-carousel img {
    flex: 0 0 100%; width: 100%; height: 100%; object-fit: cover; 
    scroll-snap-align: start; display: block;
    pointer-events: none; user-select: none; -webkit-user-drag: none;
}

/* CONTROLES CARRUSEL */
.carousel-indicators { position: absolute; bottom: 12px; left: 0; right: 0; display: flex; justify-content: center; gap: 6px; z-index: 10; align-items: center; pointer-events: auto; }
.dot { cursor: pointer; border: none; padding: 0; width: 8px; height: 8px; margin: 0 3px; border-radius: 50%; background: rgba(255, 255, 255, 0.5); box-shadow: 0 1px 3px rgba(0,0,0,0.3); transition: all 0.2s ease; }
.dot:hover { background: rgba(255, 255, 255, 0.8); transform: scale(1.2); }
.dot.active { background: #ffffff; transform: scale(1.1); }

.carousel-arrow {
    position: absolute; top: 50%; transform: translateY(-50%); background: rgba(255, 255, 255, 0.9);
    color: var(--text-main); border: none; border-radius: 50%; width: 32px; height: 32px; font-size: 1.2rem;
    display: flex; align-items: center; justify-content: center; cursor: pointer; z-index: 10;
    opacity: 0; transition: opacity 0.2s ease, transform 0.1s ease; box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}
.post-card:hover .carousel-arrow { opacity: 1; }
.carousel-arrow:hover { background: #ffffff; transform: translateY(-50%) scale(1.1); }
.carousel-arrow:active { transform: translateY(-50%) scale(0.95); }
.carousel-arrow.prev { left: 8px; }
.carousel-arrow.next { right: 8px; }
@media (max-width: 768px) { .carousel-arrow { display: none !important; } }

/* ETIQUETAS */
.floating-tags { position: absolute; top: 12px; left: 12px; display: flex; flex-direction: column; gap: 6px; z-index: 10; }
.badge { background: rgba(0,0,0,0.65); color: #fff; padding: 4px 8px; border-radius: var(--radius-sm); font-size: 0.7rem; font-weight: 700; backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); letter-spacing: 0.5px; width: max-content; }
.badge.urgente { background: rgba(255, 56, 92, 0.9); }
.badge.gratis { background: rgba(16, 185, 129, 0.9); }

/* INFO */
.card-info { 
    padding: 10px; /* Reducimos 2px el padding para ganar espacio interior */
    width: 100%; 
}
.card-price { font-size: 1.3rem; font-weight: 800; color: var(--text-main); margin-bottom: 4px; line-height: 1.2; }
.card-title { font-size: 0.95rem; font-weight: 500; line-height: 1.4; margin-bottom: 8px; color: var(--text-main); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: break-word; }
.card-meta { 
    display: flex; 
    justify-content: space-between; 
    align-items: center; 
    font-size: 0.75rem; /* Un pelín más chico para mobile */
    color: var(--text-sec); 
    margin-bottom: 12px;
    flex-wrap: wrap; /* Permite que si no hay espacio, bajen de forma natural */
    gap: 4px;
}

/* DETALLES DE PRODUCTO (Condición y Categoría) */
.card-details {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
    font-size: 0.75rem;
}

.condition-badge {
    padding: 2px 6px;
    border-radius: 4px;
    font-weight: 600;
    letter-spacing: 0.3px;
}

/* Colores sutiles para la condición */
.condition-badge.nuevo { background: #dbeafe; color: #1d4ed8; } /* Azul suave */
.condition-badge.usado { background: var(--bg-app); color: var(--text-sec); } /* Gris neutro */

.category-btn {
    color: var(--text-sec);
    font-weight: 500;
    cursor: pointer;
    transition: color 0.2s ease;
    display: flex;
    align-items: center;
    gap: 4px;
}

.category-btn:hover, .category-btn:active {
    color: var(--primary);
    text-decoration: underline;
}

/* REACCIONES SOCIALES */
.card-social { display: flex; justify-content: space-between; align-items: center; border-top: 1px solid var(--border); padding-top: 12px; }
.reaction-group { display: flex; gap: 16px; }
.btn-reaction { font-size: 1.1rem; display: flex; align-items: center; gap: 4px; color: var(--text-sec); transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275); -webkit-tap-highlight-color: transparent; }
.btn-reaction:active { transform: scale(1.2); }
.btn-reaction span { font-size: 0.8rem; font-weight: 600; }
.btn-save { font-size: 1.3rem; }

/* SKELETONS (ACTUALIZADO A LA NUEVA ESTRUCTURA) */
.skeleton { break-inside: avoid; -webkit-column-break-inside: avoid; display: inline-block; width: 100%; background: var(--bg-card); border-radius: var(--radius-lg); overflow: hidden; margin-bottom: 16px; box-shadow: var(--shadow-card); }
.skel-img { width: 100%; aspect-ratio: 4/5; background: #e2e8f0; animation: pulse 1.5s infinite ease-in-out; }
.skel-body { padding: 12px; }
.skel-line { height: 12px; background: #e2e8f0; border-radius: 4px; margin-bottom: 10px; animation: pulse 1.5s infinite ease-in-out; }

@keyframes pulse { 0% { opacity: 0.6; } 50% { opacity: 0.3; } 100% { opacity: 0.6; } }

/* BOTTOM BAR MÓVIL */
.bottom-bar { position: fixed; bottom: 0; left: 0; right: 0; background: rgba(255,255,255,0.98); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); border-top: 1px solid var(--border); display: flex; justify-content: space-around; align-items: center; padding: 10px 0 calc(10px + var(--safe-bottom)); z-index: 1000; width: 100%; }
.nav-item { font-size: 1.5rem; color: var(--text-sec); padding: 8px 16px; display: flex; align-items: center; justify-content: center; transition: color 0.2s; -webkit-tap-highlight-color: transparent; }
.nav-item.active { color: var(--text-main); }
.nav-avatar { width: 28px; height: 28px; border-radius: 50%; border: 2px solid transparent; }
.nav-item.active .nav-avatar { border-color: var(--text-main); }
.post-btn span { background: var(--primary); color: #fff; width: 44px; height: 44px; display: flex; align-items: center; justify-content: center; border-radius: 14px; font-size: 1.8rem; font-weight: 300; margin-top: -6px; box-shadow: 0 4px 12px rgba(255, 56, 92, 0.3); }