/* ==================== Базовые стили ==================== */
:root {
    --bg-primary: #f5f5f7;
    --bg-secondary: #ffffff;
    --text-primary: #1c1c1e;
    --text-secondary: #8e8e93;
    --accent: #007aff;
    --accent-hover: #0051d5;
    --border: #e9e9ef;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
    --shadow-hover: 0 8px 24px rgba(0, 0, 0, 0.12);
    --vip-border: #ffd700;
    --vip-glow: rgba(255, 215, 0, 0.2);
}

[data-theme="dark"] {
    --bg-primary: #000000;
    --bg-secondary: #1c1c1e;
    --text-primary: #ffffff;
    --text-secondary: #8e8e93;
    --border: #2c2c2e;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    --shadow-hover: 0 8px 24px rgba(0, 0, 0, 0.5);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', Helvetica, Arial, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.4;
    transition: background 0.3s, color 0.3s;
}

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

/* ==================== Шапка ==================== */
.header {
    background: rgba(var(--bg-secondary-rgb, 255, 255, 255), 0.95);
    backdrop-filter: blur(10px);
    position: sticky;
    top: 0;
    z-index: 100;
    border-bottom: 1px solid var(--border);
    padding: 12px 0;
}

.header-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
}

.logo {
    font-size: 24px;
    font-weight: 600;
    background: linear-gradient(135deg, #007aff, #5856d6);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    text-decoration: none;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.city-selector {
    padding: 8px 16px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 20px;
    font-size: 14px;
    cursor: pointer;
    color: var(--text-primary);
}

.theme-toggle {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: var(--bg-secondary);
    cursor: pointer;
    font-size: 20px;
    transition: transform 0.2s;
}

.theme-toggle:hover {
    transform: scale(1.05);
}

.btn-add {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: var(--accent);
    color: white;
    font-size: 24px;
    cursor: pointer;
    transition: transform 0.2s;
}

.btn-add:hover {
    transform: scale(1.05);
}

/* ==================== Поиск ==================== */
.search-section {
    margin: 20px 0;
    position: relative;
}

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

.search-input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.1);
}

.search-suggestions {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 12px;
    margin-top: 8px;
    max-height: 300px;
    overflow-y: auto;
    z-index: 1000;
    display: none;
}

.search-suggestions.active {
    display: block;
}

.suggestion-item {
    padding: 12px 16px;
    cursor: pointer;
    transition: background 0.2s;
}

.suggestion-item:hover {
    background: var(--border);
}

/* ==================== Категории ==================== */
.categories-section {
    margin: 24px 0;
}

.categories-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 16px;
}

.categories-header h2 {
    font-size: 20px;
    font-weight: 600;
}

.link-btn {
    background: none;
    border: none;
    color: var(--accent);
    cursor: pointer;
    font-size: 14px;
}

.categories {
    display: flex;
    gap: 12px;
    overflow-x: auto;
    padding: 8px 0 16px;
    scrollbar-width: thin;
    -webkit-overflow-scrolling: touch;
}

.category {
    flex-shrink: 0;
    padding: 8px 20px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 30px;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
    color: var(--text-primary);
}

.category.active {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

/* ==================== Объявления ==================== */
.ads-section {
    margin: 24px 0;
}

.ads-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 16px;
    flex-wrap: wrap;
    gap: 12px;
}

.ads-header h2 {
    font-size: 20px;
    font-weight: 600;
}

.sort-buttons {
    display: flex;
    gap: 8px;
}

.sort-btn {
    padding: 6px 12px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 20px;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
    color: var(--text-primary);
}

.sort-btn.active {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

.ads-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
    margin: 20px 0;
}

@media (min-width: 768px) {
    .ads-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (min-width: 1024px) {
    .ads-grid {
        grid-template-columns: repeat(4, 1fr);
    }
}

/* Карточка объявления */
.ad-card {
    background: var(--bg-secondary);
    border-radius: 12px;
    overflow: hidden;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    box-shadow: var(--shadow);
    position: relative;
}

.ad-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-hover);
}

.ad-card.vip {
    border: 2px solid var(--vip-border);
}

