@font-face { font-family: Vazirmatn; src: url("../assets/fonts/Vazirmatn-Regular.woff2") format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: Vazirmatn; src: url("../assets/fonts/Vazirmatn-Medium.woff2") format("woff2"); font-weight: 500; font-display: swap; }
@font-face { font-family: Vazirmatn; src: url("../assets/fonts/Vazirmatn-Bold.woff2") format("woff2"); font-weight: 700; font-display: swap; }
@font-face { font-family: Vazirmatn; src: url("../assets/fonts/Vazirmatn-ExtraBold.woff2") format("woff2"); font-weight: 800; font-display: swap; }

:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --line: #e5e7eb;
  --text: #0f172a;
  --muted: #64748b;
  --faint: #94a3b8;
  --primary: #4f46e5;
  --primary-soft: #eef2ff;
  --teal: #0d9488;
  --teal-soft: #e6f7f5;
  --amber: #d97706;
  --amber-soft: #fef6e7;
  --rose: #e11d48;
  --rose-soft: #fdecef;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 4px 16px rgba(15, 23, 42, .05);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: Vazirmatn, Tahoma, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--primary); text-decoration: none; }
h1, h2, h3 { margin: 0; line-height: 1.4; }
h1 { font-size: 22px; font-weight: 800; }
h2 { font-size: 17px; font-weight: 700; }
h3 { font-size: 15px; font-weight: 700; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.num { font-variant-numeric: tabular-nums; }

/* ---------- چیدمان ---------- */
.shell { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--surface); border-inline-start: 1px solid var(--line);
  padding: 20px 14px; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 4px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 18px; }
