/* 「站在其中」后台样式
 *
 * 取自站点的配色（deploy 的 app.css :root），但把用途换了：
 * 站点是给读者慢慢读的，字大、行高松、衬线标题；后台是给运营快速扫的，
 * 因此基准字号降到 14px、行高收紧、正文全用无衬线、数字用等宽数字对齐。
 * 保留琥珀与棕是为了让两边看起来是同一个产品，而不是同一种页面。
 *
 * 全文件零内联样式：CSP 的 style-src 因此可以只给 'self'，
 * 比主站还严一格（主站还留着 unsafe-inline，见 Caddyfile 注释）。
 */

:root {
  --amber: #f5a623;
  --orange: #e8880a;
  --brown: #3d1f0a;
  --cream: #fff8ec;
  --milk: #fffdf7;
  --paper: #f7efe1;
  --muted: #816b58;
  --line: rgba(61, 31, 10, 0.18);
  --soft-line: rgba(61, 31, 10, 0.1);
  --success: #48623d;
  --danger: #8b3f2f;
  --shadow: 0 18px 60px rgba(61, 31, 10, 0.1);
  --serif: "Source Han Serif SC", "Noto Serif CJK SC", "Songti SC", STSong, serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --sidebar-width: 208px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--brown);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.6;
}

button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
h1, h2, h3, p { margin-top: 0; }

:focus-visible {
  outline: 3px solid rgba(245, 166, 35, 0.5);
  outline-offset: 2px;
}

/* ---------------- 通用控件 ---------------- */

.button {
  padding: 7px 16px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--milk);
  cursor: pointer;
  white-space: nowrap;
  transition: background 150ms ease, border-color 150ms ease;
}
.button:hover { border-color: var(--brown); }
.button:disabled { opacity: 0.45; cursor: default; }
.button:disabled:hover { border-color: var(--line); }
.button.primary {
  border-color: var(--brown);
  background: var(--brown);
  color: var(--cream);
}
.button.primary:hover { background: #52290e; }
.button.ghost { background: transparent; }

.link-button {
  padding: 0;
  border: 0;
  border-bottom: 1px solid currentColor;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
}
.link-button:hover { color: var(--brown); }

.icon-button {
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
  font-size: 22px;
  line-height: 1;
}
.icon-button:hover { background: rgba(61, 31, 10, 0.07); }

.field { display: block; margin-bottom: 14px; }
.field-label {
  display: block;
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.04em;
}
.field input, .select {
  width: 100%;
  padding: 8px 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--milk);
}
.field input:focus, .select:focus { border-color: var(--amber); }

.select { width: auto; min-width: 132px; cursor: pointer; }

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

.gate {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
}
.gate-card {
  width: min(100%, 360px);
  padding: 34px 32px 30px;
  border: 1px solid var(--soft-line);
  border-radius: 18px;
  background: var(--milk);
  box-shadow: var(--shadow);
}
.gate-brand {
  margin-bottom: 2px;
  color: var(--muted);
  font-family: var(--serif);
  font-size: 15px;
  letter-spacing: 0.16em;
}
.gate-title {
  margin-bottom: 12px;
  font-family: var(--serif);
  font-size: 28px;
  font-weight: 800;
  letter-spacing: -0.03em;
}
.gate-note {
  margin-bottom: 22px;
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.65;
}
.gate-error {
  margin: 0 0 12px;
  padding: 8px 11px;
  border-radius: 8px;
  background: rgba(139, 63, 47, 0.09);
  color: var(--danger);
  font-size: 13px;
}
.gate-card .button.primary { width: 100%; }

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

.shell {
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--soft-line);
  background: var(--cream);
  position: sticky;
  top: 0;
  height: 100vh;
}
.sidebar-brand { padding: 22px 20px 16px; }
.sidebar-brand-word {
  display: block;
  font-family: var(--serif);
  font-size: 19px;
  font-weight: 800;
  letter-spacing: -0.02em;
}
.sidebar-brand-tag {
  display: block;
  margin-top: 1px;
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.14em;
}

.nav { flex: 1; overflow-y: auto; padding: 4px 10px 16px; }
.nav-group {
  margin: 14px 0 5px;
  padding-left: 10px;
  color: var(--muted);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.16em;
}
.nav-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  padding: 7px 10px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: inherit;
  cursor: pointer;
  text-align: left;
  text-decoration: none;
}
.nav-item:hover { background: rgba(61, 31, 10, 0.06); }
.nav-item.active { background: var(--brown); color: var(--cream); }
.nav-count {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}
.nav-item.active .nav-count { color: rgba(255, 248, 236, 0.72); }

.sidebar-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 20px 16px;
  border-top: 1px solid var(--soft-line);
}
.who {
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.main { min-width: 0; padding: 26px 30px 60px; }
.main-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 22px;
}
.main-title {
  margin-bottom: 2px;
  font-family: var(--serif);
  font-size: 24px;
  font-weight: 800;
  letter-spacing: -0.03em;
}
.main-sub { margin: 0; color: var(--muted); font-size: 12.5px; }

/* ---------------- 总览 ---------------- */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(178px, 1fr));
  gap: 12px;
  margin-bottom: 26px;
}
.stat {
  padding: 15px 17px;
  border: 1px solid var(--soft-line);
  border-radius: 12px;
  background: var(--milk);
}
.stat-label { color: var(--muted); font-size: 12px; }
.stat-value {
  margin-top: 3px;
  font-family: var(--mono);
  font-size: 26px;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  line-height: 1.15;
}
.stat-delta { margin-top: 3px; color: var(--muted); font-size: 11.5px; }
.stat-delta.warn { color: var(--danger); }
.stat-delta.good { color: var(--success); }

