:root {
  --bg: #0f1117;
  --surface: #181a23;
  --surface-2: #20232e;
  --surface-3: #282b38;
  --border: rgba(255,255,255,0.08);
  --border-h: rgba(255,255,255,0.16);
  --text: #e4e6eb;
  --text-2: #9ca3af;
  --text-3: #6b7280;
  --accent: #6366f1;
  --accent-l: #818cf8;
  --green: #34d399;
  --green-l: #6ee7b7;
  --red: #f87171;
  --amber: #fbbf24;
  --blue: #60a5fa;
  --cyan: #22d3ee;
  --radius: 10px;
  --radius-lg: 14px;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  line-height: 1.6;
}
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-h); }

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

/* Sidebar */
.sidebar {
  width: 220px; min-height: 100vh; background: var(--surface);
  border-right: 1px solid var(--border); padding: 20px 0; flex-shrink: 0;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.logo { padding: 0 22px 24px; display: flex; align-items: center; gap: 10px; }
.logo-icon {
  width: 36px; height: 36px; border-radius: 9px;
  background: linear-gradient(135deg, var(--accent), var(--cyan));
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; font-weight: 700; color: #fff;
}
.logo-text { font-size: 15px; font-weight: 600; }
.logo-text span { display: block; font-size: 11px; color: var(--text-3); font-weight: 400; }
.nav { padding: 0 12px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; border-radius: 8px; cursor: pointer;
  color: var(--text-2); font-size: 13px; font-weight: 500;
  transition: all 0.15s; margin-bottom: 2px; user-select: none;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--accent); color: #fff; }
.nav-item .icon { font-size: 16px; width: 20px; text-align: center; }
.nav-badge {
  margin-left: auto; background: var(--surface-3);
  padding: 1px 8px; border-radius: 10px; font-size: 11px;
}
.nav-item.active .nav-badge { background: rgba(255,255,255,0.2); }
.sidebar-footer { padding: 16px 22px; margin-top: auto; font-size: 11px; color: var(--text-3); border-top: 1px solid var(--border); }

/* Main */
.main { flex: 1; padding: 28px 36px; max-width: 100%; overflow-x: hidden; }
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 24px; }
.page-title { font-size: 22px; font-weight: 600; }
.page-desc { font-size: 13px; color: var(--text-2); margin-top: 2px; }

/* Buttons */
.btn {
  padding: 8px 16px; border-radius: 8px; font-size: 13px; font-weight: 500;
  cursor: pointer; border: 1px solid var(--border-h); background: var(--surface-2);
  color: var(--text); transition: all 0.15s; display: inline-flex; align-items: center; gap: 6px;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-3); border-color: var(--border-h); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-l); }
.btn-success { background: var(--green); border-color: var(--green); color: #042f1e; }
.btn-danger { background: transparent; border-color: var(--red); color: var(--red); }
.btn-danger:hover { background: rgba(248,113,113,0.1); }
.btn-sm { padding: 5px 12px; font-size: 12px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Cards */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 20px;
}
.card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.card-title { font-size: 15px; font-weight: 600; }

/* Stats grid */
.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 24px; }
.stat-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 18px 20px;
}
.stat-label { font-size: 12px; color: var(--text-2); margin-bottom: 8px; }
.stat-value { font-size: 28px; font-weight: 700; }
.stat-trend { font-size: 12px; margin-top: 6px; display: flex; align-items: center; gap: 4px; }
.stat-trend.up { color: var(--green); }
.stat-trend.down { color: var(--red); }
.stat-icon { width: 40px; height: 40px; border-radius: 10px; display: flex; align-items: center; justify-content: center; font-size: 20px; float: right; }

/* Table */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; padding: 10px 14px; color: var(--text-2); font-weight: 500; font-size: 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
td { padding: 12px 14px; border-bottom: 1px solid var(--border); }
tr:hover td { background: var(--surface-2); }
.table-empty { text-align: center; padding: 40px; color: var(--text-3); }

/* Badges */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 10px; border-radius: 20px; font-size: 12px; font-weight: 500; }
.badge-green { background: rgba(52,211,153,0.12); color: var(--green); }
.badge-red { background: rgba(248,113,113,0.12); color: var(--red); }
.badge-amber { background: rgba(251,191,36,0.12); color: var(--amber); }
.badge-blue { background: rgba(96,165,250,0.12); color: var(--blue); }
.badge-gray { background: var(--surface-3); color: var(--text-2); }
.badge-purple { background: rgba(129,140,248,0.12); color: var(--accent-l); }

