:root {
  color-scheme: light;
  --canvas: #eef3f5;
  --surface: #ffffff;
  --chat-bg: #f5f7fa;
  --line: #e1e7eb;
  --text: #17212b;
  --muted: #8d98a4;
  --green: #12b76a;
  --green-dark: #08874c;
  --green-soft: #dff7e9;
  --orange: #ff4f2e;
  --shadow: 0 18px 55px rgba(43, 61, 72, 0.15);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-width: 320px;
  min-height: 100%;
  margin: 0;
  background: var(--canvas);
  color: var(--text);
}

body {
  min-height: 100dvh;
  overflow: hidden;
}

button,
input,
textarea {
  font: inherit;
}

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

[hidden] {
  display: none !important;
}

.page-stage {
  display: grid;
  min-height: 100dvh;
  place-items: center;
  padding: 0;
}

.chat-app {
  position: relative;
  display: flex;
  width: min(100%, 430px);
  height: 100dvh;
  max-height: 920px;
  flex-direction: column;
  overflow: hidden;
  background: var(--chat-bg);
  box-shadow: var(--shadow);
}

.chat-header {
  z-index: 12;
  display: grid;
  min-height: 82px;
  flex: 0 0 auto;
  grid-template-columns: 48px minmax(0, 1fr) 48px;
  align-items: center;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  padding: env(safe-area-inset-top, 0) 10px 0;
}

.icon-button {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: #202a34;
  cursor: pointer;
}

.icon-button:active {
  background: #f1f4f6;
}

.icon-button:focus-visible,
.image-picker:focus-within,
.send-button:focus-visible,
.message-image-button:focus-visible,
.reconnect-toggle:focus-visible,
.reconnect-image-button:focus-visible {
  outline: 3px solid rgba(18, 183, 106, 0.22);
  outline-offset: 2px;
}

