/* ==========================================================================
   Portal design system — 主基调取自 Willowsum（暖绿 + 衬线）
   辅助：Index Lantern 的数据卡片 / Mara&Teo 的胶囊标签
   ========================================================================== */

:root {
  /* 基础色板 */
  --canvas:        #f3f0e7;
  --panel:         #fffdf8;
  --forest:        #183b32;
  --forest-deep:   #122c25;
  --forest-soft:   #dce8df;
  --ink:           #202722;
  --muted:         #626d65;
  --rule:          #d8ddd3;
  --chartreuse:    #dce9a8;

  /* 辅助色（胶囊 / 图表 / 状态） */
  --c-1: #2e5b4c;
  --c-2: #7b9870;
  --c-3: #769a9d;
  --c-4: #c97455;
  --c-5: #d0a24d;
  --c-6: #a66558;
  --c-7: #8d7892;
  --c-8: #6e8293;
  --danger: #a34f39;

  /* 字体 */
  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI",
               "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --font-serif: "Fraunces", "Iowan Old Style", Georgia,
                "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", "Noto Sans SC", sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  /* 尺寸 */
  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 14px;
  --r-pill: 999px;
  --sidebar-w: 248px;
  --shadow-card: 0 1px 2px rgba(24, 59, 50, .035);
  --shadow-pop: 0 12px 32px rgba(24, 59, 50, .12);

  color-scheme: light;
}

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

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--canvas);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--forest); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 2px; }

h1, h2, h3 {
  font-family: var(--font-serif);
  font-weight: 600;
  margin: 0;
  letter-spacing: -.4px;
}
h1 { font-size: 34px; line-height: 1.1; letter-spacing: -.85px; }
h2 { font-size: 22px; line-height: 1.2; }
h3 { font-size: 17px; line-height: 1.3; letter-spacing: -.2px; }

p { margin: 0; }

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .5; }
[hidden], output:empty { display: none; }

::selection { background: var(--chartreuse); color: var(--forest); }

/* ---------- 表单原子 ---------- */
label { display: grid; gap: 6px; font-size: 13px; color: var(--muted); }

