:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --panel: rgba(255, 255, 255, 0.78);
  --panel-strong: #ffffff;
  --ink: #172033;
  --muted: #667085;
  --line: rgba(23, 32, 51, 0.1);
  --accent: #16a085;
  --accent-dark: #0f766e;
  --warm: #ffb86b;
  --rose: #e85d75;
  --shadow: 0 24px 80px rgba(40, 52, 84, 0.16);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

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

body {
  color: var(--ink);
  background:
    radial-gradient(circle at 18% 8%, rgba(255, 184, 107, 0.28), transparent 26rem),
    radial-gradient(circle at 82% 18%, rgba(22, 160, 133, 0.2), transparent 24rem),
    linear-gradient(135deg, #f8fbff 0%, #eef4f7 50%, #fbf7f2 100%);
  overflow: hidden;
}

button,
textarea {
  font: inherit;
}

.app-shell {
  min-height: 100dvh;
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(360px, 0.75fr);
  gap: 22px;
  align-items: stretch;
  width: min(1420px, 100%);
  height: 100dvh;
  margin: 0 auto;
  padding: 32px;
}

.chat-panel {
  width: 100%;
  min-width: 0;
  height: calc(100dvh - 64px);
  display: grid;
  grid-template-rows: auto 1fr auto;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.72);
  border-radius: 30px;
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(24px);
}

.recommendation-panel {
  min-width: 0;
  height: calc(100dvh - 64px);
  display: grid;
  grid-template-rows: auto 1fr;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.72);
  border-radius: 30px;
  background: rgba(255, 255, 255, 0.7);
  box-shadow: var(--shadow);
  backdrop-filter: blur(24px);
}

.recommendation-header {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 22px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.64);
}

.rec-handle {
  display: none;
}

.rec-close {
  display: none;
}

.recommendation-header h2 {
  margin: 0;
  font-size: 24px;
  line-height: 1.15;
  letter-spacing: 0;
}

.mode-pill {
  margin-left: auto;
  padding: 7px 10px;
  border: 1px solid rgba(23, 32, 51, 0.08);
  border-radius: 999px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.72);
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.mode-pill[data-tone="loading"] {
  color: #805a1f;
  background: rgba(255, 184, 107, 0.18);
}

.mode-pill[data-tone="ready"] {
  color: var(--accent-dark);
  background: rgba(22, 160, 133, 0.1);
}

.mode-pill[data-tone="local"] {
  color: var(--rose);
  background: rgba(232, 93, 117, 0.1);
}

.recommendation-list {
  display: grid;
  align-content: start;
  gap: 14px;
  overflow-y: auto;
  padding: 18px;
}

.recommendation-list::-webkit-scrollbar {
  width: 10px;
}

.recommendation-list::-webkit-scrollbar-thumb {
  border: 3px solid transparent;
  border-radius: 999px;
  background: rgba(23, 32, 51, 0.18);
  background-clip: content-box;
}

.recommendation-empty {
  display: grid;
  gap: 8px;
  padding: 22px;
  border: 1px dashed rgba(22, 160, 133, 0.28);
  border-radius: 20px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.66);
  line-height: 1.55;
}

.recommendation-empty strong {
  color: var(--ink);
  font-size: 18px;
}

.rec-backdrop {
  display: none;
}

.rec-toggle {
  display: none;
}

.mini-loader {
  display: inline-flex;
  gap: 6px;
  align-items: center;
  height: 22px;
}

.mini-loader span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  animation: typing 1s ease-in-out infinite;
}

.mini-loader span:nth-child(2) {
  animation-delay: 120ms;
}

.mini-loader span:nth-child(3) {
  animation-delay: 240ms;
}

.chat-header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 22px 24px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.62);
}

.agent-mark {
  width: 52px;
  height: 52px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 18px;
  background:
    linear-gradient(145deg, rgba(22, 160, 133, 0.95), rgba(232, 93, 117, 0.78)),
    #16a085;
  box-shadow: 0 14px 32px rgba(22, 160, 133, 0.28);
}

