{% set y3_rev = d.annuals[2].revenue if d.annuals | length >= 3 else 0 %}
{% set y3_dscr = d.dscr[2].dscr if d.dscr | length >= 3 else 0 %}
{% set is_in = s.venue == 'indoor' %}

<div class="mb-section">
  <div class="section-header"><h3>{{ t.metrics_revenue }}</h3></div>
  <div class="grid-4">
    <div class="metric-card metric-card-sm">
      <div class="metric-card__label">RevPAH <span class="ti">i<span class="tp">{{ t.tip_result_revpah }}</span></span></div>
      <div class="metric-card__value c-blue">{{ d.revPAH | fmt_currency }}</div>
      <div class="metric-card__sub">Revenue per Available Hour</div>
    </div>
    <div class="metric-card metric-card-sm">
      <div class="metric-card__label">Revenue / m²</div>
      <div class="metric-card__value c-blue">{{ d.revPerSqm | int | fmt_currency }}</div>
      <div class="metric-card__sub">Annual net revenue ÷ area</div>
    </div>
    <div class="metric-card metric-card-sm">
      <div class="metric-card__label">Revenue / Court</div>
      <div class="metric-card__value c-head">{{ (y3_rev / [1, d.totalCourts] | max) | int | fmt_currency }}</div>
      <div class="metric-card__sub">Year 3 annual</div>
    </div>
    <div class="metric-card metric-card-sm">
      <div class="metric-card__label">Avg Booked Rate</div>
      <div class="metric-card__value c-head">{{ d.weightedRate | int | fmt_currency }}</div>
      <div class="metric-card__sub">Blended peak/off-peak</div>
    </div>
  </div>
</div>

<div class="mb-section">
  <div class="section-header"><h3>{{ t.metrics_cost }}</h3></div>
  <div class="grid-4">
    <div class="metric-card metric-card-sm">
      <div class="metric-card__label">EBITDA Margin</div>
      <div class="metric-card__value {{ 'c-green' if d.ebitdaMargin > 0.3 else 'c-amber' }}">{{ d.ebitdaMargin | fmt_pct }}</div>
      <div class="metric-card__sub">Operating profit margin</div>
    </div>
    <div class="metric-card metric-card-sm">
      <div class="metric-card__label">OpEx Ratio</div>
      <div class="metric-card__value c-head">{{ d.opexRatio | fmt_pct }}</div>
      <div class="metric-card__sub">OpEx ÷ Revenue</div>
    </div>
    <div class="metric-card metric-card-sm">
      <div class="metric-card__label">Occupancy Cost</div>
      <div class="metric-card__value {{ 'c-green' if d.rentRatio < 0.3 else 'c-red' }}">{{ d.rentRatio | fmt_pct }}</div>
      <div class="metric-card__sub">Rent ÷ Revenue</div>
    </div>
    <div class="metric-card metric-card-sm">
      <div class="metric-card__label">Cost / Booked Hour</div>
      <div class="metric-card__value c-head">{{ d.costPerBookedHr | fmt_currency }}</div>
      <div class="metric-card__sub">All-in cost per hour sold</div>
    </div>
  </div>
</div>

