:root {
    --bg-color: #0d0f14;
    --sidebar-bg: rgba(20, 24, 31, 0.8);
    --card-bg: rgba(30, 35, 45, 0.6);
    --primary-gradient: linear-gradient(135deg, #6366f1 0%, #a855f7 50%, #ec4899 100%);
    --accent-color: #a855f7;
    --text-primary: #ffffff;
    --text-secondary: #94a3b8;
    --border-color: rgba(255, 255, 255, 0.1);
    --msg-bg-assistant: rgba(45, 55, 72, 0.5);
    --msg-bg-user: rgba(99, 102, 241, 0.2);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Inter', sans-serif;
}

body {
    background-color: var(--bg-color);
    color: var(--text-primary);
    overflow: hidden;
    height: 100vh;
    width: 100vw;
}

.background-glow {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 800px;
    height: 800px;
    background: radial-gradient(circle, rgba(168, 85, 247, 0.15) 0%, rgba(0, 0, 0, 0) 70%);
    z-index: -1;
    pointer-events: none;
}

.app-container {
    display: flex;
    height: 100vh;
    backdrop-filter: blur(20px);
}

/* Sidebar */
.sidebar {
    width: 280px;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    padding: 2rem 1.5rem;
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 3rem;
}

.logo-icon {
    width: 40px;
    height: 40px;
    background: var(--primary-gradient);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
}

.logo h1 {
    font-family: 'Outfit', sans-serif;
    font-size: 1.4rem;
    font-weight: 700;
}

.logo span {
    background: var(--primary-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.nav-links {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    flex-grow: 1;
}

.nav-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    padding: 1rem;
    text-align: left;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 1rem;
    font-size: 1rem;
    font-weight: 500;
}

.nav-btn:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
}

.nav-btn.active {
    background: rgba(99, 102, 241, 0.15);
    color: var(--text-primary);
    box-shadow: inset 0 0 0 1px rgba(99, 102, 241, 0.3);
}

.sidebar-footer {
    padding-top: 1rem;
    border-top: 1px solid var(--border-color);
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

.online { background-color: #10b981; box-shadow: 0 0 8px #10b981; }

/* Content Area */
.content-area {
    flex-grow: 1;
    position: relative;
    padding: 2rem;
    overflow-y: auto;
}

.section {
    display: none;
    min-height: 100%;
    flex-direction: column;
    animation: fadeIn 0.4s ease;
}

.section.active { display: flex; }

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

.section-header {
    margin-bottom: 2rem;
}

.section-header h2 {
    font-family: 'Outfit', sans-serif;
    font-size: 2rem;
    margin-bottom: 0.25rem;
}

.section-header p {
    color: var(--text-secondary);
}

/* Chat Styles */
.chat-viewport {
    flex-grow: 1;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.message {
    display: flex;
    gap: 1rem;
    max-width: 80%;
}

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

.avatar {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9rem;
    flex-shrink: 0;
}

.message.user .avatar {
    background: var(--accent-color);
}

.bubble {
    padding: 1rem 1.25rem;
    border-radius: 18px;
    line-height: 1.6;
    font-size: 0.95rem;
    word-break: break-word;
}

.assistant .bubble {
    max-width: 100%;
    background: var(--msg-bg-assistant);
    border-bottom-left-radius: 4px;
    border: 1px solid var(--border-color);
}

/* Markdown Extra Styling */
.bubble h1, .bubble h2, .bubble h3 { margin: 1rem 0 0.5rem 0; font-family: 'Outfit'; }
.bubble code { background: rgba(0,0,0,0.3); padding: 0.2rem 0.4rem; border-radius: 4px; font-family: monospace; }
.bubble pre { background: #1a1a1a !important; padding: 1rem; border-radius: 12px; overflow-x: auto; margin: 1rem 0; border: 1px solid var(--border-color); }
.bubble table { border-collapse: collapse; margin: 1rem 0; width: 100%; }
.bubble th, .bubble td { border: 1px solid var(--border-color); padding: 0.75rem; text-align: left; }
.bubble th { background: rgba(255,255,255,0.05); }

/* Attachment UI */
#attach-btn { background: transparent; border: none; color: var(--text-secondary); font-size: 1.1rem; padding: 0.5rem; }
.attachment-preview { 
    display: flex; gap: 0.5rem; padding: 0.5rem 0; flex-wrap: wrap; 
}
.attach-tag { 
    background: rgba(168, 85, 247, 0.2); border: 1px solid var(--accent-color); 
    padding: 4px 10px; border-radius: 8px; font-size: 0.8rem; display: flex; align-items: center; gap: 5px;
}
.attach-tag i { cursor: pointer; color: #f43f5e; }

/* Settings & API Keys */
.settings-grid { display: grid; grid-template-columns: 1.5fr 1fr; gap: 2rem; }
.key-item { 
    background: rgba(0,0,0,0.2); border: 1px solid var(--border-color);
    padding: 1rem; border-radius: 12px; display: flex; justify-content: space-between;
    align-items: center; margin-bottom: 0.75rem; 
}
.key-details { display: flex; flex-direction: column; gap: 0.25rem; }
.key-string { font-family: monospace; color: var(--accent-color); font-size: 0.9rem; }
.key-name { font-weight: 600; font-size: 0.8rem; color: var(--text-secondary); }
.badge { padding: 4px 8px; border-radius: 6px; font-size: 0.7rem; font-weight: 700; }
.badge.online { background: rgba(16, 185, 129, 0.2); color: #10b981; }
.badge.offline { background: rgba(244, 63, 94, 0.2); color: #f43f5e; }
.service-item { display: flex; justify-content: space-between; padding: 1rem 0; border-bottom: 1px solid var(--border-color); }
.service-item:last-child { border-bottom: none; }
.revoke-btn { color: #f43f5e; cursor: pointer; font-size: 1.1rem; transition: transform 0.2s; }
.revoke-btn:hover { transform: scale(1.2); }
    background: var(--msg-bg-user);
    border-bottom-right-radius: 4px;
    border: 1px solid rgba(99, 102, 241, 0.3);
}

.input-container {
    padding: 0 1rem;
}

.input-wrapper {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    display: flex;
    align-items: flex-end;
    padding: 0.75rem 1rem;
    gap: 1rem;
    transition: border-color 0.3s ease;
}

.input-wrapper:focus-within {
    border-color: var(--accent-color);
}

textarea {
    flex-grow: 1;
    background: transparent;
    border: none;
    color: var(--text-primary);
    resize: none;
    font-size: 1rem;
    padding: 0.5rem 0;
    max-height: 200px;
    outline: none;
}

.input-actions {
    display: flex;
    gap: 0.5rem;
    padding-bottom: 0.25rem;
}

button {
    cursor: pointer;
}

#tts-toggle {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 1.2rem;
    transition: color 0.3s ease;
}

#tts-toggle.active { color: #f43f5e; }

.primary-btn {
    background: var(--primary-gradient);
    border: none;
    color: white;
    width: 40px;
    height: 40px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease;
}

.primary-btn:hover {
    transform: scale(1.05);
}

/* TTS Grid Area */
.tts-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2rem;
    flex-grow: 1;
}

.card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 24px;
    padding: 2rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.card h3 {
    font-family: 'Outfit', sans-serif;
    font-size: 1.2rem;
    color: var(--text-secondary);
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.control-group label {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.control-group textarea, .control-group select {
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 1rem;
    color: white;
}

.primary-btn.wide {
    width: 100%;
    height: 50px;
    font-weight: 600;
    font-size: 1rem;
    justify-content: center;
    gap: 1rem;
}

.visualizer {
    height: 100px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    margin-bottom: 1.5rem;
}

.bar {
    width: 6px;
    height: 20px;
    background: var(--primary-gradient);
    border-radius: 3px;
    transition: height 0.1s ease;
}

.visualizing .bar {
    animation: wave 1s infinite ease-in-out;
}

.bar:nth-child(2) { animation-delay: 0.1s; }
.bar:nth-child(3) { animation-delay: 0.2s; }
.bar:nth-child(4) { animation-delay: 0.3s; }
.bar:nth-child(5) { animation-delay: 0.4s; }

@keyframes wave {
    0%, 100% { height: 20px; }
    50% { height: 60px; }
}

audio {
    width: 100%;
    filter: invert(1) hue-rotate(180deg) brightness(1.5);
}

.audio-info {
    text-align: center;
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-top: 1rem;
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, 0.2); }
