:root {
  color-scheme: light;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --announcement-bg: #1d2754;
  --announcement-text: #ffffff;
  --text-strong: #1f2937;
  --text: #4b5563;
  --text-muted: #6b7280;
  --border: #e5e7eb;
  --surface: #ffffff;
  --surface-muted: #f9fafb;
  --incoming: #e5e7eb;
  --danger: #dc2626;
  --chat-width: 500px;
  --chat-height: 640px;
  --sidebar-width: 240px;
  font-family:
    -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  min-width: 320px;
  min-height: 100%;
  margin: 0;
}

body {
  min-height: 100vh;
  color: var(--text-strong);
  background: #ffffff;
}

button,
textarea,
input {
  font: inherit;
}

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

button {
  border: 0;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
}

a {
  color: inherit;
  text-decoration: none;
}

img,
video,
svg {
  display: block;
}

#app {
  min-height: 100vh;
}

.app-stage {
  display: flex;
  min-height: 100vh;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: #ffffff;
}

.chat-shell {
  position: relative;
  display: flex;
  width: var(--chat-width);
  height: var(--chat-height);
  overflow: hidden;
  border-radius: 8px;
  background: var(--surface);
  box-shadow:
    0 10px 15px -3px rgb(0 0 0 / 0.1),
    0 4px 6px -4px rgb(0 0 0 / 0.1);
  transition: width 180ms ease-out;
}

.chat-shell.has-sidebar {
  width: calc(var(--chat-width) + var(--sidebar-width));
}

.chat-main {
  display: flex;
  width: var(--chat-width);
  min-width: 0;
  height: 100%;
  flex-direction: column;
  background: var(--surface);
}

.chat-header {
  display: flex;
  min-height: 50px;
  flex: 0 0 50px;
  align-items: center;
  justify-content: space-between;
  padding: 5px 16px;
  color: #ffffff;
  background: var(--primary);
}

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

.agent-avatar {
  display: grid;
  width: 40px;
  height: 40px;
  flex: 0 0 40px;
  place-items: center;
  overflow: hidden;
  border-radius: 50%;
  color: #ffffff;
  background:
    radial-gradient(circle at 34% 28%, rgb(255 255 255 / 0.32), transparent 36%),
    #60a5fa;
  font-size: 17px;
  font-weight: 600;
}

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

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

.agent-name {
  overflow: hidden;
  font-size: 18px;
  font-weight: 500;
  line-height: 1.35;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.agent-status {
  margin-top: 1px;
  color: rgb(255 255 255 / 0.78);
  font-size: 11px;
  line-height: 1.4;
}

.header-actions {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 6px;
  margin-left: 12px;
}

.icon-button {
  display: inline-grid;
  width: 32px;
  height: 32px;
  place-items: center;
  border-radius: 5px;
  color: var(--text-muted);
  background: transparent;
  transition:
    color 150ms ease,
    background-color 150ms ease;
}

.icon-button:hover {
  color: var(--text-strong);
  background: rgb(0 0 0 / 0.04);
}

.icon-button.on-primary {
  color: #ffffff;
}

.icon-button.on-primary:hover {
  color: #ffffff;
  background: rgb(255 255 255 / 0.14);
}

.icon-button svg {
  width: 20px;
  height: 20px;
}

.mobile-sidebar-button {
  display: none;
}

.announcement {
  position: relative;
  display: flex;
  height: 50px;
  flex: 0 0 50px;
  align-items: center;
  overflow: hidden;
  color: var(--announcement-text);
  background: var(--announcement-bg);
}

.announcement::before {
  position: absolute;
  z-index: 1;
  top: 0;
  bottom: 0;
  left: 0;
  width: 18px;
  background: linear-gradient(90deg, var(--announcement-bg), transparent);
  content: "";
}

.announcement::after {
  position: absolute;
  z-index: 1;
  top: 0;
  right: 0;
  bottom: 0;
  width: 18px;
  background: linear-gradient(270deg, var(--announcement-bg), transparent);
  content: "";
}

.announcement-track {
  display: inline-flex;
  min-width: max-content;
  padding-left: 100%;
  animation: announcement-scroll 24s linear infinite;
  font-size: 15px;
  line-height: 1.4;
  white-space: nowrap;
}

@keyframes announcement-scroll {
  to {
    transform: translateX(-100%);
  }
}

.message-area {
  position: relative;
  min-height: 0;
  flex: 1 1 auto;
  overflow-x: hidden;
  overflow-y: auto;
  padding: 16px;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: #d1d5db transparent;
}

.message-area::-webkit-scrollbar,
.sidebar-body::-webkit-scrollbar {
  width: 6px;
}

.message-area::-webkit-scrollbar-thumb,
.sidebar-body::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background: #d1d5db;
}

