/* ============================================================
   Family Cloud · 样式
   ------------------------------------------------------------
   家里用的东西不该冷冰冰的，所以配色偏暖（米白 + 墨蓝 + 一点橘）。
   深色模式跟着系统走。

   iPad 适配要点：
     · 所有可点区域最小 44pt（手指）
     · env(safe-area-inset-*) 处理刘海、圆角、底部指示条
     · 底部标签栏固定，面板从底部升起
     · -webkit-overflow-scrolling 让滚动更跟手
   ============================================================ */

:root {
  --bg: #F6F3EE;
  --bg-2: #FFFFFF;
  --bg-3: #EFEAE2;
  --ink: #1E2430;
  --ink-2: #59616F;
  --ink-3: #98A0AE;
  --line: rgba(30, 36, 48, .10);
  --brand: #2F6BE4;
  --brand-2: #7EA8F5;
  --accent: #E8834A;
  --good: #1FA97A;
  --warn: #D9A23B;
  --danger: #D9534F;
  --shadow: 0 1px 2px rgba(20,24,33,.05), 0 6px 20px rgba(20,24,33,.07);
  --shadow-lg: 0 8px 40px rgba(20,24,33,.16);
  --r: 14px;
  --r-lg: 20px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --tabh: 58px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171D;
    --bg-2: #1C2028;
    --bg-3: #232833;
    --ink: #ECEFF4;
    --ink-2: #A8B0BD;
    --ink-3: #6E7787;
    --line: rgba(255,255,255,.10);
    --brand: #5C92F5;
    --brand-2: #8FB6FA;
    --accent: #F09A63;
    --good: #3FBF92;
    --shadow: 0 1px 2px rgba(0,0,0,.30), 0 6px 20px rgba(0,0,0,.28);
    --shadow-lg: 0 8px 40px rgba(0,0,0,.5);
  }
}

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

/* hidden 属性必须赢过所有 display 声明。
   浏览器里 hidden 只是 UA 层的一条 display:none，
   作者层任何 .app{display:flex} / .form{display:flex} 都会把它顶掉。
   结果就是引导页、登录表单、主界面三样一起显示（真踩过）。
   这条要放在所有布局规则之前，且用 !important 兜底。 */
[hidden] { display: none !important; }

html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--bg); color: var(--ink);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "SF Pro SC", "PingFang SC",
        "Helvetica Neue", "Microsoft YaHei", sans-serif;
  overscroll-behavior-y: none;
}
body.lock { overflow: hidden; }

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; }
input, select {
  width: 100%; padding: 11px 13px; border-radius: 11px;
  border: 1px solid var(--line); background: var(--bg-2);
  -webkit-appearance: none; appearance: none;
}
select { background-image: none; }
input:focus, select:focus { outline: 2px solid var(--brand); outline-offset: -1px; }

/* Chrome/Edge 自动填充会画一块灰底（那个灰块在深色界面上特别扎眼），
   用 autofill 伪类把底色改回主题色，框还是浏览器那个黄/蓝框，认得出是自动填的。 */
input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus,
input:-webkit-autofill:active {
  -webkit-text-fill-color: var(--ink);
  -webkit-box-shadow: 0 0 0 1000px var(--bg-2) inset;
  caret-color: var(--ink);
  transition: background-color 9999s ease-out 0s;
}
input:-webkit-autofill::placeholder { color: var(--ink-3); }
::placeholder { color: var(--ink-3); opacity: 1; }

/* ───────────────────── 登录 / 初始化 ───────────────────── */

