/**
 * assets/css/main.css — все стили проекта (конкатенация из vinyl.php)
 * Импортируется через <link> в head.php
 */

@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@400;500;600;700;800;900&display=swap');
@import 'variables.css';

* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

/* ── iOS: запобігання зуму при натисканні на інпути (font-size < 16px = зум) ── */
@media (max-width: 768px) {

    input,
    textarea,
    select {
        font-size: 16px !important;
    }
}

/* Прибираємо 300ms затримку дотику на кнопках та інтерактивних елементах */
button,
a,
[onclick],
input,
textarea,
select,
label {
    touch-action: manipulation;
}


body {
    background: var(--bg);
    color: var(--text);
    font-family: 'Outfit', -apple-system, sans-serif;
    margin: 0;
    padding: 0 0 20px 0;
    transition: background 0.3s ease;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 20px;
}

/* ── Top Bar ────────────────────────────────────────────────────────────── */
.top-bar {
    position: sticky;
    top: 0;
    z-index: 100;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 15px;
    flex-wrap: wrap;
    background: var(--bg);
    border-bottom: 1px solid transparent;
    padding: 20px 20px 10px;
    width: 100%;
    box-sizing: border-box;
    transition: background 0.3s ease, border-color 0.3s ease, backdrop-filter 0.3s ease, padding 0.3s ease, box-shadow 0.3s ease;
}

.top-bar.scrolled {
    background: rgba(248, 250, 252, 0.85);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
    box-shadow: 0 4px 20px -5px rgba(0, 0, 0, 0.05);
    padding: 15px 20px;
}

[data-theme="dark"] .top-bar.scrolled {
    background: rgba(9, 13, 22, 0.85);
    box-shadow: 0 4px 20px -5px rgba(0, 0, 0, 0.3);
}

.logo-box {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo-icon {
    width: 45px;
    height: 45px;
    background: var(--accent);
    color: var(--bg);
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
}

.logo-title {
    margin: 0;
    font-size: 26px;
    font-weight: 900;
    letter-spacing: -0.5px;
    line-height: 1.1;
}

.logo-subtitle {
    font-size: 13px;
    color: var(--accent-light);
    font-weight: 500;
}

/* ── Buttons ──────────────────────────────────────────────────────────────── */
.btn {
    border: none;
    border-radius: var(--radius-md);
    padding: 12px 22px;
    font-family: inherit;
    font-weight: 700;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: var(--transition);
    font-size: 15px;
    text-decoration: none;
}

.btn:active {
    transform: scale(0.97);
}

.btn-primary {
    background: var(--accent);
    color: var(--bg);
}

.btn-primary:hover {
    opacity: 0.9;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.15);
}

.btn-secondary {
    background: var(--border);
    color: var(--text);
}

.btn-secondary:hover {
    filter: brightness(0.95);
}

.theme-toggle {
    width: 46px;
    height: 46px;
    border-radius: var(--radius-md);
    border: none;
    background: var(--border);
    color: var(--text);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    cursor: pointer;
    transition: var(--transition);
}

.theme-toggle:hover {
    filter: brightness(0.95);
}

[data-theme="dark"] .theme-toggle:hover {
    filter: brightness(1.1);
}

/* ── Search & Filter Bar ─────────────────────────────────────────────────── */
.search-bar-row {
    display: flex;
    gap: 12px;
    align-items: center;
    background: var(--card);
    border-radius: var(--radius-lg);
    padding: 14px 18px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    margin-bottom: 14px;
}

.search-box {
    position: relative;
    flex: 1;
}

.search-icon {
    position: absolute;
    left: 16px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--accent-light);
    font-size: 20px;
    pointer-events: none;
}

.search-input {
    width: 100%;
    padding: 14px 18px 14px 48px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
    font-family: inherit;
    font-size: 15px;
    font-weight: 500;
    outline: none;
    transition: var(--transition);
}

.search-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(15, 23, 42, 0.05);
}

.sort-select {
    padding: 14px 18px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
    font-family: inherit;
    font-size: 14px;
    font-weight: 600;
    outline: none;
    cursor: pointer;
    min-width: 200px;
}

.filter-toggle-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 14px 20px;
    border-radius: var(--radius-md);
    background: var(--accent);
    color: var(--bg);
    border: none;
    font-family: inherit;
    font-weight: 700;
    font-size: 14px;
    cursor: pointer;
    transition: var(--transition);
    white-space: nowrap;
    position: relative;
}

.filter-toggle-btn:hover {
    opacity: 0.9;
}

.filter-count-badge {
    background: rgba(255, 255, 255, 0.25);
    color: inherit;
    font-size: 11px;
    font-weight: 900;
    padding: 1px 7px;
    border-radius: 8px;
    display: none;
}

.filter-count-badge.visible {
    display: inline-block;
}

.active-chips-row {
    display: none;
    flex-wrap: wrap;
    gap: 8px;
    padding: 0 2px 14px;
}

.active-chips-row.visible {
    display: flex;
}

.active-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 700;
    background: var(--accent);
    color: var(--bg);
    cursor: pointer;
    transition: var(--transition);
}

.active-chip ion-icon {
    font-size: 14px;
    opacity: 0.7;
}

.active-chip:hover ion-icon {
    opacity: 1;
}

.clear-all-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 700;
    background: #fee2e2;
    color: #dc2626;
    cursor: pointer;
    border: none;
    font-family: inherit;
    transition: var(--transition);
}

[data-theme="dark"] .clear-all-btn {
    background: rgba(220, 38, 38, 0.15);
    color: #f87171;
}

.clear-all-btn:hover {
    filter: brightness(0.95);
}

/* ── Filter Drawer ─────────────────────────────────────────────────────── */
.filter-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    backdrop-filter: blur(4px);
    z-index: 1050;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.filter-overlay.open {
    opacity: 1;
    pointer-events: all;
}

.filter-drawer {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 415px;
    max-width: 90vw;
    background: var(--card);
    border-right: 1px solid var(--border);
    box-shadow: 4px 0 30px rgba(0, 0, 0, 0.12);
    z-index: 1100;
    overflow-y: auto;
    transform: translateX(-100%);
    transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
}

.filter-drawer.open {
    transform: translateX(0);
}

.filter-drawer::-webkit-scrollbar {
    width: 4px;
}

.filter-drawer::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}

.drawer-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 22px 24px;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    background: var(--card);
    z-index: 10;
}

.drawer-title {
    font-size: 18px;
    font-weight: 900;
    margin: 0;
    display: flex;
    align-items: center;
    gap: 10px;
}

.drawer-close {
    width: 38px;
    height: 38px;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    cursor: pointer;
    transition: var(--transition);
}

.drawer-close:hover {
    border-color: var(--accent-light);
    background: var(--border);
}

.drawer-body {
    padding: 20px 24px;
    flex: 1;
}

.drawer-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--border);
    position: sticky;
    bottom: 0;
    background: var(--card);
    display: flex;
    gap: 10px;
}

/* Accordion */
.filter-section {
    margin-bottom: 6px;
}

