/* ======================================================
   VARIABLES & RESET
====================================================== */
:root {
    --primary-color: #2c7be5;
    --success-color: #28a745;
    --danger-color: #dc3545;
    --secondary-color: #6c757d;
    --dark-bg: #111;
    --light-bg: #f8fafc;
    --card-bg: #ffffff;
    --border-color: #e2e8f0;
    --text-color: #0f172a;
    --transition-speed: .3s;
}

*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
    width: 100%;
    min-height: 100%;
}

body {
    display: flex;
    flex-direction: column;
    width: 100%;
    min-height: 100vh;
    font-family: 'Vazirmatn', Tahoma, Arial, sans-serif;
    font-size: 16px;
    line-height: 1.6;
    color: var(--text-color);
    background: var(--light-bg);
    overflow-x: hidden;
}

main {
    flex: 1;
}

img {
    display: block;
    max-width: 100%;
    height: auto;
}

a {
    text-decoration: none;
    color: inherit;
    transition: var(--transition-speed);
}

ul {
    list-style: none;
}

button,
input,
textarea,
select {
    font: inherit;
    outline: none;
}

.container {
    width: 90%;
    max-width: 1400px;
    margin: auto;
}

/* ======================================================
   NAVBAR
====================================================== */
.navbar {
    background: var(--dark-bg);
    color: #fff;
    padding: 14px 0;
    position: sticky;
    top: 0;
    z-index: 1000;
}

.navbar .container {
    display: flex;
    align-items: center;
    gap: 20px;
    position: relative;
}

.logo {
    margin-left: 0;
    font-size: 24px;
    font-weight: 700;
    color: #fff;
    transition: var(--transition-speed);
}

.logo:hover,
.menu-toggle:hover,
.nav-links a:hover,
.nav-item:hover,
.nav_sabad:hover {
    color: var(--success-color);
}

.logo:hover,
.nav_sabad:hover,
.nav-ai:hover,
.btn:hover {
    transform: translateY(-2px);
}

.menu-toggle {
    margin-right: auto;
    background: none;
    border: none;
    color: #fff;
    cursor: pointer;
    font-size: 30px;
    transition: var(--transition-speed);
}

.nav-links {
    display: none;
    flex-direction: column;
    position: absolute;
    left: 0;
    top: 100%;
    min-width: 220px;
    padding: 15px;
    background: #222;
    border-radius: 0 0 12px 12px;
    box-shadow: 0 10px 20px rgba(0, 0, 0, .2);
}

.nav-links.active {
    display: flex;
}

.nav-links a,
.nav-item {
    color: #fff;
    padding: 10px 0;
    transition: var(--transition-speed);
}

.user-badge {
    background: #333;
    color: #00ff66;
    padding: 7px 14px;
    border-radius: 30px;
    font-size: 13px;
    font-weight: bold;
}

.nav_sabad {
    margin-right: auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 16px;
    background: #000;
    color: #fff;
    border-radius: 12px;
    font-weight: bold;
    box-shadow: 0 4px 12px rgba(0, 0, 0, .2);
    transition: var(--transition-speed);
}

.nav-ai {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 7px 11px;
    border-radius: 8px;
    color: #fff;
    font-size: 10px;
    font-weight: 600;
    transition: all 0.2s ease;
}

.nav-ai:hover {
    background: var(--success-color);
}

/* ======================================================
   BUTTONS
====================================================== */
.btn {
    display: inline-flex;
    justify-content: center;
    align-items: center;
    padding: 10px 18px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    color: #fff;
    font-size: 14px;
    font-weight: 600;
    transition: var(--transition-speed);
}

.btn:hover {
    opacity: .9;
}

.primary, .login { background: var(--primary-color); }
.success, .register, .add { background: var(--success-color); }
.danger, .logout, .remove { background: var(--danger-color); }
.secondary, .back { background: var(--secondary-color); }

/* ======================================================
   PRODUCTS
====================================================== */
.grid {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 20px;
    margin-top: 20px;
}

.card {
    background: var(--card-bg);
    border-radius: 14px;
    overflow: hidden;
    box-shadow: 0 5px 15px rgba(0, 0, 0, .08);
    transition: var(--transition-speed);
    display: flex;
    flex-direction: column;
    padding: 15px;
}

.card:hover {
    transform: translateY(-5px);
    box-shadow: 0 10px 25px rgba(0, 0, 0, .15);
}

.product-img {
    width: 100%;
    height: 220px;
    object-fit: cover;
    border-radius: 10px;
    margin-bottom: 12px;
}

.card h3 {
    font-size: 18px;
    margin-bottom: 8px;
    color: #111827;
}

.card p {
    color: #1f2937;
    line-height: 1.7;
    flex: 1;
}

.price {
    margin-top: 12px;
    color: var(--primary-color);
    font-size: 20px;
    font-weight: bold;
}

.actions {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    margin-top: 15px;
}

/* ======================================================
   FORMS & AUTH
====================================================== */
.form-container,
.auth-container,
.profile-container {
    display: flex;
    justify-content: center;
    padding: 30px 0;
}

