@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;600&family=Space+Grotesk:wght@300;500;700&display=swap');

:root {
    /* Color Palette (Dark Default) */
    --bg-deep: #0a0a0c;
    --bg-card: rgba(20, 20, 25, 0.7);
    --accent-primary: #8b5cf6;
    --accent-secondary: #ec4899;
    --accent-glow: rgba(139, 92, 246, 0.4);
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --glass-border: rgba(255, 255, 255, 0.1);
    --input-bg: rgba(255, 255, 255, 0.05);

    /* Spacing & Radii */
    --radius-lg: 24px;
    --radius-md: 16px;
    --safe-area-bottom: env(safe-area-inset-bottom);
}

body.light-mode {
    --bg-deep: #e2e8f0;
    /* Slightly darker slate for better depth */
    --bg-card: rgba(255, 255, 255, 0.4);
    /* Much more transparent */
    --text-main: #1e293b;
    /* Darker slate for main text */
    --text-muted: #475569;
    /* Darker muted text */
    --glass-border: rgba(255, 255, 255, 0.8);
    /* Refined border */
    --input-bg: rgba(255, 255, 255, 0.6);
    --accent-glow: rgba(139, 92, 246, 0.1);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    background-color: var(--bg-deep);
    color: var(--text-main);
    font-family: 'Outfit', sans-serif;
    overflow: hidden;
    height: 100vh;
    width: 100vw;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* Hide scrollbars but keep scrolling functional */
* {
    scrollbar-width: none;
    /* Firefox */
    -ms-overflow-style: none;
    /* IE and Edge */
}

*::-webkit-scrollbar {
    display: none;
    /* Chrome, Safari, Opera */
}

/* Mobile Container */
#app {
    width: 100%;
    max-width: 480px;
    /* Max mobile width */
    height: 100%;
    background: radial-gradient(circle at top right, rgba(139, 92, 246, 0.15), transparent),
        radial-gradient(circle at bottom left, rgba(236, 72, 153, 0.1), transparent);
    position: relative;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Page Transitions */
.page {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    padding: 24px;
    padding-top: 80px;
    /* Space for top bar */
    opacity: 0;
    transform: translateX(20px);
    pointer-events: none;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.page.active {
    opacity: 1;
    transform: translateY(0);
    pointer-events: all;
    z-index: 10;
}

/* Glassmorphism Utility */
.glass {
    -webkit-backdrop-filter: blur(12px);
    backdrop-filter: blur(12px);
    background: var(--bg-card);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-md);
}

/* Typography */
h1 {
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 700;
    font-size: 2rem;
    background: linear-gradient(135deg, var(--text-main), var(--accent-primary));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 8px;
}

/* Sidebar Navigation */
#sidebar {
    position: absolute;
    top: 0;
    left: -260px;
    width: 260px;
    height: 100%;
    z-index: 1001;
    padding: 32px 24px;
    display: flex;
    flex-direction: column;
    transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    -webkit-backdrop-filter: blur(20px);
    backdrop-filter: blur(20px);
    border-right: 1px solid var(--glass-border);
}

#sidebar.open {
    left: 0;
}

.sidebar-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    -webkit-backdrop-filter: blur(4px);
    backdrop-filter: blur(4px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    z-index: 999;
}

.sidebar-overlay.active {
    opacity: 1;
    pointer-events: all;
}

.page {
    display: none;
    flex-direction: column;
    height: 100%;
    animation: fadeIn 0.4s ease-out;
    position: relative;
    /* Anchor for absolute elements */
}

.page.active {
    display: flex;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin-top: 40px;
}

.nav-item {
    color: var(--text-muted);
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 16px;
    text-decoration: none;
    font-size: 1.1rem;
    padding: 12px 16px;
    border-radius: var(--radius-md);
}

.nav-item.active {
    color: var(--text-main);
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--glass-border);
}

.nav-item svg {
    width: 20px;
    height: 20px;
}

