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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    padding: 0;
    margin: 0;
}

.main-nav {
    display: flex;
    gap: 15px;
    margin-bottom: 20px;
    padding: 15px 20px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    backdrop-filter: blur(10px);
}

.nav-link {
    color: white;
    text-decoration: none;
    padding: 8px 15px;
    border-radius: 5px;
    transition: background 0.3s;
    font-weight: 500;
}

.nav-link:hover {
    background: rgba(255, 255, 255, 0.2);
}

.nav-link.active {
    background: rgba(255, 255, 255, 0.3);
    font-weight: 600;
}

.container {
    display: flex;
    min-height: 100vh;
    padding: 0;
    margin: 0;
}

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

header h1 {
    font-size: 2.5em;
    margin-bottom: 10px;
}

header p {
    font-size: 1.2em;
    opacity: 0.9;
}

.domains {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 30px;
    margin-bottom: 40px;
}

.domain-card {
    background: white;
    border-radius: 15px;
    padding: 40px;
    text-align: center;
    cursor: pointer;
    transition: transform 0.3s, box-shadow 0.3s;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    text-decoration: none;
    color: inherit;
    display: block;
}

.domain-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 8px 15px rgba(0, 0, 0, 0.2);
}

.domain-link {
    margin-top: 15px;
    color: #667eea;
    font-weight: 600;
    font-size: 0.9em;
}

.domain-icon {
    font-size: 4em;
    margin-bottom: 20px;
}

.domain-card h2 {
    color: #333;
    margin-bottom: 10px;
    font-size: 1.8em;
}

.domain-card p {
    color: #666;
    font-size: 1.1em;
}

.chat-container {
    background: white;
    border-radius: 15px;
    box-shadow: 0 8px 15px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
    height: calc(100vh - 200px);
    min-height: 600px;
    max-height: 900px;
}

.chat-container.hidden {
    display: none;
}

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

.model-info {
    font-size: 0.9em;
    color: #666;
    background: #f0f0f0;
    padding: 5px 10px;
    border-radius: 5px;
}

.chat-header {
    padding: 20px;
    border-bottom: 1px solid #eee;
    display: flex;
    align-items: center;
    gap: 15px;
}

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

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

#domain-title {
    color: #333;
    font-size: 1.5em;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.message {
    display: flex;
    flex-direction: column;
    max-width: 80%;
    animation: fadeIn 0.3s;
}

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

.message.user {
    align-self: flex-end;
}

.message.assistant {
    align-self: flex-start;
}

.message-content {
    padding: 15px 20px;
    border-radius: 15px;
    word-wrap: break-word;
}

.message.user .message-content {
    background: #667eea;
    color: white;
}

.message.assistant .message-content {
    background: #f0f0f0;
    color: #333;
}

.message-time {
    font-size: 0.8em;
    color: #999;
    margin-top: 5px;
    padding: 0 5px;
}

.message.user .message-time {
    text-align: right;
}