.gate {
  position: fixed; inset: 0; display: grid; place-items: center;
  padding: calc(var(--safe-t) + 24px) 24px calc(var(--safe-b) + 24px);
  background:
    radial-gradient(120% 80% at 15% 0%, rgba(47,107,228,.10), transparent 60%),
    radial-gradient(100% 70% at 90% 100%, rgba(232,131,74,.12), transparent 60%),
    var(--bg);
  overflow-y: auto;
}
.gate__card {
  width: 100%; max-width: 400px; background: var(--bg-2);
  border-radius: var(--r-lg); box-shadow: var(--shadow-lg); padding: 30px 26px;
}
.brand { text-align: center; margin-bottom: 24px; }
.brand__mark {
  width: 62px; height: 62px; margin: 0 auto 12px; border-radius: 18px;
  display: grid; place-items: center; color: #fff;
  background: linear-gradient(145deg, var(--brand), var(--brand-2));
  box-shadow: 0 6px 18px rgba(47,107,228,.32);
}
.brand__mark svg { width: 34px; height: 34px; }
.brand__name { margin: 0; font-size: 22px; letter-spacing: -.4px; }
.brand__sub { margin: 5px 0 0; font-size: 13.5px; color: var(--ink-3); }

.form { display: flex; flex-direction: column; gap: 14px; }
.form__lead { margin: 0; font-size: 13.5px; color: var(--ink-2); line-height: 1.6; }
.form__err { margin: 0; min-height: 18px; font-size: 13px; color: var(--danger); text-align: center; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: 12.5px; color: var(--ink-2); font-weight: 500; }
.check { display: flex; align-items: center; gap: 8px; font-size: 13.5px; }
.check input { width: auto; }

