.attachment-tray {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
  padding: 2px;
  overflow-x: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.attachment-tray[hidden],
.composer-error[hidden],
.attachment-menu[hidden] {
  display: none;
}

.attachment-card {
  position: relative;
  display: grid;
  grid-template-columns: 46px minmax(0, 1fr) 36px;
  align-items: center;
  width: min(250px, calc(100vw - 48px));
  min-width: 210px;
  min-height: 58px;
  padding: 6px;
  gap: 8px;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg2);
}

.attachment-card.is-processing {
  grid-template-columns: 46px minmax(0, 1fr);
}

.attachment-preview {
  position: relative;
  display: flex;
  width: 46px;
  height: 46px;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border-radius: 7px;
  background: var(--bg3);
  color: var(--accent2);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.06);
}

.attachment-preview img,
.attachment-preview video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.attachment-preview video {
  background: #000;
}

.attachment-file-icon {
  font-family: 'SF Mono', 'Fira Code', ui-monospace, monospace;
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.attachment-kind-badge {
  position: absolute;
  right: 3px;
  bottom: 3px;
  display: inline-flex;
  min-width: 18px;
  height: 18px;
  padding: 0 4px;
  align-items: center;
  justify-content: center;
  border-radius: 5px;
  background: rgba(12, 10, 8, 0.82);
  color: var(--text);
  font-size: 0.58rem;
  font-weight: 700;
  line-height: 1;
  backdrop-filter: blur(5px);
}

.attachment-info {
  min-width: 0;
}

.attachment-name {
  overflow: hidden;
  color: var(--text2);
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1.35;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.attachment-meta {
  margin-top: 3px;
  overflow: hidden;
  color: var(--muted);
  font-size: 0.65rem;
  font-variant-numeric: tabular-nums;
  line-height: 1.35;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.attachment-remove {
  position: relative;
  display: inline-flex;
  width: 36px;
  height: 36px;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition:
    background-color 150ms cubic-bezier(0.23, 1, 0.32, 1),
    color 150ms cubic-bezier(0.23, 1, 0.32, 1),
    transform 120ms cubic-bezier(0.23, 1, 0.32, 1);
}

.attachment-remove:hover {
  background: rgba(248, 113, 113, 0.08);
  color: var(--red);
}

.attachment-remove:active {
  transform: scale(0.97);
}

.attachment-remove:focus-visible,
.btn-attach:focus-visible,
.attachment-menu-item:focus-visible,
.capture-button:focus-visible,
.capture-close:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.attachment-progress {
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: attachment-spin 800ms linear infinite;
}

@keyframes attachment-spin {
  to { transform: rotate(360deg); }
}

.composer-error {
  margin: 0 2px 8px;
  padding: 7px 10px;
  border: 1px solid rgba(248, 113, 113, 0.2);
  border-radius: 8px;
  background: rgba(248, 113, 113, 0.06);
  color: #fca5a5;
  font-size: 0.72rem;
  line-height: 1.45;
}

.attach-control {
  position: relative;
  flex-shrink: 0;
}

.btn-attach {
  border: 1px solid var(--border);
  background: var(--bg2);
  color: var(--text2);
}

.btn-attach:hover,
.btn-attach[aria-expanded="true"] {
  border-color: var(--border-hover);
  background: var(--bg3);
  color: var(--accent2);
}

.btn-attach:active {
  transform: scale(0.97);
}

.btn-attach:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}

.attachment-menu {
  position: absolute;
  z-index: 20;
  bottom: calc(100% + 9px);
  left: 0;
  width: 250px;
  padding: 6px;
  border: 1px solid var(--border-hover);
  border-radius: 12px;
  background: var(--bg2);
  box-shadow:
    0 0 0 1px rgba(0, 0, 0, 0.2),
    0 12px 32px rgba(0, 0, 0, 0.35);
  transform-origin: bottom left;
  animation: attachment-menu-in 160ms cubic-bezier(0.23, 1, 0.32, 1);
}

@keyframes attachment-menu-in {
  from {
    opacity: 0;
    transform: translateY(4px) scale(0.97);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.attachment-menu-item {
  display: grid;
  width: 100%;
  min-height: 44px;
  grid-template-columns: 30px minmax(0, 1fr);
  align-items: center;
  padding: 6px 9px;
  gap: 8px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text2);
  font-family: inherit;
  text-align: left;
  cursor: pointer;
  transition:
    background-color 140ms cubic-bezier(0.23, 1, 0.32, 1),
    color 140ms cubic-bezier(0.23, 1, 0.32, 1);
}

.attachment-menu-item:hover {
  background: var(--bg3);
  color: var(--text);
}

.attachment-menu-icon {
  display: inline-flex;
  width: 30px;
  height: 30px;
  align-items: center;
  justify-content: center;
  border-radius: 7px;
  background: rgba(232, 144, 58, 0.08);
  color: var(--accent2);
}

.attachment-menu-copy {
  min-width: 0;
}

.attachment-menu-label {
  display: block;
  font-size: 0.76rem;
  font-weight: 600;
  line-height: 1.3;
}

.attachment-menu-hint {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.64rem;
  line-height: 1.35;
}

.message-attachments {
  display: grid;
  width: min(100%, 430px);
  gap: 7px;
  margin-top: 8px;
}

.message-attachment {
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr);
  min-height: 58px;
  align-items: center;
  gap: 9px;
  padding: 5px;
  overflow: hidden;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.025);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.06);
}

