:root {
  color-scheme: light;
  --bg: #f5f7fa;
  --surface: #ffffff;
  --line: #d9e0e7;
  --text: #202632;
  --muted: #6c7584;
  --blue: #2e78c7;
  --green: #23835a;
  --orange: #c46a2d;
  --red: #bc4343;
  --ink-soft: #edf1f5;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, "Segoe UI", "Noto Sans TC", Arial, sans-serif;
}

button {
  font: inherit;
}

.app {
  display: grid;
  grid-template-columns: 272px minmax(0, 1fr);
  min-height: 100vh;
  overflow-x: hidden;
}

.sidebar {
  background: #17202c;
  color: #fff;
  min-width: 0;
  padding: 24px 16px;
}

.brand {
  font-size: 22px;
  font-weight: 700;
  margin: 2px 8px 28px;
}

.account-list {
  display: grid;
  gap: 8px;
  max-width: 100%;
  min-width: 0;
  scrollbar-width: none;
}

.account-list::-webkit-scrollbar {
  display: none;
}

.account-item {
  width: 100%;
  border: 0;
  border-radius: 8px;
  padding: 12px;
  color: #dce6ef;
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.account-item.active {
  color: #fff;
  background: #2e78c7;
}

.account-item .name {
  display: block;
  font-weight: 700;
}

.account-item .email {
  display: block;
  margin-top: 3px;
  overflow: hidden;
  color: inherit;
  opacity: .76;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
}

.main {
  min-width: 0;
  padding: 28px;
}

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

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 26px;
  line-height: 1.2;
}

h2 {
  font-size: 16px;
}

#rangeText {
  margin-top: 6px;
  color: var(--muted);
  font-size: 14px;
}

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

.icon-button {
  width: 40px;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}

.icon-button:disabled {
  cursor: wait;
  opacity: .55;
}

.text-button {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
  padding: 0 13px;
  white-space: nowrap;
}

.text-button.active {
  border-color: var(--blue);
  background: #eef6ff;
  color: var(--blue);
}

.toggle-button {
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
  color: var(--blue);
  cursor: pointer;
  font-size: 13px;
  padding: 7px 10px;
  white-space: nowrap;
}

.toggle-button:hover {
  border-color: var(--blue);
  background: #eef6ff;
}

.detail-body[hidden] {
  display: none;
}

.panel[hidden] {
  display: none;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(142px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.metric {
  min-height: 96px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 14px;
}

.metric .label {
  color: var(--muted);
  font-size: 13px;
}

.metric .value {
  margin-top: 10px;
  font-size: 24px;
  font-weight: 750;
}

.metric .value.positive {
  color: var(--green);
}

.metric .value.negative {
  color: var(--red);
}

.metric .value.neutral {
  color: var(--muted);
}

.metric .subline {
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  margin-bottom: 16px;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 56px;
  border-bottom: 1px solid var(--line);
  padding: 0 16px;
}

.panel-subtitle {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.x-card-panel {
  overflow: hidden;
}

.x-card-stats {
  display: grid;
  grid-template-columns: repeat(5, minmax(120px, 1fr));
  border-bottom: 1px solid var(--line);
}

.x-card-stat {
  min-height: 82px;
  border-right: 1px solid var(--ink-soft);
  padding: 14px 16px;
}

.x-card-stat:last-child {
  border-right: 0;
}

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

.x-card-stat .value {
  margin-top: 8px;
  font-size: 22px;
  font-weight: 750;
}

.x-card-stat .subline {
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.x-card-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(260px, .65fr);
  gap: 18px;
  padding: 16px;
}

.x-card-block {
  min-width: 0;
}

.x-card-grid + .x-card-block {
  padding: 0 16px 16px;
}

.block-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 34px;
}

.block-header h3 {
  margin: 0;
  font-size: 14px;
}

.compact-table {
  min-width: 560px;
}

.compact-summary {
  padding: 0;
}

.segmented {
  display: inline-flex;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--ink-soft);
}

.segmented button {
  border: 0;
  border-right: 1px solid var(--line);
  background: transparent;
  padding: 8px 12px;
  cursor: pointer;
  color: var(--muted);
}

.segmented button:last-child {
  border-right: 0;
}

.segmented button.active {
  background: var(--surface);
  color: var(--blue);
  font-weight: 700;
}

#rankingTabs {
  flex-shrink: 0;
}

.chart-wrap {
  position: relative;
  height: 360px;
  padding: 18px;
}

