/* 按钮与分段控件 (docs/06-design-spec.md 五「按钮」「分段控件」), shared by the parent page and the console, loaded
   after each page's own sheet. Solid colours; controls.js moves them. */

/* Secondary: white with a fine edge. */
:is(
    .secondary,
    .chips button,
    .orders-trigger,
    .confirm-cancel,
    .confirm-danger,
    .order-drawer header button
  ) {
  background: var(--ds-card);
  box-shadow: inset 0 0 0 1px var(--ds-dash);
}

/* Primary: navy, white text. */
:is(.primary, .send, .card-option, .child-submit, .confirm-ok, .boot-error button, .wechat-only button) {
  background: var(--ds-navy);
  color: var(--ds-card);
}

/* Disabled: grey fill and grey text. That is the whole signal: the pages' general fade for disabled buttons would
   wash the grey text out a second time. */
:is(.primary, .send, .card-option, .child-submit, .confirm-ok, .secondary):disabled {
  background: var(--ds-fill);
  box-shadow: none;
  color: var(--ds-ink-4);
  opacity: 1;
}

/* 分段控件: a grey track, the navy thumb under the labels, and their white copy over them, cut to the thumb by
   controls.js. */
.segmented {
  background: var(--ds-fill);
}
.seg-thumb {
  position: absolute;
  z-index: -1;
  top: 2px;
  bottom: 2px;
  border-radius: var(--ds-radius-pill);
  background: var(--ds-navy);
  cursor: grab;
}
.segmented.is-dragging .seg-thumb {
  cursor: grabbing;
}
.seg-ink {
  position: absolute;
  inset: 0;
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  padding: 2px;
  pointer-events: none;
}
.seg-ink > span {
  color: var(--ds-card);
}

/* The elastic press (controls.js sets the pivot and the classes): every button sinks toward the finger on the tight
   spring and springs back past rest on the elastic one. Text actions only dim. */
button {
  transform-origin: var(--ox, 50%) var(--oy, 50%);
  transition: transform var(--ds-spring-elastic-ms) var(--ds-spring-elastic);
}
button.is-pressed {
  transform: scale(0.96);
  transition-duration: var(--ds-spring-tight-ms);
  transition-timing-function: var(--ds-spring-tight);
}
button.is-pressed.is-deep {
  transform: scale(0.93);
}
/* Dragged off before letting go: back without the bounce, so tearing off reads differently from a tap. */
button.is-cancelled {
  transition: transform 300ms var(--ds-ease-out);
}
:is(.text-button, .oi-quote, .card-human, .history-link, .child-unbind, .child-remove-row, .orders-refresh):active {
  opacity: 0.6;
}

@media (hover: hover) and (pointer: fine) {
  :is(.secondary, .chips button, .orders-trigger, .confirm-cancel, .confirm-danger, .order-drawer header button):not(
      :disabled
    ):hover {
    background: var(--ds-fill);
  }
  :is(.primary, .send, .card-option, .child-submit, .confirm-ok, .boot-error button, .wechat-only button):not(
      :disabled
    ):hover {
    opacity: 0.9;
  }
}

/* 减弱动态效果: no sinking; the button dims under the finger instead. */
@media (prefers-reduced-motion: reduce) {
  button,
  button.is-pressed,
  button.is-pressed.is-deep {
    transform: none;
    transition: opacity 120ms ease-out;
  }
  button.is-pressed {
    opacity: 0.8;
  }
}

/* 增强对比度: a clear edge. */
@media (prefers-contrast: more) {
  :is(.secondary, .chips button, .orders-trigger, .confirm-cancel, .confirm-danger, .order-drawer header button),
  .segmented {
    box-shadow: inset 0 0 0 1px var(--ds-ink-3);
  }
}

/* —— 二次确认 (confirmDialog in app.js): an icon block, the title and what it means, the main button, and 取消
   beneath it. Centered for staff; a bottom sheet on the parent's phone that can be pulled down. —— */
