/* Discord 归档阅读器。
 *
 * 无构建、无框架、无 CDN——CSP 里 style-src 只给 'self'，也就不可能引外部字体。
 * 配色跟着系统走（prefers-color-scheme），设置页里能强制覆盖（data-theme）。
 *
 * 红底绿底这次终于能用上了：notify/base.py 里明说过 Telegram 的 HTML「没有任何
 * 颜色这回事」，只能退而求其次用删除线和加粗。Web 端没这个限制，
 * 直接照 ConsoleSink 的 ANSI 配色来——跟在终端里看 diff 一模一样。
 */

:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #eef0f4;
  --text: #1b1f24;
  --text-dim: #626b76;
  --border: #dfe3e9;
  --accent: #2f6fed;

  --mod: #b06a00;          /* 主持人的 ★ */
  --deleted: #d43b3b;
  --edited: #c98a00;
  --button: #2f6fed;

  --diff-del-bg: #ffd7d7;
  --diff-del-fg: #7a1616;
  --diff-ins-bg: #d3f5d8;
  --diff-ins-fg: #17591f;

  --radius: 10px;
  --gap: 12px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #171a21;
    --surface-2: #1f242d;
    --text: #e6e9ef;
    --text-dim: #9aa4b2;
    --border: #2a303b;
    --accent: #6ea0ff;

    --mod: #ffc663;
    --deleted: #ff7b7b;
    --edited: #ffce5c;
    --button: #6ea0ff;

    --diff-del-bg: #5a1f1f;
    --diff-del-fg: #ffd9d9;
    --diff-ins-bg: #1d4a26;
    --diff-ins-fg: #d6f7dc;
  }
}

/* 设置页里手动选的主题，优先于系统 */
:root[data-theme='light'] {
  --bg: #f6f7f9; --surface: #ffffff; --surface-2: #eef0f4;
  --text: #1b1f24; --text-dim: #626b76; --border: #dfe3e9; --accent: #2f6fed;
  --mod: #b06a00; --deleted: #d43b3b; --edited: #c98a00; --button: #2f6fed;
  --diff-del-bg: #ffd7d7; --diff-del-fg: #7a1616;
  --diff-ins-bg: #d3f5d8; --diff-ins-fg: #17591f;
}

