/* 日常助手 · 样式
   结构：变量 → 基础 → 布局 → 侧栏 → 顶栏 → 消息 → 正文 → 图片 → 输入区 → 弹窗 → 状态 → 断点
   改颜色只动 :root；其余一律引用变量，不在组件里写死色值。 */

:root {
  color-scheme: dark;

  /* 底色与墨色（沿用原配色，未改动色相） */
  --page: #17191f;
  --sidebar: #111319;
  --paper: #222630;
  --soft: #252f49;
  --line: #343b4a;
  --ink: #edf1fa;
  --muted: #a9b3c8;
  --accent: #9badff;
  --action: #4159dd;
  --action-hover: #4960e8;
  --warning: #ffb6a1;

  /* 由上面派生，不新增色相。每行先给一个等价旧写法的兜底，
     不支持 color-mix 的旧内核用上一行，支持的两行都认最后一行。 */
  --line-soft: rgb(52 59 74 / .62);
  --line-soft: color-mix(in srgb, var(--line) 62%, transparent);
  --line-strong: #4c5360;
  --line-strong: color-mix(in srgb, var(--line) 88%, #ffffff 12%);
  --accent-soft: rgb(155 173 255 / .16);
  --accent-soft: color-mix(in srgb, var(--accent) 16%, transparent);
  --accent-line: #5f6b96;
  --accent-line: color-mix(in srgb, var(--accent) 42%, var(--line));
  --action-soft: rgb(65 89 221 / .26);
  --action-soft: color-mix(in srgb, var(--action) 26%, transparent);
  --warning-soft: rgb(255 182 161 / .14);
  --warning-soft: color-mix(in srgb, var(--warning) 14%, transparent);
  --code-bg: #14161c;
  --accent-ink: #10142a;
  --danger: var(--warning);

  /* 光与影：深色界面靠一层顶部细高光把面板托起来 */
  --sheen: inset 0 1px 0 rgb(255 255 255 / .05);
  --rise-1: 0 1px 2px rgb(5 7 12 / .35);
  --rise-2: 0 12px 30px rgb(5 7 12 / .42);
  --rise-3: 0 24px 60px rgb(5 7 12 / .55);
  --ring: 0 0 0 3px rgb(155 173 255 / .18);
  --ring: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);

  /* 字号与行高 */
  --fs-2xs: 11.5px;
  --fs-xs: 12.5px;
  --fs-sm: 13.5px;
  --fs-md: 14.5px;
  --fs-base: 15px;
  --fs-lg: 17px;
  --fs-xl: 19px;
  --lh-read: 1.75;

  /* 间距与圆角 */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 22px;
  --sp-6: 28px;
  --r-xs: 6px;
  --r-sm: 9px;
  --r-md: 12px;
  --r-lg: 16px;
  --r-xl: 20px;
  --r-pill: 999px;

  --ease: cubic-bezier(.32, .72, .28, 1);
  --fast: .14s var(--ease);
  --mid: .2s var(--ease);

  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Noto Sans CJK SC", "Microsoft YaHei", sans-serif;
  font-size: var(--fs-base);
  line-height: 1.6;
  color: var(--ink);
  background: var(--page);
  -webkit-text-size-adjust: 100%;
}

* { box-sizing: border-box; }
body { margin: 0; }
button, textarea, input, select { font: inherit; color: inherit; }
button {
  cursor: pointer; border: 0; border-radius: var(--r-md); padding: 9px 12px;
  background: transparent; color: inherit;
  transition: background var(--fast), color var(--fast), border-color var(--fast), transform var(--fast), box-shadow var(--fast);
}
button:hover { background: color-mix(in srgb, var(--soft) 78%, transparent); }
button:active { transform: translateY(.5px); }
button:disabled { cursor: default; opacity: .45; }
button:disabled:hover { background: transparent; transform: none; }
button:focus-visible, a:focus-visible, input:focus-visible, textarea:focus-visible,
select:focus-visible, [tabindex]:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
h1, h2, h3, h4, p { margin: 0; }
[hidden] { display: none !important; }
::selection { background: color-mix(in srgb, var(--accent) 32%, transparent); color: var(--ink); }

/* 滚动条：桌面细、悬停才明显 */
* { scrollbar-width: thin; scrollbar-color: color-mix(in srgb, var(--line) 85%, transparent) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb {
  background: color-mix(in srgb, var(--line) 85%, transparent);
  background-clip: padding-box; border: 3px solid transparent; border-radius: var(--r-pill);
}
::-webkit-scrollbar-thumb:hover { background: var(--line-strong); background-clip: padding-box; }
::-webkit-scrollbar-track { background: transparent; }

/* ---------- 布局 ---------- */
#layout {
  display: grid; grid-template-columns: 245px minmax(0, 1fr);
  height: 100vh; height: 100dvh; overflow: hidden;
}
aside {
  display: flex; flex-direction: column; gap: var(--sp-3); min-height: 0;
  padding: 22px 14px 16px;
  background: var(--sidebar);
  border-right: 1px solid var(--line-soft);
}

