:root {
  --bg: #eef2f8;
  --panel: #ffffff;
  --ink: #16202e;
  --muted: #6b7a8d;
  --line: #e4eaf2;
  --line-2: #d5dee9;
  --brand: #2f6df6;
  --brand-d: #1d4ed8;
  --brand-soft: #eaf1ff;
  --ok: #15a35b;
  --warn: #d97706;
  --danger: #e03131;
  --nav-bg: #0e1826;
  --nav-bg-2: #16263c;
  --shadow-sm: 0 1px 2px rgba(16, 32, 55, .06), 0 1px 1px rgba(16, 32, 55, .04);
  --shadow: 0 6px 20px rgba(16, 32, 55, .08);
  --shadow-lg: 0 24px 60px rgba(9, 20, 38, .28);
  --radius: 12px;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg); color: var(--ink); font-size: 14px; line-height: 1.55;
  -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale;
}
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: 14px; }
a { color: var(--brand); }
h1, h2, h3, h4 { letter-spacing: .2px; }

/* ---------- Login ---------- */
#loginView {
  min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px;
  background:
    radial-gradient(900px 520px at 12% -10%, rgba(47,109,246,.55) 0%, transparent 60%),
    radial-gradient(800px 520px at 100% 110%, rgba(23,86,214,.40) 0%, transparent 55%),
    linear-gradient(160deg, #0b1524 0%, #0e1b30 55%, #08101d 100%);
}
.auth-card {
  width: 412px; max-width: 100%; background: #fff;
  border: 1px solid rgba(255,255,255,.6); border-radius: 20px;
  box-shadow: var(--shadow-lg); padding: 38px 34px 30px;
  animation: rise .5s cubic-bezier(.2,.7,.2,1);
}
@keyframes rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
.auth-logo {
  width: 56px; height: 56px; border-radius: 16px; margin-bottom: 20px;
  background: linear-gradient(140deg, #4d8bff, #1d4ed8); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 26px; font-weight: 800; box-shadow: 0 12px 26px rgba(47,109,246,.45);
}
.auth-card h1 { font-size: 21px; margin: 0 0 6px; }
.auth-card .sub { color: var(--muted); margin: 0 0 24px; font-size: 13px; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 6px; font-weight: 500; }
.field input {
  width: 100%; padding: 11px 13px; border: 1px solid var(--line-2); border-radius: 10px; outline: none;
  background: #fbfcfe; transition: border-color .18s, box-shadow .18s, background .18s;
}
.field input:focus { border-color: var(--brand); background: #fff; box-shadow: 0 0 0 4px rgba(47,109,246,.15); }
.btn {
  width: 100%; padding: 12px 0; background: linear-gradient(135deg, #3b7bff, #1d4ed8); color: #fff; border: none;
  border-radius: 10px; font-weight: 700; font-size: 15px; letter-spacing: 3px;
  box-shadow: 0 8px 20px rgba(47,109,246,.32); transition: transform .12s, box-shadow .2s, filter .2s;
}
.btn:hover { filter: brightness(1.04); box-shadow: 0 10px 24px rgba(47,109,246,.4); }
.btn:active { transform: translateY(1px); }
.btn.ghost { background: #fff; color: var(--brand); border: 1px solid var(--brand); box-shadow: none; letter-spacing: 0; font-weight: 600; }
.btn.sm { width: auto; padding: 7px 14px; font-weight: 600; font-size: 13px; letter-spacing: 0; box-shadow: none; border-radius: 8px; }
.btn.danger { background: #fff; color: var(--danger); border: 1px solid #f2c4c4; box-shadow: none; letter-spacing: 0; }
.btn.danger:hover { background: #fff5f5; }
.row2 { display: flex; gap: 8px; }
.linkbtn { background: none; border: none; color: var(--brand); padding: 0; font-size: 13px; }
.hint { color: var(--muted); font-size: 12.5px; margin-top: 12px; line-height: 1.6; }
.error { color: var(--danger); font-size: 13px; margin: 10px 0 0; min-height: 16px; }

/* ---------- App shell ---------- */
#appView { display: none; }
#appView.show { display: flex; min-height: 100vh; }
#sideNav {
  width: 232px; flex: 0 0 232px; color: #c7d3e1; padding: 16px 12px;
  background: linear-gradient(180deg, var(--nav-bg) 0%, var(--nav-bg-2) 120%);
  display: flex; flex-direction: column; overflow-y: auto;
}
#sideNav .brand {
  font-weight: 800; color: #fff; font-size: 15.5px; padding: 8px 12px 16px; letter-spacing: .3px;
  display: flex; align-items: center; gap: 9px;
}
#sideNav .brand::before {
  content: "加"; width: 28px; height: 28px; border-radius: 9px; flex: 0 0 28px;
  background: linear-gradient(140deg, #4d8bff, #1d4ed8); color: #fff; font-size: 15px;
  display: flex; align-items: center; justify-content: center; box-shadow: 0 6px 14px rgba(47,109,246,.5);
}
#sideNav .navgroup { padding: 12px 12px 5px; font-size: 10.5px; font-weight: 700; letter-spacing: .1em; color: #5f7896; }
#sideNav .navgroup:first-of-type { padding-top: 2px; }
#sideNav a {
  display: flex; align-items: center; gap: 9px; padding: 9px 12px; border-radius: 9px; color: #b6c4d6;
  text-decoration: none; margin-bottom: 2px; font-size: 13.5px; font-weight: 500; transition: background .16s, color .16s, transform .16s;
}
#sideNav a:hover { background: rgba(255,255,255,.07); color: #fff; transform: translateX(2px); }
#sideNav a.active { background: linear-gradient(135deg, rgba(59,123,255,.95), rgba(29,78,216,.95)); color: #fff; box-shadow: 0 8px 18px rgba(29,78,216,.4); }
#sideNav .spacer { flex: 1; }
#main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
#topbar {
  height: 60px; background: rgba(255,255,255,.85); backdrop-filter: saturate(1.4) blur(8px);
  border-bottom: 1px solid var(--line); display: flex; align-items: center;
  justify-content: space-between; padding: 0 24px; position: sticky; top: 0; z-index: 10;
}
#topbar #pageTitle { font-size: 17px; font-weight: 700; }
#topbar .who { color: var(--muted); font-size: 13px; }
#topbar .who b { color: var(--ink); }
#content { padding: 24px; overflow: auto; }
.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; gap: 12px; flex-wrap: wrap; }
.page-head h2 { margin: 0; font-size: 20px; font-weight: 800; }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.toolbar input, .toolbar select {
  padding: 9px 12px; border: 1px solid var(--line-2); border-radius: 9px; outline: none; background: #fff;
  transition: border-color .16s, box-shadow .16s;
}
.toolbar input:focus, .toolbar select:focus { border-color: var(--brand); box-shadow: 0 0 0 4px rgba(47,109,246,.13); }

/* ---------- Cards / tables ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(186px, 1fr)); gap: 16px; margin-bottom: 8px; }
.stat {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px;
  box-shadow: var(--shadow-sm); transition: transform .18s, box-shadow .2s, border-color .2s;
}
.stat:hover { transform: translateY(-3px); box-shadow: var(--shadow); border-color: var(--line-2); }
.stat .n { font-size: 28px; font-weight: 800; letter-spacing: -.5px; }
.stat .l { color: var(--muted); font-size: 13px; margin-top: 3px; }

table.grid {
  width: 100%; border-collapse: separate; border-spacing: 0; background: var(--panel);
  border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow-sm);
}
table.grid th, table.grid td { padding: 11px 14px; text-align: left; border-bottom: 1px solid var(--line); font-size: 13px; vertical-align: top; }
table.grid th { background: #f7f9fc; color: #55637a; font-weight: 700; font-size: 12px; letter-spacing: .04em; text-transform: uppercase; }
table.grid tbody tr:hover, table.grid tr:hover td { background: #f8fbff; }
table.grid tr:last-child td { border-bottom: none; }
.badge { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--brand-soft); color: var(--brand); }
.badge.green { background: #e4f8ec; color: var(--ok); }
.badge.amber { background: #fdf0d9; color: var(--warn); }
.badge.red { background: #fde8e8; color: var(--danger); }
.tag { display: inline-block; background: #eef2f7; color: #495a70; border-radius: 7px; padding: 2px 8px; font-size: 12px; margin: 1px 4px 1px 0; }
.row-actions button { margin-right: 6px; }
.empty { color: var(--muted); padding: 34px; text-align: center; }

/* ---------- Modal ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(9,18,32,.5); backdrop-filter: blur(3px); display: none; align-items: center; justify-content: center; z-index: 50; padding: 20px; }
.modal-back.show { display: flex; }
.modal {
  width: 540px; max-width: 100%; max-height: 88vh; overflow: auto; background: #fff; border-radius: 16px;
  padding: 24px 26px; box-shadow: var(--shadow-lg); animation: rise .28s cubic-bezier(.2,.7,.2,1);
}
.modal h3 { margin: 0 0 18px; font-size: 18px; }
.modal .field { margin-bottom: 14px; }
.modal .foot { display: flex; justify-content: flex-end; gap: 10px; margin-top: 10px; }
.toast {
  position: fixed; left: 50%; bottom: 30px; transform: translateX(-50%) translateY(8px); background: #0e1826; color: #fff;
  padding: 11px 20px; border-radius: 11px; font-size: 13px; opacity: 0; transition: opacity .22s, transform .22s; pointer-events: none; z-index: 60;
  box-shadow: 0 12px 30px rgba(9,18,32,.4);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (max-width: 820px) {
  #sideNav { position: fixed; inset: 0 auto 0 0; z-index: 40; transform: translateX(-100%); transition: transform .25s; }
  #sideNav.open { transform: none; }
  #topbar { padding: 0 16px; }
  #content { padding: 16px; }
}
