:root {
  --bg: #f6f8fa;
  --surface: #ffffff;
  --surface-soft: #eef2f5;
  --border: #d8dee4;
  --border-strong: #b7c0ca;
  --text: #1f2328;
  --muted: #59636e;
  --faint: #8c959f;
  --accent: #0969da;
  --green-0: #ebedf0;
  --green-1: #dbeee2;
  --green-2: #9be9a8;
  --green-3: #40c463;
  --green-4: #30a14e;
  --green-5: #216e39;
  --warning: #bf8700;
  --danger: #cf222e;
  --purple: #8250df;
  --shadow: 0 16px 40px rgba(31, 35, 40, 0.08);
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
}

body {
  margin: 0;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  font-size: 15px;
  line-height: 1.45;
}

button,
input,
table {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  width: min(1440px, calc(100% - 40px));
  margin: 0 auto;
  padding: 28px 0 18px;
}

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

h1,
h2,
p {
  margin: 0;
}

h1 {
  max-width: 860px;
  font-size: 30px;
  line-height: 1.12;
  letter-spacing: 0;
}

.source-badge {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  margin-top: 10px;
  padding: 0 9px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.source-badge.real {
  border-color: #8cbdff;
  background: #eef6ff;
  color: #0757b8;
}

.source-badge.imported {
  border-color: #9be9a8;
  background: #eefbef;
  color: #216e39;
}

h2 {
  font-size: 16px;
  line-height: 1.2;
  letter-spacing: 0;
}

.panel-header p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.header-actions,
.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.supabase-panel,
.filter-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.supabase-fields,
.supabase-actions,
.filter-row {
  flex-wrap: wrap;
}

.supabase-fields {
  display: grid;
  grid-template-columns: minmax(180px, 1.1fr) minmax(180px, 1.1fr) minmax(160px, 0.9fr) minmax(140px, 0.8fr);
  gap: 8px;
  flex: 1 1 auto;
}

.supabase-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.supabase-fields input,
.filter-row select {
  min-height: 36px;
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface);
  color: var(--text);
}

.supabase-fields input {
  padding: 0 10px;
}

.filter-row {
  justify-content: flex-start;
}

.filter-row label {
  display: grid;
  gap: 4px;
  min-width: 150px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.filter-row select {
  padding: 0 8px;
  font-size: 14px;
  font-weight: 600;
}

.file-input {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  clip-path: inset(50%);
}

.button,
.segmented button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface);
  color: var(--text);
  font-weight: 650;
  text-decoration: none;
  white-space: nowrap;
}

.button {
  padding: 0 13px;
}

.button.secondary {
  border-color: #8cbdff;
  color: #0757b8;
}

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

.button:hover,
.segmented button:hover {
  border-color: var(--border-strong);
  background: #f9fbfd;
}

.dashboard-shell {
  width: min(1440px, calc(100% - 40px));
  margin: 0 auto;
  padding-bottom: 36px;
}

.toolbar {
  justify-content: space-between;
  padding: 12px 0 16px;
}

.segmented {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #eef2f5;
}

.segmented button {
  min-width: 54px;
  border-color: transparent;
  background: transparent;
  color: var(--muted);
  box-shadow: none;
}

.segmented button.active {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
  box-shadow: 0 1px 2px rgba(31, 35, 40, 0.07);
}

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

.stat-card,
.panel {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.stat-card {
  min-height: 118px;
  padding: 16px;
}

.stat-card span,
.stat-card small {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.stat-card strong {
  display: block;
  margin: 8px 0 4px;
  font-size: 28px;
  line-height: 1;
  letter-spacing: 0;
  overflow-wrap: anywhere;
}

.panel {
  padding: 18px;
  min-width: 0;
}

.panel.wide {
  margin-bottom: 14px;
}

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

.panel-header.compact {
  margin-bottom: 10px;
}

.heatmap-scroll {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 4px 0 2px;
}

.heatmap-layout {
  display: grid;
  grid-template-columns: 34px max-content;
  grid-template-rows: 18px max-content;
  column-gap: 8px;
  row-gap: 6px;
  min-width: max-content;
}

.corner-spacer {
  grid-column: 1;
  grid-row: 1;
}

.month-row {
  grid-column: 2;
  grid-row: 1;
  display: grid;
  grid-auto-columns: 13px;
  gap: 4px;
  color: var(--muted);
  font-size: 11px;
}

.month-row span {
  min-width: 34px;
  white-space: nowrap;
}

.weekday-labels {
  grid-column: 1;
  grid-row: 2;
  display: grid;
  grid-template-rows: repeat(7, 13px);
  gap: 4px;
  color: var(--muted);
  font-size: 11px;
  line-height: 13px;
}

.heatmap-grid {
  grid-column: 2;
  grid-row: 2;
  display: grid;
  grid-template-rows: repeat(7, 13px);
  grid-auto-flow: column;
  grid-auto-columns: 13px;
  gap: 4px;
}

.heat-cell,
.heat-legend i {
  border: 1px solid rgba(31, 35, 40, 0.08);
  border-radius: 3px;
}

.heat-cell {
  width: 13px;
  height: 13px;
  padding: 0;
  background: var(--green-0);
}

.heat-cell.outside {
  opacity: 0.36;
}

.heat-cell.selected {
  outline: 2px solid #1f2328;
  outline-offset: 1px;
}

.heat-tooltip {
  position: fixed;
  z-index: 20;
  width: min(280px, calc(100vw - 24px));
  padding: 12px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 18px 42px rgba(31, 35, 40, 0.18);
  color: var(--text);
  font-size: 12px;
  pointer-events: none;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 120ms ease, transform 120ms ease;
}

.heat-tooltip.visible {
  opacity: 1;
  transform: translateY(0);
}

.heat-tooltip-title {
  margin-bottom: 8px;
  font-size: 13px;
  font-weight: 750;
}

.heat-tooltip-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 5px 12px;
}

.heat-tooltip-grid dt {
  color: var(--muted);
}

.heat-tooltip-grid dd {
  margin: 0;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  text-align: right;
}

.heat-tooltip-sub {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
  color: var(--muted);
  line-height: 1.4;
}

.level-0 {
  background: var(--green-0);
}

.level-1 {
  background: var(--green-1);
}

.level-2 {
  background: var(--green-2);
}

.level-3 {
  background: var(--green-3);
}

.level-4 {
  background: var(--green-4);
}

.level-5 {
  background: var(--green-5);
}

.heat-legend {
  display: flex;
  align-items: center;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.heat-legend i {
  width: 13px;
  height: 13px;
  display: inline-block;
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.75fr) minmax(340px, 0.8fr);
  gap: 14px;
  margin-bottom: 14px;
}

.bottom-grid {
  grid-template-columns: minmax(0, 1.35fr) minmax(360px, 1fr);
  margin-bottom: 0;
}

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

#log-chart {
  display: block;
  width: 100%;
  height: 342px;
}

