/* ==========================================================================
   1. ПЕРЕМЕННЫЕ И БАЗОВЫЕ НАСТРОЙКИ
   ========================================================================== */
:root {
    --bg-primary: #0f1115;
    --bg-secondary: #1a1d24;
    --bg-card: #1e222b;
    --bg-hover: #252a35;
    --border: #2a2f3a;
    --text-primary: #e4e6eb;
    --text-secondary: #8b92a5;
    --text-muted: #5a6175;
    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --accent-soft: rgba(59, 130, 246, 0.15);
    --success: #10b981;
    --warn: #f59e0b;
    --danger: #ef4444;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    /* Учет челки iPhone */
    padding-top: env(safe-area-inset-top);
}

a {
    color: var(--accent);
    text-decoration: none;
    transition: color 0.2s;
}
a:hover {
    color: var(--accent-hover);
}

/* ==========================================================================
   2. КОНТЕЙНЕР И ШАПКА (АДАПТИВНАЯ)
   ========================================================================== */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
}

.navbar {
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    padding: 16px 0;
    position: sticky;
    top: 0;
    z-index: 1000;
    backdrop-filter: blur(10px);
    /* Учет челки iPhone для липкой шапки */
    padding-top: calc(16px + env(safe-area-inset-top));
}

.navbar-container {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    position: relative;
}

.logo {
    font-size: 22px;
    font-weight: 700;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
    z-index: 1002;
}

.logo-dot {
    width: 10px;
    height: 10px;
    background: var(--accent);
    border-radius: 50%;
    box-shadow: 0 0 12px var(--accent);
}

/* Десктопная навигация */
.nav-links {
    display: flex;
    gap: 8px;
    align-items: center;
}

.nav-links a {
    color: var(--text-secondary);
    padding: 8px 14px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s;
    white-space: nowrap;
}

.nav-links a:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.nav-verify {
    color: var(--warn) !important;
}

.nav-logout {
    margin-left: 8px;
}

/* Бургер-кнопка (скрыта на десктопе) */
.burger-menu {
    display: none;
    flex-direction: column;
    justify-content: space-between;
    width: 32px;
    height: 24px;
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 0;
    z-index: 1002;
    flex-shrink: 0;
}

.burger-menu span {
    display: block;
    width: 100%;
    height: 3px;
    background: var(--text-primary);
    border-radius: 2px;
    transition: all 0.3s ease;
    transform-origin: center;
}

/* Анимация бургера в крестик */
.burger-menu.active span:nth-child(1) {
    transform: translateY(10.5px) rotate(45deg);
}
.burger-menu.active span:nth-child(2) {
    opacity: 0;
    transform: scaleX(0);
}
.burger-menu.active span:nth-child(3) {
    transform: translateY(-10.5px) rotate(-45deg);
}

/* Оверлей (затемнение фона) */
.nav-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    z-index: 998;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.nav-overlay.active {
    display: block;
    opacity: 1;
}

/* ==========================================================================
   3. МОБИЛЬНАЯ АДАПТАЦИЯ НАВБАРА
   ========================================================================== */
@media (max-width: 768px) {
    .navbar {
        padding: 12px 0;
    }

    .logo {
        font-size: 18px;
    }

    .logo-dot {
        width: 8px;
        height: 8px;
    }

    .burger-menu {
        display: flex;
    }

    .nav-links {
        position: fixed;
        top: 0;
        right: -100%;
        width: 75%;
        max-width: 320px;
        height: 100vh;
        height: 100dvh; /* Динамическая высота для мобильных браузеров */
        background: var(--bg-secondary);
        border-left: 1px solid var(--border);
        flex-direction: column;
        align-items: stretch;
        justify-content: flex-start;
        padding: calc(80px + env(safe-area-inset-top)) 24px calc(24px + env(safe-area-inset-bottom));
        gap: 4px;
        transition: right 0.3s ease;
        z-index: 999;
        overflow-y: auto;
        box-shadow: -4px 0 20px rgba(0, 0, 0, 0.3);
    }

    .nav-links.active {
        right: 0;
    }

    .nav-links a {
        padding: 14px 16px;
        font-size: 16px;
        border-radius: var(--radius-sm);
        text-align: left;
    }

    .nav-links a:hover {
        background: var(--bg-hover);
    }

    .nav-links .btn {
        margin-top: 12px;
        text-align: center;
        justify-content: center;
    }

    .nav-logout {
        margin-left: 0;
        margin-top: 16px;
        border-top: 1px solid var(--border);
        padding-top: 16px;
    }
}

@media (max-width: 380px) {
    .logo { font-size: 16px; }
    .nav-links { width: 85%; }
}

