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;
}

/* ============================================= */
/* === Стили для страницы брифов (case_brief.html) === */
/* ============================================= */

#brief-container {
    max-width: 900px;
    margin: 2rem auto;
    background: white;
    border-radius: 1rem;
    box-shadow: 0 0 10px rgba(0,0,0,0.15);
    overflow: hidden;
}

.brief-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #002d72;
    color: rgba(255, 255, 255, 0.95);
    padding: 1rem 1.5rem;
    font-size: 1.25rem;
    font-weight: 600;
}

#brief-form {
    padding: 2rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    border-bottom: 1px solid #eee;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.form-group label {
    font-weight: 500;
    color: #333;
}

.checkbox-group {
    flex-direction: row;
    align-items: center;
}

.checkbox-group label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: normal;
    cursor: pointer;
}

.checkbox-group input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
}

#brief-form input[type="text"] {
    padding: 0.75rem 1rem;
    border: 1px solid #ccc;
    border-radius: 0.5rem;
    font-size: 16px;
    transition: border-color 0.2s;
}

#brief-form input[type="text"]:focus {
    outline: none;
    border-color: #0061eb;
    box-shadow: 0 0 0 2px rgba(0, 97, 235, 0.1);
}

#brief-form button[type="submit"] {
    background: #0061eb;
    color: white;
    padding: 1rem;
    border: none;
    border-radius: 0.5rem;
    cursor: pointer;
    font-size: 16px;
    font-weight: 600;
    transition: opacity 0.3s, background 0.3s;
}

#brief-form button[type="submit"]:hover:not(:disabled) {
    background: #0052c9;
}

#brief-form button[type="submit"]:disabled {
    background: #ccc;
    cursor: not-allowed;
    opacity: 0.6;
}

#brief-form input:disabled,
#brief-form input[type="checkbox"]:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

#loading-indicator {
    padding: 3rem 2rem;
    text-align: center;
    background: #f9fafb;
}

.loading-text {
    font-size: 1rem;
    color: #666;
    margin-bottom: 1rem;
}

.loading-dots {
    display: flex;
    justify-content: center;
    gap: 0.25rem;
    font-size: 2rem;
}

.loading-dots .dot {
    display: inline-block;
    font-weight: bold;
    animation: wave 1s infinite ease-in-out;
    color: #666;
}

.loading-dots .dot1 { animation-delay: 0s; }
.loading-dots .dot2 { animation-delay: 0.2s; }
.loading-dots .dot3 { animation-delay: 0.4s; }

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

#brief-result {
    padding: 2rem;
}

#brief-result:empty {
    display: none;
}

.brief-meta {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    padding: 1rem;
    background: #f9fafb;
    border-radius: 0.5rem;
    margin-bottom: 2rem;
    border: 1px solid #e5e8ed;
}

.meta-item {
    font-size: 14px;
}

.meta-item strong {
    display: block;
    color: #666;
    font-weight: 600;
    margin-bottom: 0.25rem;
}

.brief-content {
    line-height: 1.8;
    color: #333;
}

.brief-content h1,
.brief-content h2,
.brief-content h3,
.brief-content h4 {
    color: #002d72;
    margin-top: 1.5rem;
    margin-bottom: 1rem;
}

.brief-content h1 {
    font-size: 2rem;
    border-bottom: 2px solid #002d72;
    padding-bottom: 0.5rem;
}

.brief-content h2 {
    font-size: 1.5rem;
}

.brief-content h3 {
    font-size: 1.25rem;
}

.brief-content p {
    margin-bottom: 1rem;
}

.brief-content ul,
.brief-content ol {
    margin-left: 1.5rem;
    margin-bottom: 1rem;
}

.brief-content li {
    margin-bottom: 0.5rem;
}

.brief-content a {
    color: #0061eb;
    text-decoration: none;
}

.brief-content a:hover {
    text-decoration: underline;
}

.brief-content code {
    background: #f4f4f5;
    padding: 0.2rem 0.4rem;
    border-radius: 0.25rem;
    font-family: monospace;
    font-size: 0.9em;
}

.brief-content pre {
    background: #f4f4f5;
    padding: 1rem;
    border-radius: 0.5rem;
    overflow-x: auto;
    margin-bottom: 1rem;
}

.brief-content blockquote {
    border-left: 4px solid #002d72;
    padding-left: 1rem;
    margin-left: 0;
    margin-bottom: 1rem;
    color: #666;
    font-style: italic;
}

.brief-error {
    background: #fff3f3;
    border: 1px solid #ffcccc;
    border-radius: 0.5rem;
    padding: 1.5rem;
    color: #cc0000;
}

.brief-error h3 {
    margin-top: 0;
    margin-bottom: 0.5rem;
}

/* Адаптивность для мобильных устройств */
@media (max-width: 768px) {
    #brief-container {
        margin: 1rem;
        border-radius: 0.5rem;
    }

    #brief-form {
        padding: 1.5rem;
    }

    .brief-header {
        padding: 0.75rem 1rem;
        font-size: 1rem;
    }

    .brief-meta {
        grid-template-columns: 1fr;
    }

    #brief-result {
        padding: 1rem;
    }

    .brief-content h1 {
        font-size: 1.5rem;
    }

    .brief-content h2 {
        font-size: 1.25rem;
    }
}
