body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  margin: 0;
  background: #f7f7f5;
  color: #1f2937;
}

a {
  color: #0f766e;
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.site-header,
.page-shell {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.25rem;
}

.site-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 1rem;
  border-bottom: 1px solid #e5e7eb;
  background: white;
}

.eyebrow {
  margin: 0 0 0.25rem;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #6b7280;
}

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

.site-header-actions {
  display: grid;
  justify-items: end;
  gap: 0.5rem;
}

.site-nav {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}

.site-user {
  margin: 0;
  font-size: 0.9rem;
  color: #6b7280;
}

.site-user strong {
  color: #111827;
}

.flash {
  max-width: 1200px;
  margin: 1rem auto 0;
  padding: 0.75rem 1rem;
  border-radius: 0.5rem;
}

.flash-notice {
  background: #ecfdf5;
  color: #065f46;
}

.flash-alert {
  background: #fef2f2;
  color: #991b1b;
}

.panel,
.card,
.table-wrap {
  background: white;
  border: 1px solid #e5e7eb;
  border-radius: 0.75rem;
  padding: 1rem;
  margin-bottom: 1rem;
}

.dashboard-hero h2 {
  margin-bottom: 0.5rem;
}

.dashboard-hero-layout {
  align-items: start;
}

.dashboard-hero-title {
  margin-top: 0.25rem;
}