/* ---------- 侧栏 ---------- */
.brand {
  display: flex; align-items: center; gap: 9px; padding: 0 6px;
  font-size: var(--fs-md); font-weight: 700; letter-spacing: .01em;
}
.logo {
  display: grid; place-items: center; flex: none;
  width: 30px; height: 30px; border-radius: 9px;
  background: linear-gradient(160deg, var(--action-hover), var(--action));
  box-shadow: var(--sheen), 0 2px 8px color-mix(in srgb, var(--action) 45%, transparent);
  color: #fff; font: 600 17px/1 Georgia, "Songti SC", serif;
}
.primary {
  background: var(--action); color: #fff; font-weight: 600;
  box-shadow: var(--sheen), 0 2px 10px color-mix(in srgb, var(--action) 38%, transparent);
}
.primary:hover { background: var(--action-hover); }
.side-action { text-align: left; }

section.history { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 2px; }
#history-list {
  min-height: 0; overflow-y: auto; overscroll-behavior: contain;
  display: flex; flex-direction: column; align-items: stretch; gap: 2px;
  margin: 0 -4px; padding: 0 4px;
}
.side-label, .history h2 {
  color: var(--muted); font-size: var(--fs-2xs); font-weight: 600;
  letter-spacing: .06em; padding: 8px 8px 4px;
}
.history button { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-align: left; }
.history-toolbar, .history-batch { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.history-toolbar select {
  flex: 1; min-width: 0; height: 32px; padding: 0 26px 0 9px;
  appearance: none; -webkit-appearance: none;
  border: 1px solid var(--line-soft); border-radius: var(--r-sm);
  background-color: color-mix(in srgb, var(--paper) 45%, transparent);
  background-image:
    linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 15px) 13px, calc(100% - 10px) 13px;
  background-size: 5px 5px, 5px 5px; background-repeat: no-repeat;
  color: var(--ink); font-size: var(--fs-sm); font-weight: 500;
  transition: border-color var(--fast), background-color var(--fast);
}
.history-toolbar select:hover { border-color: var(--line-strong); }
.history-toolbar button, .history-batch button {
  font-size: var(--fs-xs); padding: 6px 9px; color: var(--muted);
}
.history-toolbar button:hover, .history-batch button:hover { color: var(--ink); }
.history-batch .danger { color: var(--warning); }
.history-batch .danger:hover { color: var(--warning); background: var(--warning-soft); }
.history-toolbar button[aria-pressed="true"] {
  color: var(--accent); background: var(--accent-soft);
}
.history-row { display: flex; align-items: center; gap: 2px; min-width: 0; }
.history-row .history-title { flex: 1; min-width: 0; }
.history-title {
  padding: 8px 9px; border-radius: var(--r-sm);
  font-size: var(--fs-sm); font-weight: 450; color: color-mix(in srgb, var(--ink) 88%, var(--muted));
}
.history-title:hover { color: var(--ink); }
.history-row .history-more {
  flex: none; padding: 6px 7px; font-size: var(--fs-sm); color: var(--muted);
  opacity: 0; transition: opacity var(--fast), color var(--fast), background var(--fast);
}
.history-row:hover .history-more, .history-more:focus-visible { opacity: 1; }
.history-row input[type="checkbox"] { flex: none; width: 16px; height: 16px; margin: 0 4px 0 6px; }
#history-feedback { color: var(--warning); font-size: var(--fs-xs); padding: 2px 8px; }
#history-feedback:empty { display: none; }
.history-actions { display: grid; gap: 2px; }
.history-actions button { text-align: left; padding: 9px 10px; font-size: var(--fs-md); border-radius: var(--r-sm); }
.history-actions button:hover { background: color-mix(in srgb, var(--soft) 70%, transparent); }
.danger { color: var(--warning); }
.danger:hover { background: var(--warning-soft); }
.history .active {
  background: color-mix(in srgb, var(--soft) 82%, transparent);
  box-shadow: inset 2px 0 0 var(--accent);
  color: var(--ink); font-weight: 600;
}
.history-days { flex: none; padding-right: 6px; font-size: var(--fs-2xs); color: var(--muted); }
.side-foot {
  display: grid; gap: 1px;
  border-top: 1px solid var(--line-soft); padding-top: 8px;
}
.side-foot button, .side-foot a {
  color: color-mix(in srgb, var(--ink) 76%, var(--muted));
  font-size: var(--fs-sm); font-weight: 450; text-align: left;
  padding: 8px 10px; border-radius: var(--r-sm); text-decoration: none;
}
.side-foot button:hover, .side-foot a:hover {
  color: var(--ink); background: color-mix(in srgb, var(--soft) 55%, transparent);
}
.side-toggle {
  display: flex; align-items: center; gap: 7px; cursor: pointer;
  padding: 7px 10px; border-radius: var(--r-sm);
  color: var(--muted); font-size: var(--fs-sm);
}
.side-toggle:hover { color: var(--ink); }
.side-toggle input { width: 15px; height: 15px; }
.build-tag {
  color: color-mix(in srgb, var(--muted) 82%, var(--sidebar));
  font-size: var(--fs-2xs); padding: 4px 10px 2px; letter-spacing: .02em;
}