.agent-mark span {
  width: 22px;
  height: 22px;
  display: block;
  border-radius: 50%;
  background: #ffffff;
  box-shadow:
    0 0 0 8px rgba(255, 255, 255, 0.24),
    inset -5px -5px 0 rgba(255, 184, 107, 0.78);
  animation: breathe 2.7s ease-in-out infinite;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent-dark);
  font-size: 13px;
  font-weight: 700;
}

h1 {
  margin: 0;
  font-size: clamp(22px, 3vw, 30px);
  line-height: 1.1;
  letter-spacing: 0;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
  padding: 8px 12px;
  border: 1px solid rgba(22, 160, 133, 0.18);
  border-radius: 999px;
  color: var(--accent-dark);
  background: rgba(22, 160, 133, 0.08);
  font-size: 13px;
  font-weight: 700;
}

.status-pill span {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: #20c997;
  box-shadow: 0 0 0 6px rgba(32, 201, 151, 0.12);
}

.messages {
  display: flex;
  flex-direction: column;
  gap: 18px;
  overflow-y: auto;
  padding: 24px;
  scroll-behavior: smooth;
}

.messages::-webkit-scrollbar {
  width: 10px;
}

.messages::-webkit-scrollbar-thumb {
  border: 3px solid transparent;
  border-radius: 999px;
  background: rgba(23, 32, 51, 0.18);
  background-clip: content-box;
}

.message {
  display: flex;
  animation: messageIn 420ms cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

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

.bubble {
  max-width: min(760px, 88%);
  padding: 16px 18px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.82);
  box-shadow: 0 12px 34px rgba(40, 52, 84, 0.08);
}

.message.user .bubble {
  color: #ffffff;
  border: 0;
  border-bottom-right-radius: 8px;
  background: linear-gradient(135deg, #137c72, #16a085);
  box-shadow: 0 18px 36px rgba(22, 160, 133, 0.24);
}

.message.agent .bubble {
  border-bottom-left-radius: 8px;
}

.bubble p {
  margin: 0;
  font-size: 16px;
  line-height: 1.68;
  white-space: pre-wrap;
}

.bubble h3,
.bubble h4 {
  margin: 12px 0 6px;
  font-size: 16px;
  line-height: 1.35;
  letter-spacing: 0;
}

.bubble ul {
  margin: 8px 0;
  padding-left: 20px;
}

.bubble li {
  margin: 5px 0;
  line-height: 1.6;
}

.bubble code {
  padding: 2px 5px;
  border-radius: 6px;
  background: rgba(23, 32, 51, 0.08);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.92em;
}

.bubble.streaming > p::after {
  content: "";
  display: inline-block;
  width: 7px;
  height: 1.1em;
  margin-left: 3px;
  border-radius: 999px;
  background: var(--accent);
  vertical-align: -0.18em;
  animation: cursorBlink 900ms steps(2, start) infinite;
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 14px;
}

.chip {
  min-height: 36px;
  padding: 0 13px;
  border: 1px solid rgba(22, 160, 133, 0.2);
  border-radius: 999px;
  color: var(--accent-dark);
  background: rgba(22, 160, 133, 0.08);
  cursor: pointer;
  transition: transform 160ms ease, background 160ms ease;
}

.chip:hover {
  background: rgba(22, 160, 133, 0.14);
  transform: translateY(-1px);
}

.recommendations {
  display: grid;
  gap: 14px;
  margin-top: 16px;
}

.product-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 132px;
  gap: 16px;
  align-items: stretch;
  padding: 14px;
  border: 1px solid rgba(23, 32, 51, 0.08);
  border-radius: 20px;
  background: var(--panel-strong);
  box-shadow: 0 16px 38px rgba(40, 52, 84, 0.1);
  animation: cardIn 480ms cubic-bezier(0.2, 0.8, 0.2, 1) both;
  animation-delay: var(--delay);
}

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

