* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #4a90e2;
    --secondary-color: #7b68ee;
    --success-color: #50c878;
    --danger-color: #e74c3c;
    --bg-color: #f5f7fa;
    --card-bg: #ffffff;
    --text-primary: #2c3e50;
    --text-secondary: #7f8c8d;
    --border-color: #e1e8ed;
    --shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    --shadow-hover: 0 4px 20px rgba(0, 0, 0, 0.15);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    padding: 20px;
    color: var(--text-primary);
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    background: var(--card-bg);
    border-radius: 20px;
    box-shadow: var(--shadow-hover);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    height: calc(100vh - 40px);
}

header {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
    color: white;
    padding: 25px 30px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 15px;
}

.header-content h1 {
    font-size: 2.5em;
    margin-bottom: 5px;
    font-weight: 700;
}

.subtitle {
    font-size: 1.1em;
    opacity: 0.95;
    font-weight: 300;
}

.header-actions {
    display: flex;
    gap: 10px;
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.2);
    border: 2px solid rgba(255, 255, 255, 0.3);
    color: white;
    padding: 10px 20px;
    border-radius: 25px;
    cursor: pointer;
    font-size: 0.95em;
    transition: all 0.3s ease;
    backdrop-filter: blur(10px);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: translateY(-2px);
}

.chat-container {
    flex: 1;
    overflow-y: auto;
    padding: 30px;
    background: var(--bg-color);
}

.chat-messages {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.welcome-message,
.message {
    display: flex;
    gap: 15px;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message.user {
    flex-direction: row-reverse;
}

.avatar {
    width: 45px;
    height: 45px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5em;
    flex-shrink: 0;
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
    box-shadow: var(--shadow);
}

.message.user .avatar {
    background: linear-gradient(135deg, var(--success-color) 0%, #45b372 100%);
}

.message-content {
    flex: 1;
    background: var(--card-bg);
    padding: 18px 22px;
    border-radius: 18px;
    box-shadow: var(--shadow);
    max-width: 75%;
    line-height: 1.6;
}

.message.user .message-content {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
    color: white;
}

.message-content p {
    margin-bottom: 10px;
}

.message-content p:last-child {
    margin-bottom: 0;
}

.message-content pre {
    background: rgba(0, 0, 0, 0.05);
    padding: 15px;
    border-radius: 10px;
    overflow-x: auto;
    margin: 10px 0;
    font-family: 'Courier New', monospace;
    font-size: 0.9em;
}

.message.user .message-content pre {
    background: rgba(255, 255, 255, 0.2);
}

.message-content code {
    background: rgba(0, 0, 0, 0.05);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Courier New', monospace;
    font-size: 0.9em;
}

.message.user .message-content code {
    background: rgba(255, 255, 255, 0.2);
}

.message-content table {
    width: 100%;
    border-collapse: collapse;
    margin: 15px 0;
    background: var(--card-bg);
    border-radius: 8px;
    overflow: hidden;
}

.message.user .message-content table {
    background: rgba(255, 255, 255, 0.15);
}

.message-content table th,
.message-content table td {
    padding: 12px;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

.message-content table th {
    background: rgba(0, 0, 0, 0.05);
    font-weight: 600;
}

.message.user .message-content table th {
    background: rgba(255, 255, 255, 0.2);
}

.message-content ul,
.message-content ol {
    margin: 10px 0;
    padding-left: 25px;
}

.message-content li {
    margin: 5px 0;
}

.loading {
    display: flex;
    gap: 15px;
    align-items: center;
}

.loading-dots {
    display: flex;
    gap: 5px;
    padding: 18px 22px;
    background: var(--card-bg);
    border-radius: 18px;
    box-shadow: var(--shadow);
}

.loading-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--primary-color);
    animation: bounce 1.4s infinite ease-in-out both;
}

.loading-dot:nth-child(1) {
    animation-delay: -0.32s;
}

.loading-dot:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes bounce {
    0%, 80%, 100% {
        transform: scale(0);
    }
    40% {
        transform: scale(1);
    }
}

.uploaded-file-info {
    padding: 15px 30px;
    background: #fff3cd;
    border-top: 2px solid #ffc107;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 15px;
}

.uploaded-file-info span {
    flex: 1;
    color: var(--text-primary);
    font-weight: 500;
}

.btn-remove {
    background: var(--danger-color);
    color: white;
    border: none;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1.2em;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
}

.btn-remove:hover {
    transform: scale(1.1);
    background: #c0392b;
}

.input-container {
    padding: 25px 30px;
    background: var(--card-bg);
    border-top: 2px solid var(--border-color);
    display: flex;
    gap: 15px;
    align-items: flex-end;
}

#messageInput {
    flex: 1;
    padding: 15px 20px;
    border: 2px solid var(--border-color);
    border-radius: 25px;
    font-size: 1em;
    font-family: inherit;
    resize: none;
    max-height: 150px;
    transition: all 0.3s ease;
    background: var(--bg-color);
}

#messageInput:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(74, 144, 226, 0.1);
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
    color: white;
    border: none;
    padding: 15px 35px;
    border-radius: 25px;
    font-size: 1em;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: var(--shadow);
    white-space: nowrap;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-hover);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-primary:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

