/* ═══════════════════════════════════════════════════════════
   چت هوشمند — استایل یکپارچه با مینی‌اپ (نسخه ۲)
   ⚠️ باید بعد از styles.css لود شود
   کاملاً ایزوله در #plan-ai-container
   ═══════════════════════════════════════════════════════════ */

/* ─── متغیرهای تم (فقط داخل کانتینر چت) ─── */
#plan-ai-container {
    --tg-bg: var(--bg-primary, #0f172a);
    --tg-text: var(--text-primary, #f8fafc);
    --tg-hint: var(--text-secondary, #94a3b8);
    --tg-link: var(--brand, #14b8a6);
    --tg-button: var(--button-bg, #14b8a6);
    --tg-button-text: var(--button-text, #ffffff);
    --tg-secondary-bg: var(--bg-secondary, #1e293b);

    --accent: #10b981;
    --accent-hover: #059669;
    --accent-glow: rgba(16, 185, 129, 0.25);
    --accent-soft: rgba(16, 185, 129, 0.12);
    --success: #22c55e;
    --error: #ef4444;

    --surface: #1e293b;
    --surface-hover: #334155;
    --surface-active: #475569;
    --border: #334155;
    --border-strong: #475569;

    --user-bubble: linear-gradient(135deg, #10b981 0%, #059669 100%);
    --user-text: #ffffff;
    --assistant-bubble: rgba(255, 255, 255, 0.06);
    --assistant-text: var(--tg-text);

    --radius: 18px;
    --radius-sm: 12px;
    --radius-xs: 8px;
    --header-height: 56px;

    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.2);
    --shadow-md: 0 4px 24px rgba(0, 0, 0, 0.3);

    --font-mono: 'JetBrains Mono', 'Fira Code', 'Courier New', monospace;
    --ease: cubic-bezier(0.4, 0, 0.2, 1);
    --ease-bounce: cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* ─── کانتینر: باکس ایزوله داخل تب ─── */
#plan-ai-container {
    position: relative;
    display: flex;
    flex-direction: column;
    width: 100%;
    height: auto;
    min-height: calc(100dvh - 260px);
    max-height: min(100dvh, 920px);
    background: var(--card-bg, #1e293b);
    border: 1px solid var(--card-border, rgba(255, 255, 255, 0.06));
    border-radius: 18px;
    overflow: visible;
    box-shadow: var(--card-shadow, 0 10px 30px -10px rgba(0, 0, 0, 0.5));
    color: var(--tg-text);
    -webkit-tap-highlight-color: transparent;
}

#plan-ai-container.hidden {
    display: none !important;
}

#plan-ai-container *,
#plan-ai-container *::before,
#plan-ai-container *::after {
    box-sizing: border-box;
}

/* ─── دکمه‌های آیکونی ─── */
.ai-icon-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: none;
    background: transparent;
    color: var(--tg-text);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.2s var(--ease);
    -webkit-tap-highlight-color: transparent;
}

.ai-icon-btn:hover {
    background: var(--surface-hover);
}

.ai-icon-btn:active {
    transform: scale(0.92);
    background: var(--surface-active);
}

/* ═══════════ هدر چت (داخل کانتینر، نه fixed) ═══════════ */
.ai-header {
    position: relative;
    flex: 0 0 auto;
    height: var(--header-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 0 12px;
    background: rgba(15, 23, 42, 0.55);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
    border-radius: 18px 18px 0 0;
    /* گوشه‌های گرد بالا (چون overflow کانتینر visible شد) */
    z-index: 30;
}

/* دو گروه هدر — با dir صفحه آینه می‌شوند */
.ai-header-group {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

/* عنوان تک‌خطی در یک سمت */
.ai-header-title-text {
    font-size: 0.98rem;
    font-weight: 600;
    letter-spacing: -0.01em;
    color: var(--tg-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* دکمه‌های دایره‌ای به سبک Gemini */
.ai-header-btn {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: var(--surface);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
    flex-shrink: 0;
}

.ai-header-btn:hover {
    background: var(--surface-hover);
}

.ai-header-btn:active {
    transform: scale(0.92);
    background: var(--surface-active);
}

.ai-model-badge {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 2px 10px;
    background: var(--accent-soft);
    color: var(--accent);
    border: none;
    border-radius: 20px;
    font-family: inherit;
    font-size: 0.7rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s var(--ease);
}

.ai-model-badge:hover {
    background: var(--accent-glow);
}

.ai-model-badge svg {
    transition: transform 0.2s var(--ease);
}

.ai-model-badge:active svg {
    transform: rotate(180deg);
}

/* ═══════════ سایدبار مکالمات (fixed — روی کل صفحه) ═══════════ */
.ai-sidebar {
    position: fixed;
    top: 0;
    right: -300px;
    width: 280px;
    height: 100%;
    background: var(--tg-secondary-bg);
    border-left: 1px solid var(--border);
    z-index: 200;
    transition: right 0.3s var(--ease);
    display: flex;
    flex-direction: column;
}

.ai-sidebar.open {
    right: 0;
}

.ai-sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px;
    border-bottom: 1px solid var(--border);
}

.ai-sidebar-header h2 {
    font-size: 1.1rem;
    font-weight: 700;
}

.ai-conversation-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.ai-conversation-list::-webkit-scrollbar {
    width: 4px;
}

.ai-conversation-list::-webkit-scrollbar-thumb {
    background: var(--border-strong);
    border-radius: 4px;
}

.ai-conv-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.2s var(--ease);
    margin-bottom: 4px;
}

.ai-conv-item:hover {
    background: var(--surface-hover);
}

.ai-conv-item.active {
    background: var(--accent-soft);
    border: 1px solid var(--accent-glow);
}

.ai-conv-item-content {
    flex: 1;
    min-width: 0;
}

.ai-conv-item-title {
    font-size: 0.85rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ai-conv-item-preview {
    font-size: 0.75rem;
    color: var(--tg-hint);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 2px;
}

.ai-conv-item-delete {
    opacity: 0;
    transition: opacity 0.2s;
    color: var(--error);
}

.ai-conv-item:hover .ai-conv-item-delete {
    opacity: 1;
}

.ai-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s var(--ease);
    z-index: 150;
}

.ai-overlay.visible {
    opacity: 1;
    visibility: visible;
}

/* ═══════════ شیت انتخاب مدل ═══════════ */
.ai-bottom-sheet {
    position: absolute;
    top: calc(var(--header-height) + 8px);
    left: 12px;
    /* پیش‌فرض LTR: زیر دکمه‌ی مدل (سمت چپ) */
    right: auto;
    width: min(320px, calc(100% - 24px));
    background: var(--tg-secondary-bg);
    border: 1px solid var(--border);
    border-radius: 24px;
    padding: 8px;
    z-index: 300;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
    max-height: 70vh;
    overflow-y: auto;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px) scale(0.96);
    transform-origin: top left;
    transition: opacity 0.2s var(--ease), transform 0.22s var(--ease-bounce), visibility 0.2s;
}

.ai-bottom-sheet.open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}

.ai-bottom-sheet::-webkit-scrollbar {
    width: 4px;
}

.ai-bottom-sheet::-webkit-scrollbar-thumb {
    background: var(--border-strong);
    border-radius: 4px;
}

/* دستگیره و عنوان بزرگ در popover معنا ندارند */
.ai-sheet-handle {
    display: none;
}

.ai-bottom-sheet h3 {
    display: none;
}

.model-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

/* ردیف مدل به سبک Gemini */
.ai-model-option {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 12px 14px;
    background: transparent;
    border: none;
    border-radius: 16px;
    cursor: pointer;
    text-align: start;
    font-family: inherit;
    color: var(--tg-text);
    transition: background 0.15s var(--ease);
    -webkit-tap-highlight-color: transparent;
}

.ai-model-option:hover {
    background: var(--surface-hover);
}

.ai-model-option:active {
    background: var(--surface-active);
}

/* تیک — فقط کنار مدل فعال دیده می‌شود */
.ai-model-check {
    flex-shrink: 0;
    width: 18px;
    height: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--accent);
    font-size: 1rem;
    font-weight: 700;
    opacity: 0;
    transition: opacity 0.15s var(--ease);
}

.ai-model-option.selected .ai-model-check {
    opacity: 1;
}

.ai-model-option-text {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.ai-model-option-name {
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--tg-text);
    line-height: 1.3;
}

.ai-model-option-desc {
    font-size: 0.78rem;
    color: var(--tg-hint);
    line-height: 1.3;
}

.ai-model-option-desc.free {
    color: var(--success);
    font-weight: 600;
}

/* ═══════════ ناحیه چت (flex child، نه fixed) ═══════════ */
.ai-chat-area {
    position: relative;
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    scroll-behavior: smooth;
    z-index: 1;
}

.ai-chat-area::-webkit-scrollbar {
    width: 4px;
}

.ai-chat-area::-webkit-scrollbar-track {
    background: transparent;
}

.ai-chat-area::-webkit-scrollbar-thumb {
    background: var(--border-strong);
    border-radius: 4px;
}

.ai-messages {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 16px;
    max-width: 800px;
    margin: 0 auto;
    min-height: 100%;
}

.ai-messages:empty {
    padding: 0;
    min-height: 0;
}

/* ─── حباب پیام ─── */
.ai-message {
    display: flex;
    flex-direction: column;
    max-width: 85%;
    animation: aiMessageIn 0.3s var(--ease-bounce);
}

@keyframes aiMessageIn {
    from {
        opacity: 0;
        transform: translateY(12px) scale(0.97);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.ai-message.user {
    align-self: flex-start;
    align-items: flex-start;
}

.ai-message.assistant {
    align-self: flex-end;
    align-items: flex-end;
}

.ai-message-bubble {
    padding: 12px 16px;
    border-radius: var(--radius);
    font-size: 0.9rem;
    line-height: 1.7;
    word-wrap: break-word;
    word-break: break-word;
    overflow-wrap: break-word;
    max-width: 100%;
    box-sizing: border-box;
    position: relative;
}

.ai-message.user .ai-message-bubble {
    background: var(--user-bubble);
    color: var(--user-text);
    border-bottom-right-radius: 6px;
    box-shadow: var(--shadow-sm);
}

.ai-message.assistant .ai-message-bubble {
    background: var(--assistant-bubble);
    color: var(--assistant-text);
    border: 1px solid var(--border);
    border-bottom-left-radius: 6px;
}

/* ─── اکشن‌های پیام ─── */
.ai-message-actions {
    display: flex;
    gap: 4px;
    margin-top: 6px;
    opacity: 0;
    transition: opacity 0.2s;
}

.ai-message:hover .ai-message-actions {
    opacity: 1;
}

.ai-msg-action-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border: none;
    background: var(--surface);
    color: var(--tg-hint);
    border-radius: var(--radius-xs);
    cursor: pointer;
    font-size: 0.75rem;
    transition: all 0.2s;
}

.ai-msg-action-btn:hover {
    background: var(--surface-hover);
    color: var(--tg-text);
}

.ai-msg-action-btn:active {
    transform: scale(0.9);
}

/* ─── مارک‌داون و کد ─── */
.ai-message-bubble p {
    margin-bottom: 8px;
}

.ai-message-bubble p:last-child {
    margin-bottom: 0;
}

.ai-message-bubble ul,
.ai-message-bubble ol {
    padding-inline-start: 20px;
    margin-bottom: 8px;
}

.ai-message-bubble li {
    margin-bottom: 4px;
}

.ai-message-bubble strong {
    font-weight: 700;
    color: var(--accent);
}

.ai-message-bubble a {
    color: var(--tg-link);
    text-decoration: none;
}

.ai-message-bubble a:hover {
    text-decoration: underline;
}

.ai-message-bubble pre {
    background: #0d1117;
    border-radius: var(--radius-sm);
    margin: 10px 0;
    overflow-x: auto !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
    border: 1px solid var(--border);
}

.ai-code-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    background: rgba(255, 255, 255, 0.05);
    border-bottom: 1px solid var(--border);
    font-size: 0.7rem;
    color: var(--tg-hint);
    font-family: var(--font-mono);
}

.ai-copy-code {
    padding: 3px 10px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--tg-text);
    font-family: inherit;
    font-size: 0.7rem;
    cursor: pointer;
    transition: all 0.2s;
}

.ai-copy-code:hover {
    background: var(--surface-hover);
}

.ai-message-bubble pre code {
    display: block;
    padding: 12px;
    overflow-x: auto !important;
    white-space: pre-wrap !important;
    word-break: break-word !important;
    word-wrap: break-word !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
    font-family: var(--font-mono);
    font-size: 0.8rem;
    line-height: 1.5;
    direction: ltr;
    text-align: left;
}

.ai-message-bubble code:not(pre code) {
    background: var(--surface);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: var(--font-mono);
    font-size: 0.85em;
    direction: ltr;
    unicode-bidi: embed;
}

/* ─── نشانگر تایپ ─── */
.ai-typing {
    display: flex;
    gap: 4px;
    padding: 12px 16px;
    align-self: flex-end;
}

.ai-typing span {
    width: 8px;
    height: 8px;
    background: var(--accent);
    border-radius: 50%;
    animation: aiTypingBounce 1.4s infinite ease-in-out;
}

.ai-typing span:nth-child(2) {
    animation-delay: 0.2s;
}

.ai-typing span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes aiTypingBounce {

    0%,
    80%,
    100% {
        transform: scale(0.6);
        opacity: 0.4;
    }

    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* ─── دکمه اسکرول به پایین (داخل کانتینر) ─── */
.ai-scroll-btn {
    position: absolute;
    bottom: 88px;
    right: 20px;
    left: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    background: var(--surface);
    color: var(--tg-text);
    border: 1px solid var(--border);
    border-radius: 50%;
    cursor: pointer;
    box-shadow: var(--shadow-md);
    transition: all 0.3s var(--ease-bounce);
    z-index: 50;
}

body[dir="rtl"] .ai-scroll-btn {
    right: 20px;
    left: auto;
}

body[dir="ltr"] .ai-scroll-btn {
    left: 20px;
    right: auto;
}

.ai-scroll-btn:hover {
    background: var(--surface-hover);
    color: var(--accent);
    transform: scale(1.1);
}

.ai-scroll-btn.hidden {
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px);
}

/* ═══════════ حالت خالی (داخل ناحیه چت) ═══════════ */
.ai-empty-state {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 32px 24px;
    text-align: center;
    z-index: 2;
    min-height: calc(100dvh - 380px);
}

.ai-empty-icon {
    font-size: 3rem;
    margin-bottom: 16px;
    animation: aiFloat 3s ease-in-out infinite;
}

@keyframes aiFloat {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-10px);
    }
}

