:root {
  color-scheme: light;
  --keyboard-offset: 0px;
  --bg: #ffffff;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --text: #111827;
  --muted: #6b7280;
  --line: #e5e7eb;
  --line-strong: #d8dde5;
  --primary: #2f86ff;
  --primary-strong: #1769ff;
  --green: #46b7a5;
  --shadow: 0 14px 36px rgba(15, 23, 42, 0.08);
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  font-family: "Segoe UI", "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
}

* {
  box-sizing: border-box;
}

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

body {
  min-height: 100dvh;
}

button,
textarea {
  font: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
  border: 0;
  background: none;
  cursor: pointer;
}

.chat-app {
  position: relative;
  display: flex;
  width: min(100%, 430px);
  min-height: 100dvh;
  margin: 0 auto;
  flex-direction: column;
  overflow: hidden;
  background: var(--surface);
}

.app-header {
  display: grid;
  grid-template-columns: 56px 1fr 56px;
  align-items: center;
  min-height: calc(76px + env(safe-area-inset-top));
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(16px);
  z-index: 3;
}

.app-header h1 {
  margin: 0;
  text-align: center;
  font-size: 21px;
  font-weight: 850;
  letter-spacing: 0;
}

.header-icon {
  position: relative;
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  color: var(--text);
  transition: transform 160ms var(--ease), opacity 160ms ease;
}

.header-icon:active {
  transform: scale(0.94);
}

.menu-button span {
  display: block;
  width: 25px;
  height: 2px;
  margin: 3px 0;
  border-radius: 999px;
  background: var(--text);
}

.new-chat-button span {
  position: relative;
  width: 28px;
  height: 25px;
  border: 2px solid var(--text);
  border-radius: 5px;
}

.new-chat-button span::before,
.new-chat-button span::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 13px;
  height: 2px;
  border-radius: 999px;
  background: var(--text);
  transform: translate(-50%, -50%);
}

.new-chat-button span::after {
  transform: translate(-50%, -50%) rotate(90deg);
}

.new-chat-button span {
  box-shadow: 0 7px 0 -5px var(--surface), 0 9px 0 -5px var(--text);
}

.task-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 32px;
  gap: 10px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.9);
  color: #2f343b;
  z-index: 2;
}

.task-bar p {
  margin: 0;
  font-size: 15px;
  font-weight: 650;
}

.task-bar span {
  color: var(--primary-strong);
  font-size: 12px;
  font-weight: 800;
}

.messages {
  flex: 1;
  min-height: 0;
  padding: 22px 18px calc(112px + var(--keyboard-offset));
  overflow-y: auto;
  scroll-behavior: smooth;
}

.message {
  display: flex;
  gap: 12px;
  margin-bottom: 20px;
  animation: messageIn 220ms var(--ease) both;
}

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

.message-stack {
  display: flex;
  max-width: min(82%, 326px);
  flex-direction: column;
  align-items: flex-start;
}

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

.bot-logo {
  position: relative;
  display: grid;
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: #fbfdff;
  box-shadow: 0 8px 18px rgba(15, 23, 42, 0.05);
}

.bot-face {
  position: relative;
  display: block;
  width: 25px;
  height: 20px;
  border: 3px solid var(--green);
  border-radius: 6px;
  background: #f8fffd;
}

.bot-face::before,
.bot-face::after {
  content: "";
  position: absolute;
  top: 7px;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: #111827;
}

.bot-face::before {
  left: 5px;
}

.bot-face::after {
  right: 5px;
}

.bot-face i {
  position: absolute;
  left: 50%;
  top: -12px;
  width: 3px;
  height: 9px;
  border-radius: 999px;
  background: var(--green);
  transform: translateX(-50%);
}

.bot-face i::before {
  content: "";
  position: absolute;
  left: 50%;
  top: -5px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--green);
  transform: translateX(-50%);
}

.bubble {
  position: relative;
  overflow: hidden;
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: 0 8px 18px rgba(15, 23, 42, 0.04);
}

.message.user .bubble {
  width: auto;
  max-width: 100%;
  border: 0;
  border-radius: 16px 16px 2px 16px;
  background: linear-gradient(145deg, #2d8cff, #2478f2);
  color: #fff;
  box-shadow: 0 12px 26px rgba(36, 120, 242, 0.22);
}

.bubble p {
  margin: 0;
  padding: 15px 17px 0;
  font-size: 16px;
  font-weight: 600;
  line-height: 1.68;
  letter-spacing: 0;
  word-break: keep-all;
  overflow-wrap: anywhere;
}

.bubble p:last-of-type {
  padding-bottom: 18px;
}

.message.user .bubble p {
  padding: 14px 17px;
  font-size: 16px;
  font-weight: 650;
  line-height: 1.55;
}

.bubble-actions {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  min-height: 48px;
  border-top: 1px solid var(--line);
}

.bubble-actions button {
  position: relative;
  display: grid;
  place-items: center;
  color: #1f2937;
  transition: background-color 160ms ease, transform 160ms var(--ease);
}

.bubble-actions button:active {
  transform: scale(0.92);
}

.bubble-actions button::before {
  content: "";
  display: block;
  width: 21px;
  height: 21px;
  background: currentColor;
  opacity: 0.88;
}

.bubble-actions [data-action="copy"]::before {
  background: none;
  border: 2px solid currentColor;
  border-radius: 4px;
  box-shadow: -5px 5px 0 -2px #fff, -5px 5px 0 0 currentColor;
}

.bubble-actions [data-action="refresh"]::before {
  width: 22px;
  height: 22px;
  border: 2px solid currentColor;
  border-left-color: transparent;
  border-radius: 50%;
  background: none;
}

.bubble-actions [data-action="share"]::before {
  clip-path: polygon(45% 0, 70% 25%, 56% 25%, 56% 67%, 34% 67%, 34% 25%, 20% 25%);
}

.bubble-actions [data-action="like"]::before {
  clip-path: polygon(34% 95%, 20% 88%, 18% 42%, 34% 42%, 46% 8%, 58% 8%, 62% 42%, 84% 42%, 84% 61%, 74% 95%);
}

.bubble-actions button.is-done {
  color: var(--primary-strong);
}

time {
  display: block;
  margin-top: 7px;
  color: var(--muted);
  font-size: 13px;
}

.check {
  color: var(--primary);
  font-weight: 900;
}

.quick-actions {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(82px + env(safe-area-inset-bottom));
  display: flex;
  gap: 12px;
  padding: 0 14px 10px;
  overflow-x: auto;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0), #fff 28%);
  scrollbar-width: none;
}

