/* The 작업 tab's chat (js/workchat.js): the conversation beside the work being made.
   It fills whatever box work.js gives it: the right-hand column on a computer, the sheet at
   the bottom on a phone (.work-sheet, work.css). Colours come from the tokens in styles.css,
   so the dark theme follows by itself.
   It is drawn as the AI assistant's card on the 공부 page is: its head, bubbles, message box, mic
   and send button carry the assistant's own classes (styles.css .agent-head, .agent-avatar,
   .agent-msg.user / .assistant, .agent-compose, .agent-input, .agent-btn.agent-mic / .agent-send),
   and its box is .agent-skin, which takes the card's own rules (styles.css, :is(.agent-panel.docked,
   .agent-skin)): the user's bubble on the right, the assistant writing on the card, the one round
   message box with the input, the mic and the send button. What is here is only what the work chat
   has besides (cards, chips, the selected part, the sheet on a phone). */

.wch {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  min-width: 0;
}

/* ---------- the conversation ---------- */

.wch-list {
  flex: 1;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain; /* (scrolling the chat never scrolls the canvas or the page) */
  padding: 8px 18px 10px; /* (the assistant's card's list) */
  display: flex;
  flex-direction: column;
  gap: 10px;
}
/* (the assistant's bubbles, agent-msg, with their size and spacing: the animation is the work chat's) */
.wch-msg {
  animation: wch-in 0.2s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}
@keyframes wch-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
}
/* A message waiting for the plan to start: it goes as soon as it does. */
.wch-user.is-held {
  opacity: 0.55;
}
/* Its answer: written on the card as the assistant's is, holding paragraphs (written out, so not pre-wrap) and cards. */
.wch-ai {
  display: flex;
  flex-direction: column;
  gap: 8px;
  white-space: normal;
}
/* The engine's own lines (what it will make, halfway, the end) and its offer of news or a joke:
   tinted as the assistant's status line is (what it is doing now). */
.wch .agent-msg.wch-ai.is-event,
.wch .agent-msg.wch-ai.is-offer {
  padding: 7px 12px;
  border-radius: 12px;
  background: color-mix(in srgb, var(--accent) 7%, transparent);
}
.wch-text {
  min-width: 0;
}
.wch-text.muted {
  color: var(--muted);
}
.wch-error {
  color: var(--bad);
  font-size: 13px;
}

/* A small line of its own: the pace was changed in the chat. */
.wch-line {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  color: var(--muted);
}
.wch-list > .wch-line {
  align-self: center;
}
.wch-line .icon {
  color: var(--accent);
  flex: none;
}

/* The AI is answering: three dots. */
.wch-dots {
  display: inline-flex;
  gap: 4px;
  padding: 6px 2px;
}
.wch-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  opacity: 0.35;
  animation: wch-dot 1.1s ease-in-out infinite;
}
.wch-dots span:nth-child(2) {
  animation-delay: 0.15s;
}
.wch-dots span:nth-child(3) {
  animation-delay: 0.3s;
}
@keyframes wch-dot {
  40% {
    opacity: 1;
    transform: translateY(-3px);
  }
}

/* ---------- cards: one for each change, with where it stands ---------- */

.wch-card {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 10px;
  padding: 7px 10px 8px;
  font-size: 13px;
  line-height: 1.5;
  min-width: 0;
}
/* Feedback the student gave (on the canvas, or by a button) stands on their side. */
.wch-list > .wch-card {
  max-width: 88%;
  animation: wch-in 0.2s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}
.wch-card.is-user {
  align-self: flex-end;
  background: var(--surface-2);
}
.wch-ai .wch-card {
  background: var(--surface);
  border-color: var(--line);
}
/* Feedback the student gave stands on their side, in the colour of their bubbles. */
.wch-list > .wch-card.is-user {
  background: var(--accent-soft);
  border-color: transparent;
  border-radius: 18px 18px 6px 18px;
}
.wch-card-head {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}
.wch-card-head > .icon {
  flex: none;
  color: var(--accent);
}
.wch-card.is-failed .wch-card-head > .icon {
  color: var(--bad);
}
.wch-card-target {
  font-weight: 650;
  color: var(--ink);
  white-space: nowrap;
}
.wch-card-state {
  margin-left: auto;
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11.5px;
  font-weight: 600;
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--surface-3);
  color: var(--muted);
}
.wch-card-state .spinner {
  width: 10px;
  height: 10px;
  border-width: 1.5px;
}
.wch-card.is-queued .wch-card-state {
  background: var(--warn-soft);
  color: var(--warn);
}
.wch-card.is-applying .wch-card-state {
  background: var(--accent-soft);
  color: var(--accent-text);
}
.wch-card.is-applied .wch-card-state {
  background: var(--good-soft);
  color: var(--good);
}
.wch-card-text {
  margin-top: 2px;
  color: var(--ink-2);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.wch-card.is-cancelled .wch-card-text {
  color: var(--muted);
  text-decoration: line-through;
  text-decoration-color: color-mix(in srgb, var(--muted) 60%, transparent);
}
.wch-card.is-failed {
  border-color: color-mix(in srgb, var(--bad) 35%, transparent);
}
.wch-card-acts {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 4px;
}
.wch-card-btn {
  appearance: none;
  border: 0;
  background: none;
  padding: 2px 0;
  font: inherit;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--accent-text);
  cursor: pointer;
}
.wch-card-btn:hover {
  text-decoration: underline;
  text-underline-offset: 3px;
}
.wch-card-btn:focus-visible {
  outline: none;
  box-shadow: var(--ring);
  border-radius: 4px;
}

/* ---------- over the input: the selected part ---------- */

