/* ==========================================================================
   Sol Caribe Group LLC — Catálogo de la ciudad (Compras y Farmacias)
   Plan 2026-11-12-rediseno-catalogo-ciudad. Prefijo .cc-
   Barra de ubicación fija, estanterías deslizables, tarjeta de producto,
   cabecera de "Ver todo" y barra inferior del carrito en el móvil.
   Usa los tokens de css/styles.css (se carga después).
   ========================================================================== */

:root {
    --cc-surface: #FFFFFF;
    --cc-photo-bg: #F3EFE8;
    --cc-line: rgba(10, 58, 64, 0.1);
    --cc-radius: 14px;
    --cc-card-w: 208px;
    --cc-focus: 0 0 0 3px var(--color-accent-dark);
}

/* ── Barra de ubicación ─────────────────────────────────────────────────── */
.cc-locbar {
    position: sticky;
    top: 0;
    z-index: 900;
    background: rgba(255, 255, 255, 0.97);
    border-bottom: 1px solid var(--cc-line);
    transition: top 0.3s ease;
}

/* Mientras el menú fijo está visible, la barra queda justo debajo. */
body:has(.navbar.scrolled:not(.navbar-hidden)) .cc-locbar {
    top: 75px;
}

.cc-locbar[hidden] {
    display: none;
}

.cc-locbar-inner {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    min-height: 52px;
    font-size: 0.92rem;
    color: var(--color-text-main);
}

.cc-locbar-inner > svg {
    width: 18px;
    height: 18px;
    flex: none;
    fill: none;
    stroke: var(--color-accent-dark);
    stroke-width: 2;
}

.cc-locbar-text {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.cc-locbar-text strong {
    color: var(--color-primary);
}

.cc-locbar-change {
    margin-left: auto;
    flex: none;
    min-height: 44px;
    padding: 0 0.9rem;
    border: 1px solid var(--cc-line);
    border-radius: 999px;
    background: var(--cc-surface);
    color: var(--color-primary);
    font: 600 0.88rem var(--font-body);
    cursor: pointer;
}

.cc-locbar-change:hover {
    border-color: var(--color-primary);
}

/* La cabecera del catálogo se queda en título: los productos empiezan antes. */
#catalog-section {
    padding-top: 3rem;
}

#catalog-header {
    margin-bottom: 1.25rem;
}

#catalog-header p {
    display: none;
}

/* ── Estanterías ───────────────────────────────────────────────────────── */
.cc-shelves {
    display: grid;
    gap: 2.25rem;
    margin-top: 1.75rem;
}

.cc-shelves[hidden] {
    display: none;
}

.cc-shelf {
    min-width: 0;
}

.cc-shelf-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 0.85rem;
}

.cc-shelf-head h3 {
    margin: 0;
    font: 700 1.2rem/1.3 var(--font-body);
    color: var(--color-primary);
}

.cc-shelf-count {
    display: inline-block;
    margin-left: 0.35rem;
    padding: 0.1rem 0.55rem;
    border-radius: 999px;
    background: rgba(10, 58, 64, 0.07);
    color: var(--color-text-muted);
    font-size: 0.78rem;
    font-weight: 600;
    vertical-align: 0.15em;
}

.cc-shelf-all {
    display: inline-flex;
    align-items: center;
    gap: 0.15rem;
    flex: none;
    min-height: 44px;
    padding: 0 0.25rem;
    border: 0;
    background: none;
    color: var(--color-accent-dark);
    font: 700 0.92rem var(--font-body);
    cursor: pointer;
}

.cc-shelf-all svg {
    width: 18px;
    height: 18px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2.4;
}

.cc-shelf-all:hover {
    color: var(--color-primary);
}

.cc-track-wrap {
    position: relative;
}

.cc-track {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: var(--cc-card-w);
    gap: 1rem;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scroll-snap-type: x mandatory;
    scroll-padding-inline: 2px;
    padding: 2px 2px 0.6rem;
    scrollbar-width: none;
}

.cc-track::-webkit-scrollbar {
    display: none;
}

.cc-track-item {
    scroll-snap-align: start;
    min-width: 0;
    display: flex;
}

/* Flechas: solo con ratón y pantalla ancha; en el móvil se desliza con el dedo. */
.cc-arrow {
    display: none;
}

