/* ============================================
   TechChat - ChatGPT Style Theme (Mobile Fixed)
   ============================================ */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg-primary: #ffffff;
    --bg-secondary: #f7f7f8;
    --bg-sidebar: #f9f9f9;
    --text-primary: #0d0d0d;
    --text-secondary: #6e6e80;
    --border-color: #e5e5e5;
    --accent: #10a37f;
    --accent-hover: #0d8a6a;
    --user-bubble: #f7f7f8;
    --bot-bubble: #ffffff;
    --shadow: 0 2px 8px rgba(0,0,0,0.08);
    --radius: 12px;
}

[data-theme="dark"] {
    --bg-primary: #212121;
    --bg-secondary: #2f2f2f;
    --bg-sidebar: #171717;
    --text-primary: #ececec;
    --text-secondary: #9b9b9b;
    --border-color: #3a3a3a;
    --accent: #19c37d;
    --accent-hover: #15a86b;
    --user-bubble: #2f2f2f;
    --bot-bubble: #212121;
    --shadow: 0 2px 8px rgba(0,0,0,0.3);
}

html, body {
    height: 100%;
    overflow: hidden; /* جلوگیری از اسکرول کل صفحه */
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Vazirmatn", "Tahoma", sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    direction: rtl;
    transition: background 0.2s, color 0.2s;
}

/* ============================================
   LOGIN PAGE
   ============================================ */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: linear-gradient(135deg, #126b88 0%, #15b09b 100%);
    height: 100dvh; /* استفاده از dvh برای موبایل */
}

.login-box {
    background: var(--bg-primary);
    border-radius: 16px;
    padding: 40px 32px;
    width: 100%;
    max-width: 400px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.2);
}

.logo-area { text-align: center; margin-bottom: 32px; }
.logo-area h1 { font-size: 28px; margin-top: 12px; color: var(--text-primary); }
.logo-area p { color: var(--text-secondary); font-size: 14px; margin-top: 4px; }

.input-group { margin-bottom: 16px; }
.input-group label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: var(--text-primary); }
.input-group input {
    width: 100%; padding: 12px 16px; border: 1px solid var(--border-color);
    border-radius: var(--radius); background: var(--bg-secondary);
    color: var(--text-primary); font-size: 15px; font-family: inherit;
}
.input-group input:focus { outline: none; border-color: var(--accent); }

.btn-primary {
    width: 100%; padding: 12px; background: var(--accent); color: #fff;
    border: none; border-radius: var(--radius); font-size: 15px;
    font-weight: 600; cursor: pointer; font-family: inherit; transition: background 0.2s;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; }

.error-msg { color: #e53935; font-size: 13px; margin: 8px 0; min-height: 18px; }

/* ============================================
   CHAT PAGE
   ============================================ */
.chat-page {
    display: flex;
    height: 100dvh; /* 100dvh مشکل نوار مرورگر موبایل را حل می‌کند */
    width: 100vw;
    overflow: hidden;
    position: relative;
}

/* Sidebar */
.sidebar {
    width: 260px;
    background: var(--bg-sidebar);
    border-left: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    transition: transform 0.3s;
    flex-shrink: 0;
}

.sidebar-header { padding: 16px; border-bottom: 1px solid var(--border-color); }
.new-chat-btn {
    width: 100%; padding: 10px 14px; background: transparent;
    border: 1px solid var(--border-color); border-radius: var(--radius);
    color: var(--text-primary); font-size: 14px; font-weight: 600;
    cursor: pointer; text-align: right; font-family: inherit;
}
.new-chat-btn:hover { background: var(--bg-secondary); }

.sidebar-content { flex: 1; overflow-y: auto; padding: 8px; }
.chat-item {
    padding: 10px 12px; border-radius: 8px; cursor: pointer;
    font-size: 14px; color: var(--text-primary); margin-bottom: 2px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chat-item:hover, .chat-item.active { background: var(--bg-secondary); }

.sidebar-footer { padding: 12px; border-top: 1px solid var(--border-color); }
.user-info {
    display: flex; align-items: center; gap: 10px; padding: 8px;
    border-radius: 8px; cursor: pointer;
}
.user-info:hover { background: var(--bg-secondary); }
.user-avatar {
    width: 32px; height: 32px; border-radius: 50%; background: var(--accent);
    color: #fff; display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 14px;
}
.user-name { font-size: 14px; font-weight: 600; color: var(--text-primary); flex: 1; }

/* Main Chat Area */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-primary);
    min-width: 0;
    height: 100%;
}

.chat-header {
    padding: 12px 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0; /* هدر جمع نشود */
}

.chat-title { font-size: 15px; font-weight: 600; color: var(--text-primary); }
.chat-actions { display: flex; gap: 8px; }
.icon-btn {
    background: transparent; border: none; padding: 8px; border-radius: 8px;
    cursor: pointer; color: var(--text-secondary); font-size: 18px;
}
.icon-btn:hover { background: var(--bg-secondary); }

