/* ==========================================================================
   chat-widget.css — Styles for the reusable Codex chat FAB + panel widget.
   All classes prefixed with cw- to avoid collisions with host page styles.
   ========================================================================== */

/* --------------------------------------------------------------------------
   CSS Custom Properties
   -------------------------------------------------------------------------- */
:root {
  --cw-bg: #0d0d0d;
  --cw-bg-elevated: #151515;
  --cw-panel-bg: #1a1a1a;
  --cw-panel-bg-2: #202020;
  --cw-border: #2f2f2f;
  --cw-border-strong: #444;
  --cw-text: #e6e6e6;
  --cw-text-muted: #989898;
  --cw-text-soft: #b6b6b6;
  --cw-accent: #d9c56d;
  --cw-accent-dim: rgba(217, 197, 109, 0.3);
  --cw-shadow: 0 24px 64px rgba(0, 0, 0, 0.5);
  --cw-radius: 20px;
  --cw-radius-sm: 12px;
  --cw-font: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --cw-mobile-top-gap: 60px;
  --cw-running-color: #e6a817;
  --cw-unread-color: #4ecdc4;
  --cw-bounce: cubic-bezier(0.34, 1.56, 0.64, 1);
  --cw-ease-out: cubic-bezier(0.25, 1, 0.5, 1);
}

/* --------------------------------------------------------------------------
   FAB — Floating Action Button
   -------------------------------------------------------------------------- */
.cw-fab-stack {
  position: fixed;
  bottom: max(16px, calc(env(safe-area-inset-bottom, 0px) + 8px));
  right: max(16px, calc(env(safe-area-inset-right, 0px) + 8px));
  z-index: 900;
  width: 56px;
  height: 56px;
  pointer-events: none;
  overflow: visible;
}

.cw-fab-stack > * {
  pointer-events: auto;
}

.cw-fab {
  position: fixed;
  bottom: max(16px, calc(env(safe-area-inset-bottom, 0px) + 8px));
  right: max(16px, calc(env(safe-area-inset-right, 0px) + 8px));
  z-index: 900;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 1px solid var(--cw-accent-dim);
  background: rgba(26, 26, 26, 0.95);
  color: var(--cw-accent);
  cursor: pointer;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  transition:
    transform 180ms var(--cw-bounce),
    box-shadow 180ms ease,
    border-color 180ms ease;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  outline: none;
  -webkit-tap-highlight-color: transparent;
}

.cw-fab-stack .cw-fab {
  position: relative;
  right: auto;
  bottom: auto;
  z-index: 1;
}

.cw-fab--fallback {
  pointer-events: none;
}

.cw-fab__satellite {
  --cw-fab-satellite-offset: -52px;
  position: absolute;
  top: 6px;
  right: 6px;
  z-index: 0;
  width: 44px;
  height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 1px solid rgba(82, 211, 139, 0.22);
  border-radius: 50%;
  background: rgba(13, 28, 20, 0.96);
  color: #52d38b;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.28);
  cursor: pointer;
  opacity: 0;
  transform: translateX(0) scale(0.78);
  transform-origin: right center;
  pointer-events: none;
  transition:
    transform 260ms var(--cw-ease-out),
    opacity 180ms ease,
    border-color 180ms ease,
    background-color 180ms ease,
    box-shadow 180ms ease;
}

.cw-fab-stack--expanded .cw-fab__satellite {
  opacity: 1;
  transform: translateX(var(--cw-fab-satellite-offset)) scale(1);
  pointer-events: auto;
}

.cw-fab__satellite:hover {
  border-color: rgba(82, 211, 139, 0.42);
  background: rgba(18, 43, 29, 0.98);
  box-shadow: 0 14px 28px rgba(7, 20, 13, 0.36);
}

.cw-fab__satellite--active {
  border-color: rgba(82, 211, 139, 0.54);
  color: #7bf0ab;
  background: rgba(21, 55, 35, 0.98);
}

.cw-fab__satellite:active {
  transform: translateX(var(--cw-fab-satellite-offset)) scale(0.98);
}

.cw-fab__satellite-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: currentColor;
}

.cw-fab:hover {
  transform: scale(1.08);
  border-color: rgba(217, 197, 109, 0.5);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
}

.cw-fab:active {
  transform: scale(0.95);
  transition-duration: 80ms;
}

.cw-fab__icon {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.cw-fab__icon svg {
  width: 100%;
  height: 100%;
}

/* Status dot on FAB */
.cw-fab__status-dot {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2.5px solid var(--cw-panel-bg);
  transition: opacity 200ms ease, background-color 300ms ease, transform 200ms ease;
  pointer-events: none;
}

.cw-fab__status-dot--hidden {
  opacity: 0;
  transform: scale(0.5);
}

.cw-fab__status-dot--running {
  background: var(--cw-running-color);
  opacity: 1;
  transform: scale(1);
  animation: cw-pulse 2s ease-in-out infinite;
}

.cw-fab__status-dot--unread {
  background: var(--cw-unread-color);
  opacity: 1;
  transform: scale(1);
}

@keyframes cw-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* --------------------------------------------------------------------------
   Panel — Floating Chat Container
   -------------------------------------------------------------------------- */
.cw-panel {
  position: fixed;
  bottom: 108px;
  right: 24px;
  z-index: 899;
  width: 420px;
  height: 600px;
  max-height: calc(100vh - 120px);
  border-radius: var(--cw-radius);
  border: 1px solid var(--cw-border);
  background: var(--cw-bg);
  color: var(--cw-text);
  font: 400 13px/1.5 var(--cw-font);
  box-shadow: var(--cw-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform-origin: bottom right;
}

/* Panel states */
.cw-panel--closed {
  transform: scale(0.3) translateY(20px);
  opacity: 0;
  pointer-events: none;
  transition: transform 180ms ease-in, opacity 150ms ease-in;
}

.cw-panel--open {
  transform: scale(1) translateY(0);
  opacity: 1;
  pointer-events: auto;
  transition: transform 280ms var(--cw-bounce), opacity 200ms ease-out;
}

.cw-panel--minimized {
  height: 52px;
  transform: scale(1) translateY(0);
  opacity: 1;
  pointer-events: auto;
  transition: height 200ms ease-out, transform 200ms ease-out;
}

.cw-panel--minimized .cw-panel__body {
  display: none;
}

.cw-panel--minimized .cw-panel__minimize-preview {
  display: flex;
}

.cw-panel:not(.cw-panel--minimized) .cw-panel__minimize-preview {
  display: none;
}

.cw-panel--minimized .cw-panel__header {
  display: none;
}

/* Input-only mode: just the composer bar floating at the bottom */
.cw-panel--input {
  height: auto;
  transform: scale(1) translateY(0);
  opacity: 1;
  pointer-events: auto;
  transition: transform 220ms var(--cw-bounce), opacity 160ms ease-out;
  border-radius: 16px;
}

.cw-panel--input .cw-panel__header {
  display: none;
}

.cw-panel--input .cw-panel__body .cw-panel__thread-rail,
.cw-panel--input .cw-panel__message-feed {
  display: none;
}

.cw-panel--input .cw-panel__body {
  display: block;
}

.cw-panel--input .cw-panel__chat-area {
  display: block;
}

.cw-panel--input .cw-panel__minimize-preview {
  display: none;
}

.cw-panel--new-thread {
  background: transparent;
  border-color: transparent;
  box-shadow: none;
  pointer-events: none;
}

.cw-panel--new-thread .cw-panel__header,
.cw-panel--new-thread .cw-panel__composer,
.cw-panel--new-thread .cw-panel__thread-rail {
  pointer-events: auto;
}

.cw-panel--new-thread .cw-panel__header,
.cw-panel--new-thread .cw-panel__composer {
  background: rgba(13, 13, 13, 0.94);
  border: 1px solid var(--cw-border);
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.32);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}

.cw-panel--new-thread .cw-panel__header {
  margin: 0 0 12px;
  border-radius: 16px;
}

.cw-panel--new-thread .cw-panel__body,
.cw-panel--new-thread .cw-panel__chat-area,
.cw-panel--new-thread .cw-panel__message-feed {
  background: transparent;
}

.cw-panel--new-thread .cw-panel__message-feed {
  pointer-events: none;
}

.cw-panel--new-thread .cw-panel__composer {
  border-top: none;
  border-radius: 16px;
}

.cw-panel--new-thread .cw-panel__title-editor {
  min-width: 0;
}

/* Topic prefix shown inside composer meta row */
.cw-panel__topic-prefix {
  display: inline-flex;
  align-items: center;
  max-width: 100%;
  background: rgba(217, 197, 109, 0.08);
  border: 1px solid rgba(217, 197, 109, 0.18);
  color: var(--cw-accent);
  border-radius: 4px;
  padding: 2px 6px;
  font-size: 11px;
  font-weight: 600;
  flex-shrink: 0;
  white-space: nowrap;
  line-height: 1.1;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cw-panel__topic-prefix:empty {
  display: none;
}

/* Embedded mode (full-page) */
.cw-panel--embedded {
  position: relative;
  width: 100%;
  height: 100%;
  max-height: none;
  border-radius: 0;
  box-shadow: none;
  border: none;
  bottom: auto;
  right: auto;
  transform: none !important;
  opacity: 1 !important;
}

/* --------------------------------------------------------------------------
   Panel Header
   -------------------------------------------------------------------------- */
.cw-panel__header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--cw-border);
  background: var(--cw-panel-bg);
  flex-shrink: 0;
  min-height: 44px;
}

.cw-panel__back-btn {
  background: none;
  border: none;
  color: var(--cw-text-soft);
  cursor: pointer;
  font-size: 16px;
  padding: 4px 6px;
  border-radius: 6px;
  transition: background 120ms ease;
}

.cw-panel__back-btn:hover {
  background: var(--cw-panel-bg-2);
}

.cw-panel__back-btn--hidden {
  display: none;
}

.cw-panel__threads-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  background: none;
  border: 1px solid var(--cw-border);
  color: var(--cw-text-soft);
  cursor: pointer;
  font: inherit;
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 8px;
  transition: background 120ms ease, border-color 120ms ease;
}

.cw-panel__threads-btn:hover {
  background: var(--cw-panel-bg-2);
  border-color: var(--cw-border-strong);
}

.cw-panel__new-thread-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: 1px solid var(--cw-border);
  color: var(--cw-accent);
  cursor: pointer;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  padding: 0;
  transition: background 120ms ease, border-color 120ms ease;
}

.cw-panel__new-thread-btn:hover {
  background: var(--cw-panel-bg-2);
  border-color: var(--cw-accent-dim);
}

/* Threads dot */
.cw-panel__threads-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  transition: opacity 200ms ease, background-color 300ms ease;
}

.cw-panel__threads-dot--hidden {
  opacity: 0;
}

.cw-panel__threads-dot--running {
  background: var(--cw-running-color);
  opacity: 1;
}

.cw-panel__threads-dot--unread {
  background: var(--cw-unread-color);
  opacity: 1;
}

.cw-panel__title {
  flex: 1;
  font-size: 13px;
  font-weight: 600;
  color: var(--cw-text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cw-panel__provider-select {
  max-width: 108px;
  border: 1px solid var(--cw-border);
  border-radius: 8px;
  background: var(--cw-panel-bg-2);
  color: var(--cw-text-soft);
  font: inherit;
  font-size: 12px;
  padding: 4px 8px;
}

.cw-panel__provider-select:focus {
  outline: none;
  border-color: var(--cw-accent-dim);
}

.cw-panel__header-actions {
  display: flex;
  align-items: center;
  gap: 2px;
}

.cw-panel__minimize-btn,
.cw-panel__close-btn {
  background: none;
  border: none;
  color: var(--cw-text-muted);
  cursor: pointer;
  padding: 6px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 120ms ease, color 120ms ease;
}

.cw-panel__minimize-btn:hover,
.cw-panel__close-btn:hover {
  background: var(--cw-panel-bg-2);
  color: var(--cw-text);
}

/* --------------------------------------------------------------------------
   Panel Body
   -------------------------------------------------------------------------- */
.cw-panel__body {
  display: flex;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

/* Thread Rail (sidebar) */
.cw-panel__thread-rail {
  width: 220px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--cw-border);
  background: var(--cw-panel-bg);
  overflow: hidden;
  transition: width 200ms ease, opacity 200ms ease;
}

.cw-panel__thread-rail--hidden {
  width: 0;
  opacity: 0;
  pointer-events: none;
  border-right: none;
}

/* Embedded mode: wider thread rail */
.cw-panel--embedded .cw-panel__thread-rail {
  width: 280px;
}

/* Topic filter pill */
.cw-panel__topic-filter {
  padding: 8px 10px 0;
}

.cw-topic-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: rgba(217, 197, 109, 0.12);
  border: 1px solid var(--cw-accent-dim);
  color: var(--cw-accent);
  border-radius: 12px;
  padding: 3px 10px;
  font-size: 11px;
  font-weight: 600;
}

.cw-topic-pill__clear {
  background: none;
  border: none;
  color: var(--cw-accent);
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  padding: 0 2px;
  opacity: 0.7;
  transition: opacity 120ms ease;
}

.cw-topic-pill__clear:hover {
  opacity: 1;
}

/* Thread search */
.cw-panel__thread-search {
  padding: 8px 10px;
}

.cw-panel__thread-search-input {
  width: 100%;
  background: var(--cw-bg);
  border: 1px solid var(--cw-border);
  border-radius: 8px;
  color: var(--cw-text);
  font: inherit;
  font-size: 16px; /* >= 16px prevents iOS zoom on focus */
  padding: 6px 10px;
  outline: none;
  transition: border-color 120ms ease;
}

.cw-panel__thread-search-input:focus {
  border-color: var(--cw-accent-dim);
}

/* Thread list */
.cw-panel__thread-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 6px 8px;
}

.cw-thread-empty {
  padding: 20px 10px;
  text-align: center;
  color: var(--cw-text-muted);
  font-size: 12px;
}

.cw-thread-group__label {
  padding: 8px 8px 4px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--cw-text-muted);
}

.cw-thread-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 10px;
  background: none;
  border: none;
  border-radius: 8px;
  color: var(--cw-text-soft);
  cursor: pointer;
  font: inherit;
  font-size: 12px;
  text-align: left;
  transition: background 120ms ease;
}

.cw-thread-item:hover {
  background: var(--cw-panel-bg-2);
}

.cw-thread-item--active {
  background: var(--cw-panel-bg-2);
  color: var(--cw-text);
  font-weight: 600;
}

.cw-thread-item--unread .cw-thread-item__title {
  color: var(--cw-text);
  font-weight: 600;
}

.cw-thread-item__title {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cw-thread-item__main {
  flex: 1;
  min-width: 0;
}

/* .cw-thread-item__category removed — group headers are sufficient */

.cw-thread-item__dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--cw-unread-color);
  flex-shrink: 0;
}

.cw-thread-item--stuck {
  border-left: 2px solid #e05555;
}

.cw-thread-item__stuck-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #e05555;
  flex-shrink: 0;
}

.cw-message--stuck-warning {
  color: #e05555;
  font-size: 12px;
  padding: 8px 12px;
  border: 1px solid rgba(224, 85, 85, 0.3);
  border-radius: 6px;
  margin-top: 8px;
  text-align: center;
}

/* Chat area */
.cw-panel__chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

/* --------------------------------------------------------------------------
   Message Feed
   -------------------------------------------------------------------------- */
.cw-panel__message-feed {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.cw-message-empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--cw-text-muted);
  font-size: 13px;
}

/* Message cards (user + final answer) */
.cw-message--card {
  background: var(--cw-panel-bg);
  border: 1px solid var(--cw-border);
  border-radius: var(--cw-radius-sm);
  padding: 10px 14px;
}

.cw-message--card.cw-message--user {
  background: var(--cw-panel-bg-2);
  border-color: var(--cw-border-strong);
}

.cw-message--card.cw-message--agent {
  border-left: 3px solid var(--cw-accent);
}

.cw-message__role {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--cw-text-muted);
  margin-bottom: 4px;
}

.cw-message__role-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.cw-message__meta {
  font-size: 10px;
  color: var(--cw-text-muted);
}

.cw-message__body {
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 13px;
  line-height: 1.55;
}

.cw-message__actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 10px;
}

.cw-message__attachment-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(88px, 1fr));
  gap: 8px;
  margin-top: 10px;
}

.cw-message__attachment-thumb {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  display: block;
  border: 1px solid var(--cw-border);
  border-radius: 10px;
  background: #101010;
}

.cw-message__review-btn.is-pending-review {
  background: #2a2112;
  border-color: #8a6630;
  color: #f1d6a3;
}

.cw-message__review-btn.is-reviewed {
  background: #1e2a20;
  border-color: #3f6143;
  color: #d7f0d9;
}

.cw-message__status-pill {
  display: inline-flex;
  align-items: center;
  padding: 4px 8px;
  border: 1px solid transparent;
  border-radius: 999px;
  font-size: 11px;
  letter-spacing: 0.02em;
}

.cw-message__status-pill--unread {
  background: #2a1820;
  border-color: #8f425c;
  color: #ffd6e3;
}

.cw-message__status-pill--review {
  background: #2a2112;
  border-color: #8a6630;
  color: #f1d6a3;
}

.cw-message__body.cw-markdown-body {
  white-space: normal;
}

.cw-markdown-body > :first-child {
  margin-top: 0;
}

.cw-markdown-body > :last-child {
  margin-bottom: 0;
}

.cw-markdown-body p,
.cw-markdown-body ul,
.cw-markdown-body ol,
.cw-markdown-body pre,
.cw-markdown-body blockquote,
.cw-markdown-body hr,
.cw-markdown-body table {
  margin: 0 0 0.9em;
}

.cw-markdown-body h1,
.cw-markdown-body h2,
.cw-markdown-body h3,
.cw-markdown-body h4,
.cw-markdown-body h5,
.cw-markdown-body h6 {
  margin: 0 0 0.7em;
  color: var(--cw-text);
  line-height: 1.2;
}

.cw-markdown-body h1 {
  font-size: 18px;
}

.cw-markdown-body h2 {
  font-size: 16px;
}

.cw-markdown-body h3,
.cw-markdown-body h4,
.cw-markdown-body h5,
.cw-markdown-body h6 {
  font-size: 14px;
}

.cw-markdown-body ul,
.cw-markdown-body ol {
  padding-left: 1.4em;
}

.cw-markdown-body li + li {
  margin-top: 0.3em;
}

.cw-markdown-body a {
  color: var(--cw-accent);
}

.cw-markdown-body code {
  display: inline-block;
  padding: 0.08rem 0.35rem;
  border: 1px solid rgba(217, 197, 109, 0.2);
  border-radius: 6px;
  background: rgba(217, 197, 109, 0.08);
  font-family: var(--cw-font);
  font-size: 0.95em;
}

.cw-markdown-body pre {
  overflow-x: auto;
  padding: 12px;
  border: 1px solid var(--cw-border);
  border-radius: 10px;
  background: rgba(10, 10, 10, 0.9);
}

.cw-markdown-body pre code {
  display: block;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
}

.cw-markdown-body blockquote {
  padding-left: 12px;
  border-left: 3px solid rgba(217, 197, 109, 0.45);
  color: var(--cw-text-soft);
}

.cw-markdown-body hr {
  border: 0;
  border-top: 1px solid var(--cw-border);
}

.cw-markdown-checkbox {
  display: inline-flex;
  align-items: flex-start;
  gap: 0.55rem;
}

.cw-markdown-checkbox__box {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1rem;
  height: 1rem;
  margin-top: 0.1rem;
  border: 1px solid rgba(217, 197, 109, 0.4);
  border-radius: 0.3rem;
  background: rgba(217, 197, 109, 0.08);
  color: var(--cw-accent);
  font-size: 0.72rem;
  line-height: 1;
  flex-shrink: 0;
}

.cw-markdown-checkbox[data-checked="true"] .cw-markdown-checkbox__box {
  background: rgba(78, 205, 196, 0.16);
  border-color: rgba(78, 205, 196, 0.42);
  color: #9ee8df;
}

.tr-notes {
  display: grid;
  gap: 18px;
  min-height: 100%;
  color: var(--cw-text);
  font: 400 13px/1.55 var(--cw-font);
}

.tr-notes--widget {
  gap: 14px;
}

.tr-notes__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.tr-notes__heading {
  min-width: 0;
}

.tr-notes__eyebrow {
  margin: 0 0 8px;
  color: var(--cw-accent);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.tr-notes__title {
  margin: 0;
  font-size: 24px;
  line-height: 1;
}

.tr-notes__subhead {
  margin: 10px 0 0;
  max-width: 52ch;
  color: var(--cw-text-soft);
}

.tr-notes__toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
}

.tr-notes__file-pill,
.tr-notes__action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  padding: 0 14px;
  border-radius: 999px;
  border: 1px solid var(--cw-border);
  background: rgba(20, 20, 20, 0.94);
  color: var(--cw-text);
  text-decoration: none;
  font: inherit;
}

.tr-notes__action {
  cursor: pointer;
  transition: border-color 160ms ease, transform 160ms var(--cw-ease-out), background-color 160ms ease;
}

.tr-notes__action:hover {
  border-color: rgba(217, 197, 109, 0.36);
  background: rgba(31, 31, 31, 0.98);
}

.tr-notes__layout {
  display: grid;
  grid-template-columns: minmax(0, 1.12fr) minmax(280px, 0.88fr);
  gap: 18px;
  min-height: 0;
}

.tr-notes__editor-shell,
.tr-notes__preview-shell {
  display: flex;
  flex-direction: column;
  min-height: 0;
  border: 1px solid var(--cw-border);
  border-radius: 18px;
  background: rgba(16, 16, 16, 0.96);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.24);
}

.tr-notes__panel-label {
  padding: 14px 16px 0;
  color: var(--cw-text-muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.tr-notes__editor {
  flex: 1;
  min-height: 420px;
  padding: 16px;
  border: 0;
  background: transparent;
  color: var(--cw-text);
  font: inherit;
  resize: vertical;
  outline: none;
}

.tr-notes__preview-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.tr-notes__status {
  padding-right: 16px;
  color: var(--cw-text-muted);
  font-size: 11px;
}

.tr-notes__status[data-state="retry_scheduled"],
.tr-notes__status[data-state="failed"] {
  color: #f4b7b7;
}

.tr-notes__preview {
  flex: 1;
  min-height: 420px;
  padding: 16px;
  overflow: auto;
}

.tr-notes__empty {
  margin: 0;
  color: var(--cw-text-muted);
}

.cw-notes-sheet {
  position: fixed;
  right: 96px;
  bottom: 108px;
  z-index: 899;
  width: min(560px, calc(100vw - 148px));
  height: min(640px, calc(100vh - 128px));
  border: 1px solid var(--cw-border);
  border-radius: var(--cw-radius);
  background: rgba(10, 10, 10, 0.98);
  box-shadow: var(--cw-shadow);
  color: var(--cw-text);
  transform-origin: bottom right;
}

.cw-notes-sheet--closed {
  opacity: 0;
  transform: translateY(18px) scale(0.96);
  pointer-events: none;
  transition: transform 180ms ease, opacity 140ms ease;
}

.cw-notes-sheet--open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
  transition: transform 240ms var(--cw-ease-out), opacity 180ms ease;
}

.cw-notes-sheet__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 18px 0;
}

.cw-notes-sheet__eyebrow {
  margin: 0 0 6px;
  color: var(--cw-accent);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.cw-notes-sheet__title {
  margin: 0;
  font-size: 20px;
}

.cw-notes-sheet__actions {
  display: inline-flex;
  gap: 8px;
}

.cw-notes-sheet__button {
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid var(--cw-border);
  border-radius: 999px;
  background: rgba(20, 20, 20, 0.96);
  color: var(--cw-text);
  font: inherit;
  cursor: pointer;
}

.cw-notes-sheet__body,
.cw-notes-sheet__editor-host {
  height: calc(100% - 70px);
}

.cw-notes-sheet__editor-host {
  padding: 18px;
}

.cw-notes-backdrop {
  position: fixed;
  inset: 0;
  z-index: 898;
  background: rgba(0, 0, 0, 0.36);
  transition: opacity 180ms ease;
}

.cw-notes-backdrop--hidden {
  opacity: 0;
  pointer-events: none;
}

@media (max-width: 768px) {
  .cw-fab__satellite {
    --cw-fab-satellite-offset: -48px;
  }

  .cw-fab-stack--expanded .cw-fab__satellite {
    transform: translateX(var(--cw-fab-satellite-offset)) scale(1);
  }

  .tr-notes__header,
  .tr-notes__layout,
  .cw-notes-sheet__header {
    grid-template-columns: 1fr;
    flex-direction: column;
  }

  .tr-notes__layout {
    grid-template-columns: 1fr;
  }

  .tr-notes__editor,
  .tr-notes__preview {
    min-height: 280px;
  }

  .cw-notes-sheet {
    right: 0;
    left: 0;
    bottom: var(--cw-mobile-fab-clearance);
    width: 100%;
    height: calc(100vh - var(--cw-mobile-top-gap) - var(--cw-mobile-fab-clearance));
    border-radius: var(--cw-radius) var(--cw-radius) 0 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .cw-fab,
  .cw-fab__status-dot,
  .cw-fab__satellite,
  .cw-notes-sheet,
  .cw-notes-backdrop,
  .cw-panel,
  .cw-backdrop {
    animation: none !important;
    transition-duration: 0.01ms !important;
  }
}

/* Inline messages (reasoning, actions, commentary) */
.cw-message-inline {
  width: 100%;
  font-size: 12px;
  line-height: 1.5;
  color: var(--cw-text);
}

.cw-message-inline-label {
  margin-right: 10px;
  color: #7f8a91;
  text-transform: uppercase;
}

.cw-message-inline-body {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.cw-message-inline-user {
  color: #d9c56d;
}

.cw-message-inline-user .cw-message-inline-label {
  color: #d9c56d;
}

.cw-message-inline-agent {
  color: #c8d6de;
}

.cw-message-inline-reasoning {
  color: #d7ae61;
}

.cw-message-inline-event,
.cw-message-inline-event .cw-message-inline-label {
  color: #8b949b;
}

.cw-message--pending {
  opacity: 0.62;
}

/* --------------------------------------------------------------------------
   Approval Cards
   -------------------------------------------------------------------------- */
.cw-approval-card {
  min-width: min(360px, 100%);
  background: var(--cw-panel-bg);
  border: 1px solid var(--cw-border);
  border-radius: var(--cw-radius-sm);
  padding: 12px;
}

.cw-approval-card h3,
.cw-approval-card p,
.cw-approval-card label,
.cw-approval-card pre {
  margin: 0;
}

.cw-approval-card h3 {
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 6px;
}

.cw-approval-card p,
.cw-approval-card label {
  font-size: 12px;
  color: var(--cw-text-muted);
}

.cw-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.cw-approval-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.cw-approval-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 10px;
}

.cw-approval-input,
.cw-approval-select {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--cw-border);
  border-radius: var(--cw-radius-sm);
  background: var(--cw-bg-elevated);
  color: var(--cw-text);
  padding: 8px 10px;
  font: inherit;
}

.cw-approval-input:focus,
.cw-approval-select:focus {
  outline: none;
  border-color: var(--cw-border-strong);
}

.cw-action-button {
  appearance: none;
  border: 1px solid var(--cw-border-strong);
  border-radius: 999px;
  background: #242424;
  color: var(--cw-text);
  cursor: pointer;
  font: inherit;
  font-size: 11px;
  padding: 8px 12px;
  white-space: nowrap;
  transition: background 120ms ease, border-color 120ms ease;
}

.cw-action-button:hover,
.cw-action-button:focus-visible {
  background: #2a2a2a;
  border-color: #585858;
  outline: none;
}

.cw-action-button-primary {
  background: #303030;
}

/* --------------------------------------------------------------------------
   Composer
   -------------------------------------------------------------------------- */
.cw-panel__composer {
  flex-shrink: 0;
  border-top: 1px solid var(--cw-border);
  background: var(--cw-panel-bg);
  padding: 10px 12px;
}

.cw-panel__composer-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.cw-panel__composer-attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.cw-panel__composer-attachment {
  position: relative;
  width: 72px;
  height: 72px;
  border: 1px solid var(--cw-border);
  border-radius: 10px;
  overflow: hidden;
  background: #101010;
}

.cw-panel__composer-attachment-thumb {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.cw-panel__composer-attachment-remove {
  position: absolute;
  right: 4px;
  bottom: 4px;
  appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 999px;
  background: rgba(13, 13, 13, 0.88);
  color: var(--cw-text);
  cursor: pointer;
  font: inherit;
  font-size: 10px;
  line-height: 1.2;
  padding: 3px 8px;
}

.cw-panel__composer-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  min-width: 0;
}

.cw-panel__thread-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1 1 auto;
  min-width: 0;
}

