/* Путь: baby_tracker/web/chat.css */

:root {
    --bg-primary: #f5f5f5;
    --bg-secondary: #efeff4;
    --bg-message-user: #007aff;
    --bg-message-bot: #e5e5ea;
    --bg-typing-dot: #8e8e93;
    --bg-button: #007aff;
    --bg-button-disabled: #c7c7cc;
    
    --text-primary: #000000;
    --text-secondary: #8e8e93;
    --text-white: #ffffff;
    
    --border-color: #c8c7cc;
    
    --radius-bubble: 18px;
    --radius-bubble-tail: 4px;
    --radius-button: 50%;
    --radius-container: 20px;
    
    --transition-fast: 0.2s ease;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg-primary);
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    max-width: 100%;
    background: var(--bg-primary);
}

/* Header */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: var(--bg-secondary);
    border-bottom: 0.5px solid var(--border-color);
}

.header-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.avatar {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-button);
    background: #34c759;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    flex-shrink: 0;
}

.header-text {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.bot-name {
    font-weight: 600;
    font-size: 15px;
    color: var(--text-primary);
}

.bot-status {
    font-size: 13px;
    color: var(--text-secondary);
}

.limits-badge {
    font-size: 15px;
    color: var(--text-secondary);
}

/* Messages */
.messages {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 12px 16px;
    background: var(--bg-primary);
    scroll-behavior: smooth;
}

.message {
    margin-bottom: 12px;
    display: flex;
    animation: fadeIn var(--transition-fast);
}

@keyframes fadeIn {
    from { 
        opacity: 0; 
        transform: translateY(8px); 
    }
    to { 
        opacity: 1; 
        transform: translateY(0); 
    }
}

.user-message {
    justify-content: flex-end;
}

.bot-message {
    justify-content: flex-start;
}

.message-bubble {
    max-width: 70%;
    padding: 8px 12px;
    border-radius: var(--radius-bubble);
    word-wrap: break-word;
    white-space: pre-wrap;
    position: relative;
}

.user-message .message-bubble {
    background: var(--bg-message-user);
    color: var(--text-white);
    border-bottom-right-radius: var(--radius-bubble-tail);
}

.bot-message .message-bubble {
    background: var(--bg-message-bot);
    color: var(--text-primary);
    border-bottom-left-radius: var(--radius-bubble-tail);
}

.message-time {
    font-size: 11px;
    opacity: 0.6;
    margin-top: 4px;
    text-align: right;
}

/* Typing indicator */
.typing-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    justify-content: center;
    background: var(--bg-primary);
    opacity: 0;
    transition: opacity var(--transition-fast);
    pointer-events: none;
}

.typing-indicator.visible {
    opacity: 1;
}

.typing-dots {
    display: flex;
    gap: 4px;
}

.typing-dots span {
    width: 8px;
    height: 8px;
    background: var(--bg-typing-dot);
    border-radius: var(--radius-button);
    animation: bounce 1.4s infinite ease-in-out;
}

.typing-dots span:nth-child(1) {
    animation-delay: -0.32s;
}

.typing-dots span:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes bounce {
    0%, 80%, 100% {
        transform: scale(0.8);
        opacity: 0.5;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

.typing-text {
    font-size: 13px;
    color: var(--text-secondary);
    font-weight: 500;
}

/* Image Preview */
.image-preview-container {
    display: none;
    padding: 8px 16px;
    background: var(--bg-primary);
    border-top: 0.5px solid var(--border-color);
    max-height: 120px;
    overflow-x: auto;
    overflow-y: hidden;
}

.image-preview-container.active {
    display: flex;
    gap: 8px;
}

.preview-item {
    position: relative;
    flex-shrink: 0;
    width: 80px;
    height: 80px;
    border-radius: 8px;
    overflow: hidden;
    background: var(--bg-secondary);
}

.preview-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.preview-item .remove-btn {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.6);
    border: none;
    color: white;
    font-size: 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

.preview-item .remove-btn:active {
    background: rgba(0, 0, 0, 0.8);
}

.preview-item .upload-progress {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: rgba(0, 122, 255, 0.3);
}

.preview-item .upload-progress-bar {
    height: 100%;
    background: var(--bg-button);
    transition: width 0.3s;
}

.input-wrapper {
    background: var(--bg-primary);
    border-top: 0.5px solid var(--border-color);
    padding: 8px 16px calc(20px + env(safe-area-inset-bottom));
}

.input-container {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: var(--bg-secondary);
    border-radius: var(--radius-container);
    padding: 5px 5px 5px 5px;
}

.attach-button {
    width: 34px;
    height: 34px;
    border: none;
    border-radius: var(--radius-button);
    background: transparent;
    color: var(--bg-button);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: opacity var(--transition-fast);
    flex-shrink: 0;
}

.attach-button:active:not(:disabled) {
    opacity: 0.5;
}

.attach-button:disabled {
    color: var(--bg-button-disabled);
    cursor: not-allowed;
}

#messageInput {
    flex: 1;
    min-height: 34px;
    max-height: 120px;
    padding: 8px 8px;
    border: none;
    background: transparent;
    font-size: 16px;
    font-family: inherit;
    resize: none;
    outline: none;
    color: var(--text-primary);
    overflow-y: auto;
}

#messageInput::-webkit-scrollbar {
    display: none;
}

