.app-shell {
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
}

.sidebar {
  min-height: 0;
}

.workspace {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
}

.workspace > .page:not(.chat-layout) {
  flex: 1;
  min-height: 0;
  overflow: auto;
}

.topbar {
  flex: 0 0 98px;
}

.chat-layout {
  flex: 1;
  width: 100%;
  height: auto;
  min-height: 0;
  margin: 0 auto;
}

.chat-list-panel {
  min-height: 0;
  overflow-y: auto;
}

.chat-main {
  min-height: 0;
  overflow: hidden;
}

.messages {
  min-height: 0;
  overscroll-behavior: contain;
}

.composer {
  display: flex;
  flex: 0 0 auto;
  flex-direction: column;
  gap: 8px;
  padding: 12px max(12px, 7%);
}

.composer-row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
}

.voice-input-button {
  width: 48px;
  height: 48px;
  padding: 0;
  touch-action: none;
}

.voice-input-button.recording {
  color: #ffb2aa;
  border-color: #9c4545;
  background: #351e23;
}

.voice-input-status {
  min-height: 0;
}

.composer textarea {
  min-height: 48px;
  max-height: 160px;
  resize: vertical;
  overflow: auto;
}

.attach-button {
  height: 48px;
  white-space: nowrap;
}

.attachment-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.attachment-chip,
.message-attachment {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: 100%;
  padding: 5px 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  font-size: 11px;
  overflow-wrap: anywhere;
}

.attachment-chip button {
  padding: 0 3px;
  border: 0;
  background: transparent;
  color: var(--danger);
}

.message {
  position: relative;
  padding-top: 32px;
}

.message-tools {
  position: absolute;
  top: 5px;
  right: 6px;
  z-index: 1;
  margin: 0;
}

.message-tools .message-delete {
  min-width: 26px;
  padding: 1px 7px;
  color: var(--danger);
  font-size: 15px;
  line-height: 1.2;
}

.message-audio {
  display: none;
}

.message-attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 10px;
}

.message-attachments img {
  display: block;
  max-width: min(340px, 100%);
  max-height: 280px;
  border-radius: 8px;
  object-fit: contain;
  cursor: zoom-in;
}

.message-image-frame {
  position: relative;
  max-width: min(340px, 100%);
}

.sensitive-image img {
  width: 320px;
  height: auto;
  max-height: 220px;
  filter: blur(14px);
  user-select: none;
  background: #171d28;
}

.image-revealed img {
  filter: none;
}

.image-reveal {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  width: 100%;
  padding: 12px;
  border: 0;
  border-radius: 8px;
  background: rgb(12 15 22 / 55%);
  color: #fff;
  font-size: 13px;
  opacity: 0;
  visibility: hidden;
  cursor: pointer;
}

.image-status {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  padding: 12px;
  border-radius: 8px;
  background: rgb(12 15 22 / 35%);
  color: #fff;
  font-size: 13px;
  text-align: center;
  pointer-events: none;
}

.sensitive-image:hover .image-reveal,
.sensitive-image:focus-within .image-reveal {
  opacity: 1;
  visibility: visible;
}

.image-lightbox {
  position: fixed;
  inset: 0;
  max-width: min(96vw, 1500px);
  max-height: 96dvh;
  padding: 44px 12px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #10131b;
}

.image-lightbox::backdrop {
  background: rgb(0 0 0 / 82%);
}

.image-lightbox img {
  display: block;
  max-width: calc(96vw - 24px);
  max-height: calc(96dvh - 60px);
  margin: 0 auto;
  object-fit: contain;
}

.age-verification-dialog {
  width: min(440px, calc(100vw - 32px));
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #10131b;
  color: var(--text);
}

.age-verification-dialog::backdrop {
  background: rgb(0 0 0 / 82%);
}

.age-verification-dialog h2 {
  margin: 0;
  font-size: 19px;
}

.image-lightbox-close {
  position: absolute;
  top: 7px;
  right: 7px;
  min-width: 34px;
  padding: 2px 9px;
  font-size: 21px;
}

@media (pointer: coarse) {
  .sensitive-image .image-reveal {
    opacity: 1;
    visibility: visible;
  }
}

.pending-message {
  opacity: .75;
}

.heading-actions,
.agent-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.agent-actions {
  margin-top: 12px;
}

.agent-actions button {
  flex: 1;
}

.danger-button {
  border-color: #673a3b;
  color: #ffb2aa;
}

#teamMemberAgents {
  min-height: 130px;
}

.companion-panel {
  position: relative;
  display: flex;
  flex: 0 0 280px;
  align-items: center;
  justify-content: center;
  padding: 12px max(16px, 7%);
  border-bottom: 1px solid var(--line);
  background: radial-gradient(ellipse at center, rgb(107 229 186 / 9%), transparent 70%);
}