.dashboard-hero-actions {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.dashboard-period-form {
  margin: 0 0 1rem;
}

.dashboard-hero-selects {
  gap: 0.75rem;
}

.dashboard-hero-notes {
  margin: 0.75rem 0 0;
  padding-left: 1.2rem;
  color: #6b7280;
}

.dashboard-hero-notes li + li {
  margin-top: 0.25rem;
}

.grid {
  display: grid;
  gap: 1rem;
}

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

.kpi {
  font-size: 1.75rem;
  font-weight: 700;
  margin: 0.25rem 0 0;
}

.metric-breakdown {
  list-style: none;
  padding: 0;
  margin: 0.75rem 0 0;
}

.metric-breakdown li {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 0.75rem;
  align-items: center;
  padding: 0.35rem 0;
  border-top: 1px solid #f3f4f6;
}

.metric-breakdown li:first-child {
  border-top: 0;
  padding-top: 0;
}

.metric-link {
  font-weight: 600;
}

.metric-secondary-link {
  justify-self: end;
  font-size: 0.85rem;
  color: #6b7280;
}

.metric-meta {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-top: 0.5rem;
}

.dashboard-list {
  margin: 0;
  padding-left: 1.2rem;
}

.dashboard-list li + li {
  margin-top: 0.6rem;
}

.derived-metric .metric-explanation {
  margin-bottom: 0.5rem;
}

.metric-details {
  margin-top: 0.75rem;
}

.metric-details summary {
  cursor: pointer;
  font-weight: 600;
}

.metric-subsection {
  margin-top: 0.75rem;
}

.metric-subheading {
  margin-bottom: 0.4rem;
  font-size: 0.85rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #6b7280;
}

.metric-lines {
  list-style: none;
  padding: 0;
  margin: 0;
}

.metric-lines li {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.75rem;
  padding: 0.35rem 0;
  border-top: 1px solid #f3f4f6;
}

.metric-line-label {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  align-items: center;
}

.metric-row-trend-popover {
  position: relative;
  display: inline-block;
}

.metric-row-trend-popover > summary {
  list-style: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
}

.metric-row-trend-popover > summary::-webkit-details-marker {
  display: none;
}

.metric-row-trend-summary-hint {
  font-size: 0.65rem;
  font-weight: 700;
  line-height: 1;
  padding: 0.1rem 0.2rem;
  border-radius: 999px;
}

.trend-hint.good {
  color: #065f46;
}

.trend-hint.bad {
  color: #991b1b;
}

.trend-hint.neutral {
  color: #6b7280;
}

.metric-row-trend-card {
  position: absolute;
  z-index: 10;
  top: 1.75rem;
  left: 0;
  background: white;
  border: 1px solid #e5e7eb;
  border-radius: 0.75rem;
  padding: 0.55rem 0.65rem;
  box-shadow: 0 12px 28px rgba(15, 23, 42, 0.12);
  white-space: nowrap;
  display: grid;
  gap: 0.35rem;
}

.metric-row-trend-title {
  margin: 0;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #6b7280;
}

.metric-row-trend-card .trend-badge {
  font-size: 0.68rem;
  padding: 0.15rem 0.4rem;
}

.metric-lines li.emphasis {
  font-weight: 700;
}

.metric-evidence {
  margin-bottom: 0;
}

.chart {
  display: grid;
  gap: 0.85rem;
}

.chart-row {
  display: grid;
  grid-template-columns: minmax(0, 12rem) minmax(0, 1fr) auto;
  gap: 0.75rem;
  align-items: center;
}

.chart-row-highlight {
  padding: 0.35rem 0.5rem;
  background: #f9fafb;
  border-radius: 0.5rem;
}

.chart-row-label {
  font-weight: 600;
}

.chart-row-value {
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.chart-note {
  font-size: 0.85rem;
  color: #6b7280;
}

.dashboard-waterfall {
  display: grid;
  gap: 0.5rem;
}

.dashboard-waterfall-step {
  display: grid;
  grid-template-columns: minmax(0, 12rem) minmax(0, 1fr) auto;
  gap: 0.75rem;
  align-items: center;
}

.dashboard-waterfall-label {
  display: grid;
  gap: 0.15rem;
}

.dashboard-waterfall-value {
  font-variant-numeric: tabular-nums;
  text-align: right;
  font-weight: 700;
}

.dashboard-waterfall-arrow {
  padding-left: 0.5rem;
  color: #9ca3af;
  font-size: 1rem;
  line-height: 1;
}

.chart-track {
  position: relative;
  height: 1rem;
  background: #eef2f7;
  border-radius: 999px;
  overflow: hidden;
}

.chart-track-reference {
  overflow: visible;
}

.chart-marker {
  position: absolute;
  top: -0.25rem;
  bottom: -0.25rem;
  width: 2px;
  background: #111827;
  opacity: 0.45;
  transform: translateX(-1px);
}

.chart-bar,
.chart-segment {
  display: block;
  height: 100%;
}

.chart-bar {
  border-radius: 999px;
}

.chart-bar.income,
.chart-segment.income,
.chart-bar.headroom {
  background: #0f766e;
}

.chart-bar.cost,
.chart-bar.running-cost,
.chart-segment.running_cost {
  background: #2563eb;
}

.chart-bar.positive,
.chart-segment.irregular {
  background: #16a34a;
}

.chart-bar.negative {
  background: #dc2626;
}

.chart-bar.holiday,
.chart-segment.holiday {
  background: #f59e0b;
}

.chart-bar.big_purchase,
.chart-segment.big_purchase {
  background: #7c3aed;
}

.chart-bar.exceptional,
.chart-segment.exceptional {
  background: #ef4444;
}

.chart-stack {
  display: flex;
  height: 1rem;
  border-radius: 999px;
  overflow: hidden;
  background: #eef2f7;
}

.chart-stack-inline {
  background: transparent;
}

.chart-legend {
  display: grid;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.chart-legend-item {
  display: grid;
  grid-template-columns: 1rem 1fr auto;
  gap: 0.5rem;
  align-items: center;
}

.chart-swatch {
  width: 1rem;
  height: 1rem;
  border-radius: 999px;
}

.waterfall {
  display: grid;
  gap: 0.85rem;
}

.waterfall-row {
  display: grid;
  grid-template-columns: minmax(10rem, 1.2fr) minmax(0, 2fr) auto;
  gap: 0.75rem;
  align-items: center;
}

.waterfall-label {
  display: grid;
  gap: 0.2rem;
}

.waterfall-track {
  height: 0.9rem;
  background: #eef2f7;
  border-radius: 999px;
  overflow: hidden;
}

.waterfall-bar {
  display: block;
  height: 100%;
  border-radius: 999px;
}

.waterfall-bar.positive,
.waterfall-bar.running_cost,
.waterfall-bar.stable {
  background: #0f766e;
}

.dashboard-line-chart {
  position: relative;
  height: 15rem;
}

.dashboard-line-chart canvas {
  width: 100% !important;
  height: 100% !important;
}

.dashboard-monthly-figures {
  margin-top: 0.75rem;
}

.dashboard-monthly-figures summary {
  cursor: pointer;
  font-weight: 600;
}

.dashboard-monthly-figures .table-wrap {
  margin-top: 0.75rem;
  margin-bottom: 0;
}

.waterfall-bar.negative,
.waterfall-bar.watch,
.waterfall-bar.temporary {
  background: #dc2626;
}

.waterfall-bar.neutral,
.waterfall-bar.structural {
  background: #2563eb;
}

.waterfall-value {
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.mini-history {
  display: flex;
  align-items: end;
  gap: 0.4rem;
  height: 4rem;
  margin: 0.75rem 0 0.35rem;
}

.mini-history-item {
  flex: 1;
  display: grid;
  gap: 0.2rem;
  justify-items: center;
  align-items: end;
  min-width: 0.45rem;
}

.mini-history-bar {
  width: 100%;
  background: #cbd5e1;
  border-radius: 0.4rem 0.4rem 0 0;
  min-height: 0.2rem;
}

.mini-history-bar.current {
  background: #0f766e;
}

.mini-history-label {
  font-size: 0.72rem;
  color: #6b7280;
}

.chartjs-chart {
  position: relative;
  height: 13rem;
  margin-top: 0.75rem;
}

.chartjs-chart canvas {
  width: 100% !important;
  height: 100% !important;
}

.chartjs-sparkline {
  position: relative;
  width: 9rem;
  height: 2.25rem;
}

.chartjs-sparkline canvas {
  width: 100% !important;
  height: 100% !important;
}

.category-breakdown-table td,
.category-breakdown-table th {
  vertical-align: middle;
}

.category-breakdown-table td.sparkline-cell {
  width: 9rem;
}

.table-sort-button {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  font-weight: 700;
  text-transform: inherit;
  letter-spacing: inherit;
  cursor: pointer;
}

.typical-value-popover {
  display: inline-block;
  position: relative;
}

.typical-value-trigger {
  display: inline-flex;
  list-style: none;
  cursor: pointer;
  color: #0f766e;
  font-weight: 700;
  text-decoration: underline dotted;
  text-underline-offset: 0.15em;
}

.typical-value-trigger::-webkit-details-marker {
  display: none;
}

.typical-value-popover-panel {
  position: absolute;
  left: 0;
  top: calc(100% + 0.4rem);
  z-index: 10;
  min-width: 12rem;
  max-width: 16rem;
  padding: 0.75rem;
  border: 1px solid #d1d5db;
  border-radius: 0.75rem;
  background: white;
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.12);
}

.typical-value-popover:not([open]) .typical-value-popover-panel {
  display: none;
}

.typical-value-popover-title {
  margin-bottom: 0.5rem;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #6b7280;
}

.typical-value-popover-list {
  display: grid;
  gap: 0.35rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.typical-value-popover-list li {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  font-variant-numeric: tabular-nums;
}

.trend-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.2rem 0.5rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1;
}

.trend-badge.good {
  background: #ecfdf5;
  color: #065f46;
}

.trend-badge.bad {
  background: #fef2f2;
  color: #991b1b;
}

.trend-badge.neutral {
  background: #f3f4f6;
  color: #4b5563;
}

.muted { color: #6b7280; }

label { display: block; font-weight: 600; margin-bottom: 0.5rem; }
input[type="text"],
input[type="number"],
input[type="file"],
select,
textarea {
  width: 100%;
  box-sizing: border-box;
  padding: 0.65rem 0.75rem;
  border: 1px solid #d1d5db;
  border-radius: 0.5rem;
  background: white;
  margin-bottom: 1rem;
}
input[type="file"] { display: block; }
button, .button, input[type="submit"] {
  display: inline-block;
  padding: 0.65rem 1rem;
  border: 0;
  border-radius: 0.5rem;
  background: #0f766e;
  color: white;
  font-weight: 600;
  cursor: pointer;
}

.session-panel {
  max-width: 28rem;
}

.table-wrap { overflow-x: auto; }
table {
  width: 100%;
  border-collapse: collapse;
}
th, td {
  text-align: left;
  vertical-align: top;
  padding: 0.65rem 0.5rem;
  border-bottom: 1px solid #e5e7eb;
  font-size: 0.95rem;
}
th { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.05em; color: #6b7280; }
pre {
  background: #0f172a;
  color: #e2e8f0;
  padding: 1rem;
  border-radius: 0.75rem;
  overflow-x: auto;
}

@media (max-width: 900px) {
  .grid.cols-2, .grid.cols-3, .grid.cols-4 { grid-template-columns: 1fr; }
  .site-header { align-items: start; flex-direction: column; }
}
