/* ========================================
   RESPONSIVE - ПОЛНАЯ МОБИЛЬНАЯ АДАПТАЦИЯ
   PWA-ready стили
   ======================================== */

/* ========================================
   PWA / Safe Areas для устройств с вырезом
   ======================================== */
:root {
    --safe-area-inset-top: env(safe-area-inset-top, 0px);
    --safe-area-inset-bottom: env(safe-area-inset-bottom, 0px);
    --safe-area-inset-left: env(safe-area-inset-left, 0px);
    --safe-area-inset-right: env(safe-area-inset-right, 0px);
}

/* ========================================
   MOBILE (до 768px) - Полная переработка
   ======================================== */
@media (max-width: 767px) {
    /* =====================================
       BODY - PWA Fullscreen режим
       БЕЗ padding на body - safe areas в компонентах
       ===================================== */
    body {
        /* Убираем padding с body чтобы фон заполнял весь экран */
        padding: 0;
        margin: 0;
        -webkit-user-select: none;
        user-select: none;
        overscroll-behavior: none;
        /* Фон расширяется под status bar и home indicator */
        background-attachment: fixed;
    }

    /* Разрешить выделение текста только в сообщениях */
    .messages-area,
    .markdown-content,
    .user-bubble,
    .assistant-content {
        -webkit-user-select: text;
        user-select: text;
    }

    /* =====================================
       УНИФИЦИРОВАННЫЕ РАЗМЕРЫ КНОПОК - ВСЕ ОДИНАКОВЫЕ
       ===================================== */
    /* Все иконки кнопок */
    button,
    .btn,
    .chats-toggle,
    .catalog-toggle,
    .lang-btn-active,
    .accent-dot-active,
    .mode-action-btn,
    .prompt-action-btn,
    .chat-delete-btn,
    .msg-action-btn,
    .catalog-close,
    .chats-close,
    .new-chat-btn,
    .modal-card-close,
    .logout-btn {
        -webkit-appearance: none;
        appearance: none;
        box-sizing: border-box;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        flex-shrink: 0;
    }

    /* Все кнопки-иконки: 36x36px */
    .btn,
    .chats-toggle,
    .catalog-toggle,
    .lang-btn-active,
    .mode-action-btn,
    .catalog-close,
    .chats-close,
    .new-chat-btn,
    .modal-card-close,
    .logout-btn {
        width: 36px !important;
        height: 36px !important;
        min-width: 36px !important;
        min-height: 36px !important;
        padding: 0.5rem !important;
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
        flex-shrink: 0 !important;
    }

    /* Акцентная точка - тоже 36x36px, но без внешнего бордера */
    .accent-dot-active {
        width: 36px !important;
        height: 36px !important;
        min-width: 36px !important;
        min-height: 36px !important;
        padding: 0 !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        border-radius: 50% !important;
        border: none !important;
        background: transparent !important;
    }

    .accent-dot-inner {
        width: 12px !important;
        height: 12px !important;
        min-width: 12px !important;
        min-height: 12px !important;
        border-radius: 50% !important;
        position: absolute !important;
        top: 50% !important;
        left: 50% !important;
        transform: translate(-50%, -50%) !important;
        border: 1.5px solid !important;
        background: transparent !important;
    }

    /* Кнопка отправки (primary) */
    .btn.primary {
        width: 36px !important;
        height: 36px !important;
        min-width: 36px !important;
        min-height: 36px !important;
        padding: 0 !important;
    }

    /* Селекторы режима/модели - фиксированная высота */
    .mode-selector-btn,
    .model-selector-btn {
        height: 36px !important;
        min-height: 36px !important;
        box-sizing: border-box;
    }

    /* Кнопки действий в сообщениях */
    .msg-action-btn {
        min-height: 36px !important;
        padding: 0.5rem 0.75rem !important;
        box-sizing: border-box;
    }

    /* Кнопки в карточках промптов */
    .prompt-action-btn {
        width: 36px !important;
        height: 36px !important;
        min-width: 36px !important;
        min-height: 36px !important;
        padding: 0.5rem !important;
    }

    /* =====================================
       SAFARI FIXES - Исправления для Safari
       ===================================== */
    /* Убираем стандартные стили Safari */
    button,
    input[type="button"],
    input[type="submit"],
    input[type="reset"] {
        -webkit-appearance: none;
        -moz-appearance: none;
        appearance: none;
        -webkit-tap-highlight-color: transparent;
        box-sizing: border-box;
    }

    /* Фиксируем размеры инпутов в Safari */
    input,
    textarea,
    select {
        -webkit-appearance: none;
        -moz-appearance: none;
        appearance: none;
        box-sizing: border-box;
    }

    /* Исправление для textarea в Safari */
    .text-input {
        -webkit-appearance: none;
        resize: none;
        box-sizing: border-box;
        -webkit-box-sizing: border-box;
        -moz-box-sizing: border-box;
    }

    /* Выравнивание всех flex контейнеров */
    .header,
    .header-actions,
    .mode-selector-row,
    .input-wrapper,
    .actions {
        -webkit-box-align: center;
        -webkit-box-pack: center;
        box-sizing: border-box;
    }

    /* Исправление выравнивания кнопок в Safari */
    .btn,
    button {
        vertical-align: middle;
        -webkit-box-align: center;
        -webkit-box-pack: center;
    }

    /* Исправление отступов в Safari */
    * {
        -webkit-box-sizing: border-box;
        -moz-box-sizing: border-box;
    }

    /* Универсальные стили для SVG в кнопках */
    .btn svg,
    .chats-toggle svg,
    .catalog-toggle svg,
    .lang-btn-active svg,
    .mode-action-btn svg,
    .catalog-close svg,
    .chats-close svg,
    .new-chat-btn svg,
    .modal-card-close svg,
    .logout-btn svg,
    button svg {
        width: 18px !important;
        height: 18px !important;
        min-width: 18px !important;
        min-height: 18px !important;
        flex-shrink: 0;
        display: block;
    }

    /* =====================================
       HEADER - Мобильный (Apple HIG / Material Design)
       ===================================== */
    .header {
        padding: 0.75rem 1rem;
        padding-top: calc(0.75rem + var(--safe-area-inset-top));
        padding-left: calc(1rem + var(--safe-area-inset-left));
        padding-right: calc(1rem + var(--safe-area-inset-right));
        gap: 0.625rem;
        min-height: calc(56px + var(--safe-area-inset-top));
        box-sizing: border-box;
        display: flex;
        align-items: center;
    }

    .logo {
        gap: 0.5rem;
        flex-shrink: 0;
    }

    .logo-icon {
        width: 26px;
        height: 26px;
    }

    .logo-text {
        font-size: 1rem;
    }

    /* Иконки в кнопках header */
    .list-icon {
        width: 18px !important;
        height: 18px !important;
    }

    /* Скрыть слоган полностью */
    .header-slogan {
        display: none !important;
    }

    .header-actions {
        gap: 0.375rem;
        flex-shrink: 0;
        display: flex;
        align-items: center;
    }

    /* Языковой переключатель */
    .lang-btn-active {
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        gap: 0 !important;
    }

    .lang-text {
        display: none !important;
    }

    .lang-icon,
    .lang-btn-active svg {
        width: 18px !important;
        height: 18px !important;
        min-width: 18px !important;
        min-height: 18px !important;
        flex-shrink: 0;
    }

    .lang-dropdown {
        right: 0;
        left: auto;
        min-width: 120px;
    }

    .lang-option {
        padding: 0.625rem 0.875rem;
        min-height: 36px;
        font-size: 0.875rem;
        box-sizing: border-box;
    }

    /* Кнопка промтов */
    .catalog-toggle {
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        gap: 0 !important;
    }

    .catalog-toggle span {
        display: none !important;
    }

    .toggle-icon,
    .catalog-toggle svg {
        width: 18px !important;
        height: 18px !important;
        min-width: 18px !important;
        min-height: 18px !important;
        flex-shrink: 0;
    }

    /* Акцентный цвет */
    .accent-theme-selector {
        gap: 0.25rem;
        position: relative;
    }

    /* Убираем hover на мобильных, используем touch */
    .accent-theme-selector:hover .accent-dropdown {
        opacity: 0;
        visibility: hidden;
    }

    .accent-theme-selector.active .accent-dropdown {
        opacity: 1 !important;
        visibility: visible !important;
        transform: translateY(0) !important;
        pointer-events: auto !important;
    }

    .accent-dropdown {
        right: 0 !important;
        left: auto !important;
        top: calc(100% + 0.5rem) !important;
        display: flex !important;
        flex-direction: column !important;
        gap: 0.5rem !important;
        padding: 0.5rem !important;
        background: hsl(var(--card)) !important;
        border: 1px solid hsl(var(--border)) !important;
        border-radius: 0.5rem !important;
        box-shadow: 0 4px 12px hsl(var(--background) / 0.5) !important;
        z-index: 10000 !important;
        min-width: auto !important;
        align-items: center !important;
    }

    .accent-dropdown .accent-dot {
        width: 24px !important;
        height: 24px !important;
        min-width: 24px !important;
        min-height: 24px !important;
        padding: 0 !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        border-radius: 50% !important;
        border: 1.5px solid transparent !important;
        box-sizing: border-box !important;
        position: relative !important;
    }

    /* Внутренние точки в выпадающем меню */
    .accent-dropdown .accent-dot::before {
        content: '';
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        width: 10px;
        height: 10px;
        border-radius: 50%;
        border: 1.5px solid currentColor;
    }

    .accent-dot-red::before {
        border-color: hsl(25 70% 50%);
    }

    .accent-dot-blue::before {
        border-color: hsl(195 70% 60%);
    }

    .accent-dot-green::before {
        border-color: hsl(142 60% 45%);
    }

    .accent-dot-gray::before {
        border-color: hsl(0 0% 100%);
    }

    /* =====================================
       MAIN LAYOUT
       ===================================== */
    .main-container {
        flex: 1;
        display: flex;
        overflow: hidden;
        position: relative;
    }

    .split-container {
        display: flex;
        width: 100%;
        height: 100%;
        position: relative;
    }

    /* =====================================
       CHAT PANEL - Всегда видна
       ===================================== */
    .chat-panel {
        flex: 1;
        display: flex;
        flex-direction: column;
        width: 100%;
        min-width: 0;
        overflow: hidden;
    }

    /* =====================================
       CHATS PANEL - Выдвижной сайдбар
       ===================================== */
    .chats-panel {
        position: fixed;
        top: 0;
        left: 0;
        width: 85vw;
        max-width: 320px;
        height: 100%;
        height: 100dvh;
        z-index: 1001;
        background: hsl(var(--background));
        border-right: 1px solid hsl(var(--border));
        transform: translateX(-100%);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        overflow: hidden;
        /* Safe areas для PWA */
        padding-top: var(--safe-area-inset-top);
        padding-bottom: var(--safe-area-inset-bottom);
        padding-left: var(--safe-area-inset-left);
    }

    .chats-panel.active {
        transform: translateX(0);
        display: flex;
        flex-direction: column;
        width: 85vw;
        max-width: 320px;
        min-width: auto;
        box-shadow: 4px 0 24px rgba(0, 0, 0, 0.3);
    }

    /* Chats Container внутри */
    .chats-container {
        padding: 1rem;
        height: 100%;
        display: flex;
        flex-direction: column;
    }

    .chats-header {
        margin-bottom: 1rem;
    }

    .chats-title {
        font-size: 1.125rem;
    }

    .chats-search {
        padding: 0.875rem;
        margin-bottom: 1rem;
        min-height: 48px;
    }

    .chats-search-input {
        font-size: 1rem;
    }

    .chats-filter {
        gap: 0.5rem;
        margin-bottom: 1rem;
        flex-wrap: wrap;
    }

    .chats-filter-btn {
        padding: 0.5rem 0.875rem;
        font-size: 0.875rem;
        min-height: 40px;
    }

    .chats-list {
        flex: 1;
        gap: 0.625rem;
    }

    .chat-item {
        padding: 1rem;
        min-height: 56px;
    }

    .chat-item-name {
        font-size: 1rem;
    }

    .new-chat-btn {
        width: 44px;
        height: 44px;
    }

    .new-chat-btn i {
        width: 20px;
        height: 20px;
    }

    .chats-close {
        width: 44px;
        height: 44px;
    }

    .chats-close i {
        width: 22px;
        height: 22px;
    }

    /* =====================================
       CATALOG PANEL - Полноэкранный
       ===================================== */
    .catalog-panel {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        width: 100%;
        height: 100%;
        height: 100dvh;
        z-index: 1001;
        background: hsl(var(--background));
        border-left: none;
        transform: translateX(100%);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        overflow: hidden;
    }

    .catalog-panel.active {
        transform: translateX(0);
        display: flex;
        flex-direction: column;
        width: 100%;
        min-width: 0;
    }

    /* Скрыть resizer */
    .resizer {
        display: none !important;
    }

    /* =====================================
       CATALOG CONTENT
       ===================================== */
    .catalog-container {
        padding: 1rem;
        padding-top: calc(1rem + var(--safe-area-inset-top));
        padding-bottom: calc(1rem + var(--safe-area-inset-bottom));
        padding-left: calc(1rem + var(--safe-area-inset-left));
        padding-right: calc(1rem + var(--safe-area-inset-right));
        height: 100%;
        display: flex;
        flex-direction: column;
    }

    .catalog-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        margin-bottom: 1rem;
        flex-shrink: 0;
    }

    .catalog-title {
        font-size: 1.125rem;
    }

    .catalog-close i {
        width: 18px;
        height: 18px;
    }

    /* Catalog Controls */
    .catalog-controls {
        flex-wrap: wrap;
        gap: 0.75rem;
        margin-bottom: 1rem;
        flex-shrink: 0;
    }

    .search-box {
        flex: 1 1 100%;
        order: 1;
        max-width: none;
        min-width: 0;
        padding: 0.625rem 0.75rem;
        min-height: 44px;
    }

    .search-box svg {
        width: 18px;
        height: 18px;
    }

    .search-box .search-input {
        font-size: 0.9375rem;
    }

    /* Filter Tabs */
    .filter-tabs {
        flex: 1 1 100%;
        order: 2;
        gap: 0.25rem;
        overflow-x: auto;
        flex-wrap: nowrap;
        padding: 0.25rem;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }

    .filter-tabs::-webkit-scrollbar {
        display: none;
    }

    .filter-tab {
        font-size: 0.8125rem;
        padding: 0.5rem 0.75rem;
        min-height: 36px;
        flex-shrink: 0;
        white-space: nowrap;
    }

    .filter-icon {
        width: 16px;
        height: 16px;
    }

    /* Category Chips */
    .category-chips {
        flex: 1 1 100%;
        order: 3;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 0.5rem;
        flex-wrap: nowrap;
        scrollbar-width: none;
        gap: 0.375rem;
    }
    
    .category-chips::-webkit-scrollbar {
        display: none;
    }

    .category-chip {
        flex-shrink: 0;
        font-size: 0.8125rem;
        padding: 0.5rem 0.75rem;
        min-height: 36px;
        white-space: nowrap;
    }

    .category-icon {
        width: 16px;
        height: 16px;
    }

    /* =====================================
       PROMPTS GRID - Мобильная сетка
       ===================================== */
    .prompts-grid {
        grid-template-columns: 1fr;
        gap: 0.75rem;
        flex: 1;
        overflow-y: auto;
        padding: 0.5rem;
        padding-bottom: calc(1rem + var(--safe-area-inset-bottom));
    }

    .prompt-card {
        padding: 1rem;
    }

    .prompt-card-header {
        margin-bottom: 0.5rem;
    }

    .prompt-category {
        font-size: 0.75rem;
        padding: 0.25rem 0.5rem;
    }

    .prompt-category-icon {
        width: 14px;
        height: 14px;
    }

    .prompt-likes {
        font-size: 0.8125rem;
        padding: 0.375rem 0.5rem;
        min-height: 32px;
    }

    .prompt-likes svg {
        width: 14px;
        height: 14px;
    }

    .prompt-title {
        font-size: 1rem;
        margin-bottom: 0.5rem;
        line-height: 1.4;
    }

    .prompt-description {
        font-size: 0.875rem;
        -webkit-line-clamp: 3;
        line-clamp: 3;
        line-height: 1.5;
    }

    .prompt-card-footer {
        margin-top: 0.75rem;
        padding-top: 0.75rem;
        gap: 0.5rem;
    }

    .prompt-author {
        gap: 0.375rem;
    }

    .author-avatar {
        width: 28px;
        height: 28px;
        font-size: 0.625rem;
    }

    .author-name {
        font-size: 0.75rem;
    }

    .prompt-actions {
        gap: 0.375rem;
    }

    .prompt-action-btn svg {
        width: 18px;
        height: 18px;
    }

    /* Expanded prompt card */
    .prompt-card-expanded {
        margin-top: 1rem;
        padding-top: 1rem;
    }

    .prompt-expanded-description {
        font-size: 1rem;
        padding: 1rem;
        line-height: 1.6;
    }

    .prompt-expanded-stats {
        flex-wrap: wrap;
        gap: 1rem;
        padding: 0.875rem;
    }

    .prompt-expanded-stats .stat-item {
        font-size: 0.9375rem;
    }

    .prompt-expanded-actions {
        flex-direction: column;
        gap: 0.75rem;
    }

    .prompt-expanded-btn {
        padding: 1rem 1.25rem;
        font-size: 1rem;
        min-height: 52px;
    }

    /* =====================================
       CHATS BAR - Скрыть на мобильных
       ===================================== */
    .chats-bar {
        display: none !important;
    }

    /* =====================================
       MESSAGES AREA
       ===================================== */
    .messages-area {
        flex: 1;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    .messages-container {
        padding: 1rem;
        padding-left: calc(1rem + var(--safe-area-inset-left));
        padding-right: calc(1rem + var(--safe-area-inset-right));
        max-width: 100%;
        gap: 1.25rem;
        padding-bottom: 1.5rem;
    }

    .user-bubble {
        padding: 1rem 1.125rem;
        font-size: 1rem;
        border-radius: 0.875rem;
        line-height: 1.5;
    }

    .assistant-content {
        padding: 0.75rem;
    }

    .message-actions {
        gap: 0.5rem;
        flex-wrap: wrap;
        padding-left: 0.75rem;
    }

    .msg-action-btn svg {
        width: 16px;
        height: 16px;
    }

    /* Markdown content на мобильных */
    .markdown-content h1,
    .markdown-content h2 {
        font-size: 1.0625rem;
        margin-top: 1.25em;
    }

    .markdown-content h3 {
        font-size: 0.9375rem;
    }

    .markdown-content p {
        font-size: 0.9375rem;
        line-height: 1.6;
    }

    .markdown-content ul,
    .markdown-content ol,
    .markdown-content li {
        font-size: 0.9375rem;
        line-height: 1.55;
    }

    .markdown-content code {
        font-size: 0.8125rem;
        padding: 0.2em 0.4em;
    }

    .markdown-content pre code {
        font-size: 0.8125rem;
        padding: 0.875rem;
    }

    .markdown-content blockquote {
        padding: 0.75rem 1rem;
        font-size: 0.9375rem;
    }

    .markdown-content table {
        font-size: 0.8125rem;
    }

    .markdown-content table th,
    .markdown-content table td {
        padding: 0.625rem;
    }

    /* =====================================
       INPUT AREA - Мобильная оптимизация
       ===================================== */
    .input-area {
        padding: 0.5rem 0.75rem;
        padding-bottom: calc(0.5rem + var(--safe-area-inset-bottom));
        padding-left: calc(0.75rem + var(--safe-area-inset-left));
        padding-right: calc(0.75rem + var(--safe-area-inset-right));
        background: hsl(var(--background));
        box-sizing: border-box;
    }

    .input-container {
        max-width: 100%;
        box-sizing: border-box;
    }

    /* Mode Selector Row */
    .mode-selector-row {
        flex-wrap: wrap;
        gap: 0.375rem;
        margin-bottom: 0.5rem;
        box-sizing: border-box;
    }

    .mode-selector-left {
        display: flex;
        flex-wrap: wrap;
        gap: 0.375rem;
        flex: 1;
        min-width: 0;
        box-sizing: border-box;
    }

    .mode-selector-right {
        flex-shrink: 0;
        box-sizing: border-box;
    }

    /* Mode & Model селекторы */
    .mode-selector,
    .model-selector {
        flex: 0 0 auto;
        box-sizing: border-box;
    }

    .mode-selector-btn,
    .model-selector-btn {
        padding: 0.5rem 0.625rem;
        font-size: 0.8125rem;
        height: 36px;
        min-height: 36px;
        gap: 0.375rem;
        box-sizing: border-box;
    }

    .mode-icon,
    .model-logo {
        width: 16px;
        height: 16px;
    }

    .mode-text,
    .model-text {
        font-size: 0.75rem;
        max-width: 70px;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .mode-chevron,
    .model-chevron {
        width: 14px;
        height: 14px;
    }

    .mode-option,
    .model-option {
        height: 36px !important;
        min-height: 36px !important;
        box-sizing: border-box;
    }

    /* Dropdowns - открываются вверх на мобильных */
    .mode-dropdown,
    .model-dropdown {
        position: absolute;
        left: 0;
        right: auto;
        top: auto;
        bottom: 100%;
        margin-bottom: 0.25rem;
        max-height: 200px;
        overflow-y: auto;
        min-width: 160px;
        border-radius: 0.5rem;
        border-bottom-left-radius: 0;
        border-bottom-right-radius: 0;
    }

    .mode-option,
    .model-option {
        padding: 0.625rem 0.75rem;
        min-height: 44px;
        font-size: 0.875rem;
    }

    .mode-action-icon {
        width: 18px;
        height: 18px;
    }

    /* Auth */
    .auth-login-btn {
        font-size: 0.8125rem;
        padding: 0.5rem 0.75rem;
        height: 36px;
        min-height: 36px;
        box-sizing: border-box;
    }

    .user-block {
        font-size: 0.75rem;
        gap: 0.375rem;
    }

    .user-name {
        max-width: 80px;
        overflow: hidden;
        text-overflow: ellipsis;
    }


    /* Input wrapper */
    .input-wrapper {
        padding: 0.5rem;
        border-radius: 0.75rem;
        box-sizing: border-box;
        display: flex;
        align-items: flex-end;
        gap: 0.5rem;
    }

    .text-input {
        font-size: 1rem;
        min-height: 48px;
        max-height: 150px;
        padding: 0.5rem;
        line-height: 1.5;
        box-sizing: border-box;
        flex: 1;
        min-width: 0;
        margin: 0;
    }

    .input-footer {
        font-size: 0.75rem;
        padding: 0.375rem 0.5rem 0;
        box-sizing: border-box;
    }

    /* Actions */
    .actions {
        gap: 0.375rem;
    }

    .btn svg {
        width: 18px;
        height: 18px;
    }

    /* File list */
    .file-list {
        gap: 0.5rem;
        padding: 0 0.25rem;
        margin-bottom: 0.5rem;
    }

    .file-item {
        padding: 0.5rem 0.625rem;
        font-size: 0.8125rem;
        min-height: 36px;
    }

    .file-item .remove-btn {
        width: 20px;
        height: 20px;
    }

    /* =====================================
       SIDEBAR OVERLAY
       ===================================== */
    .sidebar-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.6);
        z-index: 1000;
        opacity: 0;
        transition: opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        backdrop-filter: blur(4px);
        -webkit-backdrop-filter: blur(4px);
    }

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

    /* =====================================
       MODALS - Полноэкранные
       ===================================== */
    .modal-overlay {
        padding: 0 !important;
    }

    .modal-content,
    .modal-card {
        margin: 0;
        width: 100%;
        height: 100%;
        height: 100dvh;
        max-width: 100%;
        max-height: 100%;
        border-radius: 0;
    }

    .modal-card-header {
        padding: 0.75rem 1rem;
        padding-top: calc(0.75rem + var(--safe-area-inset-top));
        padding-left: calc(1rem + var(--safe-area-inset-left));
        padding-right: calc(1rem + var(--safe-area-inset-right));
    }

    .modal-card-title {
        font-size: 1rem;
    }

    .modal-card-close i {
        width: 18px;
        height: 18px;
    }

    .modal-card-body {
        flex: 1;
        overflow: hidden;
        display: flex;
        flex-direction: column;
    }

    .modal-body {
        padding: 1rem;
        padding-bottom: calc(1rem + var(--safe-area-inset-bottom));
        padding-left: calc(1rem + var(--safe-area-inset-left));
        padding-right: calc(1rem + var(--safe-area-inset-right));
    }

    /* Settings Modal - Tabs */
    #settingsModal .modal-card-tabs {
        width: 100%;
        min-width: 100%;
        border-right: none;
        border-bottom: 1px solid hsl(var(--border));
        flex-direction: row;
        overflow-x: auto;
        overflow-y: hidden;
        padding: 0 0.75rem;
        gap: 0.25rem;
    }

    #settingsModal .modal-card-tab {
        border-left: none;
        border-bottom: 2px solid transparent;
        white-space: nowrap;
        flex-shrink: 0;
        padding: 0.625rem 0.75rem;
        font-size: 0.75rem;
        justify-content: center;
        min-height: 44px;
    }

    #settingsModal .modal-card-tab.active {
        border-left-color: transparent;
        border-bottom-color: hsl(var(--primary));
    }

    #settingsModal .modal-card-content {
        padding: 1rem;
        flex: 1;
        overflow-y: auto;
        padding-bottom: calc(1rem + var(--safe-area-inset-bottom));
    }

    #settingsModal .settings-section {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    #settingsModal .settings-input,
    #settingsModal .settings-select,
    #settingsModal .settings-textarea {
        font-size: 1rem;
        padding: 0.75rem;
        min-height: 44px;
        box-sizing: border-box;
    }

    #settingsModal .settings-btn {
        padding: 0.75rem 1rem;
        font-size: 0.875rem;
        min-height: 44px;
        box-sizing: border-box;
    }

    #settingsModal .settings-options {
        gap: 0.5rem;
    }

    #settingsModal .settings-option {
        padding: 0.625rem 0.875rem;
        font-size: 0.8125rem;
        min-height: 44px;
        box-sizing: border-box;
    }

    /* Docs Modal */
    #docsModal .modal-card-tabs {
        overflow-x: auto;
        flex-wrap: nowrap;
        padding: 0 0.75rem;
    }

    #docsModal .modal-card-tab {
        flex-shrink: 0;
        white-space: nowrap;
        min-height: 44px;
        font-size: 0.8125rem;
        box-sizing: border-box;
    }

    /* Auth Modal */
    #telegramAuthModal .modal-card {
        max-width: 100%;
        height: auto;
        max-height: calc(100dvh - 2rem);
        margin: 1rem;
        border-radius: 0.75rem;
    }

    .auth-container {
        padding: 1.25rem;
    }

    .auth-icon {
        width: 56px;
        height: 56px;
    }

    .auth-icon svg {
        width: 32px;
        height: 32px;
    }

    .auth-title {
        font-size: 1rem;
    }

    .auth-description {
        font-size: 0.875rem;
        line-height: 1.5;
    }

    .auth-telegram-btn {
        padding: 0.75rem 1rem;
        font-size: 0.875rem;
        min-height: 44px;
        box-sizing: border-box;
    }

    .auth-telegram-btn svg {
        width: 18px;
        height: 18px;
    }

    /* Delete Chat Modal */
    #deleteChatModal .modal-card {
        max-width: calc(100% - 2rem);
        margin: 1rem;
        border-radius: 0.75rem;
        height: auto;
    }

    .delete-chat-container {
        padding: 1.25rem;
    }

    .delete-chat-icon {
        width: 56px;
        height: 56px;
    }

    .delete-chat-title {
        font-size: 1rem;
    }

    .delete-chat-text {
        font-size: 0.875rem;
        line-height: 1.5;
    }

    .delete-chat-actions {
        gap: 0.75rem;
    }

    .delete-chat-btn {
        padding: 0.75rem 1rem;
        font-size: 0.875rem;
        min-height: 44px;
        box-sizing: border-box;
    }

    /* =====================================
       TOAST - Мобильная позиция
       ===================================== */
    .toast-container {
        left: 0.75rem;
        right: 0.75rem;
        bottom: calc(0.75rem + var(--safe-area-inset-bottom));
    }

    .toast {
        min-width: auto;
        padding: 0.875rem 1rem;
        font-size: 0.875rem;
    }

    /* =====================================
       SHARE MENU
       ===================================== */
    .share-menu {
        min-width: 180px;
        left: auto;
        right: 0;
    }

    .share-menu-item {
        padding: 0.75rem 1rem;
        font-size: 0.875rem;
        min-height: 44px;
        box-sizing: border-box;
    }
}

