/*
 * Nodal 的样式。一个群聊产品:左边群列表,右边聊天,其余页面是窄栏的卡片。
 * 克制的浅色界面、圆角卡片配发丝阴影、无边框的浅色填充控件、系统字体;强调色是一种偏青的绿。
 *
 * Token 只有一套,分三段:浅色(默认)、跟随系统的深色、显式选择的深色。后两段内容相同 ——
 * 一段给"跟随系统",一段给"手动选了深色"。用到的每一个变量都要在这里定义,scripts/check.ts 会查。
 */

:root {
  --bg: #F2F4F5;
  --surface: #FFFFFF;
  --surface-2: #F7F8F9;
  --fill: rgba(17, 24, 39, 0.05);
  --fill-strong: rgba(17, 24, 39, 0.09);
  --line: rgba(17, 24, 39, 0.08);
  --text: #111318;
  --text-2: #5C6270;
  --text-3: #8A909C;
  --accent: #0E8A6A;
  --accent-text: #0B7558;
  --accent-soft: rgba(14, 138, 106, 0.10);
  --accent-soft-strong: rgba(14, 138, 106, 0.18);
  --on-accent: #FFFFFF;
  --mine: #D9F4E8;
  --focus: rgba(14, 138, 106, 0.6);
  --shadow-card: 0 1px 2px rgba(16, 24, 40, 0.04), 0 8px 24px rgba(16, 24, 40, 0.05);
  --shadow-pop: 0 12px 40px rgba(16, 24, 40, 0.16);
  --warn-bg: rgba(234, 138, 24, 0.14);
  --warn-text: #9A4D00;
  --danger-bg: rgba(220, 53, 38, 0.10);
  --danger-text: #B42318;
  --mono-1-bg: #E6F2EC; --mono-1-text: #17664A;
  --mono-2-bg: #F7ECE5; --mono-2-text: #9A4A22;
  --mono-3-bg: #FDF1E2; --mono-3-text: #9A5300;
  --mono-4-bg: #E8F1FC; --mono-4-text: #1F5AB4;
  --mono-5-bg: #EEEBFB; --mono-5-text: #5440C2;
  --mono-6-bg: #ECEDF0; --mono-6-text: #3B4250;
  --backdrop: rgba(15, 18, 26, 0.32);
  --radius-card: 18px;
  --radius-control: 12px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --mono-font: "SF Mono", ui-monospace, Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0A0F0E;
    --surface: #121A18;
    --surface-2: #17211F;
    --fill: rgba(255, 255, 255, 0.06);
    --fill-strong: rgba(255, 255, 255, 0.11);
    --line: rgba(255, 255, 255, 0.08);
    --text: #EDF3F1;
    --text-2: #A2B0AC;
    --text-3: #6E7C78;
    --accent: #2BAE88;
    --accent-text: #6FDDB8;
    --accent-soft: rgba(111, 221, 184, 0.14);
    --accent-soft-strong: rgba(111, 221, 184, 0.24);
    --mine: #163A2F;
    --focus: rgba(111, 221, 184, 0.7);
    --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.30), 0 10px 28px rgba(0, 0, 0, 0.26);
    --shadow-pop: 0 12px 40px rgba(0, 0, 0, 0.5);
    --warn-bg: rgba(255, 159, 64, 0.16);
    --warn-text: #FFBD7A;
    --danger-bg: rgba(255, 99, 82, 0.16);
    --danger-text: #FF948A;
    --mono-1-bg: rgba(127, 217, 168, 0.15); --mono-1-text: #7FD9A8;
    --mono-2-bg: rgba(242, 169, 133, 0.15); --mono-2-text: #F2A985;
    --mono-3-bg: rgba(255, 194, 122, 0.15); --mono-3-text: #FFC27A;
    --mono-4-bg: rgba(141, 184, 255, 0.15); --mono-4-text: #8DB8FF;
    --mono-5-bg: rgba(150, 130, 255, 0.18); --mono-5-text: #BCB0FF;
    --mono-6-bg: rgba(214, 217, 224, 0.15); --mono-6-text: #D6D9E0;
    --backdrop: rgba(0, 0, 0, 0.55);
  }
}