.history-action {
  margin: 0 0 16px;
  color: var(--text-muted);
  font-size: 13px;
  line-height: 1.5;
  text-align: center;
}

.history-action button {
  padding: 2px 4px;
  color: inherit;
  background: transparent;
}

.history-action button:hover {
  color: var(--text-strong);
}

.message-row {
  display: flex;
  width: 100%;
  margin-bottom: 16px;
  flex-direction: column;
  align-items: flex-start;
}

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

.message-meta {
  margin-bottom: 4px;
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1.35;
}

.visitor-read-state {
  color: #9ca3af;
}

.message-row.outgoing .visitor-read-state {
  color: rgb(255 255 255 / 0.78);
}

.message-bubble {
  display: inline-block;
  max-width: 80%;
  padding: 8px 10px;
  border-radius: 8px;
  color: var(--text-strong);
  background: var(--incoming);
  font-size: 16px;
  line-height: 1.45;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.message-row.outgoing .message-bubble {
  color: #ffffff;
  background: var(--primary);
}

.message-bubble.recalled-message {
  color: var(--text-muted);
  background: #f1f5f9;
  font-style: italic;
}

.message-row.outgoing .message-bubble.recalled-message {
  color: #64748b;
  background: #eef2f7;
}

.message-media {
  overflow: hidden;
  padding: 0;
  background: transparent;
}

.message-media img,
.message-media video {
  display: block;
  width: auto;
  max-width: min(280px, 100%);
  max-height: 220px;
  border-radius: 8px;
  object-fit: cover;
}

.typing-row {
  display: flex;
  margin: 2px 0 10px;
  align-items: center;
  gap: 8px;
  color: var(--text-muted);
  font-size: 12px;
}

.typing-bubble {
  display: inline-flex;
  padding: 9px 12px;
  border-radius: 8px;
  background: var(--incoming);
  gap: 4px;
}

.typing-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #6b7280;
  animation: typing-bounce 1.1s infinite ease-in-out;
}

.typing-dot:nth-child(2) {
  animation-delay: 0.14s;
}

.typing-dot:nth-child(3) {
  animation-delay: 0.28s;
}

@keyframes typing-bounce {
  0%,
  60%,
  100% {
    transform: translateY(0);
    opacity: 0.45;
  }

  30% {
    transform: translateY(-3px);
    opacity: 1;
  }
}

.queue-notice {
  margin: 0 16px 10px;
  padding: 10px 12px;
  border: 1px solid #fde68a;
  border-radius: 6px;
  color: #92400e;
  background: #fffbeb;
  font-size: 13px;
  line-height: 1.5;
}

.composer {
  position: relative;
  min-height: 80px;
  flex: 0 0 auto;
  padding: 9px 16px calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  background: #ffffff;
}

.composer-toolbar {
  display: flex;
  height: 24px;
  align-items: center;
  justify-content: space-between;
}

.composer-tools {
  display: flex;
  align-items: center;
  gap: 6px;
}

.composer-tool {
  display: inline-grid;
  width: 28px;
  height: 28px;
  place-items: center;
  border-radius: 5px;
  color: var(--text-muted);
  background: transparent;
}

.composer-tool:hover {
  color: var(--text-strong);
  background: var(--surface-muted);
}

.composer-tool svg {
  width: 20px;
  height: 20px;
}

.character-count {
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1;
}

.composer-input-row {
  display: flex;
  min-height: 38px;
  align-items: flex-end;
  gap: 10px;
  margin-top: 1px;
}

.message-input {
  width: 100%;
  min-height: 38px;
  max-height: 88px;
  resize: none;
  overflow-y: auto;
  padding: 7px 44px 7px 0;
  border: 0;
  outline: 0;
  color: var(--text-strong);
  background: transparent;
  font-size: 16px;
  line-height: 1.5;
  scrollbar-width: none;
}

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

.message-input::placeholder {
  color: #9ca3af;
}

.send-button {
  position: absolute;
  right: 16px;
  bottom: calc(12px + env(safe-area-inset-bottom));
  display: grid;
  width: 32px;
  height: 32px;
  place-items: center;
  border-radius: 50%;
  color: #ffffff;
  background: var(--primary);
  transition:
    background-color 150ms ease,
    opacity 150ms ease,
    transform 100ms ease;
}

.send-button:hover {
  background: var(--primary-hover);
}

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

.send-button:disabled {
  opacity: 0.45;
}

.send-button svg {
  width: 18px;
  height: 18px;
}

.emoji-picker {
  position: absolute;
  z-index: 20;
  right: 16px;
  bottom: calc(100% + 8px);
  display: none;
  width: 252px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #ffffff;
  box-shadow: 0 12px 28px rgb(15 23 42 / 0.16);
  grid-template-columns: repeat(7, 1fr);
  gap: 3px;
}

