:root {
  --bg: #f7efe2;
  --bg-strong: #ebddc6;
  --paper: rgba(255, 251, 244, 0.9);
  --panel: rgba(247, 239, 226, 0.74);
  --panel-strong: rgba(255, 248, 238, 0.96);
  --ink: #1d1a16;
  --muted: #625749;
  --accent: #0d6b62;
  --accent-2: #b84f2c;
  --accent-3: #1f3f59;
  --line: rgba(29, 26, 22, 0.12);
  --success: #1e7f51;
  --warning: #9d4d23;
  --shadow: 0 22px 50px rgba(73, 45, 18, 0.15);
  --radius-lg: 24px;
  --radius-md: 16px;
  --radius-sm: 10px;
  --sticky-toolbar-offset: 12px;
  --sticky-toolbar-height: 0px;
  --font-display: "Iowan Old Style", "Palatino Linotype", "Book Antiqua", Georgia, serif;
  --font-body: "Avenir Next", "Segoe UI", "Helvetica Neue", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(255, 255, 255, 0.72), transparent 28%),
    radial-gradient(circle at 78% 10%, rgba(13, 107, 98, 0.14), transparent 24%),
    linear-gradient(145deg, #f9f1e4 0%, #e8d9be 42%, #f2e9d8 100%);
  font-family: var(--font-body);
}

button,
input,
select,
textarea {
  font: inherit;
}

body {
  padding: 24px;
  overflow-x: hidden;
}

body.drawer-open {
  overflow: hidden;
}

.page-shell {
  width: min(100%, 1320px);
  margin: 0 auto;
}

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

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent-2);
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-size: 0.78rem;
  font-weight: 700;
}

h1,
h2,
h3,
h4 {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 600;
  line-height: 1.08;
}

h1 {
  font-size: clamp(2.6rem, 4vw, 4.8rem);
  max-width: 10ch;
}

h2 {
  font-size: 1.55rem;
}

p {
  margin: 0;
}

.lede {
  max-width: 72ch;
  margin-top: 12px;
  color: var(--muted);
  line-height: 1.55;
}

.header-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
}

.top-toolbar {
  display: flex;
  justify-content: flex-end;
  margin: 0 0 18px;
  padding: 0 0 12px;
}

.layout-grid {
  display: block;
}

.layout-grid > * {
  min-width: 0;
}

.panel-card {
  min-width: 0;
  border: 1px solid var(--line);
  background: var(--paper);
  backdrop-filter: blur(14px);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}

.results-panel {
  display: grid;
  gap: 18px;
}

.summary-card,
.charts-card,
.ledger-card,
.detail-panel,
.config-panel {
  padding: 22px;
}

.section-heading {
  display: grid;
  gap: 6px;
  align-items: start;
  margin-bottom: 16px;
}

.section-heading p {
  color: var(--muted);
  font-size: 0.93rem;
  max-width: 52ch;
}

.plain-list {
  margin: 0;
  padding-left: 18px;
  display: grid;
  gap: 10px;
  color: var(--muted);
  line-height: 1.45;
}

.form-grid {
  display: grid;
  gap: 12px;
}

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

.field-group {
  display: grid;
  gap: 6px;
}

.field-group label {
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--accent-3);
}

.field-group small {
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.35;
}

.field-group input {
  width: 100%;
  padding: 11px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(29, 26, 22, 0.18);
  background: rgba(255, 255, 255, 0.88);
}

.checkbox-field {
  align-content: start;
}

.checkbox-input-label {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
}

.checkbox-input-label span {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--accent-3);
}

.checkbox-field input {
  width: 18px;
  height: 18px;
  padding: 0;
  border-radius: 6px;
  justify-self: start;
  accent-color: var(--accent);
}

.ghost-button,
.metric-button,
.expand-button,
.banner-button {
  border: 1px solid rgba(29, 26, 22, 0.14);
  background: rgba(255, 255, 255, 0.72);
  color: var(--ink);
  border-radius: 999px;
  padding: 10px 14px;
  cursor: pointer;
  transition: transform 140ms ease, background 140ms ease, border-color 140ms ease;
}

.ghost-button:hover,
.metric-button:hover,
.expand-button:hover,
.file-button:hover,
.banner-button:hover {
  transform: translateY(-1px);
  background: rgba(255, 255, 255, 0.96);
  border-color: rgba(29, 26, 22, 0.28);
}

