/* ============================================
   CloudSync 管理面板样式
   遵循 DESIGN.md 设计规范
   ============================================ */

/* === Design Tokens === */
:root {
  --primary: #1890FF;
  --primary-hover: #40a9ff;
  --primary-active: #096dd9;
  --success: #52C41A;
  --warning: #FAAD14;
  --error: #FF4D4F;
  --purple: #722ED1;
  --text-primary: #1A1A2E;
  --text-secondary: #666;
  --text-muted: #999;
  --bg-page: #F0F2F5;
  --bg-card: #FFFFFF;
  --bg-sidebar: #001529;
  --border: #E8E8E8;
  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 8px;
  --shadow-sm: 0 1px 4px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.1);
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'PingFang SC', 'Microsoft YaHei', sans-serif;
  --sidebar-width: 220px;
}

/* === Reset === */
* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: var(--font); font-size: 14px; color: var(--text-primary); background: var(--bg-page); line-height: 1.5; }

/* === Layout === */
.layout { display: flex; min-height: 100vh; }

/* === Sidebar === */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-sidebar);
  color: #fff;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 100;
  transition: transform 0.3s ease;
}
.sidebar-header { padding: 16px 20px; border-bottom: 1px solid rgba(255,255,255,0.1); }
.logo { font-size: 18px; font-weight: 700; color: #fff; }
.sidebar-nav { flex: 1; padding: 8px 0; overflow-y: auto; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  color: rgba(255,255,255,0.65);
  text-decoration: none;
  transition: all 0.2s;
  border-left: 3px solid transparent;
}
.nav-item:hover { color: #fff; background: rgba(255,255,255,0.08); }
.nav-item.active { color: #fff; background: rgba(255,255,255,0.12); border-left-color: var(--primary); }

/* === Main === */
.main { flex: 1; margin-left: var(--sidebar-width); display: flex; flex-direction: column; min-height: 100vh; }

/* === Topbar === */
.topbar {
  height: 56px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 50;
}
.menu-toggle { display: none; background: none; border: none; cursor: pointer; padding: 4px; color: var(--text-primary); }
.topbar-title { font-size: 16px; font-weight: 600; }
.topbar-actions { margin-left: auto; }

.status-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  border-radius: 12px;
  font-size: 12px;
  background: #f6ffed;
  color: var(--success);
}
.status-badge.offline { background: #fff2f0; color: var(--error); }
.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  animation: pulse 2s infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* === Content === */
.content { flex: 1; padding: 24px; }
.page { display: none; }
.page.active { display: block; }
.page-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.page-header h2 { font-size: 20px; font-weight: 600; }

/* === Stats === */
.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 24px; }
.stat-card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
  position: relative;
  overflow: hidden;
  transition: transform 0.2s, box-shadow 0.2s;
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.stat-indicator {
  width: 4px;
  height: 48px;
  border-radius: 2px;
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
}
.stat-indicator.blue { background: var(--primary); }
.stat-indicator.green { background: var(--success); }
.stat-indicator.orange { background: var(--warning); }
.stat-indicator.purple { background: var(--purple); }
.stat-value { font-size: 28px; font-weight: 700; color: var(--text-primary); }
.stat-label { font-size: 13px; color: var(--text-secondary); }

/* === Card === */
.card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
  overflow: hidden;
}
.card-header { padding: 16px 20px; border-bottom: 1px solid var(--border); }
.card-header h3 { font-size: 15px; font-weight: 600; }
.card-body { padding: 16px 20px; }

/* === Table === */
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; padding: 10px 12px; font-weight: 600; color: var(--text-secondary); font-size: 12px; text-transform: uppercase; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table td { padding: 10px 12px; border-bottom: 1px solid #f5f5f5; vertical-align: middle; }
.table tr:hover td { background: #fafafa; }
.table .empty-text { text-align: center; color: var(--text-muted); padding: 40px 12px; }

/* === Toolbar === */
.toolbar { display: flex; gap: 12px; margin-bottom: 16px; }
.toolbar .input, .toolbar .select { max-width: 280px; }

/* === Form === */
.input, .select, .textarea {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 14px;
  font-family: var(--font);
  transition: border-color 0.2s, box-shadow 0.2s;
  background: #fff;
}
.input:hover, .select:hover, .textarea:hover { border-color: #b3b3b3; }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(24,144,255,0.1); }
.textarea { resize: vertical; min-height: 80px; }
.form-group { margin-bottom: 16px; }
.form-label { display: block; margin-bottom: 6px; font-weight: 500; font-size: 13px; }
.form-label .required { color: var(--error); }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }

/* === Button === */
.btn {
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 14px;
  font-family: var(--font);
  cursor: pointer;
  transition: all 0.2s;
  background: #fff;
  color: var(--text-primary);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.btn:hover { border-color: var(--primary); color: var(--primary); }
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); color: #fff; }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-danger { color: var(--error); border-color: var(--error); }
.btn-danger:hover { background: var(--error); color: #fff; }
.btn-ghost { background: transparent; border: 1px solid var(--border); color: var(--text-secondary); }
.btn-ghost:hover { background: var(--bg-page); color: var(--text-primary); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* === Badge === */
.badge { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 12px; font-weight: 500; }
.badge-success { background: #f6ffed; color: var(--success); }
.badge-warning { background: #fffbe6; color: #d48806; }
.badge-error { background: #fff2f0; color: var(--error); }
.badge-info { background: #e6f7ff; color: var(--primary); }

/* === Modal === */
.modal-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.45);
  z-index: 1000;
  align-items: center;
  justify-content: center;
}
.modal-overlay.show { display: flex; }
.modal {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  width: 560px;
  max-width: 90vw;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 8px 24px rgba(0,0,0,0.15);
  animation: modalIn 0.2s ease;
}
.modal-sm { width: 420px; }
@keyframes modalIn { from { opacity: 0; transform: translateY(-20px); } to { opacity: 1; transform: translateY(0); } }
.modal-header { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-header h3 { font-size: 16px; }
.modal-close { background: none; border: none; font-size: 22px; cursor: pointer; color: var(--text-muted); padding: 0 4px; }
.modal-close:hover { color: var(--text-primary); }
.modal-body { padding: 20px; }

/* === Pagination === */
.pagination { display: flex; justify-content: center; align-items: center; gap: 4px; margin-top: 16px; }
.pagination button {
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #fff;
  cursor: pointer;
  font-size: 13px;
}
.pagination button:hover { border-color: var(--primary); color: var(--primary); }
.pagination button.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.pagination button:disabled { opacity: 0.4; cursor: not-allowed; }

/* === Category Tree === */
.category-tree { padding: 8px 0; }
.tree-item { padding: 8px 0; }
.tree-item-row { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: var(--radius-sm); }
.tree-item-row:hover { background: #f5f5f5; }
.tree-children { padding-left: 24px; }
.tree-name { font-weight: 500; }
.tree-slug { color: var(--text-muted); font-size: 12px; }
.tree-actions { margin-left: auto; display: flex; gap: 4px; opacity: 0; }
.tree-item-row:hover .tree-actions { opacity: 1; }

/* === Toast === */
.toast-container { position: fixed; top: 16px; right: 16px; z-index: 2000; display: flex; flex-direction: column; gap: 8px; }
.toast {
  padding: 12px 20px;
  border-radius: var(--radius-md);
  background: var(--bg-card);
  box-shadow: 0 4px 16px rgba(0,0,0,0.12);
  display: flex;
  align-items: center;
  gap: 8px;
  animation: toastIn 0.3s ease;
  min-width: 240px;
}
.toast.success { border-left: 3px solid var(--success); }
.toast.error { border-left: 3px solid var(--error); }
.toast.info { border-left: 3px solid var(--primary); }
@keyframes toastIn { from { opacity: 0; transform: translateX(100px); } to { opacity: 1; transform: translateX(0); } }

/* === Responsive === */
@media (max-width: 992px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main { margin-left: 0; }
  .menu-toggle { display: block; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .table { font-size: 12px; }
}
@media (max-width: 576px) {
  .stats-grid { grid-template-columns: 1fr; }
  .toolbar { flex-direction: column; }
  .toolbar .input, .toolbar .select { max-width: 100%; }
}

/* === 登录页 === */
.login-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}
.login-card {
  background: var(--bg-card);
  border-radius: 12px;
  padding: 40px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.login-header {
  text-align: center;
  margin-bottom: 32px;
}
.login-header h1 {
  margin: 16px 0 8px;
  font-size: 24px;
  font-weight: 700;
  color: var(--text-primary);
}
.login-header p {
  color: var(--text-secondary);
  font-size: 14px;
  margin: 0;
}
.login-form .form-group { margin-bottom: 20px; }
.login-form .btn-block { width: 100%; justify-content: center; }
.login-form .btn-block svg { margin-right: 8px; }
.form-error {
  background: #fff2f0;
  border: 1px solid #ffccc7;
  color: var(--error);
  padding: 8px 12px;
  border-radius: 4px;
  font-size: 13px;
  margin-bottom: 16px;
}
.spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  margin-right: 6px;
  vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }
