/* Studio chat dock: the right-hand chat column on the crypto / TW-stock tool pages.
   Spec: designer site-chat-2026-11-23/DOCK-SPEC.md (A). Only pages with the Studio sidebar
   include it (common/studio_chat_dock.html), and it loads after chat/main.css, whose rules it
   shares through the #chat_dock_root scope; the compact sizes below override those.
   ≥1301 it is a column in #box_container's flex row (widths in sidebar.css); collapsing works
   like the left sidebar: width to 0, the 1px boundary and the handle stay. 769–1300 it is a
   drawer over the content, never remembered. ≤768 there is no dock at all.
   Area notes: docs/notes/chat.md › 右欄 */

/* the wrapper only scopes the chat rules and the event delegation; it draws no box, so the
   aside is a flex item of #box_container and the dialogs stay fixed to the viewport */
#chat_dock_root {
  display: contents;
}

#chat_dock {
  /* the DOM is moved after #box_main by studio_dock.js; order holds the place until then */
  order: 1;
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 13px;
  line-height: 1.6;
}

/* ---- ≥1301: a column, collapsible like the sidebar ---- */
@media (min-width: 1301px) {
  #chat_dock {
    position: sticky;
    top: var(--site-header-h);
    align-self: flex-start;
    flex: none;
    width: var(--st-dock-w);
    height: calc(100vh - var(--site-header-h));
    margin-left: var(--space-24);
    border-left: 1px solid var(--border-hairline);
    background: var(--bg-body);
    transition: width var(--motion-base) var(--ease-standard);
  }

  /* everything but the handle leaves the tab order and the layout the moment it collapses */
  html.st-dc #chat_dock {
    min-width: 0;
  }

  html.st-dc #chat_dock > :not(.dk-rail) {
    display: none;
  }

  #chat_dock .dk-x,
  #dk_open_m {
    display: none;
  }
}

/* the handle on the dock's left boundary: same place, look and reveal rules as .sb-handle,
   mirrored (shape in sidebar.css › Collapse handle) */
.dk-rail {
  position: absolute;
  top: 0;
  bottom: 0;
  left: -10px;
  width: 20px;
  pointer-events: none;
  z-index: 2;
}

.dk-rail .dk-handle {
  position: absolute;
  top: calc(50vh - var(--site-header-h) - 22px);
  left: 0;
  opacity: 0;
  pointer-events: none;
}

#chat_dock:hover .dk-rail .dk-handle,
.dk-rail:hover .dk-handle,
.dk-handle:focus-visible,
.dk-handle:focus,
html.st-dc .dk-rail .dk-handle {
  opacity: 1;
  pointer-events: auto;
}

@media (hover: none) {
  .dk-rail .dk-handle {
    opacity: 1;
    pointer-events: auto;
  }
}

/* open: points right (fold it away); collapsed: points left */
.dk-handle .ico {
  --ico: url("/static/img/lucide/chevron-right.svg");
}

html.st-dc .dk-rail .dk-handle .ico,
#dk_open_m .ico {
  --ico: url("/static/img/lucide/chevron-left.svg");
}

/* ---- 769–1300: a drawer over the 588 column, no scrim (reading the chart while chatting) ---- */
@media (min-width: 769px) and (max-width: 1300px) {
  #chat_dock {
    position: fixed;
    top: var(--site-header-h);
    right: 0;
    bottom: 0;
    z-index: 1020;
    width: min(360px, 92vw);
    background: var(--surface-card);
    box-shadow: var(--glass-shadow);
    transform: translateX(100%);
    visibility: hidden;
    /* closing runs at 70% of opening (canon › Motion › 收起比打開快); visibility waits for it */
    transition:
      transform calc(var(--motion-travel) * 0.7) var(--ease-standard),
      visibility 0s linear calc(var(--motion-travel) * 0.7);
  }

  html.st-dk #chat_dock {
    transform: none;
    visibility: visible;
    transition:
      transform var(--motion-travel) var(--ease-standard),
      visibility 0s;
  }

  /* the open drawer carries its handle on its left edge, always shown */
  .dk-rail .dk-handle {
    opacity: 1;
    pointer-events: auto;
  }

  /* closed: the handle waits 24 right of the 588 column's edge (50% + 294) */
  #dk_open_m {
    position: fixed;
    top: calc(50vh - 22px);
    left: calc(50% + 294px + var(--space-24) - 10px);
    z-index: 1010;
  }

  html.st-dk #dk_open_m {
    display: none;
  }
}

