/* Laygent chat surface: the project agent and the full-screen new-site builder share every rule here.
   Uses tokens from studio-ui/tokens.css (with fallbacks so the file also works on its own). */

@property --chat-angle { syntax: "<angle>"; inherits: false; initial-value: 0deg; }

/* ---- agent panel frame ---- */
.ai-workspace { display: flex; flex-direction: column; flex: 1; min-width: 0; min-height: 0; background: var(--surface-1, #111318); color: var(--text, #e9ecf1); }
.ai-head { flex: none; }
.ai-text-btn { min-height: 26px; padding: 0 8px; border-radius: var(--radius-sm, 6px); color: var(--text-muted, #aab1bc); font-size: 12px; transition: background var(--dur, .16s) var(--ease, ease), color var(--dur, .16s) var(--ease, ease); }
.ai-text-btn:hover:not(:disabled) { background: var(--surface-2, #171a20); color: var(--text, #e9ecf1); }
.ai-text-btn:disabled { opacity: .55; cursor: not-allowed; }
.ai-body-host { display: flex; flex: 1; min-width: 0; min-height: 0; }

/* ---- surface: centred empty state, then a conversation ---- */
.chat-surface { container-type: inline-size; display: flex; flex-direction: column; justify-content: center; flex: 1; min-width: 0; min-height: 0; }
.chat-surface.has-messages { justify-content: flex-start; }
.chat-thread { min-height: 0; padding: 12px 20px 8px; scroll-behavior: smooth; }
.chat-surface:not(.has-messages) .chat-thread { flex: none; overflow: visible; }
.chat-surface.has-messages .chat-thread { flex: 1; overflow: auto; }
.chat-thread:focus-visible { outline-offset: -2px; }
.chat-empty { display: flex; flex-direction: column; align-items: center; text-align: center; padding: 0 8px; animation: chatIn var(--dur-panel, .26s) var(--ease-out, ease) both; }
.has-messages .chat-empty { display: none; }
.chat-mark {
  display: grid; place-items: center; width: 44px; height: 44px; margin-bottom: 16px;
  border: 1px solid color-mix(in srgb, var(--accent, #8aa4ff) 35%, var(--border, #252a32)); border-radius: 14px;
  background: var(--surface-raised, #15181e); box-shadow: 0 10px 36px color-mix(in srgb, var(--accent, #8aa4ff) 18%, transparent);
}
.chat-mark .icon { width: 22px; height: 22px; stroke: url(#g-magic); stroke-width: 1.7; fill: none; }
.chat-title { margin: 0 0 6px; font-size: clamp(20px, 4.2cqi, 30px); font-weight: 650; letter-spacing: -.025em; line-height: 1.2; }
.chat-sub { max-width: 100%; margin: 0; overflow: hidden; color: var(--text-muted, #aab1bc); font-size: 14px; text-overflow: ellipsis; white-space: nowrap; }

.chat-dock { width: min(680px, calc(100% - 32px)); margin: 22px auto 0; padding-bottom: 12px; }
.chat-surface.has-messages .chat-dock { width: min(760px, calc(100% - 24px)); margin-top: 0; padding: 8px 0 12px; }
.chat-chips { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 14px; }
.has-messages .chat-chips { display: none; }
.chat-chips button {
  min-height: 32px; padding: 6px 12px; border: 1px solid var(--border, #252a32); border-radius: 99px;
  background: var(--surface-1, #111318); color: var(--text-muted, #aab1bc); font-size: 13px;
  transition: color var(--dur, .16s) var(--ease, ease), border-color var(--dur, .16s) var(--ease, ease), background var(--dur, .16s) var(--ease, ease), transform 120ms var(--ease, ease);
}
.chat-chips button:hover { color: var(--text, #e9ecf1); border-color: var(--border-strong, #353b45); background: var(--surface-2, #171a20); }
.chat-chips button:active { transform: scale(.97); }

/* ---- context chip ---- */
.chat-context {
  position: relative; display: inline-flex; align-items: center; gap: 6px; max-width: 100%; height: 26px; margin: 0 0 8px 2px; padding: 0 10px;
  overflow: hidden; border: 1px solid var(--border, #252a32); border-radius: 99px; background: var(--surface-raised, #15181e);
  color: var(--text-muted, #aab1bc); font-size: 12px; white-space: nowrap;
}
.ctx-dot { width: 7px; height: 7px; flex: none; border-radius: 50%; background: var(--success, #5ed3a2); box-shadow: 0 0 0 3px color-mix(in srgb, var(--success, #5ed3a2) 18%, transparent); animation: breathe 3.2s ease-in-out infinite; }
.ctx-dot.new { background: var(--accent, #8aa4ff); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent, #8aa4ff) 16%, transparent); animation: none; }
.ctx-name { overflow: hidden; color: var(--text, #e9ecf1); font-weight: 600; text-overflow: ellipsis; max-width: 22ch; }
.ctx-meta { overflow: hidden; text-overflow: ellipsis; }
.chat-context.active::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: linear-gradient(100deg, transparent 20%, color-mix(in srgb, var(--accent, #8aa4ff) 22%, transparent) 50%, transparent 80%);
  transform: translateX(-100%); animation: shimmer 1.6s var(--ease, ease) infinite;
}
@keyframes breathe { 50% { opacity: .45; transform: scale(.8); } }
@keyframes shimmer { to { transform: translateX(100%); } }

/* ---- prompt box ---- */
.chat-compose {
  position: relative; border: 1px solid var(--border-strong, #353b45); border-radius: 16px; background: var(--surface-raised, #15181e);
  box-shadow: var(--shadow-1, 0 1px 2px rgba(0,0,0,.4));
  transition: border-color 260ms var(--ease, ease), box-shadow 260ms var(--ease, ease);
}
/* a soft gradient ring that slowly turns while the box has focus */
.chat-compose::before {
  content: ""; position: absolute; inset: -1px; z-index: 0; padding: 1px; border-radius: inherit; pointer-events: none;
  background: conic-gradient(from var(--chat-angle), color-mix(in srgb, var(--accent, #8aa4ff) 90%, transparent), transparent 28%, #a77bf5aa 52%, transparent 76%, color-mix(in srgb, var(--accent, #8aa4ff) 90%, transparent));
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0); -webkit-mask-composite: xor;
  mask: linear-gradient(#000 0 0) content-box exclude, linear-gradient(#000 0 0);
  opacity: 0; transition: opacity 420ms var(--ease, ease); animation: chatRing 9s linear infinite paused;
}
.chat-compose:focus-within { border-color: transparent; box-shadow: var(--shadow-2, 0 12px 40px rgba(0,0,0,.5)), 0 0 0 4px var(--accent-soft, rgba(138,164,255,.14)); }
.chat-compose:focus-within::before { opacity: .95; animation-play-state: running; }
@keyframes chatRing { to { --chat-angle: 360deg; } }
.chat-field { position: relative; z-index: 1; }
.chat-field textarea {
  display: block; width: 100%; height: 48px; min-height: 24px; max-height: 200px; margin: 0; padding: 14px 16px 4px;
  resize: none; border: 0; background: transparent; color: var(--text, #e9ecf1); font: 400 14px/1.55 var(--font-ui, system-ui, sans-serif);
  overflow: hidden; transition: height 180ms var(--ease-out, ease);
}
.chat-field textarea:focus-visible { outline: none; }
.chat-measure {
  position: absolute; top: 0; left: 0; visibility: hidden; pointer-events: none; box-sizing: border-box;
  padding: 14px 16px 4px; font: 400 14px/1.55 var(--font-ui, system-ui, sans-serif); white-space: pre-wrap; overflow-wrap: break-word;
}
.chat-placeholder {
  position: absolute; top: 14px; left: 16px; right: 16px; overflow: hidden; color: var(--text-subtle, #8e95a1);
  font-size: 14px; line-height: 1.55; text-overflow: ellipsis; white-space: nowrap; pointer-events: none;
  transition: opacity 420ms var(--ease, ease), transform 420ms var(--ease, ease);
}
.chat-placeholder.fading { opacity: 0; transform: translate3d(0, -3px, 0); }
.chat-placeholder.gone { opacity: 0; transition-duration: 80ms; }
.chat-compose-bottom { position: relative; z-index: 1; display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 44px; padding: 2px 8px 8px 16px; }
.chat-note { min-width: 0; overflow: hidden; color: var(--text-subtle, #8e95a1); font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.chat-note.busy::before { content: ""; display: inline-block; width: 6px; height: 6px; margin: 0 7px 1px 0; border-radius: 50%; background: var(--accent, #8aa4ff); animation: breathe 1.2s ease-in-out infinite; }
.chat-note.ai-error, .chat-note.error { color: var(--danger, #ff8591); }
.chat-actions { display: flex; align-items: center; gap: 6px; flex: none; }
.chat-send {
  position: relative; display: grid; place-items: center; width: 34px; height: 34px; border-radius: 11px;
  background: var(--accent, #8aa4ff); color: var(--accent-contrast, #0b0c0f);
  box-shadow: 0 6px 18px color-mix(in srgb, var(--accent, #8aa4ff) 30%, transparent);
  transition: opacity 220ms var(--ease, ease), transform 220ms var(--ease-out, ease), background 160ms var(--ease, ease), box-shadow 220ms var(--ease, ease);
}
.chat-send .icon { width: 16px; height: 16px; stroke-width: 2; fill: none; transition: opacity 160ms var(--ease, ease), transform 220ms var(--ease-out, ease); }
.chat-send:hover:not(:disabled) { background: var(--accent-hover, #a3b8ff); }
.chat-send:hover:not(:disabled) .icon { transform: translateY(-1px); }
.chat-send:active:not(:disabled) { transform: scale(.92); }
.chat-send:disabled { opacity: .32; transform: scale(.9); box-shadow: none; cursor: default; }
.chat-compose.working .chat-send { opacity: 1; transform: none; }
.chat-compose.working .chat-send .icon { opacity: 0; }
.chat-compose.working .chat-send::after {
  content: ""; position: absolute; width: 14px; height: 14px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%;
  animation: spin 900ms linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes chatIn { from { opacity: 0; transform: translate3d(0, 6px, 0); } to { opacity: 1; transform: none; } }

/* ---- conversation ---- */
.ai-message { max-width: 760px; margin: 0 auto 18px; font-size: 13px; line-height: 1.65; overflow-wrap: anywhere; animation: chatIn 220ms var(--ease-out, ease) both; }
.ai-message .ai-author { margin-bottom: 4px; color: var(--text-subtle, #8e95a1); font-size: 12px; font-weight: 600; }
.ai-message.user .ai-body { padding: 9px 12px; border: 1px solid var(--border, #252a32); border-radius: 12px 12px 3px 12px; background: var(--surface-2, #171a20); white-space: pre-wrap; }
.ai-message.assistant .ai-body { color: var(--text, #e9ecf1); white-space: pre-wrap; }
.ai-message.assistant .ai-body:empty { display: none; }
.ai-message.assistant .ai-body.streaming::after { content: ""; display: inline-block; width: 7px; height: 14px; margin-left: 2px; vertical-align: -2px; background: var(--accent, #8aa4ff); animation: aiBlink 1s steps(2) infinite; }
@keyframes aiBlink { 50% { opacity: 0; } }
.ai-flow-token { animation: aiToken .28s var(--ease, ease) both; }
@keyframes aiToken { from { opacity: 0; } to { opacity: 1; } }
/* The agent's reply: one or two reassuring sentences, read as ordinary chat text. */
.ai-plan { margin: 0 0 6px; color: var(--text, #e9ecf1); font: inherit; white-space: pre-wrap; }
.ai-plan:empty { display: none; }
.ai-plan.streaming::after { content: ""; display: inline-block; width: 7px; height: 14px; margin-left: 2px; vertical-align: -2px; background: var(--accent, #8aa4ff); animation: aiBlink 1s steps(2) infinite; }
.ai-message.assistant .ai-body.ai-progress { color: var(--text-subtle, #8e95a1); font-size: 12px; }
.ai-message.continued { margin-top: -10px; }
.ai-message.continued .ai-author { display: none; }
.ai-run-meta { margin: 6px 0; color: var(--text-subtle, #8e95a1); font-size: 12px; font-variant-numeric: tabular-nums; }
.ai-run-meta:empty { display: none; }
.ai-time { margin-left: 8px; color: var(--text-subtle, #8e95a1); font-variant-numeric: tabular-nums; }
.ai-live-code { max-height: 280px; margin: 8px 0 0; padding: 10px 12px; overflow: auto; border: 1px solid var(--border, #252a32); border-radius: var(--radius, 8px); background: var(--code-bg, #0b0c0f); color: var(--code-text, #d7dce4); font: 12px/1.6 var(--font-mono, monospace); white-space: pre-wrap; }
.ai-live-code:empty { display: none; }
.ai-result-inline { margin-top: 8px; }
.ai-check { margin: 6px 0; font-size: 12px; }
.ai-check.passed { color: var(--success, #5ed3a2); }
.ai-reply { margin: 8px 0 2px; color: var(--text, #e9ecf1); white-space: pre-wrap; }
.ai-check.failed summary { min-height: 24px; color: var(--danger, #ff8591); cursor: pointer; }
.ai-reply + .ai-check.failed summary { color: var(--text-subtle, #8e95a1); }
.ai-check p { margin: 6px 0 0; color: var(--text-muted, #aab1bc); }
.ai-proposal-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.ai-check.left-out summary { min-height: 24px; color: var(--warning, #e8b04b); cursor: pointer; }
.ai-check.left-out ul { margin: 6px 0 0; padding-left: 18px; color: var(--text-muted, #aab1bc); font: 11px/1.5 var(--font-mono, monospace); }
.ai-check.left-out li { overflow-wrap: anywhere; }
