:root {
    --bg-dark: #050505;
    --bg-panel: #111111;
    --bg-message-user: #1a1a1a;
    --bg-message-bot: #0a0a0a;
    --accent-primary: #3b82f6;
    --accent-secondary: #8b5cf6;
    --text-main: #e5e5e5;
    --text-muted: #a3a3a3;
    --border-color: #333;
    
    /* متغیرهای جدید نسخه لوکس */
    --glass-bg: rgba(16, 16, 16, 0.95);
    --neon-blue: #00f2ff;
    --neon-purple: #bc13fe;
    --border-glass: rgba(255, 255, 255, 0.1);
}

body {
    background-color: var(--bg-dark);
    color: var(--text-main);
    font-family: 'Vazirmatn', 'Segoe UI', sans-serif;
    margin: 0;
    height: 100vh;
    overflow: hidden;
    direction: rtl;
}

.app-container { display: flex; height: 100vh; }
.sidebar { width: 260px; background-color: var(--bg-panel); border-left: 1px solid var(--border-color); display: flex; flex-direction: column; padding: 10px; }
.history-list { flex: 1; overflow-y: auto; margin-top: 10px; }
.history-item { padding: 10px; cursor: pointer; border-radius: 5px; margin-bottom: 5px; color: var(--text-muted); transition: 0.2s; display: flex; justify-content: space-between; align-items: center; }
.history-item:hover, .history-item.active { background-color: rgba(59, 130, 246, 0.1); color: var(--accent-primary); }
.history-text { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-left: 8px; }
.delete-chat-btn { background: transparent; color: #ef4444; border: none; cursor: pointer; opacity: 0.6; }
.delete-chat-btn:hover { opacity: 1; transform: scale(1.1); }
.sidebar-footer { border-top: 1px solid var(--border-color); padding-top: 10px; display: flex; gap: 5px; }

/* --- HEADER لوکس جدید --- */
.chat-interface { flex: 1; display: flex; flex-direction: column; position: relative; }
.chat-header { background: var(--bg-panel); border-bottom: 1px solid var(--border-color); padding: 15px 30px; }
.header-main { display: flex; justify-content: space-between; align-items: center; }
.brand { display: flex; align-items: center; gap: 12px; }
.brand h1 { font-size: 1.4rem; letter-spacing: 1px; margin: 0; }
.version-tag { font-size: 0.7rem; color: var(--accent-secondary); border: 1px solid; padding: 2px 6px; border-radius: 4px; vertical-align: middle; }
.neon-dot { width: 8px; height: 8px; background: var(--neon-blue); border-radius: 50%; box-shadow: 0 0 10px var(--neon-blue); }
.settings-trigger { background: rgba(255,255,255,0.05); color: var(--text-main); padding: 8px 16px; border: 1px solid var(--border-glass); border-radius: 8px; transition: 0.3s; cursor: pointer; }
.settings-trigger:hover { background: rgba(255,255,255,0.1); border-color: var(--neon-blue); box-shadow: 0 0 8px rgba(0, 242, 255, 0.2); }

/* --- MODAL (تنظیمات جدید) --- */
.modal-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0, 0, 0, 0.6); backdrop-filter: blur(5px); display: flex; justify-content: center; align-items: center; z-index: 1000; transition: 0.3s; opacity: 1; visibility: visible; }
.modal-overlay.hidden { opacity: 0; visibility: hidden; pointer-events: none; }
.settings-modal { background: var(--glass-bg); width: 90%; max-width: 700px; border: 1px solid var(--border-glass); border-radius: 16px; box-shadow: 0 25px 50px rgba(0,0,0,0.5); overflow: hidden; transform: translateY(0); transition: transform 0.3s cubic-bezier(0.18, 0.89, 0.32, 1.28); display: flex; flex-direction: column; max-height: 85vh; }
.modal-overlay.hidden .settings-modal { transform: translateY(20px); }

