:root {
    --bg: #f6f7fb;
    --card-bg: #ffffff;
    --text: #1f2330;
    --text-muted: #6c7280;
    --primary: #2e6cff;
    --primary-hover: #1e54d8;
    --border: #e3e6ef;
    --error-bg: #fdecec;
    --error-text: #a31515;
    --info-bg: #eef3fe;
    --info-text: #1e54d8;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    line-height: 1.5;
}

.brand {
    text-align: center;
    padding: 32px 16px 8px;
}

.brand__name {
    margin: 0;
    font-size: 28px;
    letter-spacing: 0.5px;
}

.brand__tagline {
    margin: 4px 0 0;
    color: var(--text-muted);
    font-size: 14px;
    font-style: italic;
}

.container {
    max-width: 480px;
    margin: 24px auto 48px;
    padding: 0 16px;
}

.card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 24px;
    box-shadow: 0 2px 8px rgba(20, 28, 50, 0.04);
}

.card h2 {
    margin: 0 0 8px;
    font-size: 20px;
}

.hint {
    color: var(--text-muted);
    font-size: 14px;
    margin: 0 0 16px;
}

.form {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: 8px;
}

.form--inline { flex-direction: row; align-items: center; }

.form label {
    display: flex;
    flex-direction: column;
    font-size: 13px;
    color: var(--text-muted);
    gap: 4px;
}

.form input {
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 15px;
    color: var(--text);
    background: #fff;
}

.form input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(46, 108, 255, 0.15);
}

.form button {
    margin-top: 8px;
    padding: 10px 14px;
    background: var(--primary);
    color: #fff;
    border: 0;
    border-radius: 8px;
    cursor: pointer;
    font-size: 15px;
    font-weight: 500;
}

.form button:hover { background: var(--primary-hover); }

.btn--secondary {
    background: transparent;
    color: var(--text-muted);
    border: 1px solid var(--border);
}
.btn--secondary:hover {
    background: #f0f2f8;
    color: var(--text);
}

.btn--link {
    display: inline-block;
    padding: 8px 14px;
    background: var(--primary);
    color: #fff;
    border-radius: 8px;
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
}
.btn--link:hover { background: var(--primary-hover); }