.btn {
  padding: 11px 16px; min-height: 44px; border-radius: 12px;
  background: var(--bg-3); color: var(--ink); font-weight: 600; font-size: 14.5px;
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  transition: transform .1s ease, background .15s ease;
}
.btn:active { transform: scale(.975); }
.btn--primary { background: var(--brand); color: #fff; box-shadow: 0 3px 12px rgba(47,107,228,.28); }
.btn--danger { background: var(--danger); color: #fff; }
.btn--ghost { background: transparent; border: 1px solid var(--line); }
.btn--block { width: 100%; }
.btn--sm { padding: 7px 12px; min-height: 36px; font-size: 13.5px; }
.btn[disabled] { opacity: .45; pointer-events: none; }

/* ───────────────────── 骨架 ───────────────────── */

.app { display: flex; flex-direction: column; height: 100%; }

.topbar {
  flex: none; display: flex; align-items: center; gap: 6px;
  padding: calc(var(--safe-t) + 8px) calc(var(--safe-l) + 12px) 8px calc(var(--safe-r) + 12px);
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(180%) blur(18px);
  -webkit-backdrop-filter: saturate(180%) blur(18px);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.topbar__back { font-size: 26px; line-height: 1; width: 36px; height: 40px; color: var(--brand); }
.topbar__title { display: flex; flex-direction: column; min-width: 0; }
.topbar__title b { font-size: 16.5px; letter-spacing: -.2px; }
.topbar__title span {
  font-size: 11.5px; color: var(--ink-3);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.topbar__spacer { flex: 1; }
.iconbtn {
  width: 40px; height: 40px; border-radius: 11px; display: grid; place-items: center;
  color: var(--ink-2);
}
.iconbtn:active { background: var(--bg-3); }
.iconbtn svg { width: 21px; height: 21px; }
.iconbtn--sm { width: 32px; height: 32px; font-size: 15px; }

.main {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
  padding: 14px calc(var(--safe-r) + 14px) calc(var(--safe-b) + var(--tabh) + 26px)
           calc(var(--safe-l) + 14px);
}

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(5, 1fr);
  padding: 4px calc(var(--safe-r) + 4px) calc(var(--safe-b) + 4px) calc(var(--safe-l) + 4px);
  background: color-mix(in srgb, var(--bg-2) 84%, transparent);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-top: 1px solid var(--line);
}
.tab {
  min-height: calc(var(--tabh) - 8px);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--ink-3); font-size: 10.5px; border-radius: 11px;
}
.tab svg { width: 22px; height: 22px; }
.tab.is-on { color: var(--brand); }

/* ───────────────────── 通用块 ───────────────────── */

.panel {
  background: var(--bg-2); border-radius: var(--r); padding: 16px;
  margin-bottom: 14px; box-shadow: var(--shadow);
}
.panel h3 { margin: 0 0 12px; font-size: 14.5px; }
.panel p { margin: 0 0 12px; font-size: 13.5px; color: var(--ink-2); line-height: 1.65; }
.row { display: flex; gap: 9px; flex-wrap: wrap; }

.cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 14px; }
.statcard {
  background: var(--bg-2); border-radius: var(--r); padding: 14px 12px;
  box-shadow: var(--shadow); text-align: center;
}
.statcard b { display: block; font-size: 17px; letter-spacing: -.3px; word-break: break-all; }
.statcard span { font-size: 11.5px; color: var(--ink-3); }
.statcard--good b { color: var(--good); }

.mini-list { display: flex; flex-direction: column; gap: 2px; margin-top: 8px; }
.mini-list__item {
  display: flex; gap: 10px; align-items: baseline;
  padding: 7px 0; border-bottom: 1px solid var(--line); font-size: 13px;
}
.mini-list__item:last-child { border-bottom: none; }
.mini-list__item time { color: var(--ink-3); font-size: 11.5px; min-width: 78px; }
.mini-list__item span { color: var(--ink-2); }
.mini-list__item b { font-weight: 600; }

.bars { display: flex; flex-direction: column; gap: 10px; }
.bar__row { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.bar__k { width: 62px; color: var(--ink-2); flex: none; }
.bar__track { flex: 1; height: 8px; border-radius: 5px; background: var(--bg-3); overflow: hidden; }
.bar__fill { height: 100%; border-radius: 5px; background: linear-gradient(90deg, var(--brand), var(--brand-2)); }
.bar__v { width: 84px; text-align: right; color: var(--ink-3); font-size: 12px; flex: none; }

.chips { display: flex; gap: 7px; overflow-x: auto; padding-bottom: 4px; -webkit-overflow-scrolling: touch; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; padding: 7px 13px; min-height: 36px; border-radius: 18px;
  background: var(--bg-3); font-size: 13px; color: var(--ink-2); white-space: nowrap;
  display: inline-flex; align-items: center; gap: 5px;
}
.chip.is-on { background: var(--brand); color: #fff; }

.filters__grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 11px; margin-bottom: 12px; }
.filter-more { margin-top: 8px; }
.filter-more summary {
  font-size: 13px; color: var(--brand); padding: 8px 0; list-style: none;
  min-height: 34px; display: flex; align-items: center;
}
.filter-more summary::-webkit-details-marker { display: none; }
.filter-more summary::before { content: "▸ "; }
.filter-more[open] summary::before { content: "▾ "; }

.meta { font-size: 12px; color: var(--ink-3); margin: 10px 0 8px; }

/* ───────────────────── 文件浏览 ───────────────────── */

.crumbs {
  display: flex; gap: 4px; overflow-x: auto; margin-bottom: 12px;
  font-size: 12.5px; color: var(--ink-3); -webkit-overflow-scrolling: touch;
}
.crumbs::-webkit-scrollbar { display: none; }
.crumbs button { color: var(--brand); flex: none; padding: 4px 2px; }
.crumbs i { flex: none; font-style: normal; padding: 4px 2px; }

.quickbar {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(76px, 1fr));
  gap: 8px; margin-bottom: 14px;
}
.quick {
  background: var(--bg-2); border-radius: var(--r); padding: 12px 6px;
  text-align: center; box-shadow: var(--shadow); min-height: 78px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 5px;
}
.quick__n { font-size: 20px; line-height: 1; }
.quick__k { font-size: 11.5px; color: var(--ink-3); }
.quick.is-on { outline: 2px solid var(--brand); outline-offset: -2px; }

.dropzone {
  border: 1.5px dashed var(--line); border-radius: var(--r);
  padding: 22px 16px; text-align: center; color: var(--ink-3);
  margin-bottom: 16px; display: flex; flex-direction: column; align-items: center; gap: 6px;
  background: var(--bg-2);
}
.dropzone svg { width: 30px; height: 30px; color: var(--brand); }
.dropzone b { font-size: 14px; color: var(--ink-2); }
.dropzone span { font-size: 12px; }
.dropzone.is-over { border-color: var(--brand); background: color-mix(in srgb, var(--brand) 8%, var(--bg-2)); }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(148px, 1fr)); gap: 11px; }
.grid--list { grid-template-columns: 1fr; gap: 8px; }

