/* ==========================================================================
   داشبورد فروشنده دیجی‌کالا — استایل اصلی
   پوستهٔ روشن/تیره: همهٔ رنگ‌ها از توکن‌های :root می‌آیند.
   ========================================================================== */

:root {
    color-scheme: light;

    --bg: #f4f6fa;
    --surface: #ffffff;
    --surface-2: #f8fafc;
    --surface-3: #f1f4f9;
    --text: #0f172a;
    --text-2: #334155;
    --muted: #64748b;
    --faint: #94a3b8;
    --line: #e4e8ef;
    --line-2: #eef1f6;
    --line-strong: #d3d9e4;

    --primary: #ef4056;
    --primary-2: #ff5a6e;
    --primary-dark: #d22f45;
    --primary-soft: #fff0f2;
    --primary-line: #fbd0d7;
    --primary-ink: #c02739;
    --ring: rgba(239, 64, 86, .2);

    --green: #0f9d58;
    --green-ink: #0a7040;
    --green-soft: #e8f7ee;
    --green-line: #bfe6cd;
    --red: #e5484d;
    --red-ink: #b42318;
    --red-soft: #fdecec;
    --red-line: #f6c9c7;
    --amber: #d97706;
    --amber-ink: #a15c07;
    --amber-soft: #fdf4e3;
    --amber-line: #f3ddb4;
    --blue: #2563eb;
    --blue-ink: #1d4ed8;
    --blue-soft: #eaf1fe;
    --blue-line: #cfdcfb;

    /* نمودار */
    --series-1: #e8384f;
    --series-2: #2563eb;
    --grid: #e8ecf2;

    --sidebar-1: #131a2b;
    --sidebar-2: #1a2337;
    --sidebar-line: rgba(255, 255, 255, .07);
    --sidebar-text: #aeb8cb;

    --code-bg: #0f172a;
    --code-text: #d7e0f0;
    --toast-bg: #0f172a;

    --radius: 14px;
    --radius-sm: 10px;
    --radius-xs: 8px;

    --shadow-sm: 0 1px 2px rgba(15, 23, 42, .05);
    --shadow: 0 1px 3px rgba(15, 23, 42, .06), 0 10px 26px -12px rgba(15, 23, 42, .18);
    --shadow-lg: 0 18px 45px -20px rgba(15, 23, 42, .35);

    --sidebar-w: 248px;
    --control-h: 40px;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        color-scheme: dark;

        --bg: #0b1120;
        --surface: #131c2e;
        --surface-2: #172136;
        --surface-3: #1c273e;
        --text: #e6ebf4;
        --text-2: #c3cbdb;
        --muted: #8b97ad;
        --faint: #637089;
        --line: #243049;
        --line-2: #1e293f;
        --line-strong: #33415c;

        --primary: #ef4056;
        --primary-2: #f25a6d;
        --primary-dark: #d22f45;
        --primary-soft: rgba(239, 64, 86, .14);
        --primary-line: rgba(239, 64, 86, .38);
        --primary-ink: #ff8d9b;
        --ring: rgba(239, 64, 86, .32);

        --green: #34d399;
        --green-ink: #6ee7b7;
        --green-soft: rgba(52, 211, 153, .12);
        --green-line: rgba(52, 211, 153, .3);
        --red: #f87171;
        --red-ink: #fca5a5;
        --red-soft: rgba(248, 113, 113, .12);
        --red-line: rgba(248, 113, 113, .32);
        --amber: #fbbf24;
        --amber-ink: #fcd34d;
        --amber-soft: rgba(251, 191, 36, .12);
        --amber-line: rgba(251, 191, 36, .3);
        --blue: #60a5fa;
        --blue-ink: #93c5fd;
        --blue-soft: rgba(96, 165, 250, .12);
        --blue-line: rgba(96, 165, 250, .3);

        --series-1: #ef4056;
        --series-2: #3b82f6;
        --grid: #222d44;

        --sidebar-1: #0d1424;
        --sidebar-2: #0d1424;
        --sidebar-line: rgba(255, 255, 255, .06);

        --code-bg: #0a0f1c;
        --toast-bg: #1f2a40;

        --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3);
        --shadow: 0 1px 3px rgba(0, 0, 0, .3), 0 10px 26px -12px rgba(0, 0, 0, .6);
        --shadow-lg: 0 18px 45px -20px rgba(0, 0, 0, .8);
    }
}

