:root {
  color-scheme: dark;
  --bg: #111318;
  --panel: #171a21;
  --line: #2a2f3a;
  --text: #f4f5f7;
  --muted: #9aa3b2;
  --mine: #2f6df6;
  --hers: #232834;
  --control: #101218;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}

body {
  overflow: hidden;
}

.app {
  display: grid;
  grid-template-rows: auto 1fr auto;
  height: 100dvh;
  max-width: 820px;
  margin: 0 auto;
  background: var(--panel);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 64px;
  padding: calc(10px + env(safe-area-inset-top)) 14px 10px;
  border-bottom: 1px solid var(--line);
}

.name {
  font-size: 18px;
  font-weight: 700;
}

.status {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.icon-button {
  width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font-size: 24px;
}

.messages {
  min-height: 0;
  overflow-y: auto;
  padding: 16px 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scrollbar-width: none;
}

.messages::-webkit-scrollbar {
  display: none;
}

.bubble {
  position: relative;
  width: fit-content;
  max-width: min(78%, 560px);
  padding: 10px 12px;
  border-radius: 16px;
  line-height: 1.45;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 15px;
}

.bubble-text {
  display: block;
}

.bubble.me {
  align-self: flex-end;
  background: var(--mine);
  color: white;
  border-bottom-right-radius: 6px;
}

.bubble.her {
  align-self: flex-start;
  background: var(--hers);
  border: 1px solid var(--line);
  border-bottom-left-radius: 6px;
  padding-right: 34px;
}

.bubble.pending {
  color: var(--muted);
}

.copy {
  position: absolute;
  right: 7px;
  bottom: 7px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  padding: 3px 8px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: rgba(35, 40, 52, 0.9);
  color: var(--muted);
  font-size: 0;
  opacity: 0.28;
  transition: opacity 140ms ease, background 140ms ease;
}

.copy::before {
  content: "";
  width: 10px;
  height: 10px;
  border: 1.5px solid currentColor;
  border-radius: 2px;
  box-shadow: -3px 3px 0 -1px rgba(35, 40, 52, 0.9), -3px 3px 0 0 currentColor;
}

.copy:hover,
.copy:focus-visible,
.copy.copied {
  opacity: 1;
}

.copy.copied::before {
  width: 11px;
  height: 7px;
  border-top: 0;
  border-right: 0;
  border-radius: 0;
  box-shadow: none;
  transform: rotate(-45deg) translateY(-1px);
}

.bubble-image {
  display: block;
  max-width: min(260px, 64vw);
  max-height: 280px;
  margin-bottom: 8px;
  border-radius: 10px;
  object-fit: cover;
}

.composer {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 9px 10px calc(9px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: rgba(23, 26, 33, 0.96);
}

.composer-row {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) 42px;
  align-items: flex-end;
  gap: 8px;
}

.file-input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

textarea {
  min-height: 42px;
  max-height: 132px;
  resize: none;
  border: 1px solid var(--line);
  border-radius: 15px;
  padding: 10px 12px;
  outline: none;
  background: var(--control);
  color: var(--text);
  font: inherit;
  font-size: 16px;
  line-height: 1.35;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
}

textarea:focus {
  border-color: #5a8cff;
}

.composer button,
.composer .attach {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 42px;
  width: 42px;
  height: 42px;
  border: 0;
  border-radius: 13px;
  background: #f4f5f7;
  color: #111318;
  font-weight: 700;
  font-size: 16px;
  touch-action: manipulation;
  transition: opacity 140ms ease, transform 140ms ease, background 140ms ease;
}

.composer .attach {
  background: #2a2f3a;
  color: var(--text);
  font-size: 14px;
  font-weight: 700;
  user-select: none;
}

.composer .attach:active,
.composer button:active {
  transform: scale(0.96);
}

.composer .stop {
  grid-column: 3;
  grid-row: 1;
  background: #2a2f3a;
  color: var(--text);
}

.composer .send {
  grid-column: 3;
  grid-row: 1;
}

.composer .stop:not([hidden]) + .send {
  display: none;
}

.preview {
  display: grid;
  grid-template-columns: 46px minmax(0, 1fr) 30px;
  align-items: center;
  gap: 10px;
  position: relative;
  min-height: 56px;
  padding: 7px 8px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: rgba(16, 18, 24, 0.82);
  animation: preview-in 160ms ease-out;
}

.preview img {
  width: 48px;
  height: 42px;
  border-radius: 10px;
  object-fit: cover;
  border: 1px solid var(--line);
}

.preview-meta {
  min-width: 0;
}

.preview-name,
.preview-info {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.preview-name {
  color: var(--text);
  font-size: 13px;
  font-weight: 650;
}

.preview-info {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.preview button {
  min-width: 20px;
  width: 30px;
  height: 30px;
  border-radius: 10px;
  padding: 0;
  background: #2a2f3a;
  color: var(--text);
  font-size: 14px;
}

.composer button:disabled {
  opacity: 0.45;
}

@keyframes preview-in {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
