:root {
  color-scheme: light dark;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --sidebar: #ffffff;
  --text: #1c2128;
  --muted: #667080;
  --border: #e3e6eb;
  --accent: #2563eb;
  --accent-text: #ffffff;
  --accent-soft: #e8efff;
  --good: #16794a;
  --good-soft: #e3f5ec;
  --bad: #c0352b;
  --bad-soft: #fcebe9;
  --warn: #9a6200;
  --warn-soft: #fbf2dc;
  --info: #1f5fbf;
  --info-soft: #e7f0fd;
  --neutral-soft: #eef0f3;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151a;
    --surface: #1b1f26;
    --sidebar: #171a20;
    --text: #e6e9ee;
    --muted: #98a2b3;
    --border: #2c323b;
    --accent: #5b8def;
    --accent-text: #0d1117;
    --accent-soft: #1f2d4a;
    --good: #57c78f;
    --good-soft: #17352a;
    --bad: #f0857b;
    --bad-soft: #3d201d;
    --warn: #e4b458;
    --warn-soft: #3a2e14;
    --info: #86b2f5;
    --info-soft: #1b2c47;
    --neutral-soft: #272c34;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.6 system-ui, -apple-system, "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 16px; font-weight: 650; }
h2 { font-size: 15px; margin: 0 0 12px; font-weight: 650; }
h3 { font-size: 14px; margin: 16px 0 8px; }
p { margin: 0 0 10px; }
code { background: var(--neutral-soft); padding: 1px 5px; border-radius: 4px; word-break: break-all; }

.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: 190px;
  flex: none;
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 18px 12px;
  background: var(--sidebar);
  border-right: 1px solid var(--border);
}
.brand { font-size: 15px; font-weight: 700; color: var(--text); padding: 0 10px 16px; }
.brand:hover { text-decoration: none; }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.sidebar nav a {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 7px 10px;
  border-radius: 7px;
  color: var(--text);
}
.sidebar nav a:hover { background: var(--neutral-soft); text-decoration: none; }
.sidebar nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.count {
  min-width: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--bad);
  color: var(--surface);
  font-size: 11px;
  font-weight: 600;
  line-height: 18px;
  text-align: center;
}
.sidebar-foot { display: flex; flex-direction: column; gap: 4px; padding: 12px 10px 0; border-top: 1px solid var(--border); font-size: 13px; }

