/* ==========================================================================
   Home category tiles (Views/Home/_CategoryTiles.cshtml)
   --------------------------------------------------------------------------
   Each tile is one picture with the category's name drawn into it (891x1143 in the design, kept
   here at 320px wide), its corners rounded by its own transparency. On a desktop they line up as
   many to a row as fit at 128px or more - nine on a full-width page - and the rest wrap to the
   next rows, as Digikala's categories do. On a phone they are one row that scrolls sideways.
   The title is the home rows'; the space around the section is the page's own (Page Builder's
   .tc-pb-sec), so the section brings none.
   ========================================================================== */

.tc-ctiles {
    margin: 0;
    font-family: yekanbakh, tahoma, sans-serif;
}

/* the title, and on a row that has one, its «مشاهده همه» at the far end (the home rows' link) */
.tc-ctiles__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 24px;
}

.tc-ctiles__title {
    margin: 0;
    font-size: 18px;
    font-weight: 700;
    line-height: 28px;
    color: #292D32;
}

.tc-ctiles__all {
    display: inline-flex;
    flex: 0 0 auto;
    align-items: center;
    gap: 6px;
    font-size: 16px;
    font-weight: 700;
    line-height: 24px;
    color: #168FDF;
    text-decoration: none;
}

/* the categories' «مشاهده همه» is a button (it opens the over-page) and only a phone has it: a
   wide screen shows every tile already */
button.tc-ctiles__all {
    margin: 0;
    padding: 0;
    border: 0;
    background: none;
    font-family: inherit;
    cursor: pointer;
}

.tc-ctiles__all--phone {
    display: none;
}

.tc-ctiles__all:hover {
    color: #168FDF;
    text-decoration: underline;
    text-underline-offset: 6px;
}

.tc-ctiles__all svg {
    width: 18px;
    height: 18px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

/* the brands' tiles: trimmed to their cards' edges (a logo's circle stands out of the top), so the gap
   between two is the rail's gap alone, as between the categories */
.tc-ctiles--brands .tc-ctiles__img {
    aspect-ratio: 320 / 397;
}

.tc-ctiles__list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(128px, 1fr));
    gap: 16px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.tc-ctiles__item {
    margin: 0;
    padding: 0;
}

.tc-ctiles__link {
    display: block;
    border-radius: 12px;
    transition: transform .2s ease;
}

.tc-ctiles__link:hover {
    transform: translateY(-3px);
}

.tc-ctiles__link:focus-visible {
    outline: 2px solid #292D32;
    outline-offset: 2px;
}

.tc-ctiles__img {
    display: block;
    width: 100%;
    max-width: none;
    height: auto;
    aspect-ratio: 320 / 411;
    object-fit: cover;
}

/* a brand's or a category's own picture, standing in until one is uploaded for the home page: a logo
   would be cut by the tall frame, so it sits whole on a light card of the frame's size - or its
   initial does, when it has no picture at all */
.tc-ctiles__img--plain {
    box-sizing: border-box;
    padding: 18%;
    border-radius: 12px;
    background: #F5F6F8;
    object-fit: contain;
}

.tc-ctiles__initial {
    display: grid;
    place-items: center;
    padding: 0;
    font-size: 32px;
    font-weight: 700;
    line-height: 1;
    color: #A1A1AA;
}

/* the name under the picture, when the admin chose so: two lines at most, centred */
.tc-ctiles__name {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    overflow: hidden;
    margin-top: 8px;
    font-size: 14px;
    font-weight: 600;
    line-height: 22px;
    color: #292D32;
    text-align: center;
    overflow-wrap: anywhere;
}

/* --------------------------------------------------------------------------
   Phones: one row, scrolled sideways, its ends at the screen's edges
   -------------------------------------------------------------------------- */