/* Form */
.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: 13px; color: var(--text-2); margin-bottom: 6px; font-weight: 500; }
.form-input, .form-select {
  width: 100%; padding: 9px 12px; background: var(--surface-2);
  border: 1px solid var(--border-h); border-radius: 8px; color: var(--text);
  font-size: 13px; outline: none; transition: border 0.15s;
}
.form-input:focus, .form-select:focus { border-color: var(--accent); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

/* Modal */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center; z-index: 100;
  backdrop-filter: blur(4px);
}
.modal {
  background: var(--surface); border: 1px solid var(--border-h);
  border-radius: var(--radius-lg); padding: 24px; width: 520px; max-width: 90vw;
  max-height: 85vh; overflow-y: auto;
}
.modal-title { font-size: 17px; font-weight: 600; margin-bottom: 20px; }
.modal-footer { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }

/* Toast */
.toast-wrap { position: fixed; top: 20px; right: 20px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--surface); border: 1px solid var(--border-h);
  border-radius: 8px; padding: 12px 18px; font-size: 13px;
  display: flex; align-items: center; gap: 10px; min-width: 280px;
  animation: slideIn 0.25s ease;
}
.toast.success { border-left: 3px solid var(--green); }
.toast.error { border-left: 3px solid var(--red); }
.toast.info { border-left: 3px solid var(--blue); }
.toast.warning { border-left: 3px solid var(--amber); }
@keyframes slideIn { from { transform: translateX(400px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* Toggle */
.toggle { position: relative; width: 38px; height: 22px; display: inline-block; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute; cursor: pointer; inset: 0;
  background: var(--surface-3); border-radius: 22px; transition: 0.2s;
}
.toggle-slider::before {
  content: ""; position: absolute; height: 16px; width: 16px;
  left: 3px; top: 3px; background: var(--text-2); border-radius: 50%; transition: 0.2s;
}
.toggle input:checked + .toggle-slider { background: var(--green); }
.toggle input:checked + .toggle-slider::before { transform: translateX(16px); background: #fff; }

/* Progress bar */
.progress { height: 6px; background: var(--surface-3); border-radius: 3px; overflow: hidden; }
.progress-bar { height: 100%; border-radius: 3px; transition: width 0.3s; }

/* Loading spinner */
.spinner {
  width: 16px; height: 16px; border: 2px solid var(--surface-3);
  border-top-color: var(--accent); border-radius: 50%;
  animation: spin 0.7s linear infinite; display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Sync flow diagram */
.sync-flow { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin: 12px 0; }
.sync-node { background: var(--surface-2); border: 1px solid var(--border-h); padding: 6px 12px; border-radius: 8px; font-size: 12px; }
.sync-arrow { color: var(--text-3); }
.sync-node.active { border-color: var(--accent); color: var(--accent-l); }
.sync-node.done { border-color: var(--green); color: var(--green); }

/* Sync page */
.sync-tabs { display: flex; gap: 8px; }
.sync-tab {
  flex: 1; padding: 14px 16px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); cursor: pointer; transition: all 0.15s; text-align: center;
  font-size: 14px; font-weight: 500; color: var(--text-2); user-select: none;
}
.sync-tab:hover { background: var(--surface-2); border-color: var(--border-h); }
.sync-tab.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.sync-tab-sub { display: block; font-size: 11px; font-weight: 400; opacity: 0.7; margin-top: 3px; }

.sync-info-item { display: flex; flex-direction: column; gap: 2px; }
.sync-info-label { font-size: 11px; color: var(--text-3); }
.sync-info-val { font-size: 13px; color: var(--text-2); }

.sync-note {
  background: rgba(96,165,250,0.06); border: 1px solid rgba(96,165,250,0.15);
  border-radius: 8px; padding: 12px 16px; font-size: 12px; color: var(--text-2); line-height: 1.7;
}
.sync-note code { background: var(--surface-3); padding: 1px 6px; border-radius: 4px; font-size: 11px; color: var(--cyan); }
.sync-warn {
  background: rgba(251,191,36,0.06); border: 1px solid rgba(251,191,36,0.15);
  border-radius: 8px; padding: 12px 16px; font-size: 13px; color: var(--amber);
}

.sync-input-table input.sync-input {
  width: 90px; padding: 6px 8px; font-size: 13px; text-align: center;
}
.sync-input-table td:first-child { white-space: nowrap; }

.btn-lg { padding: 10px 24px; font-size: 14px; }

/* Responsive */
@media (max-width: 900px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .sidebar { display: none; }
  .main { padding: 16px; }
  .form-row { grid-template-columns: 1fr; }
}
