:root {
  --bg: #f6f7f9;
  --card: #ffffff;
  --ink: #17202a;
  --muted: #6b7785;
  --line: #e3e8ee;
  --brand: #0f172a;
  --accent: #1d4ed8;
  --ok: #15803d;
  --warn: #b45309;
  --danger: #b91c1c;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg); color: var(--ink);
  font: 15px/1.6 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 16px; margin: 0 0 10px; }
h3 { font-size: 14px; margin: 16px 0 6px; color: var(--muted); }
small { font-weight: normal; }

.topbar {
  display: flex; align-items: center; gap: 18px; flex-wrap: wrap;
  padding: 10px 22px; background: var(--brand); color: #fff;
}
.brand { color: #fff; font-weight: 700; letter-spacing: .5px; }
.brand span { display: block; font-size: 11px; color: #9fb0c6; font-weight: 400; letter-spacing: 0; }
.nav { display: flex; gap: 14px; align-items: center; flex: 1; flex-wrap: wrap; }
.nav a { color: #dbe4f0; font-size: 14px; }
.nav a.primary { background: #fff; color: var(--brand); padding: 5px 12px; border-radius: 7px; font-weight: 600; }
.user { display: flex; gap: 10px; align-items: center; color: #cbd5e1; font-size: 13px; }
.user form { margin: 0; }
.link { background: none; border: 0; color: #cbd5e1; cursor: pointer; font-size: 13px; padding: 0; }
.link:hover { color: #fff; text-decoration: underline; }

.wrap { max-width: 1180px; margin: 22px auto; padding: 0 18px; }
.foot { text-align: center; color: var(--muted); font-size: 12px; padding: 30px 0 40px; }

.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; background: #e8f0fe; border: 1px solid #c7d7fe; }
.flash.success { background: #e9f7ef; border-color: #b7e4c7; }
.flash.error { background: #fdecec; border-color: #f5c2c2; }
.flash.info { background: #eef4ff; border-color: #c6d4f5; }

.page-head { display: flex; justify-content: space-between; align-items: right; gap: 16px; margin-bottom: 16px; flex-wrap: wrap; align-items: center; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 18px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; color: var(--ink); }
.stat b { display: block; font-size: 26px; line-height: 1.2; }
.stat span { color: var(--muted); font-size: 13px; }
.stat:hover { border-color: #b9c6d8; text-decoration: none; }
.cols { display: grid; grid-template-columns: 1.55fr 1fr; gap: 16px; align-items: start; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 16px 18px; margin-bottom: 16px; }
.card-head { display: flex; justify-content: space-between; align-items: center; }
.card-head h2 { margin: 0; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 9px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.table th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: none; }
.table tr:last-child td { border-bottom: 0; }
.card .table { display: block; overflow-x: auto; }

.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; border: 1px solid var(--line); background: #f1f5f9; color: #334155; white-space: nowrap; }
.st-open { background: #fff7e6; border-color: #f5d9a8; color: #8a5a00; }
.st-in_progress { background: #e8f0fe; border-color: #c7d7fe; color: #1e40af; }
.st-resolved { background: #e9f7ef; border-color: #b7e4c7; color: #166534; }
.st-closed { background: #eef1f4; color: #475569; }
.ai-pending { background: #f5f3ff; border-color: #ddd6fe; color: #5b21b6; }
.ai-running { background: #e0f2fe; border-color: #bae6fd; color: #075985; }
.ai-done { background: #ecfdf5; border-color: #a7f3d0; color: #065f46; }
.ai-failed { background: #fdecec; border-color: #f5c2c2; color: #991b1b; }
.p-urgent { background: #fdecec; border-color: #f5c2c2; color: #991b1b; }
.p-high { background: #fff7e6; border-color: #f5d9a8; color: #8a5a00; }
.kb-draft { background: #f5f3ff; border-color: #ddd6fe; color: #5b21b6; }
.kb-review { background: #fff7e6; border-color: #f5d9a8; color: #8a5a00; }
.kb-published { background: #e9f7ef; border-color: #b7e4c7; color: #166534; }
.badge.ok { background: #e9f7ef; border-color: #b7e4c7; color: #166534; }
.badge.warn { background: #fff7e6; border-color: #f5d9a8; color: #8a5a00; }

.filters { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.input, textarea.input, select.input {
  width: 100%; padding: 8px 10px; border: 1px solid #cbd5e1; border-radius: 8px;
  background: #fff; color: var(--ink); font: inherit;
}
.filters .input { width: auto; min-width: 150px; }
.filters input[type="search"] { min-width: 240px; }
.input:focus { outline: 2px solid #bfdbfe; border-color: var(--accent); }
.btn {
  display: inline-block; padding: 8px 14px; border-radius: 8px; border: 1px solid #cbd5e1;
  background: #fff; color: var(--ink); cursor: pointer; font: inherit; line-height: 1.3;
}
.btn:hover { background: #f1f5f9; text-decoration: none; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: #1e293b; }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.small { padding: 5px 10px; font-size: 13px; }
.pager { display: flex; gap: 10px; align-items: center; justify-content: center; margin: 16px 0; }

.form .field { margin-bottom: 14px; }
.form label { display: block; font-weight: 600; margin-bottom: 5px; font-size: 13px; }
.form label em { color: var(--danger); font-style: normal; margin-left: 2px; }
.hint { color: var(--muted); font-size: 12px; margin-top: 4px; }
.err { color: var(--danger); font-size: 13px; margin-top: 4px; }
.pre { white-space: pre-wrap; word-break: break-word; margin: 0 0 10px; }
.meta { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.stack { display: grid; gap: 8px; margin-top: 10px; }

.sugg { border-top: 1px solid var(--line); padding: 12px 0; }
.sugg:first-of-type { border-top: 0; }
.sugg-head { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 6px; }
.opt { background: #f8fafc; border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; margin: 8px 0; }
.opt p { margin: 4px 0; }
.cite { display: inline-block; font-size: 12px; background: #eef2ff; color: #3730a3; border-radius: 5px; padding: 0 6px; margin-right: 4px; }
.event { padding: 6px 0; border-bottom: 1px dashed var(--line); }
.event:last-child { border-bottom: 0; }
.attachment { display: flex; justify-content: space-between; gap: 10px; padding: 4px 0; }
.suggestion { display: block; padding: 8px 0; border-bottom: 1px solid var(--line); color: var(--ink); }
.suggestion:last-child { border-bottom: 0; }

.steps { margin: 0 0 10px; padding-left: 20px; }
.steps li { margin: 6px 0; }
.advanced { margin: 10px 0 14px; border-top: 1px dashed var(--line); padding-top: 10px; }
.advanced summary { cursor: pointer; color: var(--muted); font-size: 13px; font-weight: 600; }

.auth { max-width: 360px; margin: 8vh auto; background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 26px; }
.auth label { display: block; margin: 12px 0; font-weight: 600; font-size: 13px; }
.auth .input { margin-top: 5px; }
.auth .btn { width: 100%; margin-top: 6px; }

@media (max-width: 820px) {
  .cols { grid-template-columns: 1fr; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .topbar { padding: 10px 14px; padding-top: calc(10px + env(safe-area-inset-top)); }
  .wrap { padding: 0 12px; }
  .filters input[type="search"] { min-width: 0; flex: 1; }
}

/* 手机端：底部导航 + 安全区 + 触控尺寸。桌面端 .tabbar 不显示。 */
.tabbar { display: none; }

@media (max-width: 820px) {
  body { padding-bottom: calc(64px + env(safe-area-inset-bottom)); }
  .nav { display: none; }
  .topbar { gap: 10px; }
  .brand { font-size: 15px; }
  .brand span { font-size: 10px; }
  .user span { display: none; }
  .wrap { margin: 14px auto; }
  .page-head { align-items: flex-start; }
  h1 { font-size: 20px; }
  .input, textarea.input, select.input { font-size: 16px; } /* 避免 iOS 聚焦放大 */
  .btn { min-height: 44px; padding: 10px 14px; }
  .btn.small { min-height: 38px; }
  .filters .input { min-width: 0; }
  .card { padding: 14px; }
  .table th, .table td { padding: 8px 6px; }

  .tabbar {
    display: grid; grid-template-columns: repeat(4, 1fr); align-items: center;
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
    background: #fff; border-top: 1px solid var(--line);
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
    box-shadow: 0 -4px 16px rgba(15, 23, 42, .06);
  }
  .tabbar a {
    text-align: center; color: var(--muted); font-size: 12px;
    padding: 6px 2px; border-radius: 8px; min-height: 44px;
    display: flex; align-items: center; justify-content: center;
  }
  .tabbar a:hover { text-decoration: none; background: #f1f5f9; }
  .tabbar .tab-primary {
    background: var(--brand); color: #fff; font-weight: 600;
    margin: -14px 6px 0; border-radius: 999px; font-size: 14px;
  }
  .tabbar .tab-primary:hover { background: #1e293b; }
  .foot { padding-bottom: 8px; }
}
