:root {
    --bg-main: #0d0e12;
    --bg-surface: #14151b;
    --bg-sidebar: #101117;
    --bg-input: #1b1c24;
    --bg-hover: #22242f;
    --bg-active: #2b2e3c;
    --border-subtle: #242632;
    --border-strong: #333647;
    --text-primary: #f3f4f6;
    --text-secondary: #9ca3af;
    --text-muted: #6b7280;
    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --accent-gradient: linear-gradient(135deg, #3b82f6 0%, #06b6d4 100%);
    --accent-glow: rgba(59, 130, 246, 0.25);
    --bubble-user: #212534;
    --bubble-assistant: transparent;
    --danger: #ef4444;
    --success: #10b981;
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 18px;
    --radius-full: 9999px;
    --sidebar-width: 280px;
    --top-nav-height: 56px;
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --font-mono: 'JetBrains Mono', monospace;
    --transition-fast: 0.15s ease;
    --transition-normal: 0.25s ease;
}

body.light-theme {
    --bg-main: #ffffff;
    --bg-surface: #f9fafb;
    --bg-sidebar: #f3f4f6;
    --bg-input: #f3f4f6;
    --bg-hover: #e5e7eb;
    --bg-active: #d1d5db;
    --border-subtle: #e5e7eb;
    --border-strong: #d1d5db;
    --text-primary: #111827;
    --text-secondary: #4b5563;
    --text-muted: #9ca3af;
    --bubble-user: #f3f4f6;
    --bubble-assistant: transparent;
}

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

html, body {
    height: 100%;
    width: 100%;
    overflow: hidden;
    font-family: var(--font-sans);
    background-color: var(--bg-main);
    color: var(--text-primary);
    -webkit-font-smoothing: antialiased;
}

.app-container {
    display: flex;
    height: 100%;
    width: 100%;
    position: relative;
    overflow: hidden;
}

/* ==================== SIDEBAR ==================== */
.sidebar {
    width: var(--sidebar-width);
    height: 100%;
    background-color: var(--bg-sidebar);
    border-right: 1px solid var(--border-subtle);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    transition: transform var(--transition-normal);
    z-index: 50;
}

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

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
}

.brand-icon {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-sm);
    background: var(--accent-gradient);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #ffffff;
    box-shadow: 0 4px 12px var(--accent-glow);
}

.brand-name {
    font-weight: 700;
    font-size: 1.1rem;
    letter-spacing: -0.02em;
}

.brand-badge {
    font-size: 0.7rem;
    font-weight: 600;
    padding: 2px 6px;
    border-radius: var(--radius-full);
    background: var(--bg-hover);
    color: var(--accent);
    border: 1px solid var(--border-strong);
}

.sidebar-action {
    padding: 14px 16px;
}

.new-chat-btn {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 16px;
    border-radius: var(--radius-md);
    background: var(--accent-gradient);
    color: #ffffff;
    font-weight: 600;
    border: none;
    cursor: pointer;
    transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}

.new-chat-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 16px var(--accent-glow);
}

.sidebar-history-container {
    flex: 1;
    overflow-y: auto;
    padding: 8px 12px;
    scrollbar-width: thin;
    scrollbar-color: var(--border-subtle) transparent;
}

.history-label {
    font-size: 0.75rem;
    text-transform: uppercase;
    font-weight: 600;
    color: var(--text-muted);
    padding: 8px 8px 6px;
    letter-spacing: 0.05em;
}

.history-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.history-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 0.88rem;
    cursor: pointer;
    transition: background var(--transition-fast), color var(--transition-fast);
    text-decoration: none;
    overflow: hidden;
}

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

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

.history-item-delete {
    opacity: 0;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 2px;
    display: flex;
    align-items: center;
    transition: color var(--transition-fast);
}

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

.history-item-delete:hover {
    color: var(--danger);
}