.auth-container {
    align-items: center;
    min-height: 80vh;
    padding: 30px 15px;
}

.form-container {
    align-items: flex-start;
}

.form-card,
.auth-box,
.profile-card {
    width: 100%;
    background: var(--card-bg);
    padding: 30px;
    border-radius: 16px;
    box-shadow: 0 6px 20px rgba(0, 0, 0, .08);
}

.form-card { max-width: 700px; }
.auth-box { max-width: 400px; }
.profile-card { max-width: 450px; padding: 25px; }

.form-title,
.auth-title {
    text-align: center;
    margin-bottom: 25px;
    color: #111827;
}

.form-fields p,
.form-group {
    margin-bottom: 18px;
}

.form-fields label,
.form-group label {
    display: block;
    margin-bottom: 6px;
    font-weight: 600;
    color: #111827;
}

.form-fields input,
.form-fields textarea,
.form-fields select,
.form-group input {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    transition: var(--transition-speed);
    background: var(--card-bg);
    color: #111827;
}

.form-fields textarea {
    resize: vertical;
    min-height: 120px;
}

.form-fields input:focus,
.form-fields textarea:focus,
.form-fields select:focus,
.form-group input:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(44, 123, 229, .15);
}

.form-errors,
.errorlist {
    color: #c00;
    margin-bottom: 15px;
}

/* ======================================================
   PROFILE
====================================================== */
.profile-avatar {
    width: 130px;
    height: 130px;
    object-fit: cover;
    border-radius: 50%;
    margin: 0 auto 20px;
    border: 4px solid var(--success-color);
}

.profile-card h2 {
    text-align: center;
    margin-bottom: 15px;
    color: #111827;
}

.profile-card p {
    margin-bottom: 10px;
    color: #1f2937;
    font-weight: 500;
}

.profile-card .btn {
    width: 100%;
    margin-top: 15px;
}

/* ======================================================
   CART & ORDERS
====================================================== */
.cart-card,
.order-card,
.cart-summary {
    background: var(--card-bg);
    padding: 20px;
    margin-bottom: 20px;
    border-radius: 14px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, .08);
    color: #111827;
}

.cart-card {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 20px;
}

.cart-image {
    width: 120px;
    height: 120px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 5px;
    background: #f8f8f8;
    border: 1px solid #eee;
    border-radius: 10px;
    overflow: hidden;
}

.cart-image img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.cart-info { flex: 1; }

.cart-actions,
.order-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.order-actions { margin-top: 15px; }

.cart-summary {
    padding: 25px;
    margin-top: 20px;
    text-align: center;
}

.cart-summary h3 { margin-bottom: 15px; color: #111827; }
.cart-summary p { margin-bottom: 10px; font-size: 17px; color: #1f2937; font-weight: 600; }

.order-card h3 { 
    margin-bottom: 12px; 
    color: #111827; 
    font-size: 19px; 
    font-weight: 700; 
}

.order-card p,
.order-card span,
.order-card td,
.order-card div { 
    margin-bottom: 8px; 
    color: #1f2937;
    font-size: 15px; 
    font-weight: 600; 
}

.order-card strong {
    color: #000000;
    font-weight: 700;
}

/* ======================================================
   TABLES
====================================================== */
.table-wrapper {
    overflow-x: auto;
    width: 100%;
}

.table {
    width: 100%;
    border-collapse: collapse;
    background: var(--card-bg);
    border-radius: 12px;
    overflow: hidden;
}

.table th,
.table td {
    padding: 14px;
    text-align: center;
}

.table th {
    background: var(--dark-bg);
    color: #fff;
    font-weight: 700;
}

.table td {
    border-bottom: 1px solid #eee;
    color: #1f2937;
    font-weight: 500;
}

.table tr:hover {
    background: #fafafa;
}

.table-img {
    width: 65px;
    height: 65px;
    object-fit: cover;
    border-radius: 8px;
}

/* ======================================================
   SEARCH
====================================================== */
.search-form {
    width: 90%;
    max-width: 1400px;
    margin: 15px auto 0;
    display: flex;
    gap: 10px;
}

.search-form input {
    flex: 1;
    min-width: 220px;
    padding: 10px 14px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: #111827;
}

.search-form input:focus {
    border-color: var(--primary-color);
}

.search-form button {
    padding: 10px 18px;
    border: none;
    border-radius: 8px;
    background: #333;
    color: #fff;
    cursor: pointer;
    transition: var(--transition-speed);
}

.search-form button:hover {
    background: var(--success-color);
}

/* ======================================================
   CATEGORY MENU
====================================================== */
.category-menu {
    position: relative;
    display: inline-flex;
    align-items: center;
}

.category-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 6px 10px;
    background: transparent;
    border: none;
    border-radius: 6px;
    color: #fff;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s ease, color 0.2s ease;
}

.category-button:hover {
    background: var(--success-color);
    color: #fff;
}

#categoryArrow {
    font-size: 9px;
    color: #fff;
    transition: transform 0.2s ease;
}