.chat-input-container {
    padding: 20px;
    border-top: 1px solid #eee;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* Markdown Editor */
.markdown-editor-wrapper {
    display: flex;
    flex-direction: column;
    height: 100%;
    background: white;
    border-radius: 8px;
    overflow: hidden;
}

.markdown-editor-toolbar {
    display: flex;
    gap: 5px;
    padding: 10px;
    background: #f8f9fa;
    border-bottom: 1px solid #dee2e6;
    flex-wrap: wrap;
}

.toolbar-btn {
    padding: 6px 12px;
    border: 1px solid #dee2e6;
    background: white;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9em;
    transition: background 0.2s;
}

.toolbar-btn:hover {
    background: #e9ecef;
}

.toolbar-separator {
    width: 1px;
    background: #dee2e6;
    margin: 0 5px;
}

.markdown-editor-split {
    display: flex;
    height: 400px;
    border-top: 1px solid #dee2e6;
}

.markdown-editor-pane {
    flex: 1;
    border-right: 1px solid #dee2e6;
    display: flex;
    flex-direction: column;
}

.markdown-editor-textarea {
    flex: 1;
    padding: 15px;
    border: none;
    outline: none;
    font-family: 'Courier New', monospace;
    font-size: 0.95em;
    resize: none;
    line-height: 1.6;
}

.markdown-preview-pane {
    flex: 1;
    overflow-y: auto;
    padding: 15px;
    background: #f8f9fa;
}

.markdown-preview {
    max-width: 100%;
    word-wrap: break-word;
}

.markdown-preview h1,
.markdown-preview h2,
.markdown-preview h3 {
    margin-top: 1em;
    margin-bottom: 0.5em;
}

.markdown-preview h1 {
    font-size: 1.8em;
    border-bottom: 2px solid #dee2e6;
    padding-bottom: 0.3em;
}

.markdown-preview h2 {
    font-size: 1.5em;
    border-bottom: 1px solid #dee2e6;
    padding-bottom: 0.3em;
}

.markdown-preview h3 {
    font-size: 1.2em;
}

.markdown-preview code {
    background: #f1f3f5;
    padding: 2px 6px;
    border-radius: 3px;
    font-family: 'Courier New', monospace;
    font-size: 0.9em;
}

.markdown-preview pre {
    background: #f1f3f5;
    padding: 15px;
    border-radius: 6px;
    overflow-x: auto;
}

.markdown-preview pre code {
    background: none;
    padding: 0;
}

.markdown-preview ul,
.markdown-preview ol {
    margin-left: 20px;
    margin-bottom: 1em;
}

.markdown-preview li {
    margin-bottom: 0.3em;
}

.markdown-preview a {
    color: #667eea;
    text-decoration: none;
}

.markdown-preview a:hover {
    text-decoration: underline;
}

.markdown-preview img {
    max-width: 100%;
    max-height: 400px;
    border-radius: 8px;
    margin: 10px 0;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    display: block;
}

.markdown-preview .empty-preview {
    color: #999;
    font-style: italic;
}

.markdown-editor-actions {
    display: flex;
    gap: 10px;
    padding: 10px;
    background: #f8f9fa;
    border-top: 1px solid #dee2e6;
    justify-content: flex-end;
}

/* Chat tag search */
.chat-tag-search {
    padding: 10px 15px;
    border-bottom: 1px solid #dee2e6;
    background: white;
}

.chat-tag-search-input {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #dee2e6;
    border-radius: 6px;
    font-size: 0.9em;
}

.message.hidden {
    display: none;
}

/* Document messages */
.document-message {
    margin-top: 5px;
    margin-left: 20px;
    opacity: 0.9;
}

.document-content {
    background: #f8f9fa;
    border: 1px solid #dee2e6;
}

.document-image {
    display: block;
    max-width: 100%;
    max-height: 400px;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.document-filename {
    margin-top: 5px;
    font-size: 0.9em;
    color: #666;
}

.document-link-container {
    margin-top: 10px;
}

.document-link {
    text-decoration: none;
    color: #667eea;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border: 1px solid #667eea;
    border-radius: 6px;
    transition: background 0.2s;
}

.document-link:hover {
    background: #f0f0ff;
}

/* Message tags display */
.message-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    margin-bottom: 8px;
    padding: 5px 0;
}

.message-tag {
    display: inline-block;
    padding: 4px 8px;
    background: #e9ecef;
    color: #495057;
    border-radius: 4px;
    font-size: 0.75em;
    font-weight: 500;
}

.message.user .message-tags {
    justify-content: flex-end;
}

.message.assistant .message-tags {
    justify-content: flex-start;
}

.document-message .message-tags {
    margin-top: 5px;
    margin-bottom: 5px;
}

#chat-input {
    flex: 1;
    padding: 15px;
    border: 2px solid #eee;
    border-radius: 8px;
    font-size: 1em;
    outline: none;
    transition: border-color 0.3s;
}

#chat-input:focus {
    border-color: #667eea;
}

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

#send-btn:hover:not(:disabled) {
    background: #5568d3;
}

#send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.loading {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid #667eea;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

.error {
    background: #fee;
    color: #c33;
    padding: 15px;
    border-radius: 8px;
    margin: 10px 0;
}

/* Tags System */
.message-actions {
    display: flex;
    gap: 5px;
    margin-top: 5px;
    opacity: 0;
    transition: opacity 0.2s;
}

.message:hover .message-actions {
    opacity: 1;
}

.message-action-btn {
    background: rgba(102, 126, 234, 0.1);
    border: 1px solid #667eea;
    color: #667eea;
    padding: 4px 8px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.75em;
    transition: all 0.2s;
}

.message-action-btn:hover {
    background: #667eea;
    color: white;
}

.tag-input-container {
    position: relative;
    margin-top: 10px;
}

.tag-input-wrapper {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    padding: 8px;
    border: 2px solid #eee;
    border-radius: 8px;
    min-height: 40px;
    background: white;
}

.tag-input-wrapper:focus-within {
    border-color: #667eea;
}

