/* ============================================================
   全局样式表 - 亚马逊 SP-API 中台系统
   说明：现代简洁风格的管理后台样式（浅色主题）
   ============================================================ */

/* ---------- 基础重置 ---------- */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --primary: #2d6cdf;
  --primary-dark: #1f57b8;
  --success: #22a06b;
  --danger: #d64545;
  --warning: #d97008;
  --bg: #f5f7fa;
  --card-bg: #ffffff;
  --border: #e3e8ef;
  --text: #1f2d3d;
  --text-light: #6b7a90;
  --sidebar-bg: #1d2733;
  --sidebar-text: #aab7c8;
  /* 浅灰底（统计卡/置灰行用），避免各处重复写 fallback */
  --bg-soft: #f7f8fa;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
}

a { color: var(--primary); text-decoration: none; }

/* ---------- 登录页 ---------- */
.login-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #1d2733 0%, #2d4a6b 60%, #2d6cdf 100%);
}

.login-container {
  display: flex;
  background: #fff;
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  width: 780px;
  max-width: 94vw;
  min-height: 420px;
}

.login-brand {
  flex: 1;
  background: linear-gradient(160deg, #1d2733, #2d4a6b);
  color: #fff;
  padding: 48px 36px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;          /* 去掉文案后只剩图标，水平居中 */
}

.login-brand .brand-logo {
  font-size: 52px;
  margin-bottom: 0;
}

.login-brand h1 {
  font-size: 22px;
  margin-bottom: 12px;
  font-weight: 600;
}

.login-brand p {
  color: #8fa3ba;
  font-size: 13px;
  line-height: 1.9;
}

.login-form {
  flex: 1;
  padding: 48px 40px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.login-form h2 { font-size: 22px; margin-bottom: 6px; }
.login-tip { color: var(--text-light); font-size: 13px; margin-bottom: 24px; }

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 13px;
  color: var(--text);
  margin-bottom: 6px;
  font-weight: 500;
}

.form-group input,
.form-group select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  transition: border-color 0.2s;
  background: #fff;
  color: var(--text);
}

.form-group input:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(45, 108, 223, 0.12);
}

.form-error {
  background: #fdecec;
  color: var(--danger);
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 13px;
  margin-bottom: 16px;
}

/* ---------- 按钮 ---------- */
.btn {
  display: inline-block;
  padding: 9px 18px;
  border-radius: 8px;
  border: 1px solid transparent;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s;
  background: var(--primary);
  color: #fff;
}

.btn:hover { background: var(--primary-dark); }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }

.btn-outline {
  background: transparent;
  color: var(--primary);
  border-color: var(--primary);
}

.btn-outline:hover { background: rgba(45, 108, 223, 0.08); }

.btn-danger {
  background: transparent;
  color: var(--danger);
  border-color: var(--danger);
}
.btn-danger:hover { background: rgba(211, 47, 47, 0.08); }

.btn-block { width: 100%; }

.btn-sm { padding: 5px 12px; font-size: 13px; }
.btn-xs { padding: 3px 10px; font-size: 12px; }

/* ---------- 布局框架 ---------- */
.topbar {
  height: 56px;
  background: #fff;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 100;
}

.topbar .logo { font-size: 16px; font-weight: 700; color: var(--primary); }

.topbar-right { display: flex; align-items: center; gap: 12px; }
.user-name { font-size: 13px; color: var(--text-light); }

/* 站点切换器（多站点支持：美国/加拿大/全部） */
.site-switch { display: flex; align-items: center; gap: 6px; }
.site-switch-label { font-size: 12px; color: var(--text-light); }
.site-switch select {
  height: 30px;
  padding: 0 8px;
  font-size: 13px;
  color: var(--text);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  outline: none;
}
.site-switch select:focus { border-color: var(--primary); }

