:root {
  color-scheme: light;
  --bg: #160019;
  --surface: #21062a;
  --surface-soft: #2e0c3b;
  --text: #ffffff;
  --muted: #cbb9d4;
  --line: #4b2164;
  --brand: #8e5cff;
  --brand-dark: #c8a7ff;
  --accent: #ff8a86;
  --accent-soft: #35101f;
  --shadow: 0 20px 42px rgba(0, 0, 0, 0.34);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background:
    radial-gradient(circle at 85% 8%, rgba(118, 59, 255, 0.24), transparent 28rem),
    radial-gradient(circle at 22% 0%, rgba(255, 138, 134, 0.1), transparent 22rem),
    var(--bg);
  color: var(--text);
  font-family:
    Inter, Segoe UI, Roboto, Arial, sans-serif;
}

button,
input,
select {
  font: inherit;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 28px clamp(18px, 4vw, 48px);
  border-bottom: 1px solid rgba(142, 92, 255, 0.25);
  background:
    linear-gradient(90deg, rgba(24, 0, 28, 0.96), rgba(46, 6, 61, 0.92)),
    #160019;
  color: #ffffff;
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 18px;
  min-width: 0;
}

.brand-lockup img {
  width: 82px;
  height: 82px;
  object-fit: cover;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  box-shadow: 0 16px 32px rgba(0, 0, 0, 0.35);
}

.topbar h1 {
  margin: 2px 0 0;
  font-size: clamp(1.55rem, 2vw, 2.15rem);
  line-height: 1.1;
  letter-spacing: 0;
}

.eyebrow {
  margin: 0;
  color: var(--accent);
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.update-box {
  min-width: 210px;
  padding: 12px 14px;
  border: 1px solid rgba(142, 92, 255, 0.45);
  border-radius: 8px;
  background: rgba(31, 4, 42, 0.78);
}

.update-box span,
.update-box strong,
.update-box small {
  display: block;
}

.update-box span {
  color: var(--muted);
  font-size: 0.78rem;
}

.update-box strong {
  margin-top: 3px;
  font-size: 0.92rem;
}

.update-box small {
  margin-top: 5px;
  color: var(--muted);
  font-size: 0.72rem;
}

.update-box .app-version {
  margin-top: 9px;
  color: var(--brand-dark);
  font-weight: 900;
}

.page-shell {
  width: min(1920px, calc(100% - 36px));
  margin: 24px auto 42px;
}

.controls-section {
  display: grid;
  grid-template-columns: minmax(240px, 0.95fr) minmax(280px, 1.25fr) minmax(160px, 0.55fr) minmax(220px, 1fr) auto;
  gap: 14px;
  align-items: end;
  margin-bottom: 18px;
}

.field {
  display: grid;
  gap: 7px;
}

.field span {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

select,
input {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #120017;
  color: var(--text);
  padding: 0 12px;
  outline: none;
  font-size: 1rem;
}

select option {
  background: #ffffff;
  color: #1a1220;
}

select option:checked {
  background: #7d3cff;
  color: #ffffff;
}

select:focus,
input:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(142, 92, 255, 0.22);
}

button {
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), #b56aff);
  color: #ffffff;
  padding: 0 18px;
  font-weight: 800;
  cursor: pointer;
}

