/* Основные стили */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    color: #333;
}

/* Стили для логина */
.login-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 20px;
}

.login-card {
    background: white;
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
    width: 100%;
    max-width: 450px;
    overflow: hidden;
}

.login-header {
    background: linear-gradient(135deg, #4b6cb7 0%, #182848 100%);
    color: white;
    padding: 40px 30px;
    text-align: center;
}

.logo-circle {
    width: 80px;
    height: 80px;
    background: white;
    border-radius: 50%;
    margin: 0 auto 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 40px;
    color: #4b6cb7;
}

.login-header h1 {
    font-size: 1.8em;
    margin-bottom: 10px;
}

.subtitle {
    opacity: 0.9;
    font-size: 0.9em;
}

.login-body {
    padding: 40px 30px;
}

.alert {
    padding: 12px 15px;
    border-radius: 8px;
    margin-bottom: 25px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.alert-error {
    background: #fee;
    color: #c33;
    border-left: 4px solid #c33;
}

.input-group {
    margin-bottom: 25px;
}

.input-group label {
    display: block;
    margin-bottom: 8px;
    color: #555;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 8px;
}

.input-group input {
    width: 100%;
    padding: 15px;
    border: 2px solid #e0e0e0;
    border-radius: 10px;
    font-size: 16px;
    transition: all 0.3s;
}

.input-group input:focus {
    outline: none;
    border-color: #4b6cb7;
    box-shadow: 0 0 0 3px rgba(75, 108, 183, 0.1);
}

.btn-login {
    width: 100%;
    padding: 16px;
    background: linear-gradient(135deg, #4b6cb7 0%, #182848 100%);
    color: white;
    border: none;
    border-radius: 10px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    transition: transform 0.2s;
}

.btn-login:hover {
    transform: translateY(-2px);
}

.login-info {
    margin-top: 30px;
    padding: 20px;
    background: #f8f9fa;
    border-radius: 10px;
    border-left: 4px solid #4b6cb7;
}

.test-credentials {
    margin-top: 10px;
}

.credential {
    background: white;
    padding: 10px 15px;
    border-radius: 6px;
    margin-bottom: 8px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.cred-label {
    font-weight: 500;
    color: #555;
}

.cred-value {
    font-family: monospace;
    color: #4b6cb7;
}

.login-footer {
    text-align: center;
    padding: 20px;
    color: #777;
    font-size: 0.9em;
    border-top: 1px solid #eee;
}

/* Стили для чата */
.chat-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    background: #f5f7fb;
}

.chat-header {
    background: white;
    padding: 15px 30px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 20px;
}

.logo-med {
    width: 50px;
    height: 50px;
    /*background: linear-gradient(135deg, #4b6cb7 0%, #182848 100%);*/
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 24px;
}

.header-info h1 {
    font-size: 1.5em;
    color: #2c3e50;
    margin-bottom: 5px;
}

.user-greeting {
    color: #666;
    display: flex;
    align-items: center;
    gap: 10px;
}

.badge-admin {
    background: #f39c12;
    color: white;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 0.85em;
    display: inline-flex;
    align-items: center;
    gap: 5px;
}

.header-right {
    display: flex;
    gap: 15px;
}

.btn-admin, .btn-logout {
    padding: 10px 20px;
    border-radius: 8px;
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 500;
    transition: all 0.3s;
}

.btn-admin {
    background: #3498db;
    color: white;
}

.btn-logout {
    background: #e74c3c;
    color: white;
}

.btn-admin:hover, .btn-logout:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(0,0,0,0.1);
}

.connection-status {
    padding: 12px 30px;
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 500;
}

.status-online {
    background: #d4edda;
    color: #155724;
}

.status-offline {
    background: #f8d7da;
    color: #721c24;
}

.chat-window {
    flex: 1;
    overflow-y: auto;
    padding: 20px 30px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.system-message {
    text-align: center;
    padding: 40px 20px;
    background: white;
    border-radius: 15px;
    box-shadow: 0 5px 20px rgba(0,0,0,0.05);
    margin: 20px auto;
    max-width: 500px;
}

.system-message i {
    font-size: 3em;
    color: #e74c3c;
    margin-bottom: 20px;
}

.system-message h3 {
    margin-bottom: 10px;
    color: #2c3e50;
}

.system-message p {
    color: #666;
}

.empty-chat {
    text-align: center;
    padding: 60px 20px;
    color: #7f8c8d;
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

.empty-chat i {
    font-size: 4em;
    margin-bottom: 20px;
    color: #bdc3c7;
}

.empty-chat h3 {
    margin-bottom: 10px;
    color: #2c3e50;
}

.message {
    max-width: 70%;
    padding: 0;
    animation: fadeIn 0.3s ease-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.user-message {
    align-self: flex-end;
}

.ai-message {
    align-self: flex-start;
}

.message-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
    font-size: 0.9em;
    color: #666;
}

.message-time {
    margin-left: auto;
    font-size: 0.85em;
    opacity: 0.7;
}

.message-content {
    background: white;
    padding: 15px 20px;
    border-radius: 15px;
    line-height: 1.6;
    box-shadow: 0 3px 10px rgba(0,0,0,0.05);
}

.user-message .message-content {
    background: linear-gradient(135deg, #4b6cb7 0%, #182848 100%);
    color: white;
    border-bottom-right-radius: 5px;
}

.ai-message .message-content {
    background: white;
    border-bottom-left-radius: 5px;
    border: 1px solid #e0e0e0;
}

.typing .message-content {
    background: transparent;
    border: none;
    box-shadow: none;
    padding: 0;
}

.typing-dots {
    display: flex;
    gap: 5px;
    padding: 10px 0;
}

.typing-dots span {
    width: 8px;
    height: 8px;
    background: #4b6cb7;
    border-radius: 50%;
    animation: typingDot 1.4s infinite;
}

.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingDot {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-5px); }
}

.chat-input-area {
    padding: 20px 30px;
    background: white;
    border-top: 1px solid #e0e0e0;
    box-shadow: 0 -2px 10px rgba(0,0,0,0.05);
}

.input-wrapper {
    display: flex;
    gap: 15px;
    margin-bottom: 10px;
}

.input-wrapper textarea {
    flex: 1;
    padding: 15px;
    border: 2px solid #e0e0e0;
    border-radius: 15px;
    font-size: 16px;
    resize: none;
    font-family: inherit;
    transition: all 0.3s;
    min-height: 60px;
    max-height: 200px;
}

.input-wrapper textarea:focus {
    outline: none;
    border-color: #4b6cb7;
    box-shadow: 0 0 0 3px rgba(75, 108, 183, 0.1);
}

.btn-send {
    padding: 15px 30px;
    background: linear-gradient(135deg, #4b6cb7 0%, #182848 100%);
    color: white;
    border: none;
    border-radius: 15px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
    transition: all 0.3s;
    white-space: nowrap;
}

.btn-send:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(75, 108, 183, 0.3);
}

.input-hint {
    font-size: 0.9em;
    color: #7f8c8d;
    display: flex;
    align-items: center;
    gap: 8px;
}

.chat-input-disabled {
    padding: 30px;
    text-align: center;
    background: #f8d7da;
    color: #721c24;
    font-weight: 500;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
}

.chat-input-disabled i {
    font-size: 2em;
}

/* Скроллбар */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb {
    background: #4b6cb7;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #182848;
}

/* Адаптивность */
@media (max-width: 768px) {
    .chat-header {
        padding: 15px;
        flex-direction: column;
        gap: 15px;
    }

    .header-left, .header-right {
        width: 100%;
        justify-content: space-between;
    }

    .message {
        max-width: 85%;
    }

    .input-wrapper {
        flex-direction: column;
    }

    .btn-send {
        width: 100%;
        justify-content: center;
    }

    .admin-container {
        padding: 10px;
    }
}

/* Стили для страницы ошибки */
.error-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    padding: 20px;
}

.error-card {
    background: white;
    border-radius: 20px;
    padding: 40px;
    text-align: center;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
    max-width: 500px;
    width: 100%;
}

.error-icon {
    font-size: 4em;
    color: #e74c3c;
    margin-bottom: 20px;
}

.error-card h1 {
    color: #2c3e50;
    margin-bottom: 20px;
}

.error-message {
    color: #7f8c8d;
    font-size: 1.2em;
    margin-bottom: 30px;
    line-height: 1.6;
}

.btn-home {
    display: inline-block;
    background: #3498db;
    color: white;
    padding: 12px 30px;
    border-radius: 10px;
    text-decoration: none;
    font-weight: 600;
    transition: all 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    max-width: 200px;
    margin: 0 auto;
}

.btn-home:hover {
    background: #2980b9;
    transform: translateY(-2px);
}

/* Кнопка очистки истории */
.btn-clear-history {
    background: #e74c3c;
    color: white;
    padding: 10px 20px;
    border-radius: 8px;
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 500;
    transition: all 0.3s;
    cursor: pointer;
}

.btn-clear-history:hover {
    background: #c0392b;
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(231, 76, 60, 0.3);
}

/* Модальное окно подтверждения */
.confirm-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    z-index: 1000;
    justify-content: center;
    align-items: center;
}

.confirm-modal-content {
    background: white;
    border-radius: 15px;
    padding: 30px;
    max-width: 400px;
    width: 90%;
    text-align: center;
    box-shadow: 0 10px 40px rgba(0,0,0,0.3);
    animation: modalFadeIn 0.3s ease-out;
}

@keyframes modalFadeIn {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.confirm-modal h3 {
    margin-top: 0;
    color: #2c3e50;
    font-size: 1.3em;
}

.confirm-modal p {
    color: #7f8c8d;
    margin-bottom: 25px;
    line-height: 1.5;
}

.confirm-buttons {
    display: flex;
    gap: 15px;
    justify-content: center;
}

.btn-confirm {
    padding: 12px 25px;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.3s;
    min-width: 100px;
}

.btn-confirm-yes {
    background: #e74c3c;
    color: white;
}

.btn-confirm-yes:hover {
    background: #c0392b;
    transform: translateY(-2px);
}

.btn-confirm-no {
    background: #95a5a6;
    color: white;
}

.btn-confirm-no:hover {
    background: #7f8c8d;
    transform: translateY(-2px);
}

/* Анимация очистки */
.chat-clearing {
    animation: fadeOut 0.5s ease-out forwards;
}

@keyframes fadeOut {
    to {
        opacity: 0;
        transform: translateY(-10px);
    }
}

/* Уведомления */
.notification {
    position: fixed;
    top: 20px;
    right: 20px;
    background: white;
    border-radius: 10px;
    padding: 15px 20px;
    box-shadow: 0 5px 20px rgba(0,0,0,0.2);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 15px;
    z-index: 1001;
    animation: slideInRight 0.3s ease-out;
    max-width: 400px;
    border-left: 4px solid #3498db;
}

@keyframes slideInRight {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

.notification-success {
    border-left-color: #2ecc71;
}

.notification-error {
    border-left-color: #e74c3c;
}

.notification-content {
    display: flex;
    align-items: center;
    gap: 10px;
}

.notification i {
    font-size: 1.2em;
}

.notification-success i {
    color: #2ecc71;
}

.notification-error i {
    color: #e74c3c;
}

.notification-close {
    background: none;
    border: none;
    color: #7f8c8d;
    cursor: pointer;
    padding: 5px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: all 0.3s;
}

.notification-close:hover {
    background: #f5f5f5;
    color: #333;
}

/* Кнопка статуса */
.btn-status {
    background: #9b59b6;
    color: white;
    padding: 10px 20px;
    border-radius: 8px;
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 500;
    transition: all 0.3s;
}

.btn-status:hover {
    background: #8e44ad;
    transform: translateY(-2px);
}

/* Дополнительные стили для header */
.header-right {
    display: flex;
    gap: 10px;
    align-items: center;
}

/* Улучшенный responsive */
@media (max-width: 768px) {
    .header-right {
        flex-wrap: wrap;
        justify-content: center;
    }

    .btn-clear-history, .btn-status, .btn-admin, .btn-logout {
        padding: 8px 12px;
        font-size: 0.9em;
    }
}

/* Стиль для заблокированной кнопки отправки */
.btn-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.btn-send:disabled:hover {
    transform: none;
    box-shadow: none;
}

/* Стиль для заблокированного поля ввода */
#messageInput:disabled {
    background-color: #f5f5f5;
    cursor: not-allowed;
    color: #999;
}

/* Стиль для заблокированной кнопки файла */
.btn-file.disabled,
.btn-file:has(~ #fileInput:disabled) {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

/* Индикатор прогресса */
.progress-indicator {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.85);
    color: white;
    padding: 12px 24px;
    border-radius: 40px;
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 0.95em;
    z-index: 1000;
    backdrop-filter: blur(8px);
    box-shadow: 0 4px 15px rgba(0,0,0,0.3);
    font-weight: 500;
}

.progress-indicator .spinner {
    width: 18px;
    height: 18px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top: 2px solid white;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.progress-indicator .dots::after {
    content: '';
    animation: dots 1.5s steps(4, end) infinite;
}

@keyframes dots {
    0%, 20% { content: ''; }
    40% { content: '.'; }
    60% { content: '..'; }
    80%, 100% { content: '...'; }
}

.progress-indicator .timer {
    font-family: monospace;
    background: rgba(255,255,255,0.2);
    padding: 2px 8px;
    border-radius: 20px;
    font-size: 0.85em;
}

/* Кнопка умного поиска */
.btn-web-search {
    background: #6c5ce7;
    color: white;
    padding: 15px 20px;
    border-radius: 15px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all 0.3s;
    border: none;
    font-weight: 500;
}

.btn-web-search:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(108, 92, 231, 0.3);
}

.btn-web-search.active {
    background: #00b894;
    box-shadow: 0 0 10px rgba(0, 184, 148, 0.5);
}

.btn-web-search.active .search-mode-text {
    background: rgba(255,255,255,0.2);
    padding: 2px 8px;
    border-radius: 20px;
}

.btn-web-search i {
    font-size: 1.1em;
}

/* Стиль для заблокированной кнопки веб-поиска */
.btn-web-search:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.btn-web-search:disabled:hover {
    transform: none;
    box-shadow: none;
}

/* Тёмная тема — дополнительные элементы */
body.dark-theme .chat-container {
    background: #1a1a2e;
}

body.dark-theme .chat-header,
body.dark-theme .user-budget,
body.dark-theme .chat-input-area,
body.dark-theme .search-bar,
body.dark-theme .modal-content,
body.dark-theme .favorite-item,
body.dark-theme .favorites-list {
    background-color: #2d2d3f !important;
    color: #e0e0e0 !important;
}

body.dark-theme .message.ai-message .message-content {
    background: #3d3d5a !important;
    color: #e0e0e0 !important;
    border-color: #4d4d6a !important;
}

body.dark-theme .message.user-message .message-content {
    background: linear-gradient(135deg, #5a6bc7 0%, #2a3a78 100%) !important;
    color: white !important;
}

body.dark-theme .message-header,
body.dark-theme .budget-info,
body.dark-theme .input-hint,
body.dark-theme .token-badge,
body.dark-theme .favorite-question,
body.dark-theme .favorite-answer,
body.dark-theme .favorite-time {
    color: #c0c0c0 !important;
}

body.dark-theme .input-wrapper textarea {
    background: #3d3d5a !important;
    color: #e0e0e0 !important;
    border-color: #5d5d7a !important;
}

body.dark-theme .input-wrapper textarea::placeholder {
    color: #888 !important;
}

body.dark-theme .search-input {
    background: #3d3d5a !important;
    color: #e0e0e0 !important;
    border-color: #5d5d7a !important;
}

body.dark-theme .search-input::placeholder {
    color: #888 !important;
}

body.dark-theme .btn-file,
body.dark-theme .btn-voice,
body.dark-theme .btn-send {
    background: #4a4a6a !important;
}

body.dark-theme .btn-file:hover,
body.dark-theme .btn-voice:hover,
body.dark-theme .btn-send:hover {
    background: #5a5a7a !important;
}

body.dark-theme .connection-status {
    background: #2d2d3f !important;
    color: #c0c0c0 !important;
}

body.dark-theme .status-online {
    background: #1a3a2a !important;
    color: #2ecc71 !important;
}

body.dark-theme .status-offline {
    background: #3a1a1a !important;
    color: #e74c3c !important;
}

body.dark-theme .budget-bar {
    background: #3d3d5a !important;
}

body.dark-theme .budget-progress {
    background: #2ecc71 !important;
}

body.dark-theme .btn-clear-history {
    background: #c0392b !important;
}

body.dark-theme .btn-clear-history:hover {
    background: #e74c3c !important;
}

body.dark-theme .btn-theme {
    background: #5a5a7a !important;
}

body.dark-theme .btn-theme:hover {
    background: #6a6a8a !important;
}

body.dark-theme .btn-pdf {
    background: #c0392b !important;
}

body.dark-theme .btn-favorites {
    background: #d4a017 !important;
}

body.dark-theme .modal-header {
    background: linear-gradient(135deg, #5a6bc7 0%, #2a3a78 100%) !important;
}

body.dark-theme .modal-close {
    color: white !important;
}

body.dark-theme .delete-favorite {
    color: #e74c3c !important;
}

body.dark-theme .delete-favorite:hover {
    color: #ff6b6b !important;
}

body.dark-theme .empty-chat {
    color: #888 !important;
}

body.dark-theme .empty-chat i {
    color: #555 !important;
}

body.dark-theme .system-message {
    background: #2d2d3f !important;
    color: #c0c0c0 !important;
}

body.dark-theme .system-message i {
    color: #f39c12 !important;
}

body.dark-theme .modal {
    background-color: rgba(0,0,0,0.8);
}

body.dark-theme .modal-content {
    background-color: #2d2d3f !important;
}

body.dark-theme .favorite-item {
    background: #3d3d5a !important;
    border-left-color: #f39c12 !important;
}

body.dark-theme .favorite-item:hover {
    background: #4d4d6a !important;
}