:root[data-theme="dark"] {
    color-scheme: dark;

    --bg: #0b1120;
    --surface: #131c2e;
    --surface-2: #172136;
    --surface-3: #1c273e;
    --text: #e6ebf4;
    --text-2: #c3cbdb;
    --muted: #8b97ad;
    --faint: #637089;
    --line: #243049;
    --line-2: #1e293f;
    --line-strong: #33415c;

    --primary: #ef4056;
    --primary-2: #f25a6d;
    --primary-dark: #d22f45;
    --primary-soft: rgba(239, 64, 86, .14);
    --primary-line: rgba(239, 64, 86, .38);
    --primary-ink: #ff8d9b;
    --ring: rgba(239, 64, 86, .32);

    --green: #34d399;
    --green-ink: #6ee7b7;
    --green-soft: rgba(52, 211, 153, .12);
    --green-line: rgba(52, 211, 153, .3);
    --red: #f87171;
    --red-ink: #fca5a5;
    --red-soft: rgba(248, 113, 113, .12);
    --red-line: rgba(248, 113, 113, .32);
    --amber: #fbbf24;
    --amber-ink: #fcd34d;
    --amber-soft: rgba(251, 191, 36, .12);
    --amber-line: rgba(251, 191, 36, .3);
    --blue: #60a5fa;
    --blue-ink: #93c5fd;
    --blue-soft: rgba(96, 165, 250, .12);
    --blue-line: rgba(96, 165, 250, .3);

    --series-1: #ef4056;
    --series-2: #3b82f6;
    --grid: #222d44;

    --sidebar-1: #0d1424;
    --sidebar-2: #0d1424;
    --sidebar-line: rgba(255, 255, 255, .06);

    --code-bg: #0a0f1c;
    --toast-bg: #1f2a40;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3);
    --shadow: 0 1px 3px rgba(0, 0, 0, .3), 0 10px 26px -12px rgba(0, 0, 0, .6);
    --shadow-lg: 0 18px 45px -20px rgba(0, 0, 0, .8);
}

* { box-sizing: border-box; }

