:root {
  color-scheme: light;
  --bg: #f2f5f1;
  --surface: #ffffff;
  --surface-muted: #e8eee9;
  --ink: #17211c;
  --muted: #66736b;
  --line: #d5ddd7;
  --green: #176b55;
  --green-dark: #0d4d3d;
  --green-soft: #dcece5;
  --coral: #d75d4f;
  --amber: #d39a26;
  --blue: #3f73a8;
  --violet: #7866a8;
  --danger: #a53d35;
  --shadow: 0 10px 24px rgba(24, 42, 33, 0.07);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
    "Segoe UI", sans-serif;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
}

button,
input,
select {
  font: inherit;
}

button,
select,
input[type="month"] {
  min-height: 40px;
}

button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 3px solid rgba(63, 115, 168, 0.32);
  outline-offset: 2px;
}

.hidden {
  display: none !important;
}

.state-screen {
  min-height: 100vh;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 12px;
  padding: calc(32px + var(--safe-top)) 24px calc(32px + var(--safe-bottom));
  text-align: center;
}

.state-mark,
.brand-mark {
  display: grid;
  place-items: center;
  background: var(--green);
  color: #ffffff;
  border-radius: 8px;
  font-weight: 800;
}

.state-mark {
  width: 64px;
  height: 64px;
  font-size: 22px;
  box-shadow: var(--shadow);
}

.state-screen h1 {
  margin: 6px 0 0;
  max-width: 440px;
  font-size: 28px;
  line-height: 1.15;
  letter-spacing: 0;
}

.state-screen p {
  margin: 0;
  max-width: 440px;
  color: var(--muted);
  line-height: 1.5;
}

.app-shell {
  min-height: 100vh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  min-height: 76px;
  padding: calc(12px + var(--safe-top)) max(24px, calc((100vw - 1440px) / 2))
    12px;
  background: rgba(255, 255, 255, 0.96);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  font-size: 15px;
}

.brand-lockup h1 {
  margin: 0;
  font-size: 18px;
  line-height: 1.2;
  letter-spacing: 0;
}

