:root {
  --bg: #faf6f0; --surface: #ffffff; --ink: #2b2420; --muted: #8a7f76; --line: #ebe3d9;
  --accent: #c8643b; --accent-ink: #ffffff; --accent-soft: #f6e3d8;
  --remind: #fff4d6; --remind-line: #f0d98c; --danger: #b3402a; --ok: #3f7d4e;
  --fs: 17px; --radius: 16px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1c1917; --surface: #262220; --ink: #f1ebe5; --muted: #a39a91; --line: #3a3430;
    --accent: #e07a4f; --accent-ink: #1c1917; --accent-soft: #3d2b22;
    --remind: #3a3220; --remind-line: #6b5a2c; --danger: #e5735c; --ok: #7cc18c;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #1c1917; --surface: #262220; --ink: #f1ebe5; --muted: #a39a91; --line: #3a3430;
  --accent: #e07a4f; --accent-ink: #1c1917; --accent-soft: #3d2b22;
  --remind: #3a3220; --remind-line: #6b5a2c; --danger: #e5735c; --ok: #7cc18c;
  color-scheme: dark;
}
:root[data-size="l"] { --fs: 20px; }
:root[data-size="xl"] { --fs: 23px; }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--ink);
  font: var(--fs)/1.55 -apple-system, BlinkMacSystemFont, "PingFang SC", "Noto Sans SC", "Microsoft YaHei", sans-serif;
  overscroll-behavior: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

#app { display: flex; flex-direction: column; height: 100dvh; max-width: 720px; margin: 0 auto; }

header {
  display: flex; align-items: center; gap: 12px;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  border-bottom: 1px solid var(--line); background: var(--bg);
}
header h1 { margin: 0; font-size: 1.15em; font-weight: 700; flex: 1; }
header .who { color: var(--muted); font-size: .85em; }

main { flex: 1; min-height: 0; position: relative; }
.tab { position: absolute; inset: 0; overflow-y: auto; padding: 16px; display: none; }
.tab.active { display: block; }
#tab-chat.active { display: flex; flex-direction: column; padding: 0; }

nav#tabs {
  display: grid; grid-template-columns: repeat(5, 1fr);
  border-top: 1px solid var(--line); background: var(--surface);
  padding-bottom: env(safe-area-inset-bottom);
}
nav#tabs button {
  border: 0; background: none; padding: 8px 0 6px; display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: .72em; color: var(--muted); min-height: 56px;
}
nav#tabs button .ic { font-size: 1.6em; line-height: 1; filter: grayscale(.6); opacity: .8; }
nav#tabs button.active { color: var(--accent); font-weight: 600; }
nav#tabs button.active .ic { filter: none; opacity: 1; }

