* {
    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;
    display: flex;
    justify-content: flex-start;
    align-items: flex-start;
    padding: 20px 80px 20px 80px;
}

body.login-page {
    justify-content: center;
    align-items: center;
    padding: 20px;
}

.app-container {
    width: calc(100vw - 160px);
    height: 90vh;
    display: flex;
    gap: 20px;
}

.sidebar {
    width: 280px;
    min-width: 280px;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 16px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding: 20px;
}

.new-chat-btn {
    width: 100%;
    padding: 15px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    margin-bottom: 20px;
    transition: transform 0.2s, box-shadow 0.2s;
}

.new-chat-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
}

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

.chat-history h3 {
    font-size: 14px;
    color: #666;
    margin-bottom: 10px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.chat-history-list {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.chat-history-item {
    padding: 12px;
    background: #f5f5f5;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    border: 2px solid transparent;
}

.chat-history-item:hover {
    background: #e8e8ff;
}

.chat-history-item.active {
    background: linear-gradient(135deg, #667eea20 0%, #764ba220 100%);
    border-color: #667eea;
}

.chat-history-item-title-container {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
}

.chat-history-item-title {
    font-weight: 600;
    color: #333;
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-edit-btn,
.chat-delete-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    font-size: 14px;
    opacity: 0;
    transition: all 0.2s;
    flex-shrink: 0;
}

.chat-history-item:hover .chat-edit-btn,
.chat-history-item:hover .chat-delete-btn {
    opacity: 1;
}

.chat-edit-btn:hover {
    transform: scale(1.2);
}

.chat-delete-btn:hover {
    transform: scale(1.2);
    filter: brightness(1.2);
}

.chat-history-item-preview {
    font-size: 12px;
    color: #666;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-container {
    flex: 1;
    background: white;
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.chat-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 20px;
    border-radius: 16px 16px 0 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chat-header h1 {
    margin: 0;
    font-size: 24px;
}

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

.header-btn {
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.3);
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    text-decoration: none;
    display: inline-block;
}

.header-btn:hover {
    background: rgba(255, 255, 255, 0.3);
    border-color: rgba(255, 255, 255, 0.5);
    transform: translateY(-1px);
}

.api-keys-section {
    display: flex;
    gap: 15px;
    flex-wrap: wrap;
}

.api-key-container {
    display: flex;
    gap: 8px;
    flex: 1;
    min-width: 250px;
}

#claudeApiKeyInput,
#deepseekApiKeyInput {
    flex: 1;
    padding: 10px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
}

.save-key-btn {
    padding: 10px 15px;
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.3s;
    white-space: nowrap;
}

.save-key-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

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

.message {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    animation: slideIn 0.3s ease-out;
    position: relative;
}

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

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

.message-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    flex-shrink: 0;
}

.message.user .message-avatar {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

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

.message-content {
    max-width: 70%;
    padding: 12px 44px 12px 16px;
    border-radius: 12px;
    line-height: 1.5;
    position: relative;
}

.message.user .message-content {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-radius: 12px 12px 0 12px;
}

.message.assistant .message-content {
    background: #f0f0f0;
    color: #333;
    border-radius: 12px 12px 12px 0;
}

/* Copy button */
.copy-message-btn {
    position: absolute;
    bottom: 8px;
    right: 8px;
    width: 32px;
    height: 32px;
    border: none;
    background: rgba(0, 0, 0, 0.05);
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: all 0.2s ease;
    font-size: 16px;
    z-index: 10;
}

.message-content:hover .copy-message-btn {
    opacity: 1;
}

.copy-message-btn:hover {
    background: rgba(0, 0, 0, 0.1);
    transform: scale(1.05);
}

.copy-message-btn:active {
    transform: scale(0.95);
}

.copy-message-btn.copied {
    background: #4CAF50;
    color: white;
}

.message.user .copy-message-btn {
    background: rgba(255, 255, 255, 0.2);
    color: white;
}

.message.user .copy-message-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

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

#messageInput {
    width: 100%;
    padding: 12px;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    font-size: 14px;
    font-family: inherit;
    resize: none;
    transition: border-color 0.3s;
}

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

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

.provider-select {
    padding: 12px 40px 12px 16px;
    border: 2px solid #667eea;
    border-radius: 8px;
    background: white;
    background-image: url('data:image/svg+xml;charset=UTF-8,<svg xmlns="http://www.w3.org/2000/svg" width="12" height="8" viewBox="0 0 12 8"><path fill="%23667eea" d="M1.41 0L6 4.58 10.59 0 12 1.41l-6 6-6-6z"/></svg>');
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 12px;
    color: #333;
    font-size: 14px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    min-width: 150px;
    transition: all 0.3s;
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
}

.provider-select:hover {
    background-color: #f5f5ff;
    border-color: #764ba2;
    background-image: url('data:image/svg+xml;charset=UTF-8,<svg xmlns="http://www.w3.org/2000/svg" width="12" height="8" viewBox="0 0 12 8"><path fill="%23764ba2" d="M1.41 0L6 4.58 10.59 0 12 1.41l-6 6-6-6z"/></svg>');
}

.provider-select:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.2);
}