/* ========================================
   SMALL MOBILE (до 375px)
   ======================================== */
@media (max-width: 375px) {
    .header {
        padding: 0.375rem 0.5rem;
        padding-top: calc(0.375rem + var(--safe-area-inset-top));
        min-height: 48px;
    }

    .logo-text {
        font-size: 0.8125rem;
    }

    .logo-icon {
        width: 20px;
        height: 20px;
    }

    .header-actions {
        gap: 0.25rem;
    }

    /* Все кнопки остаются 36x36px даже на маленьких экранах */
    .lang-btn-active,
    .catalog-toggle,
    .accent-dot-active,
    .chats-toggle,
    .mode-action-btn,
    .btn,
    .btn.primary {
        width: 36px !important;
        height: 36px !important;
        min-width: 36px !important;
        min-height: 36px !important;
    }

    /* Input area */
    .mode-selector-btn,
    .model-selector-btn {
        padding: 0.375rem 0.5rem;
        height: 36px;
        min-height: 36px;
        box-sizing: border-box;
    }

    .mode-text,
    .model-text {
        display: none;
    }

    .mode-chevron,
    .model-chevron {
        display: none;
    }

    .auth-login-btn {
        font-size: 0.75rem;
        padding: 0.375rem 0.5rem;
        height: 36px;
        min-height: 36px;
        box-sizing: border-box;
    }

    .user-name {
        display: none;
    }

    .text-input {
        font-size: 1rem;
        min-height: 44px;
        box-sizing: border-box;
    }

    /* Prompts */
    .prompts-grid {
        gap: 0.5rem;
    }

    .prompt-card {
        padding: 0.75rem;
    }

    .prompt-title {
        font-size: 0.9375rem;
    }

    .prompt-description {
        font-size: 0.8125rem;
    }


    /* Catalog controls - только иконки */
    .filter-tab span {
        display: none;
    }

    .filter-tab {
        padding: 0.5rem;
        min-width: 36px;
        min-height: 36px;
        justify-content: center;
    }

    .category-chip span {
        display: none;
    }

    .category-chip {
        padding: 0.5rem;
        min-width: 32px;
        min-height: 32px;
        justify-content: center;
    }

    /* Messages */
    .user-bubble {
        font-size: 0.9375rem;
        padding: 0.75rem 0.875rem;
    }

    .markdown-content p,
    .markdown-content li {
        font-size: 0.9375rem;
    }

    /* Chats */
    .chat-item {
        min-height: 48px;
        padding: 0.75rem;
    }

    .chat-item-name {
        font-size: 0.875rem;
    }

}

