/* Telegram Fake Detector — پنل مدیریت (فارسی، راست‌به‌چپ).
   بدون فریم‌ورک و بدون مرحلهٔ build: یک شیوه‌نامه و متغیرهای CSS.
   طراحی تیره‌محور، چون اپراتور معمولاً حین یک حادثه به آن نگاه می‌کند.

   نکتهٔ چیدمان: همه‌جا از خصوصیات منطقی (inline-start/inline-end) استفاده شده،
   نه left/right ثابت. یعنی چیدمان از خود جهت صفحه پیروی می‌کند و برای برگرداندن
   به چپ‌به‌راست فقط کافی است dir سند عوض شود. */

/* فونت وزیرمتن همراه پروژه عرضه می‌شود: سیاست امنیتی محتوا (CSP) اجازهٔ بارگذاری
   از CDN را نمی‌دهد، و نمی‌توان به نصب‌بودن فونت فارسی روی دستگاه کاربر تکیه کرد. */
@font-face {
  font-family: "Vazirmatn";
  src: url("/static/fonts/Vazirmatn-Regular.woff2") format("woff2");
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: "Vazirmatn";
  src: url("/static/fonts/Vazirmatn-Medium.woff2") format("woff2");
  font-weight: 500 600;
  font-display: swap;
}
@font-face {
  font-family: "Vazirmatn";
  src: url("/static/fonts/Vazirmatn-Bold.woff2") format("woff2");
  font-weight: 700;
  font-display: swap;
}

:root {
  --bg: #0f1419;
  --bg-elevated: #161c23;
  --bg-hover: #1d252e;
  --border: #252e39;
  --border-strong: #35414f;
  --text: #e6edf3;
  --text-muted: #8b98a5;
  --text-dim: #5d6b7a;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --ok: #22c55e;
  --warn: #f59e0b;
  --danger: #ef4444;
  --critical: #dc2626;
  --purple: #a855f7;
  --radius: 8px;
  --radius-sm: 5px;
  --shadow: 0 4px 16px rgba(0, 0, 0, .35);
  --sidebar-w: 232px;
  /* ۱+ در راست‌به‌چپ، ۱- در چپ‌به‌راست: ضریب جهت برای translateX. */
  --rtl: 1;
  --mono: ui-monospace, "SF Mono", "Cascadia Code", Menlo, Consolas, monospace;
  --sans: "Vazirmatn", -apple-system, BlinkMacSystemFont, "Segoe UI", Tahoma, sans-serif;
}

* { box-sizing: border-box; }

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

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, .mono { font-family: var(--mono); font-size: .85em; }

/* ---------------------------------------------------------------- layout -- */

#app { min-height: 100vh; }

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

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--bg-elevated);
  border-inline-end: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; bottom: 0; inset-inline-start: 0;
  z-index: 40;
  transition: transform .2s ease;
}

.sidebar-brand {
  padding: 18px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
}
.sidebar-brand .logo {
  width: 30px; height: 30px;
  border-radius: 7px;
  background: linear-gradient(135deg, var(--accent), var(--purple));
  display: grid; place-items: center;
  font-size: 15px;
  flex-shrink: 0;
}
.sidebar-brand h1 { font-size: 13px; margin: 0; font-weight: 650; letter-spacing: .2px; }
.sidebar-brand .env { font-size: 10px; color: var(--text-dim); text-transform: uppercase; letter-spacing: .6px; }

