:root {
  color-scheme: light;
  --bg: #f6f8f2;
  --surface: #ffffff;
  --surface-2: #eef3e6;
  --text: #1e271b;
  --muted: #5e6b58;
  --line: #d4dec9;
  --olive: #687f2f;
  --olive-dark: #43581c;
  --header: #43581c;
  --on-accent: #ffffff;
  --gold: #c79a2b;
  --blue: #2c6f91;
  --red: #b95745;
  --chart-direct: #4f6f2a;
  --chart-indirect: #2f7f8f;
  --chart-carry: #b07a2a;
  --chart-budget: #536a9f;
  --chart-balance: #d8deca;
  --tooltip-bg: #ffffff;
  --tooltip-text: #1e271b;
  --focus: #0b6b4b;
  --shadow: 0 10px 24px rgba(32, 45, 27, 0.08);
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #151a13;
  --surface: #20261d;
  --surface-2: #2b3426;
  --text: #f3f7ef;
  --muted: #c1cbb9;
  --line: #44513d;
  --olive: #9bb35b;
  --olive-dark: #c0d777;
  --header: #1f2b18;
  --on-accent: #12200e;
  --gold: #e0bb55;
  --blue: #74b7d2;
  --red: #df8978;
  --chart-direct: #a8c66c;
  --chart-indirect: #70b8c1;
  --chart-carry: #e0b15c;
  --chart-budget: #98a9dc;
  --chart-balance: #4e5b46;
  --tooltip-bg: #20261d;
  --tooltip-text: #f3f7ef;
  --focus: #b3d86a;
  --shadow: 0 12px 26px rgba(0, 0, 0, 0.22);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Roboto, Arial, sans-serif;
  font-size: 10px;
  letter-spacing: 0;
}

button,
input,
select {
  font: inherit;
}

.app-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  padding: 18px clamp(16px, 4vw, 38px);
  background: var(--header);
  color: #fff;
}

.eyebrow {
  margin: 0 0 4px;
  color: rgba(255, 255, 255, 0.78);
  font-size: 10px;
  text-transform: uppercase;
}

h1,
h2,
th,
.field span,
.summary-strip span {
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0;
}

h1,
h2 {
  margin: 0;
}

.header-actions {
  display: flex;
  align-items: center;
}

.theme-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}

.theme-toggle input {
  appearance: none;
  width: 34px;
  height: 18px;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.36);
  position: relative;
  cursor: pointer;
}

.theme-toggle input::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #fff;
  transition: transform 160ms ease;
}

.theme-toggle input:checked::after {
  transform: translateX(16px);
}

.app-shell {
  width: min(1480px, 100%);
  margin: 0 auto;
  padding: 18px clamp(12px, 3vw, 30px) 32px;
}

.control-band,
.summary-strip,
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.control-band {
  display: grid;
  grid-template-columns: auto minmax(160px, 1fr) minmax(160px, 1fr) 110px auto;
  gap: 10px;
  align-items: end;
  padding: 12px;
  border-radius: 8px;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, minmax(72px, 1fr));
  gap: 2px;
  padding: 3px;
  border-radius: 8px;
  background: var(--surface-2);
}

.segment,
.submit {
  min-height: 32px;
  border: 1px solid transparent;
  border-radius: 6px;
  cursor: pointer;
}

.segment {
  background: transparent;
  color: var(--text);
}

.segment.active {
  background: var(--olive);
  color: var(--on-accent);
}

.field {
  display: grid;
  gap: 5px;
}

.field select,
.field input {
  width: 100%;
  min-height: 32px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 9px;
  background: var(--surface);
  color: var(--text);
}

.submit {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  gap: 7px;
  padding: 0 14px;
  background: var(--olive);
  color: var(--on-accent);
  font-weight: 700;
}

.submit:hover,
.segment:hover {
  border-color: var(--olive-dark);
}

.submit svg {
  width: 14px;
  height: 14px;
}

button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.summary-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1px;
  margin-top: 12px;
  border-radius: 8px;
  overflow: hidden;
}

.summary-strip div {
  display: grid;
  gap: 4px;
  padding: 10px 12px;
  background: var(--surface);
  min-width: 0;
}

.summary-strip span,
.panel-head span {
  color: var(--muted);
}

.summary-strip strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.grid {
  display: grid;
  gap: 14px;
  margin-top: 14px;
}

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

.grid.charts {
  grid-template-columns: minmax(240px, 0.9fr) minmax(360px, 1.3fr) minmax(240px, 0.9fr);
}

.panel {
  border-radius: 8px;
  overflow: hidden;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
}

.table-wrap {
  overflow: auto;
  max-height: 380px;
}

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

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

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

thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface-2);
}

td:first-child,
th:first-child {
  min-width: 220px;
}

.report-table th:nth-child(1),
.report-table td:nth-child(1) {
  min-width: 150px;
}

.report-table th:nth-child(2),
.report-table td:nth-child(2),
.report-table th:nth-child(3),
.report-table td:nth-child(3) {
  min-width: 260px;
}

td.metric {
  text-align: right;
  white-space: nowrap;
}

.target-cell,
#resultsReportTable th:nth-child(4),
#resultsReportTable td:nth-child(4) {
  min-width: 74px;
  width: 74px;
}

td.actual {
  font-weight: 700;
  color: var(--olive-dark);
}

td input {
  width: 58px;
  min-height: 26px;
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 0 6px;
  background: var(--surface);
  color: var(--text);
  text-align: right;
}

#directBudgetTable td input,
.budget-table td input {
  width: 76px;
}

.budget-table th:nth-child(2),
.budget-table td:nth-child(2) {
  min-width: 130px;
}

.subtotal-row td {
  background: color-mix(in srgb, var(--surface-2) 78%, var(--surface));
  font-weight: 700;
}

.total-row td {
  background: color-mix(in srgb, var(--olive) 14%, var(--surface));
  font-weight: 700;
}

.empty {
  text-align: center;
  color: var(--muted);
  padding: 22px;
}

.chart-panel {
  min-height: 310px;
}

.chart-panel canvas {
  width: 100% !important;
  height: 252px !important;
  padding: 10px;
}

.toast {
  position: fixed;
  right: 16px;
  bottom: 16px;
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--header);
  color: #fff;
  box-shadow: var(--shadow);
}

@media (max-width: 1080px) {
  .control-band,
  .grid.two,
  .grid.charts,
  .summary-strip {
    grid-template-columns: 1fr;
  }

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

@media (max-width: 620px) {
  .app-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .control-band {
    padding: 10px;
  }

  td:first-child,
  th:first-child {
    min-width: 170px;
  }
}
