/* Общие стили */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

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: #333;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    background: white;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    padding: 40px;
}

header {
    text-align: center;
    margin-bottom: 40px;
}

header h1 {
    color: #2c3e50;
    font-size: 1.5em;
    margin-bottom: 10px;
    font-weight: 500;
}

.subtitle {
    color: #7f8c8d;
    font-size: 1.1em;
}

/* Поиск */
.search-section {
    margin-bottom: 30px;
}

.search-form {
    display: flex;
    gap: 15px;
    align-items: flex-end;
    flex-wrap: wrap;
}

.search-form .form-group {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.search-form label {
    font-weight: 500;
    color: #333;
    font-size: 14px;
}

.search-form input[type="text"],
.search-form select {
    padding: 10px 15px;
    border: 2px solid #ddd;
    border-radius: 6px;
    font-size: 16px;
    min-width: 200px;
}

.search-form input[type="text"]:focus,
.search-form select:focus {
    outline: none;
    border-color: #667eea;
}

.link-group,
.link-block {
    cursor: pointer;
    color: #667eea;
    text-decoration: underline;
    font-weight: 500;
}

.link-group:hover,
.link-block:hover {
    color: #5568d3;
    text-decoration: underline;
}

.search-box {
    position: relative;
    margin-bottom: 20px;
}

#searchInput {
    width: 100%;
    padding: 15px 20px;
    font-size: 1.1em;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    transition: border-color 0.3s;
}

#searchInput:focus {
    outline: none;
    border-color: #667eea;
}

.autocomplete-wrapper {
    position: relative;
    width: 100%;
}

.autocomplete-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: white;
    border: 1px solid #e0e0e0;
    border-top: none;
    border-radius: 0 0 8px 8px;
    max-height: 300px;
    overflow-y: auto;
    z-index: 1000;
    display: none;
}

.autocomplete {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: white;
    border: 1px solid #e0e0e0;
    border-top: none;
    border-radius: 0 0 8px 8px;
    max-height: 300px;
    overflow-y: auto;
    z-index: 1000;
    display: none;
}

.autocomplete-item {
    padding: 12px 20px;
    cursor: pointer;
    border-bottom: 1px solid #f0f0f0;
    transition: background-color 0.2s;
}

.autocomplete-item:hover {
    background-color: #f5f5f5;
}

.autocomplete-item:last-child {
    border-bottom: none;
}

.autocomplete-item strong {
    color: #667eea;
}

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

#modelSelect {
    padding: 10px 15px;
    font-size: 1em;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    background: white;
    cursor: pointer;
}

.btn-primary {
    padding: 12px 30px;
    font-size: 1em;
    background: #667eea;
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: background-color 0.3s;
}

.btn-primary:hover {
    background: #5568d3;
}

.btn-primary:disabled {
    background: #ccc;
    cursor: not-allowed;
}

/* Загрузка */
.loading {
    text-align: center;
    padding: 40px;
}

