/* 杆杆响智慧助手 — 管理后台样式 */
/* 与 chat.css 保持统一的设计风格 */

* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  /* 继承深色主题配色 */
  --bg: #1a1a2e;
  --bg-surface: #16213e;
  --bg-card: #0f3460;
  --text: #e6e6e6;
  --text-muted: #a0a0b0;
  --accent: #e94560;
  --accent-light: #ff6b81;
  --border: #2a2a4a;
  
  /* 状态指示灯颜色 */
  --status-ok: #10b981;
  --status-warning: #f59e0b;
  --status-error: #ef4444;
  
  /* 按钮颜色 */
  --btn-danger: #ef4444;
  --btn-danger-hover: #dc2626;
}

html, body { 
  height: 100%; 
  font-family: -apple-system, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif; 
  background: var(--bg); 
  color: var(--text); 
  overflow-x: hidden;
}

/* ===== Header / Navigation ===== */
#header {
  display: flex; 
  align-items: center; 
  justify-content: space-between;
  height: 52px; 
  padding: 0 16px;
  background: var(--bg-surface); 
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

#header h1 { 
  font-size: 16px; 
  font-weight: 600; 
  white-space: nowrap; 
}

.header-left { display: flex; align-items: center; gap: 12px; }
.header-nav { display: flex; gap: 4px; }
.header-right { display: flex; align-items: center; gap: 12px; }

.nav-link {
  padding: 8px 16px;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 14px;
  border-radius: 6px;
  transition: all 0.2s;
}
.nav-link:hover { color: var(--text); background: var(--bg-card); }
.nav-link.active { 
  color: var(--accent); 
  background: rgba(233, 69, 96, 0.15); 
  font-weight: 500;
}

/* 自动刷新开关 */
.auto-refresh-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-muted);
  cursor: pointer;
}
.auto-refresh-toggle input {
  accent-color: var(--accent);
  cursor: pointer;
}

/* ===== Buttons ===== */
.btn {
  cursor: pointer; 
  border: none; 
  border-radius: 6px;
  padding: 8px 16px; 
  font-size: 13px; 
  font-weight: 500;
  transition: all 0.2s;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}
.btn-primary { 
  background: var(--accent); 
  color: #fff; 
}
.btn-primary:hover:not(:disabled) { 
  background: var(--accent-light); 
}
.btn-secondary { 
  background: var(--bg-card); 
  color: var(--text); 
  border: 1px solid var(--border);
}
.btn-secondary:hover:not(:disabled) { 
  background: var(--border); 
}
.btn-danger { 
  background: var(--btn-danger); 
  color: #fff; 
}
.btn-danger:hover:not(:disabled) { 
  background: var(--btn-danger-hover); 
}
.btn-icon { 
  background: var(--bg-card); 
  color: var(--text); 
  font-size: 16px; 
  width: 36px; 
  height: 36px; 
  padding: 0; 
  display: flex; 
  align-items: center; 
  justify-content: center;
  border-radius: 6px;
  border: none;
  cursor: pointer;
  transition: all 0.2s;
}
.btn-icon:hover { background: var(--border); }

/* Loading 状态 */
.btn.loading {
  position: relative;
  color: transparent;
}
.btn.loading::after {
  content: '';
  position: absolute;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ===== Main Layout ===== */
#main {
  padding: 24px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(380px, 1fr));
  gap: 24px;
  max-width: 1600px;
  margin: 0 auto;
}

/* ===== Card 组件 ===== */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-card);
}
.card-header h2 {
  font-size: 15px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}
.card-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}
.card-body {
  padding: 20px;
}

/* ===== Subsection ===== */
.subsection {
  margin-bottom: 24px;
}
.subsection:last-child {
  margin-bottom: 0;
}
.subsection h3 {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.subsection h4 {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 8px;
}

/* ===== Data Table ===== */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.data-table th,
.data-table td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
.data-table th {
  background: var(--bg-card);
  color: var(--text-muted);
  font-weight: 500;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.data-table tr:hover td {
  background: rgba(233, 69, 96, 0.05);
}
.data-table .hash {
  font-family: 'Consolas', 'Monaco', monospace;
  font-size: 11px;
  color: var(--text-muted);
  background: var(--bg-card);
  padding: 2px 6px;
  border-radius: 4px;
}

/* ===== Stats Grid ===== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 16px;
}
.stat-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px;
  background: var(--bg-card);
  border-radius: 8px;
}
.stat-label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.stat-value {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}

/* ===== Log List ===== */
.log-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 260px;
  overflow-y: auto;
}
.log-item {
  padding: 12px;
  background: var(--bg-card);
  border-radius: 8px;
  font-size: 13px;
  border-left: 3px solid var(--accent);
}
.log-item-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}
.log-time {
  color: var(--text-muted);
  font-size: 12px;
}
.log-stats {
  display: flex;
  gap: 12px;
  font-size: 12px;
}
.log-stat {
  display: flex;
  align-items: center;
  gap: 4px;
}
.log-stat.synced { color: var(--status-ok); }
.log-stat.skipped { color: var(--status-warning); }
.log-details {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 6px;
}
.log-empty {
  text-align: center;
  padding: 24px;
  color: var(--text-muted);
  font-size: 13px;
}

