:root {
  --bg: #f6f8fb;
  --panel: #ffffff;
  --panel-soft: #f9fbff;
  --line: #e6ebf2;
  --text: #172033;
  --muted: #667085;
  --soft-text: #8a94a6;
  --blue: #2d7ff9;
  --blue-soft: #eef5ff;
  --green: #168a58;
  --green-soft: #eafaf2;
  --amber: #b7791f;
  --amber-soft: #fff7e8;
  --red: #c2413a;
  --red-soft: #fff0ef;
  --violet: #6d5bd0;
  --violet-soft: #f2f0ff;
  --shadow: 0 18px 46px rgba(24, 39, 75, 0.08);
  --radius: 18px;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  min-height: 100%;
  color: var(--text);
  background: var(--bg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
  font-size: 14px;
  letter-spacing: 0;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 252px minmax(0, 1fr);
}

.auth-gate {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: linear-gradient(180deg, #f9fbff, #eef5ff);
}

.auth-card {
  width: min(460px, 100%);
  border: 1px solid var(--line);
  border-radius: 24px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
  padding: 26px;
}

.auth-brand {
  padding: 0 0 18px;
}

.auth-card h1 {
  margin-bottom: 10px;
}

.auth-form {
  grid-template-columns: 1fr;
  margin-top: 18px;
}

.setup-hint {
  margin-top: 18px;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: auto;
  background: rgba(255, 255, 255, 0.92);
  border-right: 1px solid var(--line);
  backdrop-filter: blur(20px);
  padding: 18px 14px 24px;
  z-index: 30;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 8px 18px;
}

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 15px;
  display: grid;
  place-items: center;
  color: #ffffff;
  font-weight: 800;
  background: linear-gradient(135deg, #2d7ff9, #18a673);
  box-shadow: 0 10px 26px rgba(45, 127, 249, 0.25);
}

.brand strong,
.brand span {
  display: block;
}

.brand strong {
  font-size: 16px;
}

.brand span {
  color: var(--muted);
  font-size: 12px;
  margin-top: 3px;
}

.nav-group {
  margin: 8px 0;
}

.nav-heading {
  color: var(--soft-text);
  padding: 10px 12px 7px;
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.nav-icon {
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: var(--panel-soft);
  color: var(--blue);
  flex: 0 0 auto;
}

.nav-button {
  width: 100%;
  border: 0;
  background: transparent;
  color: #344054;
  border-radius: 999px;
  min-height: 34px;
  text-align: left;
  padding: 7px 13px 7px 38px;
  margin: 2px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.nav-button:hover {
  background: #f0f5ff;
}

.nav-button.active {
  background: var(--blue-soft);
  color: #165dcc;
  font-weight: 700;
}

.main {
  min-width: 0;
  padding: 18px 22px 36px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 68px;
}

.crumb {
  color: var(--soft-text);
  font-size: 12px;
  margin-bottom: 5px;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 24px;
  font-weight: 760;
}

h2 {
  font-size: 18px;
  margin-bottom: 14px;
}

h3 {
  font-size: 15px;
  margin-bottom: 10px;
}

.top-actions,
.toolbar,
.inline-actions,
.filter-grid,
.tabs {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.pill,
.chip,
.tab,
.table-action,
.small-pill {
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #ffffff;
  color: #344054;
  min-height: 34px;
  padding: 0 15px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  box-shadow: 0 1px 0 rgba(15, 23, 42, 0.02);
}

.pill:hover,
.tab:hover,
.table-action:hover,
.small-pill:hover {
  border-color: #c8d8ef;
  background: #f8fbff;
}

.pill.accent,
.tab.active {
  color: #165dcc;
  background: var(--blue-soft);
  border-color: #c8dcff;
}

.pill.success {
  color: var(--green);
  background: var(--green-soft);
  border-color: #c8ead9;
}

.pill.warn {
  color: var(--amber);
  background: var(--amber-soft);
  border-color: #f1d49b;
}

.pill.danger {
  color: var(--red);
  background: var(--red-soft);
  border-color: #ffc9c4;
}

.pill[disabled],
.table-action[disabled] {
  opacity: 0.55;
  cursor: not-allowed;
}

.icon-button {
  width: 38px;
  height: 38px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #ffffff;
  display: inline-grid;
  place-items: center;
}

.icon-button span {
  width: 16px;
  height: 2px;
  background: #344054;
  border-radius: 999px;
  display: block;
}

.mobile-only {
  display: none;
}

.notice-strip {
  margin: 10px 0 18px;
  padding: 12px 16px;
  border: 1px solid #d6e4ff;
  border-radius: var(--radius);
  background: #f4f8ff;
  color: #31517e;
  display: flex;
  align-items: center;
  gap: 10px;
  line-height: 1.6;
}

.modal-notice {
  margin: 0 0 14px;
  border-radius: 16px;
}

.view {
  display: grid;
  gap: 16px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}

.panel.tight {
  padding: 14px;
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 14px;
  margin-bottom: 14px;
}

.section-header p {
  color: var(--muted);
  margin: 4px 0 0;
  line-height: 1.6;
}

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

.metric {
  min-height: 106px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(180deg, #ffffff, #fbfdff);
  padding: 15px;
  display: grid;
  align-content: space-between;
}

.metric span {
  color: var(--muted);
  font-size: 12px;
}

.metric strong {
  font-size: 24px;
  margin-top: 10px;
  display: block;
}

.metric small {
  color: var(--soft-text);
}

.filter-panel {
  display: grid;
  gap: 12px;
}

.filter-grid {
  align-items: end;
}

.field {
  display: grid;
  gap: 6px;
  min-width: 160px;
}

.field.wide {
  min-width: 280px;
  flex: 1;
}

.field label {
  color: var(--muted);
  font-size: 12px;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  min-height: 38px;
  padding: 8px 12px;
  outline: none;
  background: #ffffff;
  color: var(--text);
}

.field textarea {
  min-height: 84px;
  resize: vertical;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: #9fc5ff;
  box-shadow: 0 0 0 4px rgba(45, 127, 249, 0.12);
}

.field-error {
  color: var(--red);
  font-size: 12px;
  min-height: 18px;
}

.table-wrap {
  width: 100%;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #ffffff;
}

table {
  width: 100%;
  min-width: 980px;
  border-collapse: separate;
  border-spacing: 0;
}

th,
td {
  padding: 12px 12px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
  text-align: left;
  white-space: nowrap;
}

th {
  position: sticky;
  top: 0;
  z-index: 4;
  color: #667085;
  background: #f9fbff;
  font-size: 12px;
  font-weight: 700;
}

tr:last-child td {
  border-bottom: 0;
}

tbody tr.data-row:hover td {
  background: #fbfdff;
}

.sortable {
  cursor: pointer;
  user-select: none;
}

.sticky-col {
  position: sticky;
  left: 0;
  z-index: 3;
  background: #ffffff;
}

th.sticky-col {
  z-index: 5;
  background: #f9fbff;
}

.compact-id {
  max-width: 118px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.product-cell {
  max-width: 320px;
  white-space: normal;
  line-height: 1.45;
}

.product-cell strong {
  display: block;
  margin-bottom: 4px;
}

.muted {
  color: var(--muted);
}

.money {
  font-variant-numeric: tabular-nums;
}

.roi-good {
  color: var(--green);
  font-weight: 700;
}

.roi-low {
  color: var(--red);
  font-weight: 700;
}

.badge {
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 12px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid transparent;
  white-space: nowrap;
}

.badge.soft {
  color: #37517a;
  background: #eef5ff;
  border-color: #d9e8ff;
}

.badge.green {
  color: var(--green);
  background: var(--green-soft);
}

.badge.amber {
  color: var(--amber);
  background: var(--amber-soft);
}

.badge.red {
  color: var(--red);
  background: var(--red-soft);
}

.badge.violet {
  color: var(--violet);
  background: var(--violet-soft);
}

.expand-row td {
  background: #fbfdff;
  padding: 0;
}

.expand-panel {
  padding: 16px;
  display: grid;
  grid-template-columns: minmax(300px, 1.1fr) minmax(260px, 0.9fr);
  gap: 14px;
}

.mini-table {
  width: 100%;
  min-width: 0;
}

.mini-table th,
.mini-table td {
  padding: 9px 8px;
}

.chart-bars {
  display: grid;
  gap: 8px;
}

.bar-row {
  display: grid;
  grid-template-columns: 74px minmax(120px, 1fr) 72px;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 12px;
}

.bar-track {
  height: 9px;
  border-radius: 999px;
  background: #eef2f7;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #2d7ff9, #19a974);
}

.cards-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.rank-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
  padding: 16px;
  display: grid;
  gap: 12px;
}

.rank-card.active {
  border-color: #bfd6ff;
  box-shadow: 0 14px 34px rgba(45, 127, 249, 0.12);
}

.rank-card h3 {
  line-height: 1.5;
  margin-bottom: 0;
}

.rank-metrics {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.rank-metrics div {
  background: #f8fafc;
  border-radius: 12px;
  padding: 10px;
}

.rank-metrics span {
  color: var(--muted);
  font-size: 12px;
  display: block;
}

.rank-metrics strong {
  display: block;
  margin-top: 5px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.form-grid .field.full {
  grid-column: 1 / -1;
}

.target-picker {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  max-height: 210px;
  overflow: auto;
  padding: 2px;
}

.target-card {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #ffffff;
  padding: 11px;
  display: grid;
  gap: 6px;
}

.target-card input {
  width: 16px;
  height: 16px;
}

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}

.switch-row:last-child {
  border-bottom: 0;
}

.switch {
  position: relative;
  width: 48px;
  height: 28px;
  border-radius: 999px;
  border: 0;
  background: #d9e1ec;
  flex: 0 0 auto;
}

.switch::after {
  content: "";
  position: absolute;
  top: 4px;
  left: 4px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 3px 8px rgba(15, 23, 42, 0.15);
  transition: transform 0.2s ease;
}

.switch.on {
  background: #84d7ae;
}

.switch.on::after {
  transform: translateX(20px);
}

.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.list-stack {
  display: grid;
  gap: 10px;
}

.simple-row {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: #ffffff;
}

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  max-width: 360px;
  padding: 12px 16px;
  color: #263244;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 80;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.toast.error {
  border-color: #ffc9c4;
  background: #fff7f6;
  color: var(--red);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(16, 24, 40, 0.28);
  display: grid;
  place-items: center;
  padding: 18px;
  z-index: 90;
}

.modal {
  width: min(620px, 100%);
  max-height: min(720px, 92vh);
  overflow: auto;
  background: #ffffff;
  border-radius: 22px;
  border: 1px solid var(--line);
  box-shadow: 0 26px 80px rgba(15, 23, 42, 0.24);
  padding: 24px;
  position: relative;
}

.modal-close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 34px;
  height: 34px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #ffffff;
  color: var(--muted);
}

.empty {
  text-align: center;
  color: var(--muted);
  padding: 30px 16px;
}

.loading {
  min-height: 160px;
  display: grid;
  place-items: center;
  color: var(--muted);
}

.skeleton {
  width: min(420px, 80%);
  height: 12px;
  border-radius: 999px;
  background: linear-gradient(90deg, #eef2f7, #f9fbff, #eef2f7);
  background-size: 200% 100%;
  animation: shimmer 1.2s infinite linear;
}

@keyframes shimmer {
  from {
    background-position: 200% 0;
  }
  to {
    background-position: -200% 0;
  }
}

@media (max-width: 1180px) {
  .metric-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .cards-grid,
  .form-grid,
  .target-picker {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 820px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(86vw, 300px);
    transform: translateX(-105%);
    transition: transform 0.22s ease;
    box-shadow: var(--shadow);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .main {
    padding: 14px;
  }

  .mobile-only {
    display: inline-grid;
  }

  .topbar {
    align-items: flex-start;
  }

  .top-actions {
    justify-content: flex-end;
  }

  h1 {
    font-size: 20px;
  }

  .notice-strip,
  .section-header,
  .simple-row {
    align-items: flex-start;
    flex-direction: column;
  }

  .metric-grid,
  .cards-grid,
  .form-grid,
  .two-col,
  .expand-panel,
  .target-picker {
    grid-template-columns: 1fr;
  }

  .panel {
    padding: 14px;
  }

  .field,
  .field.wide {
    min-width: 100%;
  }

  table {
    min-width: 900px;
  }

  .product-cell {
    max-width: 250px;
  }
}
