:root {
  color-scheme: light;
  --bg: #f6f3ee;
  --panel: #ffffff;
  --panel-strong: #20312b;
  --ink: #18211f;
  --muted: #60706b;
  --line: #d9ddd6;
  --accent: #1f7a5a;
  --accent-dark: #15543e;
  --warning: #a8661f;
  --danger: #a33a32;
  --soft-green: #e6f3ed;
  --soft-amber: #fff2df;
  --soft-red: #fdebe9;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

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

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

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

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent-dark);
  font-size: 0.78rem;
  font-weight: 750;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 0;
  font-size: clamp(2rem, 4vw, 3.8rem);
  line-height: 1;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 10px;
  font-size: 1.2rem;
  letter-spacing: 0;
}

.language-control {
  display: grid;
  gap: 6px;
  min-width: 128px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

.language-control select {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 10px;
  color: var(--ink);
  background: #fff;
  font: inherit;
  cursor: pointer;
}

.header-metrics {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  color: var(--muted);
  font-size: 0.92rem;
}

.header-metrics span {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 10px;
  background: rgba(255, 255, 255, 0.72);
}

.calculator-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.08fr) minmax(320px, 0.92fr);
  gap: 18px;
  align-items: stretch;
}

.tool-panel,
.results-panel,
.scenario-section,
.zinsbindung-section,
.rent-buy-section,
.value-section,
.formula-section {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 18px 55px rgba(32, 49, 43, 0.08);
}

.tool-panel,
.results-panel {
  padding: 22px;
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  column-gap: 18px;
  row-gap: 28px;
}

