:root {
  color-scheme: light;
  --ink: #17202a;
  --muted: #687483;
  --line: #e5e9ef;
  --surface: #fff;
  --canvas: #f5f7fa;
  --brand: #1769e0;
  --brand-dark: #0d50b8;
  --success: #087a55;
  --success-bg: #e9f8f1;
  --danger: #bd2c3b;
  --danger-bg: #fff0f1;
  font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; color: var(--ink); background: var(--canvas); font-size: 14px; line-height: 1.6; }
a { color: var(--brand); text-decoration: none; }
button, input, select { font: inherit; }

.topbar { min-height: 68px; padding: 0 32px; display: flex; align-items: center; gap: 28px; color: #fff; background: #101a2b; box-shadow: 0 2px 12px rgba(16, 26, 43, .18); }
.brand { display: flex; align-items: center; gap: 10px; color: #fff; font-size: 17px; font-weight: 700; white-space: nowrap; }
.brand-mark { width: 48px; height: 48px; display: grid; place-items: center; border-radius: 14px; color: #fff; background: linear-gradient(135deg, #2a84ff, #1759d0); font-size: 24px; font-weight: 800; box-shadow: 0 8px 24px rgba(23, 105, 224, .28); }
.brand-mark.small { width: 34px; height: 34px; border-radius: 10px; font-size: 17px; }
.topbar nav { display: flex; align-self: stretch; gap: 2px; }
.topbar nav a { display: flex; align-items: center; padding: 0 14px; color: #b9c4d3; border-bottom: 3px solid transparent; }
.topbar nav a:hover, .topbar nav a.active { color: #fff; border-bottom-color: #4b94ff; }
.user-menu { margin-left: auto; display: flex; align-items: center; gap: 14px; color: #c5ced9; white-space: nowrap; }
.user-menu form, td form { margin: 0; }
.link-button { padding: 0; color: var(--brand); background: transparent; border: 0; cursor: pointer; }
.topbar .link-button { color: #fff; }

.container { width: min(1280px, calc(100% - 48px)); margin: 34px auto 64px; }
.page-heading { margin-bottom: 22px; display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 3px; font-size: 26px; line-height: 1.35; }
h2 { margin-bottom: 18px; font-size: 19px; }
.page-heading p { margin: 0; color: var(--muted); }
.back { display: inline-block; margin-bottom: 10px; }

.button { min-height: 40px; padding: 8px 18px; display: inline-flex; align-items: center; justify-content: center; color: #344054; background: #fff; border: 1px solid #cdd4de; border-radius: 8px; cursor: pointer; font-weight: 600; }
.button:hover { background: #f8fafc; }
.button.primary { color: #fff; background: var(--brand); border-color: var(--brand); }
.button.primary:hover { background: var(--brand-dark); }
.button.full { width: 100%; }

.alert { margin-bottom: 20px; padding: 12px 15px; border: 1px solid; border-radius: 9px; }
.alert-success { color: var(--success); background: var(--success-bg); border-color: #a9e4cc; }
.alert-error { color: var(--danger); background: var(--danger-bg); border-color: #f1bdc2; }

.search-bar { margin-bottom: 16px; display: flex; gap: 10px; }
.search-bar input { max-width: 520px; }
input, select { width: 100%; min-height: 42px; padding: 9px 11px; color: var(--ink); background: #fff; border: 1px solid #cfd6df; border-radius: 8px; outline: none; }
input:focus, select:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(23, 105, 224, .12); }
label { margin-bottom: 17px; display: block; color: #303b49; font-weight: 600; }
label input, label select { margin-top: 6px; font-weight: 400; }
label small { margin-top: 4px; display: block; color: var(--muted); font-weight: 400; }
.required { margin-left: 3px; color: var(--danger); }

.table-card, .form-card { overflow: hidden; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 4px 20px rgba(22, 34, 51, .05); }
.form-card { padding: 26px; }
.form-card.narrow { max-width: 680px; }
.split-grid { display: grid; grid-template-columns: minmax(300px, 380px) minmax(560px, 1fr); gap: 22px; align-items: start; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 14px 16px; text-align: left; vertical-align: middle; border-bottom: 1px solid var(--line); }
th { color: #5b6573; background: #f9fafb; font-size: 13px; font-weight: 700; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
.truncate { max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.empty { padding: 48px 20px; color: var(--muted); text-align: center; }
.copy { margin-left: 8px; padding: 2px 7px; color: var(--brand); background: #eef5ff; border: 0; border-radius: 5px; cursor: pointer; font-size: 12px; }
.code, code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.code { color: #687483; font-size: 12px; }
.muted { color: var(--muted); }
.small-text { font-size: 12px; }
.text-link { white-space: nowrap; }
.row-actions { display: flex; flex-direction: column; align-items: flex-start; gap: 3px; }
.badge { padding: 3px 8px; display: inline-block; border-radius: 999px; font-size: 12px; font-weight: 700; }
.badge.human { color: var(--success); background: var(--success-bg); }
.badge.bot { color: #855400; background: #fff5d9; }
.badge.disabled { color: #6b7280; background: #eef0f3; }

.preview { margin: 5px 0 22px; padding: 15px 17px; background: #f6f8fb; border: 1px dashed #c9d2de; border-radius: 9px; }
.preview div + div { margin-top: 9px; }
.preview span { width: 72px; display: inline-block; color: var(--muted); }
.preview code { word-break: break-all; }
.pagination { margin-top: 18px; display: flex; justify-content: center; align-items: center; gap: 18px; }

.range-tabs { display: flex; padding: 4px; gap: 3px; background: #e9edf3; border-radius: 9px; }
.range-tabs a { padding: 6px 12px; color: #596574; border-radius: 7px; font-weight: 600; }
.range-tabs a.active { color: var(--brand); background: #fff; box-shadow: 0 1px 5px rgba(24, 38, 58, .1); }
.stat-grid { margin-bottom: 22px; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
.stat-card { padding: 20px; display: flex; flex-direction: column; background: #fff; border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 4px 20px rgba(22, 34, 51, .04); }
.stat-card span { color: var(--muted); }
.stat-card strong { margin: 4px 0 1px; font-size: 30px; line-height: 1.25; }
.stat-card small { color: #8a94a2; }
.chart-card { height: 280px; margin-bottom: 22px; padding: 24px 20px 16px; display: flex; align-items: stretch; gap: 5px; overflow-x: auto; background: #fff; border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 4px 20px rgba(22, 34, 51, .04); }
.chart-column { min-width: 28px; flex: 1; display: flex; flex-direction: column; align-items: center; }
.chart-value { height: 24px; color: #687483; font-size: 11px; }
.chart-track { width: min(22px, 72%); flex: 1; display: flex; align-items: flex-end; background: #eef3fa; border-radius: 5px 5px 2px 2px; overflow: hidden; }
.chart-track i { width: 100%; display: block; background: linear-gradient(180deg, #4b94ff, #1769e0); border-radius: 5px 5px 2px 2px; }
.chart-label { margin-top: 7px; color: #778291; font-size: 10px; writing-mode: vertical-rl; }
.daily-table { margin-bottom: 24px; }
.stats-filter { margin-bottom: 22px; padding: 18px 20px; display: flex; align-items: flex-end; gap: 20px; background: #fff; border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 4px 20px rgba(22, 34, 51, .04); }
.stats-filter label { width: min(460px, 100%); margin: 0; }
.selected-link { min-width: 0; display: grid; grid-template-columns: auto 1fr; column-gap: 10px; align-items: center; }
.selected-link span { grid-row: span 3; padding-right: 6px; color: var(--muted); }
.selected-link strong, .selected-link a, .selected-link code { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.selected-link code { max-width: 540px; color: var(--muted); font-size: 11px; }

.login-page { min-height: 100vh; padding: 24px; display: grid; place-items: center; background: radial-gradient(circle at 20% 10%, #dcecff, transparent 34%), #f4f7fb; }
.login-card { width: min(420px, 100%); padding: 38px; background: #fff; border: 1px solid var(--line); border-radius: 18px; box-shadow: 0 20px 60px rgba(19, 40, 72, .13); }
.login-card .brand-mark { margin: 0 auto 20px; }
.login-card h1, .login-card > p { text-align: center; }
.login-card > p { margin-bottom: 28px; }

@media (max-width: 980px) {
  .topbar { padding: 12px 18px; flex-wrap: wrap; gap: 10px 20px; }
  .topbar nav { order: 3; width: 100%; overflow-x: auto; }
  .topbar nav a { min-height: 42px; padding: 0 10px; }
  .user-menu { font-size: 12px; }
  .container { width: min(100% - 28px, 1280px); margin-top: 24px; }
  .split-grid { grid-template-columns: 1fr; }
  .stats-filter { align-items: stretch; flex-direction: column; }
  .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .table-card { overflow-x: auto; }
  table { min-width: 760px; }
}

@media (max-width: 560px) {
  .brand > span:last-child { display: none; }
  .page-heading { align-items: stretch; flex-direction: column; }
  .page-heading .button { align-self: flex-start; }
  .search-bar { flex-direction: column; }
  .range-tabs { align-self: flex-start; }
  .stat-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat-card { padding: 15px; }
  .stat-card strong { font-size: 24px; }
  .login-card { padding: 28px 22px; }
}
