/* === Telegram Theme Variables === */
/* Logo cursor fix */
.logo-with-icon, .logo {
    user-select: none;
    cursor: default;
}

:root {
    --tg-theme-bg-color: #f4f4f9;
    --tg-theme-text-color: #333;
    --tg-theme-button-color: #007bff;
    --tg-theme-button-text-color: #fff;
    --tg-theme-secondary-bg-color: #fff;
    --tg-theme-hint-color: #999;
    --tg-theme-link-color: #007bff;
}

/* === Header Styles === */
header {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    padding: 20px 40px;
    background: transparent;
    z-index: 10;
}

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

.logo {
    font-size: 32px;
    font-weight: bold;
    color: #1a2c62;
}

.logo span {
    color: #019d50;
}

.header-logo-icon {
    width: 40px;
    height: 40px;
    object-fit: contain;
    object-position: center;
    flex-shrink: 0;
    clip-path: inset(2px 2px);
}

.logo-with-icon {
    display: flex;
    align-items: center;
    gap: 6px;
}

.auth-buttons {
    display: flex;
    align-items: center;
    gap: 12px;
}

.lang-select-header .lang-select {
    background: transparent;
    border: 1px solid #1a1a1a;
    color: #1a1a1a;
    height: 38px;
    padding: 8px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
}

.lang-select-header .lang-select option {
    color: #333;
}

/* === Buttons Styles === */
.btn-secondary {
    background-color: #019d50;
    color: white;
    padding: 10px 20px;
    border-radius: 6px;
    text-decoration: none;
    display: inline-block;
}

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

.btn-telegram {
    background-color: #1a2c62;
    color: white;
    padding: 10px 20px;
    border-radius: 6px;
    text-decoration: none;
    display: inline-block;
}

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

.btn-book {
    background-color: #1a2c62;
    color: white;
    padding: 10px 20px;
    border-radius: 6px;
    text-decoration: none;
    display: inline-block;
    border: none;
    cursor: pointer;
    font-size: 14px;
}

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

.booking-require-login {
    background-color: #1a2c62;
    color: white;
    padding: 10px 20px;
    border-radius: 6px;
    display: inline-block;
    font-size: 14px;
}

/* === Mobile Auth Modal === */
#mobileAuthModal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 2000;
    display: none;
    align-items: center;
    justify-content: center;
}

#mobileAuthModal.active {
    display: flex;
}

body.modal-open {
    overflow: hidden;
}

#mobileAuthModal .modal-content {
    background: white;
    padding: 20px;
    border-radius: 8px;
    max-width: 400px;
    width: calc(100% - 40px);
    position: relative;
    text-align: center;
}

#mobileAuthModal .modal-close {
    position: absolute;
    top: 5px;
    right: 10px;
    font-size: 24px;
    cursor: pointer;
    color: #666;
    background: none;
    border: none;
}

#mobileAuthModal .modal-close:hover {
    color: #000;
}

#mobileAuthModal .modal-buttons {
    display: flex;
    gap: 10px;
    justify-content: center;
    margin-top: 20px;
}

#mobileAuthModal p {
    text-align: center;
    margin: 0 20px 20px;
    color: #333;
}

/* === Modal Logo Styles === */
.modal-logo-container {
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 15px;
}

#mobileAuthModal .header-logo-icon {
    width: 40px;
    height: 40px;
}

#mobileAuthModal .logo {
    margin-left: 10px;
}

#mobileAuthModal .logo span:first-child {
    color: #1a2c62;
}

/* === Header Media Queries === */
@media (max-width: 768px) {
    header {
        padding: 15px 20px;
    }
    .logo {
        font-size: 24px;
    }
}

/* === Общий контейнер (WebApp ширина, как car_blank) === */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #ffffff;
    color: #1a1a1a;
    padding: 16px;
    display: flex;
    justify-content: center;
}

.search-container {
    width: 100%;
    max-width: 600px;
    margin-top: 80px;
}

/* === Desktop Layout === */
.desktop-only {
    display: none;
}

