:root {
  --cg-bg0: #0c1210;
  --cg-bg1: #14201c;
  --cg-bg2: #1a2b25;
  --cg-ink: #e8f0ec;
  --cg-muted: #8aa399;
  --cg-accent: #3dcf9a;
  --cg-accent-dim: #2a9a72;
  --cg-warn: #e6b35c;
  --cg-danger: #e07a6a;
  --cg-line: rgba(232, 240, 236, 0.12);
  --cg-font-display: "Fraunces", "Iowan Old Style", Georgia, serif;
  --cg-font-body: "Sora", "Avenir Next", "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  min-height: 100%;
  font-family: var(--cg-font-body);
  color: var(--cg-ink);
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(61, 207, 154, 0.18), transparent 55%),
    radial-gradient(900px 500px at 100% 0%, rgba(230, 179, 92, 0.12), transparent 50%),
    linear-gradient(165deg, var(--cg-bg0), var(--cg-bg1) 45%, var(--cg-bg2));
  background-attachment: fixed;
}

a { color: var(--cg-accent); }

.cg-ai-shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  max-width: 920px;
  margin: 0 auto;
  padding: 1.25rem 1.25rem 1.5rem;
  transition: max-width 0.35s ease;
}
.cg-ai-shell.is-split {
  max-width: min(1480px, 100%);
}
.cg-ai-work {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0;
  min-height: 0;
}
.cg-ai-shell.is-split .cg-ai-work {
  grid-template-columns: minmax(320px, 420px) 1fr;
  gap: 1rem;
  min-height: calc(100vh - 6rem);
}
.cg-ai-chat-pane {
  min-width: 0;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.cg-ai-shell.is-split .cg-ai-chat-pane {
  max-height: calc(100vh - 6rem);
  overflow: hidden;
}
.cg-ai-shell.is-split .cg-ai-thread {
  flex: 1;
  max-height: none;
  min-height: 0;
}
.cg-ai-shell.is-split .cg-ai-recent { display: none; }
.cg-ai-workspace-pane {
  display: flex;
  flex-direction: column;
  min-height: 420px;
  border: 1px solid var(--cg-line);
  border-radius: 1rem;
  overflow: hidden;
  background: rgba(0,0,0,0.35);
  animation: cgFadeUp 0.45s ease both;
}
.cg-ai-workspace-pane[hidden] { display: none !important; }
.cg-ai-workspace-pane__bar {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.55rem 0.75rem;
  border-bottom: 1px solid var(--cg-line);
  font-size: 0.82rem;
  color: var(--cg-muted);
}
.cg-ai-workspace-pane__bar span { flex: 1; color: var(--cg-ink); }
.cg-ai-workspace-pane__bar button {
  font: inherit;
  font-size: 0.78rem;
  border: 1px solid var(--cg-line);
  background: transparent;
  color: var(--cg-ink);
  padding: 0.35rem 0.65rem;
  border-radius: 0.45rem;
  cursor: pointer;
}
.cg-ai-workspace-cancel { border-color: var(--cg-danger) !important; color: var(--cg-danger) !important; }
.cg-ai-workspace-frame {
  flex: 1;
  width: 100%;
  min-height: calc(100vh - 9rem);
  border: 0;
  background: #0a0f0d;
}
.cg-ai-enhanced {
  margin: 0.55rem 0 0;
  padding: 0.55rem 0.7rem;
  border-radius: 0.65rem;
  background: rgba(61, 207, 154, 0.1);
  border: 1px solid rgba(61, 207, 154, 0.28);
  font-size: 0.86rem;
  color: var(--cg-ink);
  line-height: 1.4;
}
.cg-ai-enhanced strong { color: var(--cg-accent); font-weight: 600; }

.cg-ai-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.5rem;
  animation: cgFadeUp 0.55s ease both;
}