.nav { flex: 1; overflow-y: auto; padding: 10px 8px; }
.nav-section { font-size: 10px; text-transform: uppercase; letter-spacing: .7px; color: var(--text-dim); padding: 12px 8px 5px; font-weight: 600; }
.nav-item {
  display: flex; align-items: center; gap: 9px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: pointer;
  font-size: 13px;
  border: none; background: none; width: 100%; text-align: start;
  font-family: inherit;
}
.nav-item:hover { background: var(--bg-hover); color: var(--text); text-decoration: none; }
.nav-item.active { background: var(--accent); color: #fff; font-weight: 550; }
.nav-item .icon { width: 16px; text-align: center; flex-shrink: 0; }
.nav-item .badge {
  margin-inline-start: auto;
  background: var(--danger); color: #fff;
  border-radius: 10px; padding: 1px 6px; font-size: 10px; font-weight: 700;
}
.nav-item.active .badge { background: rgba(255,255,255,.28); }

.sidebar-footer { padding: 10px 12px; border-top: 1px solid var(--border); font-size: 11px; color: var(--text-dim); }

.main { flex: 1; margin-inline-start: var(--sidebar-w); min-width: 0; display: flex; flex-direction: column; }

.topbar {
  height: 54px;
  border-bottom: 1px solid var(--border);
  background: rgba(15,20,25,.9);
  backdrop-filter: blur(8px);
  display: flex; align-items: center; gap: 12px;
  padding: 0 18px;
  position: sticky; top: 0; z-index: 30;
}
.topbar h2 { font-size: 15px; margin: 0; font-weight: 600; }
.topbar .spacer { flex: 1; }

.menu-toggle { display: none; background: none; border: 1px solid var(--border-strong); color: var(--text); border-radius: var(--radius-sm); padding: 6px 9px; cursor: pointer; font-size: 15px; }

.content { padding: 18px; flex: 1; max-width: 1500px; width: 100%; }

/* --------------------------------------------------------------- widgets -- */

.card { background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.card h3 { margin: 0 0 12px; font-size: 13px; font-weight: 620; letter-spacing: .2px; }
.card-header { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.card-header h3 { margin: 0; }
.card-header .spacer { flex: 1; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat {
  background: var(--bg-elevated); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px;
}
.stat .label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .5px; margin-bottom: 6px; }
.stat .value { font-size: 26px; font-weight: 680; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat .sub { font-size: 11px; color: var(--text-dim); margin-top: 4px; }
.stat.danger .value { color: var(--danger); }
.stat.warn .value { color: var(--warn); }
.stat.ok .value { color: var(--ok); }

.badge-pill { display: inline-block; padding: 2px 8px; border-radius: 11px; font-size: 11px; font-weight: 600; white-space: nowrap; }
.b-normal { background: rgba(34,197,94,.14); color: var(--ok); }
.b-suspicious { background: rgba(245,158,11,.15); color: var(--warn); }
.b-needs_review, .b-high_risk { background: rgba(239,68,68,.14); color: var(--danger); }
.b-auto_ban, .b-critical { background: rgba(220,38,38,.2); color: #fca5a5; }
.b-banned { background: rgba(220,38,38,.2); color: #fca5a5; }
.b-active { background: rgba(34,197,94,.14); color: var(--ok); }
.b-false_positive { background: rgba(168,85,247,.16); color: var(--purple); }
.b-quarantined, .b-warning { background: rgba(245,158,11,.15); color: var(--warn); }
.b-left, .b-resolved, .b-cooldown { background: rgba(139,152,165,.14); color: var(--text-muted); }
.b-unknown { background: rgba(93,107,122,.18); color: var(--text-dim); font-style: italic; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th {
  text-align: start; padding: 9px 10px;
  font-size: 11px; text-transform: uppercase; letter-spacing: .5px;
  color: var(--text-muted); font-weight: 600;
  border-bottom: 1px solid var(--border); white-space: nowrap;
}
td { padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:hover { background: var(--bg-hover); }
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.num { font-variant-numeric: tabular-nums; text-align: end; }

button, .btn {
  background: var(--accent); color: #fff; border: none;
  border-radius: var(--radius-sm); padding: 7px 13px;
  font-size: 13px; font-weight: 550; cursor: pointer; font-family: inherit;
  display: inline-flex; align-items: center; gap: 6px;
}
button:hover, .btn:hover { background: var(--accent-hover); text-decoration: none; }
button:disabled { opacity: .45; cursor: not-allowed; }
.btn-sm { padding: 4px 9px; font-size: 12px; }
.btn-ghost { background: transparent; border: 1px solid var(--border-strong); color: var(--text-muted); }
.btn-ghost:hover { background: var(--bg-hover); color: var(--text); }
.btn-danger { background: var(--danger); }
.btn-danger:hover { background: var(--critical); }
.btn-ok { background: var(--ok); }

input, select, textarea {
  background: var(--bg); border: 1px solid var(--border-strong); color: var(--text);
  border-radius: var(--radius-sm); padding: 7px 10px; font-size: 13px;
  font-family: inherit; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
label { display: block; font-size: 11px; color: var(--text-muted); margin-bottom: 4px; text-transform: uppercase; letter-spacing: .4px; }

.filters { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; margin-bottom: 14px; align-items: end; }

.notice {
  border-radius: var(--radius); padding: 11px 13px; font-size: 12.5px;
  border-inline-start: 3px solid; margin-bottom: 14px; line-height: 1.55;
}
.notice-info { background: rgba(59,130,246,.08); border-color: var(--accent); }
.notice-warn { background: rgba(245,158,11,.08); border-color: var(--warn); }
.notice-danger { background: rgba(239,68,68,.08); border-color: var(--danger); }
.notice strong { display: block; margin-bottom: 3px; }

.empty { text-align: center; padding: 36px 16px; color: var(--text-dim); font-size: 13px; }

.reasons { display: flex; flex-direction: column; gap: 6px; }
.reason {
  display: flex; gap: 9px; align-items: flex-start;
  padding: 8px 10px; background: var(--bg); border-radius: var(--radius-sm);
  border-inline-start: 2px solid var(--border-strong);
}
.reason.strong { border-inline-start-color: var(--danger); }
.reason.weak { border-inline-start-color: var(--warn); }
.reason.mitigating { border-inline-start-color: var(--ok); }
.reason.override { border-inline-start-color: var(--purple); }
.reason .w { font-family: var(--mono); font-weight: 700; min-width: 34px; font-size: 12px; }
.reason .body { flex: 1; min-width: 0; }
.reason .lbl { font-size: 12.5px; font-weight: 550; }
.reason .dtl { font-size: 11.5px; color: var(--text-muted); margin-top: 2px; }

/* charts are hand-drawn SVG: no chart library, no CDN, CSP-clean */
.chart { width: 100%; height: 180px; display: block; }
.chart-legend { display: flex; gap: 14px; font-size: 11px; color: var(--text-muted); margin-top: 8px; flex-wrap: wrap; }
.chart-legend span { display: flex; align-items: center; gap: 5px; }
.chart-legend i { width: 10px; height: 3px; border-radius: 2px; display: inline-block; }

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.65);
  display: grid; place-items: center; z-index: 100; padding: 16px;
}
.modal {
  background: var(--bg-elevated); border: 1px solid var(--border-strong);
  border-radius: var(--radius); box-shadow: var(--shadow);
  max-width: 560px; width: 100%; max-height: 86vh; overflow-y: auto; padding: 18px;
}
.modal h3 { margin: 0 0 12px; font-size: 15px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; flex-wrap: wrap; }

.toast-host { position: fixed; bottom: 18px; inset-inline-start: 18px; z-index: 200; display: flex; flex-direction: column; gap: 8px; max-width: 380px; }
.toast {
  background: var(--bg-elevated); border: 1px solid var(--border-strong);
  border-inline-start: 3px solid var(--accent);
  border-radius: var(--radius-sm); padding: 11px 13px; font-size: 13px; box-shadow: var(--shadow);
}
.toast.ok { border-inline-start-color: var(--ok); }
.toast.err { border-inline-start-color: var(--danger); }

/* ---------------------------------------------------------------- login -- */

.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-card { background: var(--bg-elevated); border: 1px solid var(--border); border-radius: 12px; padding: 30px; width: 100%; max-width: 380px; box-shadow: var(--shadow); }
.login-card .logo-big { width: 46px; height: 46px; border-radius: 11px; background: linear-gradient(135deg, var(--accent), var(--purple)); display: grid; place-items: center; font-size: 23px; margin-bottom: 16px; }
.login-card h1 { font-size: 19px; margin: 0 0 5px; }
.login-card p.sub { color: var(--text-muted); font-size: 12.5px; margin: 0 0 20px; }
.field { margin-bottom: 13px; }
.error-box { background: rgba(239,68,68,.1); border-inline-start: 3px solid var(--danger); padding: 9px 11px; border-radius: var(--radius-sm); font-size: 12.5px; margin-bottom: 13px; }

.spinner { width: 15px; height: 15px; border: 2px solid rgba(255,255,255,.3); border-top-color: #fff; border-radius: 50%; animation: spin .6s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.matrix-cell { text-align: center; font-size: 11px; font-weight: 600; }
.m-supported { color: var(--ok); }
.m-unsupported { color: var(--danger); }
.m-partial { color: var(--warn); }
.m-manual_action_required { color: var(--purple); }

.kv { display: grid; grid-template-columns: minmax(130px, auto) 1fr; gap: 6px 14px; font-size: 13px; }
.kv dt { color: var(--text-muted); }
.kv dd { margin: 0; }

.checkbox-row { display: flex; align-items: center; gap: 8px; }
.checkbox-row input { width: auto; }
.checkbox-row label { margin: 0; text-transform: none; font-size: 13px; color: var(--text); letter-spacing: 0; }

/* -------------------------------------------------------------- responsive */

@media (max-width: 900px) {
  /* در راست‌به‌چپ، translateX مثبت یعنی «به بیرون از لبهٔ راست»،
     پس مقدار از خود جهت سند گرفته می‌شود. */
  .sidebar { transform: translateX(calc(100% * var(--rtl, -1))); box-shadow: var(--shadow); }
  .sidebar.open { transform: translateX(0); }
  .main { margin-inline-start: 0; }
  .menu-toggle { display: block; }
  .content { padding: 13px; }
  .stat-grid { grid-template-columns: repeat(auto-fit, minmax(135px, 1fr)); gap: 9px; }
  .stat { padding: 11px; }
  .stat .value { font-size: 21px; }
  .topbar { padding: 0 13px; }
  .topbar h2 { font-size: 14px; }
  .sidebar-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 35; }
  .filters { grid-template-columns: 1fr 1fr; }
  table { font-size: 12px; }
  th, td { padding: 7px 8px; }
  .hide-mobile { display: none; }
  .toast-host { inset-inline: 13px; bottom: 13px; max-width: none; }
}

@media (max-width: 520px) {
  .filters { grid-template-columns: 1fr; }
  .stat-grid { grid-template-columns: 1fr 1fr; }
  .modal { padding: 14px; }
}

/* اگر سند به چپ‌به‌راست برگردانده شود، ضریب جهت هم برمی‌گردد. */
:root:dir(ltr) { --rtl: -1; }

/* متن‌های دوجهته: شناسهٔ عددی، نام متد API و نام کاربری باید چپ‌به‌راست بمانند،
   وگرنه داخل جملهٔ فارسی جابه‌جا و ناخوانا می‌شوند. */
.ltr,
code,
.mono,
input[type="number"],
input[type="date"] {
  direction: ltr;
  unicode-bidi: isolate;
  text-align: start;
}

/* اعداد جدول‌ها باید هم‌راستا و چپ‌به‌راست باشند تا مقایسه‌شان آسان باشد. */
.num {
  direction: ltr;
  unicode-bidi: isolate;
}

/* نمودارها عمداً چپ‌به‌راست می‌مانند: محور زمان در همهٔ زبان‌ها از گذشته به
   آینده خوانده می‌شود و آینه‌کردن آن فقط گیج‌کننده است. */
.chart,
.chart-legend {
  direction: ltr;
}
.chart-legend { justify-content: flex-end; }