@media (min-width: 769px) {
    body {
        justify-content: flex-start;
    }
    
    .desktop-only {
        display: block;
    }
    
    .search-container h1 {
        text-align: left;
    }
    
    #ai-summary-desktop {
        margin-top: 20px;
    }
    
    #desktop-results-container {
        position: absolute;
        top: 80px;
        left: 38%;
        width: 60%;
        height: calc(100vh - 80px);
        background: white;
    }
    
    .search-container {
        width: 35%;
        max-width: none;
        margin-left: 0;
        margin-left: 20px;
    }
    
    .tab-btn[data-tab="results"] {
        display: none;
    }
}

h1 {
    font-size: 20px;
    margin-bottom: 14px;
    text-align: center;
}

/* === Переключатель табов: AI слева, форма справа === */
.search-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
}

.tab-btn {
    flex: 1;
    padding: 10px 12px;
    border: 2px solid #e0e0e0;
    background: #fff;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    color: #666;
}

.tab-btn.active {
    border-color: #1a2c62;
    background: #1a2c62;
    color: #fff;
}

.tab-btn:hover:not(.active):not(:disabled) {
    border-color: #019d50;
    color: #019d50;
}

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

/* === Контент табов === */
.tab-content {
    transition: opacity 0.2s;
}

.tab-content.hidden {
    display: none;
}

/* === Форма === */
.search-form {
    background: #fff;
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 16px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

.form-section {
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid #e0e0e0;
}

.form-section:last-of-type {
    border-bottom: none;
    margin-bottom: 0;
    padding-bottom: 0;
}

.form-section h3 {
    font-size: 15px;
    margin-bottom: 10px;
    color: #333;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.form-group label {
    font-size: 12px;
    font-weight: 500;
    color: #555;
}

.form-group input {
    padding: 9px 10px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 13px;
    transition: border-color 0.2s;
    min-width: 0;
    width: 100%;
}

.form-group select {
    padding: 9px 36px 9px 10px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 13px;
    transition: all 0.2s;
    min-width: 0;
    width: 100%;
    background-color: var(--tg-theme-secondary-bg-color);
    color: var(--tg-theme-text-color);
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23666' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
}

.form-group input:focus {
    outline: none;
    border-color: #019d50;
    box-shadow: 0 0 0 2px rgba(76, 175, 80, 0.2);
}

.form-group select:focus {
    outline: none;
    border-color: var(--tg-theme-button-color);
    box-shadow: 0 0 0 2px rgba(0, 123, 255, 0.15);
}

/* === Color Selector (как в car_blank) === */
.color-selector {
    position: relative;
    margin-top: 4px;
}

.color-button {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 10px;
    border: 1px solid #ddd;
    border-radius: 6px;
    background: #fff;
    color: #333;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
    text-align: left;
}

.color-button:hover {
    border-color: #019d50;
}

.color-preview-box {
    width: 22px;
    height: 22px;
    border-radius: 4px;
    border: 1px solid #ccc;
    flex-shrink: 0;
    background-color: transparent;
}

.color-text {
    flex: 1;
}

.color-arrow {
    font-size: 10px;
    color: #999;
    transition: transform 0.2s;
}

.color-button.open .color-arrow {
    transform: rotate(180deg);
}

.color-palette {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    background: #fff;
    border: 1px solid #ccc;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 100;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
    padding: 8px;
    animation: lb-fade 0.2s ease;
}

.color-palette.closing {
    opacity: 0;
    transition: opacity 0.15s ease;
}

.color-option {
    aspect-ratio: 1;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    border: 2px solid transparent;
    position: relative;
}

.color-option:hover {
    transform: scale(1.05);
    border-color: #019d50;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.color-option.selected {
    border-color: #019d50;
    box-shadow: 0 0 0 2px rgba(76, 175, 80, 0.3);
}

.color-option::after {
    content: attr(data-name);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.8);
    color: #fff;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 11px;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
    z-index: 101;
}

.color-option:hover::after {
    opacity: 1;
}

.color-option[data-color="white"],
.color-option[data-color="silver"],
.color-option[data-color="beige"],
.color-option[data-color="light-blue"] {
    border: 2px solid #ddd;
}

/* === Чекбоксы комплектации === */
.checkbox-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
}

.checkbox-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.2s;
}