.ai-empty-state h2 {
    font-size: 1.3rem;
    font-weight: 700;
    margin-bottom: 8px;
}

.ai-empty-state p {
    color: var(--tg-hint);
    font-size: 0.9rem;
    margin-bottom: 24px;
}

#plan-ai-container .suggestions {
    display: flex;
    justify-content: center;
    gap: 10px;
    max-width: 400px;
    width: 100%;
}

#plan-ai-container .suggestion {
    padding: 14px 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--tg-text);
    font-family: inherit;
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.2s var(--ease);
    text-align: center;
}

#plan-ai-container .suggestion:hover {
    background: var(--surface-hover);
    border-color: var(--accent);
    transform: translateY(-2px);
}

#plan-ai-container .suggestion:active {
    transform: scale(0.97);
}

#plan-ai-container .ai-edit-plan-btn {
    background: linear-gradient(135deg, #7c3aed 0%, #a855f7 100%);
    border: 1px solid rgba(168, 85, 247, 0.4);
    color: #ffffff;
    font-size: 0.9rem;
    font-weight: 600;
    padding: 16px 32px;
    border-radius: var(--radius-sm);
    box-shadow: 0 4px 15px rgba(124, 58, 237, 0.3);
}

#plan-ai-container .ai-edit-plan-btn:hover {
    background: linear-gradient(135deg, #6d28d9 0%, #9333ea 100%);
    border-color: rgba(147, 51, 234, 0.6);
    transform: translateY(-3px);
    box-shadow: 0 6px 20px rgba(124, 58, 237, 0.45);
}

