* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', sans-serif;
    height: 100vh;
    overflow: hidden;
    background: url('login-background.jpeg') no-repeat center center fixed;
    background-size: cover;
    display: flex;
    align-items: center;
    justify-content: center;
}

@keyframes gradientShift {
    0% {
        background-position: 0% 50%;
    }
    50% {
        background-position: 100% 50%;
    }
    100% {
        background-position: 0% 50%;
    }
}

.chat-container {
    width: 100%;
    max-width: 900px;
    height: 90vh;
    background: linear-gradient(-45deg, #667eea, #764ba2, #667eea, #764ba2);
    background-size: 400% 400%;
    background-position: 0% 50%;
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    margin: 5vh auto;
    padding: 5px;
    transition: background-position 0.3s ease;
}

.chat-container.loading {
    background: linear-gradient(-45deg, #ff0000, #ff7f00, #ffff00, #00ff00, #0000ff, #4b0082, #9400d3, #ff0000);
    background-size: 400% 400%;
    animation: gradientShift 8s ease infinite;
}

.chat-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
    color: white;
    padding: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-radius: 15px 15px 0 0;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background: #f8f9fa;
}

.chat-input-container {
    display: flex;
    gap: 12px;
    padding: 20px;
    background: white;
    border-top: 1px solid #e0e0e0;
    border-radius: 0 0 15px 15px;
}

.chat-header h2 {
    font-size: 1.5rem;
    font-weight: 600;
}

.trace-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 0.9rem;
}

.trace-toggle input {
    cursor: pointer;
    width: 18px;
    height: 18px;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background: #f8f9fa;
}

.chat-messages::-webkit-scrollbar {
    width: 8px;
}

.chat-messages::-webkit-scrollbar-track {
    background: #f1f1f1;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 4px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: #555;
}

.message {
    margin-bottom: 16px;
    padding: 12px 16px;
    border-radius: 12px;
    max-width: 80%;
    animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.user-message {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    margin-left: auto;
    border-bottom-right-radius: 4px;
}

.assistant-message {
    background: white;
    color: #333;
    margin-right: auto;
    border: 1px solid #e0e0e0;
    border-bottom-left-radius: 4px;
}

.message-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 8px;
    font-size: 0.85rem;
    opacity: 0.9;
}

.message-content {
    line-height: 1.6;
    word-wrap: break-word;
}

/* Markdown rendering */
.message-content.markdown-body {
    white-space: normal;
}

.markdown-body p {
    margin-bottom: 0.6em;
}

.markdown-body p:last-child {
    margin-bottom: 0;
}

.markdown-body h1, .markdown-body h2, .markdown-body h3,
.markdown-body h4, .markdown-body h5, .markdown-body h6 {
    margin: 0.8em 0 0.4em;
    font-weight: 600;
    line-height: 1.3;
}

.markdown-body h1 { font-size: 1.4em; }
.markdown-body h2 { font-size: 1.2em; }
.markdown-body h3 { font-size: 1.05em; }

.markdown-body ul, .markdown-body ol {
    padding-left: 1.4em;
    margin-bottom: 0.6em;
}

.markdown-body li {
    margin-bottom: 0.2em;
}

.markdown-body a {
    color: #5a67d8;
    text-decoration: underline;
}

.assistant-message .markdown-body a {
    color: #5a67d8;
}

.markdown-body a:hover {
    color: #434190;
}

.markdown-body code {
    background: #f0f0f0;
    border-radius: 3px;
    padding: 0.1em 0.35em;
    font-family: 'Monaco', 'Consolas', 'Courier New', monospace;
    font-size: 0.85em;
    color: #c7254e;
}

.markdown-body pre {
    background: #1e1e1e;
    color: #d4d4d4;
    border-radius: 6px;
    padding: 0.75em 1em;
    overflow-x: auto;
    margin: 0.6em 0;
    font-size: 0.82em;
}

.markdown-body pre code {
    background: none;
    color: inherit;
    padding: 0;
    font-size: inherit;
}

.markdown-body table {
    border-collapse: collapse;
    width: 100%;
    margin: 0.6em 0;
    font-size: 0.9em;
}

.markdown-body th, .markdown-body td {
    border: 1px solid #d0d0d0;
    padding: 6px 12px;
    text-align: left;
}

.markdown-body th {
    background: #f5f5f5;
    font-weight: 600;
}

.markdown-body tr:nth-child(even) td {
    background: #fafafa;
}

.markdown-body blockquote {
    border-left: 3px solid #5a67d8;
    margin: 0.6em 0;
    padding: 0.3em 0.8em;
    color: #555;
    background: #f8f8ff;
    border-radius: 0 4px 4px 0;
}

.markdown-body hr {
    border: none;
    border-top: 1px solid #ddd;
    margin: 0.8em 0;
}

.mcp-traces {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid #e0e0e0;
    font-size: 0.85rem;
    color: #666;
}

.trace-section {
    margin-bottom: 6px;
}

.trace-item {
    display: inline-block;
    background: #f0f0f0;
    padding: 2px 8px;
    border-radius: 4px;
    margin-right: 6px;
    margin-top: 4px;
    color: #5a67d8;
    font-family: 'Monaco', 'Consolas', monospace;
    font-size: 0.8rem;
}

.mcp-request-traces {
    margin-top: 12px;
}

.request-trace-item {
    margin-top: 8px;
    padding: 8px;
    background: #f9f9f9;
    border-left: 3px solid #666;
    border-radius: 4px;
}

