:root {
    --nav-height: 52px;
    --bottom-controls-height: 42px;
    --console-height: 110px;
    --right-panel-width: 300px;

    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --danger: #dc2626;
    --success: #16a34a;

    --dark: #111827;
    --dark-soft: #1f2937;
    --text: #374151;
    --muted: #6b7280;
    --border: #e5e7eb;
    --panel-bg: rgba(255, 255, 255, 0.97);
    --light-bg: #f9fafb;

    --shadow: 0 10px 30px rgba(0, 0, 0, 0.14);
    --radius: 12px;
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: Tahoma, sans-serif;
    background: #ffffff;
}

body,
button,
input,
select,
textarea {
    font-family: Tahoma, sans-serif;
}

button,
input {
    font-family: inherit;
}

button {
    user-select: none;
}

/* =========================
    Top Navigation
========================= */

.main-nav {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--nav-height);
    padding: 0 24px;
    background: linear-gradient(135deg, var(--dark-soft), var(--dark));
    z-index: 10000;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.18);
    display: flex;
    align-items: center;
    direction: rtl;
}

.nav-menu {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    gap: 8px;
    align-items: center;
}

.nav-item {
    position: relative;
}

.nav-link {
    color: #f9fafb;
    text-decoration: none;
    padding: 9px 14px;
    display: block;
    border-radius: 8px;
    transition: background-color 0.2s ease, color 0.2s ease;
    font-size: 14px;
    white-space: nowrap;
}

.nav-link:hover {
    background-color: rgba(255, 255, 255, 0.12);
}

.submenu {
    display: none;
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    left: auto;
    min-width: 190px;
    padding: 6px;
    margin: 0;
    background-color: #ffffff;
    box-shadow: var(--shadow);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    z-index: 10001;
}

.nav-item:hover .submenu {
    display: block;
}

.submenu li {
    list-style: none;
}

.submenu a {
    color: var(--text);
    padding: 9px 12px;
    display: block;
    text-decoration: none;
    border-radius: 7px;
    font-size: 13px;
    white-space: nowrap;
}

.submenu a:hover {
    background-color: #f3f4f6;
}

/* =========================
    Right Panel
========================= */

#rightPanel {
    position: fixed;
    top: calc(var(--nav-height) + 12px);
    right: 12px;
    width: var(--right-panel-width);
    height: calc(100vh - var(--nav-height) - var(--bottom-controls-height) - 28px);
    background: var(--panel-bg);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    border-radius: var(--radius);
    z-index: 9000;
    display: flex;
    flex-direction: column;
    direction: rtl;
    overflow: hidden;
    backdrop-filter: blur(8px);
}

#rightPanelHeader {
    height: 46px;
    min-height: 46px;
    padding: 0 12px;
    background: linear-gradient(135deg, var(--dark-soft), var(--dark));
    color: white;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid #111827;
}

#rightPanelTitle {
    font-size: 14px;
    font-weight: bold;
}

#btnBackToMainMenu {
    height: 28px;
    padding: 0 10px;
    border: none;
    border-radius: 7px;
    background: rgba(255, 255, 255, 0.14);
    color: white;
    cursor: pointer;
    font-size: 12px;
    display: none;
}

#btnBackToMainMenu:hover {
    background: rgba(255, 255, 255, 0.24);
}

#rightPanelBody {
    flex: 1;
    overflow-y: auto;
    background: #ffffff;
}

#rightPanelButtons {
    padding: 8px; /* پدینگ دور پنل کمتر شده است */
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px; /* فاصله دکمه‌ها از ۹ پیکسل به ۶ پیکسل کاهش یافت تا فشرده‌تر شوند */
    background: var(--light-bg);
    align-content: start; /* دکمه‌ها را به سمت بالای پنل جمع می‌کند تا فاصله اضافه در پایین ایجاد نشود */
}