.cw-panel__composer-input-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.cw-panel__composer-input {
  flex: 1;
  background: var(--cw-bg);
  border: 1px solid var(--cw-border);
  border-radius: 10px;
  color: var(--cw-text);
  font: inherit;
  font-size: 16px; /* >= 16px prevents iOS zoom on focus */
  line-height: 1.5;
  padding: 8px 12px;
  resize: none;
  outline: none;
  min-height: 38px;
  max-height: 120px;
  overflow-x: hidden;
  overflow-y: hidden;
  transition: border-color 120ms ease;
}

.cw-panel__composer-input:focus {
  border-color: var(--cw-accent-dim);
}

.cw-panel__composer-input::placeholder {
  color: var(--cw-text-muted);
}

.cw-panel__send-btn {
  background: var(--cw-accent);
  color: var(--cw-bg);
  border: none;
  border-radius: 10px;
  width: 38px;
  height: 38px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 120ms ease, transform 80ms ease;
}

.cw-panel__send-btn:hover {
  background: #e5d27c;
}

.cw-panel__send-btn:active {
  transform: scale(0.92);
}

.cw-panel__send-btn:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

/* Title editor */
.cw-panel__title-editor {
  display: flex;
  align-items: center;
  flex: 1;
  min-width: 0;
}

.cw-panel__archive-btn {
  flex: 0 0 auto;
  font-size: 11px;
  padding: 3px 8px;
}

.cw-panel__topic-hint {
  font-size: 11px;
  color: #7ab4d4;
}

.cw-panel__save-status {
  font-size: 11px;
  color: var(--cw-text-muted);
}

.cw-panel__save-status[data-state="retry_scheduled"],
.cw-panel__save-status[data-state="failed"] {
  color: #f4c78b;
}

.cw-panel__title-editor-input {
  flex: 1;
  min-width: 0;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 4px;
  color: var(--cw-text-soft);
  font: inherit;
  font-size: 12px;
  line-height: 1.25;
  padding: 4px 8px;
  outline: none;
  transition: border-color 120ms ease, background 120ms ease;
}

.cw-panel__title-editor-input:focus {
  border-color: var(--cw-accent-dim);
  background: rgba(255, 255, 255, 0.05);
}

.cw-panel__title-editor-input::placeholder {
  color: var(--cw-text-muted);
  opacity: 0.6;
}

