/* Mobile Chat Styles - отдельный мобильный чат */

.mobile-chat-wrapper {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100vw;
    max-width: 100vw;
    height: 100vh;
    background: var(--color-bg-primary);
    z-index: 20; /* Ниже адаптивного меню (z-index: 52) */
    display: none;
    flex-direction: column;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

.mobile-chat-wrapper.open {
    display: flex;
    opacity: 1;
    visibility: visible;
}

.mobile-chat-panel {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    position: relative;
    width: 100%;
    box-sizing: border-box;
    background: var(--color-bg-chat);
    padding-top: calc(56px + env(safe-area-inset-top)); /* Отступ для адаптивного меню */
}

.mobile-chat-messages {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: var(--spacing-lg);
    padding-bottom: 200px;
    display: flex;
    flex-direction: column;
    gap: var(--spacing-lg);
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
    width: 100%;
    box-sizing: border-box;
}

/* Message styles - синхронизированы с десктопным чатом */
.mobile-chat-messages .message {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-xs);
    width: 100%;
    margin-bottom: var(--spacing-md);
}

.mobile-chat-messages .message.user {
    align-items: flex-end;
    justify-content: flex-end;
}

.mobile-chat-messages .message.ai {
    align-items: flex-start;
    justify-content: flex-start;
}

.mobile-chat-messages .message-bubble {
    max-width: 75%;
    padding: var(--spacing-md) var(--spacing-lg);
    border-radius: var(--radius-lg);
    font-size: var(--font-size-md);
    line-height: var(--line-height-normal);
    font-family: var(--font-primary);
    word-wrap: break-word;
    word-break: break-word;
    overflow-wrap: break-word;
    position: relative;
    text-align: left;
    box-sizing: border-box;
    min-width: 0;
}

.mobile-chat-messages .message.user .message-bubble {
    background: #ffffff;
    color: #000000 !important;
    border-bottom-right-radius: 4px;
}

.mobile-chat-messages .message.user .message-bubble * {
    color: #000000 !important;
}

.mobile-chat-messages .message.ai .message-bubble {
    background: #2a2a2a;
    color: #ffffff !important;
    border-bottom-left-radius: 4px;
    max-width: 100%;
    width: 100%;
}

.mobile-chat-messages .message.ai .message-bubble * {
    color: #ffffff !important;
}

.mobile-chat-messages .message-time {
    font-size: var(--font-size-xs);
    color: var(--color-text-tertiary);
    margin-top: 2px;
    text-align: left;
    font-family: var(--font-primary);
}

.mobile-chat-messages .message.user .message-time {
    color: var(--color-text-secondary);
}

.mobile-chat-messages .message-status {
    display: flex;
    align-items: center;
    margin-top: var(--spacing-sm);
    font-size: var(--font-size-xs);
    color: var(--color-text-tertiary);
    font-family: var(--font-primary);
    justify-content: flex-start;
}

.mobile-chat-messages .message.user .message-status {
    color: var(--color-text-secondary);
}

/* Light theme для сообщений */
body.light-theme .mobile-chat-panel {
    background: rgb(255, 255, 255);
}

body.light-theme .mobile-chat-messages {
    background-color: transparent;
}

body.light-theme .mobile-chat-messages .message.user .message-bubble {
    background: #f5f5f5;
    color: #000000;
}

body.light-theme .mobile-chat-messages .message.user .message-bubble * {
    color: #000000 !important;
}

body.light-theme .mobile-chat-messages .message.ai .message-bubble {
    background: #e5e5e5;
    color: #000000;
}

body.light-theme .mobile-chat-messages .message.ai .message-bubble * {
    color: #000000 !important;
}

body.light-theme .mobile-chat-messages .message.ai .message-bubble p,
body.light-theme .mobile-chat-messages .message.ai .message-bubble span,
body.light-theme .mobile-chat-messages .message.ai .message-bubble div {
    color: #000000 !important;
}

/* Старый стиль (удален) */
body.light-theme .mobile-chat-messages .message.ai .message-bubble.old {
    background: #121212;
    color: #ffffff;
}

body.light-theme .mobile-chat-messages .message-time {
    color: #9ca3af;
}

body.light-theme .mobile-chat-messages .message-status {
    color: #9ca3af;
}