.card {
  background: var(--bg-2); border-radius: var(--r); padding: 13px;
  box-shadow: var(--shadow); position: relative; text-align: left;
  display: flex; flex-direction: column; gap: 6px; min-height: 104px;
}
.card:active { transform: scale(.985); }
.card__icon { font-size: 27px; line-height: 1; }
.card__name {
  font-size: 13.5px; font-weight: 500; line-height: 1.35;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden; word-break: break-all;
}
.card__sub { font-size: 11.5px; color: var(--ink-3); margin-top: auto; }
.card__badges { display: flex; gap: 5px; flex-wrap: wrap; }
.badge {
  font-size: 10px; padding: 2px 6px; border-radius: 5px;
  background: var(--bg-3); color: var(--ink-2);
}
.badge--lock { background: color-mix(in srgb, var(--good) 18%, transparent); color: var(--good); }
.badge--star { background: color-mix(in srgb, var(--warn) 22%, transparent); color: var(--warn); }
.badge--share { background: color-mix(in srgb, var(--brand) 16%, transparent); color: var(--brand); }

.row-item {
  display: flex; gap: 12px; align-items: center; padding: 11px 13px;
  background: var(--bg-2); border-radius: var(--r); box-shadow: var(--shadow); text-align: left;
}
.row-item__icon { font-size: 24px; flex: none; }
.row-item__body { flex: 1; min-width: 0; }
.row-item__name { font-size: 14px; font-weight: 500; word-break: break-all; }
.row-item__sub { font-size: 11.5px; color: var(--ink-3); margin-top: 2px; }
.row-item__snippet {
  font-size: 12px; color: var(--ink-2); margin-top: 4px;
  background: var(--bg-3); border-radius: 7px; padding: 5px 8px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}

.avatar {
  width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center;
  color: #fff; font-weight: 600; font-size: 16px; flex: none;
}

.empty { text-align: center; padding: 46px 20px; color: var(--ink-3); }
.empty__icon { font-size: 40px; margin-bottom: 10px; }
.empty b { display: block; font-size: 15px; color: var(--ink-2); margin-bottom: 4px; }
.empty span { font-size: 13px; }

/* ───────────────────── 上传队列 ───────────────────── */