#messageInput::placeholder {
    color: var(--text-secondary);
}

#messageInput:disabled {
    color: var(--bg-button-disabled);
}

.send-button {
    width: 34px;
    height: 34px;
    border: none;
    border-radius: var(--radius-button);
    background: var(--bg-button);
    color: var(--text-white);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: opacity var(--transition-fast);
    flex-shrink: 0;
}

.send-button:active:not(:disabled) {
    opacity: 0.7;
}

.send-button:disabled {
    background: var(--bg-button-disabled);
    cursor: not-allowed;
}

/* Scrollbar */
.messages::-webkit-scrollbar {
    width: 4px;
}

.messages::-webkit-scrollbar-track {
    background: transparent;
}

.messages::-webkit-scrollbar-thumb {
    background: var(--bg-button-disabled);
    border-radius: 2px;
}

.messages::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

.image-preview-container::-webkit-scrollbar {
    height: 4px;
}

.image-preview-container::-webkit-scrollbar-track {
    background: transparent;
}

.image-preview-container::-webkit-scrollbar-thumb {
    background: var(--bg-button-disabled);
    border-radius: 2px;
}
.message-bubble h2 {
    font-size: 1.1em;
    font-weight: 600;
    margin: 10px 0 5px 0;
}

.message-bubble h3 {
    font-size: 1em;
    font-weight: 600;
    margin: 8px 0 4px 0;
}

.message-bubble h4 {
    font-size: 0.95em;
    font-weight: 600;
    margin: 6px 0 3px 0;
}

.message-bubble strong {
    font-weight: 600;
    color: #000;
}

/* Превьюшки изображений в сообщениях */
.message-images {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
    margin-bottom: 6px;
}

.message-image-thumb {
    width: 60px;
    height: 60px;
    object-fit: cover;
    border-radius: 8px;
    cursor: pointer;
}

.user-message .message-image-thumb {
    border: 1px solid rgba(255, 255, 255, 0.3);
}

.bot-message .message-image-thumb {
    border: 1px solid rgba(0, 0, 0, 0.1);
}

.message-text {
    line-height: 1.4;
}

.preview-item.uploading img {
    opacity: 0.5;
    filter: grayscale(30%);
    transition: opacity 0.3s ease, filter 0.3s ease;
}

.preview-item.uploading::after {
    content: '';
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.25);
    pointer-events: none;
}

/* Modal для увеличения фото */
.image-modal {
    display: none;
    position: fixed;
    z-index: 9999;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.9);
    backdrop-filter: blur(4px);
}

.modal-content {
    margin: auto;
    display: block;
    max-width: 90%;
    max-height: 90%;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    border-radius: 8px;
    animation: zoom 0.3s;
}

@keyframes zoom {
    from {transform: translate(-50%, -50%) scale(0.8);}
    to {transform: translate(-50%, -50%) scale(1);}
}

.modal-close {
    position: absolute;
    top: 20px;
    right: 35px;
    color: #fff;
    font-size: 40px;
    font-weight: bold;
    cursor: pointer;
    z-index: 10000;
}

.modal-close:hover {
    color: #bbb;
}

.message-image-thumb {
    cursor: pointer;
    transition: opacity 0.2s;
}

.message-image-thumb:hover {
    opacity: 0.8;
}

/* Стрелки навигации */
.modal-prev,
.modal-next {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background-color: rgba(0, 0, 0, 0.5);
    color: white;
    border: none;
    font-size: 30px;
    padding: 16px 20px;
    cursor: pointer;
    border-radius: 4px;
    transition: background-color 0.3s;
    z-index: 10001;
}

.modal-prev:hover,
.modal-next:hover {
    background-color: rgba(0, 0, 0, 0.8);
}

.modal-prev {
    left: 20px;
}

.modal-next {
    right: 20px;
}

.modal-prev.hidden,
.modal-next.hidden {
    display: none;
}

/* Счетчик фото */
.modal-counter {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background-color: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 14px;
    z-index: 10001;
}

.modal-counter.hidden {
    display: none;
}

/* Кнопка "Прокрутить вниз" */
.scroll-down-button {
    position: fixed;
    right: 16px;
    bottom: 80px; /* Над полем ввода */
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--bg-button);
    color: var(--text-white);
    border: none;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 100;
    opacity: 0;
    visibility: hidden;
    transform: scale(0.8);
    transition: opacity 0.3s ease, visibility 0.3s ease, transform 0.3s ease;
}

.scroll-down-button.visible {
    opacity: 1;
    visibility: visible;
    transform: scale(1);
}

.scroll-down-button:active {
    transform: scale(0.9);
}

.scroll-down-button svg {
    flex-shrink: 0;
}