:root {
  --ink: #1b2a4a;
  --muted: #8a9bb2;
  --blue: #4f86c6;
  --blue-deep: #2b4c7e;
  --blue-pale: #eaf4ff;
  --pink: #ff9fb2;
  --pink-deep: #e86f8f;
  --line: #e2ecf8;
  --bg-a: #eef7ff;
  --bg-b: #fff7fb;
  --card: #ffffff;
  --shadow: 0 10px 30px rgba(43, 76, 126, .08);
}

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

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei UI", "Microsoft YaHei", "Segoe UI", sans-serif;
  color: var(--ink);
  background: linear-gradient(160deg, var(--bg-a), var(--bg-b));
  overflow: hidden;
}

button, textarea {
  font-family: inherit;
}

.hidden {
  display: none !important;
}

.app {
  position: relative;
  height: 100dvh;
  max-width: 760px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  background: linear-gradient(180deg, rgba(255, 255, 255, .72), rgba(255, 255, 255, .42));
}

/* ------------------------------------------------------------------ topbar */
.topbar {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: calc(10px + env(safe-area-inset-top)) 14px 10px;
  background: rgba(255, 255, 255, .78);
  border-bottom: 1px solid rgba(226, 236, 248, .9);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  z-index: 10;
}

.avatar {
  position: relative;
  width: 50px;
  height: 50px;
  border-radius: 50%;
  background: #fff;
  border: 1px solid var(--line);
  box-shadow: 0 5px 16px rgba(79, 134, 198, .16);
  display: grid;
  place-items: center;
  flex: none;
  overflow: hidden;
}

.avatar img {
  width: 44px;
  height: auto;
  image-rendering: pixelated;
}

.avatar::after {
  content: "";
  position: absolute;
  right: 2px;
  bottom: 3px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #63cf9a;
  border: 2px solid #fff;
}

.avatar.offline::after {
  background: #c6d2e2;
}

.who {
  min-width: 0;
  flex: 1;
}

.who h1 {
  margin: 0;
  font-size: 17px;
  letter-spacing: .3px;
}

.who p {
  margin: 3px 0 0;
  font-size: 11px;
  color: var(--muted);
}

.icon-btn {
  width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: #fff;
  color: var(--blue-deep);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  flex: none;
}

/* ------------------------------------------------------------------ banner */
.banner {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 8px 14px 0;
  padding: 9px 12px;
  border-radius: 13px;
  background: #fff7e8;
  border: 1px solid #ffe2ae;
  color: #8a6420;
  font-size: 12px;
}

.banner span {
  flex: 1;
}

.banner button {
  border: 0;
  background: #ffd98e;
  color: #6c4c12;
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  flex: none;
}

/* -------------------------------------------------------------------- chat */
.chat {
  flex: 1;
  overflow-y: auto;
  padding: 8px 14px 18px;
  scroll-behavior: smooth;
  overscroll-behavior: contain;
}

.chat::-webkit-scrollbar {
  width: 0;
}

.welcome {
  text-align: center;
  padding: 18px 8px 8px;
}

.welcome-pet {
  width: 132px;
  height: auto;
  image-rendering: pixelated;
  filter: drop-shadow(0 14px 16px rgba(43, 76, 126, .16));
  animation: bob 3.2s ease-in-out infinite;
}

.welcome h2 {
  margin: 6px 0 6px;
  font-size: 21px;
}

.welcome p {
  margin: 0 auto;
  max-width: 310px;
  color: #617792;
  font-size: 13px;
  line-height: 1.7;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin-top: 16px;
}

.chip {
  border: 1px solid var(--line);
  background: #fff;
  color: #4a6b8f;
  border-radius: 999px;
  padding: 7px 12px;
  font-size: 12px;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(79, 134, 198, .06);
}

.chip:active {
  transform: scale(.97);
}

.bubble-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  margin: 11px 0;
}

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

.bubble-row.assistant {
  align-items: flex-start;
}

.bubble-row.assistant .mini-avatar {
  margin-top: 3px;
}