/* ==========================================================================
   4. КНОПКИ
   ========================================================================== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 18px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 600;
    border: none;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
    white-space: nowrap;
}

.btn-primary {
    background: var(--accent);
    color: white;
}
.btn-primary:hover {
    background: var(--accent-hover);
    color: white;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}

.btn-secondary {
    background: var(--bg-hover);
    color: var(--text-primary);
    border: 1px solid var(--border);
}
.btn-secondary:hover {
    background: var(--border);
    color: var(--text-primary);
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
}
.btn-ghost:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.btn-sm { padding: 6px 12px; font-size: 13px; }

/* ==========================================================================
   5. КАРТОЧКИ И СЕТКА
   ========================================================================== */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    transition: all 0.2s;
}

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

.card-title {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text-primary);
}

.card-meta {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 12px;
}

.avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--accent-soft);
    color: var(--accent);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    overflow: hidden;
    flex-shrink: 0;
}

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

.avatar-lg {
    width: 96px;
    height: 96px;
    font-size: 36px;
}

.grid {
    display: grid;
    gap: 20px;
}

.grid-cards {
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
}

/* ==========================================================================
   6. ФОРМЫ (КОНСОЛИДИРОВАННЫЕ)
   ========================================================================== */
.form-group {
    margin-bottom: 18px;
}

.form-label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.form-control, .form-select, textarea.form-control {
    width: 100%;
    padding: 12px 16px;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 14px;
    font-family: inherit;
    transition: all 0.2s;
    -webkit-appearance: none;
    appearance: none;
}

.form-control:focus, .form-select:focus, textarea.form-control:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
    background: var(--bg-secondary);
}

.form-control::placeholder {
    color: var(--text-muted);
}

/* Кастомная стрелка для select */
.form-select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%238b92a5' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10l-5 5z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 40px;
}

/* Textarea */
.form-textarea {
    min-height: 120px;
    resize: vertical;
    line-height: 1.6;
}

/* File input */
input[type="file"].form-control {
    padding: 10px;
    cursor: pointer;
}

input[type="file"].form-control::file-selector-button {
    background: var(--bg-hover);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    padding: 6px 12px;
    margin-right: 12px;
    cursor: pointer;
    transition: all 0.2s;
}

input[type="file"].form-control::file-selector-button:hover {
    background: var(--border);
}

/* ИСПРАВЛЕНИЕ: Множественный выбор (Категории) */
select[multiple].form-control {
    min-height: 150px;
    padding: 8px;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    overflow-y: auto;
}

select[multiple].form-control option {
    padding: 10px 12px;
    background: var(--bg-primary);
    color: var(--text-primary);
    border-radius: 4px;
    margin: 2px 0;
    transition: all 0.2s;
    cursor: pointer;
}

select[multiple].form-control option:hover {
    background: var(--accent-soft);
    color: var(--accent);
}

select[multiple].form-control option:checked {
    background: var(--accent);
    color: white;
    font-weight: 500;
}

select[multiple].form-control + .text-muted {
    margin-top: 6px;
    font-size: 12px;
}

/* ==========================================================================
   7. КРОППЕР ИЗОБРАЖЕНИЙ
   ========================================================================== */
.image-upload-container {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
}

#cropContainer {
    background: var(--bg-primary);
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 20px;
    margin-top: 16px;
}

#cropContainer img {
    max-width: 100%;
    display: block;
    margin: 0 auto;
}

.cropper-container {
    background: var(--bg-primary) !important;
}

.cropper-view-box {
    outline: 2px solid var(--accent) !important;
    outline-offset: -2px;
}

.cropper-line {
    background: var(--accent) !important;
}

.cropper-point {
    background: var(--accent) !important;
    width: 10px !important;
    height: 10px !important;
    border-radius: 50%;
}

/* ==========================================================================
   8. БЕЙДЖИ, ГЕРОЙ, ПОИСК, ФИЛЬТРЫ
   ========================================================================== */
.badge {
    display: inline-block;
    padding: 4px 10px;
    background: var(--accent-soft);
    color: var(--accent);
    border-radius: 20px;
    font-size: 12px;
    font-weight: 500;
}

.badge-muted {
    background: var(--bg-hover);
    color: var(--text-secondary);
}

.hero {
    padding: 60px 0 40px;
    text-align: center;
}

