/* ============================================================
   КАРТОЧКИ ОБЪЯВЛЕНИЙ — вид «Авито».
   Раздел board / realty / auto (шаблон templates/board/index.php).

   Прежняя карточка собиралась через :has() и grid-области
   (title / thumb / main / under / price). Фото получало
   height:100% и растягивалось, цена уходила под фото,
   описание прыгало — отсюда «всё в разные стороны».

   Новая схема: фото сверху во всю ширину карточки с
   фиксированным соотношением, под ним ровный поток
   цена → заголовок → рубрика/город → адрес → подвал.
   Подключается после legacy.css, поэтому перекрывает его.
   ============================================================ */

/* ---------- Сетка списка ---------- */

.d-main .board-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(232px, 1fr));
    gap: 16px;
    align-items: stretch;
}

/* ---------- Карточка ---------- */

.d-main .item-card,
.d-main .item-card:has(.item-card-thumb) {
    display: flex;
    flex-direction: column;
    grid-template-columns: none;
    grid-template-areas: none;
    gap: 0;
    padding: 0;
    background: #fff;
    border: 1px solid var(--d-line, #e7e1d8);
    border-radius: 12px;
    overflow: hidden;
    align-items: stretch;
    height: 100%;
    transition: border-color .15s, box-shadow .15s;
}

.d-main .item-card:hover,
.d-main .item-card:has(.item-card-thumb):hover {
    border-color: #cfc4b4;
    box-shadow: 0 6px 20px -8px rgba(31, 27, 23, .22);
    transform: none;
}

/* ---------- Фото ---------- */

.d-main .item-card-thumb {
    display: block;
    position: relative;
    width: 100%;
    height: auto;
    aspect-ratio: 4 / 3;
    min-height: 0;
    overflow: hidden;
    background: #f1ede7;
    border-radius: 0;
    flex: none;
}

.d-main .item-card:has(.item-card-thumb) .item-card-thumb {
    width: 100%;
    height: auto;
    min-height: 0;
    grid-area: auto;
}

.d-main .item-card-thumb img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform .3s ease;
}

.d-main .item-card:hover .item-card-thumb img {
    transform: scale(1.03);
}

/* Заглушка, если фото нет */
.d-main .item-card-thumb-ph {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 10px;
    font-size: 12.5px;
    font-weight: 600;
    color: #9a9086;
    text-align: center;
    background:
        linear-gradient(135deg, #f6f2ec 0%, #eee8df 100%);
}

/* ---------- Тело карточки ---------- */

.d-main .item-card-body {
    display: flex;
    flex-direction: column;
    gap: 5px;
    padding: 12px 13px 13px;
    min-width: 0;
    flex: 1 1 auto;
}

/* Цена — крупно и первой, как на Авито */
.d-main .item-card-price,
.d-main .item-card:has(.item-card-thumb) .item-card-price {
    grid-area: auto;
    justify-self: auto;
    display: block;
    order: -1;
    font-size: 18px;
    font-weight: 800;
    letter-spacing: -.02em;
    line-height: 1.2;
    color: var(--d-text, #1f1b17);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.d-main .item-card-price strong {
    font-weight: 800;
}

.d-main .item-card-price .muted,
.d-main .item-card-price .small {
    display: none;
}

/* Заголовок */
.d-main .item-card-title {
    margin: 0;
    font-size: 14.5px;
    line-height: 1.36;
    font-weight: 600;
}

.d-main .item-card-title a {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-decoration: none;
    color: var(--d-text, #1f1b17);
    transition: color .15s;
}

.d-main .item-card-title a:hover {
    color: var(--d-accent, #8e2233);
    text-decoration: none;
}

/* Рубрика и город — мелкой строкой */
.d-main .item-card-under {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 3px 7px;
    font-size: 12px;
    line-height: 1.35;
    color: var(--d-muted, #736b62);
    min-width: 0;
}

.d-main .item-card-under a {
    text-decoration: none;
    color: var(--d-muted, #736b62);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 100%;
    transition: color .15s;
}

.d-main .item-card-under a:hover {
    color: var(--d-accent, #8e2233);
    text-decoration: none;
}

.d-main .item-card-under .tag {
    color: var(--d-accent, #8e2233);
    font-weight: 600;
    font-size: 11.5px;
    background: var(--d-accent-soft, #f7eaec);
    border-radius: 5px;
    padding: 1px 6px;
    flex: none;
}

.d-main .item-card-under .tag:hover {
    text-decoration: none;
    filter: brightness(.96);
}

/* Адрес */
.d-main .item-card-addr {
    font-size: 12px;
    color: var(--d-muted, #736b62);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 100%;
}

/* Подвал прижат к низу карточки */
.d-main .item-card-foot {
    margin-top: auto;
    padding-top: 7px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    font-size: 11.5px;
    color: #9a9086;
}

.d-main .item-card-foot time,
.d-main .item-card-views {
    white-space: nowrap;
}

.d-main .item-card-views {
    margin-left: auto;
}

/* Старые элементы, которых больше нет в разметке, но
   которые могли остаться у других шаблонов — гасим. */
.d-main .item-card > .item-card-main {
    grid-area: auto;
}

/* ---------- Плотнее на средних экранах ---------- */

@media (max-width: 1180px) {
    .d-main .board-list {
        grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
        gap: 14px;
    }
}

/* ---------- Мобильные: две колонки, как в приложении ---------- */

@media (max-width: 700px) {
    .d-main .board-list {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 10px;
    }

    .d-main .item-card-thumb {
        aspect-ratio: 1 / 1;
    }

    .d-main .item-card-body {
        padding: 9px 10px 10px;
        gap: 4px;
    }

    .d-main .item-card-price {
        font-size: 15px;
    }

    .d-main .item-card-title {
        font-size: 13px;
    }

    .d-main .item-card-title a {
        -webkit-line-clamp: 2;
    }

    .d-main .item-card-addr {
        display: none;
    }

    .d-main .item-card-foot {
        padding-top: 5px;
        font-size: 11px;
    }

    .d-main .item-card-views {
        display: none;
    }
}

@media (max-width: 420px) {
    .d-main .board-list {
        grid-template-columns: minmax(0, 1fr);
    }

    .d-main .item-card-thumb {
        aspect-ratio: 16 / 10;
    }

    .d-main .item-card-price {
        font-size: 16px;
    }

    .d-main .item-card-title {
        font-size: 14px;
    }

    .d-main .item-card-addr {
        display: block;
    }
}
