/* Connect asks first: Connect only, or Connect and follow up (js/connect-dlg.js). A card over the page, under the
   Message templates card (90) so templates open on top of it. */
html.cn-on{overflow:hidden}
#cn-dlg{position:fixed;inset:0;z-index:80;display:flex;align-items:center;justify-content:center;padding:24px;
  font-family:"Circular Std","Figtree",ui-sans-serif,system-ui,sans-serif,"Noto Sans Thai";color:var(--ink)}
#cn-dlg.hide{display:none}
#cn-dlg svg.cn-i{width:15px;height:15px;flex:none;fill:none;stroke:currentColor;stroke-width:2;stroke-linecap:round;stroke-linejoin:round}
#cn-dlg .cn-bg{position:absolute;inset:0;background:rgb(0 0 0 / .45)}
#cn-dlg .cn-card{position:relative;width:min(640px,100%);max-height:min(90vh,860px);display:flex;flex-direction:column;overflow:hidden;background:var(--surface);
  border:1px solid var(--line);border-radius:16px;box-shadow:var(--pop);animation:cn-in .16s ease-out}
@keyframes cn-in{from{transform:translateY(8px);opacity:0}to{transform:none;opacity:1}}
@media (prefers-reduced-motion:reduce){#cn-dlg .cn-card,#cn-dlg .cn-spin{animation:none}}
#cn-dlg .cn-hd{display:flex;align-items:flex-start;gap:10px;padding:16px 14px 14px 20px;border-bottom:1px solid var(--line)}
#cn-dlg .cn-ht{flex:1;min-width:0}
#cn-dlg .cn-hd h2{margin:0;font-size:16px;line-height:22px;font-weight:700;overflow-wrap:anywhere}
#cn-dlg .cn-co{display:block;font-size:13px;color:var(--ink3);margin-top:2px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
#cn-dlg .cn-x{width:32px;height:32px;display:grid;place-items:center;border-radius:50%;border:1px solid var(--line);background:var(--surface);color:var(--ink2);cursor:pointer;flex:none}
#cn-dlg .cn-x:hover{background:var(--hover);color:var(--ink)}
#cn-dlg .cn-card.wide{width:min(1080px,100%)}
#cn-dlg .cn-mid{flex:1;min-height:0;display:flex}
#cn-dlg .cn-b{flex:1;min-width:0;min-height:0;overflow-y:auto;overscroll-behavior:contain;padding:16px 20px;display:grid;gap:14px;align-content:start}
/* Write with AI: the chat on the card's right */
#cn-dlg .cn-chat{width:400px;flex:none;display:flex;flex-direction:column;min-height:0;border-left:1px solid var(--line);background:var(--bg,var(--surface))}
#cn-dlg .cn-chat.hide{display:none}
#cn-dlg .cn-chd{display:flex;align-items:flex-start;gap:10px;padding:14px 12px 12px 16px;border-bottom:1px solid var(--line)}
#cn-dlg .cn-chb{width:30px;height:30px;border-radius:9px;display:grid;place-items:center;flex:none;color:#fff;background:linear-gradient(135deg,var(--brand),oklch(.55 .15 262))}
#cn-dlg .cn-chb .cn-i{width:16px;height:16px}
#cn-dlg .cn-cht{flex:1;min-width:0;display:grid;gap:2px;align-self:center}
#cn-dlg .cn-cht b{font-size:14px;font-weight:700}
#cn-dlg .cn-x.sm{width:28px;height:28px}
#cn-dlg .cn-log{flex:1;min-height:0;overflow-y:auto;overscroll-behavior:contain;padding:14px 16px 16px;display:flex;flex-direction:column;gap:10px}
#cn-dlg .cn-hello{margin:auto 0;font-size:13px;line-height:19px;color:var(--ink3);text-align:center;padding:0 12px}
#cn-dlg .cn-msg{max-width:88%;padding:9px 12px;border-radius:14px;font-size:13.5px;line-height:19px;overflow-wrap:anywhere;white-space:pre-wrap}
#cn-dlg .cn-msg.me{align-self:flex-end;background:var(--brand);color:#fff;border-bottom-right-radius:4px}
#cn-dlg .cn-msg.ai{align-self:flex-start;background:var(--surface);border:1px solid var(--line);border-bottom-left-radius:4px;display:flex;flex-wrap:wrap;align-items:center;gap:6px 8px}
#cn-dlg .cn-msg.ai .cn-spin{margin-right:2px}
#cn-dlg .cn-msg.err{color:var(--bad);border-color:color-mix(in oklab,var(--bad) 35%,var(--line))}
#cn-dlg .cn-undo{display:inline-flex;align-items:center;gap:4px;height:24px;padding:0 8px;border-radius:7px;border:1px solid var(--line2);background:var(--surface);color:var(--ink2);font:inherit;font-size:12px;cursor:pointer}
#cn-dlg .cn-undo:hover{background:var(--hover);color:var(--ink)}
#cn-dlg .cn-undo .cn-i{width:13px;height:13px}
#cn-dlg .cn-undone{font-size:12px;color:var(--ink3)}
#cn-dlg .cn-sug{display:flex;flex-wrap:wrap;gap:6px;padding:0 16px 10px}
#cn-dlg .cn-sug:empty{display:none}
#cn-dlg .cn-sg{height:28px;padding:0 10px;border-radius:999px;border:1px solid color-mix(in oklab,var(--brand) 40%,var(--line2));background:var(--surface);color:var(--brand-d);font:inherit;font-size:12.5px;cursor:pointer}
#cn-dlg .cn-sg:hover{background:var(--tint)}
#cn-dlg .cn-chf{display:flex;gap:8px;align-items:flex-end;padding:10px 12px 12px 16px;border-top:1px solid var(--line)}
#cn-dlg .cn-chin{flex:1;min-width:0;resize:none;max-height:120px;border:1px solid var(--line2);border-radius:12px;padding:9px 11px;background:var(--surface);color:var(--ink);font:inherit;font-size:13.5px;line-height:19px;outline:none}
#cn-dlg .cn-chin:focus{border-color:var(--brand)}
#cn-dlg .cn-chin::placeholder{color:var(--ink3)}
#cn-dlg .cn-chgo{width:38px;height:38px;padding:0;border-radius:11px;flex:none}
#cn-dlg .cn-btn.ai.on{background:var(--tint);border-color:var(--brand)}
@media (max-width:900px){
  #cn-dlg .cn-mid{flex-direction:column}
  #cn-dlg .cn-chat{width:auto;height:min(46vh,420px);border-left:0;border-top:1px solid var(--line)}
  #cn-dlg .cn-chd{padding:10px 10px 8px 16px}
  #cn-dlg .cn-sug{flex-wrap:nowrap;overflow-x:auto;scrollbar-width:none;padding-bottom:8px}
  #cn-dlg .cn-sg{flex:none}
}
/* the two choices */
#cn-dlg .cn-opts{display:grid;grid-template-columns:1fr 1fr;gap:10px}
#cn-dlg .cn-opt{position:relative;display:flex;gap:10px;align-items:center;padding:12px 14px;border:1px solid var(--line2);border-radius:12px;cursor:pointer;background:var(--surface)}
#cn-dlg .cn-opt:hover{background:var(--hover)}
#cn-dlg .cn-opt.on{border-color:var(--brand);background:var(--tint);box-shadow:0 0 0 1px var(--brand) inset}
#cn-dlg .cn-opt input{position:absolute;opacity:0;width:1px;height:1px}
#cn-dlg .cn-opt:has(input:focus-visible){outline:2px solid var(--brand);outline-offset:2px}
#cn-dlg .cn-oi{width:30px;height:30px;border-radius:50%;display:grid;place-items:center;flex:none;background:var(--chip);color:var(--ink2)}
#cn-dlg .cn-opt.on .cn-oi{background:var(--brand);color:#fff}
#cn-dlg .cn-ot{display:grid;gap:2px;min-width:0}
#cn-dlg .cn-ot b{font-size:14px;font-weight:600}
/* what a choice does sits in its (i) (RM.tip), right after its name */
#cn-dlg .cn-ot b .rm-tip,#cn-dlg .cn-cht b .rm-tip,#cn-dlg .cn-lim .rm-tip{margin-left:2px}
/* the follow-up */
#cn-dlg .cn-fu{display:grid;gap:10px}
#cn-dlg .cn-fu.hide{display:none}
#cn-dlg .cn-row,#cn-dlg .cn-tools{display:flex;align-items:center;gap:8px;flex-wrap:wrap}
#cn-dlg .cn-sp{flex:1}
#cn-dlg .cn-pf{display:flex;align-items:center;gap:8px;font-size:13px;color:var(--ink2);min-width:0}
#cn-dlg .cn-sel{height:34px;max-width:220px;min-width:0;border:1px solid var(--line2);border-radius:10px;background:var(--surface);padding:0 10px;font-size:13px;color:var(--ink)}
#cn-dlg .cn-btn{display:inline-flex;align-items:center;justify-content:center;gap:6px;height:34px;padding:0 13px;border-radius:10px;border:1px solid var(--line2);
  background:var(--surface);color:var(--ink);font:inherit;font-size:13px;font-weight:600;white-space:nowrap;cursor:pointer}