#rightPanelButtons button {
    height: 36px; /* ارتفاع کمی فشرده‌تر شده است */
    padding: 0 6px;
    font-size: 11.5px; /* اندازه فونت برای هماهنگی با آیکون بهینه‌سازی شد */
    cursor: pointer;
    border: 1px solid #d1d5db;
    background: #ffffff;
    color: var(--text);
    border-radius: 6px; /* انحنای ملایم‌تر برای دکمه‌های کوچک */
    transition: all 0.18s ease;
    white-space: nowrap;
    
    /* چیدمان آیکون و متن در مرکز */
    display: flex;
    align-items: center;
    justify-content: flex-start; /* هم‌ترازی از سمت راست (RTL) */
    gap: 6px; /* فاصله بین آیکون و نوشته داخل دکمه */
    direction: rtl;
}

/* استایل آیکون‌های داخل دکمه */
#rightPanelButtons button svg,
#rightPanelButtons button i {
    width: 15px;
    height: 15px;
    stroke-width: 2px;
    color: var(--muted);
    flex-shrink: 0;
    transition: color 0.18s ease;
}

#rightPanelButtons button:hover {
    background: var(--primary);
    border-color: var(--primary);
    color: white;
    transform: translateY(-1px);
}

/* تغییر رنگ آیکون به سفید هنگام هاور شدن دکمه */
#rightPanelButtons button:hover svg,
#rightPanelButtons button:hover i {
    color: #ffffff;
}

#rightPanelButtons button:active {
    transform: translateY(0);
}

#btnUploadFile,
#btnSaveFile,
#btnAIdesign {
    grid-column: span 2;
}

#btnAIdesign {
    background: linear-gradient(135deg, #7c3aed, #2563eb);
    color: white;
    border-color: transparent;
    font-weight: bold;
}

#btnAIdesign:hover {
    background: linear-gradient(135deg, #6d28d9, #1d4ed8);
    border-color: transparent;
}

#rightPanelContent {
    min-height: 100%;
    padding: 14px;
    background: #ffffff;
    font-size: 13px;
    display: none;
}

#rightPanelBody::-webkit-scrollbar,
#rightPanelContent::-webkit-scrollbar {
    width: 7px;
}

#rightPanelBody::-webkit-scrollbar-thumb,
#rightPanelContent::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 10px;
}

#rightPanelBody::-webkit-scrollbar-track,
#rightPanelContent::-webkit-scrollbar-track {
    background: transparent;
}

/* =========================
Tools List View
========================= */

#toolsListView {
    direction: rtl;
    padding: 14px;
    font-family: Tahoma, sans-serif;
    color: var(--text);
}

#toolsListView h3 {
    margin: 0 0 12px 0;
    font-size: 15px;
    font-weight: bold;
    color: var(--dark);
}

#toolsListView .SubMenu {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

#toolsListView .SubMenu p {
    margin: 0;
}

#toolsListView .SubMenu button {
    width: 100%;
    min-height: 38px;
    padding: 0 12px;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    background: #ffffff;
    color: var(--text);
    font-size: 13px;
    font-family: Tahoma, sans-serif;
    cursor: pointer;
    text-align: center;
    transition: all 0.18s ease;
}

#toolsListView .SubMenu button:hover {
    background: var(--primary);
    color: #ffffff;
    border-color: var(--primary);
    transform: translateY(-1px);
}

#toolsListView .SubMenu button:active {
    transform: translateY(0);
}

#toolsListView .form-row {
    margin-top: 2px;
}

#toolsListView .form-row label {
    font-size: 12.5px;
    font-weight: bold;
}

#toolsListView .form-row input,
#toolsListView .form-row select {
    height: 34px;
    font-family: Tahoma, sans-serif;
    font-size: 13px;
}


/* =========================
    Forms
========================= */

.form-row {
    margin-bottom: 11px;
    display: flex;
    flex-direction: column;
    gap: 5px;
    font-size: 13px;
}