.history-empty {
    padding: 24px 8px;
    text-align: center;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.sidebar-footer {
    padding: 14px 16px;
    border-top: 1px solid var(--border-subtle);
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* Quota pill and progress */
.quota-banner {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: 10px 12px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.quota-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 0.82rem;
}

.quota-title {
    font-weight: 500;
    color: var(--text-secondary);
}

.quota-pill {
    font-size: 0.75rem;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: var(--radius-full);
    background-color: rgba(59, 130, 246, 0.15);
    color: var(--accent);
}

.quota-pill.low {
    background-color: rgba(239, 68, 68, 0.15);
    color: var(--danger);
}

.quota-progress-bg {
    height: 4px;
    background-color: var(--border-subtle);
    border-radius: var(--radius-full);
    overflow: hidden;
}

.quota-progress-bar {
    height: 100%;
    background: var(--accent-gradient);
    border-radius: var(--radius-full);
    transition: width 0.3s ease;
}

.quota-hint {
    font-size: 0.72rem;
    color: var(--text-muted);
}

/* User profile */
.user-profile-section {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 4px;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 10px;
    overflow: hidden;
}

.user-avatar {
    width: 34px;
    height: 34px;
    border-radius: var(--radius-full);
    background: var(--accent-gradient);
    color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.85rem;
}

.user-details {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.user-name {
    font-size: 0.88rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-email {
    font-size: 0.75rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ==================== MAIN CONTENT ==================== */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100%;
    position: relative;
    overflow: hidden;
    background-color: var(--bg-main);
}

.top-nav {
    height: var(--top-nav-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    border-bottom: 1px solid var(--border-subtle);
    flex-shrink: 0;
    background-color: var(--bg-main);
}

.top-nav-left, .top-nav-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.model-selector {
    display: flex;
    align-items: center;
    gap: 8px;
    background-color: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    padding: 6px 12px;
    border-radius: var(--radius-full);
}

.model-name {
    font-size: 0.88rem;
    font-weight: 600;
}

.model-badge {
    font-size: 0.7rem;
    padding: 2px 6px;
    border-radius: var(--radius-full);
    background: rgba(59, 130, 246, 0.15);
    color: var(--accent);
    font-weight: 600;
}

/* Chat Messages */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px 20px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    scroll-behavior: smooth;
    max-width: 860px;
    width: 100%;
    margin: 0 auto;
}

/* Welcome Hero */
.welcome-hero {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    margin: auto 0;
    padding: 40px 0;
    text-align: center;
}

.hero-icon-container {
    width: 64px;
    height: 64px;
    border-radius: var(--radius-lg);
    background: var(--accent-gradient);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #ffffff;
    margin-bottom: 20px;
    box-shadow: 0 8px 24px var(--accent-glow);
}

.hero-title {
    font-size: 1.8rem;
    font-weight: 700;
    letter-spacing: -0.03em;
    margin-bottom: 10px;
}

.hero-subtitle {
    font-size: 0.98rem;
    color: var(--text-secondary);
    max-width: 580px;
    line-height: 1.5;
    margin-bottom: 32px;
}

.prompt-cards-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    width: 100%;
    max-width: 720px;
}

.prompt-card {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    background-color: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: 14px 16px;
    text-align: left;
    cursor: pointer;
    transition: transform var(--transition-fast), border-color var(--transition-fast), background var(--transition-fast);
}

.prompt-card:hover {
    transform: translateY(-2px);
    border-color: var(--border-strong);
    background-color: var(--bg-hover);
}

.card-icon {
    font-size: 1.4rem;
    flex-shrink: 0;
}

.card-text {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.card-text strong {
    font-size: 0.88rem;
    font-weight: 600;
}

.card-text span {
    font-size: 0.78rem;
    color: var(--text-muted);
}

/* Chat Message Row */
.message-row {
    display: flex;
    gap: 14px;
    width: 100%;
    animation: fadeIn 0.2s ease;
}

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

.message-row.user {
    justify-content: flex-end;
}

.message-row.user .message-bubble {
    background-color: var(--bubble-user);
    border-radius: var(--radius-lg) var(--radius-lg) 4px var(--radius-lg);
    border: 1px solid var(--border-subtle);
    max-width: 80%;
}

.message-row.assistant .message-bubble {
    background-color: var(--bubble-assistant);
    flex: 1;
    max-width: 100%;
}

.message-avatar {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.message-avatar.bot {
    background: var(--accent-gradient);
    color: #ffffff;
}

.message-avatar.user-avatar {
    background: var(--bg-hover);
    color: var(--text-primary);
    font-weight: 600;
    font-size: 0.8rem;
}

.message-bubble {
    padding: 12px 18px;
    font-size: 0.95rem;
    line-height: 1.65;
    position: relative;
    word-break: break-word;
}

/* Tool execution status badge */
.tool-status-badge {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background-color: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-full);
    padding: 4px 12px;
    font-size: 0.8rem;
    color: var(--accent);
    margin-bottom: 12px;
    font-weight: 500;
}

.tool-spinner {
    width: 12px;
    height: 12px;
    border: 2px solid rgba(59, 130, 246, 0.25);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

/* Markdown styling inside assistant message */
.markdown-body {
    color: var(--text-primary);
}

.markdown-body p {
    margin-bottom: 12px;
}

.markdown-body p:last-child {
    margin-bottom: 0;
}

.markdown-body h1, .markdown-body h2, .markdown-body h3, .markdown-body h4 {
    margin: 18px 0 10px;
    font-weight: 700;
    line-height: 1.3;
}

.markdown-body ul, .markdown-body ol {
    margin: 10px 0 14px 22px;
}

.markdown-body li {
    margin-bottom: 6px;
}

.markdown-body blockquote {
    border-left: 3px solid var(--accent);
    padding-left: 14px;
    color: var(--text-secondary);
    margin: 12px 0;
}

.markdown-body table {
    width: 100%;
    border-collapse: collapse;
    margin: 14px 0;
    font-size: 0.88rem;
}

.markdown-body th, .markdown-body td {
    border: 1px solid var(--border-subtle);
    padding: 8px 12px;
    text-align: left;
}

.markdown-body th {
    background-color: var(--bg-surface);
    font-weight: 600;
}

/* Code blocks */
.code-block-wrapper {
    position: relative;
    margin: 14px 0;
    border-radius: var(--radius-md);
    background-color: #121319;
    border: 1px solid var(--border-subtle);
    overflow: hidden;
}

.code-block-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 14px;
    background-color: #1a1b24;
    font-size: 0.75rem;
    font-family: var(--font-mono);
    color: var(--text-muted);
    border-bottom: 1px solid var(--border-subtle);
}

.copy-code-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 0.75rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 2px 6px;
    border-radius: 4px;
    transition: background var(--transition-fast), color var(--transition-fast);
}

.copy-code-btn:hover {
    background-color: var(--bg-hover);
    color: var(--text-primary);
}

.code-block-wrapper pre {
    padding: 14px;
    overflow-x: auto;
    font-family: var(--font-mono);
    font-size: 0.85rem;
    line-height: 1.5;
}

.markdown-body code:not(pre code) {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: var(--font-mono);
    font-size: 0.85rem;
}

/* Typing cursor for stream */
.typing-cursor {
    display: inline-block;
    width: 6px;
    height: 16px;
    background-color: var(--accent);
    margin-left: 4px;
    vertical-align: middle;
    animation: blink 0.8s infinite;
}

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

/* ==================== INPUT BOX ==================== */
.input-container-wrapper {
    width: 100%;
    max-width: 860px;
    margin: 0 auto;
    padding: 0 20px 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    position: relative;
    flex-shrink: 0;
}

.attachment-preview {
    display: flex;
    gap: 8px;
}

.attachment-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background-color: var(--bg-surface);
    border: 1px solid var(--border-strong);
    padding: 4px 10px;
    border-radius: var(--radius-full);
    font-size: 0.82rem;
}

.chip-remove {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.1rem;
    cursor: pointer;
    line-height: 1;
}

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

.input-box {
    display: flex;
    align-items: flex-end;
    background-color: var(--bg-input);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-lg);
    padding: 8px 12px;
    gap: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
    transition: border-color var(--transition-fast);
}

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

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

.input-action-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    padding: 6px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color var(--transition-fast), background var(--transition-fast);
}