/* ---------- 主区顶栏 ---------- */
main { min-width: 0; min-height: 0; display: grid; grid-template-rows: auto minmax(0, 1fr) auto; }
header {
  display: flex; align-items: center; gap: 10px; min-width: 0;
  padding: max(13px, env(safe-area-inset-top)) max(26px, calc((100% - 784px) / 2 + 26px)) 11px;
  border-bottom: 1px solid var(--line-soft);
}
header h1 {
  font-size: var(--fs-lg); font-weight: 650; letter-spacing: -.004em;
  overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
  color: color-mix(in srgb, var(--ink) 94%, var(--muted));
}
#menu { display: none; }

/* ---------- 消息区 ---------- */
#feed { min-height: 0; overflow-y: auto; overscroll-behavior: contain; }
#messages, #welcome, .compose { width: min(100%, 784px); margin: 0 auto; }
#messages {
  display: grid; align-content: start; gap: 26px;
  padding: 26px 26px 20px;
}
#messages:empty { display: none; }

/* 欢迎页 */
#welcome { padding: clamp(38px, 10vh, 104px) 26px 34px; }
#welcome h2 {
  font-size: clamp(26px, 4.6vw, 38px); font-weight: 650;
  line-height: 1.24; letter-spacing: -.012em;
  color: var(--ink);
}
#welcome p {
  margin-top: 11px; max-width: 46ch;
  color: var(--muted); font-size: var(--fs-base); line-height: 1.78;
}
.examples { display: grid; justify-items: start; gap: 8px; margin-top: 26px; }
.examples button {
  border: 1px solid var(--line-soft); border-radius: var(--r-md);
  background: color-mix(in srgb, var(--paper) 72%, transparent);
  padding: 11px 15px; font-size: var(--fs-md); color: color-mix(in srgb, var(--ink) 88%, var(--muted));
  box-shadow: var(--sheen);
}
.examples button:hover {
  background: color-mix(in srgb, var(--soft) 82%, transparent);
  border-color: var(--line-strong); color: var(--ink);
}

/* 消息 */
.message { min-width: 0; }
.message.user {
  justify-self: end; max-width: min(86%, 620px);
  padding: 10px 15px 11px;
  background: color-mix(in srgb, var(--soft) 92%, transparent);
  border-radius: 18px 18px 5px 18px;
  box-shadow: var(--sheen), var(--rise-1);
}
.message.assistant { justify-self: stretch; padding: 0 2px; }
.message h3 {
  margin-bottom: 5px; font-size: var(--fs-2xs); font-weight: 600;
  letter-spacing: .08em; color: var(--muted);
}
.message.user h3 { margin-bottom: 3px; color: color-mix(in srgb, var(--muted) 88%, var(--soft)); }
.message-head h3, .message.user h3 { font-size: var(--fs-xs); }
.message-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; margin-bottom: 6px;
}
.message-head h3 { margin-bottom: 0; }
.message.interrupted .body { opacity: .62; }
.message-badge {
  margin-left: 7px; padding: 1px 7px; border-radius: var(--r-pill);
  font-size: var(--fs-2xs); font-weight: 500; letter-spacing: 0;
  color: var(--warning); background: var(--warning-soft);
  border: 1px solid color-mix(in srgb, var(--warning) 38%, transparent);
}
.copy-answer {
  padding: 3px 7px; border-radius: var(--r-xs);
  font-size: var(--fs-2xs); color: var(--muted); letter-spacing: .02em;
}
.copy-answer:hover { background: color-mix(in srgb, var(--soft) 72%, transparent); color: var(--ink); }
.message-image {
  display: block; max-width: min(100%, 360px); max-height: 310px; object-fit: contain;
  margin-top: 9px; border: 1px solid var(--line-soft); border-radius: var(--r-md);
  background: var(--page);
}
.message-document {
  display: inline-flex; align-items: center; gap: 6px; margin-top: 8px;
  padding: 5px 9px; border-radius: var(--r-sm);
  border: 1px solid var(--line-soft); background: color-mix(in srgb, var(--page) 55%, transparent);
  color: var(--accent); font-size: var(--fs-xs); overflow-wrap: anywhere;
}