/* Кастомный скроллбар */
.chat-container::-webkit-scrollbar {
    width: 8px;
}

.chat-container::-webkit-scrollbar-track {
    background: var(--bg-color);
}

.chat-container::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

.chat-container::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

/* Адаптивность */
@media (max-width: 768px) {
    body {
        padding: 10px;
    }

    .container {
        height: calc(100vh - 20px);
        border-radius: 15px;
    }

    header {
        padding: 20px;
        flex-direction: column;
        align-items: flex-start;
    }

    .header-content h1 {
        font-size: 2em;
    }

    .header-actions {
        width: 100%;
        justify-content: space-between;
    }

    .btn-secondary {
        flex: 1;
        text-align: center;
    }

    .chat-container {
        padding: 20px;
    }

    .message-content {
        max-width: 85%;
    }

    .input-container {
        padding: 15px 20px;
    }

    .btn-primary {
        padding: 15px 25px;
    }
}

/* Стили для KaTeX */
.katex {
    font-size: 1.1em;
}

/* Модальное окно настроек */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    justify-content: center;
    align-items: center;
    animation: fadeIn 0.3s ease;
}

.modal-content {
    background: var(--card-bg);
    border-radius: 20px;
    box-shadow: var(--shadow-hover);
    max-width: 600px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    animation: slideDown 0.3s ease;
}

@keyframes slideDown {
    from {
        transform: translateY(-50px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 30px;
    border-bottom: 2px solid var(--border-color);
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
    color: white;
    border-radius: 20px 20px 0 0;
}

.modal-header h2 {
    margin: 0;
    font-size: 1.5em;
}

.modal-close {
    background: none;
    border: none;
    color: white;
    font-size: 2em;
    cursor: pointer;
    padding: 0;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.3s ease;
}

.modal-close:hover {
    background: rgba(255, 255, 255, 0.2);
}

.modal-body {
    padding: 30px;
}

.settings-section {
    margin-bottom: 30px;
}

.settings-section:last-child {
    margin-bottom: 0;
}

.settings-section h3 {
    margin-bottom: 15px;
    color: var(--text-primary);
    font-size: 1.2em;
}

.icon-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(50px, 1fr));
    gap: 10px;
    margin-bottom: 15px;
}

.icon-btn {
    width: 50px;
    height: 50px;
    border: 2px solid var(--border-color);
    border-radius: 10px;
    background: var(--bg-color);
    font-size: 1.5em;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

.icon-btn:hover {
    border-color: var(--primary-color);
    transform: scale(1.1);
    box-shadow: var(--shadow);
}

.icon-btn.selected {
    border-color: var(--primary-color);
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
    box-shadow: var(--shadow);
    transform: scale(1.1);
}

.icon-actions {
    display: flex;
    gap: 10px;
}

.btn-icon-action {
    padding: 10px 20px;
    border: 2px solid var(--primary-color);
    border-radius: 25px;
    background: white;
    color: var(--primary-color);
    cursor: pointer;
    font-size: 0.9em;
    transition: all 0.3s ease;
}

.btn-icon-action:hover {
    background: var(--primary-color);
    color: white;
    transform: translateY(-2px);
    box-shadow: var(--shadow);
}

/* Уведомления */
@keyframes slideIn {
    from {
        transform: translateX(400px);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes slideOut {
    from {
        transform: translateX(0);
        opacity: 1;
    }
    to {
        transform: translateX(400px);
        opacity: 0;
    }
}

.notification {
    font-weight: 500;
    word-wrap: break-word;
}

/* Стили для инструкций */
.instructions-list {
    max-height: 60vh;
    overflow-y: auto;
}

.instruction-category {
    margin-bottom: 25px;
}

.instruction-category h3 {
    font-size: 1.1em;
    margin-bottom: 10px;
    color: var(--text-primary);
    border-bottom: 2px solid var(--border-color);
    padding-bottom: 5px;
}

.instruction-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 15px;
    margin-bottom: 8px;
    background: var(--bg-color);
    border-radius: 8px;
    border: 1px solid var(--border-color);
    transition: all 0.3s ease;
}

.instruction-item:hover {
    background: #f0f4f8;
    border-color: var(--primary-color);
    transform: translateX(5px);
}

.instruction-content {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 10px;
}

.instruction-priority {
    font-size: 0.9em;
    min-width: 60px;
}

.instruction-text {
    flex: 1;
    color: var(--text-primary);
    line-height: 1.5;
}

.btn-remove-instruction {
    background: none;
    border: none;
    color: var(--danger-color);
    font-size: 1.5em;
    cursor: pointer;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.3s ease;
}

.btn-remove-instruction:hover {
    background: var(--danger-color);
    color: white;
    transform: scale(1.1);
}

.instructions-info {
    margin-top: 20px;
    padding: 15px;
    background: var(--bg-color);
    border-radius: 8px;
    border-left: 4px solid var(--primary-color);
}

.instructions-info p {
    margin-bottom: 10px;
    color: var(--text-primary);
}

.instructions-info ul {
    margin-left: 20px;
    color: var(--text-secondary);
    line-height: 1.8;
}

.loading-text, .empty-state, .error-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-secondary);
    font-style: italic;
}