.ad-card.pinned::before {
    content: '📌';
    position: absolute;
    top: 8px;
    right: 8px;
    background: rgba(0, 0, 0, 0.6);
    color: white;
    padding: 4px 8px;
    border-radius: 20px;
    font-size: 12px;
    z-index: 1;
}

.ad-image {
    width: 100%;
    aspect-ratio: 1;
    object-fit: cover;
    background: var(--border);
}

.ad-info {
    padding: 12px;
}

.ad-title {
    font-weight: 600;
    font-size: 16px;
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ad-price {
    font-weight: 700;
    color: var(--accent);
    margin: 4px 0;
    font-size: 18px;
}

.ad-location {
    font-size: 12px;
    color: var(--text-secondary);
}

.ad-date {
    font-size: 11px;
    color: var(--text-secondary);
    margin-top: 4px;
}

/* Скелетоны загрузки */
.skeleton-card {
    background: var(--bg-secondary);
    border-radius: 12px;
    overflow: hidden;
    animation: pulse 1.5s ease-in-out infinite;
}

.skeleton-card::before {
    content: '';
    display: block;
    padding-top: 100%;
    background: linear-gradient(90deg, var(--border) 25%, var(--bg-primary) 50%, var(--border) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

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

.load-more-btn {
    width: 100%;
    padding: 12px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 12px;
    cursor: pointer;
    margin: 20px 0;
    color: var(--text-primary);
}

.loading-indicator {
    text-align: center;
    padding: 20px;
    color: var(--text-secondary);
}

/* ==================== История просмотров ==================== */
.history-section {
    margin: 32px 0;
    padding-top: 24px;
    border-top: 1px solid var(--border);
}

.history-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 16px;
}

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

.clear-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 13px;
}

.history-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    overflow-x: auto;
}

.history-card {
    min-width: 120px;
    background: var(--bg-secondary);
    border-radius: 8px;
    overflow: hidden;
    cursor: pointer;
}

.history-card img {
    width: 100%;
    aspect-ratio: 1;
    object-fit: cover;
}

.history-card .title {
    padding: 8px;
    font-size: 12px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ==================== Модальные окна ==================== */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(4px);
}

.modal.active {
    display: flex;
}

.modal-content {
    background: var(--bg-secondary);
    border-radius: 20px;
    max-width: 90vw;
    max-height: 90vh;
    overflow-y: auto;
    position: relative;
    padding: 24px;
    width: 500px;
}

.modal-large {
    width: 800px;
    max-width: 95vw;
}

.modal-chat {
    width: 600px;
    max-width: 95vw;
    padding: 0;
}

.modal-close {
    position: absolute;
    top: 16px;
    right: 16px;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.5);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 10;
}

/* ==================== Формы ==================== */
.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 16px;
}

.form-group textarea {
    resize: vertical;
    min-height: 100px;
}

.photo-preview {
    display: flex;
    gap: 8px;
    margin-top: 12px;
    flex-wrap: wrap;
}

.photo-preview img {
    width: 80px;
    height: 80px;
    object-fit: cover;
    border-radius: 8px;
}

.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    margin-top: 24px;
}

/* ==================== Кнопки ==================== */
.btn-primary {
    padding: 12px 24px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
}

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

.btn-secondary {
    padding: 12px 24px;
    background: var(--bg-primary);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-radius: 12px;
    font-size: 16px;
    cursor: pointer;
}

/* ==================== Чат ==================== */
.chat-header {
    padding: 16px;
    border-bottom: 1px solid var(--border);
    position: relative;
}

.chat-header h3 {
    font-size: 18px;
    margin: 0;
}

