﻿:root {
  color-scheme: dark;
  --bg: #0f0f23;
  --surface: #1a1a2e;
  --surface-2: #16213e;
  --accent: #ffd700;
  --accent-soft: #ffed4e;
  --accent-dark: #b7791f;
  --text: #f3f4f6;
  --muted: #9ca3af;
  --line: rgba(255, 215, 0, .18);
  --danger: #f87171;
  --success: #4ade80;
  --info: #60a5fa;
}

* { box-sizing: border-box; font-family: "Vazirmatn", sans-serif; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background:
    radial-gradient(circle at 12% 5%, rgba(255, 215, 0, .07), transparent 25rem),
    linear-gradient(135deg, var(--bg), var(--surface) 52%, var(--surface-2));
}
button, input, select, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }
a { color: inherit; text-decoration: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

.app-sidebar {
  position: fixed; inset: 0 0 0 auto; z-index: 50; width: 16rem;
  display: flex; flex-direction: column; background: rgba(26, 26, 46, .97);
  border-left: 1px solid var(--line); box-shadow: -20px 0 50px rgba(0,0,0,.25);
  transition: transform .32s cubic-bezier(.2,.8,.2,1);
}
.brand { display: flex; align-items: center; gap: .75rem; padding: 1.25rem; border-bottom: 1px solid var(--line); }
.brand-mark { width: 2.75rem; height: 2.75rem; display: grid; place-items: center; border-radius: 1rem; color: var(--bg); background: linear-gradient(135deg,var(--accent),var(--accent-dark)); box-shadow: 0 0 22px rgba(255,215,0,.22); }
.brand strong { color: var(--accent); display: block; }
.brand small, .profile small { color: var(--muted); }
.sidebar-nav { flex: 1; overflow-y: auto; padding: 1rem .75rem; scrollbar-width: thin; scrollbar-color: var(--accent-dark) transparent; }
.nav-link, .nav-group-toggle {
  width: 100%; display: flex; align-items: center; gap: .8rem; padding: .72rem .85rem;
  border: 0; border-radius: .75rem; color: #d1d5db; background: transparent; text-align: right;
  transition: color .2s, background .2s, transform .2s;
}
.nav-link:hover, .nav-group-toggle:hover { color: var(--accent); background: rgba(255,215,0,.07); transform: translateX(-2px); }
.nav-link.active { color: var(--accent); background: linear-gradient(90deg,rgba(255,215,0,.12),rgba(255,215,0,.04)); box-shadow: inset -3px 0 var(--accent); }
.nav-group-toggle .chevron { margin-right: auto; transition: transform .25s; }
.nav-group.open .chevron { transform: rotate(180deg); }
.nav-submenu { display: grid; grid-template-rows: 0fr; transition: grid-template-rows .25s ease; }
.nav-group.open .nav-submenu { grid-template-rows: 1fr; }
.nav-submenu > div { overflow: hidden; }
.nav-submenu .nav-link { padding: .55rem 2.65rem .55rem .75rem; font-size: .86rem; }
.sidebar-profile { margin: .75rem; padding: .8rem; display: flex; align-items: center; gap: .7rem; background: var(--surface-2); border: 1px solid var(--line); border-radius: .9rem; }
.sidebar-profile img { width: 2.35rem; height: 2.35rem; border-radius: 50%; }
.profile-status { width: .5rem; height: .5rem; margin-right: auto; border-radius: 50%; background: var(--success); box-shadow: 0 0 8px var(--success); }
.sidebar-overlay { position: fixed; inset: 0; z-index: 40; visibility: hidden; opacity: 0; background: rgba(0,0,0,.58); backdrop-filter: blur(3px); transition: .25s; }
.menu-button { display: none; position: fixed; top: 1rem; right: 1rem; z-index: 60; width: 2.75rem; height: 2.75rem; border: 0; border-radius: 50%; background: var(--accent); color: var(--bg); box-shadow: 0 8px 25px rgba(0,0,0,.3); }

.app-main { min-height: 100vh; margin-right: 16rem; }
.app-header {
  position: sticky; top: 0; z-index: 30; display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: 1.1rem 1.5rem; background: rgba(26,26,46,.76); border-bottom: 1px solid var(--line); backdrop-filter: blur(16px);
}
.page-title h1 { margin: 0; color: var(--accent); font-size: clamp(1.25rem,3vw,1.65rem); }
.page-title p { margin: .2rem 0 0; color: var(--muted); font-size: .9rem; }
.header-actions { display: flex; align-items: center; gap: .65rem; }
.icon-button { position: relative; width: 2.6rem; height: 2.6rem; border: 1px solid var(--line); border-radius: 50%; color: var(--accent); background: var(--surface-2); transition: .2s; }
.icon-button:hover { color: var(--bg); background: var(--accent); transform: translateY(-2px); }
.notification-dot { position: absolute; top: -.15rem; left: -.1rem; min-width: 1.1rem; height: 1.1rem; display: grid; place-items: center; border-radius: 1rem; color: white; background: #ef4444; font-size: .66rem; }
.page-content { width: min(100%, 1600px); margin-inline: auto; padding: 1.25rem 1.5rem 2.5rem; }

.grid { display: grid; gap: 1rem; }
.grid-2 { grid-template-columns: repeat(2,minmax(0,1fr)); }
.grid-3 { grid-template-columns: repeat(3,minmax(0,1fr)); }
.grid-4 { grid-template-columns: repeat(4,minmax(0,1fr)); }
.span-2 { grid-column: span 2; }
.mb-1 { margin-bottom: 1rem; }
.mb-2 { margin-bottom: 1.5rem; }

.card {
  position: relative; overflow: hidden; padding: 1.2rem; border: 1px solid var(--line); border-radius: 1rem;
  background: linear-gradient(145deg,rgba(26,26,46,.98),rgba(22,33,62,.9)); box-shadow: 0 12px 35px rgba(0,0,0,.13);
}
.lift { transition: transform .25s, box-shadow .25s, border-color .25s; }
.lift:hover { transform: translateY(-4px); border-color: rgba(255,215,0,.38); box-shadow: 0 18px 40px rgba(0,0,0,.23),0 0 20px rgba(255,215,0,.06); }
.section-head { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: .8rem; margin-bottom: 1rem; }
.section-head h2, .section-head h3 { margin: 0; color: var(--accent); font-size: 1.05rem; }
.section-head p { margin: .25rem 0 0; color: var(--muted); font-size: .82rem; }
.stat { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.stat-label { color: var(--muted); font-size: .82rem; }
.stat-value { margin: .3rem 0; color: var(--accent); font-size: clamp(1.25rem,3vw,1.7rem); font-weight: 700; }
.trend { font-size: .75rem; color: var(--success); }
.trend.down { color: var(--danger); }
.stat-icon { flex: 0 0 auto; width: 3.2rem; height: 3.2rem; display: grid; place-items: center; border-radius: 1rem; background: rgba(255,215,0,.1); color: var(--accent); font-size: 1.25rem; }

.btn { min-height: 2.55rem; display: inline-flex; align-items: center; justify-content: center; gap: .5rem; padding: .55rem 1rem; border: 1px solid transparent; border-radius: .7rem; font-weight: 600; transition: .2s; }
.btn:hover { transform: translateY(-2px); }
.btn-primary { color: var(--bg); background: linear-gradient(135deg,var(--accent),var(--accent-dark)); box-shadow: 0 8px 20px rgba(255,215,0,.13); }
.btn-secondary { color: var(--accent); background: rgba(255,215,0,.08); border-color: var(--line); }
.btn-danger { color: #fecaca; background: rgba(239,68,68,.12); border-color: rgba(239,68,68,.25); }
.btn-sm { min-height: 2rem; padding: .35rem .65rem; font-size: .78rem; }
.toolbar { display: flex; align-items: center; flex-wrap: wrap; gap: .7rem; }
.toolbar .field { flex: 1 1 12rem; }

.field { display: grid; gap: .4rem; }
.field label { color: #d1d5db; font-size: .82rem; font-weight: 500; }
.input, .select, .textarea {
  width: 100%; min-height: 2.7rem; padding: .62rem .8rem; color: var(--text); background: rgba(15,15,35,.62);
  border: 1px solid rgba(156,163,175,.22); border-radius: .68rem; transition: border-color .2s,box-shadow .2s;
}
.textarea { min-height: 7rem; resize: vertical; }
.input:focus, .select:focus, .textarea:focus { outline: 0; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(255,215,0,.09); }
.input::placeholder, .textarea::placeholder { color: #6b7280; }
.form-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 1rem; }
.field-full { grid-column: 1 / -1; }
.switch { display: inline-flex; align-items: center; gap: .6rem; cursor: pointer; }
.switch input { position: absolute; opacity: 0; }
.switch-track { width: 2.65rem; height: 1.4rem; padding: .18rem; border-radius: 2rem; background: #374151; transition: .2s; }
.switch-track::after { content: ""; display: block; width: 1.04rem; height: 1.04rem; border-radius: 50%; background: white; transition: transform .2s; }
.switch input:checked + .switch-track { background: var(--accent-dark); }
.switch input:checked + .switch-track::after { transform: translateX(-1.25rem); }

.table-wrap { overflow-x: auto; scrollbar-width: thin; scrollbar-color: var(--accent-dark) var(--surface); }
.data-table { width: 100%; min-width: 680px; border-collapse: collapse; }
.data-table th { padding: .85rem; color: var(--muted); font-size: .78rem; font-weight: 500; text-align: right; border-bottom: 1px solid rgba(156,163,175,.2); }
.data-table td { padding: .85rem; color: #d1d5db; font-size: .84rem; border-bottom: 1px solid rgba(156,163,175,.1); }
.data-table tbody tr { transition: background .2s; }
.data-table tbody tr:hover { background: rgba(255,215,0,.035); }
.data-table tr:last-child td { border-bottom: 0; }
.entity { display: flex; align-items: center; gap: .65rem; }
.entity-avatar { width: 2.2rem; height: 2.2rem; display: grid; place-items: center; border-radius: .7rem; color: var(--accent); background: rgba(255,215,0,.1); }
.badge { display: inline-flex; align-items: center; gap: .3rem; padding: .28rem .55rem; border-radius: 2rem; font-size: .72rem; white-space: nowrap; }
.badge.success { color: var(--success); background: rgba(34,197,94,.12); }
.badge.warning { color: var(--accent); background: rgba(255,215,0,.11); }
.badge.info { color: var(--info); background: rgba(59,130,246,.13); }
.badge.danger { color: var(--danger); background: rgba(239,68,68,.12); }
.actions { display: flex; align-items: center; gap: .35rem; }
.action-btn { width: 2rem; height: 2rem; border: 0; border-radius: .55rem; color: var(--muted); background: var(--surface-2); transition: .2s; }
.action-btn:hover { color: var(--accent); background: rgba(255,215,0,.1); }

.chart { min-height: 240px; display: flex; align-items: flex-end; gap: clamp(.45rem,2vw,1rem); padding: 1.3rem .4rem .3rem; border-bottom: 1px solid rgba(156,163,175,.18); }
.chart-bar { position: relative; flex: 1; min-width: 1rem; height: var(--value); max-width: 3rem; border-radius: .55rem .55rem 0 0; background: linear-gradient(to top,var(--accent-dark),var(--accent)); animation: grow .8s both; transform-origin: bottom; }
.chart-bar:hover { filter: brightness(1.15); }
.chart-bar::after { content: attr(data-label); position: absolute; bottom: -1.7rem; left: 50%; transform: translateX(-50%); color: var(--muted); font-size: .68rem; }
.progress { height: .5rem; overflow: hidden; border-radius: 1rem; background: rgba(156,163,175,.12); }
.progress > span { display: block; height: 100%; width: var(--value); border-radius: inherit; background: linear-gradient(90deg,var(--accent-dark),var(--accent)); }
.list { display: grid; gap: .75rem; }
.list-item { display: flex; align-items: center; gap: .75rem; padding-bottom: .75rem; border-bottom: 1px solid rgba(156,163,175,.1); }
.list-item:last-child { padding-bottom: 0; border-bottom: 0; }
.list-icon { width: 2.3rem; height: 2.3rem; display: grid; place-items: center; flex: 0 0 auto; border-radius: .75rem; color: var(--accent); background: rgba(255,215,0,.09); }
.list-copy { min-width: 0; flex: 1; }
.list-copy strong { display: block; font-size: .85rem; }
.list-copy small { color: var(--muted); }

.pagination { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: .7rem; margin-top: 1rem; color: var(--muted); font-size: .78rem; }
.pagination-controls { display: flex; gap: .3rem; }
.page-btn { min-width: 2rem; height: 2rem; border: 1px solid var(--line); border-radius: .5rem; color: var(--muted); background: transparent; }
.page-btn.active, .page-btn:hover { color: var(--bg); background: var(--accent); }
.empty-state { padding: 2.5rem 1rem; text-align: center; color: var(--muted); }
.empty-state i { display: block; margin-bottom: .7rem; color: var(--accent); font-size: 2rem; }

.modal-backdrop { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 1rem; visibility: hidden; opacity: 0; background: rgba(0,0,0,.7); backdrop-filter: blur(5px); transition: .2s; }
.modal-backdrop.open { visibility: visible; opacity: 1; }
.modal { width: min(100%, 34rem); max-height: 88vh; overflow-y: auto; padding: 1.25rem; border: 1px solid var(--line); border-radius: 1rem; background: var(--surface); transform: translateY(20px) scale(.98); transition: .25s; }
.modal-backdrop.open .modal { transform: none; }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; }
.modal-head h2 { margin: 0; color: var(--accent); font-size: 1.1rem; }
.toast-stack { position: fixed; left: 1rem; bottom: 1rem; z-index: 120; display: grid; gap: .6rem; }
.toast { display: flex; align-items: center; gap: .65rem; max-width: 22rem; padding: .85rem 1rem; border: 1px solid var(--line); border-radius: .8rem; color: var(--text); background: var(--surface-2); box-shadow: 0 15px 35px rgba(0,0,0,.3); animation: toast-in .3s both; }
.toast i { color: var(--success); }
.reveal { opacity: 0; transform: translateY(15px); animation: reveal .55s forwards; animation-delay: var(--delay,0ms); }

@keyframes reveal { to { opacity: 1; transform: none; } }
@keyframes grow { from { transform: scaleY(0); } to { transform: scaleY(1); } }
@keyframes toast-in { from { opacity: 0; transform: translateX(-15px); } }

@media (max-width: 1100px) {
  .grid-4 { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .grid-3 { grid-template-columns: repeat(2,minmax(0,1fr)); }
}
@media (max-width: 900px) {
  .app-sidebar { transform: translateX(102%); }
  body.sidebar-open .app-sidebar { transform: none; }
  body.sidebar-open .sidebar-overlay { visibility: visible; opacity: 1; }
  .menu-button { display: grid; place-items: center; }
  .app-main { margin-right: 0; }
  .app-header { padding-right: 4.5rem; }
}
@media (max-width: 640px) {
  .page-content { padding: 1rem .8rem 2rem; }
  .app-header { align-items: flex-start; padding-left: .8rem; }
  .page-title p { display: none; }
  .header-profile span { display: none; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
  .form-grid { grid-template-columns: 1fr; }
  .field-full { grid-column: auto; }
  .card { padding: 1rem; }
  .toolbar { align-items: stretch; }
  .toolbar > * { width: 100%; }
  .btn { width: 100%; }
  .actions .action-btn { width: 2.2rem; }
  .data-table.responsive { min-width: 0; }
  .data-table.responsive thead { display: none; }
  .data-table.responsive, .data-table.responsive tbody, .data-table.responsive tr, .data-table.responsive td { display: block; width: 100%; }
  .data-table.responsive tr { margin-bottom: .75rem; padding: .5rem; border: 1px solid var(--line); border-radius: .75rem; background: rgba(15,15,35,.35); }
  .data-table.responsive td { display: flex; justify-content: space-between; gap: 1rem; padding: .55rem; text-align: left; border-bottom: 1px solid rgba(156,163,175,.08); }
  .data-table.responsive td::before { content: attr(data-label); color: var(--muted); text-align: right; }
  .data-table.responsive td:last-child { border-bottom: 0; }
}
@media print {
  .app-sidebar, .app-header, .menu-button, .sidebar-overlay, .no-print { display: none !important; }
  .app-main { margin: 0; }
  body, .card { color: #111; background: #fff; box-shadow: none; }
}
@page {
  size: A4;
  margin: 14mm 12mm;
}


.lbl-white{
    color:#fff;
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
.inline-add {
    display: flex;
    gap: 6px;
    align-items: stretch;
}

    .inline-add .select {
        flex: 1;
    }

.btn-square {
    padding: 0 12px;
    flex-shrink: 0;
}

.form-error {
    color: #ff6b6b;
    margin-top: 10px;
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.9rem;
}

.checkbox-field {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    white-space: nowrap;
    color: #fff;
}

.card:has(.custom-select-list) {
    overflow: visible !important;
    position: relative;
    z-index: 30;
}

.custom-select {
    position: relative;
    flex: 1;
}

.select-trigger {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    text-align: right;
    cursor: pointer;
    color: #fff;
    background-color: #1c2333;
}

.custom-select-list {
    position: absolute;
    top: calc(100% + 4px);
    right: 0;
    left: 0;
    z-index: 9999;
    max-height: 180px;
    overflow-y: auto;
    background-color: #1c2333;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 8px;
    list-style: none;
    margin: 0;
    padding: 4px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
}

    .custom-select-list li {
        padding: 8px 10px;
        color: #fff;
        cursor: pointer;
        border-radius: 6px;
    }

        .custom-select-list li:hover,
        .custom-select-list li.active {
            background-color: #2a3550;
        }

.dropdown-overlay {
    position: fixed;
    inset: 0;
    z-index: 40;
}

.editable-cell {
    cursor: pointer;
    border-bottom: 1px dashed transparent;
    transition: border-color .15s;
}

.editable-cell:hover {
    border-color: rgba(255, 215, 0, .5);
}

.cell-edit-input {
    min-height: 2.2rem;
    padding: .3rem .5rem;
    font-size: .85rem;
    width: auto;
    min-width: 6rem;
}

.stock-dot {
    display: inline-block;
    width: .55rem;
    height: .55rem;
    border-radius: 50%;
    margin-left: .4rem;
    vertical-align: middle;
}

.stock-dot.ok { background: #22c55e; }
.stock-dot.warning { background: #f59e0b; }
.stock-dot.danger { background: #ef4444; }

/* ================= رسپانسیو مرحله ۱: اسکلت و هدر ================= */

/* ارتفاع درست در مرورگرهای موبایل (نوار آدرس) */
.app-sidebar {
    height: 100vh;
    height: 100dvh;
}

.app-main {
    min-height: 100vh;
    min-height: 100dvh;
}

/* جلوگیری از اسکرول صفحه وقتی منوی موبایل باز است */
@media (max-width: 900px) {
    body.sidebar-open {
        overflow: hidden;
    }

    .app-sidebar {
        width: min(16rem, 85vw);
    }

    .app-header {
        min-height: 4.25rem;
    }
    /* دکمه منو دقیقاً هم‌تراز با هدر */
    .menu-button {
        top: .75rem;
        right: .75rem;
    }
}

/* تبلت: ۶۴۱ تا ۹۰۰ */
@media (min-width: 641px) and (max-width: 900px) {
    .app-header {
        padding-block: .8rem;
        gap: .75rem;
    }

    .header-actions {
        gap: .45rem;
    }

    .header-logout span {
        display: none;
    }
}

/* موبایل */
@media (max-width: 640px) {
    .app-header {
        align-items: center; /* قبلاً flex-start بود */
        padding: .6rem .8rem .6rem .6rem;
        padding-right: 4rem; /* جا برای menu-button */
        gap: .5rem;
    }

    .page-title {
        min-width: 0;
        flex: 1;
    }

        .page-title h1 {
            font-size: 1rem;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
        }

    /* دکمه‌های هدر فقط آیکون، و جلوی .btn{width:100%} را بگیریم */
    .header-actions {
        flex: 0 0 auto;
        gap: .3rem;
        flex-wrap: nowrap;
    }

        .header-actions .btn {
            width: auto;
            min-width: 2.4rem;
            min-height: 2.4rem;
            padding: .4rem .6rem;
        }

        .header-actions .header-profile span,
        .header-actions .header-logout span {
            display: none;
        }

    .icon-button {
        width: 2.4rem;
        height: 2.4rem;
        flex: 0 0 auto;
    }

    /* وقتی چند آیکن اعلان داریم، فقط اسکرول افقی نرم داخل خودِ دکمه‌ها */
    .header-actions {
        overflow-x: auto;
        scrollbar-width: none;
    }

        .header-actions::-webkit-scrollbar {
            display: none;
        }

    /* بج اعلان داخل overflow بریده نشود */
    .header-actions {
        padding-top: .3rem;
        margin-top: -.3rem;
    }

    /* toast روی پایین موبایل کل عرض را بگیرد و روی منوی پایین نیفتد */
    .toast-stack {
        left: .6rem;
        right: .6rem;
        bottom: .6rem;
    }

    .toast {
        max-width: none;
    }
}

/* گوشی‌های خیلی کوچک */
@media (max-width: 380px) {
    .header-actions .header-profile {
        display: none;
    }
    /* دکمه پروفایل فعلاً عملکردی ندارد */
}

/* بج اعلان (جایگزین سه style="" تکراری در Razor) */
.notification-dot.dot-red {
    min-width: 1.2rem;
    height: 1.2rem;
    padding: 0 .3rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    background: #dc2626;
    color: #fff;
    font-size: .7rem;
    font-weight: 700;
    line-height: 1;
    box-shadow: 0 0 0 2px #0f1530;
}

/* ================= رسپانسیو مرحله ۲-۴: محتوا، جدول، فرم، مودال ================= */

/* شبکه‌ی ایمنی: سرریز المان‌ها صفحه را افقی نکشد (clip، برای اینکه sticky خراب نشود) */
body {
    overflow-x: clip;
}

.app-main, .page-content, .card {
    min-width: 0;
}

.table-wrap {
    max-width: 100%;
}

/* قفل اسکرول پشت مودال باز */
body:has(.modal-backdrop.open) {
    overflow: hidden;
}

/* خلاصه و دکمه‌های پایین فاکتور (جایگزین inline style) */
.invoice-summary {
    display: flex;
    justify-content: flex-end;
    gap: 1.5rem;
    margin-top: 1rem;
    padding: .75rem 0;
    border-top: 1px solid var(--line);
}

.invoice-actions {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: .5rem;
    margin-top: 1rem;
}

/* ---------- تبلت و کوچکتر ---------- */
@media (max-width: 900px) {
    .toolbar[style*="nowrap"] {
        flex-wrap: wrap !important;
    }

    /* جدول‌های داخل مودال: ۴ ستون به بالا اسکرول افقی بگیرند، ۲-۳ ستونی‌ها همان‌طور بمانند */
    .modal .table-wrap {
        overflow-x: auto !important;
    }

    .modal .data-table:not(.responsive):has(th:nth-child(4)) {
        min-width: 560px !important;
        table-layout: auto !important;
    }
}

/* ≥۶۴۱: جدول‌های پرستون به‌جای له‌شدن اسکرول بگیرند */
@media (min-width: 641px) {
    .data-table:has(th:nth-child(8)) {
        min-width: 900px;
    }
}

/* ---------- موبایل ---------- */
@media (max-width: 640px) {
    /* کارت‌های آمار: دو ستون و فشرده */
    .grid-4 {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: .6rem;
    }

        .grid-4 .card {
            padding: .8rem;
        }

        .grid-4 .stat-icon {
            display: none;
        }

    .stat-value {
        font-size: 1.2rem;
    }

    /* toolbar: هر فیلد یک ردیف، با غلبه بر inline styleها */
    .toolbar {
        flex-wrap: wrap !important;
    }

        .toolbar > .field {
            flex: 1 1 100% !important;
            min-width: 0 !important;
            max-width: none !important;
        }

    .field > label[style*="visibility"], .field-spacer {
        display: none;
    }

    /* دکمه‌های کوچک/مربعی/جدولی عرض طبیعی خودشان را نگه دارند */
    .btn-square, .btn-sm, .inline-add .btn, td .btn, .actions .btn {
        width: auto;
    }

    .toolbar > .action-btn {
        width: 2.4rem;
    }

    .inline-add {
        flex-wrap: nowrap;
    }

        .inline-add .custom-select {
            min-width: 0;
        }

    /* هدف لمسی و جلوگیری از زوم iOS */
    .input, .select, .textarea, .cell-edit-input {
        font-size: 16px;
    }

    .action-btn {
        width: 2.4rem;
        height: 2.4rem;
    }

    .page-btn {
        min-width: 2.4rem;
        height: 2.4rem;
    }

    /* پیجینیشن */
    .pagination {
        justify-content: center;
        text-align: center;
    }

    .pagination-controls {
        flex-wrap: wrap;
        justify-content: center;
    }

    /* حالت کارتیِ جدول */
    .data-table.responsive td {
        text-align: start;
        align-items: center;
    }

        .data-table.responsive td.empty-state {
            display: block;
            text-align: center;
        }

        .data-table.responsive td > .input,
        .data-table.responsive td > .select,
        .data-table.responsive td > .cell-edit-input {
            width: 60% !important;
            min-width: 0 !important;
        }

    .entity .cell-edit-input {
        width: 100%;
        min-width: 0;
    }

    /* مودال */
    .modal-backdrop {
        padding: .5rem;
    }

    .modal {
        max-height: 92vh;
        max-height: 92dvh;
        padding: 1rem;
    }

    .modal-head h2 {
        font-size: 1rem;
    }

    /* پنل جستجوی فاکتور: به‌جای absolute، ورقه‌ی پایین صفحه */
    .invoice-search-panel {
        position: fixed !important;
        inset: auto .5rem .5rem .5rem !important;
        width: auto !important;
        max-width: none !important;
        max-height: 80vh;
        max-height: 80dvh;
        overflow-y: auto;
        z-index: 110;
    }

    .invoice-search-filters {
        flex-direction: column;
    }

    /* خلاصه و دکمه‌های فاکتور */
    .invoice-summary {
        flex-direction: column;
        gap: .4rem;
    }

        .invoice-summary > span {
            display: flex;
            justify-content: space-between;
        }

    .invoice-actions {
        flex-wrap: wrap;
    }

        .invoice-actions > label {
            flex: 1 1 100%;
        }
}
/* ===== رسپانسیو مرحله ۷: پشتیبانی و سفارش‌ها ===== */
.support-stats {
    display: grid;
    gap: 1rem;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

/* محتوای چندتکه‌ی سلول در حالت کارتی (div داخل td) */
.data-table.responsive td > .cell-stack {
    min-width: 0;
}

@media (max-width: 640px) {
    .support-stats {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: .6rem;
    }

        .support-stats > .card {
            padding: .8rem !important;
        }

        .support-stats h2 {
            font-size: 1.2rem;
        }
        /* کارت آخرِ تکی، تمام‌عرض */
        .support-stats > :last-child:nth-child(odd) {
            grid-column: 1 / -1;
        }

    .data-table.responsive td > .cell-stack {
        text-align: start;
    }

    .data-table.responsive td[style*="max-width"] {
        max-width: none !important;
    }
    /* دکمه‌ی چت (با بج absolute) از سلول بیرون نزند */
    .data-table.responsive td .action-btn {
        flex: 0 0 auto;
    }
}

/* =====================================================================
   صفحه‌ی «فرمول مونتاژ» (BomFormula.razor) - چیدمان رسپانسیو
   از container query استفاده شده تا چیدمان به عرضِ واقعیِ کارت (نه عرضِ صفحه)
   وابسته باشه؛ پس با باز/بسته بودنِ سایدبار هم درست کار می‌کنه.
   ===================================================================== */

/* دو فیلدِ بالای صفحه (محصول / دستگاه) */
.bom-top {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 18rem), 1fr));
    gap: .8rem 1rem;
    align-items: end;
}

    .bom-top > .field {
        min-width: 0;
    }

    .bom-top .select-trigger span {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

/* فرمِ «افزودن قطعه به فرمول» */
.bom-add-wrap {
    container-type: inline-size;
    position: relative;
    z-index: 5; /* لیستِ پیشنهادِ قطعه روی جدولِ پایین بیفته */
}

.bom-add-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: .8rem;
    align-items: end;
}

    .bom-add-grid > .field {
        min-width: 0;
    }

    .bom-add-grid .field > label {
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

.bom-f-part,
.bom-f-variant,
.bom-f-action {
    grid-column: 1 / -1;
}

.bom-readout {
    display: flex;
    align-items: center;
    justify-content: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-variant-numeric: tabular-nums;
}

.bom-f-action .btn {
    width: 100%;
}

.bom-part-list {
    max-height: 280px;
    min-width: min(100%, 14rem);
}

    .bom-part-list li {
        white-space: normal;
        overflow-wrap: anywhere;
    }

/* کارتِ متوسط: دو ردیف + دکمه در ردیفِ سوم */
@container (min-width: 560px) {
    .bom-add-grid {
        grid-template-columns: repeat(12, minmax(0, 1fr));
    }

    .bom-f-part { grid-column: span 7; }
    .bom-f-variant { grid-column: span 5; }
    .bom-f-qty { grid-column: span 3; }
    .bom-f-unit { grid-column: span 2; }
    .bom-f-last { grid-column: span 3; }
    .bom-f-total { grid-column: span 4; }

    .bom-f-action {
        grid-column: 1 / -1;
        justify-self: end;
    }

        .bom-f-action .btn {
            width: auto;
        }
}

/* کارتِ عریض: دو ردیفِ کامل، دکمه کنارِ آخرین فیلد */
@container (min-width: 980px) {
    .bom-f-part { grid-column: span 5; }
    .bom-f-variant { grid-column: span 4; }
    .bom-f-qty { grid-column: span 3; }
    .bom-f-unit { grid-column: span 2; }
    .bom-f-last { grid-column: span 3; }
    .bom-f-total { grid-column: span 3; }

    .bom-f-action {
        grid-column: span 4;
        justify-self: stretch;
    }

        .bom-f-action .btn {
            width: 100%;
        }
}

/* عنوانِ طولانیِ کارت (نام محصول + رنگ/سایز) روی موبایل بشکنه */
.card .section-head h2 {
    overflow-wrap: anywhere;
}

@media (max-width: 640px) {
    .bom-add-grid .input,
    .bom-add-grid .select {
        font-size: 16px; /* جلوگیری از زوم خودکارِ iOS */
    }
}