/* ── 聊天 ── */
#msgs { flex: 1; overflow-y: auto; padding: 16px 12px 8px; display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 86%; padding: 10px 14px; border-radius: var(--radius); white-space: pre-wrap; word-break: break-word; }
.msg.user { align-self: flex-end; background: var(--accent); color: var(--accent-ink); border-bottom-right-radius: 6px; }
.msg.bot { align-self: flex-start; background: var(--surface); border: 1px solid var(--line); border-bottom-left-radius: 6px; }
.msg.bot a { color: var(--accent); }
.msg.err { align-self: center; background: none; color: var(--danger); font-size: .9em; text-align: center; }
.msg.remind { align-self: center; background: var(--remind); border: 1px solid var(--remind-line); text-align: center; max-width: 92%; }
.msg.remind .t { font-size: .78em; color: var(--muted); display: block; }
.msg .imgs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 6px; }
.msg .imgs img { width: 84px; height: 84px; object-fit: cover; border-radius: 10px; }
.msg .imgs .ph { font-size: .85em; opacity: .85; }
.msg .tools { font-size: .8em; color: var(--muted); margin-bottom: 4px; }
.msg .foot { display: flex; gap: 8px; margin-top: 6px; }
.msg .foot button { border: 1px solid var(--line); background: var(--bg); border-radius: 999px; padding: 2px 12px; font-size: .8em; color: var(--muted); }
.divider { align-self: center; color: var(--muted); font-size: .8em; padding: 4px 0; }
.typing::after { content: "▍"; animation: blink 1s steps(2) infinite; color: var(--accent); }
@keyframes blink { 50% { opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .typing::after { animation: none; } }

.chips { display: flex; gap: 8px; overflow-x: auto; padding: 0 12px 8px; scrollbar-width: none; }
.chips button { flex: none; border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 6px 14px; font-size: .85em; }

#composer { border-top: 1px solid var(--line); background: var(--bg); padding: 8px 10px; }
#pending { display: flex; gap: 6px; padding-bottom: 6px; flex-wrap: wrap; }
#pending .p { position: relative; }
#pending img { width: 64px; height: 64px; object-fit: cover; border-radius: 10px; display: block; }
#pending .x { position: absolute; top: -6px; right: -6px; width: 24px; height: 24px; border-radius: 50%; border: 0; background: var(--ink); color: var(--bg); font-size: 14px; line-height: 24px; padding: 0; }
.row { display: flex; gap: 8px; align-items: flex-end; }
#text {
  flex: 1; resize: none; border: 1px solid var(--line); border-radius: 22px; background: var(--surface);
  padding: 10px 16px; max-height: 40vh; min-height: 48px; outline: none;
}
#text:focus { border-color: var(--accent); }
.iconbtn { flex: none; width: 48px; height: 48px; border-radius: 50%; border: 1px solid var(--line); background: var(--surface); font-size: 1.3em; display: grid; place-items: center; padding: 0; }
.sendbtn { flex: none; height: 48px; padding: 0 18px; border-radius: 24px; border: 0; background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.sendbtn:disabled { opacity: .5; }

/* ── 通用卡片 / 表单 ── */
h2 { font-size: 1.05em; margin: 22px 0 10px; display: flex; align-items: center; gap: 8px; }
h2:first-child { margin-top: 0; }
#admin h2:first-child { margin-top: 28px; }
h2 .sp { flex: 1; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 4px 0; }
.item { display: flex; align-items: center; gap: 12px; padding: 10px 14px; border-top: 1px solid var(--line); min-height: 52px; }
.item:first-child { border-top: 0; }
.item .main { flex: 1; min-width: 0; }
.item .sub { color: var(--muted); font-size: .8em; }
.item.done .main { text-decoration: line-through; color: var(--muted); }
.item .del { border: 0; background: none; color: var(--muted); font-size: 1.1em; padding: 6px; }
.check { width: 30px; height: 30px; flex: none; border-radius: 9px; border: 2px solid var(--line); background: var(--bg); display: grid; place-items: center; font-size: .9em; padding: 0; color: transparent; }
.item.done .check { background: var(--ok); border-color: var(--ok); color: #fff; }
.empty { color: var(--muted); padding: 14px; text-align: center; font-size: .9em; }
.daylabel { color: var(--muted); font-size: .8em; padding: 12px 14px 2px; font-weight: 600; }
.daylabel.today { color: var(--accent); }
.when { font-variant-numeric: tabular-nums; color: var(--accent); font-weight: 600; min-width: 3.2em; }

.btn { border: 1px solid var(--line); background: var(--surface); border-radius: 12px; padding: 8px 14px; font-size: .9em; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.btn.small { padding: 4px 10px; font-size: .8em; }
.btn.danger { color: var(--danger); }

form.box { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; display: grid; gap: 10px; margin-bottom: 12px; }
form.box label { display: grid; gap: 4px; font-size: .85em; color: var(--muted); }
form.box input, form.box select, .addrow input {
  border: 1px solid var(--line); border-radius: 10px; background: var(--bg); padding: 10px 12px; min-height: 46px; width: 100%; color: var(--ink);
}
form.box .two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
form.box .acts { display: flex; gap: 8px; justify-content: flex-end; }
.pick { display: flex; gap: 6px; flex-wrap: wrap; }
.pick button { border: 1px solid var(--line); background: var(--bg); border-radius: 999px; padding: 6px 12px; font-size: .9em; color: var(--ink); }
.pick button.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 600; }
.addrow { display: flex; gap: 8px; margin-bottom: 12px; }
.addrow input { flex: 1; }

.listtabs { display: flex; gap: 8px; overflow-x: auto; margin-bottom: 12px; scrollbar-width: none; }
.listtabs button { flex: none; border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 8px 16px; }
.listtabs button.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.listtabs .n { opacity: .7; font-size: .85em; margin-left: 4px; }

.month { display: flex; align-items: center; justify-content: center; gap: 16px; margin-bottom: 8px; }
.month button { border: 0; background: none; font-size: 1.4em; color: var(--accent); padding: 4px 12px; }
.total { text-align: center; margin: 4px 0 14px; }
.total .big { font-size: 2.1em; font-weight: 700; font-variant-numeric: tabular-nums; }
.total .sub { color: var(--muted); font-size: .85em; }
.bar { height: 8px; border-radius: 4px; background: var(--accent); opacity: .85; margin-top: 4px; }
.amt { font-variant-numeric: tabular-nums; font-weight: 600; }

.meter { height: 10px; background: var(--line); border-radius: 5px; overflow: hidden; margin-top: 4px; }
.meter > div { height: 100%; background: var(--accent); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: .9em; }
.link { font-size: .75em; color: var(--muted); word-break: break-all; }
.hint { color: var(--muted); font-size: .85em; line-height: 1.6; }
table.u { width: 100%; border-collapse: collapse; font-size: .85em; font-variant-numeric: tabular-nums; }
table.u td, table.u th { padding: 6px 8px; border-top: 1px solid var(--line); text-align: right; }
table.u th:first-child, table.u td:first-child { text-align: left; }

#gate { position: fixed; inset: 0; background: var(--bg); display: grid; place-items: center; padding: 24px; }
#gate .inner { max-width: 420px; display: grid; gap: 14px; text-align: center; }
#gate .logo { width: 96px; height: 96px; margin: 0 auto; border-radius: 24px; }
#gate input { border: 1px solid var(--line); border-radius: 12px; padding: 12px; background: var(--surface); }

.toast { position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 999px; font-size: .9em; z-index: 9; max-width: 90vw; }
