:root {
  --brand: #2563eb;
  --brand-dark: #1d4ed8;
  --brand-soft: #eff4ff;
  --ink: #10162b;
  --ink-2: #384259;
  --muted: #6b7488;
  --line: #e4e8f0;
  --bg: #f5f7fb;
  --panel: #fff;
  --success: #0f9d6b;
  --warning: #c2760a;
  --danger: #d13b32;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 22, 43, .05), 0 8px 24px rgba(16, 22, 43, .05);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", "PingFang SC", sans-serif;
  font-size: 14px;
  line-height: 1.6;
}

h1, h2, h3 { margin: 0; font-weight: 600; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
code {
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: .92em;
  background: #f1f3f8;
  padding: 1px 5px;
  border-radius: 4px;
}
pre {
  margin: 0;
  font-family: "SFMono-Regular", Consolas, monospace;
  white-space: pre-wrap;
  word-break: break-word;
}

.text-muted { color: var(--muted); }
.text-danger { color: var(--danger); }
.text-warn { color: var(--warning); }

/* ---------------------------------------------------------- 布局 */

.admin-layout { display: flex; min-height: 100vh; }

.sidebar {
  width: 208px;
  flex: 0 0 208px;
  background: #151c31;
  color: #c6cddd;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar-brand {
  padding: 20px 20px 16px;
  font-size: 15px;
  font-weight: 600;
  color: #fff;
  border-bottom: 1px solid rgba(255, 255, 255, .08);
}

.sidebar-nav { padding: 12px 10px; flex: 1; }

.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 12px;
  margin-bottom: 2px;
  border-radius: 8px;
  color: #c6cddd;
  font-size: 13.5px;
}
.sidebar-nav a:hover { background: rgba(255, 255, 255, .07); color: #fff; text-decoration: none; }
.sidebar-nav a.active { background: var(--brand); color: #fff; }

.sidebar-nav .count {
  margin-left: auto;
  background: var(--danger);
  color: #fff;
  font-size: 11px;
  line-height: 1;
  padding: 3px 6px;
  border-radius: 99px;
}

.sidebar-foot {
  padding: 14px 20px;
  border-top: 1px solid rgba(255, 255, 255, .08);
  font-size: 12.5px;
}
.sidebar-foot a { color: #9aa4bd; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 28px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 5;
}
.topbar h1 { font-size: 17px; }
.topbar .actions { display: flex; gap: 8px; align-items: center; }

.content { padding: 22px 28px 40px; min-width: 0; }

/* ---------------------------------------------------------- 面板 */

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
  margin-bottom: 18px;
  min-width: 0;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin: -2px 0 14px;
}
.panel-head h2 { font-size: 14.5px; }

.detail-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 320px);
  gap: 18px;
  align-items: start;
}
.detail-main, .detail-side { min-width: 0; }

.grid-2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 18px;
}

@media (max-width: 1080px) {
  .detail-grid { grid-template-columns: minmax(0, 1fr); }
}

/* ---------------------------------------------------------- 机器人状态条 */

.robot-bar {
  background: var(--panel);
  border: 1px solid var(--line);
  border-left: 4px solid var(--muted);
  border-radius: var(--radius);
  padding: 14px 18px;
  margin-bottom: 18px;
  box-shadow: var(--shadow);
}
.robot-bar.is-live { border-left-color: var(--success); }
.robot-bar.is-dry { border-left-color: var(--warning); }
.robot-bar.is-off { border-left-color: var(--muted); }

.robot-state { font-weight: 600; display: flex; align-items: center; gap: 8px; }
.robot-meta { color: var(--muted); font-size: 12.5px; }

.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.dot-on { background: var(--success); box-shadow: 0 0 0 3px rgba(15, 157, 107, .18); }
.dot-warn { background: var(--warning); box-shadow: 0 0 0 3px rgba(194, 118, 10, .18); }
.dot-off { background: var(--muted); }

/* ---------------------------------------------------------- 统计卡 */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.stat-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
}
.stat-value { font-size: 26px; font-weight: 650; line-height: 1.2; }
.stat-label { color: var(--muted); font-size: 12.5px; }
.stat-card.danger .stat-value { color: var(--danger); }
.stat-card.warn .stat-value { color: var(--warning); }

/* ---------------------------------------------------------- 表格 */

.table-wrap { overflow-x: auto; margin: 0 -20px -18px; padding: 0 20px 18px; }
.table-wrap table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table-wrap.compact table { font-size: 13px; }

