:root {
    --bg: #0a0a0f;
    --bg-elevated: #12121a;
    --bg-card: #1a1a24;
    --border: #2a2a3a;
    --text: #f0f0f5;
    --text-muted: #8888a0;
    --accent: #6366f1;
    --accent-hover: #818cf8;
    --purple: #a855f7;
    --success: #22c55e;
    --danger: #ef4444;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 4px 24px rgba(0,0,0,0.4);
    --font: 'Inter', system-ui, sans-serif;
    --mono: 'JetBrains Mono', monospace;
}

[data-theme="light"] {
    --bg: #f8f9fc;
    --bg-elevated: #ffffff;
    --bg-card: #f1f3f9;
    --border: #e2e4ef;
    --text: #1a1a2e;
    --text-muted: #6b6b80;
    --shadow: 0 4px 24px rgba(0,0,0,0.08);
}

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

html, body {
    height: 100%;
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    overflow: hidden;
}

/* ========== SPLASH ========== */
.splash {
    position: fixed;
    inset: 0;
    background: var(--bg);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    transition: opacity 0.5s ease, visibility 0.5s;
}

.splash.hide {
    opacity: 0;
    visibility: hidden;
}

.splash-content {
    text-align: center;
}

.logo-mark {
    width: 72px;
    height: 72px;
    margin: 0 auto 20px;
    animation: pulse 2s ease infinite;
}

.logo-mark svg {
    width: 100%;
    height: 100%;
    border-radius: 18px;
}

.splash-title {
    font-size: 2.2rem;
    font-weight: 700;
    letter-spacing: -0.03em;
    background: linear-gradient(135deg, #6366f1, #a855f7);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.splash-sub {
    color: var(--text-muted);
    margin-top: 6px;
    font-size: 0.95rem;
}

.splash-loader {
    width: 120px;
    height: 3px;
    background: var(--border);
    border-radius: 2px;
    margin: 28px auto 0;
    overflow: hidden;
}

.splash-loader .bar {
    height: 100%;
    width: 40%;
    background: linear-gradient(90deg, #6366f1, #a855f7);
    border-radius: 2px;
    animation: load 1.2s ease infinite;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

@keyframes load {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(350%); }
}

/* ========== APP LAYOUT ========== */
.app {
    display: flex;
    height: 100vh;
    height: 100dvh;
}

.app.hidden {
    display: none;
}

/* Sidebar */
.sidebar {
    width: 280px;
    background: var(--bg-elevated);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    transition: transform 0.3s ease;
    z-index: 100;
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 18px;
    border-bottom: 1px solid var(--border);
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 600;
    font-size: 1.1rem;
}

.brand-icon {
    width: 28px;
    height: 28px;
    color: var(--accent);
}

.brand-icon svg {
    width: 100%;
    height: 100%;
}

.chat-list {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
}

.chat-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    color: var(--text-muted);
    font-size: 0.9rem;
    transition: all 0.15s;
    margin-bottom: 4px;
}

.chat-item:hover,
.chat-item.active {
    background: var(--bg-card);
    color: var(--text);
}

.chat-item .title {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-item .delete {
    opacity: 0;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 2px;
}

.chat-item:hover .delete {
    opacity: 1;
}

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

.memory-status {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.memory-status .dot {
    width: 8px;
    height: 8px;
    background: var(--success);
    border-radius: 50%;
    animation: blink 2s infinite;
}

@keyframes blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

/* Main */
.main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    background: var(--bg);
}

.topbar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 20px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-elevated);
}

.model-select select {
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 8px 14px;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    cursor: pointer;
    outline: none;
}

.model-select select:focus {
    border-color: var(--accent);
}

.topbar-actions {
    margin-left: auto;
}

/* Chat */
.chat-container {
    flex: 1;
    overflow-y: auto;
    position: relative;
}

.welcome {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    padding: 40px 20px;
    text-align: center;
}

.welcome.hidden {
    display: none;
}

.welcome-logo {
    width: 64px;
    height: 64px;
    margin-bottom: 20px;
}

.welcome-logo svg {
    width: 100%;
    height: 100%;
    border-radius: 16px;
}

.welcome h2 {
    font-size: 1.6rem;
    font-weight: 600;
    margin-bottom: 8px;
}

.welcome p {
    color: var(--text-muted);
    font-size: 0.95rem;
    line-height: 1.5;
    max-width: 360px;
}