.checkbox-item:hover {
    background: #f0f7f0;
}

.checkbox-item input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: #019d50;
}

.checkbox-item span {
    font-size: 13px;
}

/* === Кнопка поиска === */
.search-btn {
    width: 100%;
    padding: 12px;
    background: #019d50;
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
    margin-top: 6px;
}

.search-btn:hover {
    background: #388E3C;
}

.search-btn:disabled {
    background: #ccc;
    cursor: not-allowed;
}

/* === AI поиск === */
.ai-search-container {
    background: #fff;
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 16px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

.ai-textarea {
    width: 100%;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-size: 14px;
    resize: vertical;
    min-height: 100px;
    font-family: inherit;
}

.ai-textarea:focus {
    outline: none;
    border-color: #019d50;
    box-shadow: 0 0 0 2px rgba(76, 175, 80, 0.2);
}

.ai-hint {
    font-size: 12px;
    color: #888;
    margin-top: 6px;
    text-align: center;
}

/* === Результаты === */
.results-container {
    margin-top: 16px;
}

.results-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 14px;
}

.results-header h2 {
    font-size: 20px;
}

#results-count {
    font-size: 13px;
    color: #888;
}

.loading,
.no-results {
    text-align: center;
    padding: 30px 16px;
    color: #888;
    font-size: 14px;
}

/* === AI Summary (расшифровка запроса) === */
.ai-summary {
    background: #f0f7f0;
    border: 1px solid #c8e6c9;
    border-radius: 10px;
    padding: 12px 14px;
    margin-bottom: 12px;
}

.ai-summary-title {
    font-size: 13px;
    font-weight: 600;
    color: #2e7d32;
    margin-bottom: 6px;
}

.ai-summary-lines {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 12px;
}

.ai-summary-line {
    font-size: 12px;
    color: #333;
    background: #fff;
    padding: 2px 8px;
    border-radius: 4px;
}

.hidden {
    display: none !important;
}

.results-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* === Карточка результата === */
.result-card {
    display: flex;
    background: #fff;
    border-radius: 10px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    margin-bottom: 16px;
    overflow: visible;
}

.result-photo-wrapper {
    flex: 0 0 40%;
    position: relative;
}

.result-info {
    flex: 1;
    padding: 12px;
    min-width: 0;
    position: relative;
}

.result-photo-container {
    position: relative;
    width: 100%;
    padding-top: 75%; /* Соотношение сторон ~4:3 */
    overflow: hidden;
}

.result-main-photo {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

/* Скругление фото: убрать со стороны, соприкасающейся с информацией */
.result-main-photo {
    border-radius: 8px;
}

@media (min-width: 769px) {
    /* Desktop: фото слева — убрать скругление справа */
    .result-main-photo {
        border-top-right-radius: 0;
        border-bottom-right-radius: 0;
    }
}

@media (max-width: 768px) {
    /* Mobile: фото сверху — убрать скругление снизу */
    .result-main-photo {
        border-bottom-left-radius: 0;
        border-bottom-right-radius: 0;
    }
}

.result-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(0,0,0,0.5);
    color: white;
    border: none;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 16px;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s, visibility 0.2s;
}

.result-photo-container:hover .result-nav {
    opacity: 1;
    visibility: visible;
}

.result-nav.result-prev {
    left: 8px;
}

.result-nav.result-next {
    right: 8px;
}

/* Mobile: фото сверху, информация снизу */
@media (max-width: 768px) {
    .result-card {
        flex-direction: column;
    }
    
    .result-photo-wrapper {
        width: 100%;
        order: -1;
    }
    
    .result-photo-container {
        width: 100%;
        height: 180px;
    }
    
    .result-nav {
        display: none;
    }
}

/* Score badge — правый верхний угол (не влияет на поток) */
.result-info-header {
    position: absolute;
    top: 10px;
    right: 10px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.result-score-badge {
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 700;
    color: #fff;
    z-index: 10;
}

.favorite-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0;
    z-index: 10;
}

.favorite-icon {
    width: 24px;
    height: 24px;
    display: block;
}

.result-score-badge.high {
    background: #019d50;
}

.result-score-badge.medium {
    background: #FFC107;
    color: #333;
}