/* مهم: صفت hidden باید همیشه برنده باشد، حتی وقتی کلاس‌هایی مثل display:flex داریم */
[hidden] { display: none !important; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: Vazirmatn, "Vazirmatn FD", "IRANSansX", "IRANSans", "Segoe UI", Tahoma, sans-serif;
    font-size: 14px;
    line-height: 1.8;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body { overflow-x: hidden; }

h1, h2, h3, h4 { margin: 0 0 12px; font-weight: 700; letter-spacing: -.01em; color: var(--text); line-height: 1.5; }
h1 { font-size: 22px; }
h2 { font-size: 20px; }
h3 { font-size: 15px; }
p { margin: 0 0 12px; }

a { color: var(--blue); }

code {
    background: var(--surface-3);
    padding: 2px 6px;
    border-radius: 6px;
    font-size: 12px;
    direction: ltr;
    display: inline-block;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

pre.code {
    background: var(--code-bg);
    color: var(--code-text);
    padding: 14px 16px;
    border-radius: var(--radius-sm);
    direction: ltr;
    text-align: left;
    overflow: auto;
    font-size: 12px;
    line-height: 1.7;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.muted { color: var(--muted); }
.ok-text { color: var(--green-ink); }
.gap-pos { color: var(--red-ink); font-weight: 600; }
.gap-neg { color: var(--green-ink); font-weight: 600; }
.gap-zero { color: var(--muted); font-weight: 600; }
.num { font-variant-numeric: tabular-nums; }

/* ---------- اسکرول‌بار ---------- */
* { scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent; }
*::-webkit-scrollbar { width: 9px; height: 9px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 999px; border: 2px solid transparent; background-clip: content-box; }
*::-webkit-scrollbar-thumb:hover { background: var(--faint); background-clip: content-box; }

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

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

.sidebar {
    width: var(--sidebar-w);
    flex: 0 0 var(--sidebar-w);
    background: linear-gradient(175deg, var(--sidebar-1), var(--sidebar-2));
    border-inline-end: 1px solid var(--sidebar-line);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    padding: 18px 14px;
    position: sticky;
    top: 0;
    height: 100vh;
    z-index: 20;
}

.brand {
    display: flex;
    align-items: center;
    gap: 11px;
    color: #fff;
    line-height: 1.35;
    padding: 4px 6px 18px;
    border-bottom: 1px solid var(--sidebar-line);
    margin-bottom: 16px;
}
.brand .logo {
    width: 36px; height: 36px; flex: none;
    border-radius: 11px;
    background: linear-gradient(140deg, var(--primary), #ff8a5b);
    display: grid; place-items: center;
    color: #fff; font-weight: 800; font-size: 16px;
    box-shadow: 0 6px 16px -6px rgba(239, 64, 86, .9);
}
.brand-text { font-size: 15px; font-weight: 800; }
.brand-text small { display: block; font-size: 11px; font-weight: 500; color: #8793aa; margin-top: 1px; }

.nav-label {
    font-size: 11px;
    font-weight: 600;
    color: #6b7790;
    padding: 0 10px 6px;
}

.sidebar nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
    display: flex;
    align-items: center;
    gap: 11px;
    background: transparent;
    border: 0;
    color: var(--sidebar-text);
    text-align: right;
    padding: 9px 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-family: inherit;
    font-size: 13.5px;
    font-weight: 500;
    transition: background .15s, color .15s;
    position: relative;
}
.nav-item .ico { width: 18px; height: 18px; flex: none; opacity: .8; transition: color .15s, opacity .15s; }
.nav-item .ico svg { width: 18px; height: 18px; display: block; }
.nav-item:hover { background: rgba(255, 255, 255, .05); color: #fff; }
.nav-item:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--primary); }
.nav-item.active {
    background: rgba(255, 255, 255, .08);
    color: #fff;
    font-weight: 600;
}
.nav-item.active .ico { opacity: 1; color: #ff6b7e; }
.nav-item.active::before {
    content: '';
    position: absolute;
    inset-inline-start: -14px;
    top: 9px; bottom: 9px;
    width: 3px;
    border-radius: 0 3px 3px 0;
    background: var(--primary);
}

.sidebar-foot {
    margin-top: auto;
    padding-top: 14px;
    border-top: 1px solid var(--sidebar-line);
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.sidebar-foot .btn { width: 100%; justify-content: flex-start; }
.sidebar-foot .btn svg { width: 16px; height: 16px; flex: none; }

.main { flex: 1; padding: 26px 30px 80px; min-width: 0; }
.main > * { max-width: 1560px; margin-inline: auto; }

.view { animation: view-in .22s ease; }
@keyframes view-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.view-head {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 14px 20px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}
.view-head h2 { margin: 0; }
.view-head > div:first-child { flex: 1 1 320px; min-width: 0; }
.view-sub { margin: 2px 0 0; color: var(--muted); font-size: 13px; max-width: 680px; }
.actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* ==========================================================================
   کارت‌ها
   ========================================================================== */

.card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 18px;
    box-shadow: var(--shadow-sm);
}
.card > h3:first-child {
    margin: 0 0 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--line-2);
    display: flex;
    align-items: center;
    gap: 8px;
}
.card.highlight { border-color: var(--primary); box-shadow: 0 0 0 4px var(--primary-soft); }
.card-desc { color: var(--muted); font-size: 13px; margin-top: -6px; }

.cards {
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 14px;
    margin-bottom: 18px;
}

.stat {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 16px 16px 14px;
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
    transition: box-shadow .18s, border-color .18s;
    --accent: var(--blue);
    --accent-soft: var(--blue-soft);
}
.stat:hover { box-shadow: var(--shadow); border-color: var(--line-strong); }
.stat-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.stat .l { color: var(--muted); font-size: 12.5px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat .ic {
    width: 34px; height: 34px; flex: none;
    border-radius: 10px;
    display: grid; place-items: center;
    background: var(--accent-soft);
    color: var(--accent);
}
.stat .ic svg { width: 18px; height: 18px; }
.stat .n { font-size: 26px; font-weight: 800; line-height: 1.3; letter-spacing: -.02em; margin-top: 4px; }
.stat .meter { height: 4px; border-radius: 999px; background: var(--accent-soft); overflow: hidden; margin-top: 8px; }
.stat .meter span { display: block; height: 100%; border-radius: 999px; background: var(--accent); }
.stat .stat-meta { font-size: 11.5px; color: var(--muted); margin-top: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.stat.k-total  { --accent: var(--blue);    --accent-soft: var(--blue-soft); }
.stat.k-active { --accent: var(--green);   --accent-soft: var(--green-soft); }
.stat.k-winner { --accent: var(--amber);   --accent-soft: var(--amber-soft); }
.stat.k-rival  { --accent: var(--primary); --accent-soft: var(--primary-soft); }
.stat.k-out    { --accent: var(--red);     --accent-soft: var(--red-soft); }
.stat.k-arch   { --accent: var(--muted);   --accent-soft: var(--surface-3); }

.stat.skeleton { min-height: 128px; background: linear-gradient(90deg, var(--surface) 0%, var(--surface-2) 50%, var(--surface) 100%); background-size: 200% 100%; animation: shimmer 1.2s linear infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }

.dash-grid {
    display: grid;
    grid-template-columns: minmax(0, 5fr) minmax(0, 7fr);
    gap: 18px;
    align-items: start;
}
.dash-grid > .card { margin-bottom: 0; }

/* ==========================================================================
   فرم‌ها
   ========================================================================== */

label {
    display: block;
    font-size: 12.5px;
    font-weight: 500;
    color: var(--text-2);
    margin: 12px 0 6px;
}
label > input, label > select, label > textarea { margin-top: 6px; }

input[type=text], input[type=number], input[type=password], input[type=search], select, textarea {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: var(--surface);
    font-family: inherit;
    font-size: 13.5px;
    color: var(--text);
    transition: border-color .15s, box-shadow .15s, background .15s;
    min-height: var(--control-h);
}
textarea { min-height: 0; line-height: 1.7; resize: vertical; }
input:hover, select:hover, textarea:hover { border-color: var(--line-strong); }
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--ring);
}
input::placeholder, textarea::placeholder { color: var(--faint); }
select {
    appearance: none;
    background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%238b97ad' stroke-width='2.2' stroke-linecap='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: left 10px center;
    padding-left: 32px;
    cursor: pointer;
}
input[type=number] { direction: ltr; text-align: right; font-variant-numeric: tabular-nums; }
input[type=number]::-webkit-inner-spin-button { opacity: .5; }

.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 14px 16px; align-items: end; }
.form-grid label { margin: 0; }
.form-grid .check { display: flex; align-items: center; gap: 8px; margin: 0; color: var(--text-2); font-size: 13px; }
.form-grid label.check input { width: auto; min-height: 0; }

.form-actions {
    display: flex;
    align-items: center;
    gap: 10px 16px;
    flex-wrap: wrap;
    margin-top: 18px;
    padding-top: 16px;
    border-top: 1px solid var(--line-2);
}
.form-actions .grow { flex: 1; }
.form-grid > .form-actions { grid-column: 1 / -1; margin-top: 4px; }

.hint { color: var(--muted); font-size: 12.5px; margin: 8px 0 0; }

.switch { display: inline-flex; align-items: center; gap: 9px; margin: 0; color: var(--text-2); font-size: 13px; font-weight: 500; cursor: pointer; }
.switch input { width: auto; min-height: 0; accent-color: var(--primary); margin: 0; }
input[type=checkbox] { accent-color: var(--primary); width: 16px; height: 16px; cursor: pointer; }

/* کلید روشن/خاموش */
input[type=checkbox].toggle {
    appearance: none;
    -webkit-appearance: none;
    width: 36px; height: 20px;
    flex: none;
    border-radius: 999px;
    background: var(--line-strong);
    position: relative;
    transition: background .18s;
    margin: 0;
}
input[type=checkbox].toggle::after {
    content: '';
    position: absolute;
    top: 2px; right: 2px;
    width: 16px; height: 16px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 1px 3px rgba(15, 23, 42, .3);
    transition: transform .18s;
}
input[type=checkbox].toggle:checked { background: var(--primary); }
input[type=checkbox].toggle:checked::after { transform: translateX(-16px); }
input[type=checkbox].toggle:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--ring); }

