:root {
    --base-100: #1d232a;
    --base-200: #191e24;
    --base-300: #15191e;
    --base-content: #a6adba;
    --base-content-dim: rgba(166, 173, 186, 0.4);
    --base-content-muted: rgba(166, 173, 186, 0.7);
    --primary: #7480ff;
    --primary-content: #050617;
    --primary-dim: rgba(116, 128, 255, 0.5);
    --error: #ff6b6b;
    --error-bg: rgba(255, 107, 107, 0.1);
    --warning: #fbbd23;
    --info: #3abff8;
    --success: #36d399;
    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --radius: 1rem;
    --radius-sm: 0.5rem;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.3);
    --shadow-xl: 0 20px 25px rgba(0, 0, 0, 0.4);
    --transition: 200ms ease;
}

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

body {
    font-family: var(--font-family);
    background: var(--base-200);
    color: var(--base-content);
    height: 100vh;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
}

.chat-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    width: 100%;
    background: var(--base-200);
    overflow: hidden;
}

.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.5rem;
    background: var(--base-100);
    border-bottom: 1px solid var(--base-300);
    backdrop-filter: blur(12px);
    z-index: 10;
    flex-shrink: 0;
}

.chat-header-info {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.chat-header-title {
    font-size: 1rem;
    font-weight: 700;
    color: var(--base-content);
}

.chat-header-status {
    font-size: 0.75rem;
    margin-top: 0.125rem;
    transition: color var(--transition);
}

.chat-header-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.status-error {
    color: var(--error);
}

.status-warning {
    color: var(--warning);
}

.status-info {
    color: var(--info);
}

.status-ready {
    color: var(--base-content-muted);
}

.avatar {
    width: 2.5rem;
    height: 2.5rem;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    overflow: hidden;
}

.avatar-bot {
    background: var(--base-100);
    border: 1px solid var(--base-300);
    padding: 0.375rem;
    color: var(--primary);
}

.avatar-user {
    background: linear-gradient(135deg, var(--primary), #a78bfa);
    color: var(--primary-content);
    font-weight: 600;
    font-size: 0.75rem;
}

.avatar svg {
    width: 100%;
    height: 100%;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.375rem;
    font-family: var(--font-family);
    font-size: 0.8125rem;
    font-weight: 600;
    padding: 0.5rem 1rem;
    border-radius: var(--radius-sm);
    border: none;
    cursor: pointer;
    transition: all var(--transition);
    text-decoration: none;
    white-space: nowrap;
}

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

.btn-primary {
    background: var(--primary);
    color: var(--primary-content);
}

.btn-primary:hover:not(:disabled) {
    filter: brightness(1.1);
    box-shadow: 0 0 16px var(--primary-dim);
}

.btn-ghost {
    background: transparent;
    color: var(--base-content);
}

.btn-ghost:hover {
    background: rgba(255, 255, 255, 0.05);
}

.btn-sm {
    font-size: 0.75rem;
    padding: 0.375rem 0.75rem;
}

.btn-xs {
    font-size: 0.6875rem;
    padding: 0.25rem 0.5rem;
}

.btn-full {
    width: 100%;
}

.btn-icon {
    width: 1rem;
    height: 1rem;
}

.hidden {
    display: none !important;
}

.error-banner {
    background: var(--error-bg);
    border-bottom: 1px solid var(--error);
    padding: 0.75rem 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.error-banner-content {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.error-icon {
    width: 1.25rem;
    height: 1.25rem;
    color: var(--error);
    flex-shrink: 0;
}

#errorMessage {
    font-size: 0.875rem;
    color: var(--error);
}

.error-banner .btn-ghost {
    color: var(--error);
}

.modal {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: none;
    align-items: center;
    justify-content: center;
    margin: 0;
    padding: 0;
    width: 100vw;
    height: 100vh;
    border: none;
    background: transparent;
    max-width: none;
    max-height: none;
}

.modal[open] {
    display: flex;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(8px);
}

.modal-box {
    position: relative;
    z-index: 101;
    background: var(--base-100);
    border: 1px solid var(--base-300);
    border-radius: var(--radius);
    padding: 1.5rem;
    max-width: 28rem;
    width: 90%;
    box-shadow: var(--shadow-xl);
    animation: modalIn 200ms ease;
}

@keyframes modalIn {
    from {
        opacity: 0;
        transform: scale(0.95) translateY(8px);
    }

    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.modal-close {
    position: absolute;
    top: 0.5rem;
    right: 0.75rem;
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--base-content-muted);
    cursor: pointer;
    padding: 0.25rem;
    line-height: 1;
}

.modal-close:hover {
    color: var(--base-content);
}

.modal-title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 1.125rem;
    font-weight: 700;
    margin-bottom: 1rem;
    color: #ffffff;
}

.modal-title-icon {
    width: 1.25rem;
    height: 1.25rem;
    color: var(--primary);
}

.modal-body {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.auth-url-section {
    background: var(--base-200);
    border-radius: var(--radius-sm);
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.auth-url-description {
    font-size: 0.875rem;
    color: var(--base-content-muted);
}

.divider {
    border: none;
    border-top: 1px solid var(--base-300);
    margin: 0.5rem 0;
}

.auth-code-section {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.input-label {
    font-size: 0.875rem;
    font-weight: 600;
    color: #e0e0e0;
}

.input {
    width: 100%;
    padding: 0.625rem 0.75rem;
    font-family: 'SF Mono', 'Fira Code', monospace;
    font-size: 0.875rem;
    background: var(--base-200);
    border: 1px solid var(--base-300);
    border-radius: var(--radius-sm);
    color: var(--base-content);
    outline: none;
    transition: all var(--transition);
}

.input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px var(--primary-dim);
}

.input::placeholder {
    color: var(--base-content-dim);
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.chat-messages::-webkit-scrollbar {
    width: 6px;
}

.chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: var(--base-300);
    border-radius: 3px;
}

.message-row {
    display: flex;
    width: 100%;
    gap: 0.75rem;
    animation: fadeInUp 300ms ease;
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message-avatar {
    flex-shrink: 0;
}

.message-content {
    flex: 1;
    min-width: 0;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
}

.message-bubble {
    background: var(--base-100);
    border: 1px solid var(--base-300);
    border-radius: var(--radius);
    padding: 0.75rem 1rem;
    font-size: 0.875rem;
    line-height: 1.6;
    white-space: pre-wrap;
    word-break: break-word;
    max-width: 85%;
}

.message-bubble.message-bot {
    border-top-left-radius: 0.25rem;
    background: rgba(29, 35, 42, 0.6);
}

.message-bubble.message-user {
    border-top-right-radius: 0.25rem;
}

.message-time-wrapper {
    height: 2.5rem;
    display: flex;
    align-items: center;
    flex-shrink: 0;
    padding-left: 1rem;
}

.message-time {
    font-size: 0.75rem;
    color: var(--base-content-dim);
    white-space: nowrap;
}

.chat-input-area {
    background: var(--base-100);
    border-top: 1px solid var(--base-300);
    padding: 1rem 1.5rem;
    flex-shrink: 0;
}

.chat-input-wrapper {
    position: relative;
}

.chat-input {
    width: 100%;
    padding: 0.75rem 3.5rem 0.75rem 0.75rem;
    font-family: var(--font-family);
    font-size: 0.875rem;
    background: var(--base-200);
    border: 1px solid var(--base-300);
    border-radius: var(--radius-sm);
    color: var(--base-content);
    resize: none;
    outline: none;
    transition: all var(--transition);
    line-height: 1.5;
}

.chat-input:focus {
    background: var(--base-100);
    border-color: var(--primary);
    box-shadow: 0 0 0 2px var(--primary-dim);
}

.chat-input::placeholder {
    color: var(--base-content-dim);
}

.chat-input.disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.chat-submit-btn {
    position: absolute;
    bottom: 0.75rem;
    right: 0.75rem;
    width: 2rem;
    height: 2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--primary);
    color: var(--primary-content);
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition);
    padding: 0;
}

.chat-submit-btn:hover:not(:disabled) {
    filter: brightness(1.1);
    box-shadow: var(--shadow-md);
}

.chat-submit-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.send-icon {
    width: 1rem;
    height: 1rem;
}

.lock-icon {
    width: 1rem;
    height: 1rem;
    opacity: 0.3;
}

.spinner {
    width: 1rem;
    height: 1rem;
    border: 2px solid transparent;
    border-top-color: currentColor;
    border-radius: 50%;
    animation: spin 600ms linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

@media (max-width: 640px) {
    .chat-header {
        padding: 0.75rem 1rem;
    }

    .chat-messages {
        padding: 1rem;
    }

    .chat-input-area {
        padding: 0.75rem 1rem;
    }

    .message-bubble {
        max-width: 95%;
    }
}