/* ---------- 正文（Markdown） ---------- */
.body { font-size: var(--fs-base); line-height: var(--lh-read); overflow-wrap: anywhere; }
.message.user .body { white-space: pre-wrap; }
.body > :first-child { margin-top: 0; }
.body > :last-child { margin-bottom: 0; }
.body p { margin: 0 0 .72em; }
.body > p:last-child { margin-bottom: 0; }
.body h2, .body h3, .body h4, .body h5, .body h6 {
  margin: 1.05em 0 .42em; line-height: 1.42; font-weight: 650; letter-spacing: -.004em;
}
.body h2 { font-size: 18.5px; }
.body h3 { font-size: 16.5px; }
.body h4 { font-size: 15.5px; }
.body h5, .body h6 { font-size: var(--fs-base); }
.body ul, .body ol { margin: .38em 0 .74em; padding-left: 1.35em; }
.body li { margin: .2em 0; }
.body li::marker { color: color-mix(in srgb, var(--muted) 82%, var(--page)); }
.body li > ul, .body li > ol { margin: .18em 0 .24em; }
.body strong { font-weight: 650; color: #fff; }
.body blockquote {
  margin: .7em 0; padding: 9px 13px;
  border-left: 2px solid var(--accent-line); border-radius: 0 var(--r-sm) var(--r-sm) 0;
  background: color-mix(in srgb, var(--paper) 55%, transparent);
  color: color-mix(in srgb, var(--ink) 78%, var(--muted));
}
.body blockquote > :last-child { margin-bottom: 0; }
.body code {
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  font-size: .88em; letter-spacing: 0;
  background: var(--code-bg); border: 1px solid var(--line-soft);
  border-radius: 5px; padding: 1px 5px;
}
.body pre {
  margin: .72em 0; padding: 11px 13px;
  background: var(--code-bg); border: 1px solid var(--line-soft);
  border-radius: var(--r-md); overflow-x: auto; line-height: 1.62;
}
.body pre code { background: none; border: 0; padding: 0; font-size: var(--fs-xs); }
.body a {
  color: var(--accent); text-decoration: underline;
  text-decoration-color: color-mix(in srgb, var(--accent) 42%, transparent);
  text-decoration-thickness: 1px; text-underline-offset: 3px;
  transition: text-decoration-color var(--fast);
}
.body a:hover { text-decoration-color: var(--accent); }
.body hr { border: 0; border-top: 1px solid var(--line-soft); margin: 1.1em 0; }

/* 表格：只留横线，数字对齐 */
.body .md-table {
  margin: .72em 0; overflow-x: auto;
  border: 1px solid var(--line-soft); border-radius: var(--r-md);
  background: color-mix(in srgb, var(--paper) 55%, transparent);
}
.body table {
  width: 100%; border-collapse: collapse; font-size: var(--fs-sm);
  font-variant-numeric: tabular-nums; line-height: 1.55;
}
.body th, .body td {
  border: 0; border-bottom: 1px solid var(--line-soft);
  padding: 8px 11px; text-align: left; vertical-align: top;
}
.body th {
  background: color-mix(in srgb, var(--soft) 60%, transparent);
  color: var(--ink); font-weight: 600; white-space: nowrap;
  font-size: var(--fs-xs); letter-spacing: .02em;
}
.body tr:last-child td { border-bottom: 0; }
.body tbody tr:hover td { background: color-mix(in srgb, var(--soft) 26%, transparent); }

/* ---------- 图片滑块 ---------- */
.gallery { margin-top: 14px; }
.gallery-track {
  display: flex; gap: 10px; overflow-x: auto; scroll-snap-type: x mandatory;
  scroll-behavior: smooth; padding: 2px 2px 4px; scrollbar-width: none;
}
.gallery-track::-webkit-scrollbar { display: none; }
.shot { flex: 0 0 min(72%, 300px); margin: 0; min-width: 0; scroll-snap-align: start; }
.shot-open {
  position: relative; display: block; width: 100%; padding: 0; cursor: zoom-in;
  border: 1px solid var(--line-soft); border-radius: var(--r-lg);
  overflow: hidden; background: var(--soft);
  transition: border-color var(--mid), transform var(--mid), box-shadow var(--mid);
}
.shot-open img {
  display: block; width: 100%; aspect-ratio: 4 / 3;
  object-fit: contain; object-position: center; background: var(--code-bg);
}
.shot-open:hover { border-color: var(--accent-line); transform: translateY(-1px); box-shadow: var(--rise-2); }
.shot-open:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.shot figcaption {
  display: flex; align-items: baseline; gap: 6px; min-width: 0;
  margin-top: 6px; font-size: var(--fs-2xs); color: var(--muted);
}
.shot-title { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.shot-host { flex: none; color: color-mix(in srgb, var(--muted) 76%, var(--page)); }
.gallery-bar { display: flex; align-items: center; gap: 7px; margin-top: 8px; }
.gallery-dots { display: flex; gap: 5px; }
.gallery-dots button {
  width: 6px; height: 6px; padding: 0; border-radius: var(--r-pill);
  background: color-mix(in srgb, var(--muted) 42%, transparent);
  transition: width var(--mid), background var(--mid);
}
.gallery-dots button:hover { background: var(--muted); }
.gallery-dots button[aria-current="true"] { width: 18px; background: var(--accent); }
.gallery-move {
  width: 26px; height: 26px; padding: 0; display: grid; place-items: center;
  font-size: 14px; line-height: 1; color: var(--muted);
  border: 1px solid var(--line-soft); border-radius: var(--r-xs); background: transparent;
}
.gallery-move:hover { color: var(--ink); border-color: var(--line-strong); }
.gallery-move:disabled { opacity: .32; }
.gallery-count {
  margin-left: auto; font-size: var(--fs-2xs); color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* ---------- 来源、地图 ---------- */
.references { margin-top: 14px; padding-left: 12px; border-left: 2px solid var(--line-soft); }
.references h4 {
  margin: 0 0 5px; font-size: var(--fs-2xs); font-weight: 600;
  letter-spacing: .08em; color: var(--muted);
}
.references ol { margin: 0; padding-left: 17px; font-size: var(--fs-xs); line-height: 1.72; overflow-wrap: anywhere; }
.references a { color: var(--accent); text-decoration: none; }
.references a:hover { text-decoration: underline; text-underline-offset: 3px; }
.map-link {
  display: inline-flex; align-items: center; gap: 6px; margin-top: 12px;
  padding: 7px 12px; border-radius: var(--r-sm);
  border: 1px solid var(--line-soft); background: color-mix(in srgb, var(--soft) 62%, transparent);
  color: var(--accent); font-size: var(--fs-xs); text-decoration: none;
  transition: border-color var(--fast), background var(--fast);
}
.map-link:hover { border-color: var(--accent-line); background: var(--accent-soft); }

/* ---------- 输入区 ---------- */
.compose {
  position: relative; align-self: end;
  padding: 14px 26px max(18px, env(safe-area-inset-bottom));
}
/* 内容滚到输入区上方时淡出，避免最后一行被生硬切断 */
.compose::before {
  content: ""; position: absolute; left: 0; right: 0; top: -20px; height: 20px;
  pointer-events: none;
  background: linear-gradient(to bottom, rgb(23 25 31 / 0), var(--page) 92%);
}
.compose-feedback { display: flex; align-items: center; flex-wrap: wrap; gap: 2px 6px; min-height: 0; }
.compose-feedback p, #status {
  color: var(--muted); font-size: var(--fs-xs); line-height: 1.5; padding: 0 0 5px 2px;
}
#status:empty { padding: 0; }
#status.tool-result { color: var(--accent); }
#retry, #retry-voice {
  margin-bottom: 5px; padding: 3px 7px; border-radius: var(--r-xs);
  color: var(--accent); font-size: var(--fs-xs);
}
#retry:hover, #retry-voice:hover { background: var(--accent-soft); }

#reminder-status {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  margin: 0 0 5px; padding: 6px 2px 6px 10px;
  background: color-mix(in srgb, var(--warning) 8%, transparent);
  border-left: 2px solid color-mix(in srgb, var(--warning) 80%, transparent);
  border-radius: 0 var(--r-sm) var(--r-sm) 0;
  font-size: var(--fs-xs); color: var(--ink);
}
#reminder-text { min-width: 0; overflow-wrap: anywhere; }
#complete-reminder {
  flex: none; white-space: nowrap; padding: 5px 9px; border-radius: var(--r-xs);
  color: var(--accent); font-size: var(--fs-xs); font-weight: 550;
}
#complete-reminder:hover { background: var(--accent-soft); }

