/* داشبورد مدیریت فروش ایمن‌آب — DESIGN.md را ببینید */
@font-face {
  font-family: "Vazirmatn";
  src: url("/static/fonts/Vazirmatn-wght.woff2") format("woff2-variations"), url("/static/fonts/Vazirmatn-wght.woff2") format("woff2");
  font-weight: 100 900; font-display: swap;
}

:root {
  --bg: #F3F2EE; --panel: #FCFBF8; --panel-2: #EBE9E3; --sunk: #F7F6F2;
  --ink: #1B1E22; --ink-2: #454B53; --ink-3: #60666F;
  --line: #E0DDD5; --line-2: #CCC8BE;
  --accent: #0B5F7A; --accent-hover: #084D63; --accent-soft: #E0EDF1; --on-accent: #F5FAFB;
  --s1: #0B72A8; --s2: #B5700F;
  --crit: #B42318; --crit-soft: #FBEAE7; --warn: #8F5400; --warn-soft: #FBF0DB;
  --ok: #1B6E44; --ok-soft: #E2F1E8; --info: #2A5AA3; --info-soft: #E6EDF8;
  --focus: #0B72A8;
  --shadow-1: 0 1px 2px rgb(27 30 34 / .05), 0 2px 8px rgb(27 30 34 / .04);
  --shadow-2: 0 2px 6px rgb(27 30 34 / .08), 0 16px 40px rgb(27 30 34 / .14);
  --r: 10px; --r-sm: 7px;
  --ease: cubic-bezier(0.23, 1, 0.32, 1); --ease-drawer: cubic-bezier(0.32, 0.72, 0, 1);
  --nav-w: 236px;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #111316; --panel: #181B1F; --panel-2: #14171A; --sunk: #1D2125;
  --ink: #E9E7E2; --ink-2: #BDC0C5; --ink-3: #9A9FA6;
  --line: #2A2F35; --line-2: #3A4047;
  --accent: #5DB6D2; --accent-hover: #7CC6DD; --accent-soft: #17303A; --on-accent: #08171D;
  --s1: #2A9AB0; --s2: #C98420;
  --crit: #F08A7E; --crit-soft: #3A1E1B; --warn: #E3AA52; --warn-soft: #352914;
  --ok: #67C394; --ok-soft: #173127; --info: #93B4EC; --info-soft: #1A2638;
  --focus: #7CC6DD;
  --shadow-1: 0 1px 2px rgb(0 0 0 / .3); --shadow-2: 0 18px 48px rgb(0 0 0 / .5);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: "Vazirmatn", Tahoma, sans-serif; font-size: 1rem; line-height: 1.8;
  overflow-x: clip; min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}
::selection { background: var(--accent); color: var(--on-accent); }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
[hidden] { display: none !important; }
h1, h2, h3, h4 { line-height: 1.4; margin: 0; font-weight: 700; text-wrap: balance; }
p { margin: 0; }
a { color: var(--accent); text-underline-offset: 3px; }
button, input, select, textarea { font: inherit; color: inherit; }
.num, td.n, .kpi-val { font-variant-numeric: tabular-nums; }
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.ic { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }
.sr { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 10px; border: 2px solid var(--bg); }
::-webkit-scrollbar-track { background: transparent; }

