:root {
  --bg: #eef2f6;
  --panel: #ffffff;
  --panel-soft: #f8fafc;
  --ink: #17202a;
  --muted: #687385;
  --line: #d8e0e8;
  --line-dark: #c8d2dc;
  --accent: #1d4ed8;
  --accent-2: #0f766e;
  --warn: #c2410c;
  --danger: #b91c1c;
  --sidebar: #17202a;
  --sidebar-2: #202b38;
  --shadow: 0 8px 22px rgba(24, 38, 56, 0.08);
}

* { box-sizing: border-box; }
html { background: var(--bg); }
body {
  margin: 0;
  font-family: "Segoe UI", Arial, "Microsoft YaHei", sans-serif;
  color: var(--ink);
  background: var(--bg);
  font-size: 14px;
  letter-spacing: 0;
}
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }

.login-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  background: #ffffff;
}
.login-overlay.hidden { display: none; }
.login-card {
  width: min(430px, calc(100vw - 32px));
  display: grid;
  gap: 14px;
  padding: 24px;
  border: 1px solid rgba(255,255,255,.2);
  border-radius: 6px;
  background: #fff;
  box-shadow: 0 22px 70px rgba(15, 23, 42, .12);
}
.login-card h1 { margin: 0; font-size: 22px; }
.login-card p, .login-card small { margin: 0; color: var(--muted); line-height: 1.5; }
.login-card label { display: grid; gap: 6px; font-weight: 700; }
.login-card input {
  height: 40px;
  padding: 0 11px;
  border: 1px solid var(--line-dark);
  border-radius: 4px;
  background: #fbfdff;
}
.login-card button,
.primary-button {
  min-height: 38px;
  padding: 0 16px;
  border: 0;
  border-radius: 4px;
  background: var(--accent);
  color: #fff;
  font-weight: 800;
}
.compact-button {
  min-height: 32px;
  padding: 7px 12px;
  white-space: nowrap;
}
.login-error {
  min-height: 18px;
  color: var(--danger);
  font-size: 12px;
  font-weight: 800;
}

.platform-dock {
  position: fixed;
  left: 224px;
  right: 0;
  top: -46px;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 12px;
  height: 48px;
  padding: 6px 16px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, .96);
  box-shadow: var(--shadow);
  transition: top .18s ease;
}
.platform-dock::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: -12px;
  height: 12px;
}
.platform-dock:hover,
.platform-dock:focus-within,
.platform-dock.open { top: 0; }
.dock-handle {
  position: absolute;
  left: 16px;
  bottom: -26px;
  height: 24px;
  padding: 4px 12px;
  border: 1px solid var(--line);
  border-top: 0;
  border-radius: 0 0 4px 4px;
  background: #fff;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  cursor: pointer;
  user-select: none;
}
.platform-tabs {
  display: flex;
  gap: 8px;
  margin-left: 92px;
}
.platform-item {
  min-width: 112px;
  min-height: 34px;
  border: 1px solid var(--line-dark);
  border-radius: 4px;
  background: #fff;
  color: #334155;
  font-weight: 900;
}
.platform-item.active,
.platform-item:hover {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.app-shell {
  display: grid;
  grid-template-columns: 224px minmax(0, 1fr);
  min-height: 100vh;
}
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 14px 12px;
  background: var(--sidebar);
  color: #dbeafe;
  border-right: 1px solid #0f172a;
}
.brand-row { display: flex; align-items: center; gap: 10px; }
.brand-mark {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: 4px;
  background: #f59e0b;
  color: #111827;
  font-weight: 900;
  border: 1px solid rgba(255,255,255,.28);
}
.sidebar-brand {
  width: 100%;
  border: 0;
  background: transparent;
  text-align: left;
  cursor: pointer;
  padding: 8px 8px 14px;
  border-bottom: 1px solid rgba(255,255,255,.11);
}
.home-return:hover { background: rgba(255,255,255,.06); }
.sidebar-brand strong { display: block; color: #fff; font-size: 15px; }
.sidebar-brand span { display: block; color: #a8b3c4; font-size: 12px; margin-top: 3px; }
.nav-list { display: grid; gap: 4px; }
.nav-item {
  min-height: 38px;
  padding: 0 12px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: #cbd5e1;
  text-align: left;
  font-weight: 750;
}
.nav-item.active,
.nav-item:hover {
  background: var(--sidebar-2);
  color: #fff;
  box-shadow: inset 3px 0 0 #f59e0b;
}
.sync-card {
  margin-top: auto;
  display: grid;
  gap: 7px;
  padding: 12px;
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 4px;
  background: rgba(255,255,255,.06);
}
.sync-card span { color: #a8b3c4; font-size: 12px; }
.sync-card strong { color: #fff; font-size: 13px; }
.sync-card p { margin: 0; color: #cbd5e1; font-size: 12px; line-height: 1.45; }

.workspace {
  min-width: 0;
  padding: 14px 16px 28px;
}
.topbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  min-height: 72px;
  padding: 12px 14px;
  margin-bottom: 10px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #fff;
  box-shadow: var(--shadow);
}
.topbar h1 { margin: 0; font-size: 22px; line-height: 1.2; }
.topbar p { margin: 5px 0 0; color: var(--muted); line-height: 1.45; }
.toolbar { display: flex; gap: 8px; align-items: center; }
.icon-button {
  width: 38px;
  height: 38px;
  border: 1px solid var(--line-dark);
  border-radius: 4px;
  background: #fff;
  color: var(--ink);
  font-weight: 900;
}

.filters {
  display: grid;
  grid-template-columns: repeat(8, minmax(110px, 1fr));
  gap: 8px;
  padding: 10px;
  margin-bottom: 12px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #fff;
  box-shadow: var(--shadow);
}
.sticky-filters { position: sticky; top: 0; z-index: 20; }
.filters label {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}
.filters input,
.filters select {
  min-height: 32px;
  padding: 0 8px;
  border: 1px solid var(--line-dark);
  border-radius: 3px;
  background: #fbfdff;
  color: var(--ink);
}
.filters input:focus,
.filters select:focus,
textarea:focus {
  outline: 2px solid rgba(29, 78, 216, .18);
  border-color: var(--accent);
}
.wide-filter { grid-column: span 2; }

.page { display: none; }
.page.active { display: block; }
.panel {
  margin-bottom: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--panel);
  box-shadow: var(--shadow);
}
.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  min-height: 34px;
  margin-bottom: 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
}
.panel-header h2 {
  margin: 0;
  font-size: 15px;
  line-height: 1.3;
  font-weight: 850;
}
.panel-header p { margin: 4px 0 0; color: var(--muted); font-size: 12px; line-height: 1.4; }
.dashboard-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.chart-grid { display: grid; grid-template-columns: repeat(4, minmax(220px, 1fr)); gap: 12px; }
.sales-panel { grid-column: 1 / -1; }

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}
.metric-card {
  min-height: 96px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: linear-gradient(180deg, #fff, #f9fbfd);
  box-shadow: var(--shadow);
}
.metric-card span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
}
.metric-card strong {
  display: block;
  margin-top: 8px;
  font-size: 24px;
  line-height: 1.1;
}
.metric-card small {
  display: block;
  margin-top: 7px;
  color: var(--accent-2);
  font-size: 12px;
  font-weight: 800;
}

.ad-overview-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.lx-card {
  padding: 12px;
  border-color: #e2e8f0;
  box-shadow: 0 4px 14px rgba(15, 23, 42, .05);
}

.lx-card .panel-header {
  margin-bottom: 8px;
  border-bottom: 0;
}

.lx-metrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin: 2px 0 8px;
  border: 1px solid #edf1f5;
  border-radius: 3px;
  background: #f7f9fc;
  overflow: hidden;
}

