/* ИРБИС AI Chat Bot Styles */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #dbeafe 0%, #bfdbfe 50%, #93c5fd 100%);
    min-height: 100vh;
    padding: 20px;
    display: flex;
    gap: 20px;
    align-items: flex-start;
}

/* Режим без отладки - чат в центре */
body.debug-disabled {
    justify-content: center;
    align-items: center;
}

body.debug-disabled .chat-container {
    max-width: 800px;
    width: 100%;
}

.chat-container {
    width: 800px;
    height: 90vh;
    max-height: 700px;
    background: white;
    border-radius: 20px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    flex-shrink: 0;
}

.chat-header {
    background: linear-gradient(135deg, #1e40af 0%, #1e3a8a 50%, #1e293b 100%);
    color: white;
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 15px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.bot-avatar {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    overflow: hidden;
    border: 3px solid rgba(255, 255, 255, 0.3);
}

.bot-avatar img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    background: white;
    border-radius: 50%;
}

.bot-info h1 {
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 2px;
}

.status {
    font-size: 0.875rem;
    opacity: 0.8;
    display: flex;
    align-items: center;
    gap: 5px;
}

.status::before {
    content: '';
    width: 8px;
    height: 8px;
    background: #10b981;
    border-radius: 50%;
    display: inline-block;
}

.chat-controls {
    margin-left: auto;
}

.control-btn {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.control-btn {
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.2) 0%, rgba(255, 255, 255, 0.1) 100%);
}

.control-btn:hover {
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.3) 0%, rgba(255, 255, 255, 0.2) 100%);
    transform: scale(1.05);
}

.chat-messages {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    scroll-behavior: smooth;
}

.message {
    display: flex;
    gap: 12px;
    margin-bottom: 20px;
    animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    overflow: hidden;
    flex-shrink: 0;
}

.message-avatar img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    background: white;
    border-radius: 50%;
}

.message-content {
    flex: 1;
    max-width: calc(100% - 52px);
}

.message-text {
    background: #f3f4f6;
    padding: 12px 16px;
    border-radius: 18px;
    margin-bottom: 4px;
    word-wrap: break-word;
    white-space: pre-wrap;
}

.bot-message .message-text {
    background: linear-gradient(135deg, #f0f9ff 0%, #e0f2fe 50%, #bae6fd 100%);
    color: #1f2937;
}

.user-message {
    flex-direction: row-reverse;
}

.user-message .message-content {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
}

.user-message .message-text {
    background: linear-gradient(135deg, #3b82f6 0%, #2563eb 50%, #1d4ed8 100%);
    color: white;
}

.message-time {
    font-size: 0.75rem;
    color: #6b7280;
    display: flex;
    align-items: center;
    gap: 8px;
}

.message-generation-time {
    font-size: 0.75rem;
    color: #9ca3af;
    opacity: 0.8;
    display: none;
    align-items: center;
    gap: 4px;
}

.message-generation-time.visible {
    display: flex;
}

.message-generation-time::before {
    content: '⏱';
    font-size: 0.7rem;
}

.welcome-message {
    margin-bottom: 30px;
}

.welcome-message .message-text {
    font-size: 1.1rem;
    font-weight: 500;
}

.typing-indicator {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 20px 20px 20px;
    animation: fadeIn 0.3s ease-out;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.typing-dots {
    display: flex;
    gap: 4px;
}

.typing-dots span {
    width: 8px;
    height: 8px;
    background: #3b82f6;
    border-radius: 50%;
    animation: typing 1.4s infinite ease-in-out;
}

.typing-dots span:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-dots span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.4;
    }
    30% {
        transform: translateY(-10px);
        opacity: 1;
    }
}

.typing-text {
    color: #6b7280;
    font-size: 0.875rem;
    font-style: italic;
}

.chat-input-container {
    border-top: 1px solid #e5e7eb;
    padding: 20px;
    background: white;
}

.chat-input-wrapper {
    display: flex;
    gap: 12px;
    align-items: flex-end;
}

#message-input {
    flex: 1;
    border: 2px solid #e5e7eb;
    border-radius: 25px;
    padding: 12px 20px;
    font-size: 1rem;
    resize: none;
    outline: none;
    transition: border-color 0.2s ease;
    max-height: 120px;
    min-height: 48px;
}

#message-input:focus {
    border-color: #3b82f6;
}

#message-input::placeholder {
    color: #9ca3af;
}

