/* Общие стили */
body {
    min-height: 100vh;
}

/* Страницы входа/регистрации */
.auth-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #1a2332 0%, #2d4159 100%);
    padding: 1rem;
}

.auth-card {
    width: 100%;
    max-width: 420px;
    border-radius: 0.75rem;
}

.auth-logo {
    font-size: 2.2rem;
    color: #0d6efd;
}

/* Раскладка чата */
.chat-layout {
    display: flex;
    height: calc(100vh - 56px);
}

.chat-sidebar {
    width: 280px;
    flex-shrink: 0;
}

.chat-session-list {
    padding: 0.5rem 0;
}

.chat-session-item {
    display: flex;
    align-items: center;
    padding: 0.35rem 0.5rem;
    border-radius: 0.5rem;
    margin: 0 0.35rem 0.15rem;
}

.chat-session-item:hover {
    background: #f1f3f5;
}

.chat-session-item.active {
    background: #e7f1ff;
}

.chat-session-link {
    flex-grow: 1;
    text-decoration: none;
    color: #212529;
    overflow: hidden;
    white-space: nowrap;
}

.chat-session-title {
    font-size: 0.9rem;
}

.chat-session-actions {
    display: none;
    gap: 0.15rem;
}

.chat-session-item:hover .chat-session-actions {
    display: inline-flex;
}

.chat-main {
    flex-grow: 1;
    min-width: 0;
}

.chat-model-select {
    width: auto;
    max-width: 240px;
}

.chat-messages {
    overflow-y: auto;
    padding: 1.5rem 1rem;
    background: #f8f9fa;
}

.chat-empty {
    gap: 0.5rem;
}

.empty-icon {
    font-size: 3.5rem;
    opacity: 0.35;
}

/* Сообщения */
.message {
    display: flex;
    margin-bottom: 1.25rem;
}

.message-user {
    justify-content: flex-end;
}

.message-assistant {
    justify-content: flex-start;
}

.message-body {
    max-width: min(820px, 88%);
    padding: 0.75rem 1rem;
    border-radius: 0.9rem;
    font-size: 0.95rem;
    line-height: 1.55;
    overflow-wrap: break-word;
}

.message-user .message-body {
    background: #0d6efd;
    color: #fff;
    border-bottom-right-radius: 0.2rem;
}

.message-assistant .message-body {
    background: #fff;
    border: 1px solid #e9ecef;
    border-bottom-left-radius: 0.2rem;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

.message-error {
    border-color: #f1aeb5 !important;
}

.message-user .md-render p:last-child,
.message-assistant .md-render p:last-child {
    margin-bottom: 0;
}

.message-user .md-render a {
    color: #fff;
    text-decoration: underline;
}

/* Блок мышления */
.message-thinking {
    margin-bottom: 0.6rem;
    padding: 0.5rem 0.75rem;
    background: #f1f3f5;
    border-left: 3px solid #adb5bd;
    border-radius: 0.4rem;
    font-size: 0.85rem;
    color: #495057;
}

.message-thinking summary {
    cursor: pointer;
    user-select: none;
    font-weight: 600;
    font-size: 0.8rem;
    color: #6c757d;
}

/* Markdown внутри сообщений */
.md-render pre {
    background: #f6f8fa;
    border: 1px solid #e9ecef;
    border-radius: 0.5rem;
    padding: 0.75rem;
    overflow-x: auto;
}

.md-render code {
    font-size: 0.85em;
}

.md-render :not(pre) > code {
    background: rgba(13, 110, 253, 0.08);
    padding: 0.15rem 0.35rem;
    border-radius: 0.3rem;
}

.md-render table {
    border-collapse: collapse;
}

.md-render th,
.md-render td {
    border: 1px solid #dee2e6;
    padding: 0.35rem 0.6rem;
}

.md-render img {
    max-width: 100%;
}

/* Вложения */
.attachment-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
}

.attachment-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.25rem 0.55rem;
    border-radius: 0.45rem;
    font-size: 0.8rem;
    background: rgba(13, 110, 253, 0.08);
    border: 1px solid rgba(13, 110, 253, 0.2);
    color: #0d6efd;
    max-width: 240px;
}

.attachment-chip .attachment-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.attachment-chip .attachment-size {
    color: #6c757d;
    font-size: 0.72rem;
}

.attachment-chip .attachment-remove {
    border: 0;
    background: transparent;
    color: #dc3545;
    padding: 0 0.15rem;
    cursor: pointer;
}

.attachment-chip-draft {
    background: #fff;
    border-style: dashed;
    cursor: default;
}

/* Композер */
.chat-composer textarea {
    resize: none;
    max-height: 200px;
}

/* Админка */
.admin-stat-icon {
    font-size: 1.6rem;
}

.table-actions {
    white-space: nowrap;
}

.sidebar-toggle {
    display: none;
}

/* Индикатор заполненности контекста */
.context-meter {
    height: 6px;
    background: #e9ecef;
    border-radius: 4px;
    overflow: hidden;
}

.context-meter-fill {
    height: 100%;
    background: #198754;
    border-radius: 4px;
    transition: width 0.5s ease, background-color 0.3s ease;
}

.context-meter-fill.fill-warning {
    background: #fd7e14;
}

.context-meter-fill.fill-danger {
    background: #dc3545;
}

.chat-sidebar-backdrop {
    display: none;
}

@media (max-width: 768px) {
    .sidebar-toggle {
        display: inline-flex;
    }

    .chat-layout {
        display: block;
        height: auto;
    }

    /* Сайдбар — выдвижная панель */
    .chat-sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        z-index: 1050;
        width: min(300px, 85vw);
        max-height: none;
        transform: translateX(-105%);
        transition: transform 0.25s ease;
        box-shadow: 2px 0 14px rgba(0, 0, 0, 0.18);
    }

    .chat-sidebar.open {
        transform: translateX(0);
    }

    .chat-sidebar-backdrop {
        position: fixed;
        inset: 0;
        z-index: 1040;
        background: rgba(0, 0, 0, 0.45);
    }

    .chat-sidebar-backdrop.show {
        display: block;
    }

    .chat-main {
        height: calc(100dvh - 56px);
    }

    .chat-header {
        padding: 0.5rem 0.75rem;
    }

    #chatTitle {
        font-size: 0.95rem;
    }

    .chat-messages {
        padding: 1rem 0.75rem;
    }

    .chat-model-select {
        max-width: 150px;
    }

    .message-body {
        max-width: 92%;
    }

    .chat-composer {
        padding: 0.6rem 0.75rem !important;
        padding-bottom: max(0.6rem, env(safe-area-inset-bottom)) !important;
    }

    .container-fluid {
        padding-left: 0.75rem;
        padding-right: 0.75rem;
    }
}
