* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

:root {
  --app-bg: #0e2433;
  --header: #17212b;
  --header-border: rgba(255, 255, 255, 0.06);
  --bubble: #182533;
  --bubble-light: #243447;
  --my-bubble: #2b5278;
  --text: #ffffff;
  --muted: #8ea1b3;
  --accent: #2aabee;
  --green: #4ee3c1;
  --pink: #ff5ac8;
  --purple: #b982ff;
  --danger: #ff6673;
  --input: #17212b;
  --input-inner: #242f3d;
}

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

body {
  overflow-x: hidden;
}

.phone {
  min-height: 100vh;
  max-width: 820px;
  margin: 0 auto;
  position: relative;
  padding-bottom: calc(92px + env(safe-area-inset-bottom));
  background:
    radial-gradient(circle at 15% 15%, rgba(42, 171, 238, 0.11), transparent 22%),
    radial-gradient(circle at 75% 25%, rgba(78, 227, 193, 0.07), transparent 26%),
    linear-gradient(180deg, #102b3b 0%, #071d2b 100%);
}

/* Telegram-like pattern */
.phone::before {
  content: "";
  position: fixed;
  inset: 64px 0 0 0;
  z-index: 0;
  pointer-events: none;
  opacity: 0.12;
  background-image:
    radial-gradient(circle at 10px 10px, rgba(255,255,255,.9) 1px, transparent 1.5px),
    radial-gradient(circle at 34px 28px, rgba(255,255,255,.8) 1px, transparent 1.5px),
    linear-gradient(45deg, transparent 46%, rgba(255,255,255,.45) 47%, rgba(255,255,255,.45) 52%, transparent 53%);
  background-size: 58px 58px, 72px 72px, 110px 110px;
}

.topbar {
  height: 64px;
  background: rgba(23, 33, 43, 0.96);
  backdrop-filter: blur(14px);
  display: grid;
  grid-template-columns: 58px 1fr 58px;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 50;
  border-bottom: 1px solid var(--header-border);
}

.title {
  text-align: center;
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.03em;
}

.icon-btn {
  width: 58px;
  height: 58px;
  background: transparent;
  border: 0;
  color: #e7eef5;
  font-size: 34px;
  line-height: 1;
  cursor: pointer;
  opacity: 0.95;
}

.icon-btn:last-child {
  font-size: 28px;
}

.chat {
  position: relative;
  z-index: 1;
  min-height: calc(100vh - 150px);
  padding: 20px 10px 18px;
}

.start-label {
  width: max-content;
  max-width: 90%;
  margin: 8px auto 20px;
  padding: 6px 12px;
  border-radius: 13px;
  background: rgba(74, 91, 106, 0.74);
  color: rgba(255, 255, 255, 0.88);
  font-size: 14px;
  font-weight: 500;
  box-shadow: 0 4px 18px rgba(0,0,0,.12);
}

.messages {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.message {
  display: flex;
  gap: 7px;
  align-items: flex-end;
  max-width: 100%;
  cursor: pointer;
  padding-right: 6px;
}

.avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  flex: 0 0 36px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #314254, #202b37);
  color: var(--green);
  font-size: 17px;
  font-weight: 900;
  border: 1px solid rgba(255, 255, 255, 0.08);
  margin-bottom: 1px;
}

.bubble {
  position: relative;
  width: fit-content;
  min-width: 92px;
  max-width: min(620px, calc(100vw - 66px));
  background: var(--bubble-light);
  border-radius: 16px 16px 16px 5px;
  padding: 7px 9px 6px;
  box-shadow: 0 1px 2px rgba(0,0,0,.15);
}

/* маленький хвостик как у Telegram */
.bubble::before {
  content: "";
  position: absolute;
  left: -5px;
  bottom: 0;
  width: 12px;
  height: 12px;
  background: var(--bubble-light);
  clip-path: polygon(100% 0, 100% 100%, 0 100%);
  border-bottom-left-radius: 4px;
}

.author {
  margin: 0 0 3px;
  color: var(--green);
  font-size: 14px;
  line-height: 1.15;
  font-weight: 800;
}

.message:nth-child(3n) .author {
  color: var(--pink);
}

.message:nth-child(3n + 1) .author {
  color: var(--purple);
}

.text {
  color: var(--text);
  font-size: 16px;
  line-height: 1.32;
  white-space: pre-wrap;
  word-break: break-word;
  padding-right: 42px;
}

.photo {
  display: block;
  width: 100%;
  max-width: 430px;
  max-height: 520px;
  object-fit: cover;
  border-radius: 12px;
  margin-top: 5px;
  background: #0b1520;
}

.media-link {
  display: inline-block;
  margin-top: 6px;
  color: #7dd3fc;
  font-weight: 700;
  text-decoration: none;
}

.meta {
  min-height: 18px;
  margin-top: 2px;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 6px;
  color: rgba(210, 220, 230, 0.62);
  font-size: 12px;
  line-height: 1;
}

.reaction-badge {
  border: 0;
  border-radius: 999px;
  padding: 3px 9px;
  background: rgba(118, 130, 145, 0.68);
  color: white;
  font-size: 15px;
  font-weight: 800;
  cursor: pointer;
  margin-right: auto;
}

.composer {
  position: fixed;
  left: 50%;
  bottom: calc(10px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: min(800px, calc(100% - 16px));
  min-height: 58px;
  z-index: 60;
  display: grid;
  grid-template-columns: 44px 1fr 48px;
  align-items: end;
  gap: 7px;
  padding: 6px;
  background: var(--input);
  border-radius: 30px;
  box-shadow: 0 10px 32px rgba(0,0,0,.28);
}

.attach,
.send-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  border: 0;
  color: #dbe6ef;
  cursor: pointer;
}

.attach {
  background: var(--input-inner);
  font-size: 30px;
  font-weight: 500;
  line-height: 1;
}

.send-btn {
  background: var(--accent);
  font-size: 24px;
  color: white;
  transform: rotate(-35deg);
  padding-left: 3px;
  box-shadow: 0 4px 14px rgba(42, 171, 238, 0.24);
}

.send-btn:disabled {
  opacity: 0.55;
  cursor: wait;
}

.composer textarea {
  width: 100%;
  max-height: 118px;
  resize: none;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font-size: 18px;
  line-height: 1.35;
  padding: 10px 0 8px;
  font-family: inherit;
}

.composer textarea::placeholder {
  color: rgba(214, 224, 235, 0.52);
}

.preview {
  position: fixed;
  left: 50%;
  bottom: calc(76px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: min(800px, calc(100% - 16px));
  z-index: 62;
}

.preview-card {
  min-height: 66px;
  background: rgba(23, 33, 43, 0.98);
  border: 1px solid rgba(255,255,255,.06);
  border-radius: 18px;
  padding: 7px 9px;
  display: flex;
  align-items: center;
  gap: 9px;
  box-shadow: 0 10px 32px rgba(0,0,0,.28);
}

.preview-img {
  width: 52px;
  height: 52px;
  border-radius: 13px;
  object-fit: cover;
  flex: 0 0 52px;
}

.preview-info {
  min-width: 0;
  flex: 1;
  display: grid;
  gap: 2px;
}

.preview-info strong {
  font-size: 14px;
}

.preview-info span {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.preview-card button {
  border: 0;
  background: var(--input-inner);
  color: white;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  font-size: 22px;
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(0, 8, 16, 0.55);
  backdrop-filter: blur(7px);
}

.reaction-panel {
  position: fixed;
  left: 50%;
  bottom: calc(310px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: min(610px, calc(100% - 24px));
  z-index: 90;
  background: rgba(24, 34, 47, 0.98);
  border-radius: 28px;
  padding: 12px;
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  gap: 4px;
  box-shadow: 0 18px 70px rgba(0,0,0,.42);
}

.reaction-panel button {
  border: 0;
  background: transparent;
  font-size: 27px;
  cursor: pointer;
  padding: 7px 0;
  border-radius: 14px;
}

.reaction-panel button:hover {
  background: rgba(255,255,255,.07);
}

.action-sheet {
  position: fixed;
  left: 50%;
  bottom: calc(18px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: min(610px, calc(100% - 24px));
  z-index: 91;
  background: rgba(24, 34, 47, 0.99);
  border-radius: 24px;
  overflow: hidden;
  box-shadow: 0 18px 70px rgba(0,0,0,.42);
}

.action-sheet button {
  display: block;
  width: 100%;
  border: 0;
  border-bottom: 1px solid rgba(255,255,255,.065);
  background: transparent;
  color: var(--text);
  text-align: left;
  padding: 18px 24px;
  font-size: 20px;
  cursor: pointer;
  font-family: inherit;
}

.action-sheet button:last-child {
  border-bottom: 0;
}

.action-sheet .danger {
  color: var(--danger);
}

.hidden {
  display: none !important;
}

@media (min-width: 821px) {
  body {
    background: #0b1823;
  }

  .phone {
    min-height: 100vh;
    border-left: 1px solid rgba(255,255,255,.04);
    border-right: 1px solid rgba(255,255,255,.04);
  }
}

@media (max-width: 640px) {
  .phone {
    max-width: none;
    padding-bottom: calc(86px + env(safe-area-inset-bottom));
  }

  .topbar {
    height: 58px;
    grid-template-columns: 54px 1fr 54px;
  }

  .title {
    font-size: 22px;
  }

  .icon-btn {
    width: 54px;
    height: 54px;
    font-size: 34px;
  }

  .icon-btn:last-child {
    font-size: 27px;
  }

  .phone::before {
    inset-top: 58px;
  }

  .chat {
    padding: 16px 8px 14px;
  }

  .messages {
    gap: 7px;
  }

  .avatar {
    width: 34px;
    height: 34px;
    flex-basis: 34px;
    font-size: 16px;
  }

  .bubble {
    max-width: calc(100vw - 58px);
    border-radius: 15px 15px 15px 5px;
    padding: 7px 9px 6px;
  }

  .author {
    font-size: 14px;
  }

  .text {
    font-size: 16px;
    padding-right: 38px;
  }

  .photo {
    max-width: calc(100vw - 78px);
    max-height: 460px;
  }

  .composer {
    width: calc(100% - 14px);
    min-height: 56px;
    grid-template-columns: 42px 1fr 46px;
    bottom: calc(8px + env(safe-area-inset-bottom));
  }

  .attach,
  .send-btn {
    width: 42px;
    height: 42px;
  }

  .composer textarea {
    font-size: 17px;
  }

  .preview {
    width: calc(100% - 14px);
    bottom: calc(72px + env(safe-area-inset-bottom));
  }

  .reaction-panel {
    width: calc(100% - 24px);
    bottom: calc(292px + env(safe-area-inset-bottom));
    grid-template-columns: repeat(6, 1fr);
    border-radius: 24px;
  }

  .reaction-panel button {
    font-size: 28px;
  }

  .action-sheet {
    width: calc(100% - 24px);
    bottom: calc(18px + env(safe-area-inset-bottom));
    border-radius: 24px;
  }

  .action-sheet button {
    padding: 18px 24px;
    font-size: 20px;
  }
}

/* --- composer tuning --- */
.composer {
  min-height: 56px;
  grid-template-columns: 44px 1fr 48px;
  gap: 8px;
  padding: 6px 7px 6px 6px;
  align-items: center;
}

.attach,
.send-btn {
  display: flex;
  align-items: center;
  justify-content: center;
}

.attach {
  background: #2a3442;
}

.send-btn {
  background: #2aabee;
  transform: none;
  padding-left: 0;
}

.attach svg,
.send-btn svg {
  width: 20px;
  height: 20px;
  display: block;
}

.attach svg {
  color: #d8e3ee;
}

.send-btn svg {
  color: #ffffff;
  width: 19px;
  height: 19px;
  margin-left: 1px;
}

.composer textarea {
  padding: 9px 0 7px;
  font-size: 17px;
  line-height: 1.25;
}

.composer textarea::placeholder {
  color: rgba(220, 230, 240, 0.48);
}

@media (max-width: 640px) {
  .composer {
    min-height: 54px;
    grid-template-columns: 42px 1fr 46px;
    gap: 7px;
    padding: 6px;
  }

  .attach,
  .send-btn {
    width: 42px;
    height: 42px;
  }

  .attach svg,
  .send-btn svg {
    width: 19px;
    height: 19px;
  }

  .composer textarea {
    font-size: 16px;
    padding: 9px 0 8px;
  }
}

/* ===== minimalist composer override ===== */
.composer {
  left: 10px !important;
  right: 10px !important;
  width: auto !important;
  transform: none !important;
  min-height: 52px !important;
  grid-template-columns: 26px 1fr 26px !important;
  gap: 10px !important;
  padding: 8px 12px !important;
  border-radius: 18px !important;
  background: rgba(23, 33, 43, 0.96) !important;
  box-shadow: 0 4px 18px rgba(0,0,0,0.22) !important;
  align-items: center !important;
}

.attach,
.send-btn {
  width: 26px !important;
  height: 26px !important;
  min-width: 26px !important;
  min-height: 26px !important;
  padding: 0 !important;
  margin: 0 !important;
  border: 0 !important;
  border-radius: 0 !important;
  background: transparent !important;
  box-shadow: none !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  transform: none !important;
}

.attach svg,
.send-btn svg {
  display: block !important;
  width: 21px !important;
  height: 21px !important;
}

.attach svg {
  color: rgba(220, 230, 240, 0.68) !important;
}

.send-btn svg {
  color: #2aabee !important;
  transform: none !important;
}

.composer textarea {
  padding: 0 !important;
  margin: 0 !important;
  min-height: 24px !important;
  max-height: 100px !important;
  font-size: 16px !important;
  line-height: 1.25 !important;
}

.composer textarea::placeholder {
  color: rgba(220, 230, 240, 0.42) !important;
}

.send-btn:disabled {
  opacity: 0.45 !important;
}

.preview {
  left: 10px !important;
  right: 10px !important;
  width: auto !important;
  transform: none !important;
  bottom: calc(64px + env(safe-area-inset-bottom)) !important;
}

@media (min-width: 700px) {
  .composer {
    left: 50% !important;
    right: auto !important;
    width: min(720px, calc(100% - 30px)) !important;
    transform: translateX(-50%) !important;
  }

  .preview {
    left: 50% !important;
    right: auto !important;
    width: min(720px, calc(100% - 30px)) !important;
    transform: translateX(-50%) !important;
  }
}

/* ===== figma icons tuning ===== */
.attach svg {
  width: 20px !important;
  height: 23px !important;
}

.send-btn svg {
  width: 25px !important;
  height: 21px !important;
  color: #2aabee !important;
  transform: none !important;
  margin: 0 !important;
}

.attach,
.send-btn {
  background: transparent !important;
  border-radius: 0 !important;
  box-shadow: none !important;
}

.attach {
  color: rgba(220, 230, 240, 0.7) !important;
}

.send-btn {
  color: #2aabee !important;
}

/* enlarge send icon */
.composer {
  grid-template-columns: 28px 1fr 38px !important;
}

.send-btn {
  width: 38px !important;
  height: 38px !important;
}

.send-btn svg {
  width: 35px !important;
  height: 30px !important;
  color: #2aabee !important;
}

.attach {
  width: 28px !important;
  height: 28px !important;
}

.attach svg {
  width: 20px !important;
  height: 23px !important;
}

@media (max-width: 640px) {
  .composer {
    grid-template-columns: 28px 1fr 38px !important;
  }

  .send-btn {
    width: 38px !important;
    height: 38px !important;
  }

  .send-btn svg {
    width: 35px !important;
    height: 30px !important;
  }
}

/* ===== fix reaction menu layout ===== */

.overlay {
  backdrop-filter: blur(6px);
}

.reaction-panel {
  left: 50% !important;
  right: auto !important;
  bottom: calc(330px + env(safe-area-inset-bottom)) !important;
  transform: translateX(-50%) !important;
  width: min(560px, calc(100% - 28px)) !important;
  min-height: 58px !important;
  padding: 8px 12px !important;
  display: flex !important;
  align-items: center !important;
  justify-content: space-between !important;
  gap: 6px !important;
  overflow: visible !important;
  background: #18222f !important;
  border-radius: 22px !important;
  box-shadow: 0 16px 50px rgba(0,0,0,0.42) !important;
}

.reaction-panel button {
  width: 42px !important;
  height: 42px !important;
  min-width: 42px !important;
  min-height: 42px !important;
  padding: 0 !important;
  margin: 0 !important;
  border: 0 !important;
  border-radius: 14px !important;
  background: transparent !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  font-size: 26px !important;
  line-height: 1 !important;
  overflow: visible !important;
}

.reaction-panel button:hover {
  background: rgba(255,255,255,0.07) !important;
}

.action-sheet {
  left: 50% !important;
  right: auto !important;
  bottom: calc(28px + env(safe-area-inset-bottom)) !important;
  transform: translateX(-50%) !important;
  width: min(560px, calc(100% - 28px)) !important;
  border-radius: 22px !important;
  overflow: hidden !important;
  background: #18222f !important;
}

.action-sheet button {
  height: 58px !important;
  padding: 0 22px !important;
  display: flex !important;
  align-items: center !important;
  font-size: 18px !important;
  line-height: 1 !important;
}

/* mobile reaction menu */
@media (max-width: 640px) {
  .reaction-panel {
    bottom: calc(318px + env(safe-area-inset-bottom)) !important;
    width: calc(100% - 24px) !important;
    min-height: 58px !important;
    padding: 8px 10px !important;
    gap: 4px !important;
    overflow-x: auto !important;
    overflow-y: visible !important;
    justify-content: flex-start !important;
    scrollbar-width: none !important;
  }

  .reaction-panel::-webkit-scrollbar {
    display: none !important;
  }

  .reaction-panel button {
    width: 42px !important;
    height: 42px !important;
    min-width: 42px !important;
    font-size: 26px !important;
  }

  .action-sheet {
    width: calc(100% - 24px) !important;
    bottom: calc(20px + env(safe-area-inset-bottom)) !important;
  }

  .action-sheet button {
    height: 58px !important;
    font-size: 19px !important;
  }
}
