/* Ai Noor — پنل مدیریت | استایل اختصاصی، بدون وابستگی خارجی */
/* فونت سیستمی تا در حالت اینترنت ملی هم درست کار کند */

:root {
  --bg: #f4f6fb;
  --card: #ffffff;
  --ink: #1e2433;
  --muted: #6b7280;
  --line: #e5e7f0;
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --primary-soft: #eef0fe;
  --green: #16a34a;
  --green-soft: #e8f7ee;
  --amber: #d97706;
  --amber-soft: #fef3e2;
  --red: #dc2626;
  --red-soft: #fdecec;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(20, 24, 60, .08), 0 4px 14px rgba(20, 24, 60, .06);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: Tahoma, "Segoe UI", "Vazirmatn", sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 14.5px;
  line-height: 1.9;
}

/* ---------- چیدمان کلی ---------- */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 248px; flex-shrink: 0;
  background: #171a2e; color: #dfe3f5;
  padding: 22px 14px;
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; gap: 6px;
  overflow: hidden;
}
/* منوی وسط سایدبار به‌تنهایی اسکرول می‌خورد تا آیتم‌های پایین
   (پیشنهادها، حسابداری) روی صفحه‌های کوتاه هم در دسترس باشند؛
   لوگو بالا و دکمه خروج پایین همیشه سر جایشان می‌مانند. */
