/* Momo chat sheet on the rc7 workbench. Uses existing rc7 theme tokens only. */
.momo-chat-sheet {
  width: min(520px, calc(100vw - 28px));
  height: min(760px, calc(100dvh - 36px));
  max-width: none;
  max-height: none;
  margin: auto max(18px, env(safe-area-inset-right)) max(18px, env(safe-area-inset-bottom)) auto;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 22px;
  color: var(--text);
  background: var(--panel-strong);
  box-shadow: 0 24px 72px rgba(0, 0, 0, .28);
  padding: 0;
}
.momo-chat-sheet::backdrop { background: rgba(0, 0, 0, .32); }
.momo-chat-sheet > section { display: grid; grid-template-rows: auto minmax(0, 1fr) auto auto auto; height: 100%; }

.momo-chat-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; border-bottom: 1px solid var(--line); padding: 14px 18px; }
.momo-chat-identity { display: flex; align-items: center; gap: 12px; }
.momo-chat-identity img { width: 40px; height: 40px; border-radius: 50%; object-fit: contain; background: var(--surface-control); }
.momo-chat-identity h2 { margin: 0; font-size: 19px; font-weight: 650; }
.momo-chat-identity { margin-right: auto; }
.momo-chat-head > .momo-chat-dock { width: auto; min-height: 36px; height: auto; border: 1px solid var(--line); border-radius: 999px; padding: 6px 14px; font-size: 13px; }
.momo-chat-head > button { width: 44px; height: 44px; border: 0; border-radius: 50%; color: var(--muted); background: var(--surface-control); font-size: 22px; cursor: pointer; }

.momo-chat-messages { display: grid; align-content: end; gap: 12px; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 18px; }
.momo-chat-empty { align-self: center; color: var(--muted); padding: 40px 16px; text-align: center; }
.momo-chat-empty strong { display: block; color: var(--text); font-size: 16px; font-weight: 600; }

.momo-chat-message { display: grid; width: min(84%, 420px); }
.momo-chat-message[data-role="user"] { justify-self: end; }
.momo-chat-message[data-role="assistant"] { justify-self: start; }
.momo-chat-message > p { margin: 0; border: 1px solid var(--line); border-radius: 16px; color: var(--text); background: var(--surface-soft); padding: 10px 14px; line-height: 1.6; white-space: pre-wrap; overflow-wrap: anywhere; }
.momo-chat-message[data-role="user"] > p { color: var(--accent-ink); border-color: var(--gold); background: var(--gold); }
.momo-chat-message > small { margin-top: 4px; color: var(--muted); font-size: 13px; }
.momo-chat-message[data-role="user"] > small { text-align: right; }
.momo-chat-message details { margin-top: 6px; color: var(--muted); font-size: 13px; }
.momo-chat-message summary { width: max-content; cursor: pointer; }
.momo-chat-operation { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 6px; }
.momo-chat-undo { justify-self: start; margin-top: 6px; border: 1px solid var(--line); border-radius: 999px; color: var(--text); background: var(--surface-control); padding: 6px 12px; min-height: 32px; cursor: pointer; }

.momo-chat-interaction { margin: 0 16px 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--accent-soft); padding: 12px; }
.momo-chat-interaction p { margin: 0 0 8px; font-size: 13px; }
.momo-chat-choices { display: flex; flex-wrap: wrap; gap: 8px; }
.momo-chat-choices button { min-height: 36px; border: 1px solid var(--line); border-radius: 999px; color: var(--text); background: var(--panel); padding: 6px 12px; cursor: pointer; }

.momo-chat-composer { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; margin: 0 16px; border: 1px solid var(--line); border-radius: 16px; background: var(--surface-control); padding: 6px; }
.momo-chat-composer textarea { min-height: 44px; max-height: 132px; resize: none; border: 0; outline: none; color: var(--text); background: transparent; padding: 10px; font: inherit; line-height: 1.5; }
.momo-chat-composer textarea::placeholder { color: var(--muted); opacity: 1; }
.momo-chat-composer button { align-self: end; min-width: 68px; min-height: 44px; border: 0; border-radius: 12px; color: var(--accent-ink); background: var(--gold); padding: 0 14px; font-weight: 700; cursor: pointer; }
.momo-chat-composer button:disabled { opacity: .55; cursor: default; }
.momo-chat-sheet :focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.momo-chat-status { min-height: 30px; margin: 0; color: var(--muted); padding: 7px 20px 10px; font-size: 13px; }

@media (min-width: 821px) {
  .momo-chat-sheet[data-dock="left"] { margin: auto auto max(18px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left)); }
  .momo-chat-head { cursor: grab; touch-action: none; user-select: none; }
  .momo-chat-sheet[data-dragging] .momo-chat-head { cursor: grabbing; }
}
@media (max-width: 820px) {
  .momo-chat-head > .momo-chat-dock { display: none; }
  .momo-chat-sheet {
    width: 100%;
    height: min(calc(var(--momo-viewport-height, 100dvh) - 24px), 760px);
    margin: auto 0 var(--momo-keyboard-offset, 0);
    border-width: 1px 0 0;
    border-radius: 22px 22px 0 0;
  }
  .momo-chat-message { width: 90%; }
  .momo-chat-composer { margin-inline: 12px; }
  .momo-chat-status { padding-bottom: calc(10px + env(safe-area-inset-bottom)); }
}

