* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; background: #f0f2f5; color: #333; min-height: 100vh; }

/* 登录页 */
.login-page { display: flex; justify-content: center; align-items: center; min-height: 100vh; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); }
.login-box { background: white; padding: 40px; border-radius: 12px; box-shadow: 0 8px 32px rgba(0,0,0,0.2); min-width: 360px; }
.login-box h1 { text-align: center; margin-bottom: 8px; font-size: 24px; }
.login-subtitle { text-align: center; color: #999; margin-bottom: 24px; font-size: 14px; }
.btn-block { width: 100%; margin-top: 16px; }

/* 主页面 */
.main-page { min-height: 100vh; }
.header { background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: white; padding: 16px 24px; display: flex; justify-content: space-between; align-items: center; box-shadow: 0 2px 8px rgba(0,0,0,0.15); }
.header h1 { font-size: 20px; font-weight: 600; }
.header-actions { display: flex; gap: 8px; }

.container { display: flex; gap: 16px; padding: 16px; max-width: 1800px; margin: 0 auto; }

/* 侧边栏 */
.sidebar { width: 280px; background: white; border-radius: 8px; box-shadow: 0 1px 4px rgba(0,0,0,0.06); padding: 16px; height: fit-content; }
.sidebar-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; padding-bottom: 12px; border-bottom: 2px solid #f0f0f0; }
.sidebar-header h3 { font-size: 16px; color: #333; }
.account-list { display: flex; flex-direction: column; gap: 8px; }
.account-item { padding: 12px; border: 1px solid #e8e8e8; border-radius: 6px; cursor: pointer; transition: all 0.2s; position: relative; }
.account-item:hover { border-color: #667eea; background: #f5f7ff; }
.account-item.active { border-color: #667eea; background: #f5f7ff; box-shadow: 0 0 0 2px rgba(102,126,234,0.2); }
.account-item-name { font-weight: 600; font-size: 14px; color: #333; margin-bottom: 4px; }
.account-item-id { font-size: 12px; color: #999; }
.account-item-balance { font-size: 12px; color: #52c41a; font-weight: 600; margin-top: 4px; }
.account-item-remove { position: absolute; top: 8px; right: 8px; background: #ff4d4f; color: white; border: none; border-radius: 4px; width: 20px; height: 20px; font-size: 12px; cursor: pointer; display: none; }
.account-item:hover .account-item-remove { display: block; }
.loading-text { text-align: center; color: #999; padding: 20px; }

/* 内容区 */
.content { flex: 1; min-width: 0; }
.account-info { background: white; padding: 16px 20px; border-radius: 8px; box-shadow: 0 1px 4px rgba(0,0,0,0.06); margin-bottom: 12px; display: flex; gap: 24px; flex-wrap: wrap; }
.info-item { display: flex; align-items: center; gap: 6px; }
.info-label { color: #999; font-size: 13px; }
.info-value { font-weight: 600; font-size: 14px; color: #333; }
.info-value.balance { color: #52c41a; }

.toolbar { background: white; padding: 12px 20px; border-radius: 8px; box-shadow: 0 1px 4px rgba(0,0,0,0.06); margin-bottom: 12px; display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.toolbar-group { display: flex; align-items: center; gap: 6px; }
.toolbar-group label { font-size: 14px; color: #666; white-space: nowrap; }

.select, .input { padding: 6px 12px; border: 1px solid #d9d9d9; border-radius: 6px; font-size: 14px; outline: none; transition: border-color 0.2s; }
.select:focus, .input:focus { border-color: #667eea; box-shadow: 0 0 0 2px rgba(102,126,234,0.2); }
.select { min-width: 120px; cursor: pointer; }
.input[type="date"] { width: 150px; }

.btn { padding: 8px 16px; border: 1px solid #d9d9d9; border-radius: 6px; background: white; cursor: pointer; font-size: 14px; transition: all 0.2s; white-space: nowrap; }
.btn:hover { border-color: #667eea; color: #667eea; }
.btn:active { transform: scale(0.98); }
.btn-sm { padding: 4px 12px; font-size: 12px; }
.btn-primary { background: #667eea; color: white; border-color: #667eea; }
.btn-primary:hover { background: #5a6fd6; border-color: #5a6fd6; color: white; }
.btn-secondary { background: #722ed1; color: white; border-color: #722ed1; }
.btn-secondary:hover { background: #6528ba; border-color: #6528ba; color: white; }
.btn-success { background: #52c41a; color: white; border-color: #52c41a; }
.btn-success:hover { background: #49b018; color: white; }
.btn-danger { background: #ff4d4f; color: white; border-color: #ff4d4f; }
.btn-danger:hover { background: #e64446; color: white; }
.btn-warning { background: #faad14; color: white; border-color: #faad14; }
.btn-warning:hover { background: #e09d12; color: white; }

.stats-bar { background: white; padding: 12px 20px; border-radius: 8px; box-shadow: 0 1px 4px rgba(0,0,0,0.06); margin-bottom: 12px; display: flex; gap: 32px; flex-wrap: wrap; }
.stats-bar .stat { text-align: center; }
.stats-bar .stat-label { font-size: 12px; color: #999; margin-bottom: 4px; }
.stats-bar .stat-value { font-size: 18px; font-weight: 700; color: #333; }
.stats-bar .stat-value.cost { color: #ff4d4f; }
.stats-bar .stat-value.gmv { color: #52c41a; }
.stats-bar .stat-value.roi { color: #667eea; }

.table-container { background: white; border-radius: 8px; box-shadow: 0 1px 4px rgba(0,0,0,0.06); overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th { background: #fafafa; padding: 12px 16px; text-align: left; font-size: 13px; color: #666; font-weight: 600; border-bottom: 2px solid #f0f0f0; white-space: nowrap; }
.table td { padding: 10px 16px; border-bottom: 1px solid #f0f0f0; font-size: 14px; }
.table tr:hover { background: #f5f7ff; }
.table .loading { text-align: center; color: #999; padding: 40px; font-size: 15px; }

.status-tag { display: inline-block; padding: 2px 8px; border-radius: 4px; font-size: 12px; font-weight: 500; }
.status-enable { background: #f6ffed; color: #52c41a; border: 1px solid #b7eb8f; }
.status-disable { background: #fff1f0; color: #ff4d4f; border: 1px solid #ffa39e; }
.status-delete { background: #f5f5f5; color: #999; border: 1px solid #d9d9d9; }
.goal-tag { display: inline-block; padding: 2px 8px; border-radius: 4px; font-size: 12px; font-weight: 500; background: #e6f7ff; color: #1890ff; border: 1px solid #91d5ff; }
.cf-tag { background: #fff3e0; color: #e65100; border: 1px solid #ffb74d; }

.actions { display: flex; gap: 6px; flex-wrap: nowrap; }

.modal-overlay { display: none; position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.5); z-index: 1000; justify-content: center; align-items: center; }
.modal-overlay.active { display: flex; }
.modal { background: white; padding: 28px; border-radius: 12px; min-width: 380px; max-width: 500px; box-shadow: 0 8px 32px rgba(0,0,0,0.2); }
.modal h3 { margin-bottom: 16px; font-size: 18px; color: #333; }
.modal p { color: #666; margin-bottom: 16px; font-size: 14px; word-break: break-all; }
.form-group { margin-bottom: 16px; }
.form-group label { display: block; margin-bottom: 6px; font-size: 14px; color: #666; font-weight: 500; }
.modal-input { width: 100%; margin-bottom: 16px; padding: 10px 12px; font-size: 16px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; }
.modal-actions .btn { min-width: 80px; }

.auth-link-box { background: #f5f7ff; padding: 12px; border-radius: 6px; font-size: 13px; word-break: break-all; color: #667eea; cursor: pointer; border: 1px dashed #667eea; }
.auth-link-box:hover { background: #eef2ff; }

.modal-divider { border: none; border-top: 1px solid #e8e8e8; margin: 20px 0; }

.toast { position: fixed; top: 20px; right: 20px; padding: 12px 20px; border-radius: 8px; color: white; font-size: 14px; z-index: 2000; transform: translateX(120%); transition: transform 0.3s ease; max-width: 360px; box-shadow: 0 4px 12px rgba(0,0,0,0.15); }
.toast.show { transform: translateX(0); }
.toast.success { background: #52c41a; }
.toast.error { background: #ff4d4f; }
.toast.info { background: #1890ff; }

@media (max-width: 1200px) {
  .container { flex-direction: column; }
  .sidebar { width: 100%; }
}

@media (max-width: 768px) {
  .toolbar { flex-direction: column; align-items: stretch; }
  .toolbar-group { width: 100%; }
  .select, .input[type="date"] { width: 100%; }
  .stats-bar { gap: 16px; }
  .account-info { flex-direction: column; gap: 8px; }
}

.filter-check { display: flex; align-items: center; gap: 4px; font-size: 13px; color: #666; cursor: pointer; white-space: nowrap; margin-left: auto; }
.filter-check input { cursor: pointer; }


.tag { display: inline-block; padding: 1px 6px; border-radius: 3px; font-size: 11px; font-weight: 500; vertical-align: middle; }
.tag-blue { background: #e6f7ff; color: #1890ff; border: 1px solid #91d5ff; }
.tag-purple { background: #f9f0ff; color: #722ed1; border: 1px solid #d3adf7; }


.sortable { cursor: pointer; user-select: none; }
.sortable:hover { background-color: #f0f0f0; }
.sort-icon { font-size: 12px; color: #999; margin-left: 4px; }
.sortable:hover .sort-icon { color: #333; }

.btn-success { background: #52c41a; color: #fff; }
.btn-success:hover { background: #45a818; }
.sidebar-header { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.sidebar-header h3 { flex: 1; margin: 0; }

.step-container {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin: 16px 0;
  padding: 12px;
  background: #f8f9fa;
  border-radius: 8px;
}
.step-item {
  display: flex;
  align-items: center;
  gap: 6px;
  opacity: 0.4;
  transition: all 0.3s;
}
.step-item.active { opacity: 1; }
.step-item.done { opacity: 0.7; }
.step-number {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #ddd;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: bold;
}
.step-item.active .step-number { background: #667eea; }
.step-item.done .step-number { background: #52c41a; }
.step-text { font-size: 13px; color: #666; }
.step-item.active .step-text { color: #333; font-weight: 600; }
.step-arrow { color: #ccc; font-size: 16px; }
.oauth-step-content { min-height: 120px; }

/* BP/Shop badges */
.bp-badge { display: inline-block; padding: 1px 6px; border-radius: 3px; font-size: 11px; font-weight: 500; background: #fff7e6; color: #fa8c16; border: 1px solid #ffd591; vertical-align: middle; }
.shop-badge { display: inline-block; padding: 1px 6px; border-radius: 3px; font-size: 11px; font-weight: 500; background: #f6ffed; color: #52c41a; border: 1px solid #b7eb8f; vertical-align: middle; }

/* Rename and resolve buttons */
.account-item-rename { position: absolute; top: 8px; right: 32px; background: transparent; color: #999; border: none; cursor: pointer; font-size: 14px; display: none; padding: 2px 4px; border-radius: 3px; }
.account-item-rename:hover { color: #1890ff; background: #e6f7ff; }
.account-item:hover .account-item-rename { display: block; }

.account-item-resolve { position: absolute; top: 8px; right: 56px; background: transparent; color: #999; border: none; cursor: pointer; font-size: 14px; display: none; padding: 2px 4px; border-radius: 3px; }
.account-item-resolve:hover { color: #722ed1; background: #f9f0ff; }
.account-item:hover .account-item-resolve { display: block; }

/* Rename modal input */
#rename-input { width: 100%; padding: 10px 12px; font-size: 16px; border: 1px solid #d9d9d9; border-radius: 6px; outline: none; }
#rename-input:focus { border-color: #667eea; box-shadow: 0 0 0 2px rgba(102,126,234,0.2); }

/* Resolve all button */
#resolve-all-btn { font-size: 12px; width: 100%; }

/* Status tag improvements */
.status-on { background: #f6ffed; color: #52c41a; border: 1px solid #b7eb8f; }
.status-off { background: #fff1f0; color: #ff4d4f; border: 1px solid #ffa39e; }
.status-other { background: #f5f5f5; color: #999; border: 1px solid #d9d9d9; }

/* Stats bar improvements */
.stat-item { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.stat-label { font-size: 12px; color: #999; }
.stat-value { font-size: 18px; font-weight: 700; color: #333; }

/* Account name with badge */
.account-item-name { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }

/* Button extra small */
.btn-xs { padding: 2px 8px; font-size: 12px; border-radius: 4px; }

/* Promo name truncation */
.promo-name { max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* OAuth Steps */
.oauth-step { display:flex; align-items:center; gap:10px; padding:8px 12px; margin-bottom:6px; border-radius:6px; background:#f5f5f5; transition:all 0.3s; }
.oauth-step.active { background:#e6f7ff; border-left:3px solid #1890ff; }
.oauth-step.done { background:#f6ffed; border-left:3px solid #52c41a; }
.oauth-step .step-num { display:inline-flex; align-items:center; justify-content:center; width:24px; height:24px; border-radius:50%; background:#d9d9d9; color:#fff; font-size:12px; font-weight:bold; flex-shrink:0; }
.oauth-step.active .step-num { background:#1890ff; }
.oauth-step.done .step-num { background:#52c41a; }
.oauth-step.done .step-num::after { content:"✓"; }
.oauth-step.done .step-num { font-size:0; }
.oauth-step.done .step-num::after { font-size:12px; }
.oauth-step .step-text { font-size:13px; color:#666; }
.oauth-step.active .step-text { color:#1890ff; font-weight:500; }
.oauth-step.done .step-text { color:#52c41a; }


/* Date shortcut buttons */
.date-shortcuts { gap: 4px; }
.btn-shortcut { 
  padding: 5px 12px; 
  font-size: 12px; 
  border-radius: 4px;
  background: #f0f5ff;
  color: #667eea;
  border: 1px solid #adc6ff;
  font-weight: 500;
  transition: all 0.2s;
}
.btn-shortcut:hover { 
  background: #667eea; 
  color: #fff; 
  border-color: #667eea;
}
.btn-shortcut:active {
  transform: scale(0.95);
}
.btn-shortcut-active {
  background: #667eea !important; 
  color: #fff !important; 
  border-color: #667eea !important;
}

.btn-danger{background:#ff4d4f!important;color:#fff!important;border:none!important;cursor:pointer}.btn-danger:hover{background:#ff7875!important}


/* ==================== Auto ROI Page ==================== */
.nav-tabs {
  display: flex;
  gap: 0;
  margin-right: 16px;
}
.nav-tab {
  padding: 8px 20px;
  border: none;
  background: rgba(255,255,255,0.15);
  color: rgba(255,255,255,0.8);
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.2s;
  border-radius: 6px 6px 0 0;
}
.nav-tab:hover {
  background: rgba(255,255,255,0.25);
  color: white;
}
.nav-tab.active {
  background: rgba(255,255,255,0.95);
  color: #333;
}

.auto-roi-page {
  padding: 24px;
  max-width: 1200px;
  margin: 0 auto;
}
.auto-roi-container {
  background: white;
  border-radius: 12px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.08);
  padding: 24px;
}
.auto-roi-header {
  margin-bottom: 24px;
  padding-bottom: 16px;
  border-bottom: 2px solid #f0f0f0;
}
.auto-roi-header h2 {
  font-size: 24px;
  color: #333;
  margin-bottom: 4px;
}
.auto-roi-subtitle {
  color: #999;
  font-size: 14px;
}

.auto-roi-status-bar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 16px;
  background: #f9f9f9;
  border-radius: 8px;
  margin-bottom: 20px;
}
.status-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
}
.status-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
}
.status-dot.online {
  background: #52c41a;
  box-shadow: 0 0 8px rgba(82,196,26,0.5);
  animation: pulse 2s infinite;
}
.status-dot.offline {
  background: #d9d9d9;
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}
.status-text {
  font-weight: 600;
  font-size: 14px;
}
.status-info {
  color: #666;
  font-size: 13px;
}

.auto-roi-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: flex-end;
  padding: 16px;
  background: #fafafa;
  border-radius: 8px;
  margin-bottom: 20px;
}
.control-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.control-label {
  font-size: 12px;
  color: #666;
  font-weight: 500;
}
.control-buttons {
  display: flex;
  gap: 8px;
  margin-left: auto;
}
.btn-success {
  background: #52c41a;
  color: white;
}
.btn-success:hover {
  background: #389e0d;
}
.btn-success:disabled {
  background: #b7eb8f;
  cursor: not-allowed;
}

.auto-roi-rules {
  margin-bottom: 24px;
}
.auto-roi-rules h3 {
  font-size: 16px;
  margin-bottom: 12px;
  color: #333;
}
.rules-table-wrapper {
  overflow-x: auto;
}
.rules-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.rules-table th {
  background: #f5f5f5;
  padding: 10px 12px;
  text-align: left;
  font-weight: 600;
  color: #666;
  border-bottom: 2px solid #e8e8e8;
}
.rules-table td {
  padding: 10px 12px;
  border-bottom: 1px solid #f0f0f0;
}
.rules-table tr:hover {
  background: #fafafa;
}
.rule-condition {
  background: #e6f7ff;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 12px;
  color: #1890ff;
}
.rule-action {
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 500;
}
.rule-action.increase {
  background: #fff7e6;
  color: #fa8c16;
}
.rule-action.decrease {
  background: #f6ffed;
  color: #52c41a;
}
.rule-action.neutral {
  background: #f5f5f5;
  color: #999;
}

.auto-roi-logs {
  margin-top: 24px;
}
.auto-roi-logs h3 {
  font-size: 16px;
  margin-bottom: 12px;
  color: #333;
}
.log-container {
  background: #1e1e1e;
  color: #d4d4d4;
  padding: 16px;
  border-radius: 8px;
  font-family: 'Consolas', 'Monaco', monospace;
  font-size: 12px;
  max-height: 400px;
  overflow-y: auto;
  line-height: 1.6;
}
.log-line {
  white-space: pre-wrap;
  word-break: break-all;
}
.log-error {
  color: #f5222d;
}
.log-warn {
  color: #faad14;
}
.log-info {
  color: #1890ff;
}
.log-success {
  color: #52c41a;
}
.log-skip {
  color: #8c8c8c;
}
.log-placeholder {
  color: #666;
  font-style: italic;
}


/* Fetch All Plans Section */
.auto-roi-fetch {
  margin-bottom: 24px;
  padding: 16px;
  background: #fafafa;
  border-radius: 8px;
}
.fetch-summary {
  color: #666;
  font-size: 14px;
  font-weight: 500;
}
.fetch-results {
  margin-top: 12px;
  max-height: 500px;
  overflow-y: auto;
}
.fetch-results .rules-table {
  font-size: 12px;
}
.fetch-results .rules-table td {
  padding: 8px 10px;
}
.fetch-results tr.log-skip {
  opacity: 0.6;
}
.fetch-results tr.log-info {
  background: #fff7e6;
}


/* Pagination */
.pagination-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 12px 16px;
  margin-top: 12px;
  background: #fafafa;
  border-radius: 8px;
}
.pagination-info {
  color: #666;
  font-size: 14px;
  font-weight: 500;
}
.pagination-bar .btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}


/* Token Warning Banner */
.token-warning {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  background: linear-gradient(135deg, #ff4d4f 0%, #ff7a45 100%);
  color: white;
  padding: 12px 20px;
  text-align: center;
  font-size: 14px;
  font-weight: 500;
  z-index: 9999;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
  display: none;
  animation: slideDown 0.3s ease;
}
.token-warning button {
  background: rgba(255,255,255,0.2);
  color: white;
  border: 1px solid rgba(255,255,255,0.3);
  padding: 4px 12px;
  border-radius: 4px;
  cursor: pointer;
  margin-left: 12px;
  font-size: 13px;
  transition: all 0.2s;
}
.token-warning button:hover {
  background: rgba(255,255,255,0.3);
}
@keyframes slideDown {
  from { transform: translateY(-100%); }
  to { transform: translateY(0); }
}

/* Keep the creation dialog controls visible while its content scrolls. */
#create-modal { padding: 12px; }
#create-modal .modal { display:flex; flex-direction:column; width:680px; min-width:0; max-width:100%; max-height:calc(100vh - 24px); max-height:calc(100dvh - 24px); padding:0; overflow:hidden; }
#create-modal .create-modal-header { display:flex; align-items:center; justify-content:space-between; gap:12px; padding:16px 20px; border-bottom:1px solid #eee; flex-shrink:0; }
#create-modal .create-modal-header h3 { margin:0; }
#create-modal .create-modal-close { flex-shrink:0; }
#create-modal .create-modal-body { min-height:0; overflow-y:auto; overscroll-behavior:contain; padding:16px 20px; }
#create-modal #product-list-box { max-height:min(32vh,280px) !important; overscroll-behavior:contain; }
#create-modal .modal-actions { flex-shrink:0; margin:0; padding:12px 20px; border-top:1px solid #eee; background:#fff; }
@media(max-width:480px) { #create-modal .create-modal-header, #create-modal .create-modal-body, #create-modal .modal-actions { padding:12px; } #create-modal .form-row { flex-wrap:wrap; } }
