:root {
  --bg: #f3f5f7;
  --panel: #ffffff;
  --line: #d9e1e6;
  --text: #172026;
  --muted: #61717d;
  --soft: #eef3f5;
  --nav: #18252d;
  --nav-active: #263741;
  --accent: #0f766e;
  --accent-ink: #064e47;
  --warn: #b65b19;
  --danger: #c43b33;
  --good: #25724b;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
  color: var(--text);
  background: var(--bg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.sidebar {
  min-height: 100vh;
  padding: 18px;
  background: var(--nav);
  color: #fff;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 48px;
}

.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  background: var(--accent);
  border-radius: 6px;
  font-weight: 700;
}

.brand span {
  display: block;
  color: #b7c4cb;
  font-size: 13px;
  margin-top: 4px;
}

nav {
  display: grid;
  gap: 6px;
}

nav button,
.ghost {
  height: 38px;
  border: 0;
  border-radius: 6px;
  padding: 0 12px;
  color: #d9e3e8;
  background: transparent;
  text-align: left;
  font: inherit;
  cursor: pointer;
}

nav button.active,
nav button:hover {
  background: var(--nav-active);
  color: #fff;
}

.ghost {
  margin-top: auto;
  border: 1px solid #3a4b54;
}

main {
  min-width: 0;
}

.login-panel {
  min-height: 100vh;
  display: grid;
  place-items: center;
}

.login-card {
  width: min(380px, calc(100vw - 32px));
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 24px;
}

.login-card h1 {
  margin: 0 0 20px;
  font-size: 22px;
}

label {
  display: grid;
  gap: 8px;
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 14px;
}

input,
select {
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 10px;
  background: #fff;
  color: var(--text);
  font: inherit;
}

button[type="submit"],
.primary,
.small-primary {
  height: 40px;
  border: 0;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  font: inherit;
  cursor: pointer;
}

button[type="submit"] {
  width: 100%;
}

.small-primary {
  width: auto;
  min-width: 84px;
  padding: 0 14px;
}

.secondary {
  height: 40px;
  min-width: 72px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  font: inherit;
  cursor: pointer;
}

.secondary:hover {
  border-color: var(--accent);
  color: var(--accent-ink);
}

#loginError {
  color: var(--danger);
  min-height: 20px;
}

.hidden {
  display: none;
}

.app-panel {
  padding: 22px;
}

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

.topbar h1 {
  margin: 0;
  font-size: 24px;
}

.topbar p {
  margin: 6px 0 0;
  color: var(--muted);
}

.user-pill {
  border: 1px solid var(--line);
  background: var(--panel);
  padding: 8px 12px;
  border-radius: 999px;
  color: var(--muted);
  white-space: nowrap;
}

.filterbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 14px;
  margin: 0 0 16px;
  padding: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.searchbar {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(240px, 1.4fr) auto auto;
  gap: 10px;
  align-items: end;
  margin: 0 0 16px;
  padding: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.searchbar label {
  margin: 0;
  gap: 5px;
}

.searchbar input {
  width: 100%;
}

.search-summary {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: center;
  margin-bottom: 14px;
  padding: 12px 14px;
  border: 1px solid #b8d8d2;
  border-radius: 8px;
  background: #edf8f6;
}

.search-summary strong,
.search-summary span {
  display: block;
}

.search-summary span {
  color: var(--muted);
  font-size: 13px;
  margin-top: 3px;
}

.search-counts {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.search-counts span {
  margin: 0;
  padding: 5px 8px;
  border-radius: 6px;
  background: #fff;
  border: 1px solid #cde2de;
  color: var(--accent-ink);
  white-space: nowrap;
}

.range-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.range-buttons button {
  height: 34px;
  min-width: 82px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  font: inherit;
  cursor: pointer;
}

.range-buttons button.active {
  border-color: var(--accent);
  background: #e6f4f1;
  color: var(--accent-ink);
  font-weight: 600;
}

.custom-range {
  display: flex;
  align-items: end;
  gap: 8px;
  flex-wrap: wrap;
}

.custom-range label {
  margin: 0;
  gap: 5px;
}

.custom-range input {
  width: 150px;
}

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

.kpi-grid {
  grid-template-columns: repeat(6, minmax(0, 1fr));
}

.card,
.table-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
}

.metric {
  min-height: 104px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  color: var(--muted);
}

.metric strong {
  display: block;
  color: var(--text);
  font-size: 24px;
  line-height: 1.15;
  overflow-wrap: anywhere;
}

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

.metric-action {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--muted);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.metric-action:hover,
.metric-action:focus-visible {
  border-color: var(--accent);
  background: #f3fbf9;
  box-shadow: 0 1px 0 rgba(15, 118, 110, 0.16);
}

.metric-action:focus-visible {
  outline: 2px solid rgba(15, 118, 110, 0.24);
  outline-offset: 2px;
}

.platform-split,
.two-col {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 12px;
}

.platform-card {
  width: 100%;
  min-height: 132px;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.platform-card:hover,
.platform-card:focus-visible {
  border-color: var(--accent);
  box-shadow: 0 1px 0 rgba(15, 118, 110, 0.16);
}

.platform-card-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
}

.platform-card-head strong {
  color: var(--text);
  font-size: 18px;
}

.platform-card-metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-top: 18px;
}

