/* Ibex AI Chat (chat.html / chat.js). Colours come from the shared theme tokens, so every studio theme applies. */
body.chat-page{height:100vh;height:100dvh;overflow:hidden}
html[lang=fa] body.chat-page{font-family:Vazirmatn,Tahoma,"Segoe UI",sans-serif}
.ch-shell{display:grid;grid-template-columns:270px minmax(0,1fr);height:100%}
.ch-side{display:flex;flex-direction:column;gap:12px;min-height:0;padding:16px 12px;border-inline-end:1px solid var(--line);background:var(--surface)}
.ch-side-top{display:flex;align-items:center;justify-content:space-between;gap:10px}
.ch-brand{display:inline-flex;border-radius:8px}
.ch-brand img{display:block;border-radius:8px}
.ch-list{flex:1;min-height:0;overflow:auto;display:grid;align-content:start;gap:2px;scrollbar-width:thin}
.ch-item{display:flex;align-items:center;border-radius:8px}
.ch-item:hover,.ch-item.active{background:var(--raised)}
.ch-open{flex:1;min-width:0;text-align:start;background:none;border:0;color:var(--text);padding:9px 10px;font-size:13px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.ch-item.active .ch-open{font-weight:600}
.ch-del{background:none;border:0;color:var(--muted);font-size:18px;line-height:1;padding:4px 10px;opacity:0;border-radius:6px}
.ch-item:hover .ch-del,.ch-item.active .ch-del,.ch-del:focus-visible{opacity:1}
.ch-del:hover{color:var(--text);background:var(--line)}
.ch-none{padding:8px 10px}
.ch-side-foot{display:flex;align-items:center;justify-content:space-between;gap:8px;padding-top:10px;border-top:1px solid var(--line)}
.ch-balance{font-size:12px;color:var(--muted);white-space:nowrap}
.ch-main{display:flex;flex-direction:column;min-width:0;min-height:0;height:100%}
.ch-head{display:flex;align-items:center;gap:12px;padding:12px 20px;border-bottom:1px solid var(--line)}
.ch-head h1{flex:1;min-width:0;font-size:16px;font-weight:600;letter-spacing:0;line-height:1.5;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.ch-menu{display:none}
.ch-model .select{max-width:min(340px,48vw)}
.ch-log{flex:1;min-height:0;overflow:auto;padding:24px max(20px,calc((100% - 800px)/2)) 12px;display:flex;flex-direction:column;gap:18px;scrollbar-width:thin}
.ch-hello{margin:auto;text-align:center;max-width:560px;display:grid;justify-items:center;gap:12px;padding:20px 0}
.ch-hello-logo{border-radius:16px}
.ch-hello h2{font-size:24px}
.ch-ideas{display:grid;grid-template-columns:1fr 1fr;gap:8px;margin-top:8px;width:100%}
.ch-idea{text-align:start;background:var(--surface);border:1px solid var(--line);border-radius:10px;color:var(--text);padding:10px 12px;font-size:12.5px;line-height:1.6}
.ch-idea:hover{border-color:var(--accent)}
.ch-msg{display:grid;gap:4px;max-width:100%}
.ch-msg.user{justify-items:end}
.ch-msg.user .ch-body{background:var(--raised);border:1px solid var(--line);border-radius:14px;padding:10px 14px;max-width:min(640px,88%);white-space:normal;overflow-wrap:anywhere}
.ch-msg.assistant .ch-body{overflow-wrap:anywhere;font-size:14.5px;line-height:1.85}
.ch-body p{margin:0 0 .6em}
.ch-body p:last-child{margin-bottom:0}
.ch-body h3,.ch-body h4{margin:.8em 0 .4em;font-size:15.5px}
.ch-body ul,.ch-body ol{margin:.3em 0 .7em;padding-inline-start:1.4em}
.ch-body li{margin:.15em 0}
.ch-body a{color:var(--accent);text-decoration:underline}
.ch-body code{font-family:ui-monospace,SFMono-Regular,Consolas,monospace;font-size:.88em;background:var(--raised);border:1px solid var(--line);border-radius:5px;padding:1px 5px}
.ch-code{position:relative;margin:.5em 0 .8em}
.ch-code pre{margin:0;overflow:auto;background:var(--raised);border:1px solid var(--line);border-radius:10px;padding:12px 14px;text-align:left}
.ch-code pre code{background:none;border:0;padding:0;font-size:12.5px;white-space:pre}
.ch-copy{position:absolute;top:6px;inset-inline-end:6px;background:var(--surface);border:1px solid var(--line);border-radius:6px;color:var(--muted);font-size:11px;padding:3px 8px}
.ch-meta{font-size:11.5px;color:var(--muted)}
.ch-msg.user .ch-meta{display:none}
.ch-typing{display:inline-flex;align-items:center;gap:6px}
.ch-typing:before{content:"";width:8px;height:8px;border-radius:50%;background:var(--accent);animation:chPulse 1s ease-in-out infinite}
@keyframes chPulse{50%{opacity:.25}}
.ch-compose{display:flex;align-items:flex-end;gap:10px;margin:0 max(20px,calc((100% - 800px)/2));padding:10px;border:1px solid var(--line);border-radius:16px;background:var(--surface)}
.ch-compose .textarea{min-height:44px;max-height:220px;resize:none;border:0;background:transparent;box-shadow:none;font-size:14.5px;padding:10px}
.ch-compose .textarea:focus{box-shadow:none}
.ch-compose .btn{min-height:42px}
.ch-foot{text-align:center;padding:8px 20px 14px}
@media (max-width:760px){
 .ch-shell{grid-template-columns:1fr}
 .ch-side{position:fixed;inset-block:0;inset-inline-start:0;width:min(290px,86vw);z-index:40;transform:translateX(-105%);transition:transform .2s;box-shadow:0 0 40px #0006}
 html[dir=rtl] .ch-side{transform:translateX(105%)}
 body.ch-side-open .ch-side{transform:none}
 .ch-menu{display:flex}
 .ch-head{padding:10px 16px;gap:8px}
 .ch-model .select{min-width:0;max-width:46vw}
 .ch-log{padding:16px 16px 10px}
 .ch-compose{margin:0 16px}
 .ch-ideas{grid-template-columns:1fr}
}
.ch-balance{display:grid;justify-items:end;line-height:1.4;cursor:help}
.ch-balance small{font-size:10.5px}
.ch-meta span[title]{cursor:help;border-bottom:1px dotted var(--line)}
.ch-img-btn{display:inline-flex;align-items:center;justify-content:center;width:42px;height:42px;flex:0 0 42px;border:1px solid var(--line);border-radius:12px;background:none;color:var(--muted)}
.ch-img-btn.active{background:var(--accent);color:var(--accent-ink);border-color:var(--accent)}
.ch-img-model{max-width:220px;align-self:center}
.ch-compose{flex-wrap:wrap}
.ch-compose .textarea{flex:1;min-width:180px}
.ch-pic{display:block;max-width:min(520px,100%);margin-bottom:6px}
.ch-pic img{display:block;width:100%;height:auto;min-height:120px;border-radius:12px;border:1px solid var(--line);background:var(--raised)}
.ch-side-foot{flex-direction:column;align-items:stretch;gap:6px}
.ch-side-foot .btn{align-self:flex-start}
.ch-balance{display:flex;flex-wrap:wrap;align-items:baseline;gap:2px 8px;justify-items:initial;white-space:normal;min-width:0}
.ch-balance small{flex-basis:100%;overflow-wrap:anywhere}
.ch-attached{display:flex;flex-wrap:wrap;gap:6px;flex-basis:100%;order:-1}
.ch-chip{position:relative;width:56px;height:56px;border-radius:10px;overflow:hidden;border:1px solid var(--line)}
.ch-chip img{width:100%;height:100%;object-fit:cover}
.ch-chip.loading img{opacity:.45}
.ch-chip.file{width:auto;max-width:220px;display:flex;align-items:center;padding-inline:10px 28px;background:var(--panel,rgba(255,255,255,.04))}
.ch-file-chip{display:inline-block;max-width:200px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-size:.85rem}
.ch-files{display:flex;flex-wrap:wrap;gap:6px;margin-bottom:6px}
.ch-files .ch-file-chip{padding:4px 10px;border:1px solid var(--line);border-radius:8px}
.ch-chip.loading:after{content:"";position:absolute;inset:18px;border:2px solid var(--accent);border-right-color:transparent;border-radius:50%;animation:chspin .8s linear infinite}
.ch-chip button{position:absolute;top:2px;inset-inline-end:2px;width:20px;height:20px;border:0;border-radius:50%;background:rgba(0,0,0,.6);color:#fff;font-size:13px;line-height:1;cursor:pointer}
.ch-thumbs{display:flex;flex-wrap:wrap;gap:6px;margin-bottom:6px}
.ch-thumbs img{display:block;width:96px;height:96px;object-fit:cover;border-radius:10px;border:1px solid var(--line)}
@keyframes chspin{to{transform:rotate(360deg)}}

/* Picture model picker: families as in the studio, grouped by brand, searchable */
.ch-pick{position:relative;flex:0 0 auto}
.ch-pick-btn{display:inline-flex;align-items:center;gap:8px;max-width:260px;padding:7px 10px;border:1px solid var(--line);border-radius:10px;background:var(--surface);color:var(--text);font:inherit;font-size:13px;cursor:pointer}
.ch-pick-btn .icon{width:14px;height:14px;flex:0 0 auto;opacity:.7}
.ch-pick-btn.warn{border-color:#d9534f}
.ch-pick-name{display:inline-flex;align-items:center;gap:4px;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.ch-pick-price{color:var(--muted);font-size:12px;white-space:nowrap}
.ch-pick-warn{color:#d9534f;font-size:12px;white-space:nowrap}
.ch-pick-tag{font-size:12px}
.ch-pick-pop{position:absolute;bottom:calc(100% + 8px);inset-inline-start:0;z-index:30;width:min(360px,calc(100vw - 32px));max-height:min(460px,60vh);display:flex;flex-direction:column;
 background:var(--surface);border:1px solid var(--line);border-radius:14px;box-shadow:0 12px 40px rgba(0,0,0,.25);overflow:hidden}
.ch-pick-search{margin:10px;width:auto}
.ch-pick-list{overflow:auto;padding:0 6px 8px}
.ch-pick-cat{position:sticky;top:0;padding:8px 8px 4px;font-size:11px;font-weight:700;letter-spacing:.04em;text-transform:uppercase;color:var(--muted);background:var(--surface)}
.ch-pick-row{display:flex;align-items:center;justify-content:space-between;gap:10px;width:100%;padding:8px 10px;border:0;border-radius:9px;background:none;color:var(--text);font:inherit;font-size:13px;text-align:start;cursor:pointer}
.ch-pick-row:hover,.ch-pick-row:focus-visible{background:rgba(127,127,127,.12)}
.ch-pick-row.on{background:rgba(127,127,127,.18);font-weight:600}
.ch-pick-row.off{opacity:.55}
.ch-pick-none{padding:12px}
@media(max-width:600px){.ch-pick-btn{max-width:170px}}

/* The last picture, attached by itself so the next message edits it */
.ch-chip.follow{position:relative;outline:2px solid rgba(var(--accent-rgb,196,239,156),.7);outline-offset:1px}
.ch-follow-tag{position:absolute;inset-inline-start:2px;bottom:2px;padding:0 4px;border-radius:4px;background:rgba(0,0,0,.65);color:#fff;font-size:10px;line-height:15px}

/* One model window: Text | Pictures tabs, brand headings */
.ch-pick-tabs{display:flex;gap:4px;margin:0 10px 6px;padding:3px;border-radius:10px;background:rgba(127,127,127,.12)}
.ch-pick-tabs button{flex:1;padding:6px 8px;border:0;border-radius:8px;background:none;color:var(--muted);font:inherit;font-size:13px;font-weight:600;cursor:pointer}
.ch-pick-tabs button.on{background:var(--surface);color:var(--text);box-shadow:0 1px 3px rgba(0,0,0,.15)}
.ch-pick-sec{padding:10px 8px 2px;font-size:12px;font-weight:800;color:var(--text)}
.ch-pick-kind{flex:none;padding:1px 6px;border-radius:6px;background:rgba(127,127,127,.16);color:var(--muted);font-size:10px;font-weight:700;text-transform:uppercase;letter-spacing:.03em}
.ch-pick-kind.img{background:rgba(214,120,60,.18);color:#c26a2d}
.ch-pick-btn{max-width:320px}
#chAttach.off{opacity:.35;cursor:not-allowed}
@media(max-width:600px){.ch-pick-btn{max-width:200px}.ch-pick-kind{display:none}}
.ch-pick-note{margin:2px 10px 6px;line-height:1.5}
/* Memory */
.ch-mem-btn{display:flex;align-items:center;gap:8px;width:100%;padding:9px 10px;border:1px solid var(--line);border-radius:10px;background:none;color:var(--text);font:inherit;font-size:13px;font-weight:600;cursor:pointer}
.ch-mem-btn:hover{background:rgba(127,127,127,.1)}
.ch-mem-btn small{margin-inline-start:auto;color:var(--muted);font-weight:500}
.ch-mem-btn.off{color:var(--muted)}
.ch-mem{width:min(520px,calc(100vw - 24px));max-height:min(640px,calc(100dvh - 24px));padding:16px;border:1px solid var(--line);border-radius:16px;background:var(--surface);color:var(--text);display:none;flex-direction:column;gap:10px}
.ch-mem[open]{display:flex}
.ch-mem::backdrop{background:rgba(0,0,0,.5)}
.ch-mem-head{display:flex;align-items:center;justify-content:space-between;margin:0}
.ch-mem-head b{font-size:16px}
.ch-mem-switch{display:flex;align-items:center;gap:8px;font-size:13px;font-weight:600;cursor:pointer}
.ch-mem-add{display:flex;gap:6px;margin:0}
.ch-mem-add .input{flex:1;min-width:0}
.ch-mem.is-off .ch-mem-list{opacity:.5}
.ch-mem-list{list-style:none;margin:0;padding:0;overflow-y:auto;min-height:60px;flex:1;display:grid;gap:6px;align-content:start}
.ch-mem-list li{display:flex;align-items:center;gap:8px;padding:8px 10px;border:1px solid var(--line);border-radius:10px;font-size:13px;line-height:1.5}
.ch-mem-list li span{flex:1;min-width:0;overflow-wrap:anywhere}
.ch-mem-list li small{white-space:nowrap}
.ch-mem-list li .icon-btn{width:28px;height:28px;flex:none;font-size:12px}
.ch-mem-list .ch-mem-empty{justify-content:center;border-style:dashed}
.ch-mem-foot{display:flex;align-items:center;justify-content:space-between}
.danger-text{color:#d9534f}
/* Our own models' guide: "Best for" line + hover card */
.ch-pick-main{display:flex;flex-direction:column;gap:1px;min-width:0}
.ch-pick-best{color:var(--muted);font-size:11px;font-weight:500;white-space:normal;line-height:1.35}
.ch-guide-tip{position:fixed;z-index:1000;width:min(290px,calc(100vw - 16px));padding:12px 14px;border:1px solid var(--line);border-radius:12px;background:var(--surface);color:var(--text);box-shadow:0 14px 40px rgba(0,0,0,.35);font-size:12.5px;line-height:1.55;pointer-events:none;opacity:0;transform:translateY(4px);transition:opacity .12s,transform .12s}
.ch-guide-tip.on{opacity:1;transform:none}
.ch-guide-tip b{display:block;font-size:14px;margin-bottom:4px}
.ch-guide-tip p{margin:2px 0 0}
.ch-guide-sec{margin-top:8px;font-size:10.5px;font-weight:700;letter-spacing:.04em;text-transform:uppercase;color:var(--muted)}
.ch-guide-tags{display:flex;flex-wrap:wrap;gap:4px;margin-top:4px}
.ch-guide-tags span{padding:2px 8px;border-radius:999px;background:rgba(var(--accent-rgb,120,160,90),.16);font-size:11.5px;font-weight:600}
@media (prefers-reduced-motion:reduce){.ch-guide-tip{transition:none}}
/* Language picker in the header */
.ch-head .ch-lang{flex:none;width:auto;min-height:32px;padding:0 8px;border:1px solid var(--line);border-radius:8px;background:var(--surface);color:var(--text);font-size:12px;cursor:pointer}
/* The chat list: no sideways scrolling (long titles end in "…"), and its width can be dragged */
.ch-shell{grid-template-columns:var(--ch-side,270px) minmax(0,1fr)}
.ch-side{min-width:0}
@media (min-width:761px){.ch-side{position:relative}}   /* phones keep the slide-in (fixed) sidebar */
.ch-list{grid-template-columns:minmax(0,1fr);overflow-x:hidden}
.ch-item{min-width:0}
.ch-open{unicode-bidi:plaintext}
.ch-resize{position:absolute;inset-block:0;inset-inline-end:-4px;width:8px;cursor:col-resize;z-index:5;touch-action:none}
.ch-resize::after{content:'';position:absolute;inset-block:0;inset-inline-start:3px;width:2px;background:transparent;transition:background .15s}
.ch-resize:hover::after,.ch-resize:focus-visible::after,body.ch-resizing .ch-resize::after{background:var(--accent)}
body.ch-resizing{cursor:col-resize;user-select:none}
.ch-head h1{min-width:60px}
@media (max-width:760px){.ch-shell{grid-template-columns:1fr}.ch-resize{display:none}}
/* The Ibex logo at the top centre of the page, where the studio has it (studio header: 64px, logo 40px) */
.ch-head{position:relative;min-height:64px;padding-block:8px}
.ch-logo{position:fixed;top:6px;left:50%;transform:translateX(-50%);z-index:30;display:inline-flex;line-height:0;text-decoration:none}
.ch-head h1{flex:0 1 auto;max-width:calc(50vw - var(--ch-side,270px) - 70px);margin-inline-end:auto}
@media (max-width:760px){
 .ch-head{min-height:60px}
 .ch-logo{top:5px}
 .ch-logo .rk-logo{--rk-h:36px!important}
 .ch-head h1{max-width:calc(50vw - 100px)}
 body.ch-side-open .ch-logo{visibility:hidden}
}
/* Model guide as a plain tooltip: grey, a highlighted border, no chips (nothing in it looks clickable) */
.ch-guide-tip{width:min(260px,calc(100vw - 16px));padding:9px 11px;border:1.5px solid var(--accent);border-radius:9px;background:#3b3e44;color:#eceef1;box-shadow:0 6px 18px rgba(0,0,0,.25);font-size:12px;line-height:1.5;cursor:default;user-select:none}
.ch-guide-tip b{font-size:13px;color:#fff;margin-bottom:2px}
.ch-guide-sec{margin-top:6px;font-size:10px;color:#b3b8c0}
.ch-guide-tags{display:block;margin-top:1px}
.ch-guide-tags span{display:inline;padding:0;border-radius:0;background:none;font-size:12px;font-weight:600;color:#fff}
.ch-guide-tags span:not(:last-child)::after{content:" · ";font-weight:400;color:#b3b8c0}
.ch-guide-tip p{margin:4px 0 0;color:#dfe2e6}
.ch-guide-tip p.muted{color:#b3b8c0}
/* One logo only (the centred one at the top); the chat title stays a small heading in Persian too */
.ch-side-top{justify-content:flex-start}
body.chat-page .ch-head h1{font-size:16px!important;font-weight:600;line-height:1.5}
/* ---- Header (minimal), like the studio's: one bar across the page with the ☰ and the Ibex logo at the start, the
   chat's title in the middle and the language at the end. The ☰ opens and closes the chat list. ---- */
body.chat-page{display:flex;flex-direction:column}
body.chat-page .ch-shell{flex:1;min-height:0;height:auto}
body.chat-page .ch-head{position:relative;z-index:20;display:flex;align-items:center;gap:12px;min-height:60px;padding:8px 16px;border-bottom:1px solid var(--line);background:var(--bg)}
.ch-head-start,.ch-head-end{display:flex;align-items:center;gap:6px;flex:1 1 0;min-width:max-content}
.ch-head-end{justify-content:flex-end}
body.chat-page .ch-menu{display:inline-grid;place-items:center;width:38px;height:38px;flex:none}
body.chat-page .ch-logo{position:static;transform:none;display:inline-flex;line-height:0;padding:0 4px;border-radius:10px;text-decoration:none}
body.chat-page .ch-logo:hover{opacity:.85}
body.chat-page .ch-head h1{flex:0 1 auto;max-width:min(560px,46vw);margin:0;text-align:center;font-size:15px!important;color:var(--muted)}
body.ch-side-closed .ch-shell{grid-template-columns:minmax(0,1fr)}
body.ch-side-closed .ch-side{display:none}
@media (max-width:760px){
 body.chat-page .ch-head{min-height:56px;padding:6px 10px;gap:8px}
 body.chat-page .ch-head h1{max-width:40vw;font-size:14px!important}
 body.chat-page .ch-logo .rk-logo{--rk-h:32px!important}
 body.ch-side-open .ch-logo{visibility:visible}
 body.ch-side-closed .ch-side{display:flex}   /* the desktop choice does not hide the phone's slide-in list */
}
/* Files the AI writes (```file:name.ext): a file card with Download; any code block can be downloaded too. */
.ch-code-btns{display:flex;justify-content:flex-end;gap:4px;margin-bottom:4px}
.ch-code-btns .ch-copy{position:static}
.ch-file-out{border:1px solid var(--line);border-radius:12px;background:var(--surface);padding:8px}
.ch-file-out pre{max-height:260px}
.ch-file-head{display:flex;align-items:center;justify-content:space-between;gap:10px;padding:2px 4px 8px}
.ch-file-name{font-weight:600;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
/* Videos and sounds made from the chat */
.ch-vid{display:block;width:min(560px,100%);max-height:70vh;border-radius:12px;border:1px solid var(--line);background:#000;margin-bottom:6px}
.ch-aud{display:block;width:min(420px,100%);margin-bottom:6px}
/* Plan cards (chat_studio.py): the model, its price, a pricier one to compare, the prompt, Hybrid and Make it */
.ch-plan{border:1px solid var(--accent);border-radius:14px;background:var(--surface);padding:12px 14px;margin:.6em 0;max-width:640px}
.ch-plan.pending{border-style:dashed}
.ch-plan-head{display:flex;flex-wrap:wrap;align-items:center;gap:8px}
.ch-plan-badge{background:var(--accent);color:var(--accent-ink);border-radius:999px;font-size:11px;font-weight:700;padding:2px 8px}
.ch-plan-price{margin-inline-start:auto;font-weight:700;white-space:nowrap}
.ch-plan-set{margin-top:4px}
.ch-plan-compare{margin:.5em 0;font-size:13px}
.ch-plan-save{color:#2e9e5b}
.ch-plan-label{display:block;margin-top:6px}
.ch-plan-prompt{width:100%;min-height:96px;font-size:13px;margin-top:4px}
.ch-plan-size{margin-top:2px}
.ch-plan-size.over{color:#d9534f}
.ch-plan-hybrid{display:flex;flex-wrap:wrap;align-items:center;gap:6px 8px;margin-top:8px;padding:8px;border-radius:10px;background:var(--raised)}
.ch-plan-hybrid .select{max-width:100%;min-width:0;flex:1 1 200px}
.ch-plan-hybrid small{flex-basis:100%}
.ch-plan-acts{display:flex;flex-wrap:wrap;gap:6px;margin-top:10px}