.icon-button svg {
  width: 26px;
  height: 26px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.icon-button circle {
  fill: currentColor;
  stroke: none;
}

.header-profile {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 9px;
}

.header-avatar,
.service-avatar {
  display: block;
  flex: 0 0 auto;
  border: 1px solid #f4cadb;
  border-radius: 50%;
  background: #f9e2ec;
  object-fit: cover;
}

.header-avatar {
  width: 36px;
  height: 36px;
}

.header-copy {
  min-width: 0;
}

.header-copy h1 {
  margin: 0;
  overflow: hidden;
  color: #151b22;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.35;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.header-copy p {
  display: flex;
  margin: 2px 0 0;
  align-items: center;
  gap: 5px;
  color: #7b8793;
  font-size: 11px;
}

.online-dot {
  width: 8px;
  height: 8px;
  border: 2px solid #c9f2dc;
  border-radius: 50%;
  background: var(--green);
}

.menu-wrap {
  position: relative;
  justify-self: end;
}

.header-menu {
  position: absolute;
  top: 46px;
  right: 0;
  width: 210px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #ffffff;
  box-shadow: 0 16px 34px rgba(35, 48, 58, 0.16);
}

.header-menu p {
  margin: 0;
  padding: 13px 14px;
  color: #6f7b87;
  font-size: 12px;
}

.header-menu button {
  width: 100%;
  padding: 12px 14px;
  border: 0;
  border-top: 1px solid var(--line);
  background: #fff;
  color: #d4453f;
  cursor: pointer;
  text-align: left;
}

.verified-strip {
  z-index: 8;
  display: flex;
  min-height: 44px;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-bottom: 1px solid #ffe1d5;
  background: #fff8f5;
  color: var(--orange);
}

.verified-strip svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.verified-strip .enterprise-logo {
  flex: 0 0 auto;
  filter: drop-shadow(0 2px 4px rgb(255 101 72 / 18%));
}

.enterprise-logo-bg {
  fill: currentColor;
  stroke: none;
}

.enterprise-logo-building {
  stroke: #fff;
  stroke-width: 1.6;
}

.enterprise-logo-seal {
  fill: #fff;
  stroke: currentColor;
  stroke-width: 1.2;
}

.enterprise-logo-check {
  stroke: currentColor;
  stroke-width: 1.7;
}

.verified-strip span {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.08em;
  animation: verified-blink 1.15s ease-in-out infinite;
}

@keyframes verified-blink {
  0%,
  100% {
    opacity: 1;
    text-shadow: 0 0 0 rgba(255, 79, 46, 0);
  }
  50% {
    opacity: 0.34;
    text-shadow: 0 0 10px rgba(255, 79, 46, 0.42);
  }
}

.message-list {
  flex: 1 1 auto;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  padding: 14px 14px 26px;
  overscroll-behavior: contain;
  scrollbar-width: none;
}

.message-list::-webkit-scrollbar {
  display: none;
}

.day-label {
  margin: 2px auto 18px;
  color: #99a2ad;
  font-size: 12px;
  line-height: 1;
  text-align: center;
}

.message-row,
.typing-row {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  margin-bottom: 16px;
}

.message-row.user {
  justify-content: flex-end;
}

.service-avatar {
  width: 36px;
  height: 36px;
  margin-top: 19px;
}

.message-content {
  display: flex;
  max-width: min(78%, 286px);
  min-width: 0;
  flex-direction: column;
}

.message-row.user .message-content {
  align-items: flex-end;
}

.message-time {
  align-self: center;
  margin-bottom: 6px;
  color: #a1a9b2;
  font-size: 11px;
  line-height: 1;
}

.message-bubble {
  position: relative;
  overflow: hidden;
  border: 1px solid #e3e8ec;
  border-radius: 5px 16px 16px;
  background: #ffffff;
  box-shadow: 0 1px 2px rgba(23, 32, 42, 0.04);
}

.message-row.user .message-bubble {
  border-color: #ccefdc;
  border-radius: 16px 5px 16px 16px;
  background: var(--green-soft);
}

.message-bubble p {
  margin: 0;
  padding: 11px 13px;
  font-size: 15px;
  line-height: 1.62;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.message-bubble.has-images p {
  padding-bottom: 8px;
}

.message-images {
  display: grid;
  gap: 3px;
  padding: 3px;
}

.message-images.multi {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.message-image-button {
  display: block;
  width: 100%;
  min-width: 0;
  padding: 0;
  overflow: hidden;
  border: 0;
  border-radius: 11px;
  background: #dde3e8;
  cursor: pointer;
}

.message-image-button img {
  display: block;
  width: 100%;
  max-height: 240px;
  aspect-ratio: 4 / 3;
  object-fit: cover;
}

.message-image-button.guide-image {
  display: flex;
  align-items: center;
  justify-content: center;
  background: #ffffff;
}

.message-image-button.guide-image img {
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 360px;
  aspect-ratio: auto;
  object-fit: contain;
}

.read-state {
  margin-top: 5px;
  color: #98a2ad;
  font-size: 11px;
}

.typing-row {
  align-items: flex-end;
}

.typing-row .service-avatar {
  margin-top: 0;
}

.typing-bubble {
  display: flex;
  min-width: 62px;
  height: 38px;
  align-items: center;
  justify-content: center;
  gap: 5px;
  border: 1px solid #e3e8ec;
  border-radius: 5px 15px 15px;
  background: #fff;
}

.typing-bubble i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #9fa8b1;
  animation: typing 1s ease-in-out infinite;
}

.typing-bubble i:nth-child(2) {
  animation-delay: 0.13s;
}

.typing-bubble i:nth-child(3) {
  animation-delay: 0.26s;
}

@keyframes typing {
  0%,
  65%,
  100% {
    transform: translateY(0);
    opacity: 0.45;
  }
  30% {
    transform: translateY(-3px);
    opacity: 1;
  }
}

.reconnect-menu {
  z-index: 11;
  flex: 0 0 auto;
  border-top: 1px solid var(--line);
  background: #ffffff;
}

.reconnect-toggle {
  display: grid;
  width: 100%;
  min-height: 48px;
  grid-template-columns: 34px minmax(0, 1fr) 18px;
  align-items: center;
  gap: 9px;
  border: 0;
  background: #ffffff;
  padding: 6px max(14px, env(safe-area-inset-right)) 6px max(14px, env(safe-area-inset-left));
  color: var(--text);
  cursor: pointer;
  text-align: left;
}

.reconnect-toggle:active,
.reconnect-toggle[aria-expanded="true"] {
  background: #fff9f6;
}

.reconnect-icon {
  display: grid;
  width: 30px;
  height: 30px;
  place-items: center;
  border-radius: 9px;
  background: #fff0ea;
  color: var(--orange);
}

.reconnect-icon svg {
  width: 19px;
  height: 19px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.7;
}

.reconnect-label {
  display: grid;
  min-width: 0;
  gap: 1px;
}

.reconnect-label strong {
  font-size: 13px;
  line-height: 1.35;
}

.reconnect-label small {
  overflow: hidden;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.35;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.reconnect-chevron {
  width: 8px;
  height: 8px;
  justify-self: center;
  border-right: 1.5px solid #82909c;
  border-bottom: 1.5px solid #82909c;
  transform: rotate(45deg) translate(-2px, -2px);
  transition: transform 180ms ease;
}

.reconnect-toggle[aria-expanded="true"] .reconnect-chevron {
  transform: rotate(225deg) translate(-1px, -1px);
}

.reconnect-panel {
  max-height: min(52dvh, 430px);
  overflow-y: auto;
  border-top: 1px solid #f1ddd5;
  background: #fffaf8;
  padding: 11px 14px 14px;
}

.reconnect-panel p {
  margin: 0 auto 10px;
  max-width: 340px;
  color: #3c4751;
  font-size: 13px;
  line-height: 1.6;
}

.reconnect-image-button {
  display: block;
  width: min(100%, 340px);
  margin: 0 auto;
  overflow: hidden;
  border: 1px solid #e3e8eb;
  border-radius: 12px;
  background: #ffffff;
  padding: 8px;
  cursor: zoom-in;
}

.reconnect-image-button img {
  display: block;
  width: 100%;
  height: min(34dvh, 300px);
  border-radius: 8px;
  object-fit: contain;
}

.composer {
  z-index: 10;
  flex: 0 0 auto;
  border-top: 1px solid var(--line);
  background: #ffffff;
  padding: 9px max(12px, env(safe-area-inset-right)) max(9px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
}

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

.image-picker {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border: 1px solid #dde4e8;
  border-radius: 50%;
  background: #ffffff;
  color: #2f3c48;
  cursor: pointer;
}

.image-picker:active {
  background: #f2f5f7;
}

.image-picker svg {
  width: 23px;
  height: 23px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.7;
}

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

.message-input {
  width: 100%;
  height: 44px;
  min-width: 0;
  padding: 0 13px;
  border: 1px solid #dce3e7;
  border-radius: 13px;
  outline: 0;
  background: #ffffff;
  color: #1b252e;
  font-size: 15px;
}

.message-input::placeholder {
  color: #b0b8c1;
}

.message-input:focus {
  border-color: #9bdfbd;
  box-shadow: 0 0 0 3px rgba(18, 183, 106, 0.09);
}

.send-button {
  height: 44px;
  padding: 0 13px;
  border: 0;
  border-radius: 12px;
  background: #8fdcba;
  color: #ffffff;
  cursor: pointer;
  font-size: 14px;
  font-weight: 700;
}

.send-button:not(:disabled) {
  background: var(--green);
}

.send-button:disabled {
  cursor: default;
  opacity: 0.72;
}

.attachment-preview {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 0 0 9px 50px;
}

.attachment-item {
  position: relative;
  width: 58px;
  height: 58px;
  flex: 0 0 58px;
}

.attachment-item img {
  width: 100%;
  height: 100%;
  border: 1px solid #e0e6ea;
  border-radius: 10px;
  object-fit: cover;
}

.attachment-item button {
  position: absolute;
  top: -6px;
  right: -6px;
  display: grid;
  width: 21px;
  height: 21px;
  place-items: center;
  border: 2px solid #fff;
  border-radius: 50%;
  background: #3e4852;
  color: #fff;
  cursor: pointer;
}

.attachment-item button::before,
.attachment-item button::after {
  position: absolute;
  width: 9px;
  height: 1px;
  background: currentColor;
  content: "";
}

.attachment-item button::before {
  transform: rotate(45deg);
}

.attachment-item button::after {
  transform: rotate(-45deg);
}

.toast,
.connection-banner {
  position: absolute;
  z-index: 30;
  left: 50%;
  max-width: calc(100% - 42px);
  transform: translateX(-50%);
  border-radius: 10px;
  color: #fff;
  text-align: center;
}

.toast {
  bottom: calc(82px + env(safe-area-inset-bottom));
  padding: 9px 13px;
  background: rgba(33, 42, 50, 0.9);
  font-size: 13px;
}

.connection-banner {
  top: calc(132px + env(safe-area-inset-top));
  padding: 7px 11px;
  background: rgba(216, 145, 18, 0.92);
  font-size: 12px;
}

.image-viewer {
  position: absolute;
  z-index: 50;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 54px 14px 24px;
  background: rgba(8, 12, 16, 0.93);
}

.image-viewer > button {
  position: absolute;
  top: calc(13px + env(safe-area-inset-top));
  right: 13px;
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  cursor: pointer;
}

.image-viewer svg {
  width: 26px;
  height: 26px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-width: 1.8;
}

.image-viewer > img {
  display: block;
  max-width: 100%;
  max-height: 100%;
  border-radius: 12px;
  object-fit: contain;
}

noscript {
  position: fixed;
  inset: auto 12px 12px;
  padding: 10px;
  border-radius: 8px;
  background: #fff3cd;
  color: #6e5200;
  text-align: center;
}

@media (min-width: 700px) {
  .page-stage {
    padding: 24px;
  }

  .chat-app {
    height: min(844px, calc(100dvh - 48px));
    border: 1px solid #dce3e7;
    border-radius: 24px;
  }
}

@media (max-width: 430px) {
  html,
  body {
    background: var(--chat-bg);
  }

  .chat-app {
    max-height: none;
    box-shadow: none;
  }
}

@media (max-width: 360px) {
  .header-copy h1 {
    font-size: 15px;
  }

  .message-content {
    max-width: 80%;
  }

  .composer {
    padding-right: 8px;
    padding-left: 8px;
  }

  .composer-row {
    gap: 6px;
    grid-template-columns: 40px minmax(0, 1fr) 58px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
