*, *::before, *::after {
  box-sizing: border-box;
}

html,
body,
#root {
  min-height: 100%;
}

body {
  margin: 0;
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #111827;
  background: #eef2f6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body.image-viewer-open {
  overflow: hidden;
}

button,
textarea {
  font: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
}

.app-shell {
  min-height: 100vh;
  max-width: 560px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(circle at 20% 12%, rgba(255, 255, 255, 0.72), transparent 28%),
    linear-gradient(180deg, #f7fbff 0%, #dfe8f1 100%);
  position: relative;
  overflow: hidden;
}

.topbar {
  height: 64px;
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: 44px 1fr 28px;
  align-items: center;
  gap: 8px;
  padding: max(10px, env(safe-area-inset-top)) 14px 10px;
  background: rgba(255, 255, 255, 0.92);
  border-bottom: 1px solid rgba(15, 23, 42, 0.08);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  z-index: 10;
}

.icon-button {
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 18px;
  background: #edf2f7;
  color: #111827;
  cursor: pointer;
}

.icon-button,
.attachment-button,
.reaction-button,
.reaction-add,
.reaction-picker-button,
.reaction-picker button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.icon-button svg,
.attachment-button svg,
.reaction-button svg,
.reaction-add svg,
.reaction-picker-button svg,
.reaction-picker button svg,
.icon {
  display: block;
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

.icon-button span {
  display: block;
  font-size: 32px;
  line-height: 26px;
  transform: translateY(-1px);
}

.topbar-main {
  min-width: 0;
}

.topbar-title {
  font-weight: 700;
  font-size: 16px;
  line-height: 20px;
}

.topbar-subtitle {
  color: #64748b;
  font-size: 12px;
  line-height: 16px;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #22c55e;
  justify-self: center;
  box-shadow: 0 0 0 4px rgba(34, 197, 94, 0.12);
}

.status-dot.is-deleted {
  background: #ef4444;
  box-shadow: 0 0 0 4px rgba(239, 68, 68, 0.12);
}

.chat-window {
  flex: 1;
  overflow-y: auto;
  padding: 12px 12px 104px;
  background-color: #dce8f3;
  background-image:
    radial-gradient(circle at 18px 18px, rgba(255, 255, 255, 0.34) 0 2px, transparent 3px),
    radial-gradient(circle at 78px 52px, rgba(255, 255, 255, 0.24) 0 2px, transparent 3px);
  background-size: 112px 112px;
}

.system-card {
  margin: 0 auto 12px;
  max-width: 440px;
  padding: 12px 14px;
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid rgba(148, 163, 184, 0.22);
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.08);
}

.system-card.is-warning {
  border-color: rgba(239, 68, 68, 0.25);
  background: #fff7f7;
}

.system-card-title {
  font-size: 14px;
  line-height: 18px;
  font-weight: 700;
  color: #0f172a;
}

.system-card-text {
  margin-top: 3px;
  font-size: 13px;
  line-height: 18px;
  color: #64748b;
}

.day-pill {
  width: fit-content;
  margin: 8px auto 14px;
  padding: 5px 12px;
  border-radius: 999px;
  background: rgba(100, 116, 139, 0.35);
  color: #fff;
  font-size: 12px;
  line-height: 16px;
  font-weight: 600;
}

.empty-thread {
  margin: 24px auto;
  width: fit-content;
  max-width: 280px;
  padding: 10px 14px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.72);
  color: #64748b;
  text-align: center;
  font-size: 13px;
  line-height: 18px;
}

.message-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin: 0 0 10px;
  animation: fade-in 160ms ease-out;
}

.message-row.is-new .message-bubble {
  box-shadow: 0 0 0 2px rgba(47, 128, 237, 0.35), 0 8px 18px rgba(15, 23, 42, 0.08);
}

.avatar {
  flex: 0 0 auto;
  margin-top: 2px;
  border-radius: 50%;
  color: #fff;
  font-weight: 700;
  display: grid;
  place-items: center;
  overflow: hidden;
  user-select: none;
}