.hero h1 {
    font-size: 42px;
    font-weight: 800;
    margin-bottom: 12px;
    background: linear-gradient(135deg, var(--text-primary) 0%, var(--accent) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.hero p {
    font-size: 18px;
    color: var(--text-secondary);
    max-width: 600px;
    margin: 0 auto;
}

.search-bar {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 24px;
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    align-items: center;
}

.search-bar input, .search-bar select {
    flex: 1;
    min-width: 180px;
}

.filters {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 20px;
}

.filter-chip {
    padding: 6px 14px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 20px;
    color: var(--text-secondary);
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
}

.filter-chip:hover, .filter-chip.active {
    background: var(--accent-soft);
    border-color: var(--accent);
    color: var(--accent);
}

/* ==========================================================================
   9. ПРОФИЛЬ И УТИЛИТЫ
   ========================================================================== */
.profile-header {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 32px;
    margin-bottom: 24px;
    display: flex;
    gap: 24px;
    align-items: center;
    flex-wrap: wrap;
}

.profile-info { flex: 1; min-width: 250px; }
.profile-info h1 { font-size: 28px; margin-bottom: 4px; }
.profile-info .handle { color: var(--text-secondary); margin-bottom: 12px; }
.profile-info .bio { color: var(--text-secondary); margin-bottom: 16px; }

.stats {
    display: flex;
    gap: 24px;
    flex-wrap: wrap;
}

.stat-item .stat-value {
    font-size: 22px;
    font-weight: 700;
    color: var(--accent);
}

.stat-item .stat-label {
    font-size: 12px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.text-muted { color: var(--text-muted); }
.text-secondary { color: var(--text-secondary); }
.text-accent { color: var(--accent); }
.text-warn { color: var(--warn); }
.text-success { color: var(--success); }
.mt-2 { margin-top: 8px; }
.mt-4 { margin-top: 16px; }
.mt-6 { margin-top: 24px; }
.mb-4 { margin-bottom: 16px; }
.mb-6 { margin-bottom: 24px; }
.flex { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }

/* ==========================================================================
   10. ПАГИНАЦИЯ, СООБЩЕНИЯ, HTMX
   ========================================================================== */
.pagination {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin-top: 32px;
}

.pagination a, .pagination span {
    padding: 8px 14px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 14px;
}

.pagination a:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.pagination .current {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
}

.messages {
    margin-bottom: 20px;
}

.message {
    padding: 12px 16px;
    background: var(--accent-soft);
    border-left: 3px solid var(--accent);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    margin-bottom: 8px;
}

.htmx-indicator {
    display: none;
    color: var(--text-muted);
    font-size: 13px;
}
.htmx-request .htmx-indicator { display: inline; }
.htmx-request.htmx-indicator { display: inline; }

/* ==========================================================================
   11. ФИНАЛЬНАЯ АДАПТАЦИЯ (ОБЩИЕ МОБИЛЬНЫЕ ПРАВИЛА)
   ========================================================================== */
@media (max-width: 640px) {
    .hero h1 { font-size: 32px; }
    .hero p { font-size: 16px; }

    .profile-header {
        flex-direction: column;
        text-align: center;
        padding: 24px 16px;
    }
    .stats { justify-content: center; }

    .search-bar {
        flex-direction: column;
        align-items: stretch;
    }
    .search-bar input, .search-bar select {
        min-width: 100%;
    }

    .form-control, .form-select {
        padding: 10px 12px;
        font-size: 16px; /* 16px предотвращает зум инпута на iOS */
    }

    .image-upload-container {
        flex-direction: column;
        align-items: flex-start;
    }
}

/* === ВСПЛЫВАЮЩЕЕ УВЕДОМЛЕНИЕ (TOAST) === */
.toast-notification {
    position: fixed;
    bottom: 24px;
    right: 24px;
    background: var(--bg-card);
    border: 1px solid var(--success);
    color: var(--text-primary);
    padding: 16px 24px;
    border-radius: var(--radius);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    gap: 12px;
    z-index: 9999;
    transform: translateY(150%);
    opacity: 0;
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    max-width: 400px;
}

.toast-notification.show {
    transform: translateY(0);
    opacity: 1;
}

.toast-icon {
    font-size: 24px;
    flex-shrink: 0;
}

.toast-content {
    display: flex;
    flex-direction: column;
}

.toast-title {
    font-weight: 600;
    font-size: 14px;
    color: var(--success);
}

.toast-message {
    font-size: 13px;
    color: var(--text-secondary);
    margin-top: 2px;
}

/* Учет безопасной зоны для iPhone */
@media (max-width: 640px) {
    .toast-notification {
        bottom: calc(24px + env(safe-area-inset-bottom));
        right: 16px;
        left: 16px;
        max-width: none;
    }
}

/* Плавное появление сообщения об успешном отклике */
.response-success {
    transition: all 0.3s ease;
    opacity: 0;
    transform: translateY(10px);
}

.response-success.show {
    opacity: 1;
    transform: translateY(0);
}

/* Плавное исчезновение формы при отправке */
.response-form {
    transition: all 0.3s ease;
}

.response-form.hidden {
    opacity: 0;
    transform: translateY(-10px);
    height: 0;
    overflow: hidden;
    margin: 0 !important;
    padding: 0 !important;
}