.modal-header { padding: 20px 30px; border-bottom: 1px solid var(--border-glass); display: flex; justify-content: space-between; align-items: center; }
.modal-body { padding: 30px; overflow-y: auto; flex: 1; }
.system-status-card { background: rgba(255,255,255,0.03); border-radius: 12px; padding: 15px 20px; display: flex; gap: 40px; margin-bottom: 30px; border-right: 4px solid var(--neon-blue); }
.status-item .label { color: var(--text-muted); font-size: 0.85rem; margin-left: 10px; }
.status-item .value.online { color: #10b981; font-weight: bold; }
.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 30px; }
.settings-section h3 { font-size: 1rem; color: var(--accent-primary); margin-bottom: 15px; border-bottom: 1px solid rgba(59,130,246,0.2); padding-bottom: 8px; }
.input-group label { display: block; margin-bottom: 8px; font-size: 0.9rem; color: var(--text-muted); }
.settings-section select, .settings-section textarea { width: 100%; background: rgba(0,0,0,0.4); border: 1px solid var(--border-glass); color: white; padding: 12px; border-radius: 8px; transition: 0.3s; box-sizing: border-box; }
.settings-section select:focus, textarea:focus { border-color: var(--accent-primary); outline: none; }
.full-width { grid-column: span 2; margin-top: 20px; }
textarea#apiKeysInput { height: 100px; font-family: monospace; font-size: 0.85rem; }
.btn-save-glow { width: 100%; padding: 15px; background: linear-gradient(45deg, var(--accent-primary), var(--accent-secondary)); color: white; font-size: 1rem; border: none; cursor: pointer; transition: 0.3s; font-weight: bold; letter-spacing: 1px; }
.btn-save-glow:hover { filter: brightness(1.2); }
.close-btn { background: none; border: none; color: white; font-size: 2rem; cursor: pointer; }

/* Chat Area & Utils */
.messages-container { flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 15px; }
/* --- اصلاح ساختار پیام‌ها (Message Bubbles) --- */
.message {
    max-width: 85%; /* پیام فقط ۸۵ درصد عرض صفحه را می‌گیرد */
    width: fit-content; /* اگر متن کم بود، کادر کوچک می‌شود */
    padding: 12px 18px;
    border-radius: 12px;
    line-height: 1.7;
    position: relative;
    
    /* جادوی شکستن متن (Text Wrapping Magic) */
    white-space: pre-wrap; /* فاصله‌ها و اینترها حفظ شوند اما متن بشکند */
    word-wrap: break-word; /* کلمات طولانی شکسته شوند */
    overflow-wrap: break-word; /* استاندارد مدرن */
    word-break: break-word; /* شکستن اجباری کلمات خیلی طولانی */
}

/* استایل پیام کاربر */
.message.user {
    margin-right: 0;
    margin-left: auto; /* چسبیدن به راست */
    background-color: var(--bg-message-user);
    border: 1px solid #333;
    border-right: 3px solid var(--accent-primary);
    border-bottom-right-radius: 2px; /* گوشه تیز برای زیبایی */
}

/* استایل پیام ربات */
.message.bot {
    margin-left: 0;
    margin-right: auto; /* چسبیدن به چپ */
    background-color: var(--bg-message-bot);
    border-left: 3px solid var(--accent-secondary);
    border-bottom-left-radius: 2px;
}
.message pre {
    background: #1e1e1e !important;
    padding: 15px;
    border-radius: 8px;
    direction: ltr; /* کد همیشه چپ‌چین */
    text-align: left;
    margin: 10px 0;
    
    /* اسکرول بار برای کدهای طولانی */
    overflow-x: auto; 
    white-space: pre; /* فرمت کد حفظ شود و نشکند */
    max-width: 100%; /* از کادر مادر بیرون نزند */
    border: 1px solid rgba(255,255,255,0.1);
}

/* استایل اسکرول‌بار داخل کد */
.message pre::-webkit-scrollbar {
    height: 8px;
}
.message pre::-webkit-scrollbar-thumb {
    background: #444;
    border-radius: 4px;
}