:root[data-theme="dark"] {
  --bg: #0A0F0E;
  --surface: #121A18;
  --surface-2: #17211F;
  --fill: rgba(255, 255, 255, 0.06);
  --fill-strong: rgba(255, 255, 255, 0.11);
  --line: rgba(255, 255, 255, 0.08);
  --text: #EDF3F1;
  --text-2: #A2B0AC;
  --text-3: #6E7C78;
  --accent: #2BAE88;
  --accent-text: #6FDDB8;
  --accent-soft: rgba(111, 221, 184, 0.14);
  --accent-soft-strong: rgba(111, 221, 184, 0.24);
  --mine: #163A2F;
  --focus: rgba(111, 221, 184, 0.7);
  --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.30), 0 10px 28px rgba(0, 0, 0, 0.26);
  --shadow-pop: 0 12px 40px rgba(0, 0, 0, 0.5);
  --warn-bg: rgba(255, 159, 64, 0.16);
  --warn-text: #FFBD7A;
  --danger-bg: rgba(255, 99, 82, 0.16);
  --danger-text: #FF948A;
  --mono-1-bg: rgba(127, 217, 168, 0.15); --mono-1-text: #7FD9A8;
  --mono-2-bg: rgba(242, 169, 133, 0.15); --mono-2-text: #F2A985;
  --mono-3-bg: rgba(255, 194, 122, 0.15); --mono-3-text: #FFC27A;
  --mono-4-bg: rgba(141, 184, 255, 0.15); --mono-4-text: #8DB8FF;
  --mono-5-bg: rgba(150, 130, 255, 0.18); --mono-5-text: #BCB0FF;
  --mono-6-bg: rgba(214, 217, 224, 0.15); --mono-6-text: #D6D9E0;
  --backdrop: rgba(0, 0, 0, 0.55);
}

/* ---------------------------------------------------------------- 基础 */

*, *::before, *::after { box-sizing: border-box; }

html, body { margin: 0; }

body {
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

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

button, input, select, textarea { font: inherit; color: inherit; }

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

h1, h2, h3, p { margin: 0; }
h1 { font-size: 22px; font-weight: 700; }
h2 { font-size: 17px; font-weight: 650; }
h3 { font-size: 15px; font-weight: 600; }

/* hidden 要真的藏住:自带 display 的元素会盖掉浏览器默认的 [hidden] 样式 */
[hidden] { display: none !important; }

.skip-link {
  position: absolute; left: 16px; top: -48px; z-index: 50;
  padding: 10px 16px; border-radius: 999px;
  background: var(--surface); color: var(--text); box-shadow: var(--shadow-pop);
}
.skip-link:focus { top: 16px; }

.boot { padding: 120px 24px; text-align: center; color: var(--text-2); }

.muted { color: var(--text-2); }
.small { font-size: 12px; }
.center { text-align: center; }
.grow { flex: 1; min-width: 0; }
.pre { white-space: pre-wrap; overflow-wrap: anywhere; }
.break { overflow-wrap: anywhere; word-break: break-all; }
.icon { flex: none; }

/* ---------------------------------------------------------------- 版面 */

.page { padding: 24px 16px 64px; }
.page:has(> .space-layout) { padding: 0; }

.narrow { max-width: 640px; margin: 0 auto; }
.stack { display: flex; flex-direction: column; gap: 16px; }
.stack-tight { display: flex; flex-direction: column; gap: 4px; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.page-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.page-head h1 { overflow-wrap: anywhere; }

.card {
  padding: 20px;
  border-radius: var(--radius-card);
  background: var(--surface);
  box-shadow: var(--shadow-card);
}
.card.center { align-items: center; }
.danger-zone h2 { color: var(--danger-text); }

.empty { padding: 48px 24px; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 8px; color: var(--text-2); }
.empty h3 { color: var(--text); font-size: 17px; }
.empty .btn { margin-top: 8px; }

/* ---------------------------------------------------------------- 控件 */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 38px; padding: 0 16px;
  border: 0; border-radius: 999px;
  background: var(--fill); color: var(--text);
  font-weight: 600; cursor: pointer; white-space: nowrap; text-decoration: none;
}
.btn:hover { background: var(--fill-strong); text-decoration: none; }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn-primary { background: var(--accent); color: var(--on-accent); }
.btn-primary:hover { background: var(--accent); filter: brightness(1.06); }
.btn-danger { background: var(--danger-bg); color: var(--danger-text); }
.btn-danger:hover { background: var(--danger-bg); filter: brightness(0.97); }
.btn-small { height: 30px; padding: 0 12px; font-size: 13px; }
.btn-block { width: 100%; }
.btn-link { height: auto; padding: 4px 0; background: transparent; color: var(--accent-text); }
.btn-link:hover { background: transparent; text-decoration: underline; }

.btn-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; flex: none;
  border: 0; border-radius: 999px;
  background: transparent; color: var(--text-2); cursor: pointer;
}
.btn-icon:hover { background: var(--fill); color: var(--text); }