.field {
  display: grid;
  gap: 7px;
  min-width: 0;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

.field-label,
.metric-label {
  position: relative;
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
}

.field-label label {
  min-width: 0;
}

input[type="text"] {
  width: 100%;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 12px;
  color: var(--ink);
  background: #fbfcfa;
  font: inherit;
  font-size: 1.03rem;
  font-weight: 700;
}

input[type="text"]:focus {
  outline: 3px solid rgba(31, 122, 90, 0.2);
  border-color: var(--accent);
}

input[type="range"] {
  width: 100%;
  min-height: 22px;
  margin: 0;
  padding: 0;
  accent-color: var(--accent);
  cursor: pointer;
}

.slider-scale {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
}

.slider-scale.light {
  color: rgba(246, 251, 248, 0.74);
}

.payment-slider-control {
  display: grid;
  gap: 6px;
  margin-top: 12px;
}

.payment-slider-control input[type="range"] {
  accent-color: #8bd0b3;
}

.payment-slider-note {
  color: rgba(246, 251, 248, 0.78);
  font-size: 0.78rem;
  font-weight: 750;
}

.field-note {
  border-radius: 6px;
  padding: 8px 10px;
  color: var(--accent-dark);
  background: var(--soft-green);
  font-size: 0.82rem;
  font-weight: 800;
}

.lump-sum-savings {
  display: grid;
  gap: 4px;
  line-height: 1.3;
}

.lump-sum-savings strong {
  display: block;
}

.lump-sum-savings span {
  display: block;
  color: var(--accent-dark);
  font-size: 0.78rem;
  font-weight: 750;
}

.term-help {
  position: relative;
  display: inline-grid;
  flex: 0 0 auto;
  place-items: center;
  width: 18px;
  height: 18px;
  border: 1px solid rgba(31, 122, 90, 0.36);
  border-radius: 50%;
  color: var(--accent-dark);
  background: #eef7f2;
  font-size: 0.72rem;
  font-weight: 900;
  line-height: 1;
  cursor: help;
}

.term-help.dark {
  border-color: rgba(255, 255, 255, 0.35);
  color: #f6fbf8;
  background: rgba(255, 255, 255, 0.12);
}

.term-help::after {
  content: attr(data-tooltip);
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  z-index: 20;
  display: none;
  width: min(310px, calc(100vw - 48px));
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 10px 11px;
  color: var(--ink);
  background: #fff;
  box-shadow: 0 16px 42px rgba(32, 49, 43, 0.18);
  font-size: 0.82rem;
  font-weight: 650;
  line-height: 1.42;
  text-transform: none;
  white-space: normal;
}

.term-help:hover::after,
.term-help:focus::after {
  display: block;
}

.term-help.tooltip-left::after {
  right: 0;
  left: auto;
}

.term-help:focus {
  outline: 3px solid rgba(31, 122, 90, 0.2);
  outline-offset: 2px;
}

.actions {
  display: flex;
  gap: 10px;
  margin-top: 18px;
}

button {
  min-height: 44px;
  border: 0;
  border-radius: 6px;
  padding: 0 18px;
  color: #fff;
  background: var(--accent);
  font: inherit;
  font-weight: 800;
  cursor: pointer;
}

button:hover {
  background: var(--accent-dark);
}

button.secondary {
  color: var(--ink);
  background: #edf0ec;
}

button.secondary:hover {
  background: #e0e5df;
}

.results-panel {
  position: relative;
  display: grid;
  align-content: start;
  gap: 18px;
  color: #f6fbf8;
  background: var(--panel-strong);
  border-color: var(--panel-strong);
}

.results-topbar {
  display: contents;
}

.copy-image-button {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 15;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: auto;
  min-height: 30px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  padding: 0 12px;
  color: var(--panel-strong);
  background: #f6fbf8;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.14);
  font-size: 0.78rem;
}

.copy-image-button:hover {
  color: var(--panel-strong);
  background: #e6f3ed;
}

.copy-image-button:disabled {
  opacity: 0.68;
  cursor: progress;
}

.copy-image-tooltip {
  position: absolute;
  top: 50px;
  right: 12px;
  z-index: 25;
  width: max-content;
  max-width: min(340px, calc(100vw - 48px));
  border: 1px solid rgba(31, 122, 90, 0.24);
  border-radius: 7px;
  padding: 10px 12px;
  color: var(--accent-dark);
  background: #f6fbf8;
  box-shadow: 0 16px 42px rgba(0, 0, 0, 0.2);
  font-size: 0.82rem;
  font-weight: 800;
  line-height: 1.35;
  opacity: 0;
  pointer-events: none;
  transform: translateY(-4px);
  transition: opacity 160ms ease, transform 160ms ease;
}

.copy-image-tooltip.visible {
  opacity: 1;
  transform: translateY(0);
}

.copy-image-tooltip.error {
  border-color: rgba(163, 58, 50, 0.28);
  color: var(--danger);
  background: var(--soft-red);
}

.result-hero {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.repayment-time-block {
  margin-top: 0;
}

.metric-label {
  margin-bottom: 7px;
  color: inherit;
  opacity: 0.72;
  font-size: 0.82rem;
  font-weight: 800;
  text-transform: uppercase;
}

.metric-value {
  margin-bottom: 0;
  font-size: clamp(1.75rem, 5vw, 3rem);
  line-height: 1.04;
  font-weight: 850;
}

.payment-breakdown {
  margin: 6px 0 0;
  color: rgba(246, 251, 248, 0.78);
  font-size: 0.88rem;
  font-weight: 800;
  line-height: 1.35;
}

.metric-detail {
  margin: 5px 0 0;
  color: rgba(246, 251, 248, 0.66);
  font-size: 0.82rem;
  font-weight: 750;
  line-height: 1.35;
}

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

.metric-grid > div {
  min-width: 0;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 7px;
  padding: 14px;
  background: rgba(255, 255, 255, 0.06);
}

.metric-small {
  margin-bottom: 0;
  font-size: 1.25rem;
  line-height: 1.15;
  font-weight: 820;
}

.status-strip {
  border-radius: 7px;
  padding: 13px 14px;
  color: var(--ink);
  background: #edf0ec;
  font-weight: 750;
}

.status-strip.good {
  background: var(--soft-green);
}

.status-strip.warn {
  background: var(--soft-amber);
}

.status-strip.risk {
  background: var(--soft-red);
}

.zinsbindung-section,
.rent-buy-section,
.value-section,
.scenario-section,
.formula-section {
  margin-top: 18px;
  padding: 22px;
}

.term-heading {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
}

.term-heading h2 {
  margin-bottom: 0;
}

.section-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
}

.section-heading p,
.formula-section p {
  margin-bottom: 0;
  color: var(--muted);
}

.zinsbindung-summary {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  margin-top: 16px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 14px 16px;
  background: #fbfcfa;
}

.zinsbindung-summary span {
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 800;
  text-transform: uppercase;
}

.zinsbindung-summary strong {
  font-size: 1.45rem;
  line-height: 1.1;
}

.zinsbindung-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 10px;
  margin-top: 12px;
  font-variant-numeric: tabular-nums;
}