.brand-lockup p,
.updated-label {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.header-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.command-button {
  border: 1px solid var(--green);
  border-radius: 6px;
  padding: 8px 14px;
  background: var(--green);
  color: #ffffff;
  font-weight: 700;
  cursor: pointer;
}

.command-button:hover {
  background: var(--green-dark);
}

.command-button.secondary {
  background: var(--surface);
  color: var(--green-dark);
}

.command-button.quiet {
  border-color: transparent;
  background: transparent;
  color: var(--muted);
}

main {
  padding-bottom: calc(40px + var(--safe-bottom));
}

.filter-band {
  border-bottom: 1px solid var(--line);
  background: var(--surface-muted);
}

.filter-grid,
.summary-band,
.analytics-grid,
.detail-grid,
.table-band {
  width: min(100% - 48px, 1392px);
  margin-inline: auto;
}

.filter-grid {
  display: grid;
  grid-template-columns: 1fr 1.15fr 1.2fr 1fr 1.2fr 1.2fr;
  gap: 12px;
  padding-block: 16px;
}

.filter-grid label,
.segmented-field {
  min-width: 0;
}

.filter-grid label > span,
.segmented-field legend {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.segmented-field {
  margin: 0;
  padding: 0;
  border: 0;
}

select,
input[type="month"] {
  width: 100%;
  border: 1px solid #c8d2cb;
  border-radius: 6px;
  padding: 8px 10px;
  background: var(--surface);
  color: var(--ink);
}

select:disabled {
  opacity: 0.55;
}

.segmented-control {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  overflow: hidden;
  min-height: 40px;
  border: 1px solid #c8d2cb;
  border-radius: 6px;
  background: var(--surface);
}

.segmented-control input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.segmented-control label {
  display: grid;
  place-items: center;
  margin: 0;
  padding: 8px 10px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 750;
  cursor: pointer;
}

.segmented-control input:checked + label {
  background: var(--green);
  color: #ffffff;
}

.segmented-control input:focus-visible + label {
  box-shadow: inset 0 0 0 3px rgba(63, 115, 168, 0.45);
}

.segmented-control.compact {
  min-height: 34px;
}

.segmented-control.compact label {
  padding: 6px 12px;
  font-size: 12px;
}

.error-banner {
  width: min(100% - 48px, 1392px);
  margin: 16px auto 0;
  border-left: 4px solid var(--danger);
  padding: 12px 14px;
  background: #f8e5e2;
  color: #722820;
  font-weight: 650;
}

.summary-band {
  padding-block: 28px 24px;
}

.section-heading,
.panel-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
}

.section-heading {
  margin-bottom: 16px;
}

.section-heading h2,
.panel-heading h2 {
  margin: 2px 0 0;
  letter-spacing: 0;
}

.section-heading h2 {
  font-size: 24px;
}

.panel-heading h2 {
  font-size: 17px;
}

.eyebrow {
  margin: 0;
  color: var(--green);
  font-size: 11px;
  font-weight: 850;
  text-transform: uppercase;
}

.section-meta,
.panel-total {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

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

.metric-card {
  min-width: 0;
  min-height: 130px;
  border: 1px solid var(--line);
  border-top: 4px solid var(--blue);
  border-radius: 8px;
  padding: 18px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.metric-card.primary-metric {
  border-top-color: var(--green);
}

.metric-card.receipt-metric {
  border-top-color: var(--coral);
}

.metric-card p,
.metric-card span {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

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

.analytics-grid,
.detail-grid {
  display: grid;
  gap: 16px;
  margin-bottom: 16px;
}

.analytics-grid {
  grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.3fr);
}

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

.chart-panel,
.list-panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 20px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.donut-layout {
  display: grid;
  grid-template-columns: minmax(180px, 0.8fr) minmax(190px, 1fr);
  align-items: center;
  gap: 18px;
  min-height: 280px;
}

.canvas-wrap {
  position: relative;
  min-width: 0;
}

.donut-canvas-wrap {
  width: min(100%, 250px);
  aspect-ratio: 1;
  margin-inline: auto;
}

.trend-canvas-wrap {
  width: 100%;
  height: 300px;
  margin-top: 18px;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.donut-total {
  position: absolute;
  inset: 50% auto auto 50%;
  width: 54%;
  transform: translate(-50%, -50%);
  text-align: center;
  pointer-events: none;
}

.donut-total strong {
  display: block;
  overflow-wrap: anywhere;
  font-size: 18px;
  line-height: 1.2;
}

.donut-total span {
  color: var(--muted);
  font-size: 11px;
}

.chart-legend {
  display: grid;
  gap: 9px;
  max-height: 250px;
  overflow: auto;
  padding-right: 4px;
}

.legend-row {
  display: grid;
  grid-template-columns: 10px minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  font-size: 12px;
}

.legend-swatch {
  width: 10px;
  height: 10px;
  border-radius: 2px;
}

.legend-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.legend-value {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.ranked-list,
.budget-list {
  display: grid;
  gap: 15px;
  margin-top: 20px;
}

.ranked-row,
.budget-row {
  display: grid;
  gap: 7px;
}

.ranked-copy,
.budget-copy {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  font-size: 13px;
}

.ranked-copy strong,
.budget-copy strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ranked-copy span,
.budget-copy span {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.bar-track {
  height: 8px;
  overflow: hidden;
  border-radius: 4px;
  background: var(--surface-muted);
}

.bar-fill {
  height: 100%;
  border-radius: inherit;
  background: var(--blue);
}

.budget-row.warning .bar-fill {
  background: var(--amber);
}

.budget-row.over .bar-fill {
  background: var(--coral);
}

.table-band {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 20px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.table-scroll {
  overflow-x: auto;
  margin-top: 16px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

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

th {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  white-space: nowrap;
}

td {
  max-width: 260px;
}

tbody tr:last-child td {
  border-bottom: 0;
}

.description-cell strong,
.description-cell span {
  display: block;
}

.description-cell strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.description-cell span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 11px;
  text-transform: capitalize;
}

.amount-column {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.empty-state {
  display: grid;
  place-items: center;
  min-height: 150px;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

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

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

@media (max-width: 760px) {
  .topbar {
    position: static;
    align-items: flex-start;
    padding-inline: 16px;
  }

  .brand-lockup h1 {
    font-size: 16px;
  }

  .updated-label,
  .command-button.quiet {
    display: none;
  }

  .header-actions {
    flex-shrink: 0;
  }

  .filter-grid,
  .summary-band,
  .analytics-grid,
  .detail-grid,
  .table-band,
  .error-banner {
    width: min(100% - 24px, 1392px);
  }

  .filter-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

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

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

  .metric-card {
    min-height: 116px;
    padding: 14px;
  }

  .donut-layout {
    grid-template-columns: 1fr;
  }

  .chart-legend {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    max-height: none;
  }

  .trend-canvas-wrap {
    height: 250px;
  }
}

@media (max-width: 520px) {
  .topbar {
    gap: 8px;
  }

  .brand-mark {
    width: 36px;
    height: 36px;
  }

  .brand-lockup p {
    display: none;
  }

  .command-button {
    min-height: 36px;
    padding: 7px 10px;
    font-size: 12px;
  }

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

  .summary-band {
    padding-top: 20px;
  }

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

  .metric-grid {
    gap: 8px;
  }

  .metric-card strong {
    font-size: 20px;
  }

  .chart-panel,
  .list-panel,
  .table-band {
    padding: 16px;
  }

  .panel-heading {
    align-items: flex-start;
  }

  .chart-legend {
    grid-template-columns: 1fr;
  }

  .table-scroll {
    overflow: visible;
  }

  table,
  tbody {
    display: block;
  }

  thead {
    display: none;
  }

  tbody {
    display: grid;
    gap: 8px;
    margin-top: 16px;
  }

  tbody tr {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 5px 12px;
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 12px;
  }

  tbody td {
    display: block;
    max-width: none;
    padding: 0;
    border: 0;
  }

  tbody td:nth-child(1) {
    color: var(--muted);
    font-size: 11px;
  }

  tbody td:nth-child(2) {
    grid-column: 1;
    min-width: 0;
  }

  tbody td:nth-child(3),
  tbody td:nth-child(4),
  tbody td:nth-child(5) {
    display: none;
  }

  tbody td:nth-child(6) {
    grid-column: 2;
    grid-row: 1 / span 2;
    align-self: center;
  }
}

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

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #121815;
    --surface: #1b2420;
    --surface-muted: #222e28;
    --ink: #edf4ef;
    --muted: #a6b5ac;
    --line: #344139;
    --green: #2d9275;
    --green-dark: #55b99a;
    --green-soft: #244438;
    --shadow: none;
  }

  .topbar {
    background: rgba(27, 36, 32, 0.96);
  }

  .command-button.secondary {
    color: var(--ink);
  }

  .error-banner {
    background: #472824;
    color: #ffd7d1;
  }
}
