:root {
    /* --- COLORS --- */
    --bg-body: #09090b;
    --bg-sidebar: rgba(18, 18, 20, 0.85); /* Glassy sidebar */
    --bg-surface: #1e1e22;
    --bg-surface-hover: #27272a;
    --bg-input: rgba(39, 39, 42, 0.6);
    
    --primary: #FF6900;
    --primary-dim: rgba(255, 105, 0, 0.1);
    --primary-glow: 0 0 20px rgba(255, 105, 0, 0.2);
    
    --text-main: #f4f4f5;
    --text-muted: #a1a1aa;
    --text-dim: #52525b;
    
    --border: rgba(255, 255, 255, 0.08);
    --border-hover: rgba(255, 255, 255, 0.15);
    
    /* --- SIZES --- */
    --sidebar-w: 280px;
    --header-h: 60px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;
}

/* --- RESET & BASE --- */
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

body {
    margin: 0; 
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background: var(--bg-body); 
    color: var(--text-main);
    height: 100dvh; 
    display: flex; 
    overflow: hidden; 
    font-size: 15px;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

/* Custom Scrollbar */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #3f3f46; border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: #52525b; }

/* --- SIDEBAR --- */
#sidebar {
    width: var(--sidebar-w); 
    background: var(--bg-sidebar);
    backdrop-filter: blur(20px); /* Blur effect */
    display: flex; flex-direction: column; 
    border-right: 1px solid var(--border);
    flex-shrink: 0; z-index: 100;
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.sidebar-header {
    height: var(--header-h); padding: 0 20px;
    display: flex; align-items: center; justify-content: space-between;
}

.logo-text { font-weight: 700; font-size: 18px; letter-spacing: -0.03em; }

.close-sidebar-mobile { display: none; background:none; border:none; color:white; font-size:18px; cursor:pointer;}

#new-chat-btn {
    margin: 10px 15px 20px; padding: 12px;
    background: var(--text-main); color: #000;
    border: none; border-radius: var(--radius-md);
    cursor: pointer; font-weight: 600; font-size: 14px;
    display: flex; align-items: center; justify-content: center; gap: 8px;
    transition: transform 0.2s, box-shadow 0.2s;
}
#new-chat-btn:hover { transform: translateY(-1px); box-shadow: 0 4px 12px rgba(255,255,255,0.15); }
#new-chat-btn:active { transform: translateY(0); }

.chat-list { flex: 1; overflow-y: auto; padding: 0 10px; }

.chat-item {
    padding: 10px 14px; margin-bottom: 2px;
    border-radius: 8px; color: var(--text-muted);
    cursor: pointer; display: flex; justify-content: space-between; align-items: center;
    font-size: 14px; transition: all 0.2s ease;
    border: 1px solid transparent;
}
.chat-item:hover { background: var(--bg-surface); color: var(--text-main); }
.chat-item.active { 
    background: var(--bg-surface-hover); 
    color: var(--text-main); 
    border-color: var(--border);
    font-weight: 500;
}

.chat-title {
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 190px;
}

