/* ============================================ */

/* Main input area container */
.input-area {
    position: relative;
    background: transparent;
    border-top: none;
    padding: 0;
    z-index: 1000;
    transition: bottom 0.2s ease;
    margin-bottom: 0;
}

/* Учитываем нижнюю safe-area (iOS, новые браузеры) */
/* Safe area padding removed - handled in mobile media queries */

/* Container for input + buttons */
.input-wrapper {
    max-width: 830px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 0 20px 16px 20px; /* Убираем padding-top, чтобы капсула начиналась от верхней границы */
}

/* Input field container */
.input-field-container {
    background: var(--color-bg-input); /* Same as sidebar */
    border: 1px solid var(--color-border-secondary);
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    transition: all 0.2s ease;
    padding: 0; /* No padding - container = text input size */
    gap: 0; /* No gap between elements */
    box-shadow: 0 -2px 12px rgba(0, 0, 0, 0.08);
}

.input-field-container:focus-within {
    border-color: var(--color-border-focus);
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

/* Text input field */
.message-input {
    width: 100%;
    min-height: 52px;
    max-height: 200px; /* ~7 lines at line-height 1.5 */
    padding: 14px 16px;
    border: none;
    border-radius: 12px 12px 0 0; /* Rounded top corners only */
    font-size: 16px !important; /* Было 14px или меньше */
    line-height: 1.5;
    resize: none;
    overflow-y: auto;
    font-family: inherit;
    background: var(--color-bg-input); /* Same as sidebar */
    color: var(--color-text-primary);
}

.message-input::placeholder {
    color: var(--color-text-placeholder);
}

.message-input:focus {
    outline: none;
}

/* Scrollbar styling for input - hidden by default, visible on scroll */
.message-input::-webkit-scrollbar {
    width: 6px;
}

.message-input::-webkit-scrollbar-track {
    background: transparent;
}

.message-input::-webkit-scrollbar-thumb {
    background: transparent;
    border-radius: 3px;
    transition: background 0.3s ease;
}

/* Show scrollbar on hover, focus, or when scrolling */
.message-input:hover::-webkit-scrollbar-thumb,
.message-input:focus::-webkit-scrollbar-thumb,
.message-input.scrolling::-webkit-scrollbar-thumb {
    background: var(--color-border-secondary);
}

.message-input::-webkit-scrollbar-thumb:hover {
    background: var(--color-text-placeholder);
}

/* Firefox scrollbar */
.message-input.scrolling {
    scrollbar-color: var(--color-border-secondary) transparent;
}

/* Bottom controls row - buttons */
.input-controls {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    border-top: none; /* Remove line between textarea and buttons */
    border-radius: 0 0 12px 12px; /* Rounded bottom corners */
}

/* Left side buttons group */
.input-controls-left {
    display: flex;
    align-items: center;
    gap: 4px;
}

/* Right side button (send) */
.input-controls-right {
    display: flex;
    align-items: center;
}

/* Base button style - Claude.ai minimalist */
.input-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 36px;
    height: 36px;
    padding: 8px;
    background: transparent;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.15s ease;
    color: var(--color-text-secondary);
}

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

.input-btn:active {
    transform: scale(0.95);
}

.input-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.input-btn:disabled:hover {
    background: transparent;
    transform: none;
}

/* Attach file button */
.attach-file-btn {
    /* Inherits from .input-btn */
}

/* Web search button (Perplexity) */
.web-search-btn {
    /* Inherits from .input-btn */
}

/* Model selector in input controls */
.input-controls .model-dropdown-trigger {
    display: flex;
    align-items: center;
    gap: 6px;
    background: transparent;
    border: 1px solid var(--color-border-main);
    border-radius: 8px;
    padding: 6px 10px;
    cursor: pointer;
    font-size: 13px;
    color: var(--color-text-primary);
    transition: all 0.15s ease;
    min-width: 140px;
    height: 36px;
}

.input-controls .model-dropdown-trigger:hover {
    background: var(--color-bg-hover);
    border-color: var(--color-border-secondary);
}

.input-controls .model-dropdown-trigger i {
    font-size: 12px;
    color: var(--color-text-placeholder);
}

/* Send button - square, blue */
.send-btn {
    min-width: 36px;
    height: 36px;
    background: var(--color-primary);
    color: var(--color-bg-main);
    border: none;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: all 0.15s ease;
}