#composer {
  display: grid; gap: 4px; padding: 9px 10px 8px;
  background: linear-gradient(180deg, color-mix(in srgb, var(--paper) 97%, #ffffff 1.5%), var(--paper));
  border: 1px solid var(--line-soft); border-radius: 22px;
  box-shadow: var(--rise-2), var(--sheen);
  transition: border-color var(--mid), box-shadow var(--mid);
}
#composer:focus-within {
  border-color: var(--accent-line);
  box-shadow: var(--rise-2), var(--ring);
}
.composer-input { display: flex; align-items: flex-end; gap: 6px; min-width: 0; }
.composer-actions, .composer-options, .composer-icons { display: flex; align-items: center; min-width: 0; }
.composer-actions { justify-content: space-between; gap: 8px; padding: 0 2px; }
.composer-options { gap: 2px; }
.composer-icons { gap: 2px; }
.composer-option {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 7px 10px; border-radius: var(--r-pill);
  color: var(--muted); font-size: var(--fs-xs); font-weight: 500;
  line-height: 1.25; white-space: nowrap;
}
.composer-option:hover { color: var(--ink); }
.composer-option[aria-pressed="true"] {
  color: var(--accent); background: var(--accent-soft);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 26%, transparent);
}
.composer-option[aria-pressed="true"]:hover { background: color-mix(in srgb, var(--accent) 22%, transparent); }
.composer-option svg, .composer-icon svg {
  display: block; flex: none; width: 16px; height: 16px;
  fill: none; stroke: currentColor; stroke-width: 1.7;
  stroke-linecap: round; stroke-linejoin: round;
}
.composer-icon {
  width: 40px; height: 40px; flex: none; padding: 0;
  display: grid; place-items: center; border-radius: var(--r-md); color: var(--muted);
}
.composer-icon:hover { color: var(--ink); }
.composer-icon svg { width: 21px; height: 21px; }
#send {
  width: 38px; height: 38px; margin: 0 2px 3px 0; color: #fff;
  border-radius: 11px;
}
#send svg { width: 19px; height: 19px; }
#send:disabled { background: color-mix(in srgb, var(--action) 55%, var(--paper)); opacity: .7; }
#attach-image[aria-expanded="true"] {
  color: var(--accent); background: var(--accent-soft); box-shadow: none;
}