.flash {
    list-style: none;
    padding: 0;
    margin: 0 0 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.flash li {
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 14px;
}

.flash--error { background: var(--error-bg); color: var(--error-text); }
.flash--info  { background: var(--info-bg); color: var(--info-text); }
.flash--message { background: var(--info-bg); color: var(--info-text); }

/* ---------------- Progress / Gallery (Slice 3) ---------------- */

.card--wide { max-width: 100%; }
.container:has(.gallery-grid) { max-width: 1280px; }

.progress {
    width: 100%;
    height: 10px;
    background: #e8ecf5;
    border-radius: 6px;
    overflow: hidden;
    margin: 16px 0 8px;
}
.progress__bar {
    width: 30%;
    height: 100%;
    background: linear-gradient(90deg, var(--primary), #6c9bff);
    animation: progress-shimmer 1.6s linear infinite;
}
@keyframes progress-shimmer {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(330%); }
}

.engines {
    list-style: none;
    padding: 0;
    margin: 16px 0 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: 13px;
}
.engines--inline {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 8px;
}
.engine {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    border-radius: 6px;
    background: #f0f2f8;
    color: var(--text-muted);
}
.engine--success { background: #e6f5ec; color: #1f7a3a; }
.engine--failed { background: var(--error-bg); color: var(--error-text); }
.engine--zero_results { background: #fff5e0; color: #946800; }
.engine--quota_exceeded { background: #fde8f0; color: #9a1146; }
.engine--running { background: var(--info-bg); color: var(--info-text); }
.engine__name { font-weight: 600; }
.engine__retry { display: inline; margin: 0; padding: 0; }
.btn--retry {
    background: transparent;
    border: 1px solid currentColor;
    color: inherit;
    border-radius: 6px;
    padding: 2px 8px;
    cursor: pointer;
    font-size: 12px;
    margin-left: 4px;
}
.btn--retry:hover { background: rgba(0,0,0,0.05); }

.gallery-cell__dup-count {
    position: absolute;
    top: 6px;
    right: 6px;
    background: rgba(46, 108, 255, 0.92);
    color: #fff;
    border-radius: 10px;
    padding: 2px 8px;
    font-size: 11px;
    font-weight: 600;
    line-height: 1.3;
    box-shadow: 0 1px 3px rgba(0,0,0,.25);
}

/* ---------------- Modal (Slice 5) ---------------- */

.modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}
.modal__overlay {
    position: absolute;
    inset: 0;
    background: rgba(15, 20, 35, 0.72);
    cursor: zoom-out;
}
.modal__dialog {
    position: relative;
    background: var(--card-bg);
    border-radius: 12px;
    max-width: min(1100px, 95vw);
    max-height: 95vh;
    width: 100%;
    overflow: hidden;
    box-shadow: 0 20px 50px rgba(0,0,0,.35);
    display: flex;
    flex-direction: column;
}
.modal__header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 20px;
    border-bottom: 1px solid var(--border);
    background: #fbfcfe;
}
.modal__close {
    color: var(--text-muted);
    text-decoration: none;
    font-size: 26px;
    line-height: 1;
    padding: 0 4px;
}
.modal__close:hover { color: var(--text); }

.modal__body {
    display: grid;
    grid-template-columns: 1fr 320px;
    gap: 16px;
    padding: 16px 20px 20px;
    overflow: auto;
}
@media (max-width: 800px) {
    .modal__body { grid-template-columns: 1fr; }
}

.modal__image-wrap {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f0f2f8;
    border-radius: 8px;
    min-height: 320px;
    max-height: 70vh;
}
.modal__image {
    max-width: 100%;
    max-height: 70vh;
    object-fit: contain;
    border-radius: 6px;
}
.modal__image-missing {
    color: var(--text-muted);
    font-size: 14px;
}
.modal__nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(0,0,0,0.55);
    color: #fff;
    text-decoration: none;
    font-size: 36px;
    line-height: 1;
    width: 40px;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    transition: background .15s ease;
}
.modal__nav:hover { background: rgba(0,0,0,0.75); }
.modal__nav--prev { left: 8px; }
.modal__nav--next { right: 8px; }

.modal__meta h4 {
    margin: 16px 0 6px;
    font-size: 13px;
    text-transform: uppercase;
    color: var(--text-muted);
    letter-spacing: .04em;
}
.modal__meta .engines-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 13px;
}
.modal__meta .engines-list li {
    padding: 4px 8px;
    background: var(--info-bg);
    color: var(--info-text);
    border-radius: 6px;
}

.modal__dup-variants {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
}
.dup-variant {
    display: block;
    background: #eef0f6;
    border-radius: 6px;
    overflow: hidden;
    aspect-ratio: 1 / 1;
}
.dup-variant img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform .15s ease;
}
.dup-variant:hover img { transform: scale(1.08); }
.dup-variant__missing {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    color: var(--text-muted);
    font-size: 18px;
}

.badge {
    display: inline-block;
    padding: 2px 8px;
    background: var(--info-bg);
    color: var(--info-text);
    border-radius: 10px;
    font-size: 12px;
    margin-left: 6px;
}

/* ---------------- Tabs / Reverse badge (Slice 6) ---------------- */

.tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 16px 0 8px;
    align-items: center;
    overflow-x: auto;
}
.tab-wrap {
    display: inline-flex;
    align-items: center;
    background: #f0f2f8;
    border-radius: 8px;
    overflow: hidden;
}
.tab {
    display: inline-block;
    padding: 6px 12px;
    background: #f0f2f8;
    color: var(--text-muted);
    border-radius: 8px;
    text-decoration: none;
    font-size: 13px;
    font-weight: 500;
    border: 1px solid transparent;
    white-space: nowrap;
}
.tab:hover { background: #e3e6ef; color: var(--text); }
.tab--active {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}
.tab--mass { font-variant: small-caps; }
.tab--reverse { /* style на reverse-табах есть iconfix */ }
.tab-wrap .tab { border-radius: 8px 0 0 8px; }
.tab__delete { display: inline; margin: 0; padding: 0; }
.tab__close {
    background: transparent;
    color: var(--text-muted);
    border: 0;
    border-left: 1px solid var(--border);
    padding: 4px 8px;
    cursor: pointer;
    font-size: 14px;
    line-height: 1;
}
.tab__close:hover { background: var(--error-bg); color: var(--error-text); }

.gallery-cell__rev {
    position: absolute;
    top: 6px;
    left: 6px;
    background: rgba(255, 153, 0, 0.92);
    color: #fff;
    border-radius: 4px;
    padding: 1px 5px;
    font-size: 12px;
    line-height: 1.3;
    box-shadow: 0 1px 3px rgba(0,0,0,.25);
}

.modal__actions {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}
.modal__reverse-form, .modal__select-form { display: inline; margin: 0; }
.modal__reverse-form button, .modal__select-form button {
    padding: 8px 14px;
    border-radius: 8px;
    font-size: 14px;
    cursor: pointer;
}
.btn--selected {
    background: linear-gradient(135deg, #ffb800, #ff8a00);
    color: #fff;
}
.btn--selected:hover { background: linear-gradient(135deg, #ffa800, #ef7a00); color: #fff; }

/* ---------------- Selection / Star (Slice 7) ---------------- */

.gallery-cell {
    position: relative;
    background: #eef0f6;
    border-radius: 8px;
    overflow: hidden;
    aspect-ratio: 1 / 1;
}
.gallery-cell__link {
    display: block;
    width: 100%;
    height: 100%;
}
.gallery-cell__link img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform .15s ease;
}
.gallery-cell:hover .gallery-cell__link img { transform: scale(1.05); }
.gallery-cell--selected {
    box-shadow: 0 0 0 3px #ffb800, 0 4px 12px rgba(255, 184, 0, 0.35);
    border-radius: 8px;
}

.star-form {
    position: absolute;
    top: 6px;
    left: 6px;
    margin: 0;
    padding: 0;
    z-index: 2;
}
.star-btn {
    background: rgba(255, 255, 255, 0.85);
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 50%;
    width: 30px;
    height: 30px;
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    padding: 0;
    color: #666;
    transition: all .15s ease;
    box-shadow: 0 2px 4px rgba(0,0,0,.2);
}
.star-btn:hover {
    background: #ffe9b3;
    color: #c47100;
    transform: scale(1.1);
}
.star-btn--on {
    background: #ffb800;
    color: #fff;
    border-color: #f0a800;
}
.star-btn--on:hover { background: #ffa800; color: #fff; }

/* gallery-cell__rev moved to right since star is on left */
.gallery-cell__rev {
    left: auto;
    right: 6px;
    top: 38px;  /* below dup-count if any */
}

.gallery-cell__product {
    position: absolute;
    bottom: 6px;
    right: 6px;
    background: rgba(255, 184, 0, 0.92);
    color: #fff;
    border-radius: 4px;
    padding: 1px 5px;
    font-size: 13px;
    line-height: 1.2;
    box-shadow: 0 1px 3px rgba(0,0,0,.25);
}

.badge--product {
    background: #fff5e0;
    color: #946800;
}

.engines-list a {
    color: var(--info-text);
    text-decoration: none;
}
.engines-list a:hover { text-decoration: underline; }

/* ---------------- Bulk panel ---------------- */

.bulk-panel {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    margin: 12px 0;
    padding: 10px 12px;
    background: #fbfcfe;
    border: 1px solid var(--border);
    border-radius: 8px;
}
.bulk-panel__form { display: inline; margin: 0; }
.bulk-panel button {
    cursor: pointer;
}

/* ---------------- Export panel ---------------- */

.export-panel {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: center;
    margin: 16px 0;
    padding: 16px;
    background: linear-gradient(135deg, #fff8e1, #fff3cc);
    border: 1px solid #ffd966;
    border-radius: 10px;
}
.export-panel__form { display: inline; margin: 0; }
.btn--export {
    padding: 10px 16px;
    font-size: 14px;
    font-weight: 600;
}
.export-panel button[disabled] {
    opacity: 0.6;
    cursor: not-allowed;
}

.gallery-grid--selected {
    grid-template-columns: repeat(5, 1fr);
}
@media (max-width: 900px) { .gallery-grid--selected { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 540px) { .gallery-grid--selected { grid-template-columns: repeat(2, 1fr); } }

/* ---------------- Slice 8: dashboard / banner / advanced / quota ---------------- */

.header-quota {
    display: inline-block;
    margin-top: 8px;
    padding: 4px 12px;
    background: #f0f2f8;
    color: var(--text-muted);
    border-radius: 12px;
    font-size: 13px;
    font-weight: 500;
}
.header-quota--warn { background: #fff5e0; color: #946800; }
.header-quota--block { background: var(--error-bg); color: var(--error-text); }

.banner {
    padding: 12px 16px;
    border-radius: 8px;
    margin-bottom: 16px;
    font-size: 14px;
    font-weight: 500;
}
.banner--warning { background: #fff5e0; color: #946800; border: 1px solid #f0d069; }
.banner--error { background: var(--error-bg); color: var(--error-text); border: 1px solid #f0a8a8; }

.stats-cards {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    margin: 16px 0;
}
@media (max-width: 700px) { .stats-cards { grid-template-columns: repeat(2, 1fr); } }
.stat-card {
    background: linear-gradient(135deg, #f6f8ff, #ebf0ff);
    border: 1px solid #d3dcf2;
    border-radius: 10px;
    padding: 14px;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}
.stat-card__icon { font-size: 20px; }
.stat-card strong { font-size: 22px; color: var(--text); }
.stat-card span { font-size: 12px; color: var(--text-muted); text-transform: lowercase; }

.value-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 12px;
    font-size: 13px;
}
.value-table th, .value-table td {
    padding: 8px 10px;
    text-align: left;
    border-bottom: 1px solid var(--border);
}
.value-table th { font-size: 12px; text-transform: uppercase; color: var(--text-muted); }
.value-table tr.row--top { background: #ebfaef; }
.value-table tr.row--low { background: #fef4f0; }
.value-table tr.row--unused { color: #aab1c1; }
.value-table code {
    background: #f0f2f8;
    padding: 1px 6px;
    border-radius: 4px;
    font-size: 12px;
}

.search-history {
    list-style: none;
    padding: 0;
    margin: 0;
}
.search-history__item {
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
}
.search-history__item:last-child { border-bottom: 0; }
.search-history__row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
}
.search-history__link {
    color: var(--primary);
    text-decoration: none;
    font-size: 14px;
}
.search-history__link:hover { text-decoration: underline; }
.search-history__status {
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 10px;
    background: #f0f2f8;
    color: var(--text-muted);
    text-transform: uppercase;
}
.search-history__status.status--success { background: #e6f5ec; color: #1f7a3a; }
.search-history__status.status--partial { background: #fff5e0; color: #946800; }
.search-history__status.status--failed { background: var(--error-bg); color: var(--error-text); }
.search-history__status.status--running { background: var(--info-bg); color: var(--info-text); }
.search-history__engines {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 4px;
}
.search-history__engines span {
    background: #f0f2f8;
    padding: 1px 6px;
    border-radius: 4px;
    font-size: 11px;
    color: var(--text-muted);
}
.progress__bar--static {
    animation: none !important;
    background: linear-gradient(90deg, #2e6cff, #6c9bff);
}

/* Advanced settings */
.advanced {
    margin: 12px 0;
    padding: 12px;
    background: #fbfcfe;
    border: 1px solid var(--border);
    border-radius: 8px;
}
.advanced summary {
    cursor: pointer;
    font-size: 13px;
    color: var(--text-muted);
    user-select: none;
}
.advanced[open] summary { color: var(--text); }
.advanced__fieldset {
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px 12px;
    margin: 10px 0;
}
.advanced__fieldset legend {
    font-size: 11px;
    text-transform: uppercase;
    color: var(--text-muted);
    padding: 0 6px;
}
.advanced__check {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    margin-right: 14px;
    font-size: 13px;
    color: var(--text);
    cursor: pointer;
}
.advanced__field {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin: 8px 0;
}
.advanced__field span {
    font-size: 13px;
    color: var(--text-muted);
}
.advanced__field select, .advanced__field input {
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 13px;
    min-width: 200px;
}

.cost-preview {
    background: #eef3fe;
    color: var(--info-text);
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 13px;
    margin: 12px 0;
}
.cost-preview strong { font-size: 15px; }

/* ---------------- Gallery filter panel ---------------- */

.filter-panel {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin: 12px 0;
    padding: 12px 16px;
    background: #fbfcfe;
    border: 1px solid var(--border);
    border-radius: 10px;
    font-size: 13px;
}
.filter-row {
    display: flex;
    flex-wrap: wrap;
    gap: 12px 16px;
    align-items: center;
}

.filter-field {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}
.filter-field--grow { flex: 1 1 220px; min-width: 0; }
.filter-field span {
    font-size: 12px;
    color: var(--text-muted);
    white-space: nowrap;
}
.filter-field select, .filter-field input[type="text"] {
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 13px;
    background: #fff;
}
.filter-field--grow input[type="text"] { flex: 1; }

.filter-chips {
    display: inline-flex;
    flex-wrap: wrap;
    gap: 4px 8px;
    align-items: center;
    border: 0;
    margin: 0;
    padding: 0;
}
.filter-chips legend {
    font-size: 12px;
    color: var(--text-muted);
    margin-right: 4px;
    padding: 0;
}
.filter-chips--wide { width: 100%; }
.filter-chips label {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 8px;
    border: 1px solid var(--border);
    border-radius: 14px;
    cursor: pointer;
    background: #fff;
    font-size: 12px;
    transition: background .1s, border-color .1s;
}
.filter-chips label:has(input:checked) {
    background: var(--info-bg);
    border-color: var(--primary);
    color: var(--info-text);
}
.filter-chips input { margin: 0; cursor: pointer; }

.filter-actions {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-left: auto;
}

.gallery-grid__counter {
    margin: 12px 0 8px;
}

/* ---------------- Per-search value details ---------------- */

.run-value {
    margin: 12px 0;
    padding: 8px 12px;
    background: #fbfcfe;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 13px;
}
.run-value summary {
    cursor: pointer;
    color: var(--text);
    font-weight: 500;
    user-select: none;
    list-style: none;
}
.run-value summary::-webkit-details-marker { display: none; }
.run-value summary::before {
    content: "▶ ";
    color: var(--text-muted);
    font-size: 10px;
    margin-right: 4px;
}
.run-value[open] summary::before { content: "▼ "; }

.value-table--run {
    margin: 12px 0 4px;
    font-size: 12px;
}
.value-table--run th { font-size: 11px; }

.badge--retry {
    background: #fff5e0;
    color: #946800;
    font-size: 10px;
    padding: 1px 5px;
    border-radius: 8px;
    margin-left: 4px;
}

.gallery-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 8px;
    margin-top: 16px;
}
@media (max-width: 900px) { .gallery-grid { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 540px) { .gallery-grid { grid-template-columns: repeat(2, 1fr); } }

.gallery-cell__missing {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    color: var(--text-muted);
    font-size: 12px;
}
