/* ===== CSS Variables - Elegant Dark Theme ===== */
:root {
    --bg-primary: #09090b;
    --bg-secondary: #0c0c0e;
    --bg-tertiary: #141417;
    --bg-elevated: #18181b;
    --bg-hover: #1f1f23;
    --bg-glass: rgba(12, 12, 14, 0.85);

    --text-primary: #fafafa;
    --text-secondary: #a1a1aa;
    --text-muted: #52525b;

    --accent: #8b5cf6;
    --accent-hover: #a78bfa;
    --accent-glow: rgba(139, 92, 246, 0.2);
    --accent-subtle: rgba(139, 92, 246, 0.1);

    --success: #10b981;
    --error: #f43f5e;
    --warning: #f59e0b;

    --border: rgba(255, 255, 255, 0.08);
    --border-accent: rgba(139, 92, 246, 0.4);

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.5);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.5);
    --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.6);
    --shadow-glow: 0 0 30px rgba(139, 92, 246, 0.2);

    --radius-sm: 8px;
    --radius: 12px;
    --radius-lg: 16px;

    --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-slow: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ===== Reset ===== */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    overflow: hidden;
    min-height: 100vh;
}

body::before {
    content: '';
    position: fixed;
    inset: 0;
    background: radial-gradient(ellipse 80% 50% at 50% -20%, rgba(139, 92, 246, 0.1), transparent);
    pointer-events: none;
}

::selection {
    background: var(--accent);
    color: white;
}

/* ===== Layout ===== */
.app-container {
    display: flex;
    height: 100vh;
}

/* ===== Sidebar ===== */
.sidebar {
    width: 300px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    z-index: 100;
}

.sidebar-header {
    padding: 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.menu-close {
    display: none;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 20px;
    cursor: pointer;
    padding: 4px;
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo-icon {
    font-size: 28px;
}

.logo-text {
    font-size: 16px;
    font-weight: 600;
    background: linear-gradient(135deg, var(--text-primary), var(--text-secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.sidebar-content {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.settings-section {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.settings-section > label {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.server-input-group {
    display: flex;
    gap: 8px;
}

.server-input-group input {
    flex: 1;
    padding: 10px 12px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 13px;
    font-family: monospace;
}

.server-input-group input:focus {
    outline: none;
    border-color: var(--accent);
}

.connect-btn {
    padding: 10px 14px;
    background: var(--accent);
    border: none;
    border-radius: var(--radius-sm);
    color: white;
    cursor: pointer;
    transition: all var(--transition);
}

.connect-btn:hover {
    background: var(--accent-hover);
}

.connect-btn.loading {
    opacity: 0.7;
    pointer-events: none;
}

.connect-btn svg {
    width: 16px;
    height: 16px;
}

.hint {
    font-size: 11px;
    color: var(--text-muted);
}

.hint.success { color: var(--success); }
.hint.error { color: var(--error); }

select {
    width: 100%;
    padding: 10px 12px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 13px;
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%2371717a'%3E%3Cpath d='M2 4l4 4 4-4'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
}

select:focus {
    outline: none;
    border-color: var(--accent);
}

select:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.memory-info {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    background: var(--accent-subtle);
    border: 1px solid var(--border-accent);
    border-radius: var(--radius-sm);
    font-size: 12px;
}

.memory-count {
    color: var(--accent-hover);
    font-weight: 600;
}

.setting-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 13px;
    color: var(--text-secondary);
}

.setting-row input[type="range"] {
    width: 90px;
    accent-color: var(--accent);
}

.setting-row select {
    width: 110px;
    padding: 6px 8px;
    font-size: 12px;
}

.toggle {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    font-size: 13px;
    color: var(--text-secondary);
    margin-top: 4px;
}

.toggle input { display: none; }

.toggle-slider {
    width: 40px;
    height: 22px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 11px;
    position: relative;
    transition: all var(--transition);
}

.toggle-slider::after {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    background: var(--text-muted);
    border-radius: 50%;
    top: 2px;
    left: 2px;
    transition: all var(--transition);
}

.toggle input:checked + .toggle-slider {
    background: var(--accent);
    border-color: var(--accent);
}

.toggle input:checked + .toggle-slider::after {
    transform: translateX(18px);
    background: white;
}

.actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: auto;
}

.action-btn {
    padding: 10px 14px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 13px;
    font-family: inherit;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all var(--transition);
}

.action-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.action-btn.danger:hover {
    background: rgba(244, 63, 94, 0.1);
    border-color: rgba(244, 63, 94, 0.3);
    color: var(--error);
}

.sidebar-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--border);
}

.status {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: var(--text-muted);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-muted);
}

.status-dot.connected {
    background: var(--success);
    box-shadow: 0 0 8px var(--success);
}

.status-dot.error {
    background: var(--error);
}

/* ===== Mobile Menu ===== */
.overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 50;
}

.menu-btn {
    display: none;
    background: none;
    border: none;
    color: var(--text-secondary);
    padding: 8px;
    cursor: pointer;
}

.menu-btn svg {
    width: 24px;
    height: 24px;
}

/* ===== Chat Area ===== */
.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.chat-header {
    padding: 16px 24px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-glass);
    backdrop-filter: blur(20px);
    display: flex;
    align-items: center;
    gap: 16px;
}

.header-content h1 {
    font-size: 18px;
    font-weight: 600;
}

.header-content p {
    font-size: 12px;
    color: var(--text-muted);
}

/* ===== Messages ===== */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.welcome-message {
    text-align: center;
    padding: 40px 20px;
    max-width: 560px;
    margin: auto;
}

.welcome-icon {
    font-size: 56px;
    margin-bottom: 20px;
}

.welcome-message h2 {
    font-size: 24px;
    font-weight: 600;
    margin-bottom: 12px;
}

.welcome-message > p {
    color: var(--text-muted);
    margin-bottom: 32px;
}

.setup-card {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 24px;
    text-align: left;
    margin-bottom: 32px;
}

.setup-card h3 {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 16px;
    color: var(--text-secondary);
}

.setup-steps {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.step {
    display: flex;
    gap: 14px;
    align-items: flex-start;
}

.step-num {
    width: 24px;
    height: 24px;
    background: var(--accent);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 600;
    flex-shrink: 0;
}

.step strong {
    display: block;
    font-size: 13px;
    margin-bottom: 4px;
}

.step code {
    display: inline-block;
    background: var(--bg-primary);
    padding: 6px 10px;
    border-radius: 6px;
    font-size: 12px;
    font-family: monospace;
    color: var(--accent-hover);
    margin-top: 4px;
}

.step .muted {
    font-size: 12px;
    color: var(--text-muted);
}

.features {
    display: flex;
    justify-content: center;
    gap: 12px;
    flex-wrap: wrap;
}

.feature {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 13px;
    color: var(--text-secondary);
    transition: all var(--transition);
}

.feature:hover {
    border-color: var(--border-accent);
    transform: translateY(-2px);
}

/* Message Bubbles */
.message {
    display: flex;
    gap: 14px;
    max-width: 80%;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}

.message.user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.message-avatar {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-sm);
    background: var(--bg-elevated);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
}

.message.user .message-avatar {
    background: linear-gradient(135deg, var(--accent), #7c3aed);
}

.message-content {
    padding: 14px 18px;
    border-radius: var(--radius-lg);
    line-height: 1.6;
}

.message.user .message-content {
    background: linear-gradient(135deg, var(--accent), #7c3aed);
    color: white;
}

.message.assistant .message-content {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
}

.message-text {
    font-size: 14px;
    white-space: pre-wrap;
    word-break: break-word;
}

.message-text code {
    background: rgba(0, 0, 0, 0.3);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: monospace;
    font-size: 13px;
}

.message.assistant .message-text code {
    background: var(--bg-primary);
}

.message-text pre {
    background: var(--bg-primary);
    border: 1px solid var(--border);
    padding: 14px;
    border-radius: var(--radius-sm);
    overflow-x: auto;
    margin: 10px 0;
}

.message-text pre code {
    background: none;
    padding: 0;
}

.message-actions {
    display: flex;
    gap: 6px;
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--border);
}

.msg-action-btn {
    padding: 5px 10px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-muted);
    font-size: 11px;
    font-family: inherit;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 4px;
    transition: all var(--transition);
}

.msg-action-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

/* Typing */
.typing-indicator {
    display: flex;
    gap: 5px;
    padding: 4px 0;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    background: var(--accent);
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out;
}

.typing-indicator span:nth-child(2) { animation-delay: 0.15s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.3s; }

@keyframes bounce {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-6px); }
}