.category-dropdown {
    display: none;
    position: absolute;
    top: calc(100% + 7px);
    right: 0;
    min-width: 190px;
    background: #fff;
    border: 1px solid #eee;
    border-radius: 10px;
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.12);
    overflow: hidden;
    z-index: 9999;
}

.category-dropdown.show {
    display: block;
}

.category-item {
    display: flex;
    align-items: center;
    width: 100%;
    padding: 10px 13px;
    background: #fff;
    color: #111827;
    font-size: 13px;
    font-weight: 500;
    transition: background 0.15s ease, color 0.15s ease, padding-right 0.15s ease;
}

.category-item:hover {
    background: var(--success-color);
    color: #fff;
    padding-right: 17px;
}

.category-empty {
    padding: 10px 13px;
    background: #fff;
    color: #4b5563;
    font-size: 12px;
    text-align: center;
}

/* ======================================================
   AI DESIGN & CHAT PAGES
====================================================== */
.ai-design-page,
.ai-result-page,
.ai-chat-page {
    max-width: 900px;
    margin: 40px auto;
    padding: 0 20px;
}

.ai-chat-page {
    max-width: 950px;
    margin: 25px auto;
    padding: 0 15px;
}

.ai-design-header,
.ai-result-title,
.ai-chat-header,
.ai-previous-header {
    text-align: center;
    margin-bottom: 30px;
}

.ai-chat-header {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 14px;
    margin-bottom: 20px;
}

.ai-design-header p,
.ai-chat-header p,
.ai-previous-header p {
    color: #374151;
    font-weight: 500;
}

.ai-design-card,
.ai-result-card,
.chat-card,
.ai-chat-box {
    background: var(--card-bg);
    padding: 30px;
    border-radius: 16px;
    box-shadow: 0 5px 25px rgba(0, 0, 0, 0.08);
}

.ai-chat-box,
.chat-card {
    padding: 0;
    overflow: hidden;
    border: 1px solid #e5e5e5;
}

.ai-form-group {
    margin-bottom: 22px;
}

.ai-form-group label {
    display: block;
    font-weight: bold;
    margin-bottom: 8px;
    color: #111827;
}

.ai-form-group input,
.ai-form-group select {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 15px;
    color: #111827;
}

.ai-form-group input[type="file"] {
    padding: 10px;
    background: #fafafa;
}

.ai-form-group small {
    display: block;
    margin-top: 7px;
    color: #4b5563;
    font-size: 13px;
}

.ai-design-submit,
.ai-edit-submit,
.ai-chat-send {
    width: 100%;
    padding: 14px;
    border: none;
    border-radius: 9px;
    background: #222;
    color: #fff;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition-speed);
}

.ai-design-submit:hover,
.ai-edit-submit:hover,
.ai-chat-send:hover {
    opacity: 0.9;
    background: #333;
}

.ai-chat-send:disabled {
    opacity: 0.6;
    cursor: wait;
}

.ai-design-free-box {
    max-width: 700px;
    margin: 0 auto 20px auto;
    padding: 16px 20px;
    border-radius: 14px;
    background: #f7f7f7;
    border: 1px solid #e5e5e5;
    display: flex;
    align-items: center;
    gap: 14px;
}

.free-icon { font-size: 30px; flex-shrink: 0; }
.free-info { display: flex; flex-direction: column; gap: 5px; }
.free-info strong { font-size: 17px; color: #111827; }
.free-info span { font-size: 13px; color: #374151; }

.ai-design-locked { text-align: center; padding: 45px 25px; }
.locked-icon { font-size: 55px; margin-bottom: 15px; }
.ai-design-locked p { color: #374151; line-height: 1.8; }

.ai-custom-prompt-group,
.ai-edit-box {
    margin-top: 28px;
}

.ai-edit-box {
    padding: 22px;
    background: #f8f8f8;
    border: 1px solid #e5e5e5;
    border-radius: 14px;
}

.ai-custom-prompt-group textarea,
.ai-edit-form textarea,
.ai-chat-form textarea {
    width: 100%;
    min-height: 130px;
    padding: 14px;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    font-size: 14px;
    line-height: 1.9;
    resize: vertical;
    color: #111827;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.ai-download-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    margin-top: 15px;
    padding: 13px 20px;
    background: #198754;
    color: #fff;
    border-radius: 10px;
    font-size: 15px;
    font-weight: 600;
}

/* Previous Grid */
.ai-previous-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 18px;
}

.ai-previous-card {
    background: var(--card-bg);
    border-radius: 14px;
    overflow: hidden;
    border: 1px solid #e5e5e5;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.06);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.ai-previous-image {
    width: 100%;
    height: 220px;
    object-fit: cover;
}

.ai-previous-info {
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    color: #111827;
}

.ai-previous-view {
    display: block;
    margin-top: 8px;
    padding: 9px;
    border-radius: 8px;
    background: #222;
    color: #fff;
    text-align: center;
    font-size: 13px;
}

/* ======================================================
   HAMBURGER BUTTON STYLES (دکمه ۳ خط)
====================================================== */
.mobile-sidebar-btn {
    display: none;
    flex-direction: column;
    justify-content: space-between;
    width: 38px;
    height: 38px;
    padding: 8px;
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.05);
    transition: all 0.2s ease;
}

.mobile-sidebar-btn:hover {
    background: #f8fafc;
    border-color: #cbd5e1;
}

.hamburger-line {
    display: block;
    width: 100%;
    height: 2.5px;
    background-color: #0f172a;
    border-radius: 4px;
    transition: all 0.3s ease;
}

/* ======================================================
   AI CHAT MESSAGES & CONTAINERS
====================================================== */
.ai-chat-container {
    width: 100%;
    max-width: 950px;
    margin: 15px auto;
    padding: 15px;
    background: var(--card-bg);
    border: 1px solid #e2e8f0;
    border-radius: 16px;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.06);
    display: flex;
    flex-direction: column;
    gap: 12px;
    direction: rtl;
}

.chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 24px;
    background-color: #ffffff;
    border-bottom: 1px solid #e2e8f0;
    gap: 10px;
}

.header-info h2 {
    margin: 0;
    font-size: 18px;
    color: #0f172a;
}

.status-indicator {
    font-size: 12px;
    color: #64748b;
}

.btn-clear-chat {
    background: transparent;
    color: #dc2626;
    border: 1px solid #fca5a5;
    padding: 6px 14px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}

.btn-clear-chat:hover {
    background: #dc2626;
    color: #ffffff;
}

#aiChatMessages,
.ai-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    background-color: #ffffff;
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    scroll-behavior: smooth;
    width: 100%;
}

.ai-message,
.ai-chat-message {
    display: flex;
    gap: 12px;
    align-items: flex-start;
    max-width: 80%;
    min-width: 0; /* جلوگیری از رشد و سرریز افقی عناصر چت */
}

.user-message,
.ai-chat-user {
    align-self: flex-start;
    flex-direction: row;
}

.assistant-message,
.ai-chat-assistant {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.message-avatar,
.ai-chat-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: #f1f5f9;
    border: 1px solid #cbd5e1;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.05);
}

.message-content,
.ai-chat-content {
    display: flex;
    flex-direction: column;
    max-width: 100%;
    min-width: 0; /* جلوگیری از سرریز فرزندی در flexbox */
    overflow: hidden;
}

.message-name {
    font-size: 12px;
    font-weight: 600;
    margin-bottom: 4px;
    color: #64748b;
}

.message-text,
.ai-chat-text,
.ai-chat-response {
    padding: 12px 16px;
    border-radius: 12px;
    font-size: 14.5px;
    line-height: 1.7;
    word-wrap: break-word;
    word-break: break-word;
    white-space: pre-wrap;
    background-color: #ffffff;
    color: #0f172a;
    border: 1px solid #e2e8f0;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.03);
    max-width: 100%;
    min-width: 0;
    overflow-x: auto; /* ایجاد اسکرول افقی محلی در صورت بروز سرریز غیرمنتظره */
}

.user-message .message-text,
.ai-chat-user .ai-chat-text {
    border-top-right-radius: 4px;
}

.assistant-message .message-text,
.ai-chat-assistant .ai-chat-response {
    border-top-left-radius: 4px;
}

.message-text strong, .message-text b {
    color: #000000;
    font-weight: 700;
}

.message-text a {
    color: #2563eb;
    text-decoration: underline;
}

/* Chat Input Form */
.chat-footer {
    padding: 16px 24px;
    background-color: #ffffff;
    border-top: 1px solid #e2e8f0;
}

.file-preview-container {
    padding: 0 24px 8px;
    font-size: 13px;
    color: #2563eb;
}

.chat-input-form,
.ai-chat-form {
    display: flex;
    align-items: center;
    gap: 10px;
    background: #f8fafc;
    border: 1px solid #cbd5e1;
    padding: 8px 14px;
    border-radius: 12px;
    width: 100%;
}

.btn-attach-file {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 18px;
    color: #64748b;
    flex-shrink: 0;
    transition: color 0.2s;
}

.btn-attach-file:hover {
    color: #0f172a;
}

#aiChatInput {
    flex: 1;
    width: 100%;
    min-width: 0;
    border: none;
    outline: none;
    padding: 8px 4px;
    font-size: 14.5px;
    background: transparent;
    color: #0f172a;
}

.btn-send-message {
    background-color: #007bff;
    color: white;
    border: none;
    padding: 10px 20px;
    font-size: 16px;
    cursor: pointer;
    border-radius: 5px;
    transition: background-color 0.3s;
}

.btn-send-message:hover {
    background-color: #0056b3;
}

/* ======================================================
   CODE BLOCK WRAPPER
====================================================== */
.code-block-wrapper {
    position: relative;
    margin: 12px 0;
    border-radius: 8px;
    overflow: hidden;
    background-color: #1e1e1e;
    direction: ltr;
    text-align: left;
    border: 1px solid #333333;
    width: 100%;
    max-width: 100%; /* جلوگیری از بزرگتر شدن از عرض مانیتور */
    box-sizing: border-box;
}