.companion-avatar {
  position: relative;
  width: min(100%, 300px);
  height: 100%;
  overflow: hidden;
  border: 1px solid rgb(107 229 186 / 32%);
  border-radius: 22px;
  background: radial-gradient(circle, #1d3440 0%, #111c28 72%);
  box-shadow: 0 12px 38px rgb(0 0 0 / 24%), 0 0 26px rgb(107 229 186 / 12%);
}

.companion-avatar.talking {
  animation: avatar-call-pulse .9s ease-in-out infinite alternate;
}

.companion-avatar svg {
  display: block;
  width: 100%;
  height: 100%;
}

.companion-avatar-image {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.companion-avatar.custom-avatar svg {
  display: none;
}

.avatar-halo {
  fill: none;
  stroke: rgb(107 229 186 / 22%);
  stroke-width: 1;
}

.avatar-head {
  transform-origin: 50px 60px;
  animation: avatar-breathe 4.2s ease-in-out infinite;
}

.avatar-hair,
.avatar-hair-front {
  fill: var(--avatar-hair, #493c58);
}

.avatar-face {
  fill: var(--avatar-skin, #f0c4aa);
}

.avatar-brow,
.avatar-nose {
  fill: none;
  stroke: #805d57;
  stroke-linecap: round;
  stroke-width: 1.5;
}

.avatar-eye {
  fill: #273344;
  transform-box: fill-box;
  transform-origin: center;
  animation: avatar-blink 5s ease-in-out infinite;
}

.avatar-eye + .avatar-eye {
  animation-delay: .08s;
}

.avatar-mouth {
  fill: #a55364;
  transform-box: fill-box;
  transform-origin: center;
}

.talking .avatar-mouth {
  animation: avatar-talk .22s ease-in-out infinite alternate;
}

.avatar-neck,
.avatar-shirt {
  fill: var(--avatar-shirt, #6bbfba);
}

.avatar-halo {
  stroke: color-mix(in srgb, var(--avatar-accent, #6be5ba) 35%, transparent);
}

.companion-caption {
  position: absolute;
  right: max(24px, 8%);
  bottom: 20px;
  left: max(24px, 8%);
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
  padding: 10px 13px;
  border: 1px solid rgb(255 255 255 / 12%);
  border-radius: 12px;
  background: rgb(10 17 24 / 78%);
  backdrop-filter: blur(10px);
}

.companion-caption strong {
  overflow: hidden;
  font-size: 13px;
  text-overflow: ellipsis;
}

.companion-caption small {
  color: var(--muted);
  font-size: 11px;
}

.companion-avatar-admin-preview {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 72px;
}

.companion-avatar-admin-preview img {
  width: 72px;
  height: 72px;
  border: 1px solid var(--line);
  border-radius: 12px;
  object-fit: cover;
}

.response-pending {
  display: flex;
  align-items: center;
  gap: 13px;
  min-height: 76px;
  padding: 12px 15px;
}

.response-progress-ring {
  position: relative;
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
}

.response-progress-ring svg {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

.response-progress-ring circle {
  fill: none;
  stroke-width: 3;
}

.response-progress-track {
  stroke: #314252;
}

.response-progress-arc {
  stroke: var(--accent);
  stroke-dasharray: 94.2;
  stroke-dashoffset: 94.2;
  stroke-linecap: round;
}

.response-progress-ring[aria-valuenow] .response-progress-arc {
  transition: stroke-dashoffset .8s ease;
}

.response-progress-ring:not([aria-valuenow]) .response-progress-arc {
  stroke-dasharray: 24 70.2;
  stroke-dashoffset: 0;
  animation: response-ring-flow 1.2s linear infinite;
}

.response-progress-value {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--accent);
  font-size: 10px;
}

.response-progress-copy {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.response-progress-copy strong {
  font-size: 12px;
}

.response-progress-copy small {
  color: var(--muted);
  font-size: 11px;
}

.relationship-summary {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.relationship-summary strong {
  font-size: 12px;
}

.relationship-summary progress {
  width: 100%;
  height: 8px;
  accent-color: var(--accent);
}

@keyframes response-ring-flow {
  to { stroke-dashoffset: -94.2; }
}

@keyframes avatar-breathe {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-1.5px); }
}

@keyframes avatar-blink {
  0%, 44%, 48%, 100% { transform: scaleY(1); }
  46% { transform: scaleY(.1); }
}

@keyframes avatar-talk {
  from { transform: scaleY(.65); }
  to { transform: scaleY(2.4); }
}

@keyframes avatar-call-pulse {
  from { border-color: rgb(107 229 186 / 32%); }
  to { border-color: rgb(107 229 186 / 90%); }
}

@media (max-width: 650px) {
  .app-shell {
    display: flex;
    flex-direction: column;
  }

  .sidebar {
    flex: 0 0 auto;
  }

  .workspace {
    flex: 1;
    height: 0;
    padding: 0 11px 12px;
  }

  .topbar {
    height: 78px;
    flex-basis: 78px;
  }

  .chat-layout {
    display: flex;
    flex-direction: column;
    min-height: 0;
  }

  .chat-list-panel {
    flex: 0 0 auto;
    max-height: 130px;
  }

  .chat-main {
    flex: 1;
    min-height: 0;
  }

  .companion-panel {
    flex-basis: 190px;
    padding: 8px 12px;
  }

  .companion-avatar {
    width: min(100%, 190px);
  }

  .companion-caption {
    right: 20px;
    bottom: 14px;
    left: 20px;
    padding: 7px 10px;
  }

  .messages {
    flex: 1;
    min-height: 0;
  }

  .composer {
    padding: 10px 12px;
  }

  .composer-row {
    gap: 6px;
  }

  .attach-button {
    padding: 6px 8px;
    font-size: 12px;
  }

  .send-button {
    flex: 0 0 42px;
    width: 42px;
    height: 42px;
  }

  .top-actions {
    min-width: 0;
  }

  .top-actions #discordAutopilotToggle {
    padding: 7px 8px;
    font-size: 10px;
    white-space: nowrap;
  }

  .top-actions select {
    max-width: 90px;
  }
}
