:root {
    --primary: #2563eb;
    --secondary: #64748b;
    --success: #10b981;
    --danger: #ef4444;
    --background: #f8fafc;
    --surface: #ffffff;
    --text: #1e293b;
    --border: #e2e8f0;
    --user-msg: #dbeafe;
    --ai-msg: #f1f5f9;
    --cpl-bg: #fef3c7;
    --focus-color: #4A90D9;
}

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

:focus-visible {
    outline: 3px solid var(--focus-color);
    outline-offset: 2px;
}

button:focus-visible,
a:focus-visible {
    outline: 3px solid var(--focus-color);
    outline-offset: 2px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--background);
    color: var(--text);
    min-height: 100vh;
}

.app-container {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.app-header {
    background: var(--primary);
    color: white;
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.app-header h1 {
    font-size: 1.5rem;
    margin-bottom: 0.25rem;
}

.app-header .subtitle {
    opacity: 0.9;
    font-size: 0.875rem;
}

.toggle-btn {
    padding: 0.5rem 1rem;
    border: 2px solid white;
    background: transparent;
    color: white;
    border-radius: 0.5rem;
    cursor: pointer;
    font-size: 0.875rem;
    transition: all 0.2s;
}

.toggle-btn:hover {
    background: white;
    color: var(--primary);
}

.toggle-btn:focus-visible {
    outline: 3px solid #ffffff;
    outline-offset: 2px;
}

.main-content {
    flex: 1;
    display: flex;
    justify-content: center;
    padding: 1rem;
}

.chat-container {
    width: 100%;
    max-width: 900px;
    display: flex;
    flex-direction: column;
    height: calc(100vh - 140px);
    background: var(--surface);
    border-radius: 1rem;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    overflow: hidden;
}

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

.message {
    display: flex;
    flex-direction: column;
    max-width: 80%;
}

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

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

.message-bubble {
    padding: 0.875rem 1.25rem;
    border-radius: 1rem;
    word-wrap: break-word;
}

.message.user .message-bubble {
    background: var(--user-msg);
    border-bottom-right-radius: 0.25rem;
}

.message.ai .message-bubble {
    background: var(--ai-msg);
    border-bottom-left-radius: 0.25rem;
}

.message-label {
    font-size: 0.75rem;
    color: var(--secondary);
    margin-bottom: 0.25rem;
    font-weight: 600;
}

.cpl-layer {
    background: var(--cpl-bg);
    padding: 0.5rem 0.75rem;
    margin-top: 0.5rem;
    border-radius: 0.5rem;
    font-size: 0.75rem;
    font-family: 'Courier New', monospace;
    color: #78350f;
    border: 1px solid #fbbf24;
    display: none;
}

.cpl-layer.visible {
    display: block;
}

.cpl-label {
    font-weight: 700;
    margin-bottom: 0.25rem;
    text-transform: uppercase;
    font-size: 0.7rem;
}

.loading-indicator {
    display: flex;
    gap: 0.5rem;
    padding: 0.875rem 1.25rem;
    align-items: center;
}

.loading-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--secondary);
    animation: bounce 1.4s infinite ease-in-out both;
}

.loading-dot:nth-child(1) { animation-delay: -0.32s; }
.loading-dot:nth-child(2) { animation-delay: -0.16s; }

@keyframes bounce {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1); }
}

.input-container {
    padding: 1.5rem;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 1rem;
}

#messageInput {
    flex: 1;
    padding: 0.875rem;
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    font-family: inherit;
    font-size: 0.95rem;
    resize: none;
    background: var(--background);
    color: var(--text);
}

#messageInput:focus-visible {
    outline: 3px solid var(--focus-color);
    outline-offset: 2px;
    border-color: var(--primary);
}

.send-btn {
    padding: 0.875rem 2rem;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 0.5rem;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.2s;
}

.send-btn:hover {
    background: #1d4ed8;
}

.send-btn:focus-visible {
    outline: 3px solid #ffffff;
    outline-offset: 2px;
}

.send-btn:disabled {
    background: var(--secondary);
    cursor: not-allowed;
    opacity: 0.6;
}

.app-footer {
    background: var(--surface);
    border-top: 1px solid var(--border);
    padding: 1rem;
    text-align: center;
    font-size: 0.875rem;
    color: var(--secondary);
}

@media (max-width: 768px) {
    .app-header {
        flex-direction: column;
        gap: 0.5rem;
        text-align: center;
    }

    .message {
        max-width: 90%;
    }

    .input-container {
        flex-direction: column;
    }

    .send-btn {
        width: 100%;
    }

    .chat-container {
        height: calc(100vh - 180px);
    }
}