/* ---------- buttons & fields ---------- */
.btn {
  display: inline-flex; align-items: center; gap: .45rem; min-height: 40px; padding: 0 .9rem;
  border: 1px solid var(--line-2); border-radius: var(--r-sm); background: var(--panel); color: var(--ink);
  font-size: .9rem; font-weight: 500; cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: background-color .15s var(--ease), border-color .15s var(--ease), transform .12s var(--ease);
}
@media (hover: hover) { .btn:hover { background: var(--sunk); border-color: var(--ink-3); } }
.btn:active { transform: scale(.98); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; transform: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
@media (hover: hover) { .btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); } }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-danger { color: var(--crit); border-color: color-mix(in srgb, var(--crit) 40%, var(--line)); }
.btn-sm { min-height: 34px; padding: 0 .7rem; font-size: .84rem; }
.btn-block { width: 100%; justify-content: center; min-height: 46px; }
.btn.is-loading { pointer-events: none; opacity: .75; }
.btn.is-loading::after { content: ""; width: 14px; height: 14px; border: 2px solid currentColor; border-inline-end-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.icon-btn { display: grid; place-items: center; width: 40px; height: 40px; border: 0; border-radius: var(--r-sm); background: transparent; color: var(--ink-2); cursor: pointer; }
@media (hover: hover) { .icon-btn:hover { background: var(--line); color: var(--ink); } }

.field { display: grid; gap: .3rem; }
.field > span { font-size: .84rem; font-weight: 600; color: var(--ink-2); }
.field small { color: var(--ink-3); font-size: .78rem; line-height: 1.6; }
input:not([type="checkbox"]):not([type="radio"]):not([type="file"]), select, textarea {
  width: 100%; min-height: 42px; padding: .45rem .7rem; border: 1px solid var(--line-2); border-radius: var(--r-sm);
  background: var(--panel); transition: border-color .15s var(--ease), box-shadow .15s var(--ease);
}
input::placeholder, textarea::placeholder { color: var(--ink-3); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input[aria-invalid="true"], input[aria-invalid="true"]:focus { border-color: var(--crit); box-shadow: 0 0 0 3px var(--crit-soft); }
textarea { resize: vertical; min-height: 88px; line-height: 1.8; }
.check { display: flex; align-items: center; gap: .55rem; font-size: .9rem; cursor: pointer; min-height: 40px; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }
.form-error { color: var(--crit); font-size: .86rem; }

/* ---------- login ---------- */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 1.5rem; }
.login-card { width: min(400px, 100%); display: grid; gap: 1.1rem; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 2rem 1.75rem; box-shadow: var(--shadow-1); }
.login-foot { font-size: .78rem; color: var(--ink-3); text-align: center; }

.brand-lockup { display: flex; align-items: center; gap: .7rem; color: var(--ink); text-decoration: none; }
.brand-lockup strong { display: block; font-size: 1rem; line-height: 1.4; }
.brand-lockup span { display: block; font-size: .78rem; color: var(--ink-3); line-height: 1.5; }
.brand-mark { width: 36px; height: 36px; flex: none; }
.brand-mark rect { fill: var(--accent); }
.brand-mark path { stroke: var(--on-accent); stroke-width: 3; stroke-linecap: round; fill: none; }

/* ---------- shell ---------- */
.app { display: grid; grid-template-columns: var(--nav-w) minmax(0, 1fr); min-height: 100dvh; }
.nav { position: sticky; top: 0; height: 100dvh; display: flex; flex-direction: column; gap: 1.25rem; padding: 1.1rem .8rem; background: var(--panel-2); border-inline-end: 1px solid var(--line); }
.nav > .brand-lockup { padding: .2rem .5rem .6rem; }
.nav-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.nav-list a { position: relative; display: flex; align-items: center; gap: .7rem; min-height: 42px; padding: 0 .75rem; border-radius: var(--r-sm); color: var(--ink-2); text-decoration: none; font-size: .93rem; font-weight: 500; transition: background-color .15s var(--ease), color .15s var(--ease); }
@media (hover: hover) { .nav-list a:hover { background: var(--line); color: var(--ink); } }
.nav-list a[aria-current="page"] { background: var(--panel); color: var(--ink); font-weight: 700; box-shadow: var(--shadow-1); }
.nav-list a[aria-current="page"] .ic { color: var(--accent); }
.nav-badge { margin-inline-start: auto; min-width: 22px; height: 22px; padding: 0 6px; border-radius: 11px; background: var(--crit); color: #FFF8F7; font-size: .74rem; font-weight: 700; display: grid; place-items: center; line-height: 1; }
.nav-foot { margin-top: auto; display: flex; align-items: center; gap: .25rem; padding-top: .8rem; border-top: 1px solid var(--line); }
.who { flex: 1; min-width: 0; padding-inline-start: .5rem; line-height: 1.45; }
.who span { display: block; font-size: .86rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.who small { color: var(--ink-3); font-size: .75rem; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 1rem; padding: .85rem 1.75rem; background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
.top-title { min-width: 0; flex: 1; }
.top-title h1 { font-size: 1.3rem; }
.top-title p { font-size: .82rem; color: var(--ink-3); line-height: 1.5; }
.top-search { position: relative; width: min(340px, 34vw); display: flex; align-items: center; }
.top-search > .ic { position: absolute; inset-inline-start: .7rem; color: var(--ink-3); pointer-events: none; }
.top-search input { padding-inline-start: 2.3rem !important; padding-inline-end: 2rem !important; background: var(--panel); }
.top-search kbd { position: absolute; inset-inline-end: .6rem; font: 500 .72rem/1 "Vazirmatn"; color: var(--ink-3); border: 1px solid var(--line-2); border-radius: 4px; padding: 3px 6px; }
.search-pop { position: absolute; top: calc(100% + 6px); inset-inline: 0; z-index: 40; list-style: none; margin: 0; padding: .35rem; background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow-2); max-height: 60vh; overflow: auto; }
.search-pop li { display: flex; justify-content: space-between; gap: .5rem; padding: .5rem .65rem; border-radius: var(--r-sm); cursor: pointer; font-size: .9rem; }
.search-pop li small { color: var(--ink-3); }
.search-pop li[aria-selected="true"], .search-pop li:hover { background: var(--accent-soft); }
.top-actions { display: flex; gap: .5rem; }
.view { padding: 1.5rem 1.75rem 3rem; outline: none; max-width: 1560px; width: 100%; }

/* ---------- sections ---------- */
.section { margin-top: 2.25rem; }
.section:first-child { margin-top: 0; }
.sec-head { display: flex; align-items: center; gap: .75rem; margin-bottom: .85rem; flex-wrap: wrap; }
.sec-head h2 { font-size: 1.05rem; }
.sec-head p { font-size: .84rem; color: var(--ink-3); }
.sec-head .spacer { flex: 1; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow-1); }
.panel-pad { padding: 1.1rem 1.25rem; }
.muted { color: var(--ink-3); }
.grid-2 { display: grid; grid-template-columns: minmax(0, 1.65fr) minmax(0, 1fr); gap: 1.25rem; align-items: start; }
.grid-charts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1.25rem; }

/* KPI band — یک نوار پیوسته، نه کارت‌های جدا */
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow-1); }
.kpi { padding: 1.05rem 1.25rem 1.1rem; display: grid; gap: .2rem; align-content: start; }
.kpi + .kpi { border-inline-start: 1px solid var(--line); }
.kpi-label { font-size: .84rem; color: var(--ink-2); font-weight: 500; }
.kpi-val { font-size: 1.9rem; font-weight: 700; line-height: 1.3; letter-spacing: -.01em; }
.kpi-val small { font-size: .85rem; font-weight: 500; color: var(--ink-3); margin-inline-start: .3rem; }
.kpi-sub { font-size: .8rem; color: var(--ink-3); line-height: 1.6; }
.meter { position: relative; height: 6px; border-radius: 3px; background: var(--line); margin-top: .5rem; overflow: hidden; }
.meter > i { position: absolute; inset-block: 0; inset-inline-start: 0; border-radius: 3px; background: var(--s1); }
.meter.is-crit > i { background: var(--crit); } .meter.is-warn > i { background: var(--warn); } .meter.is-ok > i { background: var(--ok); }
.delta { display: inline-flex; align-items: center; gap: .2rem; font-weight: 600; }
.delta.up { color: var(--ok); } .delta.down { color: var(--crit); }