.filter-section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    border-radius: 14px;
    cursor: pointer;
    user-select: none;
    transition: var(--transition);
    gap: 10px;
}

.filter-section-header:hover {
    background: var(--bg);
}

.filter-section-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    font-weight: 800;
    flex: 1;
}

.filter-section-meta {
    font-size: 11px;
    font-weight: 700;
    color: var(--accent-light);
    background: var(--bg);
    padding: 2px 8px;
    border-radius: 8px;
    border: 1px solid var(--border);
}

.filter-section-meta.has-active {
    background: var(--accent);
    color: var(--bg);
    border-color: var(--accent);
}

.filter-chevron {
    font-size: 18px;
    color: var(--accent-light);
    transition: transform 0.25s ease;
}

.filter-section.open .filter-chevron {
    transform: rotate(180deg);
}

.filter-section-body {
    overflow: hidden;
    max-height: 0;
    transition: max-height 0.35s ease;
    padding: 0 8px;
}

.filter-section.open .filter-section-body {
    max-height: 2000px;
    padding: 0 8px 8px;
}

.filter-show-more {
    display: block;
    width: 100%;
    text-align: center;
    padding: 8px;
    border-radius: 10px;
    border: 1px dashed var(--border);
    background: transparent;
    color: var(--accent-light);
    font-family: inherit;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    margin-top: 4px;
    transition: var(--transition);
}

.filter-show-more:hover {
    background: var(--bg);
    color: var(--text);
    border-color: var(--accent-light);
}

.filter-search-mini {
    width: 100%;
    padding: 8px 12px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
    font-family: inherit;
    font-size: 13px;
    outline: none;
    margin-bottom: 8px;
}

.filter-check-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    border-radius: 10px;
    cursor: pointer;
    transition: var(--transition);
    user-select: none;
}

.filter-check-item:hover {
    background: var(--bg);
}

.filter-check-item input[type=checkbox] {
    appearance: none;
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    border: 2px solid var(--border);
    border-radius: 5px;
    background: var(--card);
    cursor: pointer;
    position: relative;
    outline: none;
    flex-shrink: 0;
    transition: border-radius 0.25s cubic-bezier(0.4, 0, 0.2, 1), background-color 0.25s ease, border-color 0.25s ease;
    margin: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.filter-check-item input[type=checkbox]:hover {
    border-color: var(--accent-light);
}

.filter-check-item input[type=checkbox]:checked {
    background: var(--accent);
    border-color: var(--accent);
    border-radius: 50%;
}

.filter-check-item input[type=checkbox]::after {
    content: "";
    position: absolute;
    width: 6px;
    height: 6px;
    background: var(--bg);
    border-radius: 50%;
    opacity: 0;
    transform: scale(0);
    transition: opacity 0.2s ease, transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.filter-check-item input[type=checkbox]:checked::after {
    opacity: 1;
    transform: scale(1);
}

.filter-check-label {
    flex: 1;
    font-size: 14px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.filter-check-count {
    font-size: 11px;
    font-weight: 700;
    color: var(--accent-light);
    background: var(--border);
    padding: 1px 6px;
    border-radius: 6px;
    flex-shrink: 0;
}

/* Location Tree */
.loc-tree-container {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.loc-details {
    border-left: 2px solid var(--border);
    margin-left: 8px;
    padding-left: 8px;
}

.loc-details[open] {
    margin-bottom: 4px;
}

.loc-summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 8px;
    border-radius: 8px;
    cursor: pointer;
    list-style: none;
    user-select: none;
    transition: var(--transition);
}

.loc-summary::-webkit-details-marker {
    display: none;
}

.loc-summary:hover {
    background: var(--bg);
}

.loc-summary-left {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
}

.loc-cb {
    appearance: none;
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    border: 2px solid var(--border);
    border-radius: 5px;
    background: var(--card);
    cursor: pointer;
    position: relative;
    outline: none;
    flex-shrink: 0;
    transition: border-radius 0.25s cubic-bezier(0.4, 0, 0.2, 1), background-color 0.25s ease, border-color 0.25s ease;
    margin: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.loc-cb:hover {
    border-color: var(--accent-light);
}

.loc-cb:checked {
    background: var(--accent);
    border-color: var(--accent);
    border-radius: 50%;
}

.loc-cb::after {
    content: "";
    position: absolute;
    width: 6px;
    height: 6px;
    background: var(--bg);
    border-radius: 50%;
    opacity: 0;
    transform: scale(0);
    transition: opacity 0.2s ease, transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.loc-cb:checked::after {
    opacity: 1;
    transform: scale(1);
}

#f_approx {
    appearance: none;
    -webkit-appearance: none;
    width: 20px;
    height: 20px;
    border: 2px solid var(--border);
    border-radius: 5px;
    background: var(--card);
    cursor: pointer;
    position: relative;
    outline: none;
    flex-shrink: 0;
    transition: border-radius 0.25s cubic-bezier(0.4, 0, 0.2, 1), background-color 0.25s ease, border-color 0.25s ease;
    margin: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

#f_approx:hover {
    border-color: var(--accent-light);
}

#f_approx:checked {
    background: var(--accent);
    border-color: var(--accent);
    border-radius: 50%;
}

#f_approx::after {
    content: "";
    position: absolute;
    width: 6px;
    height: 6px;
    background: var(--bg);
    border-radius: 50%;
    opacity: 0;
    transform: scale(0);
    transition: opacity 0.2s ease, transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}

#f_approx:checked::after {
    opacity: 1;
    transform: scale(1);
}

.loc-name {
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
}

.loc-leaf {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 8px 6px 16px;
    border-radius: 8px;
    user-select: none;
    transition: var(--transition);
}

.loc-leaf:hover {
    background: var(--bg);
}

.loc-leaf-left {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
}

.loc-chevron {
    font-size: 16px;
    color: var(--accent-light);
    transition: transform 0.2s ease;
    margin-right: 4px;
    display: inline-flex;
    align-items: center;
}

.loc-details[open]>.loc-summary .loc-chevron {
    transform: rotate(90deg);
}

.loc-others-title {
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
    color: var(--accent-light);
    margin: 12px 0 6px 4px;
}

/* ── Catalog Grid ─────────────────────────────────────────────────────── */
.grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 25px;
}

.card {
    background: var(--card);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    cursor: pointer;
    transition: var(--transition);
    height: 100%;
    display: flex;
    flex-direction: column;
    position: relative;
    /* Ізолюємо reflow кожної картки від сусідніх */
    contain: layout style;
    /* Браузер пропускає рендеринг карток поза viewport */
    content-visibility: auto;
    contain-intrinsic-size: 0 380px;
}

.card:hover {
    transform: translateY(-4px);
    box-shadow: 0 16px 32px -8px rgba(0, 0, 0, 0.18);
    border-color: var(--accent-light);
    will-change: transform;
}

.img-preview-wrapper {
    height: 250px;
    width: 100%;
    position: relative;
    overflow: hidden;
    background: #05070f;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
}