.product-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 8px;
}

.product-meta span {
  padding: 5px 8px;
  border-radius: 999px;
  color: #805a1f;
  background: rgba(255, 184, 107, 0.2);
  font-size: 12px;
  font-weight: 700;
}

.product-card h2 {
  margin: 0;
  font-size: 18px;
  line-height: 1.35;
  letter-spacing: 0;
}

.reason {
  margin: 8px 0 12px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.62;
  white-space: normal;
}

.product-facts {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.product-facts strong {
  color: var(--rose);
  font-size: 18px;
}

.product-facts span {
  min-width: 0;
  color: var(--muted);
  font-size: 13px;
}

.qr-wrap {
  display: grid;
  gap: 8px;
  place-content: center;
  place-items: center;
  min-width: 0;
  padding: 12px;
  border: 1px solid rgba(23, 32, 51, 0.06);
  border-radius: 14px;
  background: #f7faf9;
  animation: qrFade 600ms ease both;
}

.qr-wrap img,
.qr-empty {
  width: 104px;
  height: 104px;
  border-radius: 10px;
}

.qr-wrap img {
  object-fit: contain;
  background: #ffffff;
}

.qr-empty {
  display: grid;
  place-items: center;
  color: var(--muted);
  background: repeating-linear-gradient(45deg, #eef2f4, #eef2f4 8px, #f7faf9 8px, #f7faf9 16px);
  font-size: 13px;
  line-height: 1.35;
  text-align: center;
}

.qr-wrap span {
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 800;
}

.thinking {
  display: inline-flex;
  gap: 7px;
  align-items: center;
  min-width: 76px;
  min-height: 48px;
}

.thinking span {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--accent);
  animation: typing 1s ease-in-out infinite;
}

.thinking span:nth-child(2) {
  animation-delay: 120ms;
}

.thinking span:nth-child(3) {
  animation-delay: 240ms;
}

.composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 52px;
  gap: 12px;
  align-items: end;
  padding: 18px 20px calc(18px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.76);
}

textarea {
  width: 100%;
  max-height: 132px;
  resize: none;
  padding: 16px 18px;
  border: 1px solid rgba(23, 32, 51, 0.1);
  border-radius: 18px;
  outline: none;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.92);
  line-height: 1.5;
  transition: border 160ms ease, box-shadow 160ms ease, background 160ms ease;
}

textarea:focus {
  border-color: rgba(22, 160, 133, 0.55);
  background: #ffffff;
  box-shadow: 0 0 0 5px rgba(22, 160, 133, 0.1);
}

textarea:disabled {
  opacity: 0.7;
}

#sendButton {
  width: 52px;
  height: 52px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 18px;
  color: #ffffff;
  background: linear-gradient(135deg, #137c72, #16a085);
  box-shadow: 0 14px 28px rgba(22, 160, 133, 0.24);
  cursor: pointer;
  transition: transform 160ms ease, box-shadow 160ms ease, opacity 160ms ease;
}

#sendButton:hover {
  transform: translateY(-2px);
  box-shadow: 0 18px 36px rgba(22, 160, 133, 0.3);
}

#sendButton:active {
  transform: translateY(0) scale(0.98);
}

#sendButton:disabled {
  cursor: wait;
  opacity: 0.58;
}

#sendButton svg {
  width: 24px;
  height: 24px;
  fill: currentColor;
}

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

.login-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 18% 8%, rgba(255, 184, 107, 0.28), transparent 26rem),
    radial-gradient(circle at 82% 18%, rgba(22, 160, 133, 0.2), transparent 24rem),
    linear-gradient(135deg, #f8fbff 0%, #eef4f7 50%, #fbf7f2 100%);
  transition: opacity 380ms ease, visibility 380ms ease;
}