/* chips */
.chip { display: inline-flex; align-items: center; gap: .3rem; height: 24px; padding: 0 .55rem; border-radius: 12px; font-size: .76rem; font-weight: 600; white-space: nowrap; background: var(--sunk); color: var(--ink-2); border: 1px solid var(--line); }
.chip .ic { width: 13px; height: 13px; stroke-width: 2.2; }
.chip.low, .chip.ok, .chip.positive { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.chip.medium, .chip.warning { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.chip.high, .chip.critical { background: var(--crit-soft); color: var(--crit); border-color: transparent; }
.chip.info { background: var(--info-soft); color: var(--info); border-color: transparent; }
.chip.unknown { background: var(--sunk); color: var(--ink-3); }

.health { display: inline-flex; align-items: center; gap: .4rem; font-weight: 700; font-size: .9rem; }
.health small { font-weight: 500; font-size: .74rem; color: var(--ink-3); }
.health i { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); }
.health.mid i { background: var(--warn); } .health.bad i { background: var(--crit); }

/* action list (overview) */
.act-list { list-style: none; margin: 0; padding: 0; }
.act-list li { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: .35rem 1rem; padding: .9rem 1.25rem; border-top: 1px solid var(--line); cursor: pointer; transition: background-color .15s var(--ease); }
.act-list li:first-child { border-top: 0; }
@media (hover: hover) { .act-list li:hover { background: var(--sunk); } }
.act-name { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; font-weight: 700; }
.act-name small { font-weight: 400; color: var(--ink-3); font-size: .82rem; }
.act-issue { grid-column: 1; font-size: .87rem; color: var(--ink-2); line-height: 1.7; }
.act-side { grid-row: 1 / span 2; grid-column: 2; display: grid; justify-items: end; align-content: center; gap: .25rem; }
.act-more { font-size: .78rem; color: var(--ink-3); }

/* AI panel */
.ai-head { display: flex; align-items: center; gap: .6rem; padding: .95rem 1.25rem; border-bottom: 1px solid var(--line); }
.ai-head h2 { font-size: 1rem; flex: 1; display: flex; align-items: center; gap: .45rem; }
.ai-head h2 .ic { color: var(--accent); }
.ai-body { padding: 1rem 1.25rem 1.2rem; display: grid; gap: .9rem; }
.ai-headline { font-weight: 600; line-height: 1.85; }
.ai-items { list-style: none; margin: 0; padding: 0; display: grid; gap: .8rem; }
.ai-items li { display: grid; gap: .2rem; padding-bottom: .8rem; border-bottom: 1px dashed var(--line); }
.ai-items li:last-child { border-bottom: 0; padding-bottom: 0; }
.ai-items h3 { font-size: .93rem; display: flex; align-items: center; gap: .45rem; flex-wrap: wrap; }
.ai-items p { font-size: .86rem; color: var(--ink-2); line-height: 1.8; }
.ai-items .ai-action { color: var(--ink); font-weight: 500; }
.ai-meta { font-size: .75rem; color: var(--ink-3); }
.pri { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.pri.high { background: var(--crit); } .pri.medium { background: var(--warn); } .pri.low { background: var(--info); }

/* empty */
.empty { display: grid; justify-items: start; gap: .6rem; padding: 1.5rem 1.25rem; }
.empty h3 { font-size: 1rem; }
.empty p { color: var(--ink-2); font-size: .9rem; max-width: 62ch; }
.empty.center { justify-items: center; text-align: center; padding: 3.5rem 1.5rem; }
.empty ol { margin: 0; padding-inline-start: 1.2rem; color: var(--ink-2); font-size: .9rem; }

/* skeleton */
.sk { border-radius: 6px; background: linear-gradient(90deg, var(--line) 0%, var(--sunk) 50%, var(--line) 100%); background-size: 200% 100%; animation: sk 1.3s ease-in-out infinite; }
@keyframes sk { from { background-position: 200% 0; } to { background-position: -200% 0; } }

/* charts */
.chart { padding: 1rem 1.25rem 1.15rem; }
.chart h3 { font-size: .95rem; }
.chart .chart-sub { font-size: .8rem; color: var(--ink-3); margin-bottom: .85rem; }
.legend { display: flex; gap: 1rem; flex-wrap: wrap; font-size: .8rem; color: var(--ink-2); margin-bottom: .7rem; }
.legend span { display: inline-flex; align-items: center; gap: .4rem; }
.legend i { width: 12px; height: 12px; border-radius: 3px; }
.legend i.l-line { width: 14px; height: 0; border-top: 2px dashed var(--ink-3); border-radius: 0; }
.hbars { display: grid; gap: .55rem; }
.hbar { display: grid; grid-template-columns: minmax(84px, 9.5rem) minmax(0, 1fr) 4.2rem; align-items: center; gap: .7rem; font-size: .84rem; }
.hbar-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--ink-2); }
.hbar-val { text-align: end; font-weight: 600; font-variant-numeric: tabular-nums; }
.track { position: relative; height: 22px; }
.track .bar { position: absolute; inset-inline-start: 0; height: 100%; border-radius: 0 4px 4px 0; background: var(--s1); transition: width .4s var(--ease); }
[dir="rtl"] .track .bar { border-radius: 4px 0 0 4px; }
.track .bar.s2 { background: var(--s2); }
.track.pair { height: 26px; }
.track.pair .bar { height: 11px; }
.track.pair .bar.s2 { top: 13px; }
.track .mark { position: absolute; inset-block: -3px; width: 0; border-inline-start: 2px dashed var(--ink-3); }
.track .mark.solid { border-inline-start-style: solid; border-color: var(--ink-2); }
.track .bar[data-tip], .hbar[data-tip] { cursor: default; }
.stack { display: flex; height: 26px; gap: 2px; border-radius: 5px; overflow: hidden; }
.stack > i { display: block; height: 100%; }
.stack-legend { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: .6rem; margin-top: .9rem; }
.stack-legend div { display: grid; gap: .1rem; font-size: .82rem; }
.stack-legend b { font-size: 1.05rem; }
.stack-legend span { display: inline-flex; align-items: center; gap: .4rem; color: var(--ink-2); }
.stack-legend span i { width: 10px; height: 10px; border-radius: 3px; }
.tip { position: fixed; z-index: 90; pointer-events: none; background: var(--ink); color: var(--bg); font-size: .8rem; line-height: 1.7; padding: .45rem .65rem; border-radius: 6px; box-shadow: var(--shadow-2); max-width: 280px; opacity: 0; transition: opacity .12s var(--ease); }
.tip.on { opacity: 1; }