.toggle-list { display: flex; flex-direction: column; gap: 12px; margin-top: 16px; }

.switch-card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    padding: 0 14px;
    min-height: var(--control-h);
}

/* جستجو با آیکن */
.search-field { position: relative; flex: 1 1 240px; min-width: 180px; }
.search-field svg {
    position: absolute;
    inset-inline-start: 11px;
    top: 50%;
    transform: translateY(-50%);
    width: 16px; height: 16px;
    color: var(--faint);
    pointer-events: none;
}
.search-field input { padding-inline-start: 34px; }

/* ورودی با برچسب و واحد */
.input-group {
    display: inline-flex;
    align-items: stretch;
    margin: 0;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: var(--surface);
    min-height: var(--control-h);
    overflow: hidden;
    transition: border-color .15s, box-shadow .15s;
}
.input-group:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px var(--ring); }
.input-group input,
.input-group input:focus { border: 0; box-shadow: none; border-radius: 0; min-height: 0; width: 96px; margin: 0; background: transparent; }
.input-group .ig-label,
.input-group .ig-suffix {
    display: flex;
    align-items: center;
    padding: 0 11px;
    font-size: 12px;
    color: var(--muted);
    background: var(--surface-2);
    white-space: nowrap;
}
.input-group .ig-label { border-inline-end: 1px solid var(--line); }
.input-group .ig-suffix { border-inline-start: 1px solid var(--line); }

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

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    padding: 8px 16px;
    min-height: var(--control-h);
    border-radius: var(--radius-sm);
    border: 1px solid var(--line);
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
    font-family: inherit;
    font-size: 13.5px;
    font-weight: 600;
    text-decoration: none;
    transition: background .15s, border-color .15s, color .15s, transform .12s, box-shadow .15s;
    white-space: nowrap;
    line-height: 1.4;
}
.btn svg { width: 16px; height: 16px; flex: none; }
.btn:hover { background: var(--surface-2); border-color: var(--line-strong); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--ring); }
.btn.danger { color: var(--red-ink); border-color: var(--red-line); background: var(--surface); }
.btn.danger:hover { background: var(--red-soft); }
.btn.primary {
    background: linear-gradient(180deg, var(--primary-2), var(--primary));
    border-color: var(--primary);
    color: #fff;
    box-shadow: 0 6px 16px -8px rgba(239, 64, 86, .9);
}
.btn.primary:hover { background: linear-gradient(180deg, var(--primary), var(--primary-dark)); border-color: var(--primary-dark); }
.btn.ghost { background: rgba(255, 255, 255, .04); border-color: rgba(255, 255, 255, .1); color: #d3d9e6; font-weight: 500; }
.btn.ghost:hover { background: rgba(255, 255, 255, .1); color: #fff; }
.btn.small { padding: 5px 12px; min-height: 32px; font-size: 12.5px; border-radius: var(--radius-xs); }
.btn:disabled { opacity: .55; cursor: not-allowed; transform: none; box-shadow: none; }

.btn-link {
    background: none;
    border: 0;
    color: var(--blue);
    cursor: pointer;
    font-family: inherit;
    font-size: 12.5px;
    font-weight: 600;
    padding: 3px 8px;
    border-radius: 6px;
    transition: background .15s, color .15s;
}
.btn-link:hover { background: var(--blue-soft); }
.btn-link.danger { color: var(--red-ink); }
.btn-link.danger:hover { background: var(--red-soft); }
.btn-link[data-act="toggle"] { color: var(--amber-ink); }
.btn-link[data-act="toggle"]:hover { background: var(--amber-soft); }

.icon-btn {
    display: inline-grid;
    place-items: center;
    width: 32px; height: 32px;
    flex: none;
    border: 0;
    border-radius: var(--radius-xs);
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--surface-3); color: var(--text); }
.icon-btn:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--ring); }
.icon-btn svg { width: 16px; height: 16px; }

/* ==========================================================================
   هشدارها
   ========================================================================== */

.alert {
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    margin-bottom: 16px;
    border: 1px solid transparent;
    font-size: 13.5px;
    font-weight: 500;
}
.alert.ok { background: var(--green-soft); color: var(--green-ink); border-color: var(--green-line); }
.alert.err { background: var(--red-soft); color: var(--red-ink); border-color: var(--red-line); }
.alert.info { background: var(--blue-soft); color: var(--blue-ink); border-color: var(--blue-line); }

/* ==========================================================================
   جدول
   ========================================================================== */

.table-wrap {
    overflow: auto;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    max-height: 72vh;
}
.table-wrap.flat { box-shadow: none; border-radius: var(--radius-sm); max-height: none; }

