:root {
    --bg: #0e1117;
    --panel: #161a23;
    --panel-2: #1e222d;
    --border: rgba(255,255,255,.10);
    --text: #e7ebf3;
    --muted: #94a3b8;
    --accent: #818cf8;
    --accent-2: #6366f1;
    --user-bg: #232838;
    --topbar-bg: rgba(14,17,23,.85);
    --radius: 14px;
    --font: 'Vazirmatn', Tahoma, sans-serif;
}

* { box-sizing: border-box; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.send-btn.stop { background: #b45454; }
/* class rules like `.drawer{display:flex}` outrank the UA `[hidden]` rule, so a
   hidden element still shows. Force it. */
[hidden] { display: none !important; }
html, body {
    margin: 0; padding: 0; height: 100%;
    background: var(--bg); color: var(--text);
    font-family: var(--font); font-size: 15px; line-height: 1.85;
}
a { color: var(--accent); }

/* ── Icons (inline Lucide sprite) ── */
.ic {
    width: 1em; height: 1em; flex: none; fill: none; stroke: currentColor;
    stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
    vertical-align: -0.14em;
}
.ic-brand { width: 1.4em; height: 1.4em; color: var(--accent); vertical-align: -0.3em; }
.icon-btn .ic { width: 1.15rem; height: 1.15rem; }
.msg .avatar .ic { width: 1.05rem; height: 1.05rem; }
.chip .ic, .sug .ic { width: .95rem; height: .95rem; margin-inline-end: .35rem; }
.chips-label .ic, .sug-title .ic { color: var(--accent); }
.support-card .ic { color: #fbbf24; }
.support-row .ic, .support-contacts .ic { width: 1rem; height: 1rem; margin-inline-end: .2rem; vertical-align: -0.18em; }
.login-emoji .ic { width: 2rem; height: 2rem; color: var(--accent); }
.welcome-emoji .ic { width: 2.6rem; height: 2.6rem; color: var(--accent); }
.tab .ic { width: .95rem; height: .95rem; margin-inline-end: .3rem; vertical-align: -0.15em; }
.brand .ic { color: var(--accent); }
.warn .ic { width: .9rem; height: .9rem; }
.fb button .ic { width: 1rem; height: 1rem; }

.grad-title {
    background: linear-gradient(135deg,#c7d2fe 0%,#818cf8 40%,#6366f1 70%,#a78bfa 100%);
    -webkit-background-clip: text; background-clip: text;
    -webkit-text-fill-color: transparent; font-weight: 800;
}
.sub { color: var(--muted); font-size: .9rem; }

/* ── Login ── */
.login-wrap { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.login-card {
    width: min(420px, 92vw); background: var(--panel); border: 1px solid var(--border);
    border-radius: 18px; padding: 34px 28px; text-align: center;
}
.login-emoji { font-size: 2.2rem; }
.login-card h1 { font-size: 1.5rem; margin: .4rem 0 .3rem; }
.text-input {
    width: 100%; margin-top: 16px; padding: 12px 14px; border-radius: 10px;
    background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
    font-family: var(--font); font-size: 16px; text-align: center;
}
.text-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(99,102,241,.15); }

/* icon-prefixed / password fields (login, signup, account) */
.field { position: relative; margin-top: 16px; }
.field .text-input { margin-top: 0; text-align: right; padding-inline-start: 42px; padding-inline-end: 14px; }
.field.has-toggle .text-input { padding-inline-end: 42px; }
.field[dir="ltr"] .text-input { text-align: left; }
.field > .f-ic {
    position: absolute; inset-inline-start: 13px; top: 50%; transform: translateY(-50%);
    width: 1.05rem; height: 1.05rem; color: var(--muted); pointer-events: none;
    fill: none; stroke: currentColor; stroke-width: 2;
    stroke-linecap: round; stroke-linejoin: round;
}
.pw-toggle {
    position: absolute; inset-inline-end: 8px; top: 50%; transform: translateY(-50%);
    background: none; border: none; padding: 6px; cursor: pointer; color: var(--muted);
    display: inline-flex; border-radius: 8px;
}
.pw-toggle:hover { color: var(--accent); }
.pw-toggle .ic { width: 1.05rem; height: 1.05rem; }
.pw-hint { color: var(--muted); font-size: .78rem; margin: 8px 2px 0; text-align: right; }
.primary-btn {
    width: 100%; margin-top: 12px; padding: 12px; border-radius: 10px; border: none;
    background: linear-gradient(135deg,var(--accent-2),var(--accent)); color: #fff;
    font-family: var(--font); font-size: 1rem; font-weight: 600; cursor: pointer;
}
.primary-btn:hover { filter: brightness(1.08); }
.error-box {
    margin-top: 14px; padding: 10px; border-radius: 10px; font-size: .88rem;
    background: rgba(239,68,68,.10); border: 1px solid rgba(239,68,68,.35); color: #fca5a5;
}

/* ── App layout ── */
.topbar {
    position: relative;
    display: flex; align-items: center; justify-content: space-between;
    padding: 12px 16px; border-bottom: 1px solid var(--border); flex: 0 0 auto;
}
/* brand pinned to the true horizontal center of the bar, regardless of the
   differing widths of the menu button and the actions cluster. */
.brand { position: absolute; left: 50%; transform: translateX(-50%);
    font-weight: 700; font-size: 1.05rem; display: inline-flex; align-items: center;
    gap: 6px; white-space: nowrap; pointer-events: none; }
.logout { font-size: .85rem; color: var(--muted); text-decoration: none; }
.logout:hover { color: var(--accent); }

.chat { flex: 1 1 auto; overflow-y: auto; padding: 18px 16px 8px; scroll-behavior: smooth; }

.welcome { text-align: center; margin-top: 6vh; }
.welcome-emoji { font-size: 2.4rem; }
.welcome-title { font-size: 1.8rem; margin: .3rem 0; }
.chips-label { color: var(--muted); font-size: .88rem; margin-top: 1.6rem; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: .4rem; }

.chip, .sug {
    border-radius: 999px; border: 1px solid var(--border); background: var(--panel-2);
    color: var(--text); font-family: var(--font); font-size: .82rem; padding: .4rem .85rem;
    cursor: pointer; transition: all .15s ease;
}
.chip:hover, .sug:hover { border-color: var(--accent); color: var(--accent); background: rgba(99,102,241,.08); }

/* ── Messages ── */
.msg { display: flex; gap: 10px; margin: 14px 0; align-items: flex-start; }
.msg .avatar { flex: 0 0 auto; font-size: 1.15rem; margin-top: 2px; }
.bubble {
    background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 12px 15px; max-width: 100%; overflow-wrap: anywhere;
}
.msg.user { flex-direction: row-reverse; }
.msg.user .bubble { background: var(--user-bg); }

.bubble p:first-child { margin-top: 0; } .bubble p:last-child { margin-bottom: 0; }
.bubble h1,.bubble h2,.bubble h3,.bubble h4 { margin: .7em 0 .4em; line-height: 1.5; }
.bubble ul,.bubble ol { padding-right: 1.4rem; padding-left: 0; }
.bubble table { display: block; overflow-x: auto; border-collapse: collapse; max-width: 100%; }
.bubble th,.bubble td { border: 1px solid var(--border); padding: 6px 10px; }
.bubble th { background: rgba(255,255,255,.05); }

/* inline code stays LTR inside Persian text */
.bubble :not(pre) > code {
    direction: ltr; unicode-bidi: isolate; display: inline-block; vertical-align: baseline;
    padding: .12rem .42rem; margin: 0 .18rem; border-radius: 6px;
    background: rgba(99,102,241,.12); color: #c7d2fe; font-size: .88em;
    font-family: 'JetBrains Mono','Fira Code',monospace;
}
/* code cards */
.bubble pre {
    position: relative; padding: 1.9rem .9rem .9rem; border-radius: 10px;
    background: #12151c; border: 1px solid var(--border);
    direction: ltr; text-align: left; overflow-x: auto;
}
.bubble pre code { color: #e7ebf3; font-family: 'JetBrains Mono','Fira Code',monospace; font-size: .86em; }
.bubble a { unicode-bidi: isolate; }

.typing::after { content: "▍"; color: var(--accent); animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }

/* suggestions + feedback under an answer */
.after { margin-top: 10px; }
.sug-title { color: var(--muted); font-size: .84rem; margin: .6rem 0 .35rem; }
.sug-row { display: flex; flex-wrap: wrap; gap: 8px; }
.fb { display: flex; gap: 8px; margin-top: 8px; }
.fb button {
    background: transparent; border: 1px solid var(--border); border-radius: 8px;
    padding: 3px 9px; cursor: pointer; font-size: .95rem; color: var(--muted);
}
.fb button:hover { border-color: var(--accent); }
.fb button.done { color: var(--accent); border-color: var(--accent); }
.warn { color: #fbbf24; font-size: .8rem; margin-top: 6px; }
.err-retry { display: inline-flex; align-items: center; gap: 6px; margin-top: 10px;
    background: transparent; border: 1px solid var(--border); border-radius: 8px;
    padding: 5px 12px; cursor: pointer; font-family: var(--font); font-size: .85rem; color: var(--text); }
.err-retry:hover { border-color: var(--accent); color: var(--accent); }
.err-retry .ic { width: 1rem; height: 1rem; }

/* ── Onboarding wizard (paced walkthrough steps) ── */
.wizard { display: flex; flex-direction: column; gap: 12px; }
.wiz-head { display: flex; align-items: center; gap: 10px; }
.wiz-count { flex: 0 0 auto; font-size: .82rem; font-weight: 700; color: var(--accent); white-space: nowrap; }
.wiz-bar { flex: 1 1 auto; height: 6px; border-radius: 999px; background: var(--panel-2); overflow: hidden; }
.wiz-bar > span { display: block; height: 100%; border-radius: 999px;
    background: linear-gradient(90deg, var(--accent-2), var(--accent)); transition: width .25s ease; }
.wiz-step { min-height: 2.5em; }
.wiz-step > :first-child { margin-top: 0; }
.wiz-acts { display: flex; flex-wrap: wrap; gap: 8px; }
.wiz-act { display: inline-flex; align-items: center; gap: 4px; border-radius: 999px;
    border: 1px solid var(--border); background: var(--panel-2); color: var(--muted);
    font-family: var(--font); font-size: .8rem; padding: .35rem .8rem; cursor: pointer;
    transition: border-color .15s, color .15s; }
.wiz-act:hover { border-color: var(--accent); color: var(--accent); }
.wiz-act .ic { width: .9rem; height: .9rem; }
.wiz-nav { display: flex; gap: 10px; }
.wiz-btn { flex: 1 1 auto; padding: 9px 14px; border-radius: 10px; font-family: var(--font); font-size: .9rem;
    font-weight: 600; cursor: pointer; border: 1px solid var(--border); background: var(--panel-2); color: var(--text);
    transition: border-color .15s, color .15s, opacity .15s; }
.wiz-next { background: linear-gradient(135deg, var(--accent-2), var(--accent)); color: #fff; border: none; }
.wiz-next:hover { filter: brightness(1.06); }
.wiz-prev:hover { border-color: var(--accent); color: var(--accent); }
.wiz-btn:disabled { opacity: .45; cursor: default; filter: none; }
.wiz-all { align-self: flex-start; background: none; border: none; color: var(--muted); font-family: var(--font);
    font-size: .82rem; cursor: pointer; text-decoration: underline; padding: 0; }
.wiz-all:hover { color: var(--accent); }

/* ── Support handoff card ── */
.support-card {
    border: 1px solid rgba(251,191,36,.30);
    background: linear-gradient(180deg,rgba(251,191,36,.07),rgba(251,191,36,.02));
    border-radius: 12px; padding: 14px 16px; margin-top: 10px;
}
.support-card h4 { margin: 0 0 .5rem; font-size: .95rem; color: #fbbf24; }
.support-row { font-size: .84rem; margin-bottom: 5px; }
.support-ref {
    font-family: 'JetBrains Mono',monospace; direction: ltr; unicode-bidi: isolate;
    display: inline-block; background: rgba(251,191,36,.14); border: 1px solid rgba(251,191,36,.3);
    color: #fcd34d; border-radius: 6px; padding: 1px 8px; font-size: .82rem;
}
.support-contacts { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.support-contacts a {
    font-size: .8rem; padding: 5px 12px; border-radius: 999px;
    border: 1px solid rgba(251,191,36,.35); color: #fcd34d !important;
    text-decoration: none; cursor: pointer;
}
.support-contacts a:hover { background: rgba(251,191,36,.14); }
.s-copy { margin-top: 10px; font-size: .82rem; color: var(--muted); }
.s-copy pre { white-space: pre-wrap; background: var(--panel-2); border: 1px solid var(--border);
    border-radius: 8px; padding: 10px; margin-top: 8px; direction: rtl; }

/* ── Composer ── */
.composer {
    flex: 0 0 auto; display: flex; align-items: flex-end; gap: 8px;
    padding: 12px 16px 16px; border-top: 1px solid var(--border);
}
.composer-input {
    flex: 1 1 auto; resize: none; max-height: 180px; padding: 12px 18px; border-radius: 24px;
    background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
    font-family: var(--font); font-size: 16px; line-height: 1.6;
    transition: border-color .15s, box-shadow .15s;
}
.composer-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }
.send-btn {
    flex: 0 0 auto; width: 44px; height: 44px; border-radius: 50%; border: none;
    background: linear-gradient(135deg,var(--accent-2),var(--accent)); color: #fff;
    font-size: 1.2rem; cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.send-btn:disabled { opacity: .5; cursor: default; }
.attach-btn {
    flex: 0 0 auto; width: 44px; height: 44px; border-radius: 50%;
    background: var(--panel-2); border: 1px solid var(--border); color: var(--text-dim, var(--text));
    cursor: pointer; display: flex; align-items: center; justify-content: center;
    transition: border-color .15s, color .15s;
}
.attach-btn:hover { border-color: var(--accent); color: var(--accent); }
.attach-btn.has-img { border-color: var(--accent); color: var(--accent); }
.img-preview {
    flex: 0 0 auto; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 0 16px 8px;
    padding: 8px 12px; border-radius: 10px; background: var(--panel-2);
    border: 1px solid var(--border); font-size: .85rem;
}
/* removable image thumbnails in the attach tray */
.thumb { position: relative; flex: 0 0 auto; width: 56px; height: 56px; border-radius: 10px;
    overflow: hidden; border: 1px solid var(--border); }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb-x { position: absolute; top: 2px; inset-inline-end: 2px; width: 18px; height: 18px;
    border-radius: 50%; border: none; background: rgba(0,0,0,.6); color: #fff; cursor: pointer;
    display: flex; align-items: center; justify-content: center; padding: 0; }
.thumb-x .ic { width: 11px; height: 11px; }
.thumb-x:hover { background: #b45454; }
.thumb-x--chip { position: static; margin-inline-start: 4px; background: transparent; color: var(--muted); width: 20px; height: 20px; }
.thumb-x--chip:hover { background: transparent; color: var(--accent); }
.img-tag { display: inline-flex; align-items: center; gap: 3px; padding: 2px 8px; margin-inline-start: 4px; border-radius: 999px; background: var(--panel-2); border: 1px solid var(--border); font-size: .8em; opacity: .85; vertical-align: middle; }
.chat-img { display: block; max-width: 260px; max-height: 260px; width: auto; height: auto; border-radius: 12px; border: 1px solid var(--border); }
.img-row { display: flex; flex-wrap: wrap; gap: 6px; }
.img-row .chat-img { max-width: 180px; max-height: 180px; }
.msg-text { white-space: pre-wrap; margin-top: 8px; }
.file-chip { display: inline-flex; align-items: center; gap: 5px; padding: 8px 12px; border-radius: 10px; background: var(--panel-2); border: 1px solid var(--border); font-size: .9em; color: var(--text); text-decoration: none; direction: ltr; }
a.file-chip:hover { border-color: var(--accent); }

@media (max-width: 600px) { body { font-size: 14px; } .welcome { margin-top: 3vh; } }

/* ── Phase 3: history drawer + topbar actions ── */
.top-actions { display: flex; align-items: center; gap: 10px; }
.icon-btn {
    background: transparent; border: 1px solid var(--border); color: var(--text);
    border-radius: 8px; width: 34px; height: 34px; font-size: 1.05rem; cursor: pointer;
    display: grid; place-items: center;
}
.icon-btn:hover { border-color: var(--accent); color: var(--accent); }
.convlist { display: flex; flex-direction: column; gap: 4px; flex: 1 1 auto;
    overflow-y: auto; min-height: 0; }
.conv-row {
    display: flex; align-items: stretch; gap: 2px; border-radius: 8px;
    border: 1px solid transparent; border-bottom: 1px solid var(--border);
}
.conv-row:hover { background: var(--panel-2); border-color: var(--border); }
.conv-row.active { background: rgba(99,102,241,.12); border-color: rgba(99,102,241,.35); }
.conv-row.active .conv-item { color: var(--accent); }
.conv-item {
    flex: 1 1 auto; min-width: 0; text-align: right; background: transparent;
    border: 0; color: var(--text); opacity: 1; border-radius: 8px;
    padding: 10px 10px; font-family: var(--font);
    font-size: .9rem; font-weight: 500; line-height: 1.6;
    cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.conv-act {
    flex: 0 0 auto; display: grid; place-items: center; width: 32px;
    background: transparent; border: 0; color: var(--muted); cursor: pointer;
    border-radius: 8px; opacity: 0; transition: opacity .12s, color .12s;
    text-decoration: none;
}
.conv-act .ic { width: 16px; height: 16px; }
.conv-row:hover .conv-act, .conv-act:focus-visible { opacity: 1; }
.conv-act:hover { color: var(--accent); background: var(--panel-2); }
.conv-del:hover { color: #e08a8a; background: rgba(224,138,138,.12); }
.conv-empty { color: var(--muted); font-size: .85rem; text-align: center; padding: 18px 8px; }
.conv-search { position: relative; flex: 0 0 auto; margin-bottom: 8px; }
.conv-search .ic { position: absolute; inset-inline-start: 10px; top: 50%; transform: translateY(-50%);
    width: 15px; height: 15px; color: var(--muted); pointer-events: none; }
.conv-search input { width: 100%; box-sizing: border-box; padding: 8px 34px 8px 10px;
    background: var(--panel-2); border: 1px solid var(--border); border-radius: 9px;
    color: var(--text); font-family: var(--font); font-size: .86rem; }
.conv-search input:focus { outline: none; border-color: var(--accent); }
.conv-group { color: var(--muted); font-size: .72rem; font-weight: 700; padding: 10px 6px 4px;
    position: sticky; top: 0; background: var(--panel); }
.ui-modal-input { width: 100%; box-sizing: border-box; margin-top: 4px; text-align: right; }

/* ── Branded modal (uiConfirm/uiAlert) ── */
.ui-modal { position: fixed; inset: 0; z-index: 200; display: grid; place-items: center;
    background: rgba(0,0,0,.5); backdrop-filter: blur(2px); padding: 20px;
    animation: ui-fade .14s ease; }
.ui-modal-card { width: min(400px, 100%); background: var(--panel); color: var(--text);
    border: 1px solid var(--border); border-radius: 18px; padding: 22px 22px 18px;
    text-align: center; box-shadow: 0 20px 60px rgba(0,0,0,.4); animation: ui-pop .16s ease; }
.ui-modal-icon { width: 46px; height: 46px; border-radius: 50%; margin: 0 auto 12px;
    display: grid; place-items: center; background: rgba(99,102,241,.14);
    border: 1px solid rgba(99,102,241,.4); }
.ui-modal-icon .ic { width: 22px; height: 22px; color: var(--accent); }
.ui-modal-card.danger .ui-modal-icon { background: rgba(224,138,138,.14); border-color: rgba(224,138,138,.4); }
.ui-modal-card.danger .ui-modal-icon .ic { color: #e08a8a; }
.ui-modal-title { margin: 0 0 6px; font-size: 1.08rem; font-weight: 700; }
.ui-modal-msg { margin: 0 0 4px; color: var(--muted); font-size: .92rem; line-height: 1.7;
    white-space: pre-line; }
.ui-modal-actions { display: flex; gap: 10px; margin-top: 18px; }
.ui-btn { flex: 1; padding: 11px 14px; border-radius: 11px; font-family: var(--font);
    font-size: .92rem; font-weight: 600; cursor: pointer; border: 1px solid transparent; }
.ui-btn-primary { background: linear-gradient(135deg,var(--accent-2),var(--accent)); color: #fff; }
.ui-btn-primary:hover { filter: brightness(1.05); }
.ui-btn-danger { background: #b45454; color: #fff; }
.ui-btn-ghost { background: transparent; border-color: var(--border); color: var(--text); }
.ui-btn-ghost:hover { background: var(--panel-2); }
.ui-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
@keyframes ui-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes ui-pop { from { opacity: 0; transform: translateY(8px) scale(.97); } to { opacity: 1; transform: none; } }
@media (hover: none) { .conv-act { opacity: 1; } }
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 30; }

/* ── Phase 4: admin panel ── */
.admin-tabs { display: flex; gap: 8px; margin-bottom: 14px; }
.tab {
    background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
    border-radius: 8px; padding: 6px 12px; font-family: var(--font); font-size: .84rem; cursor: pointer;
}
.tab.active { border-color: var(--accent); color: var(--accent); }
.tab-badge { display: inline-grid; place-items: center; min-width: 18px; height: 18px;
    margin-inline-start: 6px; padding: 0 5px; border-radius: 999px; font-size: .7rem;
    background: #ef4444; color: #fff; vertical-align: middle; }
.review-list { display: flex; flex-direction: column; gap: 12px; }
.review-card { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; }
.review-card.resolved { opacity: .6; }
.rc-head { display: flex; align-items: center; gap: 8px; margin: 4px 0; }
.rc-count { background: rgba(99,102,241,.15); color: var(--accent); border-radius: 6px; padding: 1px 8px; font-size: .78rem; }
.rc-kind { color: var(--muted); font-size: .78rem; }
.rc-done { color: #34d399; font-size: .78rem; margin-inline-start: auto; }
.rc-q { font-weight: 600; margin: 6px 0; }
.rc-answer { margin: 8px 0; }
.rc-msg { margin-top: 6px; }
.user-add { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 10px; }
.user-add .text-input { width: auto; margin: 0; flex: 1 1 160px; text-align: right; }
.user-add .primary-btn { flex: 0 0 auto; }
.user-ctl { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 8px; }
.u-row-msg { margin-inline-start: auto; }

/* ── Analytics tab ── */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
.stat { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 14px; }
.stat-val { font-size: 1.5rem; font-weight: 800; color: var(--accent); }
.stat-label { color: var(--muted); font-size: .82rem; margin-top: 2px; }
.stat-hint { color: var(--muted); font-size: .74rem; margin-top: 4px; }
.stats-h { margin: 18px 0 8px; font-size: .95rem; }
.bars { display: flex; flex-direction: column; gap: 6px; }
.bar-row { display: flex; align-items: center; gap: 8px; }
.bar-label { flex: 0 0 92px; font-size: .78rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar { flex: 1 1 auto; height: 10px; background: var(--panel-2); border-radius: 999px; overflow: hidden; }
.bar-fill { display: block; height: 100%; background: linear-gradient(90deg,var(--accent-2),var(--accent)); border-radius: 999px; }
.bar-num { flex: 0 0 auto; font-size: .78rem; color: var(--muted); min-width: 28px; text-align: left; }

.list-search { text-align: right; margin: 4px 0 12px; }
.list-more { display: block; margin: 12px auto 0; }

/* ── Phase 4: notification bell ── */
.bell { position: relative; }
.bell-badge {
    position: absolute; top: -4px; inset-inline-start: -4px; background: #ef4444; color: #fff;
    border-radius: 999px; min-width: 16px; height: 16px; font-size: .66rem; display: grid;
    place-items: center; padding: 0 4px;
}
.notif-panel {
    position: absolute; top: 46px; inset-inline-start: 8px; width: 300px; max-height: 60vh; overflow-y: auto;
    background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 10px; z-index: 50;
}
.notif-item { font-size: .82rem; padding: 8px; border-bottom: 1px solid var(--border); }
.notif-item:last-child { border-bottom: none; }
.notif-empty { color: var(--muted); font-size: .82rem; padding: 8px; text-align: center; }

/* ── Phase 5: polish ── */
.topbar { position: sticky; top: 0; z-index: 20; background: var(--topbar-bg); backdrop-filter: blur(8px); }
.msg .avatar {
    width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center;
    background: var(--panel-2); border: 1px solid var(--border); font-size: .95rem;
}
.msg.user .avatar { background: rgba(99,102,241,.15); border-color: rgba(99,102,241,.3); }
.msg { animation: rise .18s ease both; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.bubble { box-shadow: 0 1px 2px rgba(0,0,0,.15); }
.chip:active, .sug:active, .send-btn:active { transform: scale(.96); }
.chat::-webkit-scrollbar, .drawer::-webkit-scrollbar { width: 8px; }
.chat::-webkit-scrollbar-thumb, .drawer::-webkit-scrollbar-thumb { background: rgba(255,255,255,.10); border-radius: 8px; }
.composer { padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px)); }

@media (max-width: 640px) {
    body { font-size: 14px; }
    .app { max-width: 100%; }
    .topbar { padding: 10px 10px; gap: 6px; }
    /* stop the absolute-centered brand from overlapping the actions; let it flow
       and shrink between the menu button and the action icons. */
    .brand { position: static; transform: none; font-size: .95rem;
             flex: 1 1 auto; min-width: 0; overflow: hidden; }
    .brand .grad-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .top-actions { gap: 2px; }
    .top-actions .logout { display: none; }   /* moved into the ☰ drawer on mobile */
    .icon-btn { padding: 6px; }
    .chat { padding: 14px 12px 6px; }
    .welcome { margin-top: 4vh; }
    .welcome-title { font-size: 1.5rem; }
    .composer { padding: 10px 12px calc(12px + env(safe-area-inset-bottom, 0px)); }
    .composer-input { font-size: 16px; } /* prevent iOS zoom on focus */
    .msg .avatar { width: 26px; height: 26px; }
    .bubble { padding: 10px 12px; }
}

/* copy button on code blocks (top-inline-end, inside the mac-style card) */
.bubble pre { }
.code-copy {
    position: absolute; top: 6px; inset-inline-end: 8px;
    background: rgba(255,255,255,.06); border: 1px solid var(--border);
    color: #c9d1d9; border-radius: 7px; padding: 3px 6px; cursor: pointer;
    display: inline-flex; line-height: 0; opacity: .55; transition: opacity .15s;
}
.code-copy:hover { opacity: 1; border-color: var(--accent); color: var(--accent); }
.code-copy .ic { width: .95rem; height: .95rem; }
.fb button.done { color: var(--accent); border-color: var(--accent); }

/* inline validation messages (login + signup) */
.field-msg { font-size: .76rem; margin: 6px 4px 0; min-height: 1em; color: var(--muted); }
.field-msg.ok  { color: #7fb15c; }
.field-msg.err { color: #e08a8a; }

.primary-btn:disabled { opacity: .5; cursor: not-allowed; filter: none; }

/* ── Light theme (toggle sets html[data-theme="light"]; dark is the default) ── */
:root[data-theme="light"] {
    --bg: #f4f5f9;
    --panel: #ffffff;
    --panel-2: #eef0fb;
    --border: rgba(30,34,60,.16);
    --text: #1c2230;
    --muted: #5b6270;
    --accent: #4f46e5;
    --accent-2: #4338ca;
    --user-bg: #e6e8fb;
    --topbar-bg: rgba(244,245,249,.9);
}
:root[data-theme="light"] .bubble th { background: rgba(0,0,0,.05); }
:root[data-theme="light"] .bubble :not(pre) > code { background: rgba(63,125,51,.12); color: #3730a3; }
:root[data-theme="light"] .error-box { color: #b23b3b; }
/* deeper, higher-contrast brand gradient on the light ground */
:root[data-theme="light"] .grad-title {
    background: linear-gradient(135deg,#6366f1 0%,#4f46e5 55%,#7c3aed 100%);
    -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
}
/* icon buttons + logout links need a touch more presence on the light bar */
:root[data-theme="light"] .icon-btn { border-color: rgba(30,60,30,.22); }
:root[data-theme="light"] .logout { color: #3f5238; }
/* code cards stay dark in both themes (readable, conventional) */

/* theme toggle button */
.theme-toggle { background: none; border: none; cursor: pointer; color: var(--muted);
    display: inline-flex; padding: 6px; border-radius: 8px; }
.theme-toggle:hover { color: var(--accent); }
.theme-toggle .ic { width: 1.15rem; height: 1.15rem; }
:root[data-theme="light"] .theme-toggle .i-sun { display: none; }
.theme-toggle .i-moon { display: none; }
:root[data-theme="light"] .theme-toggle .i-moon { display: inline; }
:root[data-theme="light"] .theme-toggle .i-sun { display: none; }

.theme-toggle--fixed { position: fixed; top: 10px; inset-inline-start: 12px; z-index: 40;
    background: var(--panel-2); border: 1px solid var(--border); }

/* the fixed corner toggle is only for pages without a topbar (login/signup/account);
   when the page already has a toggle in its topbar (chat + admin), hide the fixed
   one so there is never a redundant second button. */
body:has(.topbar .theme-toggle) .theme-toggle--fixed { display: none; }

/* ── UX polish: toasts, RTL tables, scroll-to-bottom, empty-state hint ── */
.ui-toasts { position: fixed; bottom: 90px; left: 50%; transform: translateX(-50%);
    z-index: 300; display: flex; flex-direction: column; gap: 8px; align-items: center;
    pointer-events: none; }
.ui-toast { background: var(--panel-2); color: var(--text); border: 1px solid var(--border);
    border-radius: 999px; padding: 8px 16px; font-size: .85rem; font-family: var(--font);
    box-shadow: 0 8px 24px rgba(0,0,0,.3); opacity: 0; transform: translateY(10px);
    transition: opacity .2s ease, transform .2s ease; }
.ui-toast.in { opacity: 1; transform: none; }
.ui-toast.err { border-color: rgba(224,138,138,.5); color: #e08a8a; }

.how-to { color: var(--muted); font-size: .9rem; line-height: 1.9; max-width: 520px;
    margin: 2px auto 12px; }

/* guest access banner (styling was previously inline in chat.html) */
.guest-banner { flex: 0 0 auto; margin: 10px 16px; padding: 10px 14px; border: 1px solid var(--border);
    border-radius: 10px; background: var(--panel-2); font-size: .92rem; display: flex; gap: 10px;
    align-items: center; justify-content: space-between; flex-wrap: wrap; }
.guest-banner .ic { color: var(--accent); }
.guest-banner .primary-btn { width: auto; margin: 0; padding: 6px 14px; }

/* Markdown tables inside an answer bubble: real, readable, horizontally scrollable. */
.bubble table { display: block; max-width: 100%; overflow-x: auto; border-collapse: collapse;
    margin: 10px 0; font-size: .9rem; }
.bubble th, .bubble td { border: 1px solid var(--border); padding: 6px 10px; text-align: right;
    vertical-align: top; }
.bubble thead th { background: var(--panel-2); font-weight: 700; white-space: nowrap; }
.bubble tbody tr:nth-child(even) { background: rgba(127,127,127,.05); }

.scroll-bottom { position: fixed; bottom: 92px; left: 50%; transform: translateX(-50%);
    z-index: 25; width: 40px; height: 40px; border-radius: 50%; background: var(--panel);
    border: 1px solid var(--border); color: var(--accent); display: grid; place-items: center;
    cursor: pointer; box-shadow: 0 6px 20px rgba(0,0,0,.3); }
.scroll-bottom .ic { width: 20px; height: 20px; }
.scroll-bottom:hover { background: var(--panel-2); }

/* ── Superadmin: per-user conversation links (P4) ── */
.u-convos-list { display: flex; flex-direction: column; gap: 4px; margin-top: 8px; }
.convo-link { font-size: .82rem; color: var(--accent); text-decoration: none; padding: 4px 8px;
    border: 1px solid var(--border); border-radius: 8px; background: var(--panel-2); }
.convo-link:hover { border-color: var(--accent); }

/* ── Auth extras (commercial) ── */
.notice-box { margin-top: 14px; padding: 10px 12px; border-radius: 10px; font-size: .85rem;
    background: rgba(99,102,241,.14); border: 1px solid rgba(99,102,241,.4); color: var(--accent); }
.field.good .text-input { border-color: rgba(99,102,241,.55); }
.field.bad .text-input { border-color: rgba(224,138,138,.55); }

/* ── Admin: knowledge-doc upload form ── */
.doc-form-title { display: flex; align-items: center; gap: 8px; margin: 0 0 12px; font-size: 1rem; }
.doc-form-title .ic { color: var(--accent); width: 18px; height: 18px; }
.doc-field { display: block; margin-top: 12px; }
.doc-label { display: flex; align-items: center; gap: 6px; font-size: .82rem; color: var(--muted); margin-bottom: 6px; }
.doc-label .ic { width: .9rem; height: .9rem; color: var(--accent); }
.doc-field .text-input { margin-top: 0; text-align: right; }
.doc-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.doc-or { display: flex; align-items: center; gap: 12px; margin: 16px 0 6px; color: var(--muted); font-size: .8rem; }
.doc-or::before, .doc-or::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.dropzone { display: flex; flex-direction: column; align-items: center; gap: 4px; text-align: center;
    padding: 20px; border: 1.5px dashed var(--border); border-radius: 12px; background: var(--panel-2);
    cursor: pointer; transition: border-color .15s, background .15s; }
.dropzone:hover { border-color: var(--accent); }
.dropzone.has-file { border-color: var(--accent); border-style: solid; background: rgba(99,102,241,.06); }
.dropzone .dz-ic { width: 1.6rem; height: 1.6rem; color: var(--accent); }
.dropzone .dz-main { font-size: .9rem; font-weight: 600; color: var(--text); overflow-wrap: anywhere; }
.dropzone .dz-sub { font-size: .74rem; color: var(--muted); direction: ltr; }
.doc-form .primary-btn { margin-top: 14px; }
@media (max-width: 560px) { .doc-grid { grid-template-columns: 1fr; } }


/* ── Unified collapsible sidebar shell (chat + admin) ── */
.shell { display: flex; height: 100dvh; overflow: hidden; }
.side {
    flex: 0 0 272px; width: 272px; display: flex; flex-direction: column; min-height: 0;
    background: var(--panel); border-inline-start: 1px solid var(--border);
    padding: 14px 12px calc(12px + env(safe-area-inset-bottom, 0px));
    transition: flex-basis .18s ease, width .18s ease;
}
.side-head { display: flex; align-items: center; gap: 8px; padding: 2px 4px 12px; }
.side-brand {
    position: static; transform: none; pointer-events: auto; flex: 1 1 auto; min-width: 0;
    font-size: 1.12rem; font-weight: 800; display: inline-flex; align-items: center; gap: 8px; white-space: nowrap;
}
.side-brand .ic-brand { color: var(--accent); flex: 0 0 auto; }
.side-toggle {
    flex: 0 0 auto; width: 38px; height: 38px; border-radius: 10px; border: 1px solid transparent;
    background: transparent; color: var(--muted); cursor: pointer; display: flex; align-items: center; justify-content: center;
    transition: background .15s, color .15s;
}
.side-toggle:hover { background: var(--panel-2); color: var(--accent); }

.side-actions { display: flex; flex-direction: column; gap: 4px; padding-bottom: 8px; }
.side-body { flex: 1 1 auto; overflow-y: auto; overflow-x: hidden; display: flex; flex-direction: column; gap: 2px; min-height: 0; }
/* on chat the conversation list (#convlist) is the scroller, so side-body must
   not add a second outer scrollbar over it (admin/account nav still scrolls). */
.side-body:has(#convlist) { overflow: hidden; }
.side-foot { padding-top: 10px; margin-top: 6px; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 6px; }

.side-item {
    display: flex; align-items: center; gap: 11px; width: 100%; justify-content: flex-start;
    padding: 10px 12px; border-radius: 11px; border: 1px solid transparent; background: transparent;
    color: var(--text); font-family: var(--font); font-size: .95rem; cursor: pointer; text-align: start;
    text-decoration: none; white-space: nowrap; transition: background .15s, color .15s, border-color .15s;
}
.side-item .ic { opacity: .78; flex: 0 0 auto; width: 1.05rem; height: 1.05rem; }
.side-item:hover { background: var(--panel-2); }
.side-item.active {
    background: linear-gradient(135deg, color-mix(in srgb, var(--accent) 24%, transparent), color-mix(in srgb, var(--accent-2) 15%, transparent));
    color: var(--accent); border-color: color-mix(in srgb, var(--accent) 36%, transparent); font-weight: 700;
}
.side-item.active .ic { opacity: 1; }
.side-item-primary { background: linear-gradient(135deg, var(--accent-2), var(--accent)); color: #fff; font-weight: 700; }
.side-item-primary .ic { opacity: 1; color: #fff; }
.side-item-primary:hover { filter: brightness(1.06); }
.side-item .tab-badge { margin-inline-start: auto; background: var(--accent); color: #fff; border-radius: 999px;
    font-size: .72rem; line-height: 1.5; padding: 0 7px; min-width: 18px; text-align: center; }
.side-section-label { font-size: .74rem; color: var(--muted); padding: 10px 12px 4px; }

/* user card: account link + logout, merged into one element */
.side-user { display: flex; align-items: center; gap: 6px; }
.side-user-main {
    flex: 1 1 auto; min-width: 0; display: flex; align-items: center; gap: 10px; padding: 8px 10px;
    border-radius: 12px; text-decoration: none; color: var(--text);
    background: var(--panel-2); border: 1px solid var(--border); transition: border-color .15s;
}
.side-user-main:hover { border-color: var(--accent); }
.side-avatar {
    flex: 0 0 auto; width: 36px; height: 36px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
    background: linear-gradient(135deg, var(--accent-2), var(--accent)); color: #fff; font-weight: 700; font-size: 1rem; text-transform: uppercase;
}
.side-user-meta { display: flex; flex-direction: column; min-width: 0; line-height: 1.3; }
.side-user-name { font-weight: 700; font-size: .9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.side-user-role { font-size: .74rem; color: var(--muted); }
.side-user-logout {
    flex: 0 0 auto; width: 40px; height: 40px; border-radius: 11px; display: flex; align-items: center; justify-content: center;
    background: rgba(239,68,68,.10); border: 1px solid rgba(239,68,68,.32); color: #f87171; text-decoration: none; transition: color .15s, border-color .15s, background .15s;
}
.side-user-logout:hover { color: #fecaca; border-color: #ef4444; background: rgba(239,68,68,.20); }

/* main content column */
.shell-main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; height: 100dvh; overflow: hidden; }
.shell-main > .topbar { position: relative; display: flex; align-items: center; justify-content: space-between;
    padding: 10px 14px; border-bottom: 1px solid var(--border); flex: 0 0 auto; }
.shell-main .chat, .shell-main .composer { width: 100%; max-width: 880px; margin-inline: auto; }
.only-desktop { display: inline-flex; }
.only-mobile { display: none; }

/* admin content area, centered */
.admin-content { flex: 1 1 auto; overflow-y: auto; width: 100%; }
.admin-inner { max-width: 960px; margin-inline: auto; padding: 24px clamp(16px, 4vw, 40px); }
.admin-inner > section { animation: admin-fade .18s ease; }
@keyframes admin-fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* collapsed desktop icon rail */
.shell.collapsed .side { flex-basis: 74px; width: 74px; }
.shell.collapsed .side-label { display: none; }
.shell.collapsed .side-brand { justify-content: center; }
.shell.collapsed .side-head { flex-direction: column; align-items: center; justify-content: center; gap: 10px; }
.shell.collapsed .side-brand { justify-content: center; }
.shell.collapsed .side-brand .ic-brand { width: 1.5em; height: 1.5em; }
.shell.collapsed .side-item { justify-content: center; padding-inline: 0; }
.shell.collapsed .side-item .tab-badge,
.shell.collapsed .side-section-label,
.shell.collapsed .conv-search,
.shell.collapsed #convlist,
.shell.collapsed .side-user-meta,
.shell.collapsed .side-user-logout { display: none; }
.shell.collapsed .side-user-main { justify-content: center; padding-inline: 0; }

/* mobile: off-canvas overlay sidebar (physically on the right) */
@media (max-width: 860px) {
    .only-desktop { display: none; }
    .only-mobile { display: inline-flex; }
    .side {
        position: fixed; top: 0; bottom: 0; right: 0; z-index: 60;
        width: 286px; flex-basis: 286px; transform: translateX(100%);
        transition: transform .2s ease; box-shadow: -8px 0 30px rgba(0,0,0,.4);
    }
    .shell.side-open .side { transform: translateX(0); }
    .shell.collapsed .side { flex-basis: 286px; width: 286px; }
    .shell.collapsed .side-label, .shell.collapsed #convlist, .shell.collapsed .conv-search,
    .shell.collapsed .side-section-label, .shell.collapsed .side-user-meta, .shell.collapsed .side-user-logout,
    .shell.collapsed .side-item .tab-badge { display: revert; }
    .shell.collapsed .side-item, .shell.collapsed .side-user-main, .shell.collapsed .side-head, .shell.collapsed .side-brand { justify-content: flex-start; padding-inline: 12px; }
    .admin-inner { padding: 16px; }
}

/* ── Account cards (full /account page + chat slide-over panel) ── */
.acc-card { background: var(--panel); border: 1px solid var(--border); border-radius: 16px; padding: 18px; scroll-margin-top: 16px; }
.acc-card h2 { margin: 0 0 12px; font-size: 1rem; display: flex; align-items: center; gap: 8px; color: var(--text); }
.acc-card h2 .ic { width: 18px; height: 18px; color: var(--accent); }
.acc-top { text-align: center; }
.acc-avatar { width: 56px; height: 56px; border-radius: 50%; display: grid; place-items: center; margin: 0 auto 8px;
    background: color-mix(in srgb, var(--accent) 16%, transparent); border: 1px solid color-mix(in srgb, var(--accent) 40%, transparent); }
.acc-avatar .ic { width: 26px; height: 26px; color: var(--accent); }
.acc-name { font-size: 1.15rem; font-weight: 700; }
.acc-phone { color: var(--muted); direction: ltr; font-size: .9rem; margin-top: 2px; }
.badges { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-top: 10px; }
.badge { font-size: .78rem; padding: 4px 10px; border-radius: 999px; border: 1px solid var(--border); background: var(--panel-2); color: var(--text); }
.badge.role, .badge-ok { border-color: color-mix(in srgb, var(--accent) 45%, transparent); color: var(--accent); }
.acc-stats { display: flex; gap: 10px; margin-top: 14px; }
.acc-stats .stat { flex: 1; text-align: center; background: var(--panel-2); border: 1px solid var(--border); border-radius: 12px; padding: 10px 6px; }
.acc-stats .stat b { display: block; font-size: 1.3rem; color: var(--accent); }
.acc-stats .stat span { font-size: .75rem; color: var(--muted); }
.btn-line { display: flex; gap: 10px; flex-wrap: wrap; }
.lnk-btn { display: inline-flex; align-items: center; gap: 6px; text-decoration: none;
    border: 1px solid var(--accent); color: var(--accent); background: transparent;
    padding: 9px 14px; border-radius: 10px; font-family: var(--font); font-size: .9rem; cursor: pointer; }
.lnk-btn.solid { background: linear-gradient(135deg,var(--accent-2),var(--accent)); color: #fff; border: none; }
.lnk-btn .ic { width: 16px; height: 16px; }
.pw-hint { color: var(--muted); font-size: .78rem; margin: 8px 4px; }
.acc-card.danger { border-color: rgba(239,68,68,.35); }
.acc-card.danger h2 { color: #f87171; } .acc-card.danger h2 .ic { color: #f87171; }
.danger-btn { border-color: rgba(239,68,68,.5); color: #f87171; }
.danger-btn:hover { background: rgba(239,68,68,.12); }
.ok-box { background: color-mix(in srgb, var(--accent) 14%, transparent); border: 1px solid color-mix(in srgb, var(--accent) 40%, transparent);
    color: var(--accent); border-radius: 10px; padding: 8px 12px; font-size: .85rem; margin-bottom: 10px; }

/* ── Slide-over panel (account settings over the chat) ── */
/* Docked on the right, next to the sidebar + user card that opens it (RTL). */
.sheet { position: fixed; top: 0; bottom: 0; right: 0; left: auto; z-index: 70; width: min(440px, 92vw);
    background: var(--panel); border-left: 1px solid var(--border); box-shadow: -8px 0 34px rgba(0,0,0,.45);
    display: flex; flex-direction: column; transform: translateX(100%); transition: transform .22s ease; }
.sheet.open { transform: translateX(0); }
.sheet-head { flex: 0 0 auto; display: flex; align-items: center; justify-content: space-between;
    padding: 16px 18px; border-bottom: 1px solid var(--border); }
.sheet-head .sheet-title { display: inline-flex; align-items: center; gap: 8px; font-weight: 800; font-size: 1.1rem; }
.sheet-head .sheet-title .ic { color: var(--accent); width: 1.3em; height: 1.3em; }
.sheet-close { width: 38px; height: 38px; border-radius: 10px; border: 1px solid var(--border); background: var(--panel-2);
    color: var(--muted); cursor: pointer; display: flex; align-items: center; justify-content: center; transition: color .15s, border-color .15s; }
.sheet-close:hover { color: var(--accent); border-color: var(--accent); }
.sheet-body { flex: 1 1 auto; overflow-y: auto; padding: 16px 18px calc(22px + env(safe-area-inset-bottom,0px));
    display: flex; flex-direction: column; gap: 14px; }

/* user card can be a button (chat: opens the account panel) or a link (admin/account) */
button.side-user-main { font: inherit; text-align: start; cursor: pointer; }

/* drag-over hint while dropping a file onto the chat */
.shell-main.dragging { position: relative; }
.shell-main.dragging::after {
    content: "تصویر یا فایل را اینجا رها کنید"; position: absolute; inset: 10px; z-index: 50;
    display: flex; align-items: center; justify-content: center; text-align: center;
    border: 2px dashed var(--accent); border-radius: 16px; color: var(--accent); font-weight: 700;
    background: color-mix(in srgb, var(--accent) 10%, transparent); pointer-events: none;
}
