:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --line: #e6e8ec;
  --text: #16181d;
  --muted: #6b7280;
  --accent: #2563eb;
  --accent-soft: #eef3ff;
  --ok: #15803d;
  --ok-soft: #eaf7ee;
  --bad: #dc2626;
  --bad-soft: #fdecec;
  --warn: #b45309;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

code, .mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12.5px;
}

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

.sidebar {
  width: 208px;
  flex: 0 0 208px;
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 18px 12px;
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 14px;
  letter-spacing: .2px;
  padding: 2px 8px 10px;
}

.dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: #c7ccd6;
  flex: 0 0 8px;
}
.dot.on { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft); }
.dot.off { background: var(--bad); box-shadow: 0 0 0 3px var(--bad-soft); }

nav { display: flex; flex-direction: column; gap: 2px; }

.nav-item {
  appearance: none;
  border: 0;
  background: transparent;
  text-align: left;
  padding: 8px 10px;
  border-radius: 8px;
  color: var(--muted);
  font-size: 13.5px;
  cursor: pointer;
}
.nav-item:hover { background: #f3f5f8; color: var(--text); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

.sidebar-foot {
  margin-top: auto;
  padding: 8px;
  color: var(--muted);
  font-size: 12px;
  border-top: 1px solid var(--line);
}

.main { flex: 1 1 auto; min-width: 0; padding: 20px 24px 60px; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}
.topbar h1 { font-size: 18px; margin: 0; font-weight: 600; }
.top-actions { display: flex; gap: 8px; }

/* ----------------------------------------------------------------- panel */
.panel { display: none; flex-direction: column; gap: 14px; }
.panel.active { display: flex; }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}
.card h2 {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  margin: 0 0 12px;
  letter-spacing: .3px;
  text-transform: uppercase;
}

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
}
.tile {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
}
.tile .label { color: var(--muted); font-size: 12px; }
.tile .value { font-size: 22px; font-weight: 600; margin-top: 4px; letter-spacing: -.3px; }
.tile .sub { color: var(--muted); font-size: 12px; margin-top: 2px; }

.grid2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 14px;
}

.kv { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; }
.kv dt { color: var(--muted); font-size: 12.5px; white-space: nowrap; }
.kv dd { margin: 0; font-size: 13px; word-break: break-all; }

/* ---------------------------------------------------------------- tables */
.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: 8px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th {
  background: #fafbfc;
  text-align: left;
  font-weight: 600;
  font-size: 12px;
  color: var(--muted);
  padding: 9px 12px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
  position: sticky;
  top: 0;
}
tbody td { padding: 9px 12px; border-bottom: 1px solid #f1f3f5; vertical-align: top; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fafbfe; }
.empty { padding: 24px; text-align: center; color: var(--muted); font-size: 13px; }
.text-cell { max-width: 480px; }
.text-cell .clamp {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  white-space: pre-wrap;
  word-break: break-word;
}

/* ------------------------------------------------------------------- ui */
.badge {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  border: 1px solid transparent;
}
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.warn { background: #fff5e8; color: var(--warn); }
.badge.plain { background: #f2f4f7; color: var(--muted); }

.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  border-radius: 8px;
  padding: 7px 12px;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
  transition: background .12s ease, border-color .12s ease;
}
.btn:hover { background: #f6f7f9; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #1d4ed8; }
.btn.danger { color: var(--bad); border-color: #f3c9c9; }
.btn.danger:hover { background: var(--bad-soft); }
.btn.sm { padding: 4px 9px; font-size: 12.5px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

input[type="text"], input[type="password"], input[type="number"], textarea, select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 13px;
  font-family: inherit;
  background: #fff;
  color: var(--text);
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
textarea { resize: vertical; min-height: 96px; line-height: 1.5; }
input::placeholder, textarea::placeholder { color: #a4abb8; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field > label { font-size: 12.5px; color: var(--muted); }
.field .hint { font-size: 12px; color: var(--muted); }
.field-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px; }

.switch { display: flex; align-items: center; gap: 10px; }
.switch input { width: 16px; height: 16px; accent-color: var(--accent); }
.switch span { font-size: 13px; }

.row-inline { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row-inline input { flex: 1 1 240px; max-width: 320px; }

.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar select, .toolbar input { width: auto; min-width: 140px; }
.spacer { flex: 1 1 auto; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

/* ------------------------------------------------------------ auth pages */
.auth-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--bg);
  padding: 24px;
}
.auth-wrap { width: 100%; max-width: 392px; }
.auth-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 26px 24px;
  box-shadow: 0 8px 28px rgba(16, 24, 40, .06);
}
.auth-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 14px;
}
.auth-brand .dot { background: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.auth-card h1 { font-size: 18px; margin: 0 0 14px; font-weight: 600; }
.btn.block { width: 100%; margin-top: 4px; }
.form-msg { min-height: 18px; font-size: 12.5px; color: var(--muted); margin: 10px 0 0; }
.form-msg.ok { color: var(--ok); }
.form-msg.bad { color: var(--bad); }
.auth-hint { font-size: 12.5px; color: var(--muted); margin: 10px 0 0; line-height: 1.6; }
.auth-hint a { color: var(--accent); text-decoration: none; }
.auth-hint a:hover { text-decoration: underline; }

.user-chip { padding: 8px; font-size: 12.5px; color: var(--muted); border-top: 1px solid var(--line); }
.user-chip .name { color: var(--text); font-weight: 600; }
.user-chip .actions { display: flex; gap: 6px; margin-top: 8px; }

/* ----------------------------------------------------------------- toast */
.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  max-width: 360px;
  padding: 10px 14px;
  border-radius: 8px;
  background: #111827;
  color: #fff;
  font-size: 13px;
  box-shadow: 0 8px 24px rgba(16, 24, 40, .18);
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: opacity .18s ease, transform .18s ease;
  z-index: 50;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.bad { background: #991b1b; }

@media (max-width: 760px) {
  .shell { flex-direction: column; }
  .sidebar {
    width: 100%;
    flex: 0 0 auto;
    height: auto;
    position: static;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
  nav { flex-direction: row; overflow-x: auto; }
  .nav-item { white-space: nowrap; }
  .sidebar-foot { display: none; }
  .main { padding: 16px 14px 48px; }
}
