:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-light: #dbeafe;
  --sidebar: #0f172a;
  --sidebar-hover: #1e293b;
  --bg: #f1f5f9;
  --card: #ffffff;
  --text: #0f172a;
  --text-2: #475569;
  --muted: #94a3b8;
  --border: #e2e8f0;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --info: #0ea5e9;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(15, 23, 42, .06), 0 8px 24px rgba(15, 23, 42, .04);
  --shadow-lg: 0 10px 40px rgba(15, 23, 42, .16);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }

/* ---------------------------- 登录 ---------------------------- */
.login-wrap {
  position: relative;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: #0b1220;
}
.login-bg {
  position: absolute; inset: -20%;
  background:
    radial-gradient(circle at 20% 20%, rgba(37, 99, 235, .35), transparent 40%),
    radial-gradient(circle at 80% 30%, rgba(14, 165, 233, .25), transparent 45%),
    radial-gradient(circle at 50% 90%, rgba(99, 102, 241, .3), transparent 50%);
  filter: blur(10px);
  animation: float 18s ease-in-out infinite alternate;
}
@keyframes float {
  from { transform: translate(0, 0) scale(1); }
  to { transform: translate(2%, -2%) scale(1.06); }
}
.login-card {
  position: relative;
  width: 400px;
  max-width: calc(100vw - 32px);
  background: rgba(255, 255, 255, .97);
  border-radius: 20px;
  padding: 36px 34px 28px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, .45);
  backdrop-filter: blur(20px);
}
.brand { display: flex; align-items: center; gap: 14px; margin-bottom: 28px; }
.brand-logo {
  width: 52px; height: 52px;
  border-radius: 14px;
  background: linear-gradient(135deg, #2563eb, #06b6d4);
  color: #fff; font-size: 26px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 8px 20px rgba(37, 99, 235, .35);
}
.brand-logo.small { width: 38px; height: 38px; font-size: 19px; border-radius: 10px; box-shadow: none; }
.brand h1 { margin: 0; font-size: 24px; letter-spacing: 1px; }
.brand p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.field { display: block; margin-bottom: 18px; }
.field > span { display: block; font-size: 13px; color: var(--text-2); margin-bottom: 8px; font-weight: 500; }
input, select, textarea {
  width: 100%;
  padding: 11px 13px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 14px;
  color: var(--text);
  background: #fff;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
  font-family: inherit;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .12);
}
textarea { resize: vertical; min-height: 90px; }
.form-error { color: var(--danger); font-size: 13px; min-height: 18px; margin-bottom: 8px; }
.login-tip { font-size: 12px; color: var(--muted); text-align: center; margin: 16px 0 0; }