.side-nav {
  flex: 1; min-height: 0; overflow-y: auto;
  display: flex; flex-direction: column; gap: 6px;
  padding-bottom: 6px;
  scrollbar-width: thin; scrollbar-color: #3a3f66 transparent;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 18px; }
.brand-mark {
  width: 40px; height: 40px; border-radius: 12px;
  background: linear-gradient(135deg, #6d64ff, #38bdf8);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; color: #fff; font-size: 18px;
}
.brand-name { font-weight: 700; font-size: 17px; color: #fff; }
.brand-logo { height: 40px; width: auto; border-radius: 10px; flex-shrink: 0; }
.topbar-mobile .brand-logo { height: 32px; }
.login-card .brand-logo { display: block; height: 56px; margin: 0 auto 12px; }
.brand-sub { font-size: 11.5px; color: #9aa0c3; }
.nav-link {
  display: flex; align-items: center; gap: 10px;
  color: #c6cbe8; text-decoration: none;
  padding: 10px 12px; border-radius: 10px; font-size: 14px;
}
.nav-link:hover { background: rgba(255,255,255,.07); color: #fff; }
.nav-link.active { background: var(--primary); color: #fff; }
.nav-link .ico { width: 22px; text-align: center; }
.side-foot { margin-top: auto; padding: 10px; font-size: 11.5px; color: #8b90b5; }
.side-foot button {
  background: none; border: 1px solid #3a3f66; color: #c6cbe8;
  border-radius: 8px; padding: 6px 10px; cursor: pointer; font-family: inherit; font-size: 12px;
}
.main { flex: 1; min-width: 0; padding: 26px 30px 60px; max-width: 1180px; }
.page-title { font-size: 22px; font-weight: 700; margin: 0 0 4px; }
.page-sub { color: var(--muted); margin: 0 0 22px; font-size: 13.5px; }

/* ---------- کارت ---------- */
.card {
  background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 20px 22px; margin-bottom: 18px;
  border: 1px solid var(--line);
}
.card h3 { margin: 0 0 12px; font-size: 16px; }
.grid { display: grid; gap: 18px; }
.grid.c2 { grid-template-columns: repeat(2, 1fr); }
.grid.c3 { grid-template-columns: repeat(3, 1fr); }
.grid.c4 { grid-template-columns: repeat(4, 1fr); }
.grid > * { min-width: 0; }
/* STATNUM-FIX (۲۲ نوامبر ۲۰۲۶): عدد بزرگ کارت‌ها در ستون باریک و موبایل سرریز نکند. */
.stat-num { font-size: clamp(20px, 3vw, 30px); font-weight: 700; margin: 2px 0; overflow-wrap: break-word; line-height: 1.35; }
.stat-label { color: var(--muted); font-size: 13px; }

/* ---------- دکمه ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: none; border-radius: 10px; cursor: pointer;
  font-family: inherit; font-size: 14px; font-weight: 600;
  padding: 10px 20px; text-decoration: none; color: #fff;
  background: var(--primary);
}
.btn:hover { background: var(--primary-dark); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.secondary { background: #eef0f7; color: var(--ink); }
.btn.secondary:hover { background: #e2e5f1; }
.btn.danger { background: var(--red); }
.btn.danger:hover { background: #b91c1c; }
.btn.success { background: #16a34a; }
.btn.success:hover { background: #15803d; }
.btn.warning { background: #d97706; }
.btn.warning:hover { background: #b45309; }
.btn.icon { padding: 5px 8px; border-radius: 8px; }
.btn svg { width: 17px; height: 17px; vertical-align: -3px; }
.btn.icon svg { width: 15px; height: 15px; }
.row-actions { display: flex; gap: 6px; align-items: center; flex-wrap: nowrap; }
.btn.ghost { background: transparent; color: var(--primary); padding: 8px 12px; }
.btn.small { padding: 7px 14px; font-size: 13px; }
.btn.block { width: 100%; }

/* ---------- فرم ---------- */
.field { margin-bottom: 16px; }
.field label { display: block; font-weight: 600; margin-bottom: 6px; font-size: 13.5px; }
.field .hint { font-size: 12px; color: var(--muted); margin-top: 4px; font-weight: 400; }
.input, .textarea, .select {
  width: 100%; border: 1.5px solid var(--line); border-radius: 10px;
  padding: 10px 14px; font-family: inherit; font-size: 14px; background: #fff; color: var(--ink);
}
.input:focus, .textarea:focus, .select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.textarea { min-height: 130px; resize: vertical; line-height: 2; }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.err { background: var(--red-soft); color: var(--red); border-radius: 10px; padding: 10px 14px; margin-bottom: 14px; font-size: 13.5px; }
.okmsg { background: var(--green-soft); color: var(--green); border-radius: 10px; padding: 10px 14px; margin-bottom: 14px; font-size: 13.5px; }
.warn { background: var(--amber-soft); color: var(--amber); border-radius: 10px; padding: 10px 14px; margin-bottom: 14px; font-size: 13.5px; }

/* ---------- جدول ---------- */
.table-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.tbl th, table.tbl td { padding: 10px 12px; border-bottom: 1px solid var(--line); text-align: right; }
table.tbl th { color: var(--muted); font-weight: 600; font-size: 12.5px; white-space: nowrap; }
table.tbl tr:last-child td { border-bottom: none; }
.pill {
  display: inline-block; padding: 3px 12px; border-radius: 20px; font-size: 12px; font-weight: 600;
}
.pill.green { background: var(--green-soft); color: var(--green); }
.pill.gray { background: #eef0f7; color: var(--muted); }
.pill.red { background: var(--red-soft); color: var(--red); }
.pill.amber { background: var(--amber-soft); color: var(--amber); }
.pill.blue { background: var(--primary-soft); color: var(--primary); }

/* ---------- نوار پیشرفت ---------- */
.progress { height: 10px; background: #e9ecf5; border-radius: 8px; overflow: hidden; }
.progress > div { height: 100%; border-radius: 8px; background: var(--green); transition: width .4s; }
.progress > div.warn { background: var(--amber); }
.progress > div.danger { background: var(--red); }

/* ---------- تب ---------- */
.tabs { display: flex; gap: 6px; border-bottom: 2px solid var(--line); margin-bottom: 20px; overflow-x: auto; }
.tab {
  padding: 10px 18px; cursor: pointer; border: none; background: none;
  font-family: inherit; font-size: 14px; font-weight: 600; color: var(--muted);
  border-bottom: 3px solid transparent; margin-bottom: -2px; white-space: nowrap;
}
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }

/* ---------- ویزارد ---------- */
.steps { display: flex; gap: 0; margin-bottom: 26px; }
.step { flex: 1; text-align: center; position: relative; padding-top: 30px; font-size: 13px; color: var(--muted); }
.step::before {
  content: attr(data-n); position: absolute; top: 0; right: 50%; transform: translateX(50%);
  width: 30px; height: 30px; border-radius: 50%; background: #e2e5f1; color: var(--muted);
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 14px;
}
.step.done::before { background: var(--green); color: #fff; }
.step.now { color: var(--ink); font-weight: 700; }
.step.now::before { background: var(--primary); color: #fff; }
.step::after { content: ""; position: absolute; top: 15px; right: calc(-50% + 18px); left: calc(50% + 18px); height: 2px; background: var(--line); }
.step:first-child::after { display: none; }
.step.done::after { background: var(--green); }

/* ---------- چت (پلی‌گراند) ---------- */
.chat-box { display: flex; flex-direction: column; height: 480px; border: 1.5px solid var(--line); border-radius: var(--radius); overflow: hidden; background: #fff; }
.chat-log { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 10px; background: #fafbfe; }
.msg { max-width: 82%; padding: 10px 14px; border-radius: 14px; font-size: 14px; line-height: 1.9; white-space: pre-wrap; }
.msg.user { align-self: flex-start; background: var(--primary); color: #fff; border-bottom-right-radius: 4px; }
.msg.bot { align-self: flex-end; background: #fff; border: 1px solid var(--line); border-bottom-left-radius: 4px; box-shadow: var(--shadow); }
.msg .meta { font-size: 11px; opacity: .75; margin-top: 6px; }
.chat-input { display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--line); background: #fff; }
.chat-input .input { flex: 1; }
.typing { color: var(--muted); font-size: 13px; padding: 4px 8px; }

/* ---------- مودال ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(15, 18, 40, .5); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px; }
.modal { background: #fff; border-radius: 16px; padding: 26px; width: 100%; max-width: 480px; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.modal h3 { margin: 0 0 6px; }
.modal .sub { color: var(--muted); font-size: 13px; margin-bottom: 16px; }

/* ---------- صفحه ورود ---------- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; background: linear-gradient(135deg, #171a2e, #2b2f6b); }
.login-card { background: #fff; border-radius: 20px; padding: 38px 34px; width: 100%; max-width: 430px; box-shadow: 0 24px 70px rgba(0,0,0,.35); text-align: center; }
.login-card .brand-mark { margin: 0 auto 12px; width: 54px; height: 54px; font-size: 24px; }

/* ---------- قالب‌ها ---------- */
.tpl-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.tpl-card { border: 1.5px solid var(--line); border-radius: 12px; padding: 16px; cursor: pointer; transition: .15s; background: #fff; }
.tpl-card:hover { border-color: var(--primary); box-shadow: var(--shadow); }
.tpl-card h4 { margin: 0 0 6px; font-size: 14.5px; }
.tpl-card p { margin: 0; font-size: 12.5px; color: var(--muted); }

/* ---------- نمودار میله‌ای ساده ---------- */
.bars { display: flex; align-items: flex-end; gap: 6px; height: 150px; padding: 10px 4px 0; direction: ltr; }
.bar { flex: 1; background: linear-gradient(180deg, #6d64ff, #4f46e5); border-radius: 6px 6px 0 0; min-height: 4px; position: relative; }
.bar span { position: absolute; bottom: -22px; right: 50%; transform: translateX(50%); font-size: 10px; color: var(--muted); white-space: nowrap; }

/* ---------- متفرقه ---------- */
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.mt { margin-top: 14px; }
.center { text-align: center; }
.empty { text-align: center; color: var(--muted); padding: 40px 10px; }
.pager { display: flex; gap: 8px; align-items: center; justify-content: center; margin-top: 16px; }
.kv { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px dashed var(--line); font-size: 13.5px; }
.kv:last-child { border-bottom: none; }
code.key { background: #f1f2f9; border: 1px solid var(--line); border-radius: 8px; padding: 6px 12px; font-family: monospace; direction: ltr; display: inline-block; }
.copy-btn { cursor: pointer; border: 1px solid var(--line); background: #fff; border-radius: 8px; padding: 6px 12px; font-family: inherit; font-size: 12.5px; }
.highlight-ring { animation: ring 1.6s ease-in-out 2; border-radius: 12px; }
@keyframes ring { 0%,100% { box-shadow: 0 0 0 0 rgba(79,70,229,0);} 50% { box-shadow: 0 0 0 5px rgba(79,70,229,.35);} }

@media (max-width: 900px) {
  .sidebar { display: none; }
  .main { padding: 16px; }
  .grid.c2, .grid.c3, .grid.c4 { grid-template-columns: 1fr; }
  .tpl-grid { grid-template-columns: 1fr; }
  .topbar-mobile { display: flex !important; }
  .mobile-identity { display: flex !important; }
}
.topbar-mobile { display: none; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.topbar-mobile select { font-family: inherit; padding: 8px 12px; border-radius: 10px; border: 1.5px solid var(--line); }

/* ---------- نشانهٔ هویت نشست (سازمان + کاربر) ---------- */
.whoami { margin: 10px 4px 4px; padding: 10px 12px; border-radius: 10px; background: rgba(255,255,255,0.08); color: #fff; font-size: 12.5px; line-height: 1.9; word-break: break-word; }
.whoami-org { font-weight: bold; }
.whoami-user { opacity: 0.85; }
/* ردیف هویت در موبایل (سایدبار پنهان است) + دکمهٔ خروج */
.mobile-identity { display: none; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; padding: 10px 12px; border: 1.5px solid var(--line); border-radius: 10px; background: #fff; font-size: 13px; }
.mobile-identity .whoami-sep { color: var(--muted); }
.mobile-identity #logoutBtnM { margin-inline-start: auto; }