@media (hover: hover) and (min-width: 900px) {
    .cc-arrow {
        position: absolute;
        top: calc(var(--cc-card-w) / 2 - 22px);
        z-index: 2;
        display: grid;
        place-items: center;
        width: 44px;
        height: 44px;
        border: 1px solid var(--cc-line);
        border-radius: 50%;
        background: var(--cc-surface);
        color: var(--color-primary);
        box-shadow: var(--shadow-md);
        cursor: pointer;
        transition: opacity 0.2s ease;
    }

    .cc-arrow svg {
        width: 20px;
        height: 20px;
        fill: none;
        stroke: currentColor;
        stroke-width: 2.4;
    }

    .cc-arrow-prev {
        left: -18px;
    }

    .cc-arrow-next {
        right: -18px;
    }

    .cc-arrow:disabled {
        opacity: 0;
        pointer-events: none;
    }
}

/* Tira de tiendas */
.cc-stores .cc-track {
    grid-auto-columns: 150px;
}

.cc-store {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.45rem;
    width: 100%;
    padding: 1rem 0.75rem;
    border: 1px solid var(--cc-line);
    border-radius: var(--cc-radius);
    background: var(--cc-surface);
    color: var(--color-text-main);
    font-family: var(--font-body);
    text-align: center;
    cursor: pointer;
    transition: border-color 0.2s ease, transform 0.2s ease;
}

.cc-store:hover {
    border-color: var(--color-primary);
    transform: translateY(-2px);
}

.cc-store-logo {
    display: block;
    width: 68px;
    height: 68px;
    border-radius: 50%;
    overflow: hidden;
    background: var(--cc-photo-bg);
    border: 1px solid var(--cc-line);
}

.cc-store-logo img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.cc-store-logo.sin-foto img {
    object-fit: contain;
    padding: 10px;
}

.cc-store-name {
    font-size: 0.9rem;
    font-weight: 700;
    line-height: 1.25;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.cc-store-count {
    font-size: 0.78rem;
    color: var(--color-text-muted);
}

/* ── Tarjeta de producto ───────────────────────────────────────────────── */
.cc-card {
    position: relative;
    display: flex;
    flex-direction: column;
    width: 100%;
    background: var(--cc-surface);
    border: 1px solid var(--cc-line);
    border-radius: var(--cc-radius);
    overflow: hidden;
    container-type: inline-size;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.cc-card:hover {
    border-color: rgba(10, 58, 64, 0.22);
    box-shadow: var(--shadow-md);
}

.cc-card-main {
    display: flex;
    flex-direction: column;
    flex: 1;
    width: 100%;
    padding: 0;
    border: 0;
    background: none;
    color: inherit;
    font-family: var(--font-body);
    text-align: left;
    cursor: pointer;
}

.cc-card-img {
    position: relative;
    display: block;
    aspect-ratio: 1;
    background: var(--cc-photo-bg);
}

/* Foto entera: muchas son carteles con texto y recortarlas se come el producto. */
.cc-card-img img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: contain;
    padding: 6px;
}

.cc-card-img.sin-foto img {
    padding: 22%;
    opacity: 0.85;
}

.cc-card-flag {
    position: absolute;
    top: 8px;
    left: 8px;
    padding: 0.2rem 0.55rem;
    border-radius: 999px;
    background: var(--color-text-main);
    color: #FFFFFF;
    font-size: 0.72rem;
    font-weight: 700;
}

.cc-card-photos {
    position: absolute;
    top: 8px;
    right: 8px;
    display: inline-flex;
    align-items: center;
    gap: 0.2rem;
    padding: 0.15rem 0.45rem;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.92);
    color: var(--color-text-main);
    font-size: 0.72rem;
    font-weight: 700;
}

.cc-card-photos svg {
    width: 13px;
    height: 13px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
}

.cc-card-body {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    padding: 0.75rem 0.85rem 0.9rem;
}

.cc-card-name {
    font-size: 0.9rem;
    font-weight: 600;
    line-height: 1.3;
    color: var(--color-text-main);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    min-height: 2.6em;
}

.cc-card-price {
    font-size: 1.1rem;
    font-weight: 800;
    color: var(--color-primary);
    font-variant-numeric: tabular-nums;
}

.cc-card-price .product-card-from {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--color-text-muted);
}

.cc-card-meta {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--color-accent-dark);
}

.cc-card-seller {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    margin-top: 0.15rem;
    font-size: 0.76rem;
    color: var(--color-text-muted);
    min-width: 0;
}

.cc-card-seller svg {
    width: 13px;
    height: 13px;
    flex: none;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
}

.cc-card-seller span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.cc-card.is-sold-out .cc-card-img img {
    opacity: 0.5;
}

