/* distco.ir — سامانه پایش شرکت‌های توزیع | RTL, Vazirmatn */
:root {
  --navy: #16324f;
  --navy-2: #1e4266;
  --blue: #2563eb;
  --blue-soft: #dbeafe;
  /* تنالیته توانیر (۱۴۰۵/۰۹/۰۲): زرد طلایی دایره نشان + قرمز زیگزاگ نشان */
  --gold: #f5b800;
  --gold-dark: #a67c00;
  --gold-soft: #fef3c7;
  --tavanir-red: #e30613;
  --green: #15803d;
  --green-soft: #dcfce7;
  --red: #b91c1c;
  --red-soft: #fee2e2;
  --amber: #b45309;
  --amber-soft: #fef3c7;
  --bg: #f1f5f9;
  --card: #ffffff;
  --text: #1e293b;
  --muted: #64748b;
  --border: #e2e8f0;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Vazirmatn", Tahoma, sans-serif;
  /* گرادیان ملایم پس‌زمینه (۱۴۰۵/۰۹/۰۲): فقط سی‌اس‌اس، یک‌بار نقاشی
     می‌شود؛ بدون تصویر، بدون تاری و بدون فونت تازه — سرعت را کم نمی‌کند. */
  background: linear-gradient(180deg, #f4f7fa 0%, #e9eef3 100%);
  background-attachment: scroll;
  color: var(--text);
  font-size: 14px;
  line-height: 1.8;
}
a { color: var(--gold-dark); }
button, input, select, textarea { font-family: inherit; font-size: 14px; }
input, select, textarea {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  background: #fff;
  width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--gold-soft); border-color: var(--gold); }
label { display: block; font-weight: 600; margin-bottom: 4px; }
.hidden { display: none !important; }

/* ---------- login ---------- */
/* پس‌زمینه صفحه ورود (۱۴۰۵/۰۹/۰۲): سه تصویر سبک مرتبط با توانیر
   (دکل و خط انتقال، پست برق) با چرخش نرم؛ روی آن‌ها یک لایه سرمه‌ای
   نیمه‌شفاف است تا کارت سفید خوانا بماند. تصویر اول همان اول بارگذاری
   می‌شود و بقیه در پس‌زمینه می‌آیند. */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; background: var(--navy); position: relative; overflow: hidden; }
