/* ==========================================================================
   مستندیار CRM — دیزاین‌سیستم اختصاصی (RTL، بدون Bootstrap)
   همه رنگ‌ها/فاصله‌ها از متغیرهای زیر می‌آیند تا کل ظاهر از یک نقطه قابل تنظیم باشد.
   ========================================================================== */

:root {
    /* رنگ برند */
    --brand: #2f6fed;
    --brand-600: #2560d8;
    --brand-700: #1c4db4;
    --brand-soft: #eaf1fe;

    --success: #12a67a;
    --success-soft: #e3f7f0;
    --warning: #e0912f;
    --warning-soft: #fdf3e4;
    --danger: #e0483f;
    --danger-soft: #fdeceb;
    --info: #6b5ce7;
    --info-soft: #efedfd;

    /* سطوح */
    --bg: #f4f6fb;
    --surface: #ffffff;
    --surface-2: #f8fafd;
    --border: #e4e9f2;
    --border-strong: #d3dae7;

    /* متن */
    --text: #1b2437;
    --text-2: #5a6b85;
    --text-3: #8e9ab1;

    --radius-sm: 8px;
    --radius: 14px;
    --radius-lg: 20px;

    --shadow-sm: 0 1px 2px rgba(27, 36, 55, .06), 0 1px 3px rgba(27, 36, 55, .05);
    --shadow: 0 4px 16px rgba(27, 36, 55, .07);
    --shadow-lg: 0 12px 34px rgba(27, 36, 55, .12);

    --sidebar-w: 262px;
    --topbar-h: 68px;

    /* @font-face در fonts.css تعریف شده و پیش از این فایل بارگذاری می‌شود. */
    --font: var(--font-fa, "Vazirmatn", "Segoe UI", Tahoma, "Iranian Sans", sans-serif);
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: 14px;
    line-height: 1.7;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--brand); text-decoration: none; }
a:hover { color: var(--brand-700); }

/* اعداد و کدها همیشه چپ‌چین و تک‌عرض، تا سریال/کد رهگیری خوانا بماند */
.ltr, .mono {
    direction: ltr;
    unicode-bidi: embed;
    text-align: left;
}
.mono { font-family: "Cascadia Mono", Consolas, monospace; letter-spacing: .3px; }

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

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

.sidebar {
    width: var(--sidebar-w);
    flex: 0 0 var(--sidebar-w);
    background: var(--surface);
    border-left: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
}

.sidebar__brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 20px 20px 18px;
}

.sidebar__logo {
    width: 42px; height: 42px;
    border-radius: 12px;
    background: linear-gradient(135deg, var(--brand) 0%, var(--info) 100%);
    display: grid; place-items: center;
    color: #fff; font-size: 19px;
    box-shadow: 0 6px 16px rgba(47, 111, 237, .32);
}

.sidebar__title { font-weight: 700; font-size: 15px; line-height: 1.35; }
.sidebar__subtitle { font-size: 11.5px; color: var(--text-3); }

.sidebar__nav { flex: 1; overflow-y: auto; padding: 6px 12px 16px; }

.nav-group__label {
    font-size: 11px;
    font-weight: 700;
    color: var(--text-3);
    letter-spacing: .4px;
    padding: 16px 10px 6px;
    text-transform: uppercase;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 10px 12px;
    border-radius: 10px;
    color: var(--text-2);
    font-weight: 500;
    margin-bottom: 2px;
    transition: background .15s, color .15s;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.is-active { background: var(--brand); color: #fff; box-shadow: 0 4px 12px rgba(47,111,237,.28); }
.nav-item.is-active .nav-item__icon { opacity: 1; }
.nav-item__icon { width: 18px; height: 18px; flex: 0 0 18px; opacity: .85; }
.nav-item__badge {
    margin-inline-start: auto;
    background: var(--danger);
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    border-radius: 999px;
    padding: 1px 7px;
}
.nav-item.is-active .nav-item__badge { background: rgba(255,255,255,.25); }

.sidebar__footer {
    padding: 14px 16px;
    border-top: 1px solid var(--border);
    font-size: 11.5px;
    color: var(--text-3);
    text-align: center;
}

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
    height: var(--topbar-h);
    background: rgba(255,255,255,.85);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 0 26px;
    position: sticky;
    top: 0;
    z-index: 20;
}

.topbar__title { font-size: 17px; font-weight: 700; }
.topbar__subtitle { font-size: 12px; color: var(--text-3); font-weight: 400; }
.topbar__spacer { flex: 1; }

.user-chip {
    display: flex; align-items: center; gap: 10px;
    padding: 6px 12px 6px 6px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--surface);
}
.avatar {
    width: 34px; height: 34px; border-radius: 50%;
    background: var(--brand-soft); color: var(--brand-700);
    display: grid; place-items: center;
    font-weight: 700; font-size: 13px;
    flex: 0 0 34px;
}
.avatar--sm { width: 28px; height: 28px; flex-basis: 28px; font-size: 11.5px; }
.user-chip__name { font-size: 12.5px; font-weight: 600; line-height: 1.25; }
.user-chip__role { font-size: 11px; color: var(--text-3); line-height: 1.2; }

