:root {
  color: #24231f;
  background: #f7f4ee;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 16px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background: #f7f4ee;
}

button,
input {
  font: inherit;
}

.app-shell {
  width: min(1280px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0;
}

.tool-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.tool-header h1 {
  margin: 0;
  font-size: 2rem;
  line-height: 1;
}

.tool-header p {
  margin: 8px 0 0;
  color: #68635b;
}

.simulator-grid {
  display: grid;
  grid-template-columns: minmax(280px, 380px) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.input-panel,
.results-panel {
  border: 1px solid #ddd7ca;
  border-radius: 8px;
  background: #fffdf9;
  box-shadow: 0 10px 26px rgba(37, 33, 25, 0.07);
}

.input-panel {
  padding: 18px;
}

.tab-list {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 6px;
  margin-bottom: 16px;
}

.tab-button {
  min-width: 0;
  min-height: 38px;
  padding: 7px 6px;
  border-color: #d8d1c4;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.tab-button.is-active {
  border-color: #17493f;
  color: #ffffff;
  background: #17493f;
}

.tab-panel[hidden] {
  display: none;
}

.empty-panel {
  margin: 0;
  border: 1px solid #e4ded2;
  border-radius: 8px;
  padding: 12px;
  color: #68635b;
  background: #ffffff;
  line-height: 1.6;
}

.estimate-note {
  margin: 0;
  border: 1px solid #e4ded2;
  border-radius: 8px;
  padding: 10px 12px;
  color: #4f4b44;
  background: #ffffff;
  font-size: 0.9rem;
}

.estimate-note strong {
  color: #17493f;
}

.income-list,
.event-list,
.family-list,
.plan-list {
  display: grid;
  gap: 10px;
}

.income-card,
.event-card,
.family-card,
.plan-card {
  display: grid;
  gap: 10px;
  margin: 0;
  border: 1px solid #e4ded2;
  border-radius: 8px;
  padding: 12px;
  background: #ffffff;
}

.income-card legend,
.event-card legend,
.family-card legend,
.plan-card legend {
  padding: 0 4px;
  color: #4f4b44;
  font-size: 0.88rem;
  font-weight: 750;
}

.labor-income-fields,
.family-fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.one-time-income-fields,
.recurring-expense-fields,
.plan-fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.secondary-button {
  width: 100%;
  background: #ffffff;
}

.text-button {
  justify-self: end;
  min-height: 32px;
  border: 0;
  padding: 4px 2px;
  color: #8b3d29;
  background: transparent;
  font-size: 0.86rem;
  font-weight: 650;
}

.text-button:hover {
  color: #642817;
  background: transparent;
}

.field-grid {
  display: grid;
  gap: 14px;
}

label {
  display: grid;
  gap: 6px;
}

label span,
.risk-presets legend,
.advanced-options summary {
  color: #4f4b44;
  font-size: 0.88rem;
  font-weight: 650;
}

.year-age-field {
  display: grid;
  grid-template-columns: minmax(72px, 1fr) auto;
  align-items: center;
  gap: 8px;
}

.year-age-hint {
  min-width: 3.5em;
  color: #6d6256;
  font-size: 0.82rem;
  font-weight: 700;
  white-space: nowrap;
}

input {
  width: 100%;
  min-height: 42px;
  border: 1px solid #cfc8bb;
  border-radius: 6px;
  padding: 9px 10px;
  color: #24231f;
  background: #ffffff;
}

input:focus {
  border-color: #2f6f62;
  outline: 3px solid rgba(47, 111, 98, 0.18);
}

.risk-presets {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 0;
  padding: 0;
  border: 0;
}

.risk-presets legend {
  grid-column: 1 / -1;
  margin-bottom: 2px;
}

.risk-presets button {
  min-width: 0;
  padding: 8px 6px;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.advanced-options {
  margin-top: 16px;
  border-top: 1px solid #e4ded2;
  padding-top: 14px;
}

.advanced-options summary {
  cursor: pointer;
  list-style-position: outside;
}

.advanced-options label {
  margin-top: 12px;
}

button {
  min-height: 40px;
  border: 1px solid #cfc8bb;
  border-radius: 6px;
  color: #2a2a25;
  background: #f6f1e8;
  cursor: pointer;
}

button:hover {
  border-color: #a99f8d;
  background: #efe8db;
}

.primary-button {
  width: 100%;
  margin-top: 14px;
  border-color: #17493f;
  color: #ffffff;
  background: #17493f;
  font-weight: 750;
}

.primary-button:hover {
  border-color: #0f382f;
  background: #0f382f;
}

.ghost-button {
  min-width: 84px;
  padding-inline: 14px;
}

.error-text {
  min-height: 20px;
  margin: 12px 0 0;
  color: #a13f27;
  font-size: 0.9rem;
}

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

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

.metric-card {
  min-width: 0;
  border: 1px solid #e4ded2;
  border-radius: 8px;
  padding: 12px;
  background: #ffffff;
}

.metric-card span {
  display: block;
  margin-bottom: 6px;
  color: #666158;
  font-size: 0.78rem;
  font-weight: 650;
}

.metric-card strong {
  display: block;
  overflow-wrap: anywhere;
  font-size: clamp(1rem, 1.7vw, 1.35rem);
  line-height: 1.15;
}

.chart-wrap {
  position: relative;
  width: 100%;
  min-height: 360px;
  border: 1px solid #e4ded2;
  border-radius: 8px;
  overflow: hidden;
  background: #ffffff;
}

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

.asset-section,
.cashflow-section {
  margin-top: 18px;
}

.asset-section {
  margin-top: 0;
}

.asset-section h2,
.cashflow-section h2 {
  margin: 0 0 10px;
  color: #24231f;
  font-size: 1rem;
  line-height: 1.2;
}

.cashflow-chart-wrap {
  min-height: 280px;
}

.cashflow-chart-wrap canvas {
  height: 300px;
}

.chart-tooltip {
  position: absolute;
  z-index: 2;
  min-width: 190px;
  max-width: min(260px, calc(100% - 20px));
  border: 1px solid rgba(23, 73, 63, 0.18);
  border-radius: 8px;
  padding: 10px 12px;
  color: #24231f;
  background: rgba(255, 253, 249, 0.96);
  box-shadow: 0 12px 28px rgba(37, 33, 25, 0.16);
  font-size: 0.82rem;
  line-height: 1.45;
  pointer-events: none;
}

.chart-tooltip[hidden] {
  display: none;
}

.chart-tooltip strong {
  display: block;
  margin-bottom: 5px;
  color: #17493f;
  font-size: 0.9rem;
}

.chart-tooltip dl {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 3px 12px;
  margin: 0;
}

.chart-tooltip dt {
  color: #666158;
}

.chart-tooltip dd {
  margin: 0;
  text-align: right;
  font-weight: 650;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 18px;
  align-items: center;
  margin-top: 12px;
  color: #4f4b44;
  font-size: 0.85rem;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.swatch,
.line {
  display: inline-block;
  width: 24px;
  height: 10px;
  border-radius: 2px;
}

.swatch.p0595 {
  background: rgba(84, 139, 120, 0.16);
}

.swatch.p3070 {
  background: rgba(84, 139, 120, 0.28);
}

.line {
  height: 0;
  border-top: 3px solid #17493f;
}

.bar-swatch {
  display: inline-block;
  width: 12px;
  height: 14px;
  border-radius: 2px;
}

.bar-swatch.income {
  background: #2f6f62;
}

.bar-swatch.expense {
  background: #b35b3d;
}

.bar-swatch.net {
  background: #315f9f;
}

.line.cash {
  border-top-color: #2f6f8f;
}

.line.net {
  border-top-color: #315f9f;
}

.line.allocation {
  border-top-color: #6c5b85;
  border-top-style: dashed;
}

.assumptions {
  margin: 12px 0 0;
  color: #68635b;
  font-size: 0.86rem;
  line-height: 1.55;
}

@media (max-width: 980px) {
  .simulator-grid {
    grid-template-columns: 1fr;
  }

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

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

  .app-shell {
    width: min(100% - 20px, 1280px);
    padding: 16px 0;
  }

  .tool-header {
    align-items: start;
  }

  .tool-header h1 {
    font-size: 1.6rem;
  }

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

  .labor-income-fields,
  .one-time-income-fields,
  .recurring-expense-fields {
    grid-template-columns: 1fr;
  }

  canvas {
    height: 320px;
  }
}