th, td {
  text-align: left;
  padding: 9px 10px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
  white-space: nowrap;
}
th {
  color: var(--muted);
  font-weight: 500;
  font-size: 12.5px;
  white-space: nowrap;
  background: #fafbfe;
}
tbody tr:hover { background: #fbfcfe; }
tbody tr:last-child td { border-bottom: none; }

.cell-clip {
  max-width: 240px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.row-actions { white-space: nowrap; display: flex; gap: 6px; }
.row-muted { opacity: .55; }

.pager { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 14px; }
.pager a, .pager .current {
  min-width: 30px;
  text-align: center;
  padding: 4px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 13px;
}
.pager .current { background: var(--brand); border-color: var(--brand); color: #fff; }

.empty { color: var(--muted); padding: 18px 0; margin: 0; text-align: center; }

/* ---------------------------------------------------------- 按钮 */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 14px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--ink-2);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s, border-color .15s;
}
.btn:hover { background: #f4f6fb; border-color: #ccd3e0; text-decoration: none; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); border-color: var(--brand-dark); }
.btn-danger { color: var(--danger); border-color: #f0cfcc; }
.btn-danger:hover { background: #fdf3f2; }
.btn-sm { padding: 4px 10px; font-size: 12.5px; }
.btn-block { width: 100%; }

/* ---------------------------------------------------------- 表单 */

label {
  display: block;
  margin: 12px 0 5px;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-2);
}
label.required::after { content: " *"; color: var(--danger); }

input[type="text"], input[type="password"], input[type="number"],
input[type="search"], select, textarea {
  width: 100%;
  padding: 8px 11px;
  border: 1px solid var(--line);
  border-radius: 7px;
  font-family: inherit;
  font-size: 13.5px;
  color: var(--ink);
  background: #fff;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .12);
}
textarea { resize: vertical; line-height: 1.65; }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-actions { display: flex; gap: 8px; margin-top: 16px; }

.check-inline {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  margin: 10px 0 0;
  font-weight: 400;
  cursor: pointer;
}
.check-inline input { width: auto; margin: 0; }

.switch-group { margin-top: 6px; }
.switch-group .check-inline { display: flex; }

.hint { color: var(--muted); font-size: 12.5px; margin: 6px 0 0; }

.filter-bar {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 18px;
  box-shadow: var(--shadow);
}
.filter-bar input[type="search"] { flex: 1 1 240px; width: auto; }
.filter-bar select { width: auto; min-width: 130px; }
.filter-bar .check-inline { margin: 0; white-space: nowrap; }

/* ---------------------------------------------------------- 标签 */

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 12px;
  line-height: 1.5;
  background: #eef1f6;
  color: #5b6478;
  white-space: nowrap;
}
.badge-success, .badge-completed, .badge-done { background: #e6f7f1; color: #07714f; }
.badge-info, .badge-replied { background: var(--brand-soft); color: var(--brand-dark); }
.badge-warn, .badge-skipped { background: #fff5e6; color: #a6620a; }
.badge-danger, .badge-failed { background: #fdeeec; color: #b32e26; }
.badge-new { background: #f3e8ff; color: #7028c8; }

/* ---------------------------------------------------------- 详情 */

.complaint-body {
  margin: 0 0 14px;
  padding: 14px 16px;
  background: #fbfaf6;
  border-left: 3px solid #e6c977;
  border-radius: 6px;
  font-size: 14.5px;
  line-height: 1.75;
}

.kv { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 7px 16px; margin: 0; }
.kv dt { color: var(--muted); font-size: 13px; }
.kv dd { margin: 0; min-width: 0; word-break: break-word; }

.decision {
  border: 1px solid var(--line);
  border-left: 4px solid var(--muted);
  border-radius: 8px;
  padding: 12px 16px;
  background: #fafbfe;
}
.decision-reply { border-left-color: var(--brand); }
.decision-complete { border-left-color: var(--success); }
.decision-skip { border-left-color: var(--warning); }
.decision-head { font-weight: 600; }
.decision-reason { color: var(--muted); font-size: 12.5px; }
.decision-preview {
  margin-top: 10px;
  padding: 12px 14px;
  background: #fff;
  border: 1px dashed var(--line);
  border-radius: 6px;
  font-size: 13px;
  line-height: 1.7;
}

.error-box {
  background: #fdf3f2;
  border: 1px solid #f2d4d1;
  border-radius: 6px;
  padding: 10px 12px;
  font-size: 12.5px;
  color: #96271f;
}

.reply-list { list-style: none; margin: 0; padding: 0; }
.reply-list li { padding: 12px 0; border-bottom: 1px solid var(--line); }
.reply-list li:last-child { border-bottom: none; padding-bottom: 0; }
.reply-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 12.5px;
  margin-bottom: 6px;
}
.reply-body {
  background: var(--brand-soft);
  border-radius: 8px;
  padding: 11px 14px;
  line-height: 1.7;
}

.timeline { list-style: none; margin: 0; padding: 0 0 0 16px; }
.timeline li { position: relative; padding: 0 0 14px 14px; border-left: 2px solid var(--line); }
.timeline li:last-child { border-left-color: transparent; padding-bottom: 0; }
.timeline li::before {
  content: "";
  position: absolute;
  left: -6px;
  top: 4px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid var(--brand);
}
.timeline-time { color: var(--muted); font-size: 12px; }
.timeline-body { font-size: 13px; }

/* ---------------------------------------------------------- 提示条 */

.alert {
  padding: 11px 15px;
  border-radius: 8px;
  margin-bottom: 16px;
  font-size: 13.5px;
  border: 1px solid transparent;
}
.alert-success { background: #e9f8f2; border-color: #bfe8d8; color: #07603f; }
.alert-error { background: #fdeeec; border-color: #f3ccc8; color: #96271f; }

/* ---------------------------------------------------------- 登录 / 404 */

.login-page, .center-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
  background: linear-gradient(160deg, #eef2fb, #f7f9fd 60%);
}

.login-card, .card {
  width: 100%;
  max-width: 380px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 12px 40px rgba(16, 22, 43, .1);
  padding: 30px 28px;
}
.login-card h1 { font-size: 19px; text-align: center; }
.login-card .sub { text-align: center; color: var(--muted); font-size: 13px; margin-bottom: 18px; }
.login-card .btn-block { margin-top: 20px; }

.notfound { text-align: center; }
.notfound h1 { font-size: 46px; color: var(--muted); }

.field { margin-bottom: 4px; }
.inline-form { display: inline; }
