/* ==========================================================
   نمایندگی فروش بیمه عمر - استایل اصلی (RTL)
   ========================================================== */

:root {
    --brand:        #133051;   /* سرمه‌ای لوگو */
    --brand-dark:   #0c2039;
    --brand-light:  #2a5585;
    --accent:       #c79c54;   /* طلایی لوگو */
    --bg:           #f4f6f8;
    --surface:      #ffffff;
    --text:         #1f2933;
    --text-soft:    #5b6b7a;
    --border:       #dfe5ea;
    --ok:           #1d8a4e;
    --ok-bg:        #e6f6ed;
    --warn:         #b3761a;
    --warn-bg:      #fdf3e2;
    --bad:          #c0392b;
    --bad-bg:       #fdecea;
    --info:         #1d6fa5;
    --info-bg:      #e8f2fa;
    --alt:          #6b4bb8;
    --alt-bg:       #f0ebfa;
    --brand-ring:   rgba(42,85,133,.18);    /* حلقهٔ فوکوس و هاله */
    --brand-wash:   #eef2f8;                /* پس‌زمینهٔ بسیار روشن برند */
    --side-text:    #cfdcea;                /* متن منوی کناری */
    --radius:       10px;
    --shadow:       0 1px 3px rgba(16,24,40,.08), 0 1px 2px rgba(16,24,40,.06);
    --shadow-lg:    0 8px 24px rgba(16,24,40,.10);
}

@font-face {
    font-family: 'Vazirmatn';
    src: local('Vazirmatn'), local('Vazir'), local('Tahoma');
    font-display: swap;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    direction: rtl;
    font-family: 'Vazirmatn', 'Segoe UI', Tahoma, 'Iranian Sans', sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    line-height: 1.8;
}

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

h1, h2, h3, h4 { margin: 0 0 .6rem; font-weight: 700; line-height: 1.5; }
h1 { font-size: 1.7rem; }
h2 { font-size: 1.35rem; }
h3 { font-size: 1.1rem; }

.container { max-width: 1200px; margin: 0 auto; padding: 0 16px; }
.container-wide { max-width: 1500px; margin: 0 auto; padding: 0 16px; }

