.astrid-root,
.team-chat-root {
  --team-chat-surface: var(--c-white);
  --team-chat-canvas: var(--c-surface);
  --team-chat-ink: var(--c-n900);
  --team-chat-muted: var(--c-n500);
  --team-chat-line: var(--c-g200);
  --team-chat-soft: var(--c-g50);
  --team-chat-active: var(--c-brand-400);
  --team-chat-danger: var(--c-err);
  --team-chat-radius: var(--r-sm);
}

/* ---------- standalone mode (no Iris/Anam shell) ---------- */

.team-chat-root {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 9990;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

.team-chat-launcher {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 9px;
  min-height: 48px;
  padding: 0 19px;
  border: 0;
  border-radius: var(--r-full);
  background: var(--c-btn);
  color: var(--c-white);
  font: inherit;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(22, 22, 23, 0.16), 0 12px 28px -10px rgba(22, 22, 23, 0.35);
  transition:
    transform 0.16s var(--ease),
    box-shadow 0.16s var(--ease);
}

.team-chat-launcher:hover {
  transform: translateY(-1px);
  box-shadow: 0 3px 8px rgba(22, 22, 23, 0.18), 0 16px 32px -10px rgba(22, 22, 23, 0.4);
}

.team-chat-launcher:active {
  transform: scale(0.96);
}

.team-chat-launcher:focus-visible {
  outline: 2px solid var(--team-chat-active);
  outline-offset: 2px;
}

.team-chat-launcher svg {
  width: 19px;
  height: 19px;
}

.team-chat-root[data-mode="expanded"] .team-chat-launcher {
  display: none;
}

.team-chat-card {
  position: relative;
  display: none;
  width: 380px;
  height: min(560px, calc(100vh - 32px));
  overflow: hidden;
  border: 1px solid var(--team-chat-line);
  border-radius: var(--r-lg);
  background: var(--team-chat-surface);
  box-shadow: 0 2px 8px rgba(22, 22, 23, 0.1), 0 24px 56px -16px rgba(22, 22, 23, 0.3);
}

.team-chat-root[data-mode="expanded"] .team-chat-card {
  display: block;
}

.team-chat-root .team-chat-panel {
  display: flex;
}

.astrid-mode-tabs {
  position: absolute;
  top: 10px;
  left: 10px;
  z-index: 9;
  display: inline-flex;
  gap: 3px;
  min-height: 40px;
  padding: 3px;
  border: 1px solid color-mix(in srgb, var(--team-chat-line) 82%, transparent);
  border-radius: var(--r-full);
  background: color-mix(in srgb, var(--team-chat-surface) 92%, transparent);
  box-shadow: var(--shadow-xs);
}

.astrid-root[data-team-chat="active"] .astrid-mode-tabs {
  left: 50%;
  transform: translateX(-50%);
}

.astrid-root[data-state="live"] .astrid-mode-tabs,
.astrid-root[data-state="connecting"] .astrid-mode-tabs,
.astrid-root[data-view="form"] .astrid-mode-tabs,
.astrid-root[data-view="sent"] .astrid-mode-tabs {
  display: none;
}

.astrid-mode-tab {
  min-width: 64px;
  min-height: 34px;
  padding: 0 12px;
  border: 0;
  border-radius: var(--r-full);
  background: transparent;
  color: var(--team-chat-muted);
  font: inherit;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  cursor: pointer;
  transition:
    background 0.16s var(--ease),
    color 0.16s var(--ease),
    transform 0.16s var(--ease);
}

.astrid-mode-tab:hover {
  color: var(--team-chat-ink);
}

.astrid-mode-tab:active {
  transform: scale(0.96);
}

.astrid-mode-tab:focus-visible {
  outline: 2px solid var(--team-chat-active);
  outline-offset: 2px;
}

.astrid-mode-tab.is-active {
  background: color-mix(in srgb, var(--team-chat-active) 18%, var(--team-chat-surface));
  color: var(--team-chat-ink);
}

.team-chat-panel {
  position: absolute;
  inset: 0;
  z-index: 7;
  display: none;
  flex-direction: column;
  overflow: hidden;
  background: var(--team-chat-surface);
  color: var(--team-chat-ink);
}

.astrid-root[data-team-chat="active"] .astrid-card {
  width: 380px;
  height: min(560px, calc(100vh - 32px));
  border-radius: var(--r-lg);
  background: var(--team-chat-surface);
}

.astrid-root[data-team-chat="active"] .team-chat-panel {
  display: flex;
}

.astrid-root[data-team-chat="active"] .astrid-media,
.astrid-root[data-team-chat="active"] .astrid-tag,
.astrid-root[data-team-chat="active"] .astrid-controls,
.astrid-root[data-team-chat="active"] .astrid-caption,
.astrid-root[data-team-chat="active"] .astrid-bar,
.astrid-root[data-team-chat="active"] .astrid-fallback,
.astrid-root[data-team-chat="active"] .astrid-form,
.astrid-root[data-team-chat="active"] .astrid-sent {
  display: none;
}

.team-chat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 16px 12px;
  border-bottom: 1px solid var(--team-chat-line);
}