table.grid { width: 100%; border-collapse: separate; border-spacing: 0; }
#variantsTable { min-width: 940px; }
#variantsTable th, #variantsTable td { padding-inline: 10px; }

table.grid th, table.grid td {
    padding: 11px 14px;
    text-align: right;
    border-bottom: 1px solid var(--line-2);
    font-size: 13px;
    vertical-align: middle;
}
table.grid th {
    background: var(--surface-2);
    font-weight: 600;
    color: var(--muted);
    position: sticky;
    top: 0;
    z-index: 5;
    font-size: 12px;
    white-space: nowrap;
    border-bottom: 1px solid var(--line);
}
table.grid th .th-unit { font-weight: 400; color: var(--faint); font-size: 11px; margin-inline-start: 3px; }
table.grid tbody tr { transition: background .12s; }
table.grid tbody tr:hover td { background: var(--surface-2); }
table.grid tbody tr:has(.row-check:checked) td { background: var(--primary-soft); }
table.grid tbody tr:last-child td { border-bottom: 0; }
table.grid td { color: var(--text-2); font-variant-numeric: tabular-nums; }
table.grid tr.is-me td { background: var(--green-soft); }

table.grid td:first-child, table.grid th:first-child { text-align: center; width: 44px; padding-inline: 10px; }
td[data-role=ref] { cursor: pointer; }
td[data-role=ref]:hover { text-decoration: underline; text-decoration-style: dotted; text-underline-offset: 4px; }

/* خانهٔ محصول */
.cell-product { min-width: 190px; max-width: 380px; }
.product-title {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    line-height: 1.6;
    font-weight: 600;
    color: var(--text);
}
.product-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 5px; font-size: 11.5px; color: var(--muted); }
.chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 1px 8px;
    border-radius: 6px;
    background: var(--surface-3);
    color: var(--text-2);
    font-size: 11.5px;
    font-weight: 500;
    line-height: 1.7;
    white-space: nowrap;
}
.chip.mono { direction: ltr; font-variant-numeric: tabular-nums; color: var(--muted); }

a.product-link {
    color: var(--text);
    text-decoration: none;
    transition: color .15s;
}
a.product-link:hover { color: var(--primary); text-decoration: underline; text-underline-offset: 4px; }

/* ورودی‌های درون جدول */
input.price-input { min-height: 34px; padding: 5px 8px; border-radius: var(--radius-xs); width: 108px; font-size: 13px; }
input.price-input[data-role=stock] { width: 70px; }

/* ستون اختلاف */
td[data-role=gap] { white-space: nowrap; }
td[data-role=gap].gap-pos::before,
td[data-role=gap].gap-neg::before {
    display: inline-block;
    margin-inline-end: 4px;
    font-size: 9px;
    vertical-align: 1px;
}
td[data-role=gap].gap-pos::before { content: '▲'; }
td[data-role=gap].gap-neg::before { content: '▼'; }

.tag {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 2px 9px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
    line-height: 1.7;
    border: 1px solid;
    white-space: nowrap;
}
.tag::before { content: ''; width: 5px; height: 5px; border-radius: 50%; background: currentColor; flex: none; }
.tag.win { color: var(--green-ink); border-color: var(--green-line); background: var(--green-soft); }
.tag.lose { color: var(--red-ink); border-color: var(--red-line); background: var(--red-soft); }
.tag.off { color: var(--muted); border-color: var(--line); background: var(--surface-2); }
.tag.warn { color: var(--amber-ink); border-color: var(--amber-line); background: var(--amber-soft); }
.tag.info { color: var(--blue-ink); border-color: var(--blue-line); background: var(--blue-soft); }

/* ستون عملیات: دکمه‌ها زیر هم با فاصله و استایل یکدست */
td.cell-actions { white-space: nowrap; }
.actions-col {
    display: flex;
    flex-direction: column;
    gap: 6px;
    align-items: stretch;
    min-width: 96px;
}
.actions-col .btn {
    width: 100%;
    justify-content: center;
    padding: 4px 10px;
    min-height: 30px;
    font-size: 12px;
    border-radius: var(--radius-xs);
}
.actions-col .btn[data-act="undercut"] {
    border-color: var(--primary-line);
    background: var(--primary-soft);
    color: var(--primary-ink);
}
.actions-col .btn[data-act="undercut"]:hover { border-color: var(--primary); }

/* برچسب‌های وضعیت: زیر هم با فاصله */
.tags { display: flex; flex-direction: column; gap: 5px; align-items: flex-start; }