@media (prefers-reduced-motion: no-preference) {
  .momo-chat-sheet[open] { animation: momo-sheet-in 160ms ease-out; }
}
@keyframes momo-sheet-in { from { opacity: 0; transform: translateY(10px); } }

/* Kain 10/20: bubbles hug their text; 查看操作 shows only after tapping that reply; nothing peeks under the sheet. */
.momo-chat-message { display: flex; flex-direction: column; align-items: flex-start; width: auto; max-width: 75%; }
.momo-chat-message[data-role="user"] { align-items: flex-end; }
.momo-chat-message > p { width: fit-content; max-width: 100%; }
.momo-chat-message details { display: none; }
.momo-chat-message.show-operations details { display: block; }
.momo-chat-message.has-operations > p { cursor: pointer; }
@media (min-width: 821px) { .momo-chat-message { max-width: min(75%, 560px); } }
@media (max-width: 820px) {
  .momo-chat-message { width: auto; max-width: 75%; }
  .momo-chat-sheet { height: calc(var(--momo-viewport-height, 100dvh) - 24px); max-height: none; margin-bottom: var(--momo-keyboard-offset, 0); }
  body[data-momo-open] .mobile-bottom-nav { visibility: hidden; }
}

/* ---- Components step 3 (P2 bar, P14 thinking, P25 copy, P78 toolbar, P56 z's) --------------------------- */
.momo-chat-sheet > section { grid-template-rows: auto minmax(0, 1fr) auto auto auto auto; }
.momo-chat-composer.ui-message { grid-template-columns: none; display: flex; margin: 0 16px; padding: 2px 4px 2px 12px; border-radius: 12px; background: var(--paper); }
.momo-chat-composer.ui-message textarea { min-height: 36px; padding: 8px 0; }
.momo-chat-composer .ui-send { align-self: flex-end; min-width: 0; min-height: 0; width: 36px; height: 36px; margin-bottom: 1px; padding: 0; border-radius: 10px; background: transparent; color: var(--muted); font-weight: 400; }
.momo-chat-composer textarea:valid ~ .ui-send, .momo-chat-composer .ui-send:hover { color: var(--accent); background: transparent; }
.momo-chat-composer .ui-send:hover { background: var(--sunken); }
.momo-chat-tools { display: flex; justify-content: flex-start; margin: 0 16px 8px; }
.momo-chat-tools .ui-toolbar button { width: 32px; height: 32px; min-height: 0; border: 0; border-radius: 50%; background: transparent; font-size: inherit; }
.momo-chat-head > .momo-chat-dock { display: none; }
.momo-chat-actions { display: flex; margin-top: 2px; }
.momo-chat-message .ui-copy { opacity: 0; transition: opacity 150ms ease; }
.momo-chat-message:hover .ui-copy, .momo-chat-message:focus-within .ui-copy, .momo-chat-message .ui-copy:is(.is-done, .is-failed) { opacity: 1; }
@media (hover: none) { .momo-chat-message .ui-copy { opacity: 1; } }
.momo-chat-message.is-thinking > p { display: inline-flex; color: var(--muted); }
.momo-chat-message.is-pending > p { opacity: .75; }
.momo-paw { position: relative; }
@media (max-width: 820px) {
  .momo-chat-tools [data-momo-dock] { display: none; }
  .momo-chat-composer.ui-message { margin-inline: 12px; }
  .momo-chat-tools { margin-inline: 12px; }
}
@media (prefers-reduced-motion: reduce) { .momo-chat-message .ui-copy { transition: none; } }

/* Result card (CI-12): what one message recorded, and what it did not and why. */
.momo-result { display: grid; gap: 10px; margin-top: 8px; border: 1px solid var(--line); border-radius: 14px; background: var(--panel); padding: 10px 12px; }
.momo-result-group h3 { margin: 0 0 4px; color: var(--muted); font-size: 13px; font-weight: 600; }
.momo-result ul { display: grid; gap: 2px; margin: 0; padding: 0; list-style: none; }
.momo-result-row { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; align-items: center; gap: 8px; min-height: 32px; font-size: 15px; }
.momo-result-label { overflow-wrap: anywhere; }
.momo-result-meta { color: var(--muted); font-size: 13px; text-align: right; }
.momo-result-row.is-undone .momo-result-label { color: var(--muted); text-decoration: line-through; }
.momo-result-row:is(.is-failed, .is-ask) { grid-template-columns: minmax(0, 1fr); gap: 0; padding: 2px 0; }
.momo-result-row:is(.is-failed, .is-ask) .momo-result-meta { text-align: left; }
.momo-result-undo { min-height: 30px; border: 1px solid var(--line); border-radius: 999px; color: var(--text); background: var(--surface-control); padding: 4px 10px; font-size: 13px; cursor: pointer; }
.momo-result-more { justify-self: start; min-height: 30px; margin-top: 2px; border: 0; color: var(--muted); background: none; padding: 4px 0; font: inherit; font-size: 13px; text-decoration: underline; cursor: pointer; }
.momo-result-batch { justify-self: end; min-height: 30px; border: 1px solid var(--line); border-radius: 999px; color: var(--text); background: var(--surface-control); padding: 4px 12px; font: inherit; font-size: 13px; cursor: pointer; }
.momo-long-list { margin-top: 8px; }