.zinsbindung-card {
  display: grid;
  gap: 4px;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 12px;
  background: #fbfcfa;
}

.zinsbindung-card.current {
  border-color: rgba(31, 122, 90, 0.42);
  background: var(--soft-green);
}

.zinsbindung-card span,
.zinsbindung-card small {
  min-width: 0;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 800;
}

.zinsbindung-card strong {
  font-size: 1.18rem;
  line-height: 1.1;
}

.zinsbindung-card b {
  font-size: 1.1rem;
  line-height: 1.12;
}

.comparison-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(145px, 1fr));
  gap: 10px;
  margin-top: 16px;
  font-variant-numeric: tabular-nums;
}

.comparison-card {
  display: grid;
  gap: 8px;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 14px;
  background: #fbfcfa;
}

.comparison-card.emphasis {
  border-color: rgba(31, 122, 90, 0.42);
  background: var(--soft-green);
}

.comparison-label {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
}

.comparison-label [data-i18n] {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.comparison-card strong {
  font-size: 1.28rem;
  line-height: 1.12;
}

.comparison-summary {
  margin-top: 12px;
  border-radius: 7px;
  padding: 13px 14px;
  color: var(--ink);
  background: #edf0ec;
  font-weight: 750;
  line-height: 1.4;
}

.value-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(145px, 1fr));
  gap: 10px;
  margin-top: 16px;
  font-variant-numeric: tabular-nums;
}

.value-card {
  display: grid;
  gap: 4px;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 14px;
  background: #fbfcfa;
}

.value-card.current {
  border-color: rgba(31, 122, 90, 0.42);
  background: var(--soft-green);
}

.value-card.negative {
  border-color: rgba(163, 58, 50, 0.45);
  background: var(--soft-red);
}

.value-card span,
.value-card small {
  min-width: 0;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 800;
}

.value-card strong {
  font-size: 1.18rem;
  line-height: 1.1;
}

.value-card b {
  font-size: 1.08rem;
  line-height: 1.12;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  min-width: 820px;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 13px 10px;
  text-align: right;
  white-space: nowrap;
}

th:first-child,
td:first-child {
  text-align: left;
}

th {
  color: var(--muted);
  font-size: 0.82rem;
  text-transform: uppercase;
}

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

.formula-section p {
  max-width: 860px;
  line-height: 1.55;
}

@media (min-width: 861px) {
  .field:nth-child(even) .term-help::after {
    right: 0;
    left: auto;
  }
}

@media (max-width: 860px) {
  .term-help::after {
    right: 0;
    left: auto;
    transform: translateX(var(--tooltip-shift-x, 0px));
  }

  .app-shell {
    width: min(100% - 20px, 680px);
    padding-top: 20px;
  }

  .app-header,
  .section-heading {
    align-items: flex-start;
    flex-direction: column;
  }

  .header-metrics {
    justify-content: flex-start;
  }

  .language-control {
    width: 100%;
  }

  .calculator-layout,
  .field-grid,
  .result-hero,
  .metric-grid {
    grid-template-columns: 1fr;
  }

  .tool-panel,
  .results-panel,
  .scenario-section,
  .zinsbindung-section,
  .rent-buy-section,
  .value-section,
  .formula-section {
    padding: 16px;
  }

  .zinsbindung-summary {
    align-items: flex-start;
    flex-direction: column;
  }

  .actions {
    flex-direction: column;
  }

  button {
    width: 100%;
  }

  .results-topbar {
    display: contents;
  }

  .copy-image-button {
    top: 10px;
    right: 10px;
    width: auto;
  }

  .copy-image-tooltip {
    top: 46px;
    right: 10px;
    width: 100%;
    max-width: calc(100% - 20px);
  }
}