.trace-header {
    color: #555;
    font-size: 0.85rem;
    margin-bottom: 6px;
    font-weight: 500;
}

.trace-duration {
    color: #999;
    font-size: 0.75rem;
    font-weight: normal;
    margin-left: 8px;
}

.trace-request,
.trace-response {
    margin-top: 6px;
    color: #666;
}

.trace-label {
    font-weight: 600;
    color: #666;
    font-size: 0.8rem;
    display: block;
    margin-bottom: 4px;
}

.trace-request pre,
.trace-response pre {
    background: #f5f5f5;
    padding: 8px;
    border-radius: 4px;
    overflow-x: auto;
    font-family: 'Monaco', 'Consolas', 'Courier New', monospace;
    font-size: 0.75rem;
    line-height: 1.4;
    color: #666;
    margin: 0;
    white-space: pre-wrap;
    word-break: break-all;
}

.trace-request pre {
    border-left: 2px solid #999;
}

.trace-response pre {
    border-left: 2px solid #5a67d8;
}

.token-usage {
    margin-top: 6px;
}

.loading {
    opacity: 0.7;
}

.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 8px 0;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    background: #667eea;
    border-radius: 50%;
    animation: bounce 1.4s infinite;
}

.typing-indicator span:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-indicator span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes bounce {
    0%, 60%, 100% {
        transform: translateY(0);
    }
    30% {
        transform: translateY(-10px);
    }
}

.chat-input-container {
    display: flex;
    gap: 12px;
    padding: 20px;
    background: white;
    border-top: 1px solid #e0e0e0;
}

.chat-input {
    flex: 1;
    padding: 12px 16px;
    border: 2px solid #e0e0e0;
    border-radius: 24px;
    font-size: 1rem;
    outline: none;
    transition: border-color 0.2s;
}

.chat-input:focus {
    border-color: #667eea;
}

.chat-input:disabled {
    background: #f5f5f5;
    cursor: not-allowed;
}

.send-button {
    padding: 12px 32px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 24px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}

.send-button:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.send-button:active:not(:disabled) {
    transform: translateY(0);
}

.send-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Header controls */
.header-controls {
    display: flex;
    align-items: center;
    gap: 16px;
}

.toolbox-button {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    border-radius: 8px;
    padding: 8px 12px;
    font-size: 1.2rem;
    cursor: pointer;
    transition: background 0.2s, transform 0.2s;
}

.toolbox-button:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.1);
}

/* MCP Selector */
.mcp-selector {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 12px 20px;
    background: rgba(255, 255, 255, 0.95);
    border-bottom: 1px solid #e0e0e0;
    align-items: center;
}

.mcp-tag-container {
    display: flex;
    align-items: center;
    gap: 4px;
}

.mcp-tag {
    padding: 6px 14px;
    border-radius: 16px;
    font-size: 0.85rem;
    font-weight: 500;
    border: none;
    cursor: pointer;
    transition: all 0.2s;
}

.mcp-tag.active {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.mcp-tag.active:hover {
    opacity: 0.9;
    transform: scale(1.05);
}

.mcp-tag.inactive {
    background: #e0e0e0;
    color: #888;
}

.mcp-tag.inactive:hover {
    background: #d0d0d0;
    color: #666;
}

.mcp-tag.unavailable {
    background: #f0f0f0;
    color: #bbb;
    cursor: not-allowed;
    text-decoration: line-through;
}

.mcp-allowed-badge {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #43ea5a !important;
    color: white;
    border: none !important;
    outline: none;
    font-size: 0.9rem;
    font-weight: bold;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, transform 0.2s;
    box-shadow: none !important;
}

.mcp-allowed-badge:hover {
    background: #dc3545 !important;
    transform: scale(1.1);
}

.mcp-allowed-badge:focus {
    outline: none;
    box-shadow: none !important;
}

.mcp-refresh-button {
    padding: 6px 12px;
    border-radius: 16px;
    font-size: 1rem;
    border: 2px dashed #ccc;
    background: transparent;
    cursor: pointer;
    transition: all 0.2s;
    margin-left: auto;
}

.mcp-refresh-button:hover:not(:disabled) {
    border-color: #667eea;
    background: rgba(102, 126, 234, 0.1);
}

.mcp-refresh-button:disabled {
    cursor: wait;
    opacity: 0.7;
}

.refresh-spinner {
    display: inline-block;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.timestamp {
    font-size: 0.75rem;
    opacity: 0.7;
}

.reset-button {
    padding: 8px 10px;
    background: none !important;
    color: #999;
    border: none !important;
    border-radius: 50%;
    font-size: 1.2rem;
    cursor: pointer;
    transition: color 0.2s;
    box-shadow: none !important;
}

.reset-button:hover:not(:disabled) {
    color: #dc3545;
    background: none !important;
    border: none !important;
}

.reset-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.permission-btn {
    padding: 8px 16px;
    background: linear-gradient(135deg, #2196f3 0%, #1565c0 100%);
    color: white;
    border: none;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
    box-shadow: none;
}

.permission-btn:hover {
    background: linear-gradient(135deg, #1976d2 0%, #0d47a1 100%);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(33, 150, 243, 0.2);
}

.permission-btn.always {
    background: linear-gradient(135deg, #43ea5a 0%, #1ec047 100%);
}

.permission-btn.always:hover {
    background: linear-gradient(135deg, #2ecc40 0%, #27ae60 100%);
    box-shadow: 0 4px 12px rgba(67, 160, 71, 0.2);
}
