Sorting Mushroom Template Card

Help trying to sort the houses by date of next event in my dashboard.

Can't work it out. "Occupied" houses are essentially "hands-off" for the next few days—they don't require any immediate action from us so I would like them to sink to the bottom.
Also I would like the badge to show the days until next event even if the task is off however I don't know if this will work ....

Any help much appreciated!

type: vertical-stack
cards:
  - square: false
    type: grid
    title: 🏠 Live House Status
    cards:
      - type: custom:mushroom-template-card
        icon: mdi:home-city
        primary: Teodoro 4
        secondary: |-
          {% if is_state('calendar.teodoro_4', 'on') %}
            🧳 OCCUPIED
          {% elif is_state('input_boolean.task_active_teodoro_4', 'on') %}
            ⏳ In Progress
          {% else %}
            ✅ READY
          {% endif %}
        tap_action:
          action: navigate
          navigation_path: /todo?entity_id=todo.property_turnovers_2
        color: |-
          {% if is_state('calendar.teodoro_4', 'on') %}
            blue
          {% elif is_state('input_boolean.task_active_teodoro_4', 'on') %}
            orange
          {% else %}
            green
          {% endif %}
        features_position: bottom
        multiline_secondary: false
        vertical: true
        badge_text: |2
            {% set entity = 'calendar.teodoro_4' %}
            {% if is_state(entity, 'on') %}
              {% set checkout_str = state_attr(entity, 'end_time') %}
              {% if checkout_str is not none %}
                {% set checkout = as_datetime(checkout_str).date() %}
                {% set today = now().date() %}
                {{ (checkout - today).days }}
              {% endif %}
            {% endif %}
      - type: custom:mushroom-template-card
        icon: mdi:home-city
        primary: Marta 1
        secondary: |-
          {% if is_state('calendar.marta_1', 'on') %}
            🧳 OCCUPIED
          {% elif is_state('input_boolean.task_active_marta_1', 'on') %}
            ⏳ In Progress
          {% else %}
            ✅ READY
          {% endif %}
        tap_action:
          action: navigate
          navigation_path: /todo?entity_id=todo.property_turnovers_2
        color: |-
          {% if is_state('calendar.marta_1', 'on') %}
            blue
          {% elif is_state('input_boolean.task_active_marta_1', 'on') %}
            orange
          {% else %}
            green
          {% endif %}
        features_position: bottom
        vertical: true
        badge_text: |-
          {% set entity = 'calendar.marta_1' %}
          {% if is_state(entity, 'on') %}
            {# IF OCCUPIED: Count days remaining until checkout #}
            {% set checkout_str = state_attr(entity, 'end_time') %}
            {% if checkout_str is not none %}
              {% set checkout = as_datetime(checkout_str).date() %}
              {% set today = now().date() %}
              {{ (checkout - today).days }}d
            {% endif %}
          {% elif is_state('input_boolean.task_active_marta_1', 'on') %}
            {# IF IN PROGRESS: Count days remaining until next booking arrives #}
            {% set checkin_str = state_attr(entity, 'start_time') %}
            {% if checkin_str is not none %}
              {% set checkin = as_datetime(checkin_str).date() %}
              {% set today = now().date() %}
              {{ (checkin - today).days }}
            {% endif %}
          {% endif %}
        badge_color: |-
          {% if is_state('calendar.marta_1', 'on') %}
            blue
          {% elif is_state('input_boolean.task_active_marta_1', 'on') %}
            red
          {% endif %}
      - type: custom:mushroom-template-card
        icon: mdi:home-city
        primary: Marika Eva 24
        secondary: |-
          {% if is_state('calendar.marika_eva_24', 'on') %}
            🧳 OCCUPIED
          {% elif is_state('input_boolean.task_active_marika_eva_24', 'on') %}
            ⏳ In Progress
          {% else %}
            ✅ READY
          {% endif %}
        tap_action:
          action: navigate
          navigation_path: /todo?entity_id=todo.property_turnovers_2
        color: |-
          {% if is_state('calendar.marika_eva_24', 'on') %}
            blue
          {% elif is_state('input_boolean.task_active_marika_eva_24', 'on') %}
            orange
          {% else %}
            green
          {% endif %}
        features_position: bottom
        vertical: true
        badge_text: |-
          {% set entity = 'calendar.marika_eva_24' %}
          {% if is_state(entity, 'on') %}
            {# IF OCCUPIED: Count days remaining until checkout #}
            {% set checkout_str = state_attr(entity, 'end_time') %}
            {% if checkout_str is not none %}
              {% set checkout = as_datetime(checkout_str).date() %}
              {% set today = now().date() %}
              {{ (checkout - today).days }}d
            {% endif %}
          {% elif is_state('input_boolean.task_active_marika_eva_24', 'on') %}
            {# IF IN PROGRESS: Count days remaining until next booking arrives #}
            {% set checkin_str = state_attr(entity, 'start_time') %}
            {% if checkin_str is not none %}
              {% set checkin = as_datetime(checkin_str).date() %}
              {% set today = now().date() %}
              {{ (checkin - today).days }}
            {% endif %}
          {% endif %}
        badge_color: |-
          {% if is_state('calendar.marika_eva_24', 'on') %}
            blue
          {% elif is_state('input_boolean.task_active_marika_eva_24', 'on') %}
            red
          {% endif %}
      - type: custom:mushroom-template-card
        icon: mdi:home-city
        primary: Guillermo 4
        secondary: |-
          {% if is_state('calendar.guillermo_4_rentals', 'on') %}
            🧳 OCCUPIED
          {% elif is_state('input_boolean.task_active_guillermo_4', 'on') %}
            ⏳ In Progress
          {% else %}
            ✅ READY
          {% endif %}
        tap_action:
          action: navigate
          navigation_path: /todo?entity_id=todo.property_turnovers_2
        color: |-
          {% if is_state('calendar.guillermo_4_rentals', 'on') %}
            blue
          {% elif is_state('input_boolean.task_active_guillermo_4', 'on') %}
            orange
          {% else %}
            green
          {% endif %}
        features_position: bottom
        vertical: true
        badge_text: |-
          {% set entity = 'calendar.guillermo_4_rentals' %}
          {% if is_state(entity, 'on') %}
            {# IF OCCUPIED: Count days remaining until checkout #}
            {% set checkout_str = state_attr(entity, 'end_time') %}
            {% if checkout_str is not none %}
              {% set checkout = as_datetime(checkout_str).date() %}
              {% set today = now().date() %}
              {{ (checkout - today).days }}d
            {% endif %}
          {% elif is_state('input_boolean.task_active_guillermo_4', 'on') %}
            {# IF IN PROGRESS: Count days remaining until next booking arrives #}
            {% set checkin_str = state_attr(entity, 'start_time') %}
            {% if checkin_str is not none %}
              {% set checkin = as_datetime(checkin_str).date() %}
              {% set today = now().date() %}
              {{ (checkin - today).days }}
            {% endif %}
          {% endif %}
        badge_color: |-
          {% if is_state('calendar.guillermo_4_rentals', 'on') %}
            blue
          {% elif is_state('input_boolean.task_active_guillermo_4', 'on') %}
            red
          {% endif %}
      - type: custom:mushroom-template-card
        icon: mdi:home-city
        primary: Debbie Silvia 38
        secondary: |-
          {% if is_state('calendar.debbie_s_calendar', 'on') %}
            🧳 OCCUPIED
          {% elif is_state('input_boolean.task_active_silvia_38', 'on') %}
            ⏳ In Progress
          {% else %}
            ✅ READY
          {% endif %}
        tap_action:
          action: navigate
          navigation_path: /todo?entity_id=todo.property_turnovers_2
        color: |-
          {% if is_state('calendar.debbie_s_calendar', 'on') %}
            blue
          {% elif is_state('input_boolean.task_active_silvia_38', 'on') %}
            orange
          {% else %}
            green
          {% endif %}
        features_position: bottom
        vertical: true
        badge_text: |-
          {% set entity = 'calendar.debbie_s_calendar' %}
          {% if is_state(entity, 'on') %}
            {# IF OCCUPIED: Count days remaining until checkout #}
            {% set checkout_str = state_attr(entity, 'end_time') %}
            {% if checkout_str is not none %}
              {% set checkout = as_datetime(checkout_str).date() %}
              {% set today = now().date() %}
              {{ (checkout - today).days }}d
            {% endif %}
          {% elif is_state('input_boolean.task_active_silvia_38', 'on') %}
            {# IF IN PROGRESS: Count days remaining until next booking arrives #}
            {% set checkin_str = state_attr(entity, 'start_time') %}
            {% if checkin_str is not none %}
              {% set checkin = as_datetime(checkin_str).date() %}
              {% set today = now().date() %}
              {{ (checkin - today).days }}
            {% endif %}
          {% endif %}
        badge_color: |-
          {% if is_state('calendar.debbie_s_calendar', 'on') %}
            blue
          {% elif is_state('input_boolean.task_active_silvia_38', 'on') %}
            red
          {% endif %}
      - type: custom:mushroom-template-card
        icon: mdi:home-city
        primary: Tora Silvia 26
        secondary: |-
          {% if is_state('calendar.tora_silvia_26', 'on') %}
            🧳 OCCUPIED
          {% elif is_state('input_boolean.task_active_tora_silvia_26', 'on') %}
            ⏳ In Progress
          {% else %}
            ✅ READY
          {% endif %}
        tap_action:
          action: navigate
          navigation_path: /todo?entity_id=todo.property_turnovers_2
        color: |-
          {% if is_state('calendar.tora_silvia_26', 'on') %}
            blue
          {% elif is_state('input_boolean.task_active_tora_silvia_26', 'on') %}
            orange
          {% else %}
            green
          {% endif %}
        features_position: bottom
        vertical: true
        badge_text: |-
          {% set entity = 'calendar.tora_silvia_26' %}
          {% if is_state(entity, 'on') %}
            {# IF OCCUPIED: Count days remaining until checkout #}
            {% set checkout_str = state_attr(entity, 'end_time') %}
            {% if checkout_str is not none %}
              {% set checkout = as_datetime(checkout_str).date() %}
              {% set today = now().date() %}
              {{ (checkout - today).days }}d
            {% endif %}
          {% elif is_state('input_boolean.task_active_tora_silvia_26', 'on') %}
            {# IF IN PROGRESS: Count days remaining until next booking arrives #}
            {% set checkin_str = state_attr(entity, 'start_time') %}
            {% if checkin_str is not none %}
              {% set checkin = as_datetime(checkin_str).date() %}
              {% set today = now().date() %}
              {{ (checkin - today).days }}
            {% endif %}
          {% endif %}
        badge_color: |-
          {% if is_state('calendar.tora_silvia_26', 'on') %}
            blue
          {% elif is_state('input_boolean.task_active_tora_silvia_26', 'on') %}
            red
          {% endif %}
      - type: custom:mushroom-template-card
        icon: mdi:home-city
        primary: Jackie
        secondary: |-
          {% if is_state('calendar.jackie_s_calendar', 'on') %}
            🧳 OCCUPIED
          {% elif is_state('input_boolean.task_active_jackie', 'on') %}
            ⏳ In Progress
          {% else %}
            ✅ READY
          {% endif %}
        tap_action:
          action: navigate
          navigation_path: /todo?entity_id=todo.property_turnovers_2
        color: |-
          {% if is_state('calendar.jackie_s_calendar', 'on') %}
            blue
          {% elif is_state('input_boolean.task_active_jackie', 'on') %}
            orange
          {% else %}
            green
          {% endif %}
        features_position: bottom
        vertical: true
        badge_text: |-
          {% set entity = 'calendar.jackie_s_calendar' %}
          {% if is_state(entity, 'on') %}
            {# IF OCCUPIED: Count days remaining until checkout #}
            {% set checkout_str = state_attr(entity, 'end_time') %}
            {% if checkout_str is not none %}
              {% set checkout = as_datetime(checkout_str).date() %}
              {% set today = now().date() %}
              {{ (checkout - today).days }}d
            {% endif %}
          {% elif is_state('input_boolean.task_active_jackie', 'on') %}
            {# IF IN PROGRESS: Count days remaining until next booking arrives #}
            {% set checkin_str = state_attr(entity, 'start_time') %}
            {% if checkin_str is not none %}
              {% set checkin = as_datetime(checkin_str).date() %}
              {% set today = now().date() %}
              {{ (checkin - today).days }}
            {% endif %}
          {% endif %}
        badge_color: |-
          {% if is_state('calendar.jackie_s_calendar', 'on') %}
            blue
          {% elif is_state('input_boolean.task_active_jackie', 'on') %}
            red
          {% endif %}
      - type: custom:mushroom-template-card
        icon: mdi:home-city
        primary: Donnelly Patricia
        secondary: >-
          {% if is_state('calendar.donnelly_patricia_9_11', 'on') %}
            🧳 OCCUPIED
          {% elif is_state('input_boolean.task_active_donnelly_patricia', 'on')
          %}
            ⏳ In Progress
          {% else %}
            ✅ READY
          {% endif %}
        tap_action:
          action: navigate
          navigation_path: /todo?entity_id=todo.property_turnovers_2
        color: >-
          {% if is_state('calendar.donnelly_patricia_9_11', 'on') %}
            blue
          {% elif is_state('input_boolean.task_active_donnelly_patricia', 'on')
          %}
            orange
          {% else %}
            green
          {% endif %}
        features_position: bottom
        vertical: true
        badge_text: >-
          {% set entity = 'calendar.donnelly_patricia_9_11' %}

          {% if is_state(entity, 'on') %}
            {# IF OCCUPIED: Count days remaining until checkout #}
            {% set checkout_str = state_attr(entity, 'end_time') %}
            {% if checkout_str is not none %}
              {% set checkout = as_datetime(checkout_str).date() %}
              {% set today = now().date() %}
              {{ (checkout - today).days }}d
            {% endif %}
          {% elif is_state('input_boolean.task_active_donnelly_patricia', 'on')
          %}
            {# IF IN PROGRESS: Count days remaining until next booking arrives #}
            {% set checkin_str = state_attr(entity, 'start_time') %}
            {% if checkin_str is not none %}
              {% set checkin = as_datetime(checkin_str).date() %}
              {% set today = now().date() %}
              {{ (checkin - today).days }}
            {% endif %}
          {% endif %}
        badge_color: >-
          {% if is_state('calendar.donnelly_patricia_9_11', 'on') %}
            blue
          {% elif is_state('input_boolean.task_active_donnelly_patricia', 'on')
          %}
            red
          {% endif %}
      - type: custom:mushroom-template-card
        icon: mdi:home-city
        primary: Coves Patricia 37
        secondary: >-
          {% if is_state('calendar.coves_patricia_37', 'on') %}
            🧳 OCCUPIED
          {% elif is_state('input_boolean.task_active_coves_patricia_37', 'on')
          %}
            ⏳ In Progress
          {% else %}
            ✅ READY
          {% endif %}
        tap_action:
          action: navigate
          navigation_path: /todo?entity_id=todo.property_turnovers_2
        color: >-
          {% if is_state('calendar.coves_patricia_37', 'on') %}
            blue
          {% elif is_state('input_boolean.task_active_coves_patricia_37', 'on')
          %}
            orange
          {% else %}
            green
          {% endif %}
        features_position: bottom
        vertical: true
        badge_text: >-
          {% set entity = 'calendar.coves_patricia_37' %}

          {% if is_state(entity, 'on') %}
            {# IF OCCUPIED: Count days remaining until checkout #}
            {% set checkout_str = state_attr(entity, 'end_time') %}
            {% if checkout_str is not none %}
              {% set checkout = as_datetime(checkout_str).date() %}
              {% set today = now().date() %}
              {{ (checkout - today).days }}d
            {% endif %}
          {% elif is_state('input_boolean.task_active_coves_patricia_37', 'on')
          %}
            {# IF IN PROGRESS: Count days remaining until next booking arrives #}
            {% set checkin_str = state_attr(entity, 'start_time') %}
            {% if checkin_str is not none %}
              {% set checkin = as_datetime(checkin_str).date() %}
              {% set today = now().date() %}
              {{ (checkin - today).days }}
            {% endif %}
          {% endif %}
        badge_color: >-
          {% if is_state('calendar.coves_patricia_37', 'on') %}
            blue
          {% elif is_state('input_boolean.task_active_coves_patricia_37', 'on')
          %}
            red
          {% endif %}
    columns: 2
  - type: custom:auto-entities
    card:
      type: entities
      title: ⏳ Property Prep Countdowns
      show_header_toggle: false
    filter:
      include:
        - entity_id: sensor.*_prep_countdown
          state: ">= 0"
          options:
            tap_action:
              action: navigate
              navigation_path: /calendar
        - entity_id: sensor.jackies_calendar_prep_countdown
          state: ">= 0"
          options:
            tap_action:
              action: navigate
              navigation_path: /calendar
    sort:
      method: state
      numeric: true
  - display_order: duedate_asc
    type: todo-list
    title: 📋 Active Handover Checklists
    entity: todo.property_turnovers_2
  - type: markdown
    content: >-
      *ℹ️ Conflict checker scans daily at 07:00 AM. Clashes sync straight to
      Google Tasks.*
  - type: horizontal-stack
    cards:
      - show_name: true
        show_icon: true
        type: button
        name: Refresh Calendars
        icon: mdi:calendar-sync
        tap_action:
          action: perform-action
          perform_action: homeassistant.update_entity
          target:
            entity_id:
              - calendar.debbie_s_calendar
              - calendar.marika_eva_24
              - calendar.guillermo_4_rentals
              - calendar.tora_silvia_26
              - calendar.teodoro_4
              - calendar.jackie_s_calendar
              - calendar.donnelly_patricia_9_11
              - calendar.marta_1
              - calendar.coves_patricia_37
        double_tap_action:
          action: perform-action
          perform_action: script.force_refresh_dashboard_colors
          target: {}
        hold_action:
          action: navigate
          navigation_path: /property-turnovers
      - type: button
        name: Refresh Tasks
        icon: mdi:clipboard-check-outline
        tap_action:
          action: perform-action
          perform_action: script.operations_google_tasks_sync_reset_2
visibility:
  - condition: screen
    media_query: "(min-width: 0px)"