.mini-avatar {
  width: 29px;
  height: 29px;
  border-radius: 50%;
  background: #fff;
  border: 1px solid var(--line);
  display: grid;
  place-items: center;
  flex: none;
  overflow: hidden;
}

.mini-avatar img {
  width: 25px;
  height: auto;
  image-rendering: pixelated;
}

.bubble {
  max-width: 82%;
  padding: 10px 13px;
  border-radius: 18px;
  font-size: 14.5px;
  line-height: 1.68;
  word-break: break-word;
  white-space: normal;
}

.bubble-row.assistant .bubble {
  background: var(--card);
  border: 1px solid var(--line);
  border-bottom-left-radius: 6px;
  box-shadow: var(--shadow);
}

.bubble-row.user .bubble {
  background: linear-gradient(135deg, #6aa5e6, #4f86c6);
  color: #fff;
  border-bottom-right-radius: 6px;
  box-shadow: 0 8px 20px rgba(79, 134, 198, .22);
}

.bubble p {
  margin: 0 0 6px;
}

.bubble p:last-child {
  margin-bottom: 0;
}

.bubble ul, .bubble ol {
  margin: 4px 0 7px;
  padding-left: 18px;
}

.bubble li {
  margin: 2px 0;
}

.bubble h3 {
  margin: 8px 0 4px;
  font-size: 15px;
}

.bubble code {
  background: #eef5fd;
  color: #2b4c7e;
  border-radius: 5px;
  padding: 1px 4px;
  font-size: .92em;
}

.bubble pre {
  margin: 7px 0;
  padding: 9px 10px;
  background: #f4f8fd;
  border-radius: 9px;
  overflow-x: auto;
  font-size: 12px;
  line-height: 1.55;
}

.bubble pre code {
  background: transparent;
  padding: 0;
}

/* --------------------------------------------------------------- file card */
.file-card {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 9px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #f8fbff;
}

.file-icon {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: #eaf3ff;
  color: #3f76ae;
  font-size: 10px;
  font-weight: 800;
  display: grid;
  place-items: center;
  flex: none;
  letter-spacing: .5px;
}

.file-card.pptx .file-icon {
  background: #fff0f3;
  color: #d46586;
}

.file-card.xlsx .file-icon {
  background: #eaf8f0;
  color: #2f8a5b;
}

.file-meta {
  flex: 1;
  min-width: 0;
}

.file-meta strong {
  display: block;
  font-size: 12.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.file-meta span {
  display: block;
  margin-top: 2px;
  font-size: 10.5px;
  color: var(--muted);
}

.file-dl {
  flex: none;
  text-decoration: none;
  color: #fff;
  background: linear-gradient(135deg, #6aa5e6, #4f86c6);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 11.5px;
  font-weight: 600;
}

/* ----------------------------------------------------------------- typing */
.typing {
  position: absolute;
  left: 50%;
  bottom: calc(78px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 7px 12px 7px 8px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 999px;
  box-shadow: var(--shadow);
  z-index: 6;
}

.typing img {
  width: 25px;
  height: auto;
  image-rendering: pixelated;
}

.dots {
  display: flex;
  gap: 3px;
}

.dots i {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #9fb6d2;
  animation: dot 1.1s ease-in-out infinite;
}

.dots i:nth-child(2) { animation-delay: .15s; }
.dots i:nth-child(3) { animation-delay: .3s; }

/* --------------------------------------------------------------- composer */
.composer {
  display: flex;
  flex-direction: column;
  gap: 7px;
  width: 100%;
  box-sizing: border-box;
  padding: 8px 12px calc(9px + env(safe-area-inset-bottom));
  background: linear-gradient(180deg, rgba(255, 255, 255, .55), rgba(255, 255, 255, .92));
  border-top: 1px solid rgba(226, 236, 248, .9);
}

.composer-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 44px;
  align-items: end;
  gap: 8px;
  width: 100%;
}

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

.tool-btn {
  border: 1px solid var(--line);
  background: #fff;
  color: #4a6b8f;
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 11.5px;
  line-height: 1.3;
  cursor: pointer;
}

.tool-btn.active {
  background: #fff0f5;
  border-color: #ffc7d6;
  color: #b04a62;
}

.attach-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  max-width: 62vw;
  padding: 4px 8px;
  border-radius: 999px;
  background: #eef7ff;
  border: 1px solid #d6e9fb;
  color: #3f6d9c;
  font-size: 11px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.attach-chip button {
  border: 0;
  background: transparent;
  color: #6f8fae;
  font-size: 13px;
  cursor: pointer;
  padding: 0 2px;
}

.speak-btn {
  margin-top: 6px;
  border: 0;
  background: transparent;
  color: #8aa3bd;
  font-size: 12px;
  padding: 0;
  cursor: pointer;
}

.bubble a {
  color: #2b6cb0;
  text-decoration: underline;
  word-break: break-all;
}

.composer textarea {
  flex: 1;
  min-width: 0;
  width: 100%;
  box-sizing: border-box;
  resize: none;
  border: 1.5px solid #dbe8f6;
  background: #fff;
  color: var(--ink);
  border-radius: 22px;
  padding: 10px 15px;
  font-size: 15px;
  line-height: 1.45;
  max-height: 120px;
  outline: none;
  box-shadow: 0 4px 14px rgba(79, 134, 198, .06);
}

.composer textarea:focus {
  border-color: #a9cdf0;
}

.composer textarea::placeholder {
  color: #a9b8cb;
}

.composer-row > button {
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: linear-gradient(135deg, #6aa5e6, #4f86c6);
  color: #fff;
  font-size: 21px;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 8px 18px rgba(79, 134, 198, .28);
  flex: none;
  transition: opacity .15s, transform .1s;
}

.composer-row > button:active {
  transform: scale(.95);
}

.composer-row > button:disabled {
  opacity: .45;
}

/* ------------------------------------------------------------------ toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(96px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  max-width: 86vw;
  padding: 9px 14px;
  border-radius: 999px;
  background: rgba(27, 42, 74, .9);
  color: #fff;
  font-size: 12.5px;
  z-index: 60;
  box-shadow: 0 10px 30px rgba(27, 42, 74, .25);
}

/* ------------------------------------------------------------------ sheet */
.sheet {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(24, 45, 76, .28);
  backdrop-filter: blur(2px);
}

.sheet-card {
  width: 100%;
  max-width: 760px;
  background: #fff;
  border-radius: 22px 22px 0 0;
  padding: 16px 16px calc(14px + env(safe-area-inset-bottom));
  box-shadow: 0 -18px 50px rgba(27, 42, 74, .16);
  animation: sheet-up .2s ease-out;
}

.sheet-card h3 {
  margin: 0 0 10px;
  font-size: 15px;
}

.sheet-body {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sheet-row {
  border: 0;
  background: transparent;
  text-align: left;
  padding: 13px 4px;
  font-size: 14.5px;
  color: var(--ink);
  border-bottom: 1px solid #f0f5fb;
  cursor: pointer;
}

.sheet-note {
  margin: 10px 2px 4px;
  padding: 11px 12px;
  background: #f6faff;
  border: 1px solid var(--line);
  border-radius: 12px;
  font-size: 12.5px;
  line-height: 1.7;
  color: #55708f;
  word-break: break-all;
}

.close-btn {
  width: 100%;
  margin-top: 12px;
  border: 1px solid var(--line);
  background: #f8fbff;
  color: #4a6b8f;
  border-radius: 14px;
  padding: 12px;
  font-size: 14px;
  cursor: pointer;
}

@media (min-width: 620px) {
  .sheet {
    align-items: center;
    padding: 20px;
  }
  .sheet-card {
    border-radius: 22px;
    max-width: 430px;
  }
}

/* ------------------------------------------------------------- animations */
@keyframes bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-5px); }
}

@keyframes dot {
  0%, 60%, 100% { opacity: .25; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-2px); }
}

@keyframes sheet-up {
  from { transform: translateY(24px); opacity: .3; }
  to { transform: translateY(0); opacity: 1; }
}
