/* ═══════════════════════════════════════════════════
СБРОС И БАЗА
═══════════════════════════════════════════════════ */
* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    font-size: 15px;
    color: #222;
    background: #f5f6f8;
    line-height: 1.5;
}

a { color: #2563eb; text-decoration: none; }
a:hover { color: #1d4ed8; text-decoration: underline; }

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

/* ═══════════════════════════════════════════════════
ШАПКА
═══════════════════════════════════════════════════ */
.board-header {
    background: #fff;
    border-bottom: 1px solid #e5e7eb;
    padding: 14px 0;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.board-header .container {
    display: flex;
    align-items: center;
    gap: 20px;
}
.logo {
    font-size: 20px;
    font-weight: 700;
    color: #111;
    white-space: nowrap;
}
.logo:hover { text-decoration: none; color: #111; }

.search-form {
    flex: 1;
    display: flex;
    gap: 8px;
}
.search-input {
    flex: 1;
    padding: 10px 14px;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    font-size: 14px;
    outline: none;
    transition: border-color .2s;
}
.search-input:focus { border-color: #2563eb; }

/* ═══════════════════════════════════════════════════
КНОПКИ
═══════════════════════════════════════════════════ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 9px 18px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background .2s, opacity .2s;
    white-space: nowrap;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: #2563eb; color: #fff; }
.btn-primary:hover { background: #1d4ed8; color: #fff; }
.btn-outline { background: transparent; border: 1px solid #d1d5db; color: #444; }
.btn-outline:hover { background: #f3f4f6; }
.btn-search { background: #2563eb; color: #fff; }
.btn-search:hover { background: #1d4ed8; }
.btn-large { padding: 14px 32px; font-size: 16px; width: 100%; }

/* ═══════════════════════════════════════════════════
ЛАЙАУТ ГЛАВНОЙ
═══════════════════════════════════════════════════ */
.main-layout {
    display: flex;
    gap: 24px;
    padding-top: 24px;
    padding-bottom: 40px;
}
.sidebar {
    width: 240px;
    flex-shrink: 0;
    background: #fff;
    border-radius: 12px;
    padding: 16px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
    align-self: flex-start;
    position: sticky;
    top: 80px;
}
.sidebar-title {
    font-size: 14px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #6b7280;
    margin-bottom: 12px;
}
.content { flex: 1; min-width: 0; }

.content-header {
    display: flex;
    align-items: baseline;
    gap: 12px;
    margin-bottom: 20px;
}
.content-header h1 { font-size: 24px; }
.ads-count { color: #6b7280; font-size: 14px; }

/* ═══════════════════════════════════════════════════
ДЕРЕВО КАТЕГОРИЙ (АККОРДЕОН)
═══════════════════════════════════════════════════ */
.cat-tree {
    list-style: none;
    padding-left: 0;
}
.cat-tree ul {
    list-style: none;
    padding-left: 16px;
    margin-top: 2px;
    display: none;
}
.cat-item { margin: 2px 0; }
.cat-item a {
    display: block;
    padding: 6px 26px 6px 10px;
    border-radius: 6px;
    color: #444;
    font-size: 14px;
    transition: background .15s;
    position: relative;
}
.cat-item a:hover { background: #f3f4f6; text-decoration: none; }
.cat-item.active > a { background: #dbeafe; color: #1d4ed8; font-weight: 600; }

/* Стрелка для категорий с подкатегориями */
.cat-item.has-children > a::after {
    content: '▶';
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 9px;
    color: #9ca3af;
    transition: transform .2s;
    pointer-events: none;
}
.cat-item.has-children.open > a::after {
    transform: translateY(-50%) rotate(90deg);
}

/* Раскрытие вложенного списка */
.cat-item.has-children.open > ul {
    display: block;
}

/* ═══════════════════════════════════════════════════
СЕТКА ОБЪЯВЛЕНИЙ
═══════════════════════════════════════════════════ */
.ads-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 16px;
}
.ad-card {
    background: #fff;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
    transition: box-shadow .2s, transform .2s;
    display: block;
    color: inherit;
}
.ad-card:hover {
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    transform: translateY(-2px);
    text-decoration: none;
}
.ad-card-image {
    width: 100%;
    aspect-ratio: 4/3;
    overflow: hidden;
    background: #f3f4f6;
}
.ad-card-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.no-photo {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 40px;
    color: #d1d5db;
    background: #f9fafb;
}
.ad-card-body { padding: 12px 14px; }
.ad-card-price {
    font-size: 18px;
    font-weight: 700;
    color: #111;
    margin-bottom: 4px;
}
.ad-card-title {
    font-size: 14px;
    color: #374151;
    margin-bottom: 8px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.ad-card-meta {
    display: flex;
    justify-content: space-between;
    font-size: 12px;
    color: #9ca3af;
}

/* ═══════════════════════════════════════════════════
ПУСТОЕ СОСТОЯНИЕ
═══════════════════════════════════════════════════ */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    background: #fff;
    border-radius: 12px;
}
.empty-state p { font-size: 18px; color: #6b7280; margin-bottom: 20px; }

/* ═══════════════════════════════════════════════════
ПАГИНАЦИЯ
═══════════════════════════════════════════════════ */
.pagination {
    display: flex;
    gap: 6px;
    justify-content: center;
    margin-top: 28px;
}
.pagination a, .pagination span {
    padding: 8px 14px;
    border-radius: 8px;
    border: 1px solid #d1d5db;
    font-size: 14px;
    color: #444;
}
.pagination a:hover { background: #f3f4f6; text-decoration: none; }
.pagination .page-current {
    background: #2563eb;
    color: #fff;
    border-color: #2563eb;
    font-weight: 600;
}

/* ═══════════════════════════════════════════════════
СТРАНИЦА ОБЪЯВЛЕНИЯ
═══════════════════════════════════════════════════ */
.breadcrumb {
    display: flex;
    gap: 8px;
    align-items: center;
    padding: 16px 0;
    font-size: 14px;
    color: #6b7280;
}
.breadcrumb a { color: #2563eb; }
.breadcrumb span { color: #d1d5db; }

.ad-detail {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 32px;
    background: #fff;
    border-radius: 12px;
    padding: 24px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
    margin-bottom: 24px;
}
.gallery-main {
    width: 100%;
    aspect-ratio: 4/3;
    border-radius: 8px;
    overflow: hidden;
    background: #f3f4f6;
    margin-bottom: 12px;
}
.gallery-main img { width: 100%; height: 100%; object-fit: cover; }
.gallery-thumbs {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}
.gallery-thumb {
    width: 64px;
    height: 64px;
    object-fit: cover;
    border-radius: 6px;
    cursor: pointer;
    border: 2px solid transparent;
    transition: border-color .2s;
}
.gallery-thumb:hover { border-color: #2563eb; }
.no-photo-large {
    width: 100%;
    aspect-ratio: 4/3;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    color: #d1d5db;
    background: #f9fafb;
    border-radius: 8px;
}

.ad-info h1 { font-size: 22px; margin-bottom: 12px; }
.ad-price-big {
    font-size: 28px;
    font-weight: 800;
    color: #111;
    margin-bottom: 8px;
}
.ad-date { font-size: 13px; color: #9ca3af; margin-bottom: 20px; }
.ad-description { border-top: 1px solid #f3f4f6; padding-top: 16px; }
.ad-description h3 { font-size: 16px; margin-bottom: 10px; }
.ad-description p { color: #444; line-height: 1.7; }

/* Детальные поля */
.ad-fields {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 40px;
}
.field-group {
    background: #fff;
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.field-group h3 {
    font-size: 16px;
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid #f3f4f6;
}
.field-table { width: 100%; border-collapse: collapse; }
.field-table td { padding: 7px 0; font-size: 14px; border-bottom: 1px solid #f9fafb; }
.field-label { color: #6b7280; width: 50%; }
.field-value { color: #111; font-weight: 500; }

/* ═══════════════════════════════════════════════════
ФОРМА СОЗДАНИЯ
═══════════════════════════════════════════════════ */
.ad-form {
    max-width: 760px;
    margin: 0 auto 40px;
}
.form-section {
    background: #fff;
    border-radius: 12px;
    padding: 24px;
    margin-bottom: 20px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.form-section h3 {
    font-size: 18px;
    margin-bottom: 16px;
    padding-bottom: 8px;
    border-bottom: 1px solid #f3f4f6;
}
.form-row { margin-bottom: 16px; }
.form-row label {
    display: block;
    font-size: 14px;
    font-weight: 500;
    color: #374151;
    margin-bottom: 6px;
}
.req { color: #ef4444; }
.form-input, .form-select, .form-textarea {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    font-size: 14px;
    font-family: inherit;
    outline: none;
    transition: border-color .2s;
}
.form-input:focus, .form-select:focus, .form-textarea:focus { border-color: #2563eb; }
.form-textarea { resize: vertical; }
.form-select { cursor: pointer; }

.category-selectors .form-row { margin-bottom: 12px; }

/* Чекбоксы в форме */
.form-checkbox-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}
.form-checkbox-row input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
}
.form-checkbox-row label { margin-bottom: 0; cursor: pointer; }

/* Динамические поля */
#dynamic-fields .form-section {
    display: none;
}
#dynamic-fields .form-section.visible {
    display: block;
}

/* Загрузка фото */
.photo-upload-area {
    border: 2px dashed #d1d5db;
    border-radius: 12px;
    padding: 32px;
    text-align: center;
    cursor: pointer;
    transition: border-color .2s, background .2s;
}
.photo-upload-area:hover, .photo-upload-area.dragover {
    border-color: #2563eb;
    background: #f0f7ff;
}
.photo-upload-hint { font-size: 15px; color: #6b7280; }
.photo-upload-hint span { display: block; }

.photo-preview-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 16px;
}
.photo-preview {
    position: relative;
    width: 100px;
    height: 100px;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}
.photo-preview img { width: 100%; height: 100%; object-fit: cover; }
.photo-preview .remove-btn {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 22px;
    height: 22px;
    background: rgba(0,0,0,0.6);
    color: #fff;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}
.photo-preview .remove-btn:hover { background: rgba(239,68,68,0.9); }
.photo-preview .main-badge {
    position: absolute;
    bottom: 4px;
    left: 4px;
    background: #2563eb;
    color: #fff;
    font-size: 10px;
    padding: 2px 6px;
    border-radius: 4px;
}

.form-actions { text-align: center; }

/* ═══════════════════════════════════════════════════
ФУТЕР
═══════════════════════════════════════════════════ */
.board-footer {
    background: #fff;
    border-top: 1px solid #e5e7eb;
    padding: 20px 0;
    text-align: center;
    color: #9ca3af;
    font-size: 14px;
}

/* ═══════════════════════════════════════════════════
АДАПТИВ
═══════════════════════════════════════════════════ */
@media (max-width: 900px) {
    .main-layout { flex-direction: column; }
    .sidebar { width: 100%; position: static; }
    .ad-detail { grid-template-columns: 1fr; gap: 20px; }
    .ad-fields { grid-template-columns: 1fr; }
}
@media (max-width: 600px) {
    .board-header .container { flex-wrap: wrap; }
    .search-form { order: 3; width: 100%; flex-basis: 100%; }
    .ads-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
}
@media (max-width: 420px) {
    .ads-grid { grid-template-columns: 1fr; }
}
.user-block {
    display: flex;
    align-items: center;
    gap: 8px;
    white-space: nowrap;
}
.user-login {
    font-size: 14px;
    font-weight: 600;
    color: #374151;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}
.admin-badge {
    background: #f59e0b;
    color: #fff;
    font-size: 10px;
    padding: 1px 6px;
    border-radius: 4px;
    font-weight: 700;
    text-transform: uppercase;
}
.btn-sm {
    padding: 6px 12px;
    font-size: 13px;
}
/* ═══════════════════════════════════════════════════
ЛАЙТБОКС — ГАЛЕРЕЯ
═══════════════════════════════════════════════════ */
.lightbox {
    display: none;
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.92);
    z-index: 9999;
    justify-content: center;
    align-items: center;
}
.lightbox.open {
    display: flex;
}
.lightbox-img {
    max-width: 90vw;
    max-height: 85vh;
    object-fit: contain;
    border-radius: 4px;
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.6);
}
.lightbox-close {
    position: absolute;
    top: 16px; right: 24px;
    background: none;
    border: none;
    color: #fff;
    font-size: 40px;
    cursor: pointer;
    line-height: 1;
    padding: 0;
    opacity: 0.7;
    transition: opacity 0.2s;
    z-index: 1;
}
.lightbox-close:hover { opacity: 1; }
.lightbox-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: #fff;
    font-size: 48px;
    cursor: pointer;
    padding: 0 16px;
    opacity: 0.6;
    transition: opacity 0.2s;
    z-index: 1;
    line-height: 1;
}
.lightbox-nav:hover { opacity: 1; }
.lightbox-prev { left: 0; }
.lightbox-next { right: 0; }
.lightbox-counter {
    position: absolute;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    color: #fff;
    font-size: 14px;
    opacity: 0.7;
}

/* ═══════════════════════════════════════════════════
ГАЛЕРЕЯ — КУРСОР И МИНИАТЮРЫ
═══════════════════════════════════════════════════ */
.gallery-main {
    cursor: pointer;
}
.gallery-thumb {
    cursor: pointer;
    transition: opacity 0.2s, border-color 0.2s;
    border: 2px solid transparent;
}
.gallery-thumb:hover {
    opacity: 0.8;
    border-color: #2563eb;
}
.preview-loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 24px;
    color: #9ca3af;
}