.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.message-stack {
  min-width: 0;
  max-width: calc(100% - 48px);
}

.message-bubble {
  position: relative;
  width: fit-content;
  max-width: 100%;
  min-width: 84px;
  padding: 8px 10px 22px;
  background: #fff;
  border-radius: 4px 14px 14px 14px;
  box-shadow: 0 4px 14px rgba(15, 23, 42, 0.08);
}

.message-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 24px;
  align-items: center;
  gap: 8px;
}

.message-author {
  margin-bottom: 3px;
  color: #2f80ed;
  font-size: 12px;
  line-height: 16px;
  font-weight: 700;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.moderation-delete {
  width: 24px;
  height: 24px;
  border: 0;
  border-radius: 50%;
  background: #fee2e2;
  color: #b42318;
  font-size: 18px;
  line-height: 20px;
  cursor: pointer;
}

.message-text {
  color: #111827;
  font-size: 14px;
  line-height: 20px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.message-meta {
  position: absolute;
  right: 10px;
  bottom: 6px;
  color: #94a3b8;
  font-size: 11px;
  line-height: 14px;
}

.quote {
  margin: 2px 0 6px;
  padding: 5px 8px;
  border-left: 3px solid #2f80ed;
  border-radius: 0 8px 8px 0;
  background: #eff6ff;
}

.quote-author {
  color: #2f80ed;
  font-size: 12px;
  line-height: 16px;
  font-weight: 700;
}

.quote-text {
  color: #64748b;
  font-size: 12px;
  line-height: 16px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.reply-button {
  margin: 3px 0 0 4px;
  padding: 0;
  border: 0;
  background: transparent;
  color: #64748b;
  font-size: 12px;
  line-height: 18px;
  font-weight: 600;
  cursor: pointer;
}

.comment-attachments {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(92px, 1fr));
  gap: 6px;
  margin-top: 7px;
  max-width: min(320px, 100%);
}

.comment-attachment {
  display: block;
  width: 100%;
  aspect-ratio: 1 / 1;
  padding: 0;
  border: 0;
  border-radius: 8px;
  overflow: hidden;
  background: #e2e8f0;
  cursor: pointer;
}

.comment-attachment img {
  display: block;
  width: 100%;
  height: 100%;
  max-width: 100%;
  object-fit: cover;
}

.reaction-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  margin: 4px 0 0 4px;
}

.reaction-chip,
.reaction-add,
.reaction-picker button {
  border: 0;
  cursor: pointer;
  background: rgba(255, 255, 255, 0.86);
  color: #334155;
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.08);
}

.reaction-chip {
  min-width: 42px;
  height: 26px;
  padding: 0 8px;
  border-radius: 13px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  font-size: 13px;
}

.reaction-chip strong {
  font-size: 12px;
  line-height: 16px;
}

.reaction-chip.is-selected {
  background: #dbeafe;
  color: #1d4ed8;
  box-shadow: 0 0 0 1px rgba(47, 128, 237, 0.26);
}

.reaction-add {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  font-size: 13px;
}

.reaction-button-icon {
  display: block;
  line-height: 1;
  transform: translateY(0);
}

.reaction-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  width: min(256px, 100%);
  margin: 5px 0 0 4px;
  padding: 6px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.72);
  box-shadow: 0 8px 20px rgba(15, 23, 42, 0.12);
}

.reaction-picker button {
  width: 32px;
  height: 32px;
  border-radius: 16px;
  font-size: 17px;
}

