:root {
  --bg-canvas: #f4f6fa;
  --bg-sidebar: #0f172a;
  --bg-sidebar-hover: #1e293b;
  --bg-sidebar-active: #2563eb;
  --bg-card: #ffffff;
  --border: #e5e9f2;
  --border-strong: #cbd5e1;
  --text-main: #0f172a;
  --text-sub: #475569;
  --text-muted: #64748b;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-soft: #eff6ff;
  --success: #059669;
  --success-soft: #ecfdf5;
  --warning: #d97706;
  --warning-soft: #fffbeb;
  --danger: #e11d48;
  --danger-soft: #fff1f2;
  --radius: 10px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow-md: 0 8px 24px rgba(15, 23, 42, 0.08);
  --font-sans: -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  font-family: var(--font-sans);
  font-size: 13.5px;
  color: var(--text-main);
  background: var(--bg-canvas);
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--text-muted); }
.text-danger { color: var(--danger); font-weight: 600; }
.text-success { color: var(--success); font-weight: 600; }
.text-warning { color: var(--warning); font-weight: 600; }
.text-primary { color: var(--primary); font-weight: 600; }

/* ─── Login Screen ─── */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: radial-gradient(circle at 20% 20%, #1e3a8a 0%, #0f172a 55%, #020617 100%);
}
.login-card {
  width: 100%;
  max-width: 460px;
  background: #ffffff;
  border-radius: 16px;
  padding: 36px 32px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
}
.login-brand {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 24px;
}
.login-brand h1 {
  margin: 0;
  font-size: 19px;
  font-weight: 700;
  color: var(--text-main);
}
.login-brand p { margin: 4px 0 0; font-size: 12.5px; }
.brand-logo-lg {
  width: 48px; height: 48px; border-radius: 12px;
  background: linear-gradient(135deg, #2563eb, #0ea5e9);
  color: #fff; font-weight: 800; font-size: 18px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.login-features {
  display: flex; flex-wrap: wrap; gap: 8px;
  margin-bottom: 24px;
}
.feat-pill {
  background: #f1f5f9;
  color: #334155;
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
}
.btn-feishu {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  padding: 13px 20px;
  background: #1456f0;
  color: #fff;
  text-decoration: none;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
  transition: background 0.15s, transform 0.1s;
}
.btn-feishu:hover { background: #0f44c7; transform: translateY(-1px); }
.login-footnote {
  margin-top: 18px;
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
  line-height: 1.5;
}
.alert-box {
  padding: 12px 14px;
  border-radius: 8px;
  margin-bottom: 18px;
  font-size: 12.5px;
  line-height: 1.55;
}
.alert-box.warn { background: var(--warning-soft); border: 1px solid #fcd34d; color: #92400e; }
.alert-box.err { background: var(--danger-soft); border: 1px solid #fda4af; color: #9f1239; }
.alert-box.info { background: var(--primary-soft); border: 1px solid #bfdbfe; color: #1e40af; }

/* ─── App Shell ─── */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 232px;
  background: var(--bg-sidebar);
  color: #e2e8f0;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  height: 100vh;
  z-index: 30;
}
.sidebar-header {
  display: flex; align-items: center; gap: 11px;
  padding: 16px 16px 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}
.brand-logo {
  width: 34px; height: 34px; border-radius: 8px;
  background: linear-gradient(135deg, #3b82f6, #06b6d4);
  color: #fff; font-weight: 800; font-size: 14px;
  display: flex; align-items: center; justify-content: center;
}
.brand-name { font-weight: 700; font-size: 14px; color: #fff; }
.brand-sub { font-size: 11px; color: #94a3b8; margin-top: 1px; }

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 10px 10px 18px;
}
.nav-group-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #64748b;
  padding: 12px 10px 6px;
  font-weight: 600;
}
.nav-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 11px;
  margin-bottom: 2px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: #cbd5e1;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  text-decoration: none;
  transition: background 0.12s, color 0.12s;
}
.nav-item:hover { background: var(--bg-sidebar-hover); color: #fff; }
.nav-item.active { background: var(--bg-sidebar-active); color: #fff; font-weight: 600; }
.nav-icon { font-size: 15px; width: 18px; text-align: center; }

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 11.5px;
  color: #94a3b8;
}
.status-dot-wrap { display: flex; align-items: center; gap: 8px; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.status-dot.ok { background: #10b981; box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.22); }

.main-wrap {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.topbar {
  height: 56px;
  background: #fff;
  border-bottom: 1px solid var(--border);
  padding: 0 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar-left { display: flex; align-items: center; gap: 12px; min-width: 0; }
.topbar-left h2 { margin: 0; font-size: 16px; font-weight: 700; white-space: nowrap; }
.page-subtitle { font-size: 12px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-right { display: flex; align-items: center; gap: 10px; }

.user-chip {
  display: flex; align-items: center; gap: 8px;
  padding: 4px 10px 4px 5px;
  border-radius: 999px;
  background: #f8fafc;
  border: 1px solid var(--border);
}
.user-avatar, .user-avatar-fallback {
  width: 28px; height: 28px; border-radius: 50%;
  object-fit: cover;
}
.user-avatar-fallback {
  background: var(--primary); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 12px;
}
.user-name { font-size: 12.5px; font-weight: 600; line-height: 1.1; }
.user-role { font-size: 10.5px; color: var(--text-muted); text-transform: uppercase; }

.content {
  padding: 18px 22px 40px;
  max-width: 1520px;
  width: 100%;
  margin: 0 auto;
}

/* ─── Cards, Grids & Controls ─── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 16px 18px;
  margin-bottom: 16px;
}
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.card-title { margin: 0; font-size: 14.5px; font-weight: 700; display: flex; align-items: center; gap: 8px; }

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(175px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.kpi-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow-sm);
}
.kpi-card.danger { border-left: 4px solid var(--danger); background: #fffafb; }
.kpi-card.success { border-left: 4px solid var(--success); }
.kpi-card.primary { border-left: 4px solid var(--primary); }
.kpi-label { font-size: 12px; color: var(--text-muted); margin-bottom: 6px; display: flex; justify-content: space-between; }
.kpi-value { font-size: 22px; font-weight: 700; color: var(--text-main); font-variant-numeric: tabular-nums; line-height: 1.2; }
.kpi-sub { font-size: 11.5px; color: var(--text-muted); margin-top: 6px; }

.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; margin-bottom: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; margin-bottom: 16px; }
.chart-box { width: 100%; height: 270px; }

.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.spacer { flex: 1; }

.input, .select {
  height: 34px;
  padding: 0 11px;
  border: 1px solid var(--border-strong);
  border-radius: 7px;
  font-size: 13px;
  color: var(--text-main);
  background: #fff;
  outline: none;
}
.input:focus, .select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12); }
.input-sm { height: 30px; font-size: 12.5px; padding: 0 9px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 34px;
  padding: 0 14px;
  border-radius: 7px;
  border: 1px solid transparent;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: all 0.12s;
  white-space: nowrap;
}
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-sm { height: 30px; padding: 0 10px; font-size: 12px; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover:not(:disabled) { background: #047857; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: #be123c; }
.btn-ghost { background: #fff; border-color: var(--border-strong); color: var(--text-main); }
.btn-ghost:hover:not(:disabled) { background: #f8fafc; }
.btn-soft-danger { background: var(--danger-soft); border-color: #fecdd3; color: var(--danger); }
.btn-soft-danger.active { background: var(--danger); color: #fff; border-color: var(--danger); }

.seg-group {
  display: inline-flex;
  background: #eef2f7;
  padding: 3px;
  border-radius: 8px;
}
.seg-btn {
  border: none;
  background: transparent;
  padding: 5px 12px;
  border-radius: 6px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-sub);
  cursor: pointer;
}
.seg-btn.active { background: #fff; color: var(--primary); box-shadow: var(--shadow-sm); }

/* ─── Tables ─── */
.table-wrap { overflow-x: auto; width: 100%; }
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
}
th {
  background: #f8fafc;
  color: var(--text-sub);
  font-weight: 600;
  text-align: left;
  padding: 9px 10px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
td {
  padding: 9px 10px;
  border-bottom: 1px solid #f1f5f9;
  vertical-align: middle;
}
tr:hover td { background: #fafcff; }
tr.row-danger td { background: #fff1f2; }
tr.row-danger:hover td { background: #ffe4e6; }
.right { text-align: right; }

.thumb {
  width: 38px; height: 38px; border-radius: 6px;
  object-fit: cover; border: 1px solid var(--border);
  background: #f1f5f9;
}
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}
.badge-blue { background: var(--primary-soft); color: var(--primary); }
.badge-green { background: var(--success-soft); color: var(--success); }
.badge-amber { background: var(--warning-soft); color: var(--warning); }
.badge-red { background: var(--danger-soft); color: var(--danger); }
.badge-gray { background: #f1f5f9; color: #475569; }

/* ─── Dropzone ─── */
.dropzone {
  border: 2px dashed #94a3b8;
  border-radius: 12px;
  padding: 36px 20px;
  text-align: center;
  background: #f8fafc;
  cursor: pointer;
  transition: all 0.15s;
}
.dropzone:hover, .dropzone.dragover {
  border-color: var(--primary);
  background: var(--primary-soft);
}
.dropzone-icon { font-size: 34px; margin-bottom: 8px; }
.dropzone-title { font-size: 15px; font-weight: 700; margin-bottom: 6px; }

/* ─── Modals & Toasts ─── */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(15, 23, 42, 0.5);
  display: flex; align-items: center; justify-content: center;
  z-index: 60; padding: 20px;
}
.modal-box {
  width: 100%; max-width: 500px;
  background: #fff; border-radius: 12px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.25);
  overflow: hidden;
}
.modal-lg { max-width: 760px; }
.modal-head {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.modal-head h3 { margin: 0; font-size: 15px; }
.modal-body { padding: 16px 18px; max-height: 70vh; overflow-y: auto; }
.modal-foot {
  padding: 12px 18px;
  border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end; gap: 10px;
}
.icon-btn {
  border: none; background: transparent; font-size: 16px;
  cursor: pointer; color: var(--text-sub); padding: 4px 8px; border-radius: 6px;
}
.icon-btn:hover { background: #f1f5f9; }

.toast-container {
  position: fixed; right: 20px; bottom: 20px;
  display: flex; flex-direction: column; gap: 8px;
  z-index: 80;
}
.toast {
  background: #0f172a; color: #fff;
  padding: 11px 16px; border-radius: 9px;
  font-size: 13px; box-shadow: var(--shadow-md);
  max-width: 380px;
}
.toast.ok { background: #065f46; }
.toast.err { background: #9f1239; }

.loading-center {
  text-align: center; padding: 60px 20px; color: var(--text-muted); font-size: 14px;
}
.pre-json {
  background: #0f172a; color: #e2e8f0; padding: 12px; border-radius: 8px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px;
  overflow-x: auto; max-height: 320px;
}
.mobile-only { display: none; }

@media (max-width: 960px) {
  .sidebar { position: fixed; left: -240px; transition: left 0.2s; }
  .sidebar.open { left: 0; }
  .mobile-only { display: inline-flex; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .content { padding: 14px; }
}