.send-button {
    width: 48px;
    height: 48px;
    border: none;
    border-radius: 50%;
    background: linear-gradient(135deg, #3b82f6 0%, #2563eb 50%, #1d4ed8 100%);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.send-button:hover:not(:disabled) {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.4);
}

.send-button:disabled {
    background: #d1d5db;
    cursor: not-allowed;
}

.input-footer {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-top: 8px;
    gap: 12px;
}

.input-info {
    font-size: 0.75rem;
    color: #6b7280;
    text-align: right;
    flex-shrink: 0;
}

#char-count {
    font-weight: 600;
    color: #3b82f6;
}

.disclaimer {
    font-size: 0.7rem;
    color: #9ca3af;
    font-style: italic;
    line-height: 1.4;
    flex: 1;
}

/* Scrollbar styling */
.chat-messages::-webkit-scrollbar {
    width: 6px;
}

.chat-messages::-webkit-scrollbar-track {
    background: #f1f5f9;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%);
    border-radius: 3px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: linear-gradient(135deg, #2563eb 0%, #1e40af 100%);
}

/* Responsive design */
@media (max-width: 768px) {
    .chat-container {
        height: 100vh;
        max-height: none;
        border-radius: 0;
        margin: 0;
    }

    .chat-header {
        padding: 15px;
    }

    .bot-info h1 {
        font-size: 1.25rem;
    }

    .chat-messages {
        padding: 15px;
    }

    .chat-input-container {
        padding: 15px;
    }

    .message-text {
        padding: 10px 14px;
        font-size: 0.95rem;
    }
}

/* Error message styling */
.error-message {
    background: #fef2f2 !important;
    border: 1px solid #fecaca;
    color: #dc2626;
}

.error-message .message-text {
    background: #fef2f2;
    color: #dc2626;
}

/* Loading animation for bot avatar */
.bot-avatar.loading {
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.6;
    }
}

/* Message meta container (time + status) */
.message-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 16px;
}

/* Message status indicators */
.message-status {
    display: flex;
    align-items: center;
    gap: 4px;
}

.message-status.sent {
    color: #10b981;
}

.message-status.error {
    color: #dc2626;
}

/* Markdown styling */
.message-text h1,
.message-text h2,
.message-text h3,
.message-text h4,
.message-text h5,
.message-text h6 {
    margin-top: 1rem;
    margin-bottom: 0.5rem;
    font-weight: 600;
    line-height: 1.2;
}

.message-text h1 {
    font-size: 1.5rem;
    color: #1f2937;
    border-bottom: 2px solid #e5e7eb;
    padding-bottom: 0.5rem;
}

.message-text h2 {
    font-size: 1.25rem;
    color: #374151;
}

.message-text h3 {
    font-size: 1.125rem;
    color: #4b5563;
}

.message-text h4 {
    font-size: 1rem;
    color: #6b7280;
}

.message-text h5 {
    font-size: 0.875rem;
    color: #6b7280;
}

.message-text h6 {
    font-size: 0.875rem;
    color: #6b7280;
    font-style: italic;
}

.message-text p {
    margin-bottom: 0.75rem;
    line-height: 1.6;
}

.message-text ul,
.message-text ol {
    margin-bottom: 0.75rem;
    padding-left: 1.5rem;
}

.message-text li {
    margin-bottom: 0.25rem;
    line-height: 1.5;
}

.message-text blockquote {
    border-left: 4px solid #3b82f6;
    padding-left: 1rem;
    margin: 1rem 0;
    background: rgba(59, 130, 246, 0.05);
    padding: 0.5rem 1rem;
    border-radius: 0 8px 8px 0;
    font-style: italic;
    color: #4b5563;
}

.message-text code {
    background: rgba(0, 0, 0, 0.1);
    padding: 0.125rem 0.25rem;
    border-radius: 3px;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 0.875em;
    color: #d73a49;
}

.message-text pre {
    background: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 8px;
    padding: 1rem;
    margin: 1rem 0;
    overflow-x: auto;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 0.875rem;
    line-height: 1.4;
}

.message-text pre code {
    background: transparent;
    padding: 0;
    color: #24292e;
}

.message-text table {
    width: 100%;
    border-collapse: collapse;
    margin: 1rem 0;
    border-radius: 8px;
    overflow: hidden;
}

.message-text th,
.message-text td {
    border: 1px solid #e5e7eb;
    padding: 0.5rem 1rem;
    text-align: left;
}

.message-text th {
    background: #f9fafb;
    font-weight: 600;
    color: #374151;
}

.message-text tr:nth-child(even) {
    background: #f9fafb;
}

.message-text a {
    color: #3b82f6;
    text-decoration: none;
    transition: color 0.2s ease;
}