/* Header / Top Bar */
.top-bar {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 70px;
    display: flex;
    align-items: center;
    padding: 0 24px;
    z-index: 50;
    justify-content: space-between;
    pointer-events: none;
    /* Let clicks pass through empty areas */
}

.top-bar>* {
    pointer-events: all;
    /* Ensure children remain clickable */
}

.menu-toggle {
    background: transparent;
    border: none;
    color: var(--text-main);
    cursor: pointer;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.2s;
}

.menu-toggle:active {
    background: rgba(255, 255, 255, 0.1);
}

.app-branding {
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 700;
    font-size: 1.25rem;
    background: linear-gradient(135deg, var(--text-main), var(--accent-primary));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

/* Chat Interface Specifics */
.chat-container {
    flex: 1;
    overflow-y: auto;
    padding-bottom: 20px;
}

.message {
    max-width: 85%;
    padding: 12px 16px;
    margin-bottom: 12px;
    border-radius: 18px;
    font-size: 0.95rem;
    line-height: 1.5;
    animation: slideIn 0.3s ease-out forwards;
    word-break: break-word;
    /* Fix overflow */
    overflow-wrap: break-word;
    position: relative;
}

.message.user {
    align-self: flex-end;
    background: linear-gradient(135deg, var(--accent-primary), #7c3aed);
    color: white;
    border-bottom-right-radius: 4px;
}

.message.ai {
    background: var(--bg-card);
    border: 1px solid var(--glass-border);
    color: var(--text-main);
    align-self: flex-start;
    border-bottom-left-radius: 4px;
}

/* Markdown Styles inside Messages */
.message.ai p {
    margin-bottom: 8px;
}

.message.ai p:last-child {
    margin-bottom: 0;
}

.message.ai ul,
.message.ai ol {
    margin-left: 20px;
    margin-bottom: 8px;
}

.message.ai table {
    width: 100%;
    border-collapse: collapse;
    margin: 12px 0;
    font-size: 0.85rem;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 8px;
    overflow: hidden;
}

.message.ai th,
.message.ai td {
    border: 1px solid var(--glass-border);
    padding: 8px 12px;
    text-align: left;
}

.message.ai th {
    background: rgba(139, 92, 246, 0.1);
    font-weight: 600;
}

.message.ai code {
    background: rgba(0, 0, 0, 0.3);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: monospace;
    font-size: 0.9em;
}

.message.ai pre {
    background: rgba(0, 0, 0, 0.4);
    padding: 12px;
    border-radius: 12px;
    overflow-x: auto;
    margin: 12px 0;
    border: 1px solid var(--glass-border);
}

.message.ai pre code {
    background: transparent;
    padding: 0;
}

.message.ai blockquote {
    border-left: 4px solid var(--accent-primary);
    padding-left: 16px;
    margin: 12px 0;
    color: var(--text-muted);
    font-style: italic;
}

/* User Input */
/* Beautiful Floating Input */
.input-area {
    padding: 12px 16px 24px;
    /* Space for bottom safe area */
    background: transparent;
    display: flex;
    justify-content: center;
    position: relative;
    z-index: 100;
}

.input-pill {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--bg-card);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    backdrop-filter: blur(20px) saturate(180%);
    border: 1px solid var(--glass-border);
    border-radius: 30px;
    padding: 6px 6px 6px 20px;
    width: 100%;
    max-width: 440px;
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.input-pill:focus-within {
    transform: translateY(-2px);
    border-color: var(--accent-primary);
}

.input-pill input {
    flex: 1;
    background: transparent !important;
    border: none;
    outline: none;
    color: var(--text-main);
    font-size: 0.95rem;
    padding: 12px 16px;
    font-family: inherit;
}

/* Ensure no autofill or focus background appears */
.input-pill input:-webkit-autofill,
.input-pill input:-webkit-autofill:hover,
.input-pill input:-webkit-autofill:focus {
    -webkit-text-fill-color: var(--text-main);
    -webkit-box-shadow: 0 0 0px 1000px transparent inset;
    transition: background-color 5000s ease-in-out 0s;
}

input::placeholder {
    color: var(--text-muted);
    opacity: 0.6;
}

input::placeholder {
    color: var(--text-muted);
    opacity: 0.7;
}

input:focus {
    border-color: var(--accent-primary);
    background: var(--bg-card);
}

button.send-btn {
    background: var(--accent-primary);
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    border: none;
    border-radius: 50%;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    flex-shrink: 0;
}

button.send-btn:hover {
    filter: brightness(1.1);
    transform: scale(1.05);
}

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

button.send-btn svg {
    width: 20px;
    height: 20px;
    stroke: white;
    transform: translateX(1px);
    /* Perfectly center visually */
}

.home-header {
    margin-bottom: 40px;
    text-align: left;
}

.new-chat-btn {
    position: fixed;
    bottom: 40px;
    right: 40px;
    background: var(--accent-primary);
    border: none;
    border-radius: 50%;
    width: 60px;
    height: 60px;
    display: flex;
    justify-content: center;
    align-items: center;
    color: white;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 8px 25px rgba(139, 92, 246, 0.4);
    z-index: 100;
}

.new-chat-btn:hover {
    transform: scale(1.1) rotate(90deg);
    background: var(--accent-secondary);
    box-shadow: 0 12px 35px rgba(139, 92, 246, 0.6);
}

.new-chat-btn svg {
    width: 28px;
    height: 28px;
}

/* Animations */

/* Page Specific Helper Classes */
.welcome-text {
    color: var(--text-muted);
}

.feature-grid {
    margin-top: 32px;
    display: grid;
    gap: 16px;
}

.feature-card {
    padding: 24px;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
    border: 1px solid var(--glass-border);
}

.feature-card:hover {
    transform: translateY(-5px);
    border-color: var(--accent-primary);
    background: linear-gradient(135deg, var(--bg-card), rgba(139, 92, 246, 0.1));
}

.feature-card h3 {
    margin-bottom: 8px;
    font-size: 1.1rem;
    color: var(--text-main);
}

.feature-card p {
    font-size: 0.85rem;
    color: var(--text-muted);
    line-height: 1.4;
}

/* System Prompt Styling */
.system-prompt-container {
    padding: 16px;
    margin-bottom: 20px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    max-height: 500px;
    opacity: 1;
}

.system-prompt-container.hidden {
    display: none;
    max-height: 0;
    opacity: 0;
    margin: 0;
    padding: 0;
}

.apply-btn {
    background: var(--accent-primary);
    border: none;
    padding: 8px 16px;
    border-radius: 8px;
    color: white;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s;
}

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

.icon-btn {
    position: absolute;
    top: 24px;
    right: 24px;
    background: transparent;
    border: none;
    width: 32px;
    height: 32px;
    display: flex;
    justify-content: center;
    align-items: center;
    color: #2D3748;
    /* Dark elegant gray */
    cursor: pointer;
    transition: all 0.2s;
    z-index: 9999;
    /* Maximize top layer */
    pointer-events: all;
}

.icon-btn:hover {
    transform: scale(1.1);
    color: #000000;
}

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

.system-prompt-input {
    width: 100%;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    padding: 12px 16px;
    color: var(--text-main);
    font-size: 0.85rem;
    resize: none;
    outline: none;
    transition: border-color 0.2s;
}

.system-prompt-input:focus {
    border-color: var(--accent-primary);
}

.system-prompt-label {
    display: block;
    font-size: 0.75rem;
    color: var(--accent-primary);
    margin-bottom: 8px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}



.model-select {
    padding: 8px 16px;
    font-size: 0.85rem;
    border-radius: 12px;
    max-width: 160px;
    background: var(--bg-card);
    color: var(--text-main);
    border: 1px solid var(--glass-border);
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 8px center;
    background-size: 16px;
    padding-right: 32px;
}

.model-select option {
    background-color: #1a1a20;
    color: #f8fafc;
    padding: 10px;
}

body.light-mode .model-select option {
    background-color: #ffffff;
    color: #1e293b;
}

.chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--glass-border);
}