#cn-dlg .cn-btn:hover:not(:disabled){background:var(--hover)}
#cn-dlg .cn-btn:disabled{opacity:.5;cursor:default}
#cn-dlg .cn-btn.pri{background:var(--brand);border-color:var(--brand);color:#fff}
#cn-dlg .cn-btn.pri:hover:not(:disabled){background:var(--brand-h)}
#cn-dlg .cn-btn.sm{height:30px;padding:0 11px;font-size:12.5px;border-radius:8px}
#cn-dlg .cn-btn.ai{color:var(--brand-d);border-color:color-mix(in oklab,var(--brand) 45%,var(--line2))}
/* the message box draws its own frame (js/msg-editor.js); the plain textarea fallback gets one here */
#cn-dlg .cn-ed textarea{width:100%;border:1px solid var(--line2);border-radius:12px;padding:10px 12px;outline:0;background:var(--surface);resize:vertical;font-size:14px;line-height:21px}
#cn-dlg .cn-tags{display:flex;flex-wrap:wrap;gap:6px}
#cn-dlg .cn-tag{height:26px;padding:0 10px;border-radius:999px;border:1px solid var(--line2);background:var(--surface);color:var(--ink2);font:inherit;font-size:12px;cursor:pointer}
#cn-dlg .cn-tag:hover{background:var(--hover);color:var(--ink)}
#cn-dlg .cn-files{display:flex;flex-wrap:wrap;gap:6px}
#cn-dlg .cn-files:has(.cn-chips:empty):has(.cn-att:empty){display:none}
#cn-dlg .cn-chips{display:contents}
#cn-dlg .cn-chip{display:inline-flex;align-items:center;gap:6px;max-width:100%;height:30px;padding:0 6px 0 10px;border-radius:8px;background:var(--chip);font-size:12.5px}
#cn-dlg .cn-chip span{overflow:hidden;text-overflow:ellipsis;white-space:nowrap;min-width:0}
#cn-dlg .cn-chip small{color:var(--ink3)}
#cn-dlg .cn-chip button{width:22px;height:22px;display:grid;place-items:center;border:0;background:none;color:var(--ink3);border-radius:6px;cursor:pointer}
#cn-dlg .cn-chip button:hover{background:var(--hover);color:var(--ink)}
#cn-dlg .cn-savef{display:flex;gap:8px;align-items:center}
#cn-dlg .cn-savef.hide{display:none}
#cn-dlg .cn-in{flex:1;min-width:0;height:34px;border:1px solid var(--line2);border-radius:10px;background:var(--surface);padding:0 12px;font-size:13px;color:var(--ink);outline:none}
#cn-dlg .cn-in:focus{border-color:var(--brand)}
#cn-dlg .cn-note{font-size:12.5px;color:var(--ink2);min-height:0}
#cn-dlg .cn-note:empty{display:none}
#cn-dlg .cn-lim{font-size:12.5px;color:var(--ink3)}
#cn-dlg .cn-ft{display:flex;align-items:center;gap:8px;padding:12px 20px;border-top:1px solid var(--line)}
#cn-dlg .cn-err{flex:1;min-width:0;font-size:12.5px;color:var(--bad)}
#cn-dlg .cn-err.soft{color:var(--ink3)}
#cn-dlg .cn-spin{display:inline-block;width:13px;height:13px;flex:none;border-radius:50%;border:1.5px solid var(--brand);border-top-color:transparent;animation:spin .8s linear infinite}
#cn-dlg .cn-btn.pri .cn-spin{border-color:#fff;border-top-color:transparent}
@media (max-width:640px){
  #cn-dlg{padding:0}
  #cn-dlg .cn-card{width:100%;height:100%;max-height:none;border:0;border-radius:0}
  #cn-dlg .cn-opts{grid-template-columns:1fr}
  #cn-dlg .cn-b{padding:14px 16px}
  #cn-dlg .cn-ft{padding:12px 16px;flex-wrap:wrap}
  #cn-dlg .cn-err{flex:1 1 100%}
  #cn-dlg .cn-ft .cn-btn{flex:1}
  #cn-dlg .cn-pf{flex:1 1 100%}
  #cn-dlg .cn-sel{flex:1;max-width:none}
  #cn-dlg .cn-row .cn-sp{display:none}
}

