:root {
  --surface: #f7f7f8;
  --paper: #ffffff;
  --ink: #111111;
  --muted: #666668;
  --faint: #8b8b8e;
  --line: #d9d9dc;
  --line-strong: #b8b8bc;
  --accent: #e4002b;
  --accent-soft: #ffe8ed;
  --success: #236b3d;
  --warning: #9a5a00;
  --radius: 4px;
  --page-width: 1440px;
  color-scheme: light;
  font-family:
    "Helvetica Neue",
    Helvetica,
    Arial,
    "PingFang SC",
    "Microsoft YaHei",
    sans-serif;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
}

* {
  box-sizing: border-box;
}

html {
  background: var(--surface);
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--surface);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.5;
  font-variant-numeric: tabular-nums;
}

button,
input,
select {
  font: inherit;
}

button {
  color: inherit;
}

.masthead {
  border-bottom: 1px solid var(--line);
  background: var(--paper);
}

.masthead-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  width: min(100% - 40px, var(--page-width));
  min-height: 72px;
  margin: 0 auto;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border: 1px solid var(--ink);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.04em;
}

.brand-copy {
  display: grid;
  gap: 1px;
}

.brand-copy strong {
  font-size: 16px;
  letter-spacing: -0.01em;
}

.brand-copy span {
  max-width: 62vw;
  overflow: hidden;
  color: var(--muted);
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.masthead-actions {
  display: flex;
  align-items: center;
  gap: 16px;
}

.current-user {
  max-width: 220px;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.logout-form {
  margin: 0;
}

.logout-form[hidden] {
  display: none;
}

.sync-status {
  color: var(--muted);
  font-size: 12px;
}

.sync-status.is-live::before {
  display: inline-block;
  width: 6px;
  height: 6px;
  margin-right: 7px;
  border-radius: 50%;
  background: var(--success);
  content: "";
  vertical-align: 1px;
}

.sync-status.is-error::before {
  display: inline-block;
  width: 6px;
  height: 6px;
  margin-right: 7px;
  border-radius: 50%;
  background: var(--accent);
  content: "";
  vertical-align: 1px;
}

.action-button {
  display: inline-flex;
  min-height: 36px;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--paper);
  cursor: pointer;
}

.action-button:hover {
  border-color: var(--ink);
}

.action-button:focus-visible,
.period-tabs button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.action-button:disabled {
  cursor: wait;
  opacity: 0.55;
}

.action-button svg {
  width: 16px;
  height: 16px;
}

.action-button.is-loading svg {
  animation: spin 0.9s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.page {
  width: min(100% - 40px, var(--page-width));
  margin: 0 auto;
  padding: 28px 0 38px;
}

.error-banner {
  margin-bottom: 18px;
  padding: 12px 14px;
  border-left: 3px solid var(--accent);
  background: var(--accent-soft);
  color: #7b0017;
  font-size: 13px;
}

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(420px, 0.95fr);
  gap: 0;
  border-top: 1px solid var(--ink);
  border-bottom: 1px solid var(--ink);
  background: var(--paper);
}

.hero-summary {
  min-height: 320px;
  padding: 34px 40px 30px 0;
  border-right: 1px solid var(--line);
}

.section-kicker {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.hero-value {
  min-height: 72px;
  font-size: 56px;
  font-weight: 650;
  letter-spacing: -0.045em;
  line-height: 1.05;
}

.hero-context {
  min-height: 23px;
  margin: 15px 0 30px;
  color: var(--muted);
  font-size: 13px;
}

.period-tabs {
  display: inline-grid;
  grid-template-columns: repeat(4, minmax(64px, auto));
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
}

.period-tabs button {
  min-height: 36px;
  padding: 7px 14px;
  border: 0;
  border-right: 1px solid var(--line-strong);
  background: var(--paper);
  cursor: pointer;
  font-size: 13px;
}

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

.period-tabs button:hover {
  background: #f1f1f2;
}

.period-tabs button.is-active {
  background: var(--ink);
  color: var(--paper);
}

.credit-section {
  min-height: 320px;
  padding: 34px 0 30px 40px;
}

.credit-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
}

.credit-value {
  font-size: 32px;
  font-weight: 650;
  letter-spacing: -0.035em;
}

.credit-used {
  display: grid;
  justify-items: end;
  color: var(--accent);
}

.credit-used span {
  font-size: 24px;
  font-weight: 650;
}

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

.credit-gauge {
  display: block;
  width: 100%;
  height: 52px;
  margin-top: 25px;
  overflow: visible;
}

.credit-scale {
  display: flex;
  justify-content: space-between;
  margin-top: 1px;
  color: var(--faint);
  font-size: 10px;
}

.credit-facts,
.pricing-list {
  display: grid;
  margin: 26px 0 0;
  border-top: 1px solid var(--line);
}

.credit-facts {
  grid-template-columns: repeat(3, 1fr);
}

.credit-facts div,
.pricing-list div {
  padding: 15px 14px 0 0;
}

.credit-facts div + div,
.pricing-list div + div {
  padding-left: 14px;
  border-left: 1px solid var(--line);
}

dt {
  color: var(--muted);
  font-size: 11px;
}

dd {
  margin: 4px 0 0;
  font-weight: 650;
}

.metric-ledger {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  margin-top: 18px;
  border: 1px solid var(--line);
  background: var(--paper);
}

.metric-cell {
  min-width: 0;
  padding: 20px 22px;
  border-right: 1px solid var(--line);
}

.metric-cell:last-child {
  border-right: 0;
}

.metric-label {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 12px;
}

.metric-label svg {
  width: 15px;
  height: 15px;
  color: var(--accent);
}

.metric-cell strong {
  display: block;
  margin: 20px 0 2px;
  overflow: hidden;
  font-size: 28px;
  font-weight: 650;
  letter-spacing: -0.03em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.workspace-grid {
  display: grid;
  grid-template-columns: minmax(0, 3fr) minmax(290px, 1fr);
  gap: 18px;
  margin-top: 18px;
}

.chart-section,
.pricing-section,
.table-section {
  border-top: 1px solid var(--ink);
  background: var(--paper);
}

.chart-section,
.pricing-section {
  min-height: 390px;
  padding-top: 22px;
}

.section-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}

.section-heading .section-kicker {
  margin-bottom: 5px;
}

.section-heading h1,
.section-heading h2 {
  margin: 0;
  font-size: 20px;
  font-weight: 650;
  letter-spacing: -0.02em;
}

.date-range {
  color: var(--muted);
  font-size: 11px;
}

.chart-wrap {
  position: relative;
  min-height: 310px;
  padding-top: 20px;
}

.spend-chart {
  display: block;
  width: 100%;
  min-height: 280px;
}

.empty-state {
  position: absolute;
  inset: 45% 0 auto;
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

.pricing-section {
  padding-left: 22px;
  padding-right: 22px;
}

.pricing-list {
  margin-top: 0;
}

.pricing-list div {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
}

.pricing-list div + div {
  padding-left: 0;
  border-left: 0;
}

.pricing-list dd {
  margin: 0;
  text-align: right;
}

.pricing-note {
  margin: 20px 0 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.7;
}

.table-section {
  margin-top: 18px;
  padding-top: 22px;
}

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

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

th,
td {
  padding: 12px 12px;
  border-bottom: 1px solid var(--line);
  text-align: right;
  white-space: nowrap;
}

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

th:last-child,
td:last-child {
  padding-right: 0;
}

th {
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

td {
  font-size: 13px;
}

tbody tr:hover {
  background: var(--surface);
}

.failure-count {
  color: var(--accent);
}

.page-footer {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  padding-top: 22px;
  color: var(--faint);
  font-size: 10px;
}

.page-footer p {
  margin: 0;
}

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

  .hero-summary {
    padding-right: 28px;
  }

  .credit-section {
    padding-left: 28px;
  }

  .metric-ledger {
    grid-template-columns: repeat(2, 1fr);
  }

  .metric-cell:nth-child(2) {
    border-right: 0;
  }

  .metric-cell:nth-child(-n + 2) {
    border-bottom: 1px solid var(--line);
  }

  .workspace-grid {
    grid-template-columns: minmax(0, 2fr) minmax(260px, 1fr);
  }
}

@media (max-width: 820px) {
  .masthead-inner,
  .page {
    width: min(100% - 28px, var(--page-width));
  }

  .sync-status {
    display: none;
  }

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

  .hero-summary,
  .credit-section {
    min-height: auto;
    padding: 26px 22px;
  }

  .hero-summary {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

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

  .chart-section,
  .pricing-section {
    min-height: auto;
    padding: 20px 18px 0;
  }

  .pricing-section {
    padding-bottom: 22px;
  }

  .chart-wrap {
    min-height: 250px;
  }

  .spend-chart {
    min-height: 230px;
  }

  .section-heading,
  .table-section .section-heading {
    padding-left: 18px;
    padding-right: 18px;
  }

  .table-section {
    padding-left: 0;
    padding-right: 0;
  }
}

@media (max-width: 560px) {
  .brand-copy span {
    max-width: 46vw;
  }

  .action-button span {
    display: none;
  }

  .action-button {
    width: 36px;
    justify-content: center;
    padding: 7px;
  }

  .hero-value {
    font-size: 46px;
  }

  .credit-heading {
    align-items: flex-end;
  }

  .credit-value {
    font-size: 27px;
  }

  .credit-used span {
    font-size: 20px;
  }

  .credit-facts {
    grid-template-columns: 1fr;
  }

  .credit-facts div,
  .credit-facts div + div {
    padding: 11px 0;
    border-left: 0;
    border-bottom: 1px solid var(--line);
  }

  .credit-facts div:last-child {
    border-bottom: 0;
  }

  .credit-facts dt,
  .credit-facts dd {
    display: inline;
  }

  .credit-facts dd {
    margin-left: 8px;
  }

  .metric-ledger {
    grid-template-columns: 1fr;
  }

  .metric-cell,
  .metric-cell:nth-child(2) {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .metric-cell:last-child {
    border-bottom: 0;
  }

  .metric-cell strong {
    margin-top: 13px;
  }

  .period-tabs {
    width: 100%;
    grid-template-columns: repeat(4, 1fr);
  }

  .period-tabs button {
    padding-right: 6px;
    padding-left: 6px;
  }

  .section-heading {
    align-items: flex-start;
    flex-direction: column;
    gap: 6px;
  }

  .page-footer {
    flex-direction: column;
    gap: 4px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .action-button.is-loading svg {
    animation: none;
  }
}

.auth-body {
  min-height: 100vh;
  background:
    linear-gradient(90deg, transparent calc(50% - 1px), var(--line) 50%, transparent calc(50% + 1px)),
    var(--surface);
}

.auth-page {
  display: grid;
  width: min(100% - 40px, 1120px);
  min-height: 100vh;
  grid-template-columns: minmax(0, 1.15fr) minmax(360px, 0.85fr);
  margin: 0 auto;
}

.auth-intro {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 34px 56px 34px 0;
  border-right: 1px solid var(--line);
}

.auth-brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: inherit;
  text-decoration: none;
}

.auth-copy {
  max-width: 610px;
  padding-bottom: 9vh;
}

.auth-copy h1 {
  max-width: 560px;
  margin: 0;
  font-size: 58px;
  font-weight: 650;
  letter-spacing: -0.05em;
  line-height: 1.06;
}

.auth-copy p {
  max-width: 500px;
  margin: 22px 0 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.75;
}

.auth-meta {
  color: var(--faint);
  font-size: 10px;
}

.auth-panel-wrap {
  display: flex;
  align-items: center;
  padding-left: 56px;
}

.auth-panel {
  width: 100%;
  max-width: 390px;
  padding: 26px 0 28px;
  border-top: 3px solid var(--accent);
}

.auth-panel h2 {
  margin: 0;
  font-size: 28px;
  font-weight: 650;
  letter-spacing: -0.03em;
}

.auth-panel-copy {
  margin: 10px 0 26px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.65;
}

.google-button {
  display: flex;
  min-height: 48px;
  align-items: center;
  justify-content: center;
  gap: 12px;
  border-radius: var(--radius);
  background: var(--ink);
  color: var(--paper);
  font-size: 14px;
  font-weight: 650;
  text-decoration: none;
}

.google-button:hover {
  background: #2a2a2b;
}

.google-button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.google-button img {
  width: 20px;
  height: 20px;
  padding: 4px;
  border-radius: 2px;
  background: var(--paper);
}

.login-error {
  margin: 18px 0 0;
  padding: 10px 12px;
  border-left: 3px solid var(--accent);
  background: var(--accent-soft);
  color: #7b0017;
  font-size: 12px;
  line-height: 1.55;
}

.auth-note {
  margin: 20px 0 0;
  color: var(--faint);
  font-size: 11px;
  line-height: 1.65;
}

@media (max-width: 820px) {
  .current-user {
    display: none;
  }

  .auth-body {
    background: var(--surface);
  }

  .auth-page {
    grid-template-columns: 1fr;
    width: min(100% - 32px, 620px);
  }

  .auth-intro {
    min-height: 42vh;
    padding: 24px 0 34px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .auth-copy {
    padding: 64px 0 0;
  }

  .auth-copy h1 {
    font-size: 42px;
  }

  .auth-panel-wrap {
    padding: 42px 0 54px;
  }

  .auth-panel {
    max-width: none;
  }
}

@media (max-width: 480px) {
  .auth-copy h1 {
    font-size: 36px;
  }

  .auth-meta {
    margin-top: 38px;
  }
}