.file-button {
  display: inline-flex;
  align-items: center;
}

.side-actions {
  position: fixed;
  left: 16px;
  top: clamp(9rem, 22vh, 16rem);
  z-index: 17;
  display: grid;
  gap: 10px;
  transition: transform 180ms ease, opacity 180ms ease;
}

.side-actions.is-drawer-open {
  opacity: 0;
  pointer-events: none;
  transform: translateX(-18px);
}

.config-tab-button,
.side-toggle-button {
  padding: 14px 16px 14px 14px;
  border: 1px solid rgba(29, 26, 22, 0.14);
  border-left: none;
  border-radius: 0 18px 18px 0;
  background: rgba(255, 255, 255, 0.9);
  color: var(--ink);
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform 180ms ease, opacity 180ms ease, background 140ms ease;
  text-align: left;
  line-height: 1.25;
}

.config-tab-button:hover,
.side-toggle-button:hover {
  background: rgba(255, 255, 255, 0.98);
  transform: translateX(4px);
}

.config-tab-button.is-hidden {
  opacity: 0;
  pointer-events: none;
  transform: translateX(-16px);
}

.side-toggle-button.is-active {
  background: rgba(13, 107, 98, 0.14);
  border-color: rgba(13, 107, 98, 0.3);
  color: var(--accent);
}

.config-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(29, 26, 22, 0.28);
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease;
  z-index: 24;
}

.config-backdrop.is-open {
  opacity: 1;
  pointer-events: auto;
}

.config-panel {
  position: fixed;
  top: 18px;
  left: 18px;
  bottom: 18px;
  width: min(540px, calc(100vw - 36px));
  overflow-y: auto;
  z-index: 32;
  transform: translateX(calc(-100% - 28px));
  transition: transform 220ms ease;
}

.config-panel.is-open {
  transform: translateX(0);
}

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

.config-note {
  padding: 18px;
  margin-bottom: 18px;
  border-radius: var(--radius-md);
  border: 1px solid rgba(29, 26, 22, 0.12);
  background: linear-gradient(155deg, rgba(255, 255, 255, 0.88), rgba(232, 217, 190, 0.55));
}

.config-note h3 {
  margin-bottom: 12px;
  font-size: 1.15rem;
}

.block-config-list {
  display: grid;
  gap: 14px;
}

.block-config-card {
  padding: 16px;
  border-radius: var(--radius-md);
  border: 1px solid rgba(29, 26, 22, 0.12);
  background: var(--panel-strong);
}

.block-config-card.is-disabled {
  background: rgba(247, 239, 226, 0.62);
}

.block-config-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px;
  align-items: start;
}

.block-config-toggle {
  padding: 0;
  border: none;
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.block-config-toggle h3 {
  margin-bottom: 6px;
  font-size: 1.2rem;
}

.block-config-toggle p {
  color: var(--muted);
  line-height: 1.42;
}

.block-config-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
  align-items: center;
}

.block-switch {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid rgba(29, 26, 22, 0.14);
  background: rgba(255, 255, 255, 0.75);
  font-size: 0.9rem;
  cursor: pointer;
}

.block-switch input {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--accent);
}

.locked-badge,
.block-state-badge {
  display: inline-flex;
  align-items: center;
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid rgba(29, 26, 22, 0.14);
  background: rgba(255, 255, 255, 0.72);
  font-size: 0.86rem;
  color: var(--muted);
}

.accordion-button {
  min-width: 96px;
}

.block-config-body {
  display: none;
  gap: 14px;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid rgba(29, 26, 22, 0.1);
}

.block-config-body.is-open {
  display: grid;
}

.block-config-status {
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.42;
}

.read-only-tax-summary {
  display: grid;
  gap: 12px;
  margin-top: 16px;
}

.read-only-grid {
  margin-top: 0;
}

.summary-sections {
  display: grid;
  gap: 18px;
}

.summary-section {
  display: grid;
  gap: 12px;
}

.summary-section-heading {
  display: grid;
  gap: 6px;
  align-items: start;
}

.summary-section-heading h3 {
  font-size: 1.1rem;
}

.summary-section-heading p {
  color: var(--muted);
  font-size: 0.88rem;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
}

