* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary: #6366f1;
    --primary-dark: #4f46e5;
    --primary-light: #818cf8;
    --gradient: linear-gradient(135deg, #6366f1 0%, #8b5cf6 50%, #a855f7 100%);
    --user-gradient: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
    --assistant-bg: #f8fafc;
    --assistant-border: #e2e8f0;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --bg-light: #f1f5f9;
    --white: #ffffff;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 20px 50px rgba(0, 0, 0, 0.15);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 20px;
    --radius-xl: 24px;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 50%, #f093fb 100%);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
}

.container {
    width: 100%;
    max-width: 950px;
    background: var(--white);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    height: 92vh;
}

/* ===== HEADER ===== */
header {
    background: var(--gradient);
    color: var(--white);
    padding: 18px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 16px;
    position: relative;
    overflow: hidden;
}

header::before {
    content: '';
    position: absolute;
    top: -50%;
    right: -20%;
    width: 300px;
    height: 300px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 50%;
    pointer-events: none;
}

header::after {
    content: '';
    position: absolute;
    bottom: -60%;
    left: -10%;
    width: 200px;
    height: 200px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 50%;
    pointer-events: none;
}

.title {
    display: flex;
    flex-direction: column;
    gap: 6px;
    z-index: 1;
}

header h1 {
    font-size: 22px;
    font-weight: 700;
    letter-spacing: -0.5px;
    display: flex;
    align-items: center;
    gap: 10px;
}

header h1::before {
    content: '🤖';
    font-size: 24px;
}

.subtitle {
    font-size: 13px;
    opacity: 0.9;
    display: flex;
    align-items: center;
    gap: 6px;
    font-weight: 500;
}

/* Status Indicator */
.status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #ef4444;
    display: inline-block;
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.3);
    transition: all 0.3s ease;
}

.subtitle.online .status-dot {
    background: #22c55e;
    box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.3);
    animation: pulse-green 2s infinite;
}

@keyframes pulse-green {
    0%, 100% { box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.3); }
    50% { box-shadow: 0 0 0 6px rgba(34, 197, 94, 0.1); }
}

/* Controls */
.controls {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    z-index: 1;
}

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

.control-group label {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    opacity: 0.8;
    font-weight: 600;
}

.model-selector,
.small-control {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.model-selector label,
.small-control label {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    opacity: 0.8;
    font-weight: 600;
    color: white;
}

.model-selector select,
.small-control input,
.small-control select {
    padding: 10px 14px;
    border: none;
    border-radius: var(--radius-sm);
    background: rgba(255, 255, 255, 0.15);
    color: var(--white);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    backdrop-filter: blur(10px);
    transition: all 0.2s ease;
    outline: none;
    min-width: 100px;
}

.model-selector select:hover,
.small-control input:hover,
.small-control select:hover {
    background: rgba(255, 255, 255, 0.25);
}

.model-selector select:focus,
.small-control input:focus,
.small-control select:focus {
    background: rgba(255, 255, 255, 0.3);
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.3);
}

.model-selector select option,
.small-control select option {
    background: var(--primary);
    color: white;
}

.small-control input[type="number"] {
    width: 80px;
}

/* ===== CHAT CONTAINER ===== */
.chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--bg-light);
}

/* Messages Area */
.messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    scroll-behavior: smooth;
}

/* Empty State */
.messages:empty::before {
    content: '💬 Начните диалог, отправив сообщение';
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-secondary);
    font-size: 15px;
    text-align: center;
}

/* Message Styles */
.message {
    display: flex;
    gap: 12px;
    animation: messageIn 0.4s cubic-bezier(0.16, 1, 0.3, 1);
    max-width: 100%;
}

@keyframes messageIn {
    from {
        opacity: 0;
        transform: translateY(15px) scale(0.98);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.message.user {
    flex-direction: row-reverse;
}

/* Avatar */
.message-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
    box-shadow: var(--shadow-sm);
}

.message.user .message-avatar {
    background: var(--user-gradient);
    color: var(--white);
}

.message.assistant .message-avatar {
    background: var(--white);
    border: 2px solid var(--assistant-border);
}

/* Message Content */
.message-content {
    max-width: 70%;
    padding: 14px 18px;
    border-radius: var(--radius-lg);
    line-height: 1.6;
    word-wrap: break-word;
    font-size: 14px;
    position: relative;
    white-space: pre-wrap;
}

.message.user .message-content {
    background: var(--user-gradient);
    color: var(--white);
    border-bottom-right-radius: 6px;
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.25);
}

.message.assistant .message-content {
    background: var(--white);
    color: var(--text-primary);
    border: 1px solid var(--assistant-border);
    border-bottom-left-radius: 6px;
    box-shadow: var(--shadow-sm);
}