:root[data-theme='dark'] {
  --bg: #0f1115; --surface: #171a21; --surface-2: #1f242d;
  --text: #e6e9ef; --text-dim: #9aa4b2; --border: #2a303b; --accent: #6ea0ff;
  --mod: #ffc663; --deleted: #ff7b7b; --edited: #ffce5c; --button: #6ea0ff;
  --diff-del-bg: #5a1f1f; --diff-del-fg: #ffd9d9;
  --diff-ins-bg: #1d4a26; --diff-ins-fg: #d6f7dc;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.6 -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC',
    'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
  /* iPhone 上「添加到主屏幕」之后是全屏的，不留这一手底栏会被小白条盖住 */
  padding-bottom: env(safe-area-inset-bottom);
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------------------------------------------------------------- 骨架 */

.shell { min-height: 100vh; display: flex; flex-direction: column; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding-top: env(safe-area-inset-top);
}

.nav { display: flex; gap: 4px; padding: 8px 12px; }

.nav-item {
  padding: 6px 14px;
  border-radius: 999px;
  color: var(--text-dim);
  font-weight: 600;
}
.nav-item:hover { background: var(--surface-2); text-decoration: none; }
.nav-item.active { background: var(--accent); color: #fff; }

.outlet { flex: 1; min-height: 0; }

.page { max-width: 900px; margin: 0 auto; padding: var(--gap); }
.page.browse {
  max-width: 1280px;
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  gap: var(--gap);
  align-items: start;
}

.page-body { display: flex; flex-direction: column; gap: var(--gap); }
.list { display: flex; flex-direction: column; gap: var(--gap); }
.list-wrap { display: flex; flex-direction: column; gap: var(--gap); min-width: 0; }

/* ---------------------------------------------------------------- 通用零件 */

.btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: var(--radius);
  padding: 7px 14px;
  font: inherit;
  cursor: pointer;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.subtle { background: transparent; }
.btn.wide { width: 100%; margin-bottom: 8px; }

.input {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: var(--radius);
  padding: 7px 10px;
  font: inherit;
  min-width: 0;
}
.input.date { max-width: 160px; }

.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.field { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; }

.note { color: var(--text-dim); font-size: 13px; }
.note.error { color: var(--deleted); }

.status { padding: 14px; text-align: center; color: var(--text-dim); font-size: 13px; }
.status.error { color: var(--deleted); }
.status:empty { padding: 0; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-dim);
  font-size: 12px;
  border: none;
  font-family: inherit;
}
button.chip { cursor: pointer; }
button.chip:hover { color: var(--text); }
.chip.deleted { color: var(--deleted); }
.chip.edited { color: var(--edited); }
.chip.ephemeral { color: var(--button); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.section-title { margin: 0 0 12px; font-size: 16px; }

/* ---------------------------------------------------------------- 登录 */

.login-page { min-height: 100vh; display: grid; place-items: center; padding: 20px; }

.login-form {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  width: min(360px, 100%);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.login-title { margin: 0 0 6px; font-size: 18px; text-align: center; }
.form-error { color: var(--deleted); font-size: 13px; margin: 0; min-height: 1.2em; }

/* 进门前就得说清楚的话（目前只有一处：当前地址存不下登录 cookie）。
 * 摆在密码框上面而不是提交之后——这种「看起来什么都对，就是进不去」
 * 的情况，等人输错三遍才提示就太晚了。 */
.callout {
  border: 1px solid var(--border);
  border-left: 3px solid var(--edited);
  border-radius: var(--radius);
  background: var(--surface-2);
  padding: 12px 14px;
  font-size: 13px;
  line-height: 1.6;
}
.callout.warn { border-left-color: var(--edited); }
.callout strong { display: block; margin-bottom: 6px; color: var(--edited); }
.callout p { margin: 6px 0 0; color: var(--muted); }
.callout p:first-of-type { margin-top: 0; }

/* ---------------------------------------------------------------- 消息卡片 */

.msg, .notif {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid transparent;
  border-radius: var(--radius);
  padding: 12px 14px;
}

/* 主持人的消息挂金色左边框 */
.msg.is-mod { border-left-color: var(--mod); }

/* 被删的整条淡化 + 红色左边框：一眼认得出。
 * **必须写在 .is-mod 后面**——被删的多半正是主持人的消息（这个项目要抓的就是
 * 「主持人偷偷删帖」），两条规则同权重时后写的赢，而「这条没了」比「这是主持人说的」
 * 重要得多，边框得是红的。 */
.msg.is-deleted { border-left-color: var(--deleted); opacity: .82; }

/* 推送流按 kind 分色 */
.notif.kind-edit { border-left-color: var(--edited); }
.notif.kind-delete { border-left-color: var(--deleted); }
.notif.kind-button { border-left-color: var(--button); }

.msg-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}
.author { font-weight: 600; }
.author.moderator { color: var(--mod); }
.star { color: var(--mod); }
.notif-title { font-weight: 600; }
.time { color: var(--text-dim); font-size: 12px; }

.content {
  /* 原文里的换行和缩进要留住——那是他实际敲下的样子 */
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.content.empty { color: var(--text-dim); }
.content.raw {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
  background: var(--surface-2);
  border-radius: 8px;
  padding: 10px;
}
.content.old { background: color-mix(in srgb, var(--diff-del-bg) 40%, transparent); border-radius: 8px; padding: 8px; }
.content.new { background: color-mix(in srgb, var(--diff-ins-bg) 40%, transparent); border-radius: 8px; padding: 8px; }

/* 编辑告警里的增删标记，照终端看 diff 的样子来 */
.diff-del { background: var(--diff-del-bg); color: var(--diff-del-fg); text-decoration: line-through; border-radius: 3px; padding: 0 2px; }
.diff-ins { background: var(--diff-ins-bg); color: var(--diff-ins-fg); text-decoration: none; border-radius: 3px; padding: 0 2px; }

.msg-foot {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-top: 8px;
  font-size: 13px;
}

/* 回复链：整条共用一个引用块（跟 Telegram 那边同一个判断） */
.quote {
  margin: 0 0 8px;
  padding: 8px 10px;
  border-left: 3px solid var(--border);
  background: var(--surface-2);
  border-radius: 0 8px 8px 0;
  font-size: 14px;
}
.quote-head { display: flex; flex-wrap: wrap; gap: 6px; align-items: baseline; margin-bottom: 2px; }
.quote-label { color: var(--text-dim); font-size: 12px; }
.quote-author { font-weight: 600; font-size: 13px; }
.quote-time { color: var(--text-dim); font-size: 12px; }
.quote-body { white-space: pre-wrap; overflow-wrap: anywhere; }
.quote-body.missing { color: var(--text-dim); }
.quote-sep { border-top: 1px dashed var(--border); margin: 8px 0; }

/* ---------------------------------------------------------------- 附件 */

.attachments { margin-top: 10px; display: flex; flex-direction: column; gap: 8px; }
.thumbs { display: flex; flex-wrap: wrap; gap: 8px; }
.thumb {
  width: 140px;
  height: 140px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--border);
  cursor: zoom-in;
  background: var(--surface-2);
}
.file { display: flex; flex-wrap: wrap; gap: 8px; align-items: baseline; font-size: 13px; }
.file-name { font-weight: 500; }
.file.missing .file-name { color: var(--text-dim); text-decoration: line-through; }

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(0, 0, 0, .88);
  display: grid;
  place-items: center;
  padding: 20px;
  cursor: zoom-out;
}
.lightbox-img { max-width: 100%; max-height: 88vh; object-fit: contain; }
.lightbox-bar { position: absolute; bottom: 16px; color: #fff; font-size: 13px; }

/* ---------------------------------------------------------------- 推送流 */

.unread-divider {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-dim);
  font-size: 12px;
}
.unread-divider::before, .unread-divider::after {
  content: '';
  flex: 1;
  border-top: 1px dashed var(--border);
}

/* ---------------------------------------------------------------- 浏览页 */

.sidebar {
  position: sticky;
  top: 64px;
  max-height: calc(100vh - 80px);
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px;
}

.tree-guild { margin-bottom: 14px; }
.tree-guild-name {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-dim);
  padding: 4px 6px;
}