.empty-state {
    color: var(--text-primary);
}

/* Стили для таблиц */
.message-content .table-wrapper {
    overflow-x: auto;
    margin: 15px 0;
}

/* Стили для графиков */
.graph-container {
    margin: 20px 0;
    padding: 15px;
    background: rgba(0, 0, 0, 0.02);
    border-radius: 10px;
    border: 1px solid var(--border-color);
}

.message.user .graph-container {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.2);
}

.graph-wrapper {
    text-align: center;
}

.graph-wrapper img {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    transition: transform 0.3s ease;
}

.graph-wrapper img:hover {
    transform: scale(1.02);
}

.graph-wrapper a {
    display: inline-block;
    margin-top: 10px;
    padding: 8px 15px;
    background: var(--primary-color);
    color: white;
    text-decoration: none;
    border-radius: 5px;
    font-size: 0.9em;
    transition: background 0.3s ease;
}

.graph-wrapper a:hover {
    background: var(--secondary-color);
}

.message.user .graph-wrapper a {
    background: rgba(255, 255, 255, 0.2);
    color: white;
}

.message.user .graph-wrapper a:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* ===== Стили для управления пользователями ===== */

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    color: var(--text-primary);
    font-weight: 500;
    font-size: 0.95em;
}

.form-group input[type="text"],
.form-group input[type="password"] {
    width: 100%;
    padding: 12px 15px;
    border: 2px solid var(--border-color);
    border-radius: 10px;
    font-size: 1em;
    font-family: inherit;
    transition: border-color 0.3s, box-shadow 0.3s;
    background: var(--bg-color);
    color: var(--text-primary);
}

.form-group input[type="text"]:focus,
.form-group input[type="password"]:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(74, 144, 226, 0.1);
}

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

.form-group label input[type="checkbox"] {
    margin-right: 8px;
}

/* Список пользователей */
.user-list {
    margin-top: 15px;
}

.user-list-items {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.user-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px;
    background: var(--bg-color);
    border: 2px solid var(--border-color);
    border-radius: 12px;
    transition: all 0.3s ease;
}

.user-item:hover {
    border-color: var(--primary-color);
    box-shadow: var(--shadow);
    transform: translateY(-2px);
}

.user-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.user-info strong {
    color: var(--text-primary);
    font-size: 1.05em;
}

.user-fullname {
    color: var(--text-secondary);
    font-size: 0.9em;
    font-style: italic;
}

.user-actions {
    display: flex;
    gap: 8px;
}

.btn-edit-user,
.btn-delete-user {
    background: transparent;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    padding: 8px 12px;
    cursor: pointer;
    font-size: 1.1em;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-edit-user {
    color: var(--primary-color);
    border-color: var(--primary-color);
}

.btn-edit-user:hover {
    background: var(--primary-color);
    color: white;
    transform: scale(1.05);
}

.btn-delete-user {
    color: var(--danger-color);
    border-color: var(--danger-color);
}

.btn-delete-user:hover {
    background: var(--danger-color);
    color: white;
    transform: scale(1.05);
}

/* Бейджи для статуса */
.badge-admin {
    display: inline-block;
    padding: 4px 10px;
    background: linear-gradient(135deg, #ffd700 0%, #ffed4e 100%);
    color: #856404;
    border-radius: 12px;
    font-size: 0.8em;
    font-weight: 600;
    margin-left: 8px;
}

.badge-inactive {
    display: inline-block;
    padding: 4px 10px;
    background: var(--text-secondary);
    color: white;
    border-radius: 12px;
    font-size: 0.8em;
    font-weight: 600;
    margin-left: 8px;
}

.loading-text {
    text-align: center;
    color: var(--text-secondary);
    padding: 20px;
    font-style: italic;
}

.error-text {
    color: var(--danger-color);
    padding: 15px;
    background: #fee;
    border: 1px solid #fcc;
    border-radius: 8px;
    margin: 15px 0;
    text-align: center;
}

/* Модальное окно для пользователя */
#userModal .modal-content {
    max-width: 500px;
}

#userModal .modal-body {
    padding: 30px;
}