.cg-ai-brand {
  font-family: var(--cg-font-display);
  font-size: clamp(1.75rem, 4vw, 2.6rem);
  font-weight: 600;
  letter-spacing: -0.02em;
  margin: 0;
  background: linear-gradient(120deg, #fff 20%, var(--cg-accent));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.cg-ai-user {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: var(--cg-muted);
  font-size: 0.875rem;
}

.cg-ai-pill {
  border: 1px solid var(--cg-line);
  background: rgba(255,255,255,0.04);
  padding: 0.35rem 0.7rem;
  border-radius: 999px;
  color: var(--cg-ink);
}

.cg-ai-hero {
  text-align: center;
  padding: 8vh 0 2rem;
  animation: cgFadeUp 0.7s ease 0.08s both;
}

.cg-ai-hero h1 {
  font-family: var(--cg-font-display);
  font-weight: 500;
  font-size: clamp(1.6rem, 3.5vw, 2.4rem);
  margin: 0 0 0.75rem;
  letter-spacing: -0.02em;
}

.cg-ai-hero p {
  margin: 0 auto;
  max-width: 34rem;
  color: var(--cg-muted);
  line-height: 1.5;
}

.cg-ai-examples {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: center;
  margin: 1.5rem 0 0;
}

.cg-ai-examples button {
  border: 1px solid var(--cg-line);
  background: rgba(255,255,255,0.03);
  color: var(--cg-ink);
  padding: 0.55rem 0.9rem;
  border-radius: 999px;
  cursor: pointer;
  font: inherit;
  font-size: 0.85rem;
  transition: border-color 0.2s, background 0.2s, transform 0.2s;
}
.cg-ai-examples button:hover {
  border-color: var(--cg-accent-dim);
  background: rgba(61, 207, 154, 0.08);
  transform: translateY(-1px);
}

.cg-ai-main {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.cg-ai-thread {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: 0.5rem 0 1.25rem;
  scroll-behavior: smooth;
}

.cg-ai-msg {
  max-width: 92%;
  animation: cgFadeUp 0.35s ease both;
}
.cg-ai-msg.user {
  align-self: flex-end;
  background: rgba(61, 207, 154, 0.14);
  border: 1px solid rgba(61, 207, 154, 0.28);
  padding: 0.85rem 1rem;
  border-radius: 1.1rem 1.1rem 0.35rem 1.1rem;
}
.cg-ai-msg.assistant {
  align-self: flex-start;
  padding: 0.25rem 0;
}
.cg-ai-msg .meta {
  font-size: 0.72rem;
  color: var(--cg-muted);
  margin-bottom: 0.35rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.cg-ai-msg .body {
  white-space: pre-wrap;
  line-height: 1.55;
}

.cg-ai-agent {
  align-self: flex-start;
  width: min(100%, 34rem);
  border: 1px solid var(--cg-line);
  background: rgba(0, 0, 0, 0.28);
  border-radius: 1rem;
  padding: 0.85rem 1rem;
  animation: cgFadeUp 0.3s ease both;
}
.cg-ai-agent__head {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  font-size: 0.72rem;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--cg-muted);
  margin-bottom: 0.65rem;
}
.cg-ai-agent__pulse {
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 50%;
  background: var(--cg-accent);
  box-shadow: 0 0 0 0 rgba(61, 207, 154, 0.45);
  animation: cgPulse 1.2s ease infinite;
}
.cg-ai-agent__steps {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.4rem;
}
.cg-ai-agent__steps li {
  display: grid;
  grid-template-columns: 1.1rem 1fr;
  gap: 0.45rem;
  align-items: start;
  font-size: 0.9rem;
  line-height: 1.35;
  color: var(--cg-muted);
}
.cg-ai-agent__steps li.active {
  color: var(--cg-ink);
}
.cg-ai-agent__steps li.done {
  color: var(--cg-accent-dim);
}
.cg-ai-agent__steps li .mark {
  font-size: 0.75rem;
  line-height: 1.45;
  color: var(--cg-muted);
}
.cg-ai-agent__steps li.done .mark { color: var(--cg-accent); }
.cg-ai-agent__steps li.active .mark { color: var(--cg-warn); }
.cg-ai-agent.done .cg-ai-agent__pulse {
  animation: none;
  background: var(--cg-accent-dim);
}
.cg-ai-process {
  margin: 0 0 0.65rem;
  padding: 0.55rem 0.7rem;
  border-left: 2px solid var(--cg-accent-dim);
  color: var(--cg-muted);
  font-size: 0.82rem;
  line-height: 1.45;
}
.cg-ai-process strong {
  color: var(--cg-ink);
  font-weight: 500;
}

.cg-ai-plan {
  margin-top: 0.85rem;
  border: 1px solid var(--cg-line);
  background: rgba(0,0,0,0.25);
  padding: 1rem 1.1rem;
  border-radius: 1rem;
  animation: cgFadeUp 0.4s ease both;
}
.cg-ai-plan h3 {
  font-family: var(--cg-font-display);
  margin: 0 0 0.5rem;
  font-size: 1.15rem;
}
.cg-ai-plan .stats {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  color: var(--cg-muted);
  font-size: 0.9rem;
  margin-bottom: 0.85rem;
}
.cg-ai-plan .streams {
  list-style: none;
  padding: 0;
  margin: 0 0 1rem;
}
.cg-ai-plan .streams li {
  display: flex;
  justify-content: space-between;
  padding: 0.35rem 0;
  border-bottom: 1px solid var(--cg-line);
  font-size: 0.92rem;
}
.cg-ai-plan-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}
.cg-ai-plan-actions button {
  font: inherit;
  border: 0;
  cursor: pointer;
  padding: 0.6rem 1rem;
  border-radius: 0.55rem;
}
.cg-ai-plan-actions .primary {
  background: var(--cg-accent);
  color: #062218;
  font-weight: 600;
}
.cg-ai-plan-actions .ghost {
  background: transparent;
  color: var(--cg-ink);
  border: 1px solid var(--cg-line);
}

.cg-ai-composer {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 0.55rem;
  align-items: end;
  padding: 0.75rem;
  border: 1px solid var(--cg-line);
  border-radius: 1.15rem;
  background: rgba(8, 14, 12, 0.72);
  backdrop-filter: blur(10px);
  animation: cgFadeUp 0.6s ease 0.12s both;
}
.cg-ai-composer textarea {
  width: 100%;
  resize: none;
  min-height: 3rem;
  max-height: 8rem;
  border: 0;
  background: transparent;
  color: var(--cg-ink);
  font: inherit;
  padding: 0.55rem 0.25rem;
  outline: none;
}
.cg-ai-mic, .cg-ai-send {
  border: 0;
  cursor: pointer;
  font: inherit;
  height: 2.75rem;
  border-radius: 0.85rem;
}
.cg-ai-mic {
  min-width: 2.75rem;
  background: rgba(255,255,255,0.06);
  color: var(--cg-ink);
  border: 1px solid var(--cg-line);
}
.cg-ai-mic.live {
  background: rgba(224, 122, 106, 0.25);
  border-color: var(--cg-danger);
  animation: cgPulse 1.2s ease infinite;
}
.cg-ai-send {
  padding: 0 1.1rem;
  background: var(--cg-accent);
  color: #062218;
  font-weight: 600;
}
.cg-ai-send:disabled, .cg-ai-mic:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.cg-ai-recent {
  margin-top: 1.25rem;
  animation: cgFadeUp 0.65s ease 0.18s both;
}
.cg-ai-recent h2 {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--cg-muted);
  font-weight: 500;
  margin: 0 0 0.6rem;
}
.cg-ai-recent-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}
.cg-ai-recent-list button {
  border: 1px solid var(--cg-line);
  background: transparent;
  color: var(--cg-ink);
  padding: 0.4rem 0.75rem;
  border-radius: 0.55rem;
  cursor: pointer;
  font: inherit;
  font-size: 0.85rem;
}