.spinner {
    border: 4px solid #f3f3f3;
    border-top: 4px solid #667eea;
    border-radius: 50%;
    width: 50px;
    height: 50px;
    animation: spin 1s linear infinite;
    margin: 0 auto 20px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Ошибка */
.error {
    background: #fee;
    border: 2px solid #fcc;
    color: #c33;
    padding: 15px 20px;
    border-radius: 8px;
    margin-bottom: 20px;
}

/* Результаты */
.results {
    margin-top: 30px;
}

.diagnosis-card {
    background: #f8f9fa;
    border-radius: 8px;
    padding: 25px;
    margin-bottom: 20px;
}

.diagnosis-header {
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 2px solid #e0e0e0;
}

.diagnosis-code {
    font-size: 1.8em;
    color: #667eea;
    font-weight: bold;
    margin-bottom: 5px;
}

.diagnosis-name {
    font-size: 1.2em;
    color: #555;
}

.tabs {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
    border-bottom: 2px solid #e0e0e0;
}

.tab {
    padding: 12px 20px;
    background: none;
    border: none;
    border-bottom: 3px solid transparent;
    cursor: pointer;
    font-size: 1em;
    color: #666;
    transition: all 0.3s;
}

.tab:hover {
    color: #667eea;
}

.tab.active {
    color: #667eea;
    border-bottom-color: #667eea;
    font-weight: bold;
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

.context-section {
    margin-bottom: 25px;
}

.context-section h3 {
    color: #2c3e50;
    margin-bottom: 10px;
    font-size: 1.3em;
}

.context-item {
    background: white;
    padding: 15px;
    border-radius: 6px;
    margin-bottom: 15px;
    border-left: 4px solid #667eea;
}

.context-item h4 {
    color: #667eea;
    margin-bottom: 8px;
    font-size: 1.1em;
}

.context-item p {
    color: #555;
    line-height: 1.6;
    margin-bottom: 10px;
}

.source-link {
    display: inline-block;
    margin-top: 10px;
    color: #667eea;
    text-decoration: none;
    font-size: 0.9em;
}

.source-link:hover {
    text-decoration: underline;
}

/* Блоки и группы */
.block-link, .group-link {
    color: #667eea;
    cursor: pointer;
    text-decoration: underline;
    margin: 0 5px;
}

.block-link:hover, .group-link:hover {
    color: #5568d3;
}

.block-detail, .group-detail {
    background: #fff;
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    padding: 15px;
    margin: 10px 0;
    display: none;
}

.block-detail.active, .group-detail.active {
    display: block;
}

.block-detail h5, .group-detail h5 {
    color: #2c3e50;
    margin-bottom: 10px;
}

/* Семантический поиск */
.search-results-list {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.search-result-item {
    background: #f8f9fa;
    border-radius: 8px;
    padding: 20px;
    border-left: 4px solid #667eea;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}

.search-result-item:hover {
    transform: translateX(5px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.search-result-score {
    display: inline-block;
    background: #667eea;
    color: white;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 0.85em;
    margin-bottom: 10px;
}

/* Навигационные вкладки */
.nav-tabs {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
    border-bottom: 2px solid #e0e0e0;
}

.nav-tab {
    padding: 12px 24px;
    background: none;
    border: none;
    border-bottom: 3px solid transparent;
    cursor: pointer;
    font-size: 1em;
    color: #666;
    transition: all 0.3s;
}

.nav-tab:hover {
    color: #667eea;
}

.nav-tab.active {
    color: #667eea;
    border-bottom-color: #667eea;
    font-weight: bold;
}

.tab-panel {
    display: none;
}

.tab-panel.active {
    display: block;
}

/* Просмотр базы данных */
.db-viewer {
    margin-top: 20px;
}

.db-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 15px;
    margin-bottom: 30px;
}

.stat-card {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 20px;
    border-radius: 8px;
    text-align: center;
}

.stat-value {
    font-size: 2.5em;
    font-weight: bold;
    margin-bottom: 5px;
}

.stat-label {
    font-size: 0.9em;
    opacity: 0.9;
}

.stat-details {
    grid-column: 1 / -1;
    background: #f8f9fa;
    padding: 15px;
    border-radius: 8px;
    margin-top: 10px;
}

.db-tabs {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
    border-bottom: 2px solid #e0e0e0;
}

.db-tab {
    padding: 10px 20px;
    background: none;
    border: none;
    border-bottom: 3px solid transparent;
    cursor: pointer;
    color: #666;
    transition: all 0.3s;
}

.db-tab:hover {
    color: #667eea;
}

.db-tab.active {
    color: #667eea;
    border-bottom-color: #667eea;
    font-weight: bold;
}

.db-panel {
    display: none;
}

.db-panel.active {
    display: block;
}

.db-header {
    margin-bottom: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 15px;
}

.db-header h3 {
    margin: 0;
    color: #2c3e50;
}

.db-search {
    padding: 8px 15px;
    border: 2px solid #e0e0e0;
    border-radius: 6px;
    font-size: 0.95em;
    min-width: 250px;
}

.db-search:focus {
    outline: none;
    border-color: #667eea;
}

.db-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.db-item {
    background: white;
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    padding: 15px;
    cursor: pointer;
    transition: all 0.2s;
}

.db-item:hover {
    border-color: #667eea;
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.1);
    transform: translateX(3px);
}

.db-item-code {
    font-size: 1.2em;
    font-weight: bold;
    color: #667eea;
    margin-bottom: 5px;
}

.db-item-name {
    color: #555;
    margin-bottom: 8px;
    line-height: 1.5;
}

.db-item-meta {
    font-size: 0.85em;
    color: #999;
}

.db-pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 15px;
    margin-top: 20px;
    padding: 15px;
}

/* Стили для лекарственных средств */
.drugs-list {
    margin-top: 20px;
}

.drug-item {
    margin-bottom: 30px;
    padding: 20px;
    background: #f8f9fa;
    border-radius: 8px;
    border-left: 4px solid #667eea;
}

.drug-name {
    font-size: 1.2em;
    margin-bottom: 15px;
    color: #2c3e50;
}

.drug-name strong {
    font-weight: 700;
    color: #1a1a1a;
}

.drug-dose {
    margin-bottom: 15px;
}

.drug-dose-text {
    padding: 12px;
    background: white;
    border-radius: 6px;
    line-height: 1.6;
    color: #333;
}

.drug-notes {
    margin-bottom: 10px;
}

.drug-notes-text {
    padding: 12px;
    background: white;
    border-radius: 6px;
    line-height: 1.6;
    color: #555;
    font-style: italic;
}

.drug-notes-text em {
    font-style: italic;
    color: #6c757d;
}

/* Стили для диагностических блоков (таблица 0) */
.block-content {
    margin-top: 20px;
    padding: 20px;
    background: #f8f9fa;
    border-radius: 8px;
    line-height: 1.8;
    color: #333;
}

.block-content-pre {
    margin: 0;
    padding: 0;
    background: transparent;
    border: none;
    white-space: pre-wrap;
    font-family: inherit;
    font-size: inherit;
    line-height: 1.8;
    color: #333;
    word-wrap: break-word;
}

.block-item {
    font-weight: 600;
    margin-top: 12px;
    margin-bottom: 8px;
    color: #2c3e50;
    white-space: pre-wrap;
}

.block-text {
    margin-left: 20px;
    margin-bottom: 8px;
    color: #555;
    white-space: pre-wrap;
}

.db-pagination button {
    padding: 8px 20px;
    background: #667eea;
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.3s;
}

.db-pagination button:hover {
    background: #5568d3;
}

.db-details {
    background: white;
    padding: 20px;
    border-radius: 8px;
}

.btn-back {
    padding: 8px 15px;
    background: #f0f0f0;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    margin-bottom: 20px;
    transition: background 0.3s;
}

.btn-back:hover {
    background: #e0e0e0;
}

.context-card {
    background: #f8f9fa;
    border-left: 4px solid #667eea;
    padding: 15px;
    margin-bottom: 15px;
    border-radius: 4px;
}

.context-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    font-size: 0.9em;
}

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

.btn-edit, .btn-delete {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 18px;
    padding: 4px 8px;
    border-radius: 4px;
    transition: background-color 0.2s;
}

.btn-edit:hover {
    background-color: #e3f2fd;
}

.btn-delete:hover {
    background-color: #ffebee;
}

.context-column {
    background: #667eea;
    color: white;
    padding: 4px 10px;
    border-radius: 12px;
    font-weight: bold;
}

.context-page {
    color: #999;
}

.context-text {
    color: #555;
    line-height: 1.6;
    white-space: pre-wrap;
}

/* Модальное окно */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-content {
    background: white;
    border-radius: 8px;
    max-width: 800px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    border-bottom: 1px solid #dee2e6;
}

.modal-header h3 {
    margin: 0;
}

.modal-close {
    background: none;
    border: none;
    font-size: 28px;
    cursor: pointer;
    color: #666;
    padding: 0;
    width: 32px;
    height: 32px;
    line-height: 32px;
}

.modal-close:hover {
    color: #000;
}

.modal-body {
    padding: 20px;
}

.modal-footer {
    padding: 20px;
    border-top: 1px solid #dee2e6;
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}

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

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
    color: #333;
}

.btn-secondary {
    background: #6c757d;
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 4px;
    cursor: pointer;
}

.btn-secondary:hover {
    background: #5a6268;
}
    white-space: pre-wrap;
}

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

    header h1 {
        font-size: 1.8em;
    }

    .controls {
        flex-direction: column;
        align-items: stretch;
    }

    #modelSelect, .btn-primary {
        width: 100%;
    }

    .tabs {
        flex-wrap: wrap;
    }

    .db-stats {
        grid-template-columns: repeat(2, 1fr);
    }

    .db-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .db-search {
        width: 100%;
    }
}