.login-bg { position: absolute; inset: 0; overflow: hidden; }
.login-bg-img { position: absolute; inset: 0; background-size: cover; background-position: center; opacity: 0; animation: loginBg 18s infinite; }
.login-bg-img:nth-child(1) { animation-delay: 0s; }
.login-bg-img:nth-child(2) { animation-delay: 6s; }
.login-bg-img:nth-child(3) { animation-delay: 12s; }
@keyframes loginBg {
  0% { opacity: 0; }
  8% { opacity: 1; }
  33% { opacity: 1; }
  41% { opacity: 0; }
  100% { opacity: 0; }
}
.login-bg::after { content: ""; position: absolute; inset: 0; background: rgba(22,50,79,.55); }
.login-card { background: #fff; border-radius: 16px; padding: 32px; width: 100%; max-width: 420px; box-shadow: 0 20px 50px rgba(0,0,0,.25); position: relative; z-index: 1; border-top: 4px solid var(--tavanir-red); }
.login-card h1 { margin: 0 0 4px; font-size: 20px; color: var(--navy); }
.login-card p { color: var(--muted); margin: 0 0 20px; }
/* نشان توانیر در صفحه ورود (۱۴۰۵/۰۹/۰۲): تنها تصویر طراحی سامانه؛
   روی کارت سفید، بدون تاری و بدون پس‌زمینه ثابت — سبک و سریع. */
.login-logo { display: block; width: 140px; height: auto; margin: 0 auto 16px; }
.login-card .field { margin-bottom: 14px; }

/* ---------- layout ---------- */
.shell { display: flex; min-height: 100vh; }
.sidebar { width: 250px; background: linear-gradient(180deg, var(--navy) 0%, #0e2338 100%); color: #fff; padding: 18px 12px; flex-shrink: 0; }
.sidebar h1 { font-size: 17px; margin: 4px 8px 2px; }
.sidebar .sub { color: #94a3b8; font-size: 12px; margin: 0 8px 18px; }
.sidebar nav button {
  display: block; width: 100%; text-align: right; background: transparent;
  border: 0; color: #cbd5e1; padding: 10px 12px; border-radius: 8px; cursor: pointer; margin-bottom: 2px;
}
.sidebar nav button:hover { background: rgba(255,255,255,.08); color: #fff; }
.sidebar nav button.active { background: var(--gold); color: var(--navy); box-shadow: 0 2px 8px rgba(0,0,0,.28); }
/* ---------- بخش‌بندی منو (۱۴۰۵/۰۹/۰۲): ۴ بخش اصلی سامانه ---------- */
.nav-section { margin-bottom: 10px; }
.nav-section-title {
  display: flex; width: 100%; align-items: center; justify-content: space-between;
  background: transparent; border: 0; color: #94a3b8; font-size: 12px; font-weight: 700;
  padding: 8px 12px 4px; cursor: pointer; text-align: right;
}
.nav-section-title:hover { color: #fff; }
.nav-section-title .chev { display: inline-block; transition: transform .2s; font-size: 11px; }
.nav-section.collapsed .nav-section-title .chev { transform: rotate(90deg); }
.nav-section.collapsed .nav-section-items { display: none; }
.nav-section-items button { padding-right: 22px; }
.sidebar .who { margin: 18px 8px 0; padding-top: 14px; border-top: 1px solid rgba(255,255,255,.15); font-size: 13px; color: #cbd5e1; }
.sidebar .who button { background: transparent; border: 1px solid rgba(255,255,255,.4); color: #fff; border-radius: 8px; padding: 4px 12px; cursor: pointer; margin-top: 8px; }
.main { flex: 1; padding: 22px 26px; min-width: 0; }
.main h2 { margin: 0 0 4px; font-size: 20px; color: var(--navy); }
.main h2::after { content: ""; display: block; width: 52px; height: 3px; background: var(--gold); border-radius: 2px; margin-top: 6px; }
.main .desc { color: var(--muted); margin: 0 0 18px; }

/* ---------- cards / KPI ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; margin-bottom: 18px; }
.kpi { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; box-shadow: 0 1px 3px rgba(22,50,79,.06), 0 4px 12px rgba(22,50,79,.05); border-top: 3px solid var(--navy); }
.kpi .n { font-size: 26px; font-weight: 800; color: var(--navy); line-height: 1.2; }
.kpi .t { color: var(--muted); font-size: 13px; }
.card { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 18px; margin-bottom: 18px; box-shadow: 0 1px 3px rgba(22,50,79,.06), 0 4px 12px rgba(22,50,79,.05); }
.card h3 { margin: 0 0 12px; font-size: 16px; color: var(--navy); }
.card h4 { margin: 16px 0 8px; font-size: 14px; color: var(--navy); }

/* ---------- داشبورد مدیریت (#/admin): کارت‌های آماری + بخش‌های کشویی ---------- */
.admin-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat-card { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 14px 10px; text-align: center; box-shadow: 0 1px 3px rgba(22,50,79,.06), 0 4px 12px rgba(22,50,79,.05); }
.stat-num { font-size: 28px; font-weight: 700; color: var(--navy); line-height: 1.2; }
.stat-label { color: var(--muted); font-size: 13px; margin-top: 4px; }
.stat-pending { border-top: 3px solid var(--gold); }
.stat-pending .stat-num { color: var(--gold-dark); }
.collapse-head { width: 100%; text-align: right; background: none; border: none; cursor: pointer; font-family: inherit; font-size: 16px; font-weight: 700; color: var(--navy); padding: 0; display: flex; justify-content: space-between; align-items: center; }
.collapse-meta { font-size: 13px; font-weight: 400; color: var(--muted); }
.collapse-arrow { display: inline-block; transition: transform .2s; margin-right: 4px; }
.collapsible.collapsed .collapse-body { display: none; }
.collapsible.collapsed .collapse-arrow { transform: rotate(-90deg); }
.collapsible .collapse-body { margin-top: 12px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
@media (max-width: 900px) { .grid2 { grid-template-columns: 1fr; } }

/* ---------- موبایل (مدیران بیشتر با موبایل کار می‌کنند) ---------- */
@media (max-width: 768px) {
  html, body { overflow-x: hidden; }
  /* ستون کناری ثابت، دلیل اصلی به‌هم‌ریختگی موبایل بود: ۲۵۰ پیکسل از
     صفحه ۳۹۰ پیکسلی را می‌گرفت و برای محتوا فقط ۱۴۰ پیکسل می‌ماند.
     در موبایل، نوار کناری به یک سربرگ بالای صفحه تبدیل می‌شود. */
  .shell { flex-direction: column; }
  .sidebar { width: 100%; padding: 12px 12px 10px; }
  .sidebar h1 { font-size: 15px; margin: 2px 4px; }
  .sidebar .sub { margin: 0 4px 10px; }
  /* منوی گروه‌بندی‌شده در موبایل: عمودی و بازشونده (به‌جای نوار افقی) */
  .sidebar nav { display: block; overflow-x: visible; padding-bottom: 0; }
  .sidebar nav button { width: 100%; flex-shrink: 1; white-space: normal; padding: 10px 12px; margin-bottom: 2px; }
  .sidebar nav .nav-section { margin-bottom: 6px; }
  .sidebar .who { margin: 10px 4px 0; padding-top: 10px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
  .sidebar .who button { margin-top: 0; }
  .main { padding: 14px 12px; }
  .main h2 { font-size: 18px; }
  .card { padding: 14px; margin-bottom: 14px; }
  .login-card { padding: 24px 20px; }
  .login-wrap { padding: 12px; }
  .mgmt-overall { padding: 16px; }
  .mgmt-overall-score { font-size: 32px; }
  .iran-map { max-width: 100%; }
  th, td { padding: 6px 8px; font-size: 13px; }
  .toolbar .field { min-width: 140px; }
  .kpis { gap: 10px; }
  .mgmt-programs { gap: 10px; }
  .form-grid { gap: 10px; }
}
@media (max-width: 400px) {
  body { font-size: 13px; }
  button, input, select, textarea { font-size: 13px; }
  .main { padding: 12px 10px; }
  .card { padding: 12px; }
}
.progress { height: 10px; background: #e2e8f0; border-radius: 6px; overflow: hidden; }
.progress > div { height: 100%; background: var(--gold); }
.sample-badge { background: var(--amber-soft); color: var(--amber); border-radius: 6px; padding: 1px 8px; font-size: 11px; font-weight: 700; }

/* ---------- tables ---------- */
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; margin-bottom: 12px; }
.toolbar .field { min-width: 170px; flex: 1; }
.table-wrap { overflow-x: auto; }

/* تب‌های بخش بسته اضطراری در کنسول و تب‌های کل کنسول — هر تب یک بخش یکپارچه است */
.emg-tabs, .console-tabs { display: flex; gap: 4px; flex-wrap: wrap; border-bottom: 2px solid var(--border); margin: 4px 0 14px; }
.emg-tab-btn, .console-tab-btn { border: 0; background: none; padding: 8px 14px; cursor: pointer; font-size: 14px; color: var(--muted); border-bottom: 3px solid transparent; margin-bottom: -2px; }
.emg-tab-btn:hover, .console-tab-btn:hover { color: var(--navy); }
.emg-tab-btn.active, .console-tab-btn.active { color: var(--navy); font-weight: 700; border-bottom-color: var(--gold); }
.emg-tab-panel, .console-tab-panel { display: none; }
.emg-tab-panel.active, .console-tab-panel.active { display: block; }
table { border-collapse: collapse; width: 100%; background: #fff; }
th, td { border: 1px solid var(--border); padding: 8px 10px; text-align: right; white-space: nowrap; }
th { background: #e8eef4; color: var(--navy); border-bottom: 2px solid var(--gold); }
tr:nth-child(even) td { background: #f8fafc; }

/* ---------- forms ---------- */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.form-grid .full { grid-column: 1 / -1; }
.calc-box { background: var(--blue-soft); border-radius: 10px; padding: 12px 14px; }
.calc-box b { color: var(--navy); }

/* ---------- buttons ---------- */
.btn { border: 0; border-radius: 8px; padding: 9px 18px; cursor: pointer; background: linear-gradient(180deg, #ffd91e 0%, var(--gold) 100%); color: var(--navy); font-weight: 600; box-shadow: 0 2px 6px rgba(166,124,0,.25); }
.btn:hover { filter: brightness(1.08); }
.btn.secondary { background: #e2e8f0; color: var(--text); }
.btn.danger { background: var(--red); }
.btn.green { background: var(--green); }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn:disabled { opacity: .55; cursor: default; }

/* ---------- misc ---------- */
.alert { border-radius: 10px; padding: 12px 14px; margin-bottom: 14px; }
.alert.err { background: var(--red-soft); color: var(--red); border: 1px solid #fecaca; }
.alert.ok { background: var(--green-soft); color: var(--green); border: 1px solid #bbf7d0; }
.alert.info { background: var(--blue-soft); color: #1e40af; border: 1px solid #bfdbfe; }
pre.code { background: #0f172a; color: #e2e8f0; border-radius: 10px; padding: 14px; direction: ltr; text-align: left; overflow-x: auto; font-size: 13px; }
.chat-box { border: 1px solid var(--border); border-radius: 12px; background: #fff; padding: 14px; max-height: 320px; overflow-y: auto; margin-bottom: 12px; }
.chat-msg { margin-bottom: 8px; }
.chat-msg.in { text-align: right; }
.chat-msg.out { text-align: left; }
.chat-msg span { display: inline-block; padding: 8px 12px; border-radius: 12px; max-width: 80%; }
.chat-msg.in span { background: var(--blue-soft); }
.chat-msg.out span { background: #f1f5f9; }
.muted { color: var(--muted); font-size: 13px; }

/* ---------- داشبورد مدیریتی ---------- */
.mgmt-overall { text-align: center; padding: 22px; }
.mgmt-overall-score { font-size: 40px; font-weight: 800; line-height: 1.2; }
.mgmt-programs { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; margin-bottom: 18px; }
.mgmt-program-card { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; cursor: pointer; transition: box-shadow .2s ease, transform .2s ease; box-shadow: 0 1px 3px rgba(22,50,79,.06), 0 4px 12px rgba(22,50,79,.05); }
.mgmt-program-card:hover { box-shadow: 0 6px 18px rgba(22, 50, 79, .12); transform: translateY(-2px); }
.mgmt-program-card.selected { box-shadow: 0 0 0 2px var(--navy); }
.mgmt-prog-title { font-weight: 700; color: var(--navy); margin-bottom: 4px; }
.mgmt-prog-score { font-size: 24px; font-weight: 800; color: var(--navy); line-height: 1.3; margin-bottom: 6px; }
.band-chip { display: inline-block; border-radius: 999px; padding: 2px 10px; font-size: 12px; font-weight: 700; white-space: nowrap; }
.mgmt-legend { display: flex; gap: 8px; flex-wrap: wrap; }
.mgmt-company { margin-bottom: 16px; }
.mgmt-company-head { margin-bottom: 8px; }
.iran-map { max-width: 960px; margin: 0 auto; }
.map-card-full { grid-column: 1 / -1; }
.iran-map svg { width: 100%; height: auto; display: block; }
.iran-map svg path, .iran-map svg polygon { cursor: pointer; transition: filter .25s ease; }
.iran-map svg path:hover, .iran-map svg polygon:hover { filter: brightness(1.12); }
/* استان/شرکت انتخاب‌شده فقط با رنگ و قاب مشخص می‌شود؛ از نقشه جدا
   نمی‌شود و برچسبش هم سر جایش می‌ماند (درخواست کاربر ۱۴۰۵/۰۹/۰۱) */
.iran-map .prov-selected { filter: brightness(1.18); stroke: #111827; stroke-width: 2.5; }
/* برچسب نام شرکت روی نقشه: فونت صمیم (خواناتر از وزیرمتن در اندازه کوچک)؛
   هاله بر حسب رنگ متن است: متن سفید روی باند تیره هاله تیره می‌گیرد تا حروف
   چاق و تار نشوند، متن تیره روی باند روشن هاله سفید می‌گیرد */
.iran-map .map-label { font-family: "Samim", Tahoma, sans-serif; font-size: 13px; font-weight: 700; pointer-events: none; paint-order: stroke; stroke-width: 2; }
.iran-map .map-label-light { stroke: rgba(0,0,0,.45); }
.iran-map .map-label-dark { stroke: rgba(255,255,255,.9); }
.iran-map .prov-dimmed { opacity: .22; filter: grayscale(1); }
.iran-map .map-label-dimmed { opacity: .25; }
.iran-map .map-city-marker { pointer-events: none; }
/* دکمه بزرگ انتخاب شرکت در پنل جزئیات استان (جایگزین ساده کلیک روی
   دایره کوچک نقشه): تمام‌عرض، لمسی و واضح. */
.company-pick { display: block; width: 100%; text-align: right; margin: 8px 0; padding: 14px 16px; font-size: 1.05rem; }
/* شرکت انتخاب‌شده در پنل جزئیات / شرکت‌های دیگر کم‌رنگ */
.mgmt-company-selected { border: 2px solid #2563eb; border-radius: 12px; padding: 10px; }
.mgmt-company-dimmed { opacity: .45; filter: grayscale(.7); }
.mgmt-company-head[data-select-company] { cursor: pointer; }
/* ردیف برنامه قابل‌کلیک (باز کردن نمودارهای روند همان برنامه) */
.prog-row { cursor: pointer; }
.prog-row:hover td { background: #eff6ff; }
/* تفاوت با میانگین کل شرکت‌ها */
.diff-up { color: #15803d; font-weight: 700; }
.diff-down { color: #dc2626; font-weight: 700; }
.diff-same { color: #64748b; }
.seg-btn.active { background: var(--navy); color: #fff; }

/* ---------- بازدید میدانی: برچسب نتیجه + گزارش قابل چاپ ---------- */
.chip-ok, .chip-bad, .chip-warn { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 700; }
.chip-ok { background: #dcfce7; color: #166534; }
.chip-bad { background: #fee2e2; color: #991b1b; }
.chip-warn { background: #fef3c7; color: #92400e; }
.fv-report { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 24px; }
.fv-report-head { text-align: center; border-bottom: 2px solid var(--gold); padding-bottom: 12px; margin-bottom: 16px; }
.fv-report-head h2 { margin: 0 0 4px; color: var(--navy); }
.fv-report-head p { color: var(--muted); margin: 0; font-size: 13px; }
.fv-report-meta { width: 100%; border-collapse: collapse; margin-bottom: 18px; }
.fv-report-meta th, .fv-report-meta td { border: 1px solid var(--border); padding: 8px 10px; text-align: right; font-size: 14px; }
.fv-report-meta th { background: #e8eef4; color: var(--navy); width: 130px; }
.fv-report-item { border: 1px solid var(--border); border-radius: 8px; padding: 14px; margin-bottom: 14px; page-break-inside: avoid; }
.fv-report-item h3 { margin: 0 0 8px; font-size: 15px; color: var(--navy); }
.fv-report-item p { margin: 4px 0; font-size: 14px; }
.fv-report-photo { max-width: 100%; max-height: 320px; border-radius: 8px; margin-top: 8px; }
.fv-report-sign { margin-top: 24px; display: flex; justify-content: space-between; font-size: 14px; }
@media print {
  .sidebar, .no-print, #page-alert { display: none !important; }
  .shell { display: block !important; }
  .main { padding: 0 !important; margin: 0 !important; }
  .fv-report { border: none; padding: 0; }
  body { background: #fff !important; }
}

/* ---------- تقویم جدولی جلالی ---------- */
input.jalali-date { cursor: pointer; background: #fff; }
.jalali-picker { display: none; position: absolute; z-index: 1000; width: 272px; background: var(--card); border: 1px solid var(--border); border-radius: 12px; box-shadow: 0 8px 28px rgba(0,0,0,.18); padding: 12px; direction: rtl; }
.jp-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.jp-title { font-weight: 700; color: var(--navy); font-size: 15px; }
.jp-nav { width: 30px; height: 30px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--navy); font-size: 18px; cursor: pointer; line-height: 1; }
.jp-nav:hover { background: #e8eef4; }
.jp-week { display: grid; grid-template-columns: repeat(7, 1fr); text-align: center; font-size: 12px; color: var(--muted); font-weight: 700; margin-bottom: 4px; }
.jp-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.jp-day { height: 32px; border: none; border-radius: 8px; background: transparent; color: var(--text); font-size: 14px; cursor: pointer; }
.jp-day:hover { background: #e8eef4; }
.jp-day.jp-today { border: 1px solid var(--gold); color: var(--navy); font-weight: 700; }
.jp-day.jp-selected { background: var(--navy); color: #fff; font-weight: 700; }
.jp-day.jp-empty { cursor: default; }
.jp-foot { display: flex; justify-content: space-between; margin-top: 10px; }
.jp-today-btn, .jp-clear-btn { border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--navy); font-size: 13px; padding: 5px 12px; cursor: pointer; }
.jp-today-btn:hover, .jp-clear-btn:hover { background: #e8eef4; }

/* ---------- کارت‌های بخش‌های سامانه ---------- */
.module-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px; }
.module-card { border: 1px solid var(--border); border-radius: 12px; padding: 16px; background: var(--surface); }
.module-card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
.module-card-head b { color: var(--navy); font-size: 16px; }
.module-card p { margin: 6px 0; font-size: 14px; }

/* ---------- ویرایشگر متن گزارش بازدید ---------- */
.rte-toolbar { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.rte-toolbar button { border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--navy); font-size: 13px; padding: 5px 10px; cursor: pointer; }
.rte-toolbar button:hover { background: #e8eef4; }
.rte-editor { min-height: 180px; border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; background: #fff; outline: none; line-height: 1.9; }
.rte-editor:focus { border-color: var(--gold); box-shadow: 0 0 0 2px rgba(245,184,0,.25); }
.rte-editor h2 { font-size: 18px; margin: 10px 0 6px; }
.rte-editor h3 { font-size: 16px; margin: 10px 0 6px; }
.rte-view { line-height: 1.9; }
.rte-view h2 { font-size: 18px; margin: 10px 0 6px; }
.rte-view h3 { font-size: 16px; margin: 10px 0 6px; }
.fv-report-text { margin: 16px 0; }
.fv-report-text h3 { border-bottom: 2px solid var(--gold); padding-bottom: 6px; }