.send-btn:hover:not(:disabled) {
    background: var(--color-primary-hover);
}

.send-btn:active:not(:disabled) {
    transform: scale(0.95);
}

.send-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.send-btn i {
    font-size: 18px;
}

/* Send button when generating (stop mode) */
.send-btn.generating {
    /* Color remains blue */
}

/* ============================================
   FILE ATTACHMENTS - Thumbnails
   ============================================ */

/* Attached files container - below input */
.attached-files-container {
    position: relative;
    margin-top: 6px;
    margin-bottom: 8px;
    display: none;
    width: 100%;
    max-width: 830px;
    margin-left: auto;
    margin-right: auto;
    padding: 0 20px;
}

.attached-files-container.has-files {
    display: block;
}

#attachedFilesList {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

/* File thumbnail item */
.attached-file-item {
    position: relative;
    width: 80px;
    height: 80px;
    background: var(--color-bg-sidebar);
    border: 1px solid var(--color-border-thin);
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    padding: 6px;
    transition: all 0.15s ease;
}

.attached-file-item:hover {
    background: var(--color-bg-hover);
    border-color: var(--color-border-thin);
    transform: none;
}

.file-name {
    font-size: 8px;
    color: var(--color-text-primary);
    font-weight: 400;
    text-align: left;
    line-height: 1.1;
    flex: 1;
    word-break: break-word;
    padding: 4px 6px 20px 6px; /* Add more left padding, bottom padding to avoid overlap with tag */
    display: flex;
    align-items: flex-start;
    justify-content: flex-start;
    overflow: hidden;
}

.file-type-tag {
    position: absolute;
    bottom: 4px;
    right: 4px;
    background: var(--color-text-muted);
    border: none;
    border-radius: 3px;
    padding: 2px 4px;
    font-size: 7px;
    color: var(--color-bg-main);
    font-weight: 500;
    text-transform: uppercase;
}