.metric-card {
  padding: 14px;
  border-radius: var(--radius-md);
  background: linear-gradient(155deg, rgba(255, 255, 255, 0.88), rgba(232, 217, 190, 0.68));
  border: 1px solid rgba(29, 26, 22, 0.12);
}

.metric-card.clickable-card {
  cursor: pointer;
  transition: transform 140ms ease, box-shadow 140ms ease, border-color 140ms ease;
}

.metric-card.clickable-card:hover,
.metric-card.clickable-card:focus-visible {
  transform: translateY(-1px);
  box-shadow: 0 8px 24px rgba(29, 26, 22, 0.08);
  border-color: rgba(13, 107, 98, 0.3);
  outline: none;
}

.flow-grid .metric-card {
  background: linear-gradient(155deg, rgba(255, 250, 243, 0.92), rgba(240, 228, 207, 0.68));
}

.metric-label {
  display: block;
  font-size: 0.82rem;
  color: var(--muted);
  margin-bottom: 8px;
}

.metric-value {
  font-size: 1.15rem;
}

.warning-summary {
  margin-top: 18px;
}

.warning-banner,
.ok-banner {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 14px;
  align-items: center;
  padding: 14px 16px;
  border-radius: var(--radius-md);
}

.warning-banner {
  border: 1px solid rgba(184, 79, 44, 0.24);
  background: rgba(184, 79, 44, 0.08);
  color: var(--warning);
}

.ok-banner {
  border: 1px solid rgba(30, 127, 81, 0.24);
  background: rgba(30, 127, 81, 0.08);
  color: var(--success);
}

.banner-copy {
  display: grid;
  gap: 4px;
}

.banner-title {
  font-weight: 700;
}

.banner-text {
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.4;
}

.chart-area {
  display: grid;
  gap: 16px;
  grid-template-columns: minmax(0, 1fr);
}

.chart-panel {
  display: grid;
  gap: 12px;
}

.chart-panel-heading {
  display: grid;
  gap: 4px;
}

.chart-panel-heading h3 {
  font-size: 1.12rem;
}

.chart-panel-heading p {
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.4;
}

.chart-shell {
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.34);
  overflow: hidden;
  border: 1px solid rgba(29, 26, 22, 0.08);
}

.chart-host {
  width: 100%;
  height: 320px;
}

.chart-fallback {
  padding: 24px;
  color: var(--muted);
  font-size: 0.92rem;
}

.chart-tooltip-title {
  font-weight: 700;
  margin-bottom: 8px;
}

.chart-tooltip-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.chart-tooltip-row {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  color: var(--muted);
  font-size: 0.88rem;
}

.chart-tooltip-row + .chart-tooltip-row {
  margin-top: 6px;
}

.ledger-root {
  position: relative;
}

.ledger-sticky-head {
  position: sticky;
  top: var(--sticky-toolbar-offset);
  z-index: 6;
}

.ledger-head-shell {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
}

.ledger-head-period,
.ledger-head-metric-cell {
  padding: 12px 8px;
  border-bottom: 1px solid rgba(29, 26, 22, 0.1);
  background: rgba(255, 248, 238, 0.98);
  box-shadow: 0 1px 0 rgba(29, 26, 22, 0.08);
  font-weight: 700;
}

.ledger-head-period {
  text-align: left;
}

.ledger-head-metrics-viewport {
  overflow: hidden;
}

.ledger-head-metrics-track {
  display: grid;
  will-change: transform;
}

.ledger-scroll {
  overflow-x: auto;
  position: relative;
  padding-bottom: 4px;
}

.ledger-body {
  position: relative;
}

.ledger-grid-row {
  display: grid;
  width: 100%;
}

.ledger-grid-cell {
  padding: 12px 8px;
  border-bottom: 1px solid rgba(29, 26, 22, 0.1);
  text-align: right;
  min-width: 0;
}

.ledger-period-cell {
  position: sticky;
  left: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  text-align: left;
}

.ledger-grid-header .ledger-grid-cell {
  background: rgba(255, 248, 238, 0.98);
  box-shadow: 0 1px 0 rgba(29, 26, 22, 0.08);
  font-weight: 700;
}

.ledger-grid-header .ledger-period-cell {
  z-index: 8;
}

.year-row .ledger-grid-cell {
  background: rgba(255, 255, 255, 0.38);
  font-weight: 600;
}

.month-row .ledger-grid-cell {
  background: rgba(13, 107, 98, 0.04);
}