.input-action-btn:hover {
    color: var(--text-primary);
    background-color: var(--bg-hover);
}

.input-action-btn.recording {
    color: var(--danger);
    animation: pulse 1s infinite alternate;
}

@keyframes pulse {
    from { transform: scale(1); }
    to { transform: scale(1.15); }
}

.send-btn, .stop-btn {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    cursor: pointer;
    flex-shrink: 0;
    transition: transform var(--transition-fast), opacity var(--transition-fast);
}

.send-btn {
    background: var(--accent-gradient);
    color: #ffffff;
}

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

.send-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none;
}

.stop-btn {
    background-color: var(--danger);
    color: #ffffff;
}

.input-footer-note {
    font-size: 0.72rem;
    color: var(--text-muted);
    text-align: center;
}

/* ==================== BUTTONS & MODALS ==================== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    font-weight: 500;
    font-size: 0.88rem;
    cursor: pointer;
    transition: background var(--transition-fast), color var(--transition-fast), border-color var(--transition-fast);
    border: none;
}

.btn-primary {
    background: var(--accent-gradient);
    color: #ffffff;
}

.btn-outline {
    background: transparent;
    border: 1px solid var(--border-strong);
    color: var(--text-secondary);
}

.btn-outline:hover {
    background-color: var(--bg-hover);
    color: var(--text-primary);
}

.icon-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    padding: 6px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

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

.full-width {
    width: 100%;
}

/* Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(6px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    padding: 16px;
    animation: fadeIn 0.15s ease;
}

.modal-box {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 420px;
    padding: 28px;
    position: relative;
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.5);
}

.modal-close {
    position: absolute;
    top: 14px;
    right: 14px;
    background: none;
    border: none;
    font-size: 1.4rem;
    color: var(--text-muted);
    cursor: pointer;
}

.modal-brand {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-bottom: 18px;
}

.brand-icon.small {
    width: 26px;
    height: 26px;
}

.modal-brand h2 {
    font-size: 1.25rem;
    font-weight: 700;
}

.limit-notice {
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.3);
    border-radius: var(--radius-md);
    padding: 12px 14px;
    display: flex;
    gap: 12px;
    align-items: flex-start;
    margin-bottom: 18px;
}

.limit-icon {
    font-size: 1.2rem;
}

.limit-text {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.limit-text strong {
    color: var(--danger);
    font-size: 0.88rem;
}

.limit-text span {
    font-size: 0.78rem;
    color: var(--text-secondary);
    line-height: 1.4;
}

.auth-tabs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    background-color: var(--bg-main);
    border-radius: var(--radius-sm);
    padding: 4px;
    margin-bottom: 20px;
    gap: 4px;
}

.tab-btn {
    background: none;
    border: none;
    padding: 8px;
    border-radius: 6px;
    font-size: 0.88rem;
    font-weight: 500;
    color: var(--text-muted);
    cursor: pointer;
    transition: background var(--transition-fast), color var(--transition-fast);
}

.tab-btn.active {
    background-color: var(--bg-surface);
    color: var(--text-primary);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}

.auth-form {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.form-group label {
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.form-group input {
    background-color: var(--bg-main);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    color: var(--text-primary);
    font-size: 0.92rem;
    outline: none;
    transition: border-color var(--transition-fast);
}

.form-group input:focus {
    border-color: var(--accent);
}

.auth-error {
    font-size: 0.8rem;
    color: var(--danger);
    background-color: rgba(239, 68, 68, 0.1);
    padding: 8px 12px;
    border-radius: var(--radius-sm);
}

.spinner {
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: #ffffff;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

.hidden {
    display: none !important;
}

.mobile-only {
    display: none;
}

/* ==================== RESPONSIVE ==================== */
@media (max-width: 768px) {
    .mobile-only {
        display: flex;
    }

    .sidebar {
        position: absolute;
        top: 0;
        bottom: 0;
        left: 0;
        transform: translateX(-100%);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .sidebar-overlay.active {
        display: block;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.6);
        z-index: 45;
    }

    .prompt-cards-grid {
        grid-template-columns: 1fr;
    }

    .hero-title {
        font-size: 1.4rem;
    }

    .message-row.user .message-bubble {
        max-width: 90%;
    }
}
