:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --ink: #151718;
  --muted: #62707d;
  --soft: #eef1f4;
  --line: #d9e0e6;
  --idle: #d6dde3;
  --level-1: #92d8cb;
  --level-2: #43bea0;
  --level-3: #f0b64a;
  --level-4: #ee7d56;
  --level-5: #e24372;
  --focus: #315bea;
  --shadow: 0 18px 44px rgb(20 25 31 / 10%);
  --mono: "SFMono-Regular", "Cascadia Code", "Liberation Mono", Menlo, monospace;
  --sans: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  overflow-x: hidden;
  background:
    linear-gradient(180deg, rgb(255 255 255 / 72%), rgb(255 255 255 / 0%) 260px),
    var(--bg);
  color: var(--ink);
  font-family: var(--sans);
}

button,
select {
  font: inherit;
}

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

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

.eyebrow {
  margin: 0 0 6px;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 0;
  font-size: clamp(2rem, 5vw, 4.65rem);
  line-height: 0.92;
  letter-spacing: 0;
  text-wrap: balance;
}

h2 {
  margin-bottom: 0;
  font-size: 1.15rem;
  letter-spacing: 0;
}

.year-control {
  display: grid;
  gap: 8px;
  min-width: 132px;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
}

.year-control select {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  padding: 0 36px 0 12px;
}

.year-control select:focus-visible,
.day-cell:focus-visible {
  outline: 3px solid rgb(49 91 234 / 28%);
  outline-offset: 2px;
}

.lifetime-banner {
  display: flex;
  flex-direction: column;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(135deg, var(--surface), var(--soft));
  padding: 20px 22px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}

.lifetime-value {
  font-size: clamp(2.4rem, 6vw, 4rem);
  font-weight: 800;
  line-height: 0.95;
  letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;
}

.lifetime-detail {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.78rem;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}

.summary-card {
  min-height: 104px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 14px;
  box-shadow: 0 8px 22px rgb(20 25 31 / 5%);
}