.year-row .ledger-period-cell,
.month-row .ledger-period-cell {
  z-index: 2;
}

.month-label {
  padding-left: 46px;
  color: var(--muted);
}

.metric-button {
  width: 100%;
  min-width: 0;
  text-align: right;
  padding: 8px 8px;
  background: rgba(255, 255, 255, 0.45);
}

.expand-button {
  margin-right: 10px;
  padding: 6px 10px;
}

.positive {
  color: var(--success);
}

.negative {
  color: var(--accent-2);
}

.detail-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(29, 26, 22, 0.28);
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease;
  z-index: 30;
}

.detail-backdrop.is-open {
  opacity: 1;
  pointer-events: auto;
}

.detail-panel {
  position: fixed;
  top: 18px;
  right: 18px;
  bottom: 18px;
  width: min(480px, calc(100vw - 32px));
  overflow-y: auto;
  z-index: 40;
  transform: translateX(calc(100% + 28px));
  transition: transform 220ms ease;
}

.detail-panel.is-open {
  transform: translateX(0);
}

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

.detail-subhead {
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.45;
}

.close-detail-button {
  flex-shrink: 0;
}

.detail-root {
  display: grid;
  gap: 16px;
}

.detail-empty {
  color: var(--muted);
  line-height: 1.5;
}

.detail-card {
  padding: 16px;
  border-radius: var(--radius-md);
  background: linear-gradient(155deg, rgba(255, 255, 255, 0.9), rgba(232, 217, 190, 0.55));
  border: 1px solid rgba(29, 26, 22, 0.12);
}

.detail-card h3 {
  margin-bottom: 10px;
  font-size: 1.15rem;
}

.detail-value {
  margin-bottom: 10px;
  color: var(--ink);
  font-size: 1.3rem;
}

.detail-card p,
.detail-card li {
  color: var(--muted);
  line-height: 1.45;
}

.detail-note {
  margin-top: -2px;
  font-size: 0.88rem;
}

.detail-card ul,
.detail-items {
  margin: 10px 0 0;
  padding-left: 18px;
}

.detail-section {
  margin-top: 14px;
}

.detail-section h4 {
  margin-bottom: 8px;
  font-size: 0.95rem;
}

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

.detail-chip {
  display: inline-flex;
  align-items: center;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(13, 107, 98, 0.08);
  border: 1px solid rgba(13, 107, 98, 0.16);
  color: var(--ink);
  font-size: 0.84rem;
  font-weight: 600;
}

.detail-formula {
  display: block;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: rgba(29, 26, 22, 0.06);
  color: var(--ink);
  font-size: 0.88rem;
  white-space: pre-wrap;
}

.kv-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.kv-item {
  padding: 10px;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.62);
}

.kv-item span {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 4px;
}

.trace-line-item-list {
  list-style: none;
  padding: 0;
  margin: 10px 0 0;
  display: grid;
  gap: 10px;
}

.trace-line-item {
  padding: 12px;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.5);
  border: 1px solid rgba(29, 26, 22, 0.1);
}

.trace-line-item-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: baseline;
  margin-bottom: 4px;
}

.trace-line-item-meta {
  font-size: 0.86rem;
  color: var(--muted);
  line-height: 1.45;
}

@media (max-width: 760px) {
  body {
    padding: 12px;
  }

  .page-header,
  .section-heading,
  .summary-section-heading,
  .detail-panel-header,
  .config-panel-header {
    flex-direction: column;
    align-items: start;
  }

  .warning-banner,
  .ok-banner {
    grid-template-columns: 1fr;
  }

  .summary-grid,
  .form-grid.two-col,
  .kv-grid,
  .block-config-header {
    grid-template-columns: 1fr;
  }

  .config-tab-button {
    border-left: 1px solid rgba(29, 26, 22, 0.14);
    border-radius: 999px;
  }

  .side-actions {
    left: 12px;
    top: auto;
    bottom: 12px;
  }

  .config-tab-button,
  .side-toggle-button {
    border-left: 1px solid rgba(29, 26, 22, 0.14);
    border-radius: 999px;
  }

  .config-panel {
    top: 10px;
    left: 10px;
    bottom: 10px;
    width: calc(100vw - 20px);
  }

  .detail-panel {
    top: 10px;
    right: 10px;
    bottom: 10px;
    width: calc(100vw - 20px);
  }
}