.login-overlay.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.login-card {
  width: min(380px, calc(100vw - 48px));
  padding: 40px 32px 36px;
  border: 1px solid rgba(255, 255, 255, 0.72);
  border-radius: 30px;
  background: rgba(255, 255, 255, 0.78);
  box-shadow: 0 24px 80px rgba(40, 52, 84, 0.16);
  backdrop-filter: blur(24px);
  text-align: center;
  animation: cardIn 480ms cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

.login-brand {
  display: grid;
  place-items: center;
  margin-bottom: 20px;
}

.login-brand .agent-mark {
  width: 64px;
  height: 64px;
  border-radius: 22px;
}

.login-card h1 {
  margin: 0 0 6px;
  font-size: 28px;
  letter-spacing: 0;
}

.login-desc {
  margin: 0 0 28px;
  color: var(--muted);
  font-size: 15px;
}

.login-form {
  display: grid;
  gap: 16px;
  text-align: left;
}

.login-field {
  display: grid;
  gap: 6px;
}

.login-field span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.login-field input {
  width: 100%;
  padding: 14px 16px;
  border: 1px solid rgba(23, 32, 51, 0.1);
  border-radius: 14px;
  outline: none;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.92);
  font-size: 16px;
  line-height: 1.5;
  transition: border 160ms ease, box-shadow 160ms ease;
}

.login-field input:focus {
  border-color: rgba(22, 160, 133, 0.55);
  background: #ffffff;
  box-shadow: 0 0 0 5px rgba(22, 160, 133, 0.1);
}

.login-error {
  margin: 0;
  min-height: 1.4em;
  color: var(--rose);
  font-size: 13px;
  font-weight: 700;
  text-align: center;
}

