/* Bottom sheets, the thread drawer, approval / question cards, workers. */

.sheet-layer,
.drawer-layer {
  position: fixed;
  inset: 0;
}

.sheet-scrim,
.drawer-scrim {
  position: absolute;
  inset: 0;
  background: var(--c-scrim);
  opacity: 0;
  transition: opacity var(--dur-sheet) var(--ease-spring);
}

.sheet-layer[data-open="true"] .sheet-scrim,
.drawer-layer[data-open="true"] .drawer-scrim {
  opacity: 1;
}

.sheet {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  max-height: calc(100% - var(--safe-top) - var(--space-3));
  padding-bottom: max(var(--safe-bottom), var(--space-4));
  border: 1px solid var(--c-line-strong);
  border-bottom: 0;
  border-radius: var(--sheet-radius) var(--sheet-radius) 0 0;
  background: var(--c-surface-raised);
  box-shadow: var(--shadow-lg);
  outline: none;
  transform: translateY(100%);
  transition: transform var(--dur-sheet) var(--ease-spring);
  touch-action: pan-x pan-y;
  will-change: transform;
}

.sheet-layer[data-open="true"] .sheet {
  transform: translateY(0);
}

.sheet[data-dragging="true"] {
  transition: none;
}

.sheet[data-size="tall"] {
  height: 88%;
}

.sheet[data-size="full"] {
  /* A full-screen page that still drags down: nothing of the screen below peeks out. */
  height: 100%;
  max-height: 100%;
  padding-top: var(--safe-top);
  border: 0;
  border-radius: 0;
  background: var(--c-surface);
}

.sheet[data-tone="danger"] {
  border-color: var(--c-danger);
  box-shadow:
    0 0 0 1px var(--c-danger-line),
    var(--shadow-lg);
}

.sheet[data-tone="attention"] {
  border-color: var(--c-attention);
}

.sheet-grab {
  display: grid;
  place-items: center;
  flex: none;
  height: 28px;
  cursor: grab;
  touch-action: none;
}

.sheet-grab i {
  width: 40px;
  height: 5px;
  border-radius: var(--radius-pill);
  background: var(--c-line-strong);
}

.sheet-body {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 0 var(--space-5);
}

.sheet-title {
  margin-bottom: var(--space-4);
}

.sheet-title h2 {
  margin: 0;
  font-size: var(--text-xl);
  font-weight: var(--weight-semibold);
  line-height: var(--leading-tight);
}

.sheet-title p {
  margin: var(--space-1) 0 0;
  color: var(--c-ink-muted);
  font-size: var(--text-sm);
}

/* ── Approval / question card ───────────────────────────────── */
.card-sheet {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  padding-bottom: var(--space-1);
}

.cs-eyebrow {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  color: var(--c-attention);
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
}

.cs-eyebrow .dot {
  background: var(--c-attention);
  animation: pulse 1.4s var(--ease-in-out) infinite;
}

.cs-eyebrow .badge {
  margin-left: auto;
}

.card-sheet[data-tone="danger"] .cs-eyebrow {
  color: var(--c-danger);
}

.card-sheet[data-tone="danger"] .cs-eyebrow .dot {
  background: var(--c-danger);
}

.cs-origin {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
  margin: 0;
  color: var(--c-ink-muted);
  font-size: var(--text-sm);
}

.cs-origin .sep {
  color: var(--c-ink-faint);
}

.cs-worker {
  overflow: hidden;
  color: var(--c-ink-soft);
  white-space: nowrap;
  text-overflow: ellipsis;
}

.cs-title {
  margin: 0;
  font-size: var(--text-2xl);
  font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-display);
  line-height: var(--leading-tight);
  overflow-wrap: anywhere;
}

.cs-summary {
  margin: 0;
  color: var(--c-ink-soft);
  font-size: var(--text-md);
  line-height: var(--leading-body);
  overflow-wrap: anywhere;
}

.cs-detail {
  margin: 0;
  max-height: 132px;
  padding: var(--space-3) var(--space-4);
  overflow: auto;
  border-radius: var(--radius-md);
  background: var(--c-surface-sunken);
  color: var(--c-ink-soft);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  line-height: var(--leading-ui);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.cs-note {
  margin: 0;
  word-break: keep-all;
  overflow-wrap: anywhere;
  color: var(--c-ink-muted);
  font-size: var(--text-xs);
  line-height: var(--leading-ui);
}

.cs-error {
  margin: 0;
  color: var(--c-danger);
  font-size: var(--text-sm);
}

.cs-actions {
  display: grid;
  grid-template-columns: 1fr 1.35fr;
  gap: var(--space-3);
  margin-top: var(--space-2);
}

.cs-more {
  margin: 0;
  color: var(--c-ink-muted);
  font-size: var(--text-xs);
  text-align: center;
}

.cs-choices {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.btn.choice {
  justify-content: flex-start;
  font-size: var(--text-md);
}

.cs-answer {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 4px 4px 4px var(--space-4);
  border: 1px solid var(--c-line-strong);
  border-radius: var(--radius-pill);
}

.cs-input {
  flex: 1;
  min-width: 0;
  min-height: var(--touch);
  border: 0;
  outline: 0;
  background: transparent;
}

/* ── Thread drawer ──────────────────────────────────────────── */
.drawer-layer {
  z-index: 90;
}

.drawer {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  display: flex;
  flex-direction: column;
  width: min(86%, 360px);
  padding: calc(var(--safe-top) + var(--space-2)) 0 max(var(--safe-bottom), var(--space-3)) var(--safe-left);
  border-right: 1px solid var(--c-line);
  background: var(--c-sidebar);
  outline: none;
  transform: translateX(-100%);
  transition: transform var(--dur-sheet) var(--ease-spring);
}

.drawer-layer[data-open="true"] .drawer {
  transform: translateX(0);
}

.dr-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-1) var(--space-3) var(--space-3) var(--space-5);
}

.dr-brand {
  font-family: var(--font-display);
  font-size: var(--text-xl);
  font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-display);
}

.dr-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 0 var(--space-2);
}

.dr-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: 100%;
  min-height: 60px;
  padding: var(--space-2) var(--space-3);
  border: 0;
  border-radius: var(--radius-md);
  background: transparent;
  text-align: left;
}

.dr-item:active,
.dr-item[aria-current="true"] {
  background: var(--c-active);
}

.dr-title {
  overflow: hidden;
  font-size: var(--text-md);
  white-space: nowrap;
  text-overflow: ellipsis;
}

.dr-meta {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  color: var(--c-ink-muted);
  font-size: var(--text-xs);
}

.dr-state {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.dr-state[data-tone="attention"] {
  color: var(--c-attention);
  font-weight: var(--weight-medium);
}

.dr-state[data-tone="attention"] .dot {
  background: var(--c-attention);
}

.dr-state .spin {
  width: 10px;
  height: 10px;
}

.dr-empty {
  padding: var(--space-4);
  color: var(--c-ink-muted);
  font-size: var(--text-sm);
}

.dr-foot {
  padding: var(--space-2) var(--space-2) 0;
  border-top: 1px solid var(--c-line);
}

.dr-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  min-height: 60px;
  padding: 0 var(--space-3);
  border: 0;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--c-ink);
  text-align: left;
}

.dr-row:active {
  background: var(--c-active);
}

.dr-row-text {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-width: 0;
  font-size: var(--text-xs);
  color: var(--c-ink-muted);
}

.dr-row-text b {
  overflow: hidden;
  color: var(--c-ink);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  white-space: nowrap;
  text-overflow: ellipsis;
}

/* ── Workers ────────────────────────────────────────────────── */
.workers-sheet {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-height: 0;
}

.workers-wrap {
  /* Sized to the tallest card (cards stretch to match, so swiping never jumps the sheet);
     a long stream scrolls inside its card once the sheet reaches its max height. */
  min-height: 52%;
}

.workers-wrap .sheet-body {
  padding: 0;
}

.workers-sheet .sheet-title {
  padding: 0 var(--space-5);
}

