/* ChatG chat app (/chat). Needs tokens.css + md.css. Logical properties throughout (RTL: ar, he, fa). */
*, *::before, *::after { box-sizing: border-box; }
html:has(> body.cg-body) { height: 100%; -webkit-text-size-adjust: 100%; }
.cg-body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--text); font-family: var(--font); font-size: 15px; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; }
.cg-body button, .cg-body input, .cg-body select, .cg-body textarea { font-family: inherit; }
.cg-body :focus-visible { outline: none; box-shadow: var(--ring); }
.cg-i { flex: none; display: block; }
.cg-grow { flex: 1 1 auto; }
.cg-body [hidden] { display: none !important; }
.cg-skip { position: absolute; inset-inline-start: 12px; top: -60px; z-index: 200; padding: 8px 14px; border-radius: 10px; background: var(--text); color: var(--bg); text-decoration: none; }
.cg-skip:focus { top: 12px; }
.cg-muted { color: var(--muted); line-height: 1.6; margin: 0 0 14px; }
.cg-noscript { position: fixed; inset: auto 0 0; padding: 12px; text-align: center; background: var(--coral); color: #fff; }

/* ---------- layout ---------- */
.cg-app { display: flex; height: 100vh; height: 100dvh; overflow: hidden; }
.cg-side {
  width: 284px; flex: none; display: flex; flex-direction: column; gap: 2px; padding: 10px 10px 8px;
  background: var(--bg-soft); border-inline-end: 1px solid var(--border);
  transition: margin-inline-start .26s var(--ease), visibility .26s;
}
.cg-app[data-side="closed"] .cg-side { margin-inline-start: -284px; visibility: hidden; }
.cg-main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; position: relative; }

/* ---------- sidebar ---------- */
.cg-side-top { display: flex; align-items: center; justify-content: space-between; padding: 2px 2px 10px 8px; }
.cg-brand { display: inline-flex; align-items: center; gap: 9px; color: var(--text); text-decoration: none; font-weight: 700; font-size: 18.5px; letter-spacing: -.025em; border-radius: 10px; padding: 4px 2px; }
.cg-brand .cg-mark { flex: none; width: 28px; height: 28px; display: block; }
.cg-top-brand .cg-mark { width: 26px; height: 26px; }
.cg-ib { width: 36px; height: 36px; flex: none; display: inline-grid; place-items: center; border: 0; border-radius: 10px; background: transparent; color: var(--text-soft); cursor: pointer; transition: background .15s, color .15s; }
.cg-ib:hover { background: var(--surface-2); color: var(--text); }
.cg-ib:disabled { opacity: .38; cursor: default; background: transparent; }
.cg-ib-sm { width: 30px; height: 30px; border-radius: 8px; }
.cg-newbtn {
  display: flex; align-items: center; gap: 10px; height: 42px; padding: 0 12px; width: 100%;
  border: 1px solid var(--border); border-radius: 13px; background: var(--surface); color: var(--text);
  font-size: 14px; font-weight: 550; cursor: pointer; box-shadow: var(--shadow-sm); transition: border-color .15s, box-shadow .15s;
}
.cg-newbtn:hover { border-color: var(--border-strong); box-shadow: var(--shadow); }
.cg-newbtn .cg-i { color: var(--accent); }
.cg-kbd { margin-inline-start: auto; font: 500 11px var(--font-mono); color: var(--muted); letter-spacing: .02em; white-space: nowrap; }
.cg-search { position: relative; display: flex; align-items: center; margin-top: 8px; }
.cg-search > .cg-i { position: absolute; inset-inline-start: 11px; color: var(--muted); pointer-events: none; }
.cg-search input {
  width: 100%; height: 38px; border: 1px solid transparent; border-radius: 11px; background: var(--surface-2); color: var(--text);
  font-size: 14px; padding-inline: 34px 54px; outline: none; transition: border-color .15s, background .15s;
}
.cg-search input::placeholder { color: var(--muted); }
.cg-search input:focus { background: var(--surface); border-color: var(--border-strong); box-shadow: var(--ring); }
.cg-search input::-webkit-search-cancel-button { cursor: pointer; }
.cg-search .cg-kbd { position: absolute; inset-inline-end: 10px; pointer-events: none; }
.cg-search input:focus ~ .cg-kbd, .cg-search input:not(:placeholder-shown) ~ .cg-kbd { display: none; }
.cg-side-nav { display: flex; flex-direction: column; gap: 1px; margin: 8px 0 4px; }
.cg-navbtn {
  display: flex; align-items: center; gap: 11px; width: 100%; min-width: 0; height: 38px; padding: 0 10px; border: 0; border-radius: 10px;
  background: transparent; color: var(--text-soft); font-size: 14px; font-weight: 500; text-align: start; cursor: pointer; transition: background .15s, color .15s;
}
.cg-navbtn span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cg-navbtn:hover, .cg-navbtn[aria-expanded="true"] { background: var(--surface-2); color: var(--text); }