.img-blur-bg {
    position: absolute;
    inset: -20px;
    width: calc(100% + 40px);
    height: calc(100% + 40px);
    object-fit: cover;
    /* За замовчуванням blur вимкнено для збереження GPU */
    filter: none;
    transform: scale(1.1) translateZ(0);
    opacity: 0;
    /* Швидкий fade при появі картки у viewport */
    transition: opacity 0.2s ease;
}

/* Blur активується тільки коли картка у viewport (IntersectionObserver додає .in-view) */
.card.in-view .img-blur-bg {
    filter: blur(14px);
    opacity: 0.55;
    will-change: opacity;
}


.img-original {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: contain;
    z-index: 1;
    transition: transform 0.4s ease;
    transform: translateZ(0);
    will-change: transform;
}

.card:hover .img-original {
    transform: scale(1.03) translateZ(0);
}

.card-gallery-track {
    display: flex;
    overflow-x: scroll;
    overflow-y: hidden;
    scroll-snap-type: x mandatory;
    scroll-behavior: smooth;
    width: 100%;
    height: 100%;
    scrollbar-width: none;
}

.card-gallery-track::-webkit-scrollbar {
    display: none;
}

.card-gallery-slide {
    flex: 0 0 100%;
    width: 100%;
    height: 100%;
    scroll-snap-align: start;
    position: relative;
}

.card-gallery-track.dragging {
    scroll-snap-type: none;
    scroll-behavior: auto;
    cursor: grabbing;
}

.card-gallery-dots {
    position: absolute;
    bottom: 12px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 5px;
    align-items: center;
    z-index: 15;
    /* Замінено backdrop-filter:blur() → суцільний фон. Економія: ~24 GPU-шари */
    background: rgba(10, 15, 35, 0.78);
    padding: 4px 8px;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    max-width: calc(100% - 24px);
    overflow: hidden;
}

.card-dot {
    flex-shrink: 0;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.4);
    cursor: pointer;
    transition: background 0.2s, width 0.2s, transform 0.2s, opacity 0.2s;
}

.card-dot.active {
    background: #ffffff;
    width: 14px;
    border-radius: 7px;
}

/* Windowed size hints — set by syncCardGalleryDots */
.card-dot.dot-sm { transform: scale(0.65); opacity: 0.5; }
.card-dot.dot-xs { transform: scale(0.4);  opacity: 0.3; }

.card-zoom-btn {
    position: absolute;
    bottom: 12px;
    right: 12px;
    z-index: 15;
    width: 32px;
    height: 32px;
    border-radius: 10px;
    /* Замінено backdrop-filter:blur() → суцільний фон. Економія: ~24 GPU-шари */
    background: rgba(10, 15, 35, 0.82);
    border: 1px solid rgba(255, 255, 255, 0.15);
    color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    cursor: pointer;
    transition: var(--transition);
}

.card-zoom-btn:hover {
    background: var(--accent);
    color: var(--bg);
    transform: scale(1.08);
    border-color: transparent;
}

/* Lightbox */
.lightbox {
    position: fixed;
    inset: 0;
    background: rgba(9, 13, 22, 0.95);
    backdrop-filter: blur(15px);
    -webkit-backdrop-filter: blur(15px);
    z-index: 99999;
    display: none;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.lightbox-content {
    max-width: 90vw;
    max-height: 80vh;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    user-select: none;
}

.lightbox-content img {
    max-width: 100%;
    max-height: 80vh;
    object-fit: contain;
    border-radius: 12px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.lightbox-close {
    position: absolute;
    top: 25px;
    right: 25px;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.15);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    cursor: pointer;
    transition: var(--transition);
}

.lightbox-close:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.05);
}

.lightbox-arrow {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    cursor: pointer;
    transition: var(--transition);
    user-select: none;
    z-index: 1010;
}

.lightbox-arrow:hover {
    background: var(--accent);
    color: var(--bg);
    transform: translateY(-50%) scale(1.1);
    border-color: transparent;
}

.lightbox-arrow.prev {
    left: 30px;
}

.lightbox-arrow.next {
    right: 30px;
}

.lightbox-counter {
    position: absolute;
    bottom: 25px;
    left: 50%;
    transform: translateX(-50%);
    color: rgba(255, 255, 255, 0.7);
    font-size: 14px;
    font-weight: 700;
    background: rgba(255, 255, 255, 0.08);
    padding: 6px 14px;
    border-radius: 20px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

/* Pills on cards */
.pill-top-left {
    position: absolute;
    top: 14px;
    left: 14px;
    background: rgba(15, 23, 42, 0.75);
    backdrop-filter: blur(10px);
    color: #fff;
    font-size: 12px;
    font-weight: 800;
    padding: 5px 12px;
    border-radius: 20px;
    z-index: 10;
    border: 1px solid rgba(255, 255, 255, 0.15);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    letter-spacing: 0.5px;
}

.pill-top-right {
    position: absolute;
    top: 14px;
    right: 14px;
    background: var(--accent);
    color: var(--bg);
    font-size: 12px;
    font-weight: 800;
    padding: 5px 12px;
    border-radius: 20px;
    z-index: 10;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    letter-spacing: 0.5px;
}

.pill-bottom-left {
    position: absolute;
    bottom: 14px;
    left: 14px;
    background: rgba(15, 23, 42, 0.75);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    color: #fff;
    font-size: 11px;
    font-weight: 800;
    padding: 5px 10px;
    border-radius: 20px;
    z-index: 10;
    border: 1px solid rgba(255, 255, 255, 0.15);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    letter-spacing: 0.5px;
    display: flex;
    align-items: center;
    gap: 4px;
    user-select: none;
    pointer-events: none;
}

.pill-bottom-left ion-icon {
    font-size: 13px;
}

.pill-bottom-right {
    position: absolute;
    bottom: 14px;
    right: 14px;
    z-index: 10;
    cursor: pointer;
}

/* Card body */
.card-body {
    padding: 22px;
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 15px;
}

.card-title {
    font-weight: 800;
    font-size: 18px;
    margin-bottom: 6px;
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.card-meta {
    font-size: 13px;
    color: var(--accent-light);
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

.meta-dot {
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: var(--accent-light);
    opacity: 0.5;
}

.card-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-top: 10px;
    border-top: 1px dashed var(--border);
}

.price-box {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 18px;
    font-weight: 900;
}

.approx-indicator {
    font-size: 10px;
    background: #fef3c7;
    color: #d97706;
    padding: 2px 6px;
    border-radius: 8px;
    font-weight: 800;
    border: 1px solid #fde68a;
}

[data-theme="dark"] .approx-indicator {
    background: rgba(245, 158, 11, 0.15);
    border-color: rgba(245, 158, 11, 0.3);
    color: #fbbf24;
}

.uah-price {
    font-size: 11px;
    color: #34d399;
    font-weight: 700;
    letter-spacing: 0.02em;
    opacity: 0.9;
}
[data-theme="light"] .uah-price {
    color: #059669;
}

/* Pagination */
.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    margin: 40px 0;
}

.page-btn {
    padding: 10px 16px;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: var(--card);
    color: var(--text);
    cursor: pointer;
    font-weight: 700;
    font-family: inherit;
    transition: var(--transition);
}

.page-btn.active {
    background: var(--accent);
    color: var(--bg);
    border-color: var(--accent);
}

.page-btn:hover:not(:disabled):not(.active) {
    border-color: var(--accent-light);
}

.page-btn:disabled {
    opacity: 0.3;
    cursor: default;
}

/* ── Modals ─────────────────────────────────────────────────────────────── */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(12px);
    z-index: 2000;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 16px;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.modal.active {
    display: flex;
    opacity: 1;
}

.modal-content {
    background: var(--card);
    width: 100%;
    max-width: 550px;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    /* KEY: flex column so children fill height */
    display: flex;
    flex-direction: column;
    /* Max height + hidden overflow keeps header/footer sticky */
    max-height: 90vh;
    overflow: hidden;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
}

/* cartView / checkoutView — must be flex too! */
.modal-view {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    /* allows scroll child to grow */
    overflow: hidden;
}

.modal-header {
    padding: 18px 24px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
    /* never shrink — stays on top */
}

.modal-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--border);
    background: var(--card);
    flex-shrink: 0;
    /* never shrink — stays on bottom */
}

