:root {
  --primary: #1677ff;
  --primary-hover: #4096ff;
  --primary-light: #e6f4ff;
  --bg: #f0f2f5;
  --surface: #ffffff;
  --border: #e8e8e8;
  --border-light: #f0f0f0;
  --text: #262626;
  --text-secondary: #595959;
  --muted: #8c8c8c;
  --ok: #52c41a;
  --warn: #faad14;
  --bad: #ff4d4f;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.03), 0 1px 6px rgba(0, 0, 0, 0.04);
  --sidebar-w: 220px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; color: var(--text); line-height: 1.5715; background: var(--bg); }
a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-hover); }
code { background: #f5f5f5; padding: 2px 6px; border-radius: 4px; font-size: 0.88em; color: #cf1322; }

.admin-app { min-height: 100vh; }
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w); flex-shrink: 0; background: var(--surface);
  border-right: 1px solid var(--border); display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}
.sidebar-brand {
  display: flex; align-items: center; gap: 10px; padding: 18px 20px;
  border-bottom: 1px solid var(--border-light); font-weight: 700; font-size: 1.05rem;
}
.brand-mark {
  width: 36px; height: 36px; border-radius: 8px; background: var(--primary);
  color: #fff; display: flex; align-items: center; justify-content: center; font-size: 0.75rem;
}
.brand-text { color: var(--text); }