.input-area { padding: 20px; background-color: var(--bg-panel); display: flex; gap: 10px; }
textarea { flex: 1; background: #000; border: 1px solid var(--border-color); color: white; padding: 10px; border-radius: 5px; resize: none; }
button { cursor: pointer; border: none; padding: 8px 12px; border-radius: 5px; font-weight: bold; }
.btn-primary { background: var(--accent-primary); color: white; width: 100%; }
.btn-secondary { background: #333; color: white; flex: 1; font-size: 0.8rem; }
.send-btn { background: var(--accent-secondary); color: white; width: 50px; font-size: 1.2rem; }
pre { background: #1e1e1e !important; border-radius: 5px; direction: ltr; text-align: left; }
.hidden { display: none !important; }

/* استایل اختصاصی برای منوهای کشویی */
#personaSelect, 
#thinkingLevel {
    background-color: #0a0a0a !important; /* مشکی خالص */
    color: #e5e5e5 !important;
    border: 1px solid rgba(255, 255, 255, 0.1) !important;
    padding: 12px;
    border-radius: 8px;
    cursor: pointer;
    appearance: none; /* حذف ظاهر پیش‌فرض مرورگر */
    -webkit-appearance: none;
    -moz-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%2360a5fa' viewBox='0 0 16 16'%3E%3Cpath d='M7.247 11.14 2.451 5.658C1.885 5.013 2.345 4 3.204 4h9.592a1 1 0 0 1 .753 1.659l-4.796 5.48a1 1 0 0 1-1.506 0z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: left 12px center; /* قرار دادن آیکون فلش در سمت چپ برای RTL */
    padding-left: 35px;
}

/* استایل‌دهی به گزینه‌های داخل منو (dropdown list) */
#personaSelect option, 
#thinkingLevel option {
    background-color: #111111 !important; /* رنگ پس‌زمینه لیست */
    color: #ffffff !important;
    padding: 10px;
}

/* حالت فوکوس برای ایجاد درخشش ملایم نئونی */
#personaSelect:focus, 
#thinkingLevel:focus {
    border-color: #3b82f6 !important;
    box-shadow: 0 0 10px rgba(59, 130, 246, 0.3);
    outline: none;
}

/* برای مرورگرهای قدیمی‌تر و سازگاری بیشتر */
select::-ms-expand {
    display: none;
}

/* اصلاح چیدمان بعد از حذف اینترنت */
.settings-section.full-width {
    grid-column: span 2;
    background: rgba(255, 255, 255, 0.02);
    padding: 15px;
    border-radius: 12px;
}

/* --- استایل منوی شخصیت در هدر --- */
.persona-selector-wrapper {
    flex: 1; /* فضای خالی وسط را پر کند */
    display: flex;
    justify-content: center; /* وسط‌چین شود */
    margin: 0 15px;
}

.header-select {
    background: rgba(0, 242, 255, 0.05); /* پس‌زمینه خیلی محو آبی */
    color: var(--neon-blue);
    border: 1px solid rgba(0, 242, 255, 0.3);
    padding: 8px 15px;
    border-radius: 20px; /* گرد و قرصی شکل */
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.3s ease;
    text-align: center;
    
    /* حذف استایل‌های پیش‌فرض */
    appearance: none;
    -webkit-appearance: none;
    
    /* آیکون فلش کوچک */
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' fill='%2300f2ff' viewBox='0 0 16 16'%3E%3Cpath d='M7.247 11.14 2.451 5.658C1.885 5.013 2.345 4 3.204 4h9.592a1 1 0 0 1 .753 1.659l-4.796 5.48a1 1 0 0 1-1.506 0z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: left 10px center;
    padding-left: 30px; /* جا برای آیکون */
    min-width: 200px;
}

.header-select:hover {
    background: rgba(0, 242, 255, 0.15);
    box-shadow: 0 0 15px rgba(0, 242, 255, 0.2);
}

.header-select:focus {
    outline: none;
    border-color: var(--neon-blue);
}

/* رنگ گزینه‌های داخل منو (برای اینکه خوانا باشد) */
.header-select option {
    background-color: #050505;
    color: white;
    padding: 10px;
}
/* --- استایل فوتر مینیمال --- */
.app-footer {
    background: rgba(0, 0, 0, 0.4); /* پس‌زمینه نیمه‌شفاف */
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    border-top: 1px solid var(--border-glass);
    padding: 6px 0;
    text-align: center;
    position: fixed;
    bottom: 0;
    width: 100%;
    z-index: 99;
}

.app-footer p {
    margin: 0;
    font-size: 0.75rem;
    color: var(--text-muted);
    letter-spacing: 0.5px;
    opacity: 0.7;
}