.modal-scroll {
    flex: 1;
    /* fill all remaining height */
    min-height: 0;
    /* REQUIRED for flex overflow to work */
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 20px 24px;
}

/* ── Cart modal — mobile fullscreen bottom sheet ─────────────────────────── */
@media (max-width: 640px) {
    #cartModal {
        padding: 0;
        align-items: flex-end;
        /* stick to bottom */
    }

    #cartModal .modal-content {
        max-width: 100%;
        max-height: 96dvh;
        /* 96% of dynamic viewport height */
        border-radius: var(--radius-lg) var(--radius-lg) 0 0;
        border-bottom: none;
        box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.3);
        animation: slideUpCart 0.28s cubic-bezier(0.4, 0, 0.2, 1);
        /* Safe area for iPhone notch */
        padding-bottom: env(safe-area-inset-bottom, 0);
    }

    #cartModal .modal-header {
        padding: 14px 18px;
    }

    #cartModal .modal-footer {
        padding: 12px 18px;
    }

    #cartModal .modal-scroll {
        padding: 16px 18px;
    }
}

@keyframes slideUpCart {
    from {
        transform: translateY(100%);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
}

/* Cart */
.cart-count-badge {
    position: absolute;
    top: -10px;
    right: -8px;
    background: #ef4444;
    color: white;
    font-size: 11px;
    font-weight: 800;
    padding: 2px 6px;
    border-radius: 10px;
    min-width: 18px;
    text-align: center;
    line-height: 1.4;
    border: 2px solid var(--card);
    display: none;
    z-index: 10;
}

.cart-count-badge.visible {
    display: block;
}

/* Bottom-sheet drag handle (мобільний) */
.cart-drag-handle {
    display: none;
    width: 36px;
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    margin: 10px auto 4px;
    flex-shrink: 0;
    cursor: pointer;
    transition: background 0.2s;
}

.cart-drag-handle:hover {
    background: var(--accent-light);
}

@media (max-width: 640px) {
    .cart-drag-handle {
        display: block;
    }
}

.cart-item-row {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
}

.cart-item-row:last-child {
    border-bottom: none;
}

.cart-item-img {
    width: 50px;
    height: 50px;
    object-fit: cover;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: #000;
}

.cart-item-info {
    flex: 1;
    min-width: 0;
}

.cart-item-title {
    font-weight: 700;
    font-size: 15px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.cart-item-price {
    font-size: 13px;
    font-weight: 800;
    color: var(--accent-light);
    margin-top: 2px;
}

/* ── Cart currency toggle ─────────────────────────────────────────────────── */
.cart-currency-toggle {
    display: inline-flex;
    align-items: center;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 2px;
    gap: 2px;
}
.cart-currency-btn {
    padding: 4px 12px;
    border: none;
    background: transparent;
    color: var(--accent-light);
    font-size: 13px;
    font-weight: 800;
    border-radius: 16px;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    line-height: 1;
}
.cart-currency-btn.active {
    background: var(--accent);
    color: var(--bg);
}
.cart-currency-btn:hover:not(.active) {
    background: var(--card);
    color: var(--text);
}

.qty-btn {
    width: 28px;
    height: 28px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    cursor: pointer;
    transition: var(--transition);
}

.qty-btn:hover {
    background: var(--border);
}

.qty-val {
    font-size: 14px;
    font-weight: 800;
    width: 20px;
    text-align: center;
}

.cart-item-remove-btn {
    color: #ef4444;
    background: transparent;
    border: none;
    font-size: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 4px;
    border-radius: 8px;
    transition: var(--transition);
}

.cart-item-remove-btn:hover {
    background: #fee2e2;
}

[data-theme="dark"] .cart-item-remove-btn:hover {
    background: rgba(239, 68, 68, 0.15);
}

/* Forms */
.form-group {
    margin-bottom: 18px;
}

.form-group label {
    display: block;
    font-size: 12px;
    font-weight: 800;
    color: var(--accent-light);
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.form-group input {
    width: 100%;
    padding: 14px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
    font-size: 16px;
    font-family: inherit;
    font-weight: 500;
    outline: none;
    transition: var(--transition);
}

.form-group input:focus {
    border-color: var(--accent);
}

.form-group select {
    width: 100%;
    padding: 14px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
    font-size: 15px;
    font-family: inherit;
    font-weight: 600;
    outline: none;
    transition: var(--transition);
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 14px center;
    padding-right: 40px;
}

.form-group select:focus {
    border-color: var(--accent);
}

/* Condition badges */
.condition-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 8px;
    border-radius: 8px;
    font-size: 11px;
    font-weight: 900;
    letter-spacing: 0.3px;
    border: 1px solid transparent;
    white-space: nowrap;
}

.condition-M {
    color: #059669;
    background: rgba(5, 150, 105, 0.12);
    border-color: rgba(5, 150, 105, 0.3);
}

.condition-NM {
    color: #10b981;
    background: rgba(16, 185, 129, 0.1);
    border-color: rgba(16, 185, 129, 0.25);
}

.condition-VGP {
    color: #65a30d;
    background: rgba(101, 163, 13, 0.1);
    border-color: rgba(101, 163, 13, 0.25);
}

.condition-VG {
    color: #ca8a04;
    background: rgba(202, 138, 4, 0.1);
    border-color: rgba(202, 138, 4, 0.25);
}

.condition-GP {
    color: #ea580c;
    background: rgba(234, 88, 12, 0.1);
    border-color: rgba(234, 88, 12, 0.25);
}

.condition-G {
    color: #dc2626;
    background: rgba(220, 38, 38, 0.1);
    border-color: rgba(220, 38, 38, 0.25);
}

.condition-F {
    color: #7c3aed;
    background: rgba(124, 58, 237, 0.1);
    border-color: rgba(124, 58, 237, 0.25);
}

.condition-P {
    color: #94a3b8;
    background: rgba(148, 163, 184, 0.1);
    border-color: rgba(148, 163, 184, 0.25);
}

/* Photo editor */
.edit-photos {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
    gap: 10px;
    margin-top: 10px;
}

.edit-img-card {
    position: relative;
    aspect-ratio: 1;
    border-radius: 12px;
    overflow: hidden;
    border: 2px solid var(--border);
    background: #000;
}

.edit-img-card img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.remove-img {
    position: absolute;
    top: 4px;
    right: 4px;
    background: #ef4444;
    color: white;
    border: none;
    border-radius: 8px;
    width: 24px;
    height: 24px;
    font-weight: bold;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Empty state */
.empty-state {
    grid-column: 1 / -1;
    padding: 60px 20px;
    text-align: center;
    background: var(--card);
    border-radius: var(--radius-lg);
    border: 1px dashed var(--border);
    color: var(--accent-light);
}

.empty-state ion-icon {
    font-size: 64px;
    opacity: 0.4;
    margin-bottom: 15px;
}

.empty-state h3 {
    font-size: 20px;
    font-weight: 800;
    color: var(--text);
    margin: 0 0 8px 0;
}

/* ── Responsive ────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
    .top-bar {
        margin-bottom: 20px;
        gap: 10px;
        padding-top: 15px;
    }

    .logo-icon {
        width: 38px;
        height: 38px;
        font-size: 20px;
        border-radius: 10px;
    }

    .logo-title {
        font-size: 20px;
    }

    .logo-subtitle {
        font-size: 11px;
    }

    .top-bar .btn {
        padding: 10px 12px;
        border-radius: 12px;
    }

    .top-bar .btn span:not(.cart-count-badge) {
        display: none;
    }

    .top-bar>div:last-child {
        gap: 6px !important;
    }

    .theme-toggle {
        width: 38px;
        height: 38px;
        border-radius: 12px;
    }

    .search-bar-row {
        padding: 12px;
        flex-wrap: wrap;
    }

    .search-box {
        flex: 0 0 100%;
        width: 100%;
    }

    .sort-select {
        flex: 1;
        min-width: 0;
        width: auto;
        padding: 12px 14px;
    }

    .filter-toggle-btn {
        flex: 1;
        min-width: 0;
        width: auto;
        justify-content: center;
        padding: 12px 14px;
    }

    .filter-drawer {
        width: 100vw;
        max-width: 100%;
        border-right: none;
    }

    .lightbox-close {
        top: 15px;
        right: 15px;
    }

    .form-row {
        grid-template-columns: 1fr;
    }
}

/* ── index.php: Hero ──────────────────────────────────────────────────────── */
.hero {
    text-align: center;
    padding: 60px 20px 20px;
}

.hero-accent {
    background: linear-gradient(135deg, var(--text) 0%, var(--accent-light) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.hero h1 {
    font-size: clamp(36px, 7vw, 72px);
    font-weight: 900;
    margin: 0 0 16px;
    letter-spacing: -2px;
    line-height: 1;
}

.hero-desc {
    font-size: 18px;
    color: var(--accent-light);
    font-weight: 500;
    max-width: 520px;
    margin: 0 auto 40px;
    line-height: 1.6;
}

/* ── index.php: Section cards ─────────────────────────────────────────────── */
.sections-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 20px;
    margin: 0 auto;
}

@media (max-width: 680px) {
    .sections-grid {
        grid-template-columns: 1fr;
    }

    .hero h1 {
        font-size: 38px;
        letter-spacing: -1px;
    }

    .hero-desc {
        font-size: 15px;
    }
}

.section-card {
    position: relative;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 32px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    text-decoration: none;
    color: var(--text);
    transition: var(--transition);
    overflow: hidden;
    cursor: pointer;
}

.section-card::before {
    content: '';
    position: absolute;
    inset: 0;
    opacity: 0;
    transition: opacity 0.3s ease;
    border-radius: var(--radius-lg);
}

.section-card-vinyl::before {
    background: radial-gradient(circle at 80% 20%, rgba(99, 102, 241, 0.08) 0%, transparent 60%);
}

.section-card-cd::before {
    background: radial-gradient(circle at 80% 20%, rgba(16, 185, 129, 0.08) 0%, transparent 60%);
}

.section-card-cassette::before {
    background: radial-gradient(circle at 80% 20%, rgba(245, 158, 11, 0.08) 0%, transparent 60%);
}

.section-card-equip::before {
    background: radial-gradient(circle at 80% 20%, rgba(239, 68, 68, 0.08) 0%, transparent 60%);
}

.section-card:hover {
    box-shadow: var(--shadow);
    transform: translateY(-4px);
    border-color: var(--accent-light);
}

.section-card:hover::before {
    opacity: 1;
}

.section-card:active {
    transform: translateY(-2px);
}

.section-icon {
    width: 60px;
    height: 60px;
    border-radius: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    flex-shrink: 0;
}

.icon-vinyl {
    background: rgba(99, 102, 241, 0.12);
    color: #6366f1;
}

.icon-cd {
    background: rgba(16, 185, 129, 0.12);
    color: #10b981;
}

.icon-cassette {
    background: rgba(245, 158, 11, 0.12);
    color: #f59e0b;
}

.icon-equip {
    background: rgba(239, 68, 68, 0.12);
    color: #ef4444;
}

.section-card-title {
    font-size: 22px;
    font-weight: 900;
    margin: 0;
}

.section-card-desc {
    font-size: 14px;
    color: var(--accent-light);
    line-height: 1.5;
    font-weight: 500;
    margin: 0;
}

.section-card-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: auto;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

.section-stats {
    display: flex;
    gap: 16px;
}

.section-stat {
    font-size: 13px;
}

.section-stat strong {
    font-weight: 900;
}

.section-stat span {
    color: var(--accent-light);
    font-weight: 600;
}

.section-arrow {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    background: var(--bg);
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    color: var(--accent-light);
    transition: var(--transition);
}

.section-card:hover .section-arrow {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--bg);
    transform: translateX(3px);
}

.admin-notice {
    margin: 30px 0 0;
    padding: 16px 20px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    font-size: 13px;
    color: var(--accent-light);
    display: flex;
    align-items: center;
    gap: 10px;
}

.admin-notice ion-icon {
    font-size: 18px;
    flex-shrink: 0;
}

/* ── equipment.php: Cards ─────────────────────────────────────────────────── */
.catalog-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 20px;
}

@media (max-width: 540px) {
    .catalog-grid {
        grid-template-columns: 1fr;
        gap: 14px;
    }
}

.eq-card {
    background: var(--card);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    overflow: hidden;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    flex-direction: column;
}

.eq-card:hover {
    box-shadow: var(--shadow);
    transform: translateY(-3px);
    border-color: var(--accent-light);
}

.eq-card:active {
    transform: translateY(-1px);
}

.eq-card-img {
    width: 100%;
    height: 200px;
    object-fit: cover;
    background: var(--bg);
    display: flex;
    align-items: center;
    justify-content: center;
}

.eq-card-img-placeholder {
    width: 100%;
    height: 200px;
    background: var(--bg);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 60px;
    color: var(--border);
}

.eq-card-body {
    padding: 18px;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.eq-card-title {
    font-size: 17px;
    font-weight: 900;
    line-height: 1.2;
}

.eq-card-meta {
    font-size: 13px;
    color: var(--accent-light);
    font-weight: 600;
}

.eq-card-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-top: 10px;
    border-top: 1px solid var(--border);
}

.eq-price {
    font-size: 18px;
    font-weight: 900;
}

.eq-avail {
    font-size: 12px;
    font-weight: 800;
    padding: 4px 10px;
    border-radius: 10px;
}

.avail-yes {
    background: rgba(16, 185, 129, 0.1);
    color: #10b981;
}

.avail-no {
    background: rgba(239, 68, 68, 0.1);
    color: #ef4444;
}

.type-turntable {
    background: rgba(99, 102, 241, 0.1);
    color: #6366f1;
}

.type-amplifier {
    background: rgba(239, 68, 68, 0.1);
    color: #ef4444;
}

.type-cd {
    background: rgba(16, 185, 129, 0.1);
    color: #10b981;
}

.type-cassette {
    background: rgba(245, 158, 11, 0.1);
    color: #f59e0b;
}

.type-receiver {
    background: rgba(14, 165, 233, 0.1);
    color: #0ea5e9;
}

.type-tuner {
    background: rgba(168, 85, 247, 0.1);
    color: #a855f7;
}

.type-speaker {
    background: rgba(236, 72, 153, 0.1);
    color: #ec4899;
}

.eq-type-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 11px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 4px 10px;
    border-radius: 8px;
}

/* ── References page — Design System ────────────────────────────────────── */

/* Top row: Статистика | Медіа | Обладнання */
.ref-top-row {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 24px;
}

.ref-section-divider {
    width: 1px;
    height: 28px;
    background: var(--border);
    margin: 0 4px;
    flex-shrink: 0;
}

.ref-section-pill {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 18px;
    border-radius: 30px;
    font-family: inherit;
    font-size: 14px;
    font-weight: 700;
    border: 1.5px solid var(--border);
    background: var(--bg);
    color: var(--accent-light);
    cursor: pointer;
    transition: var(--transition);
    white-space: nowrap;
}

.ref-section-pill:hover {
    border-color: var(--accent);
    color: var(--text);
}

.ref-section-pill.active {
    background: var(--accent);
    color: var(--bg);
    border-color: var(--accent);
}

.ref-section-pill--stats {
    border-color: rgba(124, 58, 237, 0.35);
    color: #7c3aed;
}

.ref-section-pill--stats:hover {
    background: rgba(124, 58, 237, 0.06);
    border-color: #7c3aed;
}

.ref-section-pill--stats.active {
    background: #7c3aed;
    color: #fff;
    border-color: #7c3aed;
}

[data-theme="dark"] .ref-section-pill--stats {
    color: #a78bfa;
    border-color: rgba(167, 139, 250, 0.3);
}

[data-theme="dark"] .ref-section-pill--stats.active {
    background: #7c3aed;
    color: #fff;
}

/* Main panel (stats / media / equipment) */
.ref-main-panel {}

/* Category selector (Вініл / CD / Касети) */
.ref-section-selector {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin-bottom: 20px;
}

.ref-cat-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 9px 16px;
    border-radius: 14px;
    font-family: inherit;
    font-size: 13px;
    font-weight: 700;
    border: 1.5px solid var(--border);
    background: var(--bg);
    color: var(--accent-light);
    cursor: pointer;
    transition: var(--transition);
    white-space: nowrap;
}