.message-text a:hover {
    color: #1d4ed8;
    text-decoration: underline;
}

.message-text strong {
    font-weight: 600;
    color: #1f2937;
}

.message-text em {
    font-style: italic;
    color: #4b5563;
}

.message-text del {
    text-decoration: line-through;
    color: #9ca3af;
}

.message-text hr {
    border: none;
    border-top: 1px solid #e5e7eb;
    margin: 1.5rem 0;
}

/* Специальные стили для бота */
.bot-message .message-text h1,
.bot-message .message-text h2,
.bot-message .message-text h3,
.bot-message .message-text h4,
.bot-message .message-text h5,
.bot-message .message-text h6 {
    color: #1e293b;
}

.bot-message .message-text code {
    background: rgba(30, 41, 59, 0.1);
    color: #1e293b;
}

.bot-message .message-text pre {
    background: rgba(240, 249, 255, 0.8);
    border-color: rgba(59, 130, 246, 0.2);
}

.bot-message .message-text pre code {
    color: #1e293b;
}

.bot-message .message-text blockquote {
    border-left-color: #3b82f6;
    background: rgba(59, 130, 246, 0.05);
}

/* Специальные стили для пользователя */
.user-message .message-text h1,
.user-message .message-text h2,
.user-message .message-text h3,
.user-message .message-text h4,
.user-message .message-text h5,
.user-message .message-text h6 {
    color: #ffffff;
}

.user-message .message-text code {
    background: rgba(255, 255, 255, 0.2);
    color: #ffffff;
}

.user-message .message-text pre {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.2);
}

.user-message .message-text pre code {
    color: #ffffff;
}

.user-message .message-text blockquote {
    border-left-color: rgba(255, 255, 255, 0.6);
    background: rgba(255, 255, 255, 0.1);
}

/* Стили для отладочной панели */
.debug-iframe-container {
    flex: 1;
    height: calc(100vh - 40px);
    background: white;
    border-radius: 20px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
    overflow: hidden;
    display: flex;
    border: 2px solid #3b82f6;
}

.debug-iframe {
    width: 100%;
    height: 100%;
    border: none;
    background: white;
}

/* Адаптивность для маленьких экранов */
@media (max-width: 1200px) {
    body {
        flex-direction: column;
        align-items: stretch;
    }

    /* В режиме отладки */
    body:not(.debug-disabled) .chat-container {
        width: 100%;
        height: 60vh;
        order: 2;
    }

    body:not(.debug-disabled) .debug-iframe-container {
        order: 1;
        height: 40vh;
        margin-bottom: 20px;
    }

    /* В режиме без отладки - центрируем чат */
    body.debug-disabled {
        flex-direction: column;
        justify-content: center;
        align-items: center;
    }

    body.debug-disabled .chat-container {
        width: 100%;
        max-width: 800px;
        height: 90vh;
        margin: 0 auto;
    }
}

.source-item { margin-bottom: 6px; }
.source-file {
    font-weight: 600;
    color: #2563eb;
    text-decoration: underline;
    cursor: pointer;
    padding: 4px 0;
    display: flex;
    align-items: center;
    gap: 8px;
}
.source-file:hover { color: #1d4ed8; }

/* Вложенность строк внутри документа */
.source-group .source-lines-inner {
    margin-left: 16px; /* визуальная лестница */
    border-left: 2px dashed #e5e7eb;
    padding-left: 10px;
}
.source-line {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 2px 0;
}
.source-line .line-index {
    width: 24px;
    text-align: right;
    color: #9ca3af;
    font-variant-numeric: tabular-nums;
}
.source-line .line-text a.line-text-link {
    color: #2563eb;
    text-decoration: underline;
}
.source-line .line-text a.line-text-link:hover { color: #1d4ed8; }

/* Бейджи показателя соответствия и количества совпадений */
.source-score,
.source-chunk-count,
.line-score {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: #f1f5f9;
    color: #334155;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 2px 6px;
    font-size: 12px;
}

.source-modal-meta .meta-link {
    color: #2563eb;
    text-decoration: underline;
}
.source-modal-meta .meta-link:hover { color: #1d4ed8; }

.source-modal-meta .meta-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: #f1f5f9;
    color: #334155;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 2px 6px;
    font-size: 12px;
    margin-right: 6px;
}

.source-modal-body pre code .hl {
    background: #fde68a;
    color: #111827;
}

/* Ссылки внутри блока источников */
.sources-container a {
    color: #2563eb;
    text-decoration: underline;
}
.sources-container a:hover { color: #1d4ed8; }