input[type=text], input[type=email], input[type=password], input[type=number],
input[type=url], input[type=file], select, textarea {
  width: 100%;
  padding: 10px 12px;
  background: var(--panel);
  border: 1px solid var(--rule);
  border-radius: var(--r-sm);
  color: var(--ink);
  font-size: 15px;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--forest);
  box-shadow: 0 0 0 3px rgba(24, 59, 50, .12);
}
input[readonly] { background: #f6f4ee; color: var(--muted); }
textarea { resize: vertical; min-height: 76px; }

/* 文件选择：去掉原生按钮的粗糙感 */
input[type=file] { padding: 8px 10px; cursor: pointer; }
input[type=file]::file-selector-button {
  margin-right: 12px;
  padding: 7px 13px;
  border: 1px solid var(--rule);
  border-radius: var(--r-sm);
  background: #f1efe6;
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  transition: background .15s;
}
input[type=file]::file-selector-button:hover { background: #e9e6da; }

button, .btn {
  padding: 10px 16px;
  border-radius: var(--r-sm);
  border: 1px solid var(--rule);
  background: var(--panel);
  color: var(--ink);
  font-size: 14px;
  font-weight: 500;
  transition: background .15s, border-color .15s, transform .05s;
}
.btn { display: inline-flex; align-items: center; justify-content: center; white-space: nowrap; }
button:hover:not(:disabled), .btn:hover:not(:disabled) { background: #f6f4ee; text-decoration: none; }
button:active:not(:disabled), .btn:active:not(:disabled) { transform: translateY(1px); }

.btn-primary {
  background: var(--forest);
  border-color: var(--forest);
  color: #f2f6f2;
}
.btn-primary:hover:not(:disabled) { background: var(--forest-deep); border-color: var(--forest-deep); }

.btn-ghost { background: transparent; }
.btn-danger { color: var(--danger); border-color: #e3cfc8; }
.btn-danger:hover:not(:disabled) { background: #f8ece8; }

.stack { display: grid; gap: 14px; }
.stack-actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.section-gap { margin-bottom: 22px; }
.section-heading { margin: 24px 0 12px; }
.muted-copy { color: var(--muted); font-size: 14px; }
.panel > .muted-copy + form, .panel > .muted-copy + .stack { margin-top: 14px; }
.page-alert { margin-bottom: 16px; }
.form-panel + .form-panel { margin-top: 16px; }
.field-stack { max-width: 360px; }
.field-stack + .stack-actions, .setup-details + .field-stack { margin-top: 16px; }
.row.form-row { gap: 14px; align-items: flex-end; }
.full-width { width: 100%; }
.empty-panel { text-align: center; padding: 36px 20px; }
.file-scope { min-width: 130px; }
.row.file-line { gap: 10px; }
.copy-actions { margin-top: 10px; }
.copy-actions output { overflow-wrap: anywhere; }
.share-entry { padding: 10px 0; border-top: 1px solid var(--rule); }
.share-entry .stack-actions > input { flex: 1 1 200px; min-width: 0; }

/* ---------- 应用外壳 ---------- */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  min-height: 100vh;
  /* 侧栏是 sticky 100vh，内容更长时下方留白要靠这层底色补齐 */
  background: linear-gradient(
    to right,
    var(--forest) 0 var(--sidebar-w),
    transparent var(--sidebar-w)
  );
}

/* 侧栏 */
.sidebar {
  background: var(--forest);
  color: var(--forest-soft);
  padding: 18px 14px 14px;
  display: flex;
  flex-direction: column;
  gap: 22px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand { display: flex; align-items: center; gap: 11px; padding: 4px 8px 0; }
.brand-mark {
  width: 34px; height: 34px;
  border-radius: 10px;
  background: var(--chartreuse);
  color: var(--forest);
  display: grid; place-items: center;
  font-family: var(--font-serif);
  font-size: 18px; font-weight: 600;
  flex: none;
}
.brand-text { display: grid; gap: 1px; min-width: 0; }
.brand-name {
  font-family: var(--font-serif);
  font-size: 19px;
  font-weight: 600;
  color: #f4f8f4;
  letter-spacing: -.3px;
}
.brand-sub { font-size: 11px; color: #9db3a7; letter-spacing: .06em; text-transform: uppercase; }

.side-nav { display: grid; gap: 3px; }
.side-nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 11px;
  border-radius: var(--r-sm);
  color: #c3d4c9;
  font-size: 14.5px;
  transition: background .15s, color .15s;
}
.side-nav a:hover { background: rgba(255,255,255,.07); color: #eef5ef; text-decoration: none; }
.side-nav a[aria-current="page"] {
  background: var(--forest-soft);
  color: var(--forest);
  font-weight: 600;
}
.side-nav a[aria-current="page"] .nav-ico { opacity: 1; }
.nav-ico { width: 17px; text-align: center; opacity: .8; font-size: 15px; }

.side-foot {
  margin-top: auto;
  border-top: 1px solid rgba(220,232,223,.16);
  padding-top: 14px;
  display: grid;
  gap: 10px;
}
.who { display: flex; align-items: center; gap: 10px; min-width: 0; }
.avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--chartreuse); color: var(--forest);
  display: grid; place-items: center;
  font-size: 13px; font-weight: 600; flex: none;
}
.who-meta { display: grid; min-width: 0; }
.who-name { font-size: 13.5px; color: #eef5ef; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who-sub { font-size: 11px; color: #92a89b; }
.side-foot form button {
  width: 100%;
  background: transparent;
  border-color: rgba(220,232,223,.22);
  color: #c3d4c9;
  font-size: 13px;
  padding: 8px 10px;
}
.side-foot form button:hover:not(:disabled) { background: rgba(255,255,255,.07); }

/* 主区 */
.main { display: flex; flex-direction: column; min-width: 0; }

.topbar {
  display: flex; align-items: center; gap: 14px;
  padding: 16px 26px;
  border-bottom: 1px solid var(--rule);
  background: rgba(243,240,231,.86);
  backdrop-filter: blur(6px);
  position: sticky; top: 0; z-index: 5;
}
.crumbs { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.crumbs .sep { opacity: .5; }
.crumbs strong { color: var(--ink); font-weight: 500; }
.topbar-actions { margin-left: auto; display: flex; gap: 8px; align-items: center; }

.content { padding: 26px; max-width: 1180px; width: 100%; }

.page-head { display: grid; gap: 6px; margin-bottom: 22px; }
.page-head .eyebrow {
  font-family: var(--font-mono);
  font-size: 11px; letter-spacing: .12em; text-transform: uppercase;
  color: var(--muted);
}
.page-head p { color: var(--muted); font-size: 14.5px; max-width: 62ch; }

/* ---------- 卡片 ---------- */
.panel {
  background: var(--panel);
  border: 1px solid var(--rule);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-card);
  padding: 20px;
}
.panel-head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 12px; margin-bottom: 14px;
}
.panel-head h2, .panel-head h3 { margin: 0; }
.panel-head .more { font-size: 13px; color: var(--muted); }

/* 统计块 */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0;
  background: var(--panel);
  border: 1px solid var(--rule);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-card);
  overflow: hidden;
}
.stat { padding: 18px 20px; display: grid; gap: 6px; border-right: 1px solid var(--rule); min-width: 0; }
.stat:last-child { border-right: none; }
.stat-label { font-size: 12px; color: var(--muted); }
.stat-value {
  font-family: var(--font-serif);
  font-size: 27px; font-weight: 600; letter-spacing: -.6px;
  font-variant-numeric: tabular-nums;
}
.stat-value small { font-family: var(--font-sans); font-size: 13px; color: var(--muted); font-weight: 400; margin-left: 2px; }
.stat-value.text {
  font-family: var(--font-sans); font-size: 16px; letter-spacing: 0; font-weight: 500;
  overflow-wrap: anywhere;
}
.stat.highlight { background: var(--chartreuse); }
.stat-note { font-size: 12px; color: var(--muted); }

/* 进度条 */
.meter { display: block; width: 100%; height: 10px; accent-color: var(--forest); }
.meter[hidden] { display: none; }

/* 模块卡片网格 */
.cards {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 14px;
}
.card-link {
  grid-column: span 2;
  display: grid; gap: 10px;
  padding: 18px;
  background: var(--panel);
  border: 1px solid var(--rule);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-card);
  color: var(--ink);
  transition: border-color .15s, transform .15s, box-shadow .15s;
}
.card-link:nth-child(n + 4) { grid-column: span 3; }
.card-link:hover {
  text-decoration: none;
  border-color: #b9c7bd;
  transform: translateY(-2px);
  box-shadow: 0 6px 18px rgba(24,59,50,.08);
}
.card-top { display: flex; align-items: center; gap: 10px; }
.card-glyph {
  width: 34px; height: 34px; border-radius: 10px;
  display: grid; place-items: center;
  background: var(--forest-soft); color: var(--forest);
  font-size: 16px; flex: none;
}
.card-glyph.small { width: 30px; height: 30px; border-radius: 9px; font-size: 14px; }
.empty-panel .card-glyph { margin: 0 auto 14px; }
.card-link h3 { font-size: 16.5px; }
.card-link p { font-size: 13px; color: var(--muted); line-height: 1.45; }
.card-metric {
  font-family: var(--font-mono);
  font-size: 12px; color: var(--muted);
  margin-top: 2px;
}

/* ---------- 胶囊标签 ---------- */
.chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 9px;
  border-radius: var(--r-pill);
  font-size: 12px; font-weight: 500;
  background: var(--forest-soft); color: var(--forest-deep);
  white-space: nowrap;
}
.chip-muted { background: #eceadf; color: var(--muted); }
.chip-warn  { background: #f6e6c8; color: #7a5a15; }
.chip-danger{ background: #f4e0da; color: var(--danger); }
.chip-1 { background: #e3ece7; color: var(--c-1); }
.chip-2 { background: #e9eee4; color: #4d6644; }
.chip-3 { background: #e2ecec; color: #40676a; }
.chip-4 { background: #f7e6df; color: #8b452b; }
.chip-5 { background: #f7ecd6; color: #7d5c1c; }
.chip-7 { background: #eee8f0; color: #5c4a63; }
.chip-8 { background: #e4eaf0; color: #465a70; }

/* ---------- 列表 / 表格 ---------- */
.list { display: grid; gap: 10px; margin: 0; padding: 0; list-style: none; }
.list-item {
  background: var(--panel);
  border: 1px solid var(--rule);
  border-radius: var(--r-md);
  padding: 14px 16px;
  display: grid; gap: 10px;
}
.row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.grow { flex: 1 1 auto; min-width: 0; }
.filename {
  font-weight: 500;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.meta { font-size: 12.5px; color: var(--muted); font-variant-numeric: tabular-nums; }

.table-scroll { overflow-x: auto; }
.table-scroll .table { min-width: 920px; overflow-wrap: anywhere; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th {
  text-align: left; font-weight: 500; font-size: 12px;
  color: var(--muted); letter-spacing: .04em; text-transform: uppercase;
  padding: 0 10px 9px; border-bottom: 1px solid var(--rule);
}
.table td { padding: 11px 10px; border-bottom: 1px solid #eceae1; }
.table tr:last-child td { border-bottom: none; }

/* details / 折叠 */
details > summary {
  cursor: pointer; font-size: 13px; color: var(--muted);
  list-style: none; display: inline-flex; align-items: center; gap: 6px;
  user-select: none;
}
details > summary::-webkit-details-marker { display: none; }
details > summary::before {
  content: "＋"; font-size: 12px; opacity: .6;
}
details[open] > summary::before { content: "－"; }
details > *:not(summary) { margin-top: 12px; }

/* ---------- 认证页 ---------- */
.auth-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 32px 20px;
  background-color: var(--canvas);
  background-image:
    radial-gradient(circle at 1px 1px, rgba(24, 59, 50, .10) 1px, transparent 0),
    radial-gradient(1100px 520px at 12% -8%, #e9efe2 0%, transparent 58%),
    radial-gradient(900px 460px at 92% 108%, #ecebdd 0%, transparent 55%),
    radial-gradient(760px 520px at 50% 44%, rgba(255, 253, 248, .9) 0%, transparent 74%);
  background-size: 22px 22px, auto, auto, auto;
  background-position: 0 0, 0 0, 0 0, center;
}
.auth-card {
  width: 100%;
  max-width: 404px;
  background: var(--panel);
  border: 1px solid var(--rule);
  border-radius: 18px;
  box-shadow: 0 18px 44px rgba(24,59,50,.09);
  padding: 32px 30px 28px;
  display: grid;
  gap: 20px;
}
.auth-brand { display: flex; align-items: center; gap: 11px; }
.auth-brand .brand-name { color: var(--forest); }
.auth-brand .brand-sub { color: var(--muted); }
.auth-head { display: grid; gap: 6px; }
.auth-head h1 { font-size: 27px; letter-spacing: -.6px; }
.auth-head p { font-size: 13.5px; color: var(--muted); }
.auth-card .stack { gap: 13px; }
.auth-card button[type=submit] {
  background: var(--forest); border-color: var(--forest); color: #f2f6f2;
  padding: 12px 16px; font-size: 15px; font-weight: 500;
}
.auth-card button[type=submit]:hover:not(:disabled) { background: var(--forest-deep); }
.auth-foot { font-size: 12px; color: var(--muted); text-align: center; }

.notice {
  border: 1px solid #cfdcc2;
  background: #f2f7ea;
  color: #2f4a2f;
  border-radius: var(--r-md);
  padding: 10px 13px;
  font-size: 13.5px;
  margin-bottom: 14px;
}

/* 下载页 */
.mirror-url {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--forest);
  background: #f1efe6;
  border: 1px solid var(--rule);
  border-radius: var(--r-sm);
  padding: 9px 12px;
  word-break: break-all;
  margin: 14px 0 10px;
}
.codeblock {
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.65;
  background: var(--forest-deep);
  color: #dfe8dc;
  border-radius: var(--r-md);
  padding: 13px 15px;
  overflow-x: auto;
  margin: 0;
}
.verify-options { display: grid; gap: 12px; }
.verify-options .stack { margin-top: 12px; }
.verify-card { border: 1px solid var(--rule); border-radius: var(--r-md); padding: 16px; background: #fffefb; }
.verify-card > summary { font-size: 14px; color: var(--ink); font-weight: 500; }
.verify-card[open] { border-color: #c4d2c8; }
.verify-hint { font-size: 12.5px; color: var(--muted); }
.verify-disabled { opacity: .62; }

/* 提示条 */
.alert {
  border-radius: var(--r-sm);
  padding: 10px 13px;
  font-size: 13.5px;
  background: #f4e0da; color: var(--danger);
  border: 1px solid #e6cdc5;
}
.alert-ok { background: #e6efe6; color: #2f5b3c; border-color: #cfe0d2; }
.alert-info { background: #eef1e6; color: #4c5a44; border-color: #dde3d2; }

/* ---------- 聊天 ---------- */
.chat-shell { display: grid; grid-template-columns: minmax(230px, 300px) minmax(0, 1fr); gap: 16px; align-items: start; }
.chat-shell [hidden], #conversation-dialog [hidden] { display: none; }
.chat-sidebar, .chat-main { min-width: 0; }
.chat-sidebar .list { max-height: 68vh; overflow-y: auto; padding: 2px; }
.chat-main .panel-head { margin-bottom: 0; }
#chat-title { overflow-wrap: anywhere; }
.chat-actions { justify-content: flex-end; align-items: flex-end; }
.conversation-button {
  width: 100%; display: grid; grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center; gap: 9px; padding: 10px; text-align: left;
}
.conversation-button[aria-current="true"] { background: var(--forest-soft); border-color: var(--forest); }
.conversation-copy, .conversation-meta { display: grid; min-width: 0; }
.conversation-meta { justify-items: end; gap: 4px; }
.conversation-meta time { font-size: 11px; }
.conversation-unread {
  min-width: 17px; border-radius: var(--r-pill); padding: 0 4px;
  background: var(--danger); color: white; font-size: 11px; text-align: center;
}
#conversation-dialog { width: min(420px, calc(100% - 32px)); }
#conversation-dialog::backdrop { background: rgba(18, 44, 37, .38); }
#group-contacts fieldset { min-width: 0; border: 1px solid var(--rule); border-radius: var(--r-md); }
#contact-options { display: grid; gap: 6px; max-height: 30vh; overflow-y: auto; }
#contact-options label { display: flex; align-items: center; overflow-wrap: anywhere; }
.messages {
  list-style: none; margin: 0; padding: 16px;
  display: grid; gap: 10px;
  min-height: 260px;
  max-height: 52vh; overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--rule);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-card);
  align-content: start;
  overflow-anchor: none;
}
.messages:empty::after {
  content: "还没有消息。";
  color: var(--muted);
  font-size: 13.5px;
  align-self: center;
  justify-self: center;
  padding: 40px 0;
}
.msg { display: grid; gap: 4px; max-width: 76%; }
.msg-meta { font-size: 11px; color: var(--muted); font-family: var(--font-mono); }
.msg-body {
  padding: 9px 13px;
  border-radius: 12px;
  background: #f1efe6;
  font-size: 14.5px;
  white-space: pre-wrap;
  word-break: break-word;
}
.msg.mine { margin-left: auto; }
.msg.mine .msg-body { background: var(--forest); color: #f1f6f1; }
.msg.mine .msg-meta { text-align: right; }
.msg-attach { font-size: 12.5px; overflow-wrap: anywhere; }
#older-messages { justify-self: center; }

/* ---------- 响应式 ---------- */
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; background: none; }
  .sidebar {
    position: static; height: auto; flex-direction: row;
    align-items: center; gap: 14px; padding: 12px 14px;
    overflow-x: auto;
  }
  .side-nav { display: flex; gap: 4px; flex: 1 1 auto; min-width: 0; }
  .side-nav a { white-space: nowrap; padding: 8px 10px; }
  .side-foot { margin: 0; border: none; padding: 0; }
  .side-foot .who, .brand-sub { display: none; }
  .content { padding: 18px 16px; }
  .topbar { padding: 12px 16px; }
  h1 { font-size: 27px; letter-spacing: -.5px; }
  .stats { grid-template-columns: 1fr 1fr; }
  .stat { border-bottom: 1px solid var(--rule); }
}
@media (max-width: 630px) {
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .cards .card-link { grid-column: auto; }
  .cards .card-link:last-child { grid-column: 1 / -1; }
  .chat-shell { grid-template-columns: minmax(0, 1fr); }
  .chat-sidebar .list { max-height: 26vh; }
}