/* in the tabbed (Iris) shell, clear the floating mode tabs */
.astrid-root .team-chat-head {
  padding-top: 58px;
}

.team-chat-head div {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}

.team-chat-head span {
  color: var(--team-chat-muted);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.2;
}

.team-chat-head strong {
  color: var(--team-chat-ink);
  font-size: 16px;
  font-weight: 800;
  line-height: 1.15;
}

.team-chat-min {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border: 1px solid var(--team-chat-line);
  border-radius: var(--r-full);
  background: var(--team-chat-soft);
  color: var(--team-chat-ink);
  cursor: pointer;
  transition:
    background 0.16s var(--ease),
    transform 0.16s var(--ease);
}

.team-chat-min:hover {
  background: color-mix(in srgb, var(--team-chat-soft) 70%, var(--team-chat-surface));
}

.team-chat-min:active {
  transform: scale(0.96);
}

.team-chat-min:focus-visible {
  outline: 2px solid var(--team-chat-active);
  outline-offset: 2px;
}

.team-chat-min svg {
  width: 18px;
  height: 18px;
}

.team-chat-guard {
  margin: 10px 16px 0;
  color: var(--team-chat-muted);
  font-size: 11.5px;
  font-weight: 500;
  line-height: 1.4;
}

.team-chat-start {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 12px;
  padding: 16px;
}

.team-chat-start[hidden],
.team-chat-live[hidden] {
  display: none;
}

.team-chat-start label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  color: var(--team-chat-muted);
  font-size: 12px;
  font-weight: 700;
}

.team-chat-start input,
.team-chat-composer textarea {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--team-chat-line);
  border-radius: var(--team-chat-radius);
  background: var(--team-chat-surface);
  color: var(--team-chat-ink);
  font: inherit;
  font-size: 14px;
  letter-spacing: 0;
  outline: none;
}

.team-chat-start input {
  padding: 0 12px;
}

.team-chat-start input::placeholder,
.team-chat-composer textarea::placeholder {
  color: var(--team-chat-muted);
}

.team-chat-start input:focus,
.team-chat-composer textarea:focus {
  border-color: var(--team-chat-active);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--team-chat-active) 24%, transparent);
}

.team-chat-start-btn {
  min-height: 44px;
  margin-top: 2px;
  border: 1px solid var(--team-chat-line);
  border-radius: var(--r-full);
  background: var(--c-btn);
  color: var(--team-chat-surface);
  font: inherit;
  font-size: 14px;
  font-weight: 800;
  cursor: pointer;
  transition:
    opacity 0.16s var(--ease),
    transform 0.16s var(--ease);
}

.team-chat-start-btn:hover {
  opacity: 0.92;
}

.team-chat-start-btn:active {
  transform: scale(0.98);
}

.team-chat-start-btn:disabled {
  cursor: default;
  opacity: 0.58;
}

.team-chat-error {
  margin: 0;
  color: var(--team-chat-danger);
  font-size: 12px;
  font-weight: 650;
}

