/* ============================================================
   聚合机器人平台 - 黑白 SaaS 主题
   ============================================================ */

/* ---------- Reset & Base ---------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --black: #0a0a0a;
  --gray-900: #171717;
  --gray-800: #262626;
  --gray-700: #404040;
  --gray-600: #525252;
  --gray-500: #737373;
  --gray-400: #a3a3a3;
  --gray-300: #d4d4d4;
  --gray-200: #e5e5e5;
  --gray-100: #f5f5f5;
  --gray-50: #fafafa;
  --white: #ffffff;
  --red: #dc2626;
  --green: #16a34a;
  --amber: #d97706;
  --blue: #2563eb;
  --radius: 8px;
  --radius-sm: 6px;
  --sidebar-w: 240px;
  --header-h: 56px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --mono: "SF Mono", "JetBrains Mono", "Fira Code", Consolas, monospace;
}
html { font-size: 14px; -webkit-font-smoothing: antialiased; }
body {
  font-family: var(--font);
  background: var(--gray-50);
  color: var(--gray-900);
  line-height: 1.5;
  min-height: 100vh;
}
a { color: var(--black); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- Layout: Sidebar + Main ---------- */
.app-layout { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar-w);
  background: var(--black);
  color: var(--gray-300);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
}
.sidebar-logo {
  padding: 20px 24px;
  border-bottom: 1px solid var(--gray-800);
  display: flex;
  align-items: center;
  gap: 10px;
}
.sidebar-logo .logo-icon {
  width: 32px; height: 32px;
  background: var(--white);
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; font-weight: 800; color: var(--black);
}
.sidebar-logo .logo-text { font-size: 15px; font-weight: 700; color: var(--white); }
.sidebar-logo .logo-sub { font-size: 11px; color: var(--gray-500); }
.sidebar-nav { flex: 1; padding: 12px 12px; overflow-y: auto; }
.nav-section { margin-bottom: 20px; }
.nav-section-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--gray-600);
  padding: 0 12px;
  margin-bottom: 6px;
  font-weight: 600;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  color: var(--gray-400);
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  margin-bottom: 2px;
}
.nav-item:hover { background: var(--gray-800); color: var(--white); text-decoration: none; }
.nav-item.active { background: var(--white); color: var(--black); font-weight: 600; }
.nav-item .nav-icon { width: 18px; text-align: center; font-size: 15px; }
.nav-item .nav-badge {
  margin-left: auto;
  background: var(--gray-700);
  color: var(--gray-300);
  font-size: 11px;
  padding: 1px 7px;
  border-radius: 10px;
  font-weight: 600;
}
.nav-item.active .nav-badge { background: var(--black); color: var(--white); }
.sidebar-footer {
  padding: 16px;
  border-top: 1px solid var(--gray-800);
  font-size: 12px;
  color: var(--gray-600);
}
.sidebar-footer .version { font-family: var(--mono); }

.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}
.topbar {
  height: var(--header-h);
  background: var(--white);
  border-bottom: 1px solid var(--gray-200);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  position: sticky;
  top: 0;
  z-index: 50;
}
.topbar-title { font-size: 16px; font-weight: 700; color: var(--black); }
.topbar-right { display: flex; align-items: center; gap: 16px; }
.topbar-user {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px; color: var(--gray-600);
}
.topbar-user .avatar {
  width: 28px; height: 28px;
  background: var(--black);
  color: var(--white);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700;
}
.page-content { padding: 28px; flex: 1; }

