:root {
  color-scheme: light;
  --bg: #f6f7f4;
  --surface: #ffffff;
  --surface-strong: #f0f3ef;
  --text: #1c2521;
  --muted: #66716b;
  --line: #dfe5df;
  --primary: #176f5d;
  --primary-strong: #0f5a4b;
  --accent: #c88b2d;
  --danger: #b8463a;
  --danger-soft: #f7e2df;
  --warn-soft: #faefd8;
  --ok-soft: #dff0e8;
  --info-soft: #e0ebf3;
  --shadow: 0 18px 45px rgb(25 44 38 / 10%);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  min-width: 320px;
  background: var(--bg);
}

body {
  margin: 0;
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 15px;
  letter-spacing: 0;
  background:
    linear-gradient(180deg, #edf2ee 0, #f6f7f4 330px),
    var(--bg);
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled,
select:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

a {
  color: var(--primary-strong);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 32px;
  line-height: 1.08;
}

h2 {
  font-size: 24px;
  line-height: 1.16;
}

h3 {
  font-size: 17px;
  line-height: 1.25;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  width: min(1480px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 20px;
}

.brand {
  min-width: 0;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--primary-strong);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.account-strip {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px;
}

.status-pill,
.badge {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  border-radius: 999px;
  padding: 0 10px;
  color: #695021;
  background: var(--warn-soft);
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.status-pill.connected,
.badge.ok {
  color: var(--primary-strong);
  background: var(--ok-soft);
}

.badge.warning {
  color: #7a5414;
  background: var(--warn-soft);
}

.badge.danger {
  color: #8f2f26;
  background: var(--danger-soft);
}

.account-select {
  width: min(340px, 42vw);
}

.button,
.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 38px;
  border: 1px solid var(--primary);
  border-radius: var(--radius);
  padding: 0 14px;
  color: #fff;
  background: var(--primary);
  font-weight: 800;
  line-height: 1;
  text-decoration: none;
  white-space: nowrap;
  transition:
    transform 120ms ease,
    background 120ms ease,
    border-color 120ms ease;
}

.button:hover,
.icon-button:hover {
  background: var(--primary-strong);
  border-color: var(--primary-strong);
  text-decoration: none;
}

.button:active,
.icon-button:active {
  transform: translateY(1px);
}

.button-secondary {
  color: var(--text);
  border-color: var(--line);
  background: var(--surface);
}

.button-secondary:hover {
  color: var(--text);
  background: var(--surface-strong);
  border-color: #cbd5cd;
}

.button-danger {
  color: var(--danger);
  border-color: #e3bab5;
  background: var(--danger-soft);
}

.button-danger:hover {
  color: #fff;
  background: var(--danger);
  border-color: var(--danger);
}

.icon-button {
  width: 34px;
  min-height: 34px;
  padding: 0;
  color: var(--text);
  border-color: var(--line);
  background: var(--surface);
}

.shell {
  width: min(1480px, calc(100% - 32px));
  margin: 0 auto 28px;
}

.connect-panel {
  display: grid;
  grid-template-columns: minmax(0, 0.9fr) minmax(440px, 1.1fr);
  gap: 18px;
  align-items: stretch;
}

.connect-copy,
.auth-card,
.panel,
.metric-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgb(255 255 255 / 92%);
  box-shadow: var(--shadow);
}

.connect-copy {
  display: grid;
  align-content: center;
  gap: 18px;
  min-height: 360px;
  padding: 34px;
}

.connect-copy p:last-child {
  max-width: 60ch;
  color: var(--muted);
  font-size: 16px;
  line-height: 1.65;
}

.auth-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.auth-card {
  display: grid;
  align-content: space-between;
  gap: 18px;
  min-height: 360px;
  padding: 20px;
}

.auth-card p {
  margin-top: 8px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}

.oauth-card .button {
  align-self: end;
}

.form-note {
  min-height: 40px;
}

.dashboard {
  display: grid;
  grid-template-columns: minmax(248px, 286px) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.workspace {
  display: grid;
  gap: 18px;
  min-width: 0;
}

.panel {
  padding: 16px;
}

.filters {
  position: sticky;
  top: 14px;
  display: grid;
  gap: 16px;
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 34px;
}

.section-title h2 {
  font-size: 17px;
  line-height: 1.25;
}

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

.field {
  display: grid;
  gap: 7px;
}

.field span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.field-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

input,
select {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0 10px;
  color: var(--text);
  background: #fff;
  outline: none;
}

input:focus,
select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgb(23 111 93 / 14%);
}

.segmented {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-strong);
}

.segmented button {
  min-width: 0;
  min-height: 30px;
  border: 0;
  border-radius: 6px;
  color: var(--muted);
  background: transparent;
  font-size: 13px;
  font-weight: 800;
}

.segmented button.active {
  color: #fff;
  background: var(--primary);
}

.quota-note {
  min-height: 42px;
  padding: 10px;
  border-radius: var(--radius);
  color: #55421c;
  background: var(--warn-soft);
  font-size: 13px;
  line-height: 1.45;
}

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

.metric-card {
  display: grid;
  gap: 8px;
  min-height: 112px;
  padding: 16px;
}

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

.metric-card .value {
  overflow-wrap: anywhere;
  font-size: 28px;
  font-weight: 850;
  line-height: 1;
}

.metric-card .detail {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.08fr) minmax(0, 0.92fr);
  gap: 18px;
  align-items: stretch;
}

.ranking-list,
.warning-list,
.source-list {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.rank-item,
.source-item,
.warning-item {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
}

.warning-item {
  border-color: #efd59e;
  background: #fffaf0;
}

.rank-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(92px, 120px);
  gap: 12px;
}

.rank-main {
  display: grid;
  gap: 8px;
  min-width: 0;
}

.rank-title {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

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

.rank-meta,
.record-meta,
.source-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 7px 12px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.bar {
  position: relative;
  width: 100%;
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: #e7ece7;
}

.bar span {
  position: absolute;
  inset: 0 auto 0 0;
  width: var(--bar-width, 0%);
  max-width: 100%;
  border-radius: inherit;
  background: var(--bar-color, var(--primary));
}

.rank-percent {
  display: grid;
  align-content: center;
  justify-items: end;
  gap: 6px;
  color: var(--text);
  font-size: 20px;
  font-weight: 850;
  line-height: 1;
}

.rank-percent small {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
  margin-top: 12px;
}

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

th,
td {
  padding: 11px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
  background: var(--surface-strong);
}

tbody tr:hover {
  background: #f9faf8;
}

.number {
  font-variant-numeric: tabular-nums;
}

.metric-name {
  display: grid;
  gap: 2px;
}

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

.trend-chart {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(22px, 1fr);
  gap: 6px;
  align-items: end;
  min-height: 178px;
  margin-top: 14px;
  padding: 14px 8px 4px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  overflow-x: auto;
}

.trend-day {
  display: grid;
  grid-template-rows: 1fr auto;
  justify-items: center;
  gap: 8px;
  min-width: 22px;
  height: 148px;
}

.trend-bar {
  align-self: end;
  width: 100%;
  min-height: 4px;
  height: var(--trend-height, 0%);
  border-radius: 6px 6px 2px 2px;
  background: var(--bar-color, var(--primary));
}

.trend-day time {
  color: var(--muted);
  font-size: 11px;
  writing-mode: vertical-rl;
  transform: rotate(180deg);
}

.empty-state {
  padding: 24px 14px;
  color: var(--muted);
  text-align: center;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  background: #fff;
}

.footer {
  display: flex;
  flex-wrap: wrap;
  gap: 9px 14px;
  width: min(1480px, calc(100% - 32px));
  margin: 0 auto 28px;
  color: var(--muted);
  font-size: 13px;
}

@media (max-width: 1120px) {
  .connect-panel,
  .dashboard {
    grid-template-columns: 1fr;
  }

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

  .filters .section-title,
  .filters .quota-note {
    grid-column: 1 / -1;
  }
}

@media (max-width: 900px) {
  .auth-grid,
  .summary-grid,
  .content-grid {
    grid-template-columns: 1fr;
  }

  .auth-card,
  .connect-copy {
    min-height: auto;
  }
}

@media (max-width: 640px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .account-strip {
    justify-content: flex-start;
    width: 100%;
  }

  .account-select {
    width: 100%;
  }

  .shell,
  .topbar,
  .footer {
    width: min(100% - 20px, 1480px);
  }

  .connect-copy {
    padding: 22px;
  }

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

  .filters .section-title,
  .filters .quota-note {
    grid-column: auto;
  }

  .metric-card {
    min-height: 98px;
  }

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

  .rank-percent {
    justify-items: start;
  }
}