/* ===== Status Indicator ===== */
.status-indicator {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 500;
}
.status-indicator::before {
  content: '';
  width: 8px;
  height: 8px;
  border-radius: 50%;
  animation: pulse 2s infinite;
}
.status-indicator.ok {
  background: rgba(16, 185, 129, 0.15);
  color: var(--status-ok);
}
.status-indicator.ok::before {
  background: var(--status-ok);
}
.status-indicator.warning {
  background: rgba(245, 158, 11, 0.15);
  color: var(--status-warning);
}
.status-indicator.warning::before {
  background: var(--status-warning);
}
.status-indicator.error {
  background: rgba(239, 68, 68, 0.15);
  color: var(--status-error);
}
.status-indicator.error::before {
  background: var(--status-error);
  animation: none;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* ===== Freshness Info ===== */
.freshness-info {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}
.freshness-info h4 {
  margin-bottom: 12px;
}

/* ===== Loading Placeholder ===== */
.loading-placeholder {
  padding: 8px 0;
}
.skeleton {
  background: linear-gradient(90deg, var(--bg-card) 25%, var(--border) 50%, var(--bg-card) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: 8px;
}
.skeleton-table {
  height: 120px;
}
.skeleton-list {
  height: 180px;
}
.skeleton-stats {
  height: 100px;
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ===== Toast 通知 ===== */
#toast-container {
  position: fixed;
  top: 68px;
  right: 24px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 280px;
  max-width: 400px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  animation: slideInRight 0.3s ease;
}
.toast.success {
  background: var(--status-ok);
  color: #fff;
}
.toast.error {
  background: var(--status-error);
  color: #fff;
}
.toast.info {
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid var(--border);
}
.toast.warning {
  background: var(--status-warning);
  color: #000;
}
.toast-icon {
  font-size: 16px;
}

@keyframes slideInRight {
  from {
    transform: translateX(100%);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

/* ===== Modal 对话框 ===== */
.modal {
  position: fixed;
  inset: 0;
  z-index: 1001;
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal.hidden {
  display: none;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
}
.modal-content {
  position: relative;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
  min-width: 320px;
  max-width: 90vw;
  animation: scaleIn 0.2s ease;
}
.modal-content h3 {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 12px;
}
.modal-content p {
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: 20px;
}
.modal-actions {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
}

@keyframes scaleIn {
  from {
    transform: scale(0.95);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

/* ===== Hidden ===== */
.hidden {
  display: none !important;
}

/* ===== Tab 导航 ===== */
.tab-nav {
  display: flex;
  gap: 8px;
  padding: 16px 24px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
}
.tab-btn {
  padding: 10px 20px;
  font-size: 14px;
  font-weight: 500;
  background: transparent;
  color: var(--text-muted);
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
}
.tab-btn:hover {
  color: var(--text);
  background: var(--bg-card);
}
.tab-btn.active {
  color: var(--accent);
  background: rgba(233, 69, 96, 0.15);
}
.tab-content {
  display: none;
}
.tab-content.active {
  display: block;
}

/* ===== KPI 特定样式 ===== */
.kpi-actions {
  display: flex;
  align-items: center;
  gap: 16px;
}
.kpi-actions label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-muted);
}
.input-month {
  padding: 6px 10px;
  font-size: 13px;
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
}
.input-month:focus {
  outline: none;
  border-color: var(--accent);
}

/* KPI 表格可编辑输入框 */
.kpi-input {
  width: 100px;
  padding: 6px 10px;
  font-size: 13px;
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  text-align: right;
}
.kpi-input:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--bg-surface);
}
.kpi-input.modified {
  border-color: var(--status-warning);
  background: rgba(245, 158, 11, 0.1);
}

/* KPI 进度条 */
.kpi-progress {
  display: flex;
  align-items: center;
  gap: 8px;
}
.progress-bar {
  width: 100px;
  height: 8px;
  background: var(--bg-card);
  border-radius: 4px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.3s ease;
}
.progress-fill.green {
  background: var(--status-ok);
}
.progress-fill.blue {
  background: #3b82f6;
}
.progress-fill.orange {
  background: var(--status-warning);
}
.progress-text {
  font-size: 12px;
  font-weight: 500;
  min-width: 50px;
  text-align: right;
}

/* KPI 类型标签 */
.kpi-type-badge {
  display: inline-block;
  padding: 3px 8px;
  font-size: 11px;
  border-radius: 4px;
  background: var(--bg-card);
}
.kpi-type-badge.sales_revenue {
  background: rgba(16, 185, 129, 0.2);
  color: var(--status-ok);
}
.kpi-type-badge.lead_count {
  background: rgba(59, 130, 246, 0.2);
  color: #3b82f6;
}
.kpi-type-badge.contract_count {
  background: rgba(139, 92, 246, 0.2);
  color: #8b5cf6;
}

/* Card Footer */
.card-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  background: var(--bg-card);
  display: flex;
  justify-content: flex-end;
  gap: 12px;
}

/* 成功按钮 */
.btn-success {
  background: var(--status-ok);
  color: #fff;
}
.btn-success:hover:not(:disabled) {
  background: #059669;
}

/* 空状态 */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
}
.empty-state p {
  font-size: 14px;
}

/* ===== Scrollbar ===== */
.log-list::-webkit-scrollbar {
  width: 6px;
}
.log-list::-webkit-scrollbar-track {
  background: transparent;
}
.log-list::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}
.log-list::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
  #main {
    padding: 16px;
    grid-template-columns: 1fr;
    gap: 16px;
  }
  
  .card-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }
  
  .card-actions {
    width: 100%;
    justify-content: flex-start;
  }
  
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  
  .header-nav {
    display: none;
  }
  
  #header h1 {
    font-size: 14px;
  }
  
  .auto-refresh-toggle span {
    display: none;
  }
}