.form-row label {
    color: var(--text);
    font-weight: bold;
}

.form-row input[type="text"],
.form-row input[type="number"],
.form-row select,
.form-row textarea {
    width: 100%;
    min-height: 34px;
    padding: 4px 8px;
    font-size: 13px;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    outline: none;
    background: #ffffff;
}

.form-row textarea {
    min-height: 90px;
    resize: vertical;
}

.form-row input[type="text"]:focus,
.form-row input[type="number"]:focus,
.form-row select:focus,
.form-row textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.14);
}

.form-buttons {
    margin-top: 14px;
    display: flex;
    gap: 8px;
    justify-content: flex-start;
    flex-wrap: wrap;
}

.form-buttons button {
    height: 34px;
    padding: 0 14px;
    font-size: 13px;
    cursor: pointer;
    border: 1px solid #d1d5db;
    background: #ffffff;
    color: var(--text);
    border-radius: 8px;
}

.form-buttons button:hover {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

/* =========================
    Bottom Display Controls
========================= */

#displayControls {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    min-height: var(--bottom-controls-height);
    z-index: 9999;
    background: rgba(255, 255, 255, 0.96);
    border-top: 1px solid var(--border);
    padding: 6px 14px;
    direction: rtl;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 14px;
    flex-wrap: wrap;
    box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.08);
}

#displayControls label {
    margin: 0;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 13px;
    cursor: pointer;
    color: var(--text);
    white-space: nowrap;
}

#displayControls input[type="checkbox"] {
    margin: 0;
    accent-color: var(--primary);
}

/* =========================
    CAD Console
========================= */

#cad-console {
    position: fixed;
    bottom: var(--bottom-controls-height);
    left: 0;
    width: calc(100% - var(--right-panel-width) - 24px);
    height: var(--console-height);
    padding: 6px;
    background-color: #0f172a;
    border-top: 1px solid #1e293b;
    color: #22c55e;
    font-family: Consolas, monospace;
    display: flex;
    flex-direction: column;
    z-index: 8000;
    direction: ltr;
}

#cad-console-output {
    flex: 1;
    overflow-y: auto;
    padding: 4px;
    font-size: 13px;
    color: #22c55e;
    white-space: pre-wrap;
    word-break: break-word;
    font-family: Consolas, monospace;
}

#cad-console-input {
    height: 28px;
    background-color: #111827;
    border: 1px solid #334155;
    color: #22c55e;
    font-size: 14px;
    padding: 4px 8px;
    outline: none;
    border-radius: 6px;
    font-family: Consolas, monospace;
}

/* =========================
    Coordinate Display (انتقال به نوار بالا)
========================= */
#coordDisplay {
    position: fixed !important;
    top: 14px !important;            /* قرارگیری دقیق روی نوار منو */
    left: 24px !important;           /* سمت چپ صفحه */
    bottom: auto !important;         /* غیرفعال کردن مقدار bottom قبلی */
    padding: 6px 12px !important;
    background: rgba(15, 23, 42, 0.9) !important; /* پس‌زمینه تیره هماهنگ با نوار منو */
    color: #22c55e !important;
    font-family: Consolas, monospace !important;
    font-size: 12px !important;
    z-index: 10005 !important;       /* بالاتر از z-index نوار منو (10000) */
    border-radius: 6px !important;
    border: 1px solid rgba(34, 197, 94, 0.4) !important;
    direction: ltr !important;
    pointer-events: none !important;
    backdrop-filter: blur(4px) !important;
}


/* =========================
    Dimension Label
========================= */

#dimensionLabel {
    position: absolute;
    padding: 4px 8px;
    background: rgba(0, 0, 0, 0.7);
    color: white;
    font-size: 12px;
    border-radius: 4px;
    pointer-events: none;
    display: none;
    z-index: 12000;
    direction: ltr;
}

/* =========================
    Context Menu
========================= */