/* ========================================
   TABLET (768px - 1024px)
   ======================================== */
@media (min-width: 768px) and (max-width: 1024px) {
    .catalog-panel.active {
        width: 45%;
        min-width: 320px;
    }

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

    .chat-panel {
        min-width: 400px;
    }

    .chats-panel.active {
        width: 260px;
        min-width: 260px;
    }
}

/* ========================================
   LARGE DESKTOP (1440px+)
   ======================================== */
@media (min-width: 1440px) {
    .catalog-panel.active {
        width: 45%;
        min-width: 450px;
    }

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

/* ========================================
   LANDSCAPE MOBILE
   ======================================== */
@media (max-width: 900px) and (max-height: 500px) and (orientation: landscape) {
    .header {
        padding: 0.25rem 0.75rem;
        padding-top: calc(0.25rem + var(--safe-area-inset-top));
        min-height: 40px;
    }

    .logo-icon {
        width: 18px;
        height: 18px;
    }

    .logo-text {
        font-size: 0.75rem;
    }

    .input-area {
        padding: 0.25rem 0.5rem;
        padding-bottom: calc(0.25rem + var(--safe-area-inset-bottom));
    }

    .text-input {
        min-height: 36px;
        max-height: 60px;
        font-size: 0.875rem;
    }

    .mode-selector-row {
        gap: 0.25rem;
        margin-bottom: 0.25rem;
    }

    .mode-selector-btn,
    .model-selector-btn {
        min-height: 28px;
        padding: 0.25rem 0.5rem;
    }

    .mode-action-btn {
        width: 28px;
        height: 28px;
    }

    .btn {
        width: 32px;
        height: 32px;
    }

    .messages-area {
        padding: 0.25rem 0.5rem;
    }

    .messages-container {
        gap: 0.5rem;
        padding: 0.5rem;
    }

    .user-bubble {
        padding: 0.5rem 0.75rem;
        font-size: 0.8125rem;
    }

    /* Panels в landscape */
    .chats-panel.active {
        max-width: 280px;
    }

    .catalog-container {
        padding: 0.5rem;
    }

    .prompts-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.5rem;
    }

    .prompt-card {
        padding: 0.625rem;
    }

    .prompt-title {
        font-size: 0.8125rem;
    }

    .prompt-description {
        font-size: 0.75rem;
        -webkit-line-clamp: 2;
    }
}

