/* 数据看板 · 响应式样式 */
:root {
  --bg: #f4f6fb; --surface: #ffffff; --surface-2: #f8fafc;
  --text: #1e293b; --muted: #64748b; --border: #e2e8f0;
  --primary: #4f46e5; --primary-soft: #eef2ff;
  --up: #16a34a; --down: #dc2626;
  --shadow: 0 1px 3px rgba(15, 23, 42, .08), 0 8px 24px rgba(15, 23, 42, .05);
  --radius: 14px; --sidebar-w: 240px;
}
[data-theme="dark"] {
  --bg: #0f172a; --surface: #1e293b; --surface-2: #172033;
  --text: #e2e8f0; --muted: #94a3b8; --border: #334155;
  --primary: #818cf8; --primary-soft: #312e81;
  --shadow: 0 1px 3px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .35);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  background: var(--bg); color: var(--text); line-height: 1.5;
  -webkit-font-smoothing: antialiased; transition: background .25s ease, color .25s ease;
}
a { color: inherit; text-decoration: none; }
.muted { color: var(--muted); font-size: .85rem; }

/* 侧边栏 */
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--sidebar-w);
  background: var(--surface); border-right: 1px solid var(--border);
  padding: 20px 16px; display: flex; flex-direction: column; gap: 8px;
  z-index: 40; transition: transform .25s ease;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.15rem; padding: 4px 8px 16px; }
.brand-logo { font-size: 1.4rem; }
.nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px;
  border-radius: 10px; color: var(--muted); font-weight: 500;
  transition: background .15s ease, color .15s ease;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--primary-soft); color: var(--primary); }
.sidebar-footer { padding: 12px 8px 0; border-top: 1px solid var(--border); }

/* 主布局 */
.layout { margin-left: var(--sidebar-w); min-height: 100dvh; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; display: flex; align-items: center; gap: 12px;
  padding: 14px 24px; background: var(--surface); border-bottom: 1px solid var(--border); z-index: 30;
}
.page-title { font-size: 1.1rem; margin: 0; flex: 1; }
.topbar-right { display: flex; align-items: center; gap: 12px; }

/* 抓取控件 */
.fetch-bar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.fetch-bar label { font-size: .82rem; color: var(--muted); white-space: nowrap; }
.date-input {
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  border-radius: 8px; padding: 7px 10px; outline: none;
}
.date-input:focus { border-color: var(--primary); }
.date-sep { color: var(--muted); font-size: .82rem; }
.quick-btns { display: flex; gap: 6px; }
.quick-btn {
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  border-radius: 8px; padding: 7px 10px; cursor: pointer; font-size: .82rem;
}
.quick-btn:hover { border-color: var(--primary); }
.fetch-btn {
  background: var(--primary); color: #fff; border: 0; border-radius: 8px;
  padding: 8px 16px; cursor: pointer; font-weight: 600;
}
.fetch-btn:hover { filter: brightness(1.05); }
.fetch-btn:disabled { opacity: .6; cursor: default; }
.fetch-status { font-size: .8rem; margin-left: 2px; max-width: 320px; }
.fetch-status.ok { color: var(--up); }
.fetch-status.error { color: var(--down); }
.fetch-status.loading { color: var(--primary); }
.fetch-status.warn { color: #b45309; }
.smartoct-datebar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin: 10px 0 4px; }
.smartoct-datebar label { font-size: .82rem; color: var(--muted); white-space: nowrap; }

.icon-btn {
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  width: 40px; height: 40px; border-radius: 10px; cursor: pointer; font-size: 1.1rem;
  display: grid; place-items: center; transition: background .15s ease;
}
.icon-btn:hover { background: var(--primary-soft); }
.avatar {
  width: 40px; height: 40px; border-radius: 50%; background: var(--primary);
  color: #fff; display: grid; place-items: center; font-weight: 700;
}

