/* 群务台 v4 · 移动优先样式（无框架、无 CDN）
   设计约束：375px 视口零横向滚动；深色模式跟随系统并可手动覆盖。 */

:root {
  color-scheme: light;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Microsoft YaHei", "Noto Sans CJK SC", "Source Han Sans SC", sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Courier New", monospace;

  --bg: #f4f5f7;
  --bg-elev: #ffffff;
  --bg-sunk: #eceef3;
  --fg: #16181d;
  --fg-dim: #5a626f;
  --fg-mute: #8b93a1;
  --line: #e3e6ec;
  --line-strong: #c8ced9;

  --brand: #2f6fed;
  --brand-fg: #ffffff;
  --brand-soft: #e8f0ff;

  --ok: #13855b;
  --ok-soft: #e5f6ee;
  --warn: #a86800;
  --warn-soft: #fff4e0;
  --danger: #d13a34;
  --danger-soft: #fdecea;

  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 6px 18px rgba(16, 24, 40, 0.05);
  --tab-h: 58px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #101215;
    --bg-elev: #181b20;
    --bg-sunk: #22262d;
    --fg: #e9ecf1;
    --fg-dim: #a8b0bd;
    --fg-mute: #7d8794;
    --line: #262b33;
    --line-strong: #39414d;
    --brand: #6d9bff;
    --brand-fg: #0b1020;
    --brand-soft: #1b2740;
    --ok: #43c08c;
    --ok-soft: #16281f;
    --warn: #e0a83c;
    --warn-soft: #2b2314;
    --danger: #ff6b62;
    --danger-soft: #2c1a19;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 6px 18px rgba(0, 0, 0, 0.3);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #101215;
  --bg-elev: #181b20;
  --bg-sunk: #22262d;
  --fg: #e9ecf1;
  --fg-dim: #a8b0bd;
  --fg-mute: #7d8794;
  --line: #262b33;
  --line-strong: #39414d;
  --brand: #6d9bff;
  --brand-fg: #0b1020;
  --brand-soft: #1b2740;
  --ok: #43c08c;
  --ok-soft: #16281f;
  --warn: #e0a83c;
  --warn-soft: #2b2314;
  --danger: #ff6b62;
  --danger-soft: #2c1a19;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 6px 18px rgba(0, 0, 0, 0.3);
}

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

html,
body {
  margin: 0;
  padding: 0;
  max-width: 100%;
  overflow-x: hidden;
}

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

body {
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.55 var(--font);
  padding-bottom: env(safe-area-inset-bottom, 0);
  -webkit-tap-highlight-color: transparent;
}

img,
svg,
video,
canvas {
  max-width: 100%;
  height: auto;
}

a {
  color: var(--brand);
  text-decoration: none;
}

pre,
code {
  font-family: var(--mono);
  font-size: 13px;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
  margin: 0;
}

/* ---------------- 骨架布局 ---------------- */

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

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px calc(10px + env(safe-area-inset-top, 0px));
  background: var(--bg-elev);
  border-bottom: 1px solid var(--line);
}

.topbar .titles {
  flex: 1 1 auto;
  min-width: 0;
}

.topbar h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 650;
  line-height: 1.3;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar .sub {
  color: var(--fg-dim);
  font-size: 12px;
  line-height: 1.4;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.icon-btn {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  padding: 0;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--bg-sunk);
  color: var(--fg);
  font-size: 16px;
  cursor: pointer;
}

.icon-btn:active {
  background: var(--brand-soft);
}