/* Mobile Chat Input Area - скопировано из десктопного чата */
.mobile-chat-input-area {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: var(--spacing-xl);
    /* Внизу плотный фон, вверх уходит в прозрачность (тёмная тема) */
    background: var(--color-bg-chat-input-area);
    border-radius: 0 0 var(--radius-xl) var(--radius-xl);
    z-index: 10;
    box-sizing: border-box;
    overflow: hidden;
}

/* Адаптация padding для маленьких экранов */
@media (max-width: 445px) {
    .mobile-chat-input-area {
        padding: var(--spacing-md);
    }
    
    .mobile-chat-input-wrapper {
        padding: var(--spacing-lg);
    }
}

.mobile-chat-input-wrapper {
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    padding: var(--spacing-2xl);
    gap: var(--spacing-lg);
    width: 100%;
    min-height: auto;
    height: auto;
    background: var(--color-bg-input);
    border-radius: var(--radius-2xl);
    position: relative;
    border: 1px solid var(--color-border-primary);
    box-shadow: var(--shadow-md);
    transition: background-color var(--transition-base), border-color var(--transition-base), box-shadow var(--transition-base);
}

.mobile-chat-input-wrapper:focus-within {
    background: var(--color-bg-input-focus);
    border-color: var(--color-border-primary);
}

/* Content */
.mobile-chat-input-content {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    align-items: flex-start;
    padding: 0px;
    gap: var(--spacing-lg);
    width: 100%;
    min-height: auto;
    height: auto;
    flex: none;
    order: 0;
    align-self: stretch;
    flex-grow: 1;
}

/* Input Field */
.mobile-chat-input-field {
    margin: 0 auto;
    width: 100%;
    min-height: 23px;
    height: auto;
    font-family: var(--font-primary);
    font-style: normal;
    font-weight: var(--font-weight-normal);
    font-size: var(--font-size-xl);
    line-height: var(--line-height-normal);
    color: var(--color-input-text);
    background: none;
    border: none;
    outline: none;
    padding: 0 0 0 4px;
    flex: none;
    order: 0;
    align-self: stretch;
    flex-grow: 0;
    resize: none;
    overflow: hidden;
    white-space: pre-wrap;
    word-wrap: break-word;
}

/* Светлая тема: текст в инпуте — чисто чёрный */
body.light-theme .mobile-chat-input-field {
    color: #000000;
}

body.light-theme .mobile-chat-input-field:-webkit-autofill,
body.light-theme .mobile-chat-input-field:-webkit-autofill:hover,
body.light-theme .mobile-chat-input-field:-webkit-autofill:focus,
body.light-theme .mobile-chat-input-field:-webkit-autofill:active {
    -webkit-text-fill-color: #000000 !important;
}

.mobile-chat-input-field::placeholder {
    opacity: 0.5;
}

.mobile-chat-input-field:focus::placeholder {
    opacity: 0;
}

/* Отключение автозаполнения браузера */
.mobile-chat-input-field:-webkit-autofill,
.mobile-chat-input-field:-webkit-autofill:hover,
.mobile-chat-input-field:-webkit-autofill:focus,
.mobile-chat-input-field:-webkit-autofill:active {
    -webkit-box-shadow: 0 0 0 30px #232323 inset !important;
    -webkit-text-fill-color: #CCCCCC !important;
    transition: background-color 5000s ease-in-out 0s;
}

/* Thumbnails Container */
.mobile-chat-input-thumbnails {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: var(--spacing-sm);
    width: 100%;
    flex-wrap: wrap;
    flex: none;
    order: 1;
    align-self: stretch;
    flex-grow: 0;
}

/* Block */
.mobile-chat-input-block {
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    padding: 0px;
    gap: 204px;
    margin: 0 auto;
    width: 100%;
    height: 36px;
    flex: none;
    order: 2;
    align-self: stretch;
    flex-grow: 0;
    position: relative;
    min-width: 0;
    box-sizing: border-box;
}

/* Адаптация для маленьких экранов (320-445px) */
@media (max-width: 445px) {
    .mobile-chat-input-block {
        gap: var(--spacing-sm);
        justify-content: space-between;
        padding-right: 0;
    }
    
    .mobile-chat-input-links {
        flex-shrink: 0;
        min-width: auto;
        order: 0;
    }
    
    .mobile-chat-input-primary-wrapper {
        flex-shrink: 0;
        min-width: 32px;
        order: 1;
    }
    
    .mobile-chat-input-primary-btn {
        position: relative;
        right: auto;
        top: auto;
    }
}