/* ─── چیپ ابزار فعال (سبک جمنای) ─── */
.ai-active-tool-chip {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0 auto 8px auto;
    max-width: 800px;
    padding: 6px 14px;
    background: rgba(30, 41, 59, 0.85);
    border: 1px solid rgba(148, 163, 184, 0.3);
    border-radius: 20px;
    font-size: 0.82rem;
    color: #e2e8f0;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    animation: chipFadeIn 0.25s var(--ease);
}

@keyframes chipFadeIn {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

.ai-active-tool-chip.hidden {
    display: none !important;
}

.ai-tool-chip-icon {
    font-size: 0.95rem;
}

.ai-tool-chip-label {
    font-weight: 600;
}

.ai-tool-chip-remove {
    background: transparent;
    border: none;
    color: #94a3b8;
    cursor: pointer;
    font-size: 0.85rem;
    padding: 0 4px;
    margin-inline-start: 4px;
    border-radius: 50%;
    transition: all 0.15s;
}

.ai-tool-chip-remove:hover {
    color: #ef4444;
    background: rgba(239, 68, 68, 0.15);
}

/* ─── باکس راهنمای ابزارها (کادر وسط چت) ─── */
.ai-tool-guide-card {
    max-width: 480px;
    width: 90%;
    margin: 16px auto;
    padding: 16px 20px;
    background: rgba(30, 41, 59, 0.75);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 20px;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
    text-align: center;
    animation: chipFadeIn 0.3s var(--ease);
}

.ai-tool-guide-header {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-size: 0.98rem;
    font-weight: 700;
    color: var(--tg-text, #f8fafc);
    margin-bottom: 10px;
}

.ai-tool-guide-icon {
    font-size: 1.2rem;
}

.ai-tool-guide-body {
    font-size: 0.82rem;
    line-height: 1.6;
    color: var(--tg-hint, #cbd5e1);
}

.ai-tool-guide-examples {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 10px;
    text-align: start;
    background: rgba(15, 23, 42, 0.45);
    padding: 10px 14px;
    border-radius: 14px;
    border: 1px solid rgba(255, 255, 255, 0.06);
}

.ai-tool-guide-example-item {
    display: flex;
    align-items: center;
    gap: 6px;
    color: #e2e8f0;
    font-size: 0.8rem;
}

/* ─── اطلاعیه کسر سکه در چت ─── */
.ai-coin-deduction-notice {
    display: flex;
    justify-content: center;
    margin: 12px auto;
    max-width: 420px;
    width: 90%;
    animation: chipFadeIn 0.3s var(--ease);
}

.ai-coin-deduction-content {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    background: rgba(245, 158, 11, 0.12);
    border: 1px solid rgba(245, 158, 11, 0.3);
    border-radius: 20px;
    color: #fef3c7;
    font-size: 0.82rem;
    font-weight: 600;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    box-shadow: 0 4px 14px rgba(245, 158, 11, 0.15);
}

.ai-coin-icon {
    font-size: 1rem;
}

/* ─── کارت اخطار کمبود سکه ─── */
.ai-insufficient-coins-notice {
    max-width: 440px;
    width: 90%;
    margin: 16px auto;
    padding: 16px 20px;
    background: rgba(239, 68, 68, 0.12);
    border: 1px solid rgba(239, 68, 68, 0.3);
    border-radius: 20px;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    text-align: center;
    box-shadow: 0 8px 24px rgba(239, 68, 68, 0.15);
    animation: chipFadeIn 0.3s var(--ease);
}

.ai-insufficient-title {
    font-size: 0.95rem;
    font-weight: 700;
    color: #fca5a5;
    margin-bottom: 6px;
}

.ai-insufficient-desc {
    font-size: 0.82rem;
    color: #fecdd3;
    line-height: 1.5;
    margin-bottom: 12px;
}

.ai-recharge-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    background: linear-gradient(135deg, #ef4444, #dc2626);
    color: #ffffff;
    border: none;
    padding: 8px 18px;
    border-radius: 12px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.3);
    transition: all 0.2s var(--ease);
}

.ai-recharge-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(239, 68, 68, 0.4);
}

/* ─── دکمه + ابزارها ─── */
.ai-tools-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border: none;
    background: transparent;
    color: var(--tg-hint, #94a3b8);
    border-radius: 50%;
    cursor: pointer;
    flex-shrink: 0;
    align-self: center;
    transition: all 0.2s var(--ease);
}

.ai-tools-btn:hover {
    background: var(--surface-hover);
    color: var(--accent);
    transform: scale(1.08);
}

.ai-tools-btn:active {
    transform: scale(0.92);
}

/* ─── کشوی ابزارهای هوشمند (Gemini Bottom Sheet) ─── */
.ai-tools-drawer-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 100;
    opacity: 1;
    transition: opacity 0.3s var(--ease);
}