#prompt, .composer-input textarea {
  width: 100%; min-width: 0; min-height: 56px; max-height: 40dvh;
  resize: none; padding: 9px 4px 7px;
  background: transparent; border: 0; border-radius: var(--r-md);
  color: var(--ink); font-size: var(--fs-base); line-height: 1.6;
}
textarea { resize: none; }
#prompt::placeholder, textarea::placeholder, input::placeholder { color: var(--muted); }

.composer-option[disabled], .composer-icon[disabled] { opacity: .45; }

#composer[data-input-mode="voice"] .composer-actions {
  border-top: 1px solid var(--line-soft); padding-top: 5px; margin-top: 4px;
}
#composer[data-input-mode="voice"] #send {
  width: 44px; height: 44px; align-self: center; margin: 0 2px;
}
#composer[data-input-mode="voice"] #record-voice { flex: 1 1 auto; min-width: 0; }
#composer[data-input-mode="text"] .keyboard-icon,
#composer[data-input-mode="voice"] .voice-icon,
#send:not([data-stopping]) .stop-icon,
#send[data-stopping] .send-icon { display: none; }
#attach-image[aria-expanded="true"] .plus-icon,
#attach-image[aria-expanded="false"] .close-icon { display: none; }

#record-voice {
  width: 100%; min-height: 56px; border-radius: var(--r-md);
  background: color-mix(in srgb, var(--soft) 62%, transparent);
  border: 1px solid var(--line-soft);
  font-weight: 600; touch-action: none;
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}
#record-voice:hover { background: color-mix(in srgb, var(--soft) 82%, transparent); }
#record-voice[aria-pressed="true"]:not(.cancel-voice) {
  background: var(--accent-soft); color: var(--accent); border-color: var(--accent-line);
}
#record-voice.cancel-voice { color: var(--warning); background: var(--warning-soft); border-color: color-mix(in srgb, var(--warning) 40%, transparent); }

/* 附件预览与面板 */
#attachment-preview {
  display: flex; align-items: center; gap: 9px;
  width: fit-content; max-width: 100%; min-width: 0; margin: 2px 2px 4px;
  padding: 5px 6px; background: var(--page); border: 1px solid var(--line-soft);
  border-radius: var(--r-md);
}
#attachment-preview img { display: block; width: 40px; height: 40px; object-fit: cover; border-radius: 6px; }
#attachment-name {
  min-width: 0; max-width: 32ch; overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap; font-size: var(--fs-xs); color: color-mix(in srgb, var(--ink) 86%, var(--muted));
}
#remove-attachment { flex: none; padding: 4px 7px; font-size: var(--fs-2xs); color: var(--muted); border-radius: var(--r-xs); }
#remove-attachment:hover { color: var(--warning); background: var(--warning-soft); }