.ref-cat-btn:hover {
    border-color: var(--accent);
    color: var(--text);
}

.ref-cat-btn.active {
    background: var(--accent);
    color: var(--bg);
    border-color: var(--accent);
}

/* Tab nav (inner tabs for ref types) */
.ref-tab-nav {
    display: flex;
    gap: 4px;
    flex-wrap: nowrap;
    background: var(--card);
    padding: 8px 10px;
    border-radius: 18px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    margin-bottom: 24px;
    position: sticky;
    top: 0;
    z-index: 99;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}

.ref-tab-nav::-webkit-scrollbar {
    display: none;
}

[data-theme="dark"] .ref-tab-nav {
    background: rgba(17, 24, 39, 0.95);
    backdrop-filter: blur(10px);
}

.ref-tab-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 9px 16px;
    border-radius: 12px;
    font-family: inherit;
    font-size: 13px;
    font-weight: 700;
    color: var(--accent-light);
    cursor: pointer;
    white-space: nowrap;
    transition: var(--transition);
    border: none;
    background: transparent;
    flex-shrink: 0;
}

.ref-tab-btn:hover {
    color: var(--text);
    background: var(--bg);
}

.ref-tab-btn.active {
    background: var(--accent);
    color: var(--bg);
}

.ref-tab-label {}