.del-chat { 
    background: none; border: none; 
    color: var(--text-dim); padding: 6px; cursor: pointer; 
    opacity: 0; transition: 0.2s; border-radius: 4px;
}
.del-chat:hover { background: rgba(239, 68, 68, 0.1); color: #ef4444; }
.chat-item:hover .del-chat { opacity: 1; }

.sidebar-footer { padding: 15px; border-top: 1px solid var(--border); }
.btn-sidebar-secondary {
    width: 100%; padding: 10px; background: transparent; 
    border: none; color: var(--text-muted); cursor: pointer;
    display: flex; align-items: center; gap: 10px; font-size: 14px; font-weight: 500;
    border-radius: 8px; transition: 0.2s;
}
.btn-sidebar-secondary:hover { color: white; background: var(--bg-surface); }

/* --- MAIN LAYOUT --- */
#main {
    flex: 1; display: flex; flex-direction: column; position: relative;
    background: radial-gradient(circle at 50% -20%, #1c1c20, var(--bg-body) 60%);
}

header {
    height: var(--header-h); padding: 0 20px;
    display: none; 
    align-items: center; justify-content: space-between;
    border-bottom: 1px solid var(--border);
    background: rgba(9, 9, 11, 0.8); backdrop-filter: blur(10px);
    z-index: 50; position: sticky; top: 0;
}
.app-title-mobile { font-weight: 600; }
.burger { background: none; border: none; color: white; padding: 0; cursor: pointer; }

/* --- MESSAGES AREA --- */
#messages {
    flex: 1; overflow-y: auto;
    padding: 20px; 
    display: flex; flex-direction: column; gap: 32px;
    scroll-behavior: smooth;
}
@media (min-width: 769px) { #messages { padding: 40px 15% 40px; } }

.msg-row { 
    display: flex; flex-direction: column; width: 100%; 
    opacity: 0; animation: fade-in 0.3s forwards;
}
@keyframes fade-in { to { opacity: 1; transform: translateY(0); } from { opacity: 0; transform: translateY(10px); } }

.msg-bubble {
    max-width: 100%; width: fit-content;
    line-height: 1.7; font-size: 16px;
}

/* USER STYLE */
.msg-row.user { align-items: flex-end; }
.msg-row.user .msg-bubble {
    padding: 10px 18px;
    background: #27272a;
    color: white;
    border-radius: 20px 20px 4px 20px;
    max-width: 85%;
    white-space: pre-wrap;
    box-shadow: 0 2px 10px rgba(0,0,0,0.2);
}

/* AI STYLE */
.msg-row.assistant { align-items: flex-start; }
.msg-row.assistant .msg-bubble { width: 100%; color: var(--text-main); }

/* --- MARKDOWN STYLING (The "Pro" Look) --- */
.msg-bubble h1, .msg-bubble h2, .msg-bubble h3 { margin-top: 24px; margin-bottom: 12px; font-weight: 600; color: white; letter-spacing: -0.02em; }
.msg-bubble p { margin-bottom: 16px; color: #d4d4d8; }
.msg-bubble p:last-child { margin-bottom: 0; }
.msg-bubble strong { color: white; font-weight: 600; }
.msg-bubble a { color: var(--primary); text-decoration: none; border-bottom: 1px solid transparent; transition: 0.2s; }
.msg-bubble a:hover { border-color: var(--primary); }
.msg-bubble ul, .msg-bubble ol { margin: 16px 0; padding-left: 24px; color: #d4d4d8; }
.msg-bubble li { margin-bottom: 8px; }

/* Code Blocks */
.msg-bubble pre {
    background: #0f0f11; 
    border: 1px solid var(--border);
    border-radius: 12px; 
    margin: 20px 0; 
    position: relative;
    overflow-x: auto; 
    box-shadow: 0 4px 20px rgba(0,0,0,0.3);
}

.msg-bubble code { 
    font-family: 'JetBrains Mono', 'Fira Code', monospace; 
    font-size: 13.5px; 
}

/* Inline Code */
.msg-bubble p code, .msg-bubble li code { 
    background: rgba(255,255,255,0.1); 
    padding: 2px 6px; 
    border-radius: 6px; 
    color: #FF8C00; 
    font-size: 0.9em;
}

/* Block Code Content */
.msg-bubble pre code { 
    padding: 16px; 
    display: block; 
    color: #e4e4e7;
    line-height: 1.5;
    background: transparent;
}

/* Copy Button */
.copy-code-btn {
    position: absolute; top: 10px; right: 10px;
    background: rgba(255,255,255,0.05); 
    border: 1px solid rgba(255,255,255,0.05);
    color: var(--text-muted); border-radius: 6px; 
    font-size: 11px; padding: 4px 10px; 
    cursor: pointer; transition: 0.2s;
    font-weight: 500;
}
.copy-code-btn:hover { background: rgba(255,255,255,0.1); color: white; border-color: rgba(255,255,255,0.1); }

/* --- CHAIN OF THOUGHT --- */
.thought-block {
    background: rgba(255,255,255,0.02); 
    border: 1px solid var(--border);
    border-radius: 12px; margin-bottom: 24px; overflow: hidden;
}
.thought-summary {
    padding: 10px 16px; cursor: pointer; font-size: 13px;
    font-weight: 500; color: #71717a; display: flex; align-items: center; gap: 8px;
    user-select: none; transition: 0.2s;
}
.thought-summary:hover { color: var(--text-muted); background: rgba(255,255,255,0.01); }
.thought-summary::after { content: '▼'; font-size: 10px; margin-left: auto; transition: transform 0.2s; opacity: 0.6; }
details[open] .thought-summary::after { transform: rotate(180deg); }
.thought-summary::-webkit-details-marker { display: none; }

.thought-content {
    padding: 16px; font-size: 13px; line-height: 1.6; color: #a1a1aa;
    font-family: 'JetBrains Mono', monospace;
    border-top: 1px solid var(--border);
    background: rgba(0,0,0,0.1);
}

.msg-tools {
    display: flex; gap: 16px; margin-top: 8px; opacity: 0; transition: 0.2s;
    font-size: 12px; color: var(--text-dim);
}
.msg-row:hover .msg-tools { opacity: 1; }
.tool-btn { cursor: pointer; transition: 0.2s; }
.tool-btn:hover { color: var(--text-muted); text-decoration: underline; }

/* --- WELCOME SCREEN CARDS (From JS) --- */
.feature-card { transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1); }
.feature-card:hover { 
    transform: translateY(-5px); 
    border-color: rgba(255,255,255,0.2) !important;
    box-shadow: 0 10px 30px -10px rgba(0,0,0,0.5);
}
.feature-card h3 { font-weight: 600 !important; }

/* --- INPUT AREA --- */
.input-wrapper {
    padding: 20px 20px 30px;
    background: linear-gradient(to top, var(--bg-body) 40%, transparent);
    position: sticky; bottom: 0; z-index: 50;
    display: flex; justify-content: center;
}

.input-container-centered { width: 100%; max-width: 768px; display: flex; flex-direction: column; gap: 10px; }

.controls-bar { display: flex; padding-left: 5px; }
.think-toggle {
    display: flex; align-items: center; gap: 10px; cursor: pointer;
    font-size: 13px; font-weight: 500; color: var(--text-muted); 
    background: rgba(255,255,255,0.03); padding: 6px 14px; border-radius: 20px; 
    border: 1px solid var(--border); transition: 0.2s;
}
.think-toggle:hover { border-color: var(--border-hover); color: var(--text-main); }
.toggle-track {
    width: 32px; height: 18px; background: #3f3f46; border-radius: 20px; position: relative; transition: 0.3s;
}
.toggle-thumb {
    width: 14px; height: 14px; background: white; border-radius: 50%;
    position: absolute; top: 2px; left: 2px; transition: 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    box-shadow: 0 1px 2px rgba(0,0,0,0.3);
}
.think-toggle input:checked + .toggle-track { background: var(--primary); }
.think-toggle input:checked + .toggle-track .toggle-thumb { transform: translateX(14px); }
.think-toggle input { display: none; }

.input-box {
    background: var(--bg-input); 
    backdrop-filter: blur(12px);
    border: 1px solid var(--border);
    border-radius: 24px; padding: 12px 14px 12px 20px;
    display: flex; align-items: flex-end; gap: 12px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.2); 
    transition: all 0.3s ease;
}
.input-box:focus-within { 
    border-color: rgba(255,255,255,0.2); 
    background: rgba(39, 39, 42, 0.8);
    box-shadow: var(--primary-glow), 0 10px 30px rgba(0,0,0,0.3);
}

textarea {
    flex: 1; background: transparent; border: none; color: #fff;
    max-height: 200px; min-height: 24px; padding: 4px 0;
    resize: none; outline: none; font-size: 16px; line-height: 1.5;
}
textarea::placeholder { color: #52525b; }

.action-btn {
    width: 36px; height: 36px; border-radius: 12px; border: none;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; flex-shrink: 0; transition: all 0.2s;
}
.send-btn { background: var(--text-main); color: black; }
.send-btn:hover { background: white; transform: scale(1.05); box-shadow: 0 0 15px rgba(255,255,255,0.3); }
.stop-btn { background: #3f3f46; color: white; display: none; }
.stop-btn:hover { background: #52525b; }

.footer-note { 
    text-align: center; font-size: 12px; color: #52525b; margin-top: 4px; 
}

/* --- MOBILE --- */
@media (max-width: 768px) {
    header { display: flex; }
    
    #sidebar {
        position: fixed; inset: 0; right: auto;
        width: 80%; max-width: 300px;
        transform: translateX(-100%); 
        box-shadow: 20px 0 50px rgba(0,0,0,0.7);
        border-right: 1px solid rgba(255,255,255,0.1);
    }
    #sidebar.active { transform: translateX(0); }

    .overlay {
        position: fixed; inset: 0; background: rgba(0,0,0,0.6);
        backdrop-filter: blur(4px); z-index: 90;
        opacity: 0; pointer-events: none; transition: 0.3s;
    }
    .overlay.active { opacity: 1; pointer-events: auto; }

    #messages { padding: 80px 15px 20px; }
    .input-wrapper { padding: 10px 15px 15px; }
    .msg-tools { opacity: 1; }
    .del-chat { opacity: 1; }
}

/* --- MODAL --- */
.modal {
    position: fixed; inset: 0; background: rgba(0,0,0,0.6); backdrop-filter: blur(10px);
    z-index: 200; display: none; align-items: center; justify-content: center;
    opacity: 0; transition: opacity 0.2s; pointer-events: none;
}
.modal.open { display: flex; opacity: 1; pointer-events: auto; }

.modal-box {
    background: #18181b; width: 90%; max-width: 450px;
    border-radius: 20px; border: 1px solid var(--border); padding: 24px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.7);
    transform: scale(0.95); transition: transform 0.2s;
}
.modal.open .modal-box { transform: scale(1); }

.modal-header { display: flex; justify-content: space-between; margin-bottom: 24px; align-items: center; }
.modal-header h3 { margin: 0; font-size: 18px; }
.icon-btn { background: none; border: none; color: var(--text-muted); cursor: pointer; font-size: 20px; }
.icon-btn:hover { color: white; }

.setting-field { margin-bottom: 20px; }
.setting-field label { display: block; color: var(--text-muted); margin-bottom: 8px; font-size: 13px; font-weight: 500; }
.setting-field input, .setting-field textarea {
    width: 100%; background: #09090b; border: 1px solid #27272a;
    padding: 12px; border-radius: 10px; color: white; outline: none; transition: 0.2s;
    font-family: inherit;
}
.setting-field input:focus, .setting-field textarea:focus { border-color: var(--primary); }

.btn-danger { width:100%; padding:12px; background: rgba(239, 68, 68, 0.1); color: #ef4444; border: 1px solid transparent; border-radius: 10px; cursor: pointer; transition: 0.2s; font-weight: 500; }
.btn-danger:hover { background: rgba(239, 68, 68, 0.2); border-color: rgba(239, 68, 68, 0.3); }

.btn-primary-full { width:100%; padding:12px; background: white; color: black; border: none; border-radius: 10px; font-weight: 600; cursor: pointer; margin-top: 10px; transition: 0.2s; }
.btn-primary-full:hover { background: #e4e4e7; transform: translateY(-1px); }

/* Range Slider */
input[type=range] {
    -webkit-appearance: none; width: 100%; background: transparent;
}
input[type=range]::-webkit-slider-thumb {
    -webkit-appearance: none; height: 16px; width: 16px; border-radius: 50%;
    background: white; cursor: pointer; margin-top: -6px; box-shadow: 0 1px 3px rgba(0,0,0,0.5);
}
input[type=range]::-webkit-slider-runnable-track {
    width: 100%; height: 4px; cursor: pointer; background: #27272a; border-radius: 2px;
}