.emoji-picker.open {
  display: grid;
}

.emoji-option {
  display: grid;
  width: 30px;
  height: 30px;
  place-items: center;
  border-radius: 5px;
  background: transparent;
  font-size: 19px;
}

.emoji-option:hover {
  background: var(--surface-muted);
}

.sidebar {
  display: flex;
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  height: 100%;
  flex-direction: column;
  border-left: 1px solid var(--border);
  background: #ffffff;
}

.sidebar-tabs {
  display: flex;
  height: 100px;
  flex: 0 0 100px;
  align-items: flex-end;
  background: var(--primary);
}

.sidebar-tab {
  position: relative;
  display: flex;
  height: 50px;
  flex: 1;
  align-items: center;
  justify-content: center;
  color: rgb(255 255 255 / 0.78);
  background: transparent;
  font-size: 15px;
  font-weight: 500;
}

.sidebar-tab.active {
  color: var(--text-strong);
  background: #ffffff;
}

.sidebar-tab.active::after {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  height: 2px;
  background: #22c55e;
  content: "";
}

.sidebar-body {
  min-height: 0;
  flex: 1;
  overflow-y: auto;
}

.quick-links {
  display: grid;
  padding: 16px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.quick-link {
  display: flex;
  min-width: 0;
  min-height: 92px;
  align-items: center;
  justify-content: center;
  padding: 10px 4px;
  border-radius: 8px;
  flex-direction: column;
  gap: 8px;
  text-align: center;
  transition: background-color 150ms ease;
}

.quick-link:hover {
  background: var(--surface-muted);
}

.quick-link-icon {
  display: grid;
  width: 56px;
  height: 56px;
  flex: 0 0 56px;
  place-items: center;
  overflow: hidden;
  border-radius: 50%;
  color: #ffffff;
  background:
    radial-gradient(circle at 38% 32%, rgb(255 255 255 / 0.24), transparent 32%),
    linear-gradient(140deg, #3488f8, #0b2b91);
  font-size: 15px;
  font-weight: 600;
  line-height: 1.1;
}

.quick-link-icon img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.quick-link-text {
  max-width: 100%;
  color: var(--text);
  font-size: 12px;
  line-height: 1.3;
  overflow-wrap: anywhere;
}

.quick-link:hover .quick-link-text {
  color: #16a34a;
}

.sidebar-empty {
  padding: 32px 16px;
  color: var(--text-muted);
  font-size: 13px;
  text-align: center;
}

.faq-list {
  padding: 4px 0;
}

.faq-list .quick-link {
  min-height: 0;
  align-items: flex-start;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  border-radius: 0;
  color: var(--text);
  text-align: left;
}

.sidebar-card {
  display: grid;
  padding: 18px 16px;
  gap: 14px;
}

.sidebar-card-row {
  display: grid;
  gap: 4px;
  color: var(--text-muted);
  font-size: 12px;
}

.sidebar-card-row strong {
  color: var(--text-strong);
  font-size: 14px;
  font-weight: 500;
  overflow-wrap: anywhere;
}

.sidebar-overlay {
  display: none;
}

.evaluation-overlay {
  position: absolute;
  z-index: 60;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgb(15 23 42 / 0.34);
  backdrop-filter: blur(2px);
}

.evaluation-card {
  position: relative;
  width: min(430px, 100%);
  max-height: calc(100% - 8px);
  overflow-y: auto;
  padding: 24px;
  border-radius: 8px;
  background: #ffffff;
  box-shadow: 0 22px 55px rgb(15 23 42 / 0.28);
}

.evaluation-card h2 {
  margin: 0;
  color: var(--text-strong);
  font-size: 20px;
  font-weight: 650;
}

.evaluation-card > p {
  margin: 7px 0 18px;
  color: var(--text-muted);
  font-size: 13px;
}

.evaluation-close {
  position: absolute;
  top: 12px;
  right: 12px;
  display: grid;
  width: 28px;
  height: 28px;
  place-items: center;
  border-radius: 5px;
  color: #64748b;
  background: transparent;
  font-size: 21px;
  line-height: 1;
}

.evaluation-close:hover {
  background: #f1f5f9;
}

.evaluation-ratings {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.evaluation-ratings button {
  display: flex;
  min-height: 78px;
  align-items: center;
  justify-content: center;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--text);
  background: #ffffff;
  flex-direction: column;
  gap: 5px;
}

.evaluation-ratings button span {
  font-size: 27px;
  line-height: 1;
}

.evaluation-ratings button strong {
  font-size: 12px;
  font-weight: 600;
}

.evaluation-ratings button:hover,
.evaluation-ratings button.active {
  border-color: var(--primary);
  color: var(--primary);
  background: #eff6ff;
}

.evaluation-card textarea {
  width: 100%;
  min-height: 78px;
  resize: vertical;
  padding: 9px 10px;
  border: 1px solid #cbd5e1;
  border-radius: 7px;
  outline: 0;
  color: var(--text-strong);
  font-size: 13px;
  line-height: 1.5;
}

.evaluation-card textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgb(59 130 246 / 0.1);
}

.evaluation-label {
  display: block;
  margin: 18px 0 7px;
  color: #334155;
  font-size: 12px;
  font-weight: 600;
}

.evaluation-resolved {
  display: flex;
  margin-top: 14px;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: #475569;
  font-size: 12px;
}

.evaluation-resolved > div {
  display: flex;
  gap: 7px;
}

.evaluation-resolved button {
  min-width: 48px;
  padding: 6px 12px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  color: #475569;
  background: #ffffff;
  font-size: 12px;
}

.evaluation-resolved button.active {
  border-color: var(--primary);
  color: var(--primary);
  background: #eff6ff;
}

.evaluation-error {
  min-height: 18px;
  margin: 8px 0 0 !important;
  color: var(--danger) !important;
  font-size: 12px !important;
}

.evaluation-submit {
  width: 100%;
  min-height: 40px;
  margin-top: 8px;
  border-radius: 7px;
  color: #ffffff;
  background: var(--primary);
  font-size: 14px;
  font-weight: 600;
}

.evaluation-submit:hover {
  background: var(--primary-hover);
}

.evaluation-thanks {
  padding: 16px 4px 4px;
  text-align: center;
}

.evaluation-thanks > span {
  display: grid;
  width: 52px;
  height: 52px;
  margin: 0 auto 14px;
  place-items: center;
  border-radius: 50%;
  color: #ffffff;
  background: #16a34a;
  font-size: 24px;
}

.evaluation-thanks h2 {
  margin: 0;
  font-size: 19px;
}

.evaluation-thanks p {
  margin: 8px 0 20px;
  color: var(--text-muted);
  font-size: 13px;
}

.evaluation-thanks button {
  min-width: 120px;
  min-height: 38px;
  border-radius: 7px;
  color: #ffffff;
  background: var(--primary);
}

.toast {
  position: fixed;
  z-index: 100;
  top: 18px;
  left: 50%;
  max-width: min(360px, calc(100vw - 32px));
  padding: 9px 14px;
  border-radius: 6px;
  color: #ffffff;
  background: #111827;
  box-shadow: 0 8px 24px rgb(0 0 0 / 0.18);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, -8px);
  transition:
    opacity 160ms ease,
    transform 160ms ease;
  font-size: 13px;
  line-height: 1.45;
}