.sidebar-nav { padding: 12px 8px; flex: 1; overflow-y: auto; }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 10px 16px; margin-bottom: 4px;
  border-radius: 6px; color: var(--text-secondary); font-size: 0.925rem; transition: all 0.15s;
}
.nav-item:hover { background: #fafafa; color: var(--primary); text-decoration: none; }
.nav-item.active {
  background: var(--primary-light); color: var(--primary); font-weight: 500;
  box-shadow: inset 3px 0 0 var(--primary);
}
.nav-icon { width: 20px; text-align: center; font-size: 1rem; opacity: 0.9; }

.main-column { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  height: 56px; background: var(--surface); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; padding: 0 24px;
  position: sticky; top: 0; z-index: 10;
}
.breadcrumb { color: var(--muted); font-size: 0.875rem; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.topbar-user { color: var(--text-secondary); font-size: 0.875rem; }
.logout-form { margin: 0; }

.page-content { flex: 1; padding: 20px 24px 32px; }
.page-head {
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap;
  gap: 12px; margin-bottom: 16px;
}
.page-title { margin: 0; font-size: 1.375rem; font-weight: 600; color: var(--text); }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.page-subtitle { margin: -8px 0 16px; color: var(--muted); font-size: 0.875rem; }

.card {
  background: var(--surface); border: 1px solid var(--border-light); border-radius: var(--radius);
  padding: 20px; margin-bottom: 16px; box-shadow: var(--shadow);
}
.card h2, .card-title { margin: 0 0 16px; font-size: 1rem; font-weight: 600; color: var(--text); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 16px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 16px; }
@media (max-width: 1100px) { .grid-4 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 768px) {
  .app-shell { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; }
  .sidebar-nav { display: flex; flex-wrap: wrap; padding: 8px; }
  .nav-item { flex: 1 1 auto; min-width: 120px; box-shadow: none !important; }
  .grid-2, .grid-4 { grid-template-columns: 1fr; }
}

.stat-card {
  background: var(--surface); border: 1px solid var(--border-light); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow); display: flex; align-items: flex-start; gap: 14px;
}
.stat-icon {
  width: 44px; height: 44px; border-radius: 10px; display: flex; align-items: center;
  justify-content: center; font-size: 1.25rem; flex-shrink: 0;
}
.stat-icon.blue { background: #e6f4ff; }
.stat-icon.green { background: #f6ffed; }
.stat-icon.orange { background: #fff7e6; }
.stat-icon.purple { background: #f9f0ff; }
.stat-body { min-width: 0; }
.stat-label { color: var(--muted); font-size: 0.8125rem; margin-bottom: 4px; }
.stat-value { font-size: 1.625rem; font-weight: 600; line-height: 1.2; color: var(--text); }
.stat-value.ok { color: var(--ok); }
.stat-value.warn { color: var(--warn); }
.stat-value.bad { color: var(--bad); }
.stat-sub { color: var(--muted); font-size: 0.75rem; margin-top: 4px; }

.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
table.data thead th {
  background: #fafafa; color: var(--text-secondary); font-weight: 500;
  padding: 12px 16px; border-bottom: 1px solid var(--border); white-space: nowrap;
}
table.data tbody td {
  padding: 12px 16px; border-bottom: 1px solid var(--border-light); vertical-align: middle;
}
table.data tbody tr:hover { background: #fafafa; }
table.data.compact td, table.data.compact th { padding: 8px 12px; }

table.kv { width: 100%; font-size: 0.875rem; }
table.kv td { padding: 10px 0; border-bottom: 1px solid var(--border-light); }
table.kv td:first-child { color: var(--muted); width: 38%; }

.tag {
  display: inline-block; padding: 2px 8px; border-radius: 4px; font-size: 0.75rem; line-height: 1.5;
}
.tag.ok { background: #f6ffed; color: var(--ok); border: 1px solid #b7eb8f; }
.tag.warn { background: #fffbe6; color: #d48806; border: 1px solid #ffe58f; }
.ok { color: var(--ok); }
.bad { color: var(--bad); }
.muted { color: var(--muted); }

.btn, .btn-primary, .btn-sm, button[type="submit"]:not(.tg-auth-button) {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--primary); color: #fff; border: 1px solid var(--primary);
  border-radius: 6px; padding: 6px 16px; cursor: pointer; font-size: 0.875rem;
  line-height: 1.5715; transition: all 0.15s;
}
.btn:hover, .btn-primary:hover, button[type="submit"]:not(.tg-auth-button):hover {
  background: var(--primary-hover); border-color: var(--primary-hover); color: #fff;
}
.btn-outline {
  background: var(--surface); color: var(--text); border: 1px solid var(--border);
}
.btn-outline:hover { color: var(--primary); border-color: var(--primary); background: var(--surface); }
.btn-sm { padding: 4px 12px; font-size: 0.8125rem; }
.btn-sm.bad { background: var(--bad); border-color: var(--bad); }
.btn-row { margin-top: 12px; display: flex; flex-wrap: wrap; gap: 8px; }

.filter-bar {
  background: var(--surface); border: 1px solid var(--border-light); border-radius: var(--radius);
  padding: 16px 20px; margin-bottom: 16px; box-shadow: var(--shadow);
  display: flex; flex-wrap: wrap; align-items: center; gap: 12px;
}
.filter-bar label { color: var(--text-secondary); font-size: 0.875rem; margin-right: 4px; }
.inline-form { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.inline-form select, .inline-form input[type="text"], .inline-form input[type="date"],
.inline-form input[type="number"], .filter-bar select, .filter-bar input {
  padding: 6px 11px; border-radius: 6px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font-size: 0.875rem; min-height: 32px;
}
.inline-form select:focus, .inline-form input:focus {
  outline: none; border-color: var(--primary); box-shadow: 0 0 0 2px rgba(22, 119, 255, 0.1);
}

.tabs { display: flex; gap: 0; flex-wrap: wrap; margin-bottom: 16px; border-bottom: 1px solid var(--border); }
.tabs a {
  padding: 10px 20px; color: var(--text-secondary); border-bottom: 2px solid transparent;
  margin-bottom: -1px; font-size: 0.875rem;
}
.tabs a:hover { color: var(--primary); text-decoration: none; }
.tabs a.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 500; }

.alert { padding: 12px 16px; border-radius: 6px; margin: 12px 0; font-size: 0.875rem; }
.alert-warn { background: #fffbe6; border: 1px solid #ffe58f; color: #ad6800; }

.chat-panel { max-height: 70vh; overflow-y: auto; }
.chat-header { padding-bottom: 12px; margin-bottom: 12px; border-bottom: 1px solid var(--border-light); }
.chat-row { padding: 10px 0; }
.chat-row.in .chat-meta { color: var(--primary); }
.chat-row.out .chat-meta { color: var(--ok); }
.chat-meta { font-size: 0.75rem; color: var(--muted); margin-bottom: 4px; }
.chat-body { white-space: pre-wrap; word-break: break-word; font-size: 0.875rem; }
.chat-sep { border: none; border-top: 1px dashed var(--border); margin: 8px 0; }

.log-panel {
  max-height: 75vh; overflow: auto; font-family: ui-monospace, "Cascadia Code", monospace;
  font-size: 0.78rem; background: #fafafa; border-radius: 6px; padding: 12px;
}
.log-line { padding: 3px 0; border-bottom: 1px solid var(--border-light); word-break: break-all; }
.log-event { color: var(--primary); font-weight: 500; }

.code-block {
  background: #fafafa; border: 1px solid var(--border-light); padding: 16px; border-radius: 6px;
  overflow: auto; font-size: 0.8125rem; color: var(--text-secondary);
}
.scan-block { margin-bottom: 12px; }
.scan-report {
  padding: 10px 12px; border-left: 3px solid var(--primary); margin: 8px 0;
  font-size: 0.8125rem; background: #fafafa; border-radius: 0 6px 6px 0;
}
.sub-block { padding: 6px 0; font-size: 0.875rem; }

details { margin: 8px 0; }
details summary { cursor: pointer; padding: 8px 0; font-weight: 500; color: var(--text); }

.guest-app { min-height: 100vh; background: linear-gradient(135deg, #f0f2f5 0%, #e6f4ff 100%); }
.guest-main { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.login-box {
  width: 100%; max-width: 420px; padding: 40px 36px; background: var(--surface);
  border-radius: 12px; box-shadow: 0 6px 24px rgba(0, 0, 0, 0.08); text-align: center;
}
.login-box h1 { margin: 0 0 8px; font-size: 1.5rem; }
.tg-widget-wrap { display: flex; justify-content: center; min-height: 44px; margin: 24px 0 12px; }
.hint { font-size: 0.8125rem; color: var(--muted); margin-top: 12px; }