.axis-badge {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 10px;
  border: 1px solid #8cbdff;
  border-radius: 999px;
  color: #0757b8;
  background: #eef6ff;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.axis-grid {
  stroke: #d8dee4;
  stroke-dasharray: 3 5;
}

.axis-line {
  stroke: #8c959f;
}

.axis-label {
  fill: var(--muted);
  font-size: 11px;
}

.daily-bar {
  stroke: #8c959f;
  stroke-width: 1;
  opacity: 0.32;
}

.token-line {
  fill: none;
  stroke: var(--accent);
  stroke-width: 2.4;
}

.moving-line {
  fill: none;
  stroke: var(--warning);
  stroke-width: 2;
  stroke-dasharray: 6 5;
}

.top-dot {
  fill: var(--surface);
  stroke: var(--danger);
  stroke-width: 2;
}

.detail-body {
  display: grid;
  gap: 14px;
}

.detail-kicker {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.detail-title {
  font-size: 20px;
  line-height: 1.2;
}

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

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 9px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: #f6f8fa;
  color: var(--text);
  font-size: 12px;
  font-weight: 700;
}

.tool-stack {
  display: flex;
  width: 100%;
  height: 12px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--surface-soft);
}

.tool-stack span {
  display: block;
  min-width: 2px;
}

.tool-codex {
  background: #238636;
}

.tool-claude {
  background: #bc4c00;
}

.tool-chatgpt,
.tool-gemini {
  background: #0969da;
}

.tool-chatgpt {
  background: #10a37f;
}

.tool-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  color: var(--muted);
  font-size: 12px;
}

.tool-legend span::before {
  content: "";
  display: inline-block;
  width: 9px;
  height: 9px;
  margin-right: 5px;
  border-radius: 50%;
  vertical-align: -1px;
}

.tool-legend .codex::before {
  background: #238636;
}

.tool-legend .claude::before {
  background: #bc4c00;
}

.tool-legend .chatgpt::before,
.tool-legend .gemini::before {
  background: #0969da;
}

.tool-legend .chatgpt::before {
  background: #10a37f;
}

.table-wrap {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

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

th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
  text-transform: uppercase;
}

td {
  font-size: 14px;
}

tbody tr {
  cursor: pointer;
}

tbody tr:hover {
  background: #f6f8fa;
}

tbody tr.selected-row {
  background: #eef6ff;
}

.number-cell {
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.technical-table {
  min-width: 1040px;
}

.technical-table th,
.technical-table td {
  white-space: nowrap;
}

.technical-table .date-cell {
  min-width: 112px;
}

.tool-detail {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  white-space: normal;
}

.driver-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-width: 160px;
  color: var(--text);
  font-weight: 650;
}

.driver-dot {
  width: 9px;
  height: 9px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--accent);
}

.result-cell {
  min-width: 220px;
  color: var(--muted);
}

.drivers-list {
  display: grid;
  gap: 13px;
}

.driver-row {
  display: grid;
  grid-template-columns: minmax(150px, 0.9fr) minmax(180px, 1.2fr) minmax(92px, auto);
  gap: 12px;
  align-items: center;
}

.driver-meta {
  display: grid;
  gap: 2px;
}

.driver-name {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 750;
}

.driver-sub {
  color: var(--muted);
  font-size: 12px;
}

.driver-bar {
  position: relative;
  height: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--surface-soft);
}

.driver-bar span {
  display: block;
  height: 100%;
  width: 0;
  border-radius: inherit;
}

.driver-value {
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  text-align: right;
  white-space: nowrap;
}

.empty-state {
  padding: 18px;
  border: 1px dashed var(--border);
  border-radius: 8px;
  color: var(--muted);
  background: #f6f8fa;
}

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

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

@media (max-width: 720px) {
  .app-header,
  .dashboard-shell {
    width: min(1440px, calc(100% - 24px));
  }

  .app-header {
    align-items: flex-start;
    flex-direction: column;
  }

  h1 {
    font-size: 24px;
  }

  .toolbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .supabase-panel {
    align-items: stretch;
    flex-direction: column;
  }

  .supabase-fields {
    grid-template-columns: 1fr;
  }

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

  .panel {
    padding: 14px;
  }

  .panel-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .heat-legend {
    white-space: normal;
  }

  .driver-row {
    grid-template-columns: 1fr;
  }

  .driver-value {
    text-align: left;
  }

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

  #log-chart {
    height: 300px;
  }

  table {
    min-width: 760px;
  }
}