#userModal .form-group:last-of-type {
    margin-bottom: 0;
}

/* Секция управления пользователями в настройках */
#userManagementSection {
    border-top: 2px solid var(--border-color);
    padding-top: 25px;
    margin-top: 25px;
}

#userManagementSection h3 {
    margin-bottom: 20px;
    color: var(--text-primary);
    font-size: 1.2em;
}

/* Секция профиля */
#profileForm {
    margin-top: 15px;
}

#profileForm .form-group {
    margin-bottom: 20px;
}

#profileForm input[type="text"] {
    width: 100%;
    padding: 12px 15px;
    border: 2px solid var(--border-color);
    border-radius: 10px;
    font-size: 1em;
    font-family: inherit;
    transition: border-color 0.3s, box-shadow 0.3s;
    background: var(--bg-color);
    color: var(--text-primary);
    box-sizing: border-box;
}

#profileForm input[type="text"]:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(74, 144, 226, 0.1);
}

#profileForm label {
    display: block;
    margin-bottom: 8px;
    color: var(--text-primary);
    font-weight: 500;
    font-size: 0.95em;
}

#profileForm #saveProfileBtn {
    width: 100%;
    margin-top: 10px;
    padding: 14px;
    font-size: 1em;
}

#profileForm #saveProfileBtn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

#profileForm #saveProfileBtn:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: var(--shadow-hover);
}

/* Секция профиля */
#profileForm {
    margin-top: 15px;
}

#profileForm .form-group {
    margin-bottom: 20px;
}

#profileForm input[type="text"] {
    width: 100%;
    padding: 12px 15px;
    border: 2px solid var(--border-color);
    border-radius: 10px;
    font-size: 1em;
    font-family: inherit;
    transition: border-color 0.3s, box-shadow 0.3s;
    background: var(--bg-color);
    color: var(--text-primary);
    box-sizing: border-box;
}

#profileForm input[type="text"]:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(74, 144, 226, 0.1);
}

#profileForm label {
    display: block;
    margin-bottom: 8px;
    color: var(--text-primary);
    font-weight: 500;
    font-size: 0.95em;
}

#profileForm #saveProfileBtn {
    width: 100%;
    margin-top: 10px;
    padding: 14px;
    font-size: 1em;
}

#profileForm #saveProfileBtn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

#profileForm #saveProfileBtn:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: var(--shadow-hover);
}

/* Секция смены пароля */
#changePasswordForm {
    margin-top: 15px;
}

#changePasswordForm .form-group {
    margin-bottom: 20px;
}

#changePasswordForm .form-group:last-of-type {
    margin-bottom: 20px;
}

#changePasswordForm input[type="password"] {
    width: 100%;
    padding: 12px 15px;
    border: 2px solid var(--border-color);
    border-radius: 10px;
    font-size: 1em;
    font-family: inherit;
    transition: border-color 0.3s, box-shadow 0.3s;
    background: var(--bg-color);
    color: var(--text-primary);
    box-sizing: border-box;
}

#changePasswordForm input[type="password"]:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(74, 144, 226, 0.1);
}

#changePasswordForm label {
    display: block;
    margin-bottom: 8px;
    color: var(--text-primary);
    font-weight: 500;
    font-size: 0.95em;
}

#changePasswordForm #changePasswordBtn {
    width: 100%;
    margin-top: 10px;
    padding: 14px;
    font-size: 1em;
}

#changePasswordForm #changePasswordBtn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

#changePasswordForm #changePasswordBtn:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: var(--shadow-hover);
}

/* Кнопка выхода */
#logoutBtn {
    width: 100%;
    padding: 12px;
    margin-top: 20px;
    background: var(--danger-color);
    color: white;
    border: none;
    border-radius: 10px;
    font-size: 1em;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
}

#logoutBtn:hover {
    background: #c0392b;
    transform: translateY(-2px);
    box-shadow: var(--shadow);
}

/* Адаптивность для управления пользователями */
@media (max-width: 768px) {
    .user-item {
        flex-direction: column;
        align-items: flex-start;
        gap: 15px;
    }
    
    .user-actions {
        width: 100%;
        justify-content: flex-end;
    }
    
    .user-info {
        width: 100%;
    }
}