.confirm-dialog {
  width: min(360px, calc(100vw - 2 * var(--ds-space-4)));
  padding: var(--ds-space-6) var(--ds-space-5) var(--ds-space-4);
  border: 0;
  border-radius: var(--ds-radius-sheet);
  background: var(--ds-card);
  color: var(--ds-ink);
  box-shadow: 0 16px 48px rgba(17, 24, 39, 0.18);
  animation: confirm-in var(--ds-pop) var(--ds-ease-out);
}
.confirm-dialog::backdrop {
  background: var(--ds-scrim);
}
.confirm-icon {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  margin-bottom: var(--ds-space-4);
  border-radius: var(--ds-radius-card);
  background: var(--ds-doing-bg);
  color: var(--ds-link);
}
.confirm-icon .ui-icon {
  width: 24px;
  height: 24px;
}
.confirm-dialog.is-danger .confirm-icon {
  background: var(--ds-danger-bg);
  color: var(--ds-danger);
}
.confirm-dialog h3 {
  margin: 0;
  font-size: var(--ds-text-16);
  font-weight: 600;
  line-height: 1.35;
}
.confirm-dialog p {
  margin: var(--ds-space-2) 0 0;
  font-size: var(--ds-text-14);
  line-height: 1.5;
  color: var(--ds-ink-2);
}
.confirm-actions {
  display: flex;
  flex-direction: column;
  margin-top: var(--ds-space-6);
}
.confirm-actions button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--ds-space-2);
  width: 100%;
  height: 44px;
  border: 0;
  border-radius: var(--ds-radius-button);
  font: inherit;
  font-size: var(--ds-text-14);
  font-weight: 500;
  cursor: pointer;
}
.confirm-ok {
  transition:
    transform var(--ds-spring-elastic-ms) var(--ds-spring-elastic),
    background-color 200ms var(--ds-ease-out);
}
.confirm-danger {
  color: var(--ds-danger);
}
/* 取消: there from the start; folds into the main button once that is pressed (.is-busy). */
.confirm-more {
  display: grid;
  grid-template-rows: 1fr;
  transition:
    grid-template-rows var(--ds-spring-tight-ms) var(--ds-spring-tight),
    opacity 120ms ease-out;
}
.confirm-more > div {
  min-height: 0;
  overflow: hidden;
}
.confirm-dialog.is-busy .confirm-more {
  grid-template-rows: 0fr;
  opacity: 0;
}
.confirm-actions .confirm-cancel {
  margin-top: var(--ds-space-2);
  background: none;
  box-shadow: none;
  color: var(--ds-ink-2);
}
/* 处理中, then 完成 in the done colour. */
.confirm-dialog.is-busy .confirm-actions button {
  pointer-events: none;
}
.confirm-spin {
  width: 16px;
  height: 16px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: confirm-spin 0.7s linear infinite;
}
.confirm-dialog.is-done :is(.confirm-ok, .confirm-danger) {
  background: var(--ds-done);
  box-shadow: none;
  color: var(--ds-card);
}
.confirm-actions .ui-icon {
  width: 18px;
  height: 18px;
}
/* The parent's phone: a sheet from the bottom with a grabber, pulled down to close. */
.confirm-dialog.as-sheet {
  width: 100%;
  max-width: 760px;
  margin: auto auto 0;
  padding-bottom: max(var(--ds-space-4), env(safe-area-inset-bottom));
  border-radius: var(--ds-radius-sheet) var(--ds-radius-sheet) 0 0;
  animation: confirm-rise var(--ds-sheet) var(--ds-ease-drawer);
  touch-action: none;
}
.confirm-dialog.as-sheet::before {
  content: '';
  position: absolute;
  top: var(--ds-space-2);
  left: 50%;
  width: 36px;
  height: 5px;
  margin-left: -18px;
  border-radius: var(--ds-radius-pill);
  background: var(--ds-dash);
}
.confirm-dialog.as-sheet .confirm-actions button {
  height: 48px;
  font-size: var(--ds-text-16);
}
.confirm-dialog.is-returning {
  transition: transform var(--ds-spring-responsive-ms) var(--ds-spring-responsive);
}
.confirm-dialog.is-leaving {
  transition: transform 200ms var(--ds-ease-out);
}
@keyframes confirm-in {
  from {
    opacity: 0;
    transform: scale(0.95);
  }
}
@keyframes confirm-rise {
  from {
    transform: translateY(100%);
  }
}
@keyframes confirm-spin {
  to {
    transform: rotate(1turn);
  }
}
@keyframes confirm-fade-in {
  from {
    opacity: 0;
  }
}
@media (prefers-reduced-motion: reduce) {
  .confirm-dialog,
  .confirm-dialog.as-sheet {
    animation: confirm-fade-in 200ms ease-out;
  }
  .confirm-more {
    transition: opacity 200ms ease-out;
  }
  .confirm-spin {
    animation-duration: 1.4s;
  }
}

