:root {
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --navy-950: #030712;
  --navy-900: #0a1628;
  --navy-800: #172b46;
  --brand: #2563eb;
  --brand-hover: #1d4ed8;
  --brand-light: #14294a;
  --gold: #fbbf24;
  --surface: #111827;
  --surface-raised: #182235;
  --canvas: #080f1c;
  --input: #0d1728;
  --border: #334155;
  --control-border: #52627a;
  --text: #e5edf8;
  --muted: #9fb0c5;
  --danger: #ff8b82;
  --danger-surface: #321719;
  --danger-border: #864147;
  --success: #4ade80;
  --warning-surface: #2a2312;
  --warning-border: #9d7b26;
  --radius: 1rem;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { min-width: 20rem; min-height: 100%; }
body { margin: 0; color: var(--text); background: var(--canvas); }
button, input, textarea, select { font: inherit; }
button { min-height: 2.75rem; border: 0; border-radius: 0.7rem; padding: 0.7rem 1rem; color: #fff; background: var(--brand); font-weight: 750; cursor: pointer; }
button:hover:not(:disabled) { background: var(--brand-hover); }
button:disabled { cursor: not-allowed; opacity: 0.48; }
button.secondary { color: var(--text); border: 1px solid var(--border); background: var(--surface-raised); }
button.secondary:hover:not(:disabled) { background: var(--brand-light); }
button.danger { color: var(--danger); }
button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
input, textarea, select { width: 100%; color: var(--text); border: 1px solid var(--control-border); border-radius: 0.7rem; background: var(--input); padding: 0.8rem 0.9rem; }
input::placeholder, textarea::placeholder { color: #7f91aa; }
textarea { resize: none; line-height: 1.45; }
label { display: block; margin-bottom: 0.4rem; font-size: 0.86rem; font-weight: 700; }
h1, h2, p { margin-top: 0; }

.app-shell { width: 100%; height: 100dvh; min-height: 30rem; display: flex; flex-direction: column; overflow: hidden; background: var(--surface); }
.avatar { display: grid; place-items: center; flex: 0 0 auto; border-radius: 50%; color: var(--navy-950); background: var(--gold); font-weight: 900; }
.eyebrow { margin-bottom: 0.12rem; color: var(--gold); font-size: 0.65rem; font-weight: 850; letter-spacing: 0.12em; text-transform: uppercase; }

.login-panel { flex: 1; display: grid; place-items: center; padding: 1.25rem; background: radial-gradient(circle at 50% 0, #102d52, transparent 28rem), var(--canvas); }
.login-card { width: min(100%, 27rem); padding: 1.5rem; border: 1px solid var(--border); border-radius: 1.25rem; background: var(--surface-raised); box-shadow: 0 1.5rem 4rem rgba(0, 0, 0, 0.45); }
.login-card .eyebrow { color: #7eb0ff; }
.login-card h2 { margin-bottom: 0.55rem; font-size: 1.35rem; }
.login-card > p:not(.eyebrow) { color: var(--muted); line-height: 1.5; }
.login-card button { width: 100%; margin-top: 1rem; }
.token-field { position: relative; }
.token-field input { padding-right: 3.35rem; }
.login-card .token-visibility { position: absolute; top: 50%; right: 0.18rem; width: 2.75rem; min-width: 2.75rem; min-height: 2.75rem; margin: 0; padding: 0.62rem; transform: translateY(-50%); color: var(--muted); background: transparent; }
.login-card .token-visibility:hover:not(:disabled) { color: var(--text); background: var(--brand-light); }
.token-visibility svg { display: block; width: 100%; height: 100%; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.token-visibility .visibility-slash { display: none; }
.token-visibility[aria-pressed="true"] .visibility-slash { display: block; }
.privacy-note { margin: 0.75rem 0 0; text-align: center; font-size: 0.74rem; }
.login-error { margin: 0.75rem 0 0; color: var(--danger) !important; font-size: 0.8rem; text-align: center; }

.assistant-panel { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.identity-presence { display: flex; align-items: center; gap: 0.75rem; padding: 0.42rem 1rem; border-bottom: 1px solid var(--border); color: var(--muted); background: var(--navy-900); font-size: 0.72rem; }
.identity-summary { min-width: 0; flex: 1; display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; }
.account-summary { display: flex; align-items: center; gap: 0.55rem; }
#signed-in-as { color: var(--text); font-weight: 700; }
#editing-now { min-width: 0; overflow: hidden; text-align: right; text-overflow: ellipsis; white-space: nowrap; }
.sign-out-button { min-height: 2rem; flex: 0 0 auto; padding: 0.32rem 0.65rem; font-size: 0.7rem; }
.current-request { flex: 0 0 auto; padding: 0.7rem 1rem; border-bottom: 1px solid var(--border); background: var(--brand-light); }
.current-request strong { display: block; margin-bottom: 0.25rem; color: #8ab8ff; font-size: 0.68rem; letter-spacing: 0.06em; text-transform: uppercase; }
.current-request p { max-height: 6.4rem; margin: 0; overflow-y: auto; color: var(--text); font-size: 0.82rem; line-height: 1.45; white-space: pre-wrap; overflow-wrap: anywhere; }
.error-banner { margin: 0.75rem 1rem 0; padding: 0.75rem 0.9rem; border: 1px solid var(--danger-border); border-radius: 0.75rem; color: var(--danger); background: var(--danger-surface); overflow-wrap: anywhere; }
.transcript { flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 1rem; margin: 0; padding: 1.25rem 1rem; list-style: none; background: var(--canvas); }
.message { display: flex; align-items: flex-start; gap: 0.65rem; max-width: 48rem; }
.avatar { width: 2rem; height: 2rem; font-size: 0.72rem; }
.message { width: fit-content; padding: 0.8rem 0.95rem; border: 1px solid var(--border); border-radius: 0.95rem 0.95rem 0.95rem 0.25rem; background: var(--surface-raised); box-shadow: 0 0.2rem 0.8rem rgba(0, 0, 0, 0.24); white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.5; }
.message.user { align-self: flex-end; color: #fff; border-color: #4e8ff7; border-radius: 0.95rem 0.95rem 0.25rem 0.95rem; background: #1f63cf; }
.message.user, .message.assistant { display: flex; align-items: flex-start; gap: 0.7rem; }
.message-text { min-width: 0; flex: 1 1 auto; }
.copy-message { --copy-background: var(--input); position: relative; width: 1.9rem; min-width: 1.9rem; min-height: 1.9rem; flex: 0 0 auto; padding: 0; border: 1px solid var(--border); border-radius: 0.5rem; color: #7eb0ff; background: var(--copy-background); }
.copy-message::before, .copy-message::after { content: ""; position: absolute; width: 0.58rem; height: 0.68rem; border: 1.5px solid currentColor; border-radius: 0.12rem; }
.copy-message::before { left: 0.58rem; top: 0.42rem; }
.copy-message::after { left: 0.76rem; top: 0.62rem; background: var(--copy-background); }
.copy-message:hover:not(:disabled) { --copy-background: var(--brand-hover); color: #fff; background: var(--copy-background); }
.copy-message.copied::before, .copy-message.copy-failed::before { display: none; }
.copy-message.copied::after, .copy-message.copy-failed::after { left: 0; top: 0; width: 100%; height: 100%; display: grid; place-items: center; border: 0; background: transparent; font-size: 1rem; font-weight: 900; }
.copy-message.copied::after { content: "✓"; color: var(--success); }
.copy-message.copy-failed::after { content: "!"; color: var(--danger); }
.message.user .copy-message { --copy-background: rgba(7, 28, 65, 0.52); border-color: rgba(255, 255, 255, 0.62); color: #dbeafe; }
.message.user .message-text::selection { color: var(--navy-950); background: var(--gold); }
.message.system { padding: 0; color: var(--muted); border: 0; background: transparent; box-shadow: none; font-size: 0.78rem; font-style: italic; }
.message.error { color: var(--danger); }
.message.working { color: #c9dcfa; border-color: #315786; background: var(--brand-light); }
.message.working::before { content: ""; width: 0.55rem; height: 0.55rem; flex: 0 0 auto; align-self: center; border-radius: 50%; background: #60a5fa; animation: working-pulse 1.15s ease-in-out infinite; }
.message.working { display: flex; align-items: flex-start; gap: 0.55rem; }
.tool-line { color: var(--muted); font-size: 0.78rem; }

@keyframes working-pulse {
  0%, 100% { opacity: 0.35; transform: scale(0.8); }
  50% { opacity: 1; transform: scale(1); }
}

@media (prefers-reduced-motion: reduce) {
  .message.working::before, .mic-button.listening .mic-dot { animation: none; }
}

.ui-request-panel, .unfinished-panel, .release-panel { margin: 0 1rem 0.75rem; padding: 1rem; border: 1px solid var(--warning-border); border-radius: var(--radius); background: var(--warning-surface); }
.ui-request-panel h2, .unfinished-panel h2, .release-panel h2 { margin-bottom: 0.4rem; font-size: 1rem; }
.ui-request-panel p, .unfinished-panel p, .release-panel p { margin-bottom: 0; color: var(--muted); }
.release-panel { max-height: 16rem; overflow-y: auto; }
.release-heading, .release-history li { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; }
.release-heading button, .release-history button { min-height: 2.2rem; padding: 0.35rem 0.65rem; font-size: 0.72rem; }
.release-panel h3 { margin: 0.85rem 0 0.35rem; font-size: 0.82rem; }
.release-candidate { margin-top: 0.6rem; color: var(--text); font-size: 0.8rem; }
.release-history { display: grid; gap: 0.35rem; margin: 0; padding: 0; list-style: none; color: var(--muted); font: 0.72rem/1.35 ui-monospace, monospace; }
.release-history span { overflow-wrap: anywhere; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 0.5rem; margin-top: 0.75rem; }
.bottom-controls { border-top: 1px solid var(--border); background: var(--surface); }
.composer { display: grid; grid-template-columns: 2.85rem 2.85rem minmax(0, 1fr) auto; gap: 0.55rem; align-items: end; padding: 0.75rem max(1rem, env(safe-area-inset-right)) max(0.75rem, env(safe-area-inset-bottom)) max(1rem, env(safe-area-inset-left)); }
.composer-main { min-width: 0; display: flex; flex-direction: column; justify-content: flex-end; }
.composer textarea { display: block; width: 100%; height: 3.25rem; min-height: 3.25rem; max-height: 9rem; margin: 0; overflow-y: auto; }
.composer button { height: 3.25rem; min-height: 3.25rem; min-width: 4.5rem; padding-block: 0; align-self: end; }
.composer .attachment-button, .composer .mic-button { min-width: 2.85rem; width: 2.85rem; padding-inline: 0; font-size: 1.2rem; }
.mic-button .mic-dot { display: block; width: 0.82rem; height: 0.82rem; margin: auto; border-radius: 50%; background: currentColor; }
.mic-button.listening { color: #fff; border-color: var(--danger-border); background: var(--danger-surface); }
.mic-button.listening .mic-dot { animation: mic-pulse 1s ease-in-out infinite; }
.speech-status { margin: 0.3rem 0 0; color: var(--muted); font-size: 0.66rem; line-height: 1.3; }
.speech-status.error { color: var(--danger); }
@keyframes mic-pulse { 50% { transform: scale(1.4); opacity: 0.5; } }
.attachment-list { display: flex; flex-wrap: wrap; gap: 0.35rem; margin-bottom: 0.35rem; }
.attachment-list:empty { display: none; }
.attachment-chip { display: inline-flex; align-items: center; gap: 0.3rem; max-width: 100%; padding: 0.28rem 0.45rem; border: 1px solid var(--border); border-radius: 999px; color: var(--muted); font-size: 0.78rem; }
.attachment-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attachment-chip button { min-width: 1.5rem; min-height: 1.5rem; padding: 0; border: 0; background: transparent; color: inherit; }
.session-actions { min-height: 3.25rem; display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 0.45rem; padding: 0.35rem max(1rem, env(safe-area-inset-right)) max(0.6rem, env(safe-area-inset-bottom)) max(1rem, env(safe-area-inset-left)); }
.session-actions button { min-height: 2.5rem; padding: 0.48rem 0.75rem; font-size: 0.74rem; }
.continue-request-button { min-width: 9rem; }
.new-request-button { min-width: 7rem; }
#elapsed-time { margin-right: auto; color: var(--muted); font-size: 0.74rem; font-variant-numeric: tabular-nums; font-weight: 750; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.noscript { margin: 1rem; color: var(--danger); }

@media (min-width: 48rem) {
  body { padding: 1.5rem; background: var(--navy-950); }
  .app-shell { max-width: 68rem; height: calc(100dvh - 3rem); min-height: 36rem; margin: 0 auto; overflow: hidden; border: 1px solid #26364d; border-radius: 1.25rem; box-shadow: 0 2rem 6rem rgba(0, 0, 0, 0.55); }
  .identity-presence, .current-request, .transcript { padding-inline: 1.5rem; }
  .composer, .session-actions { padding-inline: 1.5rem; }
}

@media (max-width: 24rem) {
  .identity-summary { align-items: flex-start; flex-direction: column; gap: 0.15rem; }
  #editing-now { text-align: left; }
  .session-actions button { min-width: 0; flex: 1; }
}