.login-submit {
  width: 100%;
  padding: 15px 0;
  border: 0;
  border-radius: 16px;
  color: #ffffff;
  background: linear-gradient(135deg, #137c72, #16a085);
  box-shadow: 0 14px 28px rgba(22, 160, 133, 0.24);
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 160ms ease, box-shadow 160ms ease, opacity 160ms ease;
}

.login-submit:hover {
  transform: translateY(-1px);
  box-shadow: 0 18px 36px rgba(22, 160, 133, 0.3);
}

.login-submit:active {
  transform: translateY(0) scale(0.98);
}

.login-submit:disabled {
  opacity: 0.58;
  cursor: wait;
  transform: none;
}

@keyframes breathe {
  0%,
  100% {
    transform: scale(1);
  }
  50% {
    transform: scale(0.88);
  }
}

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

@keyframes cardIn {
  from {
    opacity: 0;
    transform: translateY(14px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes qrFade {
  from {
    opacity: 0;
    transform: scale(0.94);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes typing {
  0%,
  80%,
  100% {
    transform: translateY(0);
    opacity: 0.45;
  }
  40% {
    transform: translateY(-5px);
    opacity: 1;
  }
}

@keyframes cursorBlink {
  0%,
  45% {
    opacity: 1;
  }
  46%,
  100% {
    opacity: 0;
  }
}

@media (max-width: 1040px) and (min-width: 761px) {
  .app-shell {
    grid-template-columns: minmax(0, 1fr) 340px;
    gap: 16px;
    padding: 20px;
  }

  .chat-panel,
  .recommendation-panel {
    height: calc(100dvh - 40px);
    border-radius: 24px;
  }

  .product-card {
    grid-template-columns: 1fr;
  }

  .qr-wrap {
    grid-template-columns: 104px 1fr;
    grid-template-rows: auto;
    justify-items: start;
  }
}

@media (max-width: 760px) {
  body {
    overflow: hidden;
  }

  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr;
    gap: 0;
    width: 100%;
    height: 100dvh;
    min-height: 100dvh;
    padding: 0;
  }

  .chat-panel {
    width: 100%;
    height: 100dvh;
    min-height: 0;
    border: 0;
    border-radius: 0;
  }

  .recommendation-panel {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 110;
    height: auto;
    max-height: 62dvh;
    border: 0;
    border-radius: 22px 22px 0 0;
    box-shadow: 0 -12px 48px rgba(40, 52, 84, 0.22);
    transform: translateY(100%);
    transition: transform 340ms cubic-bezier(0.32, 0.72, 0, 1);
  }

  .recommendation-panel.open {
    transform: translateY(0);
  }

  .rec-handle {
    display: block;
    width: 36px;
    height: 5px;
    margin: 0 auto;
    border-radius: 999px;
    background: rgba(23, 32, 51, 0.18);
  }

  .rec-close {
    display: grid;
    place-items: center;
    width: 32px;
    height: 32px;
    margin-left: auto;
    padding: 0;
    border: 0;
    border-radius: 10px;
    color: var(--muted);
    background: rgba(23, 32, 51, 0.06);
    cursor: pointer;
    flex: 0 0 auto;
  }

  .rec-close svg {
    width: 16px;
    height: 16px;
  }

  .rec-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 100;
    background: rgba(23, 32, 51, 0.32);
    opacity: 0;
    pointer-events: none;
    transition: opacity 340ms cubic-bezier(0.32, 0.72, 0, 1);
  }

  .rec-backdrop.open {
    opacity: 1;
    pointer-events: auto;
  }

  .rec-toggle {
    display: flex;
    align-items: center;
    gap: 7px;
    position: fixed;
    bottom: 96px;
    right: 14px;
    z-index: 90;
    padding: 10px 16px 10px 12px;
    border: 1px solid rgba(23, 32, 51, 0.08);
    border-radius: 999px;
    color: var(--accent-dark);
    background: var(--panel-strong);
    box-shadow: 0 8px 28px rgba(40, 52, 84, 0.16);
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    transition: transform 200ms ease, opacity 200ms ease, box-shadow 200ms ease;
  }

  .rec-toggle:active {
    transform: scale(0.96);
  }

  .rec-toggle.has-recs {
    box-shadow: 0 8px 28px rgba(22, 160, 133, 0.26);
  }

  .rec-toggle svg {
    width: 20px;
    height: 20px;
  }

  .recommendation-header {
    flex-wrap: wrap;
    padding: 12px 16px 14px;
  }

  .recommendation-header h2 {
    font-size: 19px;
  }

  .recommendation-list {
    display: flex;
    gap: 12px;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 12px 14px calc(14px + env(safe-area-inset-bottom));
    scroll-snap-type: x proximity;
  }

  .recommendation-list .product-card,
  .recommendation-empty {
    width: min(370px, calc(100vw - 32px));
    flex: 0 0 min(370px, calc(100vw - 32px));
    scroll-snap-align: start;
  }

  .chat-header {
    padding: calc(14px + env(safe-area-inset-top)) 16px 14px;
    gap: 12px;
  }

  .agent-mark {
    width: 44px;
    height: 44px;
    border-radius: 15px;
  }

  .agent-mark span {
    width: 19px;
    height: 19px;
  }

  .status-pill {
    display: none;
  }

  h1 {
    font-size: 22px;
  }

  .messages {
    gap: 14px;
    padding: 16px 14px;
  }

  .bubble {
    max-width: 94%;
    padding: 14px;
    border-radius: 19px;
  }

  .bubble p {
    font-size: 15px;
  }

  .product-card {
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 12px;
    padding: 13px;
    border-radius: 18px;
  }

  .qr-wrap {
    grid-template-columns: auto;
    place-content: center;
    justify-items: center;
    gap: 6px;
  }

  .qr-wrap img,
  .qr-empty {
    width: 84px;
    height: 84px;
    border-radius: 10px;
  }

  .qr-wrap span {
    display: none;
  }

  .composer {
    grid-template-columns: minmax(0, 1fr) 50px;
    padding: 12px 12px calc(12px + env(safe-area-inset-bottom));
  }

  textarea {
    padding: 14px 15px;
    border-radius: 16px;
  }

  #sendButton {
    width: 50px;
    height: 50px;
    border-radius: 16px;
  }
}

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