.cw-panel--new-thread .cw-panel__title-editor-input {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--cw-border);
  border-radius: 4px;
  color: var(--cw-text);
  padding: 4px 8px;
}

.cw-panel--new-thread .cw-panel__title-editor-input:focus {
  border-color: var(--cw-accent-dim);
}

@media (max-width: 560px) {
  .cw-panel__topic-prefix,
  .cw-panel__thread-controls,
  .cw-panel__title-editor {
    width: 100%;
  }

}

/* --------------------------------------------------------------------------
   Minimize Preview Bar
   -------------------------------------------------------------------------- */
.cw-panel__minimize-preview {
  display: none; /* shown via .cw-panel--minimized */
  align-items: center;
  gap: 10px;
  padding: 0 16px;
  height: 52px;
  cursor: pointer;
  transition: background 120ms ease;
}

.cw-panel__minimize-preview:hover {
  background: var(--cw-panel-bg);
}

.cw-panel__minimize-icon {
  font-size: 18px;
  flex-shrink: 0;
}

.cw-panel__minimize-content {
  display: flex;
  flex: 1;
  min-width: 0;
  flex-direction: column;
  gap: 2px;
}

.cw-panel__minimize-meta {
  color: var(--cw-text-muted);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.cw-panel__minimize-text {
  font-size: 12px;
  color: var(--cw-text-soft);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* --------------------------------------------------------------------------
   Backdrop (mobile)
   -------------------------------------------------------------------------- */
.cw-backdrop {
  position: fixed;
  inset: 0;
  z-index: 898;
  background: rgba(0, 0, 0, 0.5);
  transition: opacity 200ms ease;
}

.cw-backdrop--hidden {
  opacity: 0;
  pointer-events: none;
}

/* --------------------------------------------------------------------------
   Mobile Responsive
   -------------------------------------------------------------------------- */
@media (max-width: 768px) {
  :root {
    --cw-mobile-fab-clearance: 72px;
  }

  .cw-fab {
    bottom: max(16px, calc(env(safe-area-inset-bottom, 0px) + 10px));
    right: max(16px, calc(env(safe-area-inset-right, 0px) + 10px));
    width: 48px;
    height: 48px;
  }

  .cw-fab__icon {
    width: 24px;
    height: 24px;
  }

  .cw-fab__status-dot {
    width: 12px;
    height: 12px;
    top: 0;
    right: 0;
  }

  .cw-panel {
    top: var(--cw-mobile-top-gap);
    bottom: var(--cw-mobile-fab-clearance);
    left: 0;
    right: 0;
    width: 100%;
    height: auto;
    max-height: none;
    border-radius: var(--cw-radius) var(--cw-radius) 0 0;
    transform-origin: bottom center;
  }

  .cw-panel--closed {
    transform: translateY(100%);
    opacity: 0;
  }

  .cw-panel--open {
    transform: translateY(0);
    opacity: 1;
    transition: transform 320ms var(--cw-bounce), opacity 200ms ease-out;
  }

  .cw-panel--minimized {
    top: auto;
    bottom: var(--cw-mobile-fab-clearance);
    left: 0;
    right: 0;
    height: 56px;
    border-radius: var(--cw-radius) var(--cw-radius) 0 0;
    transform: translateY(0);
  }

  /* Thread rail takes full width on mobile */
  .cw-panel__thread-rail {
    position: absolute;
    inset: 0;
    width: 100%;
    z-index: 10;
    border-right: none;
    border-radius: inherit;
  }

  .cw-panel__thread-rail--hidden {
    transform: translateX(-100%);
    opacity: 0;
  }

  /* Embedded mode on mobile */
  .cw-panel--embedded .cw-panel__thread-rail {
    width: 100%;
    position: absolute;
  }
}

/* --------------------------------------------------------------------------
   Scrollbar styling (webkit)
   -------------------------------------------------------------------------- */
.cw-panel__message-feed::-webkit-scrollbar,
.cw-panel__thread-list::-webkit-scrollbar {
  width: 6px;
}

.cw-panel__message-feed::-webkit-scrollbar-track,
.cw-panel__thread-list::-webkit-scrollbar-track {
  background: transparent;
}

.cw-panel__message-feed::-webkit-scrollbar-thumb,
.cw-panel__thread-list::-webkit-scrollbar-thumb {
  background: var(--cw-border);
  border-radius: 3px;
}

.cw-panel__message-feed::-webkit-scrollbar-thumb:hover,
.cw-panel__thread-list::-webkit-scrollbar-thumb:hover {
  background: var(--cw-border-strong);
}