.panel {
  margin-bottom: 20px;
  border: 1px solid var(--soft-line);
  border-radius: 12px;
  background: var(--milk);
}
.panel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 14px;
  padding: 14px 18px 10px;
}
.panel-title { margin: 0; font-size: 14px; font-weight: 700; }
.panel-note { margin: 0; color: var(--muted); font-size: 11.5px; }
.panel-body { padding: 4px 18px 18px; }

.panel-columns {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 20px;
}

/* 趋势图与分布图 */
.chart { display: block; width: 100%; height: auto; overflow: visible; }
.chart-bar { fill: var(--amber); }
.chart-bar:hover { fill: var(--orange); }
.chart-axis { stroke: var(--soft-line); stroke-width: 1; }
.chart-label { fill: var(--muted); font-size: 10px; }

.bars { display: grid; gap: 7px; }
.bar-row {
  display: grid;
  grid-template-columns: minmax(76px, auto) minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
}
.bar-name { overflow: hidden; font-size: 12.5px; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { height: 8px; border-radius: 999px; background: rgba(61, 31, 10, 0.08); }
.bar-fill { height: 100%; border-radius: 999px; background: var(--amber); }
.bar-value {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 11.5px;
  font-variant-numeric: tabular-nums;
}

/* ---------------- 列表 ---------------- */

.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.toolbar-label { color: var(--muted); font-size: 12px; }
.toolbar-spacer { flex: 1; }

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--soft-line);
  border-radius: 12px;
  background: var(--milk);
}
table { width: 100%; border-collapse: collapse; }
th, td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--soft-line);
  text-align: left;
  vertical-align: top;
}
th {
  position: sticky;
  top: 0;
  background: var(--cream);
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.04em;
  white-space: nowrap;
}
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: rgba(245, 166, 35, 0.06); }
tbody tr.clickable { cursor: pointer; }

td.num, th.num {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  text-align: right;
}
td.time, th.time { white-space: nowrap; }
td.time { color: var(--muted); font-family: var(--mono); font-size: 12px; }
td.mono { font-family: var(--mono); font-size: 12.5px; }

/* 长正文：默认夹到三行，点开看全文。运营扫列表时不希望一条占半屏。 */
.clamp {
  display: -webkit-box;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  white-space: pre-wrap;
  word-break: break-word;
}
.cell-text { max-width: 560px; white-space: pre-wrap; word-break: break-word; }
.cell-more {
  margin-top: 3px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--orange);
  cursor: pointer;
  font-size: 11.5px;
}

.tag {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  background: rgba(61, 31, 10, 0.07);
  color: var(--muted);
  font-size: 11.5px;
  white-space: nowrap;
}
.tag.ok { background: rgba(72, 98, 61, 0.14); color: var(--success); }
.tag.bad { background: rgba(139, 63, 47, 0.13); color: var(--danger); }
.tag.wait { background: rgba(245, 166, 35, 0.2); color: #8a5a08; }

.pager {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 14px;
}
.pager-info {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

/* 七题答案展开 */
.answers { display: grid; gap: 9px; margin: 6px 0 2px; max-width: 720px; }
.answer-item {
  padding-left: 11px;
  border-left: 2px solid rgba(245, 166, 35, 0.55);
}
.answer-q { color: var(--muted); font-size: 11.5px; }
.answer-a { white-space: pre-wrap; word-break: break-word; }
.answer-a.empty { color: var(--muted); font-style: italic; }

/* ---------------- 抽屉 ---------------- */

.drawer-scrim {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(61, 31, 10, 0.32);
}
.drawer {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 41;
  display: flex;
  flex-direction: column;
  width: min(100%, 620px);
  height: 100vh;
  border-left: 1px solid var(--line);
  background: var(--milk);
  box-shadow: var(--shadow);
}
.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--soft-line);
}
.drawer-title { margin: 0; font-family: var(--serif); font-size: 18px; font-weight: 800; }
.drawer-body { flex: 1; overflow-y: auto; padding: 18px 20px 40px; }

.detail-row { margin-bottom: 16px; }
.detail-label {
  margin-bottom: 3px;
  color: var(--muted);
  font-size: 11.5px;
  letter-spacing: 0.04em;
}
.detail-value { white-space: pre-wrap; word-break: break-word; }
.detail-value.mono { font-family: var(--mono); font-size: 13px; }
.detail-value.empty { color: var(--muted); font-style: italic; }

.attachment {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 12px;
  margin-bottom: 7px;
  border: 1px solid var(--soft-line);
  border-radius: 9px;
}
.attachment-meta { color: var(--muted); font-family: var(--mono); font-size: 12px; }

/* ---------------- 状态 ---------------- */

.placeholder {
  padding: 46px 20px;
  border: 1px dashed var(--line);
  border-radius: 12px;
  color: var(--muted);
  text-align: center;
}
.placeholder.error { border-color: rgba(139, 63, 47, 0.4); color: var(--danger); }

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  z-index: 60;
  padding: 10px 18px;
  border-radius: 999px;
  background: var(--brown);
  color: var(--cream);
  font-size: 13px;
  transform: translateX(-50%);
}

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

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--soft-line); }
  .nav { display: flex; flex-wrap: wrap; gap: 4px; padding: 0 12px 12px; }
  .nav-group { width: 100%; margin: 8px 0 2px; }
  .nav-item { width: auto; }
  .main { padding: 20px 16px 50px; }
}