/* Message Time */
.message-time {
    font-size: 10px;
    opacity: 0.6;
    margin-top: 6px;
    display: block;
}

.message.user .message-time {
    text-align: right;
}

/* File Attachment */
.message-file {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: var(--radius-sm);
    margin-top: 8px;
    font-size: 13px;
}

.message.assistant .message-file {
    background: var(--bg-light);
}

.message-file-icon {
    font-size: 20px;
}

.message-file-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.message-file-size {
    opacity: 0.7;
    font-size: 11px;
}

/* ===== INPUT AREA ===== */
.input-container {
    padding: 16px 24px 20px;
    background: var(--white);
    border-top: 1px solid var(--assistant-border);
    display: flex;
    gap: 12px;
    align-items: flex-end;
}

.input-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.input-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

/* File Upload Button */
.file-upload-btn {
    width: 40px;
    height: 40px;
    border: 2px dashed var(--assistant-border);
    border-radius: var(--radius-sm);
    background: var(--bg-light);
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    position: relative;
    overflow: hidden;
}

.file-upload-btn:hover {
    border-color: var(--primary);
    color: var(--primary);
    background: rgba(99, 102, 241, 0.05);
}

.file-upload-btn input[type="file"] {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
}

.file-upload-btn svg {
    width: 20px;
    height: 20px;
}

/* Selected File Preview */
.selected-file {
    display: none;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: var(--bg-light);
    border-radius: var(--radius-sm);
    font-size: 12px;
    color: var(--text-secondary);
}

.selected-file.visible {
    display: flex;
}

.selected-file-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.selected-file-remove {
    width: 20px;
    height: 20px;
    border: none;
    border-radius: 50%;
    background: var(--assistant-border);
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.selected-file-remove:hover {
    background: #ef4444;
    color: white;
}

/* Textarea */
.input-row {
    display: flex;
    gap: 12px;
    align-items: flex-end;
}

#userInput {
    flex: 1;
    padding: 14px 16px;
    border: 2px solid var(--assistant-border);
    border-radius: var(--radius-md);
    font-size: 15px;
    font-family: inherit;
    resize: none;
    outline: none;
    transition: all 0.2s ease;
    min-height: 52px;
    max-height: 150px;
    line-height: 1.5;
}

#userInput:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

#userInput::placeholder {
    color: var(--text-secondary);
}

/* Send Button */
.send-btn {
    width: 52px;
    height: 52px;
    border: none;
    border-radius: var(--radius-md);
    background: var(--gradient);
    color: var(--white);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    flex-shrink: 0;
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.3);
}

.send-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(99, 102, 241, 0.4);
}

.send-btn:active {
    transform: translateY(0);
}

.send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.send-btn svg {
    width: 22px;
    height: 22px;
}

/* ===== STATUS BAR ===== */
.status {
    padding: 10px 24px;
    text-align: center;
    font-size: 12px;
    color: var(--text-secondary);
    background: var(--white);
    min-height: 20px;
    border-top: 1px solid var(--bg-light);
}

/* Loading Animation */
.loading {
    display: inline-flex;
    gap: 5px;
    align-items: center;
}

.loading-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--primary);
    animation: bounce 1.4s infinite ease-in-out both;
}

.loading-dot:nth-child(1) { animation-delay: -0.32s; }
.loading-dot:nth-child(2) { animation-delay: -0.16s; }

@keyframes bounce {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1); }
}

/* Typing Indicator */
.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 12px 16px;
    background: var(--white);
    border-radius: var(--radius-lg);
    border: 1px solid var(--assistant-border);
    width: fit-content;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--primary-light);
    animation: typing 1.4s infinite;
}

.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-6px); }
}

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--assistant-border);
    border-radius: 10px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
    body {
        padding: 0;
    }

    .container {
        height: 100vh;
        border-radius: 0;
        max-width: 100%;
    }

    header {
        padding: 14px 16px;
        flex-direction: column;
        align-items: flex-start;
    }

    header h1 {
        font-size: 18px;
    }

    .controls {
        width: 100%;
        justify-content: flex-start;
    }

    .messages {
        padding: 16px;
        gap: 12px;
    }

    .message-content {
        max-width: 85%;
        padding: 12px 14px;
        font-size: 14px;
    }

    .message-avatar {
        width: 32px;
        height: 32px;
        font-size: 14px;
    }

    .input-container {
        padding: 12px 16px 16px;
    }

    #userInput {
        font-size: 16px; /* Prevents zoom on iOS */
    }

    .send-btn {
        width: 48px;
        height: 48px;
    }

    .small-control input[type="number"] {
        width: 70px;
    }
}

/* ===== DARK MODE (optional support) ===== */
@media (prefers-color-scheme: dark) {
    /* Can be enabled if needed */
}