@media (max-width: 480px) {
  .stats-grid {
    grid-template-columns: 1fr;
  }
  
  .btn {
    padding: 6px 12px;
    font-size: 12px;
  }
  
  .data-table {
    font-size: 12px;
  }
  .data-table th,
  .data-table td {
    padding: 8px;
  }
}

/* ===== 权限管理样式 ===== */

/* 角色卡片网格 */
.roles-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

.role-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  transition: all 0.2s;
}

.role-card:hover {
  border-color: var(--accent);
  box-shadow: 0 4px 12px rgba(233, 69, 96, 0.15);
}

.role-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
}

.role-card-header h4 {
  font-size: 14px;
  font-weight: 600;
  margin: 0;
}

.role-code {
  font-size: 11px;
  color: var(--text-muted);
  background: var(--bg-card);
  padding: 3px 8px;
  border-radius: 4px;
  font-family: 'Consolas', 'Monaco', monospace;
}

.role-card-body {
  padding: 14px 16px;
}

.permission-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.permission-tag {
  display: inline-block;
  padding: 4px 8px;
  font-size: 11px;
  background: rgba(233, 69, 96, 0.15);
  color: var(--accent-light);
  border-radius: 4px;
}

.permission-tag.more {
  background: var(--bg-surface);
  color: var(--text-muted);
}

.role-desc {
  margin-top: 10px;
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.4;
}

.role-card-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 12px;
}

/* 角色选择器 */
.role-select {
  padding: 6px 10px;
  font-size: 13px;
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
  min-width: 120px;
}

.role-select:focus {
  outline: none;
  border-color: var(--accent);
}

.role-select.modified {
  border-color: var(--status-warning);
  background: rgba(245, 158, 11, 0.1);
}

.role-badge {
  display: inline-block;
  padding: 4px 10px;
  font-size: 12px;
  background: var(--bg-card);
  border-radius: 4px;
}

/* 权限编辑模态框 */
.modal-lg {
  min-width: 480px;
  max-width: 600px;
}

.permission-checkboxes {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin: 20px 0;
  max-height: 400px;
  overflow-y: auto;
  padding: 4px;
}

.permission-checkbox {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
}

.permission-checkbox:hover {
  border-color: var(--accent);
  background: var(--bg-surface);
}

.permission-checkbox input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
  cursor: pointer;
  flex-shrink: 0;
  margin-top: 2px;
}

.checkbox-label {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.perm-code {
  font-size: 11px;
  color: var(--text-muted);
  font-family: 'Consolas', 'Monaco', monospace;
}

.perm-label {
  font-size: 13px;
  color: var(--text);
}

/* 响应式适配 */
@media (max-width: 768px) {
  .roles-grid {
    grid-template-columns: 1fr;
  }
  
  .modal-lg {
    min-width: auto;
    width: 95vw;
  }
  
  .permission-checkboxes {
    grid-template-columns: 1fr;
  }
}