/* ---------------------------- 按钮 ---------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 16px;
  border: 1px solid transparent;
  border-radius: 9px;
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  transition: all .15s;
  background: #fff;
  color: var(--text-2);
  white-space: nowrap;
  font-family: inherit;
}
.btn:hover { background: #f8fafc; }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #dc2626; }
.btn-outline { border-color: var(--border); background: #fff; }
.btn-ghost { background: transparent; color: var(--text-2); }
.btn-ghost:hover { background: #f1f5f9; }
.btn-sm { padding: 6px 11px; font-size: 12.5px; border-radius: 7px; }
.btn-block { width: 100%; padding: 12px; font-size: 15px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.icon-btn { border: none; background: transparent; font-size: 20px; cursor: pointer; padding: 6px 10px; border-radius: 8px; color: var(--text-2); }
.icon-btn:hover { background: #f1f5f9; }

/* ---------------------------- 布局 ---------------------------- */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 236px;
  flex-shrink: 0;
  background: var(--sidebar);
  color: #cbd5e1;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  z-index: 20;
}
.sidebar-brand { display: flex; align-items: center; gap: 11px; padding: 20px 18px 16px; }
.sidebar-brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.sidebar-brand-text strong { color: #fff; font-size: 15px; letter-spacing: .5px; }
.sidebar-brand-text span { color: #64748b; font-size: 11.5px; }
.nav { flex: 1; overflow-y: auto; padding: 4px 10px 16px; }
.nav::-webkit-scrollbar { width: 4px; }
.nav::-webkit-scrollbar-thumb { background: #334155; border-radius: 4px; }
.nav-group {
  font-size: 11px; letter-spacing: 1px; text-transform: uppercase;
  color: #475569; padding: 16px 12px 7px; font-weight: 600;
}
.nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; margin: 1px 0;
  border-radius: 8px; color: #94a3b8;
  font-size: 13.5px; transition: all .15s;
}
.nav a i { font-style: normal; font-size: 15px; width: 20px; text-align: center; }
.nav a:hover { background: var(--sidebar-hover); color: #e2e8f0; }
.nav a.active { background: var(--primary); color: #fff; box-shadow: 0 4px 14px rgba(37, 99, 235, .35); }
.sidebar-footer { padding: 14px 16px; border-top: 1px solid #1e293b; }
.admin-info { color: #94a3b8; font-size: 12.5px; line-height: 1.5; }
.admin-info strong { color: #e2e8f0; display: block; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  height: 64px; flex-shrink: 0;
  background: rgba(255, 255, 255, .85);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 28px; position: sticky; top: 0; z-index: 10;
}
.topbar-left { display: flex; align-items: center; gap: 10px; }
.topbar h2 { margin: 0; font-size: 17px; font-weight: 600; }
.topbar-right { display: flex; align-items: center; gap: 14px; font-size: 12.5px; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--success); box-shadow: 0 0 0 3px rgba(16, 185, 129, .15); }
.status-dot.bad { background: var(--danger); box-shadow: 0 0 0 3px rgba(239, 68, 68, .15); }
.page { padding: 24px 28px 48px; max-width: 1500px; width: 100%; margin: 0 auto; }

/* ---------------------------- 卡片 ---------------------------- */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid rgba(226, 232, 240, .8);
  margin-bottom: 20px;
  overflow: hidden;
}
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
  gap: 12px; flex-wrap: wrap;
}
.card-head h3 { margin: 0; font-size: 15px; font-weight: 600; }
.card-body { padding: 20px; }
.card-body.tight { padding: 0; }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 16px; margin-bottom: 20px;
}
.stat-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
  border: 1px solid rgba(226, 232, 240, .8);
  position: relative; overflow: hidden;
}
.stat-card::after {
  content: ''; position: absolute; right: -20px; top: -20px;
  width: 80px; height: 80px; border-radius: 50%;
  background: var(--primary-light); opacity: .55;
}
.stat-card .label { color: var(--text-2); font-size: 12.5px; margin-bottom: 8px; position: relative; z-index: 1; }
.stat-card .value { font-size: 27px; font-weight: 700; letter-spacing: -.5px; position: relative; z-index: 1; }
.stat-card .extra { font-size: 12px; color: var(--muted); margin-top: 6px; position: relative; z-index: 1; }
.stat-card.green::after { background: #d1fae5; }
.stat-card.orange::after { background: #fef3c7; }
.stat-card.purple::after { background: #ede9fe; }
.stat-card.red::after { background: #fee2e2; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; }
@media (max-width: 1100px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }

/* ---------------------------- 表格 ---------------------------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th {
  text-align: left; font-weight: 600; color: var(--text-2);
  background: #f8fafc; padding: 11px 16px;
  border-bottom: 1px solid var(--border); white-space: nowrap;
  font-size: 12.5px;
}
td { padding: 12px 16px; border-bottom: 1px solid #f1f5f9; vertical-align: middle; }
tbody tr:hover { background: #f8fafc; }
tbody tr:last-child td { border-bottom: none; }
.empty { text-align: center; color: var(--muted); padding: 46px 20px !important; }
.ellipsis { max-width: 300px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: inline-block; vertical-align: bottom; }
.nowrap { white-space: nowrap; }
.actions { display: flex; gap: 6px; flex-wrap: nowrap; }

/* ---------------------------- 徽章 ---------------------------- */
.badge {
  display: inline-flex; align-items: center;
  padding: 3px 9px; border-radius: 999px;
  font-size: 12px; font-weight: 500; line-height: 1.5;
  background: #f1f5f9; color: var(--text-2);
}
.badge.green { background: #d1fae5; color: #047857; }
.badge.red { background: #fee2e2; color: #b91c1c; }
.badge.orange { background: #fef3c7; color: #b45309; }
.badge.blue { background: #dbeafe; color: #1d4ed8; }
.badge.purple { background: #ede9fe; color: #6d28d9; }
.badge.gray { background: #f1f5f9; color: #64748b; }

/* ---------------------------- 工具栏 ---------------------------- */
.toolbar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 14px 20px; border-bottom: 1px solid var(--border);
  background: #fff;
}
.toolbar input, .toolbar select { width: auto; min-width: 150px; padding: 8px 11px; font-size: 13px; }
.toolbar .spacer { flex: 1; }

/* ---------------------------- 分页 ---------------------------- */
.pager {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 20px; border-top: 1px solid var(--border);
  color: var(--text-2); font-size: 13px; flex-wrap: wrap; gap: 10px;
}
.pager-btns { display: flex; gap: 6px; align-items: center; }
.pager-btns button {
  min-width: 32px; height: 32px; border: 1px solid var(--border);
  background: #fff; border-radius: 7px; cursor: pointer; color: var(--text-2);
  font-size: 13px; padding: 0 10px;
}
.pager-btns button:hover:not(:disabled) { border-color: var(--primary); color: var(--primary); }
.pager-btns button.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.pager-btns button:disabled { opacity: .45; cursor: not-allowed; }

/* ---------------------------- 弹窗 ---------------------------- */
.modal-mask {
  position: fixed; inset: 0; background: rgba(15, 23, 42, .5);
  z-index: 100; display: flex; align-items: center; justify-content: center;
  padding: 24px; animation: fade .15s ease;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.modal {
  background: #fff; border-radius: 16px; width: 560px; max-width: 100%;
  max-height: calc(100vh - 48px); display: flex; flex-direction: column;
  box-shadow: var(--shadow-lg); animation: pop .18s ease;
}
.modal.wide { width: 820px; }
@keyframes pop { from { transform: scale(.97) translateY(6px); opacity: .6; } to { transform: none; opacity: 1; } }
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 22px; border-bottom: 1px solid var(--border);
}
.modal-head h3 { margin: 0; font-size: 16px; }
.modal-body { padding: 20px 22px; overflow-y: auto; }
.modal-foot {
  display: flex; justify-content: flex-end; gap: 10px;
  padding: 15px 22px; border-top: 1px solid var(--border); background: #f8fafc;
  border-radius: 0 0 16px 16px;
}
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-row.one { grid-template-columns: 1fr; }
.form-row.three { grid-template-columns: 1fr 1fr 1fr; }
@media (max-width: 640px) { .form-row, .form-row.three { grid-template-columns: 1fr; } }
.form-actions { display: flex; gap: 10px; margin-top: 8px; }
.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; }
.switch input { display: none; }
.switch i {
  width: 38px; height: 22px; border-radius: 999px; background: #cbd5e1;
  position: relative; transition: background .2s; flex-shrink: 0;
}
.switch i::after {
  content: ''; position: absolute; width: 18px; height: 18px; border-radius: 50%;
  background: #fff; top: 2px; left: 2px; transition: transform .2s;
  box-shadow: 0 1px 3px rgba(0,0,0,.2);
}
.switch input:checked + i { background: var(--primary); }
.switch input:checked + i::after { transform: translateX(16px); }

/* ---------------------------- Toast ---------------------------- */
.toast-root { position: fixed; top: 20px; right: 20px; z-index: 200; display: flex; flex-direction: column; gap: 10px; }
.toast {
  min-width: 220px; max-width: 380px;
  background: #0f172a; color: #f8fafc;
  padding: 12px 16px; border-radius: 10px; font-size: 13.5px;
  box-shadow: var(--shadow-lg); animation: slideIn .2s ease;
  display: flex; gap: 8px; align-items: flex-start;
}
.toast.success { background: #065f46; }
.toast.error { background: #991b1b; }
@keyframes slideIn { from { transform: translateX(30px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------------------------- 图表 ---------------------------- */
.chart { width: 100%; height: 260px; }
.chart svg { width: 100%; height: 100%; overflow: visible; }
.chart-legend { display: flex; gap: 18px; font-size: 12.5px; color: var(--text-2); padding: 0 4px 8px; }
.chart-legend span { display: inline-flex; align-items: center; gap: 6px; }
.chart-legend b { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }

.bar-list { display: flex; flex-direction: column; gap: 12px; }
.bar-item { font-size: 13px; }
.bar-item .bar-top { display: flex; justify-content: space-between; margin-bottom: 5px; color: var(--text-2); }
.bar-item .bar-track { height: 8px; border-radius: 999px; background: #eef2f7; overflow: hidden; }
.bar-item .bar-fill { height: 100%; border-radius: 999px; background: linear-gradient(90deg, #2563eb, #06b6d4); }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); padding: 0 20px; background: #fff; flex-wrap: wrap; }
.tabs button {
  border: none; background: transparent; padding: 13px 16px; font-size: 13.5px;
  color: var(--text-2); cursor: pointer; border-bottom: 2px solid transparent;
  font-weight: 500; font-family: inherit;
}
.tabs button:hover { color: var(--text); }
.tabs button.active { color: var(--primary); border-bottom-color: var(--primary); }

.detail-list { display: grid; grid-template-columns: 110px 1fr; gap: 10px 14px; font-size: 13.5px; }
.detail-list dt { color: var(--muted); }
.detail-list dd { margin: 0; color: var(--text); word-break: break-all; }

.chat-view { display: flex; flex-direction: column; gap: 10px; max-height: 420px; overflow-y: auto; padding: 4px; }
.chat-msg { max-width: 78%; padding: 10px 14px; border-radius: 12px; font-size: 13.5px; line-height: 1.6; white-space: pre-wrap; word-break: break-word; }
.chat-msg.user { align-self: flex-end; background: var(--primary); color: #fff; border-bottom-right-radius: 4px; }
.chat-msg.assistant { align-self: flex-start; background: #f1f5f9; border-bottom-left-radius: 4px; }
.chat-msg .role { font-size: 11px; opacity: .7; margin-bottom: 4px; display: block; }

.tag-input { display: flex; gap: 8px; align-items: center; }
.notice { padding: 12px 16px; border-radius: 10px; background: #eff6ff; color: #1e40af; font-size: 13px; line-height: 1.6; margin-bottom: 16px; }
.notice.warn { background: #fffbeb; color: #92400e; }
.notice.danger { background: #fef2f2; color: #991b1b; }

.tenant-switch {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 4px 8px 4px 12px;
}
.tenant-switch select {
  width: auto;
  min-width: 130px;
  padding: 5px 8px;
  border: none;
  background: transparent;
  font-size: 12.5px;
  color: var(--text);
  outline: none;
}
.tenant-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--primary-light);
  color: var(--primary-dark);
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 12px;
  font-weight: 600;
}
.scope-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-radius: 12px;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  color: #1e40af;
  font-size: 13px;
  margin-bottom: 18px;
}
.scope-banner b { font-weight: 700; }

.mobile-only { display: none; }
@media (max-width: 900px) {
  .sidebar { position: fixed; left: -260px; transition: left .2s; }
  .sidebar.open { left: 0; box-shadow: 0 0 40px rgba(0,0,0,.4); }
  .page { padding: 18px 16px 40px; }
  .topbar { padding: 0 16px; }
  .mobile-only { display: inline-flex; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
}
