/* ===============================
   تنظیمات پایه و متغیرها
================================ */

:root {
    --bg: #343541;
    --box: #444654;
    --header: #202123;
    --user: #10a37f;
    --ai: #3e3f4b;
    --input: #40414f;
    --text: #ffffff;
    --border-radius: 14px;
}

.light-mode {
    --bg: #f4f6f9;
    --box: #ffffff;
    --header: #eaeaea;
    --user: #10a37f;
    --ai: #f1f1f1;
    --input: #f7f7f7;
    --text: #000000;
}

/* ===============================
   بدنه اصلی
================================ */

body {
    margin: 0;
    font-family: 'Vazirmatn', sans-serif;
    background: var(--bg);
    color: var(--text);
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    direction: rtl;
    transition: 0.3s ease;
}

/* ===============================
   کانتینر اصلی چت
================================ */

.chat-container {
    width: 100%;
    max-width: 850px;
    height: 95vh;
    background: var(--box);
    display: flex;
    flex-direction: column;
    border-radius: var(--border-radius);
    overflow: hidden;
    box-shadow: 0 10px 40px rgba(0,0,0,0.3);
    transition: 0.3s ease;
}

/* ===============================
   هدر
================================ */

.chat-header {
    background: var(--header);
    padding: 15px 20px;
    text-align: center;
    font-weight: 600;
    font-size: 16px;
    position: relative;
}

.chat-underheader {
    background: var(--header);
    padding: 15px 20px;
    text-align: center;
    font-weight: 600;
    font-size: 16px;
    position: relative;
}

.mode-btn {
    position: absolute;
    left: 15px;
    top: 12px;
    background: transparent;
    border: none;
    font-size: 18px;
    cursor: pointer;
    color: var(--text);
}

/* ===============================
   باکس پیام‌ها
================================ */

.chat-box {
    flex: 1;
    padding: 15px 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
    scroll-behavior: smooth; /* اسکرول روان */
    -webkit-overflow-scrolling: touch; /* برای موبایل */
}

.chat-box::-webkit-scrollbar {
    width: 6px;
}

.chat-box::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 10px;
}

/* ===============================
   پیام‌ها
================================ */

.ai-message, 
.user-message {
    max-width: 70%;
    padding: 12px 16px;
    border-radius: var(--border-radius);
    line-height: 1.6;
    font-size: 14px;
    word-wrap: break-word;
    overflow-wrap: break-word;
    animation: slideFadeIn 0.3s ease forwards;
    transition: all 0.3s ease;
}

/* پیام AI */
.ai-message {
    background: var(--ai);
    align-self: flex-start;
    white-space: pre-wrap;
    word-break: break-word;
}

/* پیام کاربر */
.user-message {
    background: var(--user);
    color: #fff;
    align-self: flex-end;
}

/* ===============================
   انیمیشن‌ها
================================ */

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(5px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes slideFadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ===============================
   حالت تایپینگ
================================ */

.typing {
    display: inline-block;
    position: relative;
    min-width: 20px;
}

.typing span {
    display: inline-block;
    width: 6px;
    height: 6px;
    margin: 0 2px;
    border-radius: 50%;
    background: var(--text);
    animation: bounce 0.6s infinite alternate;
}

.typing span:nth-child(2) { animation-delay: 0.2s; }
.typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes bounce {
    0% { transform: translateY(0); opacity: 0.3; }
    50% { transform: translateY(-4px); opacity: 1; }
    100% { transform: translateY(0); opacity: 0.3; }
}

/* ===============================
   بخش ورودی
================================ */

.input-area {
    display: flex;
    padding: 12px 15px;
    background: var(--input);
    gap: 10px;
    align-items: center;
}

textarea {
    flex: 1;
    resize: none;
    border-radius: 10px;
    border: none;
    padding: 10px 12px;
    font-family: inherit;
    font-size: 14px;
    outline: none;
    background: var(--box);
    color: var(--text);
    height: 45px;
    max-height: 120px;
    overflow-y: auto;
    transition: 0.2s;
}

button {
    background: var(--user);
    border: none;
    color: white;
    padding: 10px 18px;
    border-radius: 10px;
    cursor: pointer;
    font-weight: 500;
    transition: 0.2s;
}

button:hover {
    opacity: 0.85;
}

/* ===============================
   واکنش‌گرایی
================================ */

/* موبایل و تبلت */
@media (max-width: 768px) {
    .chat-container {
        height: auto; /* ارتفاع پویا */
        max-height: 100vh; 
        border-radius: 0;
        display: flex;
        flex-direction: column;
    }

    .chat-box {
        flex: 1; /* پر کردن فضای باقی‌مانده */
        overflow-y: auto;
        padding: 10px 15px;
        gap: 8px;
        scroll-behavior: smooth;
        -webkit-overflow-scrolling: touch;
    }

    .input-area {
        flex-shrink: 0; /* پایین ثابت بماند */
        padding: 8px 10px;
        gap: 6px;
    }

    textarea {
        font-size: 13px;
        padding: 8px 10px;
        height: 40px;
    }

    button {
        padding: 8px 14px;
    }
}

/* موبایل خیلی کوچک */
@media (max-width: 480px) {
    .chat-container {
        height: auto;
        max-height: 100vh;
    }

    .chat-box {
        flex: 1;
        padding: 8px 10px;
        gap: 6px;
    }

    .ai-message, 
    .user-message {
        max-width: 95%;
        font-size: 12px;
        padding: 8px 10px;
    }

    textarea {
        font-size: 12px;
        padding: 6px 8px;
        height: 35px;
    }

    .input-area {
        padding: 6px 8px;
        gap: 6px;
    }

    button {
        padding: 6px 12px;
        font-size: 13px;
    }
}
