:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e2e8f0;
  --text: #1e293b;
  --muted: #64748b;
  --accent: #1e293b;
  --accent-soft: #eef2f7;
  --danger: #dc2626;
  --ok: #16a34a;
  --side: #101828;
  --side-hover: #1c2536;
  --radius: 12px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Microsoft YaHei', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }

/* ------------------------------------------------------------ 布局 */

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

.sidebar {
  width: 220px;
  flex: 0 0 220px;
  background: var(--side);
  color: #cbd5e1;
  display: flex;
  flex-direction: column;
  padding: 18px 12px;
  gap: 6px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand { display: flex; align-items: center; gap: 10px; padding: 6px 8px 18px; color: #fff; font-weight: 600; }
.brand-mark {
  width: 28px; height: 28px; border-radius: 9px;
  background: linear-gradient(140deg, #f5d547, #f5a962);
  display: grid; place-items: center; color: #101828; font-size: 13px; font-weight: 700;
}
.brand small { display: block; font-weight: 400; font-size: 11px; color: #7c8aa3; }

.nav-label { padding: 12px 10px 4px; font-size: 11px; letter-spacing: .08em; color: #64748b; text-transform: uppercase; }
.nav-item {
  display: flex; align-items: center; gap: 9px;
  padding: 9px 10px; border-radius: 9px; color: #cbd5e1; font-size: 13px;
}
.nav-item:hover { background: var(--side-hover); color: #fff; }
.nav-item.active { background: #fff; color: #101828; font-weight: 600; }
.nav-dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .45; }

.side-foot { margin-top: auto; border-top: 1px solid #1f2937; padding-top: 12px; font-size: 12px; color: #7c8aa3; }
.side-user { color: #e2e8f0; font-weight: 600; }
.side-role { font-size: 11px; }

.main { flex: 1; min-width: 0; padding: 24px 28px 48px; }

.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.page-head h1 { margin: 0; font-size: 20px; letter-spacing: -.01em; }
.page-head p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.head-actions { display: flex; gap: 8px; align-items: center; }

/* ------------------------------------------------------------ 组件 */

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.card + .card { margin-top: 16px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.card-head h2 { margin: 0; font-size: 14px; }
.card-body { padding: 16px; }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 7px 12px; border-radius: 9px; font-size: 13px; cursor: pointer; font-family: inherit;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #0f172a; }
.btn.danger { color: var(--danger); border-color: #fecaca; background: #fff5f5; }
.btn.danger:hover { background: #fee2e2; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.sm { padding: 4px 9px; font-size: 12px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

.input, .select, .textarea {
  width: 100%; border: 1px solid var(--border); border-radius: 9px; background: #fff;
  padding: 8px 10px; font: inherit; color: var(--text); outline: none;
}
.input:focus, .select:focus, .textarea:focus { border-color: #94a3b8; box-shadow: 0 0 0 3px rgba(148, 163, 184, .18); }
.textarea { min-height: 86px; resize: vertical; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 5px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }

.table-wrap { overflow: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th, table.data td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.data th { background: var(--surface-2); color: var(--muted); font-size: 12px; font-weight: 600; white-space: nowrap; }
table.data tbody tr:hover { background: var(--surface-2); }
table.data td.actions { text-align: right; white-space: nowrap; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
.muted { color: var(--muted); }
.truncate { max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: inline-block; vertical-align: bottom; }

.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 8px; border-radius: 999px; font-size: 11px; border: 1px solid var(--border); background: var(--surface-2); color: var(--muted); }
.badge.ok { color: #15803d; border-color: #bbf7d0; background: #f0fdf4; }
.badge.off { color: #b91c1c; border-color: #fecaca; background: #fef2f2; }
.badge.info { color: #1d4ed8; border-color: #bfdbfe; background: #eff6ff; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.stat span { display: block; color: var(--muted); font-size: 12px; }
.stat strong { font-size: 24px; letter-spacing: -.02em; }

.empty { padding: 34px 16px; text-align: center; color: var(--muted); font-size: 13px; }

.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.toolbar .input { max-width: 260px; }

.flash { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }
.flash-item { padding: 9px 12px; border-radius: 10px; font-size: 13px; border: 1px solid var(--border); background: #fff; }
.flash-item.ok { border-color: #bbf7d0; background: #f0fdf4; color: #166534; }
.flash-item.error { border-color: #fecaca; background: #fef2f2; color: #991b1b; }

/* ---------------------------------------------------------- 抽屉 */

.drawer { position: fixed; inset: 0; z-index: 50; display: flex; justify-content: flex-end; }
.drawer[hidden] { display: none; }
.drawer-mask { position: absolute; inset: 0; background: rgba(15, 23, 42, .42); }
.drawer-panel {
  position: relative; width: 460px; max-width: 92vw; background: var(--surface);
  height: 100%; display: flex; flex-direction: column; box-shadow: -18px 0 40px rgba(15, 23, 42, .12);
}
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px; border-bottom: 1px solid var(--border); }
.drawer-head h3 { margin: 0; font-size: 15px; }
.drawer-body { padding: 18px; overflow: auto; flex: 1; }
.drawer-foot { padding: 12px 18px; border-top: 1px solid var(--border); display: flex; align-items: center; gap: 10px; }
.drawer-foot .spacer { flex: 1; }
.save-state { font-size: 12px; color: var(--muted); }
.save-state.saved { color: var(--ok); }
.save-state.error { color: var(--danger); }

/* -------------------------------------------------------- 分配页 */

.assign-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 6px 14px; }
.assign-item { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 8px; }
.assign-item:hover { background: var(--surface-2); }
.assign-item label { flex: 1; min-width: 0; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.assign-item .write { font-size: 11px; color: var(--muted); display: flex; align-items: center; gap: 4px; }

.tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.tab { padding: 7px 12px; border-radius: 9px; border: 1px solid var(--border); background: #fff; font-size: 13px; }
.tab.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ---------------------------------------------------------- 登录页 */

.login-wrap { min-height: 100vh; display: grid; place-items: center; background: radial-gradient(1200px 600px at 20% -10%, #e8eef7, #f5f7fb 60%); padding: 20px; }
.login-card { width: 380px; background: #fff; border: 1px solid var(--border); border-radius: 16px; padding: 28px; box-shadow: 0 24px 60px rgba(15, 23, 42, .08); }
.login-card h1 { margin: 14px 0 4px; font-size: 19px; }
.login-card p.hint { color: var(--muted); font-size: 13px; margin: 0 0 20px; }

pre.code { background: #0f172a; color: #e2e8f0; padding: 14px; border-radius: 10px; overflow: auto; font-size: 12px; line-height: 1.6; }
pre.code .k { color: #93c5fd; }
code.inline { background: var(--surface-2); padding: 1px 6px; border-radius: 6px; font-family: ui-monospace, Menlo, monospace; font-size: 12px; }

@media (max-width: 900px) {
  .sidebar { width: 64px; flex-basis: 64px; padding: 14px 8px; }
  .sidebar .nav-item span, .brand small, .side-user, .side-role, .nav-label { display: none; }
  .main { padding: 18px 14px 40px; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
}