.toast.visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

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

@media (min-width: 769px) {
  .sidebar {
    position: relative;
    transform: translateX(0);
  }

  .chat-shell:not(.has-sidebar) .sidebar {
    display: none;
  }

  .chat-shell:not(.has-sidebar) .mobile-sidebar-button {
    display: inline-grid;
  }
}

@media (max-width: 768px), (max-height: 679px) {
  .app-stage {
    padding: 0;
  }

  .chat-shell,
  .chat-shell.has-sidebar {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    border-radius: 0;
  }

  .chat-main {
    width: 100%;
  }

  .mobile-sidebar-button {
    display: inline-grid;
  }

  .sidebar {
    position: absolute;
    z-index: 40;
    top: 0;
    right: 0;
    bottom: 0;
    width: min(var(--sidebar-width), calc(100vw - 56px));
    min-width: min(var(--sidebar-width), calc(100vw - 56px));
    box-shadow: -18px 0 40px rgb(15 23 42 / 0.18);
    transform: translateX(100%);
    transition: transform 180ms ease-out;
  }

  .chat-shell.sidebar-open .sidebar {
    transform: translateX(0);
  }

  .sidebar-overlay {
    position: absolute;
    z-index: 30;
    inset: 0;
    display: block;
    background: rgb(0 0 0 / 0.2);
    opacity: 0;
    pointer-events: none;
    transition: opacity 180ms ease-out;
  }

  .chat-shell.sidebar-open .sidebar-overlay {
    opacity: 1;
    pointer-events: auto;
  }
}

@media (max-width: 440px) {
  .chat-header {
    padding-right: 10px;
    padding-left: 12px;
  }

  .agent-name {
    max-width: calc(100vw - 140px);
    font-size: 17px;
  }

  .message-area {
    padding: 14px 12px;
  }

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

  .send-button {
    right: 12px;
  }
}

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