.quick-actions::-webkit-scrollbar {
  display: none;
}

.quick-actions button {
  flex: 0 0 auto;
  min-height: 38px;
  padding: 0 14px;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  background: #fff;
  color: #3f4650;
  font-size: 14px;
  font-weight: 650;
  box-shadow: 0 5px 14px rgba(15, 23, 42, 0.03);
}

.quick-actions button:last-child {
  width: 38px;
  padding: 0;
  border: 0;
  box-shadow: none;
  font-size: 30px;
}

.composer {
  position: absolute;
  left: 11px;
  right: 11px;
  bottom: calc(24px + env(safe-area-inset-bottom) + var(--keyboard-offset));
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 66px;
  padding: 9px;
  border: 1px solid var(--line-strong);
  border-radius: 17px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 10px 28px rgba(15, 23, 42, 0.07);
  backdrop-filter: blur(18px);
  transition: bottom 180ms var(--ease);
}

.composer-main {
  display: flex;
  flex: 1 1 auto;
  min-width: 0;
  flex-direction: column;
  gap: 8px;
}

.attach-button,
.mic-button,
.send-button {
  position: relative;
  display: grid;
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  place-items: center;
  border-radius: 50%;
  transition: transform 160ms var(--ease), opacity 160ms ease;
}

.attach-button,
.mic-button {
  border: 1px solid var(--line-strong);
  background: #fff;
  color: #1f2937;
}

.attach-button span {
  width: 22px;
  height: 22px;
  border: 3px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  transform: rotate(-42deg);
}

.mic-button span {
  width: 14px;
  height: 22px;
  border: 3px solid currentColor;
  border-radius: 999px;
}

.mic-button span::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 28px;
  width: 18px;
  height: 10px;
  border-bottom: 3px solid currentColor;
  border-radius: 0 0 999px 999px;
  transform: translateX(-50%);
}

.send-button {
  border-radius: 13px;
  background: linear-gradient(145deg, #2d8cff, #2478f2);
  color: #fff;
  box-shadow: 0 12px 22px rgba(36, 120, 242, 0.26);
  opacity: 0.78;
}

.send-button span {
  width: 24px;
  height: 24px;
  background: currentColor;
  clip-path: polygon(0 8%, 100% 50%, 0 92%, 24% 56%, 58% 50%, 24% 44%);
}

.composer.has-text .send-button {
  opacity: 1;
}

.attach-button:active,
.mic-button:active,
.send-button:active {
  transform: scale(0.94);
}

textarea {
  width: 100%;
  max-height: 100px;
  min-height: 44px;
  padding: 11px 14px;
  resize: none;
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  outline: none;
  background: #fff;
  color: var(--text);
  font-size: 16px;
  line-height: 1.35;
}

textarea::placeholder {
  color: #8a929d;
}

.image-preview {
  position: relative;
  width: 74px;
  height: 74px;
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
}

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

.image-preview button {
  position: absolute;
  top: 4px;
  right: 4px;
  display: grid;
  width: 22px;
  height: 22px;
  place-items: center;
  border-radius: 50%;
  background: rgba(15, 23, 42, 0.78);
  color: #fff;
}

.message-image {
  display: block;
  max-width: 210px;
  max-height: 180px;
  margin: 0 18px 12px;
  border-radius: 12px;
  object-fit: cover;
}

.typing .bubble {
  width: 72px;
  min-height: 46px;
}

.typing .bubble p,
.typing .bubble-actions {
  display: none;
}

.typing-dots {
  display: flex;
  justify-content: center;
  gap: 5px;
  padding: 18px;
}

.typing-dots i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--primary);
  animation: typingDot 900ms ease-in-out infinite;
}

.typing-dots i:nth-child(2) {
  animation-delay: 120ms;
}

.typing-dots i:nth-child(3) {
  animation-delay: 240ms;
}

.home-indicator {
  position: absolute;
  left: 50%;
  bottom: 6px;
  width: 144px;
  height: 5px;
  border-radius: 999px;
  background: #050505;
  transform: translateX(-50%);
}

body.keyboard-open .home-indicator {
  display: none;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@keyframes messageIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes typingDot {
  0%,
  80%,
  100% {
    opacity: 0.28;
    transform: translateY(0);
  }
  38% {
    opacity: 1;
    transform: translateY(-4px);
  }
}

@media (min-width: 720px) {
  body {
    background: #f4f6f9;
  }

  .chat-app {
    min-height: 844px;
    max-height: 920px;
    box-shadow: 0 24px 70px rgba(15, 23, 42, 0.12);
  }
}

@media (max-width: 374px) {
  .app-header {
    grid-template-columns: 48px 1fr 48px;
    padding-left: 10px;
    padding-right: 10px;
  }

  .messages {
    padding-left: 14px;
    padding-right: 14px;
  }

  .message-stack {
    max-width: min(82%, 300px);
  }
}

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