/* AI Tutor chat — ChatGPT-style layout (src/app/ai/chat/page.tsx).
   All classes are cg-* so nothing here collides with the legacy ai.css rules. */

.cg-app {
  --cg-bg: #212121;
  --cg-side: #171717;
  --cg-raised: #2f2f2f;
  --cg-hover: #2a2a2a;
  --cg-line: #383838;
  --cg-text: #ececec;
  --cg-muted: #b4b4b4;
  --cg-faint: #8f8f8f;
  --cg-accent: #48aaff;
  --cg-brand: #a78bfa;
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  height: calc(100dvh - var(--header-h, 120px));
  min-height: 420px;
  width: 100%;
  overflow: hidden;
  background: var(--cg-bg);
  color: var(--cg-text);
  font-family: var(--font-inter, Inter), ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  position: relative;
}
.cg-app button { font: inherit; color: inherit; }
.cg-app :focus-visible { outline: 2px solid var(--cg-accent); outline-offset: 2px; }
.cg-loading { display: grid; place-items: center; min-height: 60vh; color: #8b949e; font-size: 1.5rem; }

/* ---------------------------------------------------------------- sidebar */
.cg-sidebar {
  display: flex; flex-direction: column; min-height: 0; min-width: 0;
  background: var(--cg-side); padding: 8px 8px 0; gap: 4px;
}
.cg-app--wide { grid-template-columns: 0 minmax(0, 1fr); }
.cg-app--wide .cg-sidebar { visibility: hidden; padding: 0; }
.cg-side-top { display: flex; justify-content: space-between; padding: 2px 2px 4px; }
.cg-icon-btn {
  display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: 8px;
  background: none; border: 0; cursor: pointer; color: var(--cg-muted); font-size: 1rem;
}
.cg-icon-btn:hover { background: var(--cg-hover); color: var(--cg-text); }
.cg-new {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 10px; border-radius: 8px;
  background: none; border: 0; cursor: pointer; text-align: left; font-size: .9rem; font-weight: 500;
}
.cg-new:hover { background: var(--cg-hover); }
.cg-search {
  display: flex; align-items: center; gap: 8px; padding: 0 10px; height: 36px; border-radius: 8px;
  background: transparent; color: var(--cg-faint); border: 1px solid transparent;
}
.cg-search:focus-within { border-color: var(--cg-line); background: #1f1f1f; }
.cg-search input {
  flex: 1; min-width: 0; background: none; border: 0; outline: none; color: var(--cg-text); font: inherit; font-size: .88rem;
}
.cg-search input::placeholder { color: var(--cg-faint); }
.cg-history { flex: 1; overflow-y: auto; min-height: 0; padding: 6px 0 12px; scrollbar-width: thin; scrollbar-color: #3a3a3a transparent; }
.cg-group { margin-bottom: 14px; }
.cg-group-label { font-size: .75rem; font-weight: 600; color: var(--cg-faint); padding: 6px 10px; }
.cg-conv { position: relative; display: flex; align-items: center; border-radius: 8px; }
.cg-conv a {
  flex: 1; min-width: 0; padding: 8px 10px; color: var(--cg-text); text-decoration: none; font-size: .88rem;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.cg-conv:hover, .cg-conv.active { background: var(--cg-raised); }
.cg-conv-actions { display: none; gap: 2px; padding-right: 4px; }
.cg-conv:hover .cg-conv-actions, .cg-conv.active .cg-conv-actions, .cg-conv:focus-within .cg-conv-actions { display: flex; }
.cg-conv-actions button {
  width: 28px; height: 28px; border-radius: 6px; border: 0; background: none; cursor: pointer; color: var(--cg-muted); font-size: .78rem;
}
.cg-conv-actions button:hover { background: #3a3a3a; color: var(--cg-text); }
.cg-conv-actions button[aria-pressed="true"] { color: var(--cg-brand); }
.cg-skel { height: 14px; margin: 12px 10px; border-radius: 6px; background: linear-gradient(90deg, #262626, #303030, #262626); background-size: 200% 100%; animation: cg-shimmer 1.4s infinite; }
@keyframes cg-shimmer { to { background-position: -200% 0; } }
.cg-empty { color: var(--cg-faint); font-size: .85rem; padding: 8px 10px; margin: 0; }
.cg-side-foot {
  display: flex; align-items: center; gap: 10px; padding: 10px 6px 12px; border-top: 1px solid #262626;
}
.cg-avatar {
  flex: none; width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center;
  background: #10a37f; color: #fff; font-weight: 700; font-size: .85rem;
}
.cg-user { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.cg-user-name { font-size: .88rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cg-plan { font-size: .74rem; color: var(--cg-muted); text-decoration: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cg-plan-up { color: var(--cg-brand); font-weight: 600; margin-left: 4px; }
.cg-plan:hover .cg-plan-up { text-decoration: underline; }
.cg-plan--pro { color: #6ee7b7; }
.cg-plan--warn { color: #fbbf24; }

/* ------------------------------------------------------------------- main */
.cg-main { position: relative; display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--cg-bg); }
.cg-top { display: flex; align-items: center; gap: 4px; height: 56px; padding: 0 10px; flex: none; }
.cg-menu-btn, .cg-top-new { display: none; }
.cg-top-new { margin-left: auto; }
.cg-agent-wrap { position: relative; }
.cg-agent-pill {
  display: inline-flex; align-items: center; gap: 8px; height: 40px; padding: 0 12px; border-radius: 10px;
  background: none; border: 0; cursor: pointer; font-size: 1.05rem; font-weight: 600; color: var(--cg-text); max-width: 70vw;
}
.cg-agent-pill span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cg-agent-pill > i:first-child { color: var(--cg-brand); font-size: .95rem; }
.cg-agent-pill:hover, .cg-agent-pill[aria-expanded="true"] { background: var(--cg-hover); }
.cg-chev { font-size: .7rem; color: var(--cg-faint); }
.cg-agent-menu {
  position: absolute; top: calc(100% + 6px); left: 0; z-index: 50;
  width: min(420px, calc(100vw - 24px)); max-height: min(560px, calc(100dvh - var(--header-h, 120px) - 90px));
  display: flex; flex-direction: column; background: #2b2b2b; border: 1px solid var(--cg-line); border-radius: 16px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, .5); overflow: hidden;
}
.cg-agent-head { padding: 14px 14px 10px; border-bottom: 1px solid var(--cg-line); display: flex; flex-direction: column; gap: 2px; }
.cg-agent-head strong { font-size: .95rem; }
.cg-agent-head > span { font-size: .78rem; color: var(--cg-muted); margin-bottom: 8px; }
.cg-search--menu { background: #212121; border-color: var(--cg-line); }
.cg-agent-list { overflow-y: auto; padding: 6px; scrollbar-width: thin; scrollbar-color: #444 transparent; }
.cg-agent-item {
  width: 100%; display: flex; align-items: center; gap: 12px; padding: 9px 10px; border-radius: 10px;
  background: none; border: 0; cursor: pointer; text-align: left;
}
.cg-agent-item:hover, .cg-agent-item:focus-visible { background: #383838; }
.cg-agent-item.active { background: #333; }
.cg-agent-icon {
  flex: none; width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center;
  background: #383838; color: var(--cg-brand); font-size: .9rem;
}
.cg-agent-copy { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.cg-agent-copy span { font-size: .9rem; font-weight: 500; }
.cg-agent-copy small { font-size: .76rem; color: var(--cg-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cg-agent-check { color: var(--cg-text); font-size: .85rem; }
.cg-alert {
  display: flex; justify-content: space-between; gap: 12px; margin: 0 16px; padding: 8px 12px; border-radius: 10px;
  background: rgba(248, 81, 73, .14); color: #ffa198; font-size: .85rem;
}
.cg-alert button { background: none; border: 0; cursor: pointer; }

/* ----------------------------------------------------------------- thread */
.cg-scroll { flex: 1; min-height: 0; overflow-y: auto; scrollbar-width: thin; scrollbar-color: #424242 transparent; overscroll-behavior: contain; }
.cg-thread { max-width: 768px; margin: 0 auto; padding: 8px 20px 32px; display: flex; flex-direction: column; gap: 28px; }
.cg-welcome { text-align: center; padding: 8vh 0 12px; }
.cg-welcome h1 { font-size: clamp(1.5rem, 3.4vw, 2rem); font-weight: 600; margin: 0 0 10px; color: var(--cg-text); letter-spacing: -.01em; }
.cg-welcome p { color: var(--cg-muted); margin: 0 auto 28px; max-width: 520px; font-size: .95rem; line-height: 1.6; }
.cg-welcome em { color: var(--cg-text); font-style: normal; }
.cg-suggest { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; text-align: left; }
.cg-card {
  display: flex; flex-direction: column; gap: 2px; padding: 14px; border-radius: 14px; cursor: pointer;
  background: none; border: 1px solid var(--cg-line); text-align: left; transition: background .15s;
}
.cg-card:hover { background: var(--cg-hover); }
.cg-card i { color: var(--cg-brand); margin-bottom: 8px; font-size: 1rem; }
.cg-card-title { font-size: .9rem; font-weight: 500; color: var(--cg-text); }
.cg-card-sub { font-size: .8rem; color: var(--cg-faint); }

.cg-msg--user { display: flex; justify-content: flex-end; }
.cg-bubble {
  max-width: min(70%, 560px); background: var(--cg-raised); padding: 10px 16px; border-radius: 20px;
  white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.6; font-size: .97rem;
}
.cg-msg--ai { display: flex; gap: 14px; align-items: flex-start; }
.cg-ai-avatar {
  flex: none; width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center;
  border: 1px solid var(--cg-line); color: var(--cg-brand); font-size: .78rem; margin-top: 2px;
}
.cg-ai-avatar--live { animation: cg-pulse 1.6s ease-in-out infinite; }
@keyframes cg-pulse { 50% { box-shadow: 0 0 0 5px rgba(167, 139, 250, .18); } }
.cg-ai-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 12px; }
.cg-md { font-size: .97rem; line-height: 1.7; color: var(--cg-text); overflow-wrap: anywhere; }
.cg-msg--err .cg-md { color: #ffb4ab; }
.cg-streaming .md > :last-child::after {
  content: ""; display: inline-block; width: 9px; height: 9px; margin-left: 4px; border-radius: 50%;
  background: var(--cg-text); vertical-align: middle; animation: cg-blink 1s infinite;
}
@keyframes cg-blink { 50% { opacity: .2; } }
.cg-thinking { display: flex; align-items: center; gap: 10px; color: var(--cg-muted); font-size: .92rem; min-height: 30px; }
.cg-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--cg-text); animation: cg-breathe 1.2s ease-in-out infinite; }
@keyframes cg-breathe { 50% { transform: scale(.6); opacity: .5; } }
.cg-actions { display: flex; align-items: center; gap: 2px; margin-left: -6px; color: var(--cg-faint); }
.cg-actions button {
  width: 32px; height: 32px; border-radius: 8px; border: 0; background: none; cursor: pointer; color: var(--cg-faint); font-size: .85rem;
}
.cg-actions button:hover { background: var(--cg-hover); color: var(--cg-text); }
.cg-actions button.on { color: var(--cg-accent); }
.cg-meta { font-size: .76rem; margin-left: 8px; color: var(--cg-faint); }
.cg-upgrade {
  align-self: flex-start; display: inline-flex; gap: 8px; align-items: center; padding: 9px 14px; border-radius: 999px;
  background: #7c3aed; color: #fff; text-decoration: none; font-weight: 600; font-size: .88rem;
}
.cg-upgrade:hover { background: #6d28d9; }

/* Sources */
.cg-sources { display: flex; flex-wrap: wrap; gap: 8px; }
.cg-source {
  display: flex; align-items: center; gap: 8px; max-width: 240px; padding: 6px 10px 6px 6px; border-radius: 10px;
  background: #262626; border: 1px solid #333; color: var(--cg-text); text-decoration: none;
}
.cg-source:hover { background: #2e2e2e; }
.cg-source-n { flex: none; width: 22px; height: 22px; border-radius: 6px; background: #3a3a3a; display: grid; place-items: center; font-size: .72rem; font-weight: 600; }
.cg-source-body { min-width: 0; display: flex; flex-direction: column; }
.cg-source-title { font-size: .8rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cg-source-site { font-size: .72rem; color: var(--cg-faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ----------------------------------------------------------- rich media */
.cg-media { display: flex; flex-direction: column; gap: 12px; }
.cg-gallery { display: grid; gap: 6px; border-radius: 14px; overflow: hidden; grid-template-columns: repeat(3, 1fr); grid-auto-rows: 150px; }
.cg-gallery.n1 { grid-template-columns: 1fr; grid-auto-rows: 300px; max-width: 460px; }
.cg-gallery.n2 { grid-template-columns: repeat(2, 1fr); grid-auto-rows: 220px; }
.cg-gallery.n4 { grid-template-columns: repeat(2, 1fr); }
.cg-gallery.n3 > :first-child, .cg-gallery.n5 > :first-child, .cg-gallery.n6 > :first-child { grid-row: span 2; }
.cg-gallery.n3 { grid-template-columns: 2fr 1fr; }
.cg-thumb { position: relative; padding: 0; border: 0; cursor: zoom-in; background: #f4f4f4; overflow: hidden; }
.cg-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform .25s; }
.cg-thumb:hover img { transform: scale(1.04); }
.cg-thumb-n {
  position: absolute; left: 8px; top: 8px; min-width: 22px; height: 22px; padding: 0 6px; border-radius: 6px;
  background: rgba(0, 0, 0, .7); color: #fff; font-size: .74rem; font-weight: 700; display: grid; place-items: center;
}
.cg-videos { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.cg-video { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.cg-video-frame { position: relative; aspect-ratio: 16 / 9; border-radius: 12px; overflow: hidden; background: #000; }
.cg-video-frame iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.cg-video-poster { position: absolute; inset: 0; padding: 0; border: 0; cursor: pointer; background: #000; }
.cg-video-poster img { width: 100%; height: 100%; object-fit: cover; opacity: .9; }
.cg-play {
  position: absolute; left: 50%; top: 50%; translate: -50% -50%; width: 54px; height: 38px; border-radius: 11px;
  background: rgba(255, 0, 0, .92); color: #fff; display: grid; place-items: center; font-size: 1rem; transition: transform .15s;
}
.cg-video-poster:hover .cg-play { transform: scale(1.08); }
.cg-duration { position: absolute; right: 6px; bottom: 6px; padding: 1px 6px; border-radius: 4px; background: rgba(0, 0, 0, .8); color: #fff; font-size: .72rem; font-weight: 600; }
.cg-video-meta { display: flex; flex-direction: column; text-decoration: none; color: var(--cg-text); }
.cg-video-title { font-size: .85rem; font-weight: 500; line-height: 1.35; display: -webkit-box; -webkit-line-clamp: 2; line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.cg-video-meta:hover .cg-video-title { text-decoration: underline; }
.cg-video-channel { font-size: .76rem; color: var(--cg-faint); }
.cg-video-channel i { color: #ff4e45; }
.cg-media-empty { font-size: .85rem; color: var(--cg-muted); }
.cg-media-empty a { color: var(--cg-accent); }
.cg-lightbox { position: fixed; inset: 0; z-index: 5000; background: rgba(0, 0, 0, .86); display: grid; place-items: center; padding: 20px; }
.cg-lightbox-inner { max-width: min(1000px, 100%); max-height: 100%; display: flex; flex-direction: column; gap: 10px; }
.cg-lightbox-inner img { max-width: 100%; max-height: calc(100dvh - 130px); object-fit: contain; border-radius: 10px; background: #f4f4f4; align-self: center; }
.cg-lightbox-bar { display: flex; justify-content: space-between; align-items: center; gap: 12px; color: #eee; }
.cg-lightbox-bar div:first-child { display: flex; flex-direction: column; min-width: 0; font-size: .88rem; }
.cg-lightbox-bar span { font-size: .76rem; color: #bbb; }
.cg-lightbox-actions { display: flex; gap: 6px; }
.cg-lightbox-actions button, .cg-lightbox-actions a {
  width: 38px; height: 38px; border-radius: 50%; border: 0; background: #333; color: #fff; display: grid; place-items: center; cursor: pointer; text-decoration: none;
}
.cg-lightbox-actions button:hover, .cg-lightbox-actions a:hover { background: #4a4a4a; }

/* ----------------------------------------------------------------- charts */
.cg-chart { margin: 14px 0; padding: 14px; border: 1px solid var(--cg-line); border-radius: 14px; background: #1b1b1b; }
.cg-chart-pending { color: var(--cg-muted); font-size: .88rem; display: flex; gap: 8px; align-items: center; }
.cg-chart-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 8px; flex-wrap: wrap; }
.cg-chart-head figcaption { font-weight: 600; font-size: .92rem; }
.cg-seg { display: inline-flex; background: #2a2a2a; border-radius: 8px; padding: 2px; }
.cg-seg button { border: 0; background: none; padding: 4px 10px; border-radius: 6px; font-size: .78rem; color: var(--cg-muted); cursor: pointer; }
.cg-seg button[aria-pressed="true"] { background: #404040; color: var(--cg-text); }
.cg-chart-plot { position: relative; }
.cg-chart-svg { width: 100%; height: auto; display: block; overflow: visible; }
.cg-chart-svg rect, .cg-chart-svg circle, .cg-pie path { cursor: crosshair; }
.cg-chart-svg rect:hover, .cg-pie path:hover { opacity: .85; }
.cg-axis { fill: #a3a3a3; font-size: 11px; font-family: inherit; }
.cg-chart-legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-bottom: 6px; font-size: .8rem; color: var(--cg-muted); }
.cg-chart-legend span, .cg-pie-keys li { display: inline-flex; align-items: center; gap: 6px; }
.cg-chart-legend i, .cg-pie-keys i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.cg-pie { display: flex; align-items: center; gap: 24px; flex-wrap: wrap; }
.cg-pie-keys { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; font-size: .86rem; color: var(--cg-text); }
.cg-pie-keys b { margin-left: 6px; color: var(--cg-muted); font-weight: 600; }
.cg-tip {
  position: absolute; pointer-events: none; z-index: 2; padding: 5px 9px; border-radius: 7px; white-space: nowrap;
  background: #f5f5f5; color: #111; font-size: .78rem; font-weight: 500; box-shadow: 0 4px 14px rgba(0, 0, 0, .4);
}

/* --------------------------------------------------------------- composer */
.cg-jump {
  position: absolute; left: 50%; bottom: 150px; translate: -50% 0; width: 34px; height: 34px; border-radius: 50%;
  background: var(--cg-bg); border: 1px solid var(--cg-line); color: var(--cg-text); cursor: pointer; z-index: 5;
  box-shadow: 0 4px 12px rgba(0, 0, 0, .4);
}
.cg-composer-wrap { flex: none; padding: 0 20px 10px; }
.cg-composer {
  max-width: 768px; margin: 0 auto; background: var(--cg-raised); border-radius: 26px; padding: 10px 10px 8px 16px;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, .04), 0 8px 24px rgba(0, 0, 0, .25);
}
.cg-composer textarea {
  display: block; width: 100%; resize: none; background: none; border: 0; outline: none; color: var(--cg-text);
  font: inherit; font-size: 1rem; line-height: 1.5; padding: 6px 4px 4px; max-height: 200px; min-height: 28px;
}
.cg-composer textarea::placeholder { color: var(--cg-faint); }
.cg-composer-bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 6px; }
.cg-tools { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; min-width: 0; margin-left: -8px; }
.cg-tool {
  display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 12px; border-radius: 999px;
  background: none; border: 1px solid transparent; cursor: pointer; font-size: .84rem; color: var(--cg-muted);
}
.cg-tool:hover { background: #3a3a3a; color: var(--cg-text); }
.cg-tool.on { color: var(--cg-accent); background: rgba(72, 170, 255, .12); border-color: rgba(72, 170, 255, .25); }
.cg-tool--icon { width: 34px; padding: 0; justify-content: center; border-color: var(--cg-line); }
.cg-create { position: relative; }
.cg-create-menu {
  position: absolute; bottom: calc(100% + 8px); left: 0; z-index: 40; width: 230px; padding: 6px;
  background: #2b2b2b; border: 1px solid var(--cg-line); border-radius: 14px; box-shadow: 0 12px 32px rgba(0, 0, 0, .5);
}
.cg-create-menu p { margin: 4px 8px 6px; font-size: .74rem; color: var(--cg-faint); }
.cg-create-menu button {
  width: 100%; display: flex; gap: 10px; align-items: center; padding: 9px 10px; border-radius: 9px; border: 0; background: none; cursor: pointer; font-size: .88rem; text-align: left;
}
.cg-create-menu button:hover:not(:disabled) { background: #383838; }
.cg-create-menu button:disabled { opacity: .45; cursor: not-allowed; }
.cg-send {
  flex: none; width: 36px; height: 36px; border-radius: 50%; border: 0; cursor: pointer;
  background: #ececec; color: #111 !important; display: grid; place-items: center; font-size: .95rem;
}
.cg-send:hover:not(:disabled) { background: #fff; }
.cg-send:disabled { background: #676767; color: #2f2f2f !important; cursor: default; }
.cg-send--stop i { font-size: .8rem; }
.cg-disclaimer { text-align: center; font-size: .74rem; color: var(--cg-faint); padding-top: 8px; }

.cg-backdrop { display: none; }

/* --------------------------------------------------------- tablet / phone */
@media (max-width: 900px) {
  .cg-app, .cg-app--wide { grid-template-columns: minmax(0, 1fr); }
  .cg-sidebar, .cg-app--wide .cg-sidebar {
    visibility: visible; padding: 8px 8px 0;
    position: fixed; z-index: 4001; inset: 0 auto 0 0; width: min(300px, 86vw); height: 100dvh;
    transform: translateX(-100%); transition: transform .22s ease; box-shadow: 8px 0 32px rgba(0, 0, 0, .5);
  }
  .cg-sidebar.open { transform: none; }
  .cg-backdrop { display: block; position: fixed; inset: 0; z-index: 4000; background: rgba(0, 0, 0, .5); opacity: 0; pointer-events: none; transition: opacity .2s; }
  .cg-backdrop.show { opacity: 1; pointer-events: auto; }
  .cg-menu-btn, .cg-top-new { display: inline-grid; }
  .cg-show-side { display: none; }
  .cg-side-top .cg-icon-btn:first-child i::before { content: "\f00d"; } /* xmark: close the drawer */
  .cg-suggest { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .cg-conv-actions { display: flex; }
}
@media (max-width: 560px) {
  .cg-top { height: 52px; padding: 0 6px; }
  .cg-agent-pill { font-size: .98rem; padding: 0 8px; }
  .cg-thread { padding: 4px 14px 24px; gap: 22px; }
  .cg-welcome { padding-top: 3vh; }
  .cg-welcome p { margin-bottom: 18px; font-size: .9rem; }
  .cg-suggest { grid-template-columns: 1fr 1fr; gap: 8px; }
  .cg-card { padding: 11px; }
  .cg-card-sub { display: none; }
  .cg-msg--ai { gap: 0; }
  .cg-ai-avatar { display: none; }
  .cg-bubble { max-width: 85%; }
  .cg-composer-wrap { padding: 0 10px calc(8px + env(safe-area-inset-bottom, 0px)); }
  .cg-composer { border-radius: 22px; padding: 8px 8px 6px 12px; }
  .cg-tool span { display: none; }
  .cg-tool { width: 34px; padding: 0; justify-content: center; }
  .cg-tool.on span { display: none; }
  .cg-gallery { grid-auto-rows: 110px; }
  .cg-gallery.n2 { grid-auto-rows: 150px; }
  .cg-gallery.n1 { grid-auto-rows: 220px; }
  .cg-videos { grid-template-columns: 1fr; }
  .cg-agent-menu { position: fixed; left: 10px; right: 10px; top: calc(var(--header-h, 120px) + 50px); width: auto; max-height: calc(100dvh - var(--header-h, 120px) - 70px); }
  .cg-jump { bottom: 130px; }
}
@media (prefers-reduced-motion: reduce) {
  .cg-app *, .cg-app *::after { animation: none !important; transition: none !important; }
}

/* ------------------------------------------------- download (PDF/Word/Text) */
.cg-dl { position: relative; display: inline-flex; align-items: center; }
.cg-dl-menu {
  position: absolute; left: 0; top: calc(100% + 6px); z-index: 60; width: 240px; padding: 6px;
  background: #2b2b2b; border: 1px solid var(--cg-line, #383838); border-radius: 14px; box-shadow: 0 14px 36px rgba(0, 0, 0, .5);
}
.cg-dl-menu.up { top: auto; bottom: calc(100% + 6px); }
.cg-dl-menu p { margin: 4px 10px 6px; font-size: .72rem; font-weight: 600; color: var(--cg-faint, #8f8f8f); text-transform: uppercase; letter-spacing: .04em; }
.cg-app .cg-dl-menu button {
  width: 100%; height: auto; display: flex; align-items: center; gap: 12px; padding: 8px 10px; border-radius: 9px;
  border: 0; background: none; cursor: pointer; text-align: left; color: var(--cg-text, #ececec); font-size: .88rem;
}
.cg-app .cg-dl-menu button:hover:not(:disabled), .cg-app .cg-dl-menu button:focus-visible { background: #383838; color: var(--cg-text, #ececec); }
.cg-dl-menu button:disabled { opacity: .6; cursor: progress; }
.cg-dl-text { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.cg-dl-menu b { font-weight: 500; }
.cg-dl-menu small { font-size: .74rem; color: var(--cg-faint, #8f8f8f); }
.cg-ftype {
  flex: none; display: inline-grid; place-items: center; width: 30px; height: 36px; border-radius: 5px 10px 5px 5px;
  font: 800 .6rem/1 var(--font-inter, Inter), system-ui, sans-serif; letter-spacing: .02em; color: #fff;
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, .18);
}
.cg-ftype--big { width: 42px; height: 52px; font-size: .72rem; border-radius: 6px 14px 6px 6px; }
.cg-ftype--pdf { background: #dc2626; }
.cg-ftype--doc { background: #2563eb; }
.cg-ftype--txt { background: #525252; }
.cg-ftype--md { background: #15803d; }
.cg-dl-err { font-size: .76rem; color: #ffb4ab; margin-left: 8px; }

.cg-doc-card {
  position: relative; display: flex; align-items: center; gap: 14px; flex-wrap: wrap; max-width: 560px;
  padding: 12px 12px 12px 14px; border: 1px solid var(--cg-line, #383838); border-radius: 16px; background: #262626;
}
.cg-doc-meta { flex: 1; min-width: 140px; display: flex; flex-direction: column; gap: 2px; }
.cg-doc-title { font-weight: 600; font-size: .93rem; line-height: 1.3; overflow-wrap: anywhere; }
.cg-doc-sub { font-size: .78rem; color: var(--cg-faint, #8f8f8f); }
.cg-doc-actions { display: flex; align-items: center; gap: 0; }
.cg-app .cg-doc-main {
  display: inline-flex; align-items: center; gap: 8px; height: 36px; padding: 0 14px; border: 0; cursor: pointer;
  border-radius: 10px 0 0 10px; background: #ececec; color: #111; font-weight: 600; font-size: .86rem;
}
.cg-app .cg-doc-main:hover:not(:disabled) { background: #fff; }
.cg-app .cg-doc-more {
  height: 36px; width: 34px; border: 0; border-left: 1px solid #c8c8c8; cursor: pointer; border-radius: 0 10px 10px 0;
  background: #ececec; color: #111; font-size: .72rem;
}
.cg-app .cg-doc-more:hover { background: #fff; }
.cg-doc-card .cg-dl-menu { left: auto; right: 0; }
.cg-doc-card .cg-dl-err { flex-basis: 100%; margin: 0; }

/* The off-screen white page an answer is drawn onto for PDF export. */
.cg-export {
  position: fixed; left: -12000px; top: 0; width: 760px; padding: 4px 6px 10px; background: #fff; color: #111;
  font-family: var(--font-inter, Inter), "Noto Sans", "Nirmala UI", "Segoe UI", Arial, sans-serif; font-size: 15px; line-height: 1.65;
}
.cg-export-head { padding-bottom: 10px; margin-bottom: 14px; border-bottom: 2px solid #7c3aed; }
.cg-export-brand { font-size: 12px; color: #6b21a8; font-weight: 600; letter-spacing: .02em; }
.cg-export h1 { font-size: 26px; line-height: 1.25; margin: 4px 0 0; color: #111; }
.cg-export-pics { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.cg-export-pics figure { margin: 0; break-inside: avoid; }
.cg-export-pics img { width: 100%; height: 190px; object-fit: contain; background: #f5f5f5; border-radius: 6px; }
.cg-export-pics figcaption { font-size: 11px; color: #555; margin-top: 3px; }
.cg-export .pro-md, .cg-export .cg-md { color: #111; font-size: 15px; }
.cg-export .pro-md strong { color: #000; }
.cg-export .pro-md a, .cg-export .pro-md .md-cite { color: #4338ca; }
.cg-export .pro-md .md-list li::marker { color: #7c3aed; }
.cg-export .pro-md .md-code { background: #f1f1f4; color: #111; }
.cg-export .pro-md .md-pre-wrap { background: #f6f8fa; border-color: #d0d7de; }
.cg-export .pro-md .md-pre { color: #1f2328; white-space: pre-wrap; overflow: visible; }
.cg-export .pro-md .md-table-wrap { border-color: #d0d0d0; overflow: visible; }
.cg-export .pro-md .md-table th { background: #f3f0ff; color: #111; }
.cg-export .pro-md .md-table th, .cg-export .pro-md .md-table td { border-bottom-color: #e3e3e3; }
.cg-export .pro-md .md-quote { background: #f7f5ff; color: #222; }
.cg-export .pro-md .md-math { background: #f7f5ff; color: #111; white-space: normal; }
.cg-export .pro-md .md-hr { border-top-color: #ddd; }
.cg-export .cg-chart { background: #fff; border-color: #ddd; color: #111; }
.cg-export .cg-chart-legend, .cg-export .cg-pie-keys { color: #333; }
.cg-export .cg-axis { fill: #444; }
.cg-export .cg-chart-svg line { stroke: #ddd; }
.cg-export .cg-chart-svg circle, .cg-export .cg-pie path { stroke: #fff; }
.cg-export-videos h3 { font-size: 17px; margin: 18px 0 6px; }
.cg-export-videos ul { margin: 0; padding-left: 20px; }
.cg-export-videos a { color: #4338ca; }
.cg-export-foot { margin-top: 18px; padding-top: 8px; border-top: 1px solid #e5e5e5; font-size: 11px; color: #777; }
.cg-chart-data[hidden] { display: none !important; }

/* ZIP of code files */
.cg-ftype--zip { background: #b45309; }
.cg-app .cg-doc-files-toggle {
  display: inline-flex; align-items: center; gap: 6px; padding: 0; border: 0; background: none; cursor: pointer;
  font-size: .78rem; color: var(--cg-faint, #8f8f8f);
}
.cg-app .cg-doc-files-toggle:hover { color: var(--cg-text, #ececec); }
.cg-doc-files-toggle i { font-size: .62rem; }
.cg-doc-files {
  flex-basis: 100%; list-style: none; margin: 2px 0 0; padding: 8px 10px; max-height: 220px; overflow-y: auto;
  border-top: 1px solid var(--cg-line, #383838); display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 4px 14px;
  font: .8rem/1.5 "JetBrains Mono", Consolas, monospace; color: var(--cg-muted, #b4b4b4);
}
.cg-doc-files li { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cg-doc-files i { color: #f59e0b; font-size: .7rem; margin-right: 4px; }