/* —— 聊天附件 (attachments.js): the + and its menu, the tray, pictures in bubbles, the full-size viewer —— */
.compose-tools {
  gap: var(--ds-space-2);
}
.attach-wrap {
  position: relative;
  display: inline-flex;
}
.attach-plus {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: var(--ds-radius-pill);
  background: var(--ds-card);
  box-shadow: inset 0 0 0 1px var(--ds-dash);
  color: var(--ds-ink-2);
}
.attach-plus .ui-icon {
  width: 18px;
  height: 18px;
  transition: transform var(--ds-spring-responsive-ms) var(--ds-spring-responsive);
}
.attach-plus[aria-expanded='true'] .ui-icon {
  transform: rotate(45deg);
}
.attach-plus:disabled {
  opacity: 0.4;
}
/* Grows out of the + upward. */
.attach-menu {
  position: absolute;
  z-index: 5;
  bottom: calc(100% + var(--ds-space-2));
  left: 0;
  min-width: 160px;
  padding: var(--ds-space-1) 0;
  border-radius: var(--ds-radius-card);
  background: var(--ds-card);
  box-shadow:
    0 0 0 1px var(--ds-line),
    0 8px 24px rgba(17, 24, 39, 0.14);
  transform-origin: 16px calc(100% + 24px);
  animation: attach-menu-in var(--ds-spring-responsive-ms) var(--ds-spring-responsive);
}
.attach-menu button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  height: 44px;
  padding: 0 var(--ds-space-4);
  font-size: var(--ds-text-14);
  color: var(--ds-ink);
}
.attach-menu button + button {
  box-shadow: inset 0 1px 0 var(--ds-line);
}
.attach-menu .ui-icon {
  color: var(--ds-ink-3);
}
@media (hover: hover) and (pointer: fine) {
  .attach-menu button:hover {
    background: var(--ds-fill);
  }
}
@keyframes attach-menu-in {
  from {
    opacity: 0;
    transform: scale(0.6);
  }
}
/* The tray above the box: 64 × 64 pictures, a ring that fills while each uploads, retry on failure. */
.attach-tray {
  display: flex;
  gap: var(--ds-space-2);
  padding: var(--ds-space-2) 0 var(--ds-space-1);
  overflow-x: auto;
  scrollbar-width: none;
}
.attach-item {
  position: relative;
  flex: none;
  width: 64px;
  height: 64px;
  margin: 6px 6px 0 0;
  border-radius: 14px;
  background: var(--ds-fill);
}
.attach-item img {
  width: 100%;
  height: 100%;
  border-radius: inherit;
  object-fit: cover;
}
.attach-item.is-up img,
.attach-item.is-fail img {
  filter: brightness(0.6);
}
.attach-ring {
  position: absolute;
  inset: 16px;
  width: 32px;
  height: 32px;
  transform: rotate(-90deg);
}
.attach-ring circle {
  fill: none;
  stroke: rgba(255, 255, 255, 0.35);
  stroke-width: 3;
}
.attach-ring .attach-ring-value {
  stroke: var(--ds-card);
  stroke-linecap: round;
  stroke-dasharray: 88;
  stroke-dashoffset: calc(88 * (1 - var(--p)));
  transition: stroke-dashoffset 200ms linear;
}
.attach-retry {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  border-radius: inherit;
  color: var(--ds-card);
}
.attach-remove {
  position: absolute;
  top: -6px;
  right: -6px;
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  border-radius: var(--ds-radius-pill);
  background: rgba(17, 24, 39, 0.72);
  color: var(--ds-card);
}
.attach-remove .ui-icon {
  width: 12px;
  height: 12px;
  stroke-width: 2.4;
}
/* A bigger target than it looks. */
.attach-remove::after {
  content: '';
  position: absolute;
  inset: -12px;
}
/* Pictures in a bubble: one at its own shape, several in a grid. A bubble of pictures alone has no frame. */
.msg-images {
  display: grid;
  gap: 4px;
  margin-bottom: var(--ds-space-1);
}
.msg-images.n1 {
  grid-template-columns: max-content; /* as wide as the picture, not the bubble */
}
.msg-images.n2,
.msg-images.four {
  grid-template-columns: repeat(2, 88px);
}
.msg-images.n3:not(.four) {
  grid-template-columns: repeat(3, 76px);
}
.msg-image {
  display: block;
  padding: 0;
  overflow: hidden;
  border-radius: var(--ds-radius-control);
  background: var(--ds-fill);
}
.msg-image img {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
}
.msg-images.n1 .msg-image {
  border-radius: var(--ds-radius-card);
}
.msg-images.n1 img {
  width: auto;
  max-width: 200px; /* a fixed cap: a percentage one is ignored when the column is sized */
  max-height: 240px;
  aspect-ratio: auto;
}
.bubble.only-images {
  padding: 0;
  background: none;
  box-shadow: none;
}
.bubble.only-images .msg-images {
  margin: 0;
}
/* The full-size viewer: dragged, the picture shrinks and rounds and the backdrop fades (--fade, attachments.js). */
.viewer {
  position: fixed;
  z-index: 100;
  inset: 0;
  display: grid;
  place-items: center;
  padding: var(--ds-space-4);
  background: rgba(0, 0, 0, calc(0.92 * var(--fade, 1)));
  opacity: 0;
  touch-action: none;
  transition: opacity 200ms var(--ds-ease-out);
}
.viewer.is-open {
  opacity: 1;
}
.viewer img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  user-select: none;
  -webkit-user-drag: none;
  transition:
    transform var(--ds-spring-responsive-ms) var(--ds-spring-responsive),
    border-radius var(--ds-spring-responsive-ms) var(--ds-spring-responsive);
}
.viewer.is-dragging img {
  transition: none;
}
@media (prefers-reduced-motion: reduce) {
  .attach-menu {
    animation: confirm-fade-in 200ms ease-out;
  }
  .attach-plus .ui-icon,
  .viewer img {
    transition: none;
  }
}
/* Picture files dragged over the console's composer: it shows it will take them. */
.compose.is-dropping {
  box-shadow: inset 0 0 0 2px var(--ds-link);
  background: var(--ds-doing-bg);
}

