/* adai：手机优先、字大、对比清楚。配色和尺寸依据见 docs/design-references.md 第 3 节。 */
:root {
  --bg: #fbf6eb;
  --card: #ffffff;
  --ink: #2b2420;
  --ink2: #5e564e;
  --ink3: #7a7168;
  --line: #e8dfd3;
  --control: #948a80;
  --input-line: #b9aea2;
  --accent: #a8323f;
  --accent-ink: #ffffff;
  --accent-soft: #f6e4e2;
  --accent-line: #d9a6ab;
  --bubble: #f4e4df;
  --shade: rgba(43, 36, 32, 0.4);
  --shadow: 0 1px 2px rgba(43, 36, 32, 0.06), 0 6px 20px rgba(43, 36, 32, 0.06);
  --font: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Microsoft YaHei", sans-serif;
  color-scheme: light dark;
  font-size: 18px;
}
:root.big {
  font-size: 20px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1917;
    --card: #26211f;
    --ink: #f2ece4;
    --ink2: #b8aea4;
    --ink3: #9a9086;
    --line: #3a3330;
    --control: #8a8078;
    --input-line: #5a514b;
    --accent: #e8838f;
    --accent-ink: #1c1917;
    --accent-soft: #3b2629;
    --accent-line: #7a4049;
    --bubble: #3a2d2a;
    --shade: rgba(0, 0, 0, 0.55);
    --shadow: none;
  }
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}
html,
body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}
body {
  overflow: hidden;
  line-height: 1.6;
}
button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
}
button:focus-visible,
a:focus-visible,
input:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}
[hidden] {
  display: none !important;
}
svg {
  flex: none;
}

/* ---------- 启动 ---------- */
.boot {
  height: 100%;
}

/* ---------- 登录 ---------- */
.login {
  height: 100%;
  overflow-y: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 20px calc(24px + env(safe-area-inset-bottom));
}
.login-card {
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.brand {
  text-align: center;
  margin-bottom: 20px;
}
.brand-mark {
  width: 72px;
  height: 72px;
  margin: 0 auto;
  color: var(--accent);
}
.brand h1 {
  margin: 8px 0 2px;
  font-size: 1.6rem;
  letter-spacing: 0.02em;
}
.brand p {
  margin: 0;
  color: var(--ink2);
}
.label {
  font-weight: 600;
}
.pw-row {
  display: flex;
  align-items: center;
  min-height: 56px;
  padding: 0 6px 0 16px;
  background: var(--card);
  border: 1px solid var(--input-line);
  border-radius: 14px;
}
.pw-row:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}
.pw-row input {
  flex: 1;
  min-width: 0;
  height: 54px;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 1.11rem;
}
.pw-row button {
  min-height: 44px;
  padding: 0 12px;
  color: var(--ink2);
}
.btn-primary {
  min-height: 56px;
  border-radius: 14px;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 700;
  font-size: 1.05rem;
}
.btn-primary:disabled {
  opacity: 0.7;
}
.form-error {
  display: flex;
  gap: 6px;
  align-items: center;
  margin: 0;
  color: var(--accent);
  font-weight: 600;
}

/* ---------- 主框架 ---------- */
.app {
  height: var(--app-h, 100dvh);
  display: flex;
  flex-direction: column;
}
.topbar {
  flex: none;
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: 56px;
  padding: calc(env(safe-area-inset-top) + 6px) 8px 6px;
  border-bottom: 1px solid transparent;
  transition: border-color 0.2s;
}
.topbar.scrolled {
  border-bottom-color: var(--line);
}
.top-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  padding: 0 12px;
  border-radius: 12px;
  font-size: 1rem;
}
.top-btn svg {
  width: 22px;
  height: 22px;
}
.top-btn:active {
  background: var(--accent-soft);
}
.top-title {
  flex: 1;
  min-width: 0;
  text-align: center;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--ink2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.scroller {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.inner {
  max-width: 720px;
  margin: 0 auto;
  padding: 0 16px;
}

/* ---------- 首页 ---------- */
.home {
  padding: 4px 0 20px;
}
.greeting {
  margin: 10px 0 2px;
  font-size: 1.4rem;
  font-weight: 700;
  line-height: 1.35;
}
.today {
  margin: 0 0 18px;
  font-size: 0.9rem;
  color: var(--ink2);
}
.cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  min-height: 100px;
  padding: 14px 14px 12px;
  text-align: left;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  transition: transform 0.1s;
}
.card svg {
  width: 28px;
  height: 28px;
  margin-bottom: 4px;
  color: var(--accent);
}
.card:active {
  transform: scale(0.98);
  background: var(--accent-soft);
}
.card-title {
  font-size: 1.05rem;
  font-weight: 700;
  line-height: 1.3;
}
.card-desc {
  font-size: 0.9rem;
  line-height: 1.4;
  color: var(--ink2);
}
.recent h2 {
  margin: 22px 0 4px;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--ink2);
}
.home-note {
  margin: 22px 0 0;
  font-size: 0.9rem;
  color: var(--ink2);
}