/* Botón "+": esquina inferior derecha de la foto. */
.cc-card-add {
    position: absolute;
    top: 8px;
    top: calc(100cqi - 52px);
    right: 8px;
    display: grid;
    place-items: center;
    width: 44px;
    height: 44px;
    border: 0;
    border-radius: 50%;
    background: var(--color-accent);
    color: var(--color-primary);
    box-shadow: var(--shadow-md);
    cursor: pointer;
    transition: transform 0.15s ease, background-color 0.2s ease;
}

.cc-card-add svg {
    width: 22px;
    height: 22px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2.6;
    stroke-linecap: round;
}

.cc-card-add:hover {
    background: var(--color-accent-hover);
}

.cc-card-add:active {
    transform: scale(0.94);
}

.cc-card-add.is-added {
    background: var(--color-success);
    color: #FFFFFF;
}

/* Foco visible en todo lo que se pulsa */
.cc-card-main:focus-visible,
.cc-card-add:focus-visible,
.cc-store:focus-visible,
.cc-shelf-all:focus-visible,
.cc-arrow:focus-visible,
.cc-back:focus-visible,
.cc-locbar-change:focus-visible,
.cc-cartbar-btn:focus-visible {
    outline: none;
    box-shadow: var(--cc-focus);
}

.cc-card-main:focus-visible {
    border-radius: var(--cc-radius);
}

/* Cuadrícula ("Ver todo", búsqueda y tienda virtual) con la tarjeta nueva */
.product-grid:has(.cc-card) {
    grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
    gap: 1rem;
}

.product-grid[hidden],
.catalog-count[hidden],
.catalog-sort[hidden] {
    display: none;
}

/* ── Cabecera de "Ver todo" ────────────────────────────────────────────── */
.cc-gridhead {
    display: flex;
    align-items: center;
    gap: 0.9rem;
    margin: 1.25rem 0 0.25rem;
}

.cc-gridhead[hidden] {
    display: none;
}

.cc-back {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    flex: none;
    min-height: 44px;
    padding: 0 1rem 0 0.7rem;
    border: 1px solid var(--cc-line);
    border-radius: 999px;
    background: var(--cc-surface);
    color: var(--color-primary);
    font: 600 0.9rem var(--font-body);
    cursor: pointer;
}

.cc-back svg {
    width: 18px;
    height: 18px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2.4;
}

.cc-back:hover {
    border-color: var(--color-primary);
}

.cc-gridhead-title {
    margin: 0;
    min-width: 0;
    font: 700 1.3rem/1.25 var(--font-body);
    color: var(--color-primary);
    overflow-wrap: anywhere;
}

/* ── Siluetas de carga ─────────────────────────────────────────────────── */
.cc-skel-title {
    width: 180px;
    height: 22px;
    margin-bottom: 0.85rem;
    border-radius: 6px;
    background: rgba(10, 58, 64, 0.08);
}

.cc-skel-card {
    height: calc(var(--cc-card-w) + 110px);
    border-radius: var(--cc-radius);
    background: linear-gradient(90deg, rgba(10, 58, 64, 0.06) 25%, rgba(10, 58, 64, 0.11) 50%, rgba(10, 58, 64, 0.06) 75%);
    background-size: 200% 100%;
    animation: cc-shimmer 1.4s ease-in-out infinite;
}

@keyframes cc-shimmer {
    from { background-position: 200% 0; }
    to { background-position: -200% 0; }
}

/* ── Barra inferior del carrito (solo móvil) ───────────────────────────── */
.cc-cartbar {
    display: none;
}