#sendBtn {
    padding: 12px 30px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    font-size: 14px;
    transition: transform 0.2s, box-shadow 0.2s;
}

#sendBtn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

#sendBtn:active {
    transform: translateY(0);
}

#sendBtn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.loading {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #667eea;
    animation: pulse 1.4s infinite ease-in-out;
}

@keyframes pulse {
    0%, 80%, 100% {
        opacity: 0.3;
    }
    40% {
        opacity: 1;
    }
}

/* Typing indicator for assistant messages */
.typing-indicator {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 0;
}

.typing-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #666;
    animation: typingAnimation 1.4s infinite;
}

.typing-dot:nth-child(1) {
    animation-delay: 0s;
}

.typing-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typingAnimation {
    0%, 60%, 100% {
        opacity: 0.3;
        transform: scale(0.8);
    }
    30% {
        opacity: 1;
        transform: scale(1);
    }
}

.error-message {
    background: #fee;
    color: #c33;
    padding: 10px;
    border-radius: 8px;
    margin: 10px;
    border: 1px solid #fcc;
}

.loading-message {
    text-align: center;
    padding: 20px;
    color: #667eea;
    font-size: 16px;
    font-weight: 500;
}

/* Modal Styles */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    animation: fadeIn 0.2s ease-out;
}

.modal.show {
    display: flex;
    justify-content: center;
    align-items: center;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

.modal-content {
    background: white;
    border-radius: 16px;
    padding: 0;
    width: 90%;
    max-width: 450px;
    max-height: 85vh;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    animation: slideUp 0.3s ease-out;
    display: flex;
    flex-direction: column;
}

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

.modal-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 24px;
    border-radius: 16px 16px 0 0;
    flex-shrink: 0;
}

.modal-header h2 {
    margin: 0;
    font-size: 22px;
    font-weight: 600;
}

.modal-body {
    padding: 24px;
    overflow-y: auto;
    flex: 1;
    min-height: 0;
}

.modal-body p {
    margin: 0 0 12px 0;
    color: #333;
    font-size: 16px;
    line-height: 1.5;
}

.modal-body p:last-child {
    margin-bottom: 0;
}

.modal-warning {
    color: #c33;
    font-size: 14px;
    font-weight: 500;
}

.modal-footer {
    padding: 20px 24px 24px 24px;
    display: flex;
    gap: 12px;
    justify-content: flex-end;
    flex-shrink: 0;
}

