:root {
  --bg: #ffffff;
  --surface: #fafaf8;
  --line: #ececea;
  --text: #1a1a1a;
  --muted: #8a8a85;
  --soft: #6b6b66;
  --brand: #2f6f4f;
  --brand-soft: #eef5f0;
  --warn: #b8860b;
  --warn-soft: #fdf6e6;
  --danger: #b3382c;
  --danger-soft: #fcf0ee;
  --blue: #2c5f8a;
  --blue-soft: #eef3f8;
  --radius: 10px;
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; font-size: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, textarea, select { font-family: inherit; font-size: inherit; color: inherit; }
a { color: var(--blue); text-decoration: none; }

.hidden { display: none !important; }
.muted { color: var(--muted); }
.soft { color: var(--soft); }
.small { font-size: 13px; }
.tiny { font-size: 12px; }
.center { text-align: center; }
.row { display: flex; align-items: center; gap: 10px; }
.spread { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.stack { display: flex; flex-direction: column; gap: 12px; }

/* ---------- 顶部 ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: rgba(255,255,255,.92);
  backdrop-filter: saturate(180%) blur(8px);
  border-bottom: 1px solid var(--line);
  padding: 12px 18px;
}
.topbar-inner { max-width: 760px; margin: 0 auto; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.brand { font-size: 15px; font-weight: 600; letter-spacing: .3px; }
.brand span { color: var(--muted); font-weight: 400; margin-left: 8px; font-size: 13px; }
.avatar {
  width: 30px; height: 30px; border-radius: 50%; background: var(--brand-soft);
  color: var(--brand); display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 600; overflow: hidden; flex: 0 0 auto;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }

.page { max-width: 760px; margin: 0 auto; padding: 24px 18px 80px; }
.page.wide { max-width: 1080px; }

/* ---------- 卡片 ---------- */
.card {
  background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px;
}
.card.plain { background: var(--surface); }

/* ---------- 输入区 ---------- */
.ask-box {
  border: 1px solid var(--line); border-radius: 14px; padding: 14px;
  transition: border-color .15s, box-shadow .15s;
  background: var(--bg);
}
.ask-box:focus-within { border-color: #cfd8d2; box-shadow: 0 2px 12px rgba(0,0,0,.04); }
.ask-box textarea {
  width: 100%; border: none; outline: none; resize: none;
  font-size: 16px; line-height: 1.65; min-height: 52px; background: transparent;
}
.ask-box textarea::placeholder { color: #b5b5b0; }
.ask-foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 6px; }

.btn {
  border-radius: 8px; padding: 8px 16px; font-size: 14px; font-weight: 500;
  background: var(--surface); color: var(--text); border: 1px solid var(--line);
  transition: background .15s, opacity .15s;
  white-space: nowrap;
}
.btn:hover { background: #f4f4f1; }
.btn.primary { background: var(--brand); color: #fff; border-color: var(--brand); }
.btn.primary:hover { background: #285f43; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--soft); padding: 6px 8px; }
.btn.ghost:hover { background: var(--surface); }
.btn.sm { padding: 5px 10px; font-size: 13px; border-radius: 6px; }
.btn.danger { color: var(--danger); border-color: #f0dcda; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

/* ---------- AI 回答 ---------- */
.answer { border-radius: 12px; background: var(--brand-soft); padding: 16px 18px; }
.answer-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; font-size: 13px; color: var(--brand); font-weight: 600; }
.answer-text { font-size: 15px; line-height: 1.7; white-space: pre-wrap; }
.cite { margin-top: 12px; padding-top: 10px; border-top: 1px solid rgba(47,111,79,.14); font-size: 12.5px; color: var(--soft); }
.cite a { color: var(--blue); }

.tag {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 12px; padding: 2px 9px; border-radius: 20px;
  background: var(--surface); color: var(--soft); border: 1px solid var(--line);
  white-space: nowrap;
}
.tag.status-pending { background: #f4f4f1; color: #6b6b66; }
.tag.status-accepted { background: var(--blue-soft); color: var(--blue); border-color: #dde8f2; }
.tag.status-processing { background: #f3eefb; color: #6b4f9e; border-color: #e7ddf7; }
.tag.status-it { background: var(--warn-soft); color: var(--warn); border-color: #f2e4c4; }
.tag.status-done { background: var(--brand-soft); color: var(--brand); border-color: #d9e9df; }
.tag.status-closed { background: #f4f4f1; color: #9a9a95; }
.tag.overdue { background: var(--danger-soft); color: var(--danger); border-color: #f3dad6; }

/* ---------- 列表 ---------- */
.ticket {
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; background: var(--bg); transition: border-color .15s;
}
.ticket:hover { border-color: #dedede; }
.ticket-title { font-size: 15px; font-weight: 500; margin-bottom: 4px; word-break: break-word; }
.ticket-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-size: 12.5px; color: var(--muted); }

/* ---------- 时间线 ---------- */
.timeline { margin-top: 12px; border-left: 2px solid var(--line); padding-left: 14px; display: flex; flex-direction: column; gap: 10px; }
.tl-item { position: relative; font-size: 13px; color: var(--soft); }
.tl-item::before {
  content: ""; position: absolute; left: -19px; top: 7px;
  width: 6px; height: 6px; border-radius: 50%; background: #d6d6d2;
}
.tl-item.active::before { background: var(--brand); }
.tl-time { color: var(--muted); font-size: 12px; }

/* ---------- 打分 ---------- */
.score-grid { display: grid; grid-template-columns: repeat(10, 1fr); gap: 6px; }
.score-btn {
  border: 1px solid var(--line); border-radius: 8px; padding: 10px 0;
  font-size: 14px; text-align: center; background: var(--bg);
}
.score-btn:hover { border-color: var(--brand); color: var(--brand); }
.score-btn.sel { background: var(--brand); color: #fff; border-color: var(--brand); }

/* ---------- 后台 ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 20px; overflow-x: auto; }
.tab {
  padding: 10px 14px; font-size: 14px; color: var(--muted);
  border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap;
}
.tab.active { color: var(--text); border-bottom-color: var(--brand); font-weight: 500; }

.metrics { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; }
.metric { border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.metric .k { font-size: 12.5px; color: var(--muted); }
.metric .v { font-size: 24px; font-weight: 600; margin-top: 4px; letter-spacing: -.5px; }
.metric .v small { font-size: 13px; font-weight: 400; color: var(--muted); margin-left: 4px; }
.metric.alert .v { color: var(--danger); }

.filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.filters select, .filters input[type="search"] {
  border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; font-size: 13.5px;
  background: var(--bg); outline: none;
}
.filters input[type="search"] { flex: 1 1 180px; min-width: 140px; }

table.data { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.data th {
  text-align: left; font-weight: 500; color: var(--muted); font-size: 12.5px;
  padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap;
}
table.data td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.data tr:hover td { background: #fcfcfa; }

.bar-row { display: grid; grid-template-columns: 90px 1fr 44px; gap: 10px; align-items: center; margin-bottom: 8px; font-size: 13px; }
.bar { height: 8px; border-radius: 4px; background: var(--surface); overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--brand); border-radius: 4px; }

.spark { display: flex; align-items: flex-end; gap: 4px; height: 80px; }
.spark > div { flex: 1; background: var(--brand-soft); border-radius: 3px 3px 0 0; min-height: 2px; position: relative; }
.spark > div > span { position: absolute; bottom: -18px; left: 0; right: 0; text-align: center; font-size: 10px; color: var(--muted); }

/* ---------- 弹层 ---------- */
.modal {
  position: fixed; inset: 0; background: rgba(20,20,18,.28);
  display: flex; align-items: flex-end; justify-content: center; z-index: 50;
  padding: 0;
}
@media (min-width: 640px) { .modal { align-items: center; padding: 24px; } }
.modal-card {
  background: var(--bg); width: 100%; max-width: 620px; max-height: 88vh; overflow-y: auto;
  border-radius: 14px 14px 0 0; padding: 20px;
}
@media (min-width: 640px) { .modal-card { border-radius: 14px; } }
.modal-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.modal-title { font-size: 16px; font-weight: 600; }

.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; color: var(--soft); margin-bottom: 5px; }
.field input, .field textarea, .field select {
  width: 100%; border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px;
  outline: none; background: var(--bg); font-size: 14px;
}
.field input:focus, .field textarea:focus, .field select:focus { border-color: #cfd8d2; }
.field textarea { min-height: 80px; resize: vertical; line-height: 1.6; }

.toast {
  position: fixed; left: 50%; bottom: 34px; transform: translateX(-50%);
  background: #24241f; color: #fff; padding: 9px 16px; border-radius: 20px;
  font-size: 13.5px; z-index: 100; opacity: 0; transition: opacity .2s, transform .2s;
  pointer-events: none; max-width: 80vw; text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(-4px); }

.empty { padding: 36px 0; text-align: center; color: var(--muted); font-size: 13.5px; }

.skeleton { background: linear-gradient(90deg, #f4f4f1, #fafaf8, #f4f4f1); background-size: 200% 100%; animation: sk 1.2s infinite; border-radius: 6px; }
@keyframes sk { 0% { background-position: 0 0; } 100% { background-position: -200% 0; } }

.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.login-card { width: 100%; max-width: 360px; text-align: center; }
.login-card h1 { font-size: 21px; font-weight: 600; margin-bottom: 8px; letter-spacing: -.3px; }
.login-card p { color: var(--muted); font-size: 13.5px; margin-bottom: 24px; line-height: 1.7; }