.ws-head {
  margin: var(--space-1) 0 0;
  color: var(--c-ink-muted);
  font-size: var(--text-sm);
}

.ws-track {
  display: flex;
  flex: 1;
  gap: var(--space-3);
  min-height: 0;
  padding: 0 var(--space-5);
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  scroll-padding: 0 var(--space-5);
  overscroll-behavior-x: contain;
  scrollbar-width: none;
}

.ws-track::-webkit-scrollbar {
  display: none;
}

.ws-card {
  display: flex;
  flex: none;
  flex-direction: column;
  width: calc(100% - var(--space-6));
  min-height: 0;
  padding: var(--space-4);
  border: 1px solid var(--c-line-strong);
  border-radius: var(--radius-lg);
  background: var(--c-surface);
  scroll-snap-align: center;
}

.ws-card[data-status="waiting"] {
  border-color: var(--c-attention);
}

.ws-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
}

.ws-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  color: var(--c-ink-soft);
}

.ws-card[data-status="waiting"] .ws-status {
  color: var(--c-attention);
}

.ws-card[data-status="waiting"] .ws-status .dot {
  background: var(--c-attention);
}

.ws-card[data-status="failed"] .ws-status,
.ws-card[data-status="stopped"] .ws-status {
  color: var(--c-ink-muted);
}

.ws-meta {
  color: var(--c-ink-faint);
  font-size: var(--text-xs);
}

.ws-title {
  margin: var(--space-2) 0 var(--space-3);
  font-size: var(--text-lg);
  font-weight: var(--weight-semibold);
  line-height: var(--leading-tight);
  overflow-wrap: anywhere;
}

.ws-stream {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: var(--space-2);
  min-height: 0;
  overflow-y: auto;
  font-size: var(--text-sm);
  line-height: var(--leading-body);
  overflow-wrap: anywhere;
}

.ws-task {
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  background: var(--c-surface-sunken);
  color: var(--c-ink-soft);
  font-size: var(--text-xs);
  line-height: var(--leading-ui);
}

.ws-tool {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
  color: var(--c-ink-muted);
  font-size: var(--text-xs);
}

.ws-tool span {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.ws-text[data-streaming="true"] > :last-child::after {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  margin-left: 4px;
  border-radius: 50%;
  background: var(--c-ink);
  animation: pulse 1s var(--ease-in-out) infinite;
}

.ws-wait {
  margin: 0;
  color: var(--c-ink-faint);
}

.ws-card-foot {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
  padding-top: var(--space-3);
}

.ws-stop .icon {
  fill: currentColor;
}

.ws-dots {
  display: flex;
  justify-content: center;
  gap: 6px;
  padding: var(--space-3) 0 var(--space-1);
}

.ws-dots i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--c-line-strong);
  transition:
    width var(--dur-base) var(--ease-out),
    background-color var(--dur-base) var(--ease-out);
}

.ws-dots i[data-on="true"] {
  width: 18px;
  border-radius: var(--radius-pill);
  background: var(--c-ink);
}

/* P13 A6: per-conversation actions and 載入更多 in the drawer */
.dr-entry {
  display: flex;
  align-items: center;
}
.dr-entry .dr-item {
  flex: 1;
  min-width: 0;
}
.dr-more {
  flex: none;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--c-ink-faint);
  font-size: var(--text-lg);
}
.dr-more[aria-expanded="true"] {
  background: var(--c-active);
  color: var(--c-ink);
}
.dr-acts {
  display: flex;
  gap: var(--space-2);
  padding: 0 var(--space-3) var(--space-2);
}
.dr-act {
  min-height: 40px;
  padding: 0 var(--space-4);
  border: 1px solid var(--c-line);
  border-radius: var(--radius-pill, 999px);
  background: transparent;
  color: var(--c-ink);
  font-size: var(--text-sm);
}
.dr-act[data-tone="danger"] {
  color: var(--c-danger);
}
.dr-load {
  width: 100%;
  min-height: 44px;
  margin-top: var(--space-2);
  border: 0;
  background: transparent;
  color: var(--c-ink-muted);
  font-size: var(--text-sm);
}