/* ---------- table ---------- */
.filters { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; margin-bottom: 1rem; }
.filters input[type="search"] { width: 240px; }
.filters select { width: auto; min-width: 140px; }
.seg { display: inline-flex; padding: 3px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 9px; }
.seg button { border: 0; background: transparent; border-radius: 6px; padding: 0 .75rem; min-height: 34px; font-size: .84rem; cursor: pointer; color: var(--ink-2); }
.seg button[aria-pressed="true"] { background: var(--panel); color: var(--ink); font-weight: 600; box-shadow: var(--shadow-1); }
.count-note { font-size: .84rem; color: var(--ink-3); margin-inline-start: auto; }
.table-wrap { overflow-x: auto; border-radius: var(--r); }
table.data { width: 100%; border-collapse: collapse; font-size: .875rem; min-width: 980px; }
table.data th { position: sticky; top: 0; background: var(--panel); text-align: start; font-weight: 600; font-size: .78rem; color: var(--ink-2); padding: .7rem .75rem; border-bottom: 1px solid var(--line-2); white-space: nowrap; }
table.data th button { all: unset; cursor: pointer; display: inline-flex; align-items: center; gap: .2rem; }
table.data th button:focus-visible { outline: 2px solid var(--focus); }
table.data th[aria-sort] button::after { content: "▾"; font-size: .7rem; color: var(--accent); }
table.data th[aria-sort="ascending"] button::after { content: "▴"; }
table.data td { padding: .7rem .75rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.data td.n { text-align: end; white-space: nowrap; }
table.data tbody tr { cursor: pointer; transition: background-color .12s var(--ease); }
@media (hover: hover) { table.data tbody tr:hover { background: var(--sunk); } }
table.data tbody tr:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }
.cell-name strong { display: block; font-weight: 700; }
.cell-name small { color: var(--ink-3); font-size: .78rem; }
.mini { display: grid; gap: 3px; min-width: 90px; }
.mini .meter { margin: 0; height: 5px; }
.alert-dots { display: inline-flex; gap: .3rem; }