.ref-tab-badge {
    font-size: 10px;
    font-weight: 900;
    background: rgba(255, 255, 255, 0.2);
    color: inherit;
    padding: 1px 6px;
    border-radius: 8px;
    min-width: 18px;
    text-align: center;
}

.ref-tab-btn:not(.active) .ref-tab-badge {
    background: var(--border);
    color: var(--accent-light);
}

/* Panel visibility */
.ref-panel {
    display: none;
}

.ref-panel.active {
    display: block;
}

/* Mini stats row */
.ref-mini-stats {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 18px;
}

.ref-mini-stat {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 8px 14px;
    font-size: 13px;
    font-weight: 600;
    color: var(--accent-light);
}

.ref-mini-stat strong {
    color: var(--text);
    font-size: 15px;
    font-weight: 900;
    margin-left: 2px;
}

.ref-mini-stat ion-icon {
    font-size: 16px;
}

/* Controls row */
.ref-controls {
    display: flex;
    gap: 10px;
    align-items: stretch;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.ref-search-wrap {
    position: relative;
    flex: 1;
    min-width: 200px;
}

.ref-search-ico {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--accent-light);
    font-size: 18px;
    pointer-events: none;
}

/* Unified input */
.ref-input {
    width: 100%;
    padding: 12px 16px 12px 44px;
    border-radius: var(--radius-md);
    border: 1.5px solid var(--border);
    background: var(--card);
    color: var(--text);
    font-family: inherit;
    font-size: 14px;
    font-weight: 600;
    outline: none;
    transition: var(--transition);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}

.ref-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(15, 23, 42, 0.06);
}

[data-theme="dark"] .ref-input:focus {
    box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.06);
}

/* When used not as search (no icon) */
.ref-merge-target {
    padding-left: 16px;
}

.ref-rename-input {
    padding: 6px 12px;
    font-size: 14px;
    border-radius: 10px;
}

/* Ref buttons */
.ref-btn {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 10px 18px;
    border-radius: var(--radius-md);
    font-family: inherit;
    font-size: 13px;
    font-weight: 700;
    border: none;
    cursor: pointer;
    transition: var(--transition);
    white-space: nowrap;
}

.ref-btn:active {
    transform: scale(0.97);
}

.ref-btn--primary {
    background: var(--accent);
    color: var(--bg);
}

.ref-btn--primary:hover {
    opacity: 0.88;
}