.team-chat-hp {
  position: absolute;
  left: -9999px;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.team-chat-live {
  display: flex;
  min-height: 0;
  flex: 1;
  flex-direction: column;
}

.team-chat-transcript {
  min-height: 0;
  flex: 1;
  overflow-y: auto;
  padding: 14px 16px;
}

.team-chat-empty {
  margin: 24px 0 0;
  color: var(--team-chat-muted);
  font-size: 14px;
  line-height: 1.45;
}

.team-chat-message {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-width: 88%;
  margin: 0 0 12px;
}

.team-chat-message--visitor {
  align-items: flex-end;
  margin-left: auto;
}

.team-chat-message--staff,
.team-chat-message--system {
  align-items: flex-start;
  margin-right: auto;
}

.team-chat-message-label {
  color: var(--team-chat-muted);
  font-size: 11px;
  font-weight: 750;
}

.team-chat-bubble {
  margin: 0;
  padding: 10px 12px;
  border: 1px solid var(--team-chat-line);
  border-radius: var(--team-chat-radius);
  background: var(--team-chat-soft);
  color: var(--team-chat-ink);
  font-size: 14px;
  line-height: 1.42;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.team-chat-message--visitor .team-chat-bubble {
  background: color-mix(in srgb, var(--team-chat-active) 16%, var(--team-chat-surface));
  border-color: color-mix(in srgb, var(--team-chat-active) 34%, var(--team-chat-line));
}

.team-chat-message--system .team-chat-bubble {
  background: color-mix(in srgb, var(--c-warn-bg) 70%, var(--team-chat-surface));
  border-color: color-mix(in srgb, var(--c-warn) 30%, var(--team-chat-line));
}

.team-chat-message.is-pending {
  opacity: 0.62;
}

.team-chat-composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 44px;
  gap: 8px;
  padding: 10px 16px 8px;
  border-top: 1px solid var(--team-chat-line);
}

.team-chat-composer-label {
  min-width: 0;
}

.team-chat-composer textarea {
  max-height: 104px;
  padding: 11px 12px;
  resize: none;
  overflow-y: auto;
}

.team-chat-send {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 1px solid var(--team-chat-line);
  border-radius: var(--r-full);
  background: var(--c-btn);
  color: var(--team-chat-surface);
  cursor: pointer;
  transition:
    opacity 0.16s var(--ease),
    transform 0.16s var(--ease);
}

.team-chat-send:hover {
  opacity: 0.92;
}

.team-chat-send:active {
  transform: scale(0.96);
}

.team-chat-send:disabled {
  cursor: default;
  opacity: 0.58;
}

.team-chat-send:focus-visible {
  outline: 2px solid var(--team-chat-active);
  outline-offset: 2px;
}

.team-chat-send svg {
  width: 19px;
  height: 19px;
}

.team-chat-status {
  margin: 0;
  padding: 0 16px 14px;
  color: var(--team-chat-muted);
  font-size: 12px;
  font-weight: 650;
  line-height: 1.35;
}

.team-chat-sr {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

/* ---------- AI mode: quick actions, ai bubbles, typing ---------- */

.team-chat-quick {
  display: flex;
  gap: 8px;
  padding: 10px 16px 0;
}

.team-chat-action {
  flex: 1;
  min-height: 34px;
  padding: 0 10px;
  border: 1px solid var(--team-chat-line);
  border-radius: var(--r-full);
  background: var(--team-chat-surface);
  color: var(--team-chat-ink);
  font: inherit;
  font-size: 12px;
  font-weight: 650;
  white-space: nowrap;
  cursor: pointer;
  transition:
    background 0.16s var(--ease),
    border-color 0.16s var(--ease),
    transform 0.16s var(--ease);
}

.team-chat-action:hover {
  background: var(--team-chat-soft);
  border-color: color-mix(in srgb, var(--team-chat-ink) 18%, var(--team-chat-line));
}

.team-chat-action:active {
  transform: scale(0.96);
}

.team-chat-action:focus-visible {
  outline: 2px solid var(--team-chat-active);
  outline-offset: 2px;
}

.team-chat-action[hidden] {
  display: none;
}

.team-chat-message--ai {
  align-items: flex-start;
  margin-right: auto;
}

.team-chat-message--ai .team-chat-bubble {
  background: color-mix(in srgb, var(--team-chat-active) 7%, var(--team-chat-surface));
  border-color: color-mix(in srgb, var(--team-chat-active) 22%, var(--team-chat-line));
}

.team-chat-typing {
  display: inline-flex;
  gap: 4px;
  margin: 0 0 12px;
  padding: 12px 14px;
  border: 1px solid var(--team-chat-line);
  border-radius: var(--team-chat-radius);
  background: var(--team-chat-soft);
}

.team-chat-typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--team-chat-muted);
  animation: teamChatTyping 1.2s ease-in-out infinite;
}

.team-chat-typing span:nth-child(2) {
  animation-delay: 0.15s;
}

.team-chat-typing span:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes teamChatTyping {
  0%,
  60%,
  100% {
    opacity: 0.35;
    transform: translateY(0);
  }
  30% {
    opacity: 1;
    transform: translateY(-3px);
  }
}

/* ---------- unread badges ---------- */

.team-chat-tab-badge,
.team-chat-pill-badge {
  display: inline-grid;
  place-items: center;
  min-width: 17px;
  height: 17px;
  padding: 0 4px;
  border-radius: var(--r-full);
  background: var(--team-chat-danger);
  color: var(--c-white);
  font-size: 10px;
  font-weight: 800;
  line-height: 1;
}

.team-chat-tab-badge {
  margin-left: 6px;
  vertical-align: 1px;
}

.team-chat-tab-badge[hidden],
.team-chat-pill-badge[hidden] {
  display: none;
}

.team-chat-pill-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  box-shadow: 0 0 0 2px var(--c-white);
}

.astrid-pill {
  position: relative;
}

@media (max-width: 560px) {
  .astrid-root[data-team-chat="active"] .astrid-card {
    width: 100vw;
    height: 100dvh;
    border-radius: 0;
  }

  .team-chat-root[data-mode="expanded"] {
    right: 0;
    bottom: 0;
  }

  .team-chat-root .team-chat-card {
    width: 100vw;
    height: 100dvh;
    border: 0;
    border-radius: 0;
  }

  .team-chat-head {
    padding-top: max(16px, env(safe-area-inset-top));
  }

  .team-chat-action {
    font-size: 11px;
    padding: 0 9px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .astrid-mode-tab,
  .team-chat-min,
  .team-chat-start-btn,
  .team-chat-send,
  .team-chat-action {
    transition: none;
  }

  .team-chat-typing span {
    animation: none;
  }
}