/* Links */
.mobile-chat-input-links {
    display: flex;
    flex-direction: row;
    align-items: center;
    padding: 0px;
    gap: var(--spacing-xs);
    width: 120px;
    height: var(--spacing-4xl);
    flex: none;
    order: 0;
    flex-grow: 0;
}

/* Button Add */
.mobile-chat-input-add-btn {
    display: flex;
    flex-direction: row;
    justify-content: center;
    align-items: center;
    padding: var(--spacing-sm);
    gap: var(--spacing-xs);
    width: var(--spacing-4xl);
    height: var(--spacing-4xl);
    border-radius: var(--radius-circle);
    border: none;
    background: none;
    cursor: pointer;
    flex: none;
    order: 0;
    flex-grow: 0;
    opacity: 0.5;
    transition: background var(--transition-base), opacity var(--transition-base);
}

.mobile-chat-input-add-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    opacity: 1;
}

.mobile-chat-input-add-icon {
    width: var(--spacing-2xl);
    height: var(--spacing-2xl);
    flex: none;
    order: 0;
    flex-grow: 0;
}

/* Button Micro */
.mobile-chat-input-micro-btn {
    display: flex;
    flex-direction: row;
    justify-content: center;
    align-items: center;
    padding: var(--spacing-sm);
    gap: var(--spacing-xs);
    width: var(--spacing-4xl);
    height: var(--spacing-4xl);
    border-radius: var(--radius-circle);
    border: none;
    background: none;
    cursor: pointer;
    flex: none;
    order: 2;
    flex-grow: 0;
    opacity: 0.5;
    transition: background var(--transition-base), opacity var(--transition-base);
    position: relative;
    z-index: 10;
    pointer-events: auto;
}

.mobile-chat-input-micro-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    opacity: 1;
}

.mobile-chat-input-micro-btn.active {
    background: var(--color-button-primary) !important;
    opacity: 1;
    color: #ffffff !important;
}

/* В активном состоянии ВСЕ дочерние элементы белые */
.mobile-chat-input-micro-btn.active,
.mobile-chat-input-micro-btn.active *,
.mobile-chat-input-micro-btn.active .mobile-chat-input-micro-icon,
.mobile-chat-input-micro-btn.active .mobile-chat-input-micro-icon *,
.mobile-chat-input-micro-btn.active .mobile-chat-input-micro-icon svg,
.mobile-chat-input-micro-btn.active .mobile-chat-input-micro-icon-svg,
.mobile-chat-input-micro-btn.active .mobile-chat-input-micro-icon-svg svg,
.mobile-chat-input-micro-btn.active .mobile-chat-input-micro-icon svg path,
.mobile-chat-input-micro-btn.active .mobile-chat-input-micro-icon-svg svg path {
    color: #ffffff !important;
}

/* SVG path использует currentColor, поэтому будет белым */
.mobile-chat-input-micro-btn.active .mobile-chat-input-micro-icon svg path,
.mobile-chat-input-micro-btn.active .mobile-chat-input-micro-icon-svg svg path {
    stroke: currentColor !important;
    stroke-opacity: 1 !important;
}

/* Активное состояние + hover - иконка остается белой */
.mobile-chat-input-micro-btn.active:hover {
    background: var(--color-button-primary) !important;
    color: #ffffff !important;
}

.mobile-chat-input-micro-btn.active:hover *,
.mobile-chat-input-micro-btn.active:hover .mobile-chat-input-micro-icon svg path,
.mobile-chat-input-micro-btn.active:hover .mobile-chat-input-micro-icon-svg svg path {
    color: #ffffff !important;
    stroke: currentColor !important;
}

.mobile-chat-input-micro-icon {
    width: var(--spacing-2xl);
    height: var(--spacing-2xl);
    flex: none;
    order: 0;
    flex-grow: 0;
    color: inherit;
}

.mobile-chat-input-micro-icon svg,
.mobile-chat-input-micro-icon-svg {
    color: inherit;
}

.mobile-chat-input-micro-icon svg path,
.mobile-chat-input-micro-icon-svg svg path {
    stroke: currentColor;
}

/* ПРИНУДИТЕЛЬНО белая иконка в активном состоянии (даже без hover) */
.mobile-chat-input-micro-btn.active .mobile-chat-input-micro-icon,
.mobile-chat-input-micro-btn.active .mobile-chat-input-micro-icon-svg {
    color: #ffffff !important;
}

.mobile-chat-input-micro-btn.active .mobile-chat-input-micro-icon svg,
.mobile-chat-input-micro-btn.active .mobile-chat-input-micro-icon-svg svg {
    color: #ffffff !important;
}