.input-pill:has(input:disabled) {
    opacity: 0.6;
    transform: none !important;
    background: rgba(255, 255, 255, 0.02);
}

button.send-btn:disabled {
    filter: grayscale(1) opacity(0.5);
    cursor: not-allowed;
    transform: none !important;
}

.clear-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 0.8rem;
    cursor: pointer;
    white-space: nowrap;
}

.message-image {
    max-width: 100%;
    border-radius: 12px;
    margin-top: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.profile-header {
    text-align: center;
    margin: 20px 0 40px;
}

.profile-avatar-container {
    position: relative;
    width: 120px;
    height: 120px;
    margin: 0 auto 24px;
}

.profile-avatar {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    border: 4px solid var(--bg-card);
    /* box-shadow removed */
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.5rem;
    font-weight: 700;
    color: white;
    position: relative;
    z-index: 2;
}

.avatar-ring {
    position: absolute;
    inset: -8px;
    border: 2px solid var(--accent-primary);
    border-radius: 50%;
    opacity: 0.3;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% {
        transform: scale(1);
        opacity: 0.3;
    }

    50% {
        transform: scale(1.15);
        opacity: 0;
    }

    100% {
        transform: scale(1);
        opacity: 0.3;
    }
}

.profile-name {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 4px;
}

.profile-tag {
    font-size: 0.85rem;
    color: var(--accent-primary);
    opacity: 0.8;
    letter-spacing: 1px;
    text-transform: uppercase;
}

.stat-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    padding: 16px;
    text-align: center;
}

