:root {
  --bg: #f3f5f9;
  --panel: #fff;
  --line: #e4e9f1;
  --line-2: #eef2f7;
  --text: #1b2433;
  --muted: #7b8798;
  --nav: #101c2e;
  --nav-2: #0a1423;
  --blue: #2f6fed;
  --blue-2: #1f5bd4;
  --green: #159a62;
  --orange: #e79a1a;
  --red: #e04b4f;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(16, 28, 46, 0.04), 0 4px 14px rgba(16, 28, 46, 0.04);
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; min-height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 13px/1.55 "Inter", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--blue); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.muted { color: var(--muted); }
.hint { color: var(--muted); font-size: 12px; margin: 6px 0; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.mono { font-family: "SFMono-Regular", Consolas, monospace; font-size: 12px; }

.btn {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  border-radius: 6px;
  height: 32px;
  padding: 0 12px;
  transition: all 0.16s var(--ease);
  white-space: nowrap;
}
.btn:hover { border-color: #c8d3e2; background: #f8fafc; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn.primary:hover { background: var(--blue-2); border-color: var(--blue-2); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { background: #f1f4f8; color: var(--text); }
.btn.small { height: 28px; padding: 0 9px; font-size: 12px; }
.btn.block { width: 100%; height: 38px; }
.btn.danger { color: var(--red); border-color: #f3caca; background: #fff7f7; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* auth */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: radial-gradient(1200px 600px at 20% 0%, #e9effa, transparent 60%), var(--bg); }
.auth-card { width: min(420px, 100%); background: #fff; border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); padding: 26px; }
.auth-brand { display: flex; gap: 10px; align-items: center; margin-bottom: 18px; }
.auth-brand .logo, .side-logo span { width: 32px; height: 32px; border-radius: 8px; background: linear-gradient(135deg, #2f6fed, #19a0d8); color: #fff; display: grid; place-items: center; font-weight: 800; }
.auth-brand b { display: block; font-size: 16px; letter-spacing: 0.2px; }
.auth-brand small { color: var(--muted); font-size: 11px; }
.auth-tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; }
.auth-tab { border: 0; background: transparent; padding: 8px 10px; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.auth-tab.active { color: var(--blue); border-bottom-color: var(--blue); font-weight: 600; }
.auth-form { display: grid; gap: 10px; }
.auth-form h2 { margin: 0; font-size: 16px; }
.auth-form label { display: grid; gap: 5px; font-size: 12px; color: #48566b; }
input, select, textarea {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  height: 34px;
  padding: 0 10px;
  outline: none;
  transition: border-color 0.16s var(--ease), box-shadow 0.16s var(--ease);
}
textarea { height: auto; padding: 9px 10px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: #9bb8f8; box-shadow: 0 0 0 3px rgba(47, 111, 237, 0.12); }
.auth-err { margin-top: 12px; border: 1px solid #f3caca; background: #fff5f5; color: #b42318; border-radius: 6px; padding: 8px 10px; font-size: 12px; }

.pw-strength { display: flex; gap: 3px; }
.pw-strength i { flex: 1; height: 3px; background: #e8edf4; border-radius: 3px; }
.pw-strength i.on { background: var(--green); }
.pw-rules { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 2px 8px; color: var(--muted); font-size: 11px; }
.pw-rules li::before { content: "○ "; }
.pw-rules li.ok { color: var(--green); }
.pw-rules li.ok::before { content: "✓ "; }

/* shell */
.layout { min-height: 100vh; }
.sidebar { position: fixed; inset: 0 auto 0 0; width: 216px; background: linear-gradient(180deg, var(--nav), var(--nav-2)); color: #c8d4e6; display: flex; flex-direction: column; z-index: 20; }
.side-logo { display: flex; align-items: center; gap: 9px; height: 56px; padding: 0 16px; color: #fff; border-bottom: 1px solid rgba(255, 255, 255, 0.07); }
.side-logo span { width: 28px; height: 28px; font-size: 13px; }
.side-logo b { font-size: 15px; letter-spacing: 0.3px; }
.side-role { padding: 12px 16px 6px; font-size: 11px; color: #7f92ad; letter-spacing: 1px; }
#menu { display: grid; gap: 2px; padding: 4px 8px; overflow: auto; }
.menu-item { display: flex; align-items: center; gap: 9px; border: 0; background: transparent; color: #b9c7db; text-align: left; padding: 9px 10px; border-radius: 6px; font-size: 13px; }
.menu-item:hover { background: rgba(255, 255, 255, 0.06); color: #fff; }
.menu-item.active { background: var(--blue); color: #fff; box-shadow: 0 4px 14px rgba(47, 111, 237, 0.3); }
.menu-item .ico { width: 18px; text-align: center; opacity: 0.9; }
.side-foot { margin-top: auto; padding: 12px 16px; border-top: 1px solid rgba(255, 255, 255, 0.07); display: grid; gap: 6px; }
.side-foot a { color: #7f92ad; font-size: 12px; }
.side-foot a:hover { color: #fff; }

.main { margin-left: 216px; min-height: 100vh; }
.topbar { height: 56px; background: #fff; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; padding: 0 20px; position: sticky; top: 0; z-index: 10; }
.crumb { font-weight: 600; font-size: 14px; }
.top-right { display: flex; gap: 10px; align-items: center; }
.who { color: var(--muted); font-size: 12px; }
.view { padding: 20px; max-width: 1500px; }

/* content */
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 14px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.stat .label { color: var(--muted); font-size: 12px; }
.stat .value { font-size: 24px; font-weight: 700; margin-top: 2px; letter-spacing: -0.3px; }
.stat .sub { color: var(--muted); font-size: 11px; margin-top: 2px; }
.grid-2 { display: grid; grid-template-columns: 1.4fr 0.9fr; gap: 12px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 14px; overflow: hidden; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--line-2); }
.panel-head h2 { font-size: 14px; margin: 0; }
.panel-body { padding: 14px; }
.empty { padding: 22px; text-align: center; color: var(--muted); font-size: 12px; }
table { width: 100%; border-collapse: collapse; font-size: 12px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
th { color: var(--muted); font-weight: 500; background: #fafbfd; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fbfcfe; }
.badge { display: inline-flex; align-items: center; height: 20px; padding: 0 7px; border-radius: 4px; font-size: 11px; background: #eef2f7; color: #526174; }
.badge.active, .badge.paid, .badge.approved, .badge.settled { background: #e8f7ef; color: #11794d; }
.badge.unused, .badge.pending, .badge.open { background: #fff6e6; color: #ad6a00; }
.badge.banned, .badge.rejected, .badge.closed { background: #fdecec; color: #b42318; }
.badge.expired, .badge.exhausted { background: #f0f2f5; color: #697586; }
.code { background: #f7f9fc; border: 1px dashed #cbd5e1; border-radius: 6px; padding: 9px 10px; font-family: Consolas, monospace; font-size: 12px; word-break: break-all; }
.kv { display: grid; grid-template-columns: 120px 1fr; gap: 8px 12px; font-size: 12px; }
.kv b { color: var(--muted); font-weight: 500; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; }
.notice { border-left: 3px solid var(--blue); background: #f4f8ff; padding: 9px 12px; border-radius: 0 6px 6px 0; margin-bottom: 8px; }
.notice b { display: block; margin-bottom: 2px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 12px; overflow: auto; }
.tab { border: 0; background: transparent; padding: 8px 10px; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tab.active { color: var(--blue); border-bottom-color: var(--blue); font-weight: 600; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.form-grid label { display: grid; gap: 5px; font-size: 12px; color: #48566b; }
.form-grid .full { grid-column: 1 / -1; }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 10px; }
.toolbar select { min-width: 220px; max-width: 100%; }
.file-drop { border: 1px dashed #c7d3e3; border-radius: 6px; padding: 10px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; background: #fbfcfe; }

/* modal / toast */
.modal { position: fixed; inset: 0; background: rgba(10, 20, 35, 0.42); backdrop-filter: blur(2px); display: grid; place-items: center; z-index: 50; padding: 18px; }
.modal-box { width: min(620px, 100%); max-height: 88vh; overflow: auto; background: #fff; border-radius: 10px; box-shadow: 0 24px 70px rgba(10, 20, 35, 0.25); }
.modal-box header { display: flex; align-items: center; justify-content: space-between; padding: 13px 16px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: #fff; }
.modal-box h2 { margin: 0; font-size: 15px; }
.modal-box > div { padding: 16px; }
.icon { border: 0; background: transparent; font-size: 20px; line-height: 1; color: var(--muted); }
.toast { position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%); background: #101c2e; color: #fff; padding: 9px 14px; border-radius: 6px; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25); z-index: 80; font-size: 12px; }
.toast.error { background: #b42318; }

@media (max-width: 980px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-2 { grid-template-columns: 1fr; }
  .sidebar { width: 64px; }
  .side-logo b, .side-role, .menu-item span:not(.ico), .side-foot { display: none; }
  .main { margin-left: 64px; }
  .menu-item { justify-content: center; }
}
@media (max-width: 620px) {
  .stats { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .view { padding: 12px; }
}