button:hover {
  background: linear-gradient(135deg, #ff7672, #9c58ff);
}

button:disabled {
  background: #5e4d68;
  cursor: not-allowed;
}

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.metric {
  min-height: 124px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.metric span,
.metric small {
  display: block;
}

.metric span {
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 800;
}

.metric strong {
  display: block;
  margin: 10px 0 7px;
  color: var(--brand-dark);
  font-size: clamp(2rem, 4vw, 3.4rem);
  line-height: 0.95;
}

.metric small {
  color: var(--muted);
  font-size: 0.86rem;
}

.metric-accent {
  background: var(--accent-soft);
  border-color: rgba(255, 138, 134, 0.45);
}

.metric-accent strong {
  color: var(--accent);
}

.products-section {
  width: 100%;
}

.qg-summary-section {
  margin-bottom: 18px;
}

.hidden {
  display: none !important;
}

.qg-table-wrap {
  max-height: none !important;
  overflow: visible !important;
}

.qg-summary-table th,
.qg-summary-table td {
  text-align: right;
}

.qg-summary-table th:first-child,
.qg-summary-table td:first-child {
  width: auto;
  color: var(--text);
  text-align: left;
  white-space: normal;
}

.qg-summary-table tbody tr[data-store-id] {
  cursor: pointer;
  transition:
    background 0.16s ease,
    box-shadow 0.16s ease,
    transform 0.16s ease;
}

.qg-summary-table tbody tr[data-store-id]:hover {
  background: rgba(142, 92, 255, 0.22);
  box-shadow: inset 4px 0 0 var(--accent);
  transform: translateX(2px);
}

.qg-summary-table .selected-row {
  background: rgba(255, 138, 134, 0.22);
  box-shadow: inset 4px 0 0 var(--accent);
}

.qg-summary-table .selected-row td:first-child {
  color: var(--accent);
}

.summary-total-row td {
  border-top: 2px solid rgba(255, 255, 255, 0.18);
  background: #17001d;
  font-weight: 900;
}

.percent-cell {
  min-width: 112px;
  color: #160019;
  font-weight: 900;
}

.percent-good {
  background: #75d98b;
}

.percent-warn {
  background: #fff074;
}

.percent-mid {
  background: #ffbe75;
}

.percent-bad {
  background: #ff7474;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.products-panel {
  display: block;
  width: 100% !important;
  max-width: none;
  min-width: 0;
}

.products-panel .panel-header,
.products-panel .table-wrap {
  width: 100%;
}

.products-panel table {
  width: 100%;
  min-width: 1080px;
  table-layout: fixed;
}

.products-panel th:first-child,
.products-panel td:first-child {
  width: 140px;
}

.products-panel th:nth-child(3),
.products-panel td:nth-child(3) {
  width: 280px;
}

.products-panel th:nth-child(4),
.products-panel td:nth-child(4) {
  width: 180px;
}

.products-panel th:nth-child(2),
.products-panel td:nth-child(2) {
  width: auto;
}

.status-linked,
.status-unlinked {
  font-weight: 900;
}

.status-linked {
  color: #75d98b;
}

.status-unlinked {
  color: #ff8a86;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 18px;
  border-bottom: 1px solid var(--line);
}

.panel-header h2 {
  margin: 3px 0 0;
  font-size: 1.08rem;
  line-height: 1.2;
  letter-spacing: 0;
}

.count-pill {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  white-space: nowrap;
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--brand-dark);
  padding: 0 10px;
  font-size: 0.78rem;
  font-weight: 800;
}

.ranking-list {
  display: grid;
  gap: 10px;
  max-height: 660px;
  overflow: auto;
  padding: 16px 18px 18px;
}

.ranking-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px 12px;
  align-items: center;
  width: 100%;
  min-height: 0;
  padding: 10px 0;
  border: 0;
  border-bottom: 1px solid rgba(142, 92, 255, 0.16);
  border-radius: 0;
  background: transparent;
  color: inherit;
  font-weight: inherit;
  text-align: left;
  cursor: pointer;
}

.ranking-item:last-child {
  border-bottom: 0;
}

.ranking-item:hover {
  background: rgba(142, 92, 255, 0.08);
}

.ranking-name {
  min-width: 0;
  font-size: 0.9rem;
  font-weight: 800;
}

.ranking-value {
  color: var(--brand-dark);
  font-weight: 900;
}

.bar-track {
  grid-column: 1 / -1;
  height: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: #3a174a;
}

.bar-fill {
  height: 100%;
  border-radius: inherit;
  background: var(--brand);
}

.ranking-item.active .ranking-name,
.ranking-item.active .ranking-value {
  color: var(--accent);
}

.ranking-item.active .bar-fill {
  background: var(--accent);
}

.table-wrap {
  max-height: 660px;
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  border-bottom: 1px solid rgba(142, 92, 255, 0.16);
  padding: 12px 14px;
  text-align: left;
  vertical-align: top;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #1a0322;
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
}

td:first-child {
  width: 150px;
  color: var(--brand-dark);
  font-weight: 800;
  white-space: nowrap;
}

td:last-child {
  width: 220px;
}

.empty-state {
  height: 180px;
  color: var(--muted);
  text-align: center;
  vertical-align: middle;
}

@media (max-width: 900px) {
  .topbar,
  .controls-section,
  .metrics-grid,
  .products-section {
    grid-template-columns: 1fr;
  }

  .topbar {
    display: grid;
  }

  .brand-lockup img {
    width: 68px;
    height: 68px;
  }

  .update-box {
    min-width: 0;
  }
}

@media (max-width: 560px) {
  .page-shell {
    width: min(100% - 24px, 1920px);
    margin-top: 16px;
  }

  .panel-header {
    align-items: flex-start;
    flex-direction: column;
  }

  th,
  td {
    padding: 10px;
  }

  td:first-child {
    width: 112px;
  }
}
