:root {
  color-scheme: light;
  --bg: #160f24;
  --panel: rgba(28, 22, 45, 0.94);
  --panel-soft: rgba(31, 25, 54, 0.92);
  --border: rgba(164, 139, 224, 0.26);
  --text: #f8f5ff;
  --muted: #b9afd2;
  --coral: #ff745f;
  --violet: #7b36d9;
  --blue: #18aef5;
  --green: #25dc41;
  --yellow: #ffc42d;
  --red: #f01414;
  --line: var(--border);
  --surface: var(--panel);
  --surface-soft: var(--panel-soft);
  --brand: var(--violet);
  --brand-dark: #a48be0;
  --accent: var(--coral);
  --accent-soft: rgba(28, 22, 45, 0.94);
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.34);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: linear-gradient(135deg, #241235 0%, #101323 48%, #181d2b 100%);
  color: var(--text);
  font-family:
    Inter, Segoe UI, Arial, sans-serif;
}

button,
input,
select {
  font: inherit;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: clamp(18px, 3vw, 42px);
  padding: 16px clamp(18px, 4vw, 48px) 20px;
  border-bottom: 1px solid var(--border);
  background: rgba(22, 15, 36, 0.88);
  color: var(--text);
  box-shadow: none;
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 18px;
  min-width: 0;
  flex: 1;
}

.brand-lockup img {
  flex: 0 0 auto;
  width: 86px;
  height: 86px;
  object-fit: cover;
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.topbar h1 {
  margin: 4px 0 3px;
  font-size: clamp(1.75rem, 2.65vw, 2.4rem);
  line-height: 1.05;
  letter-spacing: 0;
}

.eyebrow {
  margin: 0;
  color: var(--brand-dark);
  font-size: clamp(0.76rem, 0.82vw, 0.9rem);
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.hero-subtitle {
  max-width: 1060px;
  margin: 0;
  color: var(--text);
  font-size: clamp(0.84rem, 0.9vw, 0.96rem);
  line-height: 1.35;
}

.client-note {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  margin: 0 0 7px;
  border: 1px solid rgba(164, 139, 224, 0.2);
  border-radius: 8px;
  background: rgba(31, 25, 54, 0.58);
  color: var(--muted);
  padding: 0 10px;
  font-size: 0.78rem;
  font-weight: 700;
}

.update-box {
  min-width: 210px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel-soft);
  box-shadow: var(--shadow);
}

.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(--blue);
  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: rgba(16, 19, 35, 0.78);
  color: var(--text);
  padding: 0 12px;
  outline: none;
  font-size: 1rem;
}

select option {
  background: #1f1936;
  color: #f8f5ff;
}

select option:checked {
  background: var(--violet);
  color: var(--text);
}

select:focus,
input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(24, 174, 245, 0.2);
}

button {
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--violet), #075e85);
  color: var(--text);
  padding: 0 18px;
  font-weight: 800;
  cursor: pointer;
}

button:hover {
  background: linear-gradient(135deg, #8b48e8, #0874a4);
}

button:disabled {
  background: rgba(185, 175, 210, 0.24);
  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:first-child {
  border-left: 4px solid var(--violet);
}

.metric:nth-child(2) {
  border-left: 4px solid var(--coral);
}

.metric:nth-child(3) {
  border-left: 4px solid var(--blue);
}

.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(--text);
  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: var(--border);
}

.metric-accent strong {
  color: var(--coral);
}

.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(123, 54, 217, 0.18);
  box-shadow: inset 4px 0 0 var(--blue);
  transform: translateX(2px);
}

.qg-summary-table .selected-row {
  background: rgba(255, 116, 95, 0.18);
  box-shadow: inset 4px 0 0 var(--coral);
}

.qg-summary-table .selected-row td:first-child {
  color: var(--coral);
}

.summary-total-row td {
  border-top: 2px solid rgba(255, 255, 255, 0.18);
  background: rgba(22, 15, 36, 0.96);
  font-weight: 900;
}

.percent-cell {
  min-width: 112px;
  color: var(--text);
  font-weight: 900;
}

.percent-good {
  background: rgba(37, 220, 65, 0.56);
}

.percent-warn {
  background: rgba(255, 196, 45, 0.58);
}

.percent-mid {
  background: rgba(255, 116, 95, 0.52);
}

.percent-bad {
  background: rgba(240, 20, 20, 0.62);
}

.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: var(--green);
}

.status-unlinked {
  color: var(--coral);
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 18px;
  border-bottom: 1px solid var(--border);
}

.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;
  border: 1px solid rgba(164, 139, 224, 0.2);
  background: rgba(123, 54, 217, 0.16);
  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 var(--border);
  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(24, 174, 245, 0.1);
}

.ranking-name {
  min-width: 0;
  font-size: 0.9rem;
  font-weight: 800;
}

.ranking-value {
  color: var(--blue);
  font-weight: 900;
}

.bar-track {
  grid-column: 1 / -1;
  height: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(185, 175, 210, 0.16);
}

.bar-fill {
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(135deg, var(--violet), var(--blue));
}

.ranking-item.active .ranking-name,
.ranking-item.active .ranking-value {
  color: var(--coral);
}

.ranking-item.active .bar-fill {
  background: var(--coral);
}

.table-wrap {
  max-height: 660px;
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  border-bottom: 1px solid var(--border);
  padding: 12px 14px;
  text-align: left;
  vertical-align: top;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: rgba(22, 15, 36, 0.98);
  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;
}

.app-footer {
  position: fixed;
  left: 50%;
  bottom: 9px;
  transform: translateX(-50%);
  z-index: 20;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: rgba(248, 245, 255, 0.36);
  background: transparent;
  font-size: 10px;
  pointer-events: none;
}

@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;
  }
}