.ai-tools-drawer-backdrop.hidden {
    opacity: 0;
    pointer-events: none;
}

.ai-tools-sheet {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(15, 23, 42, 0.96);
    border-top: 1px solid var(--border);
    border-radius: 24px 24px 0 0;
    padding: 16px 20px 24px 20px;
    z-index: 101;
    box-shadow: 0 -10px 30px rgba(0, 0, 0, 0.4);
    transform: translateY(0);
    transition: transform 0.3s var(--ease-bounce);
}

.ai-tools-sheet.hidden {
    transform: translateY(100%);
    pointer-events: none;
}

.ai-tools-sheet-header {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    margin-bottom: 16px;
}

.ai-tools-sheet-handle {
    width: 36px;
    height: 4px;
    background: rgba(148, 163, 184, 0.3);
    border-radius: 2px;
}

.ai-tools-sheet-title {
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--tg-text, #f8fafc);
}

.ai-tools-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}

@media (max-width: 480px) {
    .ai-tools-grid {
        grid-template-columns: minmax(0, 1fr);
    }
}

.ai-tool-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    cursor: pointer;
    text-align: start;
    transition: all 0.2s var(--ease);
    min-width: 0;
    width: 100%;
    box-sizing: border-box;
}

.ai-tool-item:hover {
    background: var(--surface-hover);
    border-color: var(--accent);
    transform: translateY(-2px);
}