.mobile-chat-input-micro-btn.active .mobile-chat-input-micro-icon svg path,
.mobile-chat-input-micro-btn.active .mobile-chat-input-micro-icon-svg svg path {
    stroke: currentColor !important;
    stroke-opacity: 1 !important;
    fill: none !important;
}

/* Primary Wrapper with Gradient */
.mobile-chat-input-primary-wrapper {
    position: relative;
    width: 32px;
    height: 32px;
    flex: none;
    order: 1;
    flex-grow: 0;
}

/* Gradient under primary button */
.mobile-chat-input-gradient {
    position: absolute;
    width: 100px;
    height: 76px;
    left: calc(50% - 100px/2);
    top: -20px;
    background: #33312F;
    background: color(display-p3 0.200 0.192 0.184);
    filter: blur(28px);
    z-index: 0;
    opacity: 0;
    transition: opacity 0.2s ease;
}

/* Показать градиент только когда кнопка активна */
.mobile-chat-input-primary-wrapper:has(.mobile-chat-input-primary-btn:not(:disabled)) .mobile-chat-input-gradient {
    opacity: 1;
}

/* Button Primary */
.mobile-chat-input-primary-btn {
    display: flex;
    flex-direction: row;
    justify-content: center;
    align-items: center;
    padding: 0;
    gap: 0;
    position: absolute;
    width: var(--spacing-4xl);
    height: var(--spacing-4xl);
    right: 0px;
    top: 0px;
    background: var(--color-text-primary); /* белый фон в темной теме (#ffffff) */
    color: var(--color-text-inverse); /* черный цвет стрелки в темной теме на белом фоне (#000000) */
    border-radius: var(--radius-3xl);
    border: none;
    cursor: pointer;
    flex: none;
    order: 0;
    flex-grow: 0;
    z-index: 1;
    transition: opacity var(--transition-base);
}

.mobile-chat-input-primary-btn:hover:not(:disabled) {
    opacity: 0.9;
}

.mobile-chat-input-primary-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.mobile-chat-input-primary-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    flex: none;
    order: 0;
    flex-grow: 0;
}

/* Точная центровка SVG‑стрелки внутри кнопки отправки */
.mobile-chat-input-primary-icon-svg {
    display: block;
    margin: 0 auto;
    color: var(--color-text-inverse); /* черный цвет стрелки на белом фоне */
}

/* Темная тема: черная стрелка на белом фоне */
body:not(.light-theme) .mobile-chat-input-primary-icon-svg {
    color: var(--color-text-inverse);
}

body:not(.light-theme) .mobile-chat-input-primary-icon-svg svg {
    fill: var(--color-text-inverse);
}

body:not(.light-theme) .mobile-chat-input-primary-icon-svg svg path {
    fill: var(--color-text-inverse) !important;
}