/* ---------- Cards ---------- */
.card {
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  padding: 20px;
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.card-title { font-size: 15px; font-weight: 700; color: var(--black); }
.card-desc { font-size: 12px; color: var(--gray-500); margin-top: 2px; }

/* ---------- Stats Grid ---------- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  padding: 18px 20px;
  transition: border-color 0.15s;
}
.stat-card:hover { border-color: var(--gray-400); }
.stat-label { font-size: 12px; color: var(--gray-500); font-weight: 500; margin-bottom: 8px; text-transform: uppercase; letter-spacing: 0.04em; }
.stat-value { font-size: 26px; font-weight: 800; color: var(--black); line-height: 1.2; font-family: var(--mono); }
.stat-value.sm { font-size: 18px; }
.stat-value.ok { color: var(--green); }
.stat-value.warn { color: var(--amber); }
.stat-value.err { color: var(--red); }
.stat-sub { font-size: 12px; color: var(--gray-400); margin-top: 4px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 600;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.15s;
  font-family: var(--font);
  white-space: nowrap;
}
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-primary { background: var(--black); color: var(--white); border-color: var(--black); }
.btn-primary:hover:not(:disabled) { background: var(--gray-800); }
.btn-outline { background: var(--white); color: var(--black); border-color: var(--gray-300); }
.btn-outline:hover:not(:disabled) { background: var(--gray-50); border-color: var(--gray-400); }
.btn-danger { background: var(--red); color: var(--white); border-color: var(--red); }
.btn-danger:hover:not(:disabled) { background: #b91c1c; }
.btn-success { background: var(--green); color: var(--white); border-color: var(--green); }
.btn-success:hover:not(:disabled) { background: #15803d; }
.btn-warning { background: var(--amber); color: var(--white); border-color: var(--amber); }
.btn-warning:hover:not(:disabled) { background: #b45309; }
.btn-sm { padding: 5px 11px; font-size: 12px; }
.btn-lg { padding: 11px 24px; font-size: 14px; }
.btn-block { width: 100%; }

/* ---------- Forms ---------- */
.form-group { margin-bottom: 16px; }
.form-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--gray-700);
  margin-bottom: 6px;
}
.form-input, .form-select, .form-textarea {
  width: 100%;
  padding: 9px 12px;
  font-size: 13.5px;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius-sm);
  background: var(--white);
  color: var(--gray-900);
  font-family: var(--font);
  transition: border-color 0.15s, box-shadow 0.15s;
  outline: none;
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
  border-color: var(--black);
  box-shadow: 0 0 0 3px rgba(0,0,0,0.06);
}
.form-input::placeholder { color: var(--gray-400); }
.form-textarea { resize: vertical; min-height: 80px; }
.form-row { display: flex; gap: 12px; flex-wrap: wrap; }
.form-row .form-group { flex: 1; min-width: 160px; }
.form-hint { font-size: 12px; color: var(--gray-400); margin-top: 4px; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--gray-200); border-radius: var(--radius); background: var(--white); }
table.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data-table th {
  background: var(--gray-50);
  padding: 11px 14px;
  text-align: left;
  font-weight: 700;
  color: var(--gray-600);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--gray-200);
  white-space: nowrap;
}
table.data-table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--gray-100);
  color: var(--gray-800);
  vertical-align: middle;
}
table.data-table tr:last-child td { border-bottom: none; }
table.data-table tr:hover td { background: var(--gray-50); }
.table-empty { text-align: center; padding: 40px 20px; color: var(--gray-400); font-size: 13px; }
.mono { font-family: var(--mono); font-size: 12.5px; }
.text-ellipsis { max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.02em;
}
.badge::before {
  content: '';
  width: 6px; height: 6px;
  border-radius: 50%;
  background: currentColor;
}
.badge-success { background: #f0fdf4; color: var(--green); }
.badge-danger { background: #fef2f2; color: var(--red); }
.badge-warning { background: #fffbeb; color: var(--amber); }
.badge-info { background: #eff6ff; color: var(--blue); }
.badge-neutral { background: var(--gray-100); color: var(--gray-600); }
.badge-black { background: var(--black); color: var(--white); }

/* ---------- Toggle Switch ---------- */
.switch { position: relative; display: inline-block; width: 40px; height: 22px; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch-slider {
  position: absolute; cursor: pointer; inset: 0;
  background: var(--gray-300);
  border-radius: 22px;
  transition: 0.2s;
}
.switch-slider::before {
  content: '';
  position: absolute;
  height: 16px; width: 16px;
  left: 3px; bottom: 3px;
  background: var(--white);
  border-radius: 50%;
  transition: 0.2s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
.switch input:checked + .switch-slider { background: var(--black); }
.switch input:checked + .switch-slider::before { transform: translateX(18px); }
.switch input:disabled + .switch-slider { opacity: 0.4; cursor: not-allowed; }

/* ---------- Modal ---------- */
.modal-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(2px);
}
.modal-overlay.active { display: flex; }
.modal {
  background: var(--white);
  border-radius: var(--radius);
  width: 520px;
  max-width: 92vw;
  max-height: 88vh;
  overflow-y: auto;
  box-shadow: 0 25px 50px rgba(0,0,0,0.25);
  animation: modalIn 0.2s ease;
}
@keyframes modalIn { from { opacity: 0; transform: translateY(10px) scale(0.98); } to { opacity: 1; transform: none; } }
.modal-header {
  padding: 18px 24px;
  border-bottom: 1px solid var(--gray-200);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-title { font-size: 16px; font-weight: 700; color: var(--black); }
.modal-close {
  width: 28px; height: 28px;
  border: none; background: transparent;
  font-size: 18px; color: var(--gray-400);
  cursor: pointer; border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
}
.modal-close:hover { background: var(--gray-100); color: var(--black); }
.modal-body { padding: 24px; }
.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--gray-200);
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

/* ---------- Log Viewer ---------- */
.log-viewer {
  background: var(--black);
  color: var(--gray-300);
  padding: 16px;
  border-radius: var(--radius);
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.7;
  max-height: 420px;
  overflow-y: auto;
}
.log-viewer .log-info { color: #4ade80; }
.log-viewer .log-warn { color: #fbbf24; }
.log-viewer .log-error { color: #f87171; }
.log-viewer .log-time { color: var(--gray-500); }

/* ---------- Pagination ---------- */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin-top: 20px;
}
.pagination button {
  min-width: 32px;
  height: 32px;
  padding: 0 10px;
  border: 1px solid var(--gray-300);
  background: var(--white);
  color: var(--gray-700);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  font-family: var(--font);
  transition: all 0.15s;
}
.pagination button:hover:not(:disabled) { border-color: var(--black); color: var(--black); }
.pagination button.active { background: var(--black); color: var(--white); border-color: var(--black); }
.pagination button:disabled { opacity: 0.4; cursor: not-allowed; }
.pagination .page-info { font-size: 12px; color: var(--gray-500); margin: 0 8px; }

/* ---------- Alert / Message ---------- */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  margin-bottom: 16px;
  border: 1px solid;
}
.alert-error { background: #fef2f2; border-color: #fecaca; color: var(--red); }
.alert-success { background: #f0fdf4; border-color: #bbf7d0; color: var(--green); }
.alert-warning { background: #fffbeb; border-color: #fde68a; color: var(--amber); }
.alert-info { background: #f5f5f5; border-color: var(--gray-200); color: var(--gray-700); }

/* ---------- Feature List ---------- */
.feature-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 0;
  border-bottom: 1px solid var(--gray-100);
}
.feature-item:last-child { border-bottom: none; }
.feature-info h4 { font-size: 14px; font-weight: 700; color: var(--black); margin-bottom: 3px; }
.feature-info p { font-size: 12.5px; color: var(--gray-500); }
.feature-disabled { opacity: 0.45; }

/* ---------- Toolbar ---------- */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  gap: 12px;
  flex-wrap: wrap;
}
.toolbar-filters { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.toolbar-filters .form-group { margin-bottom: 0; }
.toolbar-filters .form-input, .toolbar-filters .form-select { width: auto; min-width: 160px; }

/* ---------- QR Code Box ---------- */
.qr-box { text-align: center; padding: 10px 0; }
.qr-box img { max-width: 220px; border: 1px solid var(--gray-200); border-radius: var(--radius); }
.qr-url {
  word-break: break-all;
  background: var(--gray-50);
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  margin-top: 14px;
  font-size: 12px;
  color: var(--gray-600);
  font-family: var(--mono);
  border: 1px solid var(--gray-200);
}

/* ---------- Key Output Box ---------- */
.key-output {
  background: var(--black);
  color: #4ade80;
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  font-family: var(--mono);
  font-size: 13px;
  max-height: 180px;
  overflow-y: auto;
  line-height: 1.8;
  margin-top: 12px;
  white-space: pre-wrap;
  word-break: break-all;
}

/* ---------- Scrollbar ---------- */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--gray-300); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--gray-400); }

/* ---------- Responsive ---------- */
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); transition: transform 0.2s; }
  .sidebar.open { transform: translateX(0); }
  .main-content { margin-left: 0; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .page-content { padding: 16px; }
}