.ai-tool-item:active {
    transform: scale(0.97);
}

.ai-tool-item-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: 12px;
    font-size: 1.1rem;
    flex-shrink: 0;
}

.ai-tool-item-icon.edit { background: rgba(124, 58, 237, 0.18); color: #a855f7; }
.ai-tool-item-icon.grocery { background: rgba(16, 185, 129, 0.18); color: #10b981; }
.ai-tool-item-icon.lactose { background: rgba(59, 130, 246, 0.18); color: #3b82f6; }
.ai-tool-item-icon.gluten { background: rgba(245, 158, 11, 0.18); color: #f59e0b; }

.ai-tool-item-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
    overflow: hidden;
    flex: 1;
    min-width: 0;
}

.ai-tool-item-name {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--tg-text, #f8fafc);
    line-height: 1.3;
    word-break: break-word;
    overflow-wrap: break-word;
}

.ai-tool-item-desc {
    font-size: 0.72rem;
    color: var(--tg-hint, #94a3b8);
    white-space: normal;
    line-height: 1.3;
    word-break: break-word;
    overflow-wrap: break-word;
}

/* ═══════════ ناحیه ورودی (فیلد شناور پین‌شده) ═══════════ */
.ai-input-area {
    position: relative;
    flex: 0 0 auto;
    padding: 6px 10px 10px 10px;
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
    z-index: 10;
}

.ai-input-wrapper {
    display: flex;
    align-items: center;
    gap: 10px;
    max-width: 800px;
    margin: 0 auto;
    background: rgba(30, 41, 59, 0.95) !important;
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid rgba(255, 255, 255, 0.12) !important;
    border-radius: 28px !important;
    padding: 6px 10px;
    box-shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
    transition: all 0.2s var(--ease);
}

.ai-input-wrapper:focus-within {
    border-color: var(--accent) !important;
    box-shadow: 0 0 0 3px var(--accent-glow), 0 8px 28px rgba(0, 0, 0, 0.5);
}

/* غلبه بر استایل سراسری textarea در styles.css */
#plan-ai-container .ai-textarea {
    flex: 1;
    border: none !important;
    background: transparent !important;
    box-shadow: none !important;
    color: var(--tg-text) !important;
    font-family: inherit;
    font-size: 0.9rem !important;
    font-weight: 400 !important;
    line-height: 1.5;
    resize: none;
    outline: none !important;
    max-height: 120px;
    min-height: 36px;
    padding: 6px 2px !important;
    border-radius: 0 !important;
    width: auto;
}

#plan-ai-container .ai-textarea::placeholder {
    color: var(--tg-hint);
}

.ai-send-btn,
.ai-stop-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.2s var(--ease);
    flex-shrink: 0;
}

.ai-send-btn {
    background: var(--accent);
    color: white;
}

.ai-send-btn:hover {
    background: var(--accent-hover);
    transform: scale(1.05);
}

.ai-send-btn:active {
    transform: scale(0.92);
}

.ai-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.ai-stop-btn {
    background: var(--error);
    color: white;
}

.ai-stop-btn:hover {
    filter: brightness(1.1);
}

#ai-typing {
    position: absolute;
    top: -26px;
    right: 20px;
}