.cg-ai-login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
}
.cg-ai-login-card {
  width: min(420px, 100%);
  padding: 2rem;
  border: 1px solid var(--cg-line);
  border-radius: 1.25rem;
  background: rgba(8,14,12,0.75);
}
.cg-ai-login-card h1 {
  font-family: var(--cg-font-display);
  margin: 0.25rem 0 1.25rem;
}
.cg-ai-login-card label {
  display: grid;
  gap: 0.35rem;
  margin-bottom: 0.9rem;
  font-size: 0.9rem;
  color: var(--cg-muted);
}
.cg-ai-login-card input {
  font: inherit;
  padding: 0.7rem 0.8rem;
  border-radius: 0.55rem;
  border: 1px solid var(--cg-line);
  background: rgba(255,255,255,0.04);
  color: var(--cg-ink);
}
.cg-ai-login-card button {
  width: 100%;
  margin-top: 0.35rem;
  border: 0;
  padding: 0.8rem;
  border-radius: 0.55rem;
  background: var(--cg-accent);
  color: #062218;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.cg-ai-error { color: var(--cg-danger); }
.cg-ai-muted { color: var(--cg-muted); font-size: 0.85rem; }

.has-thread .cg-ai-hero { display: none; }

@keyframes cgFadeUp {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes cgPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(224,122,106,0.35); }
  50% { box-shadow: 0 0 0 8px rgba(224,122,106,0); }
}

@media (max-width: 960px) {
  .cg-ai-shell.is-split .cg-ai-work {
    grid-template-columns: 1fr;
    min-height: 0;
  }
  .cg-ai-workspace-frame {
    min-height: 55vh;
  }
}
@media (max-width: 640px) {
  .cg-ai-composer { grid-template-columns: auto 1fr; }
  .cg-ai-send { grid-column: 1 / -1; }
}