/* 对话行（首页「接着聊」和抽屉共用） */
.conv-row {
  display: flex;
  align-items: center;
  border-radius: 12px;
}
.conv-row.current {
  background: var(--accent-soft);
  box-shadow: inset 4px 0 0 var(--accent);
}
.conv-open {
  flex: 1;
  min-width: 0;
  min-height: 56px;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  text-align: left;
}
.recent .conv-row {
  border-bottom: 1px solid var(--line);
  border-radius: 0;
}
.recent .conv-open {
  padding-left: 0;
}
.conv-title {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.conv-meta {
  font-size: 0.8rem;
  color: var(--ink2);
}

/* ---------- 对话 ---------- */
.thread {
  padding: 8px 0 20px;
}
.loading {
  color: var(--ink2);
  text-align: center;
  margin-top: 40px;
}
.msg {
  margin: 18px 0;
}
.msg.user {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
}
.bubble {
  max-width: 85%;
  padding: 10px 16px;
  background: var(--bubble);
  border-radius: 20px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.atts {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  max-width: 85%;
}
.att-img {
  width: 120px;
  height: 120px;
  object-fit: cover;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--card);
  cursor: zoom-in;
}
.att-file {
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 260px;
  padding: 10px 14px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  font-size: 0.9rem;
}
.att-file svg {
  width: 22px;
  height: 22px;
  color: var(--accent);
}
.att-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.msg.assistant {
  line-height: 1.75;
}
.status {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.9rem;
  color: var(--ink2);
}
.status:empty {
  display: none;
}
.status.live,
.status.done:not(:empty) {
  min-height: 28px;
  margin-bottom: 6px;
}
.dots {
  display: inline-flex;
  gap: 4px;
}
.dots i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  animation: bounce 1.2s infinite ease-in-out;
}
.dots i:nth-child(2) {
  animation-delay: 0.15s;
}
.dots i:nth-child(3) {
  animation-delay: 0.3s;
}
@keyframes bounce {
  0%,
  80%,
  100% {
    opacity: 0.3;
    transform: translateY(0);
  }
  40% {
    opacity: 1;
    transform: translateY(-3px);
  }
}

.md {
  overflow-wrap: anywhere;
}
.md > :first-child {
  margin-top: 0;
}
.md p {
  margin: 0 0 1em;
}
.md p:last-child {
  margin-bottom: 0;
}
.md h1,
.md h2,
.md h3,
.md h4 {
  line-height: 1.4;
  margin: 1.1em 0 0.5em;
}
.md h1 {
  font-size: 1.22rem;
}
.md h2 {
  font-size: 1.11rem;
}
.md h3,
.md h4 {
  font-size: 1rem;
}
.md ul,
.md ol {
  margin: 0 0 1em;
  padding-left: 1.4em;
}
.md li {
  margin: 0.25em 0;
}
.md blockquote {
  margin: 0 0 0.5em;
  padding: 12px 16px;
  background: var(--card);
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  border-radius: 12px;
}
.md blockquote p {
  margin: 0 0 0.6em;
}
.md blockquote p:last-child {
  margin: 0;
}
.md table {
  display: block;
  overflow-x: auto;
  border-collapse: collapse;
  margin: 0 0 1em;
  font-size: 0.9rem;
}
.md th,
.md td {
  border: 1px solid var(--line);
  padding: 6px 10px;
  text-align: left;
}
.md code {
  font-size: 0.9rem;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 1px 5px;
}
.md pre {
  overflow-x: auto;
  margin: 0 0 1em;
  padding: 12px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  font-size: 0.85rem;
  line-height: 1.5;
}
.md pre code {
  border: 0;
  padding: 0;
  background: none;
}
.md a {
  color: var(--accent);
}
.md hr {
  border: 0;
  border-top: 1px solid var(--line);
  margin: 1.2em 0;
}