/* ═══════════ اعلان (Toast) ═══════════ */
.ai-toast {
    position: fixed;
    top: calc(var(--header-height) + 12px);
    left: 50%;
    transform: translateX(-50%) translateY(-20px);
    padding: 10px 20px;
    background: var(--tg-secondary-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    font-weight: 500;
    box-shadow: var(--shadow-md);
    z-index: 500;
    opacity: 0;
    transition: all 0.3s var(--ease-bounce);
}

.ai-toast.visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.ai-toast.error {
    border-color: var(--error);
    color: var(--error);
}

.ai-toast.success {
    border-color: var(--success);
    color: var(--success);
}

.hidden {
    display: none !important;
}

@media (prefers-reduced-motion: reduce) {

    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}

@media (min-width: 768px) {
    .ai-message {
        max-width: 70%;
    }
}

/* ═══════════════════════════════════════════════════════════
   جهت‌گیری فیزیکی ثابت — مستقل از زبان رابط
   • کاربر همیشه راست، دستیار همیشه چپ، ارسال همیشه راست
   • همبرگری و سایدبار همیشه مخالف ریل ناوبری
   • متن حباب‌ها و ورودی تابع زبان صفحه (body[dir])
   ═══════════════════════════════════════════════════════════ */

/* ── ۱) محتوای چت: چیدمان فیزیکی ثابت ── */
.ai-messages {
    direction: ltr;
}

/* محور cross را فیزیکی می‌کند */
.ai-message.user {
    align-self: flex-end;
    align-items: flex-end;
}

/* همیشه راست */
.ai-message.assistant {
    align-self: flex-start;
    align-items: flex-start;
}

/* همیشه چپ  */

/* ── ) ناحیه ورودی: دکمه ارسال همیشه راست ── */
.ai-input-wrapper {
    direction: ltr;
}



/* ── ۴) نشانگر تایپ همیشه سمت دستیار (چپ فیزیکی) ── */
#ai-typing {
    left: 20px;
    right: auto;
}