@media (max-width: 767px) {
    :root {
        --cc-card-w: min(44vw, 190px);
    }

    .cc-shelves {
        gap: 1.75rem;
    }

    .cc-track {
        gap: 0.75rem;
    }

    .cc-stores .cc-track {
        grid-auto-columns: 128px;
    }

    .product-grid:has(.cc-card) {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 0.75rem;
    }

    .cc-card-body {
        padding: 0.65rem 0.7rem 0.8rem;
    }

    .cc-gridhead-title {
        font-size: 1.1rem;
    }

    .cc-cartbar {
        position: fixed;
        left: 12px;
        right: 12px;
        bottom: calc(12px + env(safe-area-inset-bottom));
        z-index: 1400;
        display: block;
    }

    .cc-cartbar[hidden] {
        display: none;
    }

    .cc-cartbar-btn {
        display: flex;
        align-items: center;
        gap: 0.75rem;
        width: 100%;
        min-height: 56px;
        padding: 0.6rem 1.1rem;
        border: 0;
        border-radius: 16px;
        background: var(--color-primary);
        color: #FFFFFF;
        font: 600 0.95rem var(--font-body);
        box-shadow: var(--shadow-lg);
        cursor: pointer;
    }

    .cc-cartbar-count {
        padding: 0.15rem 0.6rem;
        border-radius: 999px;
        background: rgba(255, 255, 255, 0.14);
        font-size: 0.85rem;
    }

    .cc-cartbar-total {
        font-weight: 800;
        font-variant-numeric: tabular-nums;
    }

    .cc-cartbar-cta {
        margin-left: auto;
        color: var(--color-accent);
        font-weight: 700;
    }

    /* Con la barra visible sobra el botón flotante y hace falta sitio al final. */
    body.has-cartbar .cart-fab {
        display: none;
    }

    body.has-cartbar {
        padding-bottom: 84px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .cc-locbar,
    .cc-store,
    .cc-card,
    .cc-card-add,
    .cc-arrow {
        transition: none;
    }

    .cc-store:hover {
        transform: none;
    }

    .cc-skel-card {
        animation: none;
    }
}

/* ==========================================================================
   Movimiento y materiales (criterios de los WWDC de Apple; ver js/fluido.js)
   - Respuesta en el momento de pulsar, no al soltar.
   - Materiales translúcidos para lo que flota encima del contenido.
   - La ficha y el cajón se animan con transform/opacity desde JS (se pueden
     interrumpir y arrastrar); aquí solo se fija su estado de reposo.
   ========================================================================== */

/* ── Respuesta al pulsar ── */
.cc-card,
.cc-store,
.cc-card-add,
.cc-shelf-all,
.cc-back,
.cc-locbar-change,
.cc-cartbar-btn,
#catalog-section .catalog-chip,
#catalog-section .btn,
#selector .form-control,
.storefront-back {
    -webkit-tap-highlight-color: transparent;
}

.cc-card:has(.cc-card-main:active) {
    transform: scale(0.98);
    transition: transform 100ms ease-out;
}

.cc-store:active,
.cc-card-add:active,
.cc-shelf-all:active,
.cc-back:active,
.cc-locbar-change:active,
.cc-cartbar-btn:active,
#catalog-section .catalog-chip:active,
.cart-drawer .btn:active,
.product-detail-modal .btn:active {
    transform: scale(0.97);
    transition: transform 100ms ease-out;
}

/* Los efectos de "pasar por encima" solo donde hay ratón: en el móvil se quedaban pegados. */
@media (hover: none) {
    .cc-card:hover {
        border-color: var(--cc-line);
        box-shadow: none;
    }

    .cc-store:hover {
        transform: none;
        border-color: var(--cc-line);
    }
}

/* ── Material de la barra de ubicación: el catálogo pasa por debajo ── */
.cc-locbar {
    background: rgba(255, 255, 255, 0.72);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    backdrop-filter: blur(20px) saturate(180%);
    border-bottom: 0;
    box-shadow: 0 1px 0 rgba(10, 58, 64, 0.06);
}

.cc-locbar:not([hidden]) {
    animation: cc-materialize 0.45s cubic-bezier(0.22, 1, 0.36, 1) both;
}

@keyframes cc-materialize {
    from { opacity: 0; transform: translateY(-8px); filter: blur(6px); }
    to { opacity: 1; transform: none; filter: none; }
}

/* ── Barra del carrito (móvil): material oscuro que sube al aparecer ── */
@media (max-width: 767px) {
    .cc-cartbar-btn {
        background: rgba(10, 58, 64, 0.86);
        -webkit-backdrop-filter: blur(20px) saturate(160%);
        backdrop-filter: blur(20px) saturate(160%);
        border: 1px solid rgba(255, 255, 255, 0.08);
    }

    .cc-cartbar:not([hidden]) {
        animation: cc-rise 0.45s cubic-bezier(0.22, 1, 0.36, 1) both;
    }
}

@keyframes cc-rise {
    from { opacity: 0; transform: translateY(120%); }
    to { opacity: 1; transform: none; }
}

/* ── Estanterías arrastrables con ratón ── */
@media (hover: hover) {
    .cc-track {
        cursor: grab;
    }
}

.cc-track.is-dragging {
    cursor: grabbing;
    user-select: none;
}

.cc-track img {
    -webkit-user-drag: none;
    user-select: none;
}

/* ── Ficha de producto ── */
.product-detail-overlay {
    -webkit-backdrop-filter: blur(4px);
    backdrop-filter: blur(4px);
}

.product-detail-modal {
    will-change: transform, opacity;
    overscroll-behavior: contain;
}

.cc-grabber {
    display: none;
}

/* En el móvil la ficha es una hoja que sube desde abajo y se baja con el asa. */
@media (max-width: 639px) {
    .product-detail-overlay {
        align-items: flex-end;
        padding: 0;
    }

    .product-detail-modal {
        max-width: none;
        max-height: 92vh;
        max-height: 92dvh;
        border-radius: 20px 20px 0 0;
        padding-bottom: env(safe-area-inset-bottom);
    }

    .product-detail-modal .product-detail-img {
        border-radius: 0;
    }

    .cc-grabber {
        position: sticky;
        top: 0;
        z-index: 3;
        display: flex;
        justify-content: center;
        align-items: center;
        height: 28px;
        margin-bottom: -28px;
        touch-action: none;
        cursor: grab;
    }

    .cc-grabber span {
        width: 40px;
        height: 5px;
        border-radius: 999px;
        background: rgba(255, 255, 255, 0.9);
        box-shadow: 0 0 0 1px rgba(10, 58, 64, 0.18);
    }
}

/* ── Cajón del carrito: se mueve con transform (arrastrable e interrumpible) ── */
.cart-drawer,
.cart-drawer.active {
    right: 0;
}

.cart-drawer {
    transform: translateX(calc(100% + 40px));
    transition: none;
    touch-action: pan-y;
    will-change: transform;
}

.cart-drawer.active {
    transform: none;
}

.cart-drawer-overlay {
    display: block;
    opacity: 0;
    pointer-events: none;
    -webkit-backdrop-filter: blur(4px);
    backdrop-filter: blur(4px);
}

.cart-drawer-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

/* ── Tipografía: interletrado según tamaño ── */
.page-hero h1 {
    letter-spacing: -0.02em;
    line-height: 1.08;
}

#catalog-header h2,
#selector .section-header h2 {
    letter-spacing: -0.015em;
}