.content { flex: 1; min-width: 0; padding: 26px 30px 60px; max-width: 1240px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px 18px;
  margin-bottom: 16px;
}

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stats.compact { margin: 10px 0; }
.stats.compact > div { display: flex; flex-direction: column; }
.stat { display: flex; flex-direction: column; margin: 0; color: inherit; }
a.stat:hover { text-decoration: none; border-color: var(--accent); }
.stat-value { font-size: 24px; font-weight: 650; line-height: 1.3; font-variant-numeric: tabular-nums; }
.stat-value small { font-size: 14px; font-weight: 500; color: var(--muted); }
.stat-bad .stat-value { color: var(--bad); }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-weight: 500; font-size: 12.5px; color: var(--muted); padding: 6px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
td { padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
tbody tr:last-child td { border-bottom: 0; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.title-cell { min-width: 260px; max-width: 480px; }
.clip { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 460px; }
.empty { color: var(--muted); text-align: center; padding: 22px; list-style: none; }

.badge {
  display: inline-block;
  padding: 0 8px;
  border-radius: 10px;
  font-size: 12px;
  font-weight: 500;
  line-height: 20px;
  white-space: nowrap;
}
.badge.good { background: var(--good-soft); color: var(--good); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.info { background: var(--info-soft); color: var(--info); }
.badge.muted { background: var(--neutral-soft); color: var(--muted); }

.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.good-text { color: var(--good); }
.bad-text { color: var(--bad); }
.warn-text { color: var(--warn); }
.pre { white-space: pre-wrap; overflow-wrap: anywhere; }

.banner { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; overflow-wrap: anywhere; }
.banner.good { background: var(--good-soft); color: var(--good); }
.banner.bad { background: var(--bad-soft); color: var(--bad); }
.banner.info { background: var(--info-soft); color: var(--info); }

input, select, textarea, button, .button { font: inherit; color: inherit; }
input:not([type=checkbox]), select, textarea {
  width: 100%;
  padding: 7px 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 7px;
}
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
textarea { resize: vertical; }

button, .button {
  display: inline-block;
  padding: 6px 13px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 7px;
  cursor: pointer;
  white-space: nowrap;
}
button:hover, .button:hover { background: var(--neutral-soft); text-decoration: none; }
button.primary, .button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
button.primary:hover, .button.primary:hover { filter: brightness(1.08); background: var(--accent); }
button.danger { color: var(--bad); border-color: var(--bad); }
button.danger:hover { background: var(--bad-soft); }
button.link { background: none; border: 0; padding: 0; color: var(--accent); }

label { display: block; font-size: 13px; font-weight: 500; }
label input, label select, label textarea { margin-top: 4px; font-weight: 400; }
label small { display: block; margin-top: 3px; font-weight: 400; }
label.check { display: flex; align-items: center; gap: 6px; font-weight: 400; }
label.check input { margin: 0; }

.form { display: flex; flex-direction: column; gap: 12px; align-items: stretch; }
.form > button { align-self: flex-start; }
.narrow { max-width: 460px; }
.inline { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.inline input[type=number] { width: 90px; display: inline-block; margin: 0 0 0 4px; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.stack h2 { margin-bottom: 0; }

.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; margin-bottom: 14px; }
.filters label { min-width: 150px; }
.filters .grow { flex: 1; min-width: 200px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.pager { display: flex; justify-content: center; gap: 16px; }

.heading-row { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 12px; }
.heading-row h1, .heading-row h2 { margin: 0; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.grid-2 .card { margin-bottom: 16px; }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px; margin: 0; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; }

.settings-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px 18px; }
.field > label:first-child { margin-bottom: 4px; }
.field.has-error input, .field.has-error select, .field.has-error textarea { border-color: var(--bad); }
.field small { display: block; margin-top: 3px; }
.field .check { margin-top: 4px; }
.save-bar { position: sticky; bottom: 0; padding: 10px 0; background: linear-gradient(transparent, var(--bg) 40%); }
.inline-result { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-top: 14px; }

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { padding: 4px 0; overflow-wrap: anywhere; }
.timeline time { font-variant-numeric: tabular-nums; margin-right: 6px; }
.alert-list { list-style: none; margin: 0 0 10px; padding: 0; }
.alert-list li { padding: 3px 0; }
.alert-row { padding: 10px 0; border-bottom: 1px solid var(--border); }
.alert-row:last-child { border-bottom: 0; }
.alert-row .pre { margin: 6px 0; }
.steps { margin: 0; padding-left: 20px; }
.steps li { padding: 2px 0; }
details summary { cursor: pointer; color: var(--accent); margin-bottom: 8px; }
details form + form { margin-top: 12px; }
.danger-zone { margin-top: 20px; }

.centered { display: flex; min-height: 100vh; align-items: center; justify-content: center; padding: 20px; }
.auth { width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 12px; margin: 0; }
.auth h1 { margin: 0 0 4px; text-align: center; }

@media (max-width: 760px) {
  .layout { flex-direction: column; }
  .sidebar { position: static; width: 100%; height: auto; border-right: 0; border-bottom: 1px solid var(--border); padding: 12px; }
  .brand { padding: 0 4px 8px; }
  .sidebar nav { flex-direction: row; overflow-x: auto; scrollbar-width: none; }
  .hide-sm { display: none; }
  .title-cell { min-width: 0; max-width: none; }
  .clip { max-width: none; white-space: normal; }
  td .badge { white-space: normal; line-height: 1.4; padding-top: 1px; padding-bottom: 1px; }
  th, td { padding-left: 6px; padding-right: 6px; }
  .sidebar nav a { white-space: nowrap; gap: 6px; }
  .sidebar-foot { flex-direction: row; gap: 12px; align-items: center; padding: 8px 4px 0; margin-top: 8px; }
  .content { padding: 16px 14px 40px; }
  .grid-2 { grid-template-columns: minmax(0, 1fr); }
}
