:root {
    --bg-page: #e6e8ec;       /* фон страницы слегка темнее */
    --bg-surface: #f7f8fa;   /* фон внутренних секций */
    --bg-cards: #fff;        /* фон карточек */
    --bg-header: #f3f3f3;
    --bg-footer: #e6e8ec;
    --border: #c4c8d0;
    --radius: 12px;
    --shadow: 0 2px 4px rgba(0,0,0,.06);
    --text-primary: #141414;
    --text-muted: #555;
    --btn-bg: #e8eaef;
    --btn-bg-hover: #dfe2e8;
    --btn-active: #6aa0ff;
    --btn-active-text: #fff;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body {
    font-family: Inter, Helvetica, Arial, sans-serif;
    color: var(--text-primary);
    background: var(--bg-page);
    line-height: 1.4;
}
main { background: var(--bg-surface); }
a { color: inherit; text-decoration: none; }

/* ---------- header ---------- */
header {
    background: var(--bg-header);
    padding: 16px 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    border-bottom: 1px solid var(--border);
}
.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
}

/* ---------- logo area with stats ---------- */
.logo-area {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
}
.logo img { height: 40px; width: auto; display: block; }
.queue-stats {
    font-size: 12px;
    color: var(--text-muted);
    font-weight: 500;
}

nav { display: flex; gap: 24px; }

/* ---------- search area ---------- */
.search-area {
    position: relative;       /* для dropdown */
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}
.search-area input[type="text"] {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: #fff;
}
.criteria-btn {
    padding: 8px 12px;
    background: var(--btn-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
}

/* ---------- keyword dropdown ---------- */
.keyword-dropdown {
    display: none;            /* скрыт по умолчанию */
    position: absolute;
    left: 0;
    right: 0;
    top: calc(100% + 4px);
    background: #fff;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 8px;
    box-shadow: var(--shadow);
    z-index: 1000;
    gap: 8px;
    flex-wrap: wrap;
    max-height: 80vh;
    overflow: hidden;
}
.keyword-dropdown.active { display: flex; }

.kw-btn {
    padding: 6px 10px;
    font-size: 0.875rem;
    background: var(--btn-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    white-space: nowrap;
    transition: background .15s;
}
.kw-btn:hover { background: var(--btn-bg-hover); }

/* подсветка совпадений */
.kw-btn.match {
    background: #d0e6ff;
    border-color: #6aa0ff;
}

/* ---------- grid ---------- */
main { padding: 32px 24px; }
.sections {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 32px;
}
section { display: flex; flex-direction: column; gap: 16px; }
section h2 { font-size: 1.25rem; }

/* ---------- card ---------- */
.card {
    display: flex;
    gap: 16px;
    width: 100%;
    background: var(--bg-cards);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
    min-height: 96px;
    max-height: 96px; /* единый размер */
    transition: transform .2s ease, box-shadow .2s ease;
}
.card:hover {
    transform: translateY(-4px);
    box-shadow: 0 6px 12px rgba(0,0,0,.12);
}
.card img {
    width: 25%;               /* четверть ширины */
    min-width: 60px;
    object-fit: cover;
}
.info { display: flex; flex-direction: column; padding: 12px 12px 12px 0; width: 75%; }
.info h3 { font-size: 1rem; font-weight: 600; margin-bottom: 4px; white-space: normal; }
.info p {
    font-size: 0.875rem;
    color: var(--text-muted);
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

/* ---------- pagination ---------- */
#pagination-container {
    margin-top: 32px;
    padding: 0 24px;
}

.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    padding: 24px 0;
}

.pagination-btn {
    padding: 8px 12px;
    background: var(--btn-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    text-decoration: none;
    color: var(--text-primary);
    font-size: 0.875rem;
    transition: background .15s, color .15s, border-color .15s;
    min-width: 40px;
    text-align: center;
}

.pagination-btn:hover {
    background: var(--btn-bg-hover);
}

.pagination-btn.current {
    background: var(--btn-active);
    color: var(--btn-active-text);
    border-color: var(--btn-active);
    pointer-events: none; /* Отключаем клики по текущей странице */
}

.pagination-btn.disabled {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

.pagination-info {
    font-size: 0.875rem;
    color: var(--text-muted);
    margin-right: 16px;
}

/* ---------- search results grid ---------- */
.search-results {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 16px;
    max-width: 100%;
}

/* Ограничиваем максимальное количество колонок до 5 */
@media (min-width: 1600px) {
    .search-results {
        grid-template-columns: repeat(5, 1fr);
    }
}

@media (min-width: 1280px) and (max-width: 1599px) {
    .search-results {
        grid-template-columns: repeat(4, 1fr);
    }
}

@media (min-width: 960px) and (max-width: 1279px) {
    .search-results {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (min-width: 640px) and (max-width: 959px) {
    .search-results {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 639px) {
    .search-results {
        grid-template-columns: 1fr;
    }
}

.search-results .card {
    max-width: 100%;
    /* Сохраняем горизонтальную ориентацию как на главной */
    flex-direction: row;
    max-height: 96px;
    min-height: 96px;
}

.search-results .card img {
    width: 25%;
    min-width: 60px;
    object-fit: cover;
}

.search-results .card .info {
    width: 75%;
    padding: 12px 12px 12px 0;
}

/* ---------- footer ---------- */
footer {
    background: var(--bg-footer);
    padding: 16px 24px;
    font-size: 0.875rem;
    text-align: center;
    border-top: 1px solid var(--border);
}

.criteria-btn.loading {
    opacity: 0.5;
    pointer-events: none;
}

.criteria-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

.imgs label.viewed img {
  border: 2px solid;
  border-color: #ff9900 !important;
}

@media (max-width: 480px) {
    header { padding: 12px 16px; }
    .top-bar { flex-direction: column; align-items: flex-start; }
    nav { flex-wrap: wrap; gap: 12px; }
    .card { max-height: none; } /* на узких экранах пусть растягиваются */
    
    .pagination {
        gap: 4px;
    }
    
    .pagination-btn {
        padding: 6px 8px;
        font-size: 0.75rem;
        min-width: 32px;
    }
    
    .pagination-info {
        font-size: 0.75rem;
        margin-right: 8px;
        margin-bottom: 8px;
    }
}