/* ========================================
   TOUCH DEVICE OPTIMIZATIONS
   ======================================== */
@media (hover: none) and (pointer: coarse) {
    /* Отключить hover-эффекты на touch устройствах */
    .catalog-toggle:hover,
    .lang-btn-active:hover,
    .filter-tab:hover,
    .category-chip:hover,
    .prompt-card:hover,
    .chat-item:hover,
    .msg-action-btn:hover,
    .prompt-action-btn:hover,
    .mode-selector-btn:hover,
    .model-selector-btn:hover,
    .mode-action-btn:hover,
    .btn:hover,
    .new-chat-btn:hover,
    .chats-close:hover {
        transform: none;
        box-shadow: none;
    }

    /* Добавить активное состояние вместо hover */
    .catalog-toggle:active,
    .filter-tab:active,
    .category-chip:active,
    .prompt-card:active,
    .chat-item:active,
    .prompt-action-btn:active,
    .btn:active,
    .msg-action-btn:active,
    .mode-selector-btn:active,
    .model-selector-btn:active,
    .new-chat-btn:active,
    .chats-close:active {
        opacity: 0.8;
        transform: scale(0.98);
    }
}

/* ========================================
   HIGH DPI / RETINA DISPLAYS
   ======================================== */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .logo-icon,
    .toggle-icon,
    .mode-icon,
    .model-logo {
        image-rendering: -webkit-optimize-contrast;
    }
}