.brand-mark { width: 38px; height: 38px; border-radius: 12px; background: var(--primary); color: #fff; display: grid; place-items: center; font-weight: 800; }
.brand b { display: block; font-size: 14px; }
.brand span { font-size: 12px; color: var(--muted); }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 10px; color: var(--muted); font-weight: 500;
}
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a.active { background: var(--primary-soft); color: var(--primary); font-weight: 700; }
.nav .badge { margin-inline-start: auto; }
.sidebar .me { margin-top: auto; padding: 12px; border-radius: 12px; background: var(--surface-2); font-size: 13px; }
.main { padding: 28px 32px 48px; max-width: 1200px; width: 100%; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head p { margin: 2px 0 0; color: var(--muted); font-size: 14px; }

.demo-bar {
  background: var(--amber-soft); color: #92400e; font-size: 13px; padding: 6px 16px; text-align: center;
  border-bottom: 1px solid #fde7c2;
}
.demo-bar button { background: none; border: 0; color: #92400e; text-decoration: underline; cursor: pointer; padding: 0 4px; }

/* ---------- اجزا ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }
.card + .card { margin-top: 16px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.stack { display: flex; flex-direction: column; gap: 16px; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.spacer { flex: 1; }

.stat { padding: 18px 20px; }
.stat .label { color: var(--muted); font-size: 13px; }
.stat .value { font-size: 28px; font-weight: 800; margin-top: 4px; }
.stat .value small { font-size: 14px; font-weight: 500; color: var(--muted); margin-inline-start: 4px; }
.stat .bar { height: 6px; border-radius: 6px; background: var(--surface-2); margin-top: 10px; overflow: hidden; }
.stat .bar span { display: block; height: 100%; background: var(--primary); border-radius: 6px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line);
  background: var(--surface); padding: 8px 14px; border-radius: 10px; cursor: pointer; font-weight: 500; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: #4338ca; }
.btn.danger { color: var(--rose); border-color: #fbcfd8; }
.btn.danger:hover { background: var(--rose-soft); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.sm { padding: 5px 10px; font-size: 13px; border-radius: 8px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 13px; font-weight: 700; color: #334155; }
.field .hint { font-size: 12px; color: var(--muted); }
.input, select.input, textarea.input {
  width: 100%; border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 9px 12px; outline: none;
}
.input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79, 70, 229, .12); }
textarea.input { min-height: 180px; resize: vertical; font-size: 14px; line-height: 1.9; }
.input.ltr { direction: ltr; text-align: left; }

.badge { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 700; padding: 2px 9px; border-radius: 999px; white-space: nowrap; }
.badge.green { background: var(--teal-soft); color: var(--teal); }
.badge.red { background: var(--rose-soft); color: var(--rose); }
.badge.amber { background: var(--amber-soft); color: var(--amber); }
.badge.gray { background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); }
.badge.indigo { background: var(--primary-soft); color: var(--primary); }

.alert { padding: 12px 14px; border-radius: 12px; font-size: 14px; }
.alert.info { background: var(--primary-soft); color: #3730a3; }
.alert.warn { background: var(--amber-soft); color: #92400e; }
.alert.error { background: var(--rose-soft); color: #9f1239; }
.alert.ok { background: var(--teal-soft); color: #115e59; }

/* ---------- جدول ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 10px 12px; text-align: right; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { background: var(--surface-2); color: var(--muted); font-weight: 700; font-size: 13px; position: sticky; top: 0; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fafbff; }
tr.selected { background: var(--primary-soft) !important; }
td.wrap { white-space: normal; }
.check { width: 18px; height: 18px; accent-color: var(--primary); cursor: pointer; vertical-align: middle; }
.link-row { cursor: pointer; }
tr.err td { background: var(--rose-soft); }
tr.warn td { background: #fffbeb; }

.bulk-bar {
  position: fixed; bottom: 16px; left: 32px; right: 272px; z-index: 35; background: var(--text); color: #fff; border-radius: 14px;
  padding: 10px 14px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; box-shadow: 0 10px 30px rgba(15, 23, 42, .25);
}
#bulk:not(:empty) { height: 100px; } /* جای خالی زیر جدول تا آخرین ردیف‌ها زیر نوار نروند */
.bulk-bar .btn { background: rgba(255, 255, 255, .08); border-color: rgba(255, 255, 255, .15); color: #fff; }
.bulk-bar .btn:hover { background: rgba(255, 255, 255, .16); }
.bulk-bar select.input { width: auto; background: rgba(255, 255, 255, .08); border-color: rgba(255, 255, 255, .15); color: #fff; padding: 6px 10px; }
.bulk-bar select.input option { color: var(--text); }

/* ---------- مراحل افزودن گروهی ---------- */
.steps { display: flex; gap: 8px; margin-bottom: 18px; flex-wrap: wrap; }
.steps span { padding: 6px 14px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line); color: var(--muted); font-size: 13px; font-weight: 500; }
.steps span.on { background: var(--primary); border-color: var(--primary); color: #fff; }
.steps span.done { background: var(--primary-soft); color: var(--primary); border-color: transparent; }
.dropzone {
  border: 2px dashed #c7d2fe; border-radius: 14px; padding: 18px; text-align: center; color: var(--muted); background: #fafaff; cursor: pointer;
}
.dropzone.over { background: var(--primary-soft); border-color: var(--primary); }

/* ---------- نمودار هفتگی ---------- */
.week-chart { display: grid; grid-template-columns: repeat(7, 1fr); gap: 8px; align-items: end; height: 200px; padding-top: 24px; }
.week-col { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; position: relative; }
.week-col .bar-area { position: relative; width: 100%; max-width: 46px; flex: 1; display: flex; align-items: flex-end; justify-content: center; }
.week-col .bar { width: 100%; border-radius: 10px 10px 4px 4px; background: var(--primary); position: relative; min-height: 6px; }
.week-col .bar.met { background: var(--teal); }
.week-col .bar.no-report { background: var(--line); height: 6px; }
.week-col .target { position: absolute; left: -6px; right: -6px; height: 3px; background: var(--amber); border-radius: 3px; }
.week-col .val { position: absolute; left: -8px; right: -8px; text-align: center; font-size: 12px; font-weight: 700; line-height: 1.4; }
.week-col .day { font-size: 12px; color: var(--muted); margin-top: 6px; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); flex-wrap: wrap; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-inline-end: 4px; vertical-align: middle; }

.week-top { display: grid; grid-template-columns: auto 1fr; gap: 20px; align-items: center; }
.tiles { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.tiles .stat { padding: 14px 16px; }
.tiles .stat .value { font-size: 22px; }
.grid.split { grid-template-columns: 1.4fr 1fr; }
.ring { --p: 0; width: 140px; height: 140px; border-radius: 50%; display: grid; place-items: center;
  background: conic-gradient(var(--ring-color, var(--primary)) calc(var(--p) * 1%), var(--surface-2) 0); }
.ring > div { width: 112px; height: 112px; border-radius: 50%; background: var(--surface); display: grid; place-items: center; text-align: center; }
.ring b { font-size: 26px; font-weight: 800; display: block; line-height: 1.2; }
.ring span { font-size: 11px; color: var(--muted); }

/* ---------- لیست‌ها ---------- */
.list { display: flex; flex-direction: column; }
.list-item { padding: 12px 0; border-bottom: 1px solid var(--line); display: flex; gap: 12px; align-items: flex-start; }
.list-item:last-child { border-bottom: 0; }
.list-item .grow { flex: 1; min-width: 0; }
.msg-text { white-space: pre-wrap; margin-top: 4px; }
.task { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
.task.done .title { text-decoration: line-through; color: var(--faint); }
.task .title { flex: 1; }
.day-row { display: grid; grid-template-columns: 150px 1fr; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.day-row:last-child { border-bottom: 0; }
.kv { display: flex; gap: 6px 14px; flex-wrap: wrap; font-size: 14px; }
.kv span b { font-weight: 700; }
.empty { text-align: center; color: var(--muted); padding: 28px 10px; }

/* ---------- ورود ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px;
  background: radial-gradient(circle at 15% 10%, #e0e7ff 0, transparent 40%), radial-gradient(circle at 90% 90%, #ccfbf1 0, transparent 40%), var(--bg); }
.login-card { width: 100%; max-width: 420px; }
.login-card .brand { justify-content: center; padding-bottom: 8px; }
.demo-accounts { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; margin-top: 8px; }
.demo-accounts button { text-align: right; border: 1px solid var(--line); background: var(--surface-2); border-radius: 10px; padding: 6px 10px; cursor: pointer; font-size: 13px; }
.demo-accounts button:hover { border-color: var(--primary); }
.demo-accounts small { display: block; color: var(--muted); font-size: 11px; direction: ltr; text-align: right; }

/* ---------- پیام کوتاه ---------- */
#toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px); background: var(--text); color: #fff;
  padding: 10px 18px; border-radius: 12px; font-size: 14px; opacity: 0; pointer-events: none; transition: .25s; z-index: 50; max-width: 90vw; }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.error { background: var(--rose); }

/* ---------- پنجره ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(15, 23, 42, .4); display: grid; place-items: center; padding: 16px; z-index: 40; }
.modal { background: var(--surface); border-radius: 18px; padding: 22px; width: 100%; max-width: 480px; box-shadow: 0 20px 60px rgba(15, 23, 42, .3); }
.modal h2 { margin-bottom: 12px; }
.modal .actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; }

/* ---------- گزارش ماهانه (صفحه و چاپ A4) ---------- */
.month-sheet { max-width: 920px; margin: 0 auto; display: flex; flex-direction: column; gap: 18px; padding: 28px 32px; }
.m-head { border-bottom: 1px solid var(--line); padding-bottom: 14px; display: flex; flex-direction: column; gap: 4px; }
.m-head h1 { font-size: 26px; }
.m-tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.m-tiles div { border: 1px solid var(--line); border-radius: 14px; padding: 12px; text-align: center; background: var(--surface-2); }
.m-tiles span { display: block; font-size: 13px; color: var(--muted); }
.m-tiles b { font-size: 24px; font-weight: 800; color: var(--primary); }
.m-table th { text-align: center; line-height: 1.4; }
.m-table th small { font-weight: 500; font-size: 11px; }
.m-table td { text-align: center; }
.m-table td:first-child { text-align: right; }
.m-table td.bad { color: var(--rose); font-weight: 700; }
.m-table tr.total td { background: var(--surface-2); font-weight: 700; font-size: 15px; }
.m-charts { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.m-chart h3 { margin-bottom: 6px; }
.m-bars { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; height: 210px; padding-top: 24px; border-bottom: 1px solid var(--line); }
.m-col { display: flex; flex-direction: column; height: 100%; align-items: center; }
.m-area { position: relative; flex: 1; width: 100%; max-width: 64px; display: flex; align-items: flex-end; }
.m-bar { width: 100%; border-radius: 10px 10px 3px 3px; }
.m-target { position: absolute; left: -6px; right: -6px; height: 3px; background: var(--amber); border-radius: 3px; }
.m-val { position: absolute; left: -10px; right: -10px; text-align: center; font-size: 13px; font-weight: 700; }
.m-lbl { font-size: 12px; color: var(--muted); margin: 6px 0 -26px; }
.m-sign { display: grid; grid-template-columns: 1fr 1fr; gap: 60px; margin-top: 46px; color: var(--muted); }
.m-sign div { border-bottom: 1px solid var(--line); padding-bottom: 50px; }
@media (max-width: 600px) {
  .month-sheet { padding: 16px; }
  .m-tiles { grid-template-columns: repeat(2, 1fr); }
  .m-charts { grid-template-columns: 1fr; }
}

/* ---------- کارت چاپی اطلاعات ورود ---------- */
.print-only { display: none; }
@media print {
  @page { size: A4; margin: 12mm; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .month-sheet { box-shadow: none; border: 0; padding: 0; max-width: none; gap: 14px; }
  .month-sheet .table-wrap { overflow: visible; border: 1px solid var(--line); }
  .month-sheet th { position: static; }
  .m-tiles, .m-charts { grid-template-columns: repeat(4, 1fr); }
  .m-charts { grid-template-columns: 1fr 1fr; }
  /* همه گزارش ماهانه در یک برگه A4 جا شود */
  .m-head h1 { font-size: 22px; }
  .m-tiles b { font-size: 20px; }
  .month-sheet th, .month-sheet td { padding: 6px 10px; }
  .month-sheet { gap: 10px; }
  .m-bars { height: 130px; }
  .m-sign { margin-top: 22px; }
  .m-sign div { padding-bottom: 30px; }
  .shell { min-height: 0; }
  body { background: #fff; }
  .no-print, .sidebar, .demo-bar, .bottom-nav { display: none !important; }
  .print-only { display: block; }
  .shell { display: block; }
  .main { padding: 0; }
  .cred-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .cred-card { border: 1px dashed #94a3b8; border-radius: 10px; padding: 10px 12px; break-inside: avoid; font-size: 13px; }
  .cred-card b { font-size: 15px; }
  .cred-card .ltr { direction: ltr; display: inline-block; font-weight: 700; }
}

/* ---------- موبایل ---------- */
.bottom-nav { display: none; }
@media (max-width: 900px) {
  .grid.cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid.cols-3, .grid.cols-2, .grid.split { grid-template-columns: 1fr; }
}
@media (max-width: 600px) {
  .week-top { grid-template-columns: 1fr; justify-items: center; }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); width: 100%; }
}
@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .main { padding: 16px 16px 96px; }
  .bottom-nav {
    display: flex; position: fixed; bottom: 0; left: 0; right: 0; background: var(--surface); border-top: 1px solid var(--line);
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); z-index: 30; justify-content: space-around;
  }
  .bottom-nav a { display: flex; flex-direction: column; align-items: center; font-size: 11px; color: var(--muted); padding: 4px 6px; border-radius: 10px; flex: 1; position: relative; }
  .bottom-nav a .ic { font-size: 18px; line-height: 1.3; }
  .bottom-nav a.active { color: var(--primary); font-weight: 700; }
  .bottom-nav .badge { position: absolute; top: 0; right: 18%; padding: 0 5px; }
  .day-row { grid-template-columns: 1fr; gap: 4px; }
  .bulk-bar { bottom: 84px; left: 12px; right: 12px; }
  h1 { font-size: 19px; }
  .stat .value { font-size: 24px; }
}

@media screen and (max-width: 900px) {
  .main, .grid > *, .card, .month-sheet, .table-wrap { min-width: 0; }
  .sidebar { overflow-y: auto; }
}
@media screen and (max-width: 760px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .main { padding: 14px max(12px, env(safe-area-inset-right)) calc(112px + env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left)); }
  .card { padding: 14px; }
  .bottom-nav a { min-width: 0; text-align: center; padding-inline: 2px; line-height: 1.4; justify-content: flex-start; }
  .btn, .input { min-height: 44px; max-width: 100%; }
  .btn { white-space: normal; }
  .input, textarea.input { font-size: 16px; }
  .modal { min-width: 0; max-height: calc(100dvh - 32px); overflow-y: auto; padding: 16px; }
  .modal-back { grid-template-columns: minmax(0, 1fr); }
  .bulk-bar { position: static; margin-top: 12px; }
  #bulk:not(:empty) { height: auto; }
  .msg-text, .modal-body, .task .title, .page-head { overflow-wrap: anywhere; }
  .table-wrap { max-width: 100%; overflow-x: auto; }
}

.modal { max-height: calc(100vh - 32px); max-height: calc(100dvh - 32px); overflow-y: auto; }
.exam-row { min-width: 0; border: 1px solid var(--line); border-radius: 12px; padding: 12px; }

.login-identity { display: grid; justify-items: center; gap: 5px; }
.login-identity img { object-fit: contain; }
.channel-header { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 16px; margin-bottom: 16px; padding: 10px 14px; background: #eff8f8; border-radius: 12px; color: #165960; }
.channel-header nav { display: flex; flex-wrap: wrap; gap: 16px; }
.channel-header a { color: #08606b; text-decoration: underline; text-underline-offset: 3px; }
.login-card .channel-header { margin-top: 12px; justify-content: center; font-size: 13px; }