.view {
  flex: 1 1 auto;
  width: 100%;
  max-width: 760px;
  margin: 0 auto;
  padding: 12px 12px calc(var(--tab-h) + 28px + env(safe-area-inset-bottom, 0px));
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* ---------------- 通用组件 ---------------- */

.card {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  box-shadow: var(--shadow);
}

.card + .card {
  margin-top: 0;
}

.card h2,
.card h3 {
  margin: 0 0 8px;
  font-size: 15px;
  font-weight: 650;
}

.card h3 {
  font-size: 14px;
  color: var(--fg-dim);
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.row.nowrap {
  flex-wrap: nowrap;
}

.spread {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.grow {
  flex: 1 1 auto;
}

.muted {
  color: var(--fg-dim);
  font-size: 13px;
}

.mute2 {
  color: var(--fg-mute);
  font-size: 12px;
}

.mono {
  font-family: var(--mono);
  font-size: 12px;
}

.wrap-anywhere {
  overflow-wrap: anywhere;
  word-break: break-word;
}

.divider {
  height: 1px;
  background: var(--line);
  margin: 10px 0;
  border: 0;
}

/* 按钮 */
.btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 38px;
  padding: 8px 13px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line-strong);
  background: var(--bg-elev);
  color: var(--fg);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
  touch-action: manipulation;
}

.btn:active {
  transform: translateY(1px);
}

.btn[disabled] {
  opacity: 0.55;
  pointer-events: none;
}

.btn.primary {
  background: var(--brand);
  border-color: var(--brand);
  color: var(--brand-fg);
  font-weight: 600;
}

.btn.ghost {
  background: transparent;
}

.btn.danger {
  color: var(--danger);
  border-color: var(--danger);
  background: var(--danger-soft);
}

.btn.small {
  min-height: 30px;
  padding: 4px 10px;
  font-size: 13px;
  border-radius: 9px;
}

.btn.block {
  width: 100%;
}

.btn-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

/* 标签 */
.chip {
  appearance: none;
  font: inherit;
  font-size: 13px;
  line-height: 1.2;
  padding: 7px 12px;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  background: var(--bg-elev);
  color: var(--fg-dim);
  cursor: pointer;
  white-space: nowrap;
}

.chip[aria-pressed="true"] {
  background: var(--brand-soft);
  border-color: var(--brand);
  color: var(--brand);
  font-weight: 600;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  line-height: 1.5;
  font-weight: 600;
  background: var(--bg-sunk);
  color: var(--fg-dim);
  white-space: nowrap;
}

.badge.ok {
  background: var(--ok-soft);
  color: var(--ok);
}

.badge.warn {
  background: var(--warn-soft);
  color: var(--warn);
}

.badge.danger {
  background: var(--danger-soft);
  color: var(--danger);
}

.badge.brand {
  background: var(--brand-soft);
  color: var(--brand);
}

/* 表单 */
.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.field > label {
  font-size: 13px;
  color: var(--fg-dim);
}

input,
textarea,
select {
  width: 100%;
  font: inherit;
  font-size: 15px;
  color: var(--fg);
  background: var(--bg-sunk);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 9px 10px;
  appearance: none;
}

textarea {
  min-height: 96px;
  resize: vertical;
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.5;
}

input:focus-visible,
textarea:focus-visible,
select:focus-visible,
.btn:focus-visible,
.chip:focus-visible,
.icon-btn:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 1px;
}

input[type="checkbox"] {
  width: 22px;
  height: 22px;
  min-width: 22px;
  margin: 0;
  accent-color: var(--brand);
}

label.check {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 6px 0;
  cursor: pointer;
}

label.check > span {
  flex: 1 1 auto;
  overflow-wrap: anywhere;
}

/* 列表项 */
.list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.item {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-elev);
  color: inherit;
  text-align: left;
  font: inherit;
  cursor: pointer;
}

.item:active {
  background: var(--bg-sunk);
}

.item.overdue {
  border-left: 3px solid var(--danger);
  padding-left: 10px;
}

.item .title {
  font-size: 15px;
  font-weight: 620;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

/* 条目内的标题可以是 <a>，颜色与正文一致（可点整行） */
.item a.title,
.item a {
  color: inherit;
  text-decoration: none;
  display: block;
}

.item .meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--fg-dim);
}

.item.static {
  cursor: default;
}

.kv {
  display: grid;
  grid-template-columns: minmax(84px, auto) minmax(0, 1fr);
  gap: 6px 10px;
  font-size: 14px;
}

.kv > dt {
  color: var(--fg-dim);
  font-size: 13px;
}

.kv > dd {
  margin: 0;
  overflow-wrap: anywhere;
}

.quote {
  border-left: 3px solid var(--brand);
  background: var(--bg-sunk);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  padding: 8px 10px;
  font-size: 14px;
  overflow-wrap: anywhere;
}

.group-title {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin: 6px 2px 0;
  font-size: 13px;
  font-weight: 650;
  color: var(--fg-dim);
  text-transform: none;
}

/* 时间线 */
.timeline {
  list-style: none;
  margin: 0;
  padding: 0 0 0 14px;
  border-left: 1px dashed var(--line-strong);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.timeline > li {
  position: relative;
}

.timeline > li::before {
  content: "";
  position: absolute;
  left: -19px;
  top: 6px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--line-strong);
}

.timeline > li.user::before {
  background: var(--brand);
}