/* جلوگیری از تداخل فوتر با باکس چت */
.input-area {
    padding-bottom: 35px; /* ایجاد فضا برای فوتر */
}

/* --- استایل دکمه منوی موبایل --- */
.mobile-menu-btn {
    display: none; /* در دسکتاپ مخفی است */
    background: transparent;
    border: 1px solid var(--border-glass);
    color: var(--text-main);
    font-size: 1.2rem;
    padding: 5px 10px;
    border-radius: 8px;
    cursor: pointer;
    margin-left: 10px;
}

/* --- پوشش تاریک پشت سایدبار --- */
.sidebar-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.7);
    backdrop-filter: blur(3px);
    z-index: 1400; /* بالاتر از همه چیز */
    opacity: 0;
    visibility: hidden;
    transition: 0.3s;
}
.sidebar-overlay.active {
    opacity: 1;
    visibility: visible;
}
/* --- استایل دکمه ضربدر (مخصوص دسکتاپ) --- */
.close-sidebar-btn {
    display: none; /* این خط حیاتی است: دکمه را در کامپیوتر مخفی می‌کند */
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 2rem;
    cursor: pointer;
    padding: 0 10px;
    transition: 0.3s;
}

.close-sidebar-btn:hover {
    color: #ef4444;
}
/* =========================================
   MOBILE & TABLET STYLES (Responsive Engine)
   ========================================= */
@media (max-width: 768px) {
    
    /* 1. ساختار کلی و کانتینر */
    .app-container {
        position: relative;
        overflow-x: hidden; /* جلوگیری از اسکرول افقی */
    }

    /* 2. سایدبار (منوی کشویی) */
    .sidebar {
        position: fixed;
        top: 0;
        right: -280px; /* مخفی در سمت راست */
        width: 260px;
        height: 100vh;
        z-index: 1500;
        transition: right 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        box-shadow: -5px 0 25px rgba(0,0,0,0.8);
    }
    
    .sidebar.active {
        right: 0; /* باز شدن */
    }

    /* دکمه ضربدر بستن سایدبار */
    .close-sidebar-btn {
        display: block; /* نمایش فقط در موبایل */
    }

    .sidebar-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding-bottom: 15px;
        border-bottom: 1px solid var(--border-color);
    }
    
    .sidebar-header h2 {
        font-size: 1rem;
        margin: 0;
    }

    /* 3. هدر و نوار بالا */
    .chat-header { padding: 10px 15px; }
    .brand h1 { font-size: 1rem; }
    .version-tag { display: none; } /* حذف برای فضای بیشتر */
    .mobile-menu-btn { display: block; } /* نمایش همبرگری */

    .persona-selector-wrapper { margin: 0 5px; }
    .header-select {
        min-width: auto;
        width: 100%;
        padding: 6px 25px 6px 10px;
        font-size: 0.8rem;
    }

    /* 4. تنظیمات و مودیال */
    .settings-grid { grid-template-columns: 1fr; } /* تک ستونه */
    .modal-body { padding: 15px; }

    /* 5. پیام‌ها */
    .message { max-width: 92%; }

    /* --- بخش حیاتی: فیکس کردن فوتر و اینپوت --- */

    /* الف) فوتر همیشه چسبیده به ته صفحه */
    .app-footer {
        height: 30px;
        line-height: 30px;
        padding: 0;
        font-size: 0.65rem;
        background: #050505; /* پس‌زمینه کاملاً مشکی */
        z-index: 2001; /* بالاترین اولویت */
        border-top: 1px solid #222;
    }

    /* ب) باکس ورودی چسبیده به بالای فوتر */
    .input-area {
        position: fixed; /* حتماً باید فیکس باشد */
        bottom: 30px; /* دقیقاً اندازه ارتفاع فوتر فاصله بگیرد */
        left: 0;
        right: 0;
        width: 100%;
        padding: 10px;
        background: rgba(16, 16, 16, 0.98); /* تیره و تقریباً مات */
        backdrop-filter: blur(10px);
        z-index: 2000;
        border-top: 1px solid var(--border-glass);
        box-sizing: border-box; /* جلوگیری از بیرون زدن عرض */
    }

    /* ج) فضای خالی ته چت برای اینکه متن زیر اینپوت نرود */
    .messages-container {
        padding-bottom: 110px !important; 
    }
}