/* ── ۵) متن حباب‌ها و ورودی تابع زبان صفحه ── */
body[dir="rtl"] .ai-message-bubble {
    direction: rtl;
    text-align: right;
}

body[dir="ltr"] .ai-message-bubble {
    direction: ltr;
    text-align: left;
}

body[dir="rtl"] #plan-ai-container .ai-textarea {
    direction: rtl;
    text-align: right;
}

body[dir="ltr"] #plan-ai-container .ai-textarea {
    direction: ltr;
    text-align: left;
}

body[dir="rtl"] .ai-empty-state {
    direction: rtl;
}

body[dir="ltr"] .ai-empty-state {
    direction: ltr;
}

/* بلوک‌های کد همیشه LTR (با specificity بالاتر برای غلبه بر قانون بالا) */
body[dir="rtl"] .ai-message-bubble pre code,
body[dir="rtl"] .ai-message-bubble code:not(pre code) {
    direction: ltr;
    text-align: left;
    white-space: pre-wrap !important;
    word-break: break-word !important;
    word-wrap: break-word !important;
}

/* ── ۶) سایدبار چت: فیزیکی بر اساس dir ── */
body[dir="ltr"] .ai-sidebar {
    right: -300px;
    left: auto;
}

body[dir="ltr"] .ai-sidebar.open {
    right: 0;
    left: auto;
}

body[dir="rtl"] .ai-sidebar {
    left: -300px;
    right: auto;
    border-left: none;
    border-right: 1px solid var(--border);
}

body[dir="rtl"] .ai-sidebar.open {
    left: 0;
    right: auto;
}

/* ── ۸) نشانگر تایپ: داخل حباب دستیار، نه پایین صفحه ── */
/* المان مطلق قدیمی (لبه‌ی پایین) برای همیشه مخفی */
#ai-typing {
    display: none !important;
}

/* سه نقطه‌ی تایپ داخل حباب پاسخ */
.ai-typing-dots {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 2px 0;
    direction: ltr;
    /* موج انیمیشن همیشه چپ→راست */
}

.ai-typing-dots span {
    width: 8px;
    height: 8px;
    background: var(--accent);
    border-radius: 50%;
    animation: aiTypingBounce 1.4s infinite ease-in-out;
}

.ai-typing-dots span:nth-child(2) {
    animation-delay: 0.2s;
}

.ai-typing-dots span:nth-child(3) {
    animation-delay: 0.4s;
}

/* حبابِ در‌حال‌تایپ کمی جمع‌وجورتر */
.ai-message-bubble.ai-bubble-typing {
    padding: 14px 18px;
}

/* ── ۷) popover مدل در RTL از سمت راست (زیر دکمه‌ی مدل) باز شود ── */
body[dir="rtl"] .ai-bottom-sheet {
    right: 12px;
    left: auto;
    transform-origin: top right;
}

