@font-face { font-family: Vazirmatn; src: url(fonts/Vazirmatn-Regular.ttf) format('truetype'); font-weight: 400; font-display: swap; }
@font-face { font-family: Vazirmatn; src: url(fonts/Vazirmatn-Bold.ttf) format('truetype'); font-weight: 700; font-display: swap; }
:root {
  color-scheme: light;
  --bg: #F2F4F3; --surface: #FFFFFF; --ink: #16231F; --muted: #5B6B66; --line: #D9E0DD;
  --accent: #1B6B52; --accent-soft: #E3EFEA; --attn: #B4441B; --attn-soft: #F8E7DF; --ok: #1B6B52;
  --bubble-in: #EEF1F0; --bubble-out: #DDEDE6;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #121816; --surface: #1A2320; --ink: #E6EEEA; --muted: #94A6A0; --line: #2A3632;
    --accent: #4FB38E; --accent-soft: #1F3A30; --attn: #F08A5D; --attn-soft: #3A2419; --ok: #4FB38E;
    --bubble-in: #222C29; --bubble-out: #1F3A30;
  }
}
* { box-sizing: border-box; }
html { font-size: 15px; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: Vazirmatn, Tahoma, sans-serif; line-height: 1.75; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* سربرگ */
header { background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.bar { max-width: 1180px; margin: 0 auto; padding: 12px 20px 0; display: flex; flex-wrap: wrap; align-items: center; gap: 8px 20px; }
.brand { font-weight: 700; font-size: 1.07rem; margin-inline-end: auto; }
#killSwitch { padding: 4px 12px; font-size: .87rem; }
.brand small { font-weight: 400; color: var(--muted); margin-inline-start: 6px; }
.health { display: flex; gap: 14px; font-size: .87rem; color: var(--muted); flex-wrap: wrap; }
.health span::before { content: ''; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--attn); margin-inline-end: 6px; vertical-align: middle; }
.health span.on::before { background: var(--ok); }
nav { max-width: 1180px; margin: 0 auto; padding: 0 12px; display: flex; overflow-x: auto; }
nav button { background: none; border: 0; border-bottom: 3px solid transparent; padding: 10px 12px 9px; cursor: pointer; color: var(--muted); white-space: nowrap; }
nav button[aria-current="page"] { color: var(--ink); border-color: var(--accent); font-weight: 700; }
nav b { background: var(--attn); color: #fff; border-radius: 10px; padding: 0 7px; font-size: .8rem; margin-inline-start: 4px; }

main { max-width: 1180px; margin: 0 auto; padding: 24px 20px 80px; }
h1 { font-size: 2.2rem; line-height: 1.35; margin: 0 0 6px; letter-spacing: -0.01em; }
h2 { font-size: 1.2rem; margin: 34px 0 12px; }
h3 { font-size: 1rem; margin: 0 0 6px; }
.lead { color: var(--muted); margin: 0 0 22px; max-width: 70ch; }
.muted { color: var(--muted); }
.small { font-size: .87rem; }

/* قیف فروش: مراحل پشت‌سرهم */
.funnel { display: grid; grid-template-columns: repeat(5, 1fr); border: 1px solid var(--line); background: var(--surface); border-radius: 10px; overflow: hidden; }
.funnel div { padding: 12px 14px; border-inline-start: 1px solid var(--line); position: relative; }
.funnel div:first-child { border-inline-start: 0; }
.funnel b { display: block; font-size: 1.55rem; line-height: 1.2; }
.funnel span { font-size: .85rem; color: var(--muted); }
.funnel .end b { color: var(--accent); }
@media (max-width: 760px) { .funnel div { padding: 10px 8px; } .funnel b { font-size: 1.25rem; } .funnel span { font-size: .75rem; } }

/* آیتم‌های کاری */
.item { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 16px; margin-bottom: 12px; }
.item.attn { border-inline-start: 4px solid var(--attn); }
.item-head { display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: baseline; margin-bottom: 8px; }
.item-head h3 { margin: 0; }
.tag { font-size: .8rem; padding: 1px 8px; border-radius: 6px; background: var(--accent-soft); color: var(--accent); }
.tag.attn { background: var(--attn-soft); color: var(--attn); }
.quote { background: var(--bubble-in); border-radius: 8px; padding: 8px 12px; margin: 0 0 10px; white-space: pre-wrap; }
.reason { color: var(--attn); font-size: .9rem; margin: 0 0 8px; }
textarea, input[type=text], input[type=password], input[type=number], input[type=search], select {
  width: 100%; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px;
}
textarea { min-height: 110px; resize: vertical; line-height: 1.8; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; align-items: center; }
.btn { border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 6px 14px; cursor: pointer; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 700; }
@media (prefers-color-scheme: dark) { .btn.primary { color: #0D1512; } }
.btn.danger { color: var(--attn); }
.btn:disabled { opacity: .5; cursor: wait; }
.products { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 0; padding: 0; list-style: none; font-size: .87rem; }
.products li { border: 1px solid var(--line); border-radius: 6px; padding: 2px 8px; }
.empty { color: var(--muted); padding: 18px 0; }

/* جدول‌ها */
table { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; font-size: .93rem; }
th, td { text-align: start; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 400; font-size: .85rem; }
tr:last-child td { border-bottom: 0; }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.nostock { color: var(--attn); }
.okc { color: var(--ok); }
.paused { background: var(--attn); color: #fff; text-align: center; padding: 8px 16px; font-weight: 700; }
.tablewrap { overflow-x: auto; }

/* گفتگوها */
.split { display: grid; grid-template-columns: 320px 1fr; gap: 16px; align-items: start; }
@media (max-width: 860px) { .split { grid-template-columns: 1fr; } }
.convlist { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; max-height: 75vh; overflow-y: auto; }
.convlist button { display: block; width: 100%; text-align: start; background: none; border: 0; border-bottom: 1px solid var(--line); padding: 10px 14px; cursor: pointer; }
.convlist button[aria-current="true"] { background: var(--accent-soft); }
.convlist .snippet { display: block; color: var(--muted); font-size: .85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thread { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 16px; }
.msgs { display: flex; flex-direction: column; gap: 8px; max-height: 50vh; overflow-y: auto; padding: 4px; margin-bottom: 12px; }
.msg { max-width: 78%; padding: 8px 12px; border-radius: 10px; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.in { background: var(--bubble-in); align-self: flex-start; }
.msg.out { background: var(--bubble-out); align-self: flex-end; }
.msg small { display: block; color: var(--muted); font-size: .78rem; margin-top: 2px; }

/* فرم‌ها */
.form { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 16px; display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px 16px; }
.form .full { grid-column: 1 / -1; }
@media (max-width: 640px) { .form { grid-template-columns: 1fr; } }
label { display: block; font-size: .9rem; }
label > span { display: block; color: var(--muted); margin-bottom: 4px; }
.check { display: flex; gap: 8px; align-items: center; }
.check input { width: 18px; height: 18px; }
.filters { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.filters button[aria-pressed="true"] { background: var(--ink); color: var(--surface); border-color: var(--ink); }
.code { direction: ltr; text-align: left; font-family: Consolas, monospace; font-size: .87rem; background: var(--bg); padding: 6px 10px; border-radius: 6px; word-break: break-all; }

/* ورود */
.login { max-width: 360px; margin: 14vh auto; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 28px; }
.login h1 { font-size: 1.4rem; }
#toast { position: fixed; inset-inline: 0; bottom: 18px; margin: auto; width: fit-content; max-width: 92vw; background: var(--ink); color: var(--surface); padding: 10px 18px; border-radius: 8px; opacity: 0; transform: translateY(10px); transition: .2s; pointer-events: none; }
#toast.show { opacity: 1; transform: none; }
#toast.err { background: var(--attn); color: #fff; }
@media (prefers-reduced-motion: reduce) { #toast { transition: none; } }
.scores { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 6px 0 8px; }
.scores div { background: var(--bg); border-radius: 8px; padding: 6px 10px; }
.scores b { display: block; font-size: 1.05rem; }
.scores span { font-size: .8rem; color: var(--muted); }
@media (max-width: 640px) { .scores { grid-template-columns: repeat(2, 1fr); } }
.stagesel { width: auto; padding: 2px 8px; font-size: .87rem; }
.linkbtn { background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; text-decoration: underline; font: inherit; }
.tag.linkbtn { text-decoration: none; padding: 1px 8px; background: var(--accent-soft); }

/* دستیار سایت */
.funnel.kg { grid-template-columns: repeat(5, 1fr); }
@media (max-width: 760px) { .funnel.kg { grid-template-columns: repeat(2, 1fr); } .funnel.kg div { border-top: 1px solid var(--line); } }
.dbar { height: 10px; border-radius: 5px; background: var(--accent); min-width: 2px; }
.msg .meta { display: block; margin-top: 6px; padding-top: 6px; border-top: 1px dashed var(--line); font-size: .82rem; color: var(--muted); }
.msg.r-system { align-self: center; background: transparent; border: 1px dashed var(--line); color: var(--muted); font-size: .88rem; }
.msg.r-operator { background: var(--accent-soft); }
.filters input[type=search] { width: auto; }
details summary { cursor: pointer; }
