:root {
    color-scheme: light;
    --accent: #3390ec;
    --accent-hover: #2a7fd4;
    --link: #3390ec;
    --bg: #eef1f5;
    --bar: rgba(238, 241, 245, .92);
    --surface: #fff;
    --text: #000;
    --meta: #6f7e8c;
    --border: #dfe3e7;
    --divider: #e6e9ed;
    --field: #f1f3f5;
    --chip: #e1e6eb;
    --icon: #3c4a57;
    --ph: #dfe3e7;
    --shadow: rgba(0, 0, 0, .12);
    /* радіуси як у Telegram */
    --r: 12px;
    --r-sm: 8px;
}

/* темна тема (як Telegram Night) — за налаштуванням системи користувача */
@media (prefers-color-scheme: dark) {
    :root {
        color-scheme: dark;
        --link: #6ab3f3;
        --bg: #0e1621;
        --bar: rgba(14, 22, 33, .92);
        --surface: #17212b;
        --text: #f5f5f5;
        --meta: #7f91a4;
        --border: #2b3a4a;
        --divider: #101921;
        --field: #242f3d;
        --chip: #242f3d;
        --icon: #aab8c5;
        --ph: #242f3d;
        --shadow: rgba(0, 0, 0, .35);
    }
}

html body {
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

main > .container {
    max-width: none;
    padding: 0 16px 24px;
}

/* search */
.search {
    position: sticky;
    top: 0;
    z-index: 10;
    margin: 0 -16px 16px;
    padding: 12px 16px;
    background: var(--bar);
    backdrop-filter: blur(10px);
}
#search-form { display: contents; }
.search { display: flex; align-items: center; gap: 8px; }
.search input[type=text] {
    flex: 1;
    border: 0;
    outline: 0;
    border-radius: var(--r);
    background: var(--surface);
    color: var(--text);
    box-shadow: 0 0 0 1px var(--border);
    padding: 11px 18px;
    font-size: 16px;
}
.search input[type=text]:focus { box-shadow: 0 0 0 2px var(--accent); }
.search .send, .search .clear, .filter-btn {
    flex: none;
    width: 44px; height: 44px;
    border: 0; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; text-decoration: none;
}
.search .send { background: var(--accent); }
.search .send svg { width: 22px; height: 22px; fill: #fff; }
.search .clear { background: var(--chip); color: var(--meta); font-size: 18px; }

/* filter */
.filter-btn { position: relative; background: var(--surface); box-shadow: 0 0 0 1px var(--border); color: var(--icon); }
.filter-btn svg { width: 22px; height: 22px; fill: currentColor; }
.filter-btn .badge {
    position: absolute; top: -4px; right: -4px; min-width: 18px; height: 18px; padding: 0 5px;
    border-radius: 9px; background: var(--accent); color: #fff; font-size: 11px; line-height: 18px; text-align: center;
}
.filter-panel {
    position: fixed; inset: 0; z-index: 100;
    display: flex; flex-direction: column;
    background: var(--surface);
    color: var(--text);
}
.filter-panel[hidden] { display: none; }
.fp-head { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--divider); }
.fp-title { font-size: 19px; font-weight: 600; }
.fp-close { border: 0; background: var(--chip); color: var(--meta); width: 40px; height: 40px; border-radius: 50%; font-size: 18px; cursor: pointer; }
.fp-body {
    flex: 1; overflow-y: auto; padding: 20px 16px;
    display: grid; gap: 18px 16px; align-content: start;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
}
.fp-field { display: flex; flex-direction: column; gap: 6px; }
.fp-field > span { font-size: 13px; color: var(--meta); font-weight: 500; }
.fp-field select, .fp-field input {
    width: 100%; border: 0; border-radius: var(--r-sm); background: var(--field); color: var(--text); padding: 12px 14px; font-size: 16px; outline: 0;
}
.fp-field select:focus, .fp-field input:focus { box-shadow: 0 0 0 2px var(--accent); background: var(--surface); }
.fp-range { display: flex; gap: 8px; }
.fp-foot { display: flex; gap: 10px; padding: 12px 16px calc(12px + env(safe-area-inset-bottom, 0px)); border-top: 1px solid var(--divider); }
.fp-reset { flex: none; padding: 13px 20px; border-radius: var(--r); background: var(--chip); color: var(--icon); text-decoration: none; font-weight: 500; }
.fp-apply { flex: 1; border: 0; border-radius: var(--r); background: var(--accent); color: #fff; font-size: 16px; font-weight: 600; cursor: pointer; }

.summary { color: var(--meta); font-size: 14px; margin-bottom: 12px; }

/* cards */
.cars {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 16px;
}
.car-card {
    background: var(--surface);
    border-radius: var(--r);
    overflow: hidden;
    box-shadow: 0 1px 2px var(--shadow);
    display: flex;
    flex-direction: column;
}
.car-img { display: block; width: 100%; height: 190px; object-fit: cover; }
.car-img-ph { display: flex; align-items: center; justify-content: center; }
.car-img-ph span { color: rgba(255, 255, 255, .9); font-size: 2.6rem; font-weight: 700; letter-spacing: .1em; }
.car-body { padding: 12px 14px 14px; display: flex; flex-direction: column; flex: 1; }
.car-title { font-weight: 600; font-size: 17px; color: var(--link); }
.car-sub { color: var(--meta); font-size: 13.5px; margin-bottom: 6px; }
.car-lines { font-size: 14px; line-height: 1.5; margin-bottom: 8px; }
.car-price { margin-top: auto; font-weight: 700; font-size: 20px; }

.empty { text-align: center; color: var(--meta); padding: 48px 0; }

/* gallery: колаж як альбом у Telegram */
.gallery {
    display: grid;
    gap: 2px;
    height: 190px;
    background: var(--ph);
}
.gallery.n2 { grid-template-columns: 1fr 1fr; }
.gallery.n3 { grid-template: 1fr 1fr / 3fr 2fr; }
.gallery.n3 .g-item:first-child { grid-row: span 2; }
.gallery.n4 { grid-template: 1fr 1fr / 1fr 1fr; }
.g-item {
    position: relative;
    padding: 0; border: 0; margin: 0;
    min-width: 0; min-height: 0;
    overflow: hidden;
    background: var(--ph);
    cursor: zoom-in;
}
.g-item img { display: block; width: 100%; height: 100%; object-fit: cover; }
.g-more {
    position: absolute; inset: 0;
    display: flex; align-items: center; justify-content: center;
    background: rgba(0, 0, 0, .5); color: #fff; font-size: 26px; font-weight: 600;
}

/* lightbox */
.lightbox {
    position: fixed; inset: 0; z-index: 200;
    display: flex; flex-direction: column;
    background: rgba(0, 0, 0, .98);
    color: #fff;
    user-select: none;
}
.lightbox[hidden] { display: none; }
.lb-top { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; }
.lb-count { font-size: 15px; opacity: .85; }
.lb-stage { position: relative; flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; padding: 0 56px; }
.lb-img { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: var(--r-sm); }
.lb-btn {
    border: 0; border-radius: 50%; width: 44px; height: 44px;
    background: rgba(255, 255, 255, .14); color: #fff; font-size: 26px; line-height: 1; cursor: pointer;
}
.lb-btn:hover { background: rgba(255, 255, 255, .25); }
.lb-stage .lb-btn { position: absolute; top: 50%; transform: translateY(-50%); }
.lb-prev { left: 8px; } .lb-next { right: 8px; }
.lb-thumbs { display: flex; justify-content: center; gap: 6px; padding: 12px 16px calc(12px + env(safe-area-inset-bottom, 0px)); overflow-x: auto; }
.lb-thumbs button { flex: none; width: 56px; height: 40px; padding: 0; border: 0; border-radius: 6px; overflow: hidden; opacity: .5; cursor: pointer; background: #222; }
.lb-thumbs button.active { opacity: 1; box-shadow: 0 0 0 2px var(--accent); }
.lb-thumbs img { width: 100%; height: 100%; object-fit: cover; display: block; }
@media (max-width: 600px) { .lb-stage { padding: 0; } .lb-stage .lb-btn { display: none; } }

/* "Ще" button */
.more { display: flex; justify-content: center; padding: 24px 0 8px; }
.more-btn {
    display: inline-flex; align-items: center; gap: 8px;
    border: 0; border-radius: var(--r); padding: 12px 32px;
    background: var(--accent); color: #fff; font-size: 16px; font-weight: 600; cursor: pointer;
    box-shadow: 0 2px 6px rgba(51, 144, 236, .35);
    transition: background .15s, transform .15s;
}
.more-btn:hover { background: var(--accent-hover); }
.more-btn:active { transform: scale(.97); }
.more-btn svg { width: 20px; height: 20px; }
.more.loading .more-btn { opacity: .7; cursor: progress; }
.more.loading .more-btn svg { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* шапка порталу */
.topbar {
    position: sticky; top: 0; z-index: 10;
    display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
    margin: 0 -16px 16px; padding: 12px 16px;
    background: var(--bar); backdrop-filter: blur(10px);
}
.topbar h1 { margin: 0; font-size: 20px; font-weight: 600; flex: 1; min-width: 0; }
.topbar .summary { margin: 0; }
.topbar .back {
    flex: none; width: 40px; height: 40px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    background: var(--surface); box-shadow: 0 0 0 1px var(--border);
    color: var(--icon); font-size: 26px; line-height: 1; text-decoration: none;
}
.car-card a.car-title { text-decoration: none; }
.car-card a.car-title:hover { text-decoration: underline; }

/* сторінка оголошення */
.post-view { max-width: 760px; margin: 0 auto; }
.post-view .gallery, .post-view .car-img { height: min(56vw, 420px); }
.post-view .car-price { margin: 0 0 12px; font-size: 26px; }
.specs { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0 0 16px; font-size: 15px; }
.specs dt { color: var(--meta); font-weight: 400; }
.specs dd { margin: 0; overflow-wrap: anywhere; }
.post-text { font-size: 15px; line-height: 1.55; padding: 12px 0; border-top: 1px solid var(--divider); overflow-wrap: anywhere; }
.post-text + .car-sub { margin: 0; }
.post-view .car-sub a { color: var(--link); }