.lx-metric {
  min-height: 76px;
  padding: 13px 16px;
  border-right: 1px solid #e8eef5;
}

.lx-metric:last-child { border-right: 0; }

.lx-metric span {
  display: block;
  color: #697586;
  font-size: 12px;
  font-weight: 800;
}

.lx-metric strong {
  display: block;
  margin-top: 6px;
  color: #0f172a;
  font-size: 21px;
  line-height: 1.15;
}

.lx-metric small {
  display: block;
  margin-top: 4px;
  font-size: 11px;
  font-weight: 800;
}

.good { color: #16a34a; }
.bad { color: #ef4444; }
.neutral { color: #64748b; }

.mini-tabs button {
  min-height: 26px;
  min-width: 30px;
  padding: 0 8px;
}

.lx-inline-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  color: #64748b;
  font-size: 12px;
  font-weight: 800;
}

.lx-inline-controls span {
  padding: 5px 8px;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: #f8fafc;
}

.performance-grid {
  display: grid;
  grid-template-columns: 1fr 1fr minmax(240px, .8fr);
  align-items: center;
  gap: 14px;
}

.donut-wrap {
  display: grid;
  grid-template-columns: minmax(220px, .8fr) minmax(170px, 1fr);
  align-items: center;
  gap: 8px;
}

.donut-legend {
  display: grid;
  gap: 10px;
  color: #526071;
  font-size: 12px;
}

.donut-legend div {
  display: grid;
  grid-template-columns: 10px 1fr;
  gap: 8px;
  align-items: center;
}

.donut-legend i {
  width: 9px;
  height: 9px;
  display: inline-block;
  border-radius: 50%;
}

.donut-legend b {
  grid-column: 2;
  color: #0f172a;
  font-weight: 850;
}

.analysis-box {
  display: grid;
  gap: 8px;
  padding: 18px;
  background: #f7f9fc;
  border-radius: 3px;
}

.analysis-box div,
.funnel-metrics div {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  color: #64748b;
  font-size: 12px;
}

.analysis-box strong,
.funnel-metrics strong {
  color: #0f172a;
  font-size: 14px;
}

.status-dot {
  width: 9px;
  height: 9px;
  display: inline-block;
  margin-right: 7px;
  border-radius: 50%;
  background: #22c55e;
}

.compare-bar {
  display: inline-block;
  width: 180px;
  height: 8px;
  margin-left: 10px;
  border-radius: 999px;
  background: #edf2ff;
  vertical-align: middle;
  overflow: hidden;
}

.compare-bar i {
  display: block;
  height: 100%;
  background: #8ab4ff;
}

.funnel-layout {
  display: grid;
  grid-template-columns: minmax(220px, .95fr) minmax(180px, .7fr);
  align-items: center;
  gap: 16px;
}

.funnel-metrics {
  display: grid;
  gap: 14px;
}

.table-scroll {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #fff;
}
table {
  width: 100%;
  min-width: 760px;
  border-collapse: separate;
  border-spacing: 0;
  background: #fff;
}
.wide-table { min-width: 1420px; }
th, td {
  padding: 8px 10px;
  border-right: 1px solid #edf1f5;
  border-bottom: 1px solid #e5ebf1;
  text-align: left;
  white-space: nowrap;
  vertical-align: top;
}
th:last-child,
td:last-child { border-right: 0; }
th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #f3f6f9;
  color: #334155;
  font-size: 12px;
  font-weight: 900;
  user-select: none;
}
th.sortable { cursor: pointer; }
th.sortable::after {
  content: " \21C5";
  color: #94a3b8;
  font-size: 11px;
}
th.sort-asc::after { content: " \2191"; color: var(--accent); }
th.sort-desc::after { content: " \2193"; color: var(--accent); }
tbody tr:hover td { background: #f8fbff; }
tfoot td {
  position: sticky;
  bottom: 0;
  z-index: 2;
  background: #eef4fb;
  font-weight: 900;
}
.metric-table th:nth-child(-n+4),
.metric-table td:nth-child(-n+4) {
  position: sticky;
  z-index: 3;
  background: #fff;
}
.metric-table th:nth-child(-n+4) { z-index: 5; background: #edf3f8; }
.metric-table th:nth-child(1), .metric-table td:nth-child(1) { left: 0; min-width: 150px; }
.metric-table th:nth-child(2), .metric-table td:nth-child(2) { left: 150px; min-width: 130px; }
.metric-table th:nth-child(3), .metric-table td:nth-child(3) { left: 280px; min-width: 150px; }
.metric-table th:nth-child(4), .metric-table td:nth-child(4) {
  left: 430px;
  min-width: 130px;
  box-shadow: 8px 0 12px rgba(15, 23, 42, .08);
}
textarea {
  min-width: 190px;
  min-height: 36px;
  padding: 7px;
  border: 1px solid var(--line-dark);
  border-radius: 3px;
  background: #fff;
  resize: vertical;
}

.heatmap { overflow: auto; }
.heatmap table { min-width: 1080px; }
.heatmap td,
.heatmap th {
  text-align: center;
  padding: 6px;
  min-width: 42px;
}
.heatmap td:first-child,
.heatmap th:first-child {
  position: sticky;
  left: 0;
  z-index: 4;
  background: #fff;
  text-align: left;
}
.segmented-control {
  display: inline-flex;
  gap: 0;
  border: 1px solid var(--line-dark);
  border-radius: 4px;
  overflow: hidden;
  background: #fff;
}
.segmented-control button {
  min-height: 30px;
  border: 0;
  border-right: 1px solid var(--line-dark);
  padding: 0 10px;
  background: #fff;
  font-weight: 800;
  color: var(--muted);
}
.segmented-control button:last-child { border-right: 0; }
.segmented-control button.active {
  background: var(--accent);
  color: #fff;
}
.metric-select { display: flex; flex-wrap: wrap; gap: 10px; }
.metric-select label {
  display: flex;
  gap: 6px;
  align-items: center;
  min-height: 30px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: #f8fafc;
  font-weight: 800;
}
canvas { width: 100%; max-width: 100%; display: block; }

.bulk-tool-panel {
  padding-bottom: 14px;
}

.bulk-tool-panel .panel-header {
  align-items: center;
}

.bulk-tool-panel a.primary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}

.bulk-tool-frame {
  width: 100%;
  height: 760px;
  border: 1px solid var(--line-dark);
  border-radius: 4px;
  background: #fff;
}

@media (max-width: 1180px) {
  .filters { grid-template-columns: repeat(4, minmax(120px, 1fr)); }
  .ad-overview-grid { grid-template-columns: 1fr; }
  .performance-grid { grid-template-columns: 1fr; }
  .chart-grid { grid-template-columns: repeat(2, minmax(220px, 1fr)); }
  .kpi-grid,
  .dashboard-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
}
@media (max-width: 760px) {
  .app-shell { display: block; }
  .sidebar { position: static; height: auto; }
  .workspace { padding: 10px; }
  .topbar { flex-direction: column; }
  .filters,
  .ad-overview-grid,
  .performance-grid,
  .chart-grid,
  .kpi-grid,
  .dashboard-grid { grid-template-columns: 1fr; }
  .wide-filter { grid-column: auto; }
  .platform-dock { left: 0; }
}