.modal-btn {
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

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

.modal-btn-cancel:hover {
    background: #e0e0e0;
}

.modal-btn-delete {
    background: linear-gradient(135deg, #ff4444 0%, #cc0000 100%);
    color: white;
}

.modal-btn-delete:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(255, 68, 68, 0.4);
}

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

.modal-btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.modal-btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

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

.modal-label {
    display: block;
    margin-bottom: 8px;
    color: #333;
    font-size: 14px;
    font-weight: 600;
}

.modal-input {
    width: 100%;
    padding: 12px;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    font-size: 15px;
    font-family: inherit;
    transition: border-color 0.3s;
}

.modal-input:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.modal-input::placeholder {
    color: #999;
}

.modal-select {
    width: 100%;
    padding: 12px;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    font-size: 15px;
    background-color: white;
    cursor: pointer;
    transition: border-color 0.3s;
}

.modal-select:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

/* Login Page Styles */
.login-container {
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
}

.login-card {
    background: white;
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    padding: 48px 40px;
    width: 100%;
    max-width: 420px;
    animation: slideUp 0.4s ease-out;
}

.login-title {
    font-size: 32px;
    font-weight: 700;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    text-align: center;
    margin-bottom: 12px;
}

.login-subtitle {
    text-align: center;
    color: #666;
    font-size: 16px;
    margin-bottom: 32px;
}

.login-form {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

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

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

.form-input {
    width: 100%;
    padding: 14px 16px;
    border: 2px solid #e0e0e0;
    border-radius: 10px;
    font-size: 15px;
    font-family: inherit;
    transition: all 0.3s;
}

.form-input:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.form-input::placeholder {
    color: #999;
}

.login-btn {
    width: 100%;
    padding: 14px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 10px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    margin-top: 12px;
    transition: transform 0.2s, box-shadow 0.2s;
}

.login-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
}

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

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

/* AI Settings Modal */
.modal-wide {
    max-width: 720px;
}

.settings-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.setting-item {
    display: flex;
    flex-direction: column;
}

.setting-full {
    grid-column: 1 / -1;
}

.modal-textarea {
    width: 100%;
    padding: 12px;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    font-size: 14px;
    font-family: inherit;
    transition: border-color 0.3s;
    resize: vertical;
}

.modal-textarea:focus {
    outline: none;
    border-color: #667eea;
}

.settings-hint {
    margin-top: 12px;
    font-size: 12px;
    color: #666;
    font-style: italic;
}

.setting-default {
    margin-top: 4px;
    font-size: 11px;
    color: #888;
    font-style: italic;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 14px;
}

.checkbox-label input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
    accent-color: #8b5cf6;
}

.checkbox-label span {
    user-select: none;
}

.setting-hint {
    margin-top: 6px;
    font-size: 12px;
    color: #888;
    font-style: italic;
}

/* Tooltip styles */
.label-with-tooltip {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 8px;
}

.tooltip-icon {
    cursor: help;
    font-size: 14px;
    opacity: 0.6;
    transition: opacity 0.2s;
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.tooltip-icon:hover {
    opacity: 1;
}

.tooltip-icon::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    margin-bottom: 8px;
    padding: 12px 16px;
    background: rgba(0, 0, 0, 0.9);
    color: white;
    border-radius: 8px;
    font-size: 13px;
    line-height: 1.5;
    white-space: normal;
    width: 280px;
    max-width: 90vw;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
    z-index: 1000;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    font-style: normal;
}

.tooltip-icon:hover::after {
    opacity: 1;
}

.tooltip-icon::before {
    content: '';
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    margin-bottom: 2px;
    border: 6px solid transparent;
    border-top-color: rgba(0, 0, 0, 0.9);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
    z-index: 1000;
}

.tooltip-icon:hover::before {
    opacity: 1;
}

/* HTML Response Format Styles */
.ai-response {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.ai-response .response-title,
.ai-response h3.response-title {
    font-size: 1.1em;
    font-weight: 600;
    margin: 0 0 8px 0;
    color: #333;
}

.ai-response .response-content {
    line-height: 1.6;
    color: #444;
}

.ai-response .response-content p {
    margin: 0 0 8px 0;
}

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

.ai-response .response-metadata {
    display: flex;
    gap: 12px;
    font-size: 0.85em;
    color: #888;
    margin-top: 8px;
}

.ai-response .response-metadata .confidence {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.ai-response .response-metadata .confidence::before {
    content: '✓';
}

.ai-response .response-metadata .category {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.ai-response .response-metadata .category::before {
    content: '📁';
}