@media (max-width: 768px) {
  #chat_dock_root {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  #chat_dock {
    transition: none;
  }
}

/* ---- head: room segment · 客服 · (drawer only) ✕ ---- */
.dk-head {
  display: flex;
  flex: none;
  align-items: center;
  gap: var(--space-8);
  padding: var(--space-12) var(--space-12) var(--space-8) var(--space-16);
}

.dk-head .dk-sp {
  flex: 1;
}

.dk-body {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-height: 0;
}

/* room switch: the shared pill segment at the mockup's 28, with a 44 hit layer */
#chat_dock .dk-seg button {
  position: relative;
  height: 28px;
}

#chat_dock .dk-seg button::before {
  content: "";
  position: absolute;
  inset: calc(-1 * var(--space-8)) 0;
}

#chat_dock .dk-seg .chat_lock .ico {
  width: 14px;
  height: 14px;
}

#chat_dock .dk-sup {
  white-space: nowrap;
}

/* the dialogs' ✕ recipe, sitting in the head row instead of a dialog corner */
#chat_dock .dk-x {
  position: relative;
  top: auto;
  right: auto;
  flex: none;
}

/* ---- compact room (DOCK-SPEC §6): avatar 24, name 12/600, time mono 11, text 13 ---- */
#chat_dock .chat_in {
  max-width: none;
  padding: 0 var(--space-16);
}

#chat_dock .chat_stream {
  padding-top: var(--space-8);
  padding-bottom: var(--space-8);
}

#chat_dock .chat_msg {
  gap: var(--space-8);
  margin-bottom: var(--space-16);
}

/* same 44 pitch for grouped rows as the page; only the gap after a group follows the 16 above */
#chat_dock .chat_msg.cont:not(:has(+ .chat_msg.cont)) {
  margin-bottom: calc(var(--space-16) - (44px - 1.6em));
}

#chat_dock .chat_av,
#chat_dock .chat_sk .chat_sk_a {
  width: 24px;
  height: 24px;
}

#chat_dock .chat_av {
  font-size: 11px;
}

#chat_dock .chat_sk {
  gap: var(--space-8);
  margin-bottom: var(--space-16);
}

#chat_dock .chat_name {
  font-size: 12px;
}

#chat_dock .chat_cwrap {
  padding-bottom: var(--space-8);
}

/* the column sits on the page ground, so its composer takes the card surface (the drawer is
   already a card, so there it keeps the page's ground) */
@media (min-width: 1301px) {
  #chat_dock .chat_composer:not(.locked) {
    background: var(--surface-card);
  }
}

/* ---- compact walls: one card, centred in the list area ---- */
#chat_dock .chat_view[hidden],
#chat_dock .dk-wall[hidden],
#chat_dock .dk-card[hidden] {
  display: none;
}

#chat_dock .dk-wall {
  display: flex;
  flex: 1;
  align-items: center;
  min-height: 0;
  padding: var(--space-16);
  overflow-y: auto;
}

#chat_dock .dk-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  padding: var(--space-24) var(--space-16);
  border-radius: var(--radius-lg);
  background: var(--surface-card);
  box-shadow: var(--shadow-md);
  text-align: center;
}

#chat_dock .dk-card-h {
  margin: 0 0 var(--space-6);
}

#chat_dock .dk-card-p {
  margin: 0 0 var(--space-16);
  color: var(--ink-2);
  font-size: 13px;
}

#chat_dock .dk-card-alt {
  display: inline-block;
  margin-top: var(--space-12);
}