.platform-card-metrics div {
  min-width: 0;
}

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

.platform-card-metrics strong {
  display: block;
  margin-top: 5px;
  font-size: 19px;
  overflow-wrap: anywhere;
}

.section {
  margin-top: 18px;
  scroll-margin-top: 18px;
}

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  min-height: 32px;
}

.section h2 {
  margin: 0;
  font-size: 17px;
}

.chart-card {
  margin-top: 12px;
  min-height: 284px;
}

.chart-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
  margin-bottom: 8px;
}

.chart-head strong,
.chart-head span {
  display: block;
}

.chart-head span,
.chart-legend {
  color: var(--muted);
  font-size: 12px;
}

.chart-legend {
  white-space: nowrap;
}

.chart-legend i {
  display: inline-block;
  width: 9px;
  height: 9px;
  margin: 0 4px 0 10px;
  border-radius: 2px;
}

.legend-amount {
  background: var(--accent);
}

.legend-orders {
  background: var(--warn);
}

svg {
  width: 100%;
  height: 220px;
  display: block;
}

.axis {
  stroke: #c9d5db;
}

.line {
  fill: none;
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.amount-line {
  stroke: var(--accent);
}

.order-line {
  stroke: var(--warn);
  opacity: 0.8;
}

.amount-dot {
  fill: var(--accent);
}

.rank-list {
  display: grid;
  gap: 9px;
}

.rank-row {
  display: grid;
  grid-template-columns: 32px 1fr;
  gap: 10px;
  align-items: start;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
}

.rank-index {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  background: var(--soft);
  color: var(--muted);
  font-weight: 700;
}

.rank-main {
  min-width: 0;
}

.rank-title {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}

.rank-title span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rank-title strong {
  white-space: nowrap;
}

.rank-sub {
  color: var(--muted);
  font-size: 12px;
  margin-top: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rank-bar {
  height: 5px;
  margin-top: 8px;
  overflow: hidden;
  border-radius: 4px;
  background: var(--soft);
}

.rank-bar i {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--good));
  border-radius: inherit;
}

.sales-rank-list {
  display: grid;
  gap: 9px;
}

.sales-rank-row {
  display: grid;
  grid-template-columns: 32px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
}

.sales-rank-main {
  min-width: 0;
}

.sales-rank-title {
  display: grid;
  grid-template-columns: minmax(120px, 1fr) auto;
  gap: 12px;
  align-items: center;
}

.sales-rank-title strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rank-metrics {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.rank-metric {
  min-width: 72px;
  padding: 5px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f8fbfc;
}

.rank-metric small,
.rank-metric strong {
  display: block;
}

.rank-metric small {
  color: var(--muted);
  font-size: 11px;
}

.rank-metric strong {
  margin-top: 2px;
  color: var(--text);
  font-size: 14px;
}

.product-rank-title {
  display: grid;
  gap: 5px;
}

.product-rank-prefix {
  display: inline-block;
  color: var(--accent-ink);
  font-size: 13px;
  font-weight: 700;
}

.product-rank-title strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.table-card {
  margin-top: 10px;
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

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

th {
  position: sticky;
  top: 0;
  color: var(--muted);
  font-weight: 600;
  background: #f7fafb;
  z-index: 1;
}

td {
  background: #fff;
}

tr.summary-row td {
  background: #edf7f5;
  color: var(--accent-ink);
  font-weight: 700;
}

.empty-cell,
.empty-card,
.loading {
  color: var(--muted);
}

.empty-cell {
  text-align: center;
  height: 70px;
}

.note {
  color: var(--muted);
  line-height: 1.6;
}

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

  .platform-card-metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 900px) {
  body {
    grid-template-columns: 1fr;
  }

  .sidebar {
    min-height: auto;
  }

  .filterbar,
  .searchbar,
  .topbar,
  .platform-split,
  .two-col {
    grid-template-columns: 1fr;
    flex-direction: column;
    align-items: stretch;
  }

  .grid,
  .kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .sales-rank-title {
    grid-template-columns: 1fr;
  }

  .rank-metrics {
    justify-content: flex-start;
  }
}

@media (max-width: 560px) {
  .app-panel {
    padding: 14px;
  }

  .grid,
  .kpi-grid {
    grid-template-columns: 1fr;
  }

  .custom-range input {
    width: 100%;
  }

  .custom-range,
  .searchbar,
  .range-buttons {
    width: 100%;
  }

  .range-buttons button,
  .secondary,
  .small-primary {
    flex: 1;
  }

  .searchbar {
    grid-template-columns: 1fr;
  }

  .search-summary {
    align-items: stretch;
    flex-direction: column;
  }
}