.cc-shelf-head h3 {
    letter-spacing: -0.012em;
    line-height: 1.2;
}

.cc-gridhead-title {
    letter-spacing: -0.015em;
}

.cc-card-name,
.cc-store-name {
    letter-spacing: -0.005em;
}

.cc-card-meta,
.cc-store-count,
.cc-card-seller {
    letter-spacing: 0.005em;
}

/* La ubicación es la tarea principal de esta página: el hero ocupa menos. */
.page-hero {
    padding-bottom: 56px;
}

/* ── Accesibilidad: movimiento, transparencia y contraste ── */
@media (prefers-reduced-motion: reduce) {
    .cc-card:has(.cc-card-main:active),
    .cc-store:active,
    .cc-card-add:active,
    .cc-shelf-all:active,
    .cc-back:active,
    .cc-locbar-change:active,
    .cc-cartbar-btn:active,
    #catalog-section .catalog-chip:active,
    .cart-drawer .btn:active,
    .product-detail-modal .btn:active {
        transform: none;
        opacity: 0.7;
    }

    .cc-locbar:not([hidden]),
    .cc-cartbar:not([hidden]) {
        animation: cc-fade 0.2s ease-out both;
    }
}

@keyframes cc-fade {
    from { opacity: 0; }
    to { opacity: 1; }
}

@media (prefers-reduced-transparency: reduce) {
    .cc-locbar {
        background: #FFFFFF;
        -webkit-backdrop-filter: none;
        backdrop-filter: none;
    }

    .cc-cartbar-btn {
        background: var(--color-primary);
        -webkit-backdrop-filter: none;
        backdrop-filter: none;
    }

    .product-detail-overlay,
    .cart-drawer-overlay {
        -webkit-backdrop-filter: none;
        backdrop-filter: none;
    }
}

@media (prefers-contrast: more) {
    .cc-locbar {
        background: #FFFFFF;
        -webkit-backdrop-filter: none;
        backdrop-filter: none;
        border-bottom: 1px solid var(--color-primary);
    }

    .cc-card,
    .cc-store {
        border-color: rgba(10, 58, 64, 0.45);
    }

    .cc-cartbar-btn {
        background: var(--color-primary);
        border: 1px solid #FFFFFF;
    }
}

/* ── Categorías bajo el buscador (portada) ── */
.cc-catbar {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-width: 0;
}

.cc-catbar-label {
    flex: none;
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--color-text-muted);
}

.cc-catbar-list {
    display: flex;
    gap: 0.5rem;
    min-width: 0;
    overflow-x: auto;
    padding: 2px 2px 0.4rem;
    scrollbar-width: none;
}

.cc-catbar-list::-webkit-scrollbar {
    display: none;
}

.cc-catbar .catalog-chip {
    min-height: 40px;
}

@media (max-width: 767px) {
    .cc-catbar {
        flex-direction: column;
        align-items: stretch;
        gap: 0.4rem;
    }
}