.code-block-wrapper .code-header,
.code-block-wrapper .code-block-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: #2d2d2d;
    padding: 6px 12px;
    font-family: monospace;
    font-size: 13px;
    color: #cccccc;
    border-bottom: 1px solid #3d3d3d;
    direction: ltr;
    flex-wrap: wrap;
    gap: 8px;
}

.code-block-wrapper .code-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

.code-block-wrapper .btn-copy-code, 
.code-block-wrapper .btn-download-code {
    background: #3a3d42;
    color: #ffffff;
    border: none;
    padding: 4px 10px;
    font-size: 12px;
    font-weight: 500;
    border-radius: 5px;
    cursor: pointer;
    line-height: 1.2;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    transition: background 0.2s ease;
}

.code-block-wrapper .btn-copy-code:hover, 
.code-block-wrapper .btn-download-code:hover {
    background: #4a4d52;
    color: #00ff66;
}

.code-block-wrapper pre {
    margin: 0;
    padding: 14px 16px;
    overflow-x: auto; /* ایجاد اسکرول افقی محلی به جای بیرون زدن از مانیتور */
    max-width: 100%;
    box-sizing: border-box;
    background: #1e1e1e;
    color: #d4d4d4;
    font-size: 13.5px;
    line-height: 1.6;
    font-family: 'Consolas', 'Courier New', monospace;
    white-space: pre;
    tab-size: 4;
}

.code-block-wrapper pre code {
    background: none;
    padding: 0;
    color: inherit;
    font-size: inherit;
    display: block;
}

.ai-text-part {
    white-space: pre-wrap;
    word-break: break-word;
    margin-bottom: 8px;
    line-height: 1.8;
}

/* ======================================================
   AI CHAT DASHBOARD LAYOUT & SIDEBAR STYLES
====================================================== */
.ai-chat-body {
    margin: 0;
    padding: 0;
    height: 100vh;
    overflow: hidden;
    background-color: #ffffff;
    font-family: 'Vazirmatn', Tahoma, Arial, sans-serif;
}

.ai-app-layout {
    display: flex;
    width: 100vw;
    height: 100vh;
    direction: rtl;
    overflow: hidden;
    background-color: #ffffff;
}

/* Sidebar Styles (Right Panel) */
.ai-sidebar {
    width: 280px;
    background-color: #f8fafc;
    border-left: 1px solid #e2e8f0;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    height: 100%;
}

.sidebar-header {
    padding: 16px;
    border-bottom: 1px solid #e2e8f0;
}

.btn-new-chat {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px;
    background-color: #2563eb;
    color: #ffffff;
    border: none;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s ease, transform 0.1s ease;
}

.btn-new-chat:hover {
    background-color: #1d4ed8;
    transform: translateY(-1px);
}

.conversations-list {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.list-title {
    font-size: 12px;
    color: #64748b;
    padding: 8px;
    font-weight: bold;
}

.no-conversations {
    color: #64748b;
    font-size: 13px;
    text-align: center;
    margin-top: 20px;
}

/* Conversation Items & Dropdown */
.conversation-item-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-radius: 8px;
    margin-bottom: 4px;
    transition: background 0.2s;
}

.conversation-item-wrapper:hover,
.conversation-item-wrapper.active {
    background-color: #e2e8f0;
}

.conversation-item-wrapper .conversation-item {
    display: flex;
    align-items: center;
    flex-grow: 1;
    padding: 10px;
    color: #1a1a1a;
    text-decoration: none;
    overflow: hidden;
    font-size: 13.5px;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.conversation-item-wrapper:hover .conversation-item,
.conversation-item-wrapper.active .conversation-item {
    color: #000000;
}

.conv-actions-dropdown {
    position: relative;
    padding-left: 6px;
}

.conversation-item-wrapper .btn-conv-options {
    background: transparent;
    border: none;
    color: #444444;
    font-size: 18px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
}

.conversation-item-wrapper .btn-conv-options:hover {
    color: #000000;
    background: rgba(0, 0, 0, 0.08);
}

.conv-options-menu {
    display: none;
    position: absolute;
    left: 0;
    top: 100%;
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 100;
    min-width: 120px;
    padding: 4px 0;
}

.conv-options-menu.show {
    display: block;
}

.btn-delete-conv {
    width: 100%;
    background: transparent;
    border: none;
    color: #dc3545;
    padding: 8px 12px;
    text-align: right;
    font-size: 13px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
}

.btn-delete-conv:hover {
    background: rgba(220, 53, 69, 0.1);
}

/* Chat Main Area (Left Panel) */
.ai-chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100%;
    background-color: #ffffff;
    position: relative;
    min-width: 0; /* جلوگیری از اسکرول غیرضروری کادر اصلی */
}

/* ======================================================
   FOOTER
====================================================== */
.site-footer {
    margin-top: 40px;
    background: var(--dark-bg);
    color: #fff;
}

