<div class="row mb-3">
  <div class="col-md-3 mb-2">
    <div class="card text-center">
      <div class="card-body">
        <h6 class="card-title text-muted">Total Days</h6>
        <p class="card-text display-6">{{ data.total_days }}</p>
      </div>
    </div>
  </div>
  <div class="col-md-3 mb-2">
    <div class="card text-center">
      <div class="card-body">
        <h6 class="card-title text-muted">Fasting Days</h6>
        <p class="card-text display-6">{{ data.fasting_days_count }}</p>
      </div>
    </div>
  </div>
  <div class="col-md-3 mb-2">
    <div class="card text-center">
      <div class="card-body">
        <h6 class="card-title text-muted">Fasting Rate</h6>
        <p class="card-text display-6">{{ data.fasting_rate_pct }}%</p>
      </div>
    </div>
  </div>
  <div class="col-md-3 mb-2">
    <div class="card text-center">
      <div class="card-body">
        <h6 class="card-title text-muted">Current Streak</h6>
        <p class="card-text display-6">
          {% if data.current_streak.count > 0 %}
            {{ data.current_streak.count }}
            <small class="text-muted fs-6">{{ data.current_streak.type }}</small>
          {% else %}
            &mdash;
          {% endif %}
        </p>
      </div>
    </div>
  </div>
</div>

<div class="row mb-3">
  <div class="col-12">
    <p class="text-muted">
      Periodic fasting: {{ data.periodic_threshold_hours }}h+ gaps ({{ data.periodic_fasting_count }} days) &middot;
      Full fasting: {{ data.full_threshold_hours }}h+ gaps ({{ data.full_fasting_count }} days) &middot;
      Liquid fasting: {{ data.liquid_fasting_count }} days
    </p>
  </div>
</div>

{% if data.current_streak.count > 0 %}
<div class="row mb-3">
  <div class="col-12">
    <div class="alert alert-info">
      <strong>Current streak:</strong>
      {{ data.current_streak.count }} consecutive
      <span class="{% if data.current_streak.type == 'full' %}text-danger{% else %}text-warning{% endif %}">
        {{ data.current_streak.type }}
      </span>
      fasting day{{ data.current_streak.count|pluralize }}.
    </div>
  </div>
</div>
{% endif %}

{% if data.longest_streaks %}
<div class="row mb-3">
  <div class="col-12">
    <h5>Longest Streaks</h5>
    <div class="table-responsive">
      <table class="table table-striped table-sm">
        <thead>
          <tr>
            <th>#</th>
            <th>Type</th>
            <th class="text-end">Length</th>
            <th>Start</th>
            <th>End</th>
          </tr>
        </thead>
        <tbody>
          {% for streak in data.longest_streaks %}
          <tr>
            <td>{{ forloop.counter }}</td>
            <td>
              <span class="{% if streak.type == 'full' %}text-danger{% else %}text-warning{% endif %}">
                {{ streak.type|title }}
              </span>
            </td>
            <td class="text-end">{{ streak.count }} day{{ streak.count|pluralize }}</td>
            <td>{{ streak.start }}</td>
            <td>{{ streak.end }}</td>
          </tr>
          {% endfor %}
        </tbody>
      </table>
    </div>
  </div>
</div>
{% endif %}

{% if data.fasting_days %}
<div class="row">
  <div class="col-12">
    <h5>Fasting Days</h5>
    <div class="table-responsive" style="max-height: 400px; overflow-y: auto;">
      <table class="table table-striped table-sm">
        <thead>
          <tr>
            <th>Date</th>
            <th>Type</th>
          </tr>
        </thead>
        <tbody>
          {% for day in data.fasting_days %}
          <tr>
            <td>{{ day.date }}</td>
            <td>
              {% if day.type == 'full' and day.had_drink %}
                <span class="text-info">Liquid Fast</span>
              {% elif day.type == 'full' %}
                <span class="text-danger">Full Fast</span>
              {% else %}
                <span class="text-warning">Periodic Fast</span>
              {% endif %}
            </td>
          </tr>
          {% endfor %}
        </tbody>
      </table>
    </div>
  </div>
</div>
{% else %}
<p class="text-muted">No fasting days detected for this period.</p>
{% endif %}