/* ── A phone (Max 2026-10-20: "Make it like real monile app UI now its confusing to look at on phone") ──
   A sheet from the bottom: its Cancel and Send stay where the thumb is while the choices above grow (the follow-up's box);
   a grab bar, round top corners, the home bar cleared, 16 px inputs, finger-high buttons. */
@media (max-width:800px),(pointer:coarse) and (max-width:950px){
  #cn-dlg{padding:0;align-items:flex-end}
  #cn-dlg .cn-bg{background:rgb(0 0 0 / .4)}
  #cn-dlg .cn-card,#cn-dlg .cn-card.wide{width:100%;height:auto;max-height:94vh;max-height:94dvh;border:0;border-radius:18px 18px 0 0;animation:cn-up .22s ease-out}
  @keyframes cn-up{from{transform:translateY(24px);opacity:.6}to{transform:none;opacity:1}}
  @media (prefers-reduced-motion:reduce){#cn-dlg .cn-card{animation:none}}
  #cn-dlg .cn-card::before{content:"";align-self:center;flex:none;width:36px;height:4px;margin:8px 0 0;border-radius:9999px;background:var(--line2)}
  #cn-dlg .cn-hd{padding:8px 8px 12px 16px;align-items:center}
  #cn-dlg .cn-x{width:44px;height:44px}
  #cn-dlg .cn-x.sm{width:40px;height:40px}
  #cn-dlg .cn-opts{grid-template-columns:1fr}
  #cn-dlg .cn-opt{min-height:56px}
  #cn-dlg .cn-b{padding:14px 16px}
  #cn-dlg .cn-sel{height:44px;max-width:none;flex:1;font-size:16px}
  #cn-dlg .cn-pf{flex:1 1 100%}
  #cn-dlg .cn-btn{height:44px;font-size:14px}
  #cn-dlg .cn-btn.sm{height:40px}
  #cn-dlg .cn-tag{height:40px;padding:0 14px;font-size:13px}
  #cn-dlg .cn-in,#cn-dlg .cn-chin{font-size:16px}
  #cn-dlg .cn-in{height:44px}
  #cn-dlg .cn-ed textarea{font-size:16px}
  #cn-dlg .cn-chip{height:36px}
  #cn-dlg .cn-sg{height:40px;padding:0 14px;font-size:13px}
  #cn-dlg .cn-chat{height:min(46vh,420px)}
  #cn-dlg .cn-ft{padding:12px 16px calc(12px + env(safe-area-inset-bottom));flex-wrap:wrap}
  #cn-dlg .cn-err{flex:1 1 100%}
  #cn-dlg .cn-ft .cn-btn{flex:1}
}