/* Remove file button - hidden by default, shown on hover */
.file-remove {
    position: absolute;
    top: -6px;
    right: -6px;
    width: 20px;
    height: 20px;
    background: var(--color-bg-main);
    color: var(--color-text-secondary);
    border: 1px solid var(--color-border-thin);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 12px;
    line-height: 1;
    font-weight: bold;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease, visibility 0.2s ease;
    z-index: 200;
    pointer-events: none;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.attached-file-item:hover .file-remove {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

.file-remove:hover {
    background: var(--color-bg-sidebar);
    border-color: var(--color-text-muted);
    color: var(--color-text-primary);
}

/* ============================================
   DRAG & DROP OVERLAY
   ============================================ */

.file-drop-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(102, 126, 234, 0.05);
    backdrop-filter: blur(4px);
    z-index: 9999;
    display: none;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    pointer-events: none;
}

.file-drop-overlay.active {
    display: flex;
}

.file-drop-icon {
    font-size: 48px;
    margin-bottom: 16px;
    color: var(--color-primary);
}

.file-drop-text {
    font-size: 20px;
    font-weight: 600;
    color: var(--color-primary);
    margin-bottom: 8px;
}

/* ============================================
   FILE PROCESSING INDICATOR
   ============================================ */

.file-processing {
    display: none;
    align-items: center;
    background: rgba(245, 158, 11, 0.1);
    border: 1px solid var(--color-warning);
    border-radius: 8px;
    padding: 8px 12px;
    margin-bottom: 8px;
    font-size: 13px;
    color: var(--color-warning);
}

.file-processing.active {
    display: flex;
}

.processing-spinner {
    width: 16px;
    height: 16px;
    border: 2px solid var(--color-warning);
    border-top: 2px solid var(--color-warning);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-right: 8px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* ============================================
   RESPONSIVE
   ============================================ */

@media (max-width: 830px) {
    .input-wrapper {
        max-width: 100%;
        padding-bottom: 0 !important;
    }
    
    .input-area {
        padding: 0 !important;
        padding-bottom: calc(env(safe-area-inset-bottom, 0) + 6px) !important;
    }

    .input-controls {
        padding: 6px 8px;
    }

    .input-controls .model-dropdown-trigger {
        min-width: 100px;
        font-size: 12px;
    }

    .attached-file-item {
        width: 70px;
        height: 70px;
    }
}

@media (max-width: 480px) {
    .input-wrapper {
        max-width: 100%;
        padding-bottom: 0 !important;
    }
    
    .input-area {
        padding: 0 !important;
        padding-bottom: calc(env(safe-area-inset-bottom, 0) + 6px) !important;
    }

    .input-controls {
        padding: 4px 6px;
        gap: 2px;
    }
    
    .input-controls-left {
        gap: 2px;
    }

    .input-btn {
        min-width: 32px;
        height: 32px;
        padding: 6px;
    }

    .send-btn {
        min-width: 32px;
        height: 32px;
    }

    .input-controls .model-dropdown-trigger {
        min-width: 80px;
        font-size: 11px;
        padding: 4px 8px;
    }

    .message-input {
        font-size: 16px !important; /* Было 14px или меньше */
        padding: 12px 14px;
    }

    .attached-file-item {
        width: 60px;
        height: 60px;
    }
}

/* ============================================
   HIDE FILE INPUT
   ============================================ */

.file-input-hidden {
    display: none;
}
/* ============================================
   MODEL DROPDOWN 
   ============================================ */
/* Model dropdown container */
.input-controls .model-dropdown {
    position: relative;
}

/* Trigger button */
.input-controls .model-dropdown-trigger {
    display: flex;
    align-items: center;
    gap: 6px;
    background: transparent;
    border: 1px solid var(--color-border-main);
    border-radius: 8px;
    padding: 6px 10px;
    cursor: pointer;
    font-size: 13px;
    color: var(--color-text-primary);
    transition: all 0.15s ease;
    min-width: 140px;
    height: 36px;
    font-weight: 500;
}

.input-controls .model-dropdown-trigger:hover {
    background: var(--color-bg-hover);
    border-color: var(--color-border-secondary);
}

.input-controls .model-dropdown-trigger .selected-models {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.input-controls .model-dropdown-trigger i {
    font-size: 12px;
    color: var(--color-text-placeholder);
    transition: transform 0.2s ease;
}

.input-controls .model-dropdown.open .model-dropdown-trigger i {
    transform: rotate(180deg);
}

/* Dropdown menu - opens UPWARD */
.input-controls .model-dropdown-menu {
    position: absolute;
    bottom: calc(100% + 8px); /* Opens above trigger */
    left: 0;
    background: var(--color-bg-input); /* Same as sidebar */
    border: 1px solid var(--color-border-secondary);
    border-radius: 12px;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.1);
    z-index: 2000;
    display: none;
    min-width: 600px;
    max-height: 75vh; /* 75% высоты экрана */
    overflow: hidden;
}

.input-controls .model-dropdown.open .model-dropdown-menu {
    display: flex;
    flex-direction: column;
}

/* Two-column layout */
.model-columns {
    display: flex;
    border-bottom: 1px solid var(--color-border-main);
    flex: 1; /* Занимает доступное пространство */
    min-height: 0; /* Важно для flex - позволяет скроллу работать */
    overflow: hidden; /* Скрываем overflow колонок */
}

/* Text models column (left) */
.text-models-column {
    flex: 1;
    border-right: 1px solid var(--color-border-main);
    display: flex;
    flex-direction: column;
    min-height: 0; /* Важно для flex - позволяет скроллу работать */
}

/* Image models column (right) */
.image-models-column {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0; /* Важно для flex - позволяет скроллу работать */
}

/* Column headers */
.model-column-header {
    padding: 10px 16px;
    font-size: 11px;
    font-weight: 600;
    color: var(--color-text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    background: var(--color-bg-sidebar);
    border-bottom: 1px solid var(--color-border-main);
    flex-shrink: 0; /* Не сжимается - всегда виден */
}

/* Scrollable model list */
.model-list-scroll {
    flex: 1 1 auto; /* Занимает доступное пространство в flex контейнере */
    min-height: 0; /* Важно для flex контейнеров - позволяет скроллу работать */
    max-height: 100%; /* Не превышает высоту родителя */
    overflow-y: auto;
    overflow-x: hidden;
    position: relative; /* Для правильного позиционирования scrollbar */
}

/* Scrollbar styling */
.model-list-scroll::-webkit-scrollbar {
    width: 6px;
}

.model-list-scroll::-webkit-scrollbar-track {
    background: transparent;
}

.model-list-scroll::-webkit-scrollbar-thumb {
    background: var(--color-border-secondary);
    border-radius: 3px;
}

.model-list-scroll::-webkit-scrollbar-thumb:hover {
    background: var(--color-text-placeholder);
}

/* Model option row */
.input-controls .model-option {
    display: flex;
    align-items: center;
    padding: 6px 16px;
    cursor: pointer;
    transition: background 0.15s ease;
    min-height: 32px;
    gap: 10px;
    touch-action: pan-y; /* Разрешаем вертикальный скролл на mobile */
    -webkit-tap-highlight-color: transparent; /* Убираем подсветку при тапе на mobile */
    position: relative; /* Для абсолютного позиционирования кнопки "Only" */
}

.input-controls .model-option:hover {
    background: var(--color-bg-hover);
}

/* Checkbox */
.input-controls .model-checkbox {
    flex-shrink: 0;
    display: flex;
    align-items: center;
}

.input-controls .model-checkbox input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--color-primary);
    cursor: pointer;
    margin: 0;
}

/* Model info */
.input-controls .model-info {
    flex: 1;
    min-width: 0;
}

.input-controls .model-name {
    font-size: 13px;
    font-weight: 500;
    color: var(--color-text-user);
    line-height: 1.3;
    display: flex;
    align-items: center;
    gap: 6px;
}

.input-controls .model-icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    object-fit: contain;
    display: inline-block;
    vertical-align: middle;
}

