: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; }
/* */

/* 1. تعریف انیمیشن تپش نئونی */
@keyframes neon-pulse {
    0% {
        opacity: 1;
        box-shadow: 0 0 10px var(--neon-blue);
        transform: scale(1);
    }
    50% {
        opacity: 0.5; /* نور کم می‌شود */
        box-shadow: 0 0 2px var(--neon-blue); /* هاله نور جمع می‌شود */
        transform: scale(0.9); /* نقطه کمی کوچک می‌شود */
    }
    100% {
        opacity: 1;
        box-shadow: 0 0 10px var(--neon-blue);
        transform: scale(1);
    }
}

/* 2. کلاس آپدیت شده نقطه */
.neon-dot {
    width: 8px;
    height: 8px;
    background: var(--neon-blue);
    border-radius: 50%;
    
    /* سایه اولیه */
    box-shadow: 0 0 10px var(--neon-blue);
    
    /* اتصال انیمیشن: 2 ثانیه، بی‌نهایت، نرم */
    animation: neon-pulse 2s infinite ease-in-out;
}
.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: 3000; 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);
    display: flex;
    flex-direction: column;
    /* نکته مهم: ارتفاع نباید از صفحه بزند بیرون */
    max-height: 85vh; 
    transform: translateY(0);
    transition: transform 0.3s;
}
.modal-overlay.hidden .settings-modal { transform: translateY(20px); }

.modal-header {
    padding: 12px 20px; /* کاهش پدینگ برای باز شدن فضا */
    border-bottom: 1px solid var(--border-glass);
    flex-shrink: 0; 
    
    /* جادوی Flexbox برای قرارگیری در یک خط */
    display: flex;
    justify-content: space-between;
    align-items: center;
}
/* حذف فاصله‌های پیش‌فرض تیتر داخل هدر */
.modal-header h2, 
.modal-header h3 {
    margin: 0;
    font-size: 1.2rem;
    color: var(--text-main);
}
.modal-body {
    padding: 20px;
    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: 12px;
    background: linear-gradient(45deg, var(--accent-primary), var(--accent-secondary));
    color: white;
    font-size: 1rem;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: bold;
}
.btn-save-glow:hover { filter: brightness(1.2); }
.close-btn { 
    background: transparent; 
    border: none; 
    color: var(--text-muted); /* رنگ ملایم‌تر در حالت عادی */
    font-size: 1.6rem; /* سایز ظریف‌تر و استانداردتر */
    cursor: pointer; 
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.2s ease, transform 0.2s ease;
}

/* افکت هاور جذاب برای دکمه ضربدر */
.close-btn:hover {
    color: #ef4444; /* قرمز شدن هنگام رفتن ماوس */
    transform: scale(1.1);
}

/* Chat Area & Utils */
.messages-container { flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 15px; }
/* --- اصلاح ساختار پیام‌ها (Message Bubbles) --- */
/* */
/* این کد را جایگزین کلاس .message فعلی کنید */
/* */
/* جایگزین کلاس .message فعلی */
.message {
    max-width: 85%;
    width: fit-content;
    padding: 12px 18px;
    border-radius: 12px;
    line-height: 1.7;
    position: relative;
    box-sizing: border-box;
    
    /* تغییرات جدید برای کنترل عرض */
    display: grid; /* استفاده از گرید برای کنترل بهتر فرزندان */
    grid-template-columns: minmax(0, 1fr); /* جادوی CSS: محتوا را مجبور می‌کند در عرض موجود جا شود */
    overflow-wrap: 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;
}


.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; 
    }
}

.modal-footer {
    padding: 15px 20px;
    border-top: 1px solid var(--border-glass);
    background: rgba(0,0,0,0.3); /* کمی تیره‌تر */
    flex-shrink: 0; /* جلوگیری از جمع شدن */
}
/* */

/* */
/* */
/* جایگزین کدهای انتهای فایل */

.code-block-wrapper {
    background: #1e1e1e;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    margin: 15px 0;
    
    /* تنظیمات حیاتی عرض */
    width: 100%; 
    min-width: 0; /* جلوگیری از بزرگ شدن فلکس‌باکس */
    
    display: flex;
    flex-direction: column;
    direction: ltr;
    overflow: hidden; /* هرچیزی بیرون زد مخفی شود */
}

.code-block-wrapper pre {
    margin: 0 !important;
    padding: 15px !important;
    background: transparent !important;
    border: none !important;
    
    /* شکستن بی‌رحمانه متن */
    white-space: pre-wrap !important;       /* اولویت ۱: خط بشکن */
    word-break: break-all !important;       /* اولویت ۲: کلمه را نصف کن */
    overflow-wrap: anywhere !important;     /* اولویت ۳: پشتیبانی مدرن */
    
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
}

/* هدر بالای کد (محل دکمه کپی) */
.code-block-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #2d2d2d;
    padding: 8px 15px;
    font-size: 0.8rem;
    color: #a3a3a3;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

/* دکمه کپی */
.copy-btn {
    background: transparent;
    border: none;
    color: #a3a3a3;
    cursor: pointer;
    font-size: 0.8rem;
    display: flex;
    align-items: center;
    gap: 5px;
    transition: 0.2s;
}

.copy-btn:hover {
    color: #fff;
}


/* --- نوار ابزار پایین هر پیام (Action Bar) --- */
.message-action-bar {
    display: flex;
    justify-content: flex-end; /* در حالت RTL دکمه را به سمت چپ هل می‌دهد */
    margin-top: 12px;
    padding-top: 8px;
    border-top: 1px dashed rgba(255, 255, 255, 0.1);
}

/* استایل دکمه کپی پیام */
.msg-action-btn {
    background: transparent;
    border: none;
    color: #a3a3a3;
    cursor: pointer;
    font-size: 0.75rem;
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 4px 8px;
    border-radius: 6px;
    transition: all 0.2s ease;
    opacity: 0.5; /* در حالت عادی کمی محو است */
}

/* وقتی ماوس می‌رود روی کل پیام، دکمه پررنگ‌تر می‌شود */
.message:hover .msg-action-btn {
    opacity: 0.8;
}

/* وقتی ماوس می‌رود روی خود دکمه */
.msg-action-btn:hover {
    opacity: 1;
    color: #fff;
    background: rgba(255, 255, 255, 0.08);
}