:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --border: #e5e7eb;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-soft: #eff6ff;
  --success: #16a34a;
  --success-soft: #ecfdf5;
  --warning: #d97706;
  --warning-soft: #fffbeb;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --purple: #7c3aed;
  --shadow: 0 1px 3px rgba(16,24,40,.08), 0 8px 24px rgba(16,24,40,.04);
  --radius: 14px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", "PingFang SC", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.55;
}
.hidden { display: none !important; }

/* ---------- Auth Screen ---------- */
.auth-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: radial-gradient(circle at 18% 20%, #dbeafe 0%, #f4f6fb 48%, #eef2ff 100%);
}
.auth-card {
  width: 100%;
  max-width: 820px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: 0 24px 64px rgba(15, 23, 42, 0.10);
  overflow: hidden;
}
.auth-brand {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 26px 32px 22px;
  background: linear-gradient(135deg, #101a31 0%, #1e293b 100%);
  color: #fff;
}
.brand-mark.lg {
  width: 46px;
  height: 46px;
  font-size: 22px;
  border-radius: 12px;
}
.auth-title {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.4px;
}
.auth-sub {
  margin: 3px 0 0;
  font-size: 13px;
  color: #94a3b8;
}
.auth-body {
  display: grid;
  grid-template-columns: 1fr 1.25fr;
  gap: 28px;
  padding: 28px 32px 32px;
}
.auth-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.auth-submit {
  margin-top: 6px;
  padding: 10px 16px;
  font-size: 14px;
}
.quick-accounts {
  border-left: 1px solid var(--border);
  padding-left: 26px;
}
.quick-head {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 12px;
}
.quick-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.quick-card {
  text-align: left;
  border: 1px solid var(--border);
  border-radius: 11px;
  padding: 11px 13px;
  background: #fafbff;
  cursor: pointer;
  transition: all .15s;
  font-family: inherit;
}
.quick-card:hover {
  border-color: #93c5fd;
  background: var(--primary-soft);
  transform: translateY(-1px);
}
.quick-card.active {
  border-color: var(--primary);
  background: var(--primary-soft);
}
.quick-name {
  font-weight: 700;
  font-size: 13.5px;
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.quick-dept {
  font-size: 11.5px;
  color: var(--primary);
  font-weight: 600;
  margin-top: 2px;
}
.quick-duty {
  font-size: 11.5px;
  color: var(--muted);
  margin-top: 5px;
  line-height: 1.45;
}

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

/* ---------- Sidebar ---------- */
.sidebar {
  width: 244px;
  flex: 0 0 244px;
  background: #101a31;
  color: #dbe4f5;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand { display: flex; align-items: center; gap: 11px; padding: 22px 18px 20px; border-bottom: 1px solid rgba(255,255,255,.08); }
.brand-mark {
  width: 38px; height: 38px; border-radius: 10px;
  background: linear-gradient(135deg, #3b82f6, #2563eb);
  color: #fff; font-weight: 700; font-size: 19px;
  display: flex; align-items: center; justify-content: center;
}
.brand-name { font-size: 16px; font-weight: 700; color: #fff; letter-spacing: .5px; }
.brand-sub { font-size: 11px; color: #7f92b3; letter-spacing: 1.2px; }
.nav { padding: 14px 10px; flex: 1; overflow-y: auto; }
.nav-group { font-size: 11px; color: #6f83a8; padding: 12px 12px 6px; letter-spacing: 1px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; margin: 2px 0; border-radius: 9px;
  cursor: pointer; color: #bdc9df; font-size: 13.5px;
  transition: background .15s, color .15s;
}
.nav-item:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav-item.active { background: rgba(59,130,246,.22); color: #fff; font-weight: 600; }
.nav-icon { width: 18px; text-align: center; font-size: 16px; }
.nav-badge { margin-left: auto; background: #dc2626; color: #fff; border-radius: 10px; font-size: 11px; padding: 1px 7px; }
.sidebar-foot { padding: 16px 18px 22px; border-top: 1px solid rgba(255,255,255,.08); }
.foot-tip { font-size: 11.5px; color: #7f92b3; line-height: 1.7; }

/* ---------- Main ---------- */
.main { flex: 1; min-width: 0; padding: 22px 28px 40px; }
.topbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; gap: 12px; flex-wrap: wrap; }
.page-title { font-size: 21px; font-weight: 700; }
.page-desc { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.topbar-actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.today { color: var(--muted); font-size: 12.5px; }

.user-pill {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  border: 1px solid var(--border);
  background: #fff;
  padding: 4px 11px 4px 6px;
  border-radius: 999px;
  cursor: pointer;
  font-family: inherit;
  transition: all .15s;
}
.user-pill:hover { border-color: #93c5fd; background: #f8faff; }
.user-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 700;
  font-size: 13px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.user-meta { display: flex; flex-direction: column; text-align: left; line-height: 1.2; }
.user-name { font-size: 12.5px; font-weight: 700; color: var(--text); }
.user-role { font-size: 11px; color: var(--muted); }
.user-caret { color: var(--muted); font-size: 11px; margin-left: 2px; }

.demo-banner {
  background: var(--warning-soft); border: 1px solid #fde68a; color: #92400e;
  padding: 10px 16px; border-radius: 10px; margin-bottom: 18px; font-size: 13px;
}
.link-btn { border: 0; background: none; color: var(--primary); cursor: pointer; font-size: 13px; text-decoration: underline; padding: 0 4px; font-family: inherit; }

/* ---------- Buttons ---------- */
.btn {
  border: 1px solid var(--border); background: #fff; color: var(--text);
  padding: 7px 13px; border-radius: 8px; cursor: pointer; font-size: 13px;
  transition: all .15s; font-family: inherit; white-space: nowrap;
}
.btn:hover { border-color: #c7d2fe; background: #f8faff; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 600; }
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); border-color: #fecaca; }
.btn-sm { padding: 4px 9px; font-size: 12px; border-radius: 6px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- Cards / KPI ---------- */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(178px, 1fr)); gap: 14px; margin-bottom: 18px; }
.kpi {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow); position: relative; overflow: hidden;
}
.kpi::after { content: ""; position: absolute; right: -18px; top: -18px; width: 70px; height: 70px; border-radius: 50%; opacity: .12; background: var(--accent, var(--primary)); }
.kpi-label { color: var(--muted); font-size: 12.5px; }
.kpi-value { font-size: 27px; font-weight: 700; margin-top: 5px; line-height: 1.2; color: var(--accent, var(--text)); }
.kpi-foot { font-size: 11.5px; color: var(--muted); margin-top: 5px; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); margin-bottom: 16px; overflow: hidden;
}
.card-head { padding: 14px 18px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.card-title { font-weight: 700; font-size: 14.5px; }
.card-sub { color: var(--muted); font-size: 12px; }
.card-body { padding: 16px 18px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: 1.4fr 1fr; gap: 16px; }

/* ---------- Toolbar / Filters ---------- */
.toolbar { display: flex; flex-wrap: wrap; gap: 9px; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.input, .select, .textarea {
  border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px;
  font-size: 13px; font-family: inherit; background: #fff; color: var(--text);
  outline: none; transition: border-color .15s, box-shadow .15s;
}
.input:focus, .select:focus, .textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.12); }
.input { min-width: 190px; }
.textarea { width: 100%; min-height: 68px; resize: vertical; }
.search { flex: 1; min-width: 200px; }
.toolbar .spacer { flex: 1; }

.inline-input-group { display: flex; gap: 8px; align-items: center; }
.inline-input-group .input { flex: 1; min-width: 0; }

/* ---------- Table ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; color: var(--muted); font-weight: 600; font-size: 12px; background: #f9fafb; padding: 10px 14px; white-space: nowrap; border-bottom: 1px solid var(--border); }
td { padding: 11px 14px; border-bottom: 1px solid #f1f3f7; vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fafcff; }
.cell-main { font-weight: 600; }
.cell-sub { color: var(--muted); font-size: 11.5px; margin-top: 2px; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.actions { display: flex; gap: 6px; flex-wrap: nowrap; align-items: center; white-space: nowrap; }
.role-wait { font-size: 11.5px; color: var(--muted); padding: 2px 4px; }

/* ---------- Tags ---------- */
.tag { display: inline-flex; align-items: center; border-radius: 999px; padding: 2px 9px; font-size: 11.5px; font-weight: 600; white-space: nowrap; }
.tag-blue { background: var(--primary-soft); color: var(--primary); }
.tag-green { background: var(--success-soft); color: var(--success); }
.tag-amber { background: var(--warning-soft); color: var(--warning); }
.tag-red { background: var(--danger-soft); color: var(--danger); }
.tag-gray { background: #f3f4f6; color: #6b7280; }
.tag-purple { background: #f5f3ff; color: var(--purple); }

/* ---------- Charts ---------- */
.chart-box { display: flex; align-items: center; gap: 20px; flex-wrap: wrap; }
.legend { display: flex; flex-direction: column; gap: 7px; font-size: 12.5px; }
.legend-row { display: flex; align-items: center; gap: 8px; }
.legend-dot { width: 9px; height: 9px; border-radius: 3px; }
.legend-num { color: var(--muted); margin-left: auto; padding-left: 14px; }
.timeline-list { display: flex; flex-direction: column; gap: 10px; }
.timeline-item { display: flex; gap: 10px; align-items: flex-start; font-size: 13px; }
.timeline-date { color: var(--muted); width: 78px; flex: 0 0 78px; font-size: 12px; }
.timeline-line { width: 8px; height: 8px; border-radius: 50%; margin-top: 6px; flex: 0 0 8px; }

/* ---------- Rule cards ---------- */
.rule-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: 14px; }
.rule-card { border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; background: #fff; }
.rule-title { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; gap: 8px; }
.rule-name { font-weight: 700; font-size: 14px; }
.rule-row { display: grid; grid-template-columns: 72px 1fr; gap: 8px; font-size: 12.5px; padding: 4px 0; border-top: 1px dashed #edf0f5; }
.rule-row:first-of-type { border-top: 0; }
.rule-key { color: var(--muted); }
.notice { background: var(--primary-soft); border: 1px solid #bfdbfe; color: #1e40af; padding: 12px 16px; border-radius: 10px; font-size: 13px; margin-bottom: 16px; }
.rule-hint-box { background: #f8fafc; border: 1px solid var(--border); border-radius: 9px; padding: 10px 13px; font-size: 12.5px; color: #334155; line-height: 1.6; }

/* ---------- Modal ---------- */
.modal-mask { position: fixed; inset: 0; background: rgba(15,23,42,.45); display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 50; }
.modal { background: #fff; border-radius: 16px; width: 100%; max-width: 720px; max-height: 90vh; display: flex; flex-direction: column; box-shadow: 0 24px 60px rgba(0,0,0,.18); }
.modal.wide { max-width: 900px; }
.modal-head { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.modal-title { font-weight: 700; font-size: 16px; }
.modal-body { padding: 18px 20px; overflow-y: auto; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 9px; }
.close-x { border: 0; background: none; font-size: 22px; color: var(--muted); cursor: pointer; line-height: 1; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 13px 16px; }
.form-item { display: flex; flex-direction: column; gap: 5px; }
.form-item.full { grid-column: 1 / -1; }
.form-item label { font-size: 12.5px; color: var(--muted); font-weight: 600; }
.form-item .input, .form-item .select, .form-item .textarea { width: 100%; }
.form-hint { font-size: 11.5px; color: var(--muted); }
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 20px; }
.detail-item { border-bottom: 1px dashed #edf0f5; padding-bottom: 8px; }
.detail-key { color: var(--muted); font-size: 11.5px; }
.detail-val { font-size: 13px; margin-top: 2px; word-break: break-all; }

/* ---------- Toast / Empty ---------- */
.toast-root { position: fixed; right: 22px; bottom: 22px; display: flex; flex-direction: column; gap: 9px; z-index: 80; }
.toast { background: #111827; color: #fff; padding: 10px 16px; border-radius: 9px; font-size: 13px; box-shadow: 0 8px 24px rgba(0,0,0,.2); animation: fadein .2s; }
.toast.ok { background: #15803d; }
.toast.err { background: #b91c1c; }
@keyframes fadein { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.empty { text-align: center; color: var(--muted); padding: 44px 18px; }
.empty-icon { font-size: 34px; opacity: .5; margin-bottom: 8px; }

@media (max-width: 900px) {
  .auth-body { grid-template-columns: 1fr; }
  .quick-accounts { border-left: 0; border-top: 1px solid var(--border); padding-left: 0; padding-top: 20px; }
  .quick-grid { grid-template-columns: 1fr; }
  .sidebar { width: 68px; flex-basis: 68px; }
  .brand-name, .brand-sub, .nav-group, .nav-item span:not(.nav-icon), .nav-badge, .foot-tip { display: none; }
  .brand { justify-content: center; padding: 16px 0; }
  .nav-item { justify-content: center; }
  .main { padding: 18px 16px 32px; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
}