.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-weight: 600; }
.field-hint { color: var(--text-2); font-size: 12px; }

.input, .select, .textarea {
  width: 100%; min-height: 40px; padding: 8px 12px;
  border: 0; border-radius: var(--radius-control);
  background: var(--fill); color: var(--text);
}
.textarea { resize: vertical; line-height: 1.5; }
.input:focus-visible, .select:focus-visible, .textarea:focus-visible { box-shadow: 0 0 0 3px var(--accent-soft-strong); outline: none; }
.row .select { width: auto; }

.check { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; font-size: 13px; color: var(--text-2); }

.seg { display: inline-flex; padding: 3px; gap: 2px; border-radius: 999px; background: var(--fill); flex-wrap: wrap; align-self: flex-start; }
.seg label { position: relative; height: 32px; padding: 0 14px; border-radius: 999px; color: var(--text-2); font-size: 13px; font-weight: 600; cursor: pointer; display: inline-flex; align-items: center; }
.seg label:has(input:checked) { background: var(--surface); color: var(--text); box-shadow: var(--shadow-card); }
.seg label:has(input:focus-visible) { outline: 2px solid var(--focus); outline-offset: 1px; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }

.chip { display: inline-flex; align-items: center; height: 20px; padding: 0 8px; border-radius: 999px; background: var(--accent-soft); color: var(--accent-text); font-size: 11px; font-weight: 600; white-space: nowrap; }
.chip-muted { background: var(--fill); color: var(--text-2); }

.badge { min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px; background: var(--accent); color: var(--on-accent); font-size: 11px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; }

.avatar { width: 36px; height: 36px; flex: none; border-radius: 12px; display: inline-flex; align-items: center; justify-content: center; font-weight: 700; }
.avatar-1 { background: var(--mono-1-bg); color: var(--mono-1-text); }
.avatar-2 { background: var(--mono-2-bg); color: var(--mono-2-text); }
.avatar-3 { background: var(--mono-3-bg); color: var(--mono-3-text); }
.avatar-4 { background: var(--mono-4-bg); color: var(--mono-4-text); }
.avatar-5 { background: var(--mono-5-bg); color: var(--mono-5-text); }
.avatar-6 { background: var(--mono-6-bg); color: var(--mono-6-text); }

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

.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.login-card { width: 100%; max-width: 400px; padding: 28px; border-radius: var(--radius-card); background: var(--surface); box-shadow: var(--shadow-card); display: flex; flex-direction: column; gap: 16px; }
.login-body, .login-alt { display: flex; flex-direction: column; gap: 12px; }
.login-foot { padding-top: 8px; border-top: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 10px; font-size: 18px; font-weight: 700; }
.brand-mark { width: 32px; height: 32px; border-radius: 10px; background: var(--accent); color: var(--on-accent); display: inline-flex; align-items: center; justify-content: center; }
.divider { display: flex; align-items: center; gap: 12px; color: var(--text-3); font-size: 12px; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }

/* ---------------------------------------------------------------- 首页 */

.space-list, .group-list, .member-list, .invite-list, .mark-list, .mention-list { list-style: none; margin: 0; padding: 0; }
.space-list { display: flex; flex-direction: column; gap: 10px; }
.space-card { display: flex; align-items: center; gap: 12px; padding: 14px 16px; border-radius: var(--radius-card); background: var(--surface); box-shadow: var(--shadow-card); color: var(--text); }
.space-card:hover { text-decoration: none; background: var(--surface-2); }
.space-name { font-weight: 650; overflow-wrap: anywhere; }

/* ---------------------------------------------------------------- 空间:群列表 + 聊天 */

.space-layout { display: grid; grid-template-columns: 280px minmax(0, 1fr); height: 100vh; height: 100dvh; }

.sidebar { display: flex; flex-direction: column; gap: 8px; padding: 16px 12px; overflow-y: auto; background: var(--surface-2); border-right: 1px solid var(--line); }
.sidebar-head { display: flex; flex-direction: column; gap: 6px; padding: 0 4px 8px; }
.sidebar-head .btn-link { align-self: flex-start; }
.space-title { font-size: 19px; overflow-wrap: anywhere; }
.sidebar-links { display: flex; gap: 6px; flex-wrap: wrap; padding-top: 4px; }
.sidebar-section { padding: 8px 8px 0; }
.group-list { display: flex; flex-direction: column; gap: 2px; }
.group-link { display: flex; align-items: center; gap: 8px; min-height: 40px; padding: 8px 10px; border-radius: 10px; color: var(--text); }
.group-link:hover { background: var(--fill); text-decoration: none; }
.group-link[aria-current="page"] { background: var(--accent-soft); color: var(--accent-text); font-weight: 600; }
.group-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.chat-area { display: flex; flex-direction: column; min-height: 0; background: var(--surface); }
.chat-pane { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.mobile-back { display: none; }
.chat { flex: 1; display: flex; flex-direction: column; min-height: 0; }

.chat-head { display: flex; align-items: center; gap: 6px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.chat-head .grow { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.chat-head h2 { overflow-wrap: anywhere; }

.banner { display: flex; gap: 10px; align-items: flex-start; margin: 12px 16px 0; padding: 12px 14px; border-radius: 14px; background: var(--warn-bg); color: var(--text); }
.banner .icon { color: var(--warn-text); margin-top: 3px; }
.banner strong { color: var(--warn-text); }

.message-scroll { flex: 1; overflow-y: auto; padding: 8px 16px 16px; overscroll-behavior: contain; }
.load-earlier { display: block; margin: 4px auto 8px; }
.messages { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.no-messages { padding: 48px 0; }

.msg { position: relative; display: flex; gap: 10px; padding: 6px 8px; border-radius: 12px; }
.msg:hover, .msg:focus-within { background: var(--surface-2); }
.msg-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.msg-meta { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.msg-text { align-self: flex-start; max-width: 100%; padding: 8px 12px; border-radius: 4px 14px 14px 14px; background: var(--fill); }
.msg-mine .msg-text { background: var(--mine); }
.msg-announcement .msg-text { background: var(--warn-bg); }
.msg-recalled .msg-main > p { font-style: italic; }
.msg-text a { overflow-wrap: anywhere; }
.tag { display: inline-flex; align-items: center; gap: 4px; margin-right: 6px; color: var(--accent-text); }
.msg-announcement .tag { color: var(--warn-text); }
.mark { display: inline-flex; color: var(--warn-text); }
.quote { align-self: flex-start; max-width: 100%; padding: 4px 10px; border-left: 3px solid var(--line); color: var(--text-2); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.msg-actions { position: absolute; top: -10px; right: 8px; display: none; gap: 2px; padding: 2px; border-radius: 10px; background: var(--surface); box-shadow: var(--shadow-card); }
.msg:hover .msg-actions, .msg:focus-within .msg-actions { display: flex; }
@media (hover: none) {
  /* 触屏没有悬停:操作常驻在消息下方 */
  .msg-actions { position: static; display: flex; align-self: flex-end; box-shadow: none; background: transparent; }
  .msg { flex-wrap: wrap; }
}

.composer-slot { border-top: 1px solid var(--line); }
.composer { display: flex; flex-direction: column; gap: 8px; padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); }
.composer .textarea { min-height: 44px; max-height: 40vh; }
.composer-bar { display: flex; align-items: center; gap: 8px; }
.composer-note { padding: 16px; text-align: center; }
.reply-chip { display: flex; align-items: center; gap: 8px; padding: 4px 4px 4px 12px; border-radius: 10px; background: var(--fill); font-size: 13px; color: var(--text-2); }
.reply-slot:empty { display: none; }

.join-note { max-width: 480px; padding: 12px 14px; border-radius: 12px; background: var(--fill); color: var(--text); text-align: left; white-space: pre-wrap; overflow-wrap: anywhere; }

.mark-list { display: flex; flex-direction: column; gap: 12px; max-height: 60vh; overflow-y: auto; }
.mark-list li { display: flex; flex-direction: column; gap: 4px; padding: 10px 12px; border-radius: 12px; background: var(--fill); }

.mention-list { display: flex; flex-direction: column; gap: 2px; max-height: 50vh; overflow-y: auto; }
.mention-option { display: flex; align-items: center; gap: 10px; width: 100%; padding: 6px 8px; border: 0; border-radius: 10px; background: transparent; cursor: pointer; text-align: left; }
.mention-option:hover { background: var(--fill); }
.mention-option .avatar { width: 28px; height: 28px; border-radius: 9px; font-size: 12px; }

/* ---------------------------------------------------------------- 成员、邀请 */

.member-list, .invite-list { display: flex; flex-direction: column; gap: 4px; }
.member-row, .invite-row { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 14px; background: var(--surface); }
.member-row strong { overflow-wrap: anywhere; }
.invite-row { flex-wrap: wrap; box-shadow: var(--shadow-card); }
.invite-row code { font-family: var(--mono-font); font-size: 12px; }
.invite-dead { opacity: 0.6; }
.qr { align-self: center; border-radius: 12px; }

/* ---------------------------------------------------------------- 对话框、提示 */

dialog { width: min(480px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); padding: 0; border: 0; border-radius: var(--radius-card); background: var(--surface); color: var(--text); box-shadow: var(--shadow-pop); }
dialog::backdrop { background: var(--backdrop); }
.dialog-body { padding: 24px; display: flex; flex-direction: column; gap: 16px; }
.dialog-body h2 { font-size: 18px; overflow-wrap: anywhere; }
.dialog-body.center { align-items: center; }
.dialog-body section { gap: 8px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }

.toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 60; max-width: calc(100vw - 32px); }
.toast { display: flex; align-items: center; gap: 12px; padding: 12px 14px 12px 16px; border-radius: 14px; background: var(--text); color: var(--bg); box-shadow: var(--shadow-pop); }
.toast-danger { background: var(--danger-text); color: #FFFFFF; }
.toast button { border: 0; background: transparent; color: inherit; cursor: pointer; font-size: 16px; line-height: 1; }

/* ---------------------------------------------------------------- 手机 */

@media (max-width: 767px) {
  /* 一次一栏:地址里有群就是聊天,没有就是群列表 */
  .space-layout { grid-template-columns: minmax(0, 1fr); }
  .space-layout.has-group .sidebar { display: none; }
  .space-layout:not(.has-group) .chat-area { display: none; }
  .sidebar { border-right: 0; }
  .mobile-back { display: inline-flex; align-self: flex-start; margin: 8px 12px 0; }
  .chat-head { padding: 8px 12px; }
  .message-scroll { padding: 8px 8px 16px; }
  .composer { padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); }
  .card { padding: 16px; }
}

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