.footer-container {
    width: 90%;
    max-width: 1400px;
    margin: auto;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 30px;
    padding: 40px 0;
}

.footer-box h3,
.footer-box h4 {
    color: var(--success-color);
    margin-bottom: 15px;
}

.footer-box p { color: #ccc; line-height: 1.8; }

.footer-box a {
    display: block;
    color: #bbb;
    margin-bottom: 8px;
    transition: var(--transition-speed);
}

.footer-bottom {
    text-align: center;
    padding: 18px;
    border-top: 1px solid #333;
    color: #999;
    font-size: 14px;
}

/* ======================================================
   AI RENDERING & LOADING INDICATOR STYLES
====================================================== */
button.loading-btn {
    opacity: 0.75 !important;
    cursor: wait !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 10px !important;
    pointer-events: none !important;
}

.spinner-border {
    display: inline-block;
    width: 18px;
    height: 18px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: #ffffff;
    animation: spin 0.8s linear infinite;
}

.ai-rendering-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(15, 23, 42, 0.75);
    backdrop-filter: blur(5px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 99999;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.ai-rendering-overlay.show {
    opacity: 1;
    visibility: visible;
}

.ai-rendering-box {
    background: #ffffff;
    padding: 35px 30px;
    border-radius: 20px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.25);
    text-align: center;
    max-width: 420px;
    width: 90%;
    animation: popIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.ai-rendering-box h3 {
    margin-top: 18px;
    margin-bottom: 8px;
    font-size: 18px;
    color: #1e293b;
    font-weight: 700;
}

.ai-rendering-box p {
    font-size: 14px;
    color: #64748b;
    line-height: 1.6;
    margin: 0;
}

.ai-spinner {
    width: 56px;
    height: 56px;
    margin: 0 auto;
    border: 5px solid #e2e8f0;
    border-top: 5px solid var(--primary-color, #2c7be5);
    border-right: 5px solid #00ff66;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

@keyframes popIn {
    0% { transform: scale(0.8); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

/* ======================================================
   MOBILE SIDEBAR OVERLAY
====================================================== */
.mobile-sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(2px);
    z-index: 9998;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.mobile-sidebar-overlay.show {
    display: block;
    opacity: 1;
}

/* ======================================================
   RESPONSIVE DESIGN (OPTIMIZED FOR MOBILE & TABLET)
====================================================== */
@media (max-width: 1200px) {
    .container { width: 95%; }
    .grid { grid-template-columns: repeat(4, 1fr); }
    .footer-container { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 992px) {
    .grid { grid-template-columns: repeat(3, 1fr); }
    .footer-container { grid-template-columns: repeat(2, 1fr); }
    .form-card, .profile-card { max-width: 100%; }
    .cart-card { flex-direction: column; text-align: center; }
}

@media (max-width: 768px) {
    html {
        width: 100%;
        min-width: 0;
        overflow-x: hidden;
    }

    body {
        width: 100%;
        min-width: 0;
        max-width: 100%;
        overflow-x: hidden;
        font-size: 14px;
    }

    .container {
        width: calc(100% - 24px) !important;
        max-width: none !important;
        margin-left: 12px !important;
        margin-right: 12px !important;
    }

    .mobile-sidebar-btn {
        display: flex;
    }

    /* ---------------- NAVBAR ---------------- */
    .navbar {
        width: 100%;
        padding: 10px 0;
        position: sticky;
        top: 0;
    }

    .navbar .container {
        width: 100% !important;
        margin: 0 !important;
        padding: 0 12px;
        gap: 8px;
        min-width: 0;
    }

    .logo {
        font-size: 20px;
        white-space: nowrap;
        min-width: 0;
    }

    .menu-toggle {
        margin-right: 0 !important;
        margin-left: auto !important;
        font-size: 27px;
        flex-shrink: 0;
    }

    .nav-links {
        left: 12px !important;
        right: 12px !important;
        top: calc(100% + 2px) !important;
        width: auto !important;
        min-width: 0 !important;
        max-width: none !important;
        margin: 0 !important;
        padding: 10px 14px !important;
        border-radius: 0 0 12px 12px;
    }

    .nav-links a,
    .nav-item {
        display: block;
        width: 100%;
        padding: 11px 4px;
    }

    .nav_sabad {
        padding: 8px 10px;
        font-size: 13px;
        gap: 5px;
        margin-right: 0 !important;
        margin-left: 0 !important;
        flex-shrink: 0;
    }

    .nav-ai {
        font-size: 10px;
        padding: 6px 7px;
        white-space: nowrap;
    }

    .user-badge {
        padding: 5px 8px;
        font-size: 11px;
        white-space: nowrap;
    }

    .category-menu {
        position: relative;
        width: auto;
    }

    .category-button {
        width: auto;
        justify-content: center;
        padding: 6px 10px;
    }

    .category-dropdown {
        position: absolute !important;
        top: calc(100% + 5px) !important;
        right: 0 !important;
        left: auto !important;
        width: 220px !important;
        min-width: 200px !important;
        margin-top: 0;
        box-shadow: 0 8px 25px rgba(0, 0, 0, 0.2) !important;
        border-radius: 8px;
        z-index: 99999 !important;
    }

    /* ---------------- CARDS & FORMS ---------------- */
    .form-container,
    .auth-container,
    .profile-container {
        width: 100%;
        padding: 18px 12px;
    }

    .form-card,
    .auth-box,
    .profile-card,
    .ai-design-card,
    .ai-result-card,
    .order-card,
    .cart-card {
        width: 100% !important;
        max-width: 100% !important;
        min-width: 0 !important;
        padding: 16px !important;
        margin-left: 0 !important;
        margin-right: 0 !important;
    }

    /* ---------------- PRODUCTS ---------------- */
    .grid {
        width: 100%;
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
        gap: 10px;
    }

    .card {
        min-width: 0;
        padding: 10px;
    }

    .product-img {
        height: 160px;
    }

    .card h3 { font-size: 15px; overflow-wrap: anywhere; }
    .card p { font-size: 13px; overflow-wrap: anywhere; }
    .price { font-size: 16px; }
    .actions { gap: 6px; }
    .actions .btn { width: 100%; }

    /* ---------------- SEARCH ---------------- */
    .search-form {
        width: calc(100% - 24px) !important;
        margin: 12px !important;
        flex-direction: column;
        gap: 8px;
    }

    .search-form input { width: 100%; min-width: 0 !important; }
    .search-form button { width: 100%; }

    /* ---------------- CART & ORDERS ---------------- */
    .cart-card {
        display: flex;
        flex-direction: column;
        align-items: stretch;
        text-align: center;
        gap: 12px;
    }

    .cart-image { width: 100px; height: 100px; margin: 0 auto; }
    .cart-info { width: 100%; min-width: 0; overflow-wrap: anywhere; }
    .cart-actions, .order-actions { width: 100%; justify-content: center; }
    .cart-actions .btn, .order-actions .btn { flex: 1 1 130px; min-width: 0; }

    .order-card p,
    .order-card span,
    .order-card td,
    .order-card div {
        color: #000000 !important;
        font-weight: 700 !important;
        font-size: 15px !important;
    }

    /* ---------------- TABLES ---------------- */
    .table-wrapper {
        width: 100%;
        max-width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .table { min-width: 600px; }

    /* ---------------- AI DESIGN ---------------- */
    .ai-design-page,
    .ai-result-page,
    .ai-chat-page {
        width: 100%;
        max-width: 100%;
        margin: 20px 0;
        padding: 0 12px;
        box-sizing: border-box;
    }

    .ai-previous-grid {
        grid-template-columns: 1fr !important;
        gap: 12px;
    }

    .ai-previous-image { height: auto; max-height: 300px; }

    /* ---------------- CHAT NORMAL ---------------- */
    .ai-chat-container {
        width: calc(100% - 20px) !important;
        max-width: none !important;
        margin: 10px !important;
        padding: 8px !important;
        border-radius: 12px;
        min-width: 0;
    }

    .chat-header {
        padding: 10px !important;
        gap: 8px;
        min-width: 0;
    }

    .chat-header h2 { font-size: 16px; min-width: 0; }
    .btn-clear-chat { padding: 6px 9px; font-size: 11px; flex-shrink: 0; }

    #aiChatMessages,
    .ai-chat-messages {
        width: 100%;
        max-width: 100%;
        height: 55vh !important;
        min-height: 280px;
        padding: 8px !important;
        gap: 12px;
        overflow-x: hidden;
        overflow-y: auto;
        min-width: 0;
    }

    .ai-message,
    .ai-chat-message {
        max-width: 94% !important;
        min-width: 0;
        gap: 7px;
    }

    .message-avatar,
    .ai-chat-avatar {
        width: 30px;
        height: 30px;
        font-size: 14px;
        flex: 0 0 30px;
    }

    .message-content,
    .ai-chat-content {
        min-width: 0;
        max-width: calc(100% - 37px);
    }

    .message-text,
    .ai-chat-text,
    .ai-chat-response {
        max-width: 100%;
        padding: 11px 14px;
        font-size: 13.5px !important;
        line-height: 1.75 !important;
        overflow-wrap: anywhere;
    }

    .chat-input-form,
    .ai-chat-form {
        width: 100%;
        max-width: 100%;
        min-width: 0;
        padding: 6px 7px;
        gap: 6px;
        border-radius: 10px;
    }

    .btn-attach-file {
        width: 36px;
        height: 36px;
        flex: 0 0 36px;
        font-size: 16px;
    }

    #aiChatInput {
        min-width: 0 !important;
        width: 100%;
        font-size: 14px;
        padding: 8px 2px;
    }

    .btn-send-message {
        padding: 12px 24px;
        font-size: 18px;
    }
    .footer-container { grid-template-columns: 1fr; }

    /* ---------------- DASHBOARD CHAT & SIDEBAR MOBILE DRAWER ---------------- */
    .ai-chat-body {
        width: 100%;
        height: 100dvh;
        min-height: 100dvh;
        overflow: hidden;
    }

    .ai-app-layout {
        width: 100%;
        height: 100dvh;
        min-height: 100dvh;
        overflow: hidden;
        position: relative;
    }

    .ai-sidebar {
        display: flex !important;
        position: fixed !important;
        top: 0 !important;
        right: -280px !important;
        width: 280px !important;
        height: 100dvh !important;
        z-index: 9999 !important;
        background-color: #1e293b !important;
        box-shadow: -5px 0 25px rgba(0, 0, 0, 0.25) !important;
        transition: right 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
    }

    .ai-sidebar.open {
        right: 0 !important;
    }

    .conversation-item-wrapper:hover,
    .conversation-item-wrapper.active {
        background-color: rgba(255, 255, 255, 0.12);
    }

    .conversation-item-wrapper .conversation-item {
        color: #ffffff !important;
    }

    .conversation-item-wrapper:hover .conversation-item,
    .conversation-item-wrapper.active .conversation-item {
        color: #ffffff !important;
    }

    .conversation-item-wrapper .btn-conv-options {
        color: #cccccc !important;
    }

    .conversation-item-wrapper .btn-conv-options:hover {
        color: #ffffff !important;
        background: rgba(255, 255, 255, 0.2);
    }

    .conv-options-menu {
        background: #2a2b36;
        border: 1px solid rgba(255, 255, 255, 0.1);
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
    }

    .ai-chat-main {
        width: 100%;
        max-width: 100%;
        min-width: 0;
        height: 100dvh;
        min-height: 0;
        flex: 1 1 auto;
    }

    .ai-chat-main .chat-header {
        min-height: 58px;
        padding: 9px 12px !important;
        flex-shrink: 0;
    }

    .header-info h2 {
        font-size: 15px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .status-indicator { font-size: 10px; }

    .ai-chat-main > .ai-chat-messages {
        flex: 1 1 auto;
        min-height: 0;
        height: auto !important;
        padding: 12px 9px !important;
        overflow-y: auto;
        overflow-x: hidden;
    }

    .chat-footer {
        width: 100%;
        padding: 8px 9px !important;
        flex-shrink: 0;
        box-sizing: border-box;
    }

    /* CODE BLOCK MOBILE */
    .code-block-wrapper {
        width: 100% !important;
        max-width: 100% !important;
        min-width: 0 !important;
        margin: 8px 0 !important;
        border-radius: 7px !important;
    }

    .code-block-wrapper .code-header,
    .code-block-wrapper .code-block-header {
        min-width: 0;
        padding: 6px 8px !important;
        gap: 6px;
    }

    .code-block-wrapper .btn-copy-code,
    .code-block-wrapper .btn-download-code {
        padding: 4px 6px !important;
        font-size: 10px !important;
        white-space: nowrap;
    }

    .code-block-wrapper pre,
    .message-text pre {
        width: 100%;
        max-width: 100%;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
        padding: 10px !important;
        font-size: 11.5px !important;
        line-height: 1.55 !important;
        white-space: pre !important;
    }
}

@media (max-width: 480px) {
    .navbar .container { padding: 0 8px; gap: 5px; }
    .logo { font-size: 17px; }
    .nav_sabad { font-size: 11px; padding: 7px 8px; }
    .nav-ai { font-size: 9px; padding: 5px 5px; }

    .grid { grid-template-columns: 1fr 1fr !important; gap: 8px; }
    .card { padding: 8px; border-radius: 10px; }
    .product-img { height: 130px; }
    .card h3 { font-size: 14px; }
    .card p { font-size: 12px; }
    .price { font-size: 15px; }

    .ai-chat-container {
        width: calc(100% - 12px) !important;
        margin: 6px !important;
        padding: 6px !important;
    }

    .message-avatar, .ai-chat-avatar {
        width: 28px;
        height: 28px;
        flex-basis: 28px;
        font-size: 13px;
    }

    .message-content, .ai-chat-content {
        max-width: calc(100% - 35px);
    }

    .message-text, .ai-chat-text, .ai-chat-response {
        font-size: 13px !important;
        padding: 8px 9px;
    }

    .btn-send-message span {
        display: inline-block;
    }

    .btn-send-message { padding: 7px 9px !important; font-size: 11px !important; }
}

@supports (height: 100dvh) {
    @media (max-width: 768px) {
        .ai-chat-body,
        .ai-app-layout,
        .ai-chat-main {
            height: 100dvh;
        }
    }
}

/* محدود کردن ابعاد تصویر داخل پیام چت */
.chat-message img {
    max-width: 100%;       /* عدم خروج از عرض پیام */
    max-height: 300px;     /* جلوگیری از ارتفاع بیش از حد */
    width: auto;
    height: auto;
    border-radius: 8px;    /* گوشه‌های گرد برای زیبایی */
    object-fit: cover;
    display: block;
    margin-top: 8px;
}