.ref-btn--ghost {
    background: var(--bg);
    color: var(--text);
    border: 1.5px solid var(--border);
}

.ref-btn--ghost:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.ref-btn--accent {
    background: rgba(59, 130, 246, 0.1);
    color: #3b82f6;
    border: 1.5px solid rgba(59, 130, 246, 0.3);
}

.ref-btn--accent:hover {
    background: rgba(59, 130, 246, 0.18);
}

[data-theme="dark"] .ref-btn--accent {
    background: rgba(59, 130, 246, 0.15);
    color: #60a5fa;
}

.ref-btn--danger {
    background: rgba(239, 68, 68, 0.08);
    color: #ef4444;
    border: 1.5px solid rgba(239, 68, 68, 0.2);
}

.ref-btn--danger:hover {
    background: rgba(239, 68, 68, 0.15);
}

[data-theme="dark"] .ref-btn--danger {
    background: rgba(239, 68, 68, 0.12);
    color: #f87171;
    border-color: rgba(239, 68, 68, 0.3);
}

.ref-btn--sm {
    padding: 7px 12px;
    font-size: 12px;
    border-radius: 10px;
}

.ref-btn--icon {
    padding: 8px;
    border-radius: 10px;
    background: var(--bg);
    color: var(--accent-light);
    border: 1.5px solid var(--border);
    font-size: 16px;
}

.ref-btn--icon:hover {
    color: var(--text);
    border-color: var(--accent);
}

/* Add row */
.ref-add-row {
    display: flex;
    gap: 10px;
    align-items: center;
    background: var(--card);
    border: 1.5px dashed var(--border);
    border-radius: var(--radius-md);
    padding: 12px 16px;
    margin-bottom: 20px;
}

.ref-add-ico {
    font-size: 22px;
    color: var(--accent-light);
    flex-shrink: 0;
}

.ref-add-row .ref-input {
    padding-left: 16px;
    box-shadow: none;
    border-color: transparent;
    background: transparent;
}

.ref-add-row .ref-input:focus {
    border-color: var(--accent);
    background: var(--bg);
}

/* Merge bar */
.ref-merge-bar {
    display: none;
    align-items: center;
    gap: 12px;
    background: rgba(59, 130, 246, 0.06);
    border: 1.5px solid rgba(59, 130, 246, 0.25);
    border-radius: var(--radius-md);
    padding: 14px 18px;
    margin-bottom: 18px;
    flex-wrap: wrap;
}

.ref-merge-bar.visible {
    display: flex;
}

.ref-merge-ico {
    font-size: 22px;
    color: #3b82f6;
    flex-shrink: 0;
}

.ref-merge-body {
    flex: 1;
    min-width: 0;
}

.ref-merge-label {
    font-size: 13px;
    font-weight: 700;
    color: #3b82f6;
}

.ref-merge-selected {
    font-size: 12px;
    color: var(--accent-light);
    font-weight: 600;
    margin-top: 4px;
}

.ref-merge-target {
    flex: 1;
    min-width: 180px;
}

/* List */
.ref-list {
    background: var(--card);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.ref-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 13px 18px;
    border-bottom: 1px solid var(--border);
    transition: var(--transition);
}

.ref-item:last-child {
    border-bottom: none;
}

.ref-item:hover {
    background: var(--bg);
}

.ref-item--selected {
    background: rgba(59, 130, 246, 0.05) !important;
}

.ref-item--selected .ref-name {
    color: #3b82f6;
}

/* Custom checkbox */
.ref-checkbox-wrap {
    position: relative;
    display: inline-flex;
    align-items: center;
    flex-shrink: 0;
    cursor: pointer;
}

.ref-checkbox-input {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.ref-checkbox-box {
    width: 18px;
    height: 18px;
    border-radius: 6px;
    border: 2px solid var(--border);
    background: var(--bg);
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.ref-checkbox-wrap:hover .ref-checkbox-box {
    border-color: #3b82f6;
}

.ref-checkbox-input:checked+.ref-checkbox-box {
    background: #3b82f6;
    border-color: #3b82f6;
}

.ref-checkbox-input:checked+.ref-checkbox-box::after {
    content: '';
    display: block;
    width: 5px;
    height: 9px;
    border: 2px solid #fff;
    border-top: none;
    border-left: none;
    transform: rotate(45deg) translateY(-1px);
}

.ref-name-wrap {
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.ref-name {
    font-size: 14px;
    font-weight: 700;
    word-break: break-word;
}

.ref-raw-code {
    font-size: 11px;
    font-weight: 700;
    color: var(--accent-light);
    background: var(--border);
    padding: 2px 8px;
    border-radius: 6px;
    font-family: monospace;
}

.ref-usage {
    font-size: 11px;
    font-weight: 800;
    color: var(--accent-light);
    background: var(--bg);
    padding: 3px 9px;
    border-radius: 10px;
    border: 1px solid var(--border);
    white-space: nowrap;
    flex-shrink: 0;
}

.ref-usage.has-uses {
    color: #10b981;
    border-color: rgba(16, 185, 129, 0.3);
    background: rgba(16, 185, 129, 0.07);
}

.ref-actions {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}

/* Empty state */
.ref-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 40px 20px;
    color: var(--accent-light);
    text-align: center;
}

.ref-empty ion-icon {
    font-size: 36px;
    margin-bottom: 8px;
}

.ref-empty p {
    margin: 0;
    font-size: 14px;
    font-weight: 600;
}

/* Stats filter row */
.stats-filter-row {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 24px;
}

.stats-filter-btn {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 10px 18px;
    border-radius: 30px;
    font-family: inherit;
    font-size: 13px;
    font-weight: 700;
    border: 1.5px solid var(--border);
    background: var(--bg);
    color: var(--accent-light);
    cursor: pointer;
    transition: var(--transition);
    white-space: nowrap;
}

.stats-filter-btn:hover {
    border-color: var(--accent);
    color: var(--text);
}

.stats-filter-btn.active {
    background: var(--accent);
    color: var(--bg);
    border-color: var(--accent);
}

.stats-breakdown-title {
    font-size: 12px;
    font-weight: 800;
    color: var(--accent-light);
    text-transform: uppercase;
    letter-spacing: .06em;
    margin: 28px 0 12px;
}

.td-right {
    text-align: right;
}

.td-bold {
    font-weight: 700;
}

/* Section selector */
.section-selector {
    margin-bottom: 20px;
    display: flex;
    gap: 8px;
}


/* Toast (references) */
#toast {
    position: fixed;
    bottom: 28px;
    left: 50%;
    transform: translateX(-50%);
    background: #0f172a;
    color: #f8fafc;
    padding: 12px 24px;
    border-radius: 30px;
    font-weight: 700;
    font-size: 14px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.25);
    z-index: 9999;
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
    white-space: nowrap;
}

[data-theme="dark"] #toast {
    background: #f8fafc;
    color: #0f172a;
}

#toast.show {
    opacity: 1;
}

#toast.success {
    background: #10b981;
    color: #fff;
}

#toast.error {
    background: #ef4444;
    color: #fff;
}