/* ===== Input ===== */
.chat-input-area {
    padding: 16px 24px 24px;
    background: var(--bg-glass);
    backdrop-filter: blur(20px);
    border-top: 1px solid var(--border);
}

.input-container {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 8px 8px 8px 16px;
    transition: all var(--transition);
}

.input-container:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.input-container textarea {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 14px;
    font-family: inherit;
    resize: none;
    max-height: 120px;
    outline: none;
    padding: 8px 0;
}

.input-container textarea::placeholder {
    color: var(--text-muted);
}

.input-container textarea:disabled {
    cursor: not-allowed;
}

.input-actions {
    display: flex;
    gap: 6px;
}

.voice-btn, .send-btn {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-sm);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition);
}

.voice-btn {
    background: var(--bg-tertiary);
    color: var(--text-secondary);
}

.voice-btn:hover:not(:disabled) {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.voice-btn.listening {
    background: var(--error);
    color: white;
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.08); }
}

.voice-btn svg, .send-btn svg {
    width: 18px;
    height: 18px;
}

.send-btn {
    background: linear-gradient(135deg, var(--accent), #7c3aed);
    color: white;
}

.send-btn:hover:not(:disabled) {
    transform: scale(1.05);
}

.voice-btn:disabled, .send-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none;
}

.input-hint {
    display: flex;
    justify-content: space-between;
    margin-top: 8px;
    font-size: 11px;
    color: var(--text-muted);
    padding: 0 4px;
}

#voice-status {
    color: var(--accent);
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--bg-hover); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ===== Responsive ===== */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        transform: translateX(-100%);
        transition: transform var(--transition-slow);
        box-shadow: var(--shadow-lg);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .overlay.open {
        display: block;
    }

    .menu-btn, .menu-close {
        display: block;
    }

    .message {
        max-width: 90%;
    }

    .chat-messages {
        padding: 16px;
    }

    .chat-input-area {
        padding: 12px 16px 20px;
    }

    .welcome-message {
        padding: 24px 12px;
    }

    .setup-card {
        padding: 16px;
    }
}