/* —— 加载骨架 (skeleton.js) —— */
/* One band sweeps across the whole screen: the gradient is fixed to the viewport and every skeleton starts at the
   same point of one clock (--sk-delay). */
.sk-block {
  display: block;
  flex: none;
  max-width: 100%;
  border-radius: var(--ds-radius-control);
  background: linear-gradient(105deg, var(--ds-fill) 42%, var(--ds-card) 50%, var(--ds-fill) 58%) fixed;
  background-size: 200vw 100vh;
  animation: sk-sweep 1.6s linear infinite;
  animation-delay: var(--sk-delay, 0ms);
}
.sk-round {
  border-radius: var(--ds-radius-pill);
}
.sk-bubble {
  border-radius: var(--ds-radius-card);
}
@keyframes sk-sweep {
  from {
    background-position: 100vw 0;
  }
  to {
    background-position: -100vw 0;
  }
}
.sk {
  position: relative;
}
.sk-body {
  display: grid;
  gap: var(--ds-space-3);
}
.sk-row {
  display: flex;
  align-items: center;
  gap: var(--ds-space-3);
}
.sk-lines {
  flex: 1;
  display: grid;
  gap: var(--ds-space-2);
}
.sk-msg {
  display: flex;
  align-items: flex-start;
  gap: var(--ds-space-2);
}
.sk-msg.mine {
  justify-content: flex-end;
}
.sk-card {
  display: grid;
  gap: var(--ds-space-3);
  padding: var(--ds-space-4);
  border-radius: var(--ds-radius-card);
  box-shadow: inset 0 0 0 1px var(--ds-line);
}
/* Failed: still, faded, and the reason with 重试 over it. */
.sk.is-failed .sk-block {
  animation: none;
  background: var(--ds-fill);
}
.sk.is-failed .sk-body {
  opacity: 0.45;
}
.sk-failed {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: var(--ds-space-3);
  text-align: center;
}
.sk-failed p {
  margin: 0;
  font-size: var(--ds-text-14);
  color: var(--ds-ink-2);
}
.sk-failed button {
  height: 36px;
  padding: 0 var(--ds-space-5);
  border-radius: var(--ds-radius-button);
  font-size: var(--ds-text-14);
}
/* 首屏 outlines. */
.sk-boot,
.sk-boot > .sk {
  min-height: 100dvh;
}
.sk-boot {
  background: var(--ds-paper);
}
.sk-parent {
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: var(--ds-space-6);
  min-height: 100dvh;
  padding: var(--ds-space-4);
}
.sk-parent .sk-chat {
  display: grid;
  align-content: start;
  gap: var(--ds-space-5);
}
.sk-console {
  display: grid;
  grid-template-columns: 56px 260px minmax(0, 1fr) 360px;
  min-height: 100dvh;
  background: var(--ds-card);
}
.sk-console > div {
  display: grid;
  align-content: start;
  gap: var(--ds-space-4);
  padding: var(--ds-space-5) var(--ds-space-4);
}
.sk-rail {
  justify-items: center;
  border-right: 1px solid var(--ds-line);
}
.sk-list {
  background: var(--ds-fill);
}
/* On the grey columns the blocks are white, as the rows and bubbles that will replace them. */
.sk-list .sk-block,
.sk-console .sk-chat .sk-block {
  background-color: var(--ds-card);
  background-image: linear-gradient(105deg, var(--ds-card) 42%, var(--ds-fill) 50%, var(--ds-card) 58%);
}
.sk-console .sk-chat {
  gap: var(--ds-space-6);
  padding: var(--ds-space-6);
  background: var(--ds-fill);
}
.sk-side {
  border-left: 1px solid var(--ds-line);
}
/* In place of a conversation, or of orders and knowledge rows, while they load. */
.sk-thread {
  padding: var(--ds-space-6);
}
.sk-thread .sk-body {
  gap: var(--ds-space-6);
}
.sk-panel {
  padding: var(--ds-space-5);
}