/* 内容区 */
.content { padding: 24px; display: flex; flex-direction: column; gap: 24px; flex: 1; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.card-head h2 { font-size: 1rem; margin: 0; }

.kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.kpi-label { color: var(--muted); margin: 0 0 6px; font-size: .85rem; }
.kpi-value { font-size: 1.6rem; font-weight: 700; margin: 0 0 6px; }
.kpi-trend { font-size: .8rem; margin: 0; font-weight: 600; }
.kpi-trend.up { color: var(--up); }
.kpi-trend.down { color: var(--down); }

.charts-grid {
  display: grid; grid-template-columns: 2fr 1fr;
  grid-template-areas: "wide wide" "c1 c2"; gap: 16px;
}
.chart-wide { grid-area: wide; }
.charts-grid > .chart-card:nth-of-type(2) { grid-area: c1; }
.charts-grid > .chart-card:nth-of-type(3) { grid-area: c2; }
.chart-wrap { position: relative; width: 100%; height: 320px; }
.chart-wrap canvas { width: 100% !important; height: 100% !important; }

.table-scroll { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: .9rem; min-width: 0; }
.data-table th, .data-table td { text-align: left; padding: 12px 14px; border-bottom: 1px solid var(--border); }
.data-table th { color: var(--muted); font-weight: 600; }
.data-table td.num, .data-table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.data-table tbody tr:hover { background: var(--surface-2); }
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tfoot td {
  padding: 12px 14px;
  border-top: 2px solid var(--border);
  font-weight: 700;
  background: var(--surface-2);
}
.data-table tfoot .total-label { color: var(--muted); }
.data-table tfoot .total-value { color: var(--primary); text-align: right; }
.data-table tfoot tr.total-row td { background: var(--surface-2); }

.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: .78rem; font-weight: 600; }
.badge.ok { background: #dcfce7; color: #166534; }
.badge.pending { background: #fef9c3; color: #854d0e; }
.badge.fail { background: #fee2e2; color: #991b1b; }

.page-footer { text-align: center; padding: 8px 0 4px; }

/* 数据来源徽标：真实/示例/空 一眼可辨（杜绝把假数据当真） */
.data-badge {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 14px; border-radius: 10px;
  font-size: .9rem; font-weight: 600; line-height: 1.3;
  border: 1px solid transparent;
}
.data-badge--real { background: #ecfdf5; color: #065f46; border-color: #6ee7b7; }
.data-badge--sample { background: #fff7ed; color: #9a3412; border-color: #fdba74; }
.data-badge--warn { background: #fef2f2; color: #991b1b; border-color: #fca5a5; }
.data-badge--loading { background: var(--surface-2); color: var(--muted); border-color: var(--border); }
.empty-row { text-align: center; color: var(--muted); padding: 24px 12px; font-size: .9rem; }

.overlay { position: fixed; inset: 0; background: rgba(15, 23, 42, .45); z-index: 35; }
#menuBtn { display: none; }

/* 响应式 */
@media (max-width: 1024px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .charts-grid { grid-template-columns: 1fr; grid-template-areas: "wide" "c1" "c2"; }
}
@media (max-width: 720px) {
  #menuBtn { display: grid; }
  .sidebar { transform: translateX(-100%); box-shadow: var(--shadow); }
  .sidebar.open { transform: translateX(0); }
  .layout { margin-left: 0; max-width: 100%; }
  .content { padding: 14px; gap: 14px; max-width: 100%; }

  /* 顶栏：标题一行，抓取控件整行换行，杜绝横向滑动 */
  .topbar { flex-wrap: wrap; row-gap: 10px; padding: 10px 14px; }
  .page-title { flex: 1; font-size: 1.05rem; }
  .avatar { display: none; }
  .topbar-right { flex: 1 1 100%; order: 10; flex-wrap: wrap; gap: 8px; }
  .fetch-bar { flex: 1 1 100%; flex-wrap: wrap; gap: 8px; }
  .fetch-bar label { display: none; }
  .date-input { flex: 1 1 42%; min-width: 120px; width: auto; }
  .date-sep { flex: 0 0 auto; }
  .quick-btns { flex: 1 1 100%; }
  .quick-btn { flex: 1; }
  .fetch-btn { flex: 1 1 100%; padding: 11px; }
  .fetch-status { flex: 1 1 100%; max-width: none; }

  /* KPI 两列紧凑，首屏即可看到四项核心数据 */
  .kpi-grid { grid-template-columns: repeat(2, 1fr); gap: 12px; }
  .kpi { padding: 14px; }
  .kpi-label { font-size: .8rem; }
  .kpi-value { font-size: 1.3rem; }

  .chart-wrap { height: 240px; }

  /* 移动端把「门店明细」提到图表之前，减少下滑才能看到数据 */
  .table-card { order: 1; }
  .charts-grid { order: 2; }
  .page-footer { order: 3; }
}
@media (max-width: 420px) {
  .kpi-grid { gap: 10px; }
  .kpi-value { font-size: 1.15rem; }
  .kpi-label { font-size: .75rem; }
  .content { padding: 12px; gap: 12px; }
  .date-input { min-width: 0; flex-basis: 40%; }
  .card { padding: 16px; }
}
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