.summary-card span {
  display: block;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.summary-card strong {
  display: block;
  margin-top: 12px;
  font-size: clamp(1.35rem, 2.4vw, 2.15rem);
  line-height: 1;
}

.summary-card small {
  display: block;
  margin-top: 10px;
  color: var(--muted);
  line-height: 1.35;
}

.workbench {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 16px;
  align-items: start;
}

.heatmap-section,
.detail-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.heatmap-section {
  min-width: 0;
  overflow: hidden;
  padding: 18px;
}

.section-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: end;
  gap: 8px;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.7rem;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.legend-dot {
  width: 14px;
  height: 14px;
  border-radius: 999px;
  background: var(--idle);
  box-shadow: inset 0 0 0 1px rgb(21 23 24 / 8%);
}

.legend-dot.level-1,
.day-bubble.level-1 {
  background: var(--level-1);
}

.legend-dot.level-2,
.day-bubble.level-2 {
  background: var(--level-2);
}

.legend-dot.level-3,
.day-bubble.level-3 {
  background: var(--level-3);
}

.legend-dot.level-4,
.day-bubble.level-4 {
  background: var(--level-4);
}

.legend-dot.level-5,
.day-bubble.level-5 {
  background: var(--level-5);
}

.heatmap-shell {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  gap: 10px;
  width: 100%;
  min-width: 0;
  overflow-x: auto;
  overscroll-behavior-inline: contain;
  padding-bottom: 6px;
}

.weekday-labels {
  display: grid;
  grid-template-rows: repeat(7, 22px);
  gap: 5px;
  padding-top: 24px;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.68rem;
  text-align: right;
}

.weekday-labels span {
  line-height: 22px;
}

.calendar-frame {
  width: max-content;
  min-width: calc(var(--week-count, 53) * 27px);
}

.month-labels {
  display: grid;
  grid-template-columns: repeat(var(--week-count, 53), 22px);
  column-gap: 5px;
  min-height: 18px;
  margin-bottom: 6px;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.68rem;
}

.month-label {
  white-space: nowrap;
}

.heatmap-grid {
  display: grid;
  grid-template-columns: repeat(var(--week-count, 53), 22px);
  grid-template-rows: repeat(7, 22px);
  gap: 5px;
}

.day-cell {
  display: grid;
  width: 22px;
  height: 22px;
  place-items: center;
  border: 0;
  border-radius: 999px;
  background: transparent;
  cursor: pointer;
  padding: 0;
}

.day-bubble {
  display: block;
  width: var(--bubble-size, 8px);
  height: var(--bubble-size, 8px);
  border-radius: 999px;
  background: var(--idle);
  box-shadow: inset 0 0 0 1px rgb(21 23 24 / 9%);
  transition:
    width 160ms ease,
    height 160ms ease,
    box-shadow 160ms ease,
    transform 160ms ease;
}

.day-cell:hover .day-bubble,
.day-cell:focus-visible .day-bubble,
.day-cell.is-selected .day-bubble {
  box-shadow:
    inset 0 0 0 1px rgb(21 23 24 / 11%),
    0 0 0 4px rgb(49 91 234 / 12%);
  transform: scale(1.08);
}

.day-cell.is-future {
  cursor: default;
  opacity: 0.38;
}

.day-cell.is-today .day-bubble {
  box-shadow:
    inset 0 0 0 1px rgb(21 23 24 / 12%),
    0 0 0 2px var(--ink);
}

.day-bubble.level-4,
.day-bubble.level-5 {
  box-shadow:
    inset 0 0 0 1px rgb(21 23 24 / 10%),
    0 4px 12px rgb(226 67 114 / 26%);
}

.detail-panel {
  padding: 18px;
  position: sticky;
  top: 16px;
}

.detail-panel h2 {
  font-size: 1.35rem;
  line-height: 1.15;
}

.detail-date {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.detail-cost {
  display: block;
  margin: 18px 0 8px;
  font-size: 3rem;
  font-weight: 800;
  line-height: 0.95;
}

.metric-list,
.agent-list {
  display: grid;
  gap: 8px;
  margin-top: 18px;
}

.metric-row,
.agent-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  border-top: 1px solid var(--soft);
  padding-top: 8px;
}

.metric-row span,
.agent-row span,
.agent-row small {
  color: var(--muted);
}

.metric-row span,
.agent-row span {
  min-width: 0;
  overflow-wrap: anywhere;
}

.metric-row strong,
.agent-row strong {
  white-space: nowrap;
}

.agent-section {
  margin-top: 24px;
}

.agent-section h3 {
  margin-bottom: 4px;
  font-size: 0.86rem;
  text-transform: uppercase;
  letter-spacing: 0;
  font-family: var(--mono);
}

.muted {
  color: var(--muted);
}

.tooltip {
  position: fixed;
  z-index: 20;
  display: none;
  width: min(280px, calc(100vw - 24px));
  border: 1px solid rgb(21 23 24 / 12%);
  border-radius: 8px;
  background: rgb(255 255 255 / 96%);
  box-shadow: 0 14px 38px rgb(20 25 31 / 18%);
  padding: 12px;
  pointer-events: none;
}

.tooltip.is-visible {
  display: block;
}

.tooltip strong {
  display: block;
  margin-bottom: 3px;
}

.tooltip p {
  margin: 0;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.4;
}

.error-state {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 18px;
  box-shadow: var(--shadow);
}

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

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

  .detail-panel {
    position: static;
  }
}

@media (max-width: 720px) {
  .shell {
    width: min(100% - 20px, 1440px);
    padding-top: 18px;
  }

  .topbar,
  .section-heading {
    align-items: stretch;
    flex-direction: column;
  }

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

  .summary-card {
    min-height: 96px;
  }

  .heatmap-section {
    padding: 14px;
  }

  .legend {
    justify-content: start;
  }

  .heatmap-shell {
    grid-template-columns: 34px minmax(0, 1fr);
  }

  .weekday-labels {
    font-size: 0.62rem;
  }

  .detail-cost {
    font-size: 2.35rem;
  }
}

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

  .legend {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    justify-content: stretch;
  }

  .legend-item {
    min-width: 0;
    white-space: normal;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.001ms !important;
    animation-duration: 0.001ms !important;
  }
}