.attachment-panel { display: grid; gap: 10px; padding: 12px 2px 2px; }
.attachment-panel h2 {
  color: var(--muted); font-size: var(--fs-2xs); font-weight: 600; letter-spacing: .08em;
}
.recent-images {
  display: flex; gap: 8px; overflow-x: auto; overscroll-behavior-x: contain;
  scrollbar-width: thin; padding: 2px 1px 4px;
}
.recent-image {
  position: relative; flex: 0 0 76px; height: 68px; padding: 0; overflow: hidden;
  background: var(--paper); border: 1px solid var(--line-soft); border-radius: var(--r-sm);
}
.recent-image img { width: 100%; height: 100%; object-fit: cover; display: block; }
.recent-image::after {
  content: ""; position: absolute; top: 5px; right: 5px;
  width: 12px; height: 12px; border-radius: 50%;
  border: 1px solid rgb(255 255 255 / .85); background: color-mix(in srgb, var(--page) 70%, transparent);
}
.recent-image[aria-pressed="true"] { border-color: var(--accent-line); }
.recent-image[aria-pressed="true"]::after { background: var(--action); border-color: #fff; }
#recent-empty { color: var(--muted); font-size: var(--fs-xs); }
.attachment-actions { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.attachment-actions button {
  display: grid; justify-items: center; gap: 6px; min-height: 66px;
  padding: 10px 6px; border-radius: var(--r-md);
  background: color-mix(in srgb, var(--page) 62%, transparent);
  border: 1px solid var(--line-soft);
  font-size: var(--fs-sm); color: color-mix(in srgb, var(--ink) 88%, var(--muted));
}
.attachment-actions button:hover { border-color: var(--accent-line); color: var(--ink); background: color-mix(in srgb, var(--soft) 55%, transparent); }
.attachment-actions svg {
  width: 22px; height: 22px; fill: none; stroke: var(--accent); stroke-width: 1.6;
  stroke-linecap: round; stroke-linejoin: round;
}

/* ---------- 弹窗 ---------- */
dialog {
  width: min(calc(100% - 28px), 478px); max-height: 86dvh;
  padding: 20px; color: var(--ink);
  background: var(--paper); border: 1px solid var(--line-soft); border-radius: var(--r-xl);
  box-shadow: var(--rise-3), var(--sheen);
  overflow-y: auto; overscroll-behavior: contain;
}
dialog::backdrop { background: rgb(7 10 18 / .72); backdrop-filter: blur(3px); }
.dialog-title { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.dialog-title h2 {
  min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-size: var(--fs-lg); font-weight: 650; letter-spacing: .01em;
}
.dialog-title button { flex: none; padding: 6px 9px; font-size: var(--fs-xs); color: var(--muted); border-radius: var(--r-sm); }
.dialog-title button:hover { color: var(--ink); }
dialog p { margin-bottom: 12px; color: var(--muted); font-size: var(--fs-sm); line-height: 1.68; }
dialog form { display: grid; gap: 9px; }
input[type="text"], input[type="password"] {
  width: 100%; height: 42px; padding: 0 11px;
  background: var(--page); border: 1px solid var(--line-soft);
  border-radius: var(--r-sm); color: var(--ink); font-size: var(--fs-md);
  transition: border-color var(--fast), box-shadow var(--fast);
}
input[type="text"]:focus, input[type="password"]:focus {
  border-color: var(--accent-line); box-shadow: var(--ring); outline: none;
}
input[type="checkbox"] { accent-color: var(--accent); vertical-align: middle; margin: 0 3px 0 0; }
dialog form .primary { width: 100%; min-height: 40px; }
#memory-list { display: grid; gap: 6px; margin: 14px 0 0; padding: 0; list-style: none; }
#memory-list li {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 9px 11px; border-radius: var(--r-sm);
  background: color-mix(in srgb, var(--page) 70%, transparent);
  font-size: var(--fs-sm); line-height: 1.55; overflow-wrap: anywhere;
}
#memory-list button { flex: none; padding: 4px 7px; font-size: var(--fs-2xs); color: var(--muted); border-radius: var(--r-xs); }
#memory-list button:hover { color: var(--warning); background: var(--warning-soft); }
#memory-feedback, #login-feedback { margin: 8px 0 0; color: var(--warning); font-size: var(--fs-xs); }

/* 记录与提醒 */
#activity-dialog { width: min(calc(100% - 28px), 570px); }
.activity-section + .activity-section { margin-top: 18px; }
.activity-section h3 {
  margin-bottom: 8px; font-size: var(--fs-2xs); font-weight: 600;
  letter-spacing: .08em; color: var(--muted);
}
.activity-list { display: grid; gap: 6px; margin: 0; padding: 0; list-style: none; }
.activity-list li {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center;
  gap: 2px 10px; padding: 9px 11px; border-radius: var(--r-sm);
  background: color-mix(in srgb, var(--page) 70%, transparent);
}
.activity-list p { margin: 0; color: var(--ink); font-size: var(--fs-sm); white-space: pre-wrap; overflow-wrap: anywhere; }
.activity-list small { color: var(--muted); font-size: var(--fs-2xs); grid-column: 1; }
.activity-list button {
  grid-row: 1 / span 2; grid-column: 2; padding: 5px 8px;
  font-size: var(--fs-2xs); color: var(--accent); border-radius: var(--r-xs);
}
.activity-list button:hover { background: var(--accent-soft); }
#activity-feedback { color: var(--warning); font-size: var(--fs-xs); }
.notify-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  margin-top: 12px; padding: 10px 12px; border-radius: var(--r-md);
  background: color-mix(in srgb, var(--page) 70%, transparent);
}
.notify-row p { margin: 0; color: var(--muted); font-size: var(--fs-xs); line-height: 1.6; }
.notify-row button {
  flex: none; padding: 7px 10px; border-radius: var(--r-sm);
  border: 1px solid var(--line-soft); color: var(--accent); font-size: var(--fs-xs);
}
.notify-row button:hover { border-color: var(--accent-line); background: var(--accent-soft); }

/* 大图 */
#photo-dialog {
  width: min(calc(100% - 20px), 900px); max-height: 92dvh; padding: 10px;
  border-radius: var(--r-lg);
}
#photo-dialog[open] { display: grid; gap: 8px; }
#photo-figure { display: grid; gap: 8px; min-height: 0; margin: 0; }
#photo-image {
  max-width: 100%; max-height: 70dvh; margin: 0 auto;
  object-fit: contain; border-radius: var(--r-md); background: var(--page);
}
#photo-caption {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 10px;
  padding: 0 3px 2px; font-size: var(--fs-xs); color: var(--muted);
}
#photo-name {
  grid-column: 1 / -1; min-width: 0; overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap; color: var(--ink); font-size: var(--fs-sm);
}
#photo-source { justify-self: start; color: var(--accent); white-space: nowrap; text-decoration: none; }
#photo-source:hover { text-decoration: underline; text-underline-offset: 3px; }
#photo-count { justify-self: end; white-space: nowrap; font-variant-numeric: tabular-nums; }
.photo-bar { display: flex; justify-content: center; gap: 8px; }
.photo-bar button {
  padding: 8px 15px; font-size: var(--fs-sm); border-radius: var(--r-sm);
  border: 1px solid var(--line-soft); background: color-mix(in srgb, var(--page) 60%, transparent);
  color: var(--ink);
}
.photo-bar button:hover { border-color: var(--line-strong); background: var(--soft); }
#photo-close { border-color: var(--accent-line); color: var(--accent); }
#photo-close:hover { background: var(--accent-soft); }