/* ═══════════════════════════════════════════════════════════
   حالت چت‌بات نیتیو در تب هوش مصنوعی (Native Chatbot Mode)
   • منوی ناوبری پایین در موبایل/تبلت پنهان می‌شود و ورودی چت کاملاً پایین پین می‌ماند.
   • در دسکتاپ منوی کناری حفظ شده و ورودی چت به پایین صفحه پین می‌شود بدون تداخل با منوی کناری.
   ═══════════════════════════════════════════════════════════ */

body.ai-tab-active main#main-container {
    padding-bottom: 0 !important;
    height: 100dvh !important;
    max-height: 100dvh !important;
    overflow: hidden !important;
    display: flex !important;
    flex-direction: column !important;
}

body.ai-tab-active #view-plans {
    padding-bottom: 0 !important;
    height: 100% !important;
    max-height: 100% !important;
    overflow: hidden !important;
    display: flex !important;
    flex-direction: column !important;
}

body.ai-tab-active #plan-content {
    flex: 1 1 auto !important;
    display: flex !important;
    flex-direction: column !important;
    height: 100% !important;
    min-height: 0 !important;
    overflow: hidden !important;
}

body.ai-tab-active #plan-program-tabs,
body.ai-tab-active #plan-day-tabs {
    flex-shrink: 0 !important;
}

body.ai-tab-active #plan-ai-container {
    flex: 1 1 auto !important;
    display: flex !important;
    flex-direction: column !important;
    height: 100% !important;
    min-height: 0 !important;
    max-height: none !important;
    border-radius: 18px 18px 0 0 !important;
    border-bottom: none !important;
    margin-bottom: 0 !important;
    box-shadow: none !important;
    overflow: hidden !important;
}

body.ai-tab-active #plan-ai-container .ai-chat-area {
    flex: 1 1 auto !important;
    overflow-y: auto !important;
    min-height: 0 !important;
    padding-bottom: 12px !important;
}

body.ai-tab-active #plan-ai-container .ai-input-area {
    position: sticky !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    flex-shrink: 0 !important;
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
    z-index: 40 !important;
}

/* ── ۱. فقط موبایل (< 768px) ── */
@media (max-width: 767.98px) {
    body.ai-tab-active main#main-container {
        padding-top: 3px !important;
    }

    body.ai-tab-active nav {
        display: none !important;
    }

    body.ai-tab-active #hamburger-menu-overlay {
        display: none !important;
    }

    /* پنهان کردن کپسول بالای برنامه‌ها در تب چت‌بات فقط در موبایل */
    body.ai-tab-active #plan-program-tabs {
        display: none !important;
    }

    /* تنظیم فاصله‌های بالای صفحه به ۳ پیکسل در تب چت‌بات در موبایل */
    body.ai-tab-active #view-plans {
        padding-top: 0 !important;
        padding-bottom: 0 !important;
        margin-top: 0 !important;
        overflow: hidden !important;
    }

    body.ai-tab-active #plan-content,
    body.ai-tab-active #plan-content > *:not(.hidden) ~ *:not(.hidden) {
        margin-top: 0 !important;
    }

    /* فشرده‌سازی و بهینه‌سازی ارتفاع کپسول تب‌ها فقط در تب چت‌بات در موبایل */
    body.ai-tab-active #plan-day-tabs {
        margin-top: 0 !important;
        margin-bottom: 4px !important;
        padding: 3px 4px !important;
        border-radius: 14px !important;
        flex-shrink: 0 !important;
    }

    body.ai-tab-active #plan-day-tabs button {
        padding: 4px 10px !important;
        font-size: 11px !important;
        border-radius: 10px !important;
        line-height: 1.2 !important;
    }

    body.ai-tab-active #plan-ai-container .ai-input-area {
        padding-bottom: max(10px, env(safe-area-inset-bottom)) !important;
    }
}

/* ── ۲. دسکتاپ (≥ 1024px) ── */
@media (min-width: 1024px) {
    /* حفظ منوی ناوبری کناری در دسکتاپ */
    body.ai-tab-active nav {
        display: flex !important;
    }

    body.ai-tab-active #view-plans {
        max-width: 940px !important;
        margin-left: auto !important;
        margin-right: auto !important;
        padding-top: 0 !important;
    }

    body.ai-tab-active #plan-ai-container .ai-input-area {
        padding-bottom: 12px !important;
        border-radius: 0 0 18px 18px !important;
    }
}