:root {
    --primary-color: #000000;
    --secondary-color: #1a1a1a;
    --accent-color: #007aff;
    --text-primary: #ffffff;
    --text-secondary: #8e8e93;
    --border-color: #2c2c2e;
    --card-bg: #1c1c1e;
    --modal-bg: rgba(0, 0, 0, 0.8);
    --content-max-width: 600px;
    --balance-color: #34c759;
    --profile-bg: rgba(28, 28, 30, 0.9);
    --clear-filters-bg: #ff3b30;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background-color: var(--primary-color);
    color: var(--text-primary);
    line-height: 1.5;
    padding-bottom: 20px;
    min-height: 100vh;
}

/* =========== ВЕРХНИЙ СЕКЦИЯ С ПРОФИЛЕМ И БАННЕРОМ =========== */
.top-section {
    position: relative;
    width: 100%;
    padding: 16px;
}

/* Профиль в правом верхнем углу */
.profile-container {
    display: none;
    position: absolute;
    top: 16px;
    right: 16px;
    align-items: center;
    background: var(--profile-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-radius: 50px;
    padding: 8px 12px 8px 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.25);
    border: 1px solid var(--border-color);
    max-width: 200px;
    z-index: 100;
    transition: all 0.3s ease;
}

.profile-info {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
}

.profile-photo {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid var(--accent-color);
    flex-shrink: 0;
}

.profile-details {
    display: flex;
    flex-direction: column;
    min-width: 0;
    flex: 1;
}

.profile-name {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 90px;
    line-height: 1.2;
}

.profile-balance {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 15px;
    color: var(--text-primary);
    line-height: 1.2;
}

.balance-value {
    font-weight: 600;
    color: var(--balance-color);
}

.balance-currency {
    font-size: 13px;
    color: var(--balance-color);
    font-weight: 600;
}

.profile-refresh-btn {
    background: none;
    border: none;
    padding: 6px;
    border-radius: 50%;
    cursor: pointer;
    color: var(--text-secondary);
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    margin-left: 2px;
    width: 28px;
    height: 28px;
    min-width: 28px;
    min-height: 28px;
    position: relative;
}

.profile-refresh-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--accent-color);
}

.profile-refresh-btn:active {
    transform: none !important;
}

/* Баннер под профилем */
.banner-container {
    width: 100%;
    margin-top: 90px;
    display: flex;
    justify-content: center;
}

.site-banner {
    width: 100%;
    max-width: 800px;
    height: auto;
    max-height: 150px;
    border-radius: 16px;
    object-fit: cover;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
}

/* =========== ОСНОВНОЙ КОНТЕНТ =========== */
.content-wrapper {
    max-width: 100%;
    margin: 0 auto;
    padding: 0;
    position: relative;
    min-height: 100vh;
}