.tree-channel, .tree-thread {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  text-align: left;
  border: none;
  background: transparent;
  color: var(--text);
  font: inherit;
  padding: 5px 8px;
  border-radius: 8px;
  cursor: pointer;
}
.tree-channel:hover, .tree-thread:hover { background: var(--surface-2); }
.tree-channel.active, .tree-thread.active { background: var(--accent); color: #fff; }
.tree-channel.active .count, .tree-thread.active .count { color: #e8eeff; }
.hash { color: var(--text-dim); }
.tree-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.count { font-size: 11px; color: var(--text-dim); }

.tree-fold { margin: 2px 0 6px 14px; }
.tree-fold > summary { cursor: pointer; font-size: 12px; color: var(--text-dim); padding: 2px 6px; }
.tree-threads { display: flex; flex-direction: column; }
.tree-thread { font-size: 13px; }

.filters {
  position: sticky;
  top: 56px;
  z-index: 10;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px;
}
.toggle { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; cursor: pointer; }

/* ---------------------------------------------------------------- 详情 / 编辑历史 */

.detail-head { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.detail-title { font-size: 18px; margin: 0; }
.detail-tools { display: flex; gap: 8px; }
.raw-box:empty { display: none; }

.history { display: flex; flex-direction: column; gap: 12px; }
.edit-entry {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.edit-head { display: flex; gap: 8px; align-items: center; }
.edit-label { font-size: 12px; color: var(--text-dim); }

.drawer {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(0, 0, 0, .5);
  display: flex;
  justify-content: flex-end;
}
.drawer-panel {
  background: var(--bg);
  width: min(560px, 100%);
  height: 100%;
  overflow-y: auto;
  padding: 16px;
  padding-top: calc(16px + env(safe-area-inset-top));
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.drawer-head { display: flex; justify-content: space-between; align-items: center; font-weight: 600; }
.drawer-body { display: flex; flex-direction: column; gap: 12px; }

/* ---------------------------------------------------------------- 设置 */

.settings { gap: 16px; }
.devices { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.device {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
}
.device.disabled { opacity: .7; }
.device-label { font-weight: 600; }

/* ---------------------------------------------------------------- 窄屏 */

@media (max-width: 820px) {
  .page.browse { grid-template-columns: 1fr; }
  .sidebar { position: static; max-height: 300px; }
  .filters { position: static; }
  .thumb { width: 104px; height: 104px; }
}
