@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 {
  --navy: #141B3D; --navy-2: #1E2752;
  --gold: #C9A45C; --gold-soft: #F1D79C; --gold-ink: #7A5C22; --gold-bg: #FBF5E8; --gold-line: #E5CF9F;
  --purple: #6D5BD0; --purple-2: #8E7CE0; --purple-3: #B3A7EC; --purple-4: #D5CEF5; --purple-bg: #F1EEFC; --purple-ink: #3F3391;
  --cream: #F6F1E7; --cream-2: #EFE7D6; --cream-3: #FBF8F2; --line: #E6DDCB;
  --ink: #1A1F36; --muted: #5E6278; --on-navy: #EDE6D6; --on-navy-muted: #B9B3CC;
  --ok: #2F7A4F; --bad: #A3352B;
  --radius: 6px;
  --surface: #fff; --halo: #fff;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: "Vazirmatn", Tahoma, sans-serif; background: var(--cream); color: var(--ink); line-height: 1.8; -webkit-font-smoothing: antialiased; }
a { color: #4B3FA0; } a:hover { color: #2E2670; }
button, input, textarea, select { font-family: inherit; font-size: 15px; color: inherit; }
h1, h2, h3 { color: var(--navy); margin: 0; line-height: 1.5; }
h1 { font-size: 30px; } h2 { font-size: 18px; } h3 { font-size: 15px; }
p { margin: 0; }
.muted { color: var(--muted); } .small { font-size: 13px; } .ltr { direction: ltr; unicode-bidi: embed; }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- layout ---------- */
.shell { min-height: 100vh; display: flex; flex-wrap: nowrap; align-items: stretch; }
.side { flex: 1 1 240px; min-width: 215px; max-width: 290px; background: var(--navy); color: var(--on-navy); padding: 28px 18px; display: flex; flex-direction: column; gap: 28px; }
.main { flex: 999 1 560px; min-width: 0; padding: 36px 44px 56px; }
.wrap { max-width: 1120px; margin: 0 auto; display: flex; flex-direction: column; gap: 24px; }
.brand { display: flex; align-items: center; gap: 12px; padding: 0 8px; }
.brand-mark { width: 40px; height: 40px; border-radius: 6px; background: var(--gold); color: var(--navy); display: grid; place-items: center; flex: none; }
.brand b { display: block; font-size: 18px; } .brand span { font-size: 12px; color: var(--on-navy-muted); }
.nav { display: flex; flex-direction: column; gap: 4px; }
.nav a { display: flex; align-items: center; gap: 12px; padding: 11px 14px; border-radius: 6px; color: var(--on-navy-muted); text-decoration: none; font-size: 15px; }
.nav a:hover { background: rgba(255,255,255,.05); color: var(--on-navy); }
.nav a.active { background: rgba(201,164,92,.14); color: var(--gold-soft); font-weight: 700; }
.side-foot { margin-top: auto; display: flex; flex-direction: column; gap: 12px; }
.credit { border: 1px solid rgba(201,164,92,.35); border-radius: 6px; padding: 14px 16px; }
.credit span { font-size: 12px; color: var(--on-navy-muted); display: block; }
.credit b { font-size: 19px; color: var(--gold-soft); }
.me { display: flex; align-items: center; gap: 10px; padding: 6px 8px; }
.avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--purple); color: #fff; display: grid; place-items: center; font-weight: 700; flex: none; }
.me b { font-size: 14px; display: block; } .me span { font-size: 12px; color: var(--on-navy-muted); }
.linkbtn { background: none; border: none; color: var(--on-navy-muted); cursor: pointer; padding: 6px 8px; text-align: right; font-size: 13px; }
.linkbtn:hover { color: var(--gold-soft); }
.bare { flex: 999 1 560px; min-width: 0; display: flex; }
.mtop, .mtabs, .sheet-head, .panel-btn { display: none; }
.only-m { display: none !important; }

/* ---------- surfaces ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 24px 26px; display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.card.dark { background: var(--navy); color: var(--on-navy); border: none; }
.card.dark h2, .card.dark h3 { color: var(--on-navy); }
.grid { display: grid; gap: 20px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 300px), 1fr)); }
.grid.three { grid-template-columns: repeat(auto-fit, minmax(min(100%, 230px), 1fr)); }
.row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.between { justify-content: space-between; }
.stat b { font-size: 28px; color: var(--navy); display: block; line-height: 1.4; }
.stat span { font-size: 14px; color: var(--muted); }
.pill { display: inline-block; font-size: 13px; padding: 4px 12px; border-radius: 4px; background: var(--purple-bg); color: var(--purple-ink); }
.pill.gold { background: var(--gold-bg); color: var(--gold-ink); border: 1px solid var(--gold-line); }
.pill.navy { background: var(--navy); color: var(--gold-soft); }
.pill.ok { background: #E6F2EA; color: var(--ok); } .pill.bad { background: #F8E7E5; color: var(--bad); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.bar { height: 8px; border-radius: 999px; background: var(--cream-2); overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 999px; background: var(--purple); }

/* ---------- buttons & forms ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 46px; padding: 0 22px; border-radius: 6px; border: 1px solid transparent; font-weight: 700; cursor: pointer; text-decoration: none; font-size: 15px; }
.btn.primary { background: var(--navy); color: var(--gold-soft); }
.btn.primary:hover { background: var(--navy-2); color: var(--gold-soft); }
.btn.gold { background: var(--gold); color: var(--navy); }
.btn.ghost { background: var(--surface); color: var(--navy); border-color: var(--line); }
.btn.danger { background: var(--surface); color: var(--bad); border-color: #E8C6C1; }
.btn.sm { min-height: 36px; padding: 0 14px; font-size: 13px; border-radius: 4px; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 14px; font-weight: 700; color: var(--navy); }
.input, textarea.input, select.input { width: 100%; background: var(--cream-3); border: 1px solid var(--line); border-radius: 6px; padding: 12px 14px; outline: none; }
.input:focus { border-color: var(--purple); box-shadow: 0 0 0 3px rgba(109,91,208,.15); }
textarea.input { resize: vertical; min-height: 110px; line-height: 1.9; }
.form-error { color: var(--bad); font-size: 14px; min-height: 0; }
.form-ok { color: var(--ok); font-size: 14px; }
.choice { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 16px; border-radius: 6px; border: 1.5px solid var(--line); background: var(--cream-3); cursor: pointer; font-weight: 700; }
.choice.on { background: var(--purple); border-color: var(--purple); color: #fff; }

/* ---------- auth ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: var(--cream); }
.auth-card { width: 100%; max-width: 440px; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 34px 32px; display: flex; flex-direction: column; gap: 20px; }
.auth-card .brand { padding: 0; } .auth-card .brand span { color: var(--muted); }
.login-head { display: flex; flex-direction: column; align-items: center; gap: 14px; text-align: center; margin-bottom: 4px; }
.login-alt { align-self: center; color: var(--purple); font-weight: 700; text-decoration: none; padding: 6px 12px; }
.login-alt:hover { color: var(--navy); }
.steps { display: flex; gap: 6px; } .steps i { flex: 1; height: 5px; border-radius: 999px; background: var(--cream-2); } .steps i.on { background: var(--gold); }

/* ---------- journey ---------- */
.journey { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); overflow-x: auto; }
.journey li { display: flex; flex-direction: column; align-items: center; gap: 10px; text-align: center; font-size: 13px; color: var(--on-navy-muted); }
.journey .track { display: flex; align-items: center; width: 100%; }
.journey .track i { flex: 1; height: 2px; background: rgba(237,230,214,.18); }
.journey .track i.on { background: var(--gold); }
.journey .dot { width: 34px; height: 34px; border-radius: 50%; border: 1px solid rgba(237,230,214,.3); display: grid; place-items: center; flex: none; font-size: 14px; }
.journey li.done .dot { background: var(--gold); border-color: var(--gold); color: var(--navy); }
.journey li.done { color: var(--on-navy); }
.journey li.current .dot { border: 2px solid var(--purple-3); box-shadow: 0 0 0 6px rgba(109,91,208,.25); color: #fff; }
.journey li.current { color: #fff; font-weight: 700; }

/* ---------- chat ---------- */
.chat-shell { display: flex; flex-wrap: wrap; gap: 0; flex: 999 1 560px; min-width: 0; min-height: 100vh; }
.chat-col { flex: 999 1 480px; min-width: 0; display: flex; flex-direction: column; height: 100vh; }
.chat-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; padding: 18px 28px; border-bottom: 1px solid var(--line); background: rgba(255,255,255,.6); }
.chat-list { flex: 1; overflow-y: auto; padding: 24px 28px; display: flex; flex-direction: column; gap: 16px; }
.msg { max-width: 80%; padding: 14px 18px; border-radius: 20px; font-size: 15px; line-height: 2; white-space: normal; overflow-wrap: anywhere; }
.msg.user { align-self: flex-start; background: var(--navy); color: #F4EFE4; border-bottom-left-radius: 20px; border-bottom-right-radius: 6px; white-space: pre-wrap; }
.msg.assistant { align-self: flex-end; background: var(--surface); border: 1px solid var(--line); border-bottom-left-radius: 6px; }
.msg.assistant h3 { margin: 10px 0 2px; color: var(--navy); font-size: 15px; }
.msg.assistant ul { margin: 4px 0; padding-right: 20px; }
.msg.error { align-self: center; background: #F8E7E5; color: var(--bad); font-size: 14px; }
.msg.notice { align-self: center; background: var(--gold-bg); border: 1px solid var(--gold-line); color: #4A3712; font-size: 14px; max-width: 90%; }
.typing { align-self: flex-end; display: flex; gap: 6px; padding: 12px 16px; background: var(--surface); border: 1px solid var(--line); border-radius: 999px; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--purple-2); 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; } }
.composer { padding: 14px 28px 22px; }
.composer form { display: flex; align-items: flex-end; gap: 10px; background: var(--surface); border: 1px solid var(--line); border-radius: 20px; padding: 8px; }
.composer textarea { flex: 1; min-width: 0; border: none; outline: none; resize: none; background: transparent; padding: 10px 12px; max-height: 180px; line-height: 1.8; }
.send { width: 48px; height: 48px; border-radius: 14px; border: none; background: var(--navy); color: var(--gold-soft); display: grid; place-items: center; cursor: pointer; flex: none; }
.chat-side { flex: 1 1 300px; min-width: 0; background: var(--surface); border-right: 1px solid var(--line); padding: 24px 22px; display: flex; flex-direction: column; gap: 22px; max-height: 100vh; overflow-y: auto; }
.ring { width: 64px; height: 64px; border-radius: 50%; display: grid; place-items: center; flex: none; }
.ring > span { width: 50px; height: 50px; border-radius: 50%; background: var(--surface); display: grid; place-items: center; font-weight: 700; color: var(--navy); }
.hbars { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 8px; align-items: end; height: 120px; }
.hbars > div { display: flex; flex-direction: column; align-items: center; gap: 4px; height: 100%; justify-content: flex-end; font-size: 11px; color: var(--muted); }
.hbars i { display: block; width: 100%; border-radius: 8px 8px 4px 4px; background: var(--purple-3); min-height: 3px; }
.hbars b { font-size: 12px; color: var(--navy); }

/* ---------- tables, lists ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; min-width: 520px; }
th { font-weight: 400; color: var(--muted); text-align: right; padding: 10px 8px; border-bottom: 1px solid var(--cream-2); }
td { padding: 12px 8px; border-bottom: 1px solid #F4EEE2; vertical-align: top; }
td.num, th.num { text-align: left; direction: ltr; }
.plus { color: var(--ok); font-weight: 700; } .minus { color: var(--bad); font-weight: 700; }
.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.list li { display: flex; flex-direction: column; gap: 2px; padding-bottom: 12px; border-bottom: 1px solid var(--cream-2); }
.list li:last-child { border-bottom: none; padding-bottom: 0; }
.empty { text-align: center; padding: 26px; background: var(--cream-3); border-radius: 6px; color: var(--muted); }
.copybox { display: flex; align-items: center; gap: 8px; background: var(--cream); border: 1px dashed #CFC5B0; border-radius: 6px; padding: 8px; }
.copybox code { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: inherit; font-weight: 700; color: var(--navy); padding: 0 10px; direction: ltr; text-align: left; }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.tabs button { border: 1px solid var(--line); background: var(--surface); border-radius: 6px; padding: 8px 16px; cursor: pointer; font-weight: 700; color: var(--navy); }
.tabs button.on { background: var(--navy); color: var(--gold-soft); border-color: var(--navy); }
.report-body h3 { margin: 22px 0 8px; font-size: 17px; color: var(--navy); border-right: 4px solid var(--purple); padding-right: 10px; }
.report-body p { margin: 0 0 8px; text-align: justify; line-height: 2.05; }
.report-body ul { margin: 0 0 10px; padding-right: 22px; line-height: 2; }
.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: var(--navy); color: var(--gold-soft); padding: 12px 20px; border-radius: 6px; z-index: 50; font-size: 14px; box-shadow: 0 10px 30px rgba(20,27,61,.25); }
.modal-bg { position: fixed; inset: 0; background: rgba(20,27,61,.45); display: grid; place-items: center; padding: 18px; z-index: 40; }
.modal { background: var(--cream); border-radius: 8px; width: 100%; max-width: 900px; max-height: 90vh; overflow-y: auto; padding: 24px; display: flex; flex-direction: column; gap: 16px; }
.modal.wide { max-width: 1200px; }
.prompt-edit { display: grid; grid-template-columns: minmax(0, 1fr) 280px; gap: 16px; align-items: start; }
.prompt-edit .col { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.prompt-edit textarea { min-height: 58vh; resize: vertical; font-size: 14px; line-height: 1.9; }
.prompt-edit textarea.mono.ltr { font-family: ui-monospace, Consolas, monospace; font-size: 13px; text-align: left; }
.prompt-edit textarea[readonly] { background: var(--cream-3); }
.prompt-edit aside { max-height: 58vh; overflow-y: auto; }
@media (max-width: 860px) { .prompt-edit { grid-template-columns: 1fr; } }
/* invite tree */
.tree, .tree ul { list-style: none; margin: 0; padding: 0; }
.tree ul { margin-inline-start: 14px; padding-inline-start: 18px; border-inline-start: 2px solid var(--purple-4); }
.tree li { position: relative; padding: 4px 0; }
.tree ul > li::before { content: ""; position: absolute; inset-inline-start: -18px; top: 22px; width: 14px; border-top: 2px solid var(--purple-4); }
.tree summary { cursor: pointer; list-style-position: outside; }
.tree summary::marker { color: var(--purple); }
.tnode { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 6px; }
.tnode .sep { display: inline-block; width: 1px; height: 14px; background: var(--line); margin: 0 2px; }
.tnode.code { background: var(--gold-bg); border: 1px solid var(--gold-line); }
.tnode.hit { background: var(--purple-bg); outline: 2px solid var(--purple); }
.namebtn { background: none; border: none; padding: 0; color: var(--navy); font-weight: 700; cursor: pointer; font-size: inherit; }
.namebtn:hover { color: var(--purple); text-decoration: underline; }
.pill.navy-soft { background: var(--purple-bg); color: var(--purple-ink); }
/* monitoring & AI */
.grid.four { grid-template-columns: repeat(auto-fit, minmax(min(100%, 210px), 1fr)); }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); }
.meter-bar { height: 8px; background: var(--cream-2); border-radius: 4px; overflow: hidden; margin: 4px 0; }
.meter-bar i { display: block; height: 100%; border-radius: 4px; background: var(--purple); }
.meter-bar i.warn { background: #C98A12; } .meter-bar i.bad { background: var(--bad); }
.lvl.ok { color: var(--ok); } .lvl.warn { color: #8A5D00; } .lvl.bad { color: var(--bad); font-weight: 700; }
.bars { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.bars li { display: grid; grid-template-columns: 120px 1fr 80px; gap: 10px; align-items: center; font-size: 14px; }
.bar-track { height: 10px; background: var(--cream-2); border-radius: 5px; overflow: hidden; }
.bar-track i { display: block; height: 100%; background: var(--purple); border-radius: 0 4px 4px 0; }
.alert-bad { background: #F8E7E5; border-color: #E8B9B3; } .alert-bad h2, .alert-bad li { color: var(--bad); }
.alert-ok { background: #E8F3EC; border-color: #BFDCC9; } .alert-ok h2 { color: var(--ok); }
.err-text { font-size: 12px; color: var(--bad); word-break: break-word; text-align: left; }
.chart-card { gap: 8px; min-width: 0; }
.viz { direction: ltr; display: flex; flex-direction: column; gap: 6px; }
.viz-plot { position: relative; }
.viz-svg { width: 100%; height: auto; display: block; overflow: visible; }
.viz-svg text { font-family: "Vazirmatn", Tahoma, sans-serif; }
.viz-grid { stroke: var(--cream-2); stroke-width: 1; }
.viz-axis { stroke: var(--line); stroke-width: 1; }
.viz-ref { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 4 4; }
.viz-tick { font-size: 11px; fill: var(--muted); }
.viz-hair { stroke: var(--muted); stroke-width: 1; }
.viz-svg rect:focus { outline: none; }
.viz-svg rect:focus-visible { outline: 2px solid var(--purple); }
.viz-tip { position: absolute; top: 4px; direction: rtl; background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 8px 12px; font-size: 13px; box-shadow: 0 6px 20px rgba(20,27,61,.12); pointer-events: none; min-width: 150px; z-index: 2; }
.viz-tip-time { color: var(--muted); font-size: 12px; margin-bottom: 2px; }
.viz-tip-row { display: flex; align-items: center; gap: 6px; }
.viz-tip-row b { color: var(--ink); }
.viz-sw { width: 10px; height: 10px; border-radius: 3px; display: inline-block; flex: none; }
.viz-legend { direction: rtl; display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 13px; color: var(--ink); }
.viz-legend > span { display: inline-flex; align-items: center; gap: 6px; }
.viz-table { direction: rtl; font-size: 13px; }
.viz-table summary { cursor: pointer; color: var(--muted); }
.viz-table .table-wrap { max-height: 260px; overflow: auto; }
.loading { padding: 60px; text-align: center; color: var(--muted); }

/* ---------- print (report → PDF) ---------- */

/* ======================================================================
   PHONES & SMALL TABLETS — app-style layout
   ====================================================================== */
.icon-btn { width: 44px; height: 44px; display: grid; place-items: center; border: none; background: none; color: var(--navy); border-radius: 6px; cursor: pointer; flex: none; text-decoration: none; }
.icon-btn:active { background: var(--cream-2); }
.sheet-bg { position: fixed; inset: 0; z-index: 60; background: rgba(20,27,61,.45); display: flex; align-items: flex-end; justify-content: center; animation: fade .15s ease-out; }
.sheet { width: 100%; max-width: 560px; background: var(--cream); border-radius: 10px 10px 0 0; padding: 10px 18px calc(18px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 10px; animation: up .2s ease-out; max-height: 88vh; overflow-y: auto; }
.sheet-grip { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 2px auto 6px; }
.sheet .me { padding: 4px 4px 10px; border-bottom: 1px solid var(--line); }
.sheet .me span { color: var(--muted); }
.sheet-links { display: flex; flex-direction: column; }
.sheet-links a, .sheet-links button { display: flex; align-items: center; gap: 14px; min-height: 54px; padding: 0 8px; border: none; background: none; border-bottom: 1px solid var(--cream-2); color: var(--navy); text-decoration: none; font-size: 16px; font-weight: 700; cursor: pointer; text-align: right; width: 100%; }
.sheet-links small { margin-right: auto; color: var(--gold-ink); font-weight: 700; font-size: 13px; }
.sheet-links button { color: var(--bad); border-bottom: none; }
@keyframes up { from { transform: translateY(40px); opacity: .4; } to { transform: none; opacity: 1; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.chat-title h1 { font-size: 17px; }

/* ---------- profile header: identity block on the left ---------- */
.profile-hero { flex-direction: row-reverse; flex-wrap: wrap; align-items: center; justify-content: space-between; }
.profile-id { flex-direction: row-reverse; gap: 18px; text-align: left; }
.profile-id .chips { justify-content: flex-end; }

/* ---------- admin back link in the user sidebar ---------- */
.admin-back { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-radius: 6px; border: 1px solid rgba(201,164,92,.45); color: var(--gold-soft); text-decoration: none; font-weight: 700; font-size: 14px; }
.admin-back:hover { background: rgba(201,164,92,.12); }

/* ======================================================================
   ADMIN WORKSPACE — top menu bar, wide content
   ====================================================================== */

/* dashboard: users on the right, everything else in the middle */
.dash { display: grid; grid-template-columns: 330px minmax(0, 1fr); gap: 20px; align-items: start; }
.dash-users { position: sticky; top: 88px; max-height: calc(100vh - 110px); gap: 12px; }
.dash-main { display: flex; flex-direction: column; gap: 20px; min-width: 0; }
.dash-pair { display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(0, 1fr); gap: 20px; align-items: stretch; }
.tree-svg { max-height: 460px; }
.ulist { list-style: none; margin: 0 -10px; padding: 0; overflow-y: auto; flex: 1; min-height: 120px; }
.ulist button { width: 100%; display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 10px; padding: 9px 10px; border: none; background: none; border-radius: 6px; cursor: pointer; text-align: right; font-family: inherit; color: var(--ink); }
.ulist button:hover, .ulist button:focus-visible { background: var(--cream-3); }
.u-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.u-seen { font-size: 12px; color: var(--muted); white-space: nowrap; }
.avatar.sm { width: 32px; height: 32px; font-size: 13px; position: relative; background: var(--purple-4, #CFC6F2); color: var(--purple-ink); }
.avatar.sm.on::after { content: ""; position: absolute; bottom: -1px; left: -1px; width: 10px; height: 10px; border-radius: 50%; background: var(--ok); border: 2px solid var(--surface); }
.ok-text { color: var(--ok); }
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.kpis > * { background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 14px 16px; display: flex; flex-direction: column; gap: 4px; text-decoration: none; color: inherit; min-width: 0; }
.kpis span { font-size: 12.5px; color: var(--muted); }
.kpis b { font-size: 22px; color: var(--navy); line-height: 1.3; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpis .warn { border-color: var(--gold); background: var(--gold-bg); }
.small-kpis > * { background: var(--cream-3); border: none; padding: 10px 12px; }
.small-kpis b { font-size: 17px; }
.ai-model { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 28px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 6px; }
.ai-model > div { display: flex; flex-direction: column; min-width: 0; }
.ai-model b { font-size: 14px; overflow-wrap: anywhere; }
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.dot.ok { background: var(--ok); box-shadow: 0 0 0 4px rgba(46,125,82,.15); } .dot.bad { background: var(--bad); box-shadow: 0 0 0 4px rgba(163,53,43,.15); }
.tag { font-size: 12px; padding: 2px 8px; border-radius: 4px; background: var(--cream-2); color: var(--muted); white-space: nowrap; font-weight: 700; }
.tag.gold { background: var(--gold-bg); color: #6E531B; } .tag.muted { background: none; border: 1px solid var(--line); }
.plist { list-style: none; margin: 0; padding: 0; }
.plist li { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--cream-2); font-size: 14px; }
.plist li:last-child { border-bottom: none; }
.viz-bar { opacity: .9; } .viz-bar:hover { opacity: 1; }
.tree-wrap { overflow-x: auto; direction: ltr; }
.tree-svg { display: block; }
.tree-edge { fill: none; stroke: #D9D1BF; stroke-width: 1.5; }
.tn-root { fill: var(--navy); }
.tn-code { fill: var(--gold); }
.tn-paid { fill: var(--purple); stroke: var(--surface); stroke-width: 2; }
.tn-free { fill: var(--surface); stroke: var(--purple); stroke-width: 2; }
.tn-label { paint-order: stroke; stroke: var(--halo); stroke-width: 4px; stroke-linejoin: round; font-size: 12.5px; fill: var(--ink); font-family: "Vazirmatn", Tahoma, sans-serif; }
.tn-more { font-size: 11px; fill: var(--muted); font-family: "Vazirmatn", Tahoma, sans-serif; }
.tree-node:focus-within .tn-paid, .tree-node:focus-within .tn-free { stroke-width: 3; }
.tree-legend { display: flex; flex-wrap: wrap; gap: 6px 18px; color: var(--muted); }
.tree-legend span { display: inline-flex; align-items: center; gap: 6px; }
.lg { width: 11px; height: 11px; display: inline-block; border-radius: 50%; }
.lg.paid { background: var(--purple); } .lg.free { border: 2px solid var(--purple); } .lg.code { background: var(--gold); border-radius: 2px; }
@media (max-width: 1180px) { .dash-pair { grid-template-columns: 1fr; } }
@media (max-width: 960px) {
  .dash { grid-template-columns: 1fr; }
  .dash-users { position: static; max-height: none; order: 2; }
  .ulist { max-height: 420px; }
}
.chat-side > [data-side] { display: contents; }   /* panel content lays out exactly as before the phone sheet wrapper */
.panel-btn { align-items: center; gap: 6px; height: 38px; padding: 0 12px; border-radius: 999px; border: 1px solid var(--purple-4); background: var(--purple-bg); color: var(--purple-ink); font-weight: 700; font-family: inherit; font-size: 13px; cursor: pointer; flex: none; }
.icon-btn { align-items: center; justify-content: center; }

/* PC with a narrow window (e.g. laptop at 150% scaling): keep the desktop layout,
   but the chat's profile panel becomes a drawer so the conversation keeps its width */
@media (min-width: 701px) and (max-width: 1180px) and (pointer: fine) {
  .chat-shell { flex-wrap: nowrap; }
  .chat-col { flex: 1 1 auto; }
  .panel-btn { display: inline-flex; }
  .sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 6px 0 4px; }
  .chat-scrim { position: fixed; inset: 0; z-index: 44; background: rgba(20,27,61,.35); }
  .chat-side { position: fixed; top: 0; bottom: 0; left: 0; z-index: 45; width: min(360px, 90vw); max-height: none; border-right: 1px solid var(--line); box-shadow: 10px 0 30px rgba(20,27,61,.15); transform: translateX(-105%); visibility: hidden; transition: transform .2s ease-out; }
  .chat-side.open { transform: none; visibility: visible; }
}
.tq { font-size: 26px; line-height: 1.7; }

@media (max-width: 700px), (pointer: coarse) and (max-width: 1024px) {
  :root { --radius: 6px; }
  body { -webkit-tap-highlight-color: transparent; }
  .shell { display: block; min-height: 100dvh; }
  .side { display: none; }
  .only-m { display: inline-flex !important; } .hide-m { display: none !important; }

  /* top bar */
  .mtop { display: flex; align-items: center; gap: 10px; position: sticky; top: 0; z-index: 30; height: calc(56px + env(safe-area-inset-top)); padding: env(safe-area-inset-top) 14px 0; background: var(--navy); color: var(--on-navy); }
  .brand-mark.sm { width: 34px; height: 34px; border-radius: 6px; }
  .mtop-title { flex: 1; min-width: 0; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .mtop-credit { color: var(--gold-soft); text-decoration: none; font-size: 13px; border: 1px solid rgba(201,164,92,.4); border-radius: 999px; padding: 4px 12px; white-space: nowrap; }
  .mtop-credit small { color: var(--on-navy-muted); }
  .mtop .avatar { border: none; cursor: pointer; font-family: inherit; font-size: 15px; width: 36px; height: 36px; }

  /* bottom tab bar */
  .mtabs { display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; inset: auto 0 0 0; z-index: 30; background: var(--surface); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); box-shadow: 0 -6px 20px rgba(20,27,61,.06); }
  .mtabs a, .mtabs button { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-height: 60px; color: var(--muted); text-decoration: none; font-size: 11.5px; font-weight: 700; border: none; background: none; cursor: pointer; font-family: inherit; }
  .mtabs .on { color: var(--purple); }
  .mtabs .on svg { stroke-width: 2.2; }
  .main { padding: 16px 14px calc(84px + env(safe-area-inset-bottom)); }
  .wrap { gap: 16px; }
  .main > .wrap > header h1, .wrap > h1 { font-size: 22px; }
  h1 { font-size: 22px; } h2 { font-size: 17px; }
  .toast { bottom: calc(80px + env(safe-area-inset-bottom)); max-width: calc(100% - 28px); text-align: center; }

  /* surfaces & controls */
  .card { padding: 18px 16px; gap: 14px; }
  .grid { gap: 14px; }
  .grid.three, .grid.four { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .grid.two { grid-template-columns: 1fr; }
  .stat { padding: 14px; gap: 6px; }
  .stat b, .stat b[style] { font-size: 20px !important; }
  .stat span { font-size: 12.5px; }
  .input, textarea.input, select.input, .composer textarea { font-size: 16px; }   /* no iOS zoom on focus */
  .btn { min-height: 48px; }
  .btn.sm { min-height: 40px; }
  .row.between > h2 { flex: 1 1 auto; }

  /* journey: vertical stepper */
  .journey { display: flex; flex-direction: column; overflow: visible; }
  .journey li { flex-direction: row; text-align: right; gap: 12px; position: relative; padding: 5px 0; font-size: 14px; }
  .journey .track { width: auto; }
  .journey .track i { display: none; }
  .journey .dot { width: 30px; height: 30px; font-size: 13px; position: relative; z-index: 1; background: var(--navy); }
  .journey li.done .dot { background: var(--gold); }
  .journey li:not(:last-child)::after { content: ""; position: absolute; right: 14px; top: 35px; bottom: -5px; width: 2px; background: rgba(237,230,214,.18); }
  .journey li.done:not(:last-child)::after { background: var(--gold); }
  .journey li.current .dot { box-shadow: 0 0 0 4px rgba(109,91,208,.35); }

  /* tabs (admin, ranges): one scrollable row */
  .tabs { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin: 0 -14px; padding: 2px 14px; scroll-padding: 0 14px; }
  .tabs::-webkit-scrollbar { display: none; }
  .tabs button { white-space: nowrap; flex: none; min-height: 40px; }
  .card .tabs { margin: 0; padding: 2px 0; }

  /* tables -> stacked cards */
  table { min-width: 0; }
  .table-wrap { overflow: visible; }
  table[data-stacked] thead { display: none; }
  table[data-stacked], table[data-stacked] tbody, table[data-stacked] tr, table[data-stacked] td { display: block; width: 100%; }
  table[data-stacked] tr { padding: 10px 0; border-bottom: 1px solid var(--cream-2); }
  table[data-stacked] td { border: none; padding: 3px 0; display: flex; gap: 10px; justify-content: space-between; align-items: baseline; text-align: right; direction: rtl; }
  table[data-stacked] td[data-label]::before { content: attr(data-label); color: var(--muted); font-size: 12.5px; flex: none; }
  table[data-stacked] td > * { min-width: 0; }
  table[data-stacked] td:first-child { font-size: 15px; }
  table[data-stacked] td:first-child::before { display: none; }
  table[data-stacked] td:empty { display: none; }
  .viz-table table { min-width: 0; font-size: 12px; }

  /* modals -> full screen */
  .modal-bg { padding: 0; place-items: stretch; }
  .modal, .modal.wide { max-width: none; max-height: none; height: var(--app-h, 100dvh); border-radius: 0; padding: 0 14px calc(20px + env(safe-area-inset-bottom)); gap: 14px; }
  .modal > .row:first-child { position: sticky; top: 0; z-index: 2; background: var(--cream); padding: calc(12px + env(safe-area-inset-top)) 0 10px; margin: 0; border-bottom: 1px solid var(--line); flex-wrap: nowrap; }
  .modal > .row:first-child h2 { font-size: 17px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .prompt-edit textarea { min-height: 50vh; }
  .prompt-edit .row.between { flex-direction: column; align-items: stretch; }
  .prompt-edit .row.between .row { flex-direction: column; align-items: stretch; }
  .prompt-edit .row.between input { min-width: 0 !important; }

  /* chat: full screen, composer pinned above the keyboard */
  .shell.is-bare .mtop, .shell.is-bare .mtabs { display: none; }
  .bare { display: block; }
  .chat-shell { display: block; min-height: 0; }
  .chat-col { height: var(--app-h, 100dvh); }
  .chat-head { position: relative; flex-wrap: nowrap; gap: 6px; padding: calc(6px + env(safe-area-inset-top)) 8px 6px; background: var(--surface); }
  .chat-title { flex: 1; min-width: 0; gap: 8px; }
  .chat-title > div { min-width: 0; }
  .chat-title h1 { font-size: 16px; line-height: 1.5; }
  .chat-title .muted { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 12px; }
  .panel-btn { display: inline-flex; }
  .chat-list { padding: 14px 12px; gap: 12px; overscroll-behavior: contain; }
  .msg { max-width: 88%; padding: 11px 14px; font-size: 15px; line-height: 1.95; border-radius: 18px; }
  .composer { padding: 8px 10px calc(8px + env(safe-area-inset-bottom)); background: var(--cream); }
  .composer form { border-radius: 22px; padding: 5px; }
  .composer textarea { padding: 9px 10px; max-height: 140px; }
  .send { width: 44px; height: 44px; border-radius: 50%; }
  .chat-scrim { position: fixed; inset: 0; z-index: 44; background: rgba(20,27,61,.45); }
  .chat-side { position: fixed; inset: auto 0 0 0; z-index: 45; max-height: 82vh; border: none; border-radius: 24px 24px 0 0; padding: 0 18px calc(20px + env(safe-area-inset-bottom)); transform: translateY(105%); transition: transform .22s ease-out; box-shadow: 0 -10px 30px rgba(20,27,61,.18); visibility: hidden; }
  .chat-side.open { transform: none; visibility: visible; }
  .sheet-head { display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; background: var(--surface); padding: 12px 0 8px; z-index: 1; }

  /* misc pages */
  .auth { padding: 16px; align-items: start; padding-top: max(32px, env(safe-area-inset-top)); }
  .auth-card { padding: 26px 20px; border-radius: 8px; }
  .copybox code { font-size: 15px; }
  .tree ul { margin-inline-start: 6px; padding-inline-start: 12px; }
  .tree ul > li::before { inset-inline-start: -12px; width: 9px; }
  .tnode { padding: 4px 6px; }
  .bars li { grid-template-columns: 92px 1fr 70px; font-size: 13px; }
  .report-body p { text-align: right; }
  .tq { font-size: 19px; line-height: 1.8; }
  .msg.assistant ul, .report-body ul { padding-right: 18px; }
}
@media (max-width: 700px), (pointer: coarse) and (max-width: 1024px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .kpis b { font-size: 19px; }
}
@media (max-width: 360px) {
  .grid.three, .grid.four { grid-template-columns: 1fr; }
  .mtop-credit small { display: none; }
}


/* ---------- admin workspace layout ---------- */
.ashell { min-height: 100vh; display: flex; flex-direction: column; }
.abar { position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 28px; height: 64px; padding: 0 24px; background: var(--navy); box-shadow: 0 2px 14px rgba(20,27,61,.18); }
.abrand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--on-navy); flex: none; }
.abrand b { font-size: 16px; letter-spacing: .2px; }
.abrand .brand-mark { width: 32px; height: 32px; border-radius: 6px; }
.anav { display: flex; align-items: stretch; gap: 2px; align-self: stretch; overflow-x: auto; flex: 1; min-width: 0; scrollbar-width: none; }
.anav::-webkit-scrollbar { display: none; }
.anav a { display: inline-flex; align-items: center; gap: 8px; padding: 0 14px; color: var(--on-navy-muted); text-decoration: none; font-weight: 700; font-size: 14px; white-space: nowrap; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.anav a:hover { color: var(--on-navy); }
.anav a.on { color: var(--gold-soft); border-bottom-color: var(--gold); }
.aacct { display: flex; align-items: center; gap: 10px; flex: none; }
.aview { display: inline-flex; align-items: center; gap: 7px; height: 38px; padding: 0 12px; border: 1px solid rgba(237,230,214,.25); border-radius: 6px; color: var(--on-navy); text-decoration: none; font-size: 13px; font-weight: 700; }
.aview:hover { border-color: var(--gold); color: var(--gold-soft); }
.ame { display: flex; align-items: center; gap: 10px; height: 42px; padding-inline: 8px 0; border: 1px solid rgba(237,230,214,.2); border-radius: 6px; background: rgba(255,255,255,.05); }
.ame-av { width: 28px; height: 28px; border-radius: 5px; background: var(--purple); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 13px; flex: none; }
.ame-txt { display: flex; flex-direction: column; line-height: 1.3; }
.ame-txt b { font-size: 13px; color: var(--on-navy); white-space: nowrap; }
.ame-txt small { font-size: 11px; color: var(--on-navy-muted); }
.ame-out { width: 40px; align-self: stretch; display: grid; place-items: center; border: none; border-inline-start: 1px solid rgba(237,230,214,.2); background: none; color: var(--on-navy-muted); cursor: pointer; }
.ame-out:hover { color: #F2A196; }
.amain { flex: 1; padding: 24px 28px 48px; min-width: 0; }
.awrap { max-width: 1440px; margin: 0 auto; display: flex; flex-direction: column; gap: 20px; }
.subnav { display: flex; gap: 4px; border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: none; }
.subnav a { padding: 10px 14px; color: var(--muted); text-decoration: none; font-weight: 700; font-size: 14px; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.subnav a:hover { color: var(--ink); }
.subnav a.on { color: var(--ink); border-bottom-color: var(--gold); }
.switch-row { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 14px; cursor: pointer; }
.switch-row input { width: 18px; height: 18px; }
.settings-form { max-width: 860px; }
@media (max-width: 1180px) {
  .abar { flex-wrap: wrap; height: auto; padding: 10px 16px 0; gap: 6px 12px; }
  .abar .anav { order: 3; flex-basis: 100%; height: 46px; margin: 0 -16px; padding: 0 8px; }
  .aacct { margin-inline-start: auto; }
  .dash-users { top: 130px; }
}
@media (max-width: 700px), (pointer: coarse) and (max-width: 1024px) {
  .abar { padding: calc(8px + env(safe-area-inset-top)) 12px 0; }
  .abar .anav { margin: 0 -12px; }
  .anav a { padding: 0 12px; font-size: 13.5px; }
  .ame-txt, .aview span { display: none; }
  .amain { padding: 16px 12px 40px; }
}


/* ---------- monitoring: compact live strip + charts ---------- */
.mon-head { display: flex; align-items: center; justify-content: flex-end; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.mstrip + .mcharts { margin-top: 16px; }
.mstrip { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); background: var(--surface); border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.mcell { display: flex; flex-direction: column; gap: 4px; padding: 12px 14px; min-width: 0; border-inline-start: 1px solid var(--line); }
.mcell:first-child { border-inline-start: none; }
.mcell-l { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mcell-v { font-size: 20px; line-height: 1.3; color: var(--navy); white-space: nowrap; }
.mcell-v small { font-size: 12px; color: var(--muted); font-weight: 400; }
.mcell-flag { font-style: normal; font-size: 11px; padding: 1px 6px; border-radius: 4px; vertical-align: middle; }
.mcell.warn .mcell-flag { background: var(--gold-bg); color: var(--gold); }
.mcell.bad .mcell-flag { background: rgba(240,138,126,.14); color: var(--bad); }
.mcell-bar { height: 3px; border-radius: 2px; background: var(--cream-2); overflow: hidden; }
.mcell-bar.none { background: none; }
.mcell-bar i { display: block; height: 100%; background: var(--purple); border-radius: 2px; }
.mcell.warn .mcell-bar i { background: var(--gold); } .mcell.bad .mcell-bar i { background: var(--bad); }
.mcell-d { font-size: 11.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bad-text { color: var(--bad); }
.live-dot { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); }
.live-dot i { width: 7px; height: 7px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 3px rgba(127,207,165,.18); }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.seg button { border: none; background: none; padding: 6px 12px; font-size: 13px; font-weight: 700; color: var(--muted); cursor: pointer; border-inline-start: 1px solid var(--line); }
.seg button:first-child { border-inline-start: none; }
.seg button:hover { color: var(--ink); }
.seg button.on { background: var(--purple-bg); color: var(--purple); }
.mcharts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.mchart { padding: 16px 18px 14px; display: flex; flex-direction: column; gap: 8px; min-width: 0; background: var(--surface); border: 1px solid var(--line); border-radius: 6px; }
.mchart h3 { font-size: 14px; color: var(--ink); }
@media (max-width: 1180px) { .mstrip { grid-template-columns: repeat(3, minmax(0, 1fr)); } .mcell:nth-child(3n+1) { border-inline-start: none; } .mcell:nth-child(n+4) { border-top: 1px solid var(--line); } }
@media (max-width: 860px) { .mcharts { grid-template-columns: 1fr; } }
@media (max-width: 700px), (pointer: coarse) and (max-width: 1024px) {
  .mstrip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .mcell { border-inline-start: none !important; border-top: none !important; }
  .mcell:nth-child(even) { border-inline-start: 1px solid var(--line) !important; }
  .mcell:nth-child(n+3) { border-top: 1px solid var(--line) !important; }
  .mchart { padding: 14px 14px 12px; }
  .seg button { padding: 6px 9px; font-size: 12px; }
}

@media print {
  body { background: #fff; }
  .side, .mtop, .mtabs, .sheet-bg, .no-print, .toast { display: none !important; }
  .shell { display: block; }
  .main { padding: 0; }
  .card { border: none; padding: 0; }
  .report-body h3 { break-after: avoid; }
}