/* 出网状态卡片（防 VPN 改道） */
.egress-status {
  padding: 12px 14px;
  border-radius: 8px;
  border: 1px dashed var(--border);
  background: var(--bg-soft, rgba(0, 0, 0, 0.02));
  font-size: 13px;
  line-height: 1.8;
  color: var(--text);
}
.egress-status.egress-ok {
  border: 1px solid #22a06b;
  background: rgba(34, 160, 107, 0.08);
}
.egress-status.egress-bad {
  border: 1px solid #d93025;
  background: rgba(217, 48, 37, 0.08);
}
.egress-history { margin-top: 12px; }
.egress-history-title { font-size: 12px; color: var(--text-light); margin-bottom: 6px; }

.layout {
  display: flex;
  min-height: calc(100vh - 56px);
}

.sidebar {
  width: 200px;
  background: var(--sidebar-bg);
  padding: 16px 0;
  flex-shrink: 0;
}

.menu-item {
  display: block;
  padding: 12px 24px;
  color: var(--sidebar-text);
  font-size: 14px;
  transition: all 0.2s;
  border-left: 3px solid transparent;
}

.menu-item:hover { color: #fff; background: rgba(255, 255, 255, 0.06); }

.menu-item.active {
  color: #fff;
  background: rgba(45, 108, 223, 0.25);
  border-left-color: var(--primary);
}

/* ---------- 分组子菜单（如 FBA货件 → 货件列表/发货管理） ---------- */
.menu-parent {
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
}

.menu-parent .menu-arrow {
  float: right;
  font-size: 12px;
  line-height: 18px;
  transition: transform 0.2s;
}

.menu-group.open .menu-parent .menu-arrow {
  transform: rotate(180deg);
}

.menu-sub {
  display: none;
}

.menu-group.open .menu-sub {
  display: block;
}

.menu-group.open .menu-parent {
  color: #fff;
  background: rgba(255, 255, 255, 0.04);
}

.menu-sub .menu-item {
  padding: 9px 24px 9px 44px;
  font-size: 13px;
  color: rgba(255, 255, 255, 0.75);
}

.menu-sub .menu-item:hover { color: #fff; background: rgba(255, 255, 255, 0.06); }

.menu-sub .menu-item.active {
  color: #fff;
  background: rgba(45, 108, 223, 0.3);
  border-left-color: var(--primary);
}

.content {
  flex: 1;
  /* min-width: 0 必需：flex 项默认 min-width:auto 会被宽表格撑开，
     导致横向滚动出现在页面级、表格自身容器不滚动，
     使容器内的 position:sticky 固定列失效（利润分析首列固定依赖此项） */
  min-width: 0;
  padding: 24px;
  overflow-x: auto;
}

.page-title {
  font-size: 20px;
  margin-bottom: 20px;
  font-weight: 600;
}

/* ---------- 卡片 ---------- */
.card {
  background: var(--card-bg);
  border-radius: 12px;
  border: 1px solid var(--border);
  margin-bottom: 20px;
  overflow: hidden;
}

.card-header {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.card-header h3 { font-size: 15px; font-weight: 600; }

.card-body { padding: 20px; }

/* ---------- 表单行 ---------- */
.form-row {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  align-items: flex-end;
}

.form-row .form-group { flex: 1; min-width: 160px; }

.form-action { display: flex; align-items: flex-end; }

.form-help {
  font-size: 12px;
  color: var(--text-light);
  margin-top: 8px;
}

.filter-row { display: flex; gap: 8px; align-items: center; }

.input-sm {
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  width: 200px;
}

/* ---------- 统计卡片 ---------- */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}

.stat-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  text-align: center;
}

.stat-value {
  font-size: 30px;
  font-weight: 700;
  color: var(--primary);
}

.stat-label {
  font-size: 13px;
  color: var(--text-light);
  margin-top: 4px;
}

/* ---------- 表格 ---------- */
.table-wrap { overflow-x: auto; }

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.table th {
  text-align: left;
  padding: 10px 14px;
  background: #f8fafc;
  border-bottom: 1px solid var(--border);
  color: var(--text-light);
  font-weight: 600;
  white-space: nowrap;
}

.table td {
  padding: 10px 14px;
  border-bottom: 1px solid #f0f3f7;
}

.table tr:hover td { background: #f8fafc; }

.table-compact th, .table-compact td { padding: 6px 10px; }

/* ---------- 关键词下钻（行内展开该词在各广告组的表现） ---------- */
.kw-drill-row > td {
  padding: 0 !important;
  background: #f7f9fc;
  border-bottom: 1px solid #e6ecf4;
}
.kw-drill-row:hover > td { background: #f7f9fc; }   /* 展开区不跟随行 hover 变色 */
.kw-drill-box { padding: 14px 16px; font-size: 13px; color: var(--text-light); }
.kw-drill-head {
  padding: 2px 2px 8px;
  font-size: 13px;
  color: var(--text);
  font-weight: 600;
}
.kw-drill-table { background: #fff; border: 1px solid #e6ecf4; border-radius: 6px; }
.kw-drill-table thead th {
  background: #f1f5fa;
  font-size: 12px;
  color: var(--text-light);
  font-weight: 600;
  white-space: nowrap;
}
.kw-drill-table td { font-size: 12.5px; }
.kw-drill-table tbody tr:last-child td { border-bottom: none; }

.empty-tip {
  text-align: center;
  color: var(--text-light);
  padding: 28px !important;
}

.mono { font-family: "SF Mono", Consolas, monospace; font-size: 12px; }

/* ---------- 状态徽章 ---------- */
.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
}

.badge-success { background: #e4f5ec; color: var(--success); }
.badge-danger { background: #fdecec; color: var(--danger); }
.badge-warning { background: #fdf3e4; color: var(--warning); }
.badge-default { background: #eef1f5; color: var(--text-light); }
.badge-info { background: #e6f1fb; color: var(--primary); }

/* ---------- 提示条 ---------- */
.alert {
  padding: 12px 16px;
  border-radius: 8px;
  margin-bottom: 16px;
  font-size: 13px;
}

.alert-warning {
  background: #fdf3e4;
  border: 1px solid #f5d9b0;
  color: var(--warning);
}

.alert-danger {
  background: #fdecec;
  border: 1px solid #f5b8b8;
  color: var(--danger);
}

.text-danger {
  color: var(--danger);
  font-weight: 600;
}

.text-warn {
  color: var(--warning);
  font-weight: 600;
}

.text-success {
  color: var(--success);
  font-weight: 600;
}

.alert a { color: var(--warning); font-weight: 600; text-decoration: underline; }

/* ---------- 分页 ---------- */
.pagination {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  justify-content: flex-end;
}

.page-info { font-size: 12px; color: var(--text-light); }

/* ---------- 弹窗 ---------- */
.modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}

.modal {
  background: #fff;
  border-radius: 12px;
  width: 620px;
  max-width: 96vw;
  max-height: 86vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
}

.modal-lg { width: 900px; }

.modal-header {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-header h3 { font-size: 15px; }

.modal-close {
  border: none;
  background: none;
  font-size: 22px;
  cursor: pointer;
  color: var(--text-light);
  line-height: 1;
}

.modal-body {
  padding: 20px;
  overflow-y: auto;
}

/* 详情网格 */
.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px 20px;
}

.detail-grid label {
  display: block;
  font-size: 12px;
  color: var(--text-light);
}

.detail-grid span { font-size: 13px; }

.addr-text { font-size: 13px; color: var(--text); }

/* ---------- 产品缩略图 ---------- */
.product-thumb {
  width: 44px;
  height: 44px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: #f8fafc;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  vertical-align: middle;
}

.product-thumb-empty {
  color: #c0c8d4;
  background: #f1f3f7;
}

/* ---------- 库存数量颜色（中国习惯：红涨/库存用色区分） ---------- */
.qty-available { color: var(--success); font-weight: 500; }
.qty-inbound { color: var(--primary); }
.qty-unfulfillable { color: var(--danger); }
.qty-reserved { color: var(--warning); }

/* ---------- 子菜单（页内 Tab） ---------- */
.submenu {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  border-bottom: 2px solid var(--border);
  padding-bottom: 8px;
}

.submenu-item {
  padding: 8px 18px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-secondary);
  color: var(--text-light);
  font-size: 14px;
  cursor: pointer;
  transition: all .2s;
}

.submenu-item:hover { border-color: var(--primary); color: var(--primary); }

.submenu-item.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  font-weight: 500;
}

/* ---------- 弹窗底部操作按钮 ---------- */
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 16px;
}

/* ---------- 日志查看 ---------- */
.log-viewer {
  background: #1e2a38;
  border-radius: 8px;
  padding: 14px;
  max-height: 560px;
  overflow-y: auto;
  font-family: Consolas, Menlo, monospace;
  font-size: 12px;
  line-height: 1.7;
}

.log-line {
  color: #c8d2dc;
  white-space: pre-wrap;
  word-break: break-all;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  padding: 2px 0;
}

.log-info { color: #9fd0ff; }
.log-warning { color: #f5c77a; }
.log-error { color: #ff8f8f; font-weight: 500; }

/* ---------- Toast 提示 ---------- */
.toast {
  position: fixed;
  bottom: 32px;
  left: 50%;
  transform: translateX(-50%);
  background: #1f2d3d;
  color: #fff;
  padding: 12px 24px;
  border-radius: 8px;
  font-size: 14px;
  z-index: 2000;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
  max-width: 80vw;
}

.toast.error { background: var(--danger); }
.toast.success { background: var(--success); }

/* ---------- 响应式 ---------- */
@media (max-width: 768px) {
  .sidebar { display: none; }
  .login-container { flex-direction: column; }
  .login-brand { padding: 24px; }
  .detail-grid { grid-template-columns: 1fr; }
}

/* 链接样式（利润报表产品成本链接） */
a.link {
  color: #2f6fed;
  text-decoration: none;
  cursor: pointer;
  font-weight: bold;
}
a.link:hover {
  text-decoration: underline;
  color: #1a4fc0;
}

/* 合计行 */
tr.total-row td {
  background: #f2f6ff;
  border-top: 2px solid #d0d8e8;
  font-weight: bold;
}

/* 宽表格横向滚动容器（利润分析） */
.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.table-scroll .table {
  min-width: 1600px;
}

/* 利润分析表：横向滚动时固定首列（SKU 列不随横向滚动移动） */
/* 1) 改用 separate 边框模式：collapse 模式会让部分浏览器（含 Chromium 内核）
      的 sticky 表格单元格出现定位/渲染异常，导致固定列看起来"没生效"。
      本表只有横向分隔线、无竖直边框，两种模式视觉一致 */
#page-profit-analysis .table-scroll .table {
  border-collapse: separate;
  border-spacing: 0;
}
/* 2) 滚动容器左内边距归零：让固定列紧贴卡片左边缘，避免其左侧露出滑动内容 */
#page-profit-analysis .table-scroll {
  padding-left: 0;
}
/* 3) 固定列本体：sticky + 不透明背景（否则会透出下方滑动内容）
      注意 -webkit- 前缀：兼容老内核浏览器（360/QQ 等基于旧 Chromium 的浏览器） */
#page-profit-analysis .table-scroll .table th:first-child,
#page-profit-analysis .table-scroll .table td:first-child {
  position: -webkit-sticky;
  position: sticky;
  left: 0;
  z-index: 2;
  background: var(--card-bg);
  padding-left: 20px;                      /* 补回卡片左侧留白 */
  border-right: 1px solid var(--border);   /* 固定列右分界 */
  box-shadow: 6px 0 8px -8px rgba(15, 23, 42, 0.28);  /* 右侧阴影，突出层次 */
}
/* 4) 表头首列层级更高，盖住同排其它表头单元格 */
#page-profit-analysis .table-scroll .table thead th:first-child {
  z-index: 3;
  background: #f8fafc;
}
/* 5) 行 hover 时固定列背景同步（保持整行变色一致） */
#page-profit-analysis .table-scroll .table tbody tr:hover td:first-child {
  background: #f8fafc;
}
/* 6) 合计行（若有）固定列背景同步 */
#page-profit-analysis .table-scroll .table tr.total-row td:first-child {
  background: #f2f6ff;
}
/* 7) 首列（SKU）限宽约 20 个字符：超出部分截断显示省略号，完整值由 title 悬浮提示 */
/*    宽度 = 20ch + 左右内边距（20px + 14px，border-box 下需计入） */
#page-profit-analysis .table-scroll .table th:first-child {
  width: calc(20ch + 34px);
  min-width: calc(20ch + 34px);
  max-width: calc(20ch + 34px);
  /* 与 .mono 保持同一等宽字体，保证 ch 单位计算与正文列一致 */
  font-family: "SF Mono", Consolas, monospace;
  font-size: 12px;
}
#page-profit-analysis .table-scroll .table td:first-child {
  max-width: calc(20ch + 34px);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- 经营总览（P5） ---------- */