/* 骨架屏 */
.sk {
  background: linear-gradient(90deg, var(--bg-sunk) 25%, var(--line) 37%, var(--bg-sunk) 63%);
  background-size: 400% 100%;
  animation: sk-shimmer 1.4s ease infinite;
  border-radius: 8px;
}

.sk.line {
  height: 12px;
}

.sk.title {
  height: 18px;
  width: 62%;
}

@keyframes sk-shimmer {
  0% {
    background-position: 100% 0;
  }
  100% {
    background-position: 0 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .sk {
    animation: none;
  }
}

/* 空态 / 错误态 */
.placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 26px 14px;
  text-align: center;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  background: var(--bg-elev);
  color: var(--fg-dim);
}

.placeholder .big {
  font-size: 26px;
  line-height: 1;
}

.placeholder.error {
  border-color: var(--danger);
  background: var(--danger-soft);
  color: var(--danger);
}

.placeholder .hint {
  font-size: 13px;
  color: var(--fg-dim);
  overflow-wrap: anywhere;
}

.placeholder pre {
  width: 100%;
  text-align: left;
  background: var(--bg-sunk);
  color: var(--fg-dim);
  padding: 8px 10px;
  border-radius: var(--radius-sm);
}

/* 离线 / 状态条 */
.banner {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  font-size: 13px;
  border-radius: var(--radius-sm);
  background: var(--warn-soft);
  color: var(--warn);
  overflow-wrap: anywhere;
}

.banner.danger {
  background: var(--danger-soft);
  color: var(--danger);
}

.banner.brand {
  background: var(--brand-soft);
  color: var(--brand);
}

/* 底部导航 */
.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  display: flex;
  align-items: stretch;
  justify-content: space-around;
  height: calc(var(--tab-h) + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: var(--bg-elev);
  border-top: 1px solid var(--line);
}

.tab {
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border: 0;
  background: transparent;
  color: var(--fg-mute);
  font: inherit;
  font-size: 11px;
  cursor: pointer;
  padding: 6px 2px;
}

.tab .ico {
  display: block;
  width: 22px;
  height: 22px;
}

.tab .ico svg {
  width: 22px;
  height: 22px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.tab[aria-current="page"] {
  color: var(--brand);
  font-weight: 650;
}

/* 浮层 */
.toasts {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(var(--tab-h) + 16px + env(safe-area-inset-bottom, 0px));
  z-index: 60;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: #1f2430;
  color: #fff;
  font-size: 14px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.28);
  animation: toast-in 0.18s ease-out;
  overflow-wrap: anywhere;
}

.toast.err {
  background: #b3261e;
}

.toast.ok {
  background: #14683f;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.modal-mask {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(10, 12, 16, 0.5);
  padding: 12px;
}

.modal {
  width: 100%;
  max-width: 560px;
  max-height: 84vh;
  overflow-y: auto;
  background: var(--bg-elev);
  border-radius: 16px;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.modal h3 {
  margin: 0;
  font-size: 16px;
}

/* 启动 / 首屏提示 */
.boot {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 24px 18px;
  text-align: center;
}

.boot .logo {
  width: 64px;
  height: 64px;
  border-radius: 18px;
  background: var(--brand);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 26px;
  font-weight: 700;
}

.boot h1 {
  margin: 0;
  font-size: 19px;
}

.boot .card {
  width: 100%;
  max-width: 420px;
  text-align: left;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* 表格化统计（移动端用卡片行，不用横向表格） */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.stat {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 9px 10px;
  background: var(--bg-sunk);
}

.stat .k {
  font-size: 12px;
  color: var(--fg-dim);
}

.stat .v {
  font-size: 18px;
  font-weight: 680;
  line-height: 1.3;
  overflow-wrap: anywhere;
}

.stat.wide {
  grid-column: 1 / -1;
}

details.panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-elev);
  overflow: hidden;
}

details.panel > summary {
  list-style: none;
  cursor: pointer;
  padding: 12px;
  font-weight: 620;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

details.panel > summary::-webkit-details-marker {
  display: none;
}

details.panel > summary::after {
  content: "▾";
  color: var(--fg-mute);
  font-size: 12px;
}

details.panel[open] > summary::after {
  content: "▴";
}

details.panel .body {
  padding: 0 12px 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  border-top: 1px solid var(--line);
  padding-top: 10px;
}

.version-item {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: var(--bg-sunk);
}

.secret-box {
  font-family: var(--mono);
  font-size: 12px;
  background: var(--bg-sunk);
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  overflow-wrap: anywhere;
}

.nowrap-ellipsis {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@media (min-width: 560px) {
  .stat-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}