.stat-value {
    font-family: 'Space Grotesk', sans-serif;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-main);
}

.stat-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    margin-top: 4px;
}

.profile-edit-field {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--glass-border);
    padding: 16px;
    border-radius: var(--radius-md);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.profile-name-input {
    background: transparent;
    border: none;
    text-align: right;
    color: var(--text-main);
    font-size: 1rem;
    font-weight: 500;
    width: 150px;
    outline: none;
}

.settings-section {
    padding: 20px;
    margin-top: 24px;
}

.settings-section h3 {
    margin-bottom: 12px;
    font-size: 1rem;
    color: var(--accent-primary);
}

.settings-label {
    font-size: 0.85rem;
    color: var(--text-muted);
    display: block;
    margin-bottom: 8px;
}

.settings-hint {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-top: 4px;
}

.theme-picker {
    display: flex;
    gap: 12px;
    margin-top: 4px;
}

.theme-dot {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
}

.settings-option {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.settings-option:last-child {
    border-bottom: none;
}

.select-custom {
    background: var(--input-bg);
    border: 1px solid var(--glass-border);
    padding: 8px 16px;
    border-radius: 12px;
    color: var(--text-main);
    font-size: 0.85rem;
    outline: none;
    cursor: pointer;
}

.danger-btn {
    width: 100%;
    padding: 14px;
    background: rgba(239, 68, 68, 0.1);
    color: #ef4444;
    border: 1px solid rgba(239, 68, 68, 0.2);
    border-radius: var(--radius-md);
    font-weight: 600;
    cursor: pointer;
    margin: 16px 0 8px;
    transition: all 0.2s;
}

.danger-btn:hover {
    background: #ef4444;
    color: white;
}

.theme-1 {
    background: var(--accent-primary);
    border: 2px solid white;
}

.theme-2 {
    background: #00ffcc;
    opacity: 0.5;
}

.theme-3 {
    background: #ffcc00;
    opacity: 0.5;
}

/* Utility Classes */
.u-mb-32 {
    margin-bottom: 32px;
}

.u-mt-auto {
    margin-top: auto;
}

.u-opacity-50 {
    opacity: 0.5;
}

.u-text-center {
    text-align: center;
}

.u-text-sm {
    font-size: 0.85rem;
}

.u-w-full {
    width: 100%;
}

.u-w-44 {
    width: 44px;
}

.u-accent-color {
    color: var(--accent-primary);
}
