/* ==========================================================================
   CRM — شیوه‌نامه‌ی اصلی
   رنگ‌ها از دنیای کار گرفته شده‌اند: جوهر فولادی، لبه‌ی سبزآبی شیشه،
   و برنجی یراق‌آلات (برای «قفل» و «مرحله‌ی جاری»).
   ========================================================================== */

@font-face { font-family: "Vazir"; src: url("../fonts/vazirmatn/Vazirmatn-FD-Regular.woff2") format("woff2"), url("../fonts/Vazir-Regular-FD.ttf") format("truetype"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Vazir"; src: url("../fonts/vazirmatn/Vazirmatn-FD-Medium.woff2") format("woff2"), url("../fonts/Vazir-Medium-FD.ttf") format("truetype"); font-weight: 500; font-display: swap; }
@font-face { font-family: "Vazir"; src: url("../fonts/vazirmatn/Vazirmatn-FD-Bold.woff2") format("woff2"), url("../fonts/Vazir-Bold-FD.ttf") format("truetype"); font-weight: 700; font-display: swap; }

:root {
    --ink: #1c2530;
    --ink-2: #2a3542;
    --ink-3: #3a4655;
    --paper: #f3f5f4;
    --panel: #ffffff;
    --line: #d5dcda;
    --line-soft: #e7ecea;
    --text: #1c2530;
    --muted: #687680;
    --glass: #23767d;
    --glass-deep: #1a5a60;
    --glass-wash: #e2efef;
    --brass: #a9782a;
    --brass-wash: #f6eedd;
    --danger: #a93a2c;
    --danger-wash: #f7e4e0;
    --ok: #2e7d4f;
    --ok-wash: #e1f0e6;

    --r-sm: 4px;
    --r-md: 6px;
    --sidebar: 228px;
    --font: "Vazir", Tahoma, "Segoe UI", sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }

html { font-size: 14px; }

body {
    margin: 0;
    font-family: var(--font);
    font-size: 1rem;
    line-height: 1.75;
    color: var(--text);
    background: var(--paper);
    -webkit-font-smoothing: antialiased;
}

a { color: var(--glass-deep); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3 { margin: 0; line-height: 1.4; font-weight: 700; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1rem; font-weight: 500; }

:focus-visible { outline: 2px solid var(--glass); outline-offset: 2px; }

.muted { color: var(--muted); }
.small { font-size: .88rem; }
.ltr { direction: ltr; unicode-bidi: embed; display: inline-block; }
.nowrap { white-space: nowrap; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------------------------------------------------------------- چیدمان */

.app { display: flex; min-height: 100vh; }

.sidebar {
    width: var(--sidebar);
    flex-shrink: 0;
    background: var(--ink);
    color: #cfd6dc;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
}

.brand { padding: 22px 22px 18px; border-bottom: 1px solid var(--ink-3); }
.brand strong { display: block; color: #fff; font-size: 1.15rem; }
.brand span { font-size: .82rem; color: #8e9aa5; }

.nav { padding: 14px 10px; display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav a {
    display: flex; align-items: center; gap: 10px;
    padding: 8px 12px; border-radius: var(--r-sm);
    color: #cfd6dc; text-decoration: none;
}
.nav a:hover { background: var(--ink-2); color: #fff; }
.nav a.active { background: var(--ink-2); color: #fff; box-shadow: inset -3px 0 0 var(--glass); }
.nav .count { margin-inline-start: auto; font-size: .8rem; color: #8e9aa5; }
.nav .count.alert { color: #f0b4aa; }
.nav-sep { height: 1px; background: var(--ink-3); margin: 10px 12px; }

.me { padding: 14px 22px; border-top: 1px solid var(--ink-3); font-size: .88rem; }
.me strong { color: #fff; display: block; font-weight: 500; }
.me button { background: none; border: 0; color: #8e9aa5; padding: 0; font: inherit; cursor: pointer; }
.me button:hover { color: #fff; }

.main { flex: 1; min-width: 0; padding: 26px 32px 60px; }

.page-head { display: flex; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 22px; }
.page-head .grow { flex: 1; min-width: 200px; }
.page-head p { margin: 2px 0 0; color: var(--muted); }

.menu-toggle { display: none; }

@media (max-width: 900px) {
    .app { display: block; }
    .sidebar { position: fixed; inset: 0 auto 0 0; right: 0; left: auto; transform: translateX(100%); transition: transform .2s; z-index: 50; }
    .sidebar.open { transform: none; }
    .menu-toggle { display: inline-flex; }
    .main { padding: 18px 16px 50px; }
}

/* ---------------------------------------------------------------- پنل‌ها */

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-md); }
.panel + .panel { margin-top: 18px; }
.panel-head { display: flex; align-items: center; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--line-soft); }
.panel-head h2 { font-size: 1.05rem; flex: 1; }
.panel-body { padding: 18px; }

.grid-2 { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 18px; align-items: start; }
@media (max-width: 1100px) { .grid-2 { grid-template-columns: 1fr; } }

/* ---------------------------------------------------------------- دکمه‌ها */

.btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 7px 16px; border-radius: var(--r-sm);
    border: 1px solid var(--line); background: var(--panel); color: var(--text);
    font: inherit; font-weight: 500; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { border-color: var(--muted); text-decoration: none; }
.btn-primary { background: var(--glass); border-color: var(--glass); color: #fff; }
.btn-primary:hover { background: var(--glass-deep); border-color: var(--glass-deep); }
.btn-danger { color: var(--danger); }
.btn-danger:hover { border-color: var(--danger); }
.btn-sm { padding: 3px 10px; font-size: .88rem; }
.btn[disabled] { opacity: .6; cursor: default; }

.link-btn { background: none; border: 0; padding: 0; color: var(--danger); font: inherit; font-size: .85rem; cursor: pointer; }

/* ---------------------------------------------------------------- فرم */

.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px 18px; }
.form-grid .wide { grid-column: 1 / -1; }

.field label, .field .label { display: flex; align-items: center; gap: 6px; font-size: .88rem; color: var(--muted); margin-bottom: 4px; }
.field .req { color: var(--danger); }

.input, select.input, textarea.input {
    width: 100%; padding: 7px 10px;
    border: 1px solid var(--line); border-radius: var(--r-sm);
    background: #fff; color: var(--text); font: inherit;
}
textarea.input { min-height: 78px; resize: vertical; }
.input:focus { border-color: var(--glass); outline: none; box-shadow: 0 0 0 3px var(--glass-wash); }
.input[readonly] { background: var(--paper); color: var(--muted); }
.input.is-invalid { border-color: var(--danger); }
.input-date { direction: ltr; text-align: right; }

.field .value { padding: 7px 0; min-height: 38px; white-space: pre-line; }
.field .value:empty::before { content: "—"; color: var(--line); }

.error { color: var(--danger); font-size: .85rem; margin-top: 3px; }

/* فیلد قفل‌شده: رنگ برنجی */
.field.locked label { color: var(--brass); }
.lock { width: 12px; height: 12px; flex-shrink: 0; }
.field.recent label::after { content: "تغییر اخیر"; font-size: .75rem; background: var(--brass-wash); color: var(--brass); padding: 0 6px; border-radius: 10px; }

.seg { display: inline-flex; border: 1px solid var(--line); border-radius: var(--r-sm); overflow: hidden; }
.seg label { margin: 0; padding: 6px 14px; cursor: pointer; color: var(--text); font-size: .95rem; }
.seg label + label { border-inline-start: 1px solid var(--line); }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg input:checked + span { color: var(--glass-deep); font-weight: 700; }
.seg label:has(input:checked) { background: var(--glass-wash); }
.seg input:focus-visible + span { outline: 2px solid var(--glass); outline-offset: 3px; }

.form-actions { display: flex; gap: 10px; align-items: center; padding: 14px 18px; border-top: 1px solid var(--line-soft); background: #fafbfb; border-radius: 0 0 var(--r-md) var(--r-md); }

.repeater-row { display: grid; gap: 10px; align-items: end; padding: 10px 0; border-bottom: 1px dashed var(--line-soft); }
.repeater-row:last-child { border-bottom: 0; }

.check { display: inline-flex; gap: 8px; align-items: center; cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--glass); }

/* ---------------------------------------------------------------- جدول */

.table-wrap { overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; }
.table th { text-align: right; font-weight: 500; font-size: .85rem; color: var(--muted); padding: 10px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table td { padding: 11px 14px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: #f8faf9; }
.table .row-link { color: var(--text); font-weight: 500; }

.empty { padding: 40px 18px; text-align: center; color: var(--muted); }

/* ---------------------------------------------------------------- برچسب‌ها */

.tag { display: inline-block; padding: 0 8px; border-radius: 10px; font-size: .8rem; background: var(--line-soft); color: var(--muted); white-space: nowrap; }
.tag.glass { background: var(--glass-wash); color: var(--glass-deep); }
.tag.brass { background: var(--brass-wash); color: var(--brass); }
.tag.danger { background: var(--danger-wash); color: var(--danger); }
.tag.ok { background: var(--ok-wash); color: var(--ok); }

.overdue { color: var(--danger); font-weight: 500; }

/* ---------------------------------------------------------------- فیلتر */

.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line-soft); }
.filters .input { width: auto; min-width: 140px; }
.filters .search { flex: 1; min-width: 220px; }

.tabs-inline { display: flex; gap: 4px; flex-wrap: wrap; }
.tabs-inline a { padding: 4px 12px; border-radius: 14px; color: var(--muted); font-size: .92rem; }
.tabs-inline a:hover { background: var(--line-soft); text-decoration: none; }
.tabs-inline a.active { background: var(--ink); color: #fff; }

/* ---------------------------------------------------------------- پیام‌ها */

.flash { padding: 10px 16px; border-radius: var(--r-sm); margin-bottom: 16px; border: 1px solid; }
.flash.success { background: var(--ok-wash); border-color: #bcdcc7; color: #1f5a37; }
.flash.warning { background: var(--brass-wash); border-color: #e6d3ad; color: #6f4f18; }
.flash.error { background: var(--danger-wash); border-color: #e7bdb5; color: #7c2a20; }
.flash ul { margin: 4px 0 0; padding-inline-start: 18px; }

/* ---------------------------------------------------------------- خط تولید (مراحل سفارش)
   عنصر اصلی طراحی: هر سفارش یک ریل ۸ قسمتی است.
   سبزآبی = انجام شده، برنجی = مرحله‌ی جاری، هاشور = برای این سفارش لازم نیست. */

.track { display: grid; grid-template-columns: repeat(8, 1fr); gap: 2px; min-width: 120px; }
.track i { display: block; height: 6px; background: var(--line); }
.track i:first-child { border-radius: 0 2px 2px 0; }
.track i:last-child { border-radius: 2px 0 0 2px; }
.track i.done { background: var(--glass); }
.track i.current { background: var(--brass); }
.track i.skip { background: repeating-linear-gradient(-45deg, var(--line-soft) 0 2px, var(--line) 2px 3px); }
.track-caption { font-size: .8rem; color: var(--muted); margin-top: 3px; }
.track-caption b { color: var(--brass); font-weight: 500; }

/* نسخه‌ی بزرگ در صفحه‌ی سفارش */
.rail { display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); gap: 3px; }
.rail .st { padding-top: 12px; position: relative; }
.rail .st::before { content: ""; position: absolute; inset: 0 0 auto 0; height: 8px; background: var(--line); }
.rail .st.done::before { background: var(--glass); }
.rail .st.current::before { background: var(--brass); }
.rail .st.skip::before { background: repeating-linear-gradient(-45deg, var(--line-soft) 0 3px, var(--line) 3px 4px); }
.rail .st strong { display: block; font-size: .92rem; font-weight: 500; }
.rail .st.current strong { color: var(--brass); font-weight: 700; }
.rail .st.skip strong, .rail .st.pending strong { color: var(--muted); font-weight: 400; }
.rail .st span { font-size: .8rem; color: var(--muted); }
@media (max-width: 700px) {
    .rail { grid-template-columns: repeat(4, 1fr); row-gap: 14px; }
}

/* داشبورد: خط تولید کل کارگاه */
.line-board { display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-md); overflow: hidden; }
.line-board a { position: relative; padding: 18px 14px 16px; color: var(--text); text-decoration: none; border-inline-start: 1px solid var(--line-soft); }
.line-board a:first-child { border-inline-start: 0; }
.line-board a::before { content: ""; position: absolute; inset: 0 0 auto 0; height: 4px; background: var(--line); }
.line-board a.busy::before { background: var(--glass); }
.line-board a.mine { background: linear-gradient(var(--brass-wash), var(--panel) 70%); }
.line-board a.mine::before { background: var(--brass); }
.line-board a:hover { background: #f8faf9; }
.line-board .n { display: block; font-size: 2.1rem; font-weight: 700; line-height: 1.2; font-variant-numeric: tabular-nums; }
.line-board .n.zero { color: var(--line); }
.line-board .l { font-size: .92rem; }
.line-board .mine-tag { display: block; font-size: .75rem; color: var(--brass); }
@media (max-width: 1100px) { .line-board { grid-template-columns: repeat(4, 1fr); } .line-board a:nth-child(5) { border-inline-start: 0; } .line-board a:nth-child(n+5) { border-top: 1px solid var(--line-soft); } }
@media (max-width: 560px) { .line-board { grid-template-columns: repeat(2, 1fr); } }

.stats { display: flex; gap: 28px; flex-wrap: wrap; margin: 14px 2px 24px; color: var(--muted); }
.stats b { color: var(--text); font-size: 1.15rem; margin-inline-end: 4px; }
.stats a { color: inherit; }
.stats .alert b { color: var(--danger); }

/* ---------------------------------------------------------------- سفارش: تب‌ها */

.tabbar { display: flex; gap: 0; border-bottom: 1px solid var(--line); padding: 0 12px; overflow-x: auto; }
.tabbar a { padding: 12px 16px; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabbar a:hover { color: var(--text); text-decoration: none; }
.tabbar a.active { color: var(--text); border-bottom-color: var(--glass); font-weight: 500; }
.tabbar .ro { font-size: .75rem; color: var(--muted); margin-inline-start: 4px; }
.tab-pane { display: none; }
.tab-pane.active { display: block; }

.files { display: flex; flex-direction: column; gap: 6px; margin-bottom: 8px; }
.file { display: flex; gap: 10px; align-items: center; padding: 6px 10px; border: 1px solid var(--line-soft); border-radius: var(--r-sm); background: #fafbfb; }
.file a { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file .missing { flex: 1; color: var(--muted); }
.file-add { display: grid; grid-template-columns: 1fr 1fr auto; gap: 8px; margin-top: 6px; }
@media (max-width: 600px) { .file-add { grid-template-columns: 1fr; } }

/* تاریخچه */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { display: grid; grid-template-columns: 130px 1fr; gap: 14px; padding: 10px 18px; border-bottom: 1px solid var(--line-soft); }
.timeline li:last-child { border-bottom: 0; }
.timeline .when { font-size: .85rem; color: var(--muted); }
.timeline .what b { font-weight: 500; }
.timeline .old { text-decoration: line-through; color: var(--muted); }
.timeline .arrow { color: var(--muted); margin: 0 6px; }
.timeline li.recent { background: #fdfaf3; }
@media (max-width: 600px) { .timeline li { grid-template-columns: 1fr; gap: 0; } }

/* تعریف‌ها (صفحه‌ی مشتری) */
.dl { display: grid; grid-template-columns: 130px 1fr; gap: 8px 14px; margin: 0; }
.dl dt { color: var(--muted); font-size: .9rem; }
.dl dd { margin: 0; }

/* ---------------------------------------------------------------- صفحه‌بندی */

.pager { display: flex; gap: 4px; flex-wrap: wrap; justify-content: center; padding: 16px; }
.pager a, .pager span { min-width: 34px; text-align: center; padding: 4px 10px; border-radius: var(--r-sm); border: 1px solid var(--line); color: var(--text); }
.pager a:hover { border-color: var(--glass); text-decoration: none; }
.pager .current { background: var(--ink); border-color: var(--ink); color: #fff; }
.pager .disabled { color: var(--line); }

/* ---------------------------------------------------------------- جستجوی مشتری */

.picker { position: relative; }
.picker-list { position: absolute; z-index: 20; inset: calc(100% + 2px) 0 auto 0; background: #fff; border: 1px solid var(--line); border-radius: var(--r-sm); max-height: 280px; overflow-y: auto; box-shadow: 0 8px 24px rgba(28, 37, 48, .12); }
.picker-list button { display: flex; width: 100%; gap: 10px; justify-content: space-between; padding: 8px 12px; border: 0; background: none; font: inherit; text-align: right; cursor: pointer; }
.picker-list button:hover, .picker-list button.active { background: var(--glass-wash); }
.picker-list .empty { padding: 12px; }
.picker-group { position: sticky; top: 0; padding: 4px 12px; font-size: 12px; font-weight: 700; color: var(--muted, #6b7280); background: #f3f5f6; border-bottom: 1px solid var(--line); }
.product-picker input[type=text], .desc-picker input[type=text] { padding-left: 34px; }
.desc-picker .picker-list button span { white-space: normal; }
.picker-toggle { position: absolute; left: 4px; top: 4px; bottom: 4px; width: 28px; border: 0; background: none; color: var(--muted, #6b7280); font-size: 14px; cursor: pointer; border-radius: var(--r-sm); }
.picker-toggle:hover { background: var(--glass-wash, #eef2f3); }

/* ---------------------------------------------------------------- تقویم شمسی */

.jcal { position: absolute; z-index: 30; width: 260px; background: #fff; border: 1px solid var(--line); border-radius: var(--r-md); box-shadow: 0 10px 28px rgba(28, 37, 48, .16); padding: 10px; direction: rtl; }
.jcal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.jcal-head strong { font-weight: 500; }
.jcal-head button, .jcal-foot button { border: 0; background: none; font: inherit; cursor: pointer; padding: 2px 8px; border-radius: var(--r-sm); color: var(--glass-deep); }
.jcal-head button:hover, .jcal-foot button:hover { background: var(--glass-wash); }
.jcal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; text-align: center; }
.jcal-grid .wd { font-size: .75rem; color: var(--muted); padding: 2px 0; }
.jcal-grid button { border: 0; background: none; font: inherit; padding: 5px 0; border-radius: var(--r-sm); cursor: pointer; }
.jcal-grid button:hover { background: var(--glass-wash); }
.jcal-grid button.today { box-shadow: inset 0 0 0 1px var(--glass); }
.jcal-grid button.sel { background: var(--glass); color: #fff; }
.jcal-grid button.fri { color: var(--danger); }
.jcal-foot { display: flex; justify-content: space-between; margin-top: 6px; border-top: 1px solid var(--line-soft); padding-top: 6px; }

/* ---------------------------------------------------------------- ورود */

.login-page { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr); }
.login-side { background: var(--ink); color: #cfd6dc; padding: 48px; display: flex; flex-direction: column; justify-content: space-between; }
.login-side h1 { color: #fff; font-size: 1.9rem; }
.login-side p { max-width: 34ch; }
.login-side .track { max-width: 320px; }
.login-side .track i { height: 8px; background: var(--ink-3); }
.login-side .track i.done { background: var(--glass); }
.login-side .track i.current { background: var(--brass); }
.login-form { display: flex; align-items: center; justify-content: center; padding: 32px; }
.login-form form { width: 100%; max-width: 340px; display: flex; flex-direction: column; gap: 16px; }
@media (max-width: 800px) { .login-page { grid-template-columns: 1fr; } .login-side { padding: 28px; gap: 20px; } }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
@media (max-width: 700px) { .repeater-row { grid-template-columns: 1fr !important; } }

/* ---------------------------------------------------------------- فاز ۳: فاکتور */
.num { text-align: left; font-variant-numeric: tabular-nums; direction: ltr; }
.table th.num { text-align: left; }
.inv-table td { padding: 6px 8px; vertical-align: top; }
.inv-table .input { padding: 5px 8px; }
.input.money { direction: ltr; text-align: left; font-variant-numeric: tabular-nums; }
.inv-totals { margin-inline-start: auto; max-width: 440px; padding: 12px 18px 16px; }
.inv-totals .line { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 4px 0; }
.inv-totals .line .input { max-width: 170px; }
.inv-totals .line b, .inv-totals .line > span:last-child { font-variant-numeric: tabular-nums; }
.inv-totals .grand { border-top: 2px solid var(--ink); margin-top: 6px; padding-top: 8px; font-size: 1.1rem; }
.balance { font-size: 1.3rem; font-weight: 700; }
.balance.due { color: var(--danger); }

/* ---------------------------------------------------------------- فاز ۴: گزارش‌ها */
.report-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.report-card { display: flex; flex-direction: column; gap: 6px; padding: 18px; color: var(--text); text-decoration: none; border-top: 3px solid var(--glass); }
.report-card:hover { text-decoration: none; border-color: var(--glass); box-shadow: 0 4px 16px rgba(28, 37, 48, .06); }
.report-card strong { font-size: 1.05rem; }
.report-card span { color: var(--muted); font-size: .9rem; }
.report-card + .report-card { margin-top: 0; }

.report-filter { flex-wrap: wrap; }
.report-filter .custom-range { display: inline-flex; gap: 6px; align-items: center; }
.report-filter .custom-range[hidden] { display: none; }

.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 14px; margin: 18px 0; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-md); padding: 14px 16px; display: flex; flex-direction: column; }
.kpi span { color: var(--muted); font-size: .88rem; }
.kpi b { font-size: 1.45rem; font-variant-numeric: tabular-nums; line-height: 1.5; }
.kpi small { color: var(--muted); font-size: .8rem; }
.kpi.due b { color: var(--danger); }

.bar { display: inline-block; width: 100%; height: 8px; background: var(--line-soft); border-radius: 4px; overflow: hidden; vertical-align: middle; }
.bar i { display: block; height: 100%; background: var(--glass); border-radius: 4px; min-width: 2px; }
.bar.debtor i { background: var(--danger); }
.bar.creditor i { background: var(--brass); }
.bar.cleared i { background: var(--ok); }
.bar-row { display: grid; grid-template-columns: minmax(120px, 1fr) 2fr auto; gap: 12px; align-items: center; padding: 6px 0; }
.bar-row b { white-space: nowrap; }
td .bar { width: 80px; }

.matrix td, .matrix th { padding: 7px 10px; font-size: .88rem; }
.matrix td[style*="--heat"] { background: color-mix(in srgb, var(--glass) var(--heat), transparent); }

.legend { display: flex; gap: 14px; align-items: center; font-size: .88rem; color: var(--muted); margin-bottom: 8px; }
.legend .sw { display: inline-block; width: 12px; height: 12px; border-radius: 2px; }
.sw.sales { background: var(--glass); }
.sw.received { background: var(--brass); }
.month-chart { display: flex; gap: 6px; align-items: flex-end; height: 220px; padding-top: 10px; overflow-x: auto; }
.month-chart .col { flex: 1; min-width: 44px; height: 100%; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.month-chart .bars { flex: 1; width: 100%; display: flex; align-items: flex-end; justify-content: center; gap: 3px; }
.month-chart .bars i { width: 40%; max-width: 18px; border-radius: 2px 2px 0 0; min-height: 1px; }
.month-chart .bars i.sales { background: var(--glass); }
.month-chart .bars i.received { background: var(--brass); }
.month-chart span { font-size: .72rem; color: var(--muted); white-space: nowrap; }
tfoot th { border-top: 1px solid var(--line); }
.inv-totals .pct { width: 56px; display: inline-block; padding: 3px 6px; font-size: .85rem; direction: ltr; text-align: center; margin-inline-start: 6px; }

/* ---------------------------------------------------------------- فاز ۵ */
.main-wrap { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.main-wrap .main { padding-top: 22px; }
.topbar { display: flex; align-items: center; gap: 14px; padding: 10px 32px; background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.top-search { flex: 1; max-width: 420px; }
.top-actions { display: flex; align-items: center; gap: 14px; margin-inline-start: auto; }
.bell { position: relative; color: var(--muted); display: inline-flex; padding: 4px; border-radius: 50%; }
.bell:hover { color: var(--ink); background: var(--line-soft); }
.bell .badge { position: absolute; top: -4px; inset-inline-end: -6px; background: var(--danger); color: #fff; font-size: .7rem; min-width: 18px; height: 18px; line-height: 18px; text-align: center; border-radius: 9px; padding: 0 4px; }
.me-name { font-size: .92rem; }
.nav-group { font-size: .75rem; color: #7c8894; padding: 12px 12px 4px; letter-spacing: 0; }
.nav { overflow-y: auto; }
@media (max-width: 900px) { .topbar { padding: 10px 16px; } .me-name { display: none; } }

.list-toolbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 10px 18px; border-bottom: 1px solid var(--line-soft); }
.list-toolbar .quick-search { flex: 1; min-width: 200px; max-width: 360px; }
.toolbar-actions { display: flex; gap: 8px; align-items: center; margin-inline-start: auto; }
.filter-panel { padding: 16px 18px; background: #f8faf9; border-bottom: 1px solid var(--line-soft); }
.filter-panel[hidden] { display: none; }
.range { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.range:has(> :nth-child(3)) { grid-template-columns: 1.2fr .8fr 1.2fr; }

.contact-groups { display: grid; grid-template-columns: repeat(auto-fill, minmax(420px, 1fr)); gap: 18px 28px; }
.contact-group-head { display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid var(--line-soft); padding-bottom: 4px; }
@media (max-width: 700px) { .contact-groups { grid-template-columns: 1fr; } }

.reminder { display: flex; gap: 12px; align-items: flex-start; padding: 10px 18px; border-bottom: 1px solid var(--line-soft); }
.reminder:last-child { border-bottom: 0; }
.reminder.due { background: #fdf5f3; }
.reminder.done { opacity: .6; }
.reminder .grow { flex: 1; min-width: 0; }
.reminder .tick { width: 22px; height: 22px; border: 2px solid var(--line); border-radius: 50%; background: #fff; cursor: pointer; color: var(--ok); font-weight: 700; line-height: 1; padding: 0; margin-top: 2px; }
.reminder .tick:hover { border-color: var(--ok); }

.notif button { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; width: 100%; text-align: right; padding: 10px 18px; border: 0; border-bottom: 1px solid var(--line-soft); background: none; font: inherit; cursor: pointer; }
.notif button:hover { background: #f8faf9; }
.notif.unread button { background: var(--glass-wash); }

.board { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(230px, 1fr); gap: 12px; overflow-x: auto; padding-bottom: 8px; }
.board-col { background: var(--line-soft); border-radius: var(--r-md); padding: 10px; display: flex; flex-direction: column; gap: 8px; min-height: 120px; }
.board-col header { display: flex; flex-direction: column; padding: 2px 4px 6px; border-bottom: 2px solid var(--glass); }
.board .card { display: flex; flex-direction: column; gap: 2px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-sm); padding: 8px 10px; color: var(--text); text-decoration: none; }
.board .card:hover { border-color: var(--glass); text-decoration: none; }

.lookup-types { display: flex; flex-direction: column; padding: 8px; }
.lookup-types a { padding: 6px 12px; border-radius: var(--r-sm); color: var(--text); }
.lookup-types a.active { background: var(--glass-wash); color: var(--glass-deep); font-weight: 500; }
.lookup-types a:hover { text-decoration: none; background: var(--line-soft); }

.recent-list a { display: block; padding: 6px 18px; border-bottom: 1px solid var(--line-soft); color: var(--text); }
.recent-list a:hover { background: #f8faf9; text-decoration: none; }

/* ================================================================ فاز ۶: منوی رنگی و بخش‌ها */
[hidden] { display: none !important; }

.sidebar { background: #fff; color: var(--text); border-inline-start: 1px solid var(--line); width: 244px; }
.brand { display: block; text-decoration: none; border-bottom: 1px solid var(--line-soft); }
.brand:hover { text-decoration: none; }
.brand strong { color: var(--ink); font-size: 1.2rem; }
.brand span { color: var(--muted); }
.nav { padding: 8px 8px 24px; gap: 0; }
.nav-section { padding: 4px 0 6px; border-radius: 10px; }
.nav-section + .nav-section { border-top: 1px dashed var(--line-soft); }
.nav-section.is-current { background: color-mix(in srgb, var(--c) 5%, white); }
.nav-head { display: flex; align-items: center; gap: 8px; padding: 8px 8px 4px; font-weight: 700; font-size: .88rem; color: var(--c); }
.nav-icon { width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center; color: var(--c); background: color-mix(in srgb, var(--c) 14%, white); flex-shrink: 0; }
.nav .nav-item { display: flex; align-items: center; gap: 6px; margin: 1px 0; margin-inline-start: 36px; padding: 5px 10px; border-radius: 7px; color: #334155; font-size: .95rem; text-decoration: none; box-shadow: none; }
.nav .nav-item:hover { background: color-mix(in srgb, var(--c) 10%, white); color: var(--ink); }
.nav .nav-item.active { background: var(--c); color: #fff; font-weight: 500; }
.nav-item .count { margin-inline-start: auto; background: #dc2626; color: #fff; border-radius: 10px; padding: 0 7px; font-size: .75rem; line-height: 1.6; }
.nav-item.active .count { background: #fff; color: var(--c); }

.topbar { border-top: 3px solid var(--accent); }
.page-head h1 { border-inline-start: 4px solid var(--accent); padding-inline-start: 12px; }
.btn-primary { background: var(--accent, var(--glass)); border-color: var(--accent, var(--glass)); }
.btn-primary:hover { background: var(--accent, var(--glass)); border-color: var(--accent, var(--glass)); filter: brightness(.9); }
.tabbar a.active { border-bottom-color: var(--accent); }
.help-link { display: inline-flex; gap: 4px; align-items: center; color: #a16207; font-size: .9rem; padding: 3px 10px; border: 1px solid #fde68a; background: #fefce8; border-radius: 14px; }
.help-link:hover { text-decoration: none; background: #fef9c3; }
@media (max-width: 900px) { .sidebar { width: 270px; } }

/* کاربران آنلاین */
.online-strip { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-md); padding: 10px 14px; margin-bottom: 18px; }
.online-title { font-weight: 500; display: inline-flex; align-items: center; gap: 6px; margin-inline-end: 6px; }
.online-strip .dot, .person.online::before { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: #22c55e; box-shadow: 0 0 0 3px #dcfce7; }
.person { display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; border-radius: 14px; background: var(--line-soft); font-size: .88rem; color: var(--muted); }
.person.online { background: #f0fdf4; color: #166534; }
.person.online::before { content: ""; }
.person small { font-size: .75rem; }

/* پیامک */
.placeholders { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: .88rem; color: var(--muted); }
.placeholders code { background: var(--line-soft); padding: 0 6px; border-radius: 4px; color: var(--ink); font-family: inherit; }
.sms-event { border: 1px solid var(--line-soft); border-radius: var(--r-md); padding: 12px; background: #fafbfb; }
.sms-event textarea { margin-top: 8px; }

/* رخدادها */
.audit .tag { margin-inline-end: 6px; }
.tag.ev-created { background: var(--ok-wash); color: var(--ok); }
.tag.ev-deleted, .tag.ev-login_failed { background: var(--danger-wash); color: var(--danger); }
.tag.ev-updated { background: var(--brass-wash); color: var(--brass); }
.tag.ev-sms { background: #ecfeff; color: #0e7490; }
.audit details { margin-top: 4px; }
.audit .changes { margin: 4px 0 0; padding-inline-start: 18px; }
.audit .changes .old { text-decoration: line-through; color: var(--muted); }

/* راهنما */
.help-layout { display: grid; grid-template-columns: 250px minmax(0, 1fr); gap: 18px; align-items: start; }
.help-toc { position: sticky; top: 80px; padding: 8px; display: flex; flex-direction: column; }
.help-toc a { padding: 6px 12px; border-radius: 6px; color: var(--text); }
.help-toc a:hover { background: var(--line-soft); text-decoration: none; }
.help-toc a.active { background: #fefce8; color: #a16207; font-weight: 500; }
.help-body { padding: 22px 26px; line-height: 2; }
.help-body h2 { font-size: 1.25rem; margin: 22px 0 8px; }
.help-body h2:first-child { margin-top: 0; }
.help-body h3 { margin: 16px 0 6px; font-weight: 700; }
.help-body ol, .help-body ul { padding-inline-start: 22px; margin: 6px 0 12px; }
.help-body li { margin-bottom: 4px; }
.help-body .tip { background: #fefce8; border: 1px solid #fde68a; border-radius: 8px; padding: 10px 14px; margin: 12px 0; }
.help-body .warn { background: var(--danger-wash); border: 1px solid #e7bdb5; border-radius: 8px; padding: 10px 14px; margin: 12px 0; }
.help-body kbd { background: var(--line-soft); border: 1px solid var(--line); border-radius: 4px; padding: 0 6px; font-family: inherit; font-size: .9em; }
.help-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; }
.help-card { display: flex; flex-direction: column; gap: 4px; padding: 16px; color: var(--text); border-top: 3px solid var(--c, #ca8a04); }
.help-card:hover { text-decoration: none; box-shadow: 0 4px 16px rgba(28, 37, 48, .06); }
.help-card span { color: var(--muted); font-size: .9rem; }
.help-card + .help-card { margin-top: 0; }
@media (max-width: 900px) { .help-layout { grid-template-columns: 1fr; } .help-toc { position: static; } }

/* ================================================================ فاز ۷: وظایف، پروژه‌ها، پرداخت چندگانه */
.task-list { display: flex; flex-direction: column; }
.task-item { display: flex; gap: 12px; align-items: center; padding: 11px 18px; border-bottom: 1px solid var(--line-soft); color: var(--text); text-decoration: none; border-inline-start: 3px solid transparent; }
.task-item:hover { background: #f8faf9; text-decoration: none; }
.task-item .grow { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.task-item .meta { font-size: .85rem; color: var(--muted); }
.task-item.p-urgent { border-inline-start-color: #dc2626; }
.task-item.p-high { border-inline-start-color: #f59e0b; }
.task-item.unseen b::after { content: "جدید"; font-size: .7rem; font-weight: 500; background: #dbeafe; color: #1d4ed8; padding: 0 6px; border-radius: 8px; margin-inline-start: 6px; }
.task-item.overdue-task { background: #fdf5f3; }
.board .task-item { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-sm); padding: 8px 10px; }
.task-status { width: 12px; height: 12px; border-radius: 50%; border: 2px solid var(--line); flex-shrink: 0; }
.task-status.s-doing { border-color: #0d9488; background: #99f6e4; }
.task-status.s-review { border-color: #7c3aed; background: #ddd6fe; }
.task-status.s-done { border-color: var(--ok); background: var(--ok); }
.task-status.s-canceled { border-color: var(--muted); background: var(--line); }
.tag.s-doing { background: #ccfbf1; color: #0f766e; }
.tag.s-review { background: #ede9fe; color: #6d28d9; }
.tag.s-done { background: var(--ok-wash); color: var(--ok); }
.tag.s-canceled { background: var(--line-soft); color: var(--muted); }
.tag.pr-urgent { background: #fee2e2; color: #b91c1c; }
.tag.pr-high { background: #fef3c7; color: #b45309; }
.tag.pr-low { background: var(--line-soft); color: var(--muted); }
.task-actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; padding: 12px 18px; margin-bottom: 18px; }
.task-actions form { margin: 0; }
.inline-form { display: flex; gap: 6px; align-items: center; }
.inline-form .input { width: 220px; }
.check-row { display: flex; gap: 12px; align-items: center; padding: 8px 18px; border-bottom: 1px solid var(--line-soft); margin: 0; }
.check-row .tick { width: 24px; height: 24px; border: 2px solid var(--line); border-radius: 6px; background: #fff; cursor: pointer; color: #fff; font-weight: 700; line-height: 1; padding: 0; flex-shrink: 0; }
.check-row .tick.done { background: var(--ok); border-color: var(--ok); }
.check-row .done-text { text-decoration: line-through; color: var(--muted); }

.pay-row { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)) auto; gap: 8px 10px; align-items: end; padding: 10px 0; border-bottom: 1px dashed var(--line-soft); }
.pay-row .field label { font-size: .8rem; }
.pay-row .pay-remove { grid-row: 1; grid-column: 4; }
.pay-actions { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; padding-top: 12px; }
.pay-actions .btn-primary { margin-inline-start: auto; }

/* ================================================================ موبایل و تبلت */
.icon-btn { background: none; border: 0; padding: 6px; color: var(--ink); cursor: pointer; border-radius: 8px; }
.icon-btn:hover { background: var(--line-soft); }
.drawer-close { display: none; }
.bottom-nav { display: none; }
.drawer-backdrop { position: fixed; inset: 0; background: rgba(15, 23, 42, .45); z-index: 45; }

/* تبلت عمودی و گوشی */
@media (max-width: 900px) {
    html { font-size: 15px; }
    .sidebar { position: fixed; top: 0; bottom: 0; right: 0; left: auto; width: min(300px, 86vw); height: 100%; transform: translateX(105%); transition: transform .22s ease; z-index: 50; box-shadow: -8px 0 30px rgba(15, 23, 42, .18); overflow-y: auto; }
    .sidebar.open { transform: none; }
    .drawer-close { display: block; position: absolute; top: 10px; left: 10px; width: 36px; height: 36px; border: 0; border-radius: 50%; background: var(--line-soft); font-size: 1.4rem; line-height: 1; cursor: pointer; }
    body.menu-open { overflow: hidden; }
    .menu-toggle { display: inline-flex; }

    .topbar { padding: 8px 12px; gap: 8px; flex-wrap: wrap; }
    .top-search { order: 10; flex-basis: 100%; max-width: none; }
    .top-actions { gap: 8px; }
    .help-link span, .me-name, .logout-form { display: none; }
    .help-link { padding: 5px 7px; }

    .main { padding: 14px 12px 90px; }
    .page-head { gap: 8px; margin-bottom: 14px; }
    .page-head .grow { flex-basis: 100%; }
    .page-head h1 { font-size: 1.3rem; }
    .page-head .btn, .page-head form { flex: 1 1 auto; }
    .page-head .btn { justify-content: center; }

    /* نوار پایین */
    .bottom-nav { display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 40; background: #fff; border-top: 1px solid var(--line); padding: 4px 4px calc(4px + env(safe-area-inset-bottom)); box-shadow: 0 -4px 16px rgba(15, 23, 42, .06); }
    .bottom-nav a, .bottom-nav button { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 5px 2px; color: var(--muted); font: inherit; font-size: .72rem; background: none; border: 0; border-radius: 10px; text-decoration: none; position: relative; cursor: pointer; }
    .bottom-nav a.active { color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, white); }
    .bottom-nav .dot-badge { position: absolute; top: 0; left: calc(50% - 20px); background: #dc2626; color: #fff; font-style: normal; font-size: .65rem; min-width: 16px; height: 16px; line-height: 16px; border-radius: 8px; padding: 0 3px; }

    .form-grid { grid-template-columns: 1fr 1fr; gap: 12px; }
    .form-grid .field[style*="span 2"] { grid-column: 1 / -1 !important; }
    .kpis { grid-template-columns: 1fr 1fr; }
    .board { grid-auto-columns: 82vw; }
    .help-toc { display: none; }
    .help-body { padding: 16px; }
}

/* گوشی */
@media (max-width: 640px) {
    /* جلوگیری از بزرگ‌نمایی خودکار iOS روی فیلدها */
    .input, select.input, textarea.input { font-size: 16px; min-height: 42px; }
    .btn { min-height: 40px; }
    .btn-sm { min-height: 34px; }
    .form-grid { grid-template-columns: 1fr; }
    .filters { flex-direction: column; align-items: stretch; }
    .filters .input, .filters .search, .filters .btn { width: 100%; min-width: 0; }
    .filters .tabs-inline, .list-toolbar { overflow-x: auto; flex-wrap: nowrap; }
    .list-toolbar .quick-search { max-width: none; flex-basis: 100%; }
    .toolbar-actions { margin-inline-start: 0; flex-wrap: wrap; }
    .tabbar a { padding: 10px 12px; }
    .panel-body { padding: 14px; }
    .panel-head { padding: 12px 14px; flex-wrap: wrap; }
    .grid-2 { gap: 14px; }
    .kpi b { font-size: 1.2rem; }
    .stats { gap: 10px 18px; }
    .timeline li { padding: 10px 14px; }
    .reminder, .task-item { padding: 10px 14px; }
    .task-item > .tag { display: none; }
    .inline-form { flex-direction: column; align-items: stretch; width: 100%; }
    .inline-form .input { width: 100%; }
    .dl { grid-template-columns: 110px 1fr; }
    .range { grid-template-columns: 1fr 1fr !important; }
    .pay-row { grid-template-columns: 1fr 1fr; }
    .pay-row .pay-remove { grid-row: auto; grid-column: auto; }
    .inv-totals { max-width: none; }
    .inv-totals .line .input { max-width: 150px; }
    .line-board .n { font-size: 1.6rem; }
    .contact-group .repeater-row { grid-template-columns: 1fr 1fr !important; }
    .rail .st strong { font-size: .8rem; }

    /* جدول‌ها به شکل کارت */
    table.cards thead { display: none; }
    table.cards, table.cards tbody, table.cards tr, table.cards td { display: block; width: 100%; }
    table.cards tr { border-bottom: 1px solid var(--line); padding: 8px 14px; }
    table.cards tr:hover { background: none; }
    table.cards td { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 3px 0; border: 0; text-align: left; }
    table.cards td::before { content: attr(data-label); color: var(--muted); font-size: .8rem; text-align: right; flex-shrink: 0; }
    table.cards td:first-child { font-weight: 500; }
    table.cards td[data-label=""]::before, table.cards td:not([data-label])::before { content: none; }
    table.cards td .track { width: 150px; }
    table.cards td.num { direction: rtl; }

    /* ردیف‌های فاکتور */
    .inv-table thead { display: none; }
    .inv-table, .inv-table tbody { display: block; }
    .inv-table tr.inv-row { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 8px; padding: 10px 14px; border-bottom: 1px solid var(--line); }
    .inv-table tr.inv-row td { display: block; padding: 0; border: 0; }
    .inv-table tr.inv-row td:first-child { grid-column: 1 / -1; }
    .inv-table tr.inv-row td[data-label]::before { content: attr(data-label); display: block; font-size: .75rem; color: var(--muted); }
    .inv-table tr.inv-row td:last-child { text-align: left; }

    .jcal { width: min(300px, calc(100vw - 16px)); }
    .jcal-grid button { padding: 8px 0; }
    .picker-list { max-height: 50vh; }
}

/* ================================================================ همگام‌سازی */
.sync-steps { margin: 0 0 16px; padding-inline-start: 20px; display: flex; flex-direction: column; gap: 16px; }
.sync-steps li::marker { font-weight: 700; color: var(--accent); }
.table.compact td, .table.compact th { padding: 5px 8px; font-size: .88rem; }
.sync-progress { display: flex; gap: 16px; align-items: center; margin-bottom: 18px; }
.spinner { width: 34px; height: 34px; border: 4px solid var(--line-soft); border-top-color: var(--accent); border-radius: 50%; animation: spin 1s linear infinite; flex-shrink: 0; }
@keyframes spin { to { transform: rotate(360deg); } }
tr.muted td { color: var(--muted); }

/* ================================================================ نگهداری سیستم */
.check-ok { color: var(--ok); font-weight: 700; font-size: 1.1rem; }
.check-bad { color: var(--danger); font-weight: 700; font-size: 1.1rem; }
.system-action { display: flex; gap: 12px; align-items: center; padding: 12px 18px; border-bottom: 1px solid var(--line-soft); margin: 0; }
.system-action .grow { flex: 1; }
.copy-box { display: flex; gap: 8px; align-items: center; background: var(--ink); color: #e2e8f0; border-radius: 8px; padding: 10px 12px; }
.copy-box code { flex: 1; font-family: Consolas, monospace; font-size: .82rem; word-break: break-all; text-align: left; }

/* فاز ۹: لیست فاکتورها — رنگ ردیف بر اساس نوع، ستون ارسال، جمع پایین لیست */
.invoice-list tr.row-proforma td { background: #f6f7f8; }
.invoice-list tr.row-invoice td { background: #e3effd; }
.invoice-list tr.row-proforma td:first-child { box-shadow: inset -4px 0 0 #b8c0c8; }
.invoice-list tr.row-invoice td:first-child { box-shadow: inset -4px 0 0 #3b82f6; }
.invoice-list tr.row-proforma:hover td { background: #eceff2; }
.invoice-list tr.row-invoice:hover td { background: #d2e5fb; }
.type-badge { display: inline-block; padding: 0 9px; border-radius: 10px; font-size: .8rem; font-weight: 600; white-space: nowrap; border: 1px solid; }
.type-badge.type-proforma { background: #eceff2; color: #4b5563; border-color: #cfd5db; }
.type-badge.type-invoice { background: #d6e6ff; color: #1d4ed8; border-color: #a9c8fb; }
.inv-legend { display: flex; flex-wrap: wrap; gap: 14px; align-items: center; padding: 8px 16px; font-size: .82rem; color: var(--muted); border-bottom: 1px solid var(--line-soft); }
.inv-legend .sw { display: inline-block; width: 14px; height: 14px; border-radius: 4px; vertical-align: -2px; border: 1px solid; }
.inv-legend .sw-proforma { background: #f6f7f8; border-color: #b8c0c8; }
.inv-legend .sw-invoice { background: #e3effd; border-color: #3b82f6; }
.invoice-list tfoot.list-totals th { background: #f1f5f4; font-weight: 700; padding: 12px 14px; border-top: 2px solid var(--line); font-size: .9rem; }
@media (max-width: 640px) {
    table.cards.invoice-list tr.row-proforma { background: #f6f7f8; border-right: 4px solid #b8c0c8; }
    table.cards.invoice-list tr.row-invoice { background: #e3effd; border-right: 4px solid #3b82f6; }
    table.cards.invoice-list tr td, table.cards.invoice-list tr:hover td { background: transparent; }
    table.cards.invoice-list tr td:first-child { box-shadow: none; }
    table.cards.invoice-list tfoot, table.cards.invoice-list tfoot tr, table.cards.invoice-list tfoot th { display: block; width: 100%; text-align: right; }
    table.cards.invoice-list tfoot th { padding: 6px 14px; border-top: 0; }
    table.cards.invoice-list tfoot tr { border-top: 2px solid var(--line); background: #f1f5f4; }
}
@media print { .invoice-list tr td { -webkit-print-color-adjust: exact; print-color-adjust: exact; } }

/* فاز ۹ (ز): پیگیری با شماره‌ی فاکتور */
.track-hint { background: #e3effd; border: 1px solid #a9c8fb; border-radius: var(--r-sm); padding: 10px 16px; margin-bottom: 16px; }
.track-hint > div { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.track-hint > div + div { margin-top: 8px; }
.track-card { border-top: 1px solid var(--line); padding-bottom: 8px; }
.track-head { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; padding: 14px 16px 6px; }
.track-no { font-size: 1.15rem; }
.track-no b { font-size: 1.35rem; }
.track-grid { display: flex; flex-wrap: wrap; gap: 10px 26px; padding: 6px 16px 10px; }
.track-grid > div { display: flex; flex-direction: column; }
.track-sub { font-size: .95rem; margin: 10px 16px 6px; }
.table tr.track-hit td { background: #fff3c4; }
.ref-no { font-size: 1.05rem; }
.ref-no b { font-size: 1.2rem; }

/* فرمول‌های فرم تولید */
.fx-badge { display: inline-block; font-family: serif; font-style: italic; font-weight: 700; color: #7c3aed; background: #f3e8ff; border-radius: 4px; padding: 0 5px; margin-inline-start: 4px; font-size: 12px; cursor: help; }
[data-fx-key] { background: #faf7ff; }
[data-fx-key].fx-manual { background: #fff8e6; border-color: #e0b44c; }
[data-fx-key].fx-updated { box-shadow: 0 0 0 2px #c4b5fd; transition: box-shadow .3s; }
.fx-reset { border: 0; background: none; color: #7c3aed; font: inherit; font-size: 12px; cursor: pointer; padding: 2px 4px; }
.fx-reset:hover { text-decoration: underline; }
.fx-cell { white-space: nowrap; }
.fx-err { color: #b91c1c; margin-top: 2px; }
.fx-manual-tag { font-size: 11px; color: #a16207; }
.tpl-fx { font-family: Consolas, "Courier New", monospace; direction: ltr; text-align: left; font-size: 12px; }
.tpl-fx.bad { border-color: #dc2626; background: #fff5f5; }
.tpl-fx-msg { color: #b91c1c; font-size: 11px; }
.tpl-fx-ok { color: #15803d; font-size: 11px; }

/* تنظیمات چاپ فاکتور */
.settings-sub { margin: 6px 0 0; padding-top: 12px; border-top: 1px solid var(--line-soft); font-size: 15px; }
.print-checks { display: flex; flex-wrap: wrap; gap: 6px 18px; margin: 4px 0; }
.seller-profile { border: 1px solid var(--line-soft); border-radius: 8px; padding: 6px 12px 10px; margin: 0; }
.seller-profile legend { font-weight: 700; padding: 0 6px; }
.seller-profile .form-grid { padding: 0; }

/* منوی کناری جمع‌شونده: هر گروه با کلیک باز و بسته می‌شود */
.nav-section > summary { list-style: none; cursor: pointer; user-select: none; border-radius: 8px; }
.nav-section > summary::-webkit-details-marker { display: none; }
.nav-section > summary:hover { background: color-mix(in srgb, var(--c) 8%, white); }
.nav-section > summary:focus-visible { outline: 2px solid var(--c); outline-offset: 1px; }
.nav-head .nav-label { flex: 1; }
.nav-head .nav-count { background: #dc2626; color: #fff; border-radius: 10px; padding: 0 7px; font-size: .72rem; line-height: 1.6; font-weight: 500; }
.nav-section[open] > summary .nav-count { display: none; }
.nav-chevron { width: 8px; height: 8px; border-inline-start: 2px solid #94a3b8; border-bottom: 2px solid #94a3b8; transform: rotate(45deg); transition: transform .15s; margin-inline-end: 4px; flex-shrink: 0; }
.nav-section:not([open]) > summary .nav-chevron { transform: rotate(135deg); }
.nav-section:not([open]) { padding-bottom: 2px; }

/* سفارش تکمیل/بایگانی/کنسل‌شده: آخر لیست و کم‌رنگ */
.table tr.order-closed td { opacity: .62; }
.table tr.order-closed td:last-child { opacity: 1; }

/* تابلوی مراحل سفارش */
.stage-board { display: flex; gap: 12px; overflow-x: auto; padding-bottom: 12px; align-items: flex-start; }
.stage-col { flex: 0 0 205px; background: #f3f5f6; border: 1px solid var(--line); border-radius: var(--r-md); padding: 8px; max-height: 75vh; overflow-y: auto; }
.stage-col header { display: flex; gap: 6px; align-items: center; padding: 4px 4px 8px; position: sticky; top: -8px; background: #f3f5f6; }
.stage-col header strong { flex: 1; }
.board-card { display: flex; flex-direction: column; gap: 2px; background: #fff; border: 1px solid var(--line); border-inline-start: 4px solid var(--glass, #2b7a78); border-radius: var(--r-sm); padding: 8px 10px; margin-bottom: 8px; color: var(--text); text-decoration: none; }
.board-card:hover { box-shadow: 0 4px 12px rgba(28, 37, 48, .1); text-decoration: none; }
.board-card.stale { border-inline-start-color: var(--danger, #b42318); }
.board-meta { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin-top: 4px; }
.board-empty { padding: 8px 4px; }
