html, body {
    margin: 0;
    padding: 0;
    font-family: sans-serif;
    background: #f4f4f5;
}

/* === Контейнер чата === */
#chat-container {
    position: fixed;
    bottom: 0;                /* прижали к низу */
    right: 20px;
    width: 400px;
    height: auto;
    max-height: calc(100vh - 40px); /* аккуратный отступ сверху */
    border-radius: 1rem;
    box-shadow: 0 0 10px rgba(0,0,0,0.15);
    background: white;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* === Шапка === */
.chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #002d72;
    color: rgba(255, 255, 255, 0.95);
    padding: 10px 12px;
    border-top-left-radius: 10px;
    border-top-right-radius: 10px;
}

#toggle-fullscreen {
    background: none;
    border: none;
    color: white;
    font-size: 16px;
    cursor: pointer;
    padding: 4px 8px;
}

/* === Верхние контролы (селект дела + роли) === */
.top-controls {
    display: flex;
    flex-direction: column;
    flex: 0 0 auto;          /* не растягиваем */
}

#case-select-container {
    padding: 1rem;
    display: flex;
    gap: 0.5rem;
    justify-content: center;
    background: #f9fafb;
    border-bottom: 1px solid #eee;
}

#case-select-container label {
    align-self: center;
    font-size: 14px;
    color: #333;
}

#case-select {
    padding: 8px 16px;
    margin: 4px;
    border: 1px solid #ccc;
    background-color: #f0f0f0;
    cursor: pointer;
    border-radius: 6px;
    transition: background-color 0.2s;
}

#case-select:hover {
    background-color: #eaeaea;
}

#case-select:focus {
    outline: none;
    box-shadow: 0 0 0 2px rgba(0, 123, 255, 0.25);
}

#role-select {
    padding: 1rem;
    display: flex;
    gap: 0.5rem;
    justify-content: center;
    background: #f9fafb;
    border-bottom: 1px solid #eee;
}

#role-select button {
    padding: 8px 16px;
    margin: 4px;
    border: 1px solid #ccc;
    background-color: #f0f0f0;
    cursor: pointer;
    border-radius: 6px;
    transition: background-color 0.2s;
}

#role-select button:hover {
    background: #eaeaea;
}

#role-select button.active-role {
    background-color: #007bff;
    color: white;
    border-color: #007bff;
}

/* === Сообщения === */
#messages {
    flex: 1 1 auto;          /* занимает всё оставшееся */
    min-height: 200px;           /* критично для флекс-скролла */
    padding: 1rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.message {
    max-width: 85%;
    padding: 1rem;
    border-radius: 1.5rem;
    word-wrap: break-word;
}

.user {
    align-self: flex-end;
    background: #e5e8ed;
    color: #000;
    border-bottom-right-radius: 0;
}

.bot {
    align-self: flex-start;
    background: rgb(3, 27, 78);
    color: white;
    border-bottom-left-radius: 0;
}

/* Индикатор «печатает…» */
.message.loading {
    background: transparent;
}
.message.loading .dot {
    display: inline-block;
    font-weight: bold;
    animation: wave 1s infinite ease-in-out;
    color: black;
}
.message.loading .dot1 { animation-delay: 0s; }
.message.loading .dot2 { animation-delay: 0.2s; }
.message.loading .dot3 { animation-delay: 0.4s; }
@keyframes wave {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-5px); }
}

/* === Футер (поле ввода + кнопка) === */
.chat-footer {
    background: #e5e8ed;
    padding: 1rem;
    display: flex;
    gap: 0.5rem;
    align-items: center;
    flex: 0 0 auto;          /* фикс внизу */
}

.chat-footer textarea {
    flex: 1;
    resize: none;
    padding: 0.5rem 1rem;
    border-radius: 1.5rem;
    border: none;
    outline: none;
    height: 40px;
}

.chat-footer button {
    background: #0061eb;
    color: white;
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 9999px;
    cursor: pointer;
    transition: opacity 0.3s;
}

.chat-footer button:hover {
    opacity: 0.8;
}

/* Мелкие подсказки под сообщениями */
#file-name {
    font-size: 12px;
    color: #666;
    padding: 0 1rem 1rem;
}

#clear-chat {
    text-align: left;
    padding: 6px 10px;
    margin-bottom: -10px;
}

#clear-chat a {
    font-size: 10px;
    color: #666;
    text-decoration: none;
    cursor: pointer;
}

#clear-chat a:hover {
    text-decoration: underline;
}

/* === Полноэкранный режим === */
#chat-container.fullscreen {
    position: fixed;
    inset: 0;                /* top/left/right/bottom: 0 */
    z-index: 9999;
    width: 100vw;
    height: 100vh;
    border-radius: 0;
    background: white;
    display: flex;
    flex-direction: column;
}

/* верхние контролы в одну строку */
#chat-container.fullscreen .top-controls {
    flex-direction: row;
    align-items: center;
    gap: 1rem;
    padding: 0.5rem 1rem;
    border-bottom: 1px solid #eee;
    background: #f9fafb;
}

/* без фоновых полос и лишних бордеров */
#chat-container.fullscreen #case-select-container,
#chat-container.fullscreen #role-select {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0;
    flex: 0 0 auto;
    background: transparent;
    border-bottom: none;
}

/* прокрутка сообщений делает flex, calc(...) не нужен */
#chat-container.fullscreen #messages {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
}