.content { padding: 24px 26px 48px; flex: 1; }

/* دکمهٔ همبرگر (فقط موبایل)، پردهٔ پشتِ کشوی منو، و ناوبری پایین صفحه — استایل پایه اینجا خاموش
   است و فقط داخل مدیاکوئری موبایل روشن می‌شود، چون در دسکتاپ منوی کناری همیشه ثابت و نمایان است. */
.sidebar-toggle {
    display: none;
    width: 38px; height: 38px;
    flex: 0 0 38px;
    align-items: center; justify-content: center;
    border: 1px solid var(--border);
    background: var(--surface);
    border-radius: 10px;
    font-size: 17px;
    color: var(--text);
    cursor: pointer;
}
.sidebar-backdrop { display: none; }
.bottom-nav { display: none; }

/* ============================ کارت و شبکه ============================ */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}
.card__header {
    display: flex; align-items: center; gap: 12px;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}
.card__title { font-size: 14.5px; font-weight: 700; }
.card__body { padding: 20px; }
.card__body--flush { padding: 0; }
.card__footer { padding: 14px 20px; border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 var(--radius) var(--radius); }

.grid { display: grid; gap: 16px; }
.grid--4 { grid-template-columns: repeat(4, 1fr); }
.grid--3 { grid-template-columns: repeat(3, 1fr); }
.grid--2 { grid-template-columns: repeat(2, 1fr); }
.grid--sidebar { grid-template-columns: 2fr 1fr; }

@media (max-width: 1180px) {
    .grid--4 { grid-template-columns: repeat(2, 1fr); }
    .grid--sidebar, .grid--3 { grid-template-columns: 1fr; }
}
@media (max-width: 780px) {
    .grid--4, .grid--2 { grid-template-columns: 1fr; }
    .content { padding: 16px; }
    .has-bottom-nav .content { padding-bottom: calc(84px + env(safe-area-inset-bottom)); }

    .sidebar-toggle { display: inline-flex; }

    /* منوی کناری روی موبایل به یک کشوی off-canvas تبدیل می‌شود — با margin-inline-start منفی به‌جای
       transform تا جهت RTL/LTR خودکار درست باشد، به‌جای حدس‌زدنِ علامت translateX. */
    .sidebar {
        position: fixed;
        inset-inline-start: 0;
        top: 0;
        z-index: 60;
        margin-inline-start: calc(-1 * var(--sidebar-w));
        transition: margin-inline-start .22s ease;
    }
    .app.is-nav-open .sidebar { margin-inline-start: 0; }

    .sidebar-backdrop {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(15, 23, 42, .45);
        z-index: 50;
    }
    .app.is-nav-open .sidebar-backdrop { display: block; }

    .bottom-nav {
        display: flex;
        position: fixed;
        inset-inline: 0;
        bottom: 0;
        z-index: 40;
        background: var(--surface);
        border-top: 1px solid var(--border);
        box-shadow: 0 -4px 16px rgba(27, 36, 55, .08);
        padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
    }
    .bottom-nav__item {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 2px;
        padding: 6px 2px;
        border-radius: 10px;
        color: var(--text-2);
        font-size: 10.5px;
        font-weight: 600;
        background: none;
        border: none;
        font-family: inherit;
    }
    .bottom-nav__item.is-active { color: var(--brand); }
    .bottom-nav__item-icon { font-size: 18px; line-height: 1; }
}