.message-attachment .attachment-preview {
  width: 54px;
  height: 54px;
}

.message-attachment.is-visual {
  display: block;
  padding: 0;
}

.message-attachment.is-visual .attachment-preview {
  width: 100%;
  height: auto;
  max-height: 320px;
  aspect-ratio: 16 / 10;
  border-radius: 8px;
}

.message-attachment.is-visual .attachment-caption {
  display: flex;
  min-width: 0;
  align-items: baseline;
  justify-content: space-between;
  padding: 7px 9px 8px;
  gap: 10px;
}

.attachment-caption .attachment-name {
  flex: 1;
}

.attachment-caption .attachment-meta {
  flex-shrink: 0;
  margin-top: 0;
}

.capture-dialog {
  inset: 0;
  width: min(620px, calc(100vw - 24px));
  max-width: none;
  max-height: calc(100dvh - 24px);
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--border-hover);
  border-radius: 16px;
  background: var(--bg2);
  color: var(--text);
  margin: auto;
  box-shadow: 0 24px 72px rgba(0, 0, 0, 0.55);
}

.capture-dialog::backdrop {
  background: rgba(6, 5, 4, 0.76);
  backdrop-filter: blur(7px);
}

.capture-shell {
  display: flex;
  min-height: 360px;
  flex-direction: column;
}

.capture-header {
  display: flex;
  min-height: 52px;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px 8px 16px;
  gap: 12px;
}

.capture-title {
  font-size: 0.94rem;
  font-weight: 650;
  letter-spacing: -0.01em;
}

.capture-close {
  display: inline-flex;
  width: 40px;
  height: 40px;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.capture-close:hover {
  background: var(--bg3);
  color: var(--text);
}

.capture-stage {
  position: relative;
  display: flex;
  min-height: 260px;
  flex: 1;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: #050504;
}

.capture-preview {
  width: 100%;
  height: 100%;
  max-height: min(62dvh, 520px);
  object-fit: contain;
  background: #050504;
}

.capture-recording {
  position: absolute;
  top: 12px;
  left: 12px;
  display: inline-flex;
  min-height: 30px;
  align-items: center;
  padding: 5px 9px;
  gap: 7px;
  border-radius: 8px;
  background: rgba(12, 10, 8, 0.76);
  color: var(--text);
  font-size: 0.69rem;
  font-variant-numeric: tabular-nums;
  backdrop-filter: blur(7px);
}

.capture-recording[hidden] {
  display: none;
}

.capture-recording-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--red);
  animation: capture-pulse 1s ease-in-out infinite;
}

@keyframes capture-pulse {
  50% { opacity: 0.35; }
}

.capture-footer {
  display: flex;
  min-height: 72px;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  gap: 12px;
}

.capture-help {
  color: var(--muted);
  font-size: 0.68rem;
  line-height: 1.45;
}

.capture-actions {
  display: flex;
  flex-shrink: 0;
  align-items: center;
  gap: 8px;
}

.capture-button {
  min-height: 42px;
  padding: 0 15px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--bg3);
  color: var(--text2);
  font-family: inherit;
  font-size: 0.76rem;
  font-weight: 600;
  cursor: pointer;
  transition:
    background-color 140ms cubic-bezier(0.23, 1, 0.32, 1),
    border-color 140ms cubic-bezier(0.23, 1, 0.32, 1),
    color 140ms cubic-bezier(0.23, 1, 0.32, 1),
    transform 120ms cubic-bezier(0.23, 1, 0.32, 1);
}

.capture-button:hover {
  border-color: var(--border-hover);
  color: var(--text);
}

.capture-button:active {
  transform: scale(0.97);
}

.capture-button.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.capture-button.recording {
  border-color: rgba(248, 113, 113, 0.5);
  background: rgba(248, 113, 113, 0.12);
  color: #fca5a5;
}

.capture-button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}

@media (max-width: 540px) {
  .attachment-menu {
    position: fixed;
    right: 12px;
    bottom: calc(68px + env(safe-area-inset-bottom, 0px));
    left: 12px;
    width: auto;
    transform-origin: bottom left;
  }

  .attachment-card {
    min-width: min(230px, calc(100vw - 32px));
  }

  .capture-dialog {
    width: calc(100vw - 16px);
    max-height: calc(100dvh - 16px);
    border-radius: 14px;
  }

  .capture-footer {
    align-items: flex-end;
  }

  .capture-help {
    max-width: 48%;
  }
}

@media (prefers-reduced-motion: reduce) {
  .attachment-menu {
    animation: none;
  }

  .attachment-remove,
  .capture-button {
    transition: none;
  }
}
