/* Shared workspace and conversation. Token-only: safe on the homepage.
   One boundary, a compact identity bar, one body, and stable bottom controls. */
:root {
    --ease: cubic-bezier(0.32, 0.72, 0, 1);
    --shade-1: 0 1px 2px rgba(28, 28, 30, 0.04);
    --shade-2: 0 12px 32px -12px rgba(139, 126, 102, 0.28);
}

.rig {
    display: flex;
    flex-direction: column;
    min-height: 0;
    max-height: 680px;
    padding: 0;
    background: #F9F8F4;
    border: 1px solid #CFC8B9;
    border-radius: 16px;
    overflow: hidden;
    box-shadow: none;
}
.rig > .core { display: flex; flex: 1; flex-direction: column; min-height: 0; background: transparent; border: 0; border-radius: 0; box-shadow: none; overflow: visible; }
.rig:has(#stage-ready:not(.hidden)) { flex: 0 1 auto; height: auto; max-height: 100%; }
.rig:has(#stage-ready .build-details[open]) { flex: 1; }
.build-entry-workspace .rig:has(#stage-ready .build-details[open]) { height: min(740px, calc(100dvh - 150px)); }
.rig-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 16px; flex: none; padding: 16px 24px; border-bottom: 1px solid var(--border); background: #F4F2EA; }
.rig-id { display: flex; align-items: center; gap: 12px; min-width: 0; flex: 1; }
.rig-mono { width: 36px; height: 36px; flex: none; display: grid; place-items: center; border-radius: 8px; background: var(--text-main); color: var(--bg-color); font-size: 14px; }
.rig-name { display: block; font-size: 16px; font-weight: 500; line-height: 1.4; color: var(--text-main); overflow-wrap: anywhere; }
.rig-sub { display: block; margin-top: 2px; font-size: 14px; line-height: 1.5; color: #5C5347; overflow-wrap: anywhere; }
/* Keep the complete accessible text while bounding the compact identity bar. */
.rig-name, .rig-sub { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; }
.rig-tools { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.rig-badge { font-size: 12px; color: #5C5347; white-space: nowrap; }
.rig-badge:empty { display: none; }
.rig-body { position: relative; flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior-y: contain; }
.rig-body:has(#stage-talk:not(.hidden)) { display: flex; flex-direction: column; overflow: hidden; }
#stage-talk { display: flex; flex: 1; flex-direction: column; min-height: 0; }
.rig-foot { flex: none; padding: 16px 24px; border-top: 1px solid var(--border); background: #F4F2EA; }
.rig-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.rig-label { width: 100%; font-size: 14px; color: #5C5347; margin-bottom: 4px; }
.rig-input { flex: 1; min-width: 0; min-height: 48px; padding: 11px 14px; font: inherit; font-size: 16px; color: var(--text-main); background: #F9F8F4; border: 1px solid #8B7E66; border-radius: 12px; outline: none; }
.rig-input::placeholder { color: #5C5347; opacity: 1; }
.rig-input:focus-visible { outline: 2px solid #5C5347; outline-offset: 2px; }
.rig-btn { display: inline-flex; justify-content: center; align-items: center; flex-shrink: 0; min-height: 48px; padding: 11px 20px; font: inherit; font-size: 13px; line-height: 1.5; letter-spacing: 0.06em; text-transform: uppercase; text-decoration: none; color: var(--text-main); background: transparent; border: 1px solid var(--text-main); border-radius: 999px; cursor: pointer; transition: background 180ms var(--ease); }
.rig-btn:hover:not(:disabled) { background: #E6E2D6; }
.rig-btn:disabled { opacity: 0.55; cursor: not-allowed; }
.rig-btn-solid { background: var(--text-main); color: var(--bg-color); }
.rig-btn-solid:hover:not(:disabled) { background: #000; }
.rig-btn-quiet { border-color: #CFC8B9; color: #5C5347; padding-inline: 16px; }
.rig-btn:focus-visible, .talk-chip:focus-visible, #tools-close:focus-visible { outline: 2px solid #5C5347; outline-offset: 3px; }
#stage-build.hidden, #stage-ready.hidden, #stage-talk.hidden, .rig-row.hidden, .voice-panel.hidden, .rig-foot.hidden { display: none; }
#composer #input { flex-basis: 0; }
#composer #send { margin-right: auto; }
.demo-note { flex: none; margin-top: 12px; font-size: 14px; line-height: 1.5; color: #5C5347; text-align: center; }
#demo.is-idle { justify-content: center; }
#demo.is-idle .rig-wrap { flex: 0 0 auto; }
#demo.is-idle .rig { flex: 0 0 auto; max-height: none; width: 100%; max-width: 38rem; margin: 0 auto; }
#demo.is-idle .rig-bar, #demo.is-idle .rig-body { display: none; }
#demo.is-idle .rig-foot { border-top: 0; background: transparent; }

/* Transcript: long histories scroll here at normal heights, not under controls. */
.transcript { display: flex; flex: 1; flex-direction: column; justify-content: flex-start; gap: 16px; min-height: 0; overflow-y: auto; padding: 24px; overscroll-behavior-y: contain; }
.transcript > * { flex: 0 0 auto; }
.transcript > :first-child { margin-top: auto; }
.bubble { max-width: 84%; padding: 14px 18px; font-size: 15px; line-height: 1.7; white-space: pre-wrap; overflow-wrap: anywhere; }
.bubble-agent { background: #EEEAE0; border-radius: 12px 12px 12px 4px; }
.bubble-user { background: var(--text-main); color: var(--bg-color); margin-left: auto; border-radius: 12px 12px 4px 12px; }
.bubble-speaker { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.bubble-delivery { display: block; margin-top: 6px; font-size: 14px; font-weight: 500; }
.conversation-status { font-size: 14px; line-height: 1.5; color: #5C5347; overflow-wrap: anywhere; }
.conversation-status:empty { display: none; }
.chat-feedback { padding: 0 24px 12px; flex: none; }
.chat-feedback[hidden], #suggest-block[hidden], .voice-controls [hidden], .chat-feedback [hidden] { display: none; }
.suggest-block { flex: none; padding: 0 24px 12px; }
.suggest-block summary { min-height: 44px; padding: 12px 0; font-size: 14px; color: #5C5347; cursor: pointer; }
.suggest-block summary:focus-visible { outline: 2px solid #5C5347; outline-offset: 2px; }
.suggests { display: flex; flex-wrap: wrap; gap: 8px; }
.suggest { min-height: 44px; font: inherit; font-size: 14px; line-height: 1.4; text-align: left; padding: 10px 14px; border-radius: 12px; border: 1px solid #CFC8B9; background: transparent; color: var(--text-main); cursor: pointer; transition: border-color 180ms var(--ease); }
.suggest:hover { border-color: var(--accent); background: #F4F2EA; }
.typing-dots span { display: inline-block; width: 5px; height: 5px; margin-right: 4px; border-radius: 999px; background: var(--accent); animation: bob 1.3s var(--ease) infinite; }
.typing-dots span:nth-child(2) { animation-delay: 0.16s; }
.typing-dots span:nth-child(3) { animation-delay: 0.32s; }
@keyframes bob { 0%, 65%, 100% { opacity: 0.3; } 32% { opacity: 1; } }

/* Native voice selection and stable call controls. */
.voice-panel { padding: 12px 16px; flex: none; }
.rig-foot .voice-panel { padding: 0; }
.voice-choice { display: flex; align-items: center; flex-wrap: wrap; gap: 6px 10px; min-width: 0; }
.voice-choice[hidden] { display: none; }
.voice-choice label { font-size: 14px; font-weight: 500; color: #5C5347; }
.voice-choice select { min-width: 0; min-height: 44px; max-width: 100%; padding: 8px 12px; font: inherit; font-size: 16px; color: var(--text-main); background: #F9F8F4; border: 1px solid #5C5347; border-radius: 12px; }
.voice-choice select:disabled { opacity: 0.65; cursor: not-allowed; }
.voice-choice select:focus-visible { outline: 2px solid var(--text-main); outline-offset: 3px; }
.voice-choice .conversation-status { flex-basis: 100%; margin: 0; }
.voice-panel > .voice-choice { margin-bottom: 12px; }
.voice-controls { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.voice-control, .chat-feedback button { min-height: 44px; padding: 10px 16px; font: inherit; font-size: 14px; border: 1px solid var(--text-main); border-radius: 999px; color: var(--text-main); background: transparent; cursor: pointer; }
.voice-control:first-child { background: var(--text-main); color: var(--bg-color); }
.voice-control:disabled, .chat-feedback button:disabled { opacity: 0.55; cursor: not-allowed; }
.voice-control[aria-pressed="true"] { background: var(--accent-light); }
.voice-panel .conversation-status { margin-top: 8px; }
.voice-timer { font-size: 14px; color: #5C5347; font-variant-numeric: tabular-nums; }
#to-voice, #to-chat, #tools-toggle, #tools-close { min-height: 44px; }
#to-voice, #to-chat { font-family: inherit; cursor: pointer; }
#to-voice[aria-disabled="true"], #to-chat[aria-disabled="true"] { opacity: 0.6; }
.voice-controls button:focus-visible, .chat-feedback button:focus-visible, #to-voice:focus-visible, #to-chat:focus-visible, .suggest:focus-visible { outline: 2px solid var(--text-main); outline-offset: 3px; }

/* In-place operations drawer. The shared controller makes covered content inert. */
.talk-chip { display: inline-flex; align-items: center; gap: 8px; padding: 8px 12px; border: 1px solid #CFC8B9; border-radius: 999px; background: transparent; font: inherit; font-size: 12px; color: #5C5347; white-space: nowrap; cursor: pointer; }
.talk-chip.hidden { display: none; }
.talk-chip:hover, .talk-chip[aria-expanded="true"] { border-color: var(--accent); color: var(--text-main); }
.talk-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); flex: none; }
.tools-drawer { position: absolute; inset: 0; z-index: 1; overflow-y: auto; padding: 16px 24px; background: #F9F8F4; overscroll-behavior-y: contain; }
.tools-drawer.hidden { display: none; }
#tools-empty { font-size: 14px; line-height: 1.7; }
#tools-close { padding: 8px; color: #5C5347; font-size: 14px; }
.tool-card { position: relative; padding: 16px 0; border-bottom: 1px solid var(--border); animation: slide-in 220ms var(--ease) both; }
.tool-head { display: flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 500; }
.tool-head .idx { flex: none; color: #5C5347; font-size: 14px; }
.tool-detail { font-size: 14px; color: #5C5347; margin-top: 6px; line-height: 1.6; overflow-wrap: anywhere; }
@keyframes slide-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

@media (max-width: 639px) {
    .rig-bar, .rig-foot { padding: 12px 16px; }
    .rig-id { flex-basis: 120px; }
    .rig-bar .voice-choice { flex: 1 0 100%; }
    .rig-bar .voice-choice select { flex: 1; }
    .rig-btn { padding-inline: 14px; font-size: 12px; }
    #composer #input { flex-basis: 100%; }
    #demo-actions #go-reset { flex-basis: 100%; }
    .transcript { padding: 16px; }
    .bubble { max-width: 94%; padding: 12px 14px; }
    .chat-feedback { padding-inline: 16px; }
    .suggest-block { padding: 0 16px 12px; }
    .tools-drawer { padding-inline: 16px; }
}
/* One fallback for short viewports AND insufficient space after fixed chrome.
   initWorkspace selects this mode from actual available transcript height. */
.rig.is-short { overflow-y: auto; }
.rig.is-short > .core { flex: 1 0 auto; }
.rig.is-short .rig-body, .rig.is-short .rig-body:has(#stage-talk:not(.hidden)) { flex: 1 0 auto; overflow: visible; }
.rig.is-short #stage-talk { flex: 1 0 auto; }
.rig.is-short #stage-talk .transcript { flex: 1 0 auto; min-height: 120px; overflow: visible; }
.rig.is-short .tools-drawer { overflow: visible; }
.rig.is-short .rig-body:has(.tools-drawer:not(.hidden)) { display: grid; grid-template-columns: minmax(0, 1fr); }
.rig.is-short .rig-body:has(.tools-drawer:not(.hidden)) > #stage-talk { grid-area: 1 / 1; }
.rig.is-short .rig-body > .tools-drawer:not(.hidden) { position: relative; inset: auto; grid-area: 1 / 1; }
/* The shared grid track includes both covered history and long operations. */
@media (max-height: 700px) {
    #suggest-block { display: none; }
    .voice-panel .conversation-status { margin-top: 4px; }
}
@media (prefers-reduced-motion: reduce) {
    .rig *, .tool-card, .typing-dots span { animation: none; transition: none; }
}