.cg-hist { flex: 1 1 auto; min-height: 60px; overflow-y: auto; margin: 0 -10px; padding: 0 10px 8px; scrollbar-width: thin; }
.cg-hgroup { position: sticky; top: 0; z-index: 1; padding: 14px 10px 6px; background: var(--bg-soft); color: var(--muted); font-size: 12px; font-weight: 600; letter-spacing: .01em; }
.cg-hitem { position: relative; border-radius: 10px; margin: 1px 0; transition: background .12s; }
.cg-hitem:hover { background: var(--surface-2); }
.cg-hitem.is-active { background: var(--surface); box-shadow: var(--shadow-sm); }
.cg-hlink { display: flex; flex-wrap: wrap; align-items: center; gap: 0 6px; padding: 8px 10px; padding-inline-end: 34px; color: var(--text-soft); text-decoration: none; font-size: 14px; border-radius: 10px; min-width: 0; }
.cg-hitem.is-active .cg-hlink { color: var(--text); font-weight: 550; }
.cg-htitle { flex: 1 1 0; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cg-hpin { color: var(--accent); }
.cg-hsnip { flex-basis: 100%; min-width: 0; margin-top: 2px; font-size: 12px; font-weight: 400; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cg-hist mark { background: color-mix(in srgb, var(--coral) 28%, transparent); color: inherit; border-radius: 3px; padding: 0 1px; }
.cg-hmore { position: absolute; inset-inline-end: 4px; top: 50%; translate: 0 -50%; width: 28px; height: 28px; display: grid; place-items: center; border: 0; border-radius: 8px; background: transparent; color: var(--muted); cursor: pointer; opacity: 0; transition: opacity .12s, background .12s; }
.cg-hitem:hover .cg-hmore, .cg-hitem.is-active .cg-hmore, .cg-hmore:focus-visible, .cg-hmore[aria-expanded="true"] { opacity: 1; }
.cg-hmore:hover, .cg-hmore[aria-expanded="true"] { background: var(--border); color: var(--text); }
.cg-hrename { width: 100%; height: 36px; padding: 0 10px; border: 1px solid var(--accent); border-radius: 10px; background: var(--surface); color: var(--text); font-size: 14px; outline: none; box-shadow: var(--ring); }
.cg-hempty { display: flex; align-items: center; gap: 6px; padding: 14px 10px; margin: 0; color: var(--muted); font-size: 13px; line-height: 1.5; }

.cg-side .ad-slot { flex: none; margin: 6px -2px 0; padding-top: 8px; border-top: 1px solid var(--border); min-height: 268px; text-align: center; overflow: hidden; }
.cg-side .ad-label { display: block; margin-bottom: 4px; color: var(--muted); font-size: 10.5px; letter-spacing: .06em; text-transform: uppercase; }
.cg-side-foot { flex: none; display: flex; gap: 2px; padding-top: 6px; margin-top: 4px; border-top: 1px solid var(--border); }
.cg-side-foot .cg-navbtn { flex: 1 1 0; }
@media (max-height: 640px) { .cg-side .ad-slot { display: none; } }

/* ---------- top bar ---------- */
.cg-top { flex: none; display: flex; align-items: center; gap: 4px; height: 58px; padding: 0 12px; position: relative; z-index: 3; }
.cg-top-brand { display: none; padding: 4px; }
.cg-app[data-side="closed"] .cg-top-brand { display: inline-flex; }
.cg-app[data-side="open"] #cg-expand .cg-i-desk { display: none; }
.cg-app[data-side="open"] #cg-expand { display: none; }
.cg-i-mob { display: none; }
.cg-model { display: inline-flex; align-items: center; gap: 8px; height: 40px; padding: 0 10px 0 8px; border: 0; border-radius: 12px; background: transparent; color: var(--text); font-size: 15.5px; font-weight: 620; letter-spacing: -.01em; cursor: pointer; min-width: 0; transition: background .15s; }
.cg-model:hover, .cg-model[aria-expanded="true"] { background: var(--surface-2); }
.cg-model .cg-model-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cg-model > .cg-i { color: var(--muted); }
.cg-credits { display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 12px; margin-inline-end: 4px; border-radius: var(--radius-pill); background: var(--accent-soft); color: var(--accent-ink); font-size: 12.5px; font-weight: 550; white-space: nowrap; }
.cg-credits.is-low { background: color-mix(in srgb, var(--coral) 15%, transparent); color: #C2410C; }
[data-theme="dark"] .cg-credits.is-low { color: #FF9C80; }
.cg-credits-n { display: none; font-variant-numeric: tabular-nums; }

/* model badges */
.cg-badge { --s: 22px; --h: 240; width: var(--s); height: var(--s); flex: none; display: inline-grid; place-items: center; border-radius: calc(var(--s) * .32); background: hsl(var(--h) 90% 94%); color: hsl(var(--h) 65% 36%); font-size: calc(var(--s) * .42); font-weight: 700; letter-spacing: -.03em; line-height: 1; }
[data-theme="dark"] .cg-badge { background: hsl(var(--h) 35% 20%); color: hsl(var(--h) 85% 76%); }
.cg-badge-mono, [data-theme="dark"] .cg-badge-mono { background: var(--surface-2); color: var(--text); }
.cg-badge-auto, [data-theme="dark"] .cg-badge-auto { background: var(--surface); border: 1px solid var(--border); }

/* ---------- thread ---------- */
.cg-scroll { flex: 1 1 auto; overflow-y: auto; overflow-x: hidden; overscroll-behavior: contain; scrollbar-gutter: stable both-edges; }
.cg-scroll .cg-thread { max-width: 800px; margin: 0 auto; padding: 18px 24px 40px; }
.cg-thread.is-empty { min-height: 100%; justify-content: center; padding-bottom: 24px; }
.cg-msg { animation: cg-rise .22s var(--ease) both; }
.cg-msg-ai.is-streaming .cg-md > :last-child:not(.cg-code):not(.cg-table)::after { content: ""; display: inline-block; width: 8px; height: 8px; margin-inline-start: 6px; border-radius: 50%; background: var(--accent-grad); vertical-align: middle; animation: cg-pulse 1s ease-in-out infinite; }
.cg-msg-ai.is-streaming .cg-md > ul:last-child::after, .cg-msg-ai.is-streaming .cg-md > ol:last-child::after { display: none !important; }
.cg-thinking { display: flex; align-items: center; gap: 10px; height: 30px; color: var(--muted); font-size: 14px; }
.cg-thinking > span:last-child { background: linear-gradient(90deg, var(--muted) 0%, var(--text) 50%, var(--muted) 100%); background-size: 200% 100%; -webkit-background-clip: text; background-clip: text; color: transparent; animation: cg-shimmer 1.6s linear infinite; }
.cg-dots { display: inline-flex; gap: 4px; }
.cg-dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); animation: cg-dot 1.2s ease-in-out infinite; }
.cg-dots i:nth-child(2) { animation-delay: .15s; background: color-mix(in srgb, var(--accent) 50%, var(--accent-2)); }
.cg-dots i:nth-child(3) { animation-delay: .3s; background: var(--accent-2); }
.cg-actions { display: flex; align-items: center; gap: 2px; min-height: 30px; margin-top: 6px; opacity: 0; transition: opacity .15s; }
.cg-msg-user .cg-actions { justify-content: flex-end; margin-top: 4px; }
.cg-msg:hover .cg-actions, .cg-msg:focus-within .cg-actions, .cg-msg-ai.is-last .cg-actions { opacity: 1; }
.cg-act { width: 30px; height: 30px; display: inline-grid; place-items: center; border: 0; border-radius: 8px; background: transparent; color: var(--muted); cursor: pointer; transition: background .12s, color .12s; }
.cg-act:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }
.cg-act:disabled { opacity: .35; cursor: default; }
.cg-act.is-done { color: var(--success); }
.cg-vers { display: inline-flex; align-items: center; color: var(--muted); font: 500 12.5px var(--font-mono); font-variant-numeric: tabular-nums; }
.cg-vnum { min-width: 30px; text-align: center; }
.cg-mlabel { margin-inline-start: 6px; padding: 2px 8px; border-radius: var(--radius-pill); color: var(--muted); font-size: 12px; }
[dir="rtl"] .cg-flip { transform: scaleX(-1); }
.cg-tag { display: inline-flex; align-items: center; gap: 6px; margin-top: 10px; padding: 3px 10px; border: 1px solid var(--border); border-radius: var(--radius-pill); color: var(--muted); font-size: 12px; }
.cg-card { display: flex; gap: 12px; align-items: flex-start; margin-top: 4px; padding: 14px 16px; border-radius: 16px; border: 1px solid var(--border); font-size: 14.5px; line-height: 1.55; }
.cg-card p { margin: 0 0 10px; }
.cg-card p:last-child { margin: 0; }
.cg-card-ic { flex: none; width: 36px; height: 36px; display: grid; place-items: center; border-radius: 11px; }
.cg-card-err { background: color-mix(in srgb, var(--danger) 6%, var(--surface)); border-color: color-mix(in srgb, var(--danger) 25%, transparent); }
.cg-card-err .cg-card-ic { background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger); }
.cg-card-limit { background: linear-gradient(135deg, color-mix(in srgb, var(--accent) 8%, var(--surface)), color-mix(in srgb, var(--accent-2) 8%, var(--surface))); border-color: color-mix(in srgb, var(--accent) 22%, transparent); }
.cg-card-limit .cg-card-ic { background: var(--accent-grad); color: #fff; }
.cg-msg-user.is-editing { align-items: stretch; }
.cg-edit { width: 100%; border: 1px solid var(--border-strong); border-radius: 20px; background: var(--surface); padding: 12px; box-shadow: var(--shadow); }
.cg-edit textarea { width: 100%; min-height: 60px; border: 0; outline: none; resize: none; background: transparent; color: var(--text); font-size: var(--cg-fs); line-height: 1.6; }
.cg-edit-bar { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }

/* welcome */
.cg-welcome { text-align: center; padding: 24px 0 8px; animation: cg-rise .35s var(--ease) both; }
.cg-w-mark { position: relative; width: 120px; height: 120px; margin: 0 auto 18px; display: grid; place-items: center; }
.cg-w-mark::before { content: ""; position: absolute; inset: 6px; border-radius: 50%; background: radial-gradient(circle at 35% 35%, color-mix(in srgb, var(--accent) 45%, transparent), transparent 62%), radial-gradient(circle at 70% 70%, color-mix(in srgb, var(--accent-2) 45%, transparent), transparent 60%); filter: blur(18px); opacity: .75; }
.cg-w-mark img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; border-radius: 36px; opacity: .55; }
.cg-w-logo { position: relative; width: 72px; height: 72px; display: grid; place-items: center; border-radius: 22px; background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-lg); }
.cg-w-icon { width: 68px; height: 68px; margin: 0 auto 16px; display: grid; place-items: center; border-radius: 22px; background: var(--accent-soft); color: var(--accent-ink); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 18%, transparent); }
.cg-w-title { margin: 0 0 8px; font-size: clamp(25px, 3.4vw, 33px); font-weight: 680; letter-spacing: -.03em; line-height: 1.15; }
.cg-w-text { max-width: 520px; margin: 0 auto 28px; color: var(--muted); font-size: 15.5px; line-height: 1.6; }
.cg-suggest { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; max-width: 700px; margin: 0 auto; text-align: start; }
.cg-sugg { display: flex; flex-direction: column; gap: 4px; padding: 14px 16px; border: 1px solid var(--border); border-radius: 16px; background: var(--surface); color: var(--text); text-align: start; cursor: pointer; transition: transform .16s var(--ease), border-color .16s, box-shadow .16s; }
.cg-sugg:hover { transform: translateY(-2px); border-color: var(--border-strong); box-shadow: var(--shadow); }
.cg-sugg b { font-size: 14.5px; font-weight: 600; }
.cg-sugg span { color: var(--muted); font-size: 13.5px; line-height: 1.45; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.cg-sugg:not(:has(b)) span { color: var(--text-soft); -webkit-line-clamp: 3; }

/* ---------- composer ---------- */
.cg-dock { flex: none; position: relative; width: 100%; max-width: 800px; margin: 0 auto; padding: 0 24px calc(12px + env(safe-area-inset-bottom)); }
.cg-down { position: absolute; top: -50px; left: 50%; translate: -50% 0; z-index: 2; width: 38px; height: 38px; display: grid; place-items: center; border: 1px solid var(--border); border-radius: 50%; background: var(--surface); color: var(--text); box-shadow: var(--shadow); cursor: pointer; animation: cg-rise .2s var(--ease); }
.cg-down[hidden] { display: none; }
.cg-chip { display: inline-flex; align-items: center; gap: 8px; max-width: 100%; height: 32px; margin: 0 0 8px; padding-block: 0; padding-inline: 10px 4px; border-radius: var(--radius-pill); background: var(--accent-soft); color: var(--accent-ink); font-size: 13px; font-weight: 550; }
.cg-chip[hidden] { display: none; }
.cg-chip > span:nth-child(2) { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cg-chip button { width: 24px; height: 24px; display: grid; place-items: center; border: 0; border-radius: 50%; background: transparent; color: inherit; cursor: pointer; }
.cg-chip button:hover { background: color-mix(in srgb, var(--accent) 16%, transparent); }
.cg-composer { position: relative; padding: 10px 10px 8px; padding-inline-start: 16px; border: 1px solid var(--border-strong); border-radius: 26px; background: var(--surface); box-shadow: var(--shadow); transition: border-color .18s, box-shadow .18s; }
.cg-composer:focus-within { border-color: color-mix(in srgb, var(--accent) 45%, var(--border-strong)); box-shadow: var(--shadow), 0 0 0 4px var(--accent-soft); }
#cg-input { display: block; width: 100%; min-height: 30px; max-height: 40vh; padding: 6px 4px 4px; border: 0; outline: none; resize: none; background: transparent; color: var(--text); font-size: var(--cg-fs); line-height: 1.55; scrollbar-width: thin; }
#cg-input:focus-visible { box-shadow: none; }
#cg-input::placeholder { color: var(--muted); }
.cg-comp-bar { display: flex; align-items: center; gap: 6px; margin-top: 6px; }
.cg-tb { display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 12px; border: 1px solid var(--border); border-radius: var(--radius-pill); background: transparent; color: var(--text-soft); font-size: 13px; font-weight: 500; cursor: pointer; transition: background .15s, color .15s, border-color .15s; }
.cg-tb:hover { background: var(--surface-2); color: var(--text); }
.cg-tb-ic { width: 34px; padding: 0; justify-content: center; border-color: transparent; }
.cg-tb[aria-pressed="true"] { color: var(--accent-ink); background: var(--accent-soft); }
.cg-count { font: 500 12px var(--font-mono); color: var(--muted); font-variant-numeric: tabular-nums; }
.cg-count.is-over { color: var(--danger); }
.cg-send { width: 38px; height: 38px; flex: none; display: grid; place-items: center; border: 0; border-radius: 50%; background: var(--accent-grad); color: #fff; cursor: pointer; box-shadow: 0 4px 14px -4px color-mix(in srgb, var(--accent) 70%, transparent); transition: transform .12s, opacity .15s, background .15s; }
.cg-send:hover:not(:disabled) { transform: scale(1.05); }
.cg-send:active:not(:disabled) { transform: scale(.96); }
.cg-send:disabled { background: var(--surface-2); color: var(--muted); box-shadow: none; cursor: default; }
.cg-send.is-stop { background: var(--text); color: var(--bg); box-shadow: none; }
.cg-disclaimer { margin: 8px 0 0; color: var(--muted); font-size: 12px; text-align: center; line-height: 1.4; }

/* ---------- popover menus ---------- */
.cg-menu { position: fixed; z-index: 120; min-width: 220px; max-width: min(360px, calc(100vw - 16px)); padding: 6px; border: 1px solid var(--border); border-radius: 16px; background: var(--surface); color: var(--text); box-shadow: var(--shadow-lg); animation: cg-pop .14s var(--ease); }
.cg-menu-list { max-height: min(440px, 62vh); overflow-y: auto; scrollbar-width: thin; }
.cg-menu-item { display: flex; align-items: center; gap: 11px; width: 100%; padding: 8px 10px; border: 0; border-radius: 10px; background: transparent; color: var(--text); font-size: 14px; text-align: start; text-decoration: none; cursor: pointer; }
.cg-menu-item[hidden] { display: none; }
.cg-menu-item:hover, .cg-menu-item:focus-visible { background: var(--surface-2); box-shadow: none; outline: none; }
.cg-menu-item > .cg-i { color: var(--muted); }
.cg-menu-item.is-danger, .cg-menu-item.is-danger > .cg-i { color: var(--danger); }
.cg-menu-txt { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }
.cg-menu-txt > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cg-menu-txt small { margin-top: 1px; color: var(--muted); font-size: 12.5px; line-height: 1.35; }
.cg-menu-check { width: 18px; flex: none; color: var(--accent); }
.cg-menu-item.is-checked { background: var(--accent-soft); }
.cg-menu-sep { height: 1px; margin: 5px 6px; background: var(--border); }
.cg-menu-head, .cg-menu-title { padding: 6px 10px 4px; color: var(--muted); font-size: 11.5px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; }
.cg-menu-models { width: 340px; }
.cg-menu-models .cg-menu-item { padding: 9px 10px; }
.cg-menu-lang { width: 260px; }
.cg-menu-search { position: relative; margin: 2px 2px 6px; }
.cg-menu-search .cg-i { position: absolute; inset-inline-start: 10px; top: 50%; translate: 0 -50%; color: var(--muted); }
.cg-menu-search input { width: 100%; height: 36px; padding-inline: 32px 10px; border: 1px solid var(--border); border-radius: 10px; background: var(--bg-soft); color: var(--text); font-size: 14px; outline: none; }
.cg-menu-search input:focus { border-color: var(--accent); }
.cg-lang-code { color: var(--muted); font: 500 11px var(--font-mono); text-transform: uppercase; }

/* ---------- dialogs ---------- */
.cg-dlg { width: 100%; max-width: min(560px, calc(100vw - 24px)); max-height: min(88vh, 780px); padding: 0; border: 0; background: transparent; color: var(--text); overflow: visible; }
.cg-dlg::backdrop { background: rgba(9, 10, 15, .42); backdrop-filter: blur(3px); }
.cg-dlg[open] { animation: cg-dlg .2s var(--ease); }
.cg-dlg-lg { max-width: min(880px, calc(100vw - 24px)); }
.cg-dlg-sm { max-width: min(470px, calc(100vw - 24px)); }
.cg-dlg-box { display: flex; flex-direction: column; max-height: min(88vh, 780px); overflow: hidden; border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface); box-shadow: var(--shadow-lg); }
.cg-dlg-head { flex: none; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 14px 6px 22px; padding-inline: 22px 14px; }
.cg-dlg-head[hidden] { display: none; }
.cg-dlg-head h2 { margin: 0; font-size: 18px; font-weight: 660; letter-spacing: -.015em; }
.cg-dlg-body { padding: 10px 22px 22px; overflow-y: auto; overscroll-behavior: contain; }
.cg-dlg-sm .cg-dlg-head[hidden] + .cg-dlg-body { padding-top: 22px; }
.cg-dlg-actions { display: flex; align-items: center; gap: 8px; margin-top: 18px; justify-content: flex-end; flex-wrap: wrap; }
.cg-confirm-text { margin: 0; font-size: 15px; line-height: 1.6; }
.cg-dlg-tools { display: flex; gap: 10px; align-items: center; margin-bottom: 6px; flex-wrap: wrap; }
.cg-field-search { position: relative; flex: 1 1 240px; }
.cg-field-search .cg-i { position: absolute; inset-inline-start: 12px; top: 50%; translate: 0 -50%; color: var(--muted); pointer-events: none; }
.cg-field-search input { width: 100%; height: 40px; padding-inline: 36px 12px; border: 1px solid var(--border-strong); border-radius: 12px; background: var(--bg); color: var(--text); font-size: 14px; outline: none; }
.cg-field-search input:focus { border-color: var(--accent); box-shadow: var(--ring); }
.cg-sec { display: flex; align-items: center; gap: 8px; margin: 20px 0 10px; font-size: 13px; font-weight: 650; color: var(--text-soft); letter-spacing: .01em; }

/* buttons */
.cg-btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px; height: 38px; padding: 0 16px; border: 1px solid var(--border-strong); border-radius: var(--radius-pill); background: var(--surface); color: var(--text); font-size: 14px; font-weight: 550; white-space: nowrap; cursor: pointer; text-decoration: none; transition: background .15s, border-color .15s, color .15s, transform .12s; }
.cg-btn:hover { background: var(--surface-2); }
.cg-btn:active { transform: scale(.98); }
.cg-btn:disabled { opacity: .55; cursor: default; }
.cg-btn-sm { height: 32px; padding: 0 13px; font-size: 13px; }
.cg-btn-primary { background: var(--accent); border-color: transparent; color: var(--on-accent); }
.cg-btn-primary:hover { background: color-mix(in srgb, var(--accent) 88%, #000); }
.cg-btn-ghost { background: transparent; border-color: transparent; }
.cg-btn-danger { background: var(--danger); border-color: transparent; color: #fff; }
.cg-btn-danger:hover { background: color-mix(in srgb, var(--danger) 88%, #000); }
.cg-btn-danger-ghost { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 35%, transparent); background: transparent; }
.cg-btn-danger-ghost:hover { background: color-mix(in srgb, var(--danger) 8%, transparent); }
.cg-btn.is-done { color: var(--success); }
.cg-btn-primary.is-done { color: #fff; background: var(--success); }

/* assistants */
.cg-agrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 10px; }
.cg-acard { display: flex; align-items: flex-start; gap: 12px; padding: 14px; border: 1px solid var(--border); border-radius: 16px; background: var(--surface); cursor: pointer; transition: border-color .15s, box-shadow .15s, transform .15s var(--ease); }
.cg-acard[hidden] { display: none; }
.cg-acard:hover { border-color: var(--border-strong); box-shadow: var(--shadow); transform: translateY(-1px); }
.cg-aicon { flex: none; width: 40px; height: 40px; display: grid; place-items: center; border-radius: 12px; background: var(--accent-soft); color: var(--accent-ink); }
.cg-acard-txt { flex: 1 1 auto; min-width: 0; }
.cg-acard-txt b { display: block; font-size: 14.5px; font-weight: 620; }
.cg-acard-txt p { margin: 3px 0 0; color: var(--muted); font-size: 13px; line-height: 1.45; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.cg-acard-act { flex: none; display: flex; align-items: center; gap: 2px; align-self: center; }
.cg-aform .cg-sec { margin-top: 0; }
.cg-field { display: flex; flex-direction: column; gap: 6px; margin: 0 0 14px; padding: 0; border: 0; min-width: 0; }
.cg-field > span, .cg-field > legend { font-size: 13px; font-weight: 600; color: var(--text-soft); padding: 0; margin-bottom: 6px; }
.cg-field > span { margin-bottom: 0; }
.cg-field input, .cg-field textarea { width: 100%; padding: 10px 12px; border: 1px solid var(--border-strong); border-radius: 12px; background: var(--bg); color: var(--text); font-size: 14.5px; line-height: 1.5; outline: none; resize: vertical; }
.cg-field fieldset input + input, .cg-field input + input { margin-top: 8px; }
.cg-field input:focus, .cg-field textarea:focus { border-color: var(--accent); box-shadow: var(--ring); }
.cg-field-count { align-self: flex-end; color: var(--muted); font: 500 11.5px var(--font-mono); }
.cg-icons { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 16px; }
.cg-icopt input { position: absolute; opacity: 0; pointer-events: none; }
.cg-icopt span { width: 38px; height: 38px; display: grid; place-items: center; border: 1px solid var(--border); border-radius: 11px; color: var(--text-soft); cursor: pointer; transition: all .12s; }
.cg-icopt input:checked + span { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-ink); }
.cg-icopt input:focus-visible + span { box-shadow: var(--ring); }

/* prompts */
.cg-pcats { display: flex; gap: 6px; overflow-x: auto; padding: 8px 0 12px; margin: 0 -22px; padding-inline: 22px; scrollbar-width: none; }
.cg-pcats::-webkit-scrollbar { display: none; }
.cg-pcat { flex: none; height: 32px; padding: 0 13px; border: 1px solid var(--border); border-radius: var(--radius-pill); background: transparent; color: var(--text-soft); font-size: 13px; font-weight: 500; cursor: pointer; white-space: nowrap; text-transform: capitalize; }
.cg-pcat:hover { background: var(--surface-2); }
.cg-pcat[aria-selected="true"] { background: var(--text); border-color: var(--text); color: var(--bg); }
.cg-plist { display: grid; gap: 8px; }
.cg-pcard { display: flex; align-items: flex-start; gap: 14px; padding: 14px 16px; border: 1px solid var(--border); border-radius: 14px; }
.cg-pcard:hover { border-color: var(--border-strong); }
.cg-pcard-txt { flex: 1 1 auto; min-width: 0; }
.cg-pcard-txt b { display: block; font-size: 14.5px; font-weight: 620; }
.cg-pcard-txt p { margin: 4px 0 8px; color: var(--text-soft); font-size: 13.5px; line-height: 1.5; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.cg-tags { display: flex; flex-wrap: wrap; gap: 5px; }
.cg-tags span { padding: 2px 8px; border-radius: var(--radius-pill); background: var(--surface-2); color: var(--muted); font-size: 11.5px; }
.cg-tags .cg-tagc { background: var(--accent-soft); color: var(--accent-ink); text-transform: capitalize; }

/* settings */
.cg-set-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px 0; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.cg-set-l { font-size: 14.5px; font-weight: 550; }
.cg-seg { display: inline-flex; padding: 3px; border-radius: 12px; background: var(--surface-2); gap: 2px; }
.cg-seg input { position: absolute; opacity: 0; pointer-events: none; }
.cg-seg span { display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 12px; border-radius: 9px; color: var(--text-soft); font-size: 13px; font-weight: 550; cursor: pointer; transition: background .15s, color .15s; }
.cg-seg input:checked + span { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }
.cg-seg input:focus-visible + span { box-shadow: var(--ring); }
.cg-switch { appearance: none; -webkit-appearance: none; position: relative; width: 44px; height: 26px; margin: 0; border-radius: 13px; background: var(--border-strong); cursor: pointer; transition: background .18s; flex: none; }
.cg-switch::after { content: ""; position: absolute; top: 3px; inset-inline-start: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .25); transition: inset-inline-start .18s var(--ease); }
.cg-switch:checked { background: var(--accent); }
.cg-switch:checked::after { inset-inline-start: 21px; }
.cg-select { height: 36px; max-width: 220px; padding: 0 10px; border: 1px solid var(--border-strong); border-radius: 10px; background: var(--surface); color: var(--text); font-size: 14px; }
.cg-keys { margin: 0; display: grid; gap: 2px; }
.cg-keys div { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 6px 0; font-size: 14px; }
.cg-keys dt { color: var(--text-soft); }
.cg-keys dd { margin: 0; display: flex; gap: 4px; }
kbd { display: inline-grid; place-items: center; min-width: 24px; height: 24px; padding: 0 6px; border: 1px solid var(--border-strong); border-bottom-width: 2px; border-radius: 6px; background: var(--bg-soft); color: var(--text-soft); font: 500 11.5px var(--font-mono); }
.cg-kbd { display: inline; min-width: 0; height: auto; padding: 0; border: 0; background: none; }
.cg-set-btns { display: flex; flex-wrap: wrap; gap: 8px; }

/* share */
.cg-share-hero { width: 48px; height: 48px; display: grid; place-items: center; margin-bottom: 12px; border-radius: 14px; background: var(--accent-soft); color: var(--accent-ink); }
.cg-share-link { display: flex; gap: 8px; margin-top: 4px; }
.cg-share-link input { flex: 1 1 auto; min-width: 0; height: 40px; padding: 0 12px; border: 1px solid var(--border-strong); border-radius: 12px; background: var(--bg-soft); color: var(--text); font: 13.5px var(--font-mono); outline: none; }
.cg-form-err { margin: 6px 0 0; color: var(--danger); font-size: 14px; }

/* toasts */
.cg-toasts { position: fixed; z-index: 300; left: 50%; bottom: calc(110px + env(safe-area-inset-bottom)); translate: -50% 0; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; }
.cg-toast { max-width: min(440px, calc(100vw - 32px)); padding: 10px 16px; border-radius: 12px; background: var(--text); color: var(--bg); font-size: 14px; line-height: 1.45; box-shadow: var(--shadow-lg); opacity: 0; translate: 0 8px; transition: opacity .2s, translate .2s var(--ease); }
.cg-toast.is-in { opacity: 1; translate: 0 0; }
.cg-toast-err { background: var(--danger); color: #fff; }

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  .cg-side { position: fixed; z-index: 80; inset-block: 0; inset-inline-start: 0; width: min(304px, 86vw); margin: 0 !important; visibility: visible; transform: translateX(-102%); transition: transform .26s var(--ease); box-shadow: var(--shadow-lg); padding-top: calc(10px + env(safe-area-inset-top)); }
  [dir="rtl"] .cg-side { transform: translateX(102%); }
  .cg-app.is-drawer .cg-side { transform: none; }
  .cg-scrim:not([hidden]) { position: fixed; inset: 0; z-index: 70; background: rgba(9, 10, 15, .45); animation: cg-fade .2s; }
  .cg-side .ad-slot { display: none; }
  .cg-app[data-side] #cg-expand { display: inline-grid; }
  #cg-expand .cg-i-desk { display: none; }
  #cg-expand .cg-i-mob { display: block; }
  .cg-top-brand { display: none !important; }
  .cg-kbd, .cg-hint { display: none; }
  .cg-hmore { opacity: 1; }
  .cg-top { height: 54px; padding: 0 8px; }
  .cg-scroll .cg-thread { padding: 12px 16px 32px; }
  .cg-dock { padding-inline: 12px; }
  .cg-msg-ai { grid-template-columns: minmax(0, 1fr); }
  .cg-msg-ai .cg-avatar { display: none; }
}
@media (max-width: 640px) {
  .cg-credits-full { display: none; }
  .cg-credits-n { display: inline; }
  .cg-credits { padding: 0 10px; }
  .cg-tb:not(.cg-tb-ic) { width: 34px; padding: 0; justify-content: center; }
  .cg-tb span { display: none; }
  .cg-suggest { grid-template-columns: minmax(0, 1fr); }
  .cg-suggest .cg-sugg:nth-child(n+4) { display: none; }
  .cg-w-mark { width: 92px; height: 92px; margin-bottom: 12px; }
  .cg-w-logo { width: 60px; height: 60px; border-radius: 18px; }
  .cg-w-text { margin-bottom: 20px; font-size: 14.5px; }
  .cg-bubble { max-width: 90%; }
  .cg-actions { opacity: 1; }
  .cg-dlg, .cg-dlg-lg, .cg-dlg-sm { max-width: 100%; max-height: 92dvh; margin: auto 0 0; }
  .cg-dlg-box { max-height: 92dvh; border-radius: 22px 22px 0 0; border-bottom: 0; padding-bottom: env(safe-area-inset-bottom); }
  .cg-dlg[open] { animation: cg-sheet .24s var(--ease); }
  .cg-dlg-body { padding-inline: 16px; }
  .cg-dlg-head { padding-inline: 16px 10px; }
  .cg-pcats { margin-inline: -16px; padding-inline: 16px; }
  .cg-agrid { grid-template-columns: minmax(0, 1fr); }
  .cg-share-link { flex-direction: column; }
  .cg-menu-models { width: calc(100vw - 16px); }
}
@media (hover: none) { .cg-actions { opacity: 1; } .cg-hmore { opacity: 1; } }

/* ---------- motion ---------- */
@keyframes cg-rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes cg-pop { from { opacity: 0; transform: scale(.97) translateY(-4px); } to { opacity: 1; transform: none; } }
@keyframes cg-dlg { from { opacity: 0; transform: scale(.97) translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes cg-sheet { from { transform: translateY(40px); opacity: .4; } to { transform: none; opacity: 1; } }
@keyframes cg-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes cg-dot { 0%, 80%, 100% { transform: scale(.6); opacity: .5; } 40% { transform: scale(1); opacity: 1; } }
@keyframes cg-pulse { 0%, 100% { transform: scale(.7); opacity: .6; } 50% { transform: scale(1); opacity: 1; } }
@keyframes cg-shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) {
  .cg-body *, .cg-body *::before, .cg-body *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
}