.msg-foot {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-top: 10px;
}
.msg-foot:empty {
  display: none;
}
.act-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  padding: 0 16px;
  border-radius: 22px;
  background: var(--card);
  border: 1px solid var(--line);
  font-size: 0.9rem;
  color: var(--ink2);
}
.act-btn svg {
  width: 18px;
  height: 18px;
}
.act-btn.done {
  color: var(--accent);
  border-color: var(--accent-line);
}
.quote-copy {
  margin: 0 0 1em;
}
.provider-note {
  width: 100%;
  margin: 0;
  font-size: 0.9rem;
  color: var(--ink2);
}
.sources {
  width: 100%;
  display: flex;
  flex-direction: column;
  font-size: 0.9rem;
}
.sources-title {
  color: var(--ink2);
  font-weight: 600;
}
.sources a {
  color: var(--ink2);
  padding: 8px 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.error-card {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
  padding: 14px 16px;
  background: var(--card);
  border: 1px solid var(--accent-line);
  border-radius: 14px;
}
.error-card p {
  margin: 0;
}
.btn-retry {
  min-height: 44px;
  padding: 0 18px;
  border-radius: 22px;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}

/* ---------- 输入区 ---------- */
.composer {
  flex: none;
  padding: 6px 12px calc(env(safe-area-inset-bottom) + 10px);
  background: var(--bg);
}
.composer-inner {
  position: relative;
  max-width: 720px;
  margin: 0 auto;
}
.to-bottom {
  position: absolute;
  left: 50%;
  top: -56px;
  transform: translateX(-50%);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  padding: 0 16px;
  border-radius: 22px;
  background: var(--card);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  font-size: 0.9rem;
}
.to-bottom svg {
  width: 18px;
  height: 18px;
}
.task-tag {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  min-height: 44px;
  margin-bottom: 8px;
  padding: 0 2px 0 16px;
  border-radius: 22px;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}
.task-tag button {
  width: 44px;
  height: 44px;
  font-size: 1.3rem;
  line-height: 1;
}
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 8px;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  padding: 0 14px;
  border-radius: 22px;
  background: var(--card);
  border: 1px solid var(--control);
  font-size: 0.95rem;
}
.chip svg {
  width: 20px;
  height: 20px;
  color: var(--ink2);
}
.chip.on {
  background: var(--accent-soft);
  border-color: var(--accent-line);
}
.chip.on svg {
  color: var(--accent);
}
.tray {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 2px 0 8px;
}
.tray-item {
  position: relative;
  flex: none;
  width: 72px;
  height: 72px;
  border-radius: 12px;
  overflow: hidden;
  background: var(--card);
  border: 1px solid var(--line);
}
.tray-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.tray-item.file {
  width: auto;
  max-width: 220px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 44px 0 12px;
  font-size: 0.9rem;
}
.tray-item.file svg {
  width: 22px;
  height: 22px;
  color: var(--accent);
}
.tray-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tray-state {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 2px 4px;
  text-align: center;
  font-size: 0.75rem;
  background: rgba(43, 36, 32, 0.7);
  color: #fff;
}
.tray-state.error {
  background: var(--accent);
}
.tray-x {
  position: absolute;
  top: 0;
  right: 0;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: flex-start;
  justify-content: flex-end;
  padding: 4px;
}
.tray-x span {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: rgba(43, 36, 32, 0.72);
  color: #fff;
}
.tray-x svg {
  width: 14px;
  height: 14px;
}
.pill {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  min-height: 56px;
  padding: 5px;
  background: var(--card);
  border: 1px solid var(--input-line);
  border-radius: 28px;
  box-shadow: var(--shadow);
}
.pill:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}
.round-btn {
  flex: none;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 22px;
}
.round-btn svg {
  width: 24px;
  height: 24px;
}
.round-btn:active {
  background: var(--accent-soft);
}
.mic.on {
  background: var(--accent);
  color: var(--accent-ink);
}
#input {
  flex: 1;
  min-width: 0;
  max-height: 180px;
  padding: 9px 4px;
  border: 0;
  outline: 0;
  resize: none;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 1rem;
  line-height: 1.5;
}
#input::placeholder {
  color: var(--ink3);
}
.send {
  flex: none;
  min-width: 64px;
  height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 0 16px;
  border-radius: 22px;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
  font-size: 1rem;
}
.send:disabled {
  background: var(--line);
  color: var(--ink3);
  cursor: default;
}
.send.stop {
  min-width: 84px;
  background: var(--ink);
  color: var(--bg);
}
.send.stop svg {
  width: 16px;
  height: 16px;
}