#trendChart {
  width: 100%;
  height: 100%;
  display: block;
}

.chart-dot {
  cursor: crosshair;
  outline: none;
}

.chart-dot:hover,
.chart-dot:focus {
  stroke: #ffffff;
  stroke-width: 3;
}

.chart-tooltip {
  position: absolute;
  z-index: 3;
  min-width: 124px;
  border: 1px solid rgba(23, 32, 44, .12);
  border-radius: 8px;
  background: rgba(23, 32, 44, .94);
  box-shadow: 0 10px 24px rgba(23, 32, 44, .16);
  color: #fff;
  opacity: 0;
  padding: 8px 10px;
  pointer-events: none;
  transition: opacity .12s ease;
}

.chart-tooltip strong,
.chart-tooltip span {
  display: block;
  white-space: nowrap;
}

.chart-tooltip strong {
  font-size: 12px;
  font-weight: 700;
}

.chart-tooltip span {
  margin-top: 3px;
  font-size: 13px;
}

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

.ranking-list,
.summary-list {
  padding: 12px 16px 16px;
}

.rank-row,
.summary-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--ink-soft);
}

.rank-row:last-child,
.summary-row:last-child {
  border-bottom: 0;
}

.summary-row {
  grid-template-columns: minmax(0, 1fr) auto;
}

.member-daily-row {
  grid-template-columns: minmax(0, 1fr) auto auto auto;
}

.site-summary-row {
  grid-template-columns: minmax(0, 1fr) auto auto;
}

.rank-index {
  display: inline-grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 8px;
  background: var(--ink-soft);
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.rank-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 700;
}

.rank-value {
  font-weight: 750;
}

.rank-bar {
  grid-column: 2 / 4;
  height: 6px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--ink-soft);
}

.rank-bar i {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--blue);
}

.row-label {
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.row-value {
  font-weight: 700;
}

.row-sub {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 1080px;
}

th,
td {
  border-bottom: 1px solid var(--ink-soft);
  padding: 12px 16px;
  text-align: right;
}

th:first-child,
td:first-child {
  text-align: left;
}

th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.sort-button {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  min-width: 0;
  max-width: 100%;
  border: 0;
  padding: 0;
  background: transparent;
  color: inherit;
  cursor: pointer;
  font: inherit;
  font-weight: 700;
  white-space: nowrap;
}

th:first-child .sort-button {
  justify-content: flex-start;
}

.sort-button:hover {
  color: var(--blue);
}

.date-copy {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.copy-report-button {
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
  color: var(--blue);
  cursor: pointer;
  font-size: 12px;
  line-height: 1;
  padding: 6px 8px;
  white-space: nowrap;
}

.copy-report-button:hover,
.copy-report-button.copied {
  border-color: var(--blue);
  background: #eef6ff;
}

.change-pill {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  min-width: 72px;
  border-radius: 999px;
  padding: 5px 8px;
  background: var(--ink-soft);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.change-pill.compact {
  min-width: 62px;
  padding: 4px 7px;
  font-size: 11px;
}

.change-pill.positive {
  background: #e8f6ef;
  color: var(--green);
}

.change-pill.negative {
  background: #fbeeee;
  color: var(--red);
}

.member-day-cell {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  min-width: 126px;
}

.member-day-value {
  font-weight: 700;
}

.empty {
  padding: 22px 16px;
  color: var(--muted);
}

.error {
  color: var(--red);
}

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

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 2;
    overflow: hidden;
    padding: 14px 16px;
  }

  .brand {
    margin: 0 0 12px;
  }

  .account-list {
    display: flex;
    overflow-x: auto;
    padding-bottom: 4px;
    width: 100%;
  }

  .account-item {
    min-width: 210px;
  }

  .metrics {
    grid-template-columns: repeat(3, minmax(120px, 1fr));
  }

  .x-card-stats {
    grid-template-columns: repeat(3, minmax(120px, 1fr));
  }

  .x-card-stat {
    border-bottom: 1px solid var(--ink-soft);
  }

  .x-card-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 760px) {
  .main {
    padding: 18px 14px;
  }

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

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

  .actions {
    justify-content: flex-start;
  }

  .x-card-stats {
    grid-template-columns: 1fr 1fr;
  }

  .panel-header {
    align-items: flex-start;
    flex-direction: column;
    padding: 12px 14px;
  }

  .chart-wrap {
    height: 300px;
    padding: 10px;
  }

  .member-daily-row {
    grid-template-columns: minmax(0, 1fr) auto;
  }
}