#overlay { display: none; }

/* ---------- 断点 ---------- */
@media (max-width: 650px) {
  #layout { grid-template-columns: minmax(0, 1fr); }
  aside {
    position: fixed; top: 0; bottom: 0; z-index: 3;
    width: min(288px, 84vw);
    padding-top: max(22px, env(safe-area-inset-top));
    padding-bottom: max(16px, env(safe-area-inset-bottom));
    border-right: 0; border-radius: 0 18px 18px 0;
    box-shadow: var(--rise-3);
    transform: translateX(-100%); transition: transform .2s var(--ease);
  }
  aside.open { transform: none; }
  #overlay.visible {
    display: block; position: fixed; inset: 0; z-index: 2;
    background: rgb(8 10 18 / .62); border-radius: 0;
    backdrop-filter: blur(2px);
  }
  #menu { display: inline-grid; place-items: center; width: 40px; height: 40px; padding: 0; margin-left: -6px; }
  header { padding-left: 10px; padding-right: 14px; gap: 6px; }
  header h1 { font-size: var(--fs-base); }
  #messages, #welcome { padding-left: 16px; padding-right: 16px; }
  #messages { gap: 22px; padding-top: 18px; }
  #welcome { padding-top: clamp(28px, 8vh, 64px); }
  .compose { padding: 10px 12px max(12px, env(safe-area-inset-bottom)); }
  #prompt, .composer-input textarea { min-height: 46px; }
  .composer-icon { width: 42px; height: 42px; }
  #send { width: 40px; height: 40px; margin-bottom: 2px; }
  /* iOS 聚焦输入框会放大整页：手机上一律 16px */
  #prompt, .composer-input textarea, input[type="text"], input[type="password"],
  .history-toolbar select, .activity-list input, #memory-text { font-size: 16px; }
  .history-title { padding: 10px 9px; }
  .message.user { max-width: 90%; }
  .copy-answer { padding: 6px 8px; }
  .composer-option { min-height: 34px; }
  #remove-attachment, .attachment-actions button { min-height: 36px; }
  .shot { flex-basis: min(80%, 280px); }
  /* 窄屏不要把表格挤成一列一列的字，保留横滚 */
  .body table { min-width: 440px; }
  dialog { padding: 18px; }
}

@media (max-width: 380px) {
  #composer { padding-inline: 7px; }
  .composer-option { padding: 0 9px; min-height: 34px; gap: 5px; }
  .composer-actions { gap: 4px; }
  .composer-options, .composer-icons { gap: 0; }
  .gallery .shot { flex-basis: 84%; }
}

@media (hover: none) {
  .history-row .history-more { opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