/* ---------- alerts page ---------- */
.alert-list { list-style: none; margin: 0; padding: 0; }
.alert-item { display: grid; grid-template-columns: 34px minmax(0, 1fr) auto; gap: .2rem .9rem; padding: 1rem 1.25rem; border-top: 1px solid var(--line); }
.alert-item:first-child { border-top: 0; }
.alert-ic { grid-row: 1 / span 3; width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center; }
.alert-ic.critical { background: var(--crit-soft); color: var(--crit); }
.alert-ic.warning { background: var(--warn-soft); color: var(--warn); }
.alert-ic.info { background: var(--info-soft); color: var(--info); }
.alert-ic.positive { background: var(--ok-soft); color: var(--ok); }
.alert-title { font-weight: 700; display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.alert-title button { all: unset; cursor: pointer; color: var(--accent); font-weight: 600; text-decoration: underline; text-underline-offset: 3px; text-decoration-thickness: 1px; }
.alert-detail { font-size: .88rem; color: var(--ink-2); line-height: 1.8; }
.alert-action { font-size: .86rem; line-height: 1.8; }
.alert-action b { font-weight: 600; color: var(--ink-3); }
.alert-btns { grid-column: 3; grid-row: 1 / span 3; display: flex; flex-direction: column; gap: .35rem; align-items: stretch; }
.ack-note { font-size: .78rem; color: var(--ink-3); }

/* ---------- drawer ---------- */
.scrim { position: fixed; inset: 0; z-index: 50; background: rgb(17 19 22 / .45); opacity: 0; transition: opacity .25s var(--ease); }
.scrim.on { opacity: 1; }
.drawer { position: fixed; z-index: 60; inset-block: 0; inset-inline-end: 0; width: min(720px, 100vw); background: var(--bg); box-shadow: var(--shadow-2); display: flex; flex-direction: column; transform: translateX(-104%); transition: transform .38s var(--ease-drawer); }
[dir="rtl"] .drawer { transform: translateX(-104%); }
.drawer.on { transform: none; }
.dr-head { padding: 1.1rem 1.4rem .2rem; background: var(--panel); }
.dr-top { display: flex; align-items: flex-start; gap: .75rem; }
.dr-top h2 { font-size: 1.25rem; flex: 1; }
.dr-top p { font-size: .84rem; color: var(--ink-3); }
.dr-chips { display: flex; gap: .4rem; flex-wrap: wrap; margin-top: .5rem; }
.tabs { display: flex; gap: .25rem; margin-top: .9rem; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tabs button { border: 0; background: none; padding: .55rem .8rem; min-height: 44px; cursor: pointer; font-size: .9rem; color: var(--ink-2); border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs button[aria-selected="true"] { color: var(--ink); font-weight: 700; border-bottom-color: var(--accent); }
.dr-body { flex: 1; overflow-y: auto; padding: 1.25rem 1.4rem 2rem; display: grid; grid-auto-rows: max-content; gap: 1.25rem; align-content: start; overscroll-behavior: contain; scroll-padding-block: 1rem 6rem; }
.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; }
.facts div { background: var(--panel); padding: .7rem .9rem; display: grid; gap: .1rem; }
.facts dt { font-size: .76rem; color: var(--ink-3); }
.facts dd { margin: 0; font-weight: 600; font-size: .95rem; font-variant-numeric: tabular-nums; }
.checks { list-style: none; margin: 0; padding: 0; }
.checks li { display: grid; grid-template-columns: 24px minmax(0, 1fr) auto; gap: .6rem; align-items: start; padding: .75rem 1rem; border-top: 1px solid var(--line); font-size: .88rem; }
.checks li:first-child { border-top: 0; }
.checks .ic { margin-top: .25rem; }
.checks .pass .ic { color: var(--ok); } .checks .fail .ic { color: var(--crit); } .checks .na .ic { color: var(--ink-3); }
.checks small { display: block; color: var(--ink-3); font-size: .8rem; }
.formula { font-size: .86rem; line-height: 2; color: var(--ink-2); }
.formula b { color: var(--ink); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .9rem 1rem; }
.form-grid .wide { grid-column: 1 / -1; }
fieldset { border: 0; padding: 0; margin: 0; display: grid; gap: .8rem; }
legend { font-weight: 700; font-size: .95rem; margin-bottom: .6rem; padding: 0; }
.form-actions { display: flex; gap: .5rem; align-items: center; position: sticky; bottom: -2rem; background: var(--bg); padding: .9rem 0 .5rem; border-top: 1px solid var(--line); }
.form-actions .spacer { flex: 1; }

/* ---------- AI chat ---------- */
.chat { display: grid; grid-template-rows: minmax(0, 1fr) auto; height: calc(100dvh - 170px); min-height: 460px; }
.chat-log { overflow-y: auto; padding: 1.25rem; display: grid; gap: 1rem; align-content: start; }
.msg { max-width: 82ch; line-height: 1.9; font-size: .94rem; }
.msg.user { justify-self: start; background: var(--accent-soft); padding: .6rem .9rem; border-radius: 12px 12px 12px 4px; }
.msg.bot { justify-self: stretch; }
.msg.bot h3, .msg.bot h4 { font-size: 1rem; margin: .7rem 0 .2rem; }
.msg.bot ul, .msg.bot ol { margin: .3rem 0; padding-inline-start: 1.3rem; }
.msg.bot table { border-collapse: collapse; margin: .5rem 0; font-size: .86rem; }
.msg.bot th, .msg.bot td { border: 1px solid var(--line-2); padding: .3rem .6rem; text-align: start; }
.msg.bot code { background: var(--sunk); padding: 1px 5px; border-radius: 4px; }
.msg.err { color: var(--crit); font-size: .88rem; }
.chat-form { display: flex; gap: .6rem; padding: .9rem 1.25rem; border-top: 1px solid var(--line); align-items: flex-end; }
.chat-form textarea { min-height: 46px; max-height: 180px; }
.prompts { display: flex; flex-wrap: wrap; gap: .5rem; }
.prompts button { border: 1px solid var(--line-2); background: var(--panel); border-radius: 18px; padding: .35rem .85rem; min-height: 38px; font-size: .86rem; cursor: pointer; color: var(--ink-2); text-align: start; }
@media (hover: hover) { .prompts button:hover { border-color: var(--accent); color: var(--ink); } }
.typing { display: inline-flex; gap: 4px; padding: .5rem 0; }
.typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--ink-3); animation: blink 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: .2s; } .typing i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

