:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --text: #1c2138;
  --muted: #6b7280;
  --line: #e5e8f0;
  --primary: #6c4cf1;
  --primary-dark: #5234d6;
  --danger: #e04f60;
  --success: #1ba87a;
  --warning: #d89120;
  --sidebar: #171a2e;
  --shadow: 0 8px 28px rgba(26, 32, 63, .08);
  --radius: 14px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}
button, input, select, textarea { font: inherit; }
a { color: inherit; }

.btn {
  border: 0;
  border-radius: 9px;
  padding: 9px 16px;
  cursor: pointer;
  background: #eef0f6;
  color: var(--text);
  transition: .15s ease;
  font-weight: 600;
}
.btn:hover { filter: brightness(.97); transform: translateY(-1px); }
.btn.primary { background: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); }
.btn.danger { background: #fdecee; color: var(--danger); }
.btn.ghost { background: transparent; color: var(--muted); }
.btn.small { padding: 6px 12px; font-size: 12px; }
.btn.block { width: 100%; padding: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: radial-gradient(circle at 20% 20%, #eee9ff 0, transparent 42%),
              radial-gradient(circle at 80% 80%, #dce9ff 0, transparent 40%),
              var(--bg);
}
.login-card {
  width: 400px;
  background: var(--surface);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 36px;
}
.login-brand { display: flex; align-items: center; gap: 14px; margin-bottom: 28px; }
.login-brand h1 { margin: 0; font-size: 22px; }
.login-brand p { margin: 4px 0 0; color: var(--muted); }
.brand-mark {
  width: 46px; height: 46px; border-radius: 13px;
  background: linear-gradient(135deg, var(--primary), #9a7bff);
  color: #fff; display: grid; place-items: center; font-weight: 800; letter-spacing: .5px;
}
.login-form label { display: block; margin-bottom: 16px; color: var(--muted); font-weight: 600; }
.login-form input { margin-top: 8px; }
.login-hint { color: var(--muted); font-size: 12px; text-align: center; margin: 18px 0 0; }
.form-error { color: var(--danger); font-size: 13px; text-align: center; }

input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 10px 12px;
  background: #fff;
  color: var(--text);
  outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(108,76,241,.12); }
textarea { min-height: 96px; resize: vertical; }
input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--primary); }

.app-shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 238px;
  flex: 0 0 238px;
  background: linear-gradient(180deg, var(--sidebar), #242850);
  color: #d8dcf0;
  display: flex;
  flex-direction: column;
  padding: 22px 16px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.sidebar-brand { display: flex; align-items: center; gap: 12px; padding: 0 8px 22px; }
.sidebar-brand strong { display: block; color: #fff; font-size: 16px; }
.sidebar-brand span { font-size: 12px; color: #9aa1c7; }
.nav { display: flex; flex-direction: column; gap: 4px; overflow: auto; }
.nav-group { margin: 16px 8px 6px; font-size: 11px; color: #7f86ae; letter-spacing: 1px; }
.nav-item {
  border: 0; background: transparent; color: #c7cbe3; text-align: left;
  padding: 10px 12px; border-radius: 9px; cursor: pointer; font-weight: 600;
}
.nav-item:hover { background: rgba(255,255,255,.07); color: #fff; }
.nav-item.active { background: var(--primary); color: #fff; }
.sidebar-footer { margin-top: auto; padding: 14px 8px 0; color: #7f86ae; font-size: 12px; }

.app-main { flex: 1; min-width: 0; }
.topbar {
  height: 64px; background: var(--surface); border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 28px; position: sticky; top: 0; z-index: 10;
}
.breadcrumb { color: var(--muted); }
.breadcrumb b { margin: 0 8px; color: #c8ccd8; }
.breadcrumb strong { color: var(--text); }
.topbar-right { display: flex; align-items: center; gap: 14px; }
.admin-name { font-weight: 600; }
.content { padding: 26px 28px 40px; max-width: 1500px; margin: 0 auto; }

.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; gap: 16px; }
.page-head h2 { margin: 0; font-size: 20px; }
.page-head p { margin: 6px 0 0; color: var(--muted); }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 16px; }
.stat-card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }
.stat-card span { color: var(--muted); font-size: 13px; }
.stat-card strong { display: block; font-size: 28px; margin-top: 8px; }
.panel { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; margin-top: 20px; }
.panel h3 { margin: 0 0 16px; font-size: 16px; }

.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
.toolbar input { width: 260px; }
.toolbar select { width: 140px; }
.toolbar .spacer { flex: 1; }

.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: 12px; }
table { width: 100%; border-collapse: collapse; background: var(--surface); }
th, td { padding: 12px 14px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { background: #fafbfe; color: var(--muted); font-size: 12px; letter-spacing: .3px; }
tr:last-child td { border-bottom: 0; }
tr:hover td { background: #faf9ff; }
.cell-actions { display: flex; gap: 6px; }
.badge { display: inline-block; padding: 3px 9px; border-radius: 99px; font-size: 12px; font-weight: 700; }
.badge.ok { background: #e7f7f1; color: var(--success); }
.badge.off { background: #f1f2f6; color: var(--muted); }
.badge.info { background: #efeaff; color: var(--primary); }
.muted { color: var(--muted); }
.empty { padding: 40px; text-align: center; color: var(--muted); }

.pagination { display: flex; align-items: center; gap: 10px; justify-content: flex-end; margin-top: 16px; color: var(--muted); }
.pagination button { padding: 6px 12px; border: 1px solid var(--line); border-radius: 8px; background: #fff; cursor: pointer; }
.pagination button:disabled { opacity: .45; cursor: not-allowed; }

.modal-overlay {
  position: fixed; inset: 0; background: rgba(15, 18, 35, .45);
  display: grid; place-items: center; padding: 24px; z-index: 100;
}
.modal {
  width: min(680px, 100%); max-height: 88vh; overflow: auto;
  background: var(--surface); border-radius: 18px; box-shadow: 0 24px 70px rgba(12,15,32,.28);
}
.modal.small { width: min(440px, 100%); }
.modal-head { padding: 20px 24px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; }
.modal-head h3 { margin: 0; }
.modal-head button { border: 0; background: transparent; font-size: 22px; cursor: pointer; color: var(--muted); }
.modal-body { padding: 24px; }
.modal-foot { padding: 16px 24px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 10px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-grid .full { grid-column: 1 / -1; }
.field label { display: block; margin-bottom: 6px; color: var(--muted); font-weight: 600; }
.field .hint { display: block; margin-top: 5px; font-size: 12px; color: var(--muted); }
.checkbox-field { display: flex; align-items: center; gap: 10px; padding-top: 22px; }
.checkbox-field label { margin: 0; font-weight: 600; }

.toast-root { position: fixed; right: 24px; top: 80px; z-index: 200; display: flex; flex-direction: column; gap: 10px; }
.toast {
  background: #20243c; color: #fff; padding: 12px 18px; border-radius: 10px;
  box-shadow: var(--shadow); animation: slide .18s ease;
}
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
@keyframes slide { from { transform: translateX(20px); opacity: 0; } to { transform: none; opacity: 1; } }

@media (max-width: 900px) {
  .sidebar { width: 190px; flex-basis: 190px; }
  .content { padding: 20px 16px; }
  .form-grid { grid-template-columns: 1fr; }
  .toolbar input { width: 100%; }
}