/* حالت بارگذاری */
.loading-row td { padding: 40px 14px !important; color: var(--muted); }
.empty-row td { padding: 44px 20px !important; text-align: center !important; color: var(--muted); }
.spinner {
    width: 22px; height: 22px; display: inline-block;
    border: 2.5px solid var(--line);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin .7s linear infinite;
    vertical-align: middle;
}
.spinner.sm { width: 16px; height: 16px; border-width: 2px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* حالت خالی */
.empty-state {
    text-align: center;
    padding: 48px 20px;
    color: var(--muted);
    background: var(--surface);
    border: 1px dashed var(--line-strong);
    border-radius: var(--radius);
}
.empty-state .es-ic {
    width: 52px; height: 52px;
    margin: 0 auto 14px;
    border-radius: 16px;
    display: grid; place-items: center;
    background: var(--surface-3);
    color: var(--muted);
}
.empty-state .es-ic svg { width: 24px; height: 24px; }
.empty-state h3 { margin-bottom: 4px; }
.empty-state p { margin: 0 auto; max-width: 440px; font-size: 13px; }
.empty-state.small { padding: 28px 16px; border-radius: var(--radius-sm); }

/* ==========================================================================
   فیلترها و نوار عملیات
   ========================================================================== */

.filters {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 14px;
    align-items: center;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 12px;
    box-shadow: var(--shadow-sm);
}
.filters select { width: auto; flex: 0 1 auto; min-width: 128px; max-width: 220px; }
.filters .btn { margin-inline-start: auto; }

.bulk-bar {
    position: sticky;
    top: 10px;
    z-index: 12;
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
    background: var(--toast-bg);
    color: #e6ebf4;
    padding: 10px 14px;
    border-radius: var(--radius);
    margin-bottom: 14px;
    font-size: 13px;
    font-weight: 500;
    box-shadow: var(--shadow-lg);
    animation: view-in .18s ease;
}
.bulk-count { display: inline-flex; align-items: center; gap: 6px; padding-inline-end: 4px; }
.bulk-count b {
    display: inline-grid; place-items: center;
    min-width: 26px; height: 26px; padding: 0 6px;
    border-radius: 8px;
    background: var(--primary);
    color: #fff;
    font-size: 12.5px;
}
.bulk-sep { width: 1px; align-self: stretch; background: rgba(255, 255, 255, .15); margin: 2px 4px; }
.bulk-bar input, .bulk-bar select {
    width: auto; min-width: 130px; min-height: 32px; padding: 4px 10px;
    background: rgba(255, 255, 255, .06);
    border-color: rgba(255, 255, 255, .14);
    color: #fff;
}
.bulk-bar select { padding-left: 30px; }
.bulk-bar select option { color: #0f172a; background: #fff; }
.bulk-bar input::placeholder { color: #8b97ad; }
.bulk-bar .btn:not(.primary) { background: rgba(255, 255, 255, .08); border-color: rgba(255, 255, 255, .16); color: #fff; }
.bulk-bar .btn:not(.primary):hover { background: rgba(255, 255, 255, .14); }

.pager {
    display: flex;
    gap: 10px 16px;
    margin-top: 14px;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
}
.pager-pages { display: flex; gap: 4px; flex-wrap: wrap; align-items: center; }
.pager .btn.small { min-width: 34px; padding-inline: 10px; }
.pager-gap { color: var(--faint); padding: 0 4px; }
.pager-info { color: var(--muted); font-size: 12.5px; }

/* ==========================================================================
   پنل عملیات (همگام‌سازی و …)
   ========================================================================== */

.op-panel { border-color: var(--primary-line); position: relative; overflow: hidden; }
.op-head { display: flex; align-items: center; gap: 12px; }
.op-head h3 { margin: 0; font-size: 14.5px; flex: 1; min-width: 0; }
.op-icon {
    width: 34px; height: 34px; flex: none;
    border-radius: 10px;
    display: grid; place-items: center;
    background: var(--primary-soft);
    color: var(--primary);
}
.op-icon .op-done { display: none; width: 18px; height: 18px; }
.op-panel:has(#btnSyncCancel[hidden]) .op-icon { background: var(--green-soft); color: var(--green); }
.op-panel:has(#btnSyncCancel[hidden]) .op-icon .spinner { display: none; }
.op-panel:has(#btnSyncCancel[hidden]) .op-icon .op-done { display: block; }
.op-panel:has(#btnSyncCancel[hidden]) .progress-fill::after { animation: none; background-image: none; }
.op-log { margin-top: 10px; }
.op-log summary { cursor: pointer; font-size: 12.5px; color: var(--muted); user-select: none; width: max-content; }
.op-log summary:hover { color: var(--text); }
.op-log .logs { margin-top: 8px; max-height: 200px; }

.progress { height: 8px; background: var(--surface-3); border-radius: 999px; overflow: hidden; margin: 14px 0 8px; }
.progress-fill {
    height: 100%; width: 0;
    background: linear-gradient(90deg, var(--primary), #ff8a5b);
    border-radius: 999px;
    transition: width .3s ease;
    position: relative;
}
.progress-fill::after {
    content: ''; position: absolute; inset: 0;
    background-image: linear-gradient(45deg, rgba(255,255,255,.25) 25%, transparent 25%, transparent 50%, rgba(255,255,255,.25) 50%, rgba(255,255,255,.25) 75%, transparent 75%);
    background-size: 18px 18px;
    animation: bar-stripes .8s linear infinite;
}
@keyframes bar-stripes { to { background-position: 18px 0; } }
.sync-meta { display: flex; justify-content: space-between; gap: 12px; font-size: 12.5px; color: var(--muted); }
.sync-meta #syncPercent { font-weight: 700; color: var(--text); font-variant-numeric: tabular-nums; }

/* ==========================================================================
   کلید/مقدار، لاگ و تایم‌لاین
   ========================================================================== */

.kv { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 8px; margin: 0; padding: 0; }
.kv > div, .kv > li {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    background: var(--surface-2);
    border: 1px solid var(--line-2);
    border-radius: var(--radius-sm);
    margin: 0;
    list-style: none;
    font-size: 13px;
    min-width: 0;
}
.kv span { color: var(--muted); font-size: 12.5px; }
.kv b { font-weight: 600; text-align: left; font-variant-numeric: tabular-nums; }

/* فهرست کلید/مقدار عمودی (بدون جعبه) */
.kv.kv-list { grid-template-columns: 1fr; gap: 0; }
.kv.kv-list > div { background: none; border: 0; border-bottom: 1px solid var(--line-2); border-radius: 0; padding: 10px 2px; }
.kv.kv-list > div:last-child { border-bottom: 0; }

.logs { display: flex; flex-direction: column; gap: 6px; max-height: 300px; overflow: auto; }
.log-row {
    display: flex;
    gap: 10px;
    font-size: 12.5px;
    padding: 7px 12px;
    background: var(--surface-2);
    border: 1px solid var(--line-2);
    border-radius: var(--radius-xs);
    color: var(--text-2);
}
.log-row.ok { color: var(--green-ink); background: var(--green-soft); border-color: var(--green-line); }
.log-row.err { color: var(--red-ink); background: var(--red-soft); border-color: var(--red-line); }
.log-row .t { color: var(--muted); white-space: nowrap; }

.timeline { display: flex; flex-direction: column; max-height: 420px; overflow: auto; margin: -4px 0; }
.tl-item {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: 12px;
    padding: 9px 2px;
    border-bottom: 1px solid var(--line-2);
    font-size: 13px;
}
.tl-item:last-child { border-bottom: 0; }
.tl-dot {
    width: 28px; height: 28px;
    border-radius: 9px;
    display: grid; place-items: center;
    background: var(--surface-3);
    color: var(--muted);
}
.tl-dot svg { width: 14px; height: 14px; }
.tl-dot.c-sync { background: var(--blue-soft); color: var(--blue); }
.tl-dot.c-price { background: var(--primary-soft); color: var(--primary); }
.tl-dot.c-rule { background: var(--amber-soft); color: var(--amber); }
.tl-body { display: flex; align-items: center; gap: 8px; min-width: 0; flex-wrap: wrap; }
.tl-body b { font-weight: 600; color: var(--text); }
.tl-time { text-align: left; font-size: 12px; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; line-height: 1.5; }
.tl-time b { display: block; color: var(--text-2); font-weight: 600; font-size: 12.5px; }

.sync-opts {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: 14px;
    padding-top: 14px;
    border-top: 1px solid var(--line-2);
}
.sync-opts label.field { margin: 0; }

/* ==========================================================================
   رقبا
   ========================================================================== */

.comp-search { flex-wrap: nowrap; }
.comp-search .search-field { width: 240px; flex: 0 1 240px; }

.comp-head-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.comp-head-row h3 { margin: 0 0 6px; font-size: 16px; line-height: 1.6; }
.comp-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }

.kpis {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 10px;
    margin: 18px 0 14px;
}
.kpi {
    padding: 12px 14px;
    border-radius: var(--radius-sm);
    background: var(--surface-2);
    border: 1px solid var(--line-2);
    min-width: 0;
}
.kpi span { display: block; font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi b { display: block; font-size: 19px; font-weight: 800; letter-spacing: -.01em; line-height: 1.5; color: var(--text); }
.kpi small { font-size: 11.5px; color: var(--muted); }
.kpi.gap-pos { background: var(--red-soft); border-color: var(--red-line); }
.kpi.gap-pos b { color: var(--red-ink); }
.kpi.gap-neg { background: var(--green-soft); border-color: var(--green-line); }
.kpi.gap-neg b { color: var(--green-ink); }

.comp-action {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--line-2);
}
.comp-action .muted { font-size: 12.5px; flex: 1 1 260px; margin: 0; }

.comp-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 18px; margin-bottom: 18px; }
.comp-grid > .card { margin-bottom: 0; }

/* نردبان رتبه */
.rank-ladder { display: grid; gap: 8px; }
.rank-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: var(--surface);
    transition: border-color .15s, background .15s;
}
.rank-row:hover { border-color: var(--line-strong); }
.rank-row.best { border-color: var(--green-line); background: var(--green-soft); }
.rank-badge {
    width: 30px; height: 30px; flex: none;
    border-radius: 9px;
    display: grid; place-items: center;
    background: var(--surface-3);
    font-weight: 700;
    font-size: 13px;
    color: var(--text-2);
}
.rank-row.best .rank-badge { background: var(--green); color: #fff; }
.rank-price { flex: 1; min-width: 0; }
.rank-price b { font-size: 15px; font-variant-numeric: tabular-nums; }
.rank-price small { color: var(--muted); font-size: 11.5px; margin-inline-start: 3px; }

/* نمودار روند قیمت */
.chart { position: relative; direction: ltr; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .ax { font-size: 10.5px; fill: var(--muted); font-family: inherit; }
.chart .gl { stroke: var(--grid); stroke-width: 1; }
.chart .s1 { stroke: var(--series-1); }
.chart .s2 { stroke: var(--series-2); }
.chart .dot-end { stroke: var(--surface); stroke-width: 2; }
.chart .xh { stroke: var(--line-strong); stroke-width: 1; }
.chart-tip {
    position: absolute;
    top: 0;
    pointer-events: none;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-xs);
    box-shadow: var(--shadow);
    padding: 7px 10px;
    font-size: 12px;
    line-height: 1.7;
    white-space: nowrap;
    direction: rtl;
    transform: translateX(-50%);
    z-index: 3;
}
.chart-tip .tt-date { color: var(--muted); font-size: 11px; }
.chart-tip .tt-row { display: flex; align-items: center; gap: 6px; }
.chart-tip .tt-row b { font-variant-numeric: tabular-nums; margin-inline-start: auto; padding-inline-start: 10px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 12px; color: var(--text-2); margin-bottom: 10px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.key { display: inline-block; width: 14px; height: 3px; border-radius: 2px; flex: none; }
.key.s1 { background: var(--series-1); }
.key.s2 { background: var(--series-2); }
.chart-foot { display: flex; flex-wrap: wrap; gap: 4px 16px; margin-top: 10px; font-size: 12px; color: var(--muted); }
.chart-foot b { color: var(--text-2); font-weight: 600; font-variant-numeric: tabular-nums; }

/* ==========================================================================
   قیمت‌گذاری و تنظیمات
   ========================================================================== */

.settings-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 18px;
    align-items: start;
    margin-bottom: 18px;
}
.settings-grid > .card { margin-bottom: 0; }

.danger-zone { border-color: var(--red-line); }
.danger-zone > h3:first-child { color: var(--red-ink); }

/* ==========================================================================
   توست
   ========================================================================== */

.toasts { position: fixed; left: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 10px; z-index: 60; max-width: 420px; }
.toast {
    background: var(--toast-bg);
    color: #fff;
    padding: 11px 16px;
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-lg);
    font-size: 13px;
    font-weight: 500;
    animation: toast-in .25s ease;
    border-right: 4px solid rgba(255, 255, 255, .25);
}
.toast.ok { border-right-color: #34d399; }
.toast.err { border-right-color: #f87171; }
@keyframes toast-in { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }

/* ==========================================================================
   ورود / راه‌اندازی
   ========================================================================== */

.login-screen {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background:
        radial-gradient(1000px 500px at 15% -10%, var(--primary-soft) 0%, transparent 55%),
        radial-gradient(900px 500px at 100% 110%, var(--blue-soft) 0%, transparent 55%),
        var(--bg);
}
.login-card {
    background: var(--surface);
    padding: 34px 30px 28px;
    border-radius: 20px;
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 380px;
    border: 1px solid var(--line);
}
.login-card h1 { text-align: center; font-size: 20px; margin-bottom: 4px; }
.login-card .login-logo {
    width: 56px; height: 56px; margin: 0 auto 16px;
    border-radius: 16px;
    background: linear-gradient(140deg, var(--primary), #ff8a5b);
    display: grid; place-items: center; color: #fff; font-weight: 800; font-size: 22px;
    box-shadow: 0 14px 30px -14px rgba(239, 64, 86, .95);
}
.login-card p { text-align: center; }
.login-card input { margin-bottom: 12px; min-height: 44px; }
.login-card .btn { width: 100%; font-size: 14px; min-height: 44px; }

.setup-body { min-height: 100vh; background: var(--bg); }
.setup-wrap { max-width: 780px; margin: 0 auto; padding: 34px 18px 90px; }
.setup-wrap > h1 { margin-bottom: 18px; }

.row { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; align-items: center; }
.row .btn { margin: 0; }
.row input[type=number] { width: auto; flex: 0 1 220px; }

/* ==========================================================================
   ریسپانسیو
   ========================================================================== */

@media (max-width: 1360px) {
    .cards { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 1180px) {
    .dash-grid, .comp-grid, .settings-grid { grid-template-columns: minmax(0, 1fr); }
    .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 900px) {
    .app { flex-direction: column; }
    .sidebar {
        width: 100%; flex: none; height: auto;
        position: sticky; top: 0;
        flex-direction: row; align-items: center; gap: 6px;
        padding: 8px 10px;
        border-inline-end: 0;
        border-bottom: 1px solid var(--sidebar-line);
    }
    .brand { padding: 0; margin: 0; border: 0; }
    .brand .logo { width: 32px; height: 32px; }
    .brand-text, .nav-label { display: none; }
    .sidebar nav { flex-direction: row; overflow-x: auto; flex: 1; min-width: 0; scrollbar-width: none; }
    .sidebar nav::-webkit-scrollbar { display: none; }
    .nav-item { white-space: nowrap; padding: 7px 10px; font-size: 13px; }
    .nav-item.active::before { display: none; }
    .sidebar-foot { margin: 0; padding: 0; border: 0; flex-direction: row; gap: 4px; }
    .sidebar-foot .btn { width: 34px; min-height: 34px; padding: 0; justify-content: center; }
    .sidebar-foot .btn .lbl { display: none; }
    .main { padding: 18px 16px 60px; }
    .table-wrap { max-height: none; }
    .filters select { flex: 1 1 140px; max-width: none; }
    .filters .btn { margin-inline-start: 0; }
    .toasts { left: 12px; right: 12px; max-width: none; }
}

@media (max-width: 640px) {
    .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
    .stat { padding: 13px 13px 12px; }
    .stat .n { font-size: 22px; }
    .view-head { align-items: stretch; flex-direction: column; }
    .view-head > div:first-child { flex: none; }
    .view-head .actions > .btn { flex: 1 1 auto; }
    .comp-search .search-field { flex: 1 1 auto; width: auto; }
    .kpis { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
    .kpi b { font-size: 16px; }
    .card { padding: 16px; }
    .bulk-sep { display: none; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