@media (max-width: 767.98px) {
    .tc-ctiles__head {
        margin-bottom: 16px;
    }

    .tc-ctiles__title {
        font-size: 16px;
        line-height: 26px;
    }

    .tc-ctiles__all {
        font-size: 14px;
        line-height: 22px;
    }

    .tc-ctiles__all svg {
        width: 16px;
        height: 16px;
    }

    /* the rail runs out to the screen's edges over the page's 8px gutter, its first tile still on
       the gutter's line */
    .tc-ctiles__list {
        display: flex;
        gap: 8px;
        margin-inline: -8px;
        padding-inline: 8px;
        /* the home product rows' scroller (home-showcase.css, NATIVE): the browser's own sideways
           scroll with its momentum and no snapping - snapping pulled the row back to a tile's edge
           after each flick and made it feel stiff on a phone */
        overflow-x: auto;
        overflow-y: hidden;
        overscroll-behavior-x: contain;
        -webkit-overflow-scrolling: touch;
        touch-action: auto;
        scrollbar-width: none;
    }

    .tc-ctiles__list::-webkit-scrollbar {
        display: none;
    }

    .tc-ctiles__item {
        flex: 0 0 auto;
        /* three and a part of the fourth, so the row reads as one that scrolls */
        width: calc((100vw - 16px) / 3.4);
        max-width: 132px;
    }

    .tc-ctiles__link:hover {
        transform: none;
    }

    .tc-ctiles__name {
        margin-top: 6px;
        font-size: 12px;
        line-height: 18px;
    }

    /* two rows that scroll sideways together (the admin's choice): the tiles run down each column
       first, so a flick moves both rows by the same tiles; a column is as wide as a one-row tile */
    .tc-ctiles--rows2 .tc-ctiles__list {
        display: grid;
        grid-template-columns: none;
        grid-template-rows: repeat(2, auto);
        grid-auto-flow: column;
        grid-auto-columns: min(calc((100vw - 16px) / 3.4), 132px);
        gap: 12px 8px;
    }

    .tc-ctiles--rows2 .tc-ctiles__item {
        width: auto;
        max-width: none;
    }
}

/* --------------------------------------------------------------------------
   The over-page (category-tiles.js), phones only: every tile, three to a row (four from 480px),
   a page of its own coming in from the side as the categories row's «همه» page does
   (page-builder.css, .tc-ct-page) - its back arrow, the browser's back, Esc or a drag to the
   left (overpage-swipe.js) close it. The brands' one has a search field over the tiles.
   -------------------------------------------------------------------------- */

.tc-ctiles-page[hidden] {
    display: none;
}