/* ── Availability filter checkbox ─────────────────────────────────────────── */
.avail-filter-row {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    padding: 8px 0;
}

.avail-filter-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border-radius: 12px;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    border: 1.5px solid var(--border);
    background: var(--bg);
    color: var(--text);
    transition: var(--transition);
    user-select: none;
}

.avail-filter-btn.active-avail {
    border-color: #10b981;
    background: rgba(16, 185, 129, 0.1);
    color: #10b981;
}

.avail-filter-btn.active-unavail {
    border-color: #ef4444;
    background: rgba(239, 68, 68, 0.1);
    color: #ef4444;
}

/* ── Mobile top-bar ───────────────────────────────────────────────────────── */
@media (max-width: 768px) {
    .top-bar {
        padding: 12px 14px 8px;
        gap: 8px;
        flex-wrap: nowrap;
    }

    .top-bar.scrolled {
        padding: 8px 14px;
    }

    /* Скрываем текст в кнопках шапки, остаются только иконки */
    .top-bar .btn-label {
        display: none;
    }

    .top-bar .btn {
        padding: 10px 12px;
        font-size: 14px;
        min-width: 40px;
    }

    .top-bar .btn span:not(.cart-count-badge) {
        display: none;
    }

    /* Логотип чуть меньше */
    .logo-icon {
        width: 36px;
        height: 36px;
        font-size: 20px;
        border-radius: 10px;
    }

    .logo-title {
        font-size: 20px;
    }

    .logo-subtitle {
        display: none;
    }

    /* Кнопка темы чуть меньше */
    .theme-toggle {
        width: 40px;
        height: 40px;
        font-size: 18px;
    }

    /* Правый блок кнопок — не переносится */
    .top-bar>div:last-child {
        display: flex;
        gap: 6px;
        align-items: center;
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        max-width: 100%;
    }

    .top-bar>div:last-child::-webkit-scrollbar {
        display: none;
    }
}

@media (max-width: 480px) {
    .logo-title {
        font-size: 17px;
    }

    .logo-icon {
        width: 32px;
        height: 32px;
        font-size: 17px;
    }

    .top-bar .btn {
        padding: 8px 10px;
    }

    .theme-toggle {
        width: 36px;
        height: 36px;
        font-size: 16px;
    }
}

/* ── Statistics Cards ─────────────────────────────────────────────────────── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 16px;
    margin-bottom: 8px;
}

.stat-card {
    display: flex;
    align-items: flex-start;
    gap: 16px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
    box-shadow: var(--shadow);
    transition: var(--transition);
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
}

.stat-card-icon {
    width: 52px;
    height: 52px;
    flex-shrink: 0;
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 26px;
}

.stat-card-body {
    flex: 1;
    min-width: 0;
}

.stat-card-value {
    font-size: 24px;
    font-weight: 900;
    color: var(--text);
    line-height: 1.1;
}

.stat-card-label {
    font-size: 13px;
    font-weight: 700;
    color: var(--text-secondary, var(--accent-light));
    margin-top: 4px;
}

.stat-card-sub {
    font-size: 11px;
    font-weight: 600;
    color: var(--muted, var(--accent-light));
    margin-top: 2px;
    opacity: 0.7;
}

.stat-card-uah {
    font-size: 12px;
    font-weight: 700;
    color: #34d399;
    margin-top: 1px;
    letter-spacing: 0.02em;
}
[data-theme="light"] .stat-card-uah {
    color: #059669;
}

.stat-uah-small {
    font-size: 11px;
    font-weight: 700;
    color: #34d399;
    display: inline-block;
}
[data-theme="light"] .stat-uah-small {
    color: #059669;
}

/* Stats breakdown table */
.stats-table-wrap {
    overflow-x: auto;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
}

.stats-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.stats-table thead th {
    background: var(--card);
    color: var(--accent-light);
    font-size: 11px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: .06em;
    padding: 12px 18px;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

.stats-table tbody tr {
    border-bottom: 1px solid var(--border);
    transition: var(--transition);
}

.stats-table tbody tr:last-child {
    border-bottom: none;
}

.stats-table tbody tr:hover {
    background: var(--bg);
}

.stats-table tbody td {
    padding: 14px 18px;
    color: var(--text);
    font-weight: 600;
}

@media (max-width: 600px) {
    .stats-grid {
        grid-template-columns: 1fr 1fr;
        gap: 12px;
    }

    .stat-card {
        padding: 14px;
    }

    .stat-card-value {
        font-size: 18px;
    }

    .stat-card-icon {
        width: 40px;
        height: 40px;
        font-size: 20px;
        border-radius: 10px;
    }
}

@media (max-width: 380px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }
}

/* ── References page — Mobile ────────────────────────────────────────────── */
@media (max-width: 768px) {

    /* Top row */
    .ref-top-row {
        gap: 6px;
        margin-bottom: 16px;
    }

    .ref-section-pill {
        padding: 8px 14px;
        font-size: 13px;
    }

    .ref-section-divider {
        display: none;
    }

    /* Category selector */
    .ref-section-selector {
        gap: 6px;
    }

    .ref-cat-btn {
        padding: 8px 12px;
        font-size: 12px;
    }

    /* Tab nav */
    .ref-tab-nav {
        padding: 6px 8px;
        border-radius: 14px;
        margin-bottom: 16px;
    }

    .ref-tab-btn {
        padding: 8px 12px;
        font-size: 12px;
    }

    /* Hide labels on very small screens — icon only */

    /* Controls */
    .ref-controls {
        flex-direction: column;
        gap: 8px;
    }

    .ref-search-wrap {
        min-width: 0;
    }

    .ref-btn--ghost {
        width: 100%;
        justify-content: center;
    }

    /* List items */
    .ref-item {
        padding: 11px 14px;
        gap: 10px;
    }

    .ref-actions .ref-btn--icon {
        padding: 7px;
    }

    /* Merge bar */
    .ref-merge-bar {
        flex-direction: column;
        align-items: stretch;
    }

    .ref-merge-target {
        min-width: 0;
    }

    .ref-merge-bar .ref-btn {
        justify-content: center;
    }

    /* Add row */
    .ref-add-row {
        flex-wrap: wrap;
    }

    .ref-add-row .ref-btn--primary {
        width: 100%;
        justify-content: center;
    }

    /* Stats filter */
    .stats-filter-row {
        gap: 6px;
    }

    .stats-filter-btn {
        padding: 8px 12px;
        font-size: 12px;
    }

    /* Mini stats */
    .ref-mini-stats {
        gap: 6px;
    }

    .ref-mini-stat {
        padding: 6px 10px;
        font-size: 12px;
    }
}

@media (max-width: 480px) {
    .ref-tab-btn .ref-tab-label {
        display: none;
    }

    .ref-tab-badge {
        display: none;
    }

    .ref-tab-btn {
        padding: 8px 10px;
        font-size: 16px;
    }

    .ref-section-pill {
        padding: 8px 12px;
        font-size: 12px;
        gap: 5px;
    }

    .ref-item {
        gap: 8px;
        padding: 10px 12px;
    }

    .ref-name {
        font-size: 13px;
    }
}