/* Arriving where a skeleton was: fade in, rising 6px, row by row 60ms apart. --enter carries it across re-renders. */
.arrive-rows > *,
.arrive :is(#messages, .thread-list, .detail-scroll, .kb-rows) > * {
  animation: arrive 260ms var(--ds-ease-out) both;
  animation-delay: var(--enter, 0ms);
}
.arrive-rows > :nth-child(2),
.arrive :is(#messages, .thread-list, .detail-scroll, .kb-rows) > :nth-child(2) {
  animation-delay: calc(var(--enter, 0ms) + 60ms);
}
.arrive-rows > :nth-child(3),
.arrive :is(#messages, .thread-list, .detail-scroll, .kb-rows) > :nth-child(3) {
  animation-delay: calc(var(--enter, 0ms) + 120ms);
}
.arrive-rows > :nth-child(4),
.arrive :is(#messages, .thread-list, .detail-scroll, .kb-rows) > :nth-child(4) {
  animation-delay: calc(var(--enter, 0ms) + 180ms);
}
.arrive-rows > :nth-child(n + 5),
.arrive :is(#messages, .thread-list, .detail-scroll, .kb-rows) > :nth-child(n + 5) {
  animation-delay: calc(var(--enter, 0ms) + 240ms);
}
@keyframes arrive {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
}

/* 减弱动态效果: the skeleton breathes slowly instead of sweeping; content fades without rising. */
@media (prefers-reduced-motion: reduce) {
  .sk-block {
    background: var(--ds-fill);
    animation: sk-breathe 2s ease-in-out infinite;
  }
  .arrive-rows > *,
  .arrive :is(#messages, .thread-list, .detail-scroll, .kb-rows) > * {
    animation-name: confirm-fade-in;
    animation-duration: 200ms;
  }
}
@keyframes sk-breathe {
  50% {
    opacity: 0.55;
  }
}