/* ============================ کاشی‌های پنل مدیریت ============================
   موبایل-فرست: پیش‌فرض یک ستون با کارت‌های تمام‌عرض و ناحیهٔ لمسِ بزرگ (کل کارت لینک است)،
   از ۵۸۰px به بالا در چند ستون کنار هم می‌نشینند. */

.admin-tiles {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
}
@media (min-width: 580px) {
    .admin-tiles { grid-template-columns: repeat(2, 1fr); }
}
@media (min-width: 980px) {
    .admin-tiles { grid-template-columns: repeat(3, 1fr); }
}

.admin-tile {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 16px;
    min-height: 64px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    color: var(--text);
    transition: border-color .15s, box-shadow .15s, transform .06s;
}
.admin-tile:hover { border-color: var(--brand); box-shadow: var(--shadow); color: var(--text); }
.admin-tile:active { transform: translateY(1px); }

.admin-tile__icon {
    flex: 0 0 44px;
    width: 44px; height: 44px;
    display: grid; place-items: center;
    border-radius: 12px;
    background: var(--brand-soft);
    color: var(--brand-700);
    font-size: 19px;
}
.admin-tile__body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.admin-tile__title { font-size: 14px; font-weight: 700; }
.admin-tile__desc { font-size: 12px; color: var(--text-3); line-height: 1.5; }
.admin-tile__badge { flex: none; }
.admin-tile__chevron {
    flex: none;
    font-size: 18px;
    color: var(--text-3);
    transform: scaleX(-1); /* در RTL فلش باید رو به چپ باشد */
}

/* ============================ کاشی آماری ============================ */

.stat {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px 20px;
    box-shadow: var(--shadow-sm);
    position: relative;
    overflow: hidden;
}
.stat::after {
    content: "";
    position: absolute; inset-block-start: 0; inset-inline-start: 0;
    width: 4px; height: 100%;
    background: var(--brand);
}
.stat--success::after { background: var(--success); }
.stat--warning::after { background: var(--warning); }
.stat--danger::after { background: var(--danger); }
.stat--info::after { background: var(--info); }

.stat__label { font-size: 12.5px; color: var(--text-2); font-weight: 500; }
.stat__value { font-size: 27px; font-weight: 800; letter-spacing: -.5px; margin-top: 4px; }
.stat__hint { font-size: 11.5px; color: var(--text-3); margin-top: 2px; }

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

.table-wrap { overflow-x: auto; }

