:root {
  color-scheme: light;
  --font-sans: "Plus Jakarta Sans", -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --bg: #f7f8fa;
  --surface: #ffffff;
  --surface-subtle: #fbfcfd;
  --line: #e6e8ee;
  --line-strong: #d3d8e2;
  --ink: #181c25;
  --ink-secondary: #343c4c;
  --mute: #5b6474;
  --primary: #3b5bdb;
  --primary-hover: #364fc7;
  --primary-soft: #eef2ff;
  --primary-border: #dbe4ff;
  --ok: #168564;
  --ok-soft: #ecfdf5;
  --ok-border: #b8efd9;
  --warn: #b45309;
  --warn-soft: #fffbeb;
  --warn-border: #fde68a;
  --err: #d14d52;
  --err-soft: #fef2f2;
  --err-border: #fecaca;
  --shadow-sm: 0 1px 2px rgba(24, 28, 37, 0.04);
  --shadow-md: 0 8px 24px rgba(24, 28, 37, 0.08);
  --shadow-lg: 0 18px 42px rgba(24, 28, 37, 0.14);
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

.num {
  font-variant-numeric: tabular-nums;
}

.mono {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

button,
a,
select,
input[type="checkbox"],
input[type="radio"],
[role="button"] {
  cursor: pointer;
}

button:disabled,
input:disabled,
select:disabled {
  cursor: not-allowed;
  opacity: 0.56;
}

:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* Layout Shell */
.app-shell {
  display: grid;
  grid-template-columns: 236px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 18px 14px;
  z-index: 20;
}

.brand-box {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px 16px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 14px;
}

.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: var(--primary);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.brand-title {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--ink);
  line-height: 1.2;
}

.brand-sub {
  font-size: 12px;
  color: var(--mute);
  margin-top: 2px;
}

.nav-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
}

.nav-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  min-height: 40px;
  padding: 8px 12px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--ink-secondary);
  font-size: 13.5px;
  font-weight: 500;
  text-align: left;
  transition: background-color 160ms ease, color 160ms ease, border-color 160ms ease;
}

.nav-btn:hover {
  background: var(--bg);
  color: var(--ink);
}

.nav-btn.active {
  background: var(--primary-soft);
  border-color: var(--primary-border);
  color: var(--primary);
  font-weight: 600;
}

.nav-btn-left {
  display: inline-flex;
  align-items: center;
  gap: 9px;
}

.nav-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  background: var(--bg);
  color: var(--mute);
}

.nav-badge.warn {
  background: var(--warn-soft);
  color: var(--warn);
  border: 1px solid var(--warn-border);
}

.nav-badge.err {
  background: var(--err-soft);
  color: var(--err);
  border: 1px solid var(--err-border);
}

.sidebar-foot {
  padding-top: 12px;
  border-top: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 12px;
  color: var(--mute);
}

.main-area {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

/* Persistent Top Bar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 15;
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
  padding: 10px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.topbar-metrics {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.topbar-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: var(--radius-sm);
  background: var(--bg);
  border: 1px solid var(--line);
  font-size: 12.5px;
  color: var(--ink-secondary);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.page-body {
  padding: 20px 24px 72px;
  max-width: 1520px;
  width: 100%;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

/* Buttons & Controls */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 38px;
  padding: 0 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--ink);
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  transition: background-color 150ms ease, border-color 150ms ease, transform 100ms ease;
  white-space: nowrap;
}

.btn:hover:not(:disabled) {
  background: var(--bg);
  border-color: #bcc3d0;
}

.btn:active:not(:disabled) {
  transform: translateY(1px);
}

.btn-sm {
  min-height: 32px;
  padding: 0 10px;
  font-size: 12.5px;
}

.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
}

.btn-soft {
  background: var(--primary-soft);
  border-color: var(--primary-border);
  color: var(--primary);
}

.btn-soft:hover:not(:disabled) {
  background: #e0e7ff;
}

.btn-ok {
  background: var(--ok);
  border-color: var(--ok);
  color: #fff;
}

.btn-ok:hover:not(:disabled) {
  background: #126f53;
}

.btn-danger {
  background: var(--err-soft);
  border-color: var(--err-border);
  color: var(--err);
}

.btn-danger:hover:not(:disabled) {
  background: #fee2e2;
}

/* Inputs */
.input,
.select,
.textarea {
  min-height: 38px;
  padding: 6px 11px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--ink);
  font-family: inherit;
  font-size: 13.5px;
  transition: border-color 150ms ease, box-shadow 150ms ease;
}

.textarea {
  min-height: 76px;
  resize: vertical;
  width: 100%;
}

.input:focus,
.select:focus,
.textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(59, 91, 219, 0.14);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.field-label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink-secondary);
}

.field-hint {
  font-size: 12px;
  color: var(--mute);
}

/* Cards & Panels */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  min-width: 0;
}

.card-pad {
  padding: 18px 20px;
}

.section-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.page-title {
  margin: 0;
  font-size: 19px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.page-desc {
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--mute);
}

.section-title {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
}

/* KPI Grid */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.kpi-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  padding: 14px 16px;
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
  background: var(--surface);
  text-align: left;
  transition: border-color 160ms ease, box-shadow 160ms ease, transform 120ms ease;
}

.kpi-card.clickable:hover {
  border-color: var(--primary);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.kpi-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  color: var(--mute);
  font-size: 12.5px;
  font-weight: 600;
}

.kpi-val {
  font-size: 24px;
  font-weight: 700;
  color: var(--ink);
  line-height: 1.15;
}

.kpi-sub {
  font-size: 12px;
  color: var(--mute);
}

/* Status Badges & Chips (Always Icon + Label) */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--ink-secondary);
  white-space: nowrap;
}