/* 店铺经营 / 广告投放 两栏并列；窄屏自动堆叠 */
.ov-panels {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}
.ov-panels > .card { margin-bottom: 0; }

/* 面板内的统计卡固定 2 列，避免 4 张卡被拉得太宽 */
.stat-grid.stat-grid-2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 0;
  padding: 16px;
}
.stat-grid.stat-grid-2 .stat-card { padding: 14px 10px; }
.stat-grid.stat-grid-2 .stat-value { font-size: 20px; }

/* 广告效率指标条（横向小卡片） */
.metric-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}
.metric-item {
  flex: 1 1 110px;
  min-width: 100px;
  background: var(--bg-soft, #f7f8fa);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 10px;
  text-align: center;
}
.metric-item .m-label {
  font-size: 12px;
  color: var(--text-light);
  margin-bottom: 6px;
}
.metric-item .m-value {
  font-size: 17px;
  font-weight: 600;
}

/* 每日对照表：无广告数据的日期置灰，避免误读为「当天没投放」 */
.table tbody tr.row-no-data td { color: var(--text-light); background: var(--bg-soft, #f7f8fa); }

/* ---------- 时间快捷选择（广告活动页） ---------- */
.form-group.form-group-wide { flex: 0 0 100%; }
.date-quick {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.date-quick-btn {
  padding: 6px 14px;
  font-size: 13px;
  line-height: 1.4;
  color: var(--text);
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 16px;
  cursor: pointer;
  transition: all 0.15s ease;
}
.date-quick-btn:hover { border-color: var(--primary); color: var(--primary); }
.date-quick-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  font-weight: 600;
}

/* ---------- AI 运营分析 ---------- */
.ai-summary {
  font-size: 15px;
  line-height: 1.8;
  color: var(--text);
  white-space: pre-wrap;
}
.ai-notice.warn { border-left: 4px solid #f0a020; background: #fffaf0; }
.ai-notice.error { border-left: 4px solid #e04b4b; background: #fff5f5; }
.ai-gap { margin: 8px 0 0; padding-left: 18px; font-size: 13px; color: var(--text-light); line-height: 1.8; }
.ai-gap li { margin-bottom: 2px; }
.ai-evidence { font-size: 12.5px; color: var(--text-light); line-height: 1.6; }
.ai-target { font-weight: 600; }
.ai-sev, .ai-prio {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 10px;
  font-size: 11.5px;
  font-weight: 600;
  white-space: nowrap;
}
.ai-sev.high { background: #fde8e8; color: #c0392b; }
.ai-sev.medium { background: #fff3e0; color: #b26a00; }
.ai-sev.low { background: #e8f5e9; color: #2e7d32; }
.ai-prio.p0 { background: #fde8e8; color: #c0392b; }
.ai-prio.p1 { background: #fff3e0; color: #b26a00; }
.ai-prio.p2 { background: #eef2f7; color: #5a6b80; }
.ai-history-row { cursor: pointer; }
.ai-history-row:hover td { background: #f4f8ff; }