.context-menu {
    position: absolute;
    min-width: 170px;
    background: white;
    border: 1px solid var(--border);
    display: none;
    z-index: 11000;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: var(--shadow);
    direction: rtl;
}

.context-menu div {
    padding: 9px 14px;
    cursor: pointer;
    font-size: 13px;
    color: var(--text);
}

.context-menu div:hover {
    background: #f3f4f6;
}

/* =========================
    Chat / AI Response Box
========================= */

#responseBox {
    height: 300px;
    overflow-y: auto;
    overflow-x: hidden;
    border: 1px solid #ccc;
    padding: 10px;
    background: #f9f9f9;
    white-space: normal;
    word-break: break-word;
    overflow-wrap: anywhere;
    direction: rtl;
}

.chat-user,
.chat-ai {
    display: block;
    width: 100%;
    margin-bottom: 8px;
    white-space: pre-wrap;
    word-break: break-word;
    overflow-wrap: anywhere;
    text-align: right;
    direction: rtl;
}

.chat-ai {
    text-align: left;
    direction: ltr;
}

/* =========================
    Responsive
========================= */

@media (max-width: 900px) {
    :root {
        --right-panel-width: 250px;
    }

    #rightPanel {
        right: 8px;
    }

    #rightPanelButtons {
        grid-template-columns: 1fr;
    }

    #btnUploadFile,
    #btnSaveFile,
    #btnAIdesign {
        grid-column: span 1;
    }

    #cad-console {
        width: 100%;
    }

    #displayControls {
        justify-content: flex-start;
        overflow-x: auto;
        flex-wrap: nowrap;
    }
}

/* =========================
    Left Floating Toggle Menu
========================= */

.left-toggle-menu {
    position: fixed;
    left: 14px;
    top: calc(var(--nav-height) + 14px);
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 9000;
}

.toggle-btn {
    width: 38px;
    height: 38px;
    background: var(--panel-bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.08);
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    backdrop-filter: blur(8px);
}

/* افکت هاور عمومی */
.toggle-btn:hover {
    background: var(--light-bg);
    border-color: #cbd5e1;
    transform: scale(1.04);
}

/* افکت دکمه فشرده شده (Toggle Active) */
.toggle-btn.active {
    background: var(--primary) !important;
    border-color: var(--primary) !important;
    transform: translateY(1px);
    box-shadow: inset 0 3px 6px rgba(0,0,0,0.28);
}

.toggle-btn.active svg {
    color: #fff !important;
}


/* رنگ آیکون وقتی دکمه فعال است */
.toggle-btn.active svg {
    color: #ffffff !important;
}

/* =========================
    Tooltip CSS (فارسی)
========================= */

.toggle-btn::after {
    content: attr(data-tooltip);
    position: absolute;
    left: calc(100% + 8px);
    top: 50%;
    transform: translateY(-50%) translateX(-8px);
    background: rgba(15, 23, 42, 0.95);
    color: #ffffff;
    padding: 5px 9px;
    font-size: 11px;
    font-family: Tahoma, sans-serif;
    border-radius: 5px;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: all 0.15s ease;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    direction: rtl;
}

.toggle-btn:hover::after {
    opacity: 1;
    transform: translateY(-50%) translateX(0);
}

/* استایل‌های رنگی اختصاصی آیکون‌ها در حالت عادی جهت جذابیت بیشتر */
#tglLineDrawing svg { color: #3b82f6; } /* آبی */
#tglOrtho svg { color: #f59e0b; }       /* نارنجی */
#tglSnapGrid svg { color: #10b981; }    /* سبز */
#tglWorkPlane svg { color: #8b5cf6; }   /* بنفش */
#tglVertical svg { color: #ec4899; }    /* صورتی */
#tglHorizontal svg { color: #06b6d4; }  /* فیروزه‌ای */
#tglRemoveUnusedPoints svg { color: #ef4444; /* قرمز */}
#tglDeleteLastLine svg {color: #f59e0b;}


