/* Compact, shared text/voice input. Controls are part of the field, not another row. */
.language-flag { display: inline-block; width: 1.35em; height: .9em; object-fit: cover; vertical-align: -.08em; border-radius: 2px; }
.message { position: relative; padding-right: 48px; }
.message .message-delete { position: absolute; top: 2px; right: 2px; padding: 10px; width: 44px; height: 44px; min-height: 44px; }
.message-delete svg { display: block; width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.input-shell {
  position: relative;
  width: 100%;
}
.input-shell textarea {
  display: block;
  width: 100%;
  padding: 16px 68px 16px 16px;
  border-radius: 18px;
  min-height: 94px;
  line-height: 1.65;
  resize: vertical;
}
.input-actions {
  position: absolute;
  right: 10px;
  bottom: 10px;
  display: flex;
  flex-direction: column-reverse;
  align-items: center;
  gap: 8px;
}
.input-actions .input-action {
  width: 44px;
  height: 44px;
  min-height: 44px;
  padding: 10px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}
.input-action.mic {
  color: var(--accent);
  border-color: transparent;
  background: var(--soft);
}
.input-action svg {
  width: 23px;
  height: 23px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  pointer-events: none;
}
.input-action.send-action svg { stroke-width: 3.5; }
.send-action.has-draft:not(:disabled) {
  color: #073e2d;
  border-color: transparent;
  background: #20c563;
  animation: send-ready 2.8s ease-in-out infinite;
}
@keyframes send-ready {
  0%, 100% { background-color: #20c563; }
  50% { background-color: transparent; }
}
.input-shell[data-loading="true"]::after {
  content: '';
  position: absolute;
  top: 17px;
  right: 77px;
  width: 19px;
  height: 19px;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  pointer-events: none;
  animation: input-loading .85s linear infinite;
}
#message-form .input-shell[data-loading="true"] textarea,
.context-input[data-loading="true"] textarea { padding-right: 108px; }
@keyframes input-loading { to { transform: rotate(360deg); } }
.input-action.recording { animation: recording-pulse 1.4s ease-in-out infinite; }
.input-status {
  margin: 12px 4px 0;
  color: var(--muted);
  font-size: .78rem;
  line-height: 1.6;
}
.context-input textarea { padding-right: 68px; min-height: 165px; }
.chat-page .composer { padding: 10px; }
.chat-page #message-form { display: block; }
.chat-page #message-form textarea {
  min-height: 116px;
  max-height: 240px;
  padding: 16px 68px 16px 16px;
  background: #fcfdfb;
}
.chat-page #send-text { padding: 10px; }
.chat-page .speaker-choice { margin-bottom: 6px; padding: 2px; }
.chat-page .speaker-choice button { min-height: 36px; padding-block: 6px; }
#setup { margin-top: 0; }
#context-form > label:first-child { margin-top: 0; }
body.chat-view #wallet-open { display: none; }
body.chat-view > .topbar { padding-block: 10px; }
@keyframes recording-pulse {
  50% { box-shadow: 0 0 0 5px #ab3d3d20; }
}
@media (max-width: 620px) {
  .chat-page { margin-top: 8px; }
  .chat-page .composer { padding: 10px; }
  .chat-page #message-form textarea { padding-left: 12px; padding-right: 68px; }
  .chat-page .chat-heading button { font-size: .75rem; }
}
@media (prefers-reduced-motion: reduce) {
  .input-action.recording { animation: none; }
  .send-action.has-draft:not(:disabled),
  .input-shell[data-loading="true"]::after { animation: none; }
}

/* Full-height conversation: only history scrolls, composer stays above the keyboard. */
body.chat-view {
  position: fixed;
  inset-inline: 0;
  top: var(--chat-viewport-top, 0px);
  height: var(--chat-viewport-height, 100dvh);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
body.chat-view > .topbar { flex: 0 0 auto; width: 100%; }
body.chat-view > main {
  flex: 1;
  min-height: 0;
  width: 100%;
  display: flex;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
}
body.chat-view main > .disclaimer,
body.chat-view main > footer { display: none; }
body.chat-view .chat-page {
  flex: 1;
  min-height: 0;
  width: 100%;
  display: flex;
  flex-direction: column;
  margin: 0 auto;
}
body.chat-view .composer { flex: 0 0 auto; }
body.chat-view .messages {
  flex: 1;
  min-height: 0;
  max-height: none;
  overflow-y: auto;
  overflow-anchor: none;
  padding-bottom: 16px;
}
body.chat-view .composer { margin: 0; }
.end-chat { padding: 10px; }
.end-chat svg,
#notice-open svg {
  display: block;
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
}
body.chat-view #toast {
  position: absolute;
  bottom: calc(var(--chat-composer-height, 170px) + 24px + env(safe-area-inset-bottom));
}

/* Keep the original microphone DOM node/capture alive throughout a touch gesture. */
.record-panel {
  position: absolute;
  inset: 10px;
  z-index: 2;
  border-radius: 14px;
  background: white;
}
.record-top { display: flex; align-items: center; gap: 10px; height: 40px; }
.record-indicator { width: 8px; height: 8px; border-radius: 50%; background: #c74550; }
.record-time { font-size: 1.5rem; font-variant-numeric: tabular-nums; letter-spacing: .5px; }
.record-dots { margin-left: auto; width: 52%; overflow: hidden; color: #81988b; font-size: 1.4rem; letter-spacing: 3px; }
.record-dots span { display: block; width: max-content; animation: voice-dots 1.3s linear infinite; }
.record-bottom { position: absolute; left: 0; right: 64px; bottom: 10px; display: flex; align-items: center; gap: 10px; min-height: 44px; }
.record-delete { width: 44px; height: 44px; padding: 10px; border: none; border-radius: 50%; color: #ba3545; background: #fae9ec; }
.record-swipe { font-size: .72rem; color: var(--muted); line-height: 1.5; }
.record-lock {
  position: absolute;
  right: 0;
  bottom: 82px;
  width: 48px;
  min-height: 48px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 12px 0;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: var(--soft);
  color: var(--accent);
  box-shadow: 0 5px 20px #173c3710;
}
.record-lock svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; }
#chat-composer:not([data-record-state="idle"]) .speaker-choice,
#chat-composer:not([data-record-state="idle"]) #message-text,
#chat-composer:not([data-record-state="idle"]) #send-text { visibility: hidden; }
#chat-composer:not([data-record-state="idle"]) .input-actions { z-index: 3; }
#chat-composer #chat-mic.recording,
#context-composer #context-mic.recording {
  background: #20c563 !important;
  color: #073e2d;
  border-color: #20c563;
  animation: none;
  box-shadow: 0 0 0 5px #20c56320;
  transform: scale(1.15);
}
#chat-composer[data-record-state="held"] .record-dots,
#chat-composer[data-record-state="locked"] .record-swipe,
#context-composer[data-record-state="held"] .record-dots,
#context-composer[data-record-state="locked"] .record-swipe { visibility: hidden; }
#context-composer:not([data-record-state="idle"]) textarea { visibility: hidden; }
#context-composer:not([data-record-state="idle"]) .input-actions { z-index: 3; }
#context-composer .record-bottom { right: 64px; }
#context-composer .record-lock { right: 0; }
@keyframes voice-dots { to { transform: translateX(-12px); } }
@media (max-width: 620px) {
  .record-panel { inset: 10px; }
  .record-bottom { gap: 6px; }
  .record-swipe { font-size: .65rem; }
}
@media (max-height: 520px) {
  body.chat-view > .topbar { padding-block: 6px; }
  body.chat-view .context-strip { display: none; }
  body.chat-view #message-form textarea { min-height: 116px; max-height: 116px; }
}
@media (prefers-reduced-motion: reduce) {
  .record-dots span { animation: none; }
}
#chat-costs { overflow-wrap: anywhere; }

/* A separate touch-sized handle resizes the input, never the history itself. */
#composer-splitter {
  flex: 0 0 24px;
  display: grid;
  place-items: center;
  cursor: row-resize;
  touch-action: none;
  user-select: none;
  border-radius: 8px;
  background: linear-gradient(var(--line), var(--line)) center / 100% 1px no-repeat;
}
#composer-splitter::before {
  content: '';
  width: 72px;
  height: 4px;
  border-radius: 4px;
  background: var(--muted);
}
#composer-splitter:hover::before,
#composer-splitter:focus-visible::before { background: var(--accent); }
body.resizing-composer { cursor: row-resize; user-select: none; }
body.chat-view #message-form textarea {
  resize: none;
  min-height: 116px;
  max-height: none;
}