<div class="mb-section">
  <div class="section-header"><h3>{{ t.metrics_debt }}</h3></div>
  <div class="grid-4">
    <div class="metric-card metric-card-sm">
      <div class="metric-card__label">DSCR (Y3) <span class="ti">i<span class="tp">{{ t.tip_result_dscr }}</span></span></div>
      <div class="metric-card__value {{ 'c-green' if y3_dscr >= 1.2 else 'c-red' }}">{{ '∞' if y3_dscr > 99 else y3_dscr | fmt_x }}</div>
      <div class="metric-card__sub">Min 1.2x for banks</div>
      {% if d.dscrWarning %}
      <div class="metric-card__warn c-red" style="font-size:10px;margin-top:4px">⚠ DSCR &lt; 1.25x in Y{{ d.dscrMinYear }} — bank covenant breach risk</div>
      {% endif %}
    </div>
    <div class="metric-card metric-card-sm">
      <div class="metric-card__label">LTV</div>
      <div class="metric-card__value {{ 'c-amber' if d.ltvWarning else 'c-head' }}">{{ d.ltv | fmt_pct }}</div>
      <div class="metric-card__sub">Loan ÷ Total Investment</div>
      {% if d.ltvWarning %}
      <div class="metric-card__warn c-amber" style="font-size:10px;margin-top:4px">⚠ LTV &gt; 75% — above typical commercial lending limit</div>
      {% endif %}
    </div>
    <div class="metric-card metric-card-sm">
      <div class="metric-card__label">Debt Yield <span class="ti">i<span class="tp">{{ t.tip_result_debt_yield }}</span></span></div>
      <div class="metric-card__value {{ 'c-green' if d.debtYield > 0.1 else 'c-amber' }}">{{ d.debtYield | fmt_pct }}</div>
      <div class="metric-card__sub">Stab. EBITDA ÷ Loan</div>
    </div>
    <div class="metric-card metric-card-sm">
      <div class="metric-card__label">Monthly Debt Service</div>
      <div class="metric-card__value c-red">{{ d.monthlyPayment | int | fmt_currency }}</div>
      <div class="metric-card__sub">P&amp;I payment</div>
    </div>
  </div>
</div>

<div class="mb-section">
  <div class="section-header"><h3>{{ t.metrics_invest }}</h3></div>
  <div class="grid-4">
    <div class="metric-card metric-card-sm">
      <div class="metric-card__label">CAPEX / Court</div>
      <div class="metric-card__value c-head">{{ d.capexPerCourt | int | fmt_currency }}</div>
      <div class="metric-card__sub">Total investment per court</div>
    </div>
    <div class="metric-card metric-card-sm">
      <div class="metric-card__label">CAPEX / m²</div>
      <div class="metric-card__value c-head">{{ d.capexPerSqm | int | fmt_currency }}</div>
      <div class="metric-card__sub">Investment per floor area</div>
    </div>
    <div class="metric-card metric-card-sm">
      <div class="metric-card__label">Yield on Cost <span class="ti">i<span class="tp">{{ t.tip_result_yield_on_cost }}</span></span></div>
      <div class="metric-card__value {{ 'c-green' if d.yieldOnCost > 0.08 else 'c-amber' }}">{{ d.yieldOnCost | fmt_pct }}</div>
      <div class="metric-card__sub">Stab. EBITDA ÷ CAPEX</div>
    </div>
    <div class="metric-card metric-card-sm">
      <div class="metric-card__label">Exit Value</div>
      <div class="metric-card__value c-head">{{ d.exitValue | fmt_k }}</div>
      <div class="metric-card__sub">{{ s.exitMultiple }}x Y{{ s.holdYears }} EBITDA</div>
    </div>
  </div>
</div>

<div class="mb-section">
  <div class="section-header"><h3>{{ t.metrics_ops }}</h3></div>
  <div class="grid-4">
    <div class="metric-card metric-card-sm">
      <div class="metric-card__label">Break-Even Util. <span class="ti">i<span class="tp">{{ t.tip_result_break_even }}</span></span></div>
      <div class="metric-card__value {{ 'c-green' if d.breakEvenUtil < 0.35 else 'c-amber' }}">{{ d.breakEvenUtil | fmt_pct }}</div>
      <div class="metric-card__sub">{{ d.breakEvenHrsPerCourt | round(1) }} hrs/court/day</div>
    </div>
    <div class="metric-card metric-card-sm">
      <div class="metric-card__label">Y3 Utilization</div>
      <div class="metric-card__value c-head">{{ d.avgUtil | fmt_pct }}</div>
      <div class="metric-card__sub">Effective avg utilization</div>
    </div>
    <div class="metric-card metric-card-sm">
      <div class="metric-card__label">Available Hours/mo</div>
      <div class="metric-card__value c-head">{{ d.availHoursMonth | fmt_n }}</div>
      <div class="metric-card__sub">All courts combined</div>
    </div>
    <div class="metric-card metric-card-sm">
      <div class="metric-card__label">Operating Months</div>
      <div class="metric-card__value c-head">{{ '12' if is_in else '~' ~ s.season | selectattr('>', 0) | list | length }}</div>
      <div class="metric-card__sub">{{ 'Year-round' if is_in else 'Seasonal' }}</div>
    </div>
  </div>
</div>
