:root {
  --bg: #f4f5f8;
  --surface: #ffffff;
  --surface-2: #eef0f4;
  --text: #15171c;
  --muted: #6b7280;
  --line: rgba(15, 23, 42, 0.08);
  --accent: #5b5bf0;
  --accent-2: #7c5cf5;
  --accent-text: #ffffff;
  --danger: #e5484d;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.04), 0 4px 16px rgba(15, 23, 42, 0.06);
  --radius: 18px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1014;
    --surface: #181b21;
    --surface-2: #22262e;
    --text: #e8eaef;
    --muted: #8b93a3;
    --line: rgba(255, 255, 255, 0.07);
    --accent: #6d6df5;
    --accent-2: #8b6cf7;
    --danger: #ff6b6f;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 6px 20px rgba(0, 0, 0, 0.25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; cursor: pointer; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; display: block; }

/* ---------- 品牌 ---------- */
.logo {
  width: 34px; height: 34px; border-radius: 11px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: grid; place-items: center; flex: none;
}
.logo::before {
  content: ""; width: 13px; height: 13px; background: #fff;
  border-radius: 50% 0 50% 50%; transform: rotate(-45deg) translate(-1px, 1px);
}
.logo.big { width: 56px; height: 56px; border-radius: 18px; margin: 0 auto 4px; }
.logo.big::before { width: 21px; height: 21px; transform: rotate(-45deg) translate(-1.5px, 1.5px); }

/* ---------- 登录 / 锁定 / 加载 ---------- */
.screen { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.gate {
  width: min(360px, 100%); background: var(--surface); border-radius: 24px; box-shadow: var(--shadow);
  padding: 32px 24px 24px; text-align: center; display: grid; gap: 12px;
}
.gate h1 { margin: 4px 0 0; font-size: 22px; letter-spacing: 0.2px; }
.gate p { margin: 0; }
.gate input {
  width: 100%; height: 46px; padding: 0 14px; margin-top: 8px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface-2); color: var(--text);
  font-size: 16px; outline: none; transition: border-color .15s, box-shadow .15s;
}
.gate input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent); }
.gate-msg { min-height: 20px; color: var(--danger); font-size: 13px; }
.gate-icon { width: 56px; height: 56px; margin: 0 auto 4px; border-radius: 18px; display: grid; place-items: center; background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); }
.gate-icon svg { width: 26px; height: 26px; }
.shake { animation: shake .35s; }
@keyframes shake { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }

.btn { height: 46px; border: 0; border-radius: 12px; font-weight: 600; }
.btn.primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: var(--accent-text); }
.btn:disabled { opacity: .6; cursor: default; }

.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--surface-2); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- 主界面布局 ---------- */
/* 页面占满窗口宽度（滚动条贴右边），内容限制在 860px 内居中 */
.app { height: 100dvh; display: grid; grid-template-rows: auto 1fr auto; --gutter: max(16px, calc((100% - 828px) / 2)); }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) var(--gutter) 10px;
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; }
.top-actions { display: flex; gap: 2px; }
.search {
  flex: 1; min-width: 0; height: 38px; margin-right: 8px; padding: 0 12px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface-2); color: var(--text); font-size: 16px; outline: none;
}
.search:focus { border-color: var(--accent); }
.no-match { text-align: center; margin: 32px 0; }
.older { text-align: center; margin: 0 0 12px; }
.brand-name { font-weight: 700; font-size: 17px; line-height: 1.2; }
/* 宽屏：计数和占用排在一行；窄屏：只常驻计数，点一下在顶栏下方展开占用 */
.topbar { position: relative; }
.count { border: 0; padding: 0; background: none; text-align: left; cursor: default; }
.usage:empty { display: none; }
@media (min-width: 640px) {
  .count, .usage { display: inline; }
  .usage::before { content: " · "; }
}
@media (max-width: 639px) {
  .count.more { cursor: pointer; }
  .count.more::after { content: " ▾"; }
  .show-usage .count.more::after { content: " ▴"; }
  .count { white-space: nowrap; }
  .usage {
    display: none; position: absolute; left: 0; right: 0; top: calc(100% + 1px); z-index: 10;
    padding: 8px var(--gutter); background: var(--bg); border-bottom: 1px solid var(--line);
  }
  .show-usage .usage:not(:empty) { display: block; }
}
/* 特别窄的屏幕把 logo 让给文字和按钮 */
@media (max-width: 359px) {
  .topbar .logo { display: none; }
}