/* Messages */
.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 24px 20px;
    scroll-behavior: smooth;
}

.message {
    max-width: 720px; margin: 0 auto 24px;
    display: flex; gap: 12px; animation: fadeIn 0.3s ease;
}
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

.message.own { flex-direction: row-reverse; }
.message-avatar {
    width: 32px; height: 32px; border-radius: 50%; flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 13px; color: #fff;
}
.message-avatar.user { background: var(--accent); }
.message-avatar.admin { background: #126b88; }

.message-content { flex: 1; min-width: 0; }
.message-header { display: flex; gap: 8px; align-items: baseline; margin-bottom: 4px; font-size: 13px; }
.message.own .message-header { justify-content: flex-end; }
.message-sender { font-weight: 600; color: var(--text-primary); }
.message-time { color: var(--text-secondary); font-size: 11px; }

.message-bubble {
    background: var(--bot-bubble); border: 1px solid var(--border-color);
    padding: 12px 16px; border-radius: var(--radius); font-size: 15px;
    line-height: 1.7; color: var(--text-primary); word-wrap: break-word;
    white-space: pre-wrap;
}
.message.own .message-bubble { background: var(--user-bubble); }

.message-actions { margin-top: 6px; display: flex; gap: 6px; opacity: 0; transition: opacity 0.2s; }
.message:hover .message-actions { opacity: 1; }
.msg-action-btn {
    background: transparent; border: 1px solid var(--border-color);
    padding: 4px 10px; border-radius: 6px; font-size: 12px;
    cursor: pointer; color: var(--text-secondary); font-family: inherit;
}
.msg-action-btn:hover { background: var(--bg-secondary); color: var(--text-primary); }

.locked-badge {
    display: inline-block; background: var(--bg-secondary);
    border: 1px dashed var(--border-color); padding: 8px 12px;
    border-radius: 8px; font-size: 13px; color: var(--text-secondary);
}

/* Input area */
.chat-input-area {
    padding: 12px 20px 20px;
    border-top: 1px solid var(--border-color);
    flex-shrink: 0; /* کادر ورودی همیشه در پایین بماند */
    background: var(--bg-primary);
}
.input-container {
    max-width: 720px; margin: 0 auto; display: flex;
    align-items: flex-end; gap: 8px; background: var(--bg-secondary);
    border: 1px solid var(--border-color); border-radius: 16px;
    padding: 8px 12px;
}
.input-container:focus-within { border-color: var(--accent); }
.chat-textarea {
    flex: 1; background: transparent; border: none; resize: none;
    padding: 8px; font-family: inherit; font-size: 15px;
    color: var(--text-primary); max-height: 120px; outline: none; line-height: 1.5;
}
.chat-textarea::placeholder { color: var(--text-secondary); }

.send-btn {
    background: var(--accent); color: #fff; border: none;
    width: 36px; height: 36px; border-radius: 8px; cursor: pointer;
    display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.send-btn:hover { background: var(--accent-hover); }
.send-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* ============================================
   MODAL (رفع مشکل تداخل)
   ============================================ */
.modal-overlay {
    position: fixed; /* ثابت روی کل صفحه */
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.6); /* پس‌زمینه تاریک */
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 9999; /* بالاتر از هر چیزی */
    padding: 20px;
}
.modal-overlay.active {
    display: flex; /* فقط وقتی اکتیو شد، نمایش داده شود */
}
.modal {
    background: var(--bg-primary); border-radius: 16px;
    padding: 24px; width: 100%; max-width: 400px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.3);
    z-index: 10000;
}
.modal h3 { font-size: 18px; margin-bottom: 8px; color: var(--text-primary); }
.modal p { font-size: 14px; color: var(--text-secondary); margin-bottom: 16px; line-height: 1.6; }
.modal-actions { display: flex; gap: 8px; margin-top: 16px; }
.btn-secondary {
    flex: 1; padding: 10px; background: var(--bg-secondary);
    color: var(--text-primary); border: 1px solid var(--border-color);
    border-radius: 8px; font-size: 14px; cursor: pointer; font-family: inherit;
}
.btn-secondary:hover { background: var(--border-color); }

/* ============================================
   MOBILE RESPONSIVE
   ============================================ */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        top: 0; bottom: 0; right: 0;
        z-index: 100;
        transform: translateX(100%);
        width: 280px;
        box-shadow: -4px 0 10px rgba(0,0,0,0.1);
    }
    .sidebar.open { transform: translateX(0); }

    .messages-container { padding: 16px 12px; }
    .message { margin-bottom: 16px; }
    .chat-input-area { padding: 8px 12px; padding-bottom: max(8px, env(safe-area-inset-bottom)); }

    /* نمایش دکمه منو در موبایل */
    #menuToggle { display: inline-flex !important; }
}

/* Scrollbar */
::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-secondary); }
