@font-face { font-family: "Vazirmatn"; src: url("/fonts/vazirmatn-arabic.woff2") format("woff2"); font-weight: 100 900; font-display: swap; }
@font-face { font-family: "Vazirmatn"; src: url("/fonts/vazirmatn-latin.woff2") format("woff2"); font-weight: 100 900; font-display: swap; unicode-range: U+0000-00FF; }
:root {
  --bg: #f4f6fa; --paper: #fff; --ink: #1b2130; --soft: #5d6678; --mute: #98a0b0; --line: #e4e8ef; --line2: #eef1f6;
  --acc: #3a5bd9; --acc-2: #2c47b5; --acc-50: #eef2ff; --side: #141a2a; --side-2: #1d2539; --side-ink: #c8cfdd;
  --ok: #2e8b57; --warn: #b7791f; --bad: #b42318;
  --radius: 14px; --shadow: 0 10px 30px -14px rgba(20, 26, 42, 0.25);
}
* { box-sizing: border-box; }
body { margin: 0; font-family: "Vazirmatn", Tahoma, sans-serif; background: var(--bg); color: var(--ink); line-height: 1.8; font-size: 15px; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
h1 { font-size: 1.45rem; margin: 0; line-height: 1.5; }
h2 { font-size: 1.1rem; margin: 0 0 10px; }
h3 { font-size: 0.98rem; margin: 0 0 10px; }
code, .mono { font-family: ui-monospace, Consolas, monospace; font-size: 0.86em; direction: ltr; unicode-bidi: isolate; }
.muted { color: var(--soft); margin: 0; font-size: 0.9rem; }
.tiny { font-size: 0.8rem; color: var(--mute); }
[hidden] { display: none !important; }
a { color: var(--acc); }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 42px; padding: 7px 16px; border-radius: 11px; font-weight: 700; transition: background 0.2s, border-color 0.2s, transform 0.1s; white-space: nowrap; text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn-pri { background: var(--acc); color: #fff; box-shadow: 0 8px 18px -10px rgba(58, 91, 217, 0.9); }
.btn-pri:hover { background: var(--acc-2); }
.btn-line { border: 1px solid var(--line); background: var(--paper); color: var(--ink); }
.btn-line:hover { border-color: var(--acc); }
.btn-danger { color: var(--bad); border: 1px solid #f3d0cc; background: #fff; }
.btn-sm { min-height: 34px; padding: 4px 12px; font-size: 0.86rem; border-radius: 9px; }
.btn:disabled { opacity: 0.55; cursor: default; }

/* login */
.login-body { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: radial-gradient(80% 60% at 80% 0%, rgba(58, 91, 217, 0.35), transparent 60%), var(--side); }
.login-card { width: min(400px, 100%); background: var(--paper); border-radius: 22px; padding: 34px 28px; text-align: center; box-shadow: 0 40px 80px -30px rgba(0, 0, 0, 0.6); }
.login-mark { width: 54px; height: 54px; color: var(--acc); margin: 0 auto 8px; display: block; }
.login-card form { margin-top: 22px; display: grid; gap: 10px; text-align: right; }
.login-card label { font-weight: 700; font-size: 0.9rem; }
.login-card input { min-height: 48px; border-radius: 11px; border: 1px solid var(--line); padding: 0 14px; direction: ltr; text-align: left; outline: none; }
.login-card input:focus { border-color: var(--acc); box-shadow: 0 0 0 4px rgba(58, 91, 217, 0.14); }
.form-error { color: var(--bad); min-height: 1.6em; margin: 0; font-size: 0.9rem; }

/* layout */
.app { display: grid; grid-template-columns: 252px 1fr; min-height: 100vh; }
.side { background: var(--side); color: var(--side-ink); padding: 18px 12px; display: flex; flex-direction: column; gap: 16px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: flex; align-items: center; gap: 10px; padding: 0 6px; }
.brand svg { width: 36px; height: 36px; color: #8ea6ff; }
.brand b { display: block; color: #fff; font-size: 1.05rem; line-height: 1.3; }
.brand small { color: #8c95aa; font-size: 0.78rem; }
.site-pick { display: grid; gap: 6px; padding: 10px; background: var(--side-2); border-radius: 12px; }
.site-pick label { font-size: 0.75rem; color: #8c95aa; }
.site-pick select { width: 100%; min-height: 40px; border-radius: 9px; border: 1px solid #2c3550; background: #10162a; color: #fff; padding: 0 10px; }
.site-pick .role { font-size: 0.75rem; color: #8ea6ff; }
.nav { display: grid; gap: 2px; }
.nav-sep { font-size: 0.72rem; color: #6f7890; padding: 10px 10px 2px; }
.nav-btn { display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 11px; border-radius: 10px; color: var(--side-ink); text-decoration: none; font-weight: 600; font-size: 0.93rem; text-align: right; transition: background 0.2s, color 0.2s; }
.nav-btn:hover { background: rgba(255, 255, 255, 0.06); color: #fff; }
.nav-btn.is-active { background: rgba(142, 166, 255, 0.16); color: #fff; }
.nav-btn svg { width: 19px; height: 19px; }
.nav-badge { margin-right: auto; background: var(--acc); color: #fff; border-radius: 999px; font-size: 0.72rem; padding: 0 8px; font-weight: 800; }
.side-foot { margin-top: auto; display: grid; gap: 2px; }
.me { font-size: 0.82rem; color: #8c95aa; padding: 4px 11px 8px; line-height: 1.6; }
.me b { color: #fff; display: block; }
.main { padding: 26px clamp(16px, 3vw, 36px) 60px; min-width: 0; }
.top { display: flex; justify-content: space-between; align-items: center; gap: 14px; flex-wrap: wrap; margin-bottom: 20px; }
.top .acts { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.card { background: var(--paper); border-radius: var(--radius); padding: 18px 20px; box-shadow: 0 1px 3px rgba(20, 26, 42, 0.05); border: 1px solid var(--line2); }
.card + .card { margin-top: 14px; }
.empty { text-align: center; color: var(--soft); padding: 46px 10px; }
.warn { background: #fff8e6; border: 1px solid #f5dfa8; color: #7a5410; border-radius: 12px; padding: 10px 14px; font-size: 0.9rem; margin-bottom: 14px; }

/* stats */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 18px; }
.stat { background: var(--paper); border-radius: var(--radius); padding: 14px 16px; border: 1px solid var(--line2); }
.stat b { display: block; font-size: 1.6rem; line-height: 1.3; }
.stat span { color: var(--soft); font-size: 0.84rem; }

/* filters */
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; align-items: center; }
.search { flex: 1 1 240px; display: flex; align-items: center; gap: 8px; background: var(--paper); border: 1px solid var(--line); border-radius: 11px; padding: 0 12px; min-height: 42px; }
.search.small { flex: 0 1 260px; }
.search svg { color: var(--mute); width: 18px; }
.search input { border: 0; outline: 0; width: 100%; background: transparent; }
.filters select, .seg { min-height: 42px; border-radius: 11px; border: 1px solid var(--line); background: var(--paper); padding: 0 10px; }
.seg { display: inline-flex; padding: 3px; gap: 2px; align-items: center; }
.seg button { padding: 5px 12px; border-radius: 8px; font-weight: 700; font-size: 0.86rem; color: var(--soft); display: inline-flex; gap: 6px; align-items: center; }
.seg button svg { width: 16px; height: 16px; }
.seg button.is-on { background: var(--acc-50); color: var(--acc); }

/* kanban */
.board { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(168px, 1fr); gap: 12px; overflow-x: auto; padding-bottom: 10px; align-items: start; }
.col { background: #eaeef5; border-radius: 14px; padding: 10px; min-height: 160px; transition: background 0.2s, box-shadow 0.2s; }
.col.is-over { background: #dfe6f7; box-shadow: inset 0 0 0 2px var(--c); }
.col-head { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 0.9rem; padding: 2px 4px 10px; }
.col-head i { width: 10px; height: 10px; border-radius: 50%; background: var(--c); }
.col-head small { margin-right: auto; color: var(--soft); font-weight: 700; background: #fff; border-radius: 999px; padding: 0 8px; }
.col-list { display: grid; gap: 8px; }
.kcard { touch-action: none; user-select: none; background: var(--paper); border-radius: 11px; padding: 10px 12px; border: 1px solid var(--line2); box-shadow: 0 1px 2px rgba(20, 26, 42, 0.06); cursor: grab; text-align: right; width: 100%; display: block; transition: box-shadow 0.2s, border-color 0.2s; }
.kcard:hover { border-color: #c9d3ea; box-shadow: var(--shadow); }
.kcard.is-drag { opacity: 0.45; }
.kcard b { display: block; font-size: 0.95rem; }
.kcard .phone { direction: ltr; text-align: right; font-size: 0.85rem; color: var(--soft); }
.kcard p { margin: 4px 0 0; font-size: 0.82rem; color: var(--soft); line-height: 1.6; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.kcard .meta { display: flex; justify-content: space-between; gap: 6px; margin-top: 6px; font-size: 0.75rem; color: var(--mute); }

/* list */
.list { display: grid; gap: 8px; }
.lead { display: grid; grid-template-columns: 1.3fr 1fr 1.2fr 0.9fr auto; gap: 12px; align-items: center; background: var(--paper); border-radius: 12px; padding: 12px 16px; border: 1px solid var(--line2); text-align: right; width: 100%; transition: border-color 0.2s; }
.lead:hover { border-color: #c9d3ea; }
.lead b { display: block; }
.lead small { color: var(--soft); font-size: 0.8rem; display: block; line-height: 1.6; }
.lead .phone { direction: ltr; text-align: right; font-weight: 700; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 11px; border-radius: 999px; font-size: 0.78rem; font-weight: 700; color: var(--c); background: color-mix(in srgb, var(--c) 12%, white); white-space: nowrap; }
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--c); }
.src { display: inline-flex; gap: 4px; align-items: center; font-size: 0.76rem; color: var(--soft); }
.src svg { width: 14px; height: 14px; }

/* drawer */
.scrim { position: fixed; inset: 0; background: rgba(20, 26, 42, 0.45); z-index: 20; }
.drawer { position: fixed; top: 0; bottom: 0; left: 0; width: min(520px, 100vw); background: var(--bg); z-index: 21; overflow-y: auto; transform: translateX(-105%); transition: transform 0.35s cubic-bezier(0.22, 1, 0.36, 1); box-shadow: 30px 0 80px -30px rgba(0, 0, 0, 0.5); }
.drawer.is-open { transform: none; }
.d-head { background: var(--side); color: #fff; padding: 20px 22px 22px; position: sticky; top: 0; z-index: 2; }
.d-head h2 { margin: 4px 0 0; font-size: 1.3rem; }
.d-head .phone-big { direction: ltr; text-align: right; font-size: 1.1rem; color: #b8c6ff; font-weight: 700; }
.d-close { position: absolute; top: 12px; left: 12px; width: 38px; height: 38px; border-radius: 10px; color: #fff; display: grid; place-items: center; background: rgba(255, 255, 255, 0.08); }
.d-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.d-actions .btn-line { background: rgba(255, 255, 255, 0.08); border-color: rgba(255, 255, 255, 0.15); color: #fff; }
.d-body { padding: 18px 22px 40px; display: grid; gap: 14px; }
.d-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 16px; }
.d-grid small { display: block; color: var(--mute); font-size: 0.76rem; }
.d-grid span { font-weight: 600; white-space: pre-wrap; overflow-wrap: anywhere; }
.d-grid .wide { grid-column: 1 / -1; }
.status-set { display: grid; grid-template-columns: repeat(auto-fit, minmax(118px, 1fr)); gap: 8px; }
.status-set button { border: 1px solid var(--line); border-radius: 11px; padding: 8px 10px; font-weight: 700; font-size: 0.86rem; background: #fff; display: flex; align-items: center; gap: 6px; justify-content: center; }
.status-set button::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--c); }
.status-set button.is-active { background: var(--c); color: #fff; border-color: var(--c); }
.status-set button.is-active::before { background: #fff; }
.timeline { list-style: none; margin: 0; padding: 0; display: grid; gap: 9px; }
.timeline li { border-right: 2px solid var(--acc-50); padding: 1px 12px 1px 0; white-space: pre-wrap; }
.timeline li.sys { color: var(--soft); font-size: 0.85rem; }
.timeline time { display: block; font-size: 0.74rem; color: var(--mute); }
.note-form { display: grid; gap: 8px; margin-top: 12px; }
.note-form textarea, .f textarea, .f input, .f select { border-radius: 10px; border: 1px solid var(--line); padding: 8px 12px; outline: none; background: #fff; width: 100%; }
.note-form textarea { min-height: 76px; resize: vertical; }
.f textarea:focus, .f input:focus, .f select:focus, .note-form textarea:focus { border-color: var(--acc); box-shadow: 0 0 0 3px rgba(58, 91, 217, 0.12); }

/* chats */
.chats { display: grid; grid-template-columns: 340px 1fr; gap: 14px; min-height: 60vh; }
.chat-list { display: grid; gap: 6px; align-content: start; max-height: 75vh; overflow-y: auto; }
.chat-item { text-align: right; background: var(--paper); border: 1px solid var(--line2); border-radius: 12px; padding: 10px 12px; width: 100%; }
.chat-item.is-active { border-color: var(--acc); box-shadow: 0 0 0 3px var(--acc-50); }
.chat-item p { margin: 0; font-size: 0.88rem; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.chat-item small { color: var(--mute); font-size: 0.76rem; display: flex; justify-content: space-between; gap: 8px; }
.chat-view { background: var(--paper); border-radius: var(--radius); border: 1px solid var(--line2); padding: 16px; max-height: 75vh; overflow-y: auto; }
.bubble { max-width: 82%; padding: 8px 12px; border-radius: 14px; margin: 6px 0; white-space: pre-wrap; font-size: 0.92rem; }
.bubble.user { background: var(--acc); color: #fff; margin-left: auto; border-bottom-left-radius: 4px; }
.bubble.assistant { background: #f0f2f7; margin-right: auto; border-bottom-right-radius: 4px; }
.bubble time { display: block; font-size: 0.7rem; opacity: 0.7; }
.summary { background: var(--acc-50); border-radius: 12px; padding: 10px 14px; font-size: 0.88rem; margin-bottom: 10px; white-space: pre-wrap; }

/* forms / settings */
.tabs { display: flex; gap: 4px; flex-wrap: wrap; border-bottom: 1px solid var(--line); margin-bottom: 16px; }
.tabs button { padding: 9px 14px; font-weight: 700; color: var(--soft); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs button.is-on { color: var(--acc); border-color: var(--acc); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px 16px; }
.f { display: grid; gap: 4px; align-content: start; }
.f > span { font-weight: 700; font-size: 0.88rem; }
.f > small { color: var(--mute); font-size: 0.78rem; line-height: 1.6; }
.f textarea { min-height: 90px; resize: vertical; line-height: 1.8; }
.f input[type=color] { padding: 2px; height: 42px; width: 64px; }
.f input, .f select { min-height: 42px; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 0.9rem; }
.check input { width: 18px; height: 18px; accent-color: var(--acc); }
.settings { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 18px; align-items: start; }
.preview-wrap { position: sticky; top: 16px; }
.preview { width: 100%; height: 700px; border: 1px solid var(--line); border-radius: 16px; background: repeating-linear-gradient(45deg, #f6f7fb, #f6f7fb 12px, #eef1f7 12px, #eef1f7 24px); }
.save-bar { position: sticky; bottom: 0; background: linear-gradient(transparent, var(--bg) 30%); padding: 18px 0 6px; display: flex; gap: 10px; align-items: center; z-index: 3; }
.presets { display: flex; gap: 8px; flex-wrap: wrap; }
.preset { display: inline-flex; align-items: center; gap: 8px; border: 1px solid var(--line); border-radius: 999px; padding: 5px 12px 5px 6px; background: #fff; font-weight: 600; font-size: 0.86rem; }
.preset i { width: 22px; height: 22px; border-radius: 50%; background: var(--c); box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.5); }
.preset.is-dark i { box-shadow: 0 0 0 3px #1c1d22; }
.rows { display: grid; gap: 8px; }
.rowx { display: grid; gap: 8px; align-items: center; background: #f8f9fc; border: 1px solid var(--line2); border-radius: 12px; padding: 8px; }
.rowx.field { grid-template-columns: 110px 1fr 110px 1fr auto auto; }
.rowx.stage { grid-template-columns: 110px 1fr 54px 120px auto; }
.rowx input, .rowx select { min-height: 38px; border-radius: 9px; border: 1px solid var(--line); padding: 0 10px; background: #fff; width: 100%; }
.rowx input[type=color] { padding: 2px; }
.icon-btn { width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center; color: var(--soft); }
.icon-btn:hover { background: #fff; color: var(--bad); }
.code { background: #0f1424; color: #d5ddff; border-radius: 12px; padding: 14px 16px; direction: ltr; text-align: left; font-family: ui-monospace, Consolas, monospace; font-size: 0.85rem; white-space: pre-wrap; word-break: break-all; position: relative; }
.copy { position: absolute; top: 8px; right: 8px; }
.kbadge { display: inline-block; font-size: 0.74rem; font-weight: 700; border-radius: 999px; padding: 1px 9px; }
.kbadge.ok { background: #e6f4ec; color: var(--ok); }
.kbadge.no { background: #fdf0e1; color: var(--warn); }
.prov-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.prov { display: grid; gap: 2px; border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; cursor: pointer; background: #fff; }
.prov.is-on { border-color: var(--acc); box-shadow: 0 0 0 3px var(--acc-50); }
.prov input { display: none; }
.prov small { color: var(--soft); font-size: 0.8rem; }

/* knowledge base */
.kb { display: grid; grid-template-columns: 280px 1fr; gap: 14px; align-items: start; }
.doc-list { display: grid; gap: 6px; }
.doc { text-align: right; width: 100%; background: var(--paper); border: 1px solid var(--line2); border-radius: 11px; padding: 9px 12px; }
.doc.is-active { border-color: var(--acc); box-shadow: 0 0 0 3px var(--acc-50); }
.doc b { display: block; font-size: 0.92rem; }
.doc small { color: var(--mute); font-size: 0.76rem; }
.kb-text { width: 100%; min-height: 56vh; border-radius: 12px; border: 1px solid var(--line); padding: 14px; font-family: "Vazirmatn", Tahoma, sans-serif; font-size: 0.93rem; line-height: 2; resize: vertical; outline: none; }
.kb-text:focus { border-color: var(--acc); }
.hit { border-right: 3px solid var(--acc); padding: 4px 12px; margin: 8px 0; font-size: 0.86rem; white-space: pre-wrap; }
.hit b { display: block; }

/* tables */
.tbl { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.tbl th, .tbl td { text-align: right; padding: 10px 8px; border-bottom: 1px solid var(--line2); vertical-align: top; }
.tbl th { font-size: 0.8rem; color: var(--soft); font-weight: 700; }
.access { display: flex; gap: 6px; flex-wrap: wrap; }
.access span { font-size: 0.78rem; background: var(--acc-50); color: var(--acc); padding: 0 8px; border-radius: 999px; }

.toast { position: fixed; bottom: 22px; left: 50%; transform: translate(-50%, 20px); background: var(--side); color: #fff; padding: 10px 18px; border-radius: 12px; opacity: 0; pointer-events: none; transition: opacity 0.25s, transform 0.25s; z-index: 50; max-width: 90vw; }
.toast.is-on { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 1180px) { .settings { grid-template-columns: 1fr; } .preview-wrap { position: static; } .preview { height: 620px; } }
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .side { position: static; height: auto; }
  .stats { grid-template-columns: 1fr 1fr; }
  .lead { grid-template-columns: 1fr 1fr; }
  .chats, .kb, .grid2, .grid3, .prov-grid { grid-template-columns: 1fr; }
  .rowx.field, .rowx.stage { grid-template-columns: 1fr 1fr; }
}
.tbl .icon-btn { display: inline-grid; vertical-align: middle; }