.input-controls .model-description {
    font-size: 11px;
    color: var(--color-text-secondary);
    line-height: 1.2;
    margin-top: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Key indicator (BYOK) */
.input-controls .key-indicator {
    font-size: 12px;
    color: var(--color-success);
    display: none;
}

/* Only button - скрыта по умолчанию */
.input-controls .model-only-btn {
    opacity: 0;
    visibility: hidden;
    position: absolute;
    right: 16px;
    top: 50%;
    transform: translateY(-50%);
    padding: 4px 10px;
    font-size: 12px;
    font-weight: 500;
    color: #6366f1;
    background: var(--color-bg-main); /* Фон чтобы перекрывать текст описания */
    border: 1px solid #6366f1;
    border-radius: 4px;
    cursor: pointer;
    transition: opacity 0.15s ease, visibility 0.15s ease, background 0.15s ease, color 0.15s ease;
    z-index: 1; /* Поверх описания */
    box-shadow: 0 0 4px rgba(0, 0, 0, 0.1); /* Легкая тень для лучшей видимости */
}

/* Показывать при hover на строку модели */
.input-controls .model-option:hover .model-only-btn {
    opacity: 1;
    visibility: visible;
    background: var(--color-bg-hover); /* Фон совпадает с hover фоном строки */
}

/* При hover на саму кнопку - синий фон */
.input-controls .model-only-btn:hover {
    background: #6366f1 !important; /* Приоритет над hover строки */
    color: white;
    box-shadow: 0 0 6px rgba(99, 102, 241, 0.3); /* Усиленная тень при hover */
}

/* Search container at bottom */
.model-search-container {
    padding: 12px;
    border-top: 1px solid var(--color-border-main);
    background: var(--color-bg-input);
    flex-shrink: 0; /* Не сжимается - всегда виден */
}

.model-search-input {
    width: 100%;
    padding: 8px 12px 8px 36px;
    border: 1px solid var(--color-border-secondary);
    border-radius: 8px;
    font-size: 13px;
    background: var(--color-bg-main);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%239ca3af' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cpath d='m21 21-4.35-4.35'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: 12px center;
    background-size: 16px;
    transition: all 0.15s ease;
}

.model-search-input::placeholder {
    color: var(--color-text-placeholder);
}

.model-search-input:focus {
    outline: none;
    border-color: var(--color-border-focus);
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

/* Hidden state for filtered models */
.model-option.hidden {
    display: none;
}

/* Empty state when no results */
.model-no-results {
    padding: 24px 16px;
    text-align: center;
    color: var(--color-text-placeholder);
    font-size: 13px;
    display: none;
}

.model-no-results.visible {
    display: block;
}

/* ============================================
   RESPONSIVE - MOBILE & TABLET
   ============================================ */

@media (max-width: 950px) {
    /* Single column layout для mobile и tablet portrait */
    .input-controls .model-dropdown-menu {
        min-width: 320px;
        max-width: 90vw;
        max-height: 75vh; /* 75% высоты экрана */
        left: 50%;
        transform: translateX(-50%);
    }
    
    /* ЕДИНЫЙ SCROLL для всего контента на mobile/tablet */
    .model-columns {
        flex-direction: column;
        flex: 1; /* Занимает доступное пространство */
        min-height: 0; /* Важно для flex - позволяет скроллу работать */
        overflow-y: auto; /* Единый скролл для всего контента */
        overflow-x: hidden;
        -webkit-overflow-scrolling: touch; /* Momentum scrolling на iOS */
        overscroll-behavior: contain; /* Предотвращает overscroll */
    }
    
    /* Scrollbar для единого контейнера */
    .model-columns::-webkit-scrollbar {
        width: 6px;
    }
    
    .model-columns::-webkit-scrollbar-track {
        background: transparent;
    }
    
    .model-columns::-webkit-scrollbar-thumb {
        background: var(--color-border-secondary);
        border-radius: 3px;
    }
    
    .model-columns::-webkit-scrollbar-thumb:hover {
        background: var(--color-text-placeholder);
    }
    
    .text-models-column {
        border-right: none;
        border-bottom: 1px solid var(--color-border-main);
        flex: 0 0 auto; /* Не растягивается, занимает только необходимое пространство */
        display: flex;
        flex-direction: column;
    }
    
    .image-models-column {
        flex: 0 0 auto; /* Не растягивается, занимает только необходимое пространство */
        display: flex;
        flex-direction: column;
    }
    
    /* Убираем отдельный scroll с каждой колонки на mobile/tablet */
    .model-list-scroll {
        overflow-y: visible !important; /* Убираем скролл - теперь скроллится весь .model-columns */
        overflow-x: hidden;
        flex: 0 0 auto; /* Не растягивается */
        max-height: none !important; /* Убираем ограничение высоты */
    }
    
    /* Заголовки как обычные элементы на mobile/tablet - убираем специальное позиционирование */
    .model-column-header {
        /* Убираем ВСЁ специальное позиционирование */
        position: static !important;
        flex-shrink: 0 !important; /* Не сжимается, но прокручивается */
        flex-grow: 0 !important;
        
        /* Оставляем только визуальные стили */
        padding: 10px 16px;
        font-size: 11px;
        font-weight: 600;
        color: var(--color-text-secondary);
        text-transform: uppercase;
        letter-spacing: 0.05em;
        background: var(--color-bg-sidebar);
        border-bottom: 1px solid var(--color-border-main);
    }
}

/* ============================================
   IMAGE MODE STYLING
   ============================================ */

/* Send button in image mode */
.send-btn.image-mode {
    background: var(--color-primary-image);
}

.send-btn.image-mode:hover:not(:disabled) {
    background: var(--color-primary-image-hover);
}

/* ============================================
   KEYBOARD FIX - iOS/Android
   ============================================ */

@media (max-width: 950px) {
    /* Фиксация input-area снизу на mobile */
    .input-area {
        position: fixed !important;
        bottom: 0 !important;
        left: 0;
        right: 0;
        width: 100%;
        z-index: 9999;
        margin: 0 !important;
        padding: 0 !important;
        padding-bottom: calc(env(safe-area-inset-bottom, 0) + 6px) !important;
    }
    
    /* Убираем padding-bottom из input-wrapper на мобильных */
    .input-wrapper {
        padding-bottom: 0 !important;
    }
    
    /* Предотвращаем overflow когда клавиатура открыта */
    body.keyboard-open {
        overflow: hidden;
    }
    
    /* Убеждаемся, что chat-main корректно работает с клавиатурой */
    body.keyboard-open .chat-main {
        overflow: hidden;
    }
    
    /* Fix auto-zoom на iOS - все input должны быть 16px */
    input, textarea, select {
        font-size: 16px !important;
    }
}

/* ============================================
   FIX AUTO-ZOOM ON iOS - Font size 16px
   ============================================ */

input,
textarea,
.message-input {
    font-size: 16px !important;
}

/* ============================================
   FILE DELETE BUTTON - ALWAYS VISIBLE ON MOBILE
   ============================================ */

@media (max-width: 950px) {
    /* Кнопка удаления файла всегда видна на mobile */
    .file-remove {
        opacity: 1 !important;
        visibility: visible !important;
        pointer-events: auto !important;
        /* Увеличенный размер для удобства на мобильных (+30%) */
        width: 26px !important;
        height: 26px !important;
        font-size: 16px !important;
        top: -7px !important;
        right: -7px !important;
    }
    
    /* Убираем hover эффект на mobile (его нет) */
    .attached-file-item:hover .file-remove {
        opacity: 1 !important;
        visibility: visible !important;
    }
}
