        /* ===== متغیرهای CSS ===== */
        :root {
            --bg: #0d1117;
            --bg-secondary: #161b22;
            --bg-hover: #1c2333;
            --bg-input: #0d1117;
            --text: #e6edf3;
            --text-secondary: #8b949e;
            --text-muted: #484f58;
            --border: #30363d;
            --primary: #4285F4;
            --primary-dark: #3367d6;
            --primary-light: #5a9af7;
            --user-msg: #4285F4;
            --assistant-msg: #161b22;
            --shadow: 0 8px 32px rgba(0,0,0,0.4);
            --radius: 12px;
            --radius-sm: 8px;
            --transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
            --scrollbar: #30363d;
            --danger: #f85149;
            --success: #3fb950;
            --warning: #d29922;
            --tts-bg: #1c2333;
            --tts-border: #30363d;
            --sidebar-width: 340px;
            --font-family: 'Vazirmatn', 'Segoe UI', Tahoma, Arial, sans-serif;
            --header-height: 56px;
            --input-height: 60px;
            --app-height: 100dvh;
        }

        [data-theme="light"] {
            --bg: #f6f8fa;
            --bg-secondary: #ffffff;
            --bg-hover: #f0f2f4;
            --bg-input: #f6f8fa;
            --text: #1f2328;
            --text-secondary: #656d76;
            --text-muted: #8b949e;
            --border: #d0d7de;
            --primary: #4285F4;
            --primary-dark: #3367d6;
            --primary-light: #5a9af7;
            --user-msg: #4285F4;
            --assistant-msg: #ffffff;
            --shadow: 0 8px 32px rgba(0,0,0,0.08);
            --scrollbar: #d0d7de;
            --tts-bg: #f0f2f4;
            --tts-border: #d0d7de;
        }

        * { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
        html { overflow: hidden; overscroll-behavior: none; }
        body {
            font-family: var(--font-family);
            background: var(--bg);
            color: var(--text);
            height: 100dvh;
            height: var(--app-height, 100dvh);
            overflow: hidden;
            overflow-x: hidden;
            overscroll-behavior-y: none;
            display: flex;
            flex-direction: column;
            transition: background var(--transition), color var(--transition);
            direction: rtl;
            touch-action: pan-y;
            padding: env(safe-area-inset-top, 0) env(safe-area-inset-right, 0) env(safe-area-inset-bottom, 0) env(safe-area-inset-left, 0);
            -webkit-text-size-adjust: 100%;
        }

        ::-webkit-scrollbar { width: 4px; height: 4px; }
        ::-webkit-scrollbar-track { background: transparent; }
        ::-webkit-scrollbar-thumb { background: var(--scrollbar); border-radius: 10px; }

        /* ===== هدر ===== */
        .chat-header {
            background: var(--bg-secondary);
            padding: 8px 12px;
            padding-top: env(safe-area-inset-top, 8px);
            border-bottom: 1px solid var(--border);
            display: flex;
            align-items: center;
            justify-content: space-between;
            flex-shrink: 0;
            gap: 6px;
            flex-wrap: nowrap;
            z-index: 10;
            transition: background var(--transition), border-color var(--transition);
            height: var(--header-height);
            min-height: var(--header-height);
            position: sticky;
            top: 0;
            overflow: visible;
        }
        .chat-header .info { display: flex; align-items: center; gap: 8px; min-width: 0; flex: 1; }
        .chat-header .avatar { width: 32px; height: 32px; background: var(--primary); border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 16px; flex-shrink: 0; color: white; }
        .chat-header .name { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 120px; }
        .chat-header .status { font-size: 10px; padding: 2px 10px; border-radius: 20px; font-weight: 600; flex-shrink: 0; }
        .chat-header .status.active { background: #1a4732; color: #58c48a; }
        .chat-header .status.inactive { background: #4a1a1a; color: #f87171; }
        [data-theme="light"] .chat-header .status.active { background: #d4edda; color: #155724; }
        [data-theme="light"] .chat-header .status.inactive { background: #f8d7da; color: #721c24; }
        .chat-header .back-btn { background: none; border: none; font-size: 20px; cursor: pointer; color: var(--text-secondary); padding: 4px 6px; border-radius: 8px; transition: var(--transition); touch-action: manipulation; }
        .chat-header .back-btn:hover { background: var(--bg-hover); color: var(--text); }
        .chat-header .header-actions { display: flex; align-items: center; gap: 2px; flex-shrink: 0; flex-wrap: wrap; }
        .chat-header .header-actions button { background: none; border: none; color: var(--text-secondary); cursor: pointer; padding: 4px 8px; border-radius: 6px; font-size: 16px; transition: var(--transition); touch-action: manipulation; min-width: 36px; min-height: 36px; display: flex; align-items: center; justify-content: center; }
        .chat-header .header-actions button:hover { background: var(--bg-hover); color: var(--text); }
        .chat-header .header-actions .theme-toggle { font-size: 18px; }
        .chat-header .header-actions .new-chat-btn { color: var(--primary); font-weight: 600; }
        .chat-header .header-actions .new-chat-btn:hover { background: rgba(66,133,244,0.1); }

        /* ===== انتخابگر ربات ===== */
        .robot-selector {
            position: relative;
            display: inline-block;
            margin: 0 4px;
        }
        .robot-selector select {
            appearance: none;
            -webkit-appearance: none;
            background: var(--bg-hover);
            border: 1px solid var(--border);
            border-radius: var(--radius-sm);
            color: var(--text);
            padding: 4px 28px 4px 12px;
            font-size: 13px;
            font-family: var(--font-family);
            cursor: pointer;
            max-width: 120px;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
            direction: ltr;
            transition: var(--transition);
            height: 32px;
        }
        .robot-selector select:focus { outline: none; border-color: var(--primary); }
        .robot-selector::after {
            content: "▼";
            position: absolute;
            left: 8px;
            top: 50%;
            transform: translateY(-50%);
            color: var(--text-secondary);
            font-size: 10px;
            pointer-events: none;
        }
        .robot-selector select option { background: var(--bg-secondary); color: var(--text); }

        /* ===== سایدبار ===== */
        .sidebar {
            position: fixed;
            top: 0;
            right: calc(-1 * var(--sidebar-width));
            width: var(--sidebar-width);
            height: 100%;
            background: var(--bg-secondary);
            border-left: 1px solid var(--border);
            z-index: 100;
            transition: right 0.3s ease;
            padding: 12px;
            padding-top: env(safe-area-inset-top, 12px);
            overflow-y: auto;
            display: flex;
            flex-direction: column;
            gap: 6px;
            touch-action: pan-y;
            overscroll-behavior-y: contain;
            box-shadow: -12px 0 32px rgba(0,0,0,0.25);
        }
        .sidebar.open { right: 0; }
        .sidebar-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.5); backdrop-filter: blur(2px); -webkit-backdrop-filter: blur(2px); z-index: 99; display: none; touch-action: none; opacity: 0; transition: opacity 0.25s ease; }
        .sidebar-overlay.show { display: block; opacity: 1; }
        .sidebar .sidebar-header { display: flex; justify-content: space-between; align-items: center; padding-bottom: 10px; border-bottom: 1px solid var(--border); margin-bottom: 10px; }
        .sidebar .sidebar-header h3 { font-size: 15px; color: var(--text); }
        .sidebar .sidebar-header button { background: none; border: none; color: var(--text-secondary); font-size: 22px; cursor: pointer; padding: 4px; touch-action: manipulation; }
        .sidebar .search-box { display: flex; gap: 6px; margin-bottom: 10px; }
        .sidebar .search-box input { flex: 1; padding: 8px 12px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--bg-input); color: var(--text); font-size: 13px; min-height: 40px; }
        .sidebar .search-box input:focus { outline: none; border-color: var(--primary); }
        .sidebar .search-box button { background: var(--primary); color: white; border: none; border-radius: var(--radius-sm); padding: 8px 14px; cursor: pointer; font-size: 16px; touch-action: manipulation; }
        .sidebar .chat-item { padding: 10px 12px; border-radius: var(--radius-sm); cursor: pointer; transition: var(--transition); display: flex; justify-content: space-between; align-items: center; border: 1px solid transparent; background: var(--bg); touch-action: manipulation; }
        .sidebar .chat-item:hover { background: var(--bg-hover); border-color: var(--border); }
        .sidebar .chat-item.active { border-color: var(--primary); background: rgba(66,133,244,0.08); }
        .sidebar .chat-item .chat-title { font-size: 13px; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 160px; cursor: pointer; touch-action: manipulation; }
        .sidebar .chat-item .chat-title[contenteditable="true"] { background: var(--bg-input); border: 1px solid var(--primary); border-radius: 4px; padding: 0 4px; }
        .sidebar .chat-item .chat-delete { background: none; border: none; color: var(--text-muted); cursor: pointer; font-size: 16px; padding: 4px 8px; border-radius: 4px; touch-action: manipulation; }
        .sidebar .chat-item .chat-delete:hover { color: var(--danger); background: rgba(248,81,73,0.1); }
        .sidebar .new-chat-sidebar { width: 100%; padding: 12px; background: var(--primary); color: white; border: none; border-radius: var(--radius-sm); cursor: pointer; font-weight: 600; transition: var(--transition); margin-top: auto; touch-action: manipulation; font-size: 15px; }
        .sidebar .new-chat-sidebar:hover { background: var(--primary-dark); }
        .sidebar .search-results { max-height: 300px; overflow-y: auto; }
        .sidebar .search-result-item { padding: 8px 12px; border-bottom: 1px solid var(--border); font-size: 13px; cursor: pointer; transition: var(--transition); touch-action: manipulation; }
        .sidebar .search-result-item:hover { background: var(--bg-hover); }
        .sidebar .search-result-item .highlight { color: var(--primary); font-weight: 600; }
        .sidebar .search-result-item .meta { font-size: 11px; color: var(--text-secondary); }

        /* ===== ناحیه پیام‌ها ===== */
        .chat-main {
            flex: 1;
            display: flex;
            overflow: hidden;
            transition: all var(--transition);
        }
        .chat-messages {
            flex: 1;
            overflow-y: auto;
            padding: 12px 14px;
            padding-bottom: env(safe-area-inset-bottom, 12px);
            display: flex;
            flex-direction: column;
            gap: 4px;
            scroll-behavior: smooth;
            background: var(--bg);
            transition: background var(--transition);
            -webkit-overflow-scrolling: touch;
            overscroll-behavior-y: contain;
            position: relative;
        }
        .chat-messages .user-scroll {
            scroll-behavior: auto !important;
        }
        .chat-messages .empty { text-align: center; color: var(--text-secondary); padding: 40px 16px; font-size: 14px; line-height: 2; }
        .chat-messages .empty .big-icon { font-size: 48px; display: block; margin-bottom: 12px; }
        .chat-messages .empty .title { font-size: 18px; font-weight: 700; color: var(--text); }
        .chat-messages .empty .subtitle { font-size: 13px; color: var(--text-secondary); }

        /* ===== Split View ===== */
        .split-panel {
            width: 0;
            overflow: hidden;
            background: var(--bg-secondary);
            border-left: 1px solid var(--border);
            transition: width 0.3s ease, padding 0.3s ease;
            padding: 0;
            display: flex;
            flex-direction: column;
        }
        .split-panel.open {
            width: 45%;
            padding: 12px;
        }
        .split-panel .split-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding-bottom: 10px;
            border-bottom: 1px solid var(--border);
            margin-bottom: 10px;
        }
        .split-panel .split-header h4 { font-size: 14px; color: var(--text-secondary); }
        .split-panel .split-header button { background: none; border: none; color: var(--text-secondary); cursor: pointer; font-size: 20px; touch-action: manipulation; padding: 4px; }
        .split-panel .split-content {
            flex: 1;
            overflow-y: auto;
            font-size: 14px;
            line-height: 1.8;
            color: var(--text);
            -webkit-overflow-scrolling: touch;
        }
        .split-panel .split-content .card {
            background: var(--bg);
            border: 1px solid var(--border);
            border-radius: var(--radius-sm);
            padding: 14px;
            margin-bottom: 10px;
        }
        .split-panel .split-content .card h5 { color: var(--primary); margin-bottom: 4px; }
        .split-panel .split-content table { width: 100%; border-collapse: collapse; }
        .split-panel .split-content th, .split-panel .split-content td { border: 1px solid var(--border); padding: 4px 8px; text-align: right; }

        /* ===== پیام‌ها ===== */
        .message {
            max-width: 92%;
            padding: 8px 14px;
            border-radius: var(--radius);
            word-wrap: break-word;
            animation: fadeIn 0.25s ease;
            line-height: 1.6;
            font-size: 14px;
            position: relative;
            transition: background var(--transition), border-color var(--transition);
            touch-action: manipulation;
        }
        .message.user { align-self: flex-start; background: var(--user-msg); color: white; border-bottom-right-radius: 4px; }
        .message.assistant { align-self: flex-end; background: var(--assistant-msg); border: 1px solid var(--border); border-bottom-left-radius: 4px; color: var(--text); }
        .message .footer {
            display: flex;
            justify-content: space-between;
            align-items: center;
            gap: 4px;
            margin-top: 2px;
            font-size: 10px;
            flex-wrap: wrap;
        }
        .message .time {
            opacity: 0.5;
            margin: 0;
            font-size: 10px;
        }
        .message.user .time { color: rgba(255,255,255,0.6); }
        .message.assistant .time { color: var(--text-secondary); }

        .message-actions {
            display: flex;
            flex-wrap: wrap;
            gap: 3px;
            opacity: 0;
            transition: opacity 0.2s;
        }
        .message:hover .message-actions { opacity: 1; }
        .message-actions button {
            background: none;
            border: none;
            color: var(--text-secondary);
            cursor: pointer;
            font-size: 12px;
            padding: 3px 8px;
            border-radius: 4px;
            transition: var(--transition);
            touch-action: manipulation;
            min-height: 30px;
        }
        .message-actions button:hover { background: var(--bg-hover); color: var(--text); }
        .message-actions .copy-btn:hover { color: var(--primary); }
        .message-actions .edit-btn:hover { color: var(--warning); }
        .message-actions .regenerate-btn:hover { color: var(--success); }
        .message-actions .split-btn:hover { color: var(--primary-light); }
        .message-actions .pin-btn:hover { color: var(--warning); }
        .message.user .message-actions .edit-btn:hover { color: #ffd700; }

        /* دکمه‌های نسخه */
        .version-controls {
            display: none;
            gap: 4px;
            align-items: center;
            margin-top: 4px;
            flex-wrap: wrap;
        }
        .version-controls.show { display: flex; }
        .version-controls button {
            background: var(--bg-hover);
            border: none;
            color: var(--text-secondary);
            cursor: pointer;
            font-size: 13px;
            padding: 2px 10px;
            border-radius: var(--radius-sm);
            transition: var(--transition);
            touch-action: manipulation;
            min-height: 28px;
        }
        .version-controls button:hover { background: var(--border); color: var(--text); }
        .version-controls .version-badge {
            font-size: 11px;
            color: var(--text-muted);
            padding: 0 6px;
        }

        /* ویرایش پیام */
        .edit-area { display: none; width: 100%; margin-top: 4px; gap: 4px; flex-wrap: wrap; }
        .edit-area.show { display: flex; }
        .edit-area textarea { flex: 1; min-width: 150px; padding: 6px 10px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--bg-input); color: var(--text); font-size: 14px; font-family: inherit; resize: vertical; min-height: 40px; }
        .edit-area textarea:focus { outline: none; border-color: var(--primary); }
        .edit-area button { padding: 6px 12px; border: none; border-radius: var(--radius-sm); cursor: pointer; font-weight: 600; font-size: 13px; transition: var(--transition); touch-action: manipulation; min-height: 36px; }
        .edit-area .save-edit { background: var(--primary); color: white; }
        .edit-area .save-edit:hover { background: var(--primary-dark); }
        .edit-area .cancel-edit { background: var(--bg-hover); color: var(--text-secondary); }
        .edit-area .cancel-edit:hover { background: var(--border); }

        @keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }

        /* تایپینگ */
        .typing-indicator { align-self: flex-end; background: var(--assistant-msg); border: 1px solid var(--border); border-radius: var(--radius); border-bottom-left-radius: 4px; padding: 10px 16px; display: none; gap: 4px; align-items: center; }
        .typing-indicator.show { display: flex; }
        .typing-indicator span { width: 8px; height: 8px; background: var(--text-secondary); border-radius: 50%; animation: typing 1.4s infinite; }
        .typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
        .typing-indicator span:nth-child(3) { animation-delay: 0.4s; }
        @keyframes typing { 0%, 60%, 100% { transform: translateY(0); opacity: 0.4; } 30% { transform: translateY(-8px); opacity: 1; } }
        .typing-indicator .stop-btn { background: var(--bg); border: 1px solid var(--danger); color: var(--danger); cursor: pointer; font-size: 13px; margin-left: 10px; touch-action: manipulation; padding: 4px 12px; border-radius: var(--radius-sm); font-weight: 600; display: none; transition: var(--transition); display: flex; align-items: center; gap: 4px; }
        .typing-indicator .stop-btn:hover { background: var(--danger); color: white; }

        /* وضعیت ربات */
        .robot-status { font-size: 10px; padding: 2px 10px; border-radius: 20px; font-weight: 600; }
        .robot-status.active { background: #1a4732; color: #58c48a; }
        .robot-status.inactive { background: #4a1a1a; color: #f87171; }
        [data-theme="light"] .robot-status.active { background: #d4edda; color: #155724; }
        [data-theme="light"] .robot-status.inactive { background: #f8d7da; color: #721c24; }

        /* ورودی */
        .chat-input {
            background: var(--bg-secondary);
            padding: 8px 12px;
            padding-bottom: env(safe-area-inset-bottom, 8px);
            border-top: 1px solid var(--border);
            display: flex;
            flex-direction: column;
            gap: 4px;
            flex-shrink: 0;
            transition: background var(--transition), border-color var(--transition);
        }
        .chat-input .input-wrapper { display: flex; gap: 6px; align-items: flex-end; }
        .chat-input .input-actions { display: flex; gap: 2px; align-items: center; }
        .chat-input .input-actions button {
            background: none;
            border: none;
            color: var(--text-secondary);
            cursor: pointer;
            padding: 4px 6px;
            border-radius: var(--radius-sm);
            font-size: 20px;
            transition: var(--transition);
            height: 40px;
            display: flex;
            align-items: center;
            justify-content: center;
            touch-action: manipulation;
            min-width: 36px;
        }
        .chat-input .input-actions button:hover { background: var(--bg-hover); color: var(--text); }
        .chat-input .input-actions button.active { color: var(--primary); }
        .chat-input .input-actions .file-label { cursor: pointer; }
        .chat-input .input-actions .file-label input { display: none; }
        .chat-input .input-actions .voice-btn.recording { color: var(--danger); animation: pulse 1s infinite; }
        @keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.4; } }

        .chat-input textarea {
            flex: 1;
            border: 1px solid var(--border);
            border-radius: var(--radius);
            padding: 8px 12px;
            font-size: 14px;
            font-family: inherit;
            resize: none;
            min-height: 40px;
            max-height: 120px;
            background: var(--bg-input);
            color: var(--text);
            line-height: 1.4;
            transition: var(--transition);
            touch-action: manipulation;
        }
        .chat-input textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(66,133,244,0.2); }
        .chat-input textarea::placeholder { color: var(--text-secondary); }
        .chat-input .send-btn {
            background: var(--primary);
            color: white;
            border: none;
            border-radius: var(--radius);
            padding: 8px 16px;
            font-size: 20px;
            cursor: pointer;
            height: 40px;
            display: flex;
            align-items: center;
            justify-content: center;
            flex-shrink: 0;
            transition: var(--transition);
            touch-action: manipulation;
            min-width: 44px;
        }
        .chat-input .send-btn:hover { background: var(--primary-dark); transform: scale(1.02); }
        .chat-input .send-btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

        /* فایل پیش‌نمایش */
        .file-preview {
            display: none;
            background: var(--bg-hover);
            border: 1px solid var(--border);
            border-radius: var(--radius-sm);
            padding: 4px 10px;
            font-size: 12px;
            color: var(--text-secondary);
            align-items: center;
            gap: 6px;
            width: 100%;
        }
        .file-preview.show { display: flex; }
        .file-preview .file-name { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
        .file-preview .file-remove { background: none; border: none; color: var(--danger); cursor: pointer; font-size: 16px; touch-action: manipulation; padding: 0 4px; }
        .file-preview img {
            max-height: 40px;
            max-width: 40px;
            border-radius: 4px;
            margin-left: 6px;
            display: none;
        }

        /* TTS Player - چیدمان از چپ به راست */
        .tts-player {
            display: none;
            background: var(--tts-bg);
            border: 1px solid var(--tts-border);
            border-radius: var(--radius);
            padding: 10px 14px;
            margin-top: 6px;
            align-items: center;
            gap: 8px;
            flex-wrap: wrap;
            transition: background var(--transition), border-color var(--transition);
            position: relative;
            direction: ltr;
        }
        .tts-player.show { display: flex; }
        .tts-player .tts-controls { display: flex; align-items: center; gap: 4px; }
        .tts-player .tts-controls button { background: none; border: none; color: var(--text-secondary); cursor: pointer; font-size: 18px; padding: 4px 8px; border-radius: var(--radius-sm); transition: var(--transition); width: 32px; height: 32px; display: flex; align-items: center; justify-content: center; touch-action: manipulation; }
        .tts-player .tts-controls button:hover { background: var(--bg-hover); color: var(--text); }
        .tts-player .tts-controls button.playing { color: var(--primary); }
        .tts-player .tts-progress { flex: 1; min-width: 80px; height: 4px; background: var(--border); border-radius: 2px; cursor: pointer; position: relative; touch-action: none; }
        .tts-player .tts-progress .tts-progress-bar { height: 100%; background: var(--primary); border-radius: 2px; width: 0%; transition: width 0.1s; }
        .tts-player .tts-time { font-size: 11px; color: var(--text-secondary); min-width: 70px; text-align: center; }
        .tts-player .tts-voice-select { background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm); color: var(--text); padding: 2px 6px; font-size: 11px; cursor: pointer; max-width: 100px; }
        .tts-player .tts-voice-select:focus { outline: none; border-color: var(--primary); }
        .tts-player .tts-download { background: none; border: none; color: var(--text-secondary); cursor: pointer; font-size: 16px; padding: 4px 8px; border-radius: var(--radius-sm); transition: var(--transition); touch-action: manipulation; }
        .tts-player .tts-download:hover { background: var(--bg-hover); color: var(--text); }
        .tts-player .tts-status { font-size: 10px; color: var(--text-muted); }
        .tts-player .tts-close-btn {
            background: none;
            border: none;
            color: var(--text-secondary);
            cursor: pointer;
            font-size: 14px;
            padding: 2px 6px;
            border-radius: var(--radius-sm);
            transition: var(--transition);
            position: absolute;
            top: 2px;
            right: 2px;
            line-height: 1;
            touch-action: manipulation;
        }
        .tts-player .tts-close-btn:hover { background: var(--bg-hover); color: var(--text); }
        .tts-player .tts-minimize-btn {
            background: none;
            border: none;
            color: var(--text-secondary);
            cursor: pointer;
            font-size: 14px;
            padding: 2px 6px;
            border-radius: var(--radius-sm);
            transition: var(--transition);
            position: absolute;
            top: 2px;
            right: 30px;
            line-height: 1;
            touch-action: manipulation;
        }
        .tts-player .tts-minimize-btn:hover { background: var(--bg-hover); color: var(--text); }
        .tts-player .tts-subtitle {
            width: 100%;
            font-size: 12px;
            color: var(--text-secondary);
            text-align: center;
            padding: 2px 0;
            border-top: 1px solid var(--border);
            margin-top: 2px;
            display: none;
        }
        .tts-player .tts-subtitle.show { display: block; }
        .tts-player .tts-speed-display { font-size: 11px; min-width: 28px; text-align: center; color: var(--text-secondary); }

        /* ===== ریسپانسیو موبایل ===== */
        @media (max-width: 768px) {
            :root {
                --header-height: 50px;
                --input-height: 56px;
            }
            .chat-header { padding: 4px 8px; padding-top: env(safe-area-inset-top, 4px); }
            .chat-header .name { font-size: 13px; max-width: 80px; }
            .chat-header .avatar { width: 28px; height: 28px; font-size: 14px; }
            .chat-header .status { font-size: 9px; padding: 1px 8px; }
            .chat-header .header-actions button { font-size: 14px; min-width: 32px; min-height: 32px; padding: 2px 6px; }
            .robot-selector select { font-size: 12px; max-width: 90px; height: 28px; padding: 2px 24px 2px 8px; }
            .chat-messages { padding: 8px 10px; padding-bottom: env(safe-area-inset-bottom, 8px); gap: 3px; }
            .message { max-width: 94%; font-size: 13px; padding: 6px 12px; }
            .chat-input { padding: 6px 10px; padding-bottom: env(safe-area-inset-bottom, 6px); }
            .chat-input textarea { font-size: 13px; padding: 6px 10px; min-height: 36px; max-height: 100px; }
            .chat-input .send-btn { font-size: 18px; height: 36px; min-width: 38px; padding: 6px 12px; }
            .chat-input .input-actions button { font-size: 18px; height: 36px; min-width: 32px; padding: 2px 4px; }
            .chat-messages .empty { padding: 30px 12px; font-size: 13px; }
            .chat-messages .empty .big-icon { font-size: 36px; }
            .sidebar { width: 280px; right: -280px; padding: 10px; padding-top: env(safe-area-inset-top, 10px); }
            .tts-player { padding: 8px 10px; gap: 6px; }
            .tts-player .tts-controls button { font-size: 16px; width: 28px; height: 28px; }
            .tts-player .tts-voice-select { max-width: 80px; font-size: 10px; }
            .tts-player .tts-time { font-size: 10px; min-width: 60px; }
            .split-panel.open { width: 100%; }
            .message-actions { opacity: 1; }
            .version-controls button { font-size: 12px; padding: 2px 8px; min-height: 24px; }
            .tts-autoplay-btn .tooltip { display: none !important; }
            .desktop-only-action { display: none !important; }
            .chat-header .header-actions .more-btn { display: flex; align-items: center; justify-content: center; }
            .chat-header .info { max-width: 50%; }
        }
        @media (max-width: 400px) {
            .chat-header .name { font-size: 12px; max-width: 60px; }
            .chat-header .header-actions button { font-size: 12px; min-width: 28px; min-height: 28px; }
            .robot-selector select { font-size: 11px; max-width: 70px; height: 24px; padding: 0 20px 0 6px; }
            .message { font-size: 12px; padding: 5px 10px; }
            .chat-input textarea { font-size: 12px; padding: 4px 8px; min-height: 32px; }
            .chat-input .send-btn { font-size: 16px; height: 32px; min-width: 34px; }
            .chat-input .input-actions button { font-size: 16px; height: 32px; min-width: 28px; }
        }
        @media (pointer: coarse) {
            .message-actions { opacity: 1; }
            button, select, .chat-item, .search-result-item { touch-action: manipulation; }
            .message-actions button { min-height: 36px; padding: 4px 12px; }
            .version-controls button { min-height: 32px; padding: 4px 12px; }
            .sidebar .chat-item { padding: 12px 14px; }
        }

        /* استایل دکمه Auto-Play در هدر */
        .tts-autoplay-btn {
            background: none;
            border: none;
            color: var(--text-secondary);
            cursor: pointer;
            font-size: 18px;
            padding: 4px 8px;
            border-radius: 6px;
            transition: var(--transition);
            touch-action: manipulation;
            min-width: 36px;
            min-height: 36px;
            display: flex;
            align-items: center;
            justify-content: center;
            position: relative;
            gap: 4px;
            background: var(--bg-hover);
            border: 1px solid var(--border);
        }
        .tts-autoplay-btn:hover {
            background: var(--bg-hover);
            color: var(--text);
        }
        .tts-autoplay-btn.active {
            color: var(--primary);
            border-color: var(--primary);
        }
        .tts-autoplay-btn .tooltip {
            display: none;
            position: absolute;
            top: calc(100% + 6px);
            left: 50%;
            transform: translateX(-50%);
            background: var(--bg-secondary);
            color: var(--text);
            border: 1px solid var(--border);
            border-radius: var(--radius-sm);
            padding: 4px 8px;
            font-size: 11px;
            white-space: nowrap;
            z-index: 20;
        }
        .tts-autoplay-btn:hover .tooltip {
            display: block;
        }
        .tts-autoplay-btn .autoplay-label {
            font-size: 11px;
            font-weight: 600;
            display: none;
        }
        @media (min-width: 769px) {
            .tts-autoplay-btn .autoplay-label {
                display: inline;
            }
        }
        .chat-header .header-actions .more-btn { font-size: 20px; font-weight: 700; }
        .mobile-only-action { display: none; }
        @media (max-width: 768px) {
            .mobile-only-action { display: flex; }
        }

        /* ===== کامپوننت Bottom Sheet (منوی کف صفحه) — برای دوربین و گزینه‌های بیشتر ===== */
        .sheet-overlay {
            position: fixed; inset: 0; background: rgba(0,0,0,0.5);
            backdrop-filter: blur(2px); -webkit-backdrop-filter: blur(2px);
            z-index: 199; display: none; opacity: 0; transition: opacity 0.25s ease;
        }
        .sheet-overlay.show { display: block; opacity: 1; }
        .bottom-sheet {
            position: fixed;
            left: 0; right: 0; bottom: 0;
            background: var(--bg-secondary);
            border-top: 1px solid var(--border);
            border-radius: 18px 18px 0 0;
            box-shadow: var(--shadow);
            z-index: 200;
            padding: 8px 14px calc(14px + env(safe-area-inset-bottom, 0px));
            display: flex;
            flex-direction: column;
            gap: 4px;
            transform: translateY(100%);
            transition: transform 0.28s cubic-bezier(0.32, 0.72, 0, 1);
            max-height: 75vh;
            overflow-y: auto;
        }
        .bottom-sheet.show { transform: translateY(0); }
        .bottom-sheet-handle { width: 40px; height: 4px; border-radius: 4px; background: var(--border); margin: 4px auto 10px; flex-shrink: 0; }
        .bottom-sheet .sheet-title { font-size: 13px; color: var(--text-secondary); font-weight: 600; margin-bottom: 4px; padding: 0 4px; }
        .bottom-sheet .sheet-item {
            background: none; border: none; text-align: right; width: 100%;
            padding: 13px 10px; font-size: 15px; color: var(--text);
            border-radius: var(--radius-sm); cursor: pointer; touch-action: manipulation;
            display: flex; align-items: center; gap: 8px;
        }
        .bottom-sheet .sheet-item:hover, .bottom-sheet .sheet-item:active { background: var(--bg-hover); }
        .bottom-sheet .sheet-item.danger { color: var(--danger); }
        .bottom-sheet .sheet-item.cancel { color: var(--text-secondary); border-top: 1px solid var(--border); margin-top: 4px; border-radius: 0; font-weight: 600; }
        .bottom-sheet .sheet-row { display: flex; align-items: center; justify-content: space-between; padding: 10px; font-size: 14px; }
        .bottom-sheet .sheet-select {
            background: var(--bg-hover); border: 1px solid var(--border); border-radius: var(--radius-sm);
            color: var(--text); padding: 6px 10px; font-size: 13px; max-width: 55%; direction: ltr;
        }

        /* ===== بهبودهای تکمیلی تجربه کاربری موبایل ===== */

        /* بازخورد لمسی هنگام فشردن دکمه‌ها (چون hover در موبایل معنا ندارد) */
        @media (pointer: coarse) {
            button:active, .chat-item:active, .search-result-item:active, .robot-selector select:active {
                transform: scale(0.94);
                opacity: 0.85;
                transition: transform 0.1s ease, opacity 0.1s ease;
            }
            .send-btn:active { transform: scale(0.9); }
        }

        /* دسترس‌پذیری: فوکوس واضح فقط هنگام ناوبری با کیبورد، بدون تداخل با لمس/ماوس */
        button:focus-visible, textarea:focus-visible, input:focus-visible, select:focus-visible {
            outline: 2px solid var(--primary);
            outline-offset: 2px;
        }
        button:focus:not(:focus-visible) { outline: none; }

        /* دکمه شناور «پرش به پایین گفتگو» */
        .scroll-bottom-btn {
            position: fixed;
            left: 50%;
            transform: translateX(-50%) translateY(12px);
            bottom: calc(var(--input-height) + 14px + env(safe-area-inset-bottom, 0px));
            width: 40px;
            height: 40px;
            border-radius: 50%;
            background: var(--bg-secondary);
            color: var(--text);
            border: 1px solid var(--border);
            box-shadow: var(--shadow);
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 16px;
            cursor: pointer;
            z-index: 15;
            opacity: 0;
            pointer-events: none;
            transition: opacity 0.2s ease, transform 0.2s ease;
            touch-action: manipulation;
        }
        .scroll-bottom-btn.show {
            opacity: 1;
            pointer-events: auto;
            transform: translateX(-50%) translateY(0);
        }
        .scroll-bottom-btn:hover { background: var(--bg-hover); }
        .scroll-bottom-btn .unread-dot {
            position: absolute;
            top: -2px;
            left: -2px;
            width: 12px;
            height: 12px;
            border-radius: 50%;
            background: var(--primary);
            border: 2px solid var(--bg-secondary);
            display: none;
        }
        .scroll-bottom-btn.has-unread .unread-dot { display: block; }

        @media (max-width: 768px) {
            .scroll-bottom-btn { bottom: calc(var(--input-height) + 10px + env(safe-area-inset-bottom, 0px)); width: 36px; height: 36px; font-size: 14px; }
        }

        /* حداقل اندازه لمسی مناسب طبق استاندارد در دقیق‌ترین برش موبایل، بدون تغییر ظاهر فشرده */
        @media (max-width: 400px) {
            .chat-header .header-actions button { min-width: 32px; min-height: 32px; }
            .chat-input .input-actions button, .chat-input .send-btn { min-height: 36px; }
        }

        /* عرض تطبیقی سایدبار برای گوشی‌های خیلی کوچک یا خیلی بزرگ */
        @media (max-width: 480px) {
            .sidebar { width: min(86vw, 320px); right: min(-86vw, -320px); }
        }

        /* جلوگیری از پرش تصادفی هنگام تعامل با اسکرول‌بار داخلی split panel و sidebar در آیفون */
        .split-panel .split-content, .sidebar { -webkit-overflow-scrolling: touch; }

        /* حالت کاهش انیمیشن برای کاربرانی که ترجیح می‌دهند حرکت کمتری ببینند */
        @media (prefers-reduced-motion: reduce) {
            *, *::before, *::after { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; }
        }

        /* ========================================================================================== */
        /* ✨ NEW ✨ بهینه‌سازی‌های سطح ۱ برای تجربه کاربری موبایل (بدون حذف یک کاراکتر از کد اصلی) */
        /* ========================================================================================== */
        
        /* 1. هدر هوشمند - با اسکرول به پایین مخفی می‌شود و با اسکرول به بالا ظاهر می‌شود */
        .chat-header.smart-hidden {
            transform: translateY(-100%);
            opacity: 0;
            pointer-events: none;
            transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.25s ease;
        }
        .chat-header {
            transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.25s ease, background var(--transition), border-color var(--transition);
            will-change: transform;
        }
        /* برای جلوگیری از پرش محتوا، وقتی هدر مخفی است، فضای خالی را پر می‌کنیم */
        .chat-header.smart-hidden ~ .chat-main {
            margin-top: calc(-1 * var(--header-height));
        }

        /* 2. بهبود انیمیشن و کشیدن منوی کف صفحه (Bottom Sheet Drag) */
        .bottom-sheet.dragging {
            transition: none !important;
        }
        .bottom-sheet {
            will-change: transform;
            touch-action: none; /* برای جلوگیری از اسکرول افقی/عمودی در حین کشیدن */
        }

        /* 3. دکمه ارسال شناور و چسبیده به صفحه کلید (پشتیبانی بهتر از Viewport) */
        @media (max-width: 768px) {
            .chat-input .send-btn {
                min-width: 48px;
                min-height: 48px;
                border-radius: 50%;
            }
            .chat-input textarea {
                padding: 10px 14px; /* فضای لمسی بیشتر */
            }
        }

        /* 4. بهبود کشیدن سایدبار (Edge Swipe) */
        .sidebar {
            touch-action: pan-x; /* اجازه حرکت افقی برای کشیدن */
            will-change: transform;
        }
        .sidebar.open {
            /* کاملاً باز */
        }
        .sidebar.dragging {
            transition: none !important;
        }

        /* 5. حالت تمام‌صفحه ورودی هنگام فوکوس (برای کیبوردهای موبایل) */
        body.keyboard-open .chat-input {
            padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 4px);
        }
        body.keyboard-open .chat-messages {
            padding-bottom: 0px;
        }

        /* 6. بهبودهای ظاهری برای حس بومی (Native Feel) */
        .message {
            will-change: auto;
            backface-visibility: hidden;
        }
        .chat-messages {
            scroll-behavior: smooth;
        }

        /* ========================================================================================== */