.icon-btn {
  width: 38px; height: 38px; flex: none; border: 0; border-radius: 12px; background: transparent;
  display: grid; place-items: center; color: var(--muted); transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn.spinning svg { animation: spin .8s linear infinite; }
.store-btn {
  align-self: center; height: 28px; padding: 0 10px; margin-right: 4px; border: 0; border-radius: 999px;
  background: var(--surface-2); color: var(--muted); font-size: 12px; font-weight: 600; transition: color .15s;
}
.store-btn:hover { color: var(--text); }

.scroller { overflow-y: auto; overscroll-behavior: contain; padding: 8px var(--gutter) 16px; }
.empty { height: 100%; display: grid; place-content: center; text-align: center; gap: 2px; }
.empty p { margin: 0; }
.empty-icon { width: 64px; height: 64px; margin: 0 auto 10px; border-radius: 20px; display: grid; place-items: center; background: var(--surface); box-shadow: var(--shadow); color: var(--accent); }
.empty-icon svg { width: 28px; height: 28px; }

/* ---------- 时间线 ---------- */
.timeline { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 14px; }
.day { align-self: center; font-size: 12px; color: var(--muted); background: var(--surface-2); padding: 2px 10px; border-radius: 999px; margin-top: 6px; }

.msg { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.msg.enter { animation: pop .18s ease-out; }
@keyframes pop { from { opacity: 0; transform: translateY(6px); } }
/* 别的设备发来的新内容：短暂外发光 */
.msg.fresh .bubble { animation: glow 1.6s ease-out; }
@keyframes glow { from { box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 45%, transparent), var(--shadow); } }

.bubble { max-width: min(560px, 86%); border-radius: var(--radius); border-bottom-right-radius: 6px; box-shadow: var(--shadow); overflow: hidden; }
.bubble.text {
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: var(--accent-text);
  padding: 10px 14px; white-space: pre-wrap; word-break: break-word;
}
.bubble.text a { color: inherit; text-decoration: underline; text-underline-offset: 2px; word-break: break-all; }
.bubble.text.collapsed {
  max-height: calc(1.55em * 12 + 20px);
  -webkit-mask-image: linear-gradient(#000 70%, transparent); mask-image: linear-gradient(#000 70%, transparent);
}

.bubble.file { background: var(--surface); display: flex; align-items: center; gap: 12px; padding: 10px 14px 10px 10px; min-width: 240px; }
.bubble.file.clickable { cursor: pointer; transition: background .15s; }
.bubble.file.clickable:hover { background: var(--surface-2); }
.bubble.file.clickable:active { background: var(--surface-2); }
.ficon { width: 44px; height: 44px; flex: none; border-radius: 12px; display: grid; place-items: center; background: color-mix(in srgb, var(--tint) 14%, transparent); color: var(--tint); }
.finfo { min-width: 0; flex: 1; }
.fname { font-weight: 600; }
/* 文件名拆成两段：前段放不下时省略，后段（末尾几个字符 + 扩展名）始终显示 */
.ellip { display: flex; min-width: 0; }
.ellip > :first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ellip > :last-child { flex: none; white-space: pre; }
.fmeta { font-size: 12px; color: var(--muted); }
.store-tag { flex: none; align-self: center; padding: 0 5px; border-radius: 4px; background: var(--surface-2); font-size: 10px; font-weight: 600; line-height: 16px; }
.fmeta .store-tag { display: inline-block; margin-left: 6px; vertical-align: 1px; }

.bubble.image { background: var(--surface); padding: 0; min-width: 0; }
.thumb { --edge: min(300px, 70vw); display: block; border: 0; padding: 0; background: var(--surface-2); width: var(--edge); aspect-ratio: var(--ratio, 4 / 3); cursor: zoom-in; }
/* 竖图让高度等于长边，宽度按比例缩窄 */
.thumb.tall { width: calc(var(--edge) * var(--ratio)); }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; opacity: 0; transition: opacity .2s; }
.thumb img.loaded { opacity: 1; }
.thumb.failed { cursor: default; }
/* 宽度跟随图片，不让长文件名把气泡撑宽 */
.image .caption { width: 0; min-width: 100%; padding: 6px 12px 8px; font-size: 12px; color: var(--muted); display: flex; gap: 6px; }
.image .caption > :not(.ellip) { flex: none; }
/* 文件名至少留 8 个字宽；竖图的标题栏放不下时，大小和存储标签一起换到第二行 */
.image .caption { flex-wrap: wrap; row-gap: 2px; }
.image .caption > .ellip { flex: 1 1 8em; }
.cmeta { display: flex; gap: 6px; }

.progress { height: 4px; border-radius: 4px; background: var(--surface-2); margin-top: 6px; overflow: hidden; }
.progress > i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: width .15s; }
.msg.failed .fmeta { color: var(--danger); }