/* (the assistant's message box stands on the card with no line above it) */
.wch-compose {
  flex: none;
}
.wch-context {
  display: flex;
  padding: 8px 12px 0;
}
.wch-context-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  max-width: 100%;
  padding: 2px 4px 2px 9px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-text);
  font-size: 12.5px;
  font-weight: 600;
}
.wch-context-chip > span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.wch-context-x {
  appearance: none;
  border: 0;
  background: transparent;
  color: inherit;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: inline-grid;
  place-items: center;
  cursor: pointer;
  flex: none;
}
.wch-context-x:hover {
  background: color-mix(in srgb, var(--accent) 16%, transparent);
}
/* The assistant's message box (agent-compose, as its card's): the selected part's chip sits over it. */
.wch .agent-compose {
  border-top: 0;
}
.wch-input {
  max-height: 140px;
  field-sizing: content;
}
.wch-input::placeholder {
  color: var(--muted);
}
.wch-input:focus-visible {
  box-shadow: none;
}
/* While it answers, the round button is its stop (or nothing to press, where an answer cannot be stopped). */
.wch .agent-send.busy:disabled {
  opacity: 0.55;
}
/* The mic while it listens: the helper's (red, a stop), with a ring as loud as the voice. */
.wch .agent-mic.live {
  box-shadow: 0 0 0 calc(var(--wch-level, 0) * 6px) color-mix(in srgb, var(--bad, #e5484d) 30%, transparent);
  transition: box-shadow 0.08s linear;
}

/* ---------- its head: the helper's, with the speaker ---------- */

.wch-head {
  flex: none;
}
.wch-speak {
  position: relative;
}
.wch-speak[aria-pressed="true"] {
  color: var(--accent-text, var(--accent));
}
/* Reading aloud off: the speaker struck through. */
.wch-speak.is-off::after {
  content: "";
  position: absolute;
  left: 7px;
  right: 7px;
  top: 50%;
  height: 2px;
  border-radius: 1px;
  background: currentColor;
  transform: rotate(-40deg);
}
/* Speaking: the ✦ breathes, as the helper's button did while it spoke. */
.wch.is-speaking .wch-head .agent-avatar {
  animation: wch-speak 1s ease-in-out infinite;
}
@keyframes wch-speak {
  50% {
    box-shadow: 0 0 0 5px rgb(120 110 250 / 0.25), 0 2px 8px rgb(90 80 240 / 0.3);
  }
}

/* No work chat here (no Claude key): a note where the input would be. */
.wch-note {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin: 0 12px 12px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}
.wch-note .icon {
  flex: none;
  margin-top: 2px;
}

/* ---------- the Study chat's pieces (chatparts.js, spec 23.6) ---------- */

/* Under an answer: copy and ⋯ (styles.css .msg-actions .msg-act), at its left as the words begin. */
.wch-meta {
  display: flex;
  align-items: center;
  min-height: 26px;
  margin-top: -4px;
}
.wch-meta .msg-actions {
  margin-left: -6px;
}
/* With a mouse they show when the answer is pointed at (and under the newest); on touch screens they are always there. */
@media (hover: hover) {
  .wch-ai .wch-meta .msg-actions {
    opacity: 0;
    transition: opacity 0.12s ease;
  }
  .wch-ai:hover .wch-meta .msg-actions,
  .wch-ai:focus-within .wch-meta .msg-actions,
  .wch-ai:last-child .wch-meta .msg-actions {
    opacity: 1;
  }
}
/* Selected words are purple, as in every chat (styles.css .msg ::selection). */
.wch-list ::selection {
  background: rgb(138 92 246 / 0.32);
  color: inherit;
}
/* Phones and tablets: the conversation is selected with the app's own selection, not the
   phone's (chatparts.js touchSelect): no phone menu, handles or magnifier on it. */
html.touch-ui .wch-list .wch-msg {
  position: relative;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
/* What a message carried over its words: the words selected (styles.css .msg-quote), files. */
.wch-user .wch-quote {
  display: -webkit-box;
  margin: 0 0 6px;
  max-width: 100%;
}
.wch-user .msg-files {
  margin-bottom: 6px;
}
.wch-user .file-chip {
  padding-right: 9px;
  background: var(--surface);
  border-color: var(--line);
}
.wch-said {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
/* The tiles over the box: selected words and files as the Study chat's cards, as high as a
   picture tile here (work.css: a little lower than the Study chat's). */
.wch-attach .quote-card,
.wch-attach .file-card {
  gap: 4px;
  padding: 8px 11px;
}
.wch-attach .quote-card-text {
  -webkit-line-clamp: 2;
}
.wch-attach .file-card-icon {
  width: 24px;
  height: 24px;
  border-radius: 7px;
}

/* ---------- in the sheet on a phone ---------- */

/* Folded: only the AI's last line (one line; a tap opens the sheet) and the input. */
.wch-last {
  appearance: none;
  border: 0;
  background: transparent;
  flex: none;
  display: block;
  width: 100%;
  padding: 6px 16px 4px;
  font: inherit;
  font-size: 13px;
  color: var(--ink-2);
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
}
.wch.wch-folded .wch-list,
.wch.wch-folded .wch-head {
  display: none;
}
.wch-sheet .wch-compose {
  padding-bottom: env(safe-area-inset-bottom);
}
/* (in the sheet its head sits under the sheet's handle: no line of its own above it) */
.wch-sheet .wch-head {
  padding-top: 4px;
}

@media (max-width: 560px) {
  .wch-list {
    padding: 10px 12px 8px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .wch-msg,
  .wch-list > .wch-card {
    animation: none;
  }
  .wch-dots span {
    animation: none;
    opacity: 0.7;
  }
  .wch.is-speaking .wch-head .agent-avatar,
  .wch .agent-mic.live {
    animation: none;
    transition: none;
  }
}
