*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: Arial, sans-serif; background: #f0f2f5; color: #222; font-size: 14px; }

/* ── TOP BAR ── */
.topbar { background: #1a3a5c; color: #fff; padding: 10px 20px; display: flex; align-items: center; gap: 16px; }
.topbar h1 { font-size: 20px; font-weight: 700; }
.topbar span { font-size: 13px; opacity: .75; }

.wrap { max-width: 1280px; margin: 0 auto; padding: 16px; }

/* ── FILTER GROUP GRID ── */
.fg-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 10px;
    align-items: center;
}
.fg-item {
    display: flex;
    align-items: stretch;
    border: 1px solid #c5cdd8;
    border-radius: 6px;
    overflow: hidden;
    background: #fff;
}
.fg-item.fg-active {
    border-color: #1a3a5c;
    box-shadow: 0 0 0 2px rgba(26,58,92,.15);
}
.fg-btn {
    display: block;
    padding: 6px 12px;
    font-size: 13px;
    font-weight: 600;
    color: #1a3a5c;
    white-space: nowrap;
    background: transparent;
    border: none;
    cursor: pointer;
    font-family: inherit;
    text-decoration: none;
}
.fg-item.fg-active .fg-btn { color: #fff; background: #1a3a5c; }
.fg-btn:hover { background: #e8edf5; }
.fg-item.fg-active .fg-btn:hover { background: #245080; }
.fg-hint { display: block; font-size: 10px; font-weight: 400; color: #888; line-height: 1.2; margin-top: 1px; }
.fg-item.fg-active .fg-hint { color: rgba(255,255,255,.6); }
.fg-rename, .fg-del {
    border: none;
    border-left: 1px solid #e0e5ec;
    background: transparent;
    cursor: pointer;
    font-size: 11px;
    padding: 0 7px;
    color: #aaa;
}
.fg-rename:hover { background: #f0f4fa; color: #1a3a5c; }
.fg-del:hover { background: #fee; color: #e74c3c; }
.fg-item.fg-active .fg-rename,
.fg-item.fg-active .fg-del { border-left-color: #c5cdd8; color: #888; }
.fg-item.fg-active .fg-rename:hover { background: #f0f4fa; color: #1a3a5c; }
.fg-item.fg-active .fg-del:hover    { background: #fee; color: #e74c3c; }
.fg-new {
    background: transparent;
    border: 1px dashed #c5cdd8;
    border-radius: 6px;
    padding: 6px 12px;
    font-size: 13px;
    color: #888;
    cursor: pointer;
}
.fg-new:hover { border-color: #1a3a5c; color: #1a3a5c; background: #f0f4fa; }

/* ── FILTER PANEL ── */
.filter-panel { background: #fff; border: 1px solid #d0d5dd; border-radius: 8px; padding: 12px 16px; margin-bottom: 16px; }
.filter-panel h2 {
    font-size: 14px; font-weight: 700; color: #1a3a5c;
    display: flex; justify-content: space-between; align-items: center;
    cursor: pointer; user-select: none;
    padding-bottom: 10px; border-bottom: 2px solid #1a3a5c; margin-bottom: 12px;
}
.filter-panel h2:hover { color: #245080; }
#filterToggleIcon { font-size: 13px; color: #888; }
#filterBody.collapsed { display: none; }

/* ── FILTER BLOCKS (single-row layout) ── */
.mm-blocks { display: flex; flex-direction: column; gap: 7px; margin-bottom: 10px; }

.mm-block {
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    gap: 5px;
    padding: 7px 10px;
    border: 1px solid #dde2ea;
    border-radius: 7px;
    background: #f7f9fc;
    overflow-x: auto;
}
.mm-block::-webkit-scrollbar { height: 3px; }
.mm-block::-webkit-scrollbar-thumb { background: #ccc; border-radius: 2px; }

.block-num { font-weight: 700; font-size: 11px; color: #1a3a5c; min-width: 20px; flex-shrink: 0; }

.mm-block select,
.mm-block input[type=number] {
    padding: 4px 6px;
    border: 1px solid #c5cdd8;
    border-radius: 4px;
    font-size: 12px;
    background: #fff;
    flex-shrink: 0;
    height: 28px;
}
.mm-block select:focus,
.mm-block input[type=number]:focus { outline: 1px solid #1a3a5c; border-color: #1a3a5c; }

.sel-make   { min-width: 60px;  max-width: 80px;  }
.sel-model  { min-width: 55px;  max-width: 75px;  }
.sel-year   { width: 72px; }
.inp-price  { width: 75px; }
.inp-eng    { width: 56px; }
.sel-engine { min-width: 43px;  max-width: 65px;  }
.sel-gearbox{ min-width: 53px;  max-width: 77px;  }
.sel-seats  { min-width: 63px;  max-width: 80px;  }
.sel-mileage{ min-width: 58px;  max-width: 70px;  }

.blk-sep { width: 1px; height: 22px; background: #dde2ea; margin: 0 2px; flex-shrink: 0; }

.drag-handle { cursor: grab; color: #bbb; font-size: 16px; padding: 0 2px; user-select: none; flex-shrink: 0; }
.drag-handle:hover { color: #888; }
.drag-handle:active { cursor: grabbing; }

.rm-btn { background: #e74c3c; color: #fff; border: none; border-radius: 4px; padding: 3px 8px; cursor: pointer; font-size: 13px; font-weight: 700; flex-shrink: 0; margin-left: auto; height: 28px; }
.rm-btn:hover { background: #c0392b; }

.mm-block.dragging { opacity: 0.35; }
.mm-block.drag-over-top    { border-top: 2px solid #1a3a5c; }
.mm-block.drag-over-bottom { border-bottom: 2px solid #1a3a5c; }

/* ── CHECKBOX DROPDOWN ── */
.chk-dropdown { position: relative; display: inline-block; flex-shrink: 0; }
.chk-dropdown-btn {
    padding: 4px 22px 4px 8px;
    border: 1px solid #c5cdd8; border-radius: 4px; font-size: 12px; height: 28px;
    background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%23888'/%3E%3C/svg%3E") no-repeat right 6px center;
    cursor: pointer; white-space: nowrap; min-width: 80px; text-align: left; user-select: none;
    display: flex; align-items: center;
}
.chk-dropdown-btn:hover { border-color: #aaa; }
.chk-dropdown-panel { display: none; position: fixed; background: #fff; border: 1px solid #c5cdd8; border-radius: 5px; box-shadow: 0 4px 14px rgba(0,0,0,.12); z-index: 9999; min-width: 180px; max-height: 260px; overflow-y: auto; padding: 4px 0; }
.chk-dropdown-panel.open { display: block; }
.chk-dropdown-panel label { display: flex; align-items: center; gap: 8px; padding: 5px 12px; font-size: 12px; cursor: pointer; white-space: nowrap; }
.chk-dropdown-panel label:hover { background: #f0f4fa; }
.chk-dropdown-panel input[type=checkbox] { margin: 0; accent-color: #1a3a5c; }

/* ── FILTER FOOTER ── */
.filter-footer { display: flex; gap: 8px; align-items: center; margin-top: 10px; }
.add-filter-btn { display: inline-flex; align-items: center; gap: 5px; background: #1a3a5c; color: #fff; border: none; border-radius: 5px; padding: 6px 12px; font-size: 12px; cursor: pointer; font-weight: 600; }
.add-filter-btn:hover { background: #245080; }
.btn-search { background: #e8760a; color: #fff; border: none; border-radius: 5px; padding: 6px 20px; font-size: 13px; font-weight: 700; cursor: pointer; }
.btn-search:hover { background: #c9650a; }
.btn-reset { background: #fff; color: #555; border: 1px solid #c5cdd8; border-radius: 5px; padding: 6px 14px; font-size: 12px; cursor: pointer; text-decoration: none; display: inline-block; }
.btn-reset:hover { background: #f0f2f5; }
.btn-save-update { background: #2e7d32; color: #fff; border: none; border-radius: 5px; padding: 6px 14px; font-size: 12px; font-weight: 600; cursor: pointer; }
.btn-save-update:hover { background: #1b5e20; }
.btn-save-new { background: #fff; color: #2e7d32; border: 1px solid #2e7d32; border-radius: 5px; padding: 6px 14px; font-size: 12px; font-weight: 600; cursor: pointer; }
.btn-save-new:hover { background: #e8f5e9; }

/* ── RESULTS BAR ── */
.results-bar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.results-bar .count { font-size: 13px; color: #555; }
.results-bar .count strong { color: #222; }
.sort-bar { display: flex; gap: 6px; align-items: center; font-size: 13px; }
.sort-bar label { color: #666; }
.sort-bar select { padding: 5px 8px; border: 1px solid #c5cdd8; border-radius: 4px; font-size: 13px; }

/* ── CAR LIST ── */
.car-list { display: flex; flex-direction: column; gap: 4px; }
.car-row { background: #fff; border: 1px solid #d8dde6; border-radius: 6px; display: grid; grid-template-columns: 28px 1fr; align-items: center; padding: 10px 14px; transition: box-shadow .12s; gap: 12px; }
.car-row:hover { box-shadow: 0 2px 8px rgba(0,0,0,.1); border-color: #aabbcc; }

.car-main { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.car-title { font-size: 15px; font-weight: 700; display: flex; align-items: baseline; gap: 7px; flex-wrap: wrap; }
.car-title a { color: #1a3a5c; text-decoration: none; }
.car-title a:hover { color: #e8760a; }
.car-title .company { font-size: 11px; font-weight: 400; color: #888; }

/* Year tag in title */
.year-tag { font-size: 13px; font-weight: 700; color: #e8760a; white-space: nowrap; }
.month-tag { font-size: 10px; font-weight: 400; color: #c09060; }
.ad-date-tag { font-size: 11px; font-weight: 400; color: #aaa; white-space: nowrap; }

.car-specs { display: flex; flex-wrap: wrap; gap: 12px; font-size: 13px; color: #444; }
.car-specs .spec { display: flex; align-items: center; gap: 3px; }
.note-input {
    width: 100%;
    border: none;
    border-bottom: 1px solid transparent;
    background: transparent;
    font-size: 12px;
    color: #555;
    padding: 2px 0;
    outline: none;
    font-family: inherit;
    transition: border-color .15s;
}
.note-input:hover, .note-input:focus { border-bottom-color: #c5cdd8; }
.note-input:focus { background: #f7f9fc; padding: 2px 4px; border-radius: 3px; border-bottom-color: #1a3a5c; }
.note-input::placeholder { color: #ccc; }
.car-meta { font-size: 11px; color: #bbb; }

.car-price { font-size: 18px; font-weight: 800; color: #e8760a; white-space: nowrap; margin-left: auto; }
.btn-hide { background: none; border: 1px solid #ddd; border-radius: 4px; color: #ccc; font-size: 13px; padding: 0; cursor: pointer; line-height: 1; width: 24px; height: 40px; display: flex; align-items: center; justify-content: center; align-self: center; flex-shrink: 0; }
.btn-hide:hover { background: #fee; border-color: #e74c3c; color: #e74c3c; }
.car-hidden-row { border: 1px solid #eee; border-radius: 6px; background: #fafafa; min-height: 28px; display: flex; align-items: center; padding: 0 10px; gap: 10px; flex-wrap: wrap; }
.note-input--hidden { flex: 1; min-width: 120px; font-size: 11px; color: #aaa; }
.note-input--hidden::placeholder { color: #ddd; }
.car-hidden-row .hidden-row-label { margin-left: auto; flex-shrink: 0; }
.btn-unhide { background: none; border: none; color: #bbb; font-size: 11px; cursor: pointer; padding: 0; text-decoration: underline; }
.btn-unhide:hover { color: #1a3a5c; }
.hidden-row-label { font-size: 11px; color: #ccc; flex: 1; }

/* ── HIDDEN ADS BADGE ── */
.hidden-badge { font-size: 12px; color: #e8760a; font-weight: 600; }
.clear-hidden-link { font-size: 12px; color: #888; margin-left: 4px; text-decoration: none; }
.clear-hidden-link:hover { color: #e74c3c; }

/* ── GROUP SECTIONS ── */
.group-section { margin-bottom: 20px; }
.group-header { display: flex; align-items: center; gap: 12px; padding: 8px 10px; border-bottom: 2px solid #1a3a5c; margin-bottom: 8px; cursor: pointer; user-select: none; border-radius: 4px 4px 0 0; }
.group-header:hover { background: #f0f4fa; }
.group-title { font-size: 16px; font-weight: 700; color: #1a3a5c; flex: 1; }
.group-count-inline { font-size: 14px; font-weight: 400; color: #888; margin-left: 4px; }
.group-limit { font-size: 11px; color: #e8760a; margin-left: 6px; }
.group-toggle { font-size: 13px; color: #1a3a5c; font-weight: 700; display: inline-block; }
.group-body.collapsed { display: none; }

/* ── MISC ── */
.no-results { text-align: center; padding: 60px 20px; color: #888; font-size: 16px; }

/* ── MOBILE ── */
@media (max-width: 640px) {
    .wrap { padding: 8px; }

    /* Filter group grid */
    .fg-grid { gap: 4px; }
    .fg-btn  { font-size: 12px; padding: 5px 9px; }

    /* Filter blocks — wrap instead of horizontal scroll */
    .mm-block {
        flex-wrap: wrap;
        overflow-x: visible;
        gap: 6px;
        padding: 8px;
    }
    .mm-block::-webkit-scrollbar { display: none; }
    .blk-sep { display: none; }
    .drag-handle { display: none; }

    /* Make selects / inputs fill available width in pairs */
    .sel-make, .sel-model          { flex: 1 1 42%; min-width: 0; max-width: none; }
    .sel-year                       { flex: 1 1 44%; min-width: 0; width: auto; }
    .inp-price, .inp-eng            { flex: 1 1 44%; min-width: 0; width: auto; }
    .sel-engine, .sel-gearbox,
    .sel-seats, .sel-mileage        { flex: 1 1 44%; min-width: 0; max-width: none; }
    .chk-dropdown                   { flex: 1 1 90%; }
    .chk-dropdown-btn               { width: 100%; }
    .mm-block select,
    .mm-block input[type=number]    { width: 100%; flex-shrink: 1; }

    /* Remove button stays on its own row, right-aligned */
    .rm-btn { margin-left: auto; }

    /* Footer buttons wrap and stretch */
    .filter-footer {
        flex-wrap: wrap;
    }
    .filter-footer > * {
        flex: 1 1 auto;
        text-align: center;
        justify-content: center;
    }

    /* Results bar stacks */
    .results-bar { flex-direction: column; align-items: flex-start; gap: 6px; }

    /* Car row — tighter layout */
    .car-row { grid-template-columns: 24px 1fr; padding: 8px 10px; gap: 8px; }
    .car-title { font-size: 14px; }
    .car-price { font-size: 16px; }
}

/* ── DEALER ROW ── */
.car-dealer { background: #fff5f5; }

/* ── TAGS ── */
.tag-lv { font-size: 11px; background: #e8f4e8; color: #2a6e2a; border-radius: 3px; padding: 1px 5px; }

/* ── PRICE HISTORY ── */
.price-history {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 10px;
    margin-top: 4px;
    font-size: 12px;
    color: #666;
}
.ph-entry {
    display: inline-flex;
    align-items: center;
    gap: 3px;
}
.ph-entry + .ph-entry::before {
    content: '→';
    margin-right: 6px;
    color: #aaa;
}
.ph-date {
    color: #aaa;
    font-size: 11px;
}