.actions { display: flex; align-items: center; gap: 2px; padding-right: 4px; color: var(--muted); font-size: 12px; }
.actions time { margin-left: 6px; }
.actions .act {
  height: 28px; min-width: 28px; padding: 0 6px; border: 0; border-radius: 8px; background: transparent;
  display: inline-flex; align-items: center; gap: 4px; color: var(--muted); transition: background .15s, color .15s;
}
.actions .act svg { width: 16px; height: 16px; }
.actions .act:hover { background: var(--surface-2); color: var(--text); }
.actions .act.armed { background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); }
.actions .act.armed::after { content: "确认删除"; }
.actions .act.ok { color: #16a34a; }
.actions .act.more { color: var(--accent); font-weight: 600; }
@media (hover: hover) {
  .msg .actions .act { opacity: 0; }
  .msg:hover .actions .act, .msg .actions .act.armed, .msg .actions .act.more { opacity: 1; }
}
/* 手机上按钮放大到便于手指点击 */
@media (pointer: coarse) {
  .timeline { gap: 6px; }
  .msg { gap: 0; }
  .actions { gap: 4px; }
  .actions .act { height: 36px; min-width: 36px; padding: 0 8px; }
  .actions .act svg { width: 18px; height: 18px; }
}

/* ---------- 多选 ---------- */
/* 每条左侧一个勾选圈；每条下面的操作按钮在多选时隐藏 */
.selecting .msg[data-id] { position: relative; padding-left: 36px; cursor: pointer; user-select: none; -webkit-user-select: none; }
.selecting .msg .actions { display: none; }
.selecting .msg[data-id]::before {
  content: ""; position: absolute; left: 4px; top: 50%; width: 22px; height: 22px; margin-top: -11px;
  border-radius: 50%; border: 2px solid var(--muted); box-sizing: border-box;
}
.selecting .msg.selected::before {
  border-color: var(--accent);
  background: var(--accent) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23fff' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 6 9 17l-5-5'/%3E%3C/svg%3E") center / 14px no-repeat;
}
.selecting .msg.selected .bubble { box-shadow: 0 0 0 2px var(--accent), var(--shadow); }
.select-bar {
  display: flex; align-items: center; gap: 8px; padding: 6px; border-radius: 22px;
  background: var(--surface); box-shadow: var(--shadow); border: 1px solid var(--line);
}
.select-count { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-btn { height: 38px; flex: none; padding: 0 14px; border: 0; border-radius: 999px; background: var(--surface-2); font-size: 14px; font-weight: 600; transition: background .15s, color .15s; }
.bar-btn.danger { color: var(--danger); }
.bar-btn.danger.armed { background: var(--danger); color: #fff; }
.bar-btn:disabled { opacity: .4; cursor: default; }

/* ---------- 输入区 ---------- */
.composer-wrap { position: relative; width: 100%; max-width: 860px; margin: 0 auto; padding: 8px 12px calc(12px + env(safe-area-inset-bottom)); }
.new-below {
  position: absolute; left: 50%; bottom: 100%; transform: translateX(-50%); z-index: 5;
  height: 32px; padding: 0 14px; border: 0; border-radius: 999px; font-size: 13px; font-weight: 600;
  background: var(--accent); color: var(--accent-text); box-shadow: var(--shadow);
}
.composer {
  display: flex; align-items: flex-end; gap: 6px; padding: 6px; border-radius: 22px;
  background: var(--surface); box-shadow: var(--shadow); border: 1px solid var(--line);
}
.composer textarea {
  flex: 1; min-height: 38px; max-height: 200px; resize: none; border: 0; outline: none; background: transparent;
  color: var(--text); font: inherit; font-size: 16px; line-height: 1.45; padding: 8px 4px;
}
.send-btn {
  width: 38px; height: 38px; flex: none; border: 0; border-radius: 50%; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; transition: opacity .15s, transform .1s;
}
.send-btn:active { transform: scale(.94); }
.send-btn:disabled { opacity: .35; cursor: default; }
.send-btn svg { width: 18px; height: 18px; }

/* ---------- 浮层 ---------- */
.dropzone { position: fixed; inset: 0; z-index: 20; padding: 16px; background: color-mix(in srgb, var(--bg) 70%, transparent); backdrop-filter: blur(6px); }
.dropzone-inner {
  height: 100%; border: 2px dashed var(--accent); border-radius: 24px; display: grid; place-content: center;
  text-align: center; color: var(--accent); font-weight: 600; pointer-events: none;
}
.dropzone-inner svg { width: 40px; height: 40px; margin: 0 auto 8px; }

.viewer { position: fixed; inset: 0; z-index: 30; background: rgba(0, 0, 0, .88); display: grid; place-items: center; padding: 16px; cursor: zoom-out; }
.viewer img { max-width: 100%; max-height: 100%; border-radius: 8px; }

/* 批量下载清单：从底部弹出 */
.sheet { position: fixed; inset: 0; z-index: 35; background: rgba(0, 0, 0, .4); display: grid; place-items: end center; padding: 16px; }
.sheet-card {
  width: min(480px, 100%); max-height: 70dvh; overflow-y: auto; background: var(--surface); border-radius: 20px;
  padding: 10px 14px calc(14px + env(safe-area-inset-bottom)); box-shadow: var(--shadow);
}
.sheet-card p { margin: 0 0 10px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; }
.sheet-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.sheet-row { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 12px; background: var(--surface-2); color: var(--text); text-decoration: none; }
.sheet-row .ellip { flex: 1; }
.sheet-row .small { flex: none; }
.sheet-row.started::after { content: "已点"; flex: none; color: var(--accent); font-size: 12px; font-weight: 600; }

.toast {
  position: fixed; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom)); z-index: 40;
  transform: translate(-50%, 12px); opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
  background: var(--text); color: var(--bg); padding: 8px 14px; border-radius: 999px; font-size: 13px;
  /* left: 50% 定位时可用宽度只有半屏，显式按内容定宽，避免短句也折行 */
  width: max-content; max-width: calc(100% - 32px); box-shadow: var(--shadow);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--danger); color: #fff; }