/* Светлая тема: градиент и тень для инпута чата */
body.light-theme .mobile-chat-input-area {
    background: linear-gradient(to top, #ffffff 0%, rgba(18, 18, 18, 0) 100%);
}

body.light-theme .mobile-chat-input-wrapper {
    box-shadow: var(--shadow-md);
    border: 1px solid transparent; /* Transparent border for smooth appearance */
}

/* Светлая тема: более чистый, мягкий градиент под кнопкой отправки */
body.light-theme .mobile-chat-input-gradient {
    background: color(display-p3 0.92 0.92 0.92);
    opacity: 0.7;
}

/* Светлая тема: чёрная кнопка, белая иконка (currentColor работает от color) */
body.light-theme .mobile-chat-input-primary-btn {
    background: #000000;
    color: #ffffff;
}

/* Светлая тема: add — чёрная активная кнопка с белой иконкой (как send/micro) */
body.light-theme .mobile-chat-input-add-btn {
    color: #6b7280; /* серый плюс по умолчанию */
}

body.light-theme .mobile-chat-input-add-btn.active {
    background: #000000;
    color: #ffffff;
    opacity: 1;
}

/* Светлая тема: micro — серый микрофон по умолчанию */
body.light-theme .mobile-chat-input-micro-btn {
    color: #6b7280; /* серый микрофон по умолчанию */
}

/* Светлая тема: активный микрофон — зеленая кнопка с белой иконкой */
body.light-theme .mobile-chat-input-micro-btn.active {
    background: var(--color-button-primary);
    color: #ffffff;
}

/* В light‑теме для активного микрофона белая иконка */
body.light-theme .mobile-chat-input-micro-btn.active .mobile-chat-input-micro-icon {
    color: #ffffff !important;
    filter: none !important;
}

body.light-theme .mobile-chat-input-micro-btn.active .mobile-chat-input-micro-icon svg,
body.light-theme .mobile-chat-input-micro-btn.active .mobile-chat-input-micro-icon-svg {
    color: #ffffff !important;
    filter: none !important;
}

body.light-theme .mobile-chat-input-micro-btn.active .mobile-chat-input-micro-icon svg path,
body.light-theme .mobile-chat-input-micro-btn.active .mobile-chat-input-micro-icon-svg svg path {
    stroke: #ffffff !important;
    fill: none !important;
}

body.light-theme .mobile-chat-input-micro-btn.active .mobile-chat-input-micro-icon svg,
body.light-theme .mobile-chat-input-micro-btn.active .mobile-chat-input-micro-icon-svg {
    filter: brightness(0) invert(1);
}

body.light-theme .mobile-chat-input-micro-btn.active .mobile-chat-input-micro-icon svg path,
body.light-theme .mobile-chat-input-micro-btn.active .mobile-chat-input-micro-icon-svg svg path {
    stroke: #ffffff !important;
    stroke-opacity: 1 !important;
}

body.light-theme .mobile-chat-input-micro-btn.active .mobile-chat-input-micro-icon svg path,
body.light-theme .mobile-chat-input-micro-btn.active .mobile-chat-input-micro-icon-svg svg path {
    stroke: #ffffff !important;
    stroke-opacity: 1 !important;
}

/* Светлая тема: более заметный hover для круглых иконок чата */
body.light-theme .mobile-chat-input-add-btn:hover,
body.light-theme .mobile-chat-input-micro-btn:hover {
    background: rgba(0, 0, 0, 0.06);
    opacity: 1;
}

/* Mobile Chat Toggle Button - скрыт, не используется */
.mobile-chat-toggle {
    display: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
    pointer-events: none !important;
}

.mobile-chat-toggle:hover {
    background: var(--color-button-primary-hover);
    transform: scale(1.05);
}

.mobile-chat-toggle-icon {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.9;
}

.mobile-chat-toggle-label {
    font-size: 10px;
    font-weight: var(--font-weight-medium);
    color: #ffffff;
    line-height: 1;
}

.mobile-chat-toggle-indicator {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 8px;
    height: 8px;
    border-radius: var(--radius-full);
    background: var(--color-success);
    display: none;
}

.mobile-chat-toggle-indicator:not(.hidden) {
    display: block;
}

/* Скрываем chat-minimized на мобильных */
@media (max-width: 800px) {
    .chat-minimized {
        display: none !important;
    }
}

/* Light theme */
body.light-theme .mobile-chat-wrapper {
    background: #ffffff;
}


/* Topic suggestions styles - синхронизированы с десктопным */
.mobile-chat-messages .topics-container {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: var(--spacing-lg);
    margin-bottom: var(--spacing-lg);
}

.mobile-chat-messages .topic-section {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
    width: 100%;
}

.mobile-chat-messages .topic-section-title {
    font-family: var(--font-primary);
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-medium);
    color: var(--color-text-secondary);
    margin-bottom: var(--spacing-xs);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.mobile-chat-messages .topic-suggestions-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: var(--spacing-sm);
    width: 100%;
}

.mobile-chat-messages .topic-suggestion-btn {
    display: inline-flex;
    align-items: center;
    justify-content: flex-start;
    padding: var(--spacing-sm) var(--spacing-md);
    background: rgba(255, 255, 255, 0.08);
    border: none;
    border-radius: var(--radius-xl);
    color: var(--color-text-primary);
    font-family: var(--font-primary);
    font-size: var(--font-size-md);
    font-weight: var(--font-weight-normal);
    cursor: pointer;
    transition: background-color 0.15s ease, color 0.15s ease;
    text-align: left;
    -webkit-font-smoothing: antialiased;
    contain: layout style paint;
}

.mobile-chat-messages .topic-suggestion-btn:hover {
    background: rgba(255, 255, 255, 0.12);
}

body.light-theme .mobile-chat-messages .topic-suggestion-btn {
    background: rgba(0, 0, 0, 0.05);
    color: rgba(0, 0, 0, 0.8);
}

body.light-theme .mobile-chat-messages .topic-suggestion-btn:hover {
    background: rgba(0, 0, 0, 0.1);
}