.result-score-badge.low {
    background: #FF9800;
}

/* Мини-галерея */
.result-gallery {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 14px;
    margin-bottom: 14px;
}

.result-thumb {
    width: 80px;
    height: 60px;
    object-fit: cover;
    border-radius: 6px;
    border: 1px solid #e0e0e0;
}

/* Заголовок */
.result-title-row {
    margin-bottom: 4px;
}

.result-title {
    font-size: 18px;
    font-weight: 700;
}

.result-year-vin {
    display: flex;
    gap: 12px;
    align-items: center;
    margin-bottom: 4px;
}

.result-year {
    font-size: 15px;
    color: #888;
}

.result-price-city {
    display: flex;
    gap: 16px;
    margin-top: 12px;
    margin-bottom: 4px;
}

.price-left,
.price-right {
    flex: 1;
    min-width: 0;
}

.result-price-city .detail-value {
    font-weight: 700;
    color: #019d50;
}

.result-price-city .price-right .detail-value {
    color: #333;
}

.result-vin-frame {
    font-size: 13px;
    font-family: monospace;
    letter-spacing: 1px;
    color: #666;
}

.result-details {
    display: flex;
    gap: 16px;
    margin-bottom: 8px;
    font-size: 12px;
}

.details-left,
.details-right {
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex: 1;
    min-width: 0;
}

.result-description {
    margin-top: 8px;
}

.description-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
}

.description-label {
    color: #666;
}

.description-text {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
    color: #333;
    line-height: 1.4;
}

.result-description.expanded .description-text {
    display: block;
    overflow: visible;
    white-space: pre-wrap;
}

.description-toggle {
    background: none;
    border: none;
    color: #666;
    cursor: pointer;
    font-size: 14px;
    text-decoration: underline;
    white-space: nowrap;
}

.detail-item {
    display: flex;
    flex-direction: column;
}

.detail-value {
    font-weight: 700;
    color: #333;
}

.detail-label {
    font-weight: 400;
    color: #888;
}

/* Опции комплектации */
.result-options {
    margin-top: 8px;
}

.options-header {
    font-size: 12px;
    font-weight: 600;
    color: #333;
    margin-bottom: 4px;
}

.options-list {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.option-tag {
    font-size: 11px;
    padding: 2px 6px;
    background: #f5f5f5;
    color: #333;
    border-radius: 3px;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.option-bullet {
    color: #019d50;
    font-size: 12px;
}

/* Кнопки действий в карточке */
.result-actions {
    display: flex;
    gap: 8px;
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid #e0e0e0;
    flex-wrap: wrap;
}

.btn-action {
    flex: none;
    min-width: 0;
    padding: 8px 12px;
    border: 1px solid #019d50;
    border-radius: 6px;
    background: #fff;
    color: #019d50;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    white-space: normal;
}

.btn-action:hover {
    background: #f0f7f0;
    border-color: #388E3C;
    color: #388E3C;
}

/* === Lightbox === */
.lightbox-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.9);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: lb-fade 0.2s ease;
}

@keyframes lb-fade {
    from { opacity: 0; }
    to { opacity: 1; }
}

.lightbox-close {
    position: absolute;
    top: 16px;
    right: 20px;
    font-size: 32px;
    color: #fff;
    cursor: pointer;
    z-index: 10001;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255,255,255,0.1);
    border-radius: 50%;
    transition: background 0.2s;
}

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

.lightbox-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    font-size: 36px;
    color: #fff;
    cursor: pointer;
    z-index: 10001;
    width: 50px;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255,255,255,0.1);
    border-radius: 50%;
    transition: background 0.2s;
    user-select: none;
}

.lightbox-nav:hover {
    background: rgba(255,255,255,0.25);
}

.lightbox-prev {
    left: 16px;
}

.lightbox-next {
    right: 16px;
}

.lightbox-counter {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    color: #fff;
    font-size: 14px;
    background: rgba(0,0,0,0.5);
    padding: 6px 14px;
    border-radius: 16px;
}

.lightbox-img {
    max-width: 90vw;
    max-height: 85vh;
    object-fit: contain;
    border-radius: 8px;
    cursor: pointer;
}