/* ---------- settings ---------- */
.set-grid { display: grid; grid-template-columns: 200px minmax(0, 1fr); gap: 1.5rem; align-items: start; }
.set-nav { position: sticky; top: 90px; display: grid; gap: 2px; }
.set-nav a { padding: .45rem .7rem; border-radius: var(--r-sm); color: var(--ink-2); text-decoration: none; font-size: .9rem; }
.set-nav a:hover { background: var(--line); }
.set-sec { scroll-margin-top: 90px; }
.coef { width: 100%; border-collapse: collapse; font-size: .88rem; }
.coef th, .coef td { padding: .5rem .6rem; border-bottom: 1px solid var(--line); text-align: start; }
.coef th { font-size: .8rem; color: var(--ink-2); font-weight: 600; }
.coef td input { max-width: 120px; min-height: 38px; }
.coef td small { color: var(--ink-3); }
.status-line { display: flex; align-items: center; gap: .5rem; font-size: .88rem; }
.kv { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: .9rem 1rem; align-items: start; }
.audit-list { list-style: none; margin: 0; padding: 0; font-size: .84rem; max-height: 420px; overflow: auto; }
.audit-list li { display: grid; grid-template-columns: 9rem 7rem minmax(0, 1fr); gap: .6rem; padding: .5rem 1.25rem; border-top: 1px solid var(--line); }
.audit-list li:first-child { border-top: 0; }