.main-container {
    width: 100%;
    margin: 0 auto;
    padding: 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.main-container-inner {
    width: 100%;
    max-width: var(--content-max-width);
    margin: 0 auto;
}

.clear-filters-section {
    width: 100%;
    margin-bottom: 12px;
    animation: fadeIn 0.3s ease-out;
}

.clear-filters-btn {
    width: 100%;
    padding: 10px 16px;
    background-color: var(--clear-filters-bg);
    border: none;
    border-radius: 10px;
    color: white;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.2s ease;
    box-shadow: 0 2px 8px rgba(255, 59, 48, 0.3);
}

.clear-filters-btn:hover {
    background-color: #ff2d23;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(255, 59, 48, 0.4);
}

.clear-filters-btn:active {
    transform: translateY(0);
    background-color: #ff1f15;
}

.clear-filters-icon {
    flex-shrink: 0;
}

.clear-filters-btn span {
    font-weight: 500;
}

.container {
    width: 100%;
    margin: 0 auto;
    padding: 0 16px 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.container-inner {
    width: 100%;
    max-width: var(--content-max-width);
    margin: 0 auto;
}

.filter-section, 
.sort-section, 
.refresh-section {
    width: 100%;
    margin-bottom: 16px;
}

/* =========== ФИЛЬТРЫ =========== */
.filter-wrapper { 
    background-color: var(--secondary-color); 
    border-radius: 12px; 
    overflow: hidden; 
    width: 100%;
}

.filter-row { 
    display: flex; 
    border-bottom: 1px solid var(--border-color); 
    width: 100%;
}
.filter-row:last-child { border-bottom: none; }

.filter-btn {
    flex: 1;
    width: 100%;
    padding: 12px 16px;
    border: none;
    background: none;
    color: var(--text-primary);
    font-size: 16px;
    text-align: left;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-right: 1px solid var(--border-color);
    min-height: 60px;
    transition: opacity 0.2s;
}

.filter-btn.disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.filter-btn:last-child { border-right: none; }

.filter-content {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 12px;
}

.filter-label {
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 4px;
    display: block;
}

.filter-value {
    font-size: 16px;
    font-weight: 500;
    display: block;
}

.filter-image {
    width: 32px;
    height: 32px;
    border-radius: 6px;
    object-fit: cover;
}

.chevron-icon {
    color: var(--text-secondary);
    margin-left: 8px;
    flex-shrink: 0;
}

/* =========== СОРТИРОВКА =========== */
.sort-btn {
    width: 100%;
    padding: 16px;
    background-color: var(--secondary-color);
    border: none;
    border-radius: 12px;
    color: var(--text-primary);
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.sort-icon { 
    margin-right: 8px; 
    color: var(--text-secondary); 
}

/* =========== КНОПКА ОБНОВЛЕНИЯ =========== */
.refresh-btn {
    width: 100%;
    padding: 14px 16px;
    background-color: var(--accent-color);
    border: none;
    border-radius: 12px;
    color: var(--text-primary);
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s;
    height: 48px;
    min-height: 48px;
    position: relative;
    overflow: hidden;
}

.refresh-btn:hover { 
    background-color: var(--accent-color);
    opacity: 0.9; 
}

.refresh-btn:active { 
    background-color: var(--accent-color);
    opacity: 0.8;
    transform: none !important;
}

.refresh-btn:disabled {
    opacity: 0.7;
    cursor: not-allowed;
}

.refresh-icon { 
    margin-right: 8px; 
    color: var(--text-primary);
    width: 22px;
    height: 22px;
    opacity: 0.95;
    display: block;
    flex-shrink: 0;
}

.refresh-btn span {
    display: inline-block;
    line-height: 1;
    font-size: 16px;
    font-weight: 600;
    transition: all 0.2s;
    min-width: 70px;
    text-align: center;
}

/* =========== СЕТКА ПОДАРКОВ =========== */
.nft-grid { 
    display: grid; 
    grid-template-columns: repeat(2, 1fr); 
    gap: 12px; 
    width: 100%;
}

.nft-card {
    background-color: var(--card-bg);
    border-radius: 12px;
    overflow: hidden;
    transition: all 0.3s ease;
    position: relative;
    opacity: 0;
    transform: translateY(10px);
}

.nft-card.visible {
    opacity: 1;
    transform: translateY(0);
    transition: opacity 0.4s ease, transform 0.4s ease;
}

.nft-card:hover { 
    transform: translateY(-4px);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
}

.nft-image {
    width: 100%;
    height: 180px;
    object-fit: cover;
    background-color: var(--secondary-color);
    transition: transform 0.3s ease;
}

.nft-card:hover .nft-image {
    transform: scale(1.03);
}

.nft-info { 
    padding: 12px; 
}

.nft-name {
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.nft-price {
    font-size: 16px;
    font-weight: 600;
    color: var(--accent-color);
}

.nft-price.unavailable {
    color: var(--text-secondary);
    font-size: 14px;
}

/* Модальные окна */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: var(--modal-bg);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.modal-sheet {
    background-color: var(--primary-color);
    border-radius: 12px;
    width: 90%;
    max-width: 400px;
    max-height: 80vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.modal-header {
    padding: 16px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-header h2 { font-size: 18px; font-weight: 600; }

.close-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 24px;
    cursor: pointer;
    padding: 0;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-search {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
}

.search-input {
    width: 100%;
    padding: 8px 12px;
    background-color: var(--secondary-color);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 16px;
}

.collection-list {
    flex: 1;
    overflow-y: auto;
    max-height: 400px;
}

.collection-item {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    transition: background-color 0.2s;
    display: flex;
    align-items: center;
    gap: 12px;
}

.collection-item:hover { background-color: var(--secondary-color); }
.collection-item.selected { background-color: rgba(0, 122, 255, 0.1); }

.collection-image {
    width: 32px;
    height: 32px;
    border-radius: 6px;
    object-fit: cover;
    flex-shrink: 0;
}

.collection-checkbox {
    width: 20px;
    height: 20px;
    border: 2px solid var(--border-color);
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.collection-checkbox.selected {
    background-color: var(--accent-color);
    border-color: var(--accent-color);
}

.collection-checkbox.selected::after {
    content: '✓';
    color: white;
    font-size: 14px;
    font-weight: bold;
}

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

.collection-name {
    font-size: 16px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.collection-details {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 2px;
}

.sort-list { padding: 8px 0; }

.sort-item {
    padding: 16px;
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    transition: background-color 0.2s;
}

.sort-item:hover { background-color: var(--secondary-color); }
.sort-item.selected { background-color: rgba(0, 122, 255, 0.1); }

.sort-name { font-size: 16px; }

.apply-btn {
    margin: 16px;
    padding: 14px;
    background-color: var(--accent-color);
    color: white;
    border: none;
    border-radius: 10px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    text-align: center;
}

.apply-btn:hover { opacity: 0.9; }

/* Утилиты */
.hidden { display: none !important; }
.loading { padding: 40px; text-align: center; color: var(--text-secondary); }
.error { padding: 40px; text-align: center; color: #ff3b30; }

.empty-state {
    padding: 60px 20px;
    text-align: center;
    color: var(--text-secondary);
    grid-column: 1 / -1;
    animation: fadeIn 0.5s ease-out;
}

.empty-state-icon {
    font-size: 48px;
    margin-bottom: 16px;
    opacity: 0.5;
}

.observer-target {
    height: 20px;
    width: 100%;
    grid-column: 1 / -1;
}

.pagination-info {
    text-align: center;
    padding: 10px;
    color: var(--text-secondary);
    font-size: 12px;
    grid-column: 1 / -1;
}

.market-badge {
    position: absolute;
    top: 8px;
    right: 8px;
    background: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 10px;
    font-weight: bold;
}

/* =========== АДАПТИВНЫЕ СТИЛИ =========== */
@media (max-width: 480px) {
    .top-section {
        padding: 12px;
    }
    
    .profile-container {
        top: 12px;
        right: 12px;
        padding: 6px 10px 6px 6px;
        max-width: 180px;
    }
    
    .profile-name {
        font-size: 13px;
        max-width: 70px;
    }
    
    .profile-balance {
        font-size: 14px;
    }
    
    .profile-photo {
        width: 32px;
        height: 32px;
    }
    
    .balance-currency {
        font-size: 12px;
    }
    
    .banner-container {
        margin-top: 60px;
    }
    
    .site-banner {
        max-height: 100px;
        border-radius: 12px;
    }
    
    .clear-filters-btn {
        padding: 9px 14px;
        font-size: 13px;
    }
    
    .clear-filters-icon {
        width: 14px;
        height: 14px;
    }
}

@media (max-width: 360px) {
    .profile-container {
        max-width: 160px;
    }
    
    .profile-name {
        max-width: 60px;
        font-size: 12px;
    }
    
    .profile-photo {
        width: 30px;
        height: 30px;
    }
    
    .balance-value {
        font-size: 13px;
    }
    
    .site-banner {
        max-height: 80px;
    }
    
    .clear-filters-btn {
        padding: 8px 12px;
        font-size: 12px;
    }
}

@media (min-width: 768px) {
    .main-container {
        padding-left: max(16px, calc((100% - var(--content-max-width)) / 2));
        padding-right: max(16px, calc((100% - var(--content-max-width)) / 2));
    }
    
    .container {
        padding-left: max(16px, calc((100% - var(--content-max-width)) / 2));
        padding-right: max(16px, calc((100% - var(--content-max-width)) / 2));
    }
    
    .nft-grid {
        gap: 16px;
    }
    
    .profile-container {
        top: 16px;
        right: 24px;
    }
    
    .banner-container {
        margin-top: 80px;
    }
    
    .site-banner {
        max-height: 160px;
    }
    
    .clear-filters-section {
        margin-bottom: 14px;
    }
    
    .clear-filters-btn {
        padding: 11px 18px;
        font-size: 15px;
    }
}

@media (min-width: 1024px) {
    :root {
        --content-max-width: 600px;
    }
    
    .nft-grid {
        gap: 16px;
    }
    
    .profile-container {
        max-width: 220px;
    }
    
    .profile-name {
        max-width: 100px;
    }
    
    .banner-container {
        margin-top: 90px;
    }
    
    .site-banner {
        max-height: 180px;
    }
}

/* =========== АНИМАЦИИ ДЛЯ КНОПОК =========== */
@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.refresh-btn.gifts-loading .refresh-icon {
    animation: spin 1s linear infinite;
    color: var(--text-primary);
}

.refresh-btn.gifts-loading {
    opacity: 0.9;
}

.refresh-btn.gifts-success .refresh-icon {
    color: #34c759 !important;
}

.refresh-btn.gifts-error .refresh-icon {
    color: #ff3b30 !important;
}

.profile-refresh-btn.balance-loading svg {
    animation: spin 1s linear infinite;
    color: var(--accent-color);
}

.profile-refresh-btn.balance-loading {
    opacity: 0.9;
    background: rgba(255, 255, 255, 0.1);
}

.profile-refresh-btn.balance-success svg {
    color: #34c759 !important;
}

.profile-refresh-btn.balance-error svg {
    color: #ff3b30 !important;
}

.refresh-btn span::before {
    content: none;
}

.refresh-btn.gifts-success::after,
.refresh-btn.gifts-error::after {
    content: none;
}

.profile-refresh-btn,
.profile-refresh-btn.balance-loading,
.profile-refresh-btn.balance-success,
.profile-refresh-btn.balance-error {
    width: 28px !important;
    height: 28px !important;
    min-width: 28px !important;
    min-height: 28px !important;
}

.refresh-btn,
.refresh-btn.gifts-loading,
.refresh-btn.gifts-success,
.refresh-btn.gifts-error {
    height: 48px !important;
    min-height: 48px !important;
    padding: 14px 16px !important;
}

.refresh-btn span {
    transition: opacity 0.2s;
}

/* =========== АНИМАЦИЯ ЗАГРУЗКИ ПОДАРКОВ =========== */
@keyframes pulse {
    0% { opacity: 0.5; transform: scale(0.95); }
    50% { opacity: 1; transform: scale(1); }
    100% { opacity: 0.5; transform: scale(0.95); }
}

@keyframes shimmer {
    0% { background-position: -200px 0; }
    100% { background-position: 200px 0; }
}

.loading-cards-container {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    width: 100%;
    animation: pulse 1.5s ease-in-out infinite;
}

.loading-card {
    background-color: var(--card-bg);
    border-radius: 12px;
    overflow: hidden;
    position: relative;
    height: 260px;
}

.loading-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(90deg, 
        var(--card-bg) 0%, 
        var(--secondary-color) 50%, 
        var(--card-bg) 100%);
    background-size: 200px 100%;
    animation: shimmer 1.5s infinite linear;
}

.loading-image {
    width: 100%;
    height: 180px;
    background-color: var(--secondary-color);
    position: relative;
    overflow: hidden;
}

.loading-image::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(90deg, 
        var(--secondary-color) 0%, 
        rgba(255, 255, 255, 0.1) 50%, 
        var(--secondary-color) 100%);
    background-size: 200px 100%;
    animation: shimmer 1.5s infinite linear;
}

.loading-info {
    padding: 12px;
    position: relative;
    overflow: hidden;
}

.loading-line {
    background-color: var(--secondary-color);
    border-radius: 4px;
    position: relative;
    overflow: hidden;
}

.loading-line::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(90deg, 
        var(--secondary-color) 0%, 
        rgba(255, 255, 255, 0.1) 50%, 
        var(--secondary-color) 100%);
    background-size: 200px 100%;
    animation: shimmer 1.5s infinite linear;
}

.profile-container:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.3);
}

.site-banner[src*="no_img"] {
    display: none;
}

.banner-container:empty {
    display: none;
}

.unauthorized-animation {
    width: 200px;
    height: 200px;
    margin: 0 auto 20px;
}

#sortModal .modal-sheet {
    max-height: 70vh;
    display: flex;
    flex-direction: column;
}

#sortModal .sort-list {
    flex: 1;
    overflow-y: auto;
    max-height: 400px;
    padding: 0;
}

#sortModal .apply-btn {
    margin: 16px;
    padding: 14px;
    background-color: var(--accent-color);
    color: white;
    border: none;
    border-radius: 10px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    text-align: center;
    display: block;
    width: calc(100% - 32px);
    flex-shrink: 0;
}

#sortModal .apply-btn:hover {
    opacity: 0.9;
}

#sortModal .apply-btn:active {
    transform: scale(0.98);
}

#sortModal .modal-sheet {
    max-height: 80vh;
}

#sortModal .modal-header {
    flex-shrink: 0;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}