/* ---------------- هدر عمومی ---------------- */
.top-bar {
    background: var(--brand-dark);
    color: #c4d3e4;
    font-size: .82rem;
    padding: 6px 0;
}
.top-bar a { color: #c4d3e4; }
.top-bar .container { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }

.site-header {
    background: var(--brand);
    color: #fff;
    box-shadow: var(--shadow);
    position: sticky;
    top: 0;
    z-index: 50;
}
.site-header .container,
.site-header .container-wide {
    display: flex; align-items: center; gap: 18px; min-height: 64px; flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 1.15rem; color: #fff; }
.brand .logo {
    width: 40px; height: 40px; flex: 0 0 40px;
    object-fit: contain; display: block;
}
.brand:hover { color: #fff; }

.main-nav { display: flex; gap: 4px; margin-right: auto; flex-wrap: wrap; }
.main-nav a {
    color: #dde7f2; padding: 8px 14px; border-radius: 8px; font-weight: 600;
    transition: background .15s;
}
.main-nav a:hover, .main-nav a.active { background: rgba(255,255,255,.14); color: #fff; }

.header-actions { display: flex; gap: 8px; align-items: center; }

/* ---------------- دکمه‌ها ---------------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    padding: 8px 16px; border-radius: 8px; border: 1px solid transparent;
    font-family: inherit; font-size: .88rem; font-weight: 600; cursor: pointer;
    background: var(--brand); color: #fff; transition: all .15s; white-space: nowrap;
    line-height: 1.6; text-align: center;
}
.btn:hover  { background: var(--brand-light); color: #fff; }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 2px solid var(--brand-light); outline-offset: 2px; }
.btn:disabled, .btn[disabled] { opacity: .5; cursor: not-allowed; }

/* طلایی — عمل اصلی صفحه */
.btn-accent { background: var(--accent); color: #2f2306; }
.btn-accent:hover { background: #d7ae6a; color: #2f2306; }

/* آبی — مشاهده، ویرایش، محاسبه */
.btn-info { background: var(--info); color: #fff; }
.btn-info:hover { background: #17608f; color: #fff; }

/* سبز — تأیید و عملیات مثبت */
.btn-ok { background: var(--ok); color: #fff; }
.btn-ok:hover { background: #17733f; color: #fff; }

/* قرمز — حذف و رد */
.btn-bad { background: var(--bad); color: #fff; }
.btn-bad:hover { background: #a53023; color: #fff; }

/* نارنجی — هشدار، غیرفعال‌سازی */
.btn-warn { background: var(--warn); color: #fff; }
.btn-warn:hover { background: #99620f; color: #fff; }

/* بنفش — عملیات ثانویه مثل افزودن زیرمجموعه */
.btn-alt { background: var(--alt); color: #fff; }
.btn-alt:hover { background: #5b3f9e; color: #fff; }

/* خاکستری — انصراف و بازگشت */
.btn-neutral { background: #eef1f4; color: var(--text); border-color: var(--border); }
.btn-neutral:hover { background: #e2e7ec; color: var(--text); }

/* شفاف روی هدر تیره */
.btn-outline { background: transparent; border-color: rgba(255,255,255,.5); color: #fff; }
.btn-outline:hover { background: rgba(255,255,255,.16); color: #fff; }

/* سازگاری با کلاس قدیمی */
.btn-ghost { background: #eef1f4; border-color: var(--border); color: var(--text); }
.btn-ghost:hover { background: #e2e7ec; color: var(--text); }

.btn-sm { padding: 5px 11px; font-size: .78rem; border-radius: 6px; }
.btn-lg { padding: 12px 26px; font-size: 1rem; }
.btn-block { width: 100%; }

/* گروه دکمه‌های داخل جدول */
td .btn + .btn, .btn-row .btn + .btn { margin-right: 4px; }
.btn-row { display: flex; flex-wrap: wrap; gap: 5px; }

/* ---------------- کارت‌ها ---------------- */
.card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 18px;
}
.card-head {
    padding: 14px 18px; border-bottom: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
}
.card-head h2, .card-head h3 { margin: 0; font-size: 1.02rem; }
.card-body { padding: 18px; }
.card-foot { padding: 12px 18px; border-top: 1px solid var(--border); background: #fafbfc; }

/* ---------------- فرم ---------------- */
.form-row { margin-bottom: 14px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 14px; }
label { display: block; margin-bottom: 5px; font-weight: 600; font-size: .85rem; color: var(--text-soft); }
label .req { color: var(--bad); }

input[type=text], input[type=password], input[type=number], input[type=email],
input[type=file], select, textarea {
    width: 100%; padding: 9px 12px; border: 1px solid var(--border); border-radius: 8px;
    font-family: inherit; font-size: .9rem; background: #fff; color: var(--text);
    transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
    outline: none; border-color: var(--brand-light);
    box-shadow: 0 0 0 3px var(--brand-ring);
}
input[readonly], input:disabled, select:disabled { background: #f1f4f7; color: var(--text-soft); }
textarea { min-height: 110px; resize: vertical; line-height: 1.8; }

.checkbox-row { display: flex; align-items: center; gap: 8px; }
.checkbox-row input { width: auto; }
.checkbox-row label { margin: 0; }

.help { font-size: .78rem; color: var(--text-soft); margin-top: 4px; }
.ltr { direction: ltr; text-align: left; }
.num { font-variant-numeric: tabular-nums; }

/* ---------------- جدول ---------------- */
.table-wrap { overflow-x: auto; }
table.grid { width: 100%; border-collapse: collapse; font-size: .86rem; }
table.grid th, table.grid td { padding: 9px 11px; border-bottom: 1px solid var(--border); text-align: right; }
table.grid th { background: #f7f9fa; font-weight: 700; color: var(--text-soft); white-space: nowrap; font-size: .8rem; }
table.grid tbody tr:hover { background: #fafbfc; }
table.grid td.money { font-variant-numeric: tabular-nums; white-space: nowrap; font-weight: 600; }
table.grid .empty { text-align: center; padding: 34px; color: var(--text-soft); }
table.grid tfoot td { background: #f7f9fa; font-weight: 700; }

/* ---------------- نشان‌ها ---------------- */
.badge {
    display: inline-block; padding: 2px 10px; border-radius: 20px;
    font-size: .74rem; font-weight: 700; background: #eef1f4; color: var(--text-soft); white-space: nowrap;
}
.badge-ok   { background: var(--ok-bg);   color: var(--ok); }
.badge-warn { background: var(--warn-bg); color: var(--warn); }
.badge-bad  { background: var(--bad-bg);  color: var(--bad); }
.badge-info { background: var(--info-bg); color: var(--info); }

/* ---------------- پیام‌ها ---------------- */
.msg { padding: 11px 15px; border-radius: 8px; margin-bottom: 15px; font-size: .88rem; font-weight: 600; }
.msg-ok   { background: var(--ok-bg);   color: var(--ok);   border: 1px solid #b9e3ca; }
.msg-bad  { background: var(--bad-bg);  color: var(--bad);  border: 1px solid #f3c4bf; }
.msg-warn { background: var(--warn-bg); color: var(--warn); border: 1px solid #f0dcb6; }
.msg-info { background: var(--info-bg); color: var(--info); border: 1px solid #c2ddf0; }

/* ---------------- آمار ---------------- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 16px 18px; box-shadow: var(--shadow); border-top: 3px solid var(--brand);
}
.stat .label { font-size: .8rem; color: var(--text-soft); margin-bottom: 6px; font-weight: 600; }
.stat .value { font-size: 1.5rem; font-weight: 800; font-variant-numeric: tabular-nums; color: var(--brand-dark); }
.stat .unit { font-size: .75rem; color: var(--text-soft); font-weight: 600; }
.stat.accent { border-top-color: var(--accent); }
.stat.accent .value { color: #8a6d0f; }
.stat.warn   { border-top-color: var(--warn); }
.stat.warn .value { color: var(--warn); }
.stat.bad    { border-top-color: var(--bad); }
.stat.bad .value { color: var(--bad); }

/* ---------------- پنل ---------------- */
.panel-layout { display: flex; min-height: calc(100vh - 64px); align-items: stretch; }
.sidebar {
    width: 235px; flex: 0 0 235px; background: var(--brand-dark); color: var(--side-text); padding: 14px 0;
}
.sidebar .user-box { padding: 12px 18px 16px; border-bottom: 1px solid rgba(255,255,255,.12); margin-bottom: 10px; }
.sidebar .user-box .name { color: #fff; font-weight: 700; font-size: .95rem; }
.sidebar .user-box .role { font-size: .76rem; color: var(--accent); font-weight: 600; }
.sidebar nav a {
    display: flex; align-items: center; gap: 9px; padding: 9px 18px;
    color: var(--side-text); font-size: .87rem; font-weight: 600; border-right: 3px solid transparent;
}
.sidebar nav a:hover { background: rgba(255,255,255,.07); color: #fff; }
.sidebar nav a.active { background: rgba(255,255,255,.11); color: #fff; border-right-color: var(--accent); }
.sidebar .group-title {
    padding: 14px 18px 6px; font-size: .72rem; font-weight: 700;
    color: rgba(255,255,255,.45); letter-spacing: .5px;
}
.panel-main { flex: 1; padding: 20px; min-width: 0; }
.page-head { margin-bottom: 18px; display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.page-head h1 { margin: 0; font-size: 1.35rem; }
.page-head .sub { font-size: .84rem; color: var(--text-soft); }

/* ---------------- درختواره ---------------- */
.tree { list-style: none; padding: 0; margin: 0; }
.tree ul { list-style: none; margin: 0; padding-right: 26px; position: relative; }
.tree ul::before {
    content: ''; position: absolute; top: 0; bottom: 14px; right: 10px;
    border-right: 1px dashed #b9c6d0;
}
.tree li { position: relative; padding: 3px 0; }
.tree ul > li::before {
    content: ''; position: absolute; top: 20px; right: -16px; width: 16px;
    border-top: 1px dashed #b9c6d0;
}
.node {
    display: inline-flex; align-items: center; gap: 10px; flex-wrap: wrap;
    background: #fff; border: 1px solid var(--border); border-radius: 8px;
    padding: 7px 12px; box-shadow: var(--shadow); font-size: .85rem;
}
.node.me { border-color: var(--brand); background: var(--brand-wash); box-shadow: 0 0 0 2px var(--brand-ring); }
.node.off { opacity: .6; background: #f6f7f8; }
.node .nm { font-weight: 700; }
.node .mb { color: var(--text-soft); font-size: .78rem; direction: ltr; }
.node .lv { font-size: .72rem; }
.tree-toggle {
    cursor: pointer; user-select: none; display: inline-flex; align-items: center; justify-content: center;
    width: 19px; height: 19px; border-radius: 5px; background: var(--brand); color: #fff;
    font-size: .82rem; font-weight: 800; line-height: 1; border: none; padding: 0;
}
.tree-toggle.leaf { background: #cdd6dd; cursor: default; }
li.collapsed > ul { display: none; }

/* ---------------- اسلایدر ---------------- */
.slider { position: relative; overflow: hidden; border-radius: 0; background: var(--brand-dark); }
.slide { display: none; position: relative; height: 380px; }
.slide.active { display: block; }
.slide img { width: 100%; height: 100%; object-fit: cover; opacity: .48; }
.slide .caption {
    position: absolute; inset: 0; display: flex; flex-direction: column;
    align-items: center; justify-content: center; text-align: center; color: #fff; padding: 20px;
}
.slide .caption h2 { font-size: 2rem; margin-bottom: .5rem; text-shadow: 0 2px 12px rgba(0,0,0,.5); }
.slide .caption p { font-size: 1.05rem; max-width: 640px; text-shadow: 0 2px 10px rgba(0,0,0,.5); }
.slider-dots { position: absolute; bottom: 14px; left: 0; right: 0; display: flex; justify-content: center; gap: 7px; }
.slider-dots span {
    width: 10px; height: 10px; border-radius: 50%; background: rgba(255,255,255,.45); cursor: pointer;
}
.slider-dots span.active { background: var(--accent); }

.hero-fallback {
    background: linear-gradient(135deg, var(--brand-dark), var(--brand-light));
    color: #fff; padding: 64px 20px; text-align: center;
}
.hero-fallback h1 { font-size: 2.1rem; margin-bottom: .6rem; }
.hero-fallback p { font-size: 1.05rem; opacity: .92; max-width: 680px; margin: 0 auto 18px; }

/* ---------------- محتوا ---------------- */
.section { padding: 42px 0; }
.section-head { text-align: center; margin-bottom: 28px; }
.section-head h2 { font-size: 1.5rem; }
.section-head p { color: var(--text-soft); margin: 0; }

.content-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(275px, 1fr)); gap: 18px; }
.content-card {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    overflow: hidden; box-shadow: var(--shadow); transition: transform .15s, box-shadow .15s;
    display: flex; flex-direction: column;
}
.content-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); }
.content-card .thumb {
    height: 165px; background: #e7ebef; position: relative; overflow: hidden;
    display: flex; align-items: center; justify-content: center;
}
.content-card .thumb img { width: 100%; height: 100%; object-fit: cover; }
.content-card .thumb .ph { font-size: 2.4rem; color: #aab6c0; }
.content-card .thumb .play {
    position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
    background: rgba(0,0,0,.28); color: #fff; font-size: 2.6rem;
}
.content-card .body { padding: 14px 16px; flex: 1; display: flex; flex-direction: column; }
.content-card .body h3 { font-size: .98rem; margin-bottom: 7px; }
.content-card .body p { font-size: .83rem; color: var(--text-soft); margin: 0 0 10px; flex: 1; }
.content-card .meta {
    display: flex; justify-content: space-between; align-items: center;
    font-size: .75rem; color: var(--text-soft); gap: 8px; flex-wrap: wrap;
}

.article-body { font-size: .95rem; line-height: 2.1; }
.article-body img { max-width: 100%; height: auto; border-radius: 8px; }
.video-frame { position: relative; padding-top: 56.25%; background: #000; border-radius: var(--radius); overflow: hidden; }
.video-frame iframe, .video-frame video { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }

/* ---------------- ورود ---------------- */
.login-wrap {
    min-height: 100vh; display: flex; align-items: center; justify-content: center;
    background: linear-gradient(135deg, var(--brand-dark), var(--brand-light)); padding: 20px;
}
.login-card {
    background: #fff; border-radius: 14px; box-shadow: var(--shadow-lg);
    width: 100%; max-width: 400px; padding: 30px;
}
.login-card .logo-big {
    display: block; width: 100%; max-width: 230px; height: auto;
    margin: 0 auto 18px;
}
.login-card h1 { text-align: center; font-size: 1.2rem; margin-bottom: 4px; }
.login-card .sub { text-align: center; color: var(--text-soft); font-size: .84rem; margin-bottom: 22px; }

/* ---------------- فوتر ---------------- */
.site-footer { background: var(--brand-dark); color: #b6c7da; padding: 34px 0 18px; margin-top: 44px; }
.site-footer h4 { color: #fff; font-size: .95rem; margin-bottom: 12px; }
.footer-logo { display: block; width: 54px; height: 54px; object-fit: contain; margin-bottom: 10px; }
.site-footer a { color: #b6c7da; display: block; padding: 3px 0; font-size: .85rem; }
.site-footer a:hover { color: #fff; }
.footer-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 26px; }
.footer-bottom {
    border-top: 1px solid rgba(255,255,255,.12); margin-top: 24px; padding-top: 14px;
    text-align: center; font-size: .8rem; color: #8ba1b8;
}

/* ---------------- کمکی ---------------- */
.flex { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.gap-8 { gap: 8px; } .gap-12 { gap: 12px; }
.mt-0 { margin-top: 0; } .mt-8 { margin-top: 8px; } .mt-16 { margin-top: 16px; } .mt-24 { margin-top: 24px; }
.mb-0 { margin-bottom: 0; } .mb-8 { margin-bottom: 8px; } .mb-16 { margin-bottom: 16px; }
.text-center { text-align: center; }
.text-soft { color: var(--text-soft); }
.text-ok { color: var(--ok); } .text-bad { color: var(--bad); }
.fw-700 { font-weight: 700; }
.small { font-size: .8rem; }
.nowrap { white-space: nowrap; }
.hidden { display: none !important; }
.toolbar { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 16px; }
.toolbar .form-row { margin-bottom: 0; }
.divider { height: 1px; background: var(--border); margin: 18px 0; }

/* ==========================================================
   رنگ پنل بر اساس نقش
   کلاس روی body از Panel.Master می‌آید. فقط متغیرها بازنویسی
   می‌شوند، پس هدر، منوی کناری، دکمه‌ها، نمودارها و همهٔ اجزا
   با هم عوض می‌شوند. سایت عمومی همیشه سبز می‌ماند.
   ========================================================== */

/* کاربر — سبز (همان پیش‌فرض) */
body.theme-user {
    --brand:        #0f5c4d;
    --brand-dark:   #0a4237;
    --brand-light:  #1b8a72;
    --brand-ring:   rgba(27,138,114,.16);
    --brand-wash:   #eef7f4;
    --side-text:    #cfe6e0;
}

/* نماینده — بنفش */
body.theme-agent {
    --brand:        #5d3a9b;
    --brand-dark:   #41276f;
    --brand-light:  #7c54c4;
    --brand-ring:   rgba(124,84,196,.18);
    --brand-wash:   #f3eefb;
    --side-text:    #ddd0f2;
    /* بنفشِ دکمهٔ ثانویه با رنگ پنل قاطی نشود */
    --alt:          #b0417a;
    --alt-bg:       #fbeaf3;
}

/* ادمین کل — آبی */
body.theme-admin {
    --brand:        #1a5fa8;
    --brand-dark:   #123f73;
    --brand-light:  #2f7fcc;
    --brand-ring:   rgba(47,127,204,.18);
    --brand-wash:   #eaf3fc;
    --side-text:    #cfe0f2;
    /* آبیِ دکمهٔ «مشاهده» با رنگ پنل قاطی نشود */
    --info:         #0f7b8a;
    --info-bg:      #e4f4f6;
}

/* نشان نقش کنار لوگو — تشخیص پنل فقط به رنگ وابسته نباشد */
.role-chip {
    display: inline-flex; align-items: center; gap: 6px;
    background: rgba(255,255,255,.18); border: 1px solid rgba(255,255,255,.34);
    color: #fff; font-size: .76rem; font-weight: 700;
    padding: 3px 11px; border-radius: 20px; white-space: nowrap; flex: 0 0 auto;
}
.role-chip::before {
    content: ''; width: 7px; height: 7px; border-radius: 50%;
    background: var(--accent); flex: 0 0 7px;
}

/* ==========================================================
   نمودار — SVG سمت سرور، بدون کتابخانهٔ بیرونی
   مسیرها کشیده می‌شوند تا عرض را پر کنند، ولی همهٔ متن‌ها HTML
   معمولی‌اند تا اندازهٔ قلم روی موبایل خوانا بماند.
   ========================================================== */
.chart {
    direction: ltr;                 /* محور زمان از چپ به راست */
    display: grid;
    grid-template-columns: auto 1fr;
    grid-template-rows: var(--chart-h, 230px) auto auto;
    grid-template-areas: "y plot" "ycorner x" "legend legend";
    column-gap: 9px;
    font-variant-numeric: tabular-nums;
}
.chart-y { grid-area: y; position: relative; width: 54px; }
.chart-y span {
    position: absolute; right: 0; transform: translateY(-50%);
    font-size: .7rem; color: var(--text-soft); white-space: nowrap; line-height: 1;
}
.chart-plot { grid-area: plot; position: relative; min-width: 0; }
.chart-grid { position: absolute; inset: 0; display: flex; flex-direction: column; justify-content: space-between; }
.chart-grid i { display: block; height: 0; border-top: 1px dashed var(--border); }
.chart-svg { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

.chart-fill.past    { fill: var(--brand); fill-opacity: .17; stroke: none; }
.chart-fill.future  { fill: var(--text-soft); fill-opacity: .07; stroke: none; }
.chart-line         { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart-line.past    { stroke: var(--brand); }
.chart-line.future  { stroke: var(--text-soft); stroke-width: 1.5; stroke-dasharray: 5 4; }
.chart-bar.past     { fill: var(--brand); }
.chart-bar.future   { fill: #c9d2da; }

.chart-today { position: absolute; top: 0; bottom: 0; width: 0; border-right: 1px solid var(--bad); }
.chart-today span {
    position: absolute; top: 1px; right: 4px; font-size: .65rem; font-weight: 700; color: var(--bad);
    background: rgba(255,255,255,.88); padding: 0 4px; border-radius: 4px; white-space: nowrap;
}

/* ستون‌های نامرئی برای نمایش مقدار هر بازه روی موشواره */
.chart-hover { position: absolute; inset: 0; display: flex; }
.chart-hover i { flex: 1 1 0; position: relative; min-width: 0; }
.chart-hover i:hover { background: rgba(31,41,51,.045); }
.chart-hover i:hover::after {
    content: ''; position: absolute; left: 50%; bottom: var(--v, 0%);
    width: 9px; height: 9px; margin: 0 0 -4.5px -4.5px; border-radius: 50%;
    background: #fff; border: 2px solid var(--brand);
}
.chart-hover i.future:hover::after { border-color: var(--text-soft); }

.chart-x { grid-area: x; position: relative; height: 18px; margin-top: 7px; }
.chart-x span {
    position: absolute; transform: translateX(-50%);
    font-size: .68rem; color: var(--text-soft); white-space: nowrap; line-height: 1;
}
.chart-x span.edge-start { transform: none; }
.chart-x span.edge-end   { transform: translateX(-100%); }

.chart-legend {
    grid-area: legend; direction: rtl; display: flex; gap: 14px; flex-wrap: wrap; align-items: center;
    margin-top: 9px; font-size: .75rem; color: var(--text-soft);
}
.chart-legend .sw { display: inline-block; width: 15px; height: 4px; border-radius: 2px; margin-left: 5px; vertical-align: middle; }
.chart-legend .sw.past   { background: var(--brand); }
.chart-legend .sw.future { background: #c9d2da; }
.chart-legend .unit { margin-left: auto; }

.chart-empty { padding: 32px 18px; text-align: center; color: var(--text-soft); font-size: .86rem; }

/* روی عرض کم، برچسب‌های محور افقی روی هم می‌افتند؛ فقط اول، وسط و آخر بماند */
@media (max-width: 620px) {
    .chart-x span:nth-child(2):not(:last-child),
    .chart-x span:nth-child(3):not(:last-child),
    .chart-x span:nth-child(5):not(:last-child),
    .chart-x span:nth-child(6):not(:last-child) { display: none; }
}

/* ==========================================================
   دکمهٔ منوی موبایل — روی دسکتاپ پنهان است
   ========================================================== */
.menu-toggle {
    display: none;
    align-items: center; justify-content: center; gap: 7px;
    background: rgba(255,255,255,.14); color: #fff;
    border: 1px solid rgba(255,255,255,.28); border-radius: 8px;
    padding: 8px 13px; font-family: inherit; font-size: .86rem; font-weight: 700;
    cursor: pointer;
}
.menu-toggle .bars { display: inline-flex; flex-direction: column; gap: 3px; }
.menu-toggle .bars i { display: block; width: 17px; height: 2px; background: #fff; border-radius: 2px; }

/* ==========================================================
   تبلت
   ========================================================== */
@media (max-width: 1024px) {
    .slide { height: 320px; }
    .stat-grid { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
}

/* ==========================================================
   موبایل و تبلت کوچک
   ========================================================== */
@media (max-width: 900px) {

    body { font-size: 15px; }

    /* ---- هدر ---- */
    .site-header .container,
    .site-header .container-wide { min-height: 54px; gap: 8px; flex-wrap: nowrap; }
    .brand { font-size: .95rem; gap: 7px; min-width: 0; flex: 1 1 auto; overflow: hidden; }
    .brand span:not(.logo) { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .brand .logo { width: 34px; height: 34px; flex: 0 0 34px; }
    .header-actions { margin-right: auto !important; flex: 0 0 auto; gap: 6px; }
    .header-actions .btn { padding: 8px 11px; font-size: .8rem; min-height: 36px; }
    /* داخل پنل، فضا برای دکمهٔ منو باز می‌شود */
    .panel-layout ~ * .brand span:not(.logo),
    body:has(.panel-layout) .brand span:not(.logo) { max-width: 120px; }
    .top-bar { font-size: .74rem; }
    .top-bar .container { justify-content: center; gap: 6px; }

    /* ---- منوی سایت عمومی ---- */
    .main-nav {
        order: 10; width: 100%; margin-right: 0;
        overflow-x: auto; flex-wrap: nowrap; padding-bottom: 4px;
        -webkit-overflow-scrolling: touch; scrollbar-width: none;
    }
    .main-nav::-webkit-scrollbar { display: none; }
    .main-nav a { padding: 7px 12px; font-size: .84rem; flex: 0 0 auto; }

    /* ---- پنل: منوی کناری کشویی ---- */
    .menu-toggle { display: inline-flex; }

    .panel-layout { flex-direction: column; min-height: auto; }

    .sidebar {
        width: 100%; flex: none; padding: 0;
        max-height: 0; overflow: hidden;
        transition: max-height .25s ease;
    }
    .sidebar.open { max-height: 1400px; padding: 10px 0 14px; }

    .sidebar .user-box { padding: 10px 16px 12px; margin-bottom: 6px; }
    .sidebar nav { display: flex; flex-direction: column; }
    .sidebar nav a {
        padding: 12px 18px; font-size: .92rem;
        border-right: 4px solid transparent; border-bottom: 1px solid rgba(255,255,255,.06);
    }
    .sidebar .group-title { padding: 12px 18px 5px; font-size: .74rem; }

    .panel-main { padding: 14px 12px 28px; }

    /* ---- دکمه‌ها: اندازهٔ مناسب لمس ---- */
    .btn { min-height: 42px; padding: 10px 16px; font-size: .9rem; }
    .btn-sm { min-height: 36px; padding: 8px 13px; font-size: .82rem; }
    .btn-lg { min-height: 48px; }
    .main-nav a { min-height: 38px; display: inline-flex; align-items: center; }
    .menu-toggle { min-height: 40px; }
    .tree-toggle { width: 26px; height: 26px; font-size: .95rem; }
    .slider-dots span { width: 13px; height: 13px; }

    /* ---- سرصفحهٔ صفحه ---- */
    .page-head { gap: 10px; }
    .page-head h1 { font-size: 1.15rem; }
    .page-head .sub { font-size: .8rem; }
    .page-head > span,
    .page-head > a.btn,
    .page-head > input.btn { width: 100%; }
    .page-head > span .btn { flex: 1; }

    /* ---- نشان نقش ---- */
    .role-chip { font-size: .7rem; padding: 3px 8px; gap: 4px; }
    /* فقط در پنل که نشان نقش هم جا می‌خواهد، نام برند تنگ‌تر می‌شود */
    body[class*="theme-"] .brand span:not(.logo) { max-width: 92px; }

    /* ---- نمودار ---- */
    .chart { grid-template-rows: var(--chart-h, 230px) auto auto; column-gap: 6px; }
    .chart-y { width: 48px; }
    .chart-y span { font-size: .64rem; }
    .chart-x span { font-size: .62rem; }
    .chart-legend { font-size: .7rem; gap: 10px; }
    .chart-legend .unit { margin-left: 0; }

    /* ---- آمار ---- */
    .stat-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 14px; }
    .stat { padding: 12px 13px; }
    .stat .label { font-size: .74rem; margin-bottom: 3px; }
    .stat .value { font-size: 1.15rem; }
    .stat .unit { font-size: .7rem; }

    /* ---- کارت‌ها ---- */
    .card { margin-bottom: 14px; border-radius: 9px; }
    .card-head { padding: 12px 14px; }
    .card-head h2, .card-head h3 { font-size: .95rem; }
    .card-body { padding: 14px; }
    .card-foot { padding: 12px 14px; }
    .card-foot .btn { width: 100%; margin-bottom: 8px; }
    .card-foot .btn:last-child { margin-bottom: 0; }

    /* ---- فرم‌ها: تک‌ستونه و لمسی ---- */
    .form-grid { grid-template-columns: 1fr; gap: 12px; }
    input[type=text], input[type=password], input[type=number], input[type=email],
    input[type=file], select, textarea {
        padding: 11px 12px; font-size: 16px;   /* ۱۶px از زوم خودکار iOS جلوگیری می‌کند */
    }
    label { font-size: .84rem; }
    .toolbar { gap: 10px; }
    .toolbar .form-row { width: 100%; }
    .toolbar .btn { width: 100%; }

    /* ---- جدول‌ها: تبدیل هر سطر به کارت ---- */
    table.grid thead { display: none; }
    table.grid, table.grid tbody, table.grid tr, table.grid td { display: block; width: 100%; }
    table.grid tr {
        background: #fff; border: 1px solid var(--border); border-radius: 9px;
        margin-bottom: 10px; padding: 4px 0; box-shadow: var(--shadow);
    }
    table.grid tbody tr:hover { background: #fff; }
    table.grid td {
        border-bottom: 1px dashed var(--border);
        padding: 8px 13px; text-align: left;
        display: flex; justify-content: space-between; align-items: center; gap: 10px;
    }
    table.grid td:last-child { border-bottom: none; }
    /* عنوان ستون از data-label کنار مقدار نشان داده می‌شود */
    table.grid td::before {
        content: attr(data-label);
        font-weight: 700; color: var(--text-soft); font-size: .78rem;
        text-align: right; flex: 0 0 auto;
    }
    table.grid td:empty { display: none; }
    table.grid td.money { justify-content: space-between; }
    table.grid .empty { text-align: center; display: block; padding: 22px; }
    table.grid .empty::before { content: ""; }
    table.grid tfoot { display: block; }
    table.grid tfoot tr { background: #f7f9fa; }
    /* ردیف دکمه‌ها ته کارت */
    table.grid td.actions, table.grid td.nowrap {
        display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-start; white-space: normal;
    }
    table.grid td.actions::before, table.grid td.nowrap::before { content: ""; display: none; }
    table.grid td.actions .btn, table.grid td.nowrap .btn { flex: 1 1 auto; min-width: 90px; margin: 0; }
    .table-wrap { overflow: visible; }

    /* ---- درختواره ---- */
    .tree ul { padding-right: 16px; }
    .tree ul::before { right: 7px; }
    .tree ul > li::before { right: -9px; width: 9px; }
    .node { font-size: .8rem; padding: 6px 9px; gap: 6px; }
    .node .mb { font-size: .72rem; }
    .badge { font-size: .68rem; padding: 2px 7px; }

    /* ---- اسلایدر و محتوا ---- */
    .slide { height: 230px; }
    .slide .caption h2 { font-size: 1.3rem; }
    .slide .caption p { font-size: .9rem; }
    .hero-fallback { padding: 44px 16px; }
    .hero-fallback h1 { font-size: 1.5rem; }
    .section { padding: 28px 0; }
    .section-head h2 { font-size: 1.25rem; }
    .content-grid { grid-template-columns: 1fr; gap: 14px; }
    .content-card .thumb { height: 180px; }

    /* ---- فوتر ---- */
    .site-footer { padding: 26px 0 14px; margin-top: 28px; }
    .footer-grid { gap: 18px; }
}

/* ==========================================================
   موبایل کوچک
   ========================================================== */
@media (max-width: 480px) {
    /* روی صفحهٔ باریک، نشان نقش جا نمی‌شود؛ رنگ هدر و منو تفاوت را نشان می‌دهد */
    .role-chip { display: none; }
    .chart { --chart-h: 180px !important; }
    .chart-y { width: 44px; }
    .stat-grid { grid-template-columns: 1fr; }
    .stat .value { font-size: 1.3rem; }
    .brand span:not(.logo) { font-size: .88rem; }
    body[class*="theme-"] .brand span:not(.logo) { max-width: 105px; }
    .menu-toggle span:not(.bars) { display: none; }
    .menu-toggle { padding: 8px 10px; }
    .login-card { padding: 22px 18px; }
    .slide { height: 195px; }
    table.grid td { padding: 7px 11px; font-size: .84rem; }
    .container, .container-wide { padding: 0 12px; }
}

/* ==========================================================
   چاپ
   ========================================================== */
@media print {
    .sidebar, .site-header, .site-footer, .top-bar, .toolbar,
    .btn, .menu-toggle, .card-foot { display: none !important; }
    .panel-main { padding: 0; }
    .card { box-shadow: none; border: 1px solid #ccc; page-break-inside: avoid; }
    body { background: #fff; }
}

/* پنهان‌سازی روی صفحه‌های کوچک */
@media (max-width: 900px) {
    .hide-sm { display: none !important; }
}
