#scriptChatSection {
  min-width: 0;
  margin-top: 20px;
  padding-top: 20px;
  border-top: 1px solid var(--soft-line, #dfe5ec);
}

#scriptChatSection [hidden] {
  display: none;
}

.script-chat-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

#scriptChatSection .script-chat-actions button {
  width: auto;
  max-width: 100%;
  min-height: 44px;
  padding: 8px 16px;
  gap: 8px;
  white-space: normal;
}

.script-chat-actions button img {
  flex: 0 0 18px;
  width: 18px;
  height: 18px;
}

.script-chat-status {
  margin: 12px 0 0;
  color: var(--soft-text, #596174);
  font-size: 13px;
  line-height: 1.6;
  overflow-wrap: anywhere;
}

.script-duration-advice {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px 20px;
  margin-top: 16px;
  padding: 14px 16px;
  border: 1px solid var(--soft-line, #dfe5ec);
  border-radius: 12px;
  background: var(--soft-primary-soft, #eef0ff);
}

.script-duration-advice p {
  flex: 1 1 240px;
  margin: 0;
  color: var(--soft-ink, #2d3345);
  font-size: 13px;
  line-height: 1.7;
  overflow-wrap: anywhere;
}

#scriptChatSection .script-duration-advice button {
  flex: 0 0 auto;
  width: auto;
  min-height: 44px;
  padding: 8px 14px;
  white-space: nowrap;
}

.script-chat-result-heading {
  display: flex;
  min-width: 0;
  margin: 24px 0 8px;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px 16px;
}

.script-chat-result-heading h3 {
  min-width: 0;
  margin: 0;
  color: var(--soft-ink, #2d3345);
  font-size: 17px;
  font-weight: 700;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.script-chat-version {
  flex: 0 0 auto;
  color: var(--soft-muted, #687286);
  font-size: 12px;
  white-space: nowrap;
}

.script-chat-beats,
.script-chat-messages {
  min-width: 0;
  margin: 0;
  padding: 0;
  list-style: none;
}

.script-chat-beats > li {
  min-width: 0;
  padding: 16px 0;
  border-bottom: 1px solid var(--soft-line, #dfe5ec);
}

.script-chat-beat-heading {
  display: flex;
  min-width: 0;
  margin-bottom: 12px;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 12px;
  color: var(--soft-ink, #2d3345);
  font-size: 14px;
  line-height: 1.6;
  overflow-wrap: anywhere;
}

.script-chat-beat-heading > :first-child {
  flex: 0 0 auto;
  color: var(--soft-primary-strong, #4f46e5);
  font-variant-numeric: tabular-nums;
}

.script-chat-beat-fields,
.script-chat-beat-fields dl {
  display: grid;
  min-width: 0;
  margin: 0;
  grid-template-columns: 76px minmax(0, 1fr);
  gap: 8px 12px;
  font-size: 13px;
  line-height: 1.75;
}

.script-chat-beat-fields > dl {
  grid-column: 1 / -1;
}

.script-chat-beat-fields > div {
  display: grid;
  min-width: 0;
  grid-column: 1 / -1;
  grid-template-columns: 76px minmax(0, 1fr);
  gap: 8px 12px;
}

.script-chat-beat-fields dt,
.script-chat-beat-fields > div > :first-child {
  color: var(--soft-muted, #687286);
  font-weight: 500;
}

.script-chat-beat-fields dd,
.script-chat-beat-fields > div > :last-child {
  min-width: 0;
  margin: 0;
  color: var(--soft-ink, #2d3345);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.script-chat-conversation {
  display: grid;
  min-width: 0;
  margin-top: 24px;
  padding-top: 24px;
  gap: 20px;
  border-top: 1px solid var(--soft-line, #dfe5ec);
}

.script-chat-conversation > h4 {
  margin: 0;
  color: var(--soft-ink, #2d3345);
  font-size: 15px;
  font-weight: 650;
  line-height: 1.5;
}

.script-chat-messages {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  align-content: start;
  max-height: 420px;
  gap: 20px;
  padding-right: 4px;
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
}

.script-chat-messages:empty {
  display: none;
}

.task-script-chat-history {
  padding: 16px 0;
  border-top: 1px solid var(--soft-line, #dfe5ec);
}

.task-script-chat-history > summary {
  color: var(--soft-ink, #2d3345);
  font-size: 14px;
  font-weight: 650;
  line-height: 1.6;
  cursor: pointer;
}

.task-script-chat-history[open] > summary {
  margin-bottom: 16px;
}

.task-script-chat-history .script-chat-message {
  max-width: 100%;
}

.task-script-chat-history .script-chat-message-content {
  margin-top: 4px;
  color: #262b31;
}

.script-chat-message {
  display: flex;
  width: fit-content;
  min-width: 0;
  max-width: 84%;
  justify-self: start;
  align-items: flex-start;
  gap: 12px;
}

.script-chat-message[data-role="user"] {
  justify-self: end;
  flex-direction: row-reverse;
}

.script-chat-avatar {
  display: grid;
  flex: 0 0 28px;
  width: 28px;
  height: 28px;
  margin-top: 2px;
  place-items: center;
  border-radius: 50%;
  background: #e8eaed;
}

.script-chat-avatar > img {
  width: 16px;
  height: 16px;
}

.script-chat-message[data-role="assistant"] .script-chat-avatar {
  background: #2b3036;
}

.script-chat-message[data-role="assistant"] .script-chat-avatar > img {
  filter: invert(1);
}

.script-chat-message-body {
  min-width: 0;
  max-width: calc(100% - 40px);
  padding: 12px 16px;
  border: 1px solid var(--soft-line, #dfe5ec);
  border-radius: 4px 16px 16px;
  background: #fff;
}

.script-chat-message[data-role="user"] .script-chat-message-body {
  border-color: #dedbff;
  border-radius: 16px 4px 16px 16px;
  background: #eeedff;
}

.script-chat-speaker {
  display: block;
  color: #626870;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.5;
}

.script-chat-message[data-role="user"] .script-chat-speaker {
  text-align: right;
}

.script-chat-message-content {
  min-width: 0;
  margin: 4px 0 0;
  color: #262b31;
  font-size: 14px;
  line-height: 1.75;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.script-chat-message[data-pending="true"] .script-chat-message-content {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #626870;
}

.script-chat-message-content > img {
  flex: 0 0 16px;
  width: 16px;
  height: 16px;
  animation: script-chat-spin 1s linear infinite;
}

.script-chat-composer {
  min-width: 0;
}

.script-chat-input-row {
  display: flex;
  min-width: 0;
  padding: 6px;
  align-items: flex-end;
  gap: 8px;
  border: 1px solid #cbd0d7;
  border-radius: 8px;
  background: #fff;
  transition: border-color 160ms ease, box-shadow 160ms ease;
}

.script-chat-input-row:focus-within {
  border-color: #707a85;
  box-shadow: 0 0 0 3px rgb(43 48 54 / 8%);
}

.script-chat-input-row:has(textarea:disabled) {
  background: #f4f5f6;
}

#scriptChatSection #scriptChatMessage {
  flex: 1 1 auto;
  width: 0;
  min-width: 0;
  min-height: 48px;
  max-height: 160px;
  margin: 0;
  padding: 10px 8px;
  resize: none;
  border: 0;
  border-radius: 0;
  outline: 0;
  background: transparent;
  box-shadow: none;
  color: #262b31;
  font-size: 14px;
  line-height: 1.7;
  overflow-wrap: anywhere;
}

#scriptChatSection #scriptChatMessage::placeholder {
  color: #7b828a;
}

#scriptChatSection #reviseScriptButton.script-chat-send-button {
  display: grid;
  flex: 0 0 44px;
  width: 44px;
  min-width: 44px;
  max-width: 44px;
  height: 44px;
  min-height: 44px;
  margin: 0;
  padding: 0;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: #2b3036;
  box-shadow: none;
  cursor: pointer;
  transition: background 160ms ease;
}

#scriptChatSection #reviseScriptButton > img {
  width: 20px;
  height: 20px;
  filter: invert(1);
}

#scriptChatSection #reviseScriptButton:hover:not(:disabled) {
  background: #454c55;
}

#scriptChatSection #reviseScriptButton:focus-visible {
  outline: 2px solid #2b3036;
  outline-offset: 3px;
}

#scriptChatSection #reviseScriptButton:disabled {
  background: #e3e6ea;
  cursor: not-allowed;
  opacity: 1;
}

#scriptChatSection #reviseScriptButton:disabled > img {
  filter: none;
  opacity: 0.4;
}

#scriptChatSection #reviseScriptButton[data-busy="true"] > img {
  animation: script-chat-spin 1s linear infinite;
}

@keyframes script-chat-spin {
  to { transform: rotate(360deg); }
}

@media (max-width: 600px) {
  .script-chat-result-heading {
    flex-wrap: wrap;
    gap: 4px 12px;
  }

  .script-chat-beat-fields,
  .script-chat-beat-fields dl,
  .script-chat-beat-fields > div {
    grid-template-columns: 60px minmax(0, 1fr);
    column-gap: 8px;
  }

  .script-chat-message {
    max-width: 92%;
    gap: 8px;
  }

  .script-chat-message-body {
    max-width: calc(100% - 36px);
    padding: 10px 12px;
  }

  .script-chat-message-content,
  #scriptChatSection #scriptChatMessage {
    font-size: 16px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .script-chat-input-row,
  #scriptChatSection #reviseScriptButton {
    transition: none;
  }

  .script-chat-message-content > img,
  #scriptChatSection #reviseScriptButton[data-busy="true"] > img {
    animation: none;
  }
}