.tag {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    background: #667eea;
    color: white;
    padding: 4px 8px;
    border-radius: 15px;
    font-size: 0.85em;
}

.tag-remove {
    cursor: pointer;
    font-weight: bold;
    opacity: 0.8;
}

.tag-remove:hover {
    opacity: 1;
}

.tag-input {
    border: none;
    outline: none;
    flex: 1;
    min-width: 100px;
    font-size: 0.9em;
    padding: 4px;
}

.tag-autocomplete {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: white;
    border: 1px solid #ddd;
    border-radius: 8px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    max-height: 200px;
    overflow-y: auto;
    z-index: 1000;
    margin-top: 5px;
}

.tag-autocomplete-item {
    padding: 8px 12px;
    cursor: pointer;
    border-bottom: 1px solid #eee;
}

.tag-autocomplete-item:hover,
.tag-autocomplete-item.selected {
    background: #f0f0f0;
}

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

.extract-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 2000;
    align-items: center;
    justify-content: center;
}

.extract-modal.active {
    display: flex;
}

.extract-modal-content {
    background: white;
    border-radius: 15px;
    padding: 30px;
    max-width: 600px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
}

.extract-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.extract-modal-title {
    font-size: 1.5em;
    color: #333;
}

.extract-modal-close {
    background: none;
    border: none;
    font-size: 1.5em;
    cursor: pointer;
    color: #999;
}

.extract-text {
    background: #f5f5f5;
    padding: 15px;
    border-radius: 8px;
    margin-bottom: 20px;
    max-height: 200px;
    overflow-y: auto;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.extract-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1em;
    transition: background 0.3s;
}

.btn-primary {
    background: #667eea;
    color: white;
}

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

.btn-secondary {
    background: #f0f0f0;
    color: #333;
}

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

.btn-small {
    padding: 6px 12px;
    font-size: 0.85em;
}

/* Sidebar */
.sidebar {
    width: 300px;
    background: #f8f9fa;
    border-right: 1px solid #dee2e6;
    display: flex;
    flex-direction: column;
    height: calc(100vh - 80px);
    position: fixed;
    left: 0;
    top: 80px;
}

.sidebar-header {
    padding: 15px;
    border-bottom: 1px solid #dee2e6;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.sidebar-header .btn {
    width: 100%;
}

.tag-filter-container {
    padding: 15px;
    border-bottom: 1px solid #dee2e6;
    position: relative;
}

.tag-filter-input {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #dee2e6;
    border-radius: 6px;
    font-size: 0.9em;
}

.tag-filter-results {
    position: absolute;
    top: 100%;
    left: 15px;
    right: 15px;
    background: white;
    border: 1px solid #dee2e6;
    border-radius: 6px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    max-height: 300px;
    overflow-y: auto;
    z-index: 1000;
    margin-top: 5px;
    display: none;
}

.tag-filter-results.active {
    display: block;
}

.tag-filter-item {
    padding: 10px 15px;
    cursor: pointer;
    border-bottom: 1px solid #f0f0f0;
    display: flex;
    align-items: center;
    gap: 10px;
}

.tag-filter-item:hover {
    background: #f8f9fa;
}

.tag-filter-item input[type="checkbox"] {
    margin: 0;
}

.chat-list {
    flex: 1;
    overflow-y: auto;
    padding: 10px;
}

.chat-item {
    padding: 12px;
    border-radius: 6px;
    margin-bottom: 8px;
    cursor: pointer;
    transition: background 0.2s;
    border: 1px solid transparent;
}

.chat-item:hover {
    background: #e9ecef;
}

.chat-item.active {
    background: #667eea;
    color: white;
    border-color: #5568d3;
}

.chat-item-title {
    font-weight: 500;
    margin-bottom: 5px;
}

.chat-item-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    font-size: 0.75em;
}

.chat-item-tag {
    background: rgba(255, 255, 255, 0.2);
    padding: 2px 6px;
    border-radius: 10px;
}

.chat-item.active .chat-item-tag {
    background: rgba(255, 255, 255, 0.3);
}

.chat-tags-display {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    margin-bottom: 10px;
}

.chat-tag {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    background: #667eea;
    color: white;
    padding: 4px 10px;
    border-radius: 15px;
    font-size: 0.85em;
}

.chat-tag-remove {
    cursor: pointer;
    font-weight: bold;
    opacity: 0.8;
}

.chat-tag-remove:hover {
    opacity: 1;
}

.chat-container {
    flex: 1;
    margin-left: 300px;
}