/* ---------- dialog ---------- */
.dlg { width: min(880px, calc(100vw - 2rem)); max-height: calc(100dvh - 2rem); padding: 0; border: 1px solid var(--line); border-radius: 14px; background: var(--bg); color: var(--ink); box-shadow: var(--shadow-2); }
.dlg-sm { width: min(440px, calc(100vw - 2rem)); }
.dlg::backdrop { background: rgb(17 19 22 / .45); }
.dlg[open] { animation: dlg-in .22s var(--ease); }
@keyframes dlg-in { from { opacity: 0; transform: translateY(8px) scale(.985); } }
.dlg-head { display: flex; align-items: center; gap: .75rem; padding: 1rem 1.25rem; border-bottom: 1px solid var(--line); background: var(--panel); }
.dlg-head h2 { font-size: 1.05rem; flex: 1; }
.dlg-body { padding: 1.25rem; display: grid; gap: 1rem; overflow-y: auto; max-height: calc(100dvh - 190px); }
.dlg-foot { display: flex; gap: .5rem; justify-content: flex-end; padding: .9rem 1.25rem; border-top: 1px solid var(--line); background: var(--panel); }
.drop { display: grid; justify-items: center; gap: .5rem; padding: 2.2rem 1rem; border: 1.5px dashed var(--line-2); border-radius: var(--r); background: var(--panel); text-align: center; cursor: pointer; transition: border-color .15s var(--ease), background-color .15s var(--ease); }
.drop.over, .drop:hover { border-color: var(--accent); background: var(--accent-soft); }
.drop .ic { width: 30px; height: 30px; color: var(--accent); }
.drop p { color: var(--ink-2); font-size: .9rem; }
.drop input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.stats-row { display: flex; gap: 1.5rem; flex-wrap: wrap; }
.stats-row div { display: grid; }
.stats-row b { font-size: 1.4rem; font-variant-numeric: tabular-nums; }
.stats-row span { font-size: .8rem; color: var(--ink-3); }
.warn-box { background: var(--warn-soft); color: var(--warn); border-radius: var(--r-sm); padding: .7rem .9rem; font-size: .85rem; line-height: 1.8; }
.warn-box ul { margin: .2rem 0 0; padding-inline-start: 1.1rem; }
.radio-row { display: flex; gap: 1.25rem; flex-wrap: wrap; }