.chat-container {
    display: flex;
    flex-direction: column;
    height: 500px;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.message {
    display: flex;
    flex-direction: column;
}

.message.sent {
    align-items: flex-end;
}

.message.received {
    align-items: flex-start;
}

.message-bubble {
    max-width: 70%;
    padding: 10px 14px;
    border-radius: 20px;
    word-wrap: break-word;
    position: relative;
}

.message.sent .message-bubble {
    background: var(--accent);
    color: white;
}

.message.received .message-bubble {
    background: var(--border);
    color: var(--text-primary);
}

.message-time {
    font-size: 10px;
    color: var(--text-secondary);
    margin-top: 4px;
    margin-left: 8px;
    margin-right: 8px;
}

.message-status {
    font-size: 10px;
    margin-left: 8px;
}

.chat-input-area {
    display: flex;
    padding: 12px;
    border-top: 1px solid var(--border);
    gap: 8px;
}

.chat-input-area input {
    flex: 1;
    padding: 10px 16px;
    border: 1px solid var(--border);
    border-radius: 24px;
    background: var(--bg-primary);
    color: var(--text-primary);
}

.chat-input-area button {
    padding: 8px 20px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 24px;
    cursor: pointer;
}

.chat-file-btn {
    background: var(--border);
    border: none;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    cursor: pointer;
    font-size: 20px;
}

/* ==================== Уведомления ==================== */
.notification {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--bg-secondary);
    color: var(--text-primary);
    padding: 12px 24px;
    border-radius: 40px;
    box-shadow: var(--shadow-hover);
    z-index: 1100;
    transition: transform 0.3s;
    white-space: nowrap;
}

.notification.show {
    transform: translateX(-50%) translateY(0);
}

/* ==================== Адаптив ==================== */
@media (max-width: 768px) {
    .container {
        padding: 0 12px;
    }
    
    .modal-content {
        padding: 20px;
    }
    
    .history-grid {
        grid-template-columns: repeat(3, 1fr);
    }
    
    .notification {
        font-size: 14px;
        padding: 10px 20px;
        white-space: normal;
        max-width: 90vw;
        text-align: center;
    }
}

@media (max-width: 480px) {
    .ads-header {
        flex-direction: column;
    }
    
    .sort-buttons {
        width: 100%;
        justify-content: space-between;
    }
    
    .sort-btn {
        flex: 1;
        text-align: center;
    }
}
/* Добавь в конец файла style.css */

/* Категории - исправление */
.categories {
    display: flex;
    gap: 12px;
    overflow-x: auto;
    padding: 8px 0 16px;
    scrollbar-width: thin;
    -webkit-overflow-scrolling: touch;
    scroll-snap-type: x mandatory;
}

.category {
    flex-shrink: 0;
    padding: 8px 20px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 30px;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
    color: var(--text-primary);
    scroll-snap-align: start;
}

.category:hover {
    background: var(--accent);
    color: white;
    transform: scale(1.02);
}

.category.active {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

/* Пустой результат */
.no-results {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-secondary);
    font-size: 16px;
    grid-column: 1 / -1;
}

/* Анимация загрузки */
@keyframes shimmer {
    0% { background-position: -200% 0; }
    100% { background-position: 200% 0; }
}

/* Модальное окно - дополнительные стили */
.modal-price {
    font-size: 28px;
    font-weight: 700;
    color: var(--accent);
    margin: 12px 0;
}

.modal-location {
    color: var(--text-secondary);
    margin: 8px 0;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
}

.modal-description {
    margin: 16px 0;
    line-height: 1.5;
    white-space: pre-wrap;
}

.modal-actions {
    display: flex;
    gap: 12px;
    margin-top: 24px;
    flex-wrap: wrap;
}

/* Улучшенные кнопки сортировки */
.sort-buttons {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.sort-btn {
    padding: 6px 12px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 20px;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
    color: var(--text-primary);
}

.sort-btn.active {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

/* Уведомления */
.notification {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--bg-secondary);
    color: var(--text-primary);
    padding: 12px 24px;
    border-radius: 40px;
    box-shadow: var(--shadow-hover);
    z-index: 1100;
    transition: transform 0.3s;
    white-space: nowrap;
    font-size: 14px;
    font-weight: 500;
}

.notification.show {
    transform: translateX(-50%) translateY(0);
}

/* Для мобильных */
@media (max-width: 480px) {
    .notification {
        font-size: 12px;
        padding: 10px 20px;
        white-space: normal;
        max-width: 90vw;
        text-align: center;
    }
    
    .modal-actions {
        flex-direction: column;
    }
    
    .modal-actions button {
        width: 100%;
    }
}