@font-face {
  font-family: "Vazirmatn";
  src: url("/static/fonts/Vazirmatn.woff2") format("woff2");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

:root {
  --ink: #172033;
  --ink-soft: #344054;
  --muted: #697386;
  --subtle: #98a2b3;
  --line: #e5e9f0;
  --line-strong: #d5dae4;
  --paper: #ffffff;
  --canvas: #f5f7fb;
  --sidebar: #111827;
  --sidebar-soft: #1d2638;
  --primary: #5b5bd6;
  --primary-dark: #4545b8;
  --primary-soft: #eeeeff;
  --cyan: #0b93a5;
  --green: #07875f;
  --green-soft: #e8f8f1;
  --amber: #b66a06;
  --amber-soft: #fff4df;
  --red: #c33d55;
  --red-soft: #fff0f2;
  --blue-soft: #eaf2ff;
  --radius: 16px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .04), 0 4px 12px rgba(16, 24, 40, .035);
  --shadow-lg: 0 18px 48px rgba(23, 32, 51, .12);
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--canvas); }
body { margin: 0; color: var(--ink); background: var(--canvas); font-family: "Vazirmatn", sans-serif; font-size: 14px; line-height: 1.7; }
a { color: var(--primary-dark); text-decoration: none; transition: color .18s ease; }
a:hover { color: var(--primary); }
button, input, select, textarea { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 264px minmax(0, 1fr); }
.workspace { min-width: 0; }
.sidebar { position: sticky; top: 0; z-index: 30; height: 100vh; padding: 24px 16px 18px; color: #f7f8fb; background: var(--sidebar); display: flex; flex-direction: column; box-shadow: 8px 0 32px rgba(17, 24, 39, .06); }
.brand { padding: 0 8px; display: flex; align-items: center; gap: 12px; color: #fff; }
.brand:hover { color: #fff; }
.brand-mark { width: 42px; height: 42px; display: grid; place-items: center; flex: none; border-radius: 13px; color: #fff; background: var(--primary); box-shadow: 0 8px 24px rgba(91, 91, 214, .35); font-size: 21px; font-weight: 800; direction: ltr; }
.brand-copy { font-size: 17px; font-weight: 800; letter-spacing: -.2px; direction: ltr; text-align: right; }
.brand-copy small { display: block; color: #8f9bb0; font-size: 10px; font-weight: 500; direction: rtl; }
.sidebar nav { margin-top: 34px; display: grid; gap: 4px; }
.nav-label { margin: 17px 13px 7px; color: #67738a; font-size: 10px; font-weight: 700; letter-spacing: .6px; }
.nav-label:first-child { margin-top: 0; }
.sidebar nav a { min-height: 43px; padding: 9px 12px; display: flex; align-items: center; gap: 11px; border-radius: 11px; color: #aeb8ca; font-weight: 550; }
.sidebar nav a:hover { color: #fff; background: rgba(255,255,255,.055); }
.sidebar nav a.active { color: #fff; background: var(--sidebar-soft); box-shadow: inset -3px 0 0 var(--primary); }
.nav-icon { width: 24px; color: #7f8ba0; font-family: sans-serif; font-size: 18px; text-align: center; }
.sidebar nav a.active .nav-icon { color: #9b9bf2; }
.account-box { margin-top: auto; padding: 15px 10px 0; border-top: 1px solid rgba(255,255,255,.08); display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 10px; }
.avatar { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 10px; color: #dedeff; background: rgba(91,91,214,.24); font-weight: 800; }
.account-copy { min-width: 0; }
.account-copy strong, .account-copy small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-copy strong { color: #eef1f7; font-size: 12px; }
.account-copy small { color: #748097; font-size: 10px; direction: ltr; text-align: right; }
.account-box form { margin: 0; }
.logout-button { width: 31px; height: 31px; border: 0; border-radius: 9px; color: #99a5b8; background: transparent; cursor: pointer; font-size: 19px; }
.logout-button:hover { color: #fff; background: rgba(255,255,255,.07); }

.topbar { position: sticky; top: 0; z-index: 20; height: 72px; padding: 0 34px; border-bottom: 1px solid rgba(229,233,240,.9); background: rgba(255,255,255,.9); backdrop-filter: blur(14px); display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.topbar-title strong, .topbar-title span { display: block; }
.topbar-title strong { font-size: 14px; }
.topbar-title span { color: var(--muted); font-size: 11px; }
.topbar-actions { display: flex; align-items: center; gap: 13px; }
.refresh-meta { color: var(--muted); display: flex; align-items: center; gap: 8px; font-size: 11px; }
.refresh-meta.paused .pulse-dot { background: var(--subtle); box-shadow: none; animation: none; }
.auto-refresh-button { min-height: 37px; padding: 7px 12px; border: 1px solid var(--line-strong); border-radius: 10px; color: var(--ink-soft); background: #fff; display: flex; align-items: center; gap: 8px; cursor: pointer; box-shadow: 0 1px 2px rgba(16,24,40,.03); }
.auto-refresh-button:hover { border-color: #bdbde9; color: var(--primary-dark); }
.auto-refresh-button.paused { color: var(--green); border-color: #b7dfd1; background: var(--green-soft); }
.mobile-menu { display: none; width: 38px; height: 38px; border: 1px solid var(--line); border-radius: 10px; background: #fff; cursor: pointer; }

.main-content { width: min(1560px, 100%); padding: 34px 36px 72px; }
.page-header { min-height: 84px; margin-bottom: 24px; display: flex; align-items: flex-start; justify-content: space-between; gap: 24px; }
.page-header h1 { margin: 1px 0 5px; font-size: clamp(26px, 2.8vw, 38px); line-height: 1.25; letter-spacing: -.9px; }
.page-header p { max-width: 780px; margin: 0; color: var(--muted); }
.eyebrow { color: var(--primary) !important; font-size: 11px; font-weight: 800; letter-spacing: .35px; }
.hero-header { align-items: center; }
.system-chip { min-width: 235px; padding: 12px 15px; border: 1px solid #c9e7db; border-radius: 13px; color: var(--green); background: var(--green-soft); display: flex; align-items: center; gap: 11px; }
.system-chip strong, .system-chip small { display: block; }
.system-chip strong { font-size: 12px; }
.system-chip small { color: #4f7f6e; font-size: 10px; }
.pulse-dot { width: 8px; height: 8px; flex: none; border-radius: 50%; background: #11a875; box-shadow: 0 0 0 5px rgba(17,168,117,.12); animation: pulse 2.1s infinite; }
.header-stat { min-width: 118px; padding: 11px 16px; border: 1px solid var(--line); border-radius: 13px; background: rgba(255,255,255,.7); text-align: center; }
.header-stat strong, .header-stat span { display: block; }
.header-stat strong { font-size: 24px; line-height: 1.25; }
.header-stat span { color: var(--muted); font-size: 10px; }

.stats-grid { margin-bottom: 20px; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.stat-card, .panel-section, .source-card, .queue-overview { border: 1px solid var(--line); border-radius: var(--radius); background: var(--paper); box-shadow: var(--shadow-sm); }
.stat-card { min-height: 148px; padding: 18px 19px; position: relative; overflow: hidden; }
.stat-card::after { content: ""; position: absolute; inset: auto -15px -30px auto; width: 82px; height: 82px; border-radius: 50%; background: rgba(91,91,214,.045); }
.stat-card.stat-primary { color: #fff; border-color: var(--primary); background: var(--primary); box-shadow: 0 12px 28px rgba(91,91,214,.2); }
.stat-card.stat-primary::after { background: rgba(255,255,255,.09); }
.stat-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; color: var(--muted); font-size: 12px; }
.stat-primary .stat-top, .stat-primary small { color: #dedeff; }
.metric-icon { width: 30px; height: 30px; display: grid; place-items: center; border-radius: 9px; color: var(--primary); background: var(--primary-soft); font-family: sans-serif; font-weight: 800; }
.metric-icon.success { color: var(--green); background: var(--green-soft); }
.metric-icon.warning { color: var(--amber); background: var(--amber-soft); }
.metric-icon.danger { color: var(--red); background: var(--red-soft); }
.stat-primary .metric-icon { color: #fff; background: rgba(255,255,255,.14); }
.stat-card > strong { margin-top: 7px; display: block; font-size: 35px; line-height: 1.25; }
.stat-card > small { color: var(--muted); font-size: 10px; }

.panel-section, .queue-overview { padding: 22px; margin-bottom: 20px; }
.elevated-panel { padding: 0; overflow: hidden; }
.elevated-panel .section-title { padding: 20px 22px 15px; }
.section-title { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 16px; }
.section-title h2, .section-title p { margin: 0; }
.section-title h2 { font-size: 18px; }
.section-title p { color: var(--muted); font-size: 11px; }
.section-title.compact { margin-bottom: 12px; }
.section-kicker { color: var(--primary) !important; font-weight: 750; }
.text-link { white-space: nowrap; font-size: 12px; font-weight: 750; }
.text-link span { margin-right: 4px; }

.table-panel { padding: 0; overflow: hidden; }
.table-wrap { width: 100%; overflow-x: auto; }
.data-table, table { width: 100%; border-collapse: collapse; }
th, td { padding: 14px 14px; border-bottom: 1px solid #edf0f5; text-align: right; vertical-align: middle; }
th { color: #7b8496; background: #fafbfc; font-size: 10px; font-weight: 750; white-space: nowrap; }
tbody tr { transition: background .16s ease; }
tbody tr:hover { background: #fbfbff; }
tr:last-child td { border-bottom: 0; }
.article-cell { min-width: 290px; max-width: 540px; }
.article-cell > a { display: block; overflow: hidden; color: var(--ink); font-weight: 680; text-overflow: ellipsis; white-space: nowrap; }
.article-cell > a:hover { color: var(--primary); }
.article-cell small { max-width: 510px; margin-top: 2px; display: block; overflow: hidden; color: var(--subtle); font-size: 10px; text-overflow: ellipsis; white-space: nowrap; }
.source-pill { padding: 4px 8px; border: 1px solid #e1e5ec; border-radius: 7px; color: #4d576a; background: #f8f9fb; font-size: 10px; white-space: nowrap; }
.score-pill { min-width: 55px; display: inline-flex; align-items: baseline; justify-content: center; gap: 2px; direction: ltr; }
.score-pill strong { font-size: 19px; }
.score-pill small { color: var(--subtle); font-size: 8px; }
.score-pill.high strong { color: var(--green); }
.score-pill.medium strong { color: var(--amber); }
.score-pill.low strong { color: var(--red); }
.date-cell { color: var(--ink-soft); font-size: 11px; direction: ltr; text-align: right; white-space: nowrap; }
.date-cell small { display: block; color: var(--subtle); }
.badge { padding: 4px 9px; display: inline-flex; align-items: center; border-radius: 999px; color: #5f6878; background: #eff1f5; font-size: 9px; font-weight: 750; direction: ltr; white-space: nowrap; }
.badge::before { content: ""; width: 5px; height: 5px; margin-right: 5px; border-radius: 50%; background: currentColor; opacity: .65; }
.badge-accepted, .badge-processed { color: var(--green); background: var(--green-soft); }
.badge-review, .badge-processing { color: #315faf; background: var(--blue-soft); }
.badge-duplicate, .badge-discovered { color: var(--amber); background: var(--amber-soft); }
.badge-rejected, .badge-failed, .badge-challenge_wait { color: var(--red); background: var(--red-soft); }
.badge-extracted { color: var(--primary); background: var(--primary-soft); }
.confidence { min-width: 106px; display: flex; align-items: center; gap: 8px; direction: ltr; }
.confidence > span { width: 62px; height: 5px; border-radius: 99px; background: #eaedf2; overflow: hidden; }
.confidence i { height: 100%; display: block; border-radius: inherit; background: var(--primary); }
.confidence strong { color: var(--muted); font-size: 10px; }
.attempt-count { width: 29px; height: 29px; display: grid; place-items: center; border-radius: 9px; color: var(--ink-soft); background: #f0f2f5; font-size: 11px; font-weight: 750; }
.manual-running { color: var(--green); display: inline-flex; align-items: center; gap: 8px; font-size: 10px; font-weight: 700; white-space: nowrap; }
.manual-running .pulse-dot { width: 6px; height: 6px; }
.error-cell { max-width: 360px; }
.error-cell > span { display: block; overflow: hidden; color: var(--red); font-size: 10px; text-overflow: ellipsis; white-space: nowrap; }

.status-strip { display: grid; grid-template-columns: repeat(auto-fit, minmax(135px, 1fr)); gap: 8px; }
.status-strip > div { padding: 11px 12px; border: 1px solid #edf0f5; border-radius: 11px; display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 8px; }
.status-strip span { color: var(--muted); font-size: 10px; direction: ltr; }
.status-strip strong { font-size: 16px; }
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--subtle); }
.status-processed { background: var(--green); }
.status-processing { background: #3478dc; }
.status-discovered { background: var(--amber); }
.status-failed, .status-challenge_wait { background: var(--red); }

.panel-toolbar { width: fit-content; margin: -6px 0 18px; padding: 10px; border: 1px solid var(--line); border-radius: 13px; background: #fff; box-shadow: var(--shadow-sm); display: flex; align-items: flex-end; gap: 9px; }
.panel-toolbar label { min-width: 220px; }
label { display: grid; gap: 6px; color: #4a5568; font-size: 11px; font-weight: 700; }
input, select, textarea { width: 100%; min-height: 42px; padding: 8px 11px; border: 1px solid var(--line-strong); border-radius: 9px; color: var(--ink); background: #fff; outline: 0; transition: border .16s ease, box-shadow .16s ease; }
input:focus, select:focus, textarea:focus { border-color: #9d9deb; box-shadow: 0 0 0 3px rgba(91,91,214,.11); }
.button { min-height: 40px; padding: 8px 14px; border: 1px solid transparent; border-radius: 9px; font-weight: 750; cursor: pointer; transition: transform .15s ease, background .15s ease, border .15s ease; }
.button:hover { transform: translateY(-1px); }
.button.primary { color: #fff; background: var(--primary); }
.button.primary:hover { background: var(--primary-dark); }
.button.secondary { color: var(--ink-soft); border-color: var(--line-strong); background: #fff; }
.button.secondary:hover { color: var(--primary-dark); border-color: #bdbde9; }
.button.danger { color: #fff; background: var(--red); }
.button.danger-ghost { color: var(--red); border-color: #f0c5cd; background: #fff; }
.button.small { min-height: 32px; padding: 4px 9px; font-size: 10px; white-space: nowrap; }
.button.wide { width: 100%; }
.pagination { padding: 14px; border-top: 1px solid #edf0f5; display: flex; justify-content: center; gap: 20px; color: var(--muted); font-size: 11px; }
.empty { padding: 42px 20px !important; color: var(--muted); text-align: center; }
.empty-icon { margin: 0 auto 6px; display: block; color: #aeb6c4; font-size: 28px; }

.cards-list { display: grid; gap: 13px; }
.source-card { padding: 20px; display: grid; grid-template-columns: minmax(220px, 1.2fr) 2fr auto; align-items: center; gap: 25px; }
.source-card > div { display: flex; align-items: center; gap: 12px; }
.source-card h2, .source-card p { margin: 0; }
.source-card h2 { font-size: 16px; }
.source-card dl { margin: 0; display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.source-card dt, .meta-list dt, .score-list dt { color: var(--muted); font-size: 10px; }
.source-card dd, .meta-list dd, .score-list dd { margin: 0; }
.source-card .status-dot.on { background: var(--green); box-shadow: 0 0 0 5px rgba(7,135,95,.11); }
.detail-grid { display: grid; grid-template-columns: minmax(0, 1.8fr) minmax(290px, .75fr); gap: 18px; align-items: start; }
.side-stack { display: grid; gap: 0; }
.panel-section h2 { margin: 0 0 14px; font-size: 17px; }
.article-copy { font-size: 15px; line-height: 2.15; }
.article-copy h3 { margin-top: 30px; }
.article-copy blockquote { margin: 18px 0; padding: 12px 18px; border-right: 3px solid var(--primary); border-radius: 8px; color: var(--ink-soft); background: #f7f7ff; }
.meta-list, .score-list { margin: 0; }
.meta-list div, .score-list div { padding: 8px 0; border-bottom: 1px solid #edf0f5; display: flex; justify-content: space-between; gap: 12px; }
.score-total { margin-bottom: 8px; color: var(--primary); font-size: 39px; font-weight: 800; direction: ltr; text-align: right; }
.score-total small { color: var(--muted); font-size: 11px; }
.tags { margin-top: 12px; display: flex; flex-wrap: wrap; gap: 5px; }
.tags span { padding: 3px 7px; border-radius: 6px; color: var(--red); background: var(--red-soft); font-size: 9px; direction: ltr; }
.split-layout { display: grid; grid-template-columns: minmax(0, 1.8fr) minmax(280px, .7fr); gap: 18px; align-items: start; }
.row-actions { display: flex; align-items: center; gap: 8px; }
.row-actions summary { color: var(--primary-dark); cursor: pointer; white-space: nowrap; }
.inline-reset { min-width: 250px; margin-top: 8px; display: flex; gap: 6px; }
.stack-form { display: grid; gap: 14px; }
.stack-form.narrow { max-width: 480px; }
.optional, .muted { color: var(--muted); font-weight: 400; }
.security-card { max-width: 900px; }
.security-status { margin-bottom: 22px; padding: 17px; border-radius: 11px; background: #f2f4f7; }
.security-status.enabled { color: var(--green); background: var(--green-soft); }
.security-status strong, .security-status span { display: block; }
.security-status span { margin-top: 3px; color: var(--muted); }
.setup-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 35px; align-items: center; }
.qr { width: 220px; max-width: 100%; border: 10px solid #fff; border-radius: 12px; box-shadow: var(--shadow-lg); }
.recovery-grid { margin-top: 13px; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.recovery-grid code { padding: 8px; border-radius: 7px; color: var(--ink); background: rgba(255,255,255,.8); text-align: center; }
.alert { margin-bottom: 18px; padding: 14px 17px; border: 1px solid transparent; border-radius: 11px; }
.alert h2 { margin: 0; }
.alert-error { color: #91293c; border-color: #f1c5cd; background: var(--red-soft); }
.alert-success { color: #056e4e; border-color: #bde4d6; background: var(--green-soft); }

.login-body { min-height: 100vh; padding: 24px; background: radial-gradient(circle at 18% 18%, rgba(91,91,214,.12), transparent 32%), var(--canvas); display: grid; place-items: center; }
.login-card { width: min(430px, 100%); padding: 37px; border: 1px solid rgba(255,255,255,.9); border-radius: 22px; background: rgba(255,255,255,.96); box-shadow: 0 28px 80px rgba(23,32,51,.14); }
.login-brand { margin-bottom: 34px; padding: 0; color: var(--ink); }
.login-brand:hover { color: var(--ink); }
.login-card h1 { margin: 0; font-size: 30px; }
.login-card > p { margin: 3px 0 22px; }

.block { display: block; }
.ltr { direction: ltr; text-align: left; }
.live-region { transition: opacity .16s ease, transform .16s ease; }
.live-region.is-updating { opacity: .45; transform: translateY(2px); }
.toast { position: fixed; right: 50%; bottom: 24px; z-index: 100; padding: 10px 15px; border-radius: 11px; color: #fff; background: var(--sidebar); box-shadow: var(--shadow-lg); opacity: 0; pointer-events: none; transform: translate(50%, 14px); transition: opacity .2s ease, transform .2s ease; }
.toast.show { opacity: 1; transform: translate(50%, 0); }
.toast[data-kind="error"] { background: #9f2e42; }

@keyframes pulse { 0%, 100% { box-shadow: 0 0 0 4px rgba(17,168,117,.11); } 50% { box-shadow: 0 0 0 7px rgba(17,168,117,.035); } }

@media (max-width: 1180px) {
  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .source-card { grid-template-columns: 1fr; }
}

@media (max-width: 980px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; right: 0; width: min(280px, 88vw); transform: translateX(105%); transition: transform .22s ease; }
  .sidebar.open { transform: translateX(0); }
  .mobile-menu { display: grid; place-items: center; }
  .topbar { padding: 0 18px; justify-content: flex-start; }
  .topbar-actions { margin-right: auto; }
  .main-content { padding: 28px 18px 60px; }
  .detail-grid, .split-layout { grid-template-columns: 1fr; }
}

@media (max-width: 680px) {
  .topbar-title { display: none; }
  .refresh-meta { display: none; }
  .auto-refresh-button span:last-child { display: none; }
  .auto-refresh-button { width: 39px; justify-content: center; }
  .page-header { display: block; }
  .page-header > .header-stat, .page-header > .system-chip { width: 100%; margin-top: 14px; }
  .stats-grid { grid-template-columns: 1fr; }
  .stat-card { min-height: 130px; }
  .panel-toolbar { width: 100%; align-items: stretch; flex-direction: column; }
  .panel-toolbar label { min-width: 0; }
  .section-title { align-items: flex-start; }
  .section-title > div p:last-child { display: none; }
  .setup-grid, .recovery-grid { grid-template-columns: 1fr; }
  .login-card { padding: 28px 22px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