.badge-primary {
  background: var(--primary-soft);
  border-color: var(--primary-border);
  color: var(--primary);
}

.badge-ok {
  background: var(--ok-soft);
  border-color: var(--ok-border);
  color: var(--ok);
}

.badge-warn {
  background: var(--warn-soft);
  border-color: var(--warn-border);
  color: var(--warn);
}

.badge-err {
  background: var(--err-soft);
  border-color: var(--err-border);
  color: var(--err);
}

.chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.filter-tab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 34px;
  padding: 0 11px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink-secondary);
  font-size: 12.5px;
  font-weight: 600;
  transition: all 150ms ease;
}

.filter-tab:hover {
  border-color: var(--line-strong);
  background: var(--bg);
}

.filter-tab.active {
  background: var(--ink);
  border-color: var(--ink);
  color: #fff;
}

.kw-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 5px;
  font-size: 12px;
  background: var(--bg);
  border: 1px solid var(--line);
  color: var(--ink-secondary);
}

.kw-chip.exclude {
  background: var(--err-soft);
  border-color: var(--err-border);
  color: var(--err);
}

/* Toolbar & Tables */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-subtle);
}

.toolbar-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.search-ic {
  position: absolute;
  left: 10px;
  color: var(--mute);
  pointer-events: none;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 13px;
}

.data-table th {
  padding: 10px 14px;
  font-size: 12px;
  font-weight: 600;
  color: var(--mute);
  background: var(--surface-subtle);
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

.data-table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

.data-table tbody tr {
  transition: background-color 140ms ease;
}

.data-table tbody tr:hover {
  background: #f4f6fb;
}

.data-table tbody tr.row-selected {
  background: #eef2ff;
}

.row-title {
  font-weight: 600;
  color: var(--ink);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  max-width: 340px;
  line-height: 1.45;
}

.row-sub {
  font-size: 12px;
  color: var(--mute);
  margin-top: 3px;
}

/* Sticky Bulk Bar */
.bulk-bar {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 35;
  background: var(--ink);
  color: #fff;
  padding: 10px 16px;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

/* Progress bar */
.progress-track {
  width: 100%;
  height: 7px;
  border-radius: 999px;
  background: var(--bg);
  border: 1px solid var(--line);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 999px;
  transition: width 220ms ease;
}

.progress-fill.ok {
  background: var(--ok);
}

/* Alert Banner */
.alert-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  border: 1px solid var(--err-border);
  background: var(--err-soft);
  color: #991b1b;
}

.alert-banner.warn {
  border-color: var(--warn-border);
  background: var(--warn-soft);
  color: #92400e;
}

/* Drawer & Modal */
.backdrop {
  position: fixed;
  inset: 0;
  background: rgba(24, 28, 37, 0.42);
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-box {
  background: var(--surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 620px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-head,
.drawer-head {
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.modal-body,
.drawer-body {
  padding: 18px 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.modal-foot {
  padding: 12px 20px;
  border-top: 1px solid var(--line);
  background: var(--surface-subtle);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(24, 28, 37, 0.35);
  z-index: 55;
  display: flex;
  justify-content: flex-end;
}

.drawer-panel {
  background: var(--surface);
  width: min(560px, 100vw);
  height: 100vh;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
}

/* Five-stage Timeline */
.timeline {
  display: flex;
  flex-direction: column;
  gap: 10px;
  position: relative;
  padding-left: 6px;
}

.timeline-step {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--surface-subtle);
}

.timeline-step.reached {
  border-color: var(--ok-border);
  background: #f7fefa;
}

.timeline-dot {
  width: 22px;
  height: 22px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  background: var(--line);
  color: var(--mute);
  margin-top: 1px;
}

.timeline-step.reached .timeline-dot {
  background: var(--ok);
  color: #fff;
}

/* Toast */
.toast-stack {
  position: fixed;
  top: 64px;
  right: 24px;
  z-index: 80;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 380px;
}

.toast-item {
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-left: 4px solid var(--primary);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  padding: 11px 14px;
  font-size: 13px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.toast-item.ok {
  border-left-color: var(--ok);
}

.toast-item.err {
  border-left-color: var(--err);
}

/* Login Gate */
.auth-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: var(--bg);
}

.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: 28px;
}

/* Empty & Skeleton */
.empty-box {
  padding: 40px 20px;
  text-align: center;
  color: var(--mute);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.skeleton {
  background: linear-gradient(90deg, #eef0f4 25%, #f7f8fa 50%, #eef0f4 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  border-radius: var(--radius-sm);
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.spin {
  animation: spin 0.9s linear infinite;
}

/* Responsive Breakpoints */
@media (max-width: 1024px) {
  .kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .app-shell {
    grid-template-columns: minmax(0, 1fr);
  }
  .sidebar {
    position: static;
    height: auto;
    min-width: 0;
    border-right: none;
    border-bottom: 1px solid var(--line);
    padding: 12px 16px;
  }
  .brand-box {
    padding-bottom: 10px;
    margin-bottom: 10px;
  }
  .nav-list {
    flex-direction: row;
    overflow-x: auto;
    padding-bottom: 4px;
  }
  .nav-btn {
    width: auto;
    white-space: nowrap;
  }
  .sidebar-foot {
    display: none;
  }
  .topbar {
    padding: 10px 16px;
  }
  .page-body {
    padding: 16px 16px 80px;
  }
}

@media (max-width: 640px) {
  .kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .toast-stack {
    left: 12px;
    right: 12px;
    top: 12px;
    max-width: none;
  }
  .bulk-bar {
    left: 12px;
    right: 12px;
    transform: none;
    justify-content: space-between;
  }
}