/* ---------- toast ---------- */
.toasts { position: fixed; z-index: 100; inset-block-end: 1.25rem; inset-inline-start: 50%; transform: translateX(50%); display: grid; gap: .5rem; width: min(440px, calc(100vw - 2rem)); }
.toast { background: var(--ink); color: var(--bg); padding: .7rem 1rem; border-radius: 9px; box-shadow: var(--shadow-2); font-size: .9rem; display: flex; gap: .6rem; align-items: center; animation: dlg-in .25s var(--ease); }
.toast.err { background: var(--crit); color: #FFF8F7; }

/* ---------- responsive ---------- */
@media (max-width: 1180px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi:nth-child(3) { border-inline-start: 0; }
  .kpi:nth-child(n+3) { border-top: 1px solid var(--line); }
  .grid-2 { grid-template-columns: minmax(0, 1fr); }
  .top-actions .btn span { display: none; }
}
@media (max-width: 900px) {
  .app { grid-template-columns: minmax(0, 1fr); padding-bottom: calc(64px + env(safe-area-inset-bottom)); }
  .nav { position: fixed; z-index: 30; inset-block-end: 0; inset-inline: 0; top: auto; height: auto; flex-direction: row; padding: 4px 4px calc(4px + env(safe-area-inset-bottom)); border-inline-end: 0; border-top: 1px solid var(--line); background: var(--panel); }
  .nav > .brand-lockup, .nav-foot { display: none; }
  .nav-list { grid-auto-flow: column; grid-auto-columns: 1fr; width: 100%; }
  .nav-list a { flex-direction: column; gap: 0; min-height: 56px; justify-content: center; font-size: .7rem; padding: 0 2px; }
  .nav-list a[aria-current="page"] { box-shadow: none; background: var(--accent-soft); }
  .nav-badge { position: absolute; top: 4px; inset-inline-start: calc(50% + 4px); min-width: 18px; height: 18px; font-size: .66rem; }
  .topbar { flex-wrap: wrap; padding: .7rem 1rem; gap: .6rem; }
  .top-search { order: 3; width: 100%; }
  .view { padding: 1rem 1rem 2rem; }
  .grid-charts { grid-template-columns: minmax(0, 1fr); }
  .set-grid { grid-template-columns: minmax(0, 1fr); }
  .set-nav { position: static; display: flex; overflow-x: auto; }
  .form-grid { grid-template-columns: minmax(0, 1fr); }
  .alert-item { grid-template-columns: 34px minmax(0, 1fr); }
  .alert-btns { grid-column: 2; grid-row: auto; flex-direction: row; flex-wrap: wrap; margin-top: .4rem; }
  .audit-list li { grid-template-columns: minmax(0, 1fr); gap: 0; }
  .chat { height: calc(100dvh - 230px); }
}
@media (max-width: 700px) {
  table.data.resp { min-width: 0; }
  table.data.resp thead { display: none; }
  table.data.resp tr { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .35rem 1rem; padding: .9rem 1rem; border-bottom: 1px solid var(--line); }
  table.data.resp td { display: flex; align-items: center; justify-content: space-between; gap: .5rem; padding: 0; border: 0; text-align: start; white-space: normal; }
  table.data.resp td.cell-name { grid-column: 1 / -1; display: block; margin-bottom: .2rem; }
  table.data.resp td[data-l]::before { content: attr(data-l); font-size: .74rem; color: var(--ink-3); }
  table.data.resp td[data-l="اعلان‌ها"], table.data.resp td[data-l="ریسک"] { grid-column: span 1; }
  table.data.resp .mini { min-width: 70px; text-align: end; }
  .top-search kbd { display: none; }
}
@media (max-width: 560px) {
  .kpis { grid-template-columns: minmax(0, 1fr); }
  .kpi + .kpi { border-inline-start: 0; border-top: 1px solid var(--line); }
  .kpi-val { font-size: 1.6rem; }
  .hbar { grid-template-columns: 6.5rem minmax(0, 1fr) 3.4rem; gap: .5rem; }
  .act-list li { grid-template-columns: minmax(0, 1fr); }
  .act-side { grid-row: auto; grid-column: 1; justify-items: start; grid-auto-flow: column; justify-content: start; gap: .6rem; }
  .filters input[type="search"] { width: 100%; }
  .dr-head, .dr-body { padding-inline: 1rem; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
@media print {
  .nav, .topbar, .alert-btns, .btn { display: none !important; }
  .app { display: block; } .view { padding: 0; }
}