.quick-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 28px;
    justify-content: center;
}

.chip {
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 8px 14px;
    border-radius: 20px;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.15s;
}

.chip:hover {
    border-color: var(--accent);
    background: rgba(99, 102, 241, 0.1);
}

.messages {
    padding: 24px 20px 40px;
    max-width: 820px;
    margin: 0 auto;
    width: 100%;
}

.message {
    display: flex;
    gap: 14px;
    margin-bottom: 28px;
    animation: fadeIn 0.3s ease;
}

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

.message .avatar {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    font-weight: 600;
}

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

.message.assistant .avatar {
    background: linear-gradient(135deg, #6366f1, #a855f7);
    color: white;
}

.message .content {
    flex: 1;
    min-width: 0;
}

.message .role {
    font-size: 0.8rem;
    font-weight: 600;
    margin-bottom: 6px;
    color: var(--text-muted);
}

.message .text {
    line-height: 1.65;
    font-size: 0.95rem;
    white-space: pre-wrap;
    word-break: break-word;
}

.message .text pre {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 14px;
    overflow-x: auto;
    margin: 10px 0;
    font-family: var(--mono);
    font-size: 0.85rem;
}

.message .text code {
    font-family: var(--mono);
    background: var(--bg-card);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.88em;
}

.message .files {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 10px;
}

.file-chip {
    display: flex;
    align-items: center;
    gap: 6px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    padding: 6px 10px;
    border-radius: 6px;
    font-size: 0.8rem;
}

.file-chip img {
    width: 32px;
    height: 32px;
    object-fit: cover;
    border-radius: 4px;
}

/* Input Area */
.input-area {
    padding: 12px 20px 20px;
    background: var(--bg);
    border-top: 1px solid var(--border);
}

.file-preview {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 10px;
    max-width: 820px;
    margin-left: auto;
    margin-right: auto;
}

.file-preview:empty {
    display: none;
}

.preview-item {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    padding: 6px 10px;
    border-radius: 8px;
    font-size: 0.8rem;
    max-width: 200px;
}

.preview-item img {
    width: 36px;
    height: 36px;
    object-fit: cover;
    border-radius: 4px;
}

.preview-item .name {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
}

.preview-item .remove {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 1.1rem;
    line-height: 1;
    padding: 0 2px;
}

.preview-item .remove:hover {
    color: var(--danger);
}

.input-box {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 10px 12px;
    max-width: 820px;
    margin: 0 auto;
    transition: border-color 0.2s;
}

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

.input-box textarea {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text);
    font-family: var(--font);
    font-size: 0.95rem;
    resize: none;
    outline: none;
    max-height: 160px;
    line-height: 1.5;
    padding: 6px 0;
}

.input-box textarea::placeholder {
    color: var(--text-muted);
}

.send-btn {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: var(--accent);
    border: none;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, transform 0.1s;
    flex-shrink: 0;
}

.send-btn:hover {
    background: var(--accent-hover);
}

.send-btn:active {
    transform: scale(0.95);
}

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

.send-btn svg {
    width: 18px;
    height: 18px;
}

.input-meta {
    display: flex;
    gap: 8px;
    justify-content: center;
    margin-top: 8px;
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* Buttons */
.icon-btn {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
}

.icon-btn:hover {
    background: var(--bg-card);
    color: var(--text);
}

.icon-btn svg {
    width: 18px;
    height: 18px;
}

.text-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 0.8rem;
    cursor: pointer;
    padding: 4px 0;
}

.text-btn:hover {
    color: var(--danger);
}

/* Loading dots */
.typing {
    display: flex;
    gap: 4px;
    padding: 8px 0;
}

.typing span {
    width: 7px;
    height: 7px;
    background: var(--text-muted);
    border-radius: 50%;
    animation: bounce 1.2s infinite;
}

.typing span:nth-child(2) { animation-delay: 0.15s; }
.typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes bounce {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-6px); }
}

/* Mobile */
.mobile-only {
    display: none;
}

@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        transform: translateX(-100%);
    }
    
    .sidebar.open {
        transform: translateX(0);
    }
    
    .mobile-only {
        display: flex;
    }
    
    .messages {
        padding: 16px 12px 30px;
    }
    
    .input-area {
        padding: 10px 12px 16px;
    }
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 6px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}