@media (max-width: 767.98px) {
    .tc-ctiles__all--phone {
        display: inline-flex;
    }

    html.tc-ctiles-locked,
    html.tc-ctiles-locked body {
        overflow: hidden;
    }

    .tc-ctiles-page {
        position: fixed;
        inset: 0;
        z-index: 100000;
        display: flex;
        direction: rtl;
        text-align: right;
        font-family: yekanbakh, tahoma, sans-serif;
        color: #292D32;
    }

    .tc-ctiles-page__panel {
        display: flex;
        flex-direction: column;
        width: 100%;
        height: 100%;
        background: #FFFFFF;
        transform: translateX(-100%);
        transition: transform .3s cubic-bezier(.22, .61, .36, 1);
    }

    .tc-ctiles-page.is-open .tc-ctiles-page__panel {
        transform: none;
    }

    .tc-ctiles-page__bar {
        display: flex;
        flex: 0 0 auto;
        align-items: center;
        gap: 4px;
        min-height: 56px;
        padding: 0 8px 0 16px;
        border-bottom: 1px solid #E6E8EB;
    }

    .tc-ctiles-page__back {
        display: flex;
        flex: 0 0 auto;
        align-items: center;
        justify-content: center;
        width: 40px;
        height: 40px;
        margin: 0;
        padding: 0;
        border: 0;
        border-radius: 8px;
        background: none;
        color: #292D32;
        cursor: pointer;
        -webkit-tap-highlight-color: transparent;
    }

    .tc-ctiles-page__back svg {
        width: 24px;
        height: 24px;
        fill: none;
        stroke: currentColor;
        stroke-width: 2;
        stroke-linecap: round;
        stroke-linejoin: round;
    }

    .tc-ctiles-page__title {
        flex: 1 1 auto;
        min-width: 0;
        margin: 0;
        overflow: hidden;
        font-size: 16px;
        font-weight: 700;
        line-height: 26px;
        white-space: nowrap;
        text-overflow: ellipsis;
    }

    /* the brands' search: the header's field, grey and rounded, its magnifier at the start */
    .tc-ctiles-page__search {
        position: relative;
        flex: 0 0 auto;
        padding: 12px 16px 4px;
    }

    .tc-ctiles-page__search svg {
        position: absolute;
        top: 50%;
        right: 28px;
        width: 20px;
        height: 20px;
        margin-top: 4px;
        transform: translateY(-50%);
        fill: none;
        stroke: #6B7280;
        stroke-width: 2.2;
        stroke-linecap: round;
        pointer-events: none;
    }

    .tc-ctiles-page__field {
        display: block;
        box-sizing: border-box;
        width: 100%;
        height: 44px;
        margin: 0;
        padding: 0 44px 0 14px;
        border: 1px solid transparent;
        border-radius: 12px;
        background: #F1F2F4;
        font-family: inherit;
        font-size: 16px;
        color: #292D32;
        outline: none;
        -webkit-appearance: none;
        appearance: none;
    }

    .tc-ctiles-page__field:focus {
        border-color: #D1D5DB;
        background: #FFFFFF;
    }

    .tc-ctiles-page__body {
        flex: 1 1 auto;
        overflow-y: auto;
        overscroll-behavior: contain;
        -webkit-overflow-scrolling: touch;
        padding: 16px 16px calc(24px + env(safe-area-inset-bottom, 0px));
    }

    .tc-ctiles-page__grid {
        display: grid;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 12px 8px;
        margin: 0;
        padding: 0;
        list-style: none;
    }

    .tc-ctiles-page__item {
        margin: 0;
        padding: 0;
    }

    .tc-ctiles-page__item[hidden] {
        display: none;
    }

    /* every brand of the store (_BrandTiles.cshtml): its logo on a white square, its name under it */
    .tc-ctiles-page__brand {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 6px;
        color: #18181B;
        text-decoration: none;
        -webkit-tap-highlight-color: transparent;
    }

    .tc-ctiles-page__logo {
        display: grid;
        place-items: center;
        width: 100%;
        aspect-ratio: 1 / 1;
        padding: 12px;
        box-sizing: border-box;
        border: 1px solid #ECECEE;
        border-radius: 14px;
        background: #FFFFFF;
        overflow: hidden;
    }

    .tc-ctiles-page__logo img {
        display: block;
        max-width: 100%;
        max-height: 100%;
        object-fit: contain;
    }

    .tc-ctiles-page__initial {
        font-size: 28px;
        font-weight: 700;
        line-height: 1;
        color: #A1A1AA;
    }

    .tc-ctiles-page__name {
        display: -webkit-box;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 2;
        overflow: hidden;
        width: 100%;
        font-size: 12px;
        font-weight: 600;
        line-height: 18px;
        text-align: center;
        overflow-wrap: anywhere;
    }

    .tc-ctiles-page__empty {
        margin: 32px 0 0;
        font-size: 14px;
        line-height: 22px;
        color: #6B7280;
        text-align: center;
    }
}

@media (min-width: 480px) and (max-width: 767.98px) {
    .tc-ctiles-page__grid {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }
}

@media (prefers-reduced-motion: reduce) {
    .tc-ctiles__link,
    .tc-ctiles-page__panel {
        transition: none;
    }
}