.uploads {
  position: fixed; left: calc(var(--safe-l) + 10px); right: calc(var(--safe-r) + 10px);
  bottom: calc(var(--safe-b) + var(--tabh) + 10px); z-index: 25;
  display: flex; flex-direction: column; gap: 7px; pointer-events: none;
}
.up {
  background: var(--bg-2); border-radius: 12px; padding: 9px 12px;
  box-shadow: var(--shadow); pointer-events: auto;
}
.up__head { display: flex; gap: 8px; align-items: baseline; font-size: 12.5px; }
.up__name { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.up__pct { color: var(--ink-3); font-size: 11.5px; }
.up__track { height: 5px; border-radius: 3px; background: var(--bg-3); margin-top: 6px; overflow: hidden; }
.up__fill { height: 100%; background: linear-gradient(90deg, var(--brand), var(--good)); transition: width .2s; }
.up__note { font-size: 11px; color: var(--ink-3); margin-top: 4px; }
.up__err { font-size: 11px; color: var(--danger); margin-top: 4px; }

/* ───────────────────── 弹出层 ───────────────────── */

.sheet { position: fixed; inset: 0; z-index: 60; display: flex; align-items: flex-end; }
.sheet__scrim { position: absolute; inset: 0; background: rgba(0,0,0,.42); animation: fade .2s; }
.sheet__panel {
  position: relative; width: 100%; max-height: 88%;
  background: var(--bg-2); border-radius: var(--r-lg) var(--r-lg) 0 0;
  padding: 8px 16px calc(var(--safe-b) + 20px);
  overflow-y: auto; -webkit-overflow-scrolling: touch;
  animation: rise .26s cubic-bezier(.32,.72,0,1);
  box-shadow: var(--shadow-lg);
}
.sheet__grip { width: 36px; height: 4px; border-radius: 3px; background: var(--line); margin: 4px auto 12px; }
@keyframes rise { from { transform: translateY(100%); } }
@keyframes fade { from { opacity: 0; } }

.sheet__title { font-size: 17px; margin: 0 0 4px; word-break: break-all; }
.sheet__sub { font-size: 12.5px; color: var(--ink-3); margin: 0 0 14px; }
.sheet__actions { display: flex; flex-direction: column; gap: 8px; margin-top: 16px; }
.sheet__actions .btn { width: 100%; }

.preview-box {
  width: 100%; border-radius: 12px; overflow: hidden; background: var(--bg-3);
  margin-bottom: 12px; display: grid; place-items: center; min-height: 120px;
}
.preview-box img, .preview-box video { max-width: 100%; max-height: 52vh; display: block; }
.preview-box audio { width: 100%; padding: 14px; }
.preview-box iframe { width: 100%; height: 58vh; border: 0; background: #fff; }
.preview-text {
  width: 100%; max-height: 46vh; overflow: auto; font: 13px/1.6 ui-monospace, Menlo, monospace;
  white-space: pre-wrap; word-break: break-all; background: var(--bg-3);
  border-radius: 12px; padding: 12px; margin-bottom: 12px;
}
.kv { display: grid; grid-template-columns: 84px 1fr; gap: 7px 12px; font-size: 13px; margin-bottom: 12px; }
.kv dt { color: var(--ink-3); }
.kv dd { margin: 0; word-break: break-all; }

.ver-item {
  display: flex; gap: 10px; align-items: center; padding: 9px 0;
  border-bottom: 1px solid var(--line); font-size: 13px;
}
.ver-item:last-child { border-bottom: none; }
.ver-item__body { flex: 1; min-width: 0; }
.ver-item__n { font-weight: 600; }
.ver-item__d { font-size: 11.5px; color: var(--ink-3); }

.searchbar {
  display: flex; align-items: center; gap: 8px; background: var(--bg-2);
  border-radius: 12px; padding: 0 10px; box-shadow: var(--shadow); margin-bottom: 12px;
}
.searchbar svg { width: 19px; height: 19px; color: var(--ink-3); flex: none; }
.searchbar input { border: none; background: none; padding: 12px 0; }
.searchbar input:focus { outline: none; }

.menu { display: flex; flex-direction: column; gap: 2px; }
.menu button {
  display: flex; align-items: center; gap: 12px; padding: 13px 6px;
  font-size: 15px; text-align: left; border-bottom: 1px solid var(--line); min-height: 48px;
}
.menu button:last-child { border-bottom: none; }
.menu button.danger { color: var(--danger); }
.menu button svg { width: 20px; height: 20px; flex: none; color: var(--ink-3); }

/* ───────────────────── Toast ───────────────────── */

.toast {
  position: fixed; left: 50%; bottom: calc(var(--safe-b) + var(--tabh) + 26px);
  transform: translate(-50%, 14px); z-index: 90;
  background: rgba(24,28,36,.94); color: #fff; padding: 10px 18px;
  border-radius: 22px; font-size: 13.5px; opacity: 0; pointer-events: none;
  transition: opacity .2s ease, transform .2s ease; max-width: 80vw; text-align: center;
}
.toast.is-on { opacity: 1; transform: translate(-50%, 0); }

/* ───────────────────── iPad 宽屏 ───────────────────── */

@media (min-width: 768px) {
  .main { padding-left: calc(var(--safe-l) + 26px); padding-right: calc(var(--safe-r) + 26px); }
  .grid { grid-template-columns: repeat(auto-fill, minmax(178px, 1fr)); gap: 13px; }
  .cards { gap: 14px; }
  .sheet { align-items: center; justify-content: center; }
  .sheet__panel {
    max-width: 620px; border-radius: var(--r-lg);
    max-height: 82vh; padding: 22px 24px 24px;
  }
  .sheet__grip { display: none; }
  .filters__grid { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
  .bar__k { width: 84px; }
}

@media (min-width: 1100px) {
  .grid { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
  .main { max-width: 1180px; margin: 0 auto; width: 100%; }
}
/* ============================================================
   小f · 悬浮按钮 + 对话面板
   ------------------------------------------------------------
   面板用 fixed 全屏而不是底部抽屉，原因和 AI Lab 那边的玩法面板一样：
   iPad 上打字时底部抽屉会被键盘顶起来、还会遮挡内容，全屏最省事。
   气泡背景用半透明 + blur，让底下的粒子/渐变透上来一点，不至于太闷。
   ============================================================ */

.aifab {
  position: fixed; z-index: 80;
  right: calc(var(--safe-r) + 16px);
  bottom: calc(var(--safe-b) + var(--tabh) + 16px);
  width: 54px; height: 54px; border-radius: 50%;
  border: none; cursor: pointer;
  background: linear-gradient(150deg, var(--brand), #6C4CE0);
  box-shadow: 0 6px 22px rgba(47,107,228,.42);
  color: #fff; font-size: 24px; font-weight: 700;
  display: grid; place-items: center;
  transition: transform .22s cubic-bezier(.2,.9,.3,1.4), opacity .2s;
}
.aifab:active { transform: scale(.92); }
.aifab.is-hidden { opacity: 0; transform: scale(.6); pointer-events: none; }
.aifab__face { transform: translateY(-1px); }
.aifab__dot {
  position: absolute; right: 4px; top: 4px;
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--good); border: 2px solid var(--bg-2);
}

.aipanel {
  position: fixed; inset: 0; z-index: 95;
  display: flex; flex-direction: column;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(22px) saturate(160%);
  -webkit-backdrop-filter: blur(22px) saturate(160%);
}
.aipanel[hidden] { display: none; }

.aipanel__bar {
  display: flex; align-items: center; gap: 10px;
  padding: calc(var(--safe-t) + 10px) 14px 10px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg-2) 78%, transparent);
}
.aipanel__title { flex: 1; display: flex; align-items: baseline; gap: 9px; min-width: 0; }
.aipanel__title b { font-size: 17px; letter-spacing: .5px; }
.aipanel__title span {
  font-size: 12px; color: var(--ink-3);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.aipanel__log {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 16px 14px 8px;
  display: flex; flex-direction: column; gap: 14px;
}

.aimsg { display: flex; gap: 9px; align-items: flex-start; }
.aimsg--ai { flex-direction: row; }          /* 默认方向，写出来是为了和 --me 对称 */
.aimsg--me { flex-direction: row-reverse; }
.aimsg__av {
  flex: 0 0 30px; width: 30px; height: 30px; border-radius: 50%;
  display: grid; place-items: center;
  font-size: 13px; font-weight: 700;
  background: linear-gradient(150deg, var(--brand), #6C4CE0); color: #fff;
}
.aimsg--me .aimsg__av { background: var(--bg-3); color: var(--ink-2); }
.aimsg__bubble {
  max-width: 78%; padding: 10px 13px;
  border-radius: 16px; font-size: 15px; line-height: 1.55;
  background: var(--bg-2); border: 1px solid var(--line);
  box-shadow: var(--shadow);
  word-break: break-word;
}
.aimsg--me .aimsg__bubble {
  background: var(--brand); color: #fff; border-color: transparent;
}
.aimsg__bubble p { margin: 0 0 7px; }
.aimsg__bubble p:last-child { margin-bottom: 0; }
.aimsg__bubble ul, .aimsg__bubble ol { margin: 4px 0 7px; padding-left: 20px; }
.aimsg__bubble code {
  background: rgba(127,127,127,.16); padding: 1px 5px; border-radius: 5px;
  font-size: 13px; font-family: ui-monospace, Menlo, monospace;
}
.aimsg__bubble a[data-node] { color: var(--brand); font-weight: 600; }
.aimsg--me .aimsg__bubble a[data-node] { color: #fff; text-decoration: underline; }
.aimsg.is-warn .aimsg__bubble { border-color: var(--warn); }

/* 等待模型/工具返回时的三点跳动。
   没有它的话，气泡在等的那十几秒里是完全空白的，用户会以为界面卡死了 ——
   空闲和卡死长得一模一样，这是最容易被当成 bug 的地方。

   不用 :has()（iPad Safari 15.4 才有）判断"有没有文字"，
   改成 JS 直接切has-text 类 —— 兼容性靠得住，逻辑还更好读。 */
.aimsg__bubble.is-typing:not(.has-text)::after {
  content: ''; display: inline-block; width: 34px; height: 6px;
  background:
    radial-gradient(circle at 4px  3px, var(--ink-3) 2.2px, transparent 2.4px),
    radial-gradient(circle at 17px 3px, var(--ink-3) 2.2px, transparent 2.4px),
    radial-gradient(circle at 30px 3px, var(--ink-3) 2.2px, transparent 2.4px);
  animation: aidots 1.1s ease-in-out infinite;
}
@keyframes aidots {
  0%, 100% { opacity: .3; transform: translateX(0); }
  50%      { opacity: 1;  transform: translateX(3px); }
}

.cursor { animation: aiblink .9s steps(1) infinite; opacity: .7; }
@keyframes aiblink { 50% { opacity: 0; } }

.aitool {
  align-self: center; max-width: 88%;
  padding: 5px 12px; border-radius: 14px;
  font-size: 12.5px; color: var(--ink-2);
  background: color-mix(in srgb, var(--bg-3) 80%, transparent);
  border: 1px dashed var(--line);
}
.aitool.is-bad { color: var(--danger); border-color: var(--danger); }

.aipanel__chips {
  display: flex; gap: 7px; padding: 4px 14px 10px;
  overflow-x: auto; -webkit-overflow-scrolling: touch;
}
.aipanel__chips:empty { display: none; }
.aipanel__chips button {
  flex: 0 0 auto; padding: 7px 13px; border-radius: 16px;
  border: 1px solid var(--line); background: var(--bg-2);
  color: var(--ink-2); font-size: 13px; cursor: pointer;
}

.aipanel__foot {
  display: flex; align-items: flex-end; gap: 8px;
  padding: 10px 12px calc(var(--safe-b) + 12px);
  border-top: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg-2) 82%, transparent);
}
.aipanel__foot textarea {
  flex: 1; resize: none; max-height: 120px;
  padding: 10px 14px; border-radius: 20px;
  border: 1px solid var(--line); background: var(--bg);
  color: var(--ink); font: inherit; font-size: 15px; line-height: 1.4;
}
.aipanel__foot textarea:focus { outline: 2px solid var(--brand); outline-offset: -1px; }
.aipanel__send {
  flex: 0 0 40px; width: 40px; height: 40px; border-radius: 50%;
  border: none; background: var(--brand); color: #fff;
  font-size: 19px; cursor: pointer;
}
.aipanel__send.is-stop { background: var(--danger); font-size: 15px; }

.aipanel__imgs { position: absolute; bottom: 100%; left: 0; right: 0;
  display: flex; gap: 8px; padding: 8px 14px; overflow-x: auto; }
.aiimg { position: relative; flex: 0 0 62px; height: 62px; }
.aiimg img { width: 100%; height: 100%; object-fit: cover; border-radius: 10px; }
.aiimg button {
  position: absolute; right: -5px; top: -5px;
  width: 20px; height: 20px; border-radius: 50%;
  border: none; background: var(--ink); color: var(--bg);
  font-size: 11px; line-height: 1; cursor: pointer;
}

.mini-pre {
  max-height: 46vh; overflow: auto; margin: 8px 0 0;
  padding: 12px; border-radius: 12px;
  background: var(--bg-3); font-size: 13px; line-height: 1.6;
  white-space: pre-wrap; word-break: break-word;
}
.dim { color: var(--ink-3); }
.bad { color: var(--danger); }

@media (min-width: 768px) {
  .aipanel { left: auto; width: 520px; border-left: 1px solid var(--line);
             box-shadow: var(--shadow-lg); }
  .aimsg__bubble { max-width: 84%; }
}