/* ========================================
   DARK MODE ENHANCEMENTS FOR MOBILE
   ======================================== */
@media (prefers-color-scheme: dark) and (max-width: 767px) {
    body {
        background-attachment: fixed;
    }

    .modal-overlay {
        background: hsl(var(--background) / 0.95);
    }
}

/* ========================================
   REDUCED MOTION
   ======================================== */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }

    .chats-panel,
    .catalog-panel,
    .sidebar-overlay {
        transition: none;
    }
}

/* ========================================
   PRINT STYLES
   ======================================== */
@media print {
    .header,
    .chats-panel,
    .catalog-panel,
    .input-area,
    .modal-overlay,
    .toast-container,
    .sidebar-overlay {
        display: none !important;
    }

    body {
        background: white;
        color: black;
    }

    .messages-area {
        padding: 0;
        overflow: visible;
    }

    .messages-container {
        max-width: none;
    }

    .message-group {
        page-break-inside: avoid;
    }

    .user-bubble {
        background: #f5f5f5;
        border: 1px solid #ddd;
        color: black;
    }

    .markdown-content {
        color: black;
    }

    .markdown-content code {
        background: #f5f5f5;
    }

    .markdown-content pre {
        background: #f5f5f5;
        border: 1px solid #ddd;
    }
}
