:root {
  --bg: #eef2f3;
  --panel: #fffdfa;
  --ink: #222831;
  --muted: #68727d;
  --line: #d9dee2;
  --soft: #f5f2ec;
  --blue: #4285f4;
  --teal: #11998e;
  --amber: #bd780f;
  --rose: #cf4d67;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.bi-shell {
  width: min(1540px, calc(100vw - 48px));
  margin: 38px auto 64px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: flex-start;
  border-bottom: 1px solid var(--line);
  padding-bottom: 22px;
}

.eyebrow {
  margin: 0 0 7px;
  color: #009b8e;
  font-size: 13px;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0;
}

h1, h2, p { margin-top: 0; }
h1 {
  margin-bottom: 8px;
  font-size: clamp(27px, 3vw, 34px);
  line-height: 1.08;
  font-weight: 500;
}
h2 {
  margin-bottom: 5px;
  font-size: 22px;
  line-height: 1.2;
  font-weight: 500;
  color: #69717a;
}

.source-line {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}
.source-line.live { color: #009b8e; }
.source-line.error { color: #b45309; }
.source-line.cached { color: #8a6514; }
.source-status {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 8px;
}
.refresh-button {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  padding: 7px 11px;
  font: inherit;
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
}
.refresh-button:disabled {
  cursor: wait;
  opacity: .55;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}
.user-pill, .logout-link {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  padding: 9px 13px;
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
}

.filter-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(150px, 1fr));
  gap: 10px;
  margin: 24px 0;
}
.filter-field, .annual-field {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}
select, input {
  min-height: 42px;
  border: 1px solid #e5dcca;
  border-radius: 8px;
  background: #fff8ea;
  color: var(--ink);
  padding: 0 13px;
  font: inherit;
  font-size: 14px;
  font-weight: 700;
}
select:disabled {
  color: #9aa2aa;
  background: #f2f1ee;
}

.view-tabs {
  display: flex;
  gap: 10px;
  margin: 0 0 18px;
}
.view-tabs button {
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  padding: 0 18px;
  font-size: 18px;
  font-weight: 900;
  cursor: pointer;
}
.view-tabs button.active {
  background: #2e3743;
  color: white;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 16px;
}
.kpi-row {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 12px;
}
.kpi-row.client-kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.kpi-card, .panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 7px;
  box-shadow: 0 10px 24px rgba(34, 40, 49, .05);
}
.kpi-card {
  min-height: 126px;
  padding: 20px 18px;
  border-top: 5px solid var(--teal);
}
.kpi-card.blue { border-top-color: #2f76d2; }
.kpi-card.amber { border-top-color: var(--amber); }
.kpi-card.rose { border-top-color: var(--rose); }
.kpi-card.ink { border-top-color: #2e3743; }
.kpi-card span {
  display: block;
  margin-bottom: 14px;
  color: var(--muted);
  font-weight: 900;
}
.kpi-card strong {
  display: block;
  font-size: clamp(25px, 2.4vw, 32px);
  line-height: 1;
}
.kpi-card small {
  display: block;
  margin-top: 13px;
  color: var(--muted);
  font-weight: 900;
}

.panel {
  padding: 20px;
  min-width: 0;
}
.full-span { grid-column: 1 / -1; }
.wide { grid-column: span 1; }
.split-panel { min-height: 360px; }
.chart-panel { min-height: 385px; }
.panel-title {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
}
.panel-title p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}
.panel-title > span {
  color: var(--muted);
  font-size: 13px;
}
.annual-title { align-items: flex-start; }
.annual-controls {
  display: flex;
  gap: 10px;
  min-width: 310px;
}
.annual-field { min-width: 145px; }

.chart {
  width: 100%;
  min-height: 300px;
}
.bar-label, .point-label {
  fill: var(--blue);
  font-size: 12px;
  font-weight: 800;
}
.axis-label {
  fill: #222831;
  font-size: 12px;
}
.grid-line {
  stroke: #d1d5d8;
  stroke-width: 1;
}
.axis-line {
  stroke: #111;
  stroke-width: 2;
}
.legend {
  display: flex;
  justify-content: center;
  gap: 28px;
  color: var(--ink);
  font-weight: 700;
  font-size: 14px;
}
.legend span::before {
  content: "";
  display: inline-block;
  width: 24px;
  height: 4px;
  margin-right: 8px;
  vertical-align: middle;
  background: #9aa7bd;
}
.legend span.current::before { background: var(--blue); }

.bar-list {
  display: grid;
  gap: 11px;
}
.bar-row {
  display: grid;
  grid-template-columns: 135px 1fr 110px;
  align-items: center;
  gap: 12px;
  font-weight: 800;
}
.bar-row strong {
  display: grid;
  gap: 2px;
}
.bar-row strong small {
  color: #6f7782;
  font-size: 11px;
  font-weight: 600;
}
.sku-rank {
  display: inline-grid;
  place-items: center;
  width: 24px;
  height: 24px;
  margin-right: 8px;
  border-radius: 50%;
  background: #303842;
  color: #fff;
  font-size: 12px;
  font-weight: 800;
}
.rank-active {
  color: #1769d2;
  font-weight: 800;
}
.bar-track {
  height: 26px;
  border-radius: 7px;
  background: #ece8dd;
  overflow: hidden;
}
.bar-fill {
  height: 100%;
  border-radius: 7px;
  background: linear-gradient(90deg, var(--teal), var(--blue));
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
th, td {
  padding: 13px 12px;
  border-bottom: 1px solid #e4e1da;
  text-align: left;
}
th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}
.rank-list {
  display: grid;
  gap: 10px;
}
.rank-item {
  display: grid;
  grid-template-columns: 38px 1fr auto;
  align-items: center;
  gap: 12px;
  min-height: 50px;
  padding: 8px 12px;
  border-radius: 8px;
  background: var(--soft);
  font-weight: 900;
}
.rank-item b {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: #2e3743;
  color: white;
}
.dual-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.dual-list p {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid #e4e1da;
  margin: 0;
  padding: 13px 0;
  font-weight: 900;
}
.dual-list strong { color: #2f76d2; }
.empty-state {
  margin: 32px 0;
  color: var(--muted);
  font-weight: 700;
}

.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
}
.login-card {
  width: min(420px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 30px;
  box-shadow: 0 18px 40px rgba(34, 40, 49, .12);
}
.login-card h1 { font-size: 30px; }
.login-copy { color: var(--muted); }
.login-form { display: grid; gap: 14px; }
.login-form label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 900;
  text-transform: uppercase;
}
.login-form button {
  min-height: 46px;
  border: 0;
  border-radius: 8px;
  background: #11998e;
  color: white;
  font-size: 16px;
  font-weight: 900;
  cursor: pointer;
}
.login-error {
  border: 1px solid #fecaca;
  border-radius: 8px;
  background: #fff1f2;
  color: #9f1239;
  padding: 10px 12px;
  font-weight: 800;
}

@media (max-width: 980px) {
  .bi-shell { width: min(100% - 24px, 1540px); margin-top: 22px; }
  .topbar { display: grid; }
  .filter-strip { grid-template-columns: 1fr 1fr; }
  .kpi-row, .kpi-row.client-kpis { grid-template-columns: 1fr 1fr; }
  .dashboard-grid { grid-template-columns: 1fr; }
  .wide, .split-panel { grid-column: 1 / -1; }
}

@media (max-width: 620px) {
  .filter-strip, .kpi-row, .kpi-row.client-kpis, .annual-controls, .dual-list { grid-template-columns: 1fr; }
  .view-tabs { flex-wrap: wrap; }
  .bar-row { grid-template-columns: 1fr; gap: 6px; }
  .rank-item { grid-template-columns: 34px 1fr; }
  .rank-item strong { grid-column: 2; }
}