.reply-thread {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.reply-thread .message-row {
  margin-bottom: 0;
}

.composer {
  position: fixed;
  left: 50%;
  bottom: 0;
  width: min(560px, 100%);
  transform: translateX(-50%);
  padding: 8px 10px max(10px, env(safe-area-inset-bottom));
  background: rgba(247, 250, 252, 0.94);
  border-top: 1px solid rgba(15, 23, 42, 0.08);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  z-index: 20;
}

.submit-error {
  margin: 0 2px 8px;
  color: #b42318;
  font-size: 12px;
  line-height: 16px;
  font-weight: 600;
}

.submit-error:empty {
  display: none;
}

.reply-preview {
  display: grid;
  grid-template-columns: 1fr 28px;
  align-items: center;
  gap: 8px;
  margin: 0 2px 8px;
  padding: 7px 8px;
  border-left: 3px solid #2f80ed;
  border-radius: 0 10px 10px 0;
  background: #eff6ff;
}

.reply-preview-name {
  color: #2f80ed;
  font-size: 12px;
  line-height: 16px;
  font-weight: 700;
}

.reply-preview-text {
  color: #64748b;
  font-size: 12px;
  line-height: 16px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.reply-preview button {
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 14px;
  background: transparent;
  color: #64748b;
  font-size: 20px;
  cursor: pointer;
}

.composer-row {
  display: grid;
  grid-template-columns: 42px 1fr 42px;
  align-items: end;
  gap: 8px;
}

.attach-button {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: #fff;
  color: #334155;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.08);
  border: 1px solid rgba(148, 163, 184, 0.26);
}

.icon-paperclip {
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.attach-button input {
  display: none;
}

.attach-button.is-disabled {
  opacity: 0.55;
  cursor: default;
}

.selected-photos {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 6px;
  margin: 0 2px 8px;
}

.selected-photo {
  position: relative;
  aspect-ratio: 1 / 1;
  border-radius: 8px;
  overflow: hidden;
  background: #e2e8f0;
}

.selected-photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.selected-photo button {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 22px;
  height: 22px;
  border: 0;
  border-radius: 50%;
  background: rgba(15, 23, 42, 0.74);
  color: #fff;
  font-size: 16px;
  line-height: 18px;
  cursor: pointer;
}

.composer textarea {
  width: 100%;
  min-height: 42px;
  max-height: 112px;
  resize: none;
  border: 1px solid rgba(148, 163, 184, 0.28);
  border-radius: 21px;
  padding: 10px 14px;
  outline: none;
  background: #fff;
  color: #111827;
  font-size: 14px;
  line-height: 20px;
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.05);
}

.composer textarea:focus {
  border-color: rgba(47, 128, 237, 0.55);
}

.send-button {
  width: 42px;
  height: 42px;
  border: 0;
  border-radius: 50%;
  background: #2f80ed;
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 18px;
  cursor: pointer;
  box-shadow: 0 6px 16px rgba(47, 128, 237, 0.28);
}

.send-button:disabled {
  background: #cbd5e1;
  box-shadow: none;
  cursor: default;
}

.state-view {
  min-height: 100vh;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 10px;
  padding: 24px;
  text-align: center;
}

.state-title {
  color: #0f172a;
  font-size: 18px;
  line-height: 24px;
  font-weight: 800;
}

.state-text {
  max-width: 280px;
  color: #64748b;
  font-size: 14px;
  line-height: 20px;
}

.state-action {
  margin-top: 4px;
  height: 38px;
  padding: 0 16px;
  border: 0;
  border-radius: 19px;
  background: #2f80ed;
  color: #fff;
  font-weight: 700;
  cursor: pointer;
}

.spinner {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 3px solid rgba(47, 128, 237, 0.18);
  border-top-color: #2f80ed;
  animation: spin 720ms linear infinite;
}

.bottom-space {
  height: 10px;
}

.image-viewer-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.92);
}

.image-viewer-overlay.is-open {
  display: flex;
}

.image-viewer-image {
  display: block;
  max-width: 100vw;
  max-height: 100vh;
  width: auto;
  height: auto;
  object-fit: contain;
}

.image-viewer-back {
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + 12px);
  left: 12px;
  width: 44px;
  height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.35);
  color: #fff;
  cursor: pointer;
  z-index: 10000;
}

.image-viewer-back svg {
  fill: none;
  stroke: currentColor;
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

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

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

@media (min-width: 700px) {
  body {
    background: #cbd5e1;
  }

  .app-shell {
    min-height: 100vh;
    box-shadow: 0 0 0 1px rgba(15, 23, 42, 0.08), 0 24px 80px rgba(15, 23, 42, 0.18);
  }
}