/* ---------- 抽屉 ---------- */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: var(--shade);
}
.drawer {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 41;
  width: min(85vw, 360px);
  display: flex;
  flex-direction: column;
  padding: calc(env(safe-area-inset-top) + 10px) 10px calc(env(safe-area-inset-bottom) + 10px);
  background: var(--bg);
  transform: translateX(-102%);
  transition: transform 0.22s ease;
  visibility: hidden;
}
.drawer.open {
  transform: none;
  visibility: visible;
}
.drawer-new {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 56px;
  border-radius: 14px;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 700;
}
.drawer-new svg {
  width: 22px;
  height: 22px;
}
.drawer-list {
  flex: 1;
  overflow-y: auto;
  margin: 8px 0;
}
.group-title {
  margin: 14px 10px 4px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--ink2);
}
.empty {
  color: var(--ink2);
  text-align: center;
  margin-top: 30px;
}
.drawer-foot {
  flex: none;
  border-top: 1px solid var(--line);
  padding-top: 6px;
}
.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 56px;
  padding: 0 10px;
  cursor: pointer;
}
.switch-row input {
  width: 26px;
  height: 26px;
  accent-color: var(--accent);
}

/* ---------- 底部面板 ---------- */
.sheet-shade {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: var(--shade);
}
.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 51;
  max-width: 720px;
  max-height: 85vh;
  margin: 0 auto;
  overflow-y: auto;
  padding: 10px 16px calc(env(safe-area-inset-bottom) + 14px);
  background: var(--bg);
  border-radius: 20px 20px 0 0;
  transform: translateY(100%);
  transition: transform 0.22s ease;
}
.sheet.open {
  transform: none;
}
.sheet-grip {
  width: 40px;
  height: 5px;
  margin: 0 auto 10px;
  border-radius: 3px;
  background: var(--line);
}
.sheet h2 {
  margin: 4px 0;
  font-size: 1.11rem;
}
.sheet .sub {
  margin: 0 0 12px;
  font-size: 0.9rem;
  color: var(--ink2);
}
.options,
.sheet-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 8px 0;
}
.option {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  min-height: 64px;
  padding: 10px 14px;
  text-align: left;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
}
.option.selected {
  background: var(--accent-soft);
  border: 2px solid var(--accent);
}
.option.danger {
  color: var(--accent);
  font-weight: 600;
}
.option svg {
  width: 24px;
  height: 24px;
}
.option-icon {
  color: var(--accent);
  display: flex;
}
.radio {
  flex: none;
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  border: 2px solid var(--control);
}
.option.selected .radio {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}
.radio svg {
  width: 16px;
  height: 16px;
}
.option-text {
  display: flex;
  flex-direction: column;
}
.option-title {
  font-weight: 700;
  font-size: 1.05rem;
}
.option-desc {
  font-size: 0.9rem;
  color: var(--ink2);
}
.badge {
  margin-left: 8px;
  padding: 2px 8px;
  border-radius: 10px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 0.75rem;
  font-weight: 600;
  vertical-align: 2px;
}
.btn-plain {
  width: 100%;
  min-height: 52px;
  border-radius: 14px;
  color: var(--ink2);
  font-size: 1rem;
}
.btn-danger {
  width: 100%;
  min-height: 56px;
  border-radius: 14px;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 700;
}

/* ---------- 其他 ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 170px);
  z-index: 60;
  max-width: 86vw;
  padding: 12px 18px;
  transform: translateX(-50%);
  border-radius: 14px;
  background: var(--ink);
  color: var(--bg);
  font-size: 0.95rem;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}
.toast.show {
  opacity: 1;
}
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(0, 0, 0, 0.88);
}
.lightbox img {
  max-width: 100%;
  max-height: 100%;
  border-radius: 8px;
}

@media (min-width: 768px) {
  .cards {
    grid-template-columns: repeat(3, 1fr);
  }
}
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}