table.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}
.table thead th {
    text-align: right;
    font-size: 11.5px;
    font-weight: 700;
    color: var(--text-3);
    letter-spacing: .3px;
    padding: 12px 16px;
    background: var(--surface-2);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
.table tbody td {
    padding: 13px 16px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr { transition: background .12s; }
.table tbody tr:hover { background: var(--surface-2); }
.table__strong { font-weight: 600; }
.table__muted { color: var(--text-3); font-size: 12px; }

.empty {
    padding: 46px 20px;
    text-align: center;
    color: var(--text-3);
}
.empty__icon { font-size: 34px; opacity: .5; margin-bottom: 8px; }

/* ============================ نشان‌ها ============================ */

.badge {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 3px 11px;
    border-radius: 999px;
    font-size: 11.5px;
    font-weight: 700;
    white-space: nowrap;
}
.badge--neutral { background: #eef1f6; color: #5a6b85; }
.badge--brand   { background: var(--brand-soft); color: var(--brand-700); }
.badge--success { background: var(--success-soft); color: #0b7a58; }
.badge--warning { background: var(--warning-soft); color: #a5661a; }
.badge--danger  { background: var(--danger-soft); color: #b3312a; }
.badge--info    { background: var(--info-soft); color: #4a3cc4; }

.dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

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

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    height: 40px;
    padding: 0 20px;
    border-radius: 10px;
    border: 1px solid transparent;
    font-family: var(--font);
    font-size: 13.5px;
    font-weight: 600;
    cursor: pointer;
    transition: background .15s, box-shadow .15s, transform .06s;
    white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn--primary { background: var(--brand); color: #fff; }
.btn--primary:hover { background: var(--brand-600); box-shadow: 0 6px 16px rgba(47,111,237,.3); color: #fff; }
.btn--success { background: var(--success); color: #fff; }
.btn--success:hover { background: #0e8f68; color: #fff; }
.btn--danger { background: var(--danger); color: #fff; }
.btn--danger:hover { background: #c93d35; color: #fff; }
.btn--ghost { background: var(--surface); color: var(--text-2); border-color: var(--border-strong); }
.btn--ghost:hover { background: var(--surface-2); color: var(--text); }
.btn--sm { height: 32px; padding: 0 13px; font-size: 12.5px; border-radius: 8px; }
.btn--block { width: 100%; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }

.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ============================ فرم ============================ */

.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px 18px; }
.form-grid--1 { grid-template-columns: 1fr; }
.form-grid .span-2 { grid-column: 1 / -1; }
@media (max-width: 780px) { .form-grid { grid-template-columns: 1fr; } }

.field { display: flex; flex-direction: column; gap: 6px; }
.field > label { font-size: 12.5px; font-weight: 600; color: var(--text-2); }

.input, .select, .textarea {
    width: 100%;
    height: 44px;
    padding: 0 14px;
    border: 1px solid var(--border-strong);
    border-radius: 10px;
    background: var(--surface);
    color: var(--text);
    font-family: var(--font);
    font-size: 13.5px;
    transition: border-color .15s, box-shadow .15s;
}
.textarea { height: auto; min-height: 110px; padding: 11px 14px; line-height: 1.8; resize: vertical; }
.input:focus, .select:focus, .textarea:focus {
    outline: none;
    border-color: var(--brand);
    box-shadow: 0 0 0 3px rgba(47,111,237,.14);
}
.select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--text-3) 50%), linear-gradient(135deg, var(--text-3) 50%, transparent 50%); background-position: 16px 19px, 21px 19px; background-size: 5px 5px; background-repeat: no-repeat; }

.field__error { color: var(--danger); font-size: 11.5px; }
.field__hint { color: var(--text-3); font-size: 11.5px; }

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

.alert {
    display: flex; align-items: flex-start; gap: 10px;
    padding: 13px 16px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    margin-bottom: 18px;
    border: 1px solid transparent;
}
.alert--success { background: var(--success-soft); color: #0b7a58; border-color: #bfe9dc; }
.alert--danger { background: var(--danger-soft); color: #b3312a; border-color: #f6cbc8; }
.alert--info { background: var(--brand-soft); color: var(--brand-700); border-color: #cfe0fc; }

/* ============================ صفحه ورود ============================ */

.auth {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 1fr 1fr;
    background: var(--surface);
}
@media (max-width: 900px) { .auth { grid-template-columns: 1fr; } .auth__aside { display: none; } }

.auth__aside {
    background: linear-gradient(150deg, var(--brand-700) 0%, var(--brand) 45%, var(--info) 100%);
    color: #fff;
    padding: 56px 52px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    position: relative;
    overflow: hidden;
}
.auth__aside::before {
    content: ""; position: absolute; width: 460px; height: 460px; border-radius: 50%;
    background: rgba(255,255,255,.08); inset-block-start: -140px; inset-inline-start: -120px;
}
.auth__aside::after {
    content: ""; position: absolute; width: 320px; height: 320px; border-radius: 50%;
    background: rgba(255,255,255,.07); inset-block-end: -110px; inset-inline-end: -80px;
}
.auth__aside > * { position: relative; z-index: 1; }
.auth__headline { font-size: 30px; font-weight: 800; line-height: 1.5; letter-spacing: -.5px; }
.auth__sub { font-size: 14.5px; opacity: .88; margin-top: 12px; line-height: 2; }
.auth__points { margin-top: 32px; display: flex; flex-direction: column; gap: 13px; }
.auth__point { display: flex; align-items: center; gap: 11px; font-size: 13.5px; opacity: .95; }
.auth__point span:first-child {
    width: 28px; height: 28px; border-radius: 9px; background: rgba(255,255,255,.18);
    display: grid; place-items: center; flex: 0 0 28px;
}

.auth__form { display: grid; place-items: center; padding: 40px 24px; }
.auth__form-inner { width: 100%; max-width: 380px; }

/* ============================ تخته کانبان (قیف فروش) ============================ */

.kanban { display: flex; gap: 14px; overflow-x: auto; padding-bottom: 10px; }
.kanban__col {
    flex: 0 0 262px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    display: flex; flex-direction: column;
}
.kanban__head {
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between;
    font-size: 12.5px; font-weight: 700;
}
.kanban__count { background: var(--surface); border: 1px solid var(--border); border-radius: 999px; padding: 0 8px; font-size: 11.5px; color: var(--text-2); }
.kanban__body { padding: 10px; display: flex; flex-direction: column; gap: 9px; min-height: 90px; }
.kanban__card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 11px;
    padding: 12px;
    box-shadow: var(--shadow-sm);
}
.kanban__card:hover { box-shadow: var(--shadow); }
.kanban__card-title { font-size: 12.8px; font-weight: 600; line-height: 1.6; }
.kanban__card-meta { font-size: 11.5px; color: var(--text-3); margin-top: 6px; display: flex; justify-content: space-between; gap: 8px; }

/* ============================ گفتگوی درخواست ============================ */

.thread { display: flex; flex-direction: column; gap: 14px; }
.msg { display: flex; gap: 11px; }
.msg__bubble {
    flex: 1;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px 14px;
}
.msg--internal .msg__bubble { background: var(--warning-soft); border-color: #f2ddbe; }
.msg--customer .msg__bubble { background: var(--brand-soft); border-color: #cfe0fc; }
.msg__head { display: flex; align-items: center; gap: 8px; font-size: 12px; margin-bottom: 5px; }
.msg__author { font-weight: 700; }
.msg__time { color: var(--text-3); font-size: 11.5px; margin-inline-start: auto; }
.msg__body { font-size: 13px; line-height: 1.9; white-space: pre-wrap; }

/* ============================ خط زمانی ============================ */

.timeline { position: relative; padding-inline-start: 22px; }
.timeline::before {
    content: ""; position: absolute; inset-block: 6px; inset-inline-start: 5px;
    width: 2px; background: var(--border);
}
.timeline__item { position: relative; padding-bottom: 16px; }
.timeline__item::before {
    content: ""; position: absolute; inset-inline-start: -21px; inset-block-start: 7px;
    width: 10px; height: 10px; border-radius: 50%;
    background: var(--surface); border: 2px solid var(--brand);
}
.timeline__title { font-size: 13px; font-weight: 600; }
.timeline__meta { font-size: 11.5px; color: var(--text-3); }

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

.page-head { display: flex; align-items: center; gap: 14px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head__spacer { flex: 1; }

.toolbar {
    display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end;
    padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.toolbar .field { min-width: 170px; }

.stack { display: flex; flex-direction: column; gap: 16px; }
.row { display: flex; align-items: center; gap: 10px; }
.row--between { justify-content: space-between; }
.wrap { flex-wrap: wrap; }

.muted { color: var(--text-3); }
.small { font-size: 12px; }
.strong { font-weight: 700; }
.nowrap { white-space: nowrap; }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }
.mt-0 { margin-top: 0; } .mt-1 { margin-top: 8px; } .mt-2 { margin-top: 16px; } .mt-3 { margin-top: 24px; }
.mb-0 { margin-bottom: 0; } .mb-1 { margin-bottom: 8px; } .mb-2 { margin-bottom: 16px; } .mb-3 { margin-bottom: 24px; }

.progress { height: 7px; background: var(--border); border-radius: 999px; overflow: hidden; }
.progress__bar { height: 100%; background: var(--brand); border-radius: 999px; }
.progress__bar--success { background: var(--success); }
.progress__bar--warning { background: var(--warning); }

.kv { display: grid; grid-template-columns: 130px 1fr; gap: 9px 12px; font-size: 13px; }
.kv dt { color: var(--text-3); font-size: 12.5px; }
.kv dd { margin